Blame SOURCES/ntp2chrony.py

dabfaa
#!/usr/bin/python
dabfaa
#
dabfaa
# Convert ntp configuration to chrony
dabfaa
#
dabfaa
# Copyright (C) 2018  Miroslav Lichvar <mlichvar@redhat.com>
dabfaa
#
dabfaa
# This program is free software; you can redistribute it and/or modify
dabfaa
# it under the terms of the GNU General Public License as published by
dabfaa
# the Free Software Foundation; either version 2 of the License, or
dabfaa
# (at your option) any later version.
dabfaa
#
dabfaa
# This program is distributed in the hope that it will be useful,
dabfaa
# but WITHOUT ANY WARRANTY; without even the implied warranty of
dabfaa
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dabfaa
# GNU General Public License for more details.
dabfaa
#
dabfaa
# You should have received a copy of the GNU General Public License
dabfaa
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
dabfaa
dabfaa
dabfaa
import argparse
dabfaa
import ipaddress
dabfaa
import os
dabfaa
import os.path
dabfaa
import re
dabfaa
import subprocess
dabfaa
import sys
dabfaa
dabfaa
# python2 compatibility hacks
dabfaa
if sys.version_info[0] < 3:
dabfaa
    from io import open
dabfaa
    reload(sys)
dabfaa
    sys.setdefaultencoding("utf-8")
dabfaa
dabfaa
class NtpConfiguration(object):
dabfaa
    def __init__(self, root_dir, ntp_conf, step_tickers, verbose):
dabfaa
        self.root_dir = root_dir if root_dir != "/" else ""
dabfaa
        self.ntp_conf_path = ntp_conf
dabfaa
        self.step_tickers_path = step_tickers
dabfaa
        self.verbose = verbose
dabfaa
dabfaa
        self.enabled_services = set()
dabfaa
        self.step_tickers = []
dabfaa
        self.time_sources = []
dabfaa
        self.fudges = {}
dabfaa
        self.restrictions = {
dabfaa
                # Built-in defaults
dabfaa
                ipaddress.ip_network(u"0.0.0.0/0"): set(),
dabfaa
                ipaddress.ip_network(u"::/0"): set(),
dabfaa
        }
dabfaa
        self.keyfile = ""
dabfaa
        self.keys = []
dabfaa
        self.trusted_keys = []
dabfaa
        self.driftfile = ""
dabfaa
        self.statistics = []
dabfaa
        self.leapfile = ""
dabfaa
        self.tos_options = []
dabfaa
        self.ignored_directives = set()
dabfaa
        self.ignored_lines = []
dabfaa
dabfaa
        #self.detect_enabled_services()
dabfaa
        self.parse_step_tickers()
dabfaa
        self.parse_ntp_conf()
dabfaa
dabfaa
    def detect_enabled_services(self):
dabfaa
        for service in ["ntpdate", "ntpd", "ntp-wait"]:
dabfaa
            if os.path.islink("{}/etc/systemd/system/multi-user.target.wants/{}.service"
dabfaa
                    .format(self.root_dir, service)):
dabfaa
                self.enabled_services.add(service)
dabfaa
        if self.verbose > 0:
dabfaa
            print("Enabled services found in /etc/systemd/system: " +
dabfaa
                    " ".join(self.enabled_services))
dabfaa
dabfaa
    def parse_step_tickers(self):
dabfaa
        if not self.step_tickers_path:
dabfaa
            return
dabfaa
dabfaa
        path = self.root_dir + self.step_tickers_path
dabfaa
        if not os.path.isfile(path):
dabfaa
            if self.verbose > 0:
dabfaa
                print("Missing " + path)
dabfaa
            return
dabfaa
dabfaa
        with open(path, encoding="latin-1") as f:
dabfaa
            for line in f:
dabfaa
                line = line[:line.find('#')]
dabfaa
dabfaa
                words = line.split()
dabfaa
dabfaa
                if not words:
dabfaa
                    continue
