| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 19 | $ref = eval { local $SIG{__DIE__}; do $file }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 19 | ▶ | if (ref($ref) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 19 | %NetConfig = (%NetConfig, %{$ref}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 19 | $LIBNET_CFG = $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 19 | ▶ | if ($< == $> and !$CONFIGURE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$< == $> and not $Net::Config::CONFIGURE
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 19 | ▶ | my $home = eval { local $SIG{__DIE__}; (getpwuid($>))[7] } || $ENV{HOME}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
eval {
do {
local $SIG{'__DIE__'};
(getpwuid $>)[7]
}
} || $ENV{'HOME'}
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 19 | ▶ | $home ||= $ENV{HOMEDRIVE} . ($ENV{HOMEPATH} || '') if defined $ENV{HOMEDRIVE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$home ||= $ENV{"HOMEDRIVE"} . ($ENV{"HOMEPATH"} || "")
$ENV{'HOMEPATH'} || ''
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"} || "")
Truth table0%0/2
A
A= $ENV{'HOMEPATH'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 19 | ▶ | if (defined $home) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 19 | $file = $home . "/.libnetrc"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $ref = eval { local $SIG{__DIE__}; do $file } if -f $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 19 | ▶ | %NetConfig = (%NetConfig, %{$ref}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | if ref($ref) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 19 | my ($k, $v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 19 | ▶ | while (($k, $v) = each %NetConfig) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 266 | ▶ | $NetConfig{$k} = [$v] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$k =~ /_hosts$/ and $k ne "test_hosts" and defined $v and not ref $v
$k =~ /_hosts$/ and $k ne "test_hosts" and defined $v
$k =~ /_hosts$/ and $k ne "test_hosts"
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | ▶ | $host = inet_aton($host) or return -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 5 | $host = inet_ntoa($host); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 5 | ▶ | if (exists $NetConfig{'local_netmask'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 4 | foreach (@$list) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 6 | ▶ | my ($net, $bits) = (m#^(\d+\.\d+\.\d+\.\d+)/(\d+)$#) or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||