Ignore:
Timestamp:
12/11/25 15:32:35 (24 hours ago)
Author:
Kris Deugau
Message:

/branches/cname-collision

First pass/chunk for a CNAME-collision sub
Comment much-simplified local check in CNAME validation sub, add prelimiary call to new sub
See #72.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/cname-collision/DNSDB.pm

    r912 r937  
    612612##
    613613
     614# Check for name collisions relating to CNAMEs.  Needs to be called from all other validators.
     615sub _cname_collision {
     616#  my $self = shift;
     617#  my $dbh = $self->{dbh};
     618#
     619#  my %args = @_;
     620my ($hcheck,$defrec,$revrec) = @_;
     621
     622#  my $hcheck = ($args{revrec} eq 'y' ? ${$args{val}} : ${$args{host}});
     623  my $hfield = ($args{revrec} eq 'y' ? 'val' : 'host');
     624#my $hcheck = $hname;
     625
     626  # $hcheck should be normalized by the time this sub is called.  Convert to the formal .arpa name for error reporting in reverse zones.
     627  my $arpaname = '';
     628  if ($revrec eq 'y') {
     629    $arpaname = NetAddr::IP->new($hcheck);
     630##fixme:  more voodoo if global and/or per-user ARPA display mode flag set this way or that
     631    $arpaname = _ZONE($arpaname, 'ZONE', 'r', '.').($arpaname->{isv6} ? '.ip6.arpa' : '.in-addr.arpa');
     632  }
     633
     634#  my $ret = 'OK';
     635#  my $msg = 'OK';
     636
     637  if ($args{type} == 5) {
     638    # First, check for non-CNAME collisions.
     639    my @t = $dbh->selectrow_array("SELECT count(*) FROM "._rectable($args{defrec}, $args{revrec}).
     640        " WHERE "._recparent($args{defrec}, $args{revrec})." = ? AND type <> 5 AND $hfield = ?",
     641        undef, $args{id}, $hcheck);
     642    if ($t[0] > 0) {
     643      $errstr = "One or more non-CNAME records already exist for ".($revrec eq 'y' ? $arpaname : $hcheck).
     644        ".  CNAME records cannot use the same name as other records.";
     645      return;
     646    }
     647  }
     648
     649  # Second, check for multiple CNAMEs
     650  my @t = $dbh->selectrow_array("SELECT count(*) FROM "._rectable($args{defrec}, $args{revrec}).
     651        " WHERE "._recparent($args{defrec}, $args{revrec})." = ? AND type = 5 AND $hfield = ?",
     652        undef, $args{id}, $hcheck);
     653  if ($t[0] > 1) {
     654    $errstr = "There is already a CNAME present for ".($revrec eq 'y' ? $arpaname : $hcheck).
     655        ".  Only one CNAME may be present for a given name.";
     656    return;
     657  }
     658
     659#  } else {
     660#    # Non-CNAME records will only collide with CNAMEs
     661#    my @t = $dbh->selectrow_array("SELECT count(*) FROM "._rectable($args{defrec}, $args{revrec}).
     662#       " WHERE "._recparent($args{defrec}, $args{revrec})." = ? AND type = 5 AND $hfield = ?",
     663#       undef, $args{id}, $hcheck);
     664#    return ('FAIL', "There is already a CNAME present for $hcheck.  Only one CNAME may be present for a given name.")
     665#       if $t[0] > 1;
     666#  }
     667  return 1;
     668
     669} # _cname_collision()
     670
    614671## All of these subs take substantially the same arguments:
    615672# a hash containing at least the following keys:
     
    808865      return ('FAIL', "The bare zone name may not be a CNAME") if ${$args{host}} eq $pname || ${$args{host}} =~ /^\@/;
    809866
    810 ##enhance:  Look up the passed value to see if it exists.  Ooo, fancy.
     867#      # Check for hostnames matching new name
     868#      my @t = $dbh->selectrow_array("SELECT count(*) FROM records WHERE domain_id = ? AND type <> ? AND host = ?",
     869#       undef, $args{id}, 5, ${$args{host}});
     870#      return ('FAIL', "One or more existing records already use ${$args{host}}.  CNAME records cannot use the same name as other records.")
     871#       if $t[0] > 0;
     872
    811873      return ('FAIL', $errstr) if ! _check_hostname_form(${$args{val}}, ${$args{rectype}}, $args{defrec}, $args{revrec});
     874
     875my ($code,$msg) = self->_cname_collision(%args);
     876
    812877    } # $zname !~ .rpz
    813878  } # revzone eq 'n'
Note: See TracChangeset for help on using the changeset viewer.