self.cmd_start = self.default_cmd_start
self.cmd_restart = self.default_cmd_restart
+ self.named_keys = {}
+
self.zone_tsig_key = None
self.files2replace = {}
"please use 'local' or 'public'"))
self.exit(1)
+ cmd_namedcheckconf = self.get_command('named-checkconf')
+ if not cmd_namedcheckconf:
+ self.exit(1)
+ self.cmd_checkconf = cmd_namedcheckconf
+
# -------------------------------------------------------------------------
def _run(self):
LOG.info(_("Starting: {}").format(
datetime.datetime.now(local_tz).strftime('%Y-%m-%d %H:%M:%S %Z')))
+ self.get_named_keys()
+
try:
self.pidfile.create()
except PidFileError as e:
if self.verbose > 1:
LOG.debug(_("Temporary zones conf: {!r}").format(self.temp_zones_cfg_file))
+ # -------------------------------------------------------------------------
+ def get_named_keys(self):
+
+ LOG.info(_("Trying to get all keys from named.conf ..."))
+
+ LOG.info(_("Checking syntax correctness of named.conf ..."))
+ cmd = shlex.split(self.cmd_checkconf)
+ cmd.append('-p')
+
+ cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmd))
+ LOG.debug(_("Executing: {}").format(cmd_str))
+
+ result = self.run(
+ cmd, stdout=PIPE, stderr=PIPE, timeout=10, check=True, may_simulate=False)
+ if self.verbose > 1:
+ LOG.debug(_("Result:") + '\n' + str(result))
+
+ config = result.stdout
+
+ key_pattern = r'^\s*key\s+("[^"]+"|\S+)\s+\{([^\}]+\}\s*;'
+ re_quotes = re.compile(r'^\s*"([^"]+)"\s*$')
+ re_key = re.compile(key_pattern, re.IGNORECASE | re.MULTILINE | re.DOTALL)
+
+ for match in re_key.finditer(config):
+ match_quotes = re_quotes.match(match[1])
+ if match_quotes:
+ key_name = match_quotes[1]
+ else:
+ key_name = match[1]
+ key_data = match[2].strip()
+ if self.verbose > 1:
+ LOG.debug("Found key {!r}:".format(key_name) + '\n' + key_data)
+
# -------------------------------------------------------------------------
def generate_slave_cfg_file(self):