#!/usr/bin/python import ugcs_utils,ugcs_user,shell_utils,os,os.path,sys from shell_utils import get_response from ugcs_utils import UgcsError if os.getuid() < 1000: sys.exit(0) if len(sys.argv) == 1: uidNumber = os.getuid() ldap_user = ugcs_utils.lookup_user_uid(uidNumber) username = ldap_user[1]['uid'][0] else: username = sys.argv[1] shell_locations = ['/bin', '/usr/bin' ] shell_list_file = '/etc/shells' valid_shells = open('/etc/shells', 'r').readlines() def find_shell(shell): if os.path.isfile(shell): return shell for directory in shell_locations: pass def shell_verifier(shell): shell = '%s\n' % shell return shell == '\n' or shell in valid_shells user = ugcs_user.User(username) user.read_from_ldap() try: user.shell except AttributeError: user.shell = '/bin/bash' print 'Changing the shell for %s' % username print 'Enter a new shell, or press Enter to leave it unchanged' try: newshell = get_response('Enter a new shell [%s] ' % user.shell, verifier=shell_verifier, errormessage='Please enter a valid shell') except UgcsError: sys.exit(1) if newshell == '': print 'Shell unchanged' sys.exit(0) try: user.ldap_replace('loginShell', newshell) print 'Shell changed to %s' % newshell except Exception, msg: print 'There was an error changing your shell: %s' % msg