[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] conga/luci/utils luci_admin



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe sourceware org	2006-08-03 21:11:35

Modified files:
	luci/utils     : luci_admin 

Log message:
	don't echo passwords when prompting for them

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/utils/luci_admin.diff?cvsroot=cluster&r1=1.38&r2=1.39

--- conga/luci/utils/luci_admin	2006/08/03 16:32:08	1.38
+++ conga/luci/utils/luci_admin	2006/08/03 21:11:35	1.39
@@ -67,6 +67,33 @@
 else:
 	verbose = null
 
+def read_passwd(prompt, confirm_prompt):
+	import termios
+
+	# If 1 is not standard in, it's your own fault. 
+	attr = termios.tcgetattr(0)
+	orig_attr = attr[:]
+	attr[3] &= ~termios.ECHO
+
+	try:
+		termios.tcsetattr(1, termios.TCSADRAIN, attr)
+		passwd = raw_input(prompt)
+		print
+		confirm = raw_input(confirm_prompt)
+		print "\n"
+		termios.tcsetattr(1, termios.TCSADRAIN, orig_attr)
+	except:
+		termios.tcsetattr(1, termios.TCSADRAIN, orig_attr)
+		return None
+
+	if passwd != confirm:
+		raise
+		sys.stderr.write('The passwords don\'t match.')
+		return None
+
+	return passwd
+
+
 def restore_luci_db_fsattr():
 	try:
 		luci = pwd.getpwnam(LUCI_USER)[2:4]
@@ -967,7 +994,12 @@
 
 	print '\nCreating the \'admin\' user'
 
-	password = raw_input('Enter password: ')
+	password = read_passwd('Enter password: ', 'Confirm password: ')
+	if not password:
+		sys.stderr.write('Error reading password. Exiting.')
+		sys.exit(1)
+	print "Passwords match. Setting the admin password...\n"
+
 	if not set_zope_passwd('admin', password):
 		restore_luci_db_fsattr()
 		print 'The admin password has been successfully set.'
@@ -990,7 +1022,12 @@
 
 	print 'Resetting the admin user\'s password\n'
 
-	password = raw_input('Enter password: ')
+	password = read_passwd('Enter password: ', 'Confirm password: ')
+	if not password:
+		sys.stderr.write('Error reading password. Exiting.')
+		sys.exit(1)
+	print "Passwords match. Resetting the admin password...\n"
+
 	if not set_zope_passwd('admin', password):
 		print 'The admin password has been successfully reset.'
 	else:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]