GenSSHShadow
[mirror/userdir-ldap.git] / ud-generate
index 0a6e981..412e210 100755 (executable)
@@ -324,21 +324,17 @@ def GenSSHShadow():
    safe_makedirs(os.path.join(GlobalDir, 'userkeys'))
 
    for x in PasswdAttrs:
+      a = UDLdap.Account(x[0], x[1])
+      if not 'sshRSAAuthKey' in a: continue
 
-      if x[1].has_key("uidNumber") == 0 or \
-         x[1].has_key("sshRSAAuthKey") == 0:
-         continue
-
-      User = GetAttr(x, "uid")
       F = None
-
       try:
          OldMask = os.umask(0077)
-         File = os.path.join(GlobalDir, 'userkeys', User)
+         File = os.path.join(GlobalDir, 'userkeys', a['uid'])
          F = open(File + ".tmp", "w", 0600)
          os.umask(OldMask)
 
-         for I in x[1]["sshRSAAuthKey"]:
+         for I in a['sshRSAAuthKey']:
             MultipleLine = "%s" % I
             MultipleLine = Sanitize(MultipleLine) + "\n"
             F.write(MultipleLine)
@@ -459,19 +455,16 @@ def GenGroup(File):
      
       # Sort them into a list of groups having a set of users
       for x in PasswdAttrs:
-         uid = GetAttr(x, "uid")
-         if 'gidNumber' in x[1]:
-            GroupHasPrimaryMembers[ int(x[1]["gidNumber"][0]) ] = True
-         if x[1].has_key("uidNumber") == 0 or not IsInGroup(x):
-            continue
-         if x[1].has_key("supplementaryGid") == 0:
-            continue
-     
+         a = UDLdap.Account(x[0], x[1])
+         GroupHasPrimaryMembers[ a['gidNumber'] ] = True
+         if not IsInGroup(x): continue
+         if not 'supplementaryGid' in a: continue
+
          supgroups=[]
-         addGroups(supgroups, x[1]["supplementaryGid"], uid)
+         addGroups(supgroups, a['supplementaryGid'], a['uid'])
          for g in supgroups:
-            GroupMap[g].append(uid)
-     
+            GroupMap[g].append(a['uid'])
+
       # Output the group file.
       J = 0
       for x in GroupMap.keys():
@@ -534,10 +527,9 @@ def GenForward(File):
      
       # Write out the email address for each user
       for x in PasswdAttrs:
-         if x[1].has_key("emailForward") == 0:
-            continue
-     
-         Line = "%s: %s" % (GetAttr(x, "uid"), GetAttr(x, "emailForward"))
+         a = UDLdap.Account(x[0], x[1])
+         if not 'emailForward' in a: continue
+         Line = "%s: %s" % (a['uid'], a['emailForward'])
          Line = Sanitize(Line) + "\n"
          F.write(Line)