]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Support <class> <ttl> <type> in zonefiles [#942].
authorBob Halley <halley@dnspython.org>
Fri, 9 Jun 2023 21:56:29 +0000 (14:56 -0700)
committerBob Halley <halley@dnspython.org>
Fri, 9 Jun 2023 21:56:29 +0000 (14:56 -0700)
dns/zonefile.py
tests/test_zone.py

index 48bedadb16344d35fe01efdcdbb43be5760adca6..563722e66f1e2f1255940a2d756d4c2ba0eaaa5c 100644 (file)
@@ -191,10 +191,6 @@ class Reader:
                 self.last_ttl_known = True
                 token = None
             except dns.ttl.BadTTL:
-                if self.default_ttl_known:
-                    ttl = self.default_ttl
-                elif self.last_ttl_known:
-                    ttl = self.last_ttl
                 self.tok.unget(token)
 
         # Class
@@ -212,6 +208,22 @@ class Reader:
             if rdclass != self.zone_rdclass:
                 raise dns.exception.SyntaxError("RR class is not zone's class")
 
+        if ttl is None:
+            # support for <class> <ttl> <type> syntax
+            token = self._get_identifier()
+            ttl = None
+            try:
+                ttl = dns.ttl.from_text(token.value)
+                self.last_ttl = ttl
+                self.last_ttl_known = True
+                token = None
+            except dns.ttl.BadTTL:
+                if self.default_ttl_known:
+                    ttl = self.default_ttl
+                elif self.last_ttl_known:
+                    ttl = self.last_ttl
+                self.tok.unget(token)
+
         # Type
         if self.force_rdtype is not None:
             rdtype = self.force_rdtype
index 78736567e6207185aafec3d6f59dd661f6c3a22e..eca81e017f43d1beda72c3d93e4937d3d1c0a58b 100644 (file)
@@ -58,6 +58,14 @@ ns1 3600 IN A 10.0.0.1
 ns2 3600 IN A 10.0.0.2
 """
 
+example_text_output_class_before_ttl = """@ IN 3600 SOA foo bar 1 2 3 4 5
+@ 3600 NS ns1 ; no class
+@ NS ns2 ; no class or TTL, TTL inferred from prior record
+bar.foo IN 300 MX 0 blaz.foo
+ns1 IN 3600 A 10.0.0.1
+ns2 IN 3600 A 10.0.0.2
+"""
+
 example_generate = """@ 3600 IN SOA foo bar 1 2 3 4 5
 @ 3600 IN NS ns
 $GENERATE 9-12       a.$         A 10.0.0.$
@@ -503,6 +511,13 @@ class ZoneTestCase(unittest.TestCase):
         z2 = dns.zone.from_text(example_text_output, "example.", relativize=True)
         self.assertEqual(z1, z2)
 
+    def testEqualClassBeforeTTL(self):
+        z1 = dns.zone.from_text(
+            example_text_output_class_before_ttl, "example.", relativize=True
+        )
+        z2 = dns.zone.from_text(example_text_output, "example.", relativize=True)
+        self.assertEqual(z1, z2)
+
     def testNotEqual1(self):
         z1 = dns.zone.from_text(example_text, "example.", relativize=True)
         z2 = dns.zone.from_text(something_quite_similar, "example.", relativize=True)