File Coverage

blib/lib/Unix/Conf/Bind8/Conf/Lib.pm
Criterion Covered Total %
statement 9 38 23.6
branch 0 22 0.0
condition 0 15 0.0
subroutine 3 17 17.6
pod n/a
total 12 92 13.0


line stmt bran cond sub pod time code
1             # utility routines to be shared amongst the various classes
2             #
3             # Copyright Karthik Krishnamurthy
4             package Unix::Conf::Bind8::Conf::Lib;
5              
6 10     10   48 use strict;
  10         17  
  10         323  
7 10     10   47 use warnings;
  10         18  
  10         3782  
8              
9             require Exporter;
10             our @ISA = qw (Exporter);
11             # __valid_rlim
12             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             {
40 0     0     my ($confds, $element) = @_;
41              
42             # if an Acl object, return true.
43 0 0 0       ref ($element) && UNIVERSAL::isa ($element, 'Unix::Conf::Bind8::Conf::Acl')
44             && return (1);
45              
46             # strip any leading `!'
47 0           $element =~ s/^!(.*)/$1/o;
48 0 0         if ($element =~ /^key/gc) {
49 0 0         $element =~ /\G\s+(\S+)\s*$/ || return ();
50 0 0         return (1) if (Unix::Conf::Bind8::Conf::_get_key ($confds, $1));
51 0           return (Unix::Conf->_err ("__valid_element", "key `$1' not defined"));
52             }
53 0 0         __valid_ipaddress ($element) && return (1);
54 0 0         __valid_ipprefix ($element) && return (1);
55             # must be some acl name (built-in or defined)
56             (
57 0 0 0       $element eq 'none' || $element eq 'any' ||
      0        
      0        
58             $element eq 'localhost' || $element eq 'localnets'
59             ) && return (1);
60 0 0         Unix::Conf::Bind8::Conf::_get_acl ($confds, $element) && return (1);
61 0           return (Unix::Conf->_err ("__valid_element", "acl `$element' not defined"));
62             }
63              
64              
65             sub __valid_port ($)
66             {
67 10     10   63 no warnings;
  10         18  
  10         9606  
68 0 0   0     ($_[0] eq '*') && return (1);
69 0 0         ($_[0] !~ /^\d+$/) && return ();
70 0 0 0       ($_[0] >= 0 && $_[0] <= 65536) && return (1);
71 0           return ();
72             }
73              
74             # routine to validate an IPv4 address. check this out later
75 0     0     sub __valid_ipaddress ($) { return ($_[0] =~ /^(?:(?:\d{1,3}\.){3}\d{1,3})$/); }
76             # we could tighten this up a lot
77 0     0     sub __valid_ipprefix ($) { return ($_[0] =~ /^(?:\d{1,3}(\.\d{1,3}){0,3}\/\d{1,2})$/); }
78 0     0     sub __valid_yesno ($) { return ($_[0] =~ /^(yes|no|true|false|1|0)$/); }
79 0     0     sub __valid_checknames ($) { return ($_[0] =~ /^(warn|fail|ignore)$/); }
80 0     0     sub __valid_forward ($) { return ($_[0] =~ /^(only|first)$/); }
81 0     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)$/); }
82 0     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)$/); }
83 0     0     sub __valid_severity ($) { return ($_[0] =~ /^(critical|error|warning|notice|info|debug|dynamic)$/); }
84 0     0     sub __valid_number ($) { return ($_[0] =~ /^\d+$/); }
85 0     0     sub __valid_sizespec ($) { return ($_[0] =~ /^(unlimited|default|\d+[kKmMgG]?)/); }
86 0     0     sub __valid_transfer_format { return ($_[0] =~ /^(one-answer|many-answers)$/); }
87              
88             # This routine strips any "" in the original argument as it acts on the ref
89             # returns true all the time
90 0     0     sub __valid_string ($) { $_[0] =~ s/^"(.+)"$/$1/; return (1) }
  0