From 9b6f9859d1c7b8c3cc4ee05fe268242a06621a80 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Fri, 26 Sep 2014 13:37:09 +0000 Subject: [PATCH] dns_update: assume DKIM is present --- management/dns_update.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/management/dns_update.py b/management/dns_update.py index 0a4ab7a0..dfd9ddb9 100755 --- a/management/dns_update.py +++ b/management/dns_update.py @@ -195,7 +195,7 @@ def build_zone(domain, all_domains, additional_records, env, is_zone=True): if has_rec(qname, rtype): continue records.append((qname, rtype, value, "(Set by user.)")) - # Add defaults if not overridden by the user's custom settings. + # Add defaults if not overridden by the user's custom settings (and not otherwise configured). defaults = [ (None, "A", env["PUBLIC_IP"], "Required. May have a different value. Sets the IP address that %s resolves to for web hosting and other services besides mail. The A record must be present but its value does not affect mail delivery." % domain), ("www", "A", env["PUBLIC_IP"], "Optional. Sets the IP address that www.%s resolves to, e.g. for web hosting." % domain), @@ -208,17 +208,15 @@ def build_zone(domain, all_domains, additional_records, env, is_zone=True): if not has_rec(qname, rtype): records.append((qname, rtype, value, explanation)) - # If OpenDKIM is in use.. + # Append the DKIM TXT record to the zone as generated by OpenDKIM. opendkim_record_file = os.path.join(env['STORAGE_ROOT'], 'mail/dkim/mail.txt') - if os.path.exists(opendkim_record_file): - # Append the DKIM TXT record to the zone as generated by OpenDKIM, after string formatting above. - with open(opendkim_record_file) as orf: - m = re.match(r'(\S+)\s+IN\s+TXT\s+\( "([^"]+)"\s+"([^"]+)"\s*\)', orf.read(), re.S) - val = m.group(2) + m.group(3) - records.append((m.group(1), "TXT", val, "Recommended. Provides a way for recipients to verify that this machine sent @%s mail." % domain)) + with open(opendkim_record_file) as orf: + m = re.match(r'(\S+)\s+IN\s+TXT\s+\( "([^"]+)"\s+"([^"]+)"\s*\)', orf.read(), re.S) + val = m.group(2) + m.group(3) + records.append((m.group(1), "TXT", val, "Recommended. Provides a way for recipients to verify that this machine sent @%s mail." % domain)) - # Append a DMARC record. - records.append(("_dmarc", "TXT", 'v=DMARC1; p=quarantine', "Optional. Specifies that mail that does not originate from the box but claims to be from @%s is suspect and should be quarantined by the recipient's mail system." % domain)) + # Append a DMARC record. + records.append(("_dmarc", "TXT", 'v=DMARC1; p=quarantine', "Optional. Specifies that mail that does not originate from the box but claims to be from @%s is suspect and should be quarantined by the recipient's mail system." % domain)) # Sort the records. The None records *must* go first in the nsd zone file. Otherwise it doesn't matter. records.sort(key = lambda rec : list(reversed(rec[0].split(".")) if rec[0] is not None else ""))