| 1 | # utility routines to be shared amongst the various classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Copyright Karthik Krishnamurthy <karthik.k@extremix.net> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | package Unix::Conf::Bind8::Conf::Lib; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | our @ISA = qw (Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # __valid_rlim | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | our @EXPORT = qw ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | __valid_element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | __valid_ipaddress | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | __valid_port | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | __valid_ipprefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | __valid_yesno | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | __valid_forward | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | __valid_checknames | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | __valid_category | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | __valid_facility | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | __valid_severity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | __valid_number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | __valid_sizespec | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | __valid_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | __valid_transfer_format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # used for validating resource limit type options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | #sub __valid_rlim | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | #{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # my $num = qr/\d+[KkMmGg]?/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # return ($_[0] =~ /^($num|'unlimited'|'default')$/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | #} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # ACL element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | sub __valid_element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__valid_element: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my ($confds, $element) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # if an Acl object, return true. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | ref ($element) && UNIVERSAL::isa ($element, 'Unix::Conf::Bind8::Conf::Acl') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $element and UNIVERSAL::isa($element, "Unix::Conf::Bind8::Conf::Acl")
MC/DC0%0/2
ref $element and UNIVERSAL::isa($element, "Unix::Conf::Bind8::Conf::Acl")
ref $element
UNIVERSAL::isa($element, "Unix::Conf::Bind8::Conf::Acl")
Truth table0%0/3
A and B
A= ref $elementB= UNIVERSAL::isa($element, "Unix::Conf::Bind8::Conf::Acl")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | && return (1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # strip any leading `!' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $element =~ s/^!(.*)/$1/o; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($element =~ /^key/gc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $element =~ /\G\s+(\S+)\s*$/ || return (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | return (1) if (Unix::Conf::Bind8::Conf::_get_key ($confds, $1)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | return (Unix::Conf->_err ("__valid_element", "key `$1' not defined")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | __valid_ipaddress ($element) && return (1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | __valid_ipprefix ($element) && return (1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # must be some acl name (built-in or defined) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | $element eq 'none' || $element eq 'any' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$element eq "none" or $element eq "any" or $element eq "localhost" or $element eq "localnets"
$element eq "none" or $element eq "any" or $element eq "localhost"
$element eq "none" or $element eq "any"
MC/DC0%0/4
$element eq "none" or $element eq "any" or $element eq "localhost" or $element eq "localnets"
$element eq "none"
$element eq "any"
$element eq "localhost"
$element eq "localnets"
Truth table0%0/5
A or B or C or D
A= $element eq "none"B= $element eq "any"C= $element eq "localhost"D= $element eq "localnets"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | $element eq 'localhost' || $element eq 'localnets' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ) && return (1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | Unix::Conf::Bind8::Conf::_get_acl ($confds, $element) && return (1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | return (Unix::Conf->_err ("__valid_element", "acl `$element' not defined")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | sub __valid_port ($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__valid_port: not called CC=5 SCAR=29.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 10 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | ($_[0] eq '*') && return (1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | ($_[0] !~ /^\d+$/) && return (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | ($_[0] >= 0 && $_[0] <= 65536) && return (1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_[0] >= 0 and $_[0] <= 65536
MC/DC0%0/2
$_[0] >= 0 and $_[0] <= 65536
$_[0] >= 0
$_[0] <= 65536
Truth table0%0/3
A and B
A= $_[0] >= 0B= $_[0] <= 65536
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # routine to validate an IPv4 address. check this out later | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub __valid_ipaddress ($) { return ($_[0] =~ /^(?:(?:\d{1,3}\.){3}\d{1,3})$/); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__valid_ipaddress: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # we could tighten this up a lot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub __valid_ipprefix ($) { return ($_[0] =~ /^(?:\d{1,3}(\.\d{1,3}){0,3}\/\d{1,2})$/); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__valid_ipprefix: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub __valid_yesno ($) { return ($_[0] =~ /^(yes|no|true|false|1|0)$/); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__valid_yesno: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub __valid_checknames ($) { return ($_[0] =~ /^(warn|fail|ignore)$/); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__valid_checknames: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub __valid_forward ($) { return ($_[0] =~ /^(only|first)$/); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__valid_forward: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub __valid_category ($) { return ($_[0] =~ /^(default|config|parser|queries|lame-servers|statistics|panic|update|ncache|xfer-in|xfer-out|db|eventlib|packet|notify|cname|security|os|insist|maintenance|load|reponse-checks)$/); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__valid_category: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub __valid_facility ($) { return ($_[0] =~ /^(kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|authpriv|ftp|local0|local1|local2|local3|local4|local5|local7|local7)$/); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__valid_facility: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub __valid_severity ($) { return ($_[0] =~ /^(critical|error|warning|notice|info|debug|dynamic)$/); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__valid_severity: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub __valid_number ($) { return ($_[0] =~ /^\d+$/); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__valid_number: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub __valid_sizespec ($) { return ($_[0] =~ /^(unlimited|default|\d+[kKmMgG]?)/); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__valid_sizespec: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub __valid_transfer_format { return ($_[0] =~ /^(one-answer|many-answers)$/); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__valid_transfer_format: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # This routine strips any "" in the original argument as it acts on the ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # returns true all the time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub __valid_string ($) { $_[0] =~ s/^"(.+)"$/$1/; return (1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__valid_string: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||