Пример #1
0
    def update_rnd(self):
        '''Add random records or re-sign zone.'''

        dnssec = False
        nsec3 = False

        self.update_soa()

        old_name = self.path + ".old"
        os.rename(self.path, old_name)

        with open(old_name, 'r') as old_file:
            for line in old_file:
                if "RRSIG" in line:
                    dnssec = True
                if "NSEC3PARAM" in line:
                    nsec3 = True

        try:
            params = ["-u", old_name, "-o", self.path, self.name]
            if dnssec:
                prepare_dir(self.key_dir_bind)
                params = ["-s", "-3", "y" if nsec3 else "n", "-k", self.key_dir_bind] \
                         + params
            zone_generate.main(params)
        except OSError:
            raise Exception("Can't modify zone file '%s'" % self.path)

        os.remove(old_name)
Пример #2
0
    def update_rnd(self):
        '''Add random records or resign zone.'''

        dnssec = False
        nsec3 = False

        self.update_soa()

        old_name = self.path + ".old"
        os.rename(self.path, old_name)

        with open(old_name, 'r') as old_file:
            for line in old_file:
                if "RRSIG" in line:
                    dnssec = True
                if "NSEC3PARAM" in line:
                    nsec3 = True

        try:
            params = ["-u", old_name, "-o", self.path, self.name]
            if dnssec:
                prepare_dir(self.key_dir_bind)
                params = ["-s", "-3", "y" if nsec3 else "n", "-k", self.key_dir_bind] \
                         + params
            zone_generate.main(params)
            if dnssec:
                self._kasp_import_keys(self.key_dir, self.key_dir_bind, self.name)
        except OSError:
            raise Exception("Can't modify zone file '%s'" % self.path)

        os.remove(old_name)
Пример #3
0
    def gen_file(self, dnssec=None, nsec3=None, records=None, serial=None):
        '''Generate zone file.'''

        if dnssec == None:
            dnssec = random.choice([True, False])
        if nsec3 == None:
            nsec3 = random.choice([True, False])
        if not records:
            records = random.randint(1, 200)
        if not serial:
            serial = random.randint(1, 4294967295)

        self.file_name = self.name + "rndzone"

        try:
            params = ["-i", serial, "-o", self.path, self.name, records]
            if dnssec:
                prepare_dir(self.key_dir_bind)
                params = [
                    "-s", "-3", "y" if nsec3 else "n", "-k", self.key_dir_bind
                ] + params
            if zone_generate.main(params) != 0:
                raise OSError

        except OSError:
            raise Exception("Can't create zone file '%s'" % self.path)
Пример #4
0
    def gen_file(self, dnssec=None, nsec3=None, records=None, serial=None):
        '''Generate zone file.'''

        if dnssec == None:
            dnssec = random.choice([True, False])
        if nsec3 == None:
            nsec3 = random.choice([True, False])
        if not records:
            records = random.randint(1, 1000)
        if not serial:
            serial = random.randint(1, 4294967295)

        self.file_name = self.name + "rndzone"

        try:
            params = ["-i", serial, "-o", self.path, self.name, records]
            if dnssec:
                prepare_dir(self.key_dir_bind)
                params = ["-s", "-3", "y" if nsec3 else "n",
                          "-k", self.key_dir_bind] + params
            if zone_generate.main(params) != 0:
                raise OSError
            if dnssec:
                self._kasp_import_keys(self.key_dir, self.key_dir_bind, self.name)

        except OSError:
            raise Exception("Can't create zone file '%s'" % self.path)
Пример #5
0
    def set_name(self, name=None):
        '''Set specified or generate zone name.'''

        if name:
            self.name = name
            if self.name[-1] != ".":
                self.name += "."
        else:
            self.name = zone_generate.main(["-n", 1]).strip()
Пример #6
0
    def set_name(self, name=None):
        '''Set specified or generate zone name.'''

        if name:
            self.name = name
            if self.name[-1] != ".":
                self.name += "."
        else:
            self.name = zone_generate.main(["-n", 1]).strip()
Пример #7
0
    def zone_rnd(self, number, dnssec=None, nsec3=None, records=None, serial=None):
        zones = list()

        # Generate unique zone names.
        names = zone_generate.main(["-n", number]).split()
        for name in names:
            zone = dnstest.zonefile.ZoneFile(self.zones_dir)
            zone.set_name(name)
            zone.gen_file(dnssec=dnssec, nsec3=nsec3, records=records,
                          serial=serial)
            zones.append(zone)

        return zones
Пример #8
0
    def zone_rnd(self,
                 number,
                 dnssec=None,
                 nsec3=None,
                 records=None,
                 serial=None):
        zones = list()

        # Generate unique zone names.
        names = zone_generate.main(["-n", number]).split()
        for name in names:
            zone = dnstest.zonefile.ZoneFile(self.zones_dir)
            zone.set_name(name)
            zone.gen_file(dnssec=dnssec,
                          nsec3=nsec3,
                          records=records,
                          serial=serial)
            zones.append(zone)

        return zones