use strict;
use BerkeleyDB;
my $opt = {};
usage('GetOptions processing failed.');
exit 1;
}
usage();
exit 0;
}
usage('Please specify an output BerkeleyDB filename.');
exit 1;
}
usage('Please specify an input records file.');
exit 1;
}
usage('Please specify a space seperated list of zones');
exit 1;
}
my $records = [];
my $unique_names = [];
-Subname => "dns_data"
|| die "Cannot create dns_data: $BerkeleyDB::Error";
my $replId = 0;
foreach my $r (@$records) {
my $row_name = "$zone $name";
my $row_value = "$replId $name $ttl $type $data";
die "Cannot add record '$row_name' -> '$row_value' to dns_data: $BerkeleyDB::Error";
}
$replId++;
}
}
-Subname => "dns_xfr"
or die "Cannot create dns_xfr: $BerkeleyDB::Error";
foreach my $name (@$unique_names) {
die "Cannot add record '$zone' -> '$name' to dns_xfr: $BerkeleyDB::Error";
}
}
}
-Subname => "dns_client"
or die "Cannot create dns_client: $BerkeleyDB::Error";
my $ip = '127.0.0.1';
die "Cannot add record '$zone' -> '$ip' to dns_client: $BerkeleyDB::Error";
}
}
$dns_client->db_close();
-Property => 0,
-Subname => "dns_zone"
or die "Cannot create dns_zone: $BerkeleyDB::Error";
my $reversed_zone = reverse($zone);
die "Cannot add record '$reversed_zone' -> '1' to dns_zone: $BerkeleyDB::Error";
}
};
exit 0;
sub usage {
my ($message) = @_;
}
print STDERR "usage: $0 --bdb=<bdb-file> --input=<input-file> --zones=<zone-list>\n\n";
print STDERR "\tbdb-file: The output BerkeleyDB file you wish to create and use with bdbhpt-dynamic\n\n";
print STDERR "\tinput-file: The input text-file containing records to populate within your zones\n\n";
print STDERR "\tzone-list: The space-seperated list of zones you wish to create\n\n";
}
sub populate_records {
my (%args) = @_;
my %unique;
while (<RECORDS>) {
chomp;
s/\#.*$//;
s/^\s+//;
if ($_ eq '') {
next;
}
if (validate_record($record)) {
}
}
close(RECORDS);
push @$unique_names, $name;
}
}
# This could probably do more in-depth tests, but these tests are better than nothing!
sub validate_record {
my ($r) = @_;
my @TYPES = qw/A AAAA AFSDB APL CERT CNAME DHCID DLV DNAME DNSKEY DS HIP IPSECKEY KEY KX LOC MX NAPTR NS NSEC NSEC3 NSEC3PARAM PTR RRSIG RP SIG SOA SPF SRV SSHFP TA TKEY TLSA TSIG TXT/;
my $VALID_TYPE = {};
foreach my $t (@TYPES) {
$VALID_TYPE->{$t} = 1;
}
die "Record name must be set";
}
die "Record TTL must be set";
}
die "Record TTL must be an integer 0 or greater";
}
die "Record type must be set";
}
if (!$VALID_TYPE->{$r->{type}}) {
die "Unsupported record type: $r->{type}";
}
# Lets do some data validation for the records which will cause bind to crash if they're wrong
if ($r->{type} eq 'SOA') {
my $soa_error = "SOA records must take the form: 'server email refresh retry expire negative_cache_ttl'";
my ($server, $email, $version, $refresh, $retry, $expire, $negative_cache_ttl) = split(/\s+/, $r->{data});
die "$soa_error, missing server";
}
die "$soa_error, missing email";
}
die "$soa_error, missing refresh";
}
die "$soa_error, refresh must be an integer greater than 0";
}
die "$soa_error, missing retry";
}
die "$soa_error, retry must be an integer greater than 0";
}
die "$soa_error, missing expire";
}
die "$soa_error, expire must be an integer greater than 0";
}
die "$soa_error, missing negative cache ttl";
}
die "$soa_error, negative cache ttl must be an integer greater than 0";
}
}
return 1;
}