Changeset 602


Ignore:
Timestamp:
03/28/14 15:22:03 (10 years ago)
Author:
Kris Deugau
Message:

/trunk

Review and fix up handling of "any record, any zone" in AXFR import.
See #53.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r601 r602  
    48024802      my $logfrag = '';
    48034803
     4804      # Collect some record parts
    48044805      my $type = $rr->type;
    48054806      my $host = $rr->name;
    48064807      my $ttl = ($args{newttl} ? $args{newttl} : $rr->ttl);     # allow force-override TTLs
    48074808
     4809      # Info flags for SOA and NS records
    48084810      $soaflag = 1 if $type eq 'SOA';
    48094811      $nsflag = 1 if $type eq 'NS';
     
    48284830# processing depending on the record.  le sigh.
    48294831
     4832# do the initial processing as if the record was in a forward zone.  If we're
     4833# doing a revzone, we can flip $host and $val as needed, once, after this
     4834# monster if-elsif-...-elsif-else.  This actually simplifies things a lot.
     4835
    48304836##fixme:  what record types other than TXT can/will have >255-byte payloads?
    48314837
     
    48344840      } elsif ($type eq 'NS') {
    48354841# hmm.  should we warn here if subdomain NS'es are left alone?
    4836         if ($rev eq 'y') {
    4837           # revzones have records more or less reversed from forward zones.
    4838           my ($tmpcode,$tmpmsg) = _zone2cidr($host);
    4839           die "Error converting NS record: $tmpmsg\n" if $tmpcode eq 'FAIL';    # hmm.  may not make sense...
    4840           next if ($args{rwns} && ($tmpmsg eq "$cidr"));
    4841           $val = "$tmpmsg";
    4842           $host = $rr->nsdname;
    4843           $logfrag = "Added record '$val $type $host', TTL $ttl";
    4844 # Tag and preserve.  For now this is commented for a no-op, but we have Ideas for
    4845 # another custom storage type ("DELEGATE") that will use these subzone-delegation records
    4846 #if ($val ne "$cidr") {
    4847 #  push @{$suboct{$val}{ns}}, $host;
    4848 #}
    4849         } else {
    4850           next if ($args{rwns} && ($rr->name eq $zone));
    4851           $val = $rr->nsdname;
    4852         }
     4842        next if ($args{rwns} && ($host eq $zone));
     4843        $val = $rr->nsdname;
    48534844        $nsflag = 1;
    48544845      } elsif ($type eq 'CNAME') {
    4855         if ($rev eq 'y') {
    4856           # hmm.  do we even want to bother with storing these at this level?  Sub-octet delegation
    4857           # by CNAME is essentially a record-publication hack, and we want to just represent the
    4858           # "true" logical intentions as far down the stack as we can from the UI.
    4859           ($host,$val) = _revswap($host,$rr->cname);
    4860           $logfrag = "Added record '$val $type $host', TTL $ttl";
    4861 # Tag and preserve in case we want to commit them as-is later, but mostly we don't care.
    4862 # Commented pending actually doing something with possibly new type DELEGATE
    4863 #my $tmprev = $host;
    4864 #$tmprev =~ s/^\d+\.//;
    4865 #($code,$tmprev) = _zone2cidr($tmprev);
    4866 #push @{$suboct{"$tmprev"}{cname}}, $val;
    4867           # Silently skip CNAMEs in revzones.
    4868           next;
    4869         } else {
    4870           $val = $rr->cname;
    4871         }
     4846        $val = $rr->cname;
    48724847      } elsif ($type eq 'SOA') {
    48734848        next if $args{rwsoa};
     
    48764851        $soaflag = 1;
    48774852      } elsif ($type eq 'PTR') {
    4878         ($host,$val) = _revswap($host,$rr->ptrdname);
    4879         $logfrag = "Added record '$val $type $host', TTL $ttl";
    4880         # hmm.  PTR records should not be in forward zones.
     4853        $val = $rr->ptrdname;
    48814854      } elsif ($type eq 'MX') {
    48824855        $val = $rr->exchange;
     
    48914864# details as far down the stack as we can)
    48924865# NB:  this may turn out to be more troublesome if we ever have need of >512-byte TXT records.
    4893         if ($rev eq 'y') {
    4894           ($host,$val) = _revswap($host,$rr->txtdata);
    4895           $logfrag = "Added record '$val $type $host', TTL $ttl";
    4896         } else {
    4897           $val = $rr->txtdata;
    4898         }
     4866        $val = $rr->txtdata;
    48994867      } elsif ($type eq 'SPF') {
    49004868##fixme: and the same caveat here, since it is apparently a clone of ::TXT
     
    49164884        $warnmsg .= "Unusual record ".$rr->name." ($type) found\n";
    49174885      }
     4886
     4887      if ($rev eq 'y' && $type ne 'SOA') {
     4888        # up to this point we haven't meddled with the record's hostname part or rdata part.
     4889        # for reverse records, (except SOA) we must swap the two.
     4890        $host = $val;
     4891        $val = $rr->name;
     4892        my ($tmpcode,$tmpmsg) = _zone2cidr($val);
     4893        if ($tmpcode eq 'FAIL') {
     4894          # $val did not have a valid IP value.  It's syntactically valid but WTF?
     4895          $warnmsg .= "Suspect record '".$rr->string."' may not be imported correctly: $tmpmsg\n";
     4896        } else {
     4897          # $val has a valid IP value.  See if we can store it as that IP value.
     4898          # Note we're enumerating do-nothing cases for clarity.
     4899##enhance:  this is where we will implement the more subtle variations on #53
     4900          if ($type ne 'PTR' && $type ne 'NS' && $type ne 'CNAME' && $type ne 'TXT') {
     4901            # case: the record is "weird" - ie, not a PTR, NS, CNAME, or TXT
     4902            # $warnmsg .= "Discarding suspect record '".$rr->string."'\n" if $self->{strict} eq 'full';
     4903          } elsif ($type eq 'PTR' && $tmpmsg->masklen != 32 && $tmpmsg->masklen != 128) {
     4904            # case: PTR with netblock value, not IP value
     4905            # eg, "@ PTR foo" in zone f.e.e.b.d.a.e.d.ip6.arpa should not be
     4906            # stored/displayed as dead:beef::/32 PTR foo
     4907
     4908## hrm.  WTF is this case for, anyway?  Needs testing to check the logic.
     4909#          } elsif ( ($type eq 'PTR' || $type eq 'NS' || $type eq 'CNAME' || $type eq 'TXT') &&
     4910#                    ($tmpmsg->masklen != $cidr->masklen)
     4911#                  ) {
     4912#            # leave $val as-is if the record is "normal" (a PTR, NS, CNAME, or TXT),
     4913#            # and the mask does not match the zone
     4914#$warnmsg .= "WTF case: $host $type $val\n";
     4915#            # $warnmsg .= "Discarding suspect record '".$rr->string."'\n" if $self->{strict} eq 'full';
     4916
     4917          } else {
     4918            $val = $tmpmsg;
     4919            $val =~ s/\/(?:32|128)$//;  # automagically converts $val back to a string before s///
     4920            #$val =~ s/:0$//g;
     4921          }
     4922        }
     4923        # magic?  convert * records to PTR template (not sure this actually makes sense)
     4924        #if ($val =~ /^\*/) {
     4925        #  $val =~ s/\*\.//;
     4926        #  ($tmpcode,$tmpmsg) = _zone2cidr($val);
     4927        #  if ($tmpcode eq 'FAIL') {
     4928        #    $val = "*.$val";
     4929        #    $warnmsg .= "Suspect record '".$rr->string."' may not be converted to PTR template correctly: $tmpmsg\n";
     4930        #  } else {
     4931        #    $type = 'PTR template';
     4932        #    $val = $tmpmsg; if $tmp
     4933        #    $val =~ s/\/(?:32|128)$//;  # automagically converts $val back to a string before s///
     4934        #  }
     4935        #}
     4936      } # non-SOA revrec $host/$val inversion and munging
    49184937
    49194938      my $logentry = "[AXFR ".($rev eq 'n' ? $zone : $cidr)."] ";
     
    49835002        $logentry .= $logfrag;
    49845003      } else {
    4985         $logentry .= "Added record '$host $type";
     5004        $logentry .= "Added record '".($rev eq 'y' ? $val : $host)." $type";
    49865005        $logentry .= " [distance $distance]" if $type eq 'MX';
    49875006        $logentry .= " [priority $distance] [weight $weight] [port $port]" if $type eq 'SRV';
    4988         $logentry .= " $val', TTL $ttl";
     5007        $logentry .= " ".($rev eq 'y' ? $host : $val)."', TTL $ttl";
    49895008      }
    49905009      $self->_log(group_id => $group, domain_id => $domain_id, rdns_id => $rdns_id, entry => $logentry);
Note: See TracChangeset for help on using the changeset viewer.