dabfaa
dabfaa
                self.step_tickers.extend(words)
dabfaa
dabfaa
    def parse_ntp_conf(self, path=None):
dabfaa
        if path is None:
dabfaa
            path = self.root_dir + self.ntp_conf_path
dabfaa
dabfaa
        with open(path, encoding="latin-1") as f:
dabfaa
            if self.verbose > 0:
dabfaa
                print("Reading " + path)
dabfaa
dabfaa
            for line in f:
dabfaa
                line = line[:line.find('#')]
dabfaa
dabfaa
                words = line.split()
dabfaa
dabfaa
                if not words:
dabfaa
                    continue
dabfaa
dabfaa
                if not self.parse_directive(words):
dabfaa
                    self.ignored_lines.append(line)
dabfaa
dabfaa
    def parse_directive(self, words):
dabfaa
        name = words.pop(0)
dabfaa
        if name.startswith("logconfig"):
dabfaa
            name = "logconfig"
dabfaa
dabfaa
        if words:
dabfaa
            if name in ["server", "peer", "pool"]:
dabfaa
                return self.parse_source(name, words)
dabfaa
            elif name == "fudge":
dabfaa
                return self.parse_fudge(words)
dabfaa
            elif name == "restrict":
dabfaa
                return self.parse_restrict(words)
dabfaa
            elif name == "tos":
dabfaa
                return self.parse_tos(words)
dabfaa
            elif name == "includefile":
dabfaa
                return self.parse_includefile(words)
dabfaa
            elif name == "keys":
dabfaa
                return self.parse_keys(words)
dabfaa
            elif name == "trustedkey":
dabfaa
                return self.parse_trustedkey(words)
dabfaa
            elif name == "driftfile":
dabfaa
                self.driftfile = words[0]
dabfaa
            elif name == "statistics":
dabfaa
                self.statistics = words
dabfaa
            elif name == "leapfile":
dabfaa
                self.leapfile = words[0]
dabfaa
            else:
dabfaa
                self.ignored_directives.add(name)
dabfaa
                return False
dabfaa
        else:
dabfaa
            self.ignored_directives.add(name)
dabfaa
            return False
dabfaa
dabfaa
        return True
dabfaa
dabfaa
    def parse_source(self, type, words):
dabfaa
        ipv4_only = False
dabfaa
        ipv6_only = False
dabfaa
        source = {
dabfaa
                "type": type,
dabfaa
                "options": []
dabfaa
        }
dabfaa
dabfaa
        if words[0] == "-4":
dabfaa
            ipv4_only = True
dabfaa
            words.pop(0)
dabfaa
        elif words[0] == "-6":
dabfaa
            ipv6_only = True
dabfaa
            words.pop(0)
dabfaa
dabfaa
        if not words:
dabfaa
            return False
dabfaa
dabfaa
        source["address"] = words.pop(0)
dabfaa
dabfaa
        # Check if -4/-6 corresponds to the address and ignore hostnames
dabfaa
        if ipv4_only or ipv6_only:
dabfaa
            try:
dabfaa
                version = ipaddress.ip_address(source["address"]).version
dabfaa
                if (ipv4_only and version != 4) or (ipv6_only and version != 6):
dabfaa
                    return False
dabfaa
            except ValueError:
dabfaa
                return False
dabfaa
dabfaa
        if source["address"].startswith("127.127."):
dabfaa
            if not source["address"].startswith("127.127.1."):
dabfaa
                # Ignore non-LOCAL refclocks
dabfaa
                return False
dabfaa
dabfaa
        while words:
dabfaa
            if len(words) >= 2 and words[0] in ["minpoll", "maxpoll", "version", "key"]:
dabfaa
                source["options"].append((words[0], words[1]))
dabfaa
                words = words[2:]
dabfaa
            elif words[0] in ["burst", "iburst", "noselect", "prefer", "true", "xleave"]:
dabfaa
                source["options"].append((words[0],))
