Workaround a bug in Twisted's zone file parsing. precise-prod quentin 0.0.21
authorQuentin Smith <quentin@mit.edu>
Tue, 26 Nov 2019 03:26:58 +0000 (22:26 -0500)
committerQuentin Smith <quentin@mit.edu>
Tue, 26 Nov 2019 04:18:05 +0000 (23:18 -0500)
debian/changelog
invirt-dns

index ed218aa..988f4a1 100644 (file)
@@ -1,3 +1,9 @@
+invirt-dns (0.0.21) unstable; urgency=low
+
+  * Workaround a bug in Twisted's zone file parsing.
+
+ -- Quentin Smith <quentin@mit.edu>  Mon, 25 Nov 2019 22:26:48 -0500
+
 invirt-dns (0.0.20) unstable; urgency=low
 
   * Rewrite _lookup to use inlineCallbacks for readability, in the process
index c9ce43e..188d1ce 100755 (executable)
@@ -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."""
@@ -221,7 +222,13 @@ class DelegatingQuotingBindAuthority(authority.BindAuthority):
             result = yield authority.BindAuthority._lookup(self, name, cls,
                                                            type, timeout)
             defer.returnValue(result)
-        except dns.AuthoritativeDomainError:
+        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.
@@ -234,7 +241,7 @@ class DelegatingQuotingBindAuthority(authority.BindAuthority):
                     result = yield authority.BindAuthority._lookup(self, name, cls,
                                                                    dns.NS, timeout)
                     defer.returnValue(result)
-                except (dns.DomainError, dns.AuthoritativeDomainError):
+                except Exception: # Should be one of (dns.DomainError, dns.AuthoritativeDomainError)
                     pass
             # We didn't find a delegation, so return the original
             # NXDOMAIN.
@@ -267,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))