blib/lib/Net/SSH/Perl/Config.pm

filter: Statementstmt 75.0% 72 / 96 Branchbran 46.7% 29 / 62 Conditioncond 42.8% 9 / 21 MC/DCmcdc 28.5% 4 / 14 Subroutinesub 94.4% 17 / 18 Podpod 100% 5 / 5 totaltotal 62.9% 136 / 216 SCAR 49.6
CC
42
Cov
61%
_protocol
56.0
_set_str
50.8
read_config
11.6
CRAP 143.0
« blib/lib/Net/SSH/Perl/Key/RSA.pm ↑ Summary blib/lib/Net/SSH/Perl/Key/RSA1.pm »
1 package Net::SSH::Perl::Config;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 ▶use Net::SSH::Perl::Constants qw( :protocol :kex );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use vars qw( %DIRECTIVES $AUTOLOAD );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 %DIRECTIVES = (
10 BindAddress => [ \&_set_str, 'bind_address' ],
11 Host => [ \&_host ],
12 BatchMode => [ \&_batch_mode ],
13 ChallengeResponseAuthentication => [ \&_set_yesno, 'auth_ch_res' ],
14 CheckHostIP => [ \&_set_yesno, 'check_host_ip' ],
15 Cipher => [ \&_cipher ],
16 Ciphers => [ \&_set_str, 'ciphers', KEX_DEFAULT_ENCRYPT, KEX_ALL_ENCRYPT ],
17 Compression => [ \&_set_yesno, 'compression' ],
18 CompressionLevel => [ \&_set_str, 'compression_level' ],
19 DSAAuthentication => [ \&_set_yesno, 'auth_dsa' ],
20 FingerprintHash => [ \&_set_str, 'fingerprint_hash' ],
21 GlobalKnownHostsFile => [ \&_set_str, 'global_known_hosts' ],
22 HashKnownHosts => [ \&_set_yesno, 'hash_known_hosts' ],
23 HostKeyAlgorithms => [ \&_set_str, 'host_key_algorithms', KEX_DEFAULT_PK_ALG, KEX_ALL_PK_ALG ],
24 HostName => [ \&_set_str, 'hostname' ],
25 IdentityFile => [ \&_identity_file ],
26 IdentitiesOnly => [ \&_set_yesno, 'identities_only' ],
27 KexAlgorithms => [ \&_set_str, 'kex_algorithms', KEX_DEFAULT_KEX, KEX_ALL_KEX ],
28 MACs => [ \&_set_str, 'macs', KEX_DEFAULT_MAC, KEX_ALL_MAC ],
29 NumberOfPasswordPrompts => [ \&_set_str, 'number_of_password_prompts' ],
30 PasswordAuthentication => [ \&_set_yesno, 'auth_password' ],
31 PasswordPromptHost => [ \&_set_yesno, 'password_prompt_host' ],
32 PasswordPromptLogin => [ \&_set_yesno, 'password_prompt_login' ],
33 Port => [ \&_set_str, 'port' ],
34 Protocol => [ \&_protocol ],
35 RhostsAuthentication => [ \&_set_yesno, 'auth_rhosts' ],
36 RhostsRSAAuthentication => [ \&_set_yesno, 'auth_rhosts_rsa' ],
37 RSAAuthentication => [ \&_set_yesno, 'auth_rsa' ],
38 StrictHostKeyChecking => [ \&_set_str, 'strict_host_key_checking' ],
39 UpdateHostKeys => [ \&_set_str, 'update_host_keys' ],
40 UsePrivilegedPort => [ \&_set_yesno, 'privileged' ],
41 User => [ \&_set_str, 'user' ],
42 UserKnownHostsFile => [ \&_set_str, 'user_known_hosts' ],
43 );
44  
45 sub new {
46 8 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
47 8 my $host = shift;
48 8 bless { host => $host, o => { @_ } }, $class;
49 }
50  
51 61 ▶sub get { $_[0]->{o}{ $_[1] } }
Subroutine get: called CC=1 SCAR=0.0
Pod documented
52  
53 sub set {
54 30 ▶ my($cfg, $key) = @_;
Subroutine set: called CC=2 SCAR=7.1
Pod documented
55 30 ▶ $cfg->{o}{$key} = $_[2] if @_ == 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 3 30 0 30
56 30 $cfg->{o}{$key};
57 }
58  
59 sub read_config {
60 13 ▶ my($cfg, $conf_file) = @_;
Subroutine read_config: called CC=11 SCAR=24.5
Pod documented
61  
62 13 local $cfg->{_state} = { host => $cfg->{host}, host_matched => 1 };
63  
64 13 local($_, $/);
65 13 $/ = "\n";
66 13 ▶ open my $fh, '<', $conf_file or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $conf_file or return 7 6 13
67 6 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 54 6 60
68 54 ▶ next if !/\S/ || /^#/;
Branch: 1 branch
BranchTrueFalseTotal
if not /\S/ or /^#/ 6 48 54
Condition66%2/3
not /\S/ or /^#/
l!l&&r!l&&!r
6048
MC/DC50%1/2
not /\S/ or /^#/
not /\S/ /^#/
Truth table66%2/3
not(A) or B
A= not /\S/B= /^#/
ABresult
1X1
011
000
69 48 my($key, $args) = $_ =~ /^\s*(\S+)\s+(.+)$/;
70 48 ▶ next unless $key && $args;
Branch: 1 branch
BranchTrueFalseTotal
unless $key and $args 0 48 48
Condition33%1/3
$key and $args
!ll&&!rl&&r
0048
MC/DC0%0/2
$key and $args
$key $args
Truth table33%1/3
A and B
A= $keyB= $args
ABresult
0X0
100
111
71 48 ▶ next unless $cfg->{_state}{host_matched} || $key eq "Host";
Branch: 1 branch
BranchTrueFalseTotal
unless $cfg->{"_state"}{"host_matched"} or $key eq "Host" 14 34 48
Condition100%3/3
$cfg->{"_state"}{"host_matched"} or $key eq "Host"
l!l&&r!l&&!r
33114
MC/DC100%2/2
$cfg->{"_state"}{"host_matched"} or $key eq "Host"
$cfg->{"_state"}{"host_matched"} $key eq "Host"
Truth table100%3/3
A or B
A= $cfg->{"_state"}{"host_matched"}B= $key eq "Host"
ABresult
1X1
011
000
72  
73 34 ▶ my $code = $DIRECTIVES{$key}[0] or next;
Branch: 1 branch
BranchTrueFalseTotal
my $code = $Net::SSH::Perl::Config::DIRECTIVES{$key}[0] or next 0 34 34
74 34 $code->($cfg, $key, $args);
75 }
76 6 ▶ close $fh or warn qq{Could not close "$conf_file": $!\n};
Branch: 1 branch
BranchTrueFalseTotal
close $fh or warn qq[Could not close "$conf_file": $!\n] 0 6 6
77 }
78  
79 sub merge_directive {
80 6 ▶ my($cfg, $line) = @_;
Subroutine merge_directive: called CC=4 SCAR=15.2
Pod documented
81 6 my($key, $args) = $line =~ /^\s*(\S+)\s+(.+)$/;
82 6 ▶ return unless $key && $args;
Branch: 1 branch
BranchTrueFalseTotal
unless $key and $args 0 6 6
Condition33%1/3
$key and $args
!ll&&!rl&&r
006
MC/DC0%0/2
$key and $args
$key $args
Truth table33%1/3
A and B
A= $keyB= $args
ABresult
0X0
100
111
83  
84 6 ▶ my $code = $DIRECTIVES{$key}[0] or return;
Branch: 1 branch
BranchTrueFalseTotal
my $code = $Net::SSH::Perl::Config::DIRECTIVES{$key}[0] or return 0 6 6
85 6 $code->($cfg, $key, $args);
86 }
87  
88 sub _host {
89 12 ▶ my($cfg, $key, $host) = @_;
Subroutine _host: called CC=3 SCAR=11.0
90 12 (my $hostre = $host) =~ s/\*/.*/g;
91 12 $hostre =~ s/\?/./g;
92 12 ▶ if ($host eq '*' || $cfg->{_state}{host} =~ /^$hostre$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host eq '*' or $cfg->{'_state'}{'host'} =~ /^$hostre$/) { } 6 6 12
Condition66%2/3
$host eq "*" or $cfg->{"_state"}{"host"} =~ /^$hostre$/
l!l&&r!l&&!r
066
MC/DC50%1/2
$host eq "*" or $cfg->{"_state"}{"host"} =~ /^$hostre$/
$host eq "*" $cfg->{"_state"}{"host"} =~ /^$hostre$/
Truth table66%2/3
A or B
A= $host eq "*"B= $cfg->{"_state"}{"host"} =~ /^$hostre$/
ABresult
1X1
011
000
93 6 $cfg->{_state}{host_matched} = 1;
94 }
95 else {
96 6 $cfg->{_state}{host_matched} = 0;
97 }
98 }
99  
100 sub _batch_mode {
101 2 ▶ my($cfg, $key, $batch) = @_;
Subroutine _batch_mode: called CC=3 SCAR=11.7
102 2 ▶ return if exists $cfg->{o}{interactive};
Branch: 1 branch
BranchTrueFalseTotal
if exists $cfg->{"o"}{"interactive"} 0 2 2
103 2 ▶ $cfg->{o}{interactive} = $batch eq "yes" ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$batch eq 'yes' ? : 0 2 2
104 }
105  
106 sub _identity_file {
107 10 ▶ my($cfg, $key, $id_file) = @_;
Subroutine _identity_file: called CC=2 SCAR=6.9
108 $cfg->{identity_files} = []
109 10 ▶ unless ref $cfg->{o}{identity_files} eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cfg->{"o"}{"identity_files"} eq "ARRAY" 5 5 10
110 10 $id_file =~ s!~!$ENV{HOME}!;
111 10 push @{ $cfg->{o}{identity_files} }, $id_file;
112 }
113  
114 sub _protocol {
115 0 ▶ my($cfg, $key, $p_list) = @_;
Subroutine _protocol: not called CC=7 SCAR=40.3
116 0 ▶ return if exists $cfg->{o}{protocol};
Branch: 1 branch
BranchTrueFalseTotal
if exists $cfg->{"o"}{"protocol"} 0 0 0
117 0 for my $p (split /\s*,\s*/, $p_list) {
118 0 ▶ croak "Invalid protocol: must be 1 or 2"
Branch: 1 branch
BranchTrueFalseTotal
unless $p == 1 or $p == 2 0 0 0
Condition0%0/3
$p == 1 or $p == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$p == 1 or $p == 2
$p == 1 $p == 2
Truth table0%0/3
A or B
A= $p == 1B= $p == 2
ABresult
1X1
011
000
119 unless $p == 1 || $p == 2;
120 0 $cfg->{o}{protocol} |= $p;
121 0 ▶ if ($p == PROTOCOL_SSH1 && !($cfg->{o}{protocol} & PROTOCOL_SSH2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p == &PROTOCOL_SSH1() and not $cfg->{"o"}{"protocol"} & &PROTOCOL_SSH2()) 0 0 0
Condition0%0/3
$p == &PROTOCOL_SSH1() and not $cfg->{"o"}{"protocol"} & &PROTOCOL_SSH2()
!ll&&!rl&&r
000
MC/DC0%0/2
$p == &PROTOCOL_SSH1() and not $cfg->{"o"}{"protocol"} & &PROTOCOL_SSH2()
$p == &PROTOCOL_SSH1() not $cfg->{"o"}{"protocol"} & &PROTOCOL_SSH2()
Truth table0%0/3
A and not(B)
A= $p == &PROTOCOL_SSH1()B= not $cfg->{"o"}{"protocol"} & &PROTOCOL_SSH2()
ABresult
0X0
100
111
122 0 $cfg->{o}{protocol} |= PROTOCOL_SSH1_PREFERRED;
123 }
124 }
125 }
126  
127 sub _set_str {
128 13 ▶ my($cfg, $key, $value) = @_;
Subroutine _set_str: called CC=10 SCAR=39.3
129 13 ▶ return if exists $cfg->{o}{ $DIRECTIVES{$key}[1] };
Branch: 1 branch
BranchTrueFalseTotal
if exists $cfg->{"o"}{$Net::SSH::Perl::Config::DIRECTIVES{$key}[1]} 3 10 13
130 10 ▶ if ($value =~ s/^-//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value =~ s/^-//) { } 0 10 10
elsif ($value =~ s/^\+//) { } 0 10 10
131 0 my @list;
132 0 $value =~ s/\*/\.\*/g;
133 0 ▶ my $defaults = $DIRECTIVES{$key}[2] or return;
Branch: 1 branch
BranchTrueFalseTotal
my $defaults = $Net::SSH::Perl::Config::DIRECTIVES{$key}[2] or return 0 0 0
134 0 foreach (split(',', $defaults)) {
135 0 ▶ next if /^$value$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^$value$/ 0 0 0
136 0 push @list, $_;
137 }
138 0 $value = join(',',@list);
139 }
140 elsif ($value =~ s/^\+//) {
141 0 my @list;
142 0 $value =~ s/\*/\.\*/g;
143 0 ▶ my $all = $DIRECTIVES{$key}[3] or return;
Branch: 1 branch
BranchTrueFalseTotal
my $all = $Net::SSH::Perl::Config::DIRECTIVES{$key}[3] or return 0 0 0
144 0 foreach (split(',', $all)) {
145 0 ▶ push @list, $_ if /^$value$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^$value$/ 0 0 0
146 }
147 0 $value = join(',', $DIRECTIVES{$key}[2], @list);
148 }
149 10 $cfg->{o}{ $DIRECTIVES{$key}[1] } = $value;
150 }
151  
152 {
153 5 my %cipher_map = (
154 idea => 'IDEA',
155 none => 'None',
156 des => 'DES',
157 '3des' => 'DES3',
158 arcfour => 'RC4',
159 blowfish => 'Blowfish',
160 );
161  
162 sub _cipher {
163 1 ▶ my($cfg, $key, $value) = @_;
Subroutine _cipher: called CC=2 SCAR=7.1
164 1 ▶ return if exists $cfg->{o}{cipher};
Branch: 1 branch
BranchTrueFalseTotal
if exists $cfg->{"o"}{"cipher"} 0 1 1
165 1 $cfg->{o}{cipher} = $cipher_map{$value};
166 }
167 }
168  
169 5 sub _set_yesno {
170 2 ▶ my($cfg, $key, $yesno) = @_;
Subroutine _set_yesno: called CC=4 SCAR=16.4
171 2 ▶ return if exists $cfg->{o}{ $DIRECTIVES{$key}[1] };
Branch: 1 branch
BranchTrueFalseTotal
if exists $cfg->{"o"}{$Net::SSH::Perl::Config::DIRECTIVES{$key}[1]} 0 2 2
172 2 ▶ if ($yesno eq "yes") {
Branch: 2 branches
BranchTrueFalseTotal
if ($yesno eq 'yes') { } 0 2 2
elsif ($yesno eq 'no') { } 2 0 2
173 0 $cfg->{o}{ $DIRECTIVES{$key}[1] } = 1;
174 }
175 elsif ($yesno eq "no") {
176 2 $cfg->{o}{ $DIRECTIVES{$key}[1] } = 0;
177 }
178 else {
179 0 warn "Configuration setting for '$key' must be 'yes' or 'no'";
180 }
181 }
182  
183 sub AUTOLOAD {
184 8 ▶ my $cfg = shift;
Subroutine AUTOLOAD: called CC=4 SCAR=20.9
185 8 (my $variable = $AUTOLOAD) =~ s/.*:://;
186 8 ▶ return if $variable eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $variable eq "DESTROY" 8 0 8
187  
188 croak "No such configuration option $variable"
189 0 ▶ unless exists $cfg->{o}{$variable};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $cfg->{"o"}{$variable} 0 0 0
190  
191 0 ▶ return @_ ? $cfg->set($variable, @_) : $cfg->get($variable);
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
192 }
193  
194 5 1;
195 __END__
« blib/lib/Net/SSH/Perl/Key/RSA.pm ↑ Summary blib/lib/Net/SSH/Perl/Key/RSA1.pm »