Changeset 460


Ignore:
Timestamp:
01/25/13 16:11:33 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Edge case bugfixes and fleshing-out for deleting records by CIDR. See #43

  • use AAAA+PTR template anyway; just continue to not expand it.
  • make sure to skip non-PTR-ish records when we're working with a set
  • fix the simple-but-wrong logic for CIDR requests larger than the defined reverse zones
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns-rpc.cgi

    r459 r460  
    450450      if (scalar(@$reclist) == 0) {
    451451        # Aren't Magic Numbers Fun?  See pseudotype list in dnsadmin.
    452         my $type = ($cidr->{isv6} ? 65282 : ($cidr->masklen == 32 ? 65280 : 65283) );
     452        my $type = ($cidr->{isv6} ? 65284 : ($cidr->masklen == 32 ? 65280 : 65283) );
    453453        addRec(defrec =>'n', revrec => 'y', parent_id => $zonelist->[0]->{rdns_id}, type => $type,
    454454          address => "$cidr", %args);
     
    534534          my $reccidr = new NetAddr::IP $rec->{val};
    535535          next unless $cidr->contains($reccidr);
     536          next unless $rec->{type} == 12 || $rec->{type} == 65280 || $rec->{type} == 65281 ||
     537                      $rec->{type} == 65282 || $rec->{type} == 65283 ||$rec->{type} == 65284;
    536538          ##fixme:  multiple records, wanna wax'em all, how to report errors?
    537539          if ($args{delforward} ||
     
    543545          }
    544546        }
     547        if ($args{parpatt} && $zone == $cidr) {
     548          # Edge case;  we've just gone and axed all the records in the reverse zone.
     549          # Re-add one to match the parent if we've been given a pattern to use.
     550          addRec(defrec =>'n', revrec => 'y', parent_id => $zonelist->[0]->{rdns_id},
     551                 type => ($zone->{isv6} ? 65284 : 65283), address => "$cidr", %args);
     552        }
    545553
    546554      } else {
     
    554562          my $reccidr = new NetAddr::IP $rec->{val};
    555563          next unless $cidr == $reccidr;
     564          next unless $rec->{type} == 12 || $rec->{type} == 65280 || $rec->{type} == 65281 ||
     565                      $rec->{type} == 65282 || $rec->{type} == 65283 ||$rec->{type} == 65284;
    556566          if ($args{delforward} || $rec->{type} == 12) {
    557567            my ($code,$msg) = DNSDB::delRec($dbh, 'n', 'y', $rec->{record_id});
     
    575585    # that spans multiple reverse zones (eg, /23 CIDR -> 2 /24 rzones)
    576586    foreach my $zdata (@$zonelist) {
    577       my $reclist = DNSDB::getDomRecs($dbh, defrec => 'n', revrec => 'y',
    578         id => $zdata->{rdns_id}, filter => $zdata->{revnet});
     587      my $reclist = DNSDB::getDomRecs($dbh, defrec => 'n', revrec => 'y', id => $zdata->{rdns_id});
    579588      if (scalar(@$reclist) == 0) {
    580         my $type = ($args{cidr}->{isv6} ? 65282 : ($args{cidr}->masklen == 32 ? 65280 : 65283) );
    581         addRec(defrec =>'n', revrec => 'y', parent_id => $zdata->{rdns_id}, type => $type,
    582           address => "$args{cidr}", %args);
     589# nothing to do?  or do we (re)add a record based on the parent?
     590# yes, yes we do, past the close of the else
     591#        my $type = ($args{cidr}->{isv6} ? 65282 : ($args{cidr}->masklen == 32 ? 65280 : 65283) );
     592#        addRec(defrec =>'n', revrec => 'y', parent_id => $zdata->{rdns_id}, type => $type,
     593#          address => "$args{cidr}", %args);
    583594      } else {
    584595        foreach my $rec (@$reclist) {
    585           # only the composite and/or template types;  pure PTR or nontemplate composite
    586           # types are nominally impossible here.
    587           next unless $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284;
    588           updateRec(defrec =>'n', revrec => 'y', id => $rec->{record_id},
    589             parent_id => $zdata->{rdns_id}, %args);
    590           last; # only do one record.
     596          next unless $rec->{type} == 12 || $rec->{type} == 65280 || $rec->{type} == 65281 ||
     597                      $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284;
     598          # Template types are only useful when attached to a reverse zone.
     599##fixme  ..... or ARE THEY?
     600          if ($args{delforward} ||
     601              $rec->{type} == 12 || $rec->{type} == 65282 ||
     602              $rec->{type} == 65283 || $rec->{type} == 65284) {
     603            my ($code,$msg) = DNSDB::delRec($dbh, 'n', 'y', $rec->{record_id});
     604          } else {
     605            my $ret = DNSDB::downconvert($dbh, $rec->{record_id}, $DNSDB::reverse_typemap{A});
     606          }
    591607        } # foreach @$reclist
     608      } # nrecs != 0
     609      if ($args{parpatt}) {
     610        # We've just gone and axed all the records in the reverse zone.
     611        # Re-add one to match the parent if we've been given a pattern to use.
     612        addRec(defrec =>'n', revrec => 'y', parent_id => $zdata->{rdns_id},
     613               type => ($cidr->{isv6} ? 65284 : 65283),
     614               address => $zdata->{revnet}, name => $args{parpatt}, %args);
    592615      }
    593616    } # iterate zones within $cidr
Note: See TracChangeset for help on using the changeset viewer.