dabfaa
                words.pop(0)
dabfaa
            else:
dabfaa
                return False
dabfaa
dabfaa
        self.time_sources.append(source)
dabfaa
        return True
dabfaa
dabfaa
    def parse_fudge(self, words):
dabfaa
        address = words.pop(0)
dabfaa
        options = {}
dabfaa
dabfaa
        while words:
dabfaa
            if len(words) >= 2:
dabfaa
                options[words[0]] = words[1]
dabfaa
                words = words[2:]
dabfaa
            else:
dabfaa
                return False
dabfaa
dabfaa
        self.fudges[address] = options
dabfaa
        return True
dabfaa
dabfaa
    def parse_restrict(self, words):
dabfaa
        ipv4_only = False
dabfaa
        ipv6_only = False
dabfaa
        flags = set()
dabfaa
        mask = ""
dabfaa
dabfaa
        if words[0] == "-4":
dabfaa
            ipv4_only = True
dabfaa
            words.pop(0)
dabfaa
        elif words[0] == "-6":
dabfaa
            ipv6_only = True
dabfaa
            words.pop(0)
dabfaa
dabfaa
        if not words:
dabfaa
            return False
dabfaa
dabfaa
        address = words.pop(0)
dabfaa
dabfaa
        while words:
dabfaa
            if len(words) >= 2 and words[0] == "mask":
dabfaa
                mask = words[1]
dabfaa
                words = words[2:]
dabfaa
            else:
dabfaa
                if words[0] not in ["kod", "nomodify", "notrap", "nopeer", "noquery",
dabfaa
                                    "limited", "ignore", "noserve"]:
dabfaa
                    return False
dabfaa
                flags.add(words[0])
dabfaa
                words.pop(0)
dabfaa
dabfaa
        # Convert to IP network(s), ignoring restrictions with hostnames
dabfaa
        networks = []
dabfaa
        if address == "default" and not mask:
dabfaa
            if not ipv6_only:
dabfaa
                networks.append(ipaddress.ip_network(u"0.0.0.0/0"))
dabfaa
            if not ipv4_only:
dabfaa
                networks.append(ipaddress.ip_network(u"::/0"))
dabfaa
        else:
dabfaa
            try:
dabfaa
                if mask:
dabfaa
                    networks.append(ipaddress.ip_network(u"{}/{}".format(address, mask)))
dabfaa
                else:
dabfaa
                    networks.append(ipaddress.ip_network(address))
dabfaa
            except ValueError:
dabfaa
                return False
dabfaa
dabfaa
            if (ipv4_only and networks[-1].version != 4) or \
dabfaa
                    (ipv6_only and networks[-1].version != 6):
dabfaa
                return False
dabfaa
dabfaa
        for network in networks:
dabfaa
            self.restrictions[network] = flags
dabfaa
dabfaa
        return True
dabfaa
dabfaa
    def parse_tos(self, words):
dabfaa
        options = []
dabfaa
        while words:
dabfaa
            if len(words) >= 2 and words[0] in ["minsane", "maxdist", "orphan"]:
dabfaa
                options.append((words[0], words[1]))
dabfaa
                words = words[2:]
dabfaa
            else:
dabfaa
                return False
dabfaa
dabfaa
        self.tos_options.extend(options)
dabfaa
dabfaa
        return True
dabfaa
dabfaa
    def parse_includefile(self, words):
dabfaa
        path = self.root_dir + words[0]
dabfaa
        if not os.path.isfile(path):
dabfaa
            return False
dabfaa
dabfaa
        self.parse_ntp_conf(path)
dabfaa
        return True
dabfaa
dabfaa
    def parse_keys(self, words):
dabfaa
        keyfile = words[0]
dabfaa
        path = self.root_dir + keyfile
dabfaa
        if not os.path.isfile(path):
dabfaa
            if self.verbose > 0:
dabfaa
                print("Missing file " + path)
dabfaa
            return False
dabfaa
dabfaa
        with open(path, encoding="latin-1") as f:
dabfaa
            if self.verbose > 0:
dabfaa
                print("Reading " + path)
dabfaa
            keys = []
dabfaa
            for line in f:
dabfaa
                words = line.split()
dabfaa
                if len(words) < 3 or not words[0].isdigit():
dabfaa
                    continue
dabfaa
                keys.append((int(words[0]), words[1], words[2]))
dabfaa
dabfaa
            self.keyfile = keyfile
dabfaa
            self.keys = keys
dabfaa
dabfaa
        return True
dabfaa
dabfaa
    def parse_trustedkey(self, words):
dabfaa
        key_ranges = []
dabfaa
        for word in words:
dabfaa
            if word.isdigit():
dabfaa
                key_ranges.append((int(word), int(word)))
dabfaa
            elif re.match("^[0-9]+-[0-9]+$", word):
dabfaa
                first, last = word.split("-")
dabfaa
                key_ranges.append((int(first), int(last)))
dabfaa
            else:
dabfaa
                return False
dabfaa
dabfaa
        self.trusted_keys = key_ranges
dabfaa
        return True
dabfaa
dabfaa
    def write_chrony_configuration(self, chrony_conf_path, chrony_keys_path,
dabfaa
                                   dry_run=False, backup=False):
dabfaa
        chrony_conf = self.get_chrony_conf(chrony_keys_path)
dabfaa
        if self.verbose > 1:
dabfaa
            print("Generated {}:\n{}".format(chrony_conf_path, chrony_conf))
dabfaa
dabfaa
        if not dry_run:
dabfaa
            self.write_file(chrony_conf_path, 0o644, chrony_conf, backup)
dabfaa
dabfaa
        chrony_keys = self.get_chrony_keys()
dabfaa
        if chrony_keys:
dabfaa
            if self.verbose > 1:
dabfaa
                print("Generated {}:\n{}".format(chrony_keys_path, chrony_keys))
dabfaa
dabfaa
        if not dry_run:
dabfaa
            self.write_file(chrony_keys_path, 0o640, chrony_keys, backup)
dabfaa
dabfaa
    def get_chrony_conf_sources(self):
dabfaa
        conf = ""
dabfaa
dabfaa
        if self.step_tickers:
dabfaa
            conf += "# Specify NTP servers used for initial correction.\n"
dabfaa
            conf += "initstepslew 0.1 {}\n".format(" ".join(self.step_tickers))
dabfaa
            conf += "\n"
dabfaa
dabfaa
        conf += "# Specify time sources.\n"
dabfaa
dabfaa
        for source in self.time_sources:
dabfaa
            address = source["address"]
dabfaa
            if address.startswith("127.127."):
dabfaa
                if address.startswith("127.127.1."):
dabfaa
                    continue
dabfaa
                assert False
dabfaa
            else:
dabfaa
                conf += "{} {}".format(source["type"], address)
dabfaa
                for option in source["options"]:
dabfaa
                    if option[0] in ["minpoll", "maxpoll", "version", "key",
dabfaa
                                     "iburst", "noselect", "prefer", "xleave"]:
dabfaa
                        conf += " {}".format(" ".join(option))
dabfaa
                    elif option[0] == "burst":
dabfaa
                        conf += " presend 6"
dabfaa
                    elif option[0] == "true":
dabfaa
                        conf += " trust"
dabfaa
                    else:
dabfaa
                        assert False
dabfaa
                conf += "\n"
dabfaa
        conf += "\n"
dabfaa
dabfaa
        return conf
dabfaa
dabfaa
    def get_chrony_conf_allows(self):
dabfaa
        allowed_networks = filter(lambda n: "ignore" not in self.restrictions[n] and
dabfaa
                                    "noserve" not in self.restrictions[n],
dabfaa
                                  self.restrictions.keys())
dabfaa
dabfaa
        conf = ""
dabfaa
        for network in sorted(allowed_networks, key=lambda n: (n.version, n)):
dabfaa
            if network.num_addresses > 1:
dabfaa
                conf += "allow {}\n".format(network)
dabfaa
            else:
dabfaa
                conf += "allow {}\n".format(network.network_address)
dabfaa
dabfaa
        if conf:
dabfaa
            conf = "# Allow NTP client access.\n" + conf
dabfaa
            conf += "\n"
dabfaa
dabfaa
        return conf
dabfaa
dabfaa
    def get_chrony_conf_cmdallows(self):
dabfaa
        allowed_networks = filter(lambda n: "ignore" not in self.restrictions[n] and
dabfaa
                                    "noquery" not in self.restrictions[n] and
dabfaa
                                    n != ipaddress.ip_network(u"127.0.0.1/32") and
dabfaa
                                    n != ipaddress.ip_network(u"::1/128"),
dabfaa
                                  self.restrictions.keys())
dabfaa
dabfaa
        ip_versions = set()
dabfaa
        conf = ""
dabfaa
        for network in sorted(allowed_networks, key=lambda n: (n.version, n)):
dabfaa
            ip_versions.add(network.version)
dabfaa
            if network.num_addresses > 1:
dabfaa
                conf += "cmdallow {}\n".format(network)
dabfaa
            else:
dabfaa
                conf += "cmdallow {}\n".format(network.network_address)
dabfaa
dabfaa
        if conf:
dabfaa
            conf = "# Allow remote monitoring.\n" + conf
dabfaa
            if 4 in ip_versions:
dabfaa
                conf += "bindcmdaddress 0.0.0.0\n"
dabfaa
            if 6 in ip_versions:
dabfaa
                conf += "bindcmdaddress ::\n"
dabfaa
            conf += "\n"
dabfaa
dabfaa
        return conf
dabfaa
dabfaa
    def get_chrony_conf(self, chrony_keys_path):
dabfaa
        local_stratum = 0
dabfaa
        maxdistance = 0.0
dabfaa
        minsources = 1
dabfaa
        orphan_stratum = 0
dabfaa
        logs = []
dabfaa
dabfaa
        for source in self.time_sources:
dabfaa
            address = source["address"]
dabfaa
            if address.startswith("127.127.1."):
dabfaa
                if address in self.fudges and "stratum" in self.fudges[address]:
dabfaa
                    local_stratum = int(self.fudges[address]["stratum"])
dabfaa
                else:
dabfaa
                    local_stratum = 5
dabfaa
dabfaa
        for tos in self.tos_options:
dabfaa
            if tos[0] == "maxdist":
dabfaa
                maxdistance = float(tos[1])
dabfaa
            elif tos[0] == "minsane":
dabfaa
                minsources = int(tos[1])
dabfaa
            elif tos[0] == "orphan":
dabfaa
                orphan_stratum = int(tos[1])
dabfaa
            else:
dabfaa
                assert False
dabfaa
dabfaa
        if "clockstats" in self.statistics:
dabfaa
            logs.append("refclocks");
dabfaa
        if "loopstats" in self.statistics:
dabfaa
            logs.append("tracking")
dabfaa
        if "peerstats" in self.statistics:
dabfaa
            logs.append("statistics");
dabfaa
        if "rawstats" in self.statistics:
dabfaa
            logs.append("measurements")
dabfaa
dabfaa
        conf = "# This file was converted from {}{}.\n".format(
dabfaa
                    self.ntp_conf_path,
dabfaa
                    " and " + self.step_tickers_path if self.step_tickers_path else "")
dabfaa
        conf += "\n"
dabfaa
dabfaa
        if self.ignored_lines:
dabfaa
            conf += "# The following directives were ignored in the conversion:\n"
dabfaa
dabfaa
            for line in self.ignored_lines:
dabfaa
                # Remove sensitive information
dabfaa
                line = re.sub(r"\s+pw\s+\S+", " pw XXX", line.rstrip())
dabfaa
                conf += "# " + line + "\n"
dabfaa
            conf += "\n"
dabfaa
dabfaa
        conf += self.get_chrony_conf_sources()
dabfaa
dabfaa
        conf += "# Record the rate at which the system clock gains/losses time.\n"
dabfaa
        if not self.driftfile:
dabfaa
            conf += "#"
dabfaa
        conf += "driftfile /var/lib/chrony/drift\n"
dabfaa
        conf += "\n"
dabfaa
dabfaa
        conf += "# Allow the system clock to be stepped in the first three updates\n"
dabfaa
        conf += "# if its offset is larger than 1 second.\n"
dabfaa
        conf += "makestep 1.0 3\n"
dabfaa
        conf += "\n"
dabfaa
dabfaa
        conf += "# Enable kernel synchronization of the real-time clock (RTC).\n"
dabfaa
        conf += "rtcsync\n"
dabfaa
        conf += "\n"
dabfaa
dabfaa
        conf += "# Enable hardware timestamping on all interfaces that support it.\n"
dabfaa
        conf += "#hwtimestamp *\n"
dabfaa
        conf += "\n"
dabfaa
dabfaa
        if maxdistance > 0.0:
dabfaa
            conf += "# Specify the maximum distance of sources to be selectable.\n"
dabfaa
            conf += "maxdistance {}\n".format(maxdistance)
dabfaa
            conf += "\n"
dabfaa
dabfaa
        conf += "# Increase the minimum number of selectable sources required to adjust\n"
dabfaa
        conf += "# the system clock.\n"
dabfaa
        if minsources > 1:
dabfaa
            conf += "minsources {}\n".format(minsources)
dabfaa
        else:
dabfaa
            conf += "#minsources 2\n"
dabfaa
        conf += "\n"
dabfaa
dabfaa
        conf += self.get_chrony_conf_allows()
dabfaa
dabfaa
        conf += self.get_chrony_conf_cmdallows()
dabfaa
dabfaa
        conf += "# Serve time even if not synchronized to a time source.\n"
dabfaa
        if orphan_stratum > 0 and orphan_stratum < 16:
dabfaa
            conf += "local stratum {} orphan\n".format(orphan_stratum)
dabfaa
        elif local_stratum > 0 and local_stratum < 16:
dabfaa
            conf += "local stratum {}\n".format(local_stratum)
dabfaa
        else:
dabfaa
            conf += "#local stratum 10\n"
dabfaa
        conf += "\n"
dabfaa
dabfaa
        conf += "# Specify file containing keys for NTP authentication.\n"
dabfaa
        conf += "keyfile {}\n".format(chrony_keys_path)
dabfaa
        conf += "\n"
dabfaa
dabfaa
        conf += "# Get TAI-UTC offset and leap seconds from the system tz database.\n"
dabfaa
        conf += "leapsectz right/UTC\n"
dabfaa
        conf += "\n"
dabfaa
dabfaa
        conf += "# Specify directory for log files.\n"
dabfaa
        conf += "logdir /var/log/chrony\n"
dabfaa
        conf += "\n"
dabfaa
dabfaa
        conf += "# Select which information is logged.\n"
dabfaa
        if logs:
dabfaa
            conf += "log {}\n".format(" ".join(logs))
dabfaa
        else:
dabfaa
            conf += "#log measurements statistics tracking\n"
dabfaa
dabfaa
        return conf
dabfaa
dabfaa
    def get_chrony_keys(self):
dabfaa
        if not self.keyfile:
dabfaa
            return ""
dabfaa
dabfaa
        keys = "# This file was converted from {}.\n".format(self.keyfile)
dabfaa
        keys += "\n"
dabfaa
dabfaa
        for key in self.keys:
dabfaa
            id = key[0]
dabfaa
            type = key[1]
dabfaa
            password = key[2]
dabfaa
dabfaa
            if type in ["m", "M"]:
dabfaa
                type = "MD5"
dabfaa
            elif type not in ["MD5", "SHA1", "SHA256", "SHA384", "SHA512"]:
dabfaa
                continue
dabfaa
dabfaa
            prefix = "ASCII" if len(password) <= 20 else "HEX"
dabfaa
dabfaa
            for first, last in self.trusted_keys:
dabfaa
                if first <= id <= last:
dabfaa
                    trusted = True
dabfaa
                    break
dabfaa
            else:
dabfaa
                trusted = False
dabfaa
dabfaa
            # Disable keys that were not marked as trusted
dabfaa
            if not trusted:
dabfaa
                keys += "#"
dabfaa
dabfaa
            keys += "{} {} {}:{}\n".format(id, type, prefix, password)
dabfaa
dabfaa
        return keys
dabfaa
dabfaa
    def write_file(self, path, mode, content, backup):
dabfaa
        path = self.root_dir + path
dabfaa
        if backup and os.path.isfile(path):
dabfaa
            os.rename(path, path + ".old")
dabfaa
dabfaa
        with open(os.open(path, os.O_CREAT | os.O_WRONLY | os.O_EXCL, mode), "w",
dabfaa
                  encoding="latin-1") as f:
dabfaa
            if self.verbose > 0:
dabfaa
                print("Writing " + path)
dabfaa
            f.write(u"" + content)
dabfaa
dabfaa
        # Fix SELinux context if restorecon is installed
dabfaa
        try:
dabfaa
            subprocess.call(["restorecon", path])
dabfaa
        except OSError:
dabfaa
            pass
dabfaa
dabfaa
dabfaa
def main():
dabfaa
    parser = argparse.ArgumentParser(description="Convert ntp configuration to chrony.")
dabfaa
    parser.add_argument("-r", "--root", dest="roots", default=["/"], nargs="+",
dabfaa
                        metavar="DIR", help="specify root directory (default /)")
dabfaa
    parser.add_argument("--ntp-conf", action="store", default="/etc/ntp.conf",
dabfaa
                        metavar="FILE", help="specify ntp config (default /etc/ntp.conf)")
dabfaa
    parser.add_argument("--step-tickers", action="store", default="",
dabfaa
                        metavar="FILE", help="specify ntpdate step-tickers config (no default)")
dabfaa
    parser.add_argument("--chrony-conf", action="store", default="/etc/chrony.conf",
dabfaa
                        metavar="FILE", help="specify chrony config (default /etc/chrony.conf)")
dabfaa
    parser.add_argument("--chrony-keys", action="store", default="/etc/chrony.keys",
dabfaa
                        metavar="FILE", help="specify chrony keyfile (default /etc/chrony.keys)")
dabfaa
    parser.add_argument("-b", "--backup", action="store_true", help="backup existing configs before writing")
dabfaa
    parser.add_argument("-L", "--ignored-lines", action="store_true", help="print ignored lines")
dabfaa
    parser.add_argument("-D", "--ignored-directives", action="store_true",
dabfaa
                        help="print names of ignored directives")
dabfaa
    parser.add_argument("-n", "--dry-run", action="store_true", help="don't make any changes")
dabfaa
    parser.add_argument("-v", "--verbose", action="count", default=0, help="increase verbosity")
dabfaa
dabfaa
    args = parser.parse_args()
dabfaa
dabfaa
    for root in args.roots:
dabfaa
        conf = NtpConfiguration(root, args.ntp_conf, args.step_tickers, args.verbose)
dabfaa
dabfaa
        if args.ignored_lines:
dabfaa
            for line in conf.ignored_lines:
dabfaa
                print(line)
dabfaa
dabfaa
        if args.ignored_directives:
dabfaa
            for directive in conf.ignored_directives:
dabfaa
                print(directive)
dabfaa
dabfaa
        conf.write_chrony_configuration(args.chrony_conf, args.chrony_keys, args.dry_run, args.backup)
dabfaa
dabfaa
if __name__ == "__main__":
dabfaa
    main()