More loop logic cleanup - we only handle mail for gid Debian, so we
authorStephen Gran <steve@lobefin.net>
Sat, 9 May 2009 13:33:53 +0000 (14:33 +0100)
committerStephen Gran <steve@lobefin.net>
Sat, 9 May 2009 13:33:53 +0000 (14:33 +0100)
create a new list of users with that gid, and only look at that list
for Mail purposes.

ud-generate

index b8e3d74..18c008b 100755 (executable)
@@ -36,7 +36,6 @@ global CurrentHost
 
 PasswdAttrs = None
 DisabledUsers = []
-RetiredUsers = []
 GroupIDMap = {}
 SubGroupMap = {}
 Allowed = None
@@ -108,6 +107,12 @@ def IsRetired(DnRecord):
 
    return False
 
+def IsGidDebian(x):
+   try:
+      return int(GetAttr(x, "gidNumber", 0)) == 800
+   except ValueError:
+      return False
+
 # See if this user is in the group list
 def IsInGroup(DnRecord):
   if Allowed == None:
@@ -461,8 +466,8 @@ def GenGroup(File):
    return grouprevmap
 
 def CheckForward():
-   global PasswdAttrs
-   for x in PasswdAttrs:
+   global DebianUsers
+   for x in DebianUsers:
       if x[1].has_key("emailForward") == 0:
          continue
    
@@ -488,10 +493,10 @@ def GenForward(File):
       os.umask(OldMask)
      
       # Fetch all the users
-      global PasswdAttrs
+      global DebianUsers
      
       # Write out the email address for each user
-      for x in PasswdAttrs:
+      for x in DebianUsers:
          if x[1].has_key("emailForward") == 0:
             continue
      
@@ -513,10 +518,10 @@ def GenAllForward(File):
       os.umask(OldMask)
      
       # Fetch all the users
-      global PasswdAttrs
+      global DebianUsers
      
       # Write out the email address for each user
-      for x in PasswdAttrs:
+      for x in DebianUsers:
          if x[1].has_key("emailForward") == 0:
             continue
      
@@ -541,10 +546,10 @@ def GenMarkers(File):
       F = open(File + ".tmp", "w")
      
       # Fetch all the users
-      global PasswdAttrs
+      global DebianUsers
      
       # Write out the position for each user
-      for x in PasswdAttrs:
+      for x in DebianUsers:
          if x[1].has_key("latitude") == 0 or x[1].has_key("longitude") == 0:
             continue
          try:
@@ -567,10 +572,10 @@ def GenPrivate(File):
       F = open(File + ".tmp", "w")
      
       # Fetch all the users
-      global PasswdAttrs
+      global DebianUsers
      
       # Write out the position for each user
-      for x in PasswdAttrs:
+      for x in DebianUsers:
          if x[1].has_key("privateSub") == 0:
             continue
      
@@ -578,10 +583,6 @@ def GenPrivate(File):
          if x[1].has_key("keyFingerPrint") == 0:
             continue
      
-         # Must be in the Debian group (yuk, hard coded for now)
-         if GetAttr(x, "gidNumber") != "800":
-            continue
-     
          try:
             Line = "%s"%(GetAttr(x, "privateSub"))
             Line = Sanitize(Line) + "\n"
@@ -636,9 +637,9 @@ def GenMailDisable(File):
       F = open(File + ".tmp", "w")
      
       # Fetch all the users
-      global PasswdAttrs
+      global DebianUsers
      
-      for x in PasswdAttrs:
+      for x in DebianUsers:
          Reason = None
      
          if x[1].has_key("mailDisableMessage"):
@@ -646,10 +647,6 @@ def GenMailDisable(File):
          else:
             continue
      
-         # Must be in the Debian group (yuk, hard coded for now)
-         if GetAttr(x, "gidNumber") != "800":
-            continue
-     
          try:
             Line = "%s: %s"%(GetAttr(x, "uid"), Reason)
             Line = Sanitize(Line) + "\n"
@@ -670,18 +667,14 @@ def GenMailBool(File, Key):
       F = open(File + ".tmp", "w")
      
       # Fetch all the users
-      global PasswdAttrs
+      global DebianUsers
      
-      for x in PasswdAttrs:
+      for x in DebianUsers:
          Reason = None
      
          if x[1].has_key(Key) == 0:
             continue
      
-         # Must be in the Debian group (yuk, hard coded for now)
-         if GetAttr(x, "gidNumber") != "800":
-            continue
-     
          if GetAttr(x, Key) != "TRUE":
             continue
      
@@ -705,18 +698,14 @@ def GenMailList(File, Key):
       F = open(File + ".tmp", "w")
      
       # Fetch all the users
-      global PasswdAttrs
+      global DebianUsers
      
-      for x in PasswdAttrs:
+      for x in DebianUsers:
          Reason = None
      
          if x[1].has_key(Key) == 0:
             continue
      
-         # Must be in the Debian group (yuk, hard coded for now)
-         if GetAttr(x, "gidNumber") != "800":
-            continue
-     
          try:
             found = 0
             Line = None
@@ -853,10 +842,10 @@ def GenBSMTP(File, HomePrefix):
       F = open(File + ".tmp", "w")
      
       # Fetch all the users
-      global PasswdAttrs
+      global DebianUsers
      
       # Write out the zone file entry for each user
-      for x in PasswdAttrs:
+      for x in DebianUsers:
          if x[1].has_key("dnsZoneEntry") == 0:
             continue
      
@@ -1056,11 +1045,8 @@ else:
 GlobalDir = GenerateDir + "/"
 GenDisabledAccounts(GlobalDir + "disabled-accounts")
 
-for x in PasswdAttrs:
-   if IsRetired(x):
-      RetiredUsers.append(x)
-
-PasswdAttrs = filter(lambda x: not x in RetiredUsers, PasswdAttrs)
+PasswdAttrs = filter(not IsRetired, PasswdAttrs)
+DebianUsers = filter(IsGidDebian, PasswdAttrs)
 
 CheckForward()