Exemplo n.º 1
0
    def postOptions(self):
        if self["resolv-conf"]:
            self["recursive"] = True

        self.svcs = []
        self.zones = []
        for f in self.zonefiles:
            try:
                self.zones.append(authority.PySourceAuthority(f))
            except Exception:
                traceback.print_exc()
                raise usage.UsageError("Invalid syntax in " + f)
        for f in self.bindfiles:
            try:
                self.zones.append(authority.BindAuthority(f))
            except Exception:
                traceback.print_exc()
                raise usage.UsageError("Invalid syntax in " + f)
        for f in self.secondaries:
            svc = secondary.SecondaryAuthorityService.fromServerAddressAndDomains(*f)
            self.svcs.append(svc)
            self.zones.append(self.svcs[-1].getAuthority())
        try:
            self["port"] = int(self["port"])
        except ValueError:
            raise usage.UsageError("Invalid port: %r" % (self["port"],))
Exemplo n.º 2
0
    def __init__(self, config, test_obj):
        """Initialize and configure the DNS object."""

        zones = []
        port = config.get('port', 10053)
        pyzones = config.get('python-zones', [])
        bindzones = config.get('bind-zones', [])

        for pyzone in pyzones:
            zones.append(authority.PySourceAuthority(
                '%s/dns_zones/%s' % (test_obj.test_name, pyzone)))
            LOGGER.info("Added Python zone file %s" % (pyzone))

        for bindzone in bindzones:
            zones.append(authority.BindAuthority(
                '%s/dns_zones/%s' % (test_obj.test_name, bindzone)))
            LOGGER.info("Added BIND zone file %s" % (bindzone))

        factory = server.DNSServerFactory(authorities=zones)
        protocol = dns.DNSDatagramProtocol(controller=factory)

        reactor.listenUDP(port, protocol)
        reactor.listenTCP(port, factory)

        LOGGER.info("Started DNS server (UDP and TCP) on port %d" % (port))
Exemplo n.º 3
0
    def loadBindString(self, s):
        """
        Create a new L{twisted.names.authority.BindAuthority} from C{s}.

        @param s: A string with BIND zone data.
        @type s: bytes

        @return: a new bind authority
        @rtype: L{twisted.names.authority.BindAuthority}
        """
        fp = FilePath(self.mktemp().encode("ascii"))
        fp.setContent(s)

        return authority.BindAuthority(fp.path)
Exemplo n.º 4
0
class Options(usage.Options):
    optParameters = [
        ["interface", "i", "",   "The interface to which to bind"],
        ["port",      "p", "53", "The port on which to listen"],
        ["resolv-conf", None, None,
            "Override location of resolv.conf (implies --recursive)"],
        ["hosts-file", None, None, "Perform lookups with a hosts file"],
    ]

    optFlags = [
        ["cache",       "c", "Enable record caching"],
        ["recursive",   "r", "Perform recursive lookups"],
        ["verbose",     "v", "Log verbosely"],
    ]

    zones = None
    zonefiles = None

    def __init__(self):
        usage.Options.__init__(self)
        self['verbose'] = 0
        self.bindfiles = []
        self.zonefiles = []
        self.secondaries = []


    def opt_pyzone(self, filename):
        """Specify the filename of a Python syntax zone definition"""
        if not os.path.exists(filename):
            raise usage.UsageError(filename + ": No such file")
        self.zonefiles.append(filename)

    def opt_bindzone(self, filename):
        """Specify the filename of a BIND9 syntax zone definition"""
        if not os.path.exists(filename):
            raise usage.UsageError(filename + ": No such file")
        self.bindfiles.append(filename)


    def opt_secondary(self, ip_domain):
        """Act as secondary for the specified domain, performing
        zone transfers from the specified IP (IP/domain)
        """
        args = ip_domain.split('/', 1)
        if len(args) != 2:
            raise usage.UsageError("Argument must be of the form IP/domain")
        self.secondaries.append((args[0], [args[1]]))

    def opt_verbose(self):
        """Increment verbosity level"""
        self['verbose'] += 1


    def postOptions(self):
        if self['resolv-conf']:
            self['recursive'] = True

        self.svcs = []
        self.zones = []
        for f in self.zonefiles:
            try:
                self.zones.append(authority.PySourceAuthority(f))
            except Exception, e:
                traceback.print_exc()
                raise usage.UsageError("Invalid syntax in " + f)
        for f in self.bindfiles:
            try:
                self.zones.append(authority.BindAuthority(f))
            except Exception, e:
                traceback.print_exc()
                raise usage.UsageError("Invalid syntax in " + f)