optionally read some configuration items from the environment so we can test ud-gener...
authorPeter Palfrader <peter@palfrader.org>
Mon, 2 Aug 2010 19:17:07 +0000 (19:17 +0000)
committerPeter Palfrader <peter@palfrader.org>
Mon, 2 Aug 2010 19:17:07 +0000 (19:17 +0000)
ud-generate
userdir_ldap.py

index fc6dbb2..943da31 100755 (executable)
@@ -1076,9 +1076,14 @@ def GenKeyrings(OutDir):
 
 # Connect to the ldap server
 l = connectLDAP()
-F = open(PassDir + "/pass-" + pwd.getpwuid(os.getuid())[0], "r")
-Pass = F.readline().strip().split(" ")
-F.close()
+# for testing purposes it's sometimes useful to pass username/password
+# via the environment
+if 'UD_CREDENTIALS' in os.environ:
+   Pass = os.environ['UD_CREDENTIALS'].split()
+else:
+   F = open(PassDir + "/pass-" + pwd.getpwuid(os.getuid())[0], "r")
+   Pass = F.readline().strip().split(" ")
+   F.close()
 l.simple_bind_s("uid=" + Pass[0] + "," + BaseDn, Pass[1])
 
 # Fetch all the groups
@@ -1123,6 +1128,10 @@ if HostAttrs == None:
 
 HostAttrs.sort(lambda x, y: cmp((GetAttr(x, "hostname")).lower(), (GetAttr(y, "hostname")).lower()))
 
+# override globaldir for testing
+if 'UD_GENERATEDIR' in os.environ:
+   GenerateDir = os.environ['UD_GENERATEDIR']
+
 # Generate global things
 GlobalDir = GenerateDir + "/"
 GenDisabledAccounts(GlobalDir + "disabled-accounts")
index 109c7ce..c76992c 100644 (file)
@@ -432,9 +432,12 @@ def Group2GID(l, name):
    return -1
 
 def make_hmac(str):
-   File = open(PassDir+"/key-hmac-"+pwd.getpwuid(os.getuid())[0],"r");
-   HmacKey = File.readline().strip()
-   File.close();
+   if 'UD_HMAC_KEY' in os.environ:
+      HmacKey = os.environ['UD_HMAC_KEY']
+   else:
+      File = open(PassDir+"/key-hmac-"+pwd.getpwuid(os.getuid())[0],"r");
+      HmacKey = File.readline().strip()
+      File.close();
    return hmac.new(HmacKey, str, sha1_module).hexdigest()
 
 def make_passwd_hmac(status, purpose, uid, uuid, hosts, cryptedpass):