From 89648b4805761b9df8de5c8f8ef000dc42cc5c4b Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Mon, 2 Aug 2010 22:05:41 +0000 Subject: [PATCH] GenPasswd --- UDLdap.py | 2 +- ud-generate | 43 ++++++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/UDLdap.py b/UDLdap.py index 5b0caa7..90c942d 100644 --- a/UDLdap.py +++ b/UDLdap.py @@ -4,7 +4,7 @@ import userdir_ldap class Account: array_values = ['keyFingerPrint', 'mailWhitelist', 'mailRBL', 'mailRHSBL', 'supplementaryGid', 'sshRSAAuthKey', 'sudoPassword'] - int_values = ['shadowExpire', 'gidNumber'] + int_values = ['shadowExpire', 'gidNumber', 'uidNumber'] defaults = { 'accountStatus': 'active', 'keyFingerPrint': [] diff --git a/ud-generate b/ud-generate index f4f8b58..e2b3353 100755 --- a/ud-generate +++ b/ud-generate @@ -184,29 +184,30 @@ def GenPasswd(File, HomePrefix, PwdMarker): userlist = {} # 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 - + a = UDLdap.Account(x[0], x[1]) + if not IsInGroup(x): continue + # Do not let people try to buffer overflow some busted passwd parser. - if len(GetAttr(x, "gecos")) > 100 or len(GetAttr(x, "loginShell")) > 50: - continue - - userlist[GetAttr(x, "uid")] = int(GetAttr(x, "gidNumber")) - Line = "%s:%s:%s:%s:%s:%s%s:%s" % (GetAttr(x, "uid"),\ - PwdMarker,\ - GetAttr(x, "uidNumber"), GetAttr(x, "gidNumber"),\ - GetAttr(x, "gecos"), HomePrefix, GetAttr(x, "uid"),\ - GetAttr(x, "loginShell")) - - Line = Sanitize(Line) + "\n" - F.write("0%u %s" % (I, Line)) - F.write(".%s %s" % (GetAttr(x, "uid"), Line)) - F.write("=%s %s" % (GetAttr(x, "uidNumber"), Line)) - I = I + 1 - + if len(a['gecos']) > 100 or len(a['loginShell']) > 50: continue + + userlist[a['uid']] = a['gidNumber'] + line = "%s:%s:%d:%d:%s:%s%s:%s" % ( + a['uid'], + PwdMarker, + a['uidNumber'], + a['gidNumber'], + a['gecos'], + HomePrefix, a['uid'], + a['loginShell']) + line = Sanitize(line) + "\n" + F.write("0%u %s" % (i, line)) + F.write(".%s %s" % (a['uid'], line)) + F.write("=%d %s" % (a['uidNumber'], line)) + i = i + 1 + # Oops, something unspeakable happened. except: Die(File, None, F) -- 2.20.1