Changeset 249


Ignore:
Timestamp:
02/29/12 12:42:40 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Fix lurking bug in SQL tabledef from early idea for default rdns
records
Fix logic bugs in A+PTR creation in default records:

  • we should NOT blindly prepend 'ZONE.' if it's present in the value/IP
  • we should not blindly append $config{domain} if ADMINDOMAIN is in the hostname
  • we need to check for "ZONE.1", "ZONE,1", and "ZONE::1" in the "does this PTR exist?" check because otherwise we'll silently end up with duplicates

Minor tweak to call to addRec() so that changes from validation
get propagated all the way back up the call chain.
See #26

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r248 r249  
    346346          ${$args{val}} = $args{addr}->addr;
    347347        } else {
    348           ${$args{val}} =~ s/^\.*/ZONE./;
     348          ${$args{val}} =~ s/^\.*/ZONE./ unless ${$args{val}} =~ /^ZONE/;
    349349        }
    350350      } elsif (${$args{val}} =~ /[a-f:]/) {
     
    363363        ${$args{val}} = "ZONE,${$args{val}}";
    364364      }
    365       ${$args{host}} =~ s/\.*$/\.$config{domain}/ if ${$args{host}} !~ /$config{domain}$/;
     365      ${$args{host}} =~ s/\.*$/\.$config{domain}/ if ${$args{host}} !~ /(?:$config{domain}|ADMINDOMAIN)$/;
    366366    }
    367367
     
    369369# and tend to fail in the most awkward way possible.  Check and warn.
    370370# We use $val instead of $addr->addr since we may be in a defrec, and may have eg "ZONE::42" or "ZONE.12"
    371     my ($ptrcount) = $dbh->selectrow_array("SELECT count(*) FROM "._rectable($args{defrec},$args{revrec}).
    372         " WHERE val = ?", undef, ${$args{val}});
    373     return ('WARN', "PTR record for ${$args{val}} already exists;  adding another will probably not do what you want")
     371
     372    my @checkvals = (${$args{val}});
     373    if (${$args{val}} =~ /,/) {
     374      # push . and :: variants into checkvals if val has ,
     375      my $tmp;
     376      ($tmp = ${$args{val}}) =~ s/,/./;
     377      push @checkvals, $tmp;
     378      ($tmp = ${$args{val}}) =~ s/,/::/;
     379      push @checkvals, $tmp;
     380    }
     381    my $pcsth = $dbh->prepare("SELECT count(*) FROM "._rectable($args{defrec},$args{revrec})." WHERE val = ?");
     382    foreach my $checkme (@checkvals) {
     383      my $ptrcount;
     384      ($ptrcount) = $dbh->selectrow_array("SELECT count(*) FROM "._rectable($args{defrec},$args{revrec}).
     385        " WHERE val = ?", undef, ($checkme));
     386      return ('WARN', "PTR record for $checkme already exists;  adding another will probably not do what you want")
    374387        if $ptrcount;
     388    }
    375389  } else {
    376390    # Not absolutely true but only useful if you hack things up for sub-/24 v4 reverse delegations
     
    20102024  # Call the validation sub for the type requested.
    20112025  ($retcode,$retmsg) = $validators{$$rectype}($dbh, (defrec => $defrec, revrec => $revrec, id => $id,
    2012         host => \$host, rectype => $rectype, val => \$val, addr => $addr,
     2026        host => $host, rectype => $rectype, val => $val, addr => $addr,
    20132027        dist => \$dist, port => \$port, weight => \$weight,
    20142028        fields => \$fields, vallist => \@vallist) );
     
    20182032  # Set up database fields and bind parameters
    20192033  $fields .= "host,type,val,ttl,"._recparent($defrec,$revrec);
    2020   push @vallist, ($host,$$rectype,$val,$ttl,$id);
     2034  push @vallist, ($$host,$$rectype,$$val,$ttl,$id);
    20212035  my $vallen = '?'.(',?'x$#vallist);
    20222036
  • trunk/dns.cgi

    r248 r249  
    560560
    561561    my @recargs = ($dbh,$webvar{defrec},$webvar{revrec},$webvar{parentid},
    562         $webvar{name},\$webvar{type},$webvar{address},$webvar{ttl});
     562        \$webvar{name},\$webvar{type},\$webvar{address},$webvar{ttl});
    563563    if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) {
    564564      push @recargs, $webvar{distance};
  • trunk/dns.sql

    r224 r249  
    5151);
    5252
    53 COPY default_rev_records (record_id, group_id, host, "type", ip, ttl, description) FROM stdin;
     53COPY default_rev_records (record_id, group_id, host, "type", val, ttl, description) FROM stdin;
    54541       1       hostmaster.ADMINDOMAIN:ns1.ADMINDOMAIN  6       3600:900:1048576:2560   3600   
    55552       1       unused-%r.ADMINDOMAIN   65283   ZONE    3600   
Note: See TracChangeset for help on using the changeset viewer.