diff options
author | rexxnor <rexxnor+gnunet@brief.li> | 2019-06-22 02:07:22 +0200 |
---|---|---|
committer | rexxnor <rexxnor+gnunet@brief.li> | 2019-06-22 02:07:22 +0200 |
commit | c11712c96c7e66bf21c24691f5c05cc80e1e7f53 (patch) | |
tree | 7ec3c32b5a75c0113d0631166b08f85c681d26d0 | |
parent | db545a42e300771283cac1f18c9c2626437eb657 (diff) | |
download | ascension-c11712c96c7e66bf21c24691f5c05cc80e1e7f53.tar.gz ascension-c11712c96c7e66bf21c24691f5c05cc80e1e7f53.zip |
fixed a few bugs and prepared root migration
-rw-r--r-- | ascension/ascension.py | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/ascension/ascension.py b/ascension/ascension.py index 39d5963..31f0bc8 100644 --- a/ascension/ascension.py +++ b/ascension/ascension.py | |||
@@ -92,6 +92,9 @@ class Ascender(): | |||
92 | flags: str, | 92 | flags: str, |
93 | minimum: str) -> None: | 93 | minimum: str) -> None: |
94 | self.domain = domain | 94 | self.domain = domain |
95 | # special case for root zone | ||
96 | if domain[-1] == '.' and len(domain) == 1: | ||
97 | self.domain = '@' | ||
95 | if domain[-1] == '.': | 98 | if domain[-1] == '.': |
96 | self.domain = self.domain[:-1] | 99 | self.domain = self.domain[:-1] |
97 | self.port = int(port) | 100 | self.port = int(port) |
@@ -140,7 +143,8 @@ class Ascender(): | |||
140 | :returns: Serial of the zones SOA record | 143 | :returns: Serial of the zones SOA record |
141 | """ | 144 | """ |
142 | # Makes domains better resolvable | 145 | # Makes domains better resolvable |
143 | domain = domain + "." | 146 | if not domain == "@": |
147 | domain = domain + "." | ||
144 | # SOA is different if taken directly from SOA record | 148 | # SOA is different if taken directly from SOA record |
145 | # compared to AXFR/IXFR - changed to respect this | 149 | # compared to AXFR/IXFR - changed to respect this |
146 | try: | 150 | try: |
@@ -353,7 +357,7 @@ class Ascender(): | |||
353 | '-z', zonename, | 357 | '-z', zonename, |
354 | '-n', str(label), | 358 | '-n', str(label), |
355 | ] + recordline, | 359 | ] + recordline, |
356 | ) | 360 | ) |
357 | 361 | ||
358 | if ret.returncode != 0: | 362 | if ret.returncode != 0: |
359 | logging.warning("failed adding record with name %s", | 363 | logging.warning("failed adding record with name %s", |
@@ -505,7 +509,8 @@ class Ascender(): | |||
505 | '-D', | 509 | '-D', |
506 | '-z', self.domain, | 510 | '-z', self.domain, |
507 | '-t', 'SOA', | 511 | '-t', 'SOA', |
508 | '-n', '@']) | 512 | '-n', '@'], |
513 | stderr=sp.DEVNULL) | ||
509 | serial = serial.decode() | 514 | serial = serial.decode() |
510 | except sp.CalledProcessError: | 515 | except sp.CalledProcessError: |
511 | serial = "" | 516 | serial = "" |
@@ -652,18 +657,6 @@ class Ascender(): | |||
652 | zonename, _, pkey, _, privkey = zone.split(" ") | 657 | zonename, _, pkey, _, privkey = zone.split(" ") |
653 | self.subzonedict[zonename] = (pkey, self.minimum, privkey) | 658 | self.subzonedict[zonename] = (pkey, self.minimum, privkey) |
654 | 659 | ||
655 | # Create missing zones (and add to dict) for GNS zones that are NOT DNS zones | ||
656 | # ("." is not a zone-cut in DNS, but always in GNS). | ||
657 | for name in self.zone.nodes.keys(): | ||
658 | subzones = str(name).split('.') | ||
659 | for i in range(1, len(subzones)): | ||
660 | subdomain = ".".join(subzones[i:]) | ||
661 | zonename = "%s.%s" % (subdomain, self.domain) | ||
662 | ttl = self.minimum # new record, cannot use existing one | ||
663 | if self.subzonedict.get(zonename) is None: | ||
664 | pkey, privkey = self.create_zone_and_get_pkey(zonename) | ||
665 | self.subzonedict[zonename] = (pkey, ttl, privkey) | ||
666 | |||
667 | # Check if a delegated zone is available in GNS as per NS record | 660 | # Check if a delegated zone is available in GNS as per NS record |
668 | # Adds NS records that contain "gns--pkey--" to dictionary | 661 | # Adds NS records that contain "gns--pkey--" to dictionary |
669 | nsrecords = self.zone.iterate_rdatasets(dns.rdatatype.NS) | 662 | nsrecords = self.zone.iterate_rdatasets(dns.rdatatype.NS) |
@@ -700,6 +693,19 @@ class Ascender(): | |||
700 | logging.critical("PKEY in DNS does not match PKEY in GNS for name %s", name) | 693 | logging.critical("PKEY in DNS does not match PKEY in GNS for name %s", name) |
701 | continue | 694 | continue |
702 | 695 | ||
696 | # Create missing zones (and add to dict) for GNS zones that are NOT DNS zones | ||
697 | # ("." is not a zone-cut in DNS, but always in GNS). | ||
698 | for name in self.zone.nodes.keys(): | ||
699 | subzones = str(name).split('.') | ||
700 | for i in range(1, len(subzones)): | ||
701 | subdomain = ".".join(subzones[i:]) | ||
702 | zonename = "%s.%s" % (subdomain, self.domain) | ||
703 | ttl = self.minimum # new record, cannot use existing one | ||
704 | if self.subzonedict.get(zonename) is None: | ||
705 | pkey, privkey = self.create_zone_and_get_pkey(zonename) | ||
706 | self.subzonedict[zonename] = (pkey, ttl, privkey) | ||
707 | |||
708 | |||
703 | # Generate PKEY records for all entries in subzonedict | 709 | # Generate PKEY records for all entries in subzonedict |
704 | for zone, pkeyttltuple in self.subzonedict.items(): | 710 | for zone, pkeyttltuple in self.subzonedict.items(): |
705 | pkey, ttl, _ = pkeyttltuple | 711 | pkey, ttl, _ = pkeyttltuple |