- Timestamp:
- 03/12/13 12:12:23 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r466 r467 390 390 391 391 ## All of these subs take substantially the same arguments: 392 # a database handle393 392 # a hash containing at least the following keys: 394 393 # - defrec (default/live flag) … … 404 403 # A record 405 404 sub _validate_1 { 406 my $dbh = shift; 405 my $self = shift; 406 my $dbh = $self->{dbh}; 407 407 408 408 my %args = @_; … … 412 412 # Coerce all hostnames to end in ".DOMAIN" for group/default records, 413 413 # 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})); 415 415 ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/; 416 416 … … 429 429 # NS record 430 430 sub _validate_2 { 431 my $dbh = shift; 431 my $self = shift; 432 my $dbh = $self->{dbh}; 432 433 433 434 my %args = @_; … … 439 440 if ($args{revrec} eq 'y') { 440 441 my $tmpip = NetAddr::IP->new(${$args{val}}); 441 my $pname = revName($dbh,$args{id});442 my $pname = $self->revName($args{id}); 442 443 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); 444 445 # Sub the returned thing for ZONE? This could get stupid if you have typos... 445 446 ${$args{val}} =~ s/ZONE/$tmpip->address/; 446 447 } else { 447 my $pname = domainName($dbh,$args{id});448 my $pname = $self->domainName($args{id}); 448 449 ${$args{host}} = $pname if ${$args{host}} !~ /\.$pname$/; 449 450 } … … 466 467 # CNAME record 467 468 sub _validate_5 { 468 my $dbh = shift; 469 my $self = shift; 470 my $dbh = $self->{dbh}; 469 471 470 472 my %args = @_; … … 477 479 # Coerce all hostnames to end in ".DOMAIN" for group/default records, 478 480 # 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})); 480 482 ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/; 481 483 … … 492 494 # PTR record 493 495 sub _validate_12 { 494 my $dbh = shift; 496 my $self = shift; 497 my $dbh = $self->{dbh}; 495 498 496 499 my %args = @_; … … 498 501 if ($args{revrec} eq 'y') { 499 502 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}); 502 505 ${$args{val}} = $args{addr}->addr; 503 506 } else { … … 572 575 # MX record 573 576 sub _validate_15 { 574 my $dbh = shift; 577 my $self = shift; 578 my $dbh = $self->{dbh}; 575 579 576 580 my %args = @_; … … 588 592 # Coerce all hostnames to end in ".DOMAIN" for group/default records, 589 593 # 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})); 591 595 ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/; 592 596 … … 615 619 # AAAA record 616 620 sub _validate_28 { 617 my $dbh = shift; 621 my $self = shift; 622 my $dbh = $self->{dbh}; 618 623 619 624 my %args = @_; … … 623 628 # Coerce all hostnames to end in ".DOMAIN" for group/default records, 624 629 # 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})); 626 631 ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/; 627 632 … … 637 642 # SRV record 638 643 sub _validate_33 { 639 my $dbh = shift; 644 my $self = shift; 645 my $dbh = $self->{dbh}; 640 646 641 647 my %args = @_; … … 663 669 # Coerce all hostnames to end in ".DOMAIN" for group/default records, 664 670 # 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})); 666 672 ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/; 667 673 … … 673 679 # A+PTR record. With a very little bit of magic we can also use this sub to validate AAAA+PTR. Whee! 674 680 sub _validate_65280 { 675 my $dbh = shift; 681 my $self = shift; 682 my $dbh = $self->{dbh}; 676 683 677 684 my %args = @_; … … 684 691 685 692 if ($args{revrec} eq 'y') { 686 ($code,$msg) = _validate_12($dbh,%args);693 ($code,$msg) = $self->_validate_12(%args); 687 694 return ($code,$msg) if $code eq 'FAIL'; 688 695 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 689 703 # 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}}))) { 691 705 my $addmsg = "Record ".($args{update} ? 'updated' : 'added'). 692 706 " as PTR instead of $typemap{${$args{rectype}}}; domain not found for ${$args{host}}"; … … 702 716 703 717 } 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; 706 720 return ($code,$msg) if $code eq 'FAIL'; 707 721 … … 752 766 } else { # defrec eq 'y' 753 767 if ($args{revrec} eq 'y') { 754 ($code,$msg) = _validate_12($dbh,%args);768 ($code,$msg) = $self->_validate_12(%args); 755 769 return ($code,$msg) if $code eq 'FAIL'; 756 770 if (${$args{rectype}} == 65280) { … … 784 798 # PTR template record 785 799 sub _validate_65282 { 786 my $dbh = shift; 800 my $self = shift; 801 my $dbh = $self->{dbh}; 787 802 788 803 my %args = @_; … … 791 806 if ($args{revrec} eq 'y') { 792 807 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}); 795 810 ##fixme: warn if $args{val} is not /31 or larger block? 796 811 ${$args{val}} = "$args{addr}"; … … 863 878 # A+PTR template record 864 879 sub _validate_65283 { 865 my $dbh = shift; 880 my $self = shift; 881 my $dbh = $self->{dbh}; 866 882 867 883 my %args = @_; … … 873 889 if ($args{defrec} eq 'n') { 874 890 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; 877 893 return ($code,$msg) if $code eq 'FAIL'; 878 894 … … 896 912 897 913 } 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}); 900 916 ${$args{val}} = "$args{addr}"; 901 917 902 if (!(${$args{domid}} = _hostparent($dbh,${$args{host}}))) {918 if (!(${$args{domid}} = $self->_hostparent(${$args{host}}))) { 903 919 my $addmsg = "Record ".($args{update} ? 'updated' : 'added'). 904 920 " as PTR template instead of $typemap{${$args{rectype}}}; domain not found for ${$args{host}}"; … … 915 931 916 932 } else { 917 my ($code,$msg) = _validate_65282($dbh,%args);933 my ($code,$msg) = $self->_validate_65282(%args); 918 934 return ($code, $msg) if $code eq 'FAIL'; 919 935 # get domain, check against ${$args{name}} … … 932 948 # for delegating IPv4 sub-/24 reverse blocks 933 949 sub _validate_65285 { 934 my $dbh = shift; 950 my $self = shift; 951 my $dbh = $self->{dbh}; 935 952 936 953 my %args = @_; … … 944 961 if ($args{revrec} eq 'y') { 945 962 my $tmpip = NetAddr::IP->new(${$args{val}}); 946 my $pname = revName($dbh,$args{id});963 my $pname = $self->revName($args{id}); 947 964 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); 949 966 # Normalize 950 967 ${$args{val}} = "$tmpip"; 951 968 } else { 952 my $pname = domainName($dbh,$args{id});969 my $pname = $self->domainName($args{id}); 953 970 ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/; 954 971 }
Note:
See TracChangeset
for help on using the changeset viewer.