#!/usr/bin/env python # CCS Computer Science # # Douglas Thrift # # $Id$ import admin import ldap import os.path try: from _users import users except ImportError: users = set() def user(user): if user in users: return True connection = admin.ldap_connection(False) try: return bool(connection.search_s(admin.PEOPLE, ldap.SCOPE_ONELEVEL, '(uid=%s)' % user, ('uid',), 1)) finally: connection.unbind_s() if __name__ == '__main__': parser = admin.parser(usage = '%prog [options] [FILE...]') parser.add_option('-l', '--list', action = 'store_true', default = False, help = 'list the system users from all systems') parser.add_option('-t', '--touch', help = 'touch the file TOUCH if successful') options, args = parser.parse_args() if options.list: for user in sorted(users): print user parser.exit() if not args: parser.error('no files specified') _users = frozenset(users) format = '%%%us: %%s' % ((len(max(args, key = len)) + 1) / 2 * 2) for user_file in args: with open(user_file, 'rb') as user_file: for line in user_file: if line.startswith('#'): continue _user = line.split(':', 1)[0] if not user(_user): print format % (user_file.name, _user) users.add(_user) if users != _users: with open(os.path.join(os.path.dirname(__file__), '_users.py'), 'wb') as user_file: user_file.write('users = set((\n') for user in sorted(users): user_file.write('\t%s,\n' % repr(user)) user_file.write('))\n\n# vim: noexpandtab tabstop=4\n') if options.touch: open(options.touch, 'wb') # vim: noexpandtab tabstop=4