UUID_FORMAT = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
+MAX_UD_AGE = 3600*24
EmailCheck = re.compile("^([^ <>@]+@[^ ,<>@]+)(,\s*([^ <>@]+@[^ ,<>@]+))*$")
BSMTPCheck = re.compile(".*mx 0 (master)\.debian\.org\..*",re.DOTALL)
PurposeHostField = re.compile(r".*\[\[([\*\-]?[a-z0-9.\-]*)(?:\|.*)?\]\]")
-IsV6Addr = re.compile("^[a-fA-F0-9:]+$")
IsDebianHost = re.compile(ConfModule.dns_hostmatch)
isSSHFP = re.compile("^\s*IN\s+SSHFP")
DNSZone = ".debian.net"
Keyrings = ConfModule.sync_keyrings.split(":")
GitoliteSSHRestrictions = getattr(ConfModule, "gitolitesshrestrictions", None)
+GitoliteExportHosts = re.compile(getattr(ConfModule, "gitoliteexporthosts", "."))
+MX_remap = json.loads(ConfModule.MX_remap)
def prettify(elem):
"""Return a pretty-printed XML string for the Element.
Done(File, F, None)
# Generate the sudo passwd file
-def GenSSHGitolite(accounts, File):
+def GenSSHGitolite(accounts, hosts, File):
F = None
try:
OldMask = os.umask(0022)
line = Sanitize(line) + "\n"
F.write(line)
+ for dn, attrs in hosts:
+ if not 'sshRSAHostKey' in attrs: continue
+ hostname = "host-" + attrs['hostname'][0]
+ prefix = GitoliteSSHRestrictions.replace('@@USER@@', hostname)
+ for I in attrs["sshRSAHostKey"]:
+ line = "%s %s"%(prefix, I)
+ line = Sanitize(line) + "\n"
+ F.write(line)
+
# Oops, something unspeakable happened.
except:
Die(File, F, None)
raise
Done(File, F, None)
+def is_ipv6_addr(i):
+ try:
+ socket.inet_pton(socket.AF_INET6, i)
+ except socket.error:
+ return False
+ return True
+
def ExtractDNSInfo(x):
TTLprefix="\t"
DNSInfo = []
if x[1].has_key("ipHostNumber"):
for I in x[1]["ipHostNumber"]:
- if IsV6Addr.match(I) != None:
+ if is_ipv6_addr(I):
DNSInfo.append("%sIN\tAAAA\t%s" % (TTLprefix, I))
else:
DNSInfo.append("%sIN\tA\t%s" % (TTLprefix, I))
if x[1].has_key("mXRecord"):
for I in x[1]["mXRecord"]:
- DNSInfo.append("%sIN\tMX\t%s" % (TTLprefix, I))
+ if I in MX_remap:
+ for e in MX_remap[I]:
+ DNSInfo.append("%sIN\tMX\t%s" % (TTLprefix, e))
+ else:
+ DNSInfo.append("%sIN\tMX\t%s" % (TTLprefix, I))
return DNSInfo
if Host[1].has_key("ipHostNumber"):
for addr in Host[1]["ipHostNumber"]:
IPAdresses.append(addr)
- if IsV6Addr.match(addr) is None and mapped == "True":
+ if not is_ipv6_addr(addr) and mapped == "True":
IPAdresses.append("::ffff:"+addr)
return IPAdresses
GenMarkers(accounts, global_dir + "markers")
GenSSHKnown(host_attrs, global_dir + "ssh_known_hosts")
GenHosts(host_attrs, global_dir + "debianhosts")
- GenSSHGitolite(accounts, global_dir + "ssh-gitolite")
+ GenSSHGitolite(accounts, host_attrs, global_dir + "ssh-gitolite")
GenDNS(accounts, global_dir + "dns-zone")
GenZoneRecords(host_attrs, global_dir + "dns-sshfp")
for host in host_attrs:
if not "hostname" in host[1]:
continue
- generate_host(host, global_dir, accounts, ssh_userkeys)
+ generate_host(host, global_dir, accounts, host_attrs, ssh_userkeys)
-def generate_host(host, global_dir, all_accounts, ssh_userkeys):
+def generate_host(host, global_dir, all_accounts, all_hosts, ssh_userkeys):
current_host = host[1]['hostname'][0]
OutDir = global_dir + current_host + '/'
if not os.path.isdir(OutDir):
if 'GITOLITE' in ExtraList:
DoLink(global_dir, OutDir, "ssh-gitolite")
+ if 'exportOptions' in host[1]:
+ for entry in host[1]['exportOptions']:
+ v = entry.split('=',1)
+ if v[0] != 'GITOLITE' or len(v) != 2: continue
+ gitolite_accounts = filter(lambda x: IsInGroup(x, [v[1]], current_host), all_accounts)
+ gitolite_hosts = filter(lambda x: GitoliteExportHosts.match(x[1]["hostname"][0]), all_hosts)
+ GenSSHGitolite(gitolite_accounts, gitolite_hosts, OutDir + "ssh-gitolite-%s"%(v[1],))
if 'WEB-PASSWORDS' in ExtraList:
DoLink(global_dir, OutDir, "web-passwords")
if mt > krmod:
krmod = mt
- return krmod
+ return int(krmod)
def getLastBuildTime(gdir):
cache_last_ldap_mod = 0
cache_last_unix_mod = 0
+ cache_last_run = 0
try:
fd = open(os.path.join(gdir, "last_update.trace"), "r")
try:
cache_last_ldap_mod = cache_last_mod[0]
cache_last_unix_mod = int(cache_last_mod[1])
+ cache_last_run = int(cache_last_mod[2])
except IndexError, ValueError:
pass
fd.close()
else:
raise e
- return (cache_last_ldap_mod, cache_last_unix_mod)
+ return (cache_last_ldap_mod, cache_last_unix_mod, cache_last_run)
def ud_generate():
parser = optparse.OptionParser()
time_started = int(time.time())
ldap_last_mod = getLastLDAPChangeTime(l)
unix_last_mod = getLastKeyringChangeTime()
- cache_last_ldap_mod, cache_last_unix_mod = getLastBuildTime(generate_dir)
+ cache_last_ldap_mod, cache_last_unix_mod, last_run = getLastBuildTime(generate_dir)
- need_update = (ldap_last_mod > cache_last_ldap_mod) or (unix_last_mod > cache_last_unix_mod)
+ need_update = (ldap_last_mod > cache_last_ldap_mod) or (unix_last_mod > cache_last_unix_mod) or (time_started - last_run > MAX_UD_AGE)
if not options.force and not need_update:
fd = open(os.path.join(generate_dir, "last_update.trace"), "w")
- fd.write("%s\n%s\n" % (ldap_last_mod, time_started))
+ fd.write("%s\n%s\n%s\n" % (ldap_last_mod, unix_last_mod, last_run))
fd.close()
sys.exit(0)
tracefd = open(os.path.join(generate_dir, "last_update.trace"), "w")
generate_all(generate_dir, l)
- tracefd.write("%s\n%s\n" % (ldap_last_mod, time_started))
+ tracefd.write("%s\n%s\n%s\n" % (ldap_last_mod, unix_last_mod, time_started))
tracefd.close()