| 1 | package Net::SSH::Perl; | ||||||||||||||||||||||||||||||||||||||||||||||
| 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::Packet; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Net::SSH::Perl::Buffer; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Net::SSH::Perl::Config; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Net::SSH::Perl::Constants qw( :protocol :compat :hosts ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Net::SSH::Perl::Cipher; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Net::SSH::Perl::Util qw( :hosts _read_yes_or_no _current_user_win32 ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Errno; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use vars qw( $VERSION $CONFIG $HOSTNAME ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | $CONFIG = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use Socket qw(IPPROTO_TCP TCP_NODELAY); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use IO::Socket; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use Fcntl; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | ▶ | use Symbol; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | ▶ | use File::Spec::Functions qw( catfile ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | ▶ | use Sys::Hostname; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | $HOSTNAME = hostname(); | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | $VERSION = '2.142'; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | sub VERSION { $VERSION } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
VERSION: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 5 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 5 | my $host = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | ▶ | croak "usage: ", __PACKAGE__, "->new(\$host)" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | unless defined $host; | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | my $ssh = bless { host => $host }, $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | my %p = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | $ssh->{_test} = delete $p{_test}; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 5 | $ssh->_init(%p); | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 5 | ▶ | $ssh->_connect unless $ssh->{_test}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | $ssh; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 26 | ▶ | sub protocol { $_[0]->{use_protocol} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
protocol: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | sub set_protocol { | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | my $ssh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_protocol: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | $ssh->{use_protocol} = $proto; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | my $proto_class = join '::', __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ($proto == PROTOCOL_SSH2 ? "SSH2" : "SSH1"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | (my $lib = $proto_class . ".pm") =~ s!::!/!g; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | require $lib; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | bless $ssh, $proto_class; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | $ssh->debug($proto_class->version_string); | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | $ssh->_proto_init; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 5 | ▶ | use vars qw( @COMPAT ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | @COMPAT = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | [ '^OpenSSH[-_]2\.[012]' => SSH_COMPAT_OLD_SESSIONID, ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | [ 'MindTerm' => 0, ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | [ '^2\.1\.0 ' => SSH_COMPAT_BUG_SIGBLOB | | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | SSH_COMPAT_BUG_HMAC | | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | SSH_COMPAT_OLD_SESSIONID, ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | [ '^2\.0\.' => SSH_COMPAT_BUG_SIGBLOB | | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | SSH_COMPAT_BUG_HMAC | | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | SSH_COMPAT_OLD_SESSIONID | | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | SSH_COMPAT_BUG_PUBKEYAUTH | | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | SSH_COMPAT_BUG_X11FWD, ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | [ '^2\.[23]\.0 ' => SSH_COMPAT_BUG_HMAC, ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | [ '^2\.[2-9]\.' => 0, ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | [ '^2\.4$' => SSH_COMPAT_OLD_SESSIONID, ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | [ '^3\.0 SecureCRT' => SSH_COMPAT_OLD_SESSIONID, ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | [ '^1\.7 SecureFX' => SSH_COMPAT_OLD_SESSIONID, ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | [ '^2\.' => SSH_COMPAT_BUG_HMAC, ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | sub _compat_init { | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my $ssh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compat_init: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my($version) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $ssh->{datafellows} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | for my $rec (@COMPAT) { | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my($re, $mask) = @$rec[0, 1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ($version =~ /$re/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $ssh->debug("Compat match: '$version' matches pattern '$re'."); | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $ssh->{datafellows} = $mask; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $ssh->debug("No compat match: $version."); | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ▶ | sub version_string { } | |||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version_string: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub client_version_string { $_[0]->{client_version_string} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
client_version_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub server_version_string { $_[0]->{server_version_string} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
server_version_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | sub _current_user { | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 5 | ▶ | if ( $^O eq 'MSWin32' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_current_user: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | return _current_user_win32(); | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 5 | my $user; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | 5 | eval { $user = scalar getpwuid $> }; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 5 | return $user; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | sub _init { | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 5 | ▶ | my $ssh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=17 SCAR=32.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 5 | my %arg = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | my $user_config = delete $arg{user_config} | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 5 | ▶ | || catfile($ENV{HOME} || $ENV{USERPROFILE}, '.ssh', 'config'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
delete $arg{'user_config'} || catfile($ENV{'HOME'} || $ENV{'USERPROFILE'}, '.ssh', 'config')
$ENV{'HOME'} || $ENV{'USERPROFILE'}
MC/DC0%0/2
delete $arg{'user_config'} || catfile($ENV{'HOME'} || $ENV{'USERPROFILE'}, '.ssh', 'config')
delete $arg{'user_config'}
catfile($ENV{'HOME'} || $ENV{'USERPROFILE'}, '.ssh', 'config')
MC/DC0%0/2
$ENV{'HOME'} || $ENV{'USERPROFILE'}
$ENV{'HOME'}
$ENV{'USERPROFILE'}
Truth table66%2/3
A || B
A= delete $arg{'user_config'}B= catfile($ENV{'HOME'} || $ENV{'USERPROFILE'}, '.ssh', 'config')
Truth table33%1/3
A || B
A= $ENV{'HOME'}B= $ENV{'USERPROFILE'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | my $sys_config = delete $arg{sys_config} | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | || $^O eq 'MSWin32' | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 5 | ▶ | ? catfile($ENV{WINDIR}, 'ssh_config') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
delete $arg{"sys_config"} or $^O eq "MSWin32"
MC/DC0%0/2
delete $arg{"sys_config"} or $^O eq "MSWin32"
delete $arg{"sys_config"}
$^O eq "MSWin32"
Truth table33%1/3
A or B
A= delete $arg{"sys_config"}B= $^O eq "MSWin32"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | : "/etc/ssh_config"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 5 | ▶ | my $directives = delete $arg{options} || []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $arg{'options'} || []
MC/DC100%1/1
delete $arg{'options'} || []
delete $arg{'options'}
Truth table100%2/2
A
A= delete $arg{'options'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 5 | ▶ | if (my $proto = delete $arg{protocol}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | push @$directives, "Protocol $proto"; | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 5 | my $cfg = Net::SSH::Perl::Config->new($ssh->{host}, %arg); | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 5 | $ssh->{config} = $cfg; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Merge config-format directives given through "options" | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # (just like -o option to ssh command line). Do this before | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # reading config files so we override files. | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 5 | for my $d (@$directives) { | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 4 | $cfg->merge_directive($d); | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 5 | for my $f (($user_config, $sys_config)) { | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | 10 | $ssh->debug("Reading configuration data $f"); | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 10 | $cfg->read_config($f); | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 5 | ▶ | if (my $real_host = $ssh->{config}->get('hostname')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 3 | $ssh->{host} = $real_host; | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 5 | my $user = _current_user(); | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 5 | ▶ | if ($user && $user eq "root" && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$user and $user eq "root" and not defined $ssh->{"config"}->get("privileged")
$user and $user eq "root"
MC/DC0%0/3
$user and $user eq "root" and not defined $ssh->{"config"}->get("privileged")
$user
$user eq "root"
not defined $ssh->{"config"}->get("privileged")
Truth table25%1/4
A and B and not(C)
A= $userB= $user eq "root"C= not defined $ssh->{"config"}->get("privileged")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | !defined $ssh->{config}->get('privileged')) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $ssh->{config}->set('privileged', 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 5 | ▶ | unless ($ssh->{config}->get('protocol')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 5 | $ssh->{config}->set('protocol', | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | PROTOCOL_SSH1 | PROTOCOL_SSH2 | PROTOCOL_SSH1_PREFERRED); | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 5 | ▶ | unless (defined $ssh->{config}->get('password_prompt_login')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 5 | $ssh->{config}->set('password_prompt_login', 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 5 | ▶ | unless (defined $ssh->{config}->get('password_prompt_host')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 5 | $ssh->{config}->set('password_prompt_host', 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 5 | ▶ | unless (defined $ssh->{config}->get('number_of_password_prompts')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 5 | $ssh->{config}->set('number_of_password_prompts', 3); | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ▶ | sub _proto_init { } | |||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_proto_init: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | ▶ | sub register_handler { } | |||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_handler: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 9 | ▶ | sub config { $_[0]->{config} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | sub configure { | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
configure: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $CONFIG = { @_ }; | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | sub ssh { | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | my($host, @cmd) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ssh: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my($user); | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | ($host, $user) = $host =~ m!(.+)@(.+)! ? | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | ($2, $1) : ($host, _current_user()); | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my $ssh = __PACKAGE__->new($host, %$CONFIG); | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $ssh->login($user); | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | my($out, $err, $exit) = $ssh->cmd(join ' ', @cmd); | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | print $out; | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | print STDERR $err if $err; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | sub issh { | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | my($host, @cmd) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
issh: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | print join(' ', @cmd), "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | print "Proceed: [y/N]:"; | |||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | my $x = scalar(<STDIN>); | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if ($x =~ /^y/i) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $CONFIG->{interactive} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ssh($host, @cmd); | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | sub _connect { | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | my $ssh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_connect: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $sock = $ssh->_create_socket; | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my $raddr = inet_aton($ssh->{host}); | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | croak "Net::SSH: Bad host name: $ssh->{host}" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | unless defined $raddr; | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | my $rport = $ssh->{config}->get('port') || 'ssh'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ssh->{'config'}->get('port') || 'ssh'
MC/DC0%0/1
$ssh->{'config'}->get('port') || 'ssh'
$ssh->{'config'}->get('port')
Truth table0%0/2
A
A= $ssh->{'config'}->get('port')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if ($rport =~ /\D/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | my @serv = getservbyname(my $serv = $rport, 'tcp'); | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | $rport = $serv[2] || 22; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$serv[2] || 22
MC/DC0%0/1
$serv[2] || 22
$serv[2]
Truth table0%0/2
A
A= $serv[2]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | $ssh->debug("Connecting to $ssh->{host}, port $rport."); | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | connect($sock, sockaddr_in($rport, $raddr)) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | or die "Can't connect to $ssh->{host}, port $rport: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | select((select($sock), $|=1)[0]); | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | $ssh->{session}{sock} = $sock; | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $ssh->_exchange_identification; | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | if ($^O eq 'MSWin32') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $nonblocking = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ioctl $sock, 0x8004667e, \\$nonblocking; | |||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | defined($sock->blocking(0)) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | or die "Can't set socket non-blocking: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $ssh->debug("Connection established."); | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | sub _create_socket { | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | my $ssh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_socket: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $sock = gensym; | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my ($p,$end,$delta) = (0,1,1); # normally we use whatever port we can get | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | ($p,$end,$delta) = (1023,512,-1) if $ssh->{config}->get('privileged'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # allow an explicit bind address | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | my $addr = $ssh->{config}->get('bind_address'); | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | $addr = inet_aton($addr) if $addr; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | ($p,$end,$delta) = (10000,65535,1) if $addr and not $p; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$addr and not $p
MC/DC0%0/2
$addr and not $p
$addr
not $p
Truth table0%0/3
A and not(B)
A= $addrB= not $p
| |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | $addr ||= INADDR_ANY; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$addr ||= "\0\0\0\0"
MC/DC0%0/1
$addr ||= "\0\0\0\0"
$addr
Truth table0%0/2
A
A= $addr
| |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | for(; $p != $end; $p += $delta) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | socket($sock, AF_INET, SOCK_STREAM, getprotobyname('tcp') || 0) || | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
getprotobyname 'tcp' || 0
MC/DC0%0/1
getprotobyname 'tcp' || 0
getprotobyname 'tcp'
Truth table0%0/2
A
A= getprotobyname 'tcp'
| |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | croak "Net::SSH: Can't create socket: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | setsockopt($sock, IPPROTO_TCP, TCP_NODELAY, 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | last if not $p or bind($sock, sockaddr_in($p,$addr)); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $p or bind $sock, sockaddr_in($p, $addr)
MC/DC0%0/2
not $p or bind $sock, sockaddr_in($p, $addr)
not $p
bind $sock, sockaddr_in($p, $addr)
Truth table0%0/3
not(A) or B
A= not $pB= bind $sock, sockaddr_in($p, $addr)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | if ($! =~ /Address already in use/i) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | close($sock) or warn qq{Could not close socket: $!\n}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | croak "Net::SSH: Can't bind socket to port $p: $!"; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if($p) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $ssh->debug("Allocated local port $p."); | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | $ssh->{config}->set('localport', $p); | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $sock; | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||
| 267 | ▶ | sub _disconnect { } | |||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_disconnect: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | sub fatal_disconnect { | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 1 | ▶ | my $ssh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fatal_disconnect: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | $ssh->_disconnect(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | croak @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | sub _read_version_line { | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | my $ssh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_version_line: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | my $sock = $ssh->{session}{sock}; | |||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | my $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | for(;;) { | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | my $s = IO::Select->new($sock); | |||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | my @ready = $s->can_read; | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | my $buf; | |||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my $len = sysread($sock, $buf, 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | unless(defined($len)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | next if $!{EAGAIN} || $!{EWOULDBLOCK}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$!{"EAGAIN"} or $!{"EWOULDBLOCK"}
MC/DC0%0/2
$!{"EAGAIN"} or $!{"EWOULDBLOCK"}
$!{"EAGAIN"}
$!{"EWOULDBLOCK"}
Truth table0%0/3
A or B
A= $!{"EAGAIN"}B= $!{"EWOULDBLOCK"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | croak "Read from socket failed: $!"; | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | croak "Connection closed by remote host" if $len == 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $line .= $buf; | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | croak "Version line too long: $line" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($line, 0, 4) eq "SSH-" and length $line > 255
MC/DC0%0/2
substr($line, 0, 4) eq "SSH-" and length $line > 255
substr($line, 0, 4) eq "SSH-"
length $line > 255
Truth table0%0/3
A and B
A= substr($line, 0, 4) eq "SSH-"B= length $line > 255
| |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | if substr($line, 0, 4) eq "SSH-" and length($line) > 255; | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | croak "Pre-version line too long: $line" if length($line) > 4*1024; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | return $line if $buf eq "\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | sub _read_version { | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | my $ssh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_version: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my ($line, $line_out); | |||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $line = $line_out = $ssh->_read_version_line; | |||||||||||||||||||||||||||||||||||||||||||||
| 302 | } while (substr($line, 0, 4) ne "SSH-"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | chomp($line_out); | |||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $ssh->debug("Remote version string: $line_out"); | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 10 | ▶ | sub sock { $_[0]->{session}{sock} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sock: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | sub _exchange_identification { | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | my $ssh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exchange_identification: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my $sock = $ssh->{session}{sock}; | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my $remote_id = $ssh->_read_version; | |||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ($ssh->{server_version_string} = $remote_id) =~ s/\cM?\n$//; | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my($remote_major, $remote_minor, $remote_version) = $remote_id =~ | |||||||||||||||||||||||||||||||||||||||||||||
| 316 | /^SSH-(\d+)\.(\d+)-([^\n\r]+)[\r]*\n$/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | $ssh->debug("Remote protocol version $remote_major.$remote_minor, remote software version $remote_version"); | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my $proto = $ssh->config->get('protocol'); | |||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my($mismatch, $set_proto); | |||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | if ($remote_major == 1) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | if ($remote_minor == 99 && $proto & PROTOCOL_SSH2 && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
$remote_minor == 99 and $proto & &PROTOCOL_SSH2() and not $proto & &PROTOCOL_SSH1_PREFERRED()
$remote_minor == 99 and $proto & &PROTOCOL_SSH2()
MC/DC0%0/3
$remote_minor == 99 and $proto & &PROTOCOL_SSH2() and not $proto & &PROTOCOL_SSH1_PREFERRED()
$remote_minor == 99
$proto & &PROTOCOL_SSH2()
not $proto & &PROTOCOL_SSH1_PREFERRED()
Truth table0%0/4
A and B and not(C)
A= $remote_minor == 99B= $proto & &PROTOCOL_SSH2()C= not $proto & &PROTOCOL_SSH1_PREFERRED()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | !($proto & PROTOCOL_SSH1_PREFERRED)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | $set_proto = PROTOCOL_SSH2; | |||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | elsif (!($proto & PROTOCOL_SSH1)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | $mismatch = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $set_proto = PROTOCOL_SSH1; | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | elsif ($remote_major == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | if ($proto & PROTOCOL_SSH2) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | $set_proto = PROTOCOL_SSH2; | |||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if ($mismatch) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | croak sprintf "Protocol major versions differ: %d vs. %d", | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | ($proto & PROTOCOL_SSH2) ? PROTOCOL_MAJOR_2 : | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | PROTOCOL_MAJOR_1, $remote_major; | ||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my $compat20 = $set_proto == PROTOCOL_SSH2; | |||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | my $buf = sprintf "SSH-%d.%d-%s\n", | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | $compat20 ? PROTOCOL_MAJOR_2 : PROTOCOL_MAJOR_1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | $compat20 ? PROTOCOL_MINOR_2 : PROTOCOL_MINOR_1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | $VERSION; | ||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $ssh->{client_version_string} = substr $buf, 0, -1; | |||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | syswrite $sock, $buf; | |||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $ssh->set_protocol($set_proto); | |||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | $ssh->_compat_init($remote_version); | |||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | sub debug { | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 11 | ▶ | my $ssh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: called CC=3 SCAR=15.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 11 | ▶ | if ($ssh->{config}->get('debug')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | printf STDERR "%s@_\n", $HOSTNAME ? "$HOSTNAME: " : ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | sub login { | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | ▶ | my $ssh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
login: called CC=5 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | my($user, $pass) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1 | ▶ | if (!defined $ssh->{config}->get('user')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | $ssh->{config}->set('user', | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 367 | defined $user ? $user : _current_user()); | ||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 1 | ▶ | if (!defined $pass && exists $CONFIG->{ssh_password}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $pass and exists $Net::SSH::Perl::CONFIG->{"ssh_password"}
MC/DC0%0/2
not defined $pass and exists $Net::SSH::Perl::CONFIG->{"ssh_password"}
not defined $pass
exists $Net::SSH::Perl::CONFIG->{"ssh_password"}
Truth table33%1/3
not(A) and B
A= not defined $passB= exists $Net::SSH::Perl::CONFIG->{"ssh_password"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $pass = $CONFIG->{ssh_password}; | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 1 | $ssh->{config}->set('pass', $pass); | |||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | ▶ | sub _login { } | |||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_login: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||
| 377 | ▶ | sub cmd { } | |||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmd: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | ▶ | sub shell { } | |||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shell: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | sub incoming_data { | ||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 13 | ▶ | my $ssh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
incoming_data: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 13 | ▶ | if (!exists $ssh->{session}{incoming_data}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 2 | ▶ | $ssh->{session}{incoming_data} = Net::SSH::Perl::Buffer->new( MP => $ssh->protocol == PROTOCOL_SSH2 ? 'SSH2' : 'SSH1' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 13 | $ssh->{session}{incoming_data}; | |||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | sub session_id { | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | my $ssh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
session_id: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | $ssh->{session}{id} = shift if @_ and not defined $ssh->{session}{id}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ and not defined $ssh->{"session"}{"id"}
MC/DC0%0/2
@_ and not defined $ssh->{"session"}{"id"}
@_
not defined $ssh->{"session"}{"id"}
Truth table0%0/3
A and not(B)
A= @_B= not defined $ssh->{"session"}{"id"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $ssh->{session}{id}; | |||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 1 | ▶ | sub packet_start { Net::SSH::Perl::Packet->new($_[0], type => $_[1]) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
packet_start: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | sub check_host_key { | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | my $ssh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_host_key: not called CC=25 SCAR=64.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | my($key, $host, $u_hostfile, $s_hostfile) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 399 | my $strict_host_key_checking = | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ▶ | $ssh->{config}->get('strict_host_key_checking') || 'no'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ssh->{'config'}->get('strict_host_key_checking') || 'no'
MC/DC0%0/1
$ssh->{'config'}->get('strict_host_key_checking') || 'no'
$ssh->{'config'}->get('strict_host_key_checking')
Truth table0%0/2
A
A= $ssh->{'config'}->get('strict_host_key_checking')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | $host ||= $ssh->{host}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$host ||= $ssh->{"host"}
MC/DC0%0/2
$host ||= $ssh->{"host"}
$host
$ssh->{"host"}
Truth table0%0/3
A ||= B
A= $hostB= $ssh->{"host"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | $u_hostfile ||= $ssh->{config}->get('user_known_hosts'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$u_hostfile ||= $ssh->{"config"}->get("user_known_hosts")
MC/DC0%0/2
$u_hostfile ||= $ssh->{"config"}->get("user_known_hosts")
$u_hostfile
$ssh->{"config"}->get("user_known_hosts")
Truth table0%0/3
A ||= B
A= $u_hostfileB= $ssh->{"config"}->get("user_known_hosts")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | $s_hostfile ||= $ssh->{config}->get('global_known_hosts'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$s_hostfile ||= $ssh->{"config"}->get("global_known_hosts")
MC/DC0%0/2
$s_hostfile ||= $ssh->{"config"}->get("global_known_hosts")
$s_hostfile
$ssh->{"config"}->get("global_known_hosts")
Truth table0%0/3
A ||= B
A= $s_hostfileB= $ssh->{"config"}->get("global_known_hosts")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | my $port = $ssh->{config}->get('port'); | |||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | if (defined $port && $port =~ /\D/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $port and $port =~ /\D/
MC/DC0%0/2
defined $port and $port =~ /\D/
defined $port
$port =~ /\D/
Truth table0%0/3
A and B
A= defined $portB= $port =~ /\D/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | my @serv = getservbyname(my $serv = $port, 'tcp'); | |||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $port = $serv[2]; | |||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | my $hash_known_hosts = $ssh->{config}->get('hash_known_hosts'); | |||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | my $check_ip = $ssh->{config}->get('check_host_ip'); | |||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | $check_ip = 1 unless defined $check_ip; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | my $status = _check_host_in_hostfile($host, $port, $u_hostfile, $key); | |||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | unless (defined $status && ($status == HOST_OK || $status == HOST_CHANGED)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $status and $status == &HOST_OK() || $status == &HOST_CHANGED()
$status == &HOST_OK() or $status == &HOST_CHANGED()
MC/DC0%0/3
defined $status and $status == &HOST_OK() || $status == &HOST_CHANGED()
defined $status
$status == &HOST_OK()
$status == &HOST_CHANGED()
Truth table0%0/4
A and B or C
A= defined $statusB= $status == &HOST_OK()C= $status == &HOST_CHANGED()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | $status = _check_host_in_hostfile($host, $port, $s_hostfile, $key); | |||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | if ($status == HOST_OK) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | $ssh->debug("Host '$host' is known and matches the host key."); | |||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | elsif ($status == HOST_NEW) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | if ($strict_host_key_checking =~ /(ask|yes)/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | if (!$ssh->{config}->get('interactive')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | croak "Host key verification failed."; | |||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my $prompt = | |||||||||||||||||||||||||||||||||||||||||||||
| 429 | qq(The authenticity of host '$host' can't be established. | ||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | Key fingerprint is @{[ $key->fingerprint($ssh->config->get('fingerprint_hash')) ]}. | |||||||||||||||||||||||||||||||||||||||||||||
| 431 | Are you sure you want to continue connecting (yes/no)?); | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | unless (_read_yes_or_no($prompt, "yes")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | croak "Aborted by user!"; | |||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | _add_host_to_hostfile($host, $port, $u_hostfile, $key, $hash_known_hosts); | |||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | $ssh->debug("Permanently added '$host' to the list of known hosts."); | |||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 439 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | croak "Host key for '$host' has changed!"; | |||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | return unless $check_ip && $host =~ /[a-z][A-Z]+/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$check_ip and $host =~ /[a-z][A-Z]+/
MC/DC0%0/2
$check_ip and $host =~ /[a-z][A-Z]+/
$check_ip
$host =~ /[a-z][A-Z]+/
Truth table0%0/3
A and B
A= $check_ipB= $host =~ /[a-z][A-Z]+/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | my $ip = inet_ntoa(inet_aton($host)) or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | $status = _check_host_in_hostfile($ip, $port, $u_hostfile, $key); | |||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | unless (defined $status && ($status == HOST_OK || $status == HOST_CHANGED)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $status and $status == &HOST_OK() || $status == &HOST_CHANGED()
$status == &HOST_OK() or $status == &HOST_CHANGED()
MC/DC0%0/3
defined $status and $status == &HOST_OK() || $status == &HOST_CHANGED()
defined $status
$status == &HOST_OK()
$status == &HOST_CHANGED()
Truth table0%0/4
A and B or C
A= defined $statusB= $status == &HOST_OK()C= $status == &HOST_CHANGED()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | $status = _check_host_in_hostfile($ip, $port, $s_hostfile, $key); | |||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | if ($status == HOST_NEW) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | _add_host_to_hostfile($ip, $port, $u_hostfile, $key, $hash_known_hosts); | |||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 453 | elsif ($status == HOST_CHANGED) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | my $prompt = | |||||||||||||||||||||||||||||||||||||||||||||
| 455 | qq(The host key for IP address '$ip' does not match that for '$host'. | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | Are you sure you want to continue connecting (yes/no)?); | ||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | unless (_read_yes_or_no($prompt, "yes")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | croak "Aborted by user!"; | |||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 464 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||