| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 67 | 6 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 54 | ▶ | next if !/\S/ || /^#/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not /\S/ or /^#/
MC/DC50%1/2
not /\S/ or /^#/
not /\S/
/^#/
Truth table66%2/3
not(A) or B
A= not /\S/B= /^#/
| |||||||||||||||||||||||||||||
| 69 | 48 | my($key, $args) = $_ =~ /^\s*(\S+)\s+(.+)$/; | |||||||||||||||||||||||||||
| 70 | 48 | ▶ | next unless $key && $args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key and $args
MC/DC0%0/2
$key and $args
$key
$args
Truth table33%1/3
A and B
A= $keyB= $args
| |||||||||||||||||||||||||||||
| 71 | 48 | ▶ | next unless $cfg->{_state}{host_matched} || $key eq "Host"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$cfg->{"_state"}{"host_matched"} or $key eq "Host"
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"
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 34 | ▶ | my $code = $DIRECTIVES{$key}[0] or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 34 | $code->($cfg, $key, $args); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 6 | ▶ | close $fh or warn qq{Could not close "$conf_file": $!\n}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$key and $args
MC/DC0%0/2
$key and $args
$key
$args
Truth table33%1/3
A and B
A= $keyB= $args
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 6 | ▶ | my $code = $DIRECTIVES{$key}[0] or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$host eq "*" or $cfg->{"_state"}{"host"} =~ /^$hostre$/
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$/
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 103 | 2 | ▶ | $cfg->{o}{interactive} = $batch eq "yes" ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 117 | 0 | for my $p (split /\s*,\s*/, $p_list) { | |||||||||||||||||||||||||||
| 118 | 0 | ▶ | croak "Invalid protocol: must be 1 or 2" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p == 1 or $p == 2
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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$p == &PROTOCOL_SSH1() and not $cfg->{"o"}{"protocol"} & &PROTOCOL_SSH2()
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()
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 130 | 10 | ▶ | if ($value =~ s/^-//) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 131 | 0 | my @list; | |||||||||||||||||||||||||||
| 132 | 0 | $value =~ s/\*/\.\*/g; | |||||||||||||||||||||||||||
| 133 | 0 | ▶ | my $defaults = $DIRECTIVES{$key}[2] or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | foreach (split(',', $defaults)) { | |||||||||||||||||||||||||||
| 135 | 0 | ▶ | next if /^$value$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 144 | 0 | foreach (split(',', $all)) { | |||||||||||||||||||||||||||
| 145 | 0 | ▶ | push @list, $_ if /^$value$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 172 | 2 | ▶ | if ($yesno eq "yes") { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | croak "No such configuration option $variable" | ||||||||||||||||||||||||||||
| 189 | 0 | ▶ | unless exists $cfg->{o}{$variable}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | ▶ | return @_ ? $cfg->set($variable, @_) : $cfg->get($variable); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 5 | 1; | |||||||||||||||||||||||||||
| 195 | __END__ | ||||||||||||||||||||||||||||