X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-dns.git/blobdiff_plain/95af4d43b213c0860423cb0b1dc29cedfed04ea5..refs/heads/precise-prod:/invirt-dns diff --git a/invirt-dns b/invirt-dns index 7a39f0f..188d1ce 100755 --- a/invirt-dns +++ b/invirt-dns @@ -16,6 +16,7 @@ import psycopg2 import sqlalchemy import time import re +import sys class DatabaseAuthority(common.ResolverBase): """An Authority that is loaded from a file.""" @@ -135,6 +136,7 @@ class DatabaseAuthority(common.ResolverBase): if value: if other: ip = value.other_ip + action = value.other_action else: ip = value.ip else: @@ -142,6 +144,7 @@ class DatabaseAuthority(common.ResolverBase): if value: if other: ip = value.nics[0].other_ip + action = value.nics[0].other_action else: ip = value.nics[0].ip else: @@ -152,7 +155,11 @@ class DatabaseAuthority(common.ResolverBase): record = dns.Record_A(ip, ttl) results.append(dns.RRHeader(name, dns.A, dns.IN, ttl, record, auth=True)) - elif type == dns.SOA: + if other and type in (dns.TXT, dns.ALL_RECORDS): + record = dns.Record_TXT(action if action else '', ttl=ttl) + results.append(dns.RRHeader(name, dns.TXT, dns.IN, + ttl, record, auth=True)) + if type == dns.SOA: results.append(dns.RRHeader(domain, dns.SOA, dns.IN, ttl, self.soa, auth=True)) @@ -208,20 +215,37 @@ class DelegatingQuotingBindAuthority(authority.BindAuthority): L.append(split_line) return filter(None, L) + # See https://twistedmatrix.com/documents/13.1.0/api/twisted.internet.defer.html#inlineCallbacks + @defer.inlineCallbacks def _lookup(self, name, cls, type, timeout = None): - maybeDelegate = False - deferredResult = authority.BindAuthority._lookup(self, name, cls, - type, timeout) - # If we didn't find an exact match for the name we were seeking, - # check if it's within a subdomain we're supposed to delegate to - # some other DNS server. - while (isinstance(deferredResult.result, failure.Failure) - and '.' in name): - maybeDelegate = True - name = name[name.find('.') + 1 :] - deferredResult = authority.BindAuthority._lookup(self, name, cls, - dns.NS, timeout) - return deferredResult + try: + result = yield authority.BindAuthority._lookup(self, name, cls, + type, timeout) + defer.returnValue(result) + except Exception as e: + # XXX: Twisted returns DomainError even if it is + # authoritative for the domain because our SOA record + # incorrectly contains (origin + "." + origin) + if not isinstance(e, (dns.DomainError, dns.AuthoritativeDomainError)): + sys.stderr.write("while looking up '%s', got: %s\n" % (name, e)) + + # If we didn't find an exact match for the name we were + # seeking, check if it's within a subdomain we're supposed + # to delegate to some other DNS server. + while '.' in name: + _, name = name.split('.', 1) + try: + # BindAuthority puts the NS in the authority + # section automatically for us, so just return + # it. We override the type to NS. + result = yield authority.BindAuthority._lookup(self, name, cls, + dns.NS, timeout) + defer.returnValue(result) + except Exception: # Should be one of (dns.DomainError, dns.AuthoritativeDomainError) + pass + # We didn't find a delegation, so return the original + # NXDOMAIN. + raise class TypeLenientResolverChain(resolve.ResolverChain): """ @@ -250,6 +274,9 @@ if '__main__' == __name__: r = DelegatingQuotingBindAuthority(zone) # This sucks, but if I want a generic zone file, I have to # reload the information by hand + # XXX: This causes our SOA record to contain + # (origin + "." + origin) + # As a result the resolver never believes it is authoritative. r.origin = origin lines = open(zone).readlines() lines = r.collapseContinuations(r.stripComments(lines))