#!/usr/bin/env python # CCS Computer Science # Shells # # Douglas Thrift # # $Id$ import admin import common import copy import ldap import ldap.modlist if __name__ == '__main__': parser = admin.parser() parser.add_option('-l', '--list', action = 'store_const', const = 'list', help = 'list the available shells and their per system paths', dest = 'command') parser.add_option('-u', '--update', action = 'store_const', const = 'update', help = 'update shells in the LDAP database', dest = 'command') command = parser.parse_args()[0].command if not command: parser.error('no option specified') elif command == 'list': for shell, shells in common.SHELLS: print 'shell:', shell for system, shell in zip(common.SYSTEMS, shells): print '%20s:' % system, shell if shell else '{user defined}' elif command == 'update': shells = list(common.SHELLS) shells[-1] = ('custom', dict(common.SHELLS)['bash']) try: connection = admin.ldap_connection() for shell, shells in shells: for dn, old_entry in connection.search_s(admin.PEOPLE, ldap.SCOPE_ONELEVEL, '(loginShell=%s)' % shell, ['uid'] + admin.SHELLS): if shell != 'custom': new_entry = dict(zip(admin.SHELLS, map(lambda shell: [shell], shells))) else: new_entry = copy.copy(old_entry) for type, _shell in zip(admin.SHELLS, shells): if type not in new_entry: new_entry[type] = _shell modlist = ldap.modlist.modifyModlist(old_entry, new_entry, ('uid',)) if modlist: print old_entry['uid'][0], modlist connection.modify_s(dn, modlist) connection.unbind_s() except (IOError, ldap.LDAPError), error: admin.error(error) # vim: noexpandtab tabstop=4