Config.pm

filter: Statementstmt 97.1% 68 / 70 Branchbran 67.6% 23 / 34 Conditioncond 45.0% 9 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 75.3% 107 / 142 CC 8 SCAR 16.7
CC
8
Cov
81%
requires_firewall
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.3
« Time.pm ↑ Summary FTP/E.pm »
1 # Net::Config.pm
2 #
3 # Copyright (C) 2000 Graham Barr. All rights reserved.
4 # Copyright (C) 2013-2014, 2016, 2020 Steve Hay. All rights reserved.
5 # This module is free software; you can redistribute it and/or modify it under
6 # the same terms as Perl itself, i.e. under the terms of either the GNU General
7 # Public License or the Artistic License, as specified in the F<LICENCE> file.
8  
9 package Net::Config;
10  
11 19 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 19 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 19 ▶use Socket qw(inet_aton inet_ntoa);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 19 our @EXPORT = qw(%NetConfig);
20 19 our @ISA = qw(Net::LocalCfg Exporter);
21 19 our $VERSION = "3.16";
22  
23 19 our($CONFIGURE, $LIBNET_CFG);
24  
25 19 eval {
26 19 local @INC = @INC;
27 19 ▶ pop @INC if $INC[-1] eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $INC[-1] eq "." 19 0 19
28 19 local $SIG{__DIE__};
29 19 require Net::LocalCfg;
30 };
31  
32 19 our %NetConfig = (
33 nntp_hosts => [],
34 snpp_hosts => [],
35 pop3_hosts => [],
36 smtp_hosts => [],
37 ph_hosts => [],
38 daytime_hosts => [],
39 time_hosts => [],
40 inet_domain => undef,
41 ftp_firewall => undef,
42 ftp_ext_passive => 1,
43 ftp_int_passive => 1,
44 test_hosts => 1,
45 test_exist => 1,
46 );
47  
48 #
49 # Try to get as much configuration info as possible from InternetConfig
50 #
51 {
52 ## no critic (BuiltinFunctions::ProhibitStringyEval)
53 19 ▶$^O eq 'MacOS' and eval <<TRY_INTERNET_CONFIG;
Branch: 1 branch
BranchTrueFalseTotal
$^O eq "MacOS" and eval qq[use Mac::InternetConfig;\n\n{\nmy %nc = (\n nntp_hosts => [ \$InternetConfig{ kICNNTPHost() } ],\n pop3_hosts => [ \$InternetConfig{ kICMailAccount() } =~ /\@(.*)/ ],\n smtp_hosts => [ \$InternetConfig{ kICSMTPHost() } ],\n ftp_testhost => \$InternetConfig{ kICFTPHost() } ? \$InternetConfig{ kICFTPHost()} : undef,\n ph_hosts => [ \$InternetConfig{ kICPhHost() } ],\n ftp_ext_passive => \$InternetConfig{"646F676F\245UsePassiveMode"} || 0,\n ftp_int_passive => \$InternetConfig{"646F676F\245UsePassiveMode"} || 0,\n socks_hosts => \n \$InternetConfig{ kICUseSocks() } ? [ \$InternetConfig{ kICSocksHost() } ] : [],\n ftp_firewall => \n \$InternetConfig{ kICUseFTPProxy() } ? [ \$InternetConfig{ kICFTPProxyHost() } ] : [],\n);\n\@NetConfig{keys %nc} = values %nc;\n}\n] 0 19 19
54 use Mac::InternetConfig;
55  
56 {
57 my %nc = (
58 nntp_hosts => [ \$InternetConfig{ kICNNTPHost() } ],
59 pop3_hosts => [ \$InternetConfig{ kICMailAccount() } =~ /\@(.*)/ ],
60 smtp_hosts => [ \$InternetConfig{ kICSMTPHost() } ],
61 ftp_testhost => \$InternetConfig{ kICFTPHost() } ? \$InternetConfig{ kICFTPHost()} : undef,
62 ph_hosts => [ \$InternetConfig{ kICPhHost() } ],
63 ftp_ext_passive => \$InternetConfig{"646F676F\xA5UsePassiveMode"} || 0,
64 ftp_int_passive => \$InternetConfig{"646F676F\xA5UsePassiveMode"} || 0,
65 socks_hosts =>
66 \$InternetConfig{ kICUseSocks() } ? [ \$InternetConfig{ kICSocksHost() } ] : [],
67 ftp_firewall =>
68 \$InternetConfig{ kICUseFTPProxy() } ? [ \$InternetConfig{ kICFTPProxyHost() } ] : [],
69 );
70 \@NetConfig{keys %nc} = values %nc;
71 }
72 TRY_INTERNET_CONFIG
73 }
74  
75 19 my $file = __FILE__;
76 19 my $ref;
77 19 $file =~ s/Config.pm/libnet.cfg/;
78 19 ▶if (-f $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $file) 19 0 19
79 19 $ref = eval { local $SIG{__DIE__}; do $file };
80 19 ▶ if (ref($ref) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref eq "HASH") 19 0 19
81 19 %NetConfig = (%NetConfig, %{$ref});
82 19 $LIBNET_CFG = $file;
83 }
84 }
85 19 ▶if ($< == $> and !$CONFIGURE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($< == $> and not $Net::Config::CONFIGURE) 19 0 19
Condition33%1/3
$< == $> and not $Net::Config::CONFIGURE
!ll&&!rl&&r
0019
MC/DC0%0/2
$< == $> and not $Net::Config::CONFIGURE
$< == $> not $Net::Config::CONFIGURE
Truth table33%1/3
A and not(B)
A= $< == $>B= not $Net::Config::CONFIGURE
ABresult
0X0
100
111
86 19 ▶ my $home = eval { local $SIG{__DIE__}; (getpwuid($>))[7] } || $ENV{HOME};
Condition33%1/3
eval { do { local $SIG{'__DIE__'}; (getpwuid $>)[7] } } || $ENV{'HOME'}
l!l&&r!l&&!r
1900
MC/DC0%0/2
eval { do { local $SIG{'__DIE__'}; (getpwuid $>)[7] } } || $ENV{'HOME'}
eval { do { local $SIG{'__DIE__'}; (getpwuid $>)[7] } } $ENV{'HOME'}
Truth table33%1/3
A || B
A= eval { do { local $SIG{'__DIE__'}; (getpwuid $>)[7] } }B= $ENV{'HOME'}
ABresult
1X1
011
000
87 19 ▶ $home ||= $ENV{HOMEDRIVE} . ($ENV{HOMEPATH} || '') if defined $ENV{HOMEDRIVE};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"HOMEDRIVE"} 0 19 19
Condition0%0/5
$home ||= $ENV{"HOMEDRIVE"} . ($ENV{"HOMEPATH"} || "")
l!l&&r!l&&!r
000
$ENV{'HOMEPATH'} || ''
l!l
00
MC/DC0%0/2
$home ||= $ENV{"HOMEDRIVE"} . ($ENV{"HOMEPATH"} || "")
$home $ENV{"HOMEDRIVE"} . ($ENV{"HOMEPATH"} || "")
MC/DC0%0/1
$ENV{'HOMEPATH'} || ''
$ENV{'HOMEPATH'}
Truth table0%0/3
A ||= B
A= $homeB= $ENV{"HOMEDRIVE"} . ($ENV{"HOMEPATH"} || "")
ABresult
1X1
011
000
Truth table0%0/2
A
A= $ENV{'HOMEPATH'}
Aresult
11
00
88 19 ▶ if (defined $home) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $home) 19 0 19
89 19 $file = $home . "/.libnetrc";
90 0 ▶ $ref = eval { local $SIG{__DIE__}; do $file } if -f $file;
Branch: 1 branch
BranchTrueFalseTotal
if -f $file 0 19 19
91 19 ▶ %NetConfig = (%NetConfig, %{$ref})
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref eq "HASH" 19 0 19
92 if ref($ref) eq 'HASH';
93 }
94 }
95 19 my ($k, $v);
96 19 ▶while (($k, $v) = each %NetConfig) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %Net::Config::NetConfig) 266 19 285
97 266 ▶ $NetConfig{$k} = [$v]
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /_hosts$/ and $k ne "test_hosts" and defined $v and not ref $v 0 266 266
Condition77%7/9
$k =~ /_hosts$/ and $k ne "test_hosts" and defined $v and not ref $v
!ll&&!rl&&r
1331330
$k =~ /_hosts$/ and $k ne "test_hosts" and defined $v
!ll&&!rl&&r
1330133
$k =~ /_hosts$/ and $k ne "test_hosts"
!ll&&!rl&&r
11419133
MC/DC0%0/4
$k =~ /_hosts$/ and $k ne "test_hosts" and defined $v and not ref $v
$k =~ /_hosts$/ $k ne "test_hosts" defined $v not ref $v
Truth table60%3/5
A and B and C and not(D)
A= $k =~ /_hosts$/B= $k ne "test_hosts"C= defined $vD= not ref $v
ABCDresult
0XXX0
10XX0
110X0
11100
11111
98 if ($k =~ /_hosts$/ and $k ne "test_hosts" and defined($v) and !ref($v));
99 }
100  
101 # Take a hostname and determine if it is inside the firewall
102  
103  
104 7 ▶sub requires_firewall {
Subroutine requires_firewall: called CC=8 SCAR=20.8
Pod documented
105 7 shift; # ignore package
106 7 my $host = shift;
107  
108 7 ▶ return 0 unless defined $NetConfig{'ftp_firewall'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Net::Config::NetConfig{"ftp_firewall"} 1 6 7
109  
110 6 ▶ $host = inet_aton($host) or return -1;
Branch: 1 branch
BranchTrueFalseTotal
$host = inet_aton($host) or return -1 5 1 6
111 5 $host = inet_ntoa($host);
112  
113 5 ▶ if (exists $NetConfig{'local_netmask'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Net::Config::NetConfig{"local_netmask"}) 4 1 5
114 4 my $quad = unpack("N", pack("C*", split(/\./, $host)));
115 4 my $list = $NetConfig{'local_netmask'};
116 4 ▶ $list = [$list] unless ref($list);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $list 2 2 4
117 4 foreach (@$list) {
118 6 ▶ my ($net, $bits) = (m#^(\d+\.\d+\.\d+\.\d+)/(\d+)$#) or next;
Branch: 1 branch
BranchTrueFalseTotal
() = m[^(\d+\.\d+\.\d+\.\d+)/(\d+)$] or next 6 0 6
119 6 my $mask = ~0 << (32 - $bits);
120 6 my $addr = unpack("N", pack("C*", split(/\./, $net)));
121  
122 6 ▶ return 0 if (($addr & $mask) == ($quad & $mask));
Branch: 1 branch
BranchTrueFalseTotal
if ($addr & $mask) == ($quad & $mask) 2 4 6
123 }
124 2 return 1;
125 }
126  
127 1 return 0;
128 }
129  
130 19 *is_external = \&requires_firewall;
131  
132 19 1;
133  
134 __END__
« Time.pm ↑ Summary FTP/E.pm »