From mboxrd@z Thu Jan 1 00:00:00 1970 From: rmccabe@sourceware.org Date: 3 Aug 2006 16:32:09 -0000 Subject: [Cluster-devel] conga/luci/utils luci_admin Message-ID: <20060803163209.9257.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: conga Changes by: rmccabe at sourceware.org 2006-08-03 16:32:09 Modified files: luci/utils : luci_admin Log message: set the initial admin password the same way it's reset Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/utils/luci_admin.diff?cvsroot=cluster&r1=1.37&r2=1.38 --- conga/luci/utils/luci_admin 2006/08/03 15:55:54 1.37 +++ conga/luci/utils/luci_admin 2006/08/03 16:32:08 1.38 @@ -31,15 +31,13 @@ LUCI_INIT_DEBUG = 0 -LUCI_USER='luci' -LUCI_GROUP='luci' +LUCI_USER = 'luci' +LUCI_GROUP = 'luci' -LUCI_BACKUP_DIR='/var/lib/luci/var' -LUCI_CERT_DIR='/var/lib/luci/var/certs/' -LUCI_BACKUP_PATH=LUCI_BACKUP_DIR + '/luci_backup.xml' -LUCI_DB_PATH='/var/lib/luci/var/Data.fs' - -INITUSER_FILE_PATH = '/var/lib/luci/inituser' +LUCI_BACKUP_DIR = '/var/lib/luci/var' +LUCI_CERT_DIR = '/var/lib/luci/var/certs/' +LUCI_BACKUP_PATH = LUCI_BACKUP_DIR + '/luci_backup.xml' +LUCI_DB_PATH = '/var/lib/luci/var/Data.fs' SSL_PRIVKEY_NAME = 'privkey.pem' SSL_PUBKEY_NAME = 'cacert.pem' @@ -69,27 +67,7 @@ else: verbose = null -def save_password(user, password): - inituser = file(INITUSER_FILE_PATH, 'w') - try: os.chmod(INITUSER_FILE_PATH, 0600) - except OSError, e: - sys.stderr.write('An error occurred while saving user' + user + '\'s password: ' + e + '\n') - try: - os.unlink(INITUSER_FILE_PATH) - except: pass - inituser.close() - return -1 - - inituser.write(user + ':' + password) - inituser.close() - - try: - luci = pwd.getpwnam(LUCI_USER)[2:4] - os.chown(INITUSER_FILE_PATH, luci[0], luci[1]) - except: - return -1 - -def restore_luci_fsattr(): +def restore_luci_db_fsattr(): try: luci = pwd.getpwnam(LUCI_USER)[2:4] if not luci or len(luci) != 2: @@ -183,7 +161,7 @@ db.close() fs.close() - if restore_luci_fsattr(): + if restore_luci_db_fsattr(): return -1 return ret @@ -962,16 +940,6 @@ return True - -def generate_password_hash(password): - salt_choices = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789./") - salt = random.choice(salt_choices) + random.choice(salt_choices) - pswd = '{CRYPT}' + crypt.crypt(password, salt) - return pswd - - def restart_message(): print print @@ -985,45 +953,53 @@ def init(argv): - if luci_initialized(): - sys.stderr.write('Luci site has been already initialized.\n') - sys.stderr.write('If you want to reset admin password, execute\n') - sys.stderr.write('\t' + argv[0] + ' password\n') - sys.exit(1) - print 'Initializing the Luci server' - print - print 'Generating SSL certificates...' - if generate_ssl_certs() == False: - sys.stderr.write('failed. exiting ...\n') - sys.exit(1) + if luci_initialized(): + sys.stderr.write('Luci site has been already initialized.\n') + sys.stderr.write('If you want to reset admin password, execute\n') + sys.stderr.write('\t' + argv[0] + ' password\n') + sys.exit(1) + print 'Initializing the Luci server\n' + print 'Generating SSL certificates...' - print - print 'Creating the \'admin\' user' - password = raw_input('Enter password: ') - save_password('admin', generate_password_hash(password)) - print 'The Luci server has been successfully initialized' + if generate_ssl_certs() == False: + sys.stderr.write('failed. exiting ...\n') + sys.exit(1) - restart_message() + print '\nCreating the \'admin\' user' - return + password = raw_input('Enter password: ') + if not set_zope_passwd('admin', password): + restore_luci_db_fsattr() + print 'The admin password has been successfully set.' + else: + sys.stderr.write('Unable to set the admin user\'s password.\n') + sys.exit(1) + + print 'The Luci server has been successfully initialized' + restart_message() + + return def password(argv): - if not luci_initialized(): - sys.stderr.write('The Luci site has not been initialized.\n') - sys.stderr.write('To initialize it, execute\n') - sys.stderr.write('\t' + argv[0] + ' init\n') - sys.exit(1) + if not luci_initialized(): + sys.stderr.write('The Luci site has not been initialized.\n') + sys.stderr.write('To initialize it, execute\n') + sys.stderr.write('\t' + argv[0] + ' init\n') + sys.exit(1) - print 'Resetting the admin user\'s password' - print - password = raw_input('Enter password: ') - if not set_zope_passwd('admin', password): - print 'The admin password has been successfully reset.' + print 'Resetting the admin user\'s password\n' - restart_message() + password = raw_input('Enter password: ') + if not set_zope_passwd('admin', password): + print 'The admin password has been successfully reset.' + else: + sys.stderr.write('Unable to set the admin user\'s password.\n') + sys.exit(1) - return + restart_message() + + return def backup(argv): @@ -1040,7 +1016,7 @@ except: pass doc = luci_backup(argv[2:]) - restore_luci_fsattr() + restore_luci_db_fsattr() if not doc: sys.stderr.write('The Luci backup failed. Exiting.\n') sys.exit(1) @@ -1103,7 +1079,7 @@ print 'Restore was successful.' restart_message() - if restore_luci_fsattr(): + if restore_luci_db_fsattr(): return False return ret