X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=ud-generate;h=674cc60ab210728d4218233e72dcf28b446e0ae1;hb=701528fc8153f150dae52787cca172d8ab4f4bfb;hp=d556f8b325a67718142b5c7a8f1ed46d2430f769;hpb=3b19770f41e7c4bf7882c9ae3c1e41025bcf8ea9;p=mirror%2Fuserdir-ldap.git diff --git a/ud-generate b/ud-generate index d556f8b..674cc60 100755 --- a/ud-generate +++ b/ud-generate @@ -10,6 +10,10 @@ GroupIDMap = {}; Allowed = None; CurrentHost = ""; +EmailCheck = re.compile("^([^ <>@]+@[^ ,<>@]+)?$"); +BSMTPCheck = re.compile(".*mx 0 klecker\.debian\.org\..*",re.DOTALL); +DNSZone = ".debian.net" + def Sanitize(Str): return string.translate(Str,string.maketrans("\n\r\t","$$$")); @@ -254,6 +258,9 @@ def GenForward(l,File): if len(GetAttr(x,"emailforward")) > 200: continue; + # Check the forwarding address + if EmailCheck.match(GetAttr(x,"emailforward")) == None: + continue; Line = "%s: %s" % (GetAttr(x,"uid"),GetAttr(x,"emailforward")); Line = Sanitize(Line) + "\n"; F.write(Line); @@ -286,6 +293,10 @@ def GenAllForward(l,File): if len(Forward) > 200: continue; + # Check the forwarding address + if EmailCheck.match(Forward) == None: + continue; + User = GetAttr(x,"uid"); Fdb.write("+%d,%d:%s->%s\n"%(len(User),len(Forward),User,Forward)); Fdb.write("\n"); @@ -370,13 +381,13 @@ def GenPrivate(l,File): Done(File,F,Fdb); # Generate the DNS Zone file -def GenDNS(l,File): +def GenDNS(l,File,BSMTPFile,HomePrefix): F = None; - Fdb = None; + FB = None; try: F = open(File + ".tmp","w"); - Fdb = None; - + FB = open(BSMTPFile + ".tmp","w"); + # Fetch all the users global PasswdAttrs; if PasswdAttrs == None: @@ -397,8 +408,14 @@ def GenDNS(l,File): Line = string.join(Split," ") + "\n"; F.write(Line); - # Write some identication information - if string.lower(Split[2]) != "cname": + Host = Split[0] + DNSZone; + if BSMTPCheck.match(Line) != None: + F.write("; Has BSMTP\n"); + FB.write("%s: user=%s group=Debian file=%s%s/bsmtp/%s\n"%(Host, + GetAttr(x,"uid"),HomePrefix,GetAttr(x,"uid"),Host)); + + # Write some identification information + if string.lower(Split[2]) == "a": Line = "%s IN TXT \"%s\"\n"%(Split[0],EmailAddress(x)); for y in x[1]["keyfingerprint"]: Line = Line + "%s IN TXT \"PGP %s\"\n"%(Split[0],FormatPGPKey(y)); @@ -409,13 +426,16 @@ def GenDNS(l,File): F.write("\n"); except: + F.write("; Errors\n"); pass; # Oops, something unspeakable happened. except: - Die(File,F,Fdb); + Die(File,F,None); + Die(BSMTPFile,FB,None); raise; - Done(File,F,Fdb); + Done(File,F,None); + Done(BSMTPFile,FB,None); # Connect to the ldap server l = ldap.open(LDAPServer); @@ -455,7 +475,6 @@ GlobalDir = GenerateDir+"/"; GenSSHShadow(l,GlobalDir+"ssh-rsa-shadow"); GenAllForward(l,GlobalDir+"mail-forward.cdb"); GenMarkers(l,GlobalDir+"markers"); -GenDNS(l,GlobalDir+"dns-zone"); GenPrivate(l,GlobalDir+"debian-private"); # Compatibility. @@ -507,7 +526,7 @@ while(1): DoLink(GlobalDir,OutDir,"forward-alias"); if ExtraList.has_key("[DNS]"): - DoLink(GlobalDir,OutDir,"dns-zone"); + GenDNS(l,OutDir+"dns-zone",OutDir+"bsmtp",Split[1]); if ExtraList.has_key("[PRIVATE]"): DoLink(GlobalDir,OutDir,"debian-private");