Changeset 328


Ignore:
Timestamp:
05/03/12 17:28:10 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Clean up several bugs in handling of NS records in revzones:

  • bad substitutions on new record
  • bad substitutions on zone add
  • funny-looking display and info/log messages
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r326 r328  
    383383  my %args = @_;
    384384
    385   # Coerce the hostname to "DOMAIN" for forward default records, "ZONE" for reverse default records,
    386   # or the intended parent zone for live records.
    387 ##fixme:  allow for delegating <subdomain>.DOMAIN?
    388   if ($args{revrec} eq 'y') {
    389     my $pname = ($args{defrec} eq 'y' ? 'ZONE' : revName($dbh,$args{id}));
    390     ${$args{host}} = $pname if ${$args{host}} ne $pname;
     385  # Check that the target of the record is within the parent.
     386  # Yes, host<->val are mixed up here;  can't see a way to avoid it.  :(
     387  if ($args{defrec} eq 'n') {
     388    # Check if IP/address/zone/"subzone" is within the parent
     389    if ($args{revrec} eq 'y') {
     390      my $tmpip = NetAddr::IP->new(${$args{val}});
     391      my $pname = revName($dbh,$args{id});
     392      return ('FAIL',"${$args{val}} not within $pname")
     393         unless _ipparent($dbh, $args{defrec}, $args{revrec}, $args{val}, $args{id}, \$tmpip);
     394      # Sub the returned thing for ZONE?  This could get stupid if you have typos...
     395      ${$args{val}} =~ s/ZONE/$tmpip->address/;
     396    } else {
     397      my $pname = domainName($dbh,$args{id});
     398      ${$args{host}} = $pname if ${$args{host}} !~ /\.$pname$/;
     399    }
    391400  } else {
    392     my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id}));
    393     ${$args{host}} = $pname if ${$args{host}} ne $pname;
     401    # Default reverse NS records should always refer to the implied parent
     402    ${$args{host}} = 'DOMAIN' if $args{revrec} eq 'n';
     403    ${$args{val}} = 'ZONE' if $args{revrec} eq 'y';
    394404  }
    395405
     
    17661776      }
    17671777
    1768       # Substitute $zone for ZONE in the hostname.
    1769       $host = _ZONE($zone, $host);
     1778      # Substitute $zone for ZONE in the hostname, but only for non-NS records.
     1779      # NS records get this substitution on the value instead.
     1780      $host = _ZONE($zone, $host) if $type != 2;
    17701781
    17711782      # Fill in the forward domain ID if we can find it, otherwise:
     
    29482959                (id => $id, type => ($revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec) )
    29492960        if $defrec eq 'n';
    2950   $logdata{entry} = "Added ".($defrec eq 'y' ? 'default record' : 'record')." '$$host $typemap{$$rectype} $$val";
     2961  $logdata{entry} = "Added ".($defrec eq 'y' ? 'default record' : 'record');
     2962  # NS records for revzones get special treatment
     2963  if ($revrec eq 'y' && $$rectype == 2) {
     2964    $logdata{entry} .= " '$$val $typemap{$$rectype} $$host";
     2965  } else {
     2966    $logdata{entry} .= " '$$host $typemap{$$rectype} $$val";
     2967  }
     2968
    29512969  $logdata{entry} .= " [distance $dist]" if $typemap{$$rectype} eq 'MX';
    29522970  $logdata{entry} .= " [priority $dist] [weight $weight] [port $port]"
     
    30833101                (id => $parid, type => ($revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec) )
    30843102        if $defrec eq 'n';
    3085   $logdata{entry} = "Updated ".($defrec eq 'y' ? 'default record' : 'record')." from\n".
    3086         "'$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}";
     3103  $logdata{entry} = "Updated ".($defrec eq 'y' ? 'default record' : 'record')." from\n";
     3104  # NS records for revzones get special treatment
     3105  if ($revrec eq 'y' && $$rectype == 2) {
     3106    $logdata{entry} .= " '$oldrec->{val} $typemap{$oldrec->{type}} $oldrec->{host}";
     3107  } else {
     3108    $logdata{entry} .= " '$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}";
     3109  }
    30873110  $logdata{entry} .= " [distance $oldrec->{distance}]" if $typemap{$oldrec->{type}} eq 'MX';
    30883111  $logdata{entry} .= " [priority $oldrec->{distance}] [weight $oldrec->{weight}] [port $oldrec->{port}]"
    30893112        if $typemap{$oldrec->{type}} eq 'SRV';
    3090   $logdata{entry} .= "', TTL $oldrec->{ttl}\nto\n'$$host $typemap{$$rectype} $$val";
     3113  $logdata{entry} .= "', TTL $oldrec->{ttl}\nto\n";
     3114  # More NS special
     3115  if ($revrec eq 'y' && $$rectype == 2) {
     3116    $logdata{entry} .= "'$$val $typemap{$$rectype} $$host";
     3117  } else {
     3118    $logdata{entry} .= "'$$host $typemap{$$rectype} $$val";
     3119  }
    30913120  $logdata{entry} .= " [distance $dist]" if $typemap{$$rectype} eq 'MX';
    30923121  $logdata{entry} .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$$rectype} eq 'SRV';
  • trunk/dns.sql

    r306 r328  
    54541       1       hostmaster.ADMINDOMAIN:ns1.ADMINDOMAIN  6       3600:900:1048576:2560   3600   
    55552       1       unused-%r.ADMINDOMAIN   65283   ZONE    3600   
    56 3       1       ZONE    2       ns2.example.com 7200    \N
    57 4       1       ZONE    2       ns1.example.com 7200    \N
     563       1       ns2.example.com 2       ZONE    7200    \N
     574       1       ns1.example.com 2       ZONE    7200    \N
    5858\.
    5959
Note: See TracChangeset for help on using the changeset viewer.