blib/lib/Langertha/Holmgang/Sim/Linux/Dns.pm

filter: Statementstmt 86.1% 659 / 765 Branchbran 61.9% 321 / 518 Conditioncond 48.5% 198 / 408 MC/DCmcdc 20.4% 45 / 220 Subroutinesub 96.0% 49 / 51 Podpod 100% 11 / 11 totaltotal 65.0% 1283 / 1973 CC 451 SCAR 48.3
CC
451
Cov
70%
parse_zone
535.1
rndc
137.5
host
64.0
CRAP 125.0
« blib/lib/Langertha/Holmgang/Sim/Linux/Backup.pm ↑ Summary blib/lib/Langertha/Holmgang/Grader.pm »
1 package Langertha::Holmgang::Sim::Linux::Dns;
2 # ABSTRACT: BIND 9 on a simulated Linux server — named.conf, zones, rndc, dig, secondaries
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '0.001';
11  
12  
13 2 my $T = JSON::MaybeXS::true();
14 2 my $F = JSON::MaybeXS::false();
15  
16 75 ▶sub _lx { 'Langertha::Holmgang::Sim::Linux' }
Subroutine _lx: called CC=1 SCAR=0.0
17 66 ▶sub _text { _lx()->can('_file_text')->(@_) }
Subroutine _text: called CC=1 SCAR=0.0
18  
19 46 ▶sub _bind { $_[0]{bind} }
Subroutine _bind: called CC=1 SCAR=0.0
20 25 ▶sub _svc_name { ( _bind( $_[0] ) || {} )->{service} // 'named' }
Subroutine _svc_name: called CC=3 SCAR=12.7
Condition50%2/4
(_bind($_[0]) || {})->{"service"} // "named"
l!l
025
_bind($_[0]) || {}
l!l
250
MC/DC0%0/1
(_bind($_[0]) || {})->{"service"} // "named"
_bind($_[0])
Truth table50%1/2
A
A= _bind($_[0])
Aresult
11
00
21 21 ▶sub _conf_path { ( _bind( $_[0] ) || {} )->{conf} // '/etc/bind/named.conf' }
Subroutine _conf_path: called CC=3 SCAR=12.7
Condition50%2/4
(_bind($_[0]) || {})->{"conf"} // "/etc/bind/named.conf"
l!l
021
_bind($_[0]) || {}
l!l
210
MC/DC0%0/1
(_bind($_[0]) || {})->{"conf"} // "/etc/bind/named.conf"
_bind($_[0])
Truth table50%1/2
A
A= _bind($_[0])
Aresult
11
00
22  
23 17 ▶sub _ip_of {
Subroutine _ip_of: called CC=6 SCAR=18.5
24 17 my ($dev) = @_;
25 17 my @ip;
26 17 ▶ for my $i ( sort keys %{ $dev->{interfaces} || {} } ) {
Condition50%1/2
$$dev{'interfaces'} || {}
l!l
170
MC/DC0%0/1
$$dev{'interfaces'} || {}
$$dev{'interfaces'}
Truth table50%1/2
A
A= $$dev{'interfaces'}
Aresult
11
00
27 17 ▶ for my $a ( @{ $dev->{interfaces}{$i}{addr} || [] } ) { push @ip, $1 if $a =~ m{\A([\d.]+)/} }
Branch: 1 branch
BranchTrueFalseTotal
if $a =~ m[\A([\d.]+)/] 17 0 17
Condition50%1/2
$$dev{'interfaces'}{$i}{'addr'} || []
l!l
170
MC/DC0%0/1
$$dev{'interfaces'}{$i}{'addr'} || []
$$dev{'interfaces'}{$i}{'addr'}
Truth table50%1/2
A
A= $$dev{'interfaces'}{$i}{'addr'}
Aresult
11
00
28 }
29 17 return @ip;
30 }
31  
32 25 ▶sub _running {
Subroutine _running: called CC=4 SCAR=16.1
33 25 my ($dev) = @_;
34 25 ▶ my $s = ( $dev->{services} || {} )->{ _svc_name($dev) };
Condition50%1/2
$$dev{'services'} || {}
l!l
250
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
35 25 ▶ return $s && $s->{active} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$s && $$s{'active'} ? : 25 0 25
Condition33%1/3
$s and $$s{"active"}
!ll&&!rl&&r
0025
MC/DC0%0/2
$s and $$s{"active"}
$s $$s{"active"}
Truth table33%1/3
A and B
A= $sB= $$s{"active"}
ABresult
0X0
100
111
36 }
37  
38 # --- named.conf ------------------------------------------------------------------
39  
40 53 ▶sub _conf_tokens {
Subroutine _conf_tokens: called CC=9 SCAR=22.4
41 53 my ( $text, $file ) = @_;
42 53 my @t;
43 53 my $line = 1;
44 53 pos($text) = 0;
45 53 ▶ while ( pos($text) < length $text ) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $text < length $text) 1085 53 1138
46 1085 ▶ if ( $text =~ /\G\n/gc ) { $line++ }
Branch: 7 branches
BranchTrueFalseTotal
if ($text =~ /\G\n/cg) { } 178 907 1085
elsif ($text =~ /\G[ \t\r]+/cg) { } 315 592 907
elsif ($text =~ m[\G(?://|\#)[^\n]*]cg) { } 0 592 592
elsif ($text =~ m[\G/\*(.*?)\*/]cgs) { } 0 592 592
elsif ($text =~ /\G"((?:[^"\\\n]|\\.)*)"/cg) { } 90 502 592
elsif ($text =~ /\G([{};])/cg) { } 286 216 502
elsif ($text =~ /\G([^\s{};"]+)/cg) { } 216 0 216
47 elsif ( $text =~ /\G[ \t\r]+/gc ) { }
48 elsif ( $text =~ m{\G(?://|\#)[^\n]*}gc ) { }
49 0 elsif ( $text =~ m{\G/\*(.*?)\*/}gcs ) { $line += () = $1 =~ /\n/g }
50 90 elsif ( $text =~ /\G"((?:[^"\\\n]|\\.)*)"/gc ) { push @t, { v => $1, q => 1, line => $line, file => $file } }
51 286 elsif ( $text =~ /\G([{};])/gc ) { push @t, { v => $1, p => 1, line => $line, file => $file } }
52 216 elsif ( $text =~ /\G([^\s{};"]+)/gc ) { push @t, { v => $1, line => $line, file => $file } }
53 0 else { die "$file:$line: unexpected character\n" }
54 }
55 53 return @t;
56 }
57  
58 # Anweisungen: { words => [...], block => [...]|undef }
59 108 ▶sub _conf_block {
Subroutine _conf_block: called CC=20 SCAR=32.0
60 108 my ( $toks, $inner ) = @_;
61 108 my @st;
62 108 ▶ while (@$toks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$toks) 231 50 281
63 231 my $t = $toks->[0];
64 231 ▶ if ( $t->{p} && $t->{v} eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$t{"p"} and $$t{"v"} eq "}") 52 179 231
Condition66%2/3
$$t{"p"} and $$t{"v"} eq "}"
!ll&&!rl&&r
179052
MC/DC50%1/2
$$t{"p"} and $$t{"v"} eq "}"
$$t{"p"} $$t{"v"} eq "}"
Truth table66%2/3
A and B
A= $$t{"p"}B= $$t{"v"} eq "}"
ABresult
0X0
100
111
65 52 ▶ die "$t->{file}:$t->{line}: unexpected token near '}'\n" unless $inner;
Branch: 1 branch
BranchTrueFalseTotal
unless $inner 0 52 52
66 52 return \@st;
67 }
68 179 my ( @w, $block );
69 179 while (1) {
70 485 my $x = shift @$toks;
71 485 ▶ die "$t->{file}:$t->{line}: unexpected end of input\n" unless $x;
Branch: 1 branch
BranchTrueFalseTotal
unless $x 0 485 485
72 485 ▶ if ( $x->{p} && $x->{v} eq ';' ) { last }
Branch: 1 branch
BranchTrueFalseTotal
if ($$x{"p"} and $$x{"v"} eq ";") 121 364 485
Condition100%3/3
$$x{"p"} and $$x{"v"} eq ";"
!ll&&!rl&&r
30658121
MC/DC100%2/2
$$x{"p"} and $$x{"v"} eq ";"
$$x{"p"} $$x{"v"} eq ";"
Truth table100%3/3
A and B
A= $$x{"p"}B= $$x{"v"} eq ";"
ABresult
0X0
100
111
73 364 ▶ if ( $x->{p} && $x->{v} eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$x{"p"} and $$x{"v"} eq "{") 55 309 364
Condition100%3/3
$$x{"p"} and $$x{"v"} eq "{"
!ll&&!rl&&r
306355
MC/DC100%2/2
$$x{"p"} and $$x{"v"} eq "{"
$$x{"p"} $$x{"v"} eq "{"
Truth table100%3/3
A and B
A= $$x{"p"}B= $$x{"v"} eq "{"
ABresult
0X0
100
111
74 55 $block = _conf_block( $toks, 1 );
75 52 ▶ my $close = shift @$toks or die "$x->{file}:$x->{line}: unexpected end of input\n";
Branch: 1 branch
BranchTrueFalseTotal
my $close = shift @$toks or die qq[$$x{"file"}:$$x{"line"}: unexpected end of input\n] 52 0 52
76 52 my $semi = $toks->[0];
77 die "$close->{file}:$close->{line}: missing ';' before " . ( $semi ? "'$semi->{v}'" : 'end of file' ) . "\n"
78 52 ▶ unless $semi && $semi->{p} && $semi->{v} eq ';';
Branch: 2 branches
BranchTrueFalseTotal
unless $semi and $$semi{"p"} and $$semi{"v"} eq ";" 0 52 52
$semi ? : 0 0 0
Condition33%2/6
$semi and $$semi{"p"} and $$semi{"v"} eq ";"
!ll&&!rl&&r
0052
$semi and $$semi{"p"}
!ll&&!rl&&r
0052
MC/DC0%0/3
$semi and $$semi{"p"} and $$semi{"v"} eq ";"
$semi $$semi{"p"} $$semi{"v"} eq ";"
Truth table25%1/4
A and B and C
A= $semiB= $$semi{"p"}C= $$semi{"v"} eq ";"
ABCresult
0XX0
10X0
1100
1111
79 52 shift @$toks;
80 52 last;
81 }
82 309 ▶ if ( $x->{p} && $x->{v} eq '}' ) { die "$x->{file}:$x->{line}: missing ';' before '}'\n" }
Branch: 1 branch
BranchTrueFalseTotal
if ($$x{"p"} and $$x{"v"} eq "}") 3 306 309
Condition66%2/3
$$x{"p"} and $$x{"v"} eq "}"
!ll&&!rl&&r
30603
MC/DC50%1/2
$$x{"p"} and $$x{"v"} eq "}"
$$x{"p"} $$x{"v"} eq "}"
Truth table66%2/3
A and B
A= $$x{"p"}B= $$x{"v"} eq "}"
ABresult
0X0
100
111
83 306 push @w, $x->{v};
84 }
85 173 ▶ push @st, { words => \@w, block => $block } if @w || $block;
Branch: 1 branch
BranchTrueFalseTotal
if @w or $block 173 0 173
Condition33%1/3
@w or $block
l!l&&r!l&&!r
17300
MC/DC0%0/2
@w or $block
@w $block
Truth table33%1/3
A or B
A= @wB= $block
ABresult
1X1
011
000
86 }
87 50 ▶ die "unexpected end of input\n" if $inner;
Branch: 1 branch
BranchTrueFalseTotal
if $inner 0 50 50
88 50 return \@st;
89 }
90  
91 53 ▶sub _conf_read {
Subroutine _conf_read: called CC=7 SCAR=19.8
92 53 my ( $dev, $path, $depth ) = @_;
93 53 my $text = _text( $dev, $path );
94 53 ▶ die "$path: file not found\n" unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 53 53
95 53 my @toks = _conf_tokens( $text, $path );
96 53 my $st = _conf_block( \@toks, 0 );
97 50 my @out;
98 50 for my $s (@$st) {
99 66 ▶ if ( $s->{words}[0] eq 'include' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$s{'words'}[0] eq 'include') { } 32 34 66
100 32 ▶ die "$path: include loop\n" if ( $depth // 0 ) > 8;
Branch: 1 branch
BranchTrueFalseTotal
if ($depth // 0) > 8 0 32 32
Condition50%1/2
$depth // 0
l!l
032
MC/DC0%0/1
$depth // 0
$depth
Truth table50%1/2
A
A= $depth
Aresult
11
00
101 32 ▶ push @out, @{ _conf_read( $dev, $s->{words}[1], ( $depth // 0 ) + 1 ) };
Condition50%1/2
$depth // 0
l!l
032
MC/DC0%0/1
$depth // 0
$depth
Truth table50%1/2
A
A= $depth
Aresult
11
00
102 }
103 34 else { push @out, $s }
104 }
105 47 return \@out;
106 }
107  
108 18 ▶sub _addr_list {
Subroutine _addr_list: called CC=2 SCAR=7.0
109 18 my ($block) = @_;
110 18 ▶ return [ map { join ' ', @{ $_->{words} } } @{ $block || [] } ];
Condition50%1/2
$block || []
l!l
180
MC/DC0%0/1
$block || []
$block
Truth table50%1/2
A
A= $block
Aresult
11
00
111 }
112  
113 # named.conf -> { directory, allow_transfer, zones => { name => {...} } }
114  
115 21 ▶sub parse_conf {
Subroutine parse_conf: called CC=36 SCAR=41.4
Pod documented
116 21 my ( $dev, $path ) = @_;
117 21 ▶ $path //= _conf_path($dev);
Condition33%1/3
$path //= _conf_path($dev)
l!l&&r!l&&!r
0210
MC/DC0%0/2
$path //= _conf_path($dev)
$path _conf_path($dev)
Truth table33%1/3
A //= B
A= $pathB= _conf_path($dev)
ABresult
1X1
011
000
118 21 my $st = _conf_read( $dev, $path );
119 18 my %c = ( directory => '/var/cache/bind', zones => {} );
120 18 for my $s (@$st) {
121 31 my $k = $s->{words}[0];
122 31 ▶ if ( $k eq 'options' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($k eq 'options') { } 13 18 31
elsif ($k eq 'zone') { } 18 0 18
123 13 ▶ for my $o ( @{ $s->{block} || [] } ) {
Condition50%1/2
$$s{'block'} || []
l!l
130
MC/DC0%0/1
$$s{'block'} || []
$$s{'block'}
Truth table50%1/2
A
A= $$s{'block'}
Aresult
11
00
124 26 my $ok = $o->{words}[0];
125 26 ▶ $c{directory} = $o->{words}[1] if $ok eq 'directory';
Branch: 1 branch
BranchTrueFalseTotal
if $ok eq "directory" 13 13 26
126 26 ▶ $c{allow_transfer} = _addr_list( $o->{block} ) if $ok eq 'allow-transfer';
Branch: 1 branch
BranchTrueFalseTotal
if $ok eq "allow-transfer" 0 26 26
127 26 ▶ $c{also_notify} = _addr_list( $o->{block} ) if $ok eq 'also-notify';
Branch: 1 branch
BranchTrueFalseTotal
if $ok eq "also-notify" 0 26 26
128 26 ▶ $c{notify} = $o->{words}[1] if $ok eq 'notify';
Branch: 1 branch
BranchTrueFalseTotal
if $ok eq "notify" 0 26 26
129 }
130 }
131 elsif ( $k eq 'zone' ) {
132 18 ▶ my $name = lc( $s->{words}[1] // '' );
Condition50%1/2
$$s{"words"}[1] // ""
l!l
180
MC/DC0%0/1
$$s{"words"}[1] // ""
$$s{"words"}[1]
Truth table50%1/2
A
A= $$s{"words"}[1]
Aresult
11
00
133 18 ▶ $name =~ s/\.\z// unless $name eq '.';
Branch: 1 branch
BranchTrueFalseTotal
unless $name eq "." 18 0 18
134 18 ▶ die "zone '' : missing name\n" unless length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless length $name 0 18 18
135 18 ▶ die "zone '$name': already exists\n" if $c{zones}{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $c{"zones"}{$name} 0 18 18
136 18 my %z = ( name => $name );
137 18 ▶ for my $o ( @{ $s->{block} || [] } ) {
Condition50%1/2
$$s{'block'} || []
l!l
180
MC/DC0%0/1
$$s{'block'} || []
$$s{'block'}
Truth table50%1/2
A
A= $$s{'block'}
Aresult
11
00
138 54 my $ok = $o->{words}[0];
139 54 ▶ if ( $ok eq 'type' ) { $z{type} = $o->{words}[1] }
Branch: 6 branches
BranchTrueFalseTotal
if ($ok eq 'type') { } 18 36 54
elsif ($ok eq 'file') { } 18 18 36
elsif ($ok eq 'allow-transfer') { } 13 5 18
elsif ($ok eq 'also-notify') { } 0 5 5
elsif ($ok eq 'masters' or $ok eq 'primaries') { } 5 0 5
elsif ($ok eq 'notify') { } 0 0 0
140 18 elsif ( $ok eq 'file' ) { $z{file} = $o->{words}[1] }
141 13 elsif ( $ok eq 'allow-transfer' ) { $z{allow_transfer} = _addr_list( $o->{block} ) }
142 0 elsif ( $ok eq 'also-notify' ) { $z{also_notify} = _addr_list( $o->{block} ) }
143 5 ▶ elsif ( $ok eq 'masters' || $ok eq 'primaries' ) { $z{primaries} = _addr_list( $o->{block} ) }
Condition33%1/3
$ok eq "masters" or $ok eq "primaries"
l!l&&r!l&&!r
500
MC/DC0%0/2
$ok eq "masters" or $ok eq "primaries"
$ok eq "masters" $ok eq "primaries"
Truth table33%1/3
A or B
A= $ok eq "masters"B= $ok eq "primaries"
ABresult
1X1
011
000
144 0 elsif ( $ok eq 'notify' ) { $z{notify} = $o->{words}[1] }
145 }
146 18 ▶ my $t = $z{type} // '';
Condition50%1/2
$z{"type"} // ""
l!l
180
MC/DC0%0/1
$z{"type"} // ""
$z{"type"}
Truth table50%1/2
A
A= $z{"type"}
Aresult
11
00
147 18 ▶ $z{type} = $t eq 'master' ? 'primary' : $t eq 'slave' ? 'secondary' : $t;
Branch: 2 branches
BranchTrueFalseTotal
$t eq 'master' ? : 13 5 18
$t eq 'slave' ? : 5 0 5
148 18 ▶ die "zone '$name': type not present\n" unless length $t;
Branch: 1 branch
BranchTrueFalseTotal
unless length $t 0 18 18
149 18 ▶ die "zone '$name': type '$t' not supported\n" unless $z{type} =~ /\A(?:primary|secondary|hint|forward)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $z{"type"} =~ /\A(?:primary|secondary|hint|forward)\z/ 0 18 18
150 18 ▶ die "zone '$name': missing 'file' entry\n" if $z{type} eq 'primary' && !defined $z{file};
Branch: 1 branch
BranchTrueFalseTotal
if $z{"type"} eq "primary" and not defined $z{"file"} 0 18 18
Condition66%2/3
$z{"type"} eq "primary" and not defined $z{"file"}
!ll&&!rl&&r
5130
MC/DC0%0/2
$z{"type"} eq "primary" and not defined $z{"file"}
$z{"type"} eq "primary" not defined $z{"file"}
Truth table66%2/3
A and not(B)
A= $z{"type"} eq "primary"B= not defined $z{"file"}
ABresult
0X0
100
111
151 18 ▶ die "zone '$name': missing 'primaries' entry\n" if $z{type} eq 'secondary' && !$z{primaries};
Branch: 1 branch
BranchTrueFalseTotal
if $z{"type"} eq "secondary" and not $z{"primaries"} 0 18 18
Condition66%2/3
$z{"type"} eq "secondary" and not $z{"primaries"}
!ll&&!rl&&r
1350
MC/DC0%0/2
$z{"type"} eq "secondary" and not $z{"primaries"}
$z{"type"} eq "secondary" not $z{"primaries"}
Truth table66%2/3
A and not(B)
A= $z{"type"} eq "secondary"B= not $z{"primaries"}
ABresult
0X0
100
111
152 18 $c{zones}{$name} = \%z;
153 }
154 }
155 18 for my $z ( values %{ $c{zones} } ) {
156 18 ▶ $z->{path} = !defined $z->{file} ? undef : $z->{file} =~ m{\A/} ? $z->{file} : "$c{directory}/$z->{file}";
Branch: 2 branches
BranchTrueFalseTotal
!defined($$z{'file'}) ? : 0 18 18
$$z{'file'} =~ m[\A/] ? : 17 1 18
157 }
158 18 return \%c;
159 }
160  
161 # --- Zonendateien -----------------------------------------------------------------
162  
163 712 ▶sub _ttl {
Subroutine _ttl: called CC=4 SCAR=13.9
164 712 my ($w) = @_;
165 712 ▶ return undef unless defined $w && $w =~ /\A(?:\d+[smhdw]?)+\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $w and $w =~ /\A(?:\d+[smhdw]?)+\z/i 448 264 712
Condition66%2/3
defined $w and $w =~ /\A(?:\d+[smhdw]?)+\z/i
!ll&&!rl&&r
0448264
MC/DC50%1/2
defined $w and $w =~ /\A(?:\d+[smhdw]?)+\z/i
defined $w $w =~ /\A(?:\d+[smhdw]?)+\z/i
Truth table66%2/3
A and B
A= defined $wB= $w =~ /\A(?:\d+[smhdw]?)+\z/i
ABresult
0X0
100
111
166 264 my %m = ( '' => 1, s => 1, m => 60, h => 3600, d => 86400, w => 604800 );
167 264 my $t = 0;
168 264 ▶ $t += $1 * $m{ lc $2 } while $w =~ /(\d+)([smhdw]?)/gi;
Branch: 1 branch
BranchTrueFalseTotal
$w =~ /(\d+)([smhdw]?)/gi and do { $t += $1 * $m{lc $2} } 264 264 528
169 264 return $t;
170 }
171  
172 323 ▶sub _abs {
Subroutine _abs: called CC=3 SCAR=11.0
173 323 my ( $n, $origin ) = @_;
174 323 ▶ return $origin if $n eq '@';
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "\@" 48 275 323
175 275 ▶ return lc( $n =~ /\.\z/ ? $n : "$n.$origin" ) =~ s/\A\.//r;
Branch: 1 branch
BranchTrueFalseTotal
$n =~ /\.\z/ ? : 72 203 275
176 }
177  
178 98 ▶sub _ipv4 { my ($a) = @_; return $a =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/ && !grep { $_ > 255 } $1, $2, $3, $4 }
Subroutine _ipv4: called CC=2 SCAR=7.0
Condition66%2/3
$a =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/ && !grep({$_ > 255;} $1, $2, $3, $4)
!ll&&!rl&&r
0197
MC/DC50%1/2
$a =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/ && !grep({$_ > 255;} $1, $2, $3, $4)
$a =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/ !grep({$_ > 255;} $1, $2, $3, $4)
Truth table66%2/3
A && not(B)
A= $a =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/B= !grep({$_ > 255;} $1, $2, $3, $4)
ABresult
0X0
100
111
179  
180 # Zeilen der Datei in logische Zeilen (Klammern ueber Zeilen), Kommentare weg
181 24 ▶sub _zone_lines {
Subroutine _zone_lines: called CC=14 SCAR=26.4
182 24 my ($text) = @_;
183 24 my ( @out, $cur, $depth, $start );
184 24 my $n = 0;
185 24 for my $raw ( split /\n/, $text ) {
186 321 $n++;
187 321 my ( $l, $inq ) = ( '', 0 );
188 321 for my $ch ( split //, $raw ) {
189 8456 ▶ if ( $ch eq '"' ) { $inq = !$inq }
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\"") 104 8352 8456
190 8456 ▶ last if $ch eq ';' && !$inq;
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq ";" and not $inq 24 8432 8456
Condition66%2/3
$ch eq ";" and not $inq
!ll&&!rl&&r
8432024
MC/DC50%1/2
$ch eq ";" and not $inq
$ch eq ";" not $inq
Truth table66%2/3
A and not(B)
A= $ch eq ";"B= not $inq
ABresult
0X0
100
111
191 8432 ▶ if ( !$inq && ( $ch eq '(' || $ch eq ')' ) ) { $depth += $ch eq '(' ? 1 : -1; $l .= ' '; next }
Branch: 2 branches
BranchTrueFalseTotal
if (not $inq and $ch eq "(" || $ch eq ")") 50 8382 8432
$ch eq '(' ? : 25 25 50
Condition100%6/6
not $inq and $ch eq "(" || $ch eq ")"
!ll&&!rl&&r
989739350
$ch eq "(" or $ch eq ")"
l!l&&r!l&&!r
25257393
MC/DC100%3/3
not $inq and $ch eq "(" || $ch eq ")"
not $inq $ch eq "(" $ch eq ")"
Truth table100%4/4
not(A) and B or C
A= not $inqB= $ch eq "("C= $ch eq ")"
ABCresult
0XX0
1000
11X1
1011
192 8382 $l .= $ch;
193 }
194 321 ▶ if ( defined $cur ) { $cur .= " $l" }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cur) { } 49 272 321
195 272 else { ( $cur, $start ) = ( $l, $n ) }
196 321 ▶ next if $depth;
Branch: 1 branch
BranchTrueFalseTotal
if $depth 49 272 321
197 272 ▶ push @out, [ $start, $cur ] if $cur =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $cur =~ /\S/ 272 0 272
198 272 undef $cur;
199 }
200 24 ▶ push @out, [ $start, $cur, 'eof' ] if defined $cur;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cur 0 24 24
201 24 return @out;
202 }
203  
204 248 ▶sub _zone_words {
Subroutine _zone_words: called CC=3 SCAR=11.0
205 248 my ($l) = @_;
206 248 my @w;
207 248 ▶ while ( $l =~ /\G\s*(?:"((?:[^"\\]|\\.)*)"|(\S+))/gc ) { push @w, defined $1 ? { s => $1 } : $2 }
Branch: 2 branches
BranchTrueFalseTotal
if ($l =~ /\G\s*(?:"((?:[^"\\]|\\.)*)"|(\S+))/cg) 1137 248 1385
defined $1 ? : 52 1085 1137
208 248 return @w;
209 }
210  
211 77 ▶sub _q { my ($s) = @_; return '"' . $s . '"' }
Subroutine _q: called CC=1 SCAR=0.0
212  
213  
214 24 ▶sub parse_zone {
Subroutine parse_zone: called CC=88 SCAR=62.8
Pod documented
215 24 my ( $text, $zone, $file ) = @_;
216 24 ▶ $file //= "db.$zone";
Condition100%2/2
$file //= "db.$zone"
l!l
1212
MC/DC100%1/1
$file //= "db.$zone"
$file
Truth table100%2/2
A
A= $file
Aresult
11
00
217 24 my $origin = "$zone.";
218 24 my ( $ttl, $last, @rec, @err, @warn, %show );
219 24 ▶ my $fail = sub { push @err, "zone $zone/IN: loading from master file $file failed: $_[0]"; };
Subroutine __ANON__: called CC=1 SCAR=0.0
220 24 for my $ln ( _zone_lines($text) ) {
221 272 my ( $no, $l, $eof ) = @$ln;
222 0 ▶ if ($eof) { $fail->('unexpected end of input'); last }
Branch: 1 branch
BranchTrueFalseTotal
if ($eof) 0 272 272
223 272 ▶ if ( $l =~ /\A\$TTL\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\A\$TTL\s+(\S+)/) 24 248 272
224 0 ▶ $ttl = _ttl($1) // do { $fail->("$file:$no: bad ttl"); last };
Condition33%1/3
_ttl($1) // do { &$fail("${file}:${no}: bad ttl"); last }
l!l&&r!l&&!r
2400
MC/DC0%0/2
_ttl($1) // do { &$fail("${file}:${no}: bad ttl"); last }
_ttl($1) do { &$fail("${file}:${no}: bad ttl"); last }
Truth table33%1/3
A // B
A= _ttl($1)B= do { &$fail("${file}:${no}: bad ttl"); last }
ABresult
1X1
011
000
225 24 next;
226 }
227 0 ▶ if ( $l =~ /\A\$ORIGIN\s+(\S+)/ ) { $origin = _abs( $1, $origin ); $origin .= '.' unless $origin =~ /\.\z/; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($l =~ /\A\$ORIGIN\s+(\S+)/) 0 248 248
unless $origin =~ /\.\z/ 0 0 0
228 0 ▶ if ( $l =~ /\A\$/ ) { $fail->("$file:$no: unknown \$ directive"); last }
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\A\$/) 0 248 248
229 248 my $inherit = $l =~ /\A[ \t]/;
230 248 my @w = _zone_words($l);
231 248 my $owner;
232 248 ▶ if ($inherit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inherit) { } 72 176 248
233 0 ▶ $owner = $last // do { $fail->("$file:$no: no current owner name"); last };
Condition33%1/3
$last // do { &$fail("${file}:${no}: no current owner name"); last }
l!l&&r!l&&!r
7200
MC/DC0%0/2
$last // do { &$fail("${file}:${no}: no current owner name"); last }
$last do { &$fail("${file}:${no}: no current owner name"); last }
Truth table33%1/3
A // B
A= $lastB= do { &$fail("${file}:${no}: no current owner name"); last }
ABresult
1X1
011
000
234 }
235 else {
236 176 my $o = shift @w;
237 176 $owner = _abs( $o, $origin );
238 176 ▶ $owner .= '.' unless $owner =~ /\.\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $owner =~ /\.\z/ 0 176 176
239 }
240 248 my ( $rttl, $type );
241 248 ▶ while ( @w && !ref $w[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@w and not ref $w[0]) 520 0 520
Condition33%1/3
@w and not ref $w[0]
!ll&&!rl&&r
00520
MC/DC0%0/2
@w and not ref $w[0]
@w not ref $w[0]
Truth table33%1/3
A and not(B)
A= @wB= not ref $w[0]
ABresult
0X0
100
111
242 520 ▶ if ( !defined $rttl && defined _ttl( $w[0] ) ) { $rttl = _ttl( shift @w ) }
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $rttl and defined _ttl($w[0])) { } 24 496 520
elsif (uc $w[0] eq 'IN') { } 248 248 496
Condition100%3/3
not defined $rttl and defined _ttl($w[0])
!ll&&!rl&&r
4844824
MC/DC100%2/2
not defined $rttl and defined _ttl($w[0])
not defined $rttl defined _ttl($w[0])
Truth table100%3/3
not(A) and B
A= not defined $rttlB= defined _ttl($w[0])
ABresult
0X0
100
111
243 248 elsif ( uc $w[0] eq 'IN' ) { shift @w }
244 248 else { $type = uc shift @w; last }
245 }
246 0 ▶ unless ( defined $type ) { $fail->("$file:$no: unexpected end of line"); last }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $type) 0 248 248
247 248 $last = $owner;
248 248 my @d = @w;
249 248 ▶ my $bad = sub { $fail->("$file:$no: $_[0]") };
Subroutine __ANON__: called CC=1 SCAR=0.0
250 248 ▶ my $name = sub { my $n = _abs( $_[0], $origin ); $n .= '.' unless $n =~ /\.\z/; $n };
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
unless $n =~ /\.\z/ 0 147 147
251 248 my ( $rd, $sh );
252 248 ▶ if ( $type eq 'A' ) {
Branch: 8 branches
BranchTrueFalseTotal
if ($type eq 'A') { } 98 150 248
elsif ($type eq 'AAAA') { } 0 150 150
elsif ($type =~ /\A(?:NS|CNAME|PTR)\z/) { } 75 75 150
elsif ($type eq 'MX') { } 24 51 75
elsif ($type eq 'SRV') { } 0 51 51
elsif ($type eq 'TXT') { } 27 24 51
elsif ($type eq 'CAA') { } 0 24 24
elsif ($type eq 'SOA') { } 24 0 24
253 98 ▶ unless ( @d == 1 && !ref $d[0] && _ipv4( $d[0] ) ) { $bad->('bad dotted quad'); last }
Branch: 1 branch
BranchTrueFalseTotal
unless (@d == 1 and not ref $d[0] and _ipv4($d[0])) 1 97 98
Condition50%3/6
@d == 1 and not ref $d[0] and _ipv4($d[0])
!ll&&!rl&&r
0197
@d == 1 and not ref $d[0]
!ll&&!rl&&r
0098
MC/DC33%1/3
@d == 1 and not ref $d[0] and _ipv4($d[0])
@d == 1 not ref $d[0] _ipv4($d[0])
Truth table50%2/4
A and not(B) and C
A= @d == 1B= not ref $d[0]C= _ipv4($d[0])
ABCresult
0XX0
10X0
1100
1111
254 97 $rd = $d[0];
255 }
256 elsif ( $type eq 'AAAA' ) {
257 0 ▶ unless ( @d == 1 && !ref $d[0] && $d[0] =~ /\A[0-9a-f:.]+\z/i && $d[0] =~ /:/ ) { $bad->('bad IPv6 address'); last }
Branch: 1 branch
BranchTrueFalseTotal
unless (@d == 1 and not ref $d[0] and $d[0] =~ /\A[0-9a-f:.]+\z/i and $d[0] =~ /:/) 0 0 0
Condition0%0/9
@d == 1 and not ref $d[0] and $d[0] =~ /\A[0-9a-f:.]+\z/i and $d[0] =~ /:/
!ll&&!rl&&r
000
@d == 1 and not ref $d[0] and $d[0] =~ /\A[0-9a-f:.]+\z/i
!ll&&!rl&&r
000
@d == 1 and not ref $d[0]
!ll&&!rl&&r
000
MC/DC0%0/4
@d == 1 and not ref $d[0] and $d[0] =~ /\A[0-9a-f:.]+\z/i and $d[0] =~ /:/
@d == 1 not ref $d[0] $d[0] =~ /\A[0-9a-f:.]+\z/i $d[0] =~ /:/
Truth table0%0/5
A and not(B) and C and D
A= @d == 1B= not ref $d[0]C= $d[0] =~ /\A[0-9a-f:.]+\z/iD= $d[0] =~ /:/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
258 0 $rd = lc $d[0];
259 }
260 elsif ( $type =~ /\A(?:NS|CNAME|PTR)\z/ ) {
261 0 ▶ unless ( @d == 1 && !ref $d[0] ) { $bad->( @d ? 'extra input text' : 'unexpected end of input' ); last }
Branch: 2 branches
BranchTrueFalseTotal
unless (@d == 1 and not ref $d[0]) 0 75 75
@d ? : 0 0 0
Condition33%1/3
@d == 1 and not ref $d[0]
!ll&&!rl&&r
0075
MC/DC0%0/2
@d == 1 and not ref $d[0]
@d == 1 not ref $d[0]
Truth table33%1/3
A and not(B)
A= @d == 1B= not ref $d[0]
ABresult
0X0
100
111
262 75 $rd = $name->( $d[0] );
263 }
264 elsif ( $type eq 'MX' ) {
265 0 ▶ unless ( @d == 2 && !ref $d[0] && $d[0] =~ /\A\d+\z/ && $d[0] <= 65535 && !ref $d[1] ) { $bad->('not a valid number'); last }
Branch: 1 branch
BranchTrueFalseTotal
unless (@d == 2 and not ref $d[0] and $d[0] =~ /\A\d+\z/ and $d[0] <= 65535 and not ref $d[1]) 0 24 24
Condition33%4/12
@d == 2 and not ref $d[0] and $d[0] =~ /\A\d+\z/ and $d[0] <= 65535 and not ref $d[1]
!ll&&!rl&&r
0024
@d == 2 and not ref $d[0] and $d[0] =~ /\A\d+\z/ and $d[0] <= 65535
!ll&&!rl&&r
0024
@d == 2 and not ref $d[0] and $d[0] =~ /\A\d+\z/
!ll&&!rl&&r
0024
@d == 2 and not ref $d[0]
!ll&&!rl&&r
0024
MC/DC0%0/5
@d == 2 and not ref $d[0] and $d[0] =~ /\A\d+\z/ and $d[0] <= 65535 and not ref $d[1]
@d == 2 not ref $d[0] $d[0] =~ /\A\d+\z/ $d[0] <= 65535 not ref $d[1]
Truth table16%1/6
A and not(B) and C and D and not(E)
A= @d == 2B= not ref $d[0]C= $d[0] =~ /\A\d+\z/D= $d[0] <= 65535E= not ref $d[1]
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
266 24 $rd = ( 0 + $d[0] ) . ' ' . $name->( $d[1] );
267 }
268 elsif ( $type eq 'SRV' ) {
269 0 ▶ unless ( @d == 4 && !grep( { ref } @d ) && !grep( { !/\A\d+\z/ } @d[ 0 .. 2 ] ) ) { $bad->('not a valid number'); last }
Branch: 1 branch
BranchTrueFalseTotal
unless (@d == 4 and not grep({ref $_;} @d) and not grep({not /\A\d+\z/;} @d[0..2])) 0 0 0
Condition0%0/6
@d == 4 and not grep({ref $_;} @d) and not grep({not /\A\d+\z/;} @d[0..2])
!ll&&!rl&&r
000
@d == 4 and not grep({ref $_;} @d)
!ll&&!rl&&r
000
MC/DC0%0/3
@d == 4 and not grep({ref $_;} @d) and not grep({not /\A\d+\z/;} @d[0..2])
@d == 4 not grep({ref $_;} @d) not grep({not /\A\d+\z/;} @d[0..2])
Truth table0%0/4
A and not(B) and not(C)
A= @d == 4B= not grep({ref $_;} @d)C= not grep({not /\A\d+\z/;} @d[0..2])
ABCresult
0XX0
10X0
1100
1111
270 0 $rd = join( ' ', map { 0 + $_ } @d[ 0 .. 2 ] ) . ' ' . $name->( $d[3] );
271 }
272 elsif ( $type eq 'TXT' ) {
273 0 ▶ unless (@d) { $bad->('unexpected end of input'); last }
Branch: 1 branch
BranchTrueFalseTotal
unless (@d) 0 27 27
274 27 ▶ my @s = map { ref $_ ? $_->{s} : $_ } @d;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 52 0 52
275 27 ▶ if ( grep { length( $_ =~ s/\\(.)/$1/gr ) > 255 } @s ) { $fail->('ran out of space'); last }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {length $_ =~ s/\\(.)/$1/gr > 255;} @s) 1 26 27
276 26 $rd = _q( join '', @s );
277 26 $sh = join ' ', map { _q($_) } @s;
278 }
279 elsif ( $type eq 'CAA' ) {
280 0 ▶ unless ( @d == 3 && $d[0] =~ /\A\d+\z/ ) { $bad->('not a valid number'); last }
Branch: 1 branch
BranchTrueFalseTotal
unless (@d == 3 and $d[0] =~ /\A\d+\z/) 0 0 0
Condition0%0/3
@d == 3 and $d[0] =~ /\A\d+\z/
!ll&&!rl&&r
000
MC/DC0%0/2
@d == 3 and $d[0] =~ /\A\d+\z/
@d == 3 $d[0] =~ /\A\d+\z/
Truth table0%0/3
A and B
A= @d == 3B= $d[0] =~ /\A\d+\z/
ABresult
0X0
100
111
281 0 ▶ $rd = "$d[0] $d[1] " . _q( ref $d[2] ? $d[2]{s} : $d[2] );
Branch: 1 branch
BranchTrueFalseTotal
ref $d[2] ? : 0 0 0
282 }
283 elsif ( $type eq 'SOA' ) {
284 0 ▶ unless ( @d == 7 && !grep( { ref } @d ) ) { $bad->( @d < 7 ? 'unexpected end of input' : 'extra input text' ); last }
Branch: 2 branches
BranchTrueFalseTotal
unless (@d == 7 and not grep({ref $_;} @d)) 0 24 24
@d < 7 ? : 0 0 0
Condition33%1/3
@d == 7 and not grep({ref $_;} @d)
!ll&&!rl&&r
0024
MC/DC0%0/2
@d == 7 and not grep({ref $_;} @d)
@d == 7 not grep({ref $_;} @d)
Truth table33%1/3
A and not(B)
A= @d == 7B= not grep({ref $_;} @d)
ABresult
0X0
100
111
285 24 my @n = @d[ 2 .. 6 ];
286 0 ▶ unless ( $n[0] =~ /\A\d+\z/ && $n[0] <= 4294967295 ) { $bad->('bad serial number'); last }
Branch: 1 branch
BranchTrueFalseTotal
unless ($n[0] =~ /\A\d+\z/ and $n[0] <= 4294967295) 0 24 24
Condition33%1/3
$n[0] =~ /\A\d+\z/ and $n[0] <= 4294967295
!ll&&!rl&&r
0024
MC/DC0%0/2
$n[0] =~ /\A\d+\z/ and $n[0] <= 4294967295
$n[0] =~ /\A\d+\z/ $n[0] <= 4294967295
Truth table33%1/3
A and B
A= $n[0] =~ /\A\d+\z/B= $n[0] <= 4294967295
ABresult
0X0
100
111
287 0 ▶ if ( grep { !defined _ttl($_) } @n[ 1 .. 4 ] ) { $bad->('bad ttl'); last }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not defined _ttl($_);} @n[1..4]) 0 24 24
288 24 $rd = join ' ', $name->( $d[0] ), $name->( $d[1] ), 0 + $n[0], map { _ttl($_) } @n[ 1 .. 4 ];
289 }
290 0 else { $fail->("$file:$no: unknown RR type '$type'"); last }
291 246 ▶ push @rec, { owner => $owner, ttl => $rttl // $ttl, type => $type, rd => $rd, show => $sh // $rd, line => $no };
Condition66%4/6
$rttl // $ttl
l!l&&r!l&&!r
242220
$sh // $rd
l!l&&r!l&&!r
262200
MC/DC0%0/2
$rttl // $ttl
$rttl $ttl
MC/DC0%0/2
$sh // $rd
$sh $rd
Truth table66%2/3
A // B
A= $rttlB= $ttl
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $shB= $rd
ABresult
1X1
011
000
292 }
293 24 my $apex = "$zone.";
294 24 ▶ my ($soa) = grep { $_->{type} eq 'SOA' && $_->{owner} eq $apex } @rec;
Condition66%2/3
$$_{'type'} eq 'SOA' && $$_{'owner'} eq $apex
!ll&&!rl&&r
222024
MC/DC50%1/2
$$_{'type'} eq 'SOA' && $$_{'owner'} eq $apex
$$_{'type'} eq 'SOA' $$_{'owner'} eq $apex
Truth table66%2/3
A && B
A= $$_{'type'} eq 'SOA'B= $$_{'owner'} eq $apex
ABresult
0X0
100
111
295 24 ▶ if ( !@err ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@err) 22 2 24
296 0 ▶ if ( !$soa ) { push @err, "zone $zone/IN: has no SOA record" }
Branch: 1 branch
BranchTrueFalseTotal
if (not $soa) { } 0 22 22
297 else {
298 22 my $min = ( split ' ', $soa->{rd} )[-1];
299 22 for my $r ( grep { !defined $_->{ttl} } @rec ) {
300 0 ▶ push @warn, "$file:$r->{line}: no TTL specified; using SOA MINTTL instead" unless @warn && $warn[-1] =~ /no TTL/;
Branch: 1 branch
BranchTrueFalseTotal
unless @warn and $warn[-1] =~ /no TTL/ 0 0 0
Condition0%0/3
@warn and $warn[-1] =~ /no TTL/
!ll&&!rl&&r
000
MC/DC0%0/2
@warn and $warn[-1] =~ /no TTL/
@warn $warn[-1] =~ /no TTL/
Truth table0%0/3
A and B
A= @warnB= $warn[-1] =~ /no TTL/
ABresult
0X0
100
111
301 0 $r->{ttl} = $min;
302 }
303 }
304 }
305 # Daten ausserhalb der Zone
306 24 my @in;
307 24 for my $r (@rec) {
308 246 ▶ if ( $r->{owner} eq $apex || $r->{owner} =~ /\.\Q$apex\E\z/ ) { push @in, $r }
Branch: 1 branch
BranchTrueFalseTotal
if ($$r{'owner'} eq $apex or $$r{'owner'} =~ /\.\Q$apex\E\z/) { } 245 1 246
Condition100%3/3
$$r{"owner"} eq $apex or $$r{"owner"} =~ /\.\Q$apex\E\z/
l!l&&r!l&&!r
1201251
MC/DC100%2/2
$$r{"owner"} eq $apex or $$r{"owner"} =~ /\.\Q$apex\E\z/
$$r{"owner"} eq $apex $$r{"owner"} =~ /\.\Q$apex\E\z/
Truth table100%3/3
A or B
A= $$r{"owner"} eq $apexB= $$r{"owner"} =~ /\.\Q$apex\E\z/
ABresult
1X1
011
000
309 1 else { ( my $o = $r->{owner} ) =~ s/\.\z//; push @warn, "$file:$r->{line}: ignoring out-of-zone data ($o)" }
310 }
311 24 my %seen;
312 24 @in = grep { !$seen{"$_->{owner} $_->{type} $_->{rd}"}++ } @in;
313 24 my %by;
314 24 push @{ $by{ $_->{owner} } }, $_ for @in;
315 24 ▶ if ( !@err ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @err) { } 22 2 24
316 22 ▶ push @err, "zone $zone/IN: has no NS records" unless grep { $_->{type} eq 'NS' && $_->{owner} eq $apex } @in;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$$_{"type"} eq "NS" and $$_{"owner"} eq $apex;} @in 0 22 22
Condition66%2/3
$$_{'type'} eq 'NS' && $$_{'owner'} eq $apex
!ll&&!rl&&r
181044
MC/DC50%1/2
$$_{'type'} eq 'NS' && $$_{'owner'} eq $apex
$$_{'type'} eq 'NS' $$_{'owner'} eq $apex
Truth table66%2/3
A && B
A= $$_{'type'} eq 'NS'B= $$_{'owner'} eq $apex
ABresult
0X0
100
111
317 22 for my $o ( sort keys %by ) {
318 133 my @t = map { $_->{type} } @{ $by{$o} };
319 133 ▶ if ( grep( { $_ eq 'CNAME' } @t ) && grep { $_ ne 'CNAME' } @t ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "CNAME";} @t and grep {$_ ne "CNAME";} @t) 4 129 133
Condition100%3/3
grep {$_ eq "CNAME";} @t and grep {$_ ne "CNAME";} @t
!ll&&!rl&&r
108214
MC/DC100%2/2
grep {$_ eq "CNAME";} @t and grep {$_ ne "CNAME";} @t
grep {$_ eq "CNAME";} @t grep {$_ ne "CNAME";} @t
Truth table100%3/3
A and B
A= grep {$_ eq "CNAME";} @tB= grep {$_ ne "CNAME";} @t
ABresult
0X0
100
111
320 4 ( my $s = $o ) =~ s/\.\z//;
321 4 push @err, "zone $zone/IN: $s: CNAME and other data";
322 }
323 }
324 22 ▶ my $has_addr = sub { grep { $_->{type} eq 'A' || $_->{type} eq 'AAAA' } @{ $by{ $_[0] } || [] } };
Subroutine __ANON__: called CC=3 SCAR=11.3
Condition60%3/5
$$_{'type'} eq 'A' || $$_{'type'} eq 'AAAA'
l!l&&r!l&&!r
6500
$by{$_[0]} || []
l!l
651
MC/DC0%0/2
$$_{'type'} eq 'A' || $$_{'type'} eq 'AAAA'
$$_{'type'} eq 'A' $$_{'type'} eq 'AAAA'
MC/DC100%1/1
$by{$_[0]} || []
$by{$_[0]}
Truth table33%1/3
A || B
A= $$_{'type'} eq 'A'B= $$_{'type'} eq 'AAAA'
ABresult
1X1
011
000
Truth table100%2/2
A
A= $by{$_[0]}
Aresult
11
00
325 22 ▶ my $is_cname = sub { grep { $_->{type} eq 'CNAME' } @{ $by{ $_[0] } || [] } };
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$by{$_[0]} || []
l!l
651
MC/DC100%1/1
$by{$_[0]} || []
$by{$_[0]}
Truth table100%2/2
A
A= $by{$_[0]}
Aresult
11
00
326 22 ▶ for my $r ( grep { $_->{type} eq 'NS' || $_->{type} eq 'MX' || $_->{type} eq 'SRV' } @in ) {
Condition83%5/6
$$_{'type'} eq 'NS' || $$_{'type'} eq 'MX' || $$_{'type'} eq 'SRV'
l!l&&r!l&&!r
660159
$$_{"type"} eq "NS" or $$_{"type"} eq "MX"
l!l&&r!l&&!r
4422159
MC/DC66%2/3
$$_{'type'} eq 'NS' || $$_{'type'} eq 'MX' || $$_{'type'} eq 'SRV'
$$_{"type"} eq "NS" $$_{"type"} eq "MX" $$_{'type'} eq 'SRV'
Truth table75%3/4
A or B || C
A= $$_{"type"} eq "NS"B= $$_{"type"} eq "MX"C= $$_{'type'} eq 'SRV'
ABCresult
1XX1
01X1
0011
0000
327 66 my $tg = ( split ' ', $r->{rd} )[-1];
328 66 ▶ next unless $tg eq $apex || $tg =~ /\.\Q$apex\E\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tg eq $apex or $tg =~ /\.\Q$apex\E\z/ 0 66 66
Condition33%1/3
$tg eq $apex or $tg =~ /\.\Q$apex\E\z/
l!l&&r!l&&!r
0660
MC/DC0%0/2
$tg eq $apex or $tg =~ /\.\Q$apex\E\z/
$tg eq $apex $tg =~ /\.\Q$apex\E\z/
Truth table33%1/3
A or B
A= $tg eq $apexB= $tg =~ /\.\Q$apex\E\z/
ABresult
1X1
011
000
329 66 ( my $t = $tg ) =~ s/\.\z//;
330 66 ( my $o = $r->{owner} ) =~ s/\.\z//;
331 66 ▶ if ( $is_cname->($tg) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (&$is_cname($tg)) { } 0 66 66
elsif (not &$has_addr($tg)) { } 1 65 66
332 0 ▶ push @{ $r->{type} eq 'NS' ? \@err : \@warn }, "zone $zone/IN: $o/$r->{type} '$t' is a CNAME (illegal)";
Branch: 1 branch
BranchTrueFalseTotal
$$r{'type'} eq 'NS' ? : 0 0 0
333 }
334 elsif ( !$has_addr->($tg) ) {
335 1 ▶ if ( $r->{type} eq 'NS' ) { push @err, "zone $zone/IN: NS '$t' has no address records (A or AAAA)" }
Branch: 1 branch
BranchTrueFalseTotal
if ($$r{'type'} eq 'NS') { } 1 0 1
336 0 else { push @warn, "zone $zone/IN: $o/$r->{type} '$t' has no address records (A or AAAA)" }
337 }
338 }
339 22 ▶ push @err, "zone $zone/IN: not loaded due to errors." if @err;
Branch: 1 branch
BranchTrueFalseTotal
if @err 5 17 22
340 }
341 2 else { push @err, "zone $zone/IN: not loaded due to errors." }
342 24 my ( @records, %sh );
343 24 for my $r (@in) {
344 245 my $k = "$r->{owner} $r->{ttl} IN $r->{type} $r->{rd}";
345 245 push @records, $k;
346 245 ▶ $sh{$k} = $r->{show} if $r->{show} ne $r->{rd};
Branch: 1 branch
BranchTrueFalseTotal
if $$r{"show"} ne $$r{"rd"} 25 220 245
347 }
348 return { ok => @err ? 0 : 1, errors => \@err, warnings => \@warn,
349 24 ▶ ( $soa ? ( serial => 0 + ( split ' ', $soa->{rd} )[2] ) : () ), records => \@records, show => \%sh };
Branch: 2 branches
BranchTrueFalseTotal
@err ? : 7 17 24
$soa ? : 24 0 24
350 }
351  
352 # --- Laden ------------------------------------------------------------------------
353  
354 13 ▶sub _log {
Subroutine _log: called CC=4 SCAR=14.8
355 13 my ( $dev, @l ) = @_;
356 13 ▶ my $b = $dev->{bind} //= {};
Condition50%1/2
$$dev{"bind"} //= {}
l!l
130
MC/DC0%0/1
$$dev{"bind"} //= {}
$$dev{"bind"}
Truth table50%1/2
A
A= $$dev{"bind"}
Aresult
11
00
357 13 ▶ my $h = $dev->{hostname} // 'ns';
Condition50%1/2
$$dev{"hostname"} // "ns"
l!l
013
MC/DC0%0/1
$$dev{"hostname"} // "ns"
$$dev{"hostname"}
Truth table50%1/2
A
A= $$dev{"hostname"}
Aresult
11
00
358 13 push @{ $b->{log} }, map {"Oct 20 12:00:00 $h named[812]: $_"} @l;
359 0 ▶ splice @{ $b->{log} }, 0, @{ $b->{log} } - 40 if @{ $b->{log} } > 40;
Branch: 1 branch
BranchTrueFalseTotal
if @{$$b{"log"};} > 40 0 13 13
360 13 return;
361 }
362  
363 16 ▶sub _zone_entry {
Subroutine _zone_entry: called CC=7 SCAR=19.9
364 16 my ( $z, $p ) = @_;
365 16 my %e = ( type => $z->{type} );
366 16 ▶ $e{file} = $z->{path} if defined $z->{path};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$z{"path"} 16 0 16
367 16 $e{$_} = $z->{$_} for grep { $z->{$_} } qw( allow_transfer also_notify primaries );
368 16 ▶ $e{notify} = $z->{notify} if defined $z->{notify};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$z{"notify"} 0 16 16
369 16 ▶ if ($p) { $e{serial} = $p->{serial}; $e{records} = $p->{records}; $e{show} = $p->{show} if %{ $p->{show} || {} } }
Branch: 2 branches
BranchTrueFalseTotal
if ($p) 13 3 16
if %{$$p{"show"} or {};} 13 0 13
Condition50%1/2
$$p{'show'} || {}
l!l
130
MC/DC0%0/1
$$p{'show'} || {}
$$p{'show'}
Truth table50%1/2
A
A= $$p{'show'}
Aresult
11
00
370 16 return \%e;
371 }
372  
373 4 ▶sub _serial_gt {
Subroutine _serial_gt: called CC=6 SCAR=19.3
374 4 my ( $a, $b ) = @_;
375 4 ▶ return 1 if !defined $b;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $b 0 4 4
376 4 ▶ return 0 if !defined $a || $a == $b;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $a or $a == $b 1 3 4
Condition66%2/3
not defined $a or $a == $b
l!l&&r!l&&!r
013
MC/DC50%1/2
not defined $a or $a == $b
not defined $a $a == $b
Truth table66%2/3
not(A) or B
A= not defined $aB= $a == $b
ABresult
1X1
011
000
377 3 my $d = ( $a - $b ) % 4294967296;
378 3 ▶ return $d > 0 && $d < 2147483648 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$d > 0 && $d < 2147483648 ? : 3 0 3
Condition33%1/3
$d > 0 and $d < 2147483648
!ll&&!rl&&r
003
MC/DC0%0/2
$d > 0 and $d < 2147483648
$d > 0 $d < 2147483648
Truth table33%1/3
A and B
A= $d > 0B= $d < 2147483648
ABresult
0X0
100
111
379 }
380  
381  
382 10 ▶sub prepare {
Subroutine prepare: called CC=18 SCAR=32.1
Pod documented
383 10 my ( $dev, $ctx ) = @_;
384 10 ▶ my $b = $dev->{bind} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $b = $$dev{"bind"} or return 10 0 10
385 10 ▶ return if $b->{zones};
Branch: 1 branch
BranchTrueFalseTotal
if $$b{"zones"} 0 10 10
386 0 ▶ my %over = map { $_ => $b->{source}{$_} } grep {m{\A/}} keys %{ $b->{source} || {} };
Condition100%2/2
$$b{'source'} || {}
l!l
55
MC/DC100%1/1
$$b{'source'} || {}
$$b{'source'}
Truth table100%2/2
A
A= $$b{'source'}
Aresult
11
00
387 10 ▶ local $dev->{files} = { %{ $dev->{files} || {} }, %over };
Condition50%1/2
$$dev{'files'} || {}
l!l
100
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
388 10 my $c = parse_conf($dev);
389 10 my %z;
390 10 for my $n ( sort keys %{ $c->{zones} } ) {
391 10 my $cz = $c->{zones}{$n};
392 10 ▶ my %d = ( %$cz, allow_transfer => $cz->{allow_transfer} // $c->{allow_transfer}, also_notify => $cz->{also_notify} // $c->{also_notify} );
Condition50%3/6
$$cz{"allow_transfer"} // $$c{"allow_transfer"}
l!l&&r!l&&!r
505
$$cz{"also_notify"} // $$c{"also_notify"}
l!l&&r!l&&!r
0010
MC/DC50%1/2
$$cz{"allow_transfer"} // $$c{"allow_transfer"}
$$cz{"allow_transfer"} $$c{"allow_transfer"}
MC/DC0%0/2
$$cz{"also_notify"} // $$c{"also_notify"}
$$cz{"also_notify"} $$c{"also_notify"}
Truth table66%2/3
A // B
A= $$cz{"allow_transfer"}B= $$c{"allow_transfer"}
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $$cz{"also_notify"}B= $$c{"also_notify"}
ABresult
1X1
011
000
393 10 ▶ if ( $cz->{type} eq 'primary' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$cz{'type'} eq 'primary') { } 5 5 10
elsif ($$cz{'type'} eq 'secondary') { } 5 0 5
394 5 ▶ my $text = ( $b->{source} || {} )->{$n} // _text( $dev, $cz->{path} );
Condition40%2/5
($$b{"source"} || {})->{$n} // _text($dev, $$cz{"path"})
l!l&&r!l&&!r
050
$$b{'source'} || {}
l!l
05
MC/DC0%0/2
($$b{"source"} || {})->{$n} // _text($dev, $$cz{"path"})
$$b{'source'} _text($dev, $$cz{"path"})
Truth table33%1/3
A // B
A= $$b{'source'}B= _text($dev, $$cz{"path"})
ABresult
1X1
011
000
395 5 ▶ die "prepare: Zone $n ohne Text\n" unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 5 5
396 5 my $p = parse_zone( $text, $n, $cz->{file} );
397 0 ▶ die "prepare: Zone $n laedt nicht: @{ $p->{errors} }\n" unless $p->{ok};
Branch: 1 branch
BranchTrueFalseTotal
unless $$p{"ok"} 0 5 5
398 5 $z{$n} = _zone_entry( \%d, $p );
399 }
400 elsif ( $cz->{type} eq 'secondary' ) {
401 5 ▶ my $text = ( $b->{source} || {} )->{$n};
Condition50%1/2
$$b{'source'} || {}
l!l
50
MC/DC0%0/1
$$b{'source'} || {}
$$b{'source'}
Truth table50%1/2
A
A= $$b{'source'}
Aresult
11
00
402 5 ▶ $z{$n} = _zone_entry( \%d, defined $text ? parse_zone( $text, $n ) : undef );
Branch: 1 branch
BranchTrueFalseTotal
defined $text ? : 5 0 5
403 5 _secondary_file( $dev, $z{$n} );
404 }
405 }
406 10 $b->{zones} = \%z;
407 10 delete $b->{source};
408 10 ▶ $dev->{dirs}{$_} //= {} for '/var/cache/bind', '/etc/bind'; # legt das Paket an
Condition50%1/2
$$dev{"dirs"}{$_} //= {}
l!l
020
MC/DC0%0/1
$$dev{"dirs"}{$_} //= {}
$$dev{"dirs"}{$_}
Truth table50%1/2
A
A= $$dev{"dirs"}{$_}
Aresult
11
00
409 10 return;
410 }
411  
412 # Sekundaerzone: named schreibt die uebertragene Zone in ihre Datei (hier als Text)
413 7 ▶sub _secondary_file {
Subroutine _secondary_file: called CC=5 SCAR=17.0
414 7 my ( $dev, $z ) = @_;
415 7 ▶ return unless defined $z->{file} && $z->{records};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$z{"file"} and $$z{"records"} 0 7 7
Condition33%1/3
defined $$z{"file"} and $$z{"records"}
!ll&&!rl&&r
007
MC/DC0%0/2
defined $$z{"file"} and $$z{"records"}
defined $$z{"file"} $$z{"records"}
Truth table33%1/3
A and B
A= defined $$z{"file"}B= $$z{"records"}
ABresult
0X0
100
111
416 7 ▶ my $text = '$ORIGIN .' . "\n" . join( '', map {"$_\n"} map { my @f = split ' ', $_, 5; "$f[0]\t$f[1]\tIN $f[3]\t" . ( ( $z->{show} || {} )->{$_} // $f[4] ) } @{ $z->{records} } );
Condition60%3/5
($$z{"show"} || {})->{$_} // $f[4]
l!l&&r!l&&!r
7640
$$z{'show'} || {}
l!l
710
MC/DC0%0/2
($$z{"show"} || {})->{$_} // $f[4]
$$z{'show'} $f[4]
Truth table33%1/3
A // B
A= $$z{'show'}B= $f[4]
ABresult
1X1
011
000
417 7 $dev->{files}{ $z->{file} } = { content => $text, owner => 'bind', group => 'bind', mode => '0644' };
418 7 return;
419 }
420  
421 # named laedt: mode reload (alte Zone bleibt bei Fehler), start (frisch),
422 # reconfig (nur neue Zonen und Optionen), zone (nur diese Zone).
423  
424 8 ▶sub load {
Subroutine load: called CC=30 SCAR=39.5
Pod documented
425 8 my ( $dev, $ctx, $mode, $only ) = @_;
426 8 ▶ my $b = $dev->{bind} //= {};
Condition50%1/2
$$dev{"bind"} //= {}
l!l
80
MC/DC0%0/1
$$dev{"bind"} //= {}
$$dev{"bind"}
Truth table50%1/2
A
A= $$dev{"bind"}
Aresult
11
00
427 8 ▶ my $old = $b->{zones} || {};
Condition50%1/2
$$b{'zones'} || {}
l!l
80
MC/DC0%0/1
$$b{'zones'} || {}
$$b{'zones'}
Truth table50%1/2
A
A= $$b{'zones'}
Aresult
11
00
428 8 my $c = eval { parse_conf($dev) };
429 8 ▶ if ( my $e = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 2 6 8
430 2 $e =~ s/\s+\z//;
431 2 _log( $dev, $e, 'reloading configuration failed: unexpected token' );
432 2 return ( $e, 0 );
433 }
434 6 my %new;
435 my @notify;
436 6 for my $n ( sort keys %{ $c->{zones} } ) {
437 6 my $cz = $c->{zones}{$n};
438 6 ▶ my %d = ( %$cz, allow_transfer => $cz->{allow_transfer} // $c->{allow_transfer}, also_notify => $cz->{also_notify} // $c->{also_notify} );
Condition33%2/6
$$cz{"allow_transfer"} // $$c{"allow_transfer"}
l!l&&r!l&&!r
600
$$cz{"also_notify"} // $$c{"also_notify"}
l!l&&r!l&&!r
006
MC/DC0%0/2
$$cz{"allow_transfer"} // $$c{"allow_transfer"}
$$cz{"allow_transfer"} $$c{"allow_transfer"}
MC/DC0%0/2
$$cz{"also_notify"} // $$c{"also_notify"}
$$cz{"also_notify"} $$c{"also_notify"}
Truth table33%1/3
A // B
A= $$cz{"allow_transfer"}B= $$c{"allow_transfer"}
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $$cz{"also_notify"}B= $$c{"also_notify"}
ABresult
1X1
011
000
439 6 my $was = $old->{$n};
440 6 ▶ if ( $cz->{type} eq 'primary' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$cz{'type'} eq 'primary') { } 6 0 6
elsif ($$cz{'type'} eq 'secondary') { } 0 0 0
441 6 ▶ my $keep = $mode eq 'reconfig' && $was || defined $only && $only ne $n && $was;
Condition58%7/12
$mode eq 'reconfig' && $was || defined $only && $only ne $n && $was
l!l&&r!l&&!r
105
$mode eq "reconfig" and $was
!ll&&!rl&&r
501
defined $only and $only ne $n and $was
!ll&&!rl&&r
500
defined $only and $only ne $n
!ll&&!rl&&r
410
MC/DC20%1/5
$mode eq 'reconfig' && $was || defined $only && $only ne $n && $was
$mode eq "reconfig" $was defined $only $only ne $n $was
Truth table33%3/9
A and B || C and D and E
A= $mode eq "reconfig"B= $wasC= defined $onlyD= $only ne $nE= $was
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
442 6 ▶ if ($keep) { $new{$n} = { %{ _zone_entry( \%d ) }, map { exists $was->{$_} ? ( $_ => $was->{$_} ) : () } qw( serial records show ) }; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($keep) 1 5 6
exists $$was{$_} ? : 3 0 3
443 5 my $text = _text( $dev, $cz->{path} );
444 5 ▶ my $p = defined $text ? parse_zone( $text, $n, $cz->{file} ) : { ok => 0,
Branch: 1 branch
BranchTrueFalseTotal
defined $text ? : 5 0 5
445 errors => [ "zone $n/IN: loading from master file $cz->{file} failed: file not found", "zone $n/IN: not loaded due to errors." ] };
446 5 ▶ if ( $p->{ok} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$p{'ok'}) { } 3 2 5
447 3 _log( $dev, @{ $p->{warnings} }, "zone $n/IN: loaded serial $p->{serial}" );
448 3 $new{$n} = _zone_entry( \%d, $p );
449 3 ▶ push @notify, $n if !$was || _serial_gt( $p->{serial}, $was->{serial} );
Branch: 1 branch
BranchTrueFalseTotal
if not $was or _serial_gt($$p{"serial"}, $$was{"serial"}) 2 1 3
Condition66%2/3
not $was or _serial_gt($$p{"serial"}, $$was{"serial"})
l!l&&r!l&&!r
021
MC/DC50%1/2
not $was or _serial_gt($$p{"serial"}, $$was{"serial"})
not $was _serial_gt($$p{"serial"}, $$was{"serial"})
Truth table66%2/3
not(A) or B
A= not $wasB= _serial_gt($$p{"serial"}, $$was{"serial"})
ABresult
1X1
011
000
450 }
451 else {
452 2 _log( $dev, @{ $p->{errors} } );
453 $new{$n} = $mode eq 'start' || !$was || !$was->{records} ? _zone_entry( \%d )
454 2 ▶ : { %{ _zone_entry( \%d ) }, map { exists $was->{$_} ? ( $_ => $was->{$_} ) : () } qw( serial records show ) };
Branch: 2 branches
BranchTrueFalseTotal
$mode eq 'start' || !$was || !$$was{'records'} ? : 1 1 2
exists $$was{$_} ? : 3 0 3
Condition66%4/6
$mode eq "start" or not $was or not $$was{"records"}
l!l&&r!l&&!r
101
$mode eq "start" or not $was
l!l&&r!l&&!r
101
MC/DC33%1/3
$mode eq "start" or not $was or not $$was{"records"}
$mode eq "start" not $was not $$was{"records"}
Truth table50%2/4
A or not(B) or not(C)
A= $mode eq "start"B= not $wasC= not $$was{"records"}
ABCresult
1XX1
01X1
0011
0000
455 2 ▶ return ( $p->{errors}[0] =~ s/\A.*failed: //r, 0, \%new ) if defined $only && $only eq $n;
Branch: 1 branch
BranchTrueFalseTotal
if defined $only and $only eq $n 1 1 2
Condition66%2/3
defined $only and $only eq $n
!ll&&!rl&&r
101
MC/DC50%1/2
defined $only and $only eq $n
defined $only $only eq $n
Truth table66%2/3
A and B
A= defined $onlyB= $only eq $n
ABresult
0X0
100
111
456 }
457 }
458 elsif ( $cz->{type} eq 'secondary' ) {
459 0 ▶ $new{$n} = { %{ _zone_entry( \%d ) }, $was ? ( map { exists $was->{$_} ? ( $_ => $was->{$_} ) : () } qw( serial records show ) ) : () };
Branch: 2 branches
BranchTrueFalseTotal
$was ? : 0 0 0
exists $$was{$_} ? : 0 0 0
460 }
461 }
462 5 $b->{zones} = \%new;
463 5 _notify( $dev, $ctx, $_ ) for @notify;
464 # neue Sekundaerzonen holen
465 0 ▶ for my $n ( grep { $new{$_}{type} eq 'secondary' && !$new{$_}{records} } sort keys %new ) { transfer( $dev, $ctx, $n, 1 ) }
Condition33%1/3
$new{$_}{'type'} eq 'secondary' && !$new{$_}{'records'}
!ll&&!rl&&r
500
MC/DC0%0/2
$new{$_}{'type'} eq 'secondary' && !$new{$_}{'records'}
$new{$_}{'type'} eq 'secondary' !$new{$_}{'records'}
Truth table33%1/3
A && not(B)
A= $new{$_}{'type'} eq 'secondary'B= !$new{$_}{'records'}
ABresult
0X0
100
111
466 5 return ( '', 1 );
467 }
468  
469 6 ▶sub _devices {
Subroutine _devices: called CC=4 SCAR=15.2
470 6 my ($ctx) = @_;
471 6 ▶ my $st = $ctx->{state} || {};
Condition50%1/2
$$ctx{'state'} || {}
l!l
60
MC/DC0%0/1
$$ctx{'state'} || {}
$$ctx{'state'}
Truth table50%1/2
A
A= $$ctx{'state'}
Aresult
11
00
472 6 ▶ return map { [ $_, $st->{$_} ] } grep { ref $st->{$_} eq 'HASH' && ( $st->{$_}{type} // '' ) eq 'linux' } sort keys %$st;
Condition40%2/5
ref $$st{$_} eq 'HASH' && ($$st{$_}{'type'} // '') eq 'linux'
!ll&&!rl&&r
0012
$$st{$_}{"type"} // ""
l!l
120
MC/DC0%0/2
ref $$st{$_} eq 'HASH' && ($$st{$_}{'type'} // '') eq 'linux'
ref $$st{$_} eq 'HASH' $$st{$_}{"type"}
Truth table33%1/3
A && B
A= ref $$st{$_} eq 'HASH'B= $$st{$_}{"type"}
ABresult
0X0
100
111
473 }
474  
475 6 ▶sub _device_by_ip {
Subroutine _device_by_ip: called CC=4 SCAR=14.2
476 6 my ( $ctx, $ip ) = @_;
477 6 ▶ for my $d ( _devices($ctx) ) { return @$d if $d->[0] eq $ip || grep { $_ eq $ip } _ip_of( $d->[1] ) }
Branch: 1 branch
BranchTrueFalseTotal
if $$d[0] eq $ip or grep {$_ eq $ip;} _ip_of($$d[1]) 6 3 9
Condition66%2/3
$$d[0] eq $ip or grep {$_ eq $ip;} _ip_of($$d[1])
l!l&&r!l&&!r
063
MC/DC50%1/2
$$d[0] eq $ip or grep {$_ eq $ip;} _ip_of($$d[1])
$$d[0] eq $ip grep {$_ eq $ip;} _ip_of($$d[1])
Truth table66%2/3
A or B
A= $$d[0] eq $ipB= grep {$_ eq $ip;} _ip_of($$d[1])
ABresult
1X1
011
000
478 0 return;
479 }
480  
481 4 ▶sub _allowed {
Subroutine _allowed: called CC=11 SCAR=32.1
482 4 my ( $list, @ips ) = @_;
483 4 ▶ return 1 unless $list;
Branch: 1 branch
BranchTrueFalseTotal
unless $list 0 4 4
484 4 for my $e (@$list) {
485 4 ▶ return 0 if $e eq 'none';
Branch: 1 branch
BranchTrueFalseTotal
if $e eq "none" 0 4 4
486 4 ▶ return 1 if $e eq 'any';
Branch: 1 branch
BranchTrueFalseTotal
if $e eq "any" 0 4 4
487 4 for my $ip (@ips) {
488 5 ▶ return 1 if $e eq $ip || $e eq "$ip/32";
Branch: 1 branch
BranchTrueFalseTotal
if $e eq $ip or $e eq "$ip/32" 2 3 5
Condition66%2/3
$e eq $ip or $e eq "$ip/32"
l!l&&r!l&&!r
203
MC/DC50%1/2
$e eq $ip or $e eq "$ip/32"
$e eq $ip $e eq "$ip/32"
Truth table66%2/3
A or B
A= $e eq $ipB= $e eq "$ip/32"
ABresult
1X1
011
000
489 3 ▶ if ( $e =~ m{\A([\d.]+)/(\d+)\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e =~ m[\A([\d.]+)/(\d+)\z]) 0 3 3
490 0 my ( $n, $len ) = ( $1, $2 );
491 0 ▶ my $m = $len ? ( 0xffffffff << ( 32 - $len ) ) & 0xffffffff : 0;
Branch: 1 branch
BranchTrueFalseTotal
$len ? : 0 0 0
492 0 ▶ my $f = sub { my $x = 0; $x = $x * 256 + $_ for split /\./, $_[0]; $x };
Subroutine __ANON__: not called CC=2 SCAR=17.9
493 0 ▶ return 1 if ( $f->($ip) & $m ) == ( $f->($n) & $m );
Branch: 1 branch
BranchTrueFalseTotal
if (&$f($ip) & $m) == (&$f($n) & $m) 0 0 0
494 }
495 }
496 }
497 2 return 0;
498 }
499  
500 2 ▶sub _notify {
Subroutine _notify: called CC=18 SCAR=32.0
501 2 my ( $dev, $ctx, $n ) = @_;
502 2 ▶ my $z = $dev->{bind}{zones}{$n} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $z = $$dev{"bind"}{"zones"}{$n} or return 2 0 2
503 2 ▶ return if ( $z->{notify} // '' ) eq 'no';
Branch: 1 branch
BranchTrueFalseTotal
if ($$z{"notify"} // "") eq "no" 0 2 2
Condition50%1/2
$$z{"notify"} // ""
l!l
02
MC/DC0%0/1
$$z{"notify"} // ""
$$z{"notify"}
Truth table50%1/2
A
A= $$z{"notify"}
Aresult
11
00
504 2 my $apex = "$n.";
505 2 my %ip;
506 2 ▶ for my $r ( grep {/\A\Q$apex\E \d+ IN NS /} @{ $z->{records} || [] } ) {
Condition50%1/2
$$z{'records'} || []
l!l
20
MC/DC0%0/1
$$z{'records'} || []
$$z{'records'}
Truth table50%1/2
A
A= $$z{'records'}
Aresult
11
00
507 4 my $tg = ( split ' ', $r )[-1];
508 4 $ip{$_} = 1 for map { ( split ' ', $_ )[-1] } grep {/\A\Q$tg\E \d+ IN A /} @{ $z->{records} };
509 }
510 0 ▶ $ip{$_} = 1 for map { ( split ' ' )[0] } @{ $z->{also_notify} || [] };
Condition50%1/2
$$z{'also_notify'} || []
l!l
02
MC/DC0%0/1
$$z{'also_notify'} || []
$$z{'also_notify'}
Truth table50%1/2
A
A= $$z{'also_notify'}
Aresult
11
00
511 2 my %self = map { $_ => 1 } _ip_of($dev);
512 2 my $host = $ctx->{host};
513 2 for my $ip ( sort grep { !$self{$_} } keys %ip ) {
514 2 ▶ my ( $name, $sec ) = _device_by_ip( $ctx, $ip ) or next;
Branch: 1 branch
BranchTrueFalseTotal
() = _device_by_ip($ctx, $ip) or next 2 0 2
515 2 ▶ next if $name eq ( $host // '' );
Branch: 1 branch
BranchTrueFalseTotal
if $name eq ($host // "") 0 2 2
Condition50%1/2
$host // ""
l!l
20
MC/DC0%0/1
$host // ""
$host
Truth table50%1/2
A
A= $host
Aresult
11
00
516 2 ▶ my $sz = ( ( $sec->{bind} || {} )->{zones} || {} )->{$n} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $sz = (($$sec{"bind"} || {})->{"zones"} || {})->{$n} or next 2 0 2
Condition50%2/4
($$sec{'bind'} || {})->{'zones'} || {}
l!l
20
$$sec{'bind'} || {}
l!l
20
MC/DC0%0/1
($$sec{'bind'} || {})->{'zones'} || {}
$$sec{'bind'}
Truth table50%1/2
A
A= $$sec{'bind'}
Aresult
11
00
517 2 ▶ next unless $sz->{type} eq 'secondary' && _running($sec);
Branch: 1 branch
BranchTrueFalseTotal
unless $$sz{"type"} eq "secondary" and _running($sec) 0 2 2
Condition33%1/3
$$sz{"type"} eq "secondary" and _running($sec)
!ll&&!rl&&r
002
MC/DC0%0/2
$$sz{"type"} eq "secondary" and _running($sec)
$$sz{"type"} eq "secondary" _running($sec)
Truth table33%1/3
A and B
A= $$sz{"type"} eq "secondary"B= _running($sec)
ABresult
0X0
100
111
518 2 _log( $dev, "zone $n/IN: sending notifies (serial $z->{serial})" );
519 2 transfer( $sec, { %$ctx, host => $name }, $n, 0 );
520 }
521 2 return;
522 }
523  
524  
525 3 ▶sub transfer {
Subroutine transfer: called CC=16 SCAR=33.2
Pod documented
526 3 my ( $dev, $ctx, $n, $force ) = @_;
527 3 ▶ my $z = $dev->{bind}{zones}{$n} or return ( "zone $n: not found", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $z = $$dev{"bind"}{"zones"}{$n} or return "zone ${n}: not found", 0 3 0 3
528 3 my @mine = _ip_of($dev);
529 3 ▶ for my $p ( map { ( split ' ' )[0] } @{ $z->{primaries} || [] } ) {
Condition50%1/2
$$z{'primaries'} || []
l!l
30
MC/DC0%0/1
$$z{'primaries'} || []
$$z{'primaries'}
Truth table50%1/2
A
A= $$z{'primaries'}
Aresult
11
00
530 3 ▶ my ( $pn, $pd ) = _device_by_ip( $ctx, $p ) or next;
Branch: 1 branch
BranchTrueFalseTotal
() = _device_by_ip($ctx, $p) or next 3 0 3
531 3 ▶ next unless _running($pd);
Branch: 1 branch
BranchTrueFalseTotal
unless _running($pd) 0 3 3
532 3 ▶ my $pz = ( ( $pd->{bind} || {} )->{zones} || {} )->{$n};
Condition50%2/4
($$pd{'bind'} || {})->{'zones'} || {}
l!l
30
$$pd{'bind'} || {}
l!l
30
MC/DC0%0/1
($$pd{'bind'} || {})->{'zones'} || {}
$$pd{'bind'}
Truth table50%1/2
A
A= $$pd{'bind'}
Aresult
11
00
533 3 ▶ next unless $pz && $pz->{type} eq 'primary' && $pz->{records};
Branch: 1 branch
BranchTrueFalseTotal
unless $pz and $$pz{"type"} eq "primary" and $$pz{"records"} 0 3 3
Condition33%2/6
$pz and $$pz{"type"} eq "primary" and $$pz{"records"}
!ll&&!rl&&r
003
$pz and $$pz{"type"} eq "primary"
!ll&&!rl&&r
003
MC/DC0%0/3
$pz and $$pz{"type"} eq "primary" and $$pz{"records"}
$pz $$pz{"type"} eq "primary" $$pz{"records"}
Truth table25%1/4
A and B and C
A= $pzB= $$pz{"type"} eq "primary"C= $$pz{"records"}
ABCresult
0XX0
10X0
1100
1111
534 3 ▶ if ( !_allowed( $pz->{allow_transfer}, @mine ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_allowed($$pz{"allow_transfer"}, @mine)) 1 2 3
535 1 _log( $dev, "transfer of '$n/IN' from $p#53: failed while receiving responses: REFUSED" );
536 1 _log( $pd, "client \@0x7f3a $mine[0]#40112 ($n): zone transfer '$n/AXFR/IN' denied" );
537 1 return ( 'REFUSED', 0 );
538 }
539 2 ▶ if ( !$force && !_serial_gt( $pz->{serial}, $z->{serial} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($force or _serial_gt($$pz{"serial"}, $$z{"serial"})) 0 2 2
Condition66%2/3
$force or _serial_gt($$pz{"serial"}, $$z{"serial"})
l!l&&r!l&&!r
110
MC/DC0%0/2
$force or _serial_gt($$pz{"serial"}, $$z{"serial"})
$force _serial_gt($$pz{"serial"}, $$z{"serial"})
Truth table66%2/3
A or B
A= $forceB= _serial_gt($$pz{"serial"}, $$z{"serial"})
ABresult
1X1
011
000
540 0 ▶ _log( $dev, "zone $n/IN: zone is up to date (serial $z->{serial})" ) if defined $z->{serial};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$z{"serial"} 0 0 0
541 0 return ( 'up to date', 1 );
542 }
543 2 @{$z}{qw( serial records )} = @{$pz}{qw( serial records )};
544 0 ▶ if ( $pz->{show} ) { $z->{show} = $pz->{show} } else { delete $z->{show} }
Branch: 1 branch
BranchTrueFalseTotal
if ($$pz{'show'}) { } 2 0 2
545 2 _secondary_file( $dev, $z );
546 2 _log( $dev, "zone $n/IN: transferred serial $pz->{serial}", "transfer of '$n/IN' from $p#53: Transfer completed" );
547 2 return ( 'transferred', 1 );
548 }
549 0 _log( $dev, "zone $n/IN: refresh: retry limit for primary reached" );
550 0 return ( 'no primary reachable', 0 );
551 }
552  
553  
554 3 ▶sub service_event {
Subroutine service_event: called CC=5 SCAR=16.2
Pod documented
555 3 my ( $dev, $verb, $ctx ) = @_;
556 3 ▶ return if $verb eq 'stop';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "stop" 0 3 3
557 3 ▶ my ( $o, $ok ) = load( $dev, $ctx, $verb eq 'reload' ? 'reload' : 'start' );
Branch: 1 branch
BranchTrueFalseTotal
$verb eq 'reload' ? : 1 2 3
558 3 ▶ die "Job for named.service failed because the control process exited with error code.\n"
Branch: 1 branch
BranchTrueFalseTotal
if not $ok and $verb ne "reload" 1 2 3
Condition66%2/3
not $ok and $verb ne "reload"
!ll&&!rl&&r
201
MC/DC50%1/2
not $ok and $verb ne "reload"
not $ok $verb ne "reload"
Truth table66%2/3
not(A) and B
A= not $okB= $verb ne "reload"
ABresult
0X0
100
111
559 . "See \"systemctl status named.service\" and \"journalctl -xeu named.service\" for details.\n"
560 if !$ok && $verb ne 'reload';
561 2 return;
562 }
563  
564 # --- Befehle ----------------------------------------------------------------------
565  
566  
567 6 ▶sub rndc {
Subroutine rndc: called CC=31 SCAR=49.2
Pod documented
568 6 my ( $dev, $av, $ctx ) = @_;
569 6 my @a = grep { !/\A-/ } @$av;
570 6 ▶ my $cmd = shift(@a) // '';
Condition50%1/2
shift @a // ""
l!l
60
MC/DC0%0/1
shift @a // ""
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
571 6 ▶ return ( "rndc: connect failed: 127.0.0.1#953: connection refused", 0 ) unless _running($dev);
Branch: 1 branch
BranchTrueFalseTotal
unless _running($dev) 0 6 6
572 6 ▶ my $zone = defined $a[0] ? lc( $a[0] =~ s/\.\z//r ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $a[0] ? : 2 4 6
573 6 ▶ my $zones = $dev->{bind}{zones} || {};
Condition50%1/2
$$dev{'bind'}{'zones'} || {}
l!l
60
MC/DC0%0/1
$$dev{'bind'}{'zones'} || {}
$$dev{'bind'}{'zones'}
Truth table50%1/2
A
A= $$dev{'bind'}{'zones'}
Aresult
11
00
574 6 ▶ if ( $cmd eq 'reload' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "reload") 4 2 6
575 4 ▶ if ( defined $zone ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $zone) 1 3 4
576 1 ▶ return ( "rndc: 'reload' failed: not found\nno matching zone '$zone' in any view", 0 ) unless $zones->{$zone};
Branch: 1 branch
BranchTrueFalseTotal
unless $$zones{$zone} 0 1 1
577 1 ▶ return ( "rndc: 'reload' failed: not a primary zone", 0 ) unless $zones->{$zone}{type} eq 'primary';
Branch: 1 branch
BranchTrueFalseTotal
unless $$zones{$zone}{"type"} eq "primary" 0 1 1
578 1 my $before = JSON::MaybeXS->new( canonical => 1 )->encode( $zones->{$zone} );
579 1 my ( $o, $ok ) = load( $dev, $ctx, 'zone', $zone );
580 1 ▶ return ( "rndc: 'reload' failed: $o", 0 ) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 0 1
581 0 ▶ return ( JSON::MaybeXS->new( canonical => 1 )->encode( $dev->{bind}{zones}{$zone} ) eq $before ? 'zone reload up-to-date' : 'zone reload queued', 1 );
Branch: 1 branch
BranchTrueFalseTotal
'JSON::MaybeXS'->new('canonical', 1)->encode($$dev{'bind'}{'zones'}{$zone}) eq $before ? : 0 0 0
582 }
583 3 my ( $o, $ok ) = load( $dev, $ctx, 'reload' );
584 3 ▶ return ( "rndc: 'reload' failed: unexpected token", 0 ) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 2 3
585 2 return ( 'server reload successful', 1 );
586 }
587 2 ▶ if ( $cmd eq 'reconfig' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "reconfig") 1 1 2
588 1 my ( $o, $ok ) = load( $dev, $ctx, 'reconfig' );
589 1 ▶ return ( "rndc: 'reconfig' failed: unexpected token", 0 ) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 1 1
590 1 return ( '', 1 );
591 }
592 1 ▶ if ( $cmd =~ /\A(?:retransfer|refresh|notify|zonestatus)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /\A(?:retransfer|refresh|notify|zonestatus)\z/) 1 0 1
593 1 ▶ return ( "rndc: '$cmd' failed: not found\nno matching zone '" . ( $zone // '' ) . "' in any view", 0 ) unless defined $zone && $zones->{$zone};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $zone and $$zones{$zone} 0 1 1
Condition20%1/5
defined $zone and $$zones{$zone}
!ll&&!rl&&r
001
$zone // ""
l!l
00
MC/DC0%0/2
defined $zone and $$zones{$zone}
defined $zone $$zones{$zone}
MC/DC0%0/1
$zone // ""
$zone
Truth table33%1/3
A and B
A= defined $zoneB= $$zones{$zone}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $zone
Aresult
11
00
594 1 my $z = $zones->{$zone};
595 1 ▶ if ( $cmd eq 'zonestatus' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "zonestatus") 0 1 1
596 return ( join( "\n", "name: $zone", "type: $z->{type}", ( defined $z->{file} ? "files: $z->{file}" : () ),
597 0 ▶ 'serial: ' . ( $z->{serial} // 0 ), 'nodes: ' . scalar( @{ $z->{records} || [] } ),
Branch: 1 branch
BranchTrueFalseTotal
$$z{'records'} ? : 0 0 0
Condition0%0/2
$$z{'records'} || []
l!l
00
MC/DC0%0/1
$$z{'records'} || []
$$z{'records'}
Truth table0%0/2
A
A= $$z{'records'}
Aresult
11
00
598 0 ▶ 'loaded: ' . ( $z->{records} ? 'yes' : 'no' ) ), 1 );
Branch: 1 branch
BranchTrueFalseTotal
defined $$z{'file'} ? : 0 0 0
Condition0%0/2
$$z{"serial"} // 0
l!l
00
MC/DC0%0/1
$$z{"serial"} // 0
$$z{"serial"}
Truth table0%0/2
A
A= $$z{"serial"}
Aresult
11
00
599 }
600 1 ▶ if ( $cmd eq 'notify' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "notify") 0 1 1
601 0 ▶ return ( "rndc: 'notify' failed: not a primary zone", 0 ) unless $z->{type} eq 'primary';
Branch: 1 branch
BranchTrueFalseTotal
unless $$z{"type"} eq "primary" 0 0 0
602 0 _notify( $dev, $ctx, $zone );
603 0 return ( 'zone notify queued', 1 );
604 }
605 1 ▶ return ( "rndc: '$cmd' failed: not a secondary zone", 0 ) unless $z->{type} eq 'secondary';
Branch: 1 branch
BranchTrueFalseTotal
unless $$z{"type"} eq "secondary" 0 1 1
606 1 transfer( $dev, $ctx, $zone, $cmd eq 'retransfer' );
607 1 ▶ return ( $cmd eq 'refresh' ? 'zone refresh queued' : '', 1 );
Branch: 1 branch
BranchTrueFalseTotal
$cmd eq 'refresh' ? : 0 1 1
608 }
609 0 ▶ if ( $cmd eq 'status' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "status") 0 0 0
610 0 return ( join( "\n", 'version: BIND 9.18.28-1~deb12u2-Debian (Extended Support Version) <id:>', 'running on localhost: Linux x86_64 6.1.0-26-amd64',
611 'number of zones: ' . ( 100 + keys %$zones ) . ' (99 automatic)', 'debug level: 0', 'xfers running: 0', 'server is up and running' ), 1 );
612 }
613 0 ▶ return ( '', 1 ) if $cmd eq 'flush' || $cmd eq 'freeze' || $cmd eq 'thaw';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "flush" or $cmd eq "freeze" or $cmd eq "thaw" 0 0 0
Condition0%0/6
$cmd eq "flush" or $cmd eq "freeze" or $cmd eq "thaw"
l!l&&r!l&&!r
000
$cmd eq "flush" or $cmd eq "freeze"
l!l&&r!l&&!r
000
MC/DC0%0/3
$cmd eq "flush" or $cmd eq "freeze" or $cmd eq "thaw"
$cmd eq "flush" $cmd eq "freeze" $cmd eq "thaw"
Truth table0%0/4
A or B or C
A= $cmd eq "flush"B= $cmd eq "freeze"C= $cmd eq "thaw"
ABCresult
1XX1
01X1
0011
0000
614 0 return ( "rndc: '$cmd' failed: unknown command", 0 );
615 }
616  
617  
618 3 ▶sub checkconf {
Subroutine checkconf: called CC=9 SCAR=22.0
Pod documented
619 3 my ( $dev, $av, $ctx ) = @_;
620 3 my $z = grep { $_ eq '-z' } @$av;
621 3 my ($file) = grep { !/\A-/ } @$av;
622 3 my $c = eval { parse_conf( $dev, $file ) };
623 3 ▶ if ( my $e = $@ ) { $e =~ s/\s+\z//; return ( $e, 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 1 2 3
624 2 ▶ return ( '', 1 ) unless $z;
Branch: 1 branch
BranchTrueFalseTotal
unless $z 0 2 2
625 2 my ( @o, $ok );
626 2 $ok = 1;
627 2 for my $n ( sort keys %{ $c->{zones} } ) {
628 2 my $cz = $c->{zones}{$n};
629 2 ▶ next unless $cz->{type} eq 'primary';
Branch: 1 branch
BranchTrueFalseTotal
unless $$cz{"type"} eq "primary" 0 2 2
630 2 my $t = _text( $dev, $cz->{path} );
631 2 ▶ my $p = defined $t ? parse_zone( $t, $n, $cz->{file} ) : { ok => 0, errors => ["zone $n/IN: loading from master file $cz->{file} failed: file not found"] };
Branch: 1 branch
BranchTrueFalseTotal
defined $t ? : 1 1 2
632 2 ▶ push @o, @{ $p->{warnings} || [] }, $p->{ok} ? "zone $n/IN: loaded serial $p->{serial}" : @{ $p->{errors} };
Branch: 1 branch
BranchTrueFalseTotal
$$p{'ok'} ? : 1 1 2
Condition100%2/2
$$p{'warnings'} || []
l!l
11
MC/DC100%1/1
$$p{'warnings'} || []
$$p{'warnings'}
Truth table100%2/2
A
A= $$p{'warnings'}
Aresult
11
00
633 2 ▶ $ok = 0 unless $p->{ok};
Branch: 1 branch
BranchTrueFalseTotal
unless $$p{"ok"} 1 1 2
634 }
635 2 return ( join( "\n", @o ), $ok );
636 }
637  
638  
639 1 ▶sub checkzone {
Subroutine checkzone: called CC=4 SCAR=14.2
Pod documented
640 1 my ( $dev, $av, $ctx ) = @_;
641 1 my @a = grep { !/\A-/ } @$av;
642 1 ▶ return ( "usage: named-checkzone [-djqvD] [-c class] [-f inputformat] [-F outputformat] zonename [ filename ]", 0 ) unless @a == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @a == 2 0 1 1
643 1 my ( $zone, $file ) = @a;
644 1 $zone = lc( $zone =~ s/\.\z//r );
645 1 my $t = _text( $dev, $file );
646 1 ▶ return ( "zone $zone/IN: loading from master file $file failed: file not found\nzone $zone/IN: not loaded due to errors.", 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 1 1
647 1 my $p = parse_zone( $t, $zone, $file );
648 0 ▶ return ( join( "\n", @{ $p->{warnings} }, "zone $zone/IN: loaded serial $p->{serial}", 'OK' ), 1 ) if $p->{ok};
Branch: 1 branch
BranchTrueFalseTotal
if $$p{"ok"} 0 1 1
649 1 return ( join( "\n", @{ $p->{warnings} }, @{ $p->{errors} } ), 0 );
650 }
651  
652 # Antwort eines Servers auf eine Frage: ( status, \@answer, \@authority, $aa ) oder Fehlertext
653 14 ▶sub _answer {
Subroutine _answer: called CC=17 SCAR=29.3
654 14 my ( $srv, $qname, $qtype ) = @_;
655 14 ▶ my $zones = ( $srv->{bind} || {} )->{zones} || {};
Condition50%2/4
($$srv{'bind'} || {})->{'zones'} || {}
l!l
140
$$srv{'bind'} || {}
l!l
140
MC/DC0%0/1
($$srv{'bind'} || {})->{'zones'} || {}
$$srv{'bind'}
Truth table50%1/2
A
A= $$srv{'bind'}
Aresult
11
00
656 0 ▶ my ($zn) = sort { length $b <=> length $a } grep { $qname eq "$_." || $qname =~ /\.\Q$_\E\.\z/ } keys %$zones;
Condition66%2/3
$qname eq "$_." || $qname =~ /\.\Q$_\E\.\z/
l!l&&r!l&&!r
590
MC/DC0%0/2
$qname eq "$_." || $qname =~ /\.\Q$_\E\.\z/
$qname eq "$_." $qname =~ /\.\Q$_\E\.\z/
Truth table66%2/3
A || B
A= $qname eq "$_."B= $qname =~ /\.\Q$_\E\.\z/
ABresult
1X1
011
000
657 14 ▶ return ( 'REFUSED', [], [], 0 ) unless defined $zn;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $zn 0 14 14
658 14 my $z = $zones->{$zn};
659 14 ▶ return ( 'SERVFAIL', [], [], 0 ) unless $z->{records};
Branch: 1 branch
BranchTrueFalseTotal
unless $$z{"records"} 1 13 14
660 13 my @r = @{ $z->{records} };
661 13 my ($soa) = grep {/\A\Q$zn\E\. \d+ IN SOA /} @r;
662 13 ▶ if ( $qtype eq 'AXFR' ) { return ( 'NOERROR', [ $soa, ( grep { $_ ne $soa } @r ), $soa ], [], 1, $z ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($qtype eq "AXFR") 1 12 13
663 12 my ( @ans, %seen );
664 12 my $name = $qname;
665 12 for ( 1 .. 8 ) {
666 13 my @here = grep { ( split ' ' )[0] eq $name } @r;
667 13 ▶ my @t = grep { my $ty = ( split ' ' )[3]; $qtype eq 'ANY' || $ty eq $qtype } @here;
Condition66%2/3
$qtype eq 'ANY' || $ty eq $qtype
l!l&&r!l&&!r
01117
MC/DC50%1/2
$qtype eq 'ANY' || $ty eq $qtype
$qtype eq 'ANY' $ty eq $qtype
Truth table66%2/3
A || B
A= $qtype eq 'ANY'B= $ty eq $qtype
ABresult
1X1
011
000
668 13 ▶ if (@t) { push @ans, @t; last }
Branch: 1 branch
BranchTrueFalseTotal
if (@t) 11 2 13
669 2 my ($cn) = grep { ( split ' ' )[3] eq 'CNAME' } @here;
670 2 ▶ last unless $cn && !$seen{$name}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $cn and not $seen{$name}++ 1 1 2
Condition66%2/3
$cn and not $seen{$name}++
!ll&&!rl&&r
101
MC/DC50%1/2
$cn and not $seen{$name}++
$cn not $seen{$name}++
Truth table66%2/3
A and not(B)
A= $cnB= not $seen{$name}++
ABresult
0X0
100
111
671 1 push @ans, $cn;
672 1 $name = ( split ' ', $cn )[-1];
673 1 ▶ last unless $name eq "$zn." || $name =~ /\.\Q$zn\E\.\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $name eq "$zn." or $name =~ /\.\Q$zn\E\.\z/ 0 1 1
Condition33%1/3
$name eq "$zn." or $name =~ /\.\Q$zn\E\.\z/
l!l&&r!l&&!r
010
MC/DC0%0/2
$name eq "$zn." or $name =~ /\.\Q$zn\E\.\z/
$name eq "$zn." $name =~ /\.\Q$zn\E\.\z/
Truth table33%1/3
A or B
A= $name eq "$zn."B= $name =~ /\.\Q$zn\E\.\z/
ABresult
1X1
011
000
674 }
675 12 ▶ return ( 'NOERROR', \@ans, [], 1, $z ) if @ans;
Branch: 1 branch
BranchTrueFalseTotal
if @ans 11 1 12
676 1 ▶ my $exists = grep { my $o = ( split ' ' )[0]; $o eq $qname || $o =~ /\.\Q$qname\E\z/ } @r;
Condition33%1/3
$o eq $qname || $o =~ /\.\Q$qname\E\z/
l!l&&r!l&&!r
0010
MC/DC0%0/2
$o eq $qname || $o =~ /\.\Q$qname\E\z/
$o eq $qname $o =~ /\.\Q$qname\E\z/
Truth table33%1/3
A || B
A= $o eq $qnameB= $o =~ /\.\Q$qname\E\z/
ABresult
1X1
011
000
677 1 ▶ return ( $exists ? 'NOERROR' : 'NXDOMAIN', [], [$soa], 1, $z );
Branch: 1 branch
BranchTrueFalseTotal
$exists ? : 0 1 1
678 }
679  
680 12 ▶sub _show {
Subroutine _show: called CC=4 SCAR=16.4
681 12 my ( $z, $rr ) = @_;
682 12 my @f = split ' ', $rr, 5;
683 12 ▶ my $d = ( $z && $z->{show} || {} )->{$rr} // $f[4];
Condition37%3/8
($z && $$z{"show"} || {})->{$rr} // $f[4]
l!l&&r!l&&!r
0120
$z && $$z{'show'} || {}
l!l
120
$z and $$z{"show"}
!ll&&!rl&&r
0012
MC/DC0%0/3
($z && $$z{"show"} || {})->{$rr} // $f[4]
$z $$z{"show"} $f[4]
Truth table0%0/5
A and B // C
A= $zB= $$z{"show"}C= $f[4]
ABCresult
11X1
0X11
1011
0X00
1000
684 12 return ( sprintf( "%s\t\t%s\tIN\t%s\t%s", @f[ 0, 1 ], $f[3], $d ), $d );
685 }
686  
687 # Server waehlen: ( name, dev ) | 'ext' mit dns_servers | Fehlertext
688 14 ▶sub _server {
Subroutine _server: called CC=13 SCAR=30.1
689 14 my ( $dev, $ctx, $srv ) = @_;
690 14 my $host = $ctx->{host};
691 14 ▶ if ( !defined $srv ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $srv) 9 5 14
692 9 ($srv) = _lx()->can('_nameservers')->($dev);
693 9 ▶ return ( undef, undef, ';; no nameservers configured' ) unless defined $srv;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $srv 0 9 9
694 }
695 14 ▶ if ( $srv eq '127.0.0.1' || $srv eq 'localhost' || $srv eq '::1' || $srv eq ( $host // '' ) || grep { $_ eq $srv } _ip_of($dev) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($srv eq "127.0.0.1" or $srv eq "localhost" or $srv eq "::1" or $srv eq ($host // "") or grep {$_ eq $srv;} _ip_of($dev)) 13 1 14
Condition71%10/14
$srv eq "127.0.0.1" or $srv eq "localhost" or $srv eq "::1" or $srv eq ($host // "") or grep {$_ eq $srv;} _ip_of($dev)
l!l&&r!l&&!r
1211
$srv eq "127.0.0.1" or $srv eq "localhost" or $srv eq "::1" or $srv eq ($host // "")
l!l&&r!l&&!r
1202
$srv eq "127.0.0.1" or $srv eq "localhost" or $srv eq "::1"
l!l&&r!l&&!r
1202
$srv eq "127.0.0.1" or $srv eq "localhost"
l!l&&r!l&&!r
1202
$host // ""
l!l
20
MC/DC40%2/5
$srv eq "127.0.0.1" or $srv eq "localhost" or $srv eq "::1" or $srv eq ($host // "") or grep {$_ eq $srv;} _ip_of($dev)
$srv eq "127.0.0.1" $srv eq "localhost" $srv eq "::1" $srv eq ($host // "") grep {$_ eq $srv;} _ip_of($dev)
MC/DC0%0/1
$host // ""
$host
Truth table50%3/6
A or B or C or D or E
A= $srv eq "127.0.0.1"B= $srv eq "localhost"C= $srv eq "::1"D= $srv eq ($host // "")E= grep {$_ eq $srv;} _ip_of($dev)
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
Truth table50%1/2
A
A= $host
Aresult
11
00
696 13 return ( $srv, $dev );
697 }
698 1 my ( $n, $d ) = _device_by_ip( $ctx, $srv );
699 1 ▶ return ( $srv, $d ) if $d;
Branch: 1 branch
BranchTrueFalseTotal
if $d 1 0 1
700 0 ▶ return ( $srv, undef, undef, ( $dev->{dns_servers} || {} )->{$srv} ) if ( $dev->{dns_servers} || {} )->{$srv};
Branch: 1 branch
BranchTrueFalseTotal
if ($$dev{"dns_servers"} || {})->{$srv} 0 0 0
Condition0%0/4
$$dev{'dns_servers'} || {}
l!l
00
$$dev{'dns_servers'} || {}
l!l
00
MC/DC0%0/1
$$dev{'dns_servers'} || {}
$$dev{'dns_servers'}
MC/DC0%0/1
$$dev{'dns_servers'} || {}
$$dev{'dns_servers'}
Truth table0%0/2
A
A= $$dev{'dns_servers'}
Aresult
11
00
Truth table0%0/2
A
A= $$dev{'dns_servers'}
Aresult
11
00
701 0 return ( $srv, undef, ";; communications error to $srv#53: timed out\n;; communications error to $srv#53: timed out\n;; communications error to $srv#53: timed out\n\n; <<>> DiG 9.18.28-1~deb12u2-Debian <<>> \@$srv\n;; global options: +cmd\n;; no servers could be reached" );
702 }
703  
704 14 ▶sub _query {
Subroutine _query: called CC=12 SCAR=33.1
705 14 my ( $dev, $ctx, $srv, $qname, $qtype ) = @_;
706 14 my ( $sname, $sdev, $err, $map ) = _server( $dev, $ctx, $srv );
707 14 ▶ return ( undef, $err ) if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 14 14
708 14 ▶ if ($map) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map) 0 14 14
709 0 my $ip = $map->{ $qname =~ s/\.\z//r };
710 0 ▶ return ( { status => defined $ip ? 'NOERROR' : 'NXDOMAIN', ans => defined $ip && $qtype =~ /\A(?:A|ANY)\z/ ? ["$qname 300 IN A $ip"] : [],
Branch: 2 branches
BranchTrueFalseTotal
defined $ip ? : 0 0 0
defined $ip && $qtype =~ /\A(?:A|ANY)\z/ ? : 0 0 0
Condition0%0/3
defined $ip and $qtype =~ /\A(?:A|ANY)\z/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ip and $qtype =~ /\A(?:A|ANY)\z/
defined $ip $qtype =~ /\A(?:A|ANY)\z/
Truth table0%0/3
A and B
A= defined $ipB= $qtype =~ /\A(?:A|ANY)\z/
ABresult
0X0
100
111
711 auth => [], aa => 0, server => $sname } );
712 }
713 14 ▶ if ( !_running($sdev) || !$sdev->{bind} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_running($sdev) and $$sdev{"bind"}) 0 14 14
Condition33%1/3
_running($sdev) and $$sdev{"bind"}
!ll&&!rl&&r
0014
MC/DC0%0/2
_running($sdev) and $$sdev{"bind"}
_running($sdev) $$sdev{"bind"}
Truth table33%1/3
A and B
A= _running($sdev)B= $$sdev{"bind"}
ABresult
0X0
100
111
714 0 return ( undef, ";; communications error to $sname#53: connection refused\n" x 3 . ";; no servers could be reached" );
715 }
716 14 my ( $st, $ans, $auth, $aa, $z ) = _answer( $sdev, $qname, $qtype );
717 14 ▶ if ( $qtype eq 'AXFR' && $st eq 'NOERROR' && !_allowed( $z->{allow_transfer}, _ip_of($dev), ( $sdev == $dev ? ('127.0.0.1') : () ) ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($qtype eq "AXFR" and $st eq "NOERROR" and not _allowed($$z{"allow_transfer"}, _ip_of($dev), $sdev == $dev ? "127.0.0.1" : ())) 1 13 14
$sdev == $dev ? : 1 0 1
Condition66%4/6
$qtype eq "AXFR" and $st eq "NOERROR" and not _allowed($$z{"allow_transfer"}, _ip_of($dev), $sdev == $dev ? "127.0.0.1" : ())
!ll&&!rl&&r
1301
$qtype eq "AXFR" and $st eq "NOERROR"
!ll&&!rl&&r
1301
MC/DC33%1/3
$qtype eq "AXFR" and $st eq "NOERROR" and not _allowed($$z{"allow_transfer"}, _ip_of($dev), $sdev == $dev ? "127.0.0.1" : ())
$qtype eq "AXFR" $st eq "NOERROR" not _allowed($$z{"allow_transfer"}, _ip_of($dev), $sdev == $dev ? "127.0.0.1" : ())
Truth table50%2/4
A and B and not(C)
A= $qtype eq "AXFR"B= $st eq "NOERROR"C= not _allowed($$z{"allow_transfer"}, _ip_of($dev), $sdev == $dev ? "127.0.0.1" : ())
ABCresult
0XX0
10X0
1100
1111
718 1 return ( { status => 'XFRFAIL', ans => [], auth => [], server => $sname } );
719 }
720 13 return ( { status => $st, ans => $ans, auth => $auth, aa => $aa, zone => $z, server => $sname } );
721 }
722  
723 0 ▶sub _rev { my ($ip) = @_; return join( '.', reverse split /\./, $ip ) . '.in-addr.arpa.' }
Subroutine _rev: not called CC=1 SCAR=6.9
724  
725  
726 13 ▶sub dig {
Subroutine dig: called CC=32 SCAR=41.1
Pod documented
727 13 my ( $dev, $av, $ctx ) = @_;
728 13 my ( $srv, $name, $type, $short, $answer_only, $rev );
729 13 my @a = @$av;
730 13 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 31 13 44
731 31 my $x = shift @a;
732 31 ▶ if ( $x =~ /\A@(.+)\z/ ) { $srv = $1 }
Branch: 12 branches
BranchTrueFalseTotal
if ($x =~ /\A@(.+)\z/) { } 5 26 31
elsif ($x eq '+short') { } 9 17 26
elsif ($x eq '+noall') { } 0 17 17
elsif ($x eq '+answer') { } 0 17 17
elsif ($x =~ /\A\+/) { } 0 17 17
elsif ($x eq '-x') { } 0 17 17
elsif ($x eq '-t') { } 0 17 17
elsif ($x eq '-c') { } 0 17 17
elsif ($x =~ /\A-[46]\z/) { } 0 17 17
elsif ($x =~ /\A(?:A|AAAA|MX|NS|TXT|SOA|CNAME|PTR|SRV|CAA|ANY|AXFR)\z/i and not defined $type) { } 4 13 17
elsif (uc $x eq 'IN') { } 0 13 13
elsif (not defined $name) { } 13 0 13
733 9 elsif ( $x eq '+short' ) { $short = 1 }
734 0 ▶ elsif ( $x eq '+noall' ) { $answer_only //= 0 }
Condition0%0/2
$answer_only //= 0
l!l
00
MC/DC0%0/1
$answer_only //= 0
$answer_only
Truth table0%0/2
A
A= $answer_only
Aresult
11
00
735 0 elsif ( $x eq '+answer' ) { $answer_only = 1 }
736 elsif ( $x =~ /\A\+/ ) { }
737 0 ▶ elsif ( $x eq '-x' ) { $name = _rev( shift(@a) // '' ); $type //= 'PTR' }
Condition0%0/4
shift @a // ""
l!l
00
$type //= "PTR"
l!l
00
MC/DC0%0/1
shift @a // ""
shift @a
MC/DC0%0/1
$type //= "PTR"
$type
Truth table0%0/2
A
A= shift @a
Aresult
11
00
Truth table0%0/2
A
A= $type
Aresult
11
00
738 0 ▶ elsif ( $x eq '-t' ) { $type = uc( shift(@a) // '' ) }
Condition0%0/2
shift @a // ""
l!l
00
MC/DC0%0/1
shift @a // ""
shift @a
Truth table0%0/2
A
A= shift @a
Aresult
11
00
739 0 elsif ( $x eq '-c' ) { shift @a }
740 elsif ( $x =~ /\A-[46]\z/ ) { }
741 4 ▶ elsif ( $x =~ /\A(?:A|AAAA|MX|NS|TXT|SOA|CNAME|PTR|SRV|CAA|ANY|AXFR)\z/i && !defined $type ) { $type = uc $x } # Typ vor oder nach dem Namen (dig TXT name)
Condition66%2/3
$x =~ /\A(?:A|AAAA|MX|NS|TXT|SOA|CNAME|PTR|SRV|CAA|ANY|AXFR)\z/i and not defined $type
!ll&&!rl&&r
1304
MC/DC50%1/2
$x =~ /\A(?:A|AAAA|MX|NS|TXT|SOA|CNAME|PTR|SRV|CAA|ANY|AXFR)\z/i and not defined $type
$x =~ /\A(?:A|AAAA|MX|NS|TXT|SOA|CNAME|PTR|SRV|CAA|ANY|AXFR)\z/i not defined $type
Truth table66%2/3
A and not(B)
A= $x =~ /\A(?:A|AAAA|MX|NS|TXT|SOA|CNAME|PTR|SRV|CAA|ANY|AXFR)\z/iB= not defined $type
ABresult
0X0
100
111
742 elsif ( uc $x eq 'IN' ) { }
743 13 elsif ( !defined $name ) { $name = $x }
744 0 else { $type = uc $x }
745 }
746 13 ▶ $name //= '.';
Condition50%1/2
$name //= "."
l!l
130
MC/DC0%0/1
$name //= "."
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
747 13 ▶ $type //= 'A';
Condition100%2/2
$type //= "A"
l!l
49
MC/DC100%1/1
$type //= "A"
$type
Truth table100%2/2
A
A= $type
Aresult
11
00
748 13 my $q = lc $name;
749 13 ▶ $q .= '.' unless $q =~ /\.\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $q =~ /\.\z/ 13 0 13
750 13 my ( $r, $err ) = _query( $dev, $ctx, $srv, $q, $type );
751 13 ▶ return ( $err, 0 ) unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 13 13
752 13 my @show = map { [ _show( $r->{zone}, $_ ) ] } @{ $r->{ans} };
753 13 ▶ if ( $r->{status} eq 'XFRFAIL' ) { return ( "; Transfer failed.", 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($$r{"status"} eq "XFRFAIL") 1 12 13
754 12 ▶ if ($short) { return ( join( "\n", map { $_->[1] } @show ), 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($short) 9 3 12
755 3 ▶ if ( $type eq 'AXFR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "AXFR") 0 3 3
756 return ( join( "\n", "; <<>> DiG 9.18.28-1~deb12u2-Debian <<>> " . join( ' ', @$av ), ';; global options: +cmd',
757 0 ( map { $_->[0] } @show ), ";; XFR size: " . scalar(@show) . ' records (messages 1, bytes 1024)' ), 1 );
758 }
759 3 my @l;
760 3 ▶ if ( !defined $answer_only ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $answer_only) { } 3 0 3
761 3 ▶ my $rec = $r->{aa} ? 'qr aa rd' : 'qr rd ra';
Branch: 1 branch
BranchTrueFalseTotal
$$r{'aa'} ? : 2 1 3
762 push @l, "; <<>> DiG 9.18.28-1~deb12u2-Debian <<>> " . join( ' ', @$av ), ';; global options: +cmd', ';; Got answer:',
763 ";; ->>HEADER<<- opcode: QUERY, status: $r->{status}, id: 4711",
764 3 ";; flags: $rec; QUERY: 1, ANSWER: " . scalar(@show) . ', AUTHORITY: ' . scalar( @{ $r->{auth} } ) . ', ADDITIONAL: 1';
765 3 ▶ push @l, ';; WARNING: recursion requested but not available' if $r->{aa} || $r->{status} eq 'REFUSED';
Branch: 1 branch
BranchTrueFalseTotal
if $$r{"aa"} or $$r{"status"} eq "REFUSED" 2 1 3
Condition66%2/3
$$r{"aa"} or $$r{"status"} eq "REFUSED"
l!l&&r!l&&!r
201
MC/DC50%1/2
$$r{"aa"} or $$r{"status"} eq "REFUSED"
$$r{"aa"} $$r{"status"} eq "REFUSED"
Truth table66%2/3
A or B
A= $$r{"aa"}B= $$r{"status"} eq "REFUSED"
ABresult
1X1
011
000
766 3 push @l, '', ';; QUESTION SECTION:', ";$q\t\t\tIN\t$type";
767 3 ▶ push @l, '', ';; ANSWER SECTION:', map { $_->[0] } @show if @show;
Branch: 1 branch
BranchTrueFalseTotal
if @show 1 2 3
768 3 ▶ push @l, '', ';; AUTHORITY SECTION:', map { ( _show( $r->{zone}, $_ ) )[0] } @{ $r->{auth} } if @{ $r->{auth} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$$r{"auth"};} 1 2 3
769 3 push @l, '', ';; Query time: 0 msec', ";; SERVER: $r->{server}#53($r->{server}) (UDP)", ';; WHEN: Tue Oct 20 12:00:00 CEST 2026', ';; MSG SIZE rcvd: 120';
770 }
771 0 else { push @l, map { $_->[0] } @show }
772 3 return ( join( "\n", @l ), 1 );
773 }
774  
775  
776 1 ▶sub host {
Subroutine host: called CC=27 SCAR=41.6
Pod documented
777 1 my ( $dev, $av, $ctx ) = @_;
778 1 my ( $type, @a );
779 1 my @w = @$av;
780 1 ▶ while (@w) { my $x = shift @w; if ( $x eq '-t' ) { $type = uc( shift(@w) // '' ) } elsif ( $x !~ /\A-/ ) { push @a, $x } }
Branch: 3 branches
BranchTrueFalseTotal
if (@w) 2 1 3
if ($x eq '-t') { } 1 1 2
elsif (not $x =~ /\A-/) { } 1 0 1
Condition50%1/2
shift @w // ""
l!l
10
MC/DC0%0/1
shift @w // ""
shift @w
Truth table50%1/2
A
A= shift @w
Aresult
11
00
781 1 my ( $name, $srv ) = @a;
782 1 ▶ return ( 'Usage: host [-aCdilrTvVw] [-c class] [-N ndots] [-t type] [-W time] [-R number] [-m flag] [-p port] hostname [server]', 0 ) unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 1 1
783 1 my $q = lc $name;
784 1 ▶ $q = _rev($q) if $q =~ /\A[\d.]+\z/ && _ipv4($q);
Branch: 1 branch
BranchTrueFalseTotal
if $q =~ /\A[\d.]+\z/ and _ipv4($q) 0 1 1
Condition33%1/3
$q =~ /\A[\d.]+\z/ and _ipv4($q)
!ll&&!rl&&r
100
MC/DC0%0/2
$q =~ /\A[\d.]+\z/ and _ipv4($q)
$q =~ /\A[\d.]+\z/ _ipv4($q)
Truth table33%1/3
A and B
A= $q =~ /\A[\d.]+\z/B= _ipv4($q)
ABresult
0X0
100
111
785 1 ▶ $q .= '.' unless $q =~ /\.\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $q =~ /\.\z/ 1 0 1
786 1 ▶ my @types = defined $type ? ($type) : $q =~ /in-addr\.arpa\.\z/ ? ('PTR') : qw( A AAAA MX );
Branch: 2 branches
BranchTrueFalseTotal
defined $type ? : 1 0 1
$q =~ /in-addr\.arpa\.\z/ ? : 0 0 0
787 1 my @l;
788 1 for my $t (@types) {
789 1 my ( $r, $err ) = _query( $dev, $ctx, $srv, $q, $t );
790 1 ▶ return ( ";; connection timed out; no servers could be reached", 0 ) unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 1 1
791 1 ▶ if ( $r->{status} ne 'NOERROR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$r{"status"} ne "NOERROR") 0 1 1
792 0 my %c = ( NXDOMAIN => 3, SERVFAIL => 2, REFUSED => 5 );
793 0 return ( "Host $name not found: $c{ $r->{status} }($r->{status})", 0 );
794 }
795 1 for my $rr ( @{ $r->{ans} } ) {
796 1 my ( $o, undef, undef, $ty, $d ) = split ' ', $rr, 5;
797 1 ▶ $d = ( ( $r->{zone} || {} )->{show} || {} )->{$rr} // $d;
Condition42%3/7
(($$r{"zone"} || {})->{"show"} || {})->{$rr} // $d
l!l&&r!l&&!r
100
($$r{'zone'} || {})->{'show'} || {}
l!l
10
$$r{'zone'} || {}
l!l
10
MC/DC0%0/2
(($$r{"zone"} || {})->{"show"} || {})->{$rr} // $d
$$r{'zone'} $d
Truth table33%1/3
A // B
A= $$r{'zone'}B= $d
ABresult
1X1
011
000
798 1 $o =~ s/\.\z//;
799 1 ▶ push @l, $ty eq 'A' ? "$o has address $d" : $ty eq 'AAAA' ? "$o has IPv6 address $d" : $ty eq 'MX' ? "$o mail is handled by $d"
Branch: 7 branches
BranchTrueFalseTotal
$ty eq 'A' ? : 0 1 1
$ty eq 'AAAA' ? : 0 1 1
$ty eq 'MX' ? : 0 1 1
$ty eq 'CNAME' ? : 0 1 1
$ty eq 'TXT' ? : 1 0 1
$ty eq 'PTR' ? : 0 0 0
$ty eq 'NS' ? : 0 0 0
800 : $ty eq 'CNAME' ? "$o is an alias for $d" : $ty eq 'TXT' ? "$o descriptive text $d" : $ty eq 'PTR' ? "$o domain name pointer $d"
801 : $ty eq 'NS' ? "$o name server $d" : "$o has $ty record $d";
802 }
803 1 ▶ push @l, "$name has no $t record" if defined $type && !@{ $r->{ans} };
Branch: 1 branch
BranchTrueFalseTotal
if defined $type and not @{$$r{"ans"};} 0 1 1
Condition33%1/3
defined $type and not @{$$r{"ans"};}
!ll&&!rl&&r
010
MC/DC0%0/2
defined $type and not @{$$r{"ans"};}
defined $type not @{$$r{"ans"};}
Truth table33%1/3
A and not(B)
A= defined $typeB= not @{$$r{"ans"};}
ABresult
0X0
100
111
804 }
805 1 return ( join( "\n", @l ), 1 );
806 }
807  
808 2 1;
809  
810 __END__
« blib/lib/Langertha/Holmgang/Sim/Linux/Backup.pm ↑ Summary blib/lib/Langertha/Holmgang/Grader.pm »