Changeset 302
- Timestamp:
- 04/12/12 18:26:59 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r301 r302 3236 3236 3237 3237 my $rev = 'n'; 3238 my $code = 'OK';3239 my $msg = 'foobar?';3238 my $code = 'OK'; 3239 my $msg = 'foobar?'; 3240 3240 3241 3241 # choke on possible bad setting in ifrom … … 3348 3348 $nsflag = 1 if $type eq 'NS'; 3349 3349 3350 # my @vallist = ($zone_id, $rr->name, $reverse_typemap{$type}, $rr->ttl);3351 3352 3350 # "Primary" types: 3353 3351 # A, NS, CNAME, SOA, PTR(warn in forward), MX, TXT, AAAA, SRV, A6(ob), SPF 3354 3352 # maybe KEY 3353 3354 # BIND supports: 3355 # [standard] 3356 # A AAAA CNAME MX NS PTR SOA TXT 3357 # [variously experimental, obsolete, or obscure] 3358 # HINFO MB(ex) MD(ob) MF(ob) MG(ex) MINFO(ex) MR(ex) NULL WKS AFSDB(ex) ISDN(ex) RP(ex) RT(ex) X25(ex) PX 3359 # ... if one can ever find the right magic to format them correctly 3360 3361 # Net::DNS supports: 3362 # RRSIG SIG NSAP NS NIMLOC NAPTR MX MR MINFO MG MB LOC ISDN IPSECKEY HINFO 3363 # EID DNAME CNAME CERT APL AFSDB AAAA A DS NXT NSEC3PARAM NSEC3 NSEC KEY 3364 # DNSKEY DLV X25 TXT TSIG TKEY SSHFP SRV SPF SOA RT RP PX PTR NULL APL::AplItem 3355 3365 3356 3366 # nasty big ugly case-like thing here, since we have to do *some* different … … 3364 3374 # hmm. should we warn here if subdomain NS'es are left alone? 3365 3375 next if ($rwns && ($rr->name eq $zone)); 3366 $val = $rr->nsdname; 3376 if ($rev eq 'y') { 3377 # revzones have records more or less reversed from forward zones. 3378 my ($tmpcode,$tmpmsg) = _zone2cidr($host); 3379 die "Error converting NS record: $tmpmsg" if $tmpcode eq 'FAIL'; # hmm. may not make sense... 3380 $val = "$tmpmsg"; 3381 $host = $rr->nsdname; 3382 } else { 3383 $val = $rr->nsdname; 3384 } 3367 3385 $nsflag = 1; 3368 3386 } elsif ($type eq 'CNAME') { 3369 $val = $rr->cname; 3387 if ($rev eq 'y') { 3388 3389 # hmm. do we even want to bother with storing these at this level? Sub-octet delegation 3390 # by CNAME is essentially a record-publication hack, and we want to just represent the 3391 # "true" logical intentions as far down the stack as we can from the UI. 3392 3393 # really wanna spin this bit off to somewhere common, since it's likely we'll need it 3394 # for more than CNAME and PTR... 3395 $val = $host; 3396 $host = $rr->cname; 3397 if ($val =~ /\.in-addr\.arpa\.?$/) { 3398 $val =~ s/\.in-addr\.arpa\.?$//; 3399 $val = join '.', reverse split /\./, $val; 3400 } else { 3401 $val =~ s/\.ip6\.arpa\.?$//; 3402 my @nibs = reverse split /\./, $val; 3403 $val = ''; 3404 my $nc; 3405 foreach (@nibs) { 3406 $val .= $_; 3407 $val .= ":" if ++$nc % 4 == 0 && $nc < 32; 3408 } 3409 # canonicalize with NetAddr::IP 3410 $val = NetAddr::IP->new($val)->addr unless $val =~ /\*$/; 3411 } 3412 3413 } else { 3414 $val = $rr->cname; 3415 } 3370 3416 } elsif ($type eq 'SOA') { 3371 3417 next if $rwsoa; … … 3419 3465 } 3420 3466 3421 # BIND supports: 3422 # [standard] 3423 # A AAAA CNAME MX NS PTR SOA TXT 3424 # [variously experimental, obsolete, or obscure] 3425 # HINFO MB(ex) MD(ob) MF(ob) MG(ex) MINFO(ex) MR(ex) NULL WKS AFSDB(ex) ISDN(ex) RP(ex) RT(ex) X25(ex) PX 3426 # ... if one can ever find the right magic to format them correctly 3427 3428 # Net::DNS supports: 3429 # RRSIG SIG NSAP NS NIMLOC NAPTR MX MR MINFO MG MB LOC ISDN IPSECKEY HINFO 3430 # EID DNAME CNAME CERT APL AFSDB AAAA A DS NXT NSEC3PARAM NSEC3 NSEC KEY 3431 # DNSKEY DLV X25 TXT TSIG TKEY SSHFP SRV SPF SOA RT RP PX PTR NULL APL::AplItem 3432 3433 # $sth = $dbh->prepare($sql.") VALUES (".$vallen.")") 3434 # or die "problem preparing record insert SQL: ".$dbh->errstr."\n"; 3435 # $sth->execute(@vallist) or die "failed to insert ".$rr->string.": ".$sth->errstr."\n"; 3436 3467 my $logentry = "[AXFR $zone] "; 3468 3469 $merge = 1; 3470 if ($merge) { 3471 if ($rev eq 'n') { 3472 # importing a domain; we have A and AAAA records that could be merged with matching PTR records 3473 my $etype; 3474 my ($erdns,$erid,$ettl) = $dbh->selectrow_array("SELECT rdns_id,record_id,ttl FROM records ". 3475 "WHERE host=? AND val=? AND type=12", 3476 undef, ($host, $val) ); 3477 if ($erid) { 3478 if ($type eq 'A') { # PTR -> A+PTR 3479 $etype = 65280; 3480 $logentry .= "Merged A record with existing PTR record '$host A+PTR $val', TTL $ettl"; 3481 } 3482 if ($type eq 'AAAA') { # PTR -> AAAA+PTR 3483 $etype = 65281; 3484 $logentry .= "Merged AAAA record with existing PTR record '$host AAAA+PTR $val', TTL $ettl"; 3485 } 3486 $ettl = ($ettl < $ttl ? $ettl : $ttl); # use lower TTL 3487 $dbh->do("UPDATE records SET domain_id=?,ttl=?,type=? WHERE record_id=?", undef, 3488 ($domain_id, $ettl, $etype, $erid)); 3489 $nrecs++; 3490 _log($dbh, (group_id => $group, domain_id => $domain_id, rdns_id => $erdns, entry => $logentry) ); 3491 next; # while axfr_next 3492 } 3493 } else { 3494 # importing a revzone, we have PTR records that could be merged with matching A/AAAA records 3495 my ($domid,$erid,$ettl,$etype) = $dbh->selectrow_array("SELECT domain_id,record_id,ttl,type FROM records ". 3496 "WHERE host=? AND val=? AND (type=1 OR type=28)", 3497 undef, ($host, $val) ); 3498 if ($erid) { 3499 if ($etype == 1) { # A -> A+PTR 3500 $etype = 65280; 3501 $logentry .= "Merged PTR record with existing matching A record '$host A+PTR $val', TTL $ettl"; 3502 } 3503 if ($etype == 28) { # AAAA -> AAAA+PTR 3504 $etype = 65281; 3505 $logentry .= "Merged PTR record with existing matching AAAA record '$host AAAA+PTR $val', TTL $ettl"; 3506 } 3507 $ettl = ($ettl < $ttl ? $ettl : $ttl); # use lower TTL 3508 $dbh->do("UPDATE records SET rdns_id=?,ttl=?,type=? WHERE record_id=?", undef, 3509 ($rdns_id, $ettl, $etype, $erid)); 3510 $nrecs++; 3511 _log($dbh, (group_id => $group, domain_id => $domid, rdns_id => $rdns_id, entry => $logentry) ); 3512 next; # while axfr_next 3513 } 3514 } 3515 } 3516 3517 # Insert the new record 3437 3518 $sth->execute($domain_id, $rdns_id, $host, $reverse_typemap{$type}, $val, 3438 3519 $distance, $weight, $port, $ttl); … … 3440 3521 $nrecs++; 3441 3522 3442 my $logentry = "[AXFR $zone] ";3443 3523 if ($type eq 'SOA') { 3444 3524 # also !$rwsoa, but if that's set, it should be impossible to get here. … … 3487 3567 die "Bad zone: No NS records!\n" if !$nsflag; 3488 3568 3569 #die "horribly\n"; 3489 3570 $dbh->commit; 3490 3571 … … 3503 3584 return ('WARN',"OOOK!"); 3504 3585 } # end importAXFR() 3586 3587 3588 ## DNSDB::importBIND() 3589 sub importBIND { 3590 } # end importBIND() 3591 3592 3593 ## DNSDB::import_tinydns() 3594 sub import_tinydns { 3595 } # end import_tinydns() 3505 3596 3506 3597
Note:
See TracChangeset
for help on using the changeset viewer.