fix ipv6 parsing. We would not properly handle empty blocks (i.e. ::).
[mirror/userdir-ldap.git] / ud-mailgate
index 49b26ae..cd6b517 100755 (executable)
@@ -189,10 +189,11 @@ def DoArbChange(Str, Attrs):
         if i.lower() == attrName:
             attrName = i
             break
-    if attrName in ArbChanges:
+    if attrName not in ArbChanges:
         return None
 
-    if re.match(ArbChanges[attrName], G[1]) is None:
+    value = G[1]
+    if re.match(ArbChanges[attrName], value) is None:
         raise UDFormatError("Item does not match the required format" + ArbChanges[attrName])
 
     Attrs.append((ldap.MOD_REPLACE, attrName, value))
@@ -432,7 +433,7 @@ def DoDNS(Str, Attrs, DnRecord):
             if p == "":
                 if seenEmptypart:
                     return "Invalid IPv6 address (%s): more than one :: (nothing in between colons) is not allowed" % (ipv6address)
-            seenEmptypart = True
+                seenEmptypart = True
             sanitized = "%s IN AAAA %s" % (hostname, ipv6address)
     else:
         raise UDFormatError("None of the types I recognize was it.  I shouldn't be here.  confused.")
@@ -484,7 +485,7 @@ def DoConfirmSudopassword(Str, SudoPasswd):
     return "got confirm for sudo password %s on host(s) %s, auth code %s" % (uuid, hosts, hmac)
 
 
-def FinishConfirmSudopassword(l, uid, Attrs, SudoPasswd):
+def FinishConfirmSudopassword(lc, uid, Attrs, SudoPasswd):
     result = "\n"
 
     if len(SudoPasswd) == 0:
@@ -493,7 +494,7 @@ def FinishConfirmSudopassword(l, uid, Attrs, SudoPasswd):
     res = lc.search_s(BaseDn, ldap.SCOPE_ONELEVEL, "uid=" + uid, ['sudoPassword'])
     if len(res) != 1:
         raise UDFormatError("Not exactly one hit when searching for user")
-    if sudoPassword in res[0][1]:
+    if 'sudoPassword' in res[0][1]:
         inldap = res[0][1]['sudoPassword']
     else:
         inldap = []
@@ -553,7 +554,7 @@ def connect_to_ldap_and_check_if_locked(DnRecord):
     if (GetAttr(Attrs[0], "userPassword").find("*LK*") != -1) \
        or GetAttr(Attrs[0], "userPassword").startswith("!"):
         raise UDNotAllowedError("This account is locked")
-    return l
+    return lc
 
 
 # Handle an [almost] arbitary change
@@ -599,7 +600,7 @@ def HandleChange(Reply, DnRecord, Key):
 
     if CommitChanges == 1 and len(SudoPasswd) > 0:  # only if we are still good to go
         try:
-            Res = FinishConfirmSudopassword(l, GetAttr(DnRecord, "uid"), Attrs, SudoPasswd)
+            Res = FinishConfirmSudopassword(lc, GetAttr(DnRecord, "uid"), Attrs, SudoPasswd)
             if Res is not None:
                 Result += Res + "\n"
         except Error, e: