From 29816c66079debfbaaa183bd46466698ce4d29fd Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Mon, 2 Aug 2010 19:17:07 +0000 Subject: [PATCH] optionally read some configuration items from the environment so we can test ud-generate without running it as sshdist --- ud-generate | 15 ++++++++++++--- userdir_ldap.py | 9 ++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ud-generate b/ud-generate index fc6dbb2..943da31 100755 --- a/ud-generate +++ b/ud-generate @@ -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") diff --git a/userdir_ldap.py b/userdir_ldap.py index 109c7ce..c76992c 100644 --- a/userdir_ldap.py +++ b/userdir_ldap.py @@ -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): -- 2.20.1