From: Peter Palfrader Date: Mon, 2 Aug 2010 21:55:14 +0000 (+0000) Subject: GenShadow X-Git-Tag: userdir-ldap-0.3.78~6^2~4 X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap.git;a=commitdiff_plain;h=d1ad8523f8e88bf96d9c515da8c8c451a3089bea GenShadow --- diff --git a/UDLdap.py b/UDLdap.py index ffdb6b0..5b0caa7 100644 --- a/UDLdap.py +++ b/UDLdap.py @@ -59,6 +59,13 @@ class Account: return False return True + def get_password(self): + p = self['userPassword'] + if not p.startswith('{crypt}') or len(p) > 50: + return p + else: + return p[7:] + # not expired def shadow_active(self): if 'shadowExpire' in self and \ diff --git a/ud-generate b/ud-generate index 6ac9bde..f4f8b58 100755 --- a/ud-generate +++ b/ud-generate @@ -227,35 +227,30 @@ def GenShadow(File): # Fetch all the users global PasswdAttrs - I = 0 + i = 0 for x in PasswdAttrs: - if x[1].has_key("uidNumber") == 0 or not IsInGroup(x): - continue - - Pass = GetAttr(x, "userPassword") - if Pass[0:7] != "{crypt}" or len(Pass) > 50: - Pass = '*' - else: - Pass = Pass[7:] - + a = UDLdap.Account(x[0], x[1]) + if not IsInGroup(x): continue + # If the account is locked, mark it as such in shadow # See Debian Bug #308229 for why we set it to 1 instead of 0 - if (GetAttr(x, "userPassword").find("*LK*") != -1) \ - or GetAttr(x, "userPassword").startswith("!"): - ShadowExpire = '1' - else: - ShadowExpire = GetAttr(x, "shadowExpire") - - Line = "%s:%s:%s:%s:%s:%s:%s:%s:" % (GetAttr(x, "uid"),\ - Pass, GetAttr(x, "shadowLastChange"),\ - GetAttr(x, "shadowMin"), GetAttr(x, "shadowMax"),\ - GetAttr(x, "shadowWarning"), GetAttr(x, "shadowInactive"),\ - ShadowExpire) - Line = Sanitize(Line) + "\n" - F.write("0%u %s" % (I, Line)) - F.write(".%s %s" % (GetAttr(x, "uid"), Line)) - I = I + 1 - + if not a.pw_active(): ShadowExpire = '1' + elif 'shadowExpire' in a: ShadowExpire = str(a['shadowExpire']) + else: ShadowExpire = '' + + values = [] + values.append(a['uid']) + values.append(a.get_password()) + for key in 'shadowLastChange', 'shadowMin', 'shadowMax', 'shadowWarning', 'shadowInactive': + if key in a: values.append(a[key]) + else: values.append('') + values.append(ShadowExpire) + line = ':'.join(values)+':' + line = Sanitize(line) + "\n" + F.write("0%u %s" % (i, line)) + F.write(".%s %s" % (a['uid'], line)) + i = i + 1 + # Oops, something unspeakable happened. except: Die(File, None, F)