Deprecated old export-ldap2dns.pl

Created scripts directory
moved data2ldap.pl and axfr2ldap.pl into scripts
Updated TODO


git-svn-id: https://svn.alkaloid.net/gpl/ldap2dns/trunk@139 06cd67b6-e706-0410-b29e-9de616bca6e9
This commit is contained in:
Ben Klang
2005-12-08 18:39:29 +00:00
parent bbbcb4a74a
commit b63617379c
5 changed files with 14 additions and 5 deletions

241
scripts/axfr2ldap.pl Executable file
View File

@@ -0,0 +1,241 @@
#!/usr/bin/perl
# Script to import data from DNS into LDAP
# Copyright 2000, Jacob Rief
# $Id: import.pl,v 1.24 2000/12/14 12:44:29 jrief Exp $
###### configure this ######
# remember to allow zone transfers from Your nameserver
$LDAPHOST = "ldap.myorg.com";
$LDAPBINDDN = "ou=dns,o=myorg";
$LDAPPASSWD = "secret";
$NAMESERVER = "ns1.myorg.com";
$BASEDN = "ou=dns,o=myorg";
$FULL_QUALIFIED_NAME = 0;
###### don't edit below this line ######
use Net::DNS;
use Net::LDAP;
$ldap = Net::LDAP->new($LDAPHOST) or die "Can't connect to LDAP server";
$mesg = $ldap->bind( dn => $LDAPBINDDN, password => $LDAPPASSWD );
die "Unable to bind to LDAP ", $mesg->error if ($mesg->code);
@domains;
while (<>) {
chomp;
$_ = lc;
if (/primary\s+([0-9A-Za-z._+-]+)\s+/) {
push(@domains, $1);
}
}
if ($#domains>=0) {
@domains = sort(@domains);
for ($i = 1; $i<=$#domains; $i++) {
if ($domains[$i-1] eq $domains[$i]) {
print "Warning: removing double entry for zone: $domains[$i]\n";
splice(@domains, $i, 1);
}
}
print "Adding ". ($#domains+1) ." zones to LDAP server\n";
foreach(@domains) {
read_zone($_);
}
} else {
print "No domain added to LDAP server\n";
}
sub add_attrs
{
my ($attr, $zonename) = @_;
# correct DNScname
if (defined $$attr{'DNScname'}) {
# check if DNScname is a real name
if ($$attr{'DNScname'} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/) {
$$attr{'DNSipaddr'} = "$1.$2.$3.$4";
undef $$attr{'DNScname'};
}
}
my ($tail);
if ($$attr{'DNSdomainname'} eq $zonename) {
$tail = "";
} else {
split /\.$zonename/, $$attr{'DNSdomainname'};
die "Corrupt DNSdomainname" unless (defined @_[0]);
$tail = @_[0];
}
if ($FULL_QUALIFIED_NAME) {
$$attr{'DNSdomainname'} = "$zonename." if ($tail eq "");
$$attr{'DNSdomainname'} = "$tail.$zonename." unless ($tail eq "");
$$attr{'DNScname'} .= "." if (defined $$attr{'DNScname'});
} else {
$$attr{'DNSdomainname'} = "$tail";
if (defined $$attr{'DNScname'}) {
split /\.$zonename/, $$attr{'DNScname'};
$$attr{'DNScname'} = @_[0] if (defined @_[0]);
}
}
my $rrdn;
if ($$attr{'DNStype'} eq "A") {
# A records are multivalued, use one rrset for all ipaddresses
$$attr{'cn'} = "A:$tail";
$rrdn = "cn=$$attr{'cn'},cn=$zonename,$BASEDN";
$mesg = $ldap->search(base=>$rrdn, scope=>"base", filter => "(objectclass=DNSrrset)");
if ($mesg->count==0) {
$mesg = $ldap->add(dn=>$rrdn, attr=>list_attrs($attr));
die "Failed to add entry:", $rrdn, " ", $mesg->error if ($mesg->code);
} else {
$mesg = $ldap->modify(dn=>$rrdn, add=>{ 'DNSipaddr'=>$$attr{'DNSipaddr'} });
die "Failed to modify entry:", $rrdn, " ", $mesg->error if ($mesg->code);
}
} else {
# All other records are siglevalued, use one rrset for each entry
my $i = 0;
do {
$i++;
$$attr{'cn'} = "$$attr{'DNStype'}$i:$tail";
$rrdn = "cn=$$attr{'cn'},cn=$zonename,$BASEDN";
$mesg = $ldap->search(base=>$rrdn, scope=>"base", filter=>"(objectclass=DNSrrset)");
} while ($mesg->count>0);
if ($FULL_QUALIFIED_NAME) {
$$attr{'DNScname'} = "$$attr{'DNStype'}$i.$zonename." unless defined $$attr{'DNScname'};
} else {
$$attr{'DNScname'} = "$$attr{'DNStype'}$i" unless defined $$attr{'DNScname'};
}
$mesg = $ldap->add(dn=>$rrdn, attr=>list_attrs($attr));
die "Failed to add entry:", $rrdn, " ", $mesg->error if ($mesg->code);
}
}
sub list_attrs
{
my $attr = shift;
my (@list, $key, $value);
while (($key, $value) = each %$attr) {
push(@list, $key => $value);
}
return \@list;
}
sub read_zone
{
my $zonename = shift;
$res = new Net::DNS::Resolver;
$res->nameservers($NAMESERVER);
@zone = $res->axfr($zonename);
while (!@zone) {
print "Query failed for $zonename: ", $res->errorstring, ".\n";
if ($res->errorstring eq "couldn't connect") {
print "Trying to reconnect\n";
sleep(10);
@zone = $res->axfr($zonename);
} else {
return;
}
}
print "---------- reading zone $zonename ----------\n";
foreach $rr (@zone) {
$rr->print;
if ($rr->type eq "SOA") {
die "Invalid SOA record for ", $rr->name, " " unless ($rr->string =~ /^([0-9a-zA-Z_.+-]+)\.\s+(\d+)\s+(\w+)\s+(\w+)\s+([0-9a-zA-Z_.+-]+)\s+([0-9a-zA-Z_.+-]+)\s+\((.*)\)/s);
die "Corrupt SOA record for ", $rr->name, " " unless ($1 eq $rr->name && $2 eq $rr->ttl && $3 eq $rr->class && $4 eq $rr->type);
my %attr;
$attr{'objectclass'} = "DNSzone";
$attr{'DNSzonename'} = lc $1;
$attr{'DNSttl'} = $2;
$attr{'DNSclass'} = $3;
$attr{'DNStype'} = $4;
$attr{'DNSzonemaster'} = lc $5;
$attr{'DNSadminmailbox'} = lc $6;
my $soa = $7;
die "Invalid SOA fields for ", $zonename, " " unless ($soa =~ /\s*(\d+)\D*(\d+)\D*(\d+)\D*(\d+)\D*(\d+)\s*/s);
$attr{'DNSserial'} = $1;
$attr{'DNSrefresh'} = $2;
$attr{'DNSretry'} = $3;
$attr{'DNSexpire'} = $4;
$attr{'DNSminimum'} = $5;
$attr{'cn'} = $zonename;
$mesg = $ldap->add(dn=>"cn=$zonename,$BASEDN", attr=>list_attrs(\%attr));
die "Failed to add entry:", $zonename, " ", $mesg->error if ($mesg->code);
} elsif ($rr->type eq "A") {
die "Invalid A record for ", $rr->name, " " unless ($rr->string =~ /^([0-9a-zA-Z_.+-]+)\.\s+(\d+)\s+(\w+)\s+(\w+)\s+([0-9.]+)/);
die "Corrupt A record for ", $rr->name, " " unless ($1 eq $rr->name && $2 eq $rr->ttl && $3 eq $rr->class && $4 eq $rr->type && $5 eq $rr->address);
next if $1 eq "localhost.$zonename";
my %attr;
$attr{'objectclass'} = "DNSrrset";
$attr{'DNSdomainname'} = lc $1;
$attr{'DNSttl'} = $2;
$attr{'DNSclass'} = $3;
$attr{'DNStype'} = $4;
$attr{'DNSipaddr'} = $5;
add_attrs(\%attr, $zonename);
} elsif ($rr->type eq "MX") {
die "Invalid MX record for ", $rr->name, " " unless ($rr->string =~ /^([0-9a-zA-Z_.+-]+)\.\s+(\d+)\s+(\w+)\s+(\w+)\s+(\d+)\s+([0-9a-zA-Z_.+-]+)/);
die "Corrupt MX record for ", $rr->name, " " unless ($1 eq $rr->name && $2 eq $rr->ttl && $3 eq $rr->class && $4 eq $rr->type);
my %attr;
$attr{'objectclass'} = "DNSrrset";
$attr{'DNSdomainname'} = lc $1;
$attr{'DNSttl'} = $2;
$attr{'DNSclass'} = $3;
$attr{'DNStype'} = $4;
$attr{'DNSpreference'} = $5;
$attr{'DNScname'} = lc $6;
add_attrs(\%attr, $zonename);
} elsif ($rr->type eq "NS") {
die "Invalid NS record for ", $rr->name, " " unless ($rr->string =~ /^([0-9a-zA-Z_.+-]+)\.\s+(\d+)\s+(\w+)\s+(\w+)\s+([0-9a-zA-Z_.+-]+)/);
die "Corrupt NS record for ", $rr->name, " " unless ($1 eq $rr->name && $2 eq $rr->ttl && $3 eq $rr->class && $4 eq $rr->type);
my %attr;
$attr{'objectclass'} = "DNSrrset";
$attr{'DNSdomainname'} = lc $1;
$attr{'DNSttl'} = $2;
$attr{'DNSclass'} = $3;
$attr{'DNStype'} = $4;
$attr{'DNScname'} = lc $5;
add_attrs(\%attr, $zonename);
} elsif ($rr->type eq "CNAME" || $rr->type eq "TXT") {
die "Invalid ", $rr->type, " record for ", $rr->name, " " unless ($rr->string =~ /^([0-9a-zA-Z_.+-]+)\.\s+(\d+)\s+(\w+)\s+(\w+)\s+([0-9a-zA-Z_.+-]+)/);
die "Corrupt ", $rr->type, " record for ", $rr->name, " " unless ($1 eq $rr->name && $2 eq $rr->ttl && $3 eq $rr->class && $4 eq $rr->type);
my %attr;
$attr{'objectclass'} = "DNSrrset";
$attr{'DNSdomainname'} = $1;
$attr{'DNSttl'} = $2;
$attr{'DNSclass'} = $3;
$attr{'DNStype'} = $4;
$attr{'DNScname'} = $5;
add_attrs(\%attr, $zonename);
} elsif ($rr->type eq "PTR") {
die "Invalid PTR record for ", $rr->name, " " unless ($rr->string =~ /^([0-9.]+\.in-addr\.arpa)\.\s+(\d+)\s+(\w+)\s+(\w+)\s+([0-9a-zA-Z_.+-]+)/);
die "Corrupt PTR record for ", $rr->name, " " unless ($1 eq $rr->name && $2 eq $rr->ttl && $3 eq $rr->class && $4 eq $rr->type);
my %attr;
$attr{'objectclass'} = "DNSrrset";
$attr{'DNSdomainname'} = "$1.";
$attr{'DNSttl'} = $2;
$attr{'DNSclass'} = $3;
$attr{'DNStype'} = $4;
$attr{'DNScname'} = $5;
if ($attr{'DNSdomainname'} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/) {
$attr{'DNSipaddr'} = "$4.$3.$2.$1";
$attr{'cn'} = "PTR:$1"; # Only for C-level domains yet
} else { die "Corrupt IP address for", $rr->name; }
my $rrdn = "cn=$attr{'cn'},cn=$zonename,$BASEDN";
$mesg = $ldap->add(dn=>$rrdn, attr=>list_attrs(\%attr));
die "Failed to add entry:", $rrdn, " ", $mesg->error if ($mesg->code);
}
}
}

381
scripts/data2ldap.pl Normal file
View File

@@ -0,0 +1,381 @@
#!/usr/bin/perl
use strict;
use warnings;
#use POSIX qw(strftime):
my $file = $ARGV[0];
my $output = $ARGV[1];
my $rejout;
my $basedn = $ARGV[2];
my %domains; # Keep track of which domains for which we have
# already written an SOA
my $outfh;
my $rejfh;
#my $newserial = strftime("%Y%m%d01");
if (!defined($file)) {
print STDERR "Must specify path to 'data' file to read\n";
exit 1;
}
if (!defined($output) || $output eq '-') {
$output = "/dev/stdout";
$rejout = "/dev/null";
} else {
$rejout = "$output.rej";
}
open($outfh, ">$output") or die ("Unable to open $output for writing!");
open($rejfh, ">$rejout") or die ("Unable to open $rejout for writing");
if (!defined($basedn)) {
print STDERR "Must specify a base DN as the third argument\n";
exit 1;
}
# We run in two iterations. The first attempts to enumerate all zones
# for which we have records and create SOAs in LDAP. The reason for this is
# zones are used as a container for all records so they must be in place before
# we start to add any zone data. While it takes longer, this mechanism ensures
# the proper sequence.
open(DATA, $file) or die ("Unable to open $file for reading\n");
LINE: while(<DATA>) {
chomp;
for ($_) {
/^\s*#/ && do {
# Found a comment
next LINE;
};
/^-/ && do {
# Found a disabled A record
print STDERR "Ignoring disabled record: $_\n";
print $rejfh "$_\n";
next LINE;
};
/^%/ && do {
# Location definition: %code:1.2.3.4
my ($loc, $ip) = split /:/;
$loc =~ s/^%//;
print $outfh "dn: dnslocation=$loc,$basedn\n";
print $outfh "objectClass: top\n";
print $outfh "objectClass: dnsloccodes\n";
print $outfh "dnslocation: $loc\n";
if (defined($ip) && $ip) {
print $outfh "dnsipaddr: $ip\n";
} else {
print $outfh "dnsipaddr: :\n";
}
print $outfh "\n";
next LINE;
}; # End location definition
/^Z/ && do {
my ($domain, $master, $admin, $serial, $refresh, $retry, $expire,
$minimum, $ttl, $timestamp, $loc) = split /:/;
$domain =~ s/^Z//;
print $outfh "dn: cn=$domain,$basedn\n";
print $outfh "objectClass: top\n";
print $outfh "objectClass: dnszone\n";
print $outfh "cn: $domain\n";
print $outfh "dnszonename: $domain\n";
print $outfh "dnszonemaster: $master\n";
print $outfh "dnsadminmailbox: $admin\n";
if ($serial) { print $outfh "dnsserial: $serial\n"; }
if ($refresh) { print $outfh "dnsrefresh: $refresh\n"; }
if ($retry) { print $outfh "dnsretry: $retry\n"; }
if ($expire) { print $outfh "dnsexpire: $expire\n"; }
if ($minimum) { print $outfh "dnsminimum: $minimum\n"; }
if ($ttl) { print $outfh "dnsttl: $ttl\n"; }
if ($timestamp) { print $outfh "dnstimestamp: $timestamp\n"; }
if ($loc) { print $outfh "dnslocation: $loc\n"; }
print $outfh "\n";
}; # End SOA record
/^\./ && do {
# NS+SOA+A Record
my ($fqdn, $ip, $x, $ttl, $timestamp, $loc) = split /:/;
$fqdn =~ s/^\.//;
# To find the domain name, the fqdn must have two words of any
# characters with one period somehere in the middle and an optional
# trailing period (which is trimmed) just before the end of the line
$fqdn =~ /^\.*([A-Za-z0-9-]+\.[A-Za-z0-9-]+)\.*$/;
if (!defined($1)) {
die ("Unable to find domain name for $fqdn!\n");
}
my $domain = getdomain($fqdn);
if (defined($domains{$domain})) {
# We've already generated an SOA for this domain
next LINE;
}
print $outfh "dn: cn=$domain,$basedn\n";
print $outfh "objectClass: top\n";
print $outfh "objectClass: dnszone\n";
print $outfh "cn: $domain\n";
print $outfh "dnszonename: $domain\n";
print $outfh "dnszonemaster: $x\n";
print $outfh "dnsadminmailbox: hostmaster\@$domain\n";
if (defined($ttl)) { print $outfh "dnsttl: $ttl\n"; }
if (defined($timestamp)) { print $outfh "dnstimestamp: $timestamp\n"; }
if (defined($loc)) { print $outfh "dnslocation: $loc\n"; }
print $outfh "\n";
$domains{$domain} = 1;
next LINE;
};
} # End for($_) block
} # End LINE while(<DATA>)
# Done with zone SOAs, being with resource records
seek(DATA, 0, 0) or die ("Unable to seek $file for reading\n");
LINE: while(<DATA>) {
chomp;
for ($_) {
/^\s*#/ && do {
# Found a comment
next LINE;
};
/^-/ && do {
# Found a disabled. User was warned above
next LINE;
};
/^\./ && do {
# Found NS + A + SOA (SOA handled above)
my ($fqdn, $ip, $x, $ttl, $timestamp, $loc) = split /:/;
$fqdn =~ s/^\.//;
if (!defined($ip)) { $ip = ""; }
if (!defined($x)) { $x = ""; }
if (!defined($ttl)) { $ttl = ""; }
if (!defined($timestamp)) { $timestamp = ""; }
if (!defined($loc)) { $loc = ""; }
my $id = "NSA-$fqdn-$ip-$x-$ttl-$timestamp-$loc";
my $domain = getdomain($fqdn);
print $outfh "dn: cn=$id,cn=$domain,$basedn\n";
print $outfh "objectClass: top\n";
print $outfh "objectClass: dnszone\n";
print $outfh "objectClass: dnsrrset\n";
print $outfh "cn: $id\n";
print $outfh "dnstype: ns\n";
print $outfh "dnsdomainname: $fqdn.\n";
if ($x) { print $outfh "dnscname: $x.\n"; }
if ($ip) { print $outfh "dnsipaddr: $ip\n"; }
if ($ttl) { print $outfh "dnsttl: $ttl\n"; }
if ($timestamp) { print $outfh "dnstimestamp: $timestamp\n"; }
if ($loc) { print $outfh "dnsloc: $loc\n"; }
print $outfh "\n";
next LINE;
};
/^&/ && do {
# Found NS
my ($fqdn, $ip, $x, $ttl, $timestamp, $loc) = split /:/;
$fqdn =~ s/^&//;
if (!defined($ip)) { $ip = ""; }
if (!defined($x)) { $x = ""; }
if (!defined($ttl)) { $ttl = ""; }
if (!defined($timestamp)) { $timestamp = ""; }
if (!defined($loc)) { $loc = ""; }
my $id = "NS-$fqdn-$ip-$x-$ttl-$timestamp-$loc";
my $domain = getdomain($fqdn);
print $outfh "dn: cn=$id,cn=$domain,$basedn\n";
print $outfh "objectClass: top\n";
print $outfh "objectClass: dnszone\n";
print $outfh "objectClass: dnsrrset\n";
print $outfh "cn: $id\n";
print $outfh "dnstype: ns\n";
print $outfh "dnsdomainname: $fqdn.\n";
if ($ip) { print $outfh "dnsipaddr: $ip\n"; }
if ($x) { print $outfh "dnscname: $x.\n"; }
if ($ttl) { print $outfh "dnsttl: $ttl\n"; }
if ($timestamp) { print $outfh "dnstimestamp: $timestamp\n"; }
if ($loc) { print $outfh "dnsloc: $loc\n"; }
print $outfh "\n";
next LINE;
};
/^=/ && do {
# Found an A + PTR
my ($fqdn, $ip, $ttl, $timestamp, $loc) = split /:/;
$fqdn =~ s/^=//;
if (!defined($ip)) { $ip = ""; }
if (!defined($ttl)) { $ttl = ""; }
if (!defined($timestamp)) { $timestamp = ""; }
if (!defined($loc)) { $loc = ""; }
my $id = "APTR-$fqdn-$ip-$ttl-$timestamp-$loc";
my $domain = getdomain($fqdn);
print $outfh "dn: cn=$id,cn=$domain,$basedn\n";
print $outfh "objectClass: top\n";
print $outfh "objectClass: dnszone\n";
print $outfh "objectClass: dnsrrset\n";
print $outfh "cn: $id\n";
print $outfh "dnstype: a\n";
print $outfh "dnsdomainname: $fqdn.\n";
if ($ip) { print $outfh "dnscipaddr: $ip\n"; }
if ($ttl) { print $outfh "dnsttl: $ttl\n"; }
if ($timestamp) { print $outfh "dnstimestamp: $timestamp\n"; }
if ($loc) { print $outfh "dnsloc: $loc\n"; }
print $outfh "\n";
next LINE;
};
/^\+/ && do {
# Found an A
my ($fqdn, $ip, $ttl, $timestamp, $loc) = split /:/;
$fqdn =~ s/^\+//;
if (!defined($ip)) { $ip = ""; }
if (!defined($ttl)) { $ttl = ""; }
if (!defined($timestamp)) { $timestamp = ""; }
if (!defined($loc)) { $loc = ""; }
my $id = "A-$fqdn-$ip-$ttl-$timestamp-$loc";
my $domain = getdomain($fqdn);
print $outfh "dn: cn=$id,cn=$domain,$basedn\n";
print $outfh "objectClass: top\n";
print $outfh "objectClass: dnszone\n";
print $outfh "objectClass: dnsrrset\n";
print $outfh "cn: $id\n";
print $outfh "dnstype: a\n";
print $outfh "dnsdomainname: $fqdn.\n";
if ($ip) { print $outfh "dnsipaddr: $ip\n"; }
if ($ttl) { print $outfh "dnsttl: $ttl\n"; }
if ($timestamp) { print $outfh "dnstimestamp: $timestamp\n"; }
if ($loc) { print $outfh "dnsloc: $loc\n"; }
print $outfh "\n";
next LINE;
};
/^@/ && do {
# Found an MX
my ($fqdn, $ip, $x, $dist, $ttl, $timestamp, $loc) = split /:/;
$fqdn =~ s/^@//;
if (!defined($ip)) { $ip = ""; }
if (!defined($x)) { $x = ""; }
if (!defined($dist)) { $dist = ""; }
if (!defined($ttl)) { $ttl = ""; }
if (!defined($timestamp)) { $timestamp = ""; }
if (!defined($loc)) { $loc = ""; }
my $id = "MX-$fqdn-$ip-$x-$dist-$ttl-$timestamp-$loc";
my $domain = getdomain($fqdn);
print $outfh "dn: cn=$id,cn=$domain,$basedn\n";
print $outfh "objectClass: top\n";
print $outfh "objectClass: dnszone\n";
print $outfh "objectClass: dnsrrset\n";
print $outfh "cn: $id\n";
print $outfh "dnstype: mx\n";
print $outfh "dnsdomainname: $fqdn.\n";
if ($ip) { print $outfh "dnsipaddr: $ip\n" };
if ($x) { print $outfh "dnscname: $x.\n"; }
if ($dist) { print $outfh "dnspreference: $dist\n"; }
if ($ttl) { print $outfh "dnsttl: $ttl\n"; }
if ($timestamp) { print $outfh "dnstimestamp: $timestamp\n"; }
if ($loc) { print $outfh "dnsloc: $loc\n"; }
print $outfh "\n";
next LINE;
};
/^'/ && do {
# Currently unsupported
print STDERR "Ignoring unsupported TXT record: $_\n";
print $rejfh "$_\n";
next LINE;
# Found an MX
my ($fqdn, $s, $ttl, $timestamp, $loc) = split /:/;
$fqdn =~ s/^'//;
if (!defined($ttl)) { $ttl = ""; }
if (!defined($timestamp)) { $timestamp = ""; }
if (!defined($loc)) { $loc = ""; }
my $id = "TXT-$fqdn-$ttl-$timestamp-$loc";
my $domain = getdomain($fqdn);
print $outfh "dn: cn=$id,cn=$domain,$basedn\n";
print $outfh "objectClass: top\n";
print $outfh "objectClass: dnszone\n";
print $outfh "objectClass: dnsrrset\n";
print $outfh "cn: $id\n";
print $outfh "dnstype: txt\n";
print $outfh "dnsdomainname: $fqdn.\n";
# FIXME Add TXT support to ldap2dns
# print $outfh "dnstxt: $s\n";
if ($ttl) { print $outfh "dnsttl: $ttl\n"; }
if ($timestamp) { print $outfh "dnstimestamp: $timestamp\n"; }
if ($loc) { print $outfh "dnsloc: $loc\n"; }
print $outfh "\n";
next LINE;
};
/^\^/ && do {
# Found an PTR
my ($fqdn, $ptr, $ttl, $timestamp, $loc) = split /:/;
$fqdn =~ s/^\^//;
if (!defined($ttl)) { $ttl = ""; }
if (!defined($timestamp)) { $timestamp = ""; }
if (!defined($loc)) { $loc = ""; }
my $id = "$fqdn-$ptr-$ttl-$timestamp-$loc";
my $domain = getdomain($fqdn);
print $outfh "dn: cn=$id,cn=$domain,$basedn\n";
print $outfh "objectClass: top\n";
print $outfh "objectClass: dnszone\n";
print $outfh "objectClass: dnsrrset\n";
print $outfh "cn: $id\n";
print $outfh "dnstype: ptr\n";
print $outfh "dnscname: $fqdn.\n";
print $outfh "dnsipaddr: $ptr\n";
if ($ttl) { print $outfh "dnsttl: $ttl\n"; }
if ($timestamp) { print $outfh "dnstimestamp: $timestamp\n"; }
if ($loc) { print $outfh "dnsloc: $loc\n"; }
print $outfh "\n";
next LINE;
};
/^C/ && do {
# Found a CNAME
my ($fqdn, $p, $ttl, $timestamp, $loc) = split /:/;
$fqdn =~ s/^C//;
if (!defined($ttl)) { $ttl = ""; }
if (!defined($timestamp)) { $timestamp = ""; }
if (!defined($loc)) { $loc = ""; }
my $id = "CNAME-$fqdn-$p-$ttl-$timestamp-$loc";
my $domain = getdomain($fqdn);
print $outfh "dn: cn=$id,cn=$domain,$basedn\n";
print $outfh "objectClass: top\n";
print $outfh "objectClass: dnszone\n";
print $outfh "objectClass: dnsrrset\n";
print $outfh "cn: $id\n";
print $outfh "dnstype: cname\n";
print $outfh "dnsdomainname: $fqdn.\n";
print $outfh "dnscname: $p.\n";
if ($ttl) { print $outfh "dnsttl: $ttl\n"; }
if ($timestamp) { print $outfh "dnstimestamp: $timestamp\n"; }
if ($loc) { print $outfh "dnsloc: $loc\n"; }
print $outfh "\n";
next LINE;
};
/^:/ && do {
# Found unsupported "unknown record"
print STDERR "Ignoring \"unknown record\": $_\n";
print $rejfh "$_\n";
next LINE;
}
} # End for($_) block
} # End LINE while(<DATA>)
sub getdomain
{
my $fqdn = shift(@_);
$fqdn =~ /\.*([A-Za-z0-9\-]+\.[A-Za-z0-9\-]+)\.*$/;
return $1;
}