Changeset 230 for trunk


Ignore:
Timestamp:
02/09/12 14:43:08 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Fill out _validate_* subs for NS, CNAME, and MX.
Put comment in _6 (SOA) to remind me that SOA records are handled

completely separately from others

Converted A and AAAA to pass all everything except the database

handle in a hash; I realized while filling out _validate_15()
(MX) that trying to pass arguments in a defined order was going
to get stupid very fast.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r229 r230  
    242242sub _validate_1 {
    243243  my $dbh = shift;
    244   my $defrec = shift;
    245   my $revrec = shift;
    246   my $id = shift;      # parent (group_id for defrecs, rdns_id for reverse records,
    247                        # domain_id for domain records)
    248 
    249   # These next two should be references, so we can pass them back altered.  Yes, we really want to do that.
    250   my $host = shift;
    251   my $val = shift;
    252   my $addr = shift;
    253 
    254   return ('FAIL', 'Reverse zones cannot contain A records') if $revrec eq 'y';
     244
     245  my %args = @_;
     246
     247  return ('FAIL', 'Reverse zones cannot contain A records') if $args{revrec} eq 'y';
    255248
    256249  # Coerce all hostnames to end in ".DOMAIN" for group/default records,
    257250  # or the intended parent domain for live records.
    258   my $pname = ($defrec eq 'y' ? 'DOMAIN' : domainName($dbh,$id));
    259   $$host =~ s/\.*$/\.$pname/ if $$host !~ /$pname$/;
     251  my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id}));
     252  ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
    260253
    261254  # Check IP is well-formed, and that it's a v4 address
    262255  return ('FAIL',"A record must be a valid IPv4 address")
    263         unless $addr && !$addr->{isv6};
     256        unless $args{addr} && !$args{addr}->{isv6};
    264257  # coerce IP/value to normalized form for storage
    265   $$val = $addr->addr;
     258  ${$args{val}} = $args{addr}->addr;
    266259
    267260  return ('OK','OK');
     
    270263# NS record
    271264sub _validate_2 {
     265  my $dbh = shift;
     266
     267  my %args = @_;
     268
     269  # Coerce the hostname to "DOMAIN" for forward default records, "ZONE" for reverse default records,
     270  # or the intended parent zone for live records.
     271##fixme:  allow for delegating <subdomain>.DOMAIN?
     272  if ($args{revrec} eq 'y') {
     273    my $pname = ($args{defrec} eq 'y' ? 'ZONE' : revName($dbh,$args{id}));
     274    ${$args{host}} = $pname if ${$args{host}} ne $pname;
     275  } else {
     276    my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id}));
     277    ${$args{host}} = $pname if ${$args{host}} ne $pname;
     278  }
     279
     280# Let this lie for now.  Needs more magic.
     281#  # Check IP is well-formed, and that it's a v4 address
     282#  return ('FAIL',"A record must be a valid IPv4 address")
     283#       unless $addr && !$addr->{isv6};
     284#  # coerce IP/value to normalized form for storage
     285#  $$val = $addr->addr;
     286
    272287  return ('OK','OK');
    273288} # done NS record
     
    275290# CNAME record
    276291sub _validate_5 {
     292  my $dbh = shift;
     293
     294  my %args = @_;
     295
     296# Not really true, but these are only useful for delegating smaller-than-/24 IP blocks.
     297# This is fundamentally a messy operation and should really just be taken care of by the
     298# export process, not manual maintenance of the necessary records.
     299  return ('FAIL', 'Reverse zones cannot contain CNAME records') if $args{revrec} eq 'y';
     300
     301  # Coerce all hostnames to end in ".DOMAIN" for group/default records,
     302  # or the intended parent domain for live records.
     303  my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id}));
     304  ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
     305
    277306  return ('OK','OK');
    278307} # done CNAME record
     
    280309# SOA record
    281310sub _validate_6 {
     311  # Smart monkeys won't stick their fingers in here;  we have
     312  # separate dedicated routines to deal with SOA records.
    282313  return ('OK','OK');
    283314} # done SOA record
     
    290321# MX record
    291322sub _validate_15 {
     323  my $dbh = shift;
     324
     325  my %args = @_;
     326
     327# Not absolutely true but WTF use is an MX record for a reverse zone?
     328  return ('FAIL', 'Reverse zones cannot contain MX records') if $args{revrec} eq 'y';
     329
     330  return ('FAIL', "Distance is required for MX records") unless defined(${$args{dist}});
     331  ${$args{dist}} =~ s/\s*//g;
     332  return ('FAIL',"Distance is required, and must be numeric") unless ${$args{dist}} =~ /^\d+$/;
     333
     334  ${$args{fields}} = "distance,";
     335  push @{$args{vallist}}, ${$args{dist}};
     336
     337  # Coerce all hostnames to end in ".DOMAIN" for group/default records,
     338  # or the intended parent domain for live records.
     339  my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id}));
     340  ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
     341
    292342  return ('OK','OK');
    293343} # done MX record
     
    306356sub _validate_28 {
    307357  my $dbh = shift;
    308   my $defrec = shift;
    309   my $revrec = shift;
    310   my $id = shift;      # parent (group_id for defrecs, rdns_id for reverse records,
    311                        # domain_id for domain records)
    312 
    313   # These next two should be references, so we can pass them back altered.  Yes, we really want to do that.
    314   my $host = shift;
    315   my $val = shift;
    316   my $addr = shift;
    317 
    318   return ('FAIL', 'Reverse zones cannot contain AAAA records') if $revrec eq 'y';
     358
     359  my %args = @_;
     360
     361  return ('FAIL', 'Reverse zones cannot contain AAAA records') if $args{revrec} eq 'y';
    319362
    320363  # Coerce all hostnames to end in ".DOMAIN" for group/default records,
    321364  # or the intended parent domain for live records.
    322   my $pname = ($defrec eq 'y' ? 'DOMAIN' : domainName($dbh,$id));
    323   $$host =~ s/\.*$/\.$pname/ if $$host !~ /$pname$/;
     365  my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id}));
     366  ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
    324367
    325368  # Check IP is well-formed, and that it's a v6 address
    326369  return ('FAIL',"AAAA record must be a valid IPv6 address")
    327         unless $addr && $addr->{isv6};
     370        unless $args{addr} && $args{addr}->{isv6};
    328371  # coerce IP/value to normalized form for storage
    329   $$val = $addr->addr;
     372  ${$args{val}} = $args{addr}->addr;
    330373
    331374  return ('OK','OK');
Note: See TracChangeset for help on using the changeset viewer.