[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-06-18 12:50:31

Modified files:
	luci/utils     : luci_admin 

Log message:
	

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

--- conga/luci/utils/luci_admin	2006/06/18 03:26:29	1.13
+++ conga/luci/utils/luci_admin	2006/06/18 12:50:31	1.14
@@ -1,6 +1,11 @@
 #!/usr/bin/python
 
 import sys, os, stat, random, crypt, select, string
+from sys import stderr, argv
+import types
+import xml
+import xml.dom
+from xml.dom import minidom
 
 sys.path.extend((
 	'/usr/lib64/zope/lib/python',
@@ -9,32 +14,6 @@
 	'/usr/lib/zope/lib/python/Products'
 ))
 
-from sys import stderr, argv
-import ZODB
-from ZODB.FileStorage import FileStorage
-from ZODB.DB import DB
-import xml
-import xml.dom
-from xml.dom import minidom
-import types
-
-import OFS
-from OFS.Application import AppInitializer
-import OFS.Folder
-import AccessControl
-import AccessControl.User
-from AccessControl.SecurityManagement import newSecurityManager
-import transaction
-
-null = file('/dev/null', 'rwb+', 0)
-orig_stderr = sys.stderr
-
-sys.stderr = null
-import Products.CMFCore
-sys.stderr = orig_stderr
-
-import Products.CMFCore.MemberDataTool
-
 LUCI_INIT_DEBUG = 0
 
 LUCI_USER='luci'
@@ -48,19 +27,49 @@
 
 INITUSER_FILE_PATH = '/var/lib/luci/inituser'
 
-examine_classes = [
-	'OFS.Folder.Folder',
-	'AccessControl.User.User',
-	'Products.CMFCore.MemberDataTool.MemberData'
-]
-
+null = file(os.devnull, 'rwb+', 0)
+orig_stderr = sys.stderr
 
 if LUCI_INIT_DEBUG:
 	verbose = sys.stderr
 else:
 	verbose = null
 
+def save_password(user, password):
+	inituser = file(INITUSER_FILE_PATH, 'w')
+	try: os.chmod(INITUSER_FILE_PATH, 0600)
+	except OSError, e:
+		print 'An error occurred while saving',user,'password:',e
+		try: os.unlink(INITUSER_FILE_PATH)
+		except: pass
+		inituser.close()
+		return -1
+	inituser.write(user + ':' + password)
+	inituser.close()
+
+	try:
+		import pwd
+		luci = pwd.getpwnam(LUCI_USER)[2:4]
+		os.chown(INITUSER_FILE_PATH, luci[0], luci[1])
+	except:
+		return -1
+
 def luci_restore(argv):
+	import ZODB
+	from ZODB.FileStorage import FileStorage
+	from ZODB.DB import DB
+	import OFS
+	from OFS.Application import AppInitializer
+	import OFS.Folder
+	import AccessControl
+	import AccessControl.User
+	from AccessControl.SecurityManagement import newSecurityManager
+	import transaction
+	sys.stderr = null
+	import Products.CMFCore
+	sys.stderr = orig_stderr
+	import Products.CMFCore.MemberDataTool
+
 	if len(argv) > 0:
 		dbfn = argv[0]
 	else:
@@ -144,7 +153,9 @@
 			continue
 		passwd = str(passwd)
 
-		if id != 'admin':
+		if id == 'admin':
+			save_password('admin', passwd)
+		else:
 			email = u.getAttribute('email')
 			if not email:
 				email = id + '@luci.example.org'
@@ -360,6 +371,14 @@
 	return node.cloneNode(True)
 
 def luci_backup(argv):
+	import ZODB
+	from ZODB.FileStorage import FileStorage
+	from ZODB.DB import DB
+	import OFS
+	import OFS.Folder
+	import AccessControl
+	import AccessControl.User
+
 	if len(argv) > 0:
 		dbfn = argv[0]
 	else:
@@ -374,6 +393,12 @@
 		stderr.write('Unable to open the luci database \"' + dbfn + '\"\n')
 		return -1
 
+	examine_classes = [
+		'OFS.Folder.Folder',
+		'AccessControl.User.User',
+		'Products.CMFCore.MemberDataTool.MemberData'
+	]
+
 	systems = {}
 	clusters = {}
 	users = {}
@@ -711,25 +736,12 @@
     salt = random.choice(salt_choices) + random.choice(salt_choices)
     pswd = '{CRYPT}' + crypt.crypt(password, salt)
     return pswd
-def save_password(user, password):
-    inituser = file(INITUSER_FILE_PATH, 'w')
-    os.chmod(INITUSER_FILE_PATH, stat.S_IRUSR|stat.S_IWUSR)
-    inituser.write(user + ':' + password)
-    inituser.close()
-    
-    command = '/bin/chown'
-    args = [command, LUCI_USER, INITUSER_FILE_PATH]
-    _execWithCaptureErrorStatus(command, args)
-    
-    return
-
-
 
 
 def restart_message():
     print
     print
-    print 'Restart Luci server for changes to take effect'
+    print 'Restart the Luci server for changes to take effect'
     print 'eg. service luci restart'
     print
     return 
@@ -812,6 +824,7 @@
 		print 'The Luci restore failed. Try reinstalling Luci, then restoring again.'
 		sys.exit(1)
 
+	print 'Restore was successful.'
 	restart_message()
 	return True
 


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