Changeset 467 for trunk


Ignore:
Timestamp:
03/12/13 12:12:23 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Object conversion of DNSDB.pm, 3 of <mumble>. See #11.

  • internal record data validation subs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r466 r467  
    390390
    391391## All of these subs take substantially the same arguments:
    392 # a database handle
    393392# a hash containing at least the following keys:
    394393#  - defrec (default/live flag)
     
    404403# A record
    405404sub _validate_1 {
    406   my $dbh = shift;
     405  my $self = shift;
     406  my $dbh = $self->{dbh};
    407407
    408408  my %args = @_;
     
    412412  # Coerce all hostnames to end in ".DOMAIN" for group/default records,
    413413  # or the intended parent domain for live records.
    414   my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id}));
     414  my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : $self->domainName($args{id}));
    415415  ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
    416416
     
    429429# NS record
    430430sub _validate_2 {
    431   my $dbh = shift;
     431  my $self = shift;
     432  my $dbh = $self->{dbh};
    432433
    433434  my %args = @_;
     
    439440    if ($args{revrec} eq 'y') {
    440441      my $tmpip = NetAddr::IP->new(${$args{val}});
    441       my $pname = revName($dbh,$args{id});
     442      my $pname = $self->revName($args{id});
    442443      return ('FAIL',"${$args{val}} not within $pname")
    443          unless _ipparent($dbh, $args{defrec}, $args{revrec}, $args{val}, $args{id}, \$tmpip);
     444         unless $self->_ipparent($args{defrec}, $args{revrec}, $args{val}, $args{id}, \$tmpip);
    444445      # Sub the returned thing for ZONE?  This could get stupid if you have typos...
    445446      ${$args{val}} =~ s/ZONE/$tmpip->address/;
    446447    } else {
    447       my $pname = domainName($dbh,$args{id});
     448      my $pname = $self->domainName($args{id});
    448449      ${$args{host}} = $pname if ${$args{host}} !~ /\.$pname$/;
    449450    }
     
    466467# CNAME record
    467468sub _validate_5 {
    468   my $dbh = shift;
     469  my $self = shift;
     470  my $dbh = $self->{dbh};
    469471
    470472  my %args = @_;
     
    477479  # Coerce all hostnames to end in ".DOMAIN" for group/default records,
    478480  # or the intended parent domain for live records.
    479   my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id}));
     481  my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : $self->domainName($args{id}));
    480482  ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
    481483
     
    492494# PTR record
    493495sub _validate_12 {
    494   my $dbh = shift;
     496  my $self = shift;
     497  my $dbh = $self->{dbh};
    495498
    496499  my %args = @_;
     
    498501  if ($args{revrec} eq 'y') {
    499502    if ($args{defrec} eq 'n') {
    500       return ('FAIL', "IP or IP fragment ${$args{val}} is not within ".revName($dbh, $args{id}))
    501         unless _ipparent($dbh, $args{defrec}, $args{revrec}, $args{val}, $args{id}, \$args{addr});
     503      return ('FAIL', "IP or IP fragment ${$args{val}} is not within ".$self->revName($args{id}))
     504        unless $self->_ipparent($args{defrec}, $args{revrec}, $args{val}, $args{id}, \$args{addr});
    502505      ${$args{val}} = $args{addr}->addr;
    503506    } else {
     
    572575# MX record
    573576sub _validate_15 {
    574   my $dbh = shift;
     577  my $self = shift;
     578  my $dbh = $self->{dbh};
    575579
    576580  my %args = @_;
     
    588592  # Coerce all hostnames to end in ".DOMAIN" for group/default records,
    589593  # or the intended parent domain for live records.
    590   my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id}));
     594  my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : $self->domainName($args{id}));
    591595  ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
    592596
     
    615619# AAAA record
    616620sub _validate_28 {
    617   my $dbh = shift;
     621  my $self = shift;
     622  my $dbh = $self->{dbh};
    618623
    619624  my %args = @_;
     
    623628  # Coerce all hostnames to end in ".DOMAIN" for group/default records,
    624629  # or the intended parent domain for live records.
    625   my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id}));
     630  my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : $self->domainName($args{id}));
    626631  ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
    627632
     
    637642# SRV record
    638643sub _validate_33 {
    639   my $dbh = shift;
     644  my $self = shift;
     645  my $dbh = $self->{dbh};
    640646
    641647  my %args = @_;
     
    663669  # Coerce all hostnames to end in ".DOMAIN" for group/default records,
    664670  # or the intended parent domain for live records.
    665   my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id}));
     671  my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : $self->domainName($args{id}));
    666672  ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
    667673
     
    673679# A+PTR record.  With a very little bit of magic we can also use this sub to validate AAAA+PTR.  Whee!
    674680sub _validate_65280 {
    675   my $dbh = shift;
     681  my $self = shift;
     682  my $dbh = $self->{dbh};
    676683
    677684  my %args = @_;
     
    684691
    685692    if ($args{revrec} eq 'y') {
    686       ($code,$msg) = _validate_12($dbh, %args);
     693      ($code,$msg) = $self->_validate_12(%args);
    687694      return ($code,$msg) if $code eq 'FAIL';
    688695
     696      # check A+PTR is really v4
     697      return ('FAIL',"$typemap{${$args{rectype}}} record must be a valid IPv4 address")
     698        if ${$args{rectype}} == 65280 && $args{addr}->{isv6};
     699      # check AAAA+PTR is really v6
     700      return ('FAIL',"$typemap{${$args{rectype}}} record must be a valid IPv6 address")
     701        if ${$args{rectype}} == 65281 && !$args{addr}->{isv6};
     702
    689703      # Check if the reqested domain exists.  If not, coerce the type down to PTR and warn.
    690       if (!(${$args{domid}} = _hostparent($dbh, ${$args{host}}))) {
     704      if (!(${$args{domid}} = $self->_hostparent(${$args{host}}))) {
    691705        my $addmsg = "Record ".($args{update} ? 'updated' : 'added').
    692706                " as PTR instead of $typemap{${$args{rectype}}};  domain not found for ${$args{host}}";
     
    702716
    703717    } else {
    704       ($code,$msg) = _validate_1($dbh, %args) if ${$args{rectype}} == 65280;
    705       ($code,$msg) = _validate_28($dbh, %args) if ${$args{rectype}} == 65281;
     718      ($code,$msg) = $self->_validate_1(%args) if ${$args{rectype}} == 65280;
     719      ($code,$msg) = $self->_validate_28(%args) if ${$args{rectype}} == 65281;
    706720      return ($code,$msg) if $code eq 'FAIL';
    707721
     
    752766  } else {      # defrec eq 'y'
    753767    if ($args{revrec} eq 'y') {
    754       ($code,$msg) = _validate_12($dbh, %args);
     768      ($code,$msg) = $self->_validate_12(%args);
    755769      return ($code,$msg) if $code eq 'FAIL';
    756770      if (${$args{rectype}} == 65280) {
     
    784798# PTR template record
    785799sub _validate_65282 {
    786   my $dbh = shift;
     800  my $self = shift;
     801  my $dbh = $self->{dbh};
    787802
    788803  my %args = @_;
     
    791806  if ($args{revrec} eq 'y') {
    792807    if ($args{defrec} eq 'n') {
    793       return ('FAIL', "Template block ${$args{val}} is not within ".revName($dbh, $args{id}))
    794         unless _ipparent($dbh, $args{defrec}, $args{revrec}, $args{val}, $args{id}, \$args{addr});
     808      return ('FAIL', "Template block ${$args{val}} is not within ".$self->revName($args{id}))
     809        unless $self->_ipparent($args{defrec}, $args{revrec}, $args{val}, $args{id}, \$args{addr});
    795810##fixme:  warn if $args{val} is not /31 or larger block?
    796811      ${$args{val}} = "$args{addr}";
     
    863878# A+PTR template record
    864879sub _validate_65283 {
    865   my $dbh = shift;
     880  my $self = shift;
     881  my $dbh = $self->{dbh};
    866882
    867883  my %args = @_;
     
    873889  if ($args{defrec} eq 'n') {
    874890    if ($args{revrec} eq 'n') {
    875       ($code,$msg) = _validate_1($dbh, %args) if ${$args{rectype}} == 65280;
    876       ($code,$msg) = _validate_28($dbh, %args) if ${$args{rectype}} == 65281;
     891      ($code,$msg) = $self->_validate_1(%args) if ${$args{rectype}} == 65280;
     892      ($code,$msg) = $self->_validate_28(%args) if ${$args{rectype}} == 65281;
    877893      return ($code,$msg) if $code eq 'FAIL';
    878894
     
    896912
    897913    } else {
    898       return ('FAIL', "IP or IP fragment ${$args{val}} is not within ".revName($dbh, $args{id}))
    899         unless _ipparent($dbh, $args{defrec}, $args{revrec}, $args{val}, $args{id}, \$args{addr});
     914      return ('FAIL', "IP or IP fragment ${$args{val}} is not within ".$self->revName($args{id}))
     915        unless $self->_ipparent($args{defrec}, $args{revrec}, $args{val}, $args{id}, \$args{addr});
    900916      ${$args{val}} = "$args{addr}";
    901917
    902       if (!(${$args{domid}} = _hostparent($dbh, ${$args{host}}))) {
     918      if (!(${$args{domid}} = $self->_hostparent(${$args{host}}))) {
    903919        my $addmsg = "Record ".($args{update} ? 'updated' : 'added').
    904920                " as PTR template instead of $typemap{${$args{rectype}}};  domain not found for ${$args{host}}";
     
    915931
    916932  } else {
    917     my ($code,$msg) = _validate_65282($dbh, %args);
     933    my ($code,$msg) = $self->_validate_65282(%args);
    918934    return ($code, $msg) if $code eq 'FAIL';
    919935    # get domain, check against ${$args{name}}
     
    932948# for delegating IPv4 sub-/24 reverse blocks
    933949sub _validate_65285 {
    934   my $dbh = shift;
     950  my $self = shift;
     951  my $dbh = $self->{dbh};
    935952
    936953  my %args = @_;
     
    944961    if ($args{revrec} eq 'y') {
    945962      my $tmpip = NetAddr::IP->new(${$args{val}});
    946       my $pname = revName($dbh,$args{id});
     963      my $pname = $self->revName($args{id});
    947964      return ('FAIL',"${$args{val}} not within $pname")
    948          unless _ipparent($dbh, $args{defrec}, $args{revrec}, $args{val}, $args{id}, \$tmpip);
     965         unless $self->_ipparent($args{defrec}, $args{revrec}, $args{val}, $args{id}, \$tmpip);
    949966      # Normalize
    950967      ${$args{val}} = "$tmpip";
    951968    } else {
    952       my $pname = domainName($dbh,$args{id});
     969      my $pname = $self->domainName($args{id});
    953970      ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
    954971    }
Note: See TracChangeset for help on using the changeset viewer.