- Timestamp:
- 11/24/20 17:14:09 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bind-import
r809 r810 26 26 27 27 my $dnsdb = new DNSDB; 28 my $doimport = 0; 28 29 29 30 #print Dumper(\%reverse_typemap); … … 32 33 my $rev = 'n'; 33 34 my $zid; 35 36 my %amap; 37 my %namemap; 34 38 35 39 if ($zname =~ /\.arpa\.?$/ || $zname =~ m,^[\d./]+$,) { … … 47 51 die "zone $zname not on file\n" if !$zid; 48 52 53 # still no sane way to expose a human-friendly view tag on the command line. 54 my $view = shift @ARGV; 55 $view = '' if !$view; 56 49 57 ##fixme: retrieve defttl from SOA record 50 58 my $zonettl = 900; 59 my $defttl = $zonettl; 60 my $recbase = $zname; # to append to unqualified names 51 61 62 # need to spin up a full state machine-ish thing, because BIND zone files are all about context 52 63 while (<>) { 64 chomp; 53 65 next if /^\s*$/; 54 66 next if /^\s*;/; 67 if (my ($macro,$mdetail) = (/^\s*\$(TTL|ORIGIN|INCLUDE)\s+(.+)/) ) { 68 # macro sort of thing; $TTL and $ORIGIN most common. $INCLUDE is a thing, expect it to be rare in live use tho 69 if ($macro eq 'TTL') { 70 if ($mdetail =~ /^\d+$/) { 71 $defttl = $mdetail; 72 } else { 73 warn "invalid \$TTL: $_\n"; 74 } 75 } elsif ($macro eq 'ORIGIN') { 76 ##fixme: going to skip the stupid case of "$ORIGIN com." and the like that lie 77 # between . and the root domain we were told we're importing; anyone using such 78 # a mess outside the root servers is clearly insane 79 # handled cases: 80 # $ORIGIN . 81 # $ORIGIN [zonedomain]. 82 # $ORIGIN [subdomain.zonedomain]. 83 if ($mdetail eq '.' || $mdetail =~ /$zname\.$/ || $zname =~ /$mdetail\.$/) { 84 $recbase = $mdetail; 85 } else { 86 # if we continue, we either use an $ORIGIN that's out of zone, or ignore it and potentially publish incorrect records. 87 die "bad \$ORIGIN: $_\n"; 88 } 89 } 90 next; 91 } 92 # skip stale records that have no value 93 next if /^ip-192-168-1(12|20)-\d+/; 94 next if /ip.add.re.\d+\s*$/; 55 95 my ($name) = /([\w_.-]+)\s/; 56 96 # append zone name to record name if missing AND not dot-terminated; … … 59 99 # impossible with valid BIND zone file but... 60 100 $name .= ".$zname" if $name !~ /$zname$/ && $zname !~ /\.$/; 101 $name = $zname if /^\s*IN/; 61 102 s/([\w_.-]+)\s+//; 62 103 my ($class) = /(IN|CS|CH|HS)\s/; … … 94 135 } 95 136 137 if ($type eq 'A') { 138 # if ($amap{$name}) { 139 # print "urp: dupe name $name $rdata\n"; 140 # } else { 141 push @{$amap{$name}}, $rdata; 142 # } 143 push @{$namemap{$rdata}}, $name; 144 } 145 96 146 no warnings qw(uninitialized); 97 print "parsed: '$name' '$class' '$ttl' '$type'->'$itype' '$rdata'\t";147 #print "parsed: '$name' '$class' '$ttl' '$type'->'$itype' '$rdata'\n"; 98 148 #print; 99 149 #;imap IN 900 CNAME deepnet.cx. 100 150 ##fixme: not sure how to handle the case where someone leaves off the class. 101 my ($code, $msg); 102 if ($rev eq 'n') { 103 ($code,$msg) = $dnsdb->addRec('n', $rev, $zid, \$name, \$itype, \$rdata, $ttl); 104 } else { 105 ($code,$msg) = $dnsdb->addRec('n', $rev, $zid, \$rdata, \$itype, \$name, $ttl); 151 if ($doimport) { 152 my ($code, $msg); 153 if ($rev eq 'n') { 154 ($code,$msg) = $dnsdb->addRec('n', $rev, $zid, \$name, \$itype, \$rdata, $ttl); 155 } else { 156 ($code,$msg) = $dnsdb->addRec('n', $rev, $zid, \$rdata, \$itype, \$name, $ttl); 157 } 158 print "$code: $msg\n"; 106 159 } 107 print "$code: $msg\n";108 160 } 161 162 163 #print Dumper \%amap; 164 foreach my $n (keys %amap) { 165 foreach my $ip (@{$amap{$n}}) { 166 #print "$ip $n\n"; 167 push @{$namemap{$ip}}, $n unless grep $n, @{$namemap{$ip}}; 168 } 169 } 170 171 #print Dumper \%namemap; 172 foreach my $ip (sort keys %namemap) { 173 print "$ip ".join(' ', @{$namemap{$ip}})."\n"; 174 }
Note:
See TracChangeset
for help on using the changeset viewer.