Changeset 653 for trunk


Ignore:
Timestamp:
08/01/14 17:14:09 (10 years ago)
Author:
Kris Deugau
Message:

/trunk

Fix up subtle bugs in handling of '@' as a hostname a la BIND. This
commit fixes add/update (validation).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r644 r653  
    597597      # Forcibly append the domain name if the hostname being added does not end with the current domain name
    598598      my $pname = $self->domainName($args{id});
    599       ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
     599      ${$args{host}} =~ s/\.*$/\.$pname/ if (${$args{host}} ne '@' && ${$args{host}} !~ /$pname$/);
    600600    }
    601601  } else {
     
    659659    # CNAMEs can not be used for parent nodes;  just leaf nodes with no other record types
    660660    # Enforce this for the zone name
    661     return ('FAIL', "The bare zone name may not be a CNAME") if ${$args{host}} eq $pname;
     661    return ('FAIL', "The bare zone name may not be a CNAME") if ${$args{host}} eq $pname || ${$args{host}} =~ /^\@/;
    662662
    663663##enhance:  Look up the passed value to see if it exists.  Ooo, fancy.
     
    742742      # Fetch the domain and append if the passed hostname isn't within it.
    743743      my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : $self->domainName($args{id}));
    744       ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
     744      ${$args{host}} =~ s/\.*$/\.$pname/ if (${$args{host}} ne '@' && ${$args{host}} !~ /$pname$/);
    745745      # Validate hostname and target for form
    746746      return ('FAIL', $errstr) if ! _check_hostname_form(${$args{host}}, ${$args{rectype}}, $args{defrec}, $args{revrec});
     
    817817    # or the intended parent domain for live records.
    818818    my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : $self->domainName($args{id}));
    819     ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
     819    ${$args{host}} =~ s/\.*$/\.$pname/ if (${$args{host}} ne '@' && ${$args{host}} !~ /$pname$/);
     820    return ('FAIL', $errstr) if ! _check_hostname_form(${$args{host}}, ${$args{rectype}}, $args{defrec}, $args{revrec});
    820821  } else {
    821822    # MX target check - IP addresses not allowed.  Must be a more or less well-formed hostname.
     
    855856    # or the intended parent domain for live records.
    856857    my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : $self->domainName($args{id}));
    857     ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
     858    ${$args{host}} =~ s/\.*$/\.$pname/ if (${$args{host}} ne '@' && ${$args{host}} !~ /$pname$/);
    858859    return ('FAIL', $errstr) if ! _check_hostname_form(${$args{host}}, ${$args{rectype}}, $args{defrec}, $args{revrec});
    859860  } else {
     
    11151116      ${$args{fields}} .= "rdns_id,";
    11161117      push @{$args{vallist}}, $revid;
    1117     }
     1118
     1119      # Coerce the hostname back to the domain;  this is so it displays and manipulates
     1120      # sanely in the reverse zone.
     1121      if (${$args{host}} eq '@') {
     1122        ${$args{host}} = $self->domainName($args{id});  # errors?  What errors?
     1123      }
     1124    } # revrec ne 'y'
    11181125
    11191126  } else {      # defrec eq 'y'
     
    12431250  if ($args{defrec} eq 'n') {
    12441251    if ($args{revrec} eq 'n') {
    1245       ($code,$msg) = $self->_validate_1(%args) if ${$args{rectype}} == 65280;
    1246       ($code,$msg) = $self->_validate_28(%args) if ${$args{rectype}} == 65281;
    1247       return ($code,$msg) if $code eq 'FAIL';
     1252
     1253      # Coerce all hostnames to end in ".DOMAIN" for group/default records,
     1254      # or the intended parent domain for live records.
     1255      my $pname = $self->domainName($args{id});
     1256      ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
     1257
     1258      # check for form;  note this checks both normal and "other" hostnames.
     1259      return ('FAIL', $errstr)
     1260        if !_check_hostname_form(${$args{host}}, ${$args{rectype}}, $args{defrec}, $args{revrec});
    12481261
    12491262      # Check if the requested reverse zone exists - note, an IP fragment won't
     
    16321645    # we don't actually need to test with the real IP passed;  that saves a bit of fiddling.
    16331646    _template4_expand(\$tmphost, '10.10.10.10');
    1634     if ($tmphost =~ /\%/) {
     1647    if ($tmphost =~ /\%/ || lc($tmphost) !~ /^(?:\*\.)?(?:[0-9a-z_.-]+)$/) {
    16351648      $errstr = "Invalid template $hname";
    16361649      return;
Note: See TracChangeset for help on using the changeset viewer.