Changeset 616


Ignore:
Timestamp:
04/23/14 16:34:03 (10 years ago)
Author:
Kris Deugau
Message:

/trunk

Update _validate_2() to handle any-record-in-any-zone, and handle
semigibberish reverse zone records that are syntactically valid.

See #53.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r615 r616  
    551551  my %args = @_;
    552552
     553  # NS target check - IP addresses not allowed.  Must be a more or less well-formed hostname.
     554  if ($args{revrec} eq 'y') {
     555    return ('FAIL', "NS records cannot point directly to an IP address")
     556      if ${$args{host}} =~ /^(?:[\d.]+|[0-9a-fA-F:]+)$/;
     557##enhance:  Look up the passed value to see if it exists.  Ooo, fancy.
     558    return ('FAIL', $errstr) if ! _check_hostname_form(${$args{host}}, ${$args{rectype}}, $args{defrec}, $args{revrec});
     559  } else {
     560    return ('FAIL', "NS records cannot point directly to an IP address")
     561      if ${$args{val}} =~ /^(?:[\d.]+|[0-9a-fA-F:]+)$/;
     562##enhance:  Look up the passed value to see if it exists.  Ooo, fancy.
     563    return ('FAIL', $errstr) if ! _check_hostname_form(${$args{val}}, ${$args{rectype}}, $args{defrec}, $args{revrec});
     564  }
     565
    553566  # Check that the target of the record is within the parent.
    554   # Yes, host<->val are mixed up here;  can't see a way to avoid it.  :(
    555567  if ($args{defrec} eq 'n') {
    556568    # Check if IP/address/zone/"subzone" is within the parent
    557569    if ($args{revrec} eq 'y') {
    558       my $tmpip = NetAddr::IP->new(${$args{val}});
    559       my $pname = $self->revName($args{id});
    560       return ('FAIL',"${$args{val}} not within $pname")
    561          unless $self->_ipparent($args{defrec}, $args{revrec}, $args{val}, $args{id}, \$tmpip);
    562       # Sub the returned thing for ZONE?  This could get stupid if you have typos...
    563       ${$args{val}} =~ s/ZONE/$tmpip->address/;
     570      # Get the revzone, so we can see if ${$args{val}} is in that zone
     571      my $revzone = new NetAddr::IP $self->revName($args{id}, 'y');
     572
     573      # Note the NS record may or may not be for the zone itself, it may be a pointer for a subzone
     574      return ('FAIL', $errstr) if !$self->_inrev($args{val}, $revzone);
     575
     576      # ${$args{val}} is either a valid IP or a string ending with the .arpa zone name;
     577      # now check if it's a well-formed FQDN
     578##enhance or ##fixme
     579# convert well-formed .arpa names to IP addresses to match old "strict" validation design
     580      return ('FAIL', $errstr) if ! _check_hostname_form(${$args{val}}, ${$args{rectype}}, $args{defrec}, $args{revrec}) &&
     581        ${$args{val}} =~ /\.arpa$/;
    564582    } else {
     583      # Forcibly append the domain name if the hostname being added does not end with the current domain name
    565584      my $pname = $self->domainName($args{id});
    566       ${$args{host}} = $pname if ${$args{host}} !~ /\.$pname$/;
     585      ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
    567586    }
    568587  } else {
    569     # Default reverse NS records should always refer to the implied parent
    570     ${$args{host}} = 'DOMAIN' if $args{revrec} eq 'n';
    571     ${$args{val}} = 'ZONE' if $args{revrec} eq 'y';
    572   }
    573 
    574 # Let this lie for now.  Needs more magic.
    575 #  # Check IP is well-formed, and that it's a v4 address
    576 #  return ('FAIL',"A record must be a valid IPv4 address")
    577 #       unless $addr && !$addr->{isv6};
    578 #  # coerce IP/value to normalized form for storage
    579 #  $$val = $addr->addr;
     588    # Default reverse NS records should always refer to the implied parent. 
     589    if ($args{revrec} eq 'y') {
     590      ${$args{val}} = 'ZONE';
     591    } else {
     592      ${$args{host}} = 'DOMAIN';
     593    }   
     594  }
    580595
    581596  return ('OK','OK');
Note: See TracChangeset for help on using the changeset viewer.