Add dnsTTL host attribute to override the zone default TTL for A and AAAA records...
[mirror/userdir-ldap.git] / ud-generate
index 334af5d..795816c 100755 (executable)
@@ -823,14 +823,17 @@ def GenDNS(File):
 
 def ExtractDNSInfo(x):
 
-   DNSInfo = []
+   TTLprefix="\t"
+   if 'dnsTTL' in x[1]:
+      TTLprefix="%s\t"%(x[1]["dnsTTL"][0])
 
+   DNSInfo = []
    if x[1].has_key("ipHostNumber"):
       for I in x[1]["ipHostNumber"]:
          if IsV6Addr.match(I) != None:
-            DNSInfo.append("IN\tAAAA\t%s" % (I))
+            DNSInfo.append("%sIN\tAAAA\t%s" % (TTLprefix, I))
          else:
-            DNSInfo.append("IN\tA\t%s" % (I))
+            DNSInfo.append("%sIN\tA\t%s" % (TTLprefix, I))
 
    Host = GetAttr(x, "hostname")
    Arch = GetAttr(x, "architecture")
@@ -845,16 +848,16 @@ def ExtractDNSInfo(x):
       if Algorithm == None:
          continue
       Fingerprint = sha.new(base64.decodestring(Split[1])).hexdigest()
-      DNSInfo.append("IN\tSSHFP\t%u 1 %s" % (Algorithm, Fingerprint))
+      DNSInfo.append("%sIN\tSSHFP\t%u 1 %s" % (TTLprefix, Algorithm, Fingerprint))
 
    Mach = ""
    if x[1].has_key("machine"):
       Mach = " " + GetAttr(x, "machine")
-   DNSInfo.append("IN\tHINFO\t\"%s%s\" \"%s\"" % (Arch, Mach, "Debian GNU/Linux"))
+   DNSInfo.append("%sIN\tHINFO\t\"%s%s\" \"%s\"" % (TTLprefix, Arch, Mach, "Debian GNU/Linux"))
 
    if x[1].has_key("mXRecord"):
       for I in x[1]["mXRecord"]:
-         DNSInfo.append("IN\tMX\t%s" % (I))
+         DNSInfo.append("%sIN\tMX\t%s" % (TTLprefix, I))
 
    return DNSInfo
 
@@ -986,7 +989,10 @@ def GenSSHKnown(File, mode=None):
      
          for I in x[1]["sshRSAHostKey"]:
             if mode and mode == 'authorized_keys':
-               Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,from="%s" %s' % (Host, ",".join(HostToIP(x)), I)
+               hosts = HostToIP(x)
+               if 'sshdistAuthKeysHost' in x[1]:
+                  hosts += x[1]['sshdistAuthKeysHost']
+               Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,from="%s" %s' % (Host, ",".join(hosts), I)
                #Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding %s' % (Host,I)
             else:
                Line = "%s %s" %(",".join(HostNames + HostToIP(x, False)), I)
@@ -1015,6 +1021,9 @@ def GenHosts(File):
          if IsDebianHost.match(GetAttr(x, "hostname")) is None:
             continue
 
+         if not 'ipHostNumber' in x[1]:
+            continue
+
          addrs = x[1]["ipHostNumber"]
          for addr in addrs:
             if addr not in seen:
@@ -1046,6 +1055,8 @@ Attrs = l.search_s(BaseDn, ldap.SCOPE_ONELEVEL, "gid=*",\
 
 # Generate the SubGroupMap and GroupIDMap
 for x in Attrs:
+   if x[1].has_key("accountStatus") and x[1]['accountStatus'] == "disabled":
+      continue
    if x[1].has_key("gidNumber") == 0:
       continue
    GroupIDMap[x[1]["gid"][0]] = int(x[1]["gidNumber"][0])
@@ -1072,7 +1083,7 @@ PasswdAttrs.sort(lambda x, y: cmp((GetAttr(x, "uid")).lower(), (GetAttr(y, "uid"
 # Fetch all the hosts
 HostAttrs    = l.search_s(HostBaseDn, ldap.SCOPE_ONELEVEL, "objectClass=debianServer",\
                 ["hostname", "sshRSAHostKey", "purpose", "allowedGroups", "exportOptions",\
-                 "mXRecord", "ipHostNumber", "machine", "architecture"])
+                 "mXRecord", "ipHostNumber", "dnsTTL", "machine", "architecture"])
 
 if HostAttrs == None:
    raise UDEmptyList, "No Hosts"