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

filter: Statementstmt 27.4% 84 / 306 Branchbran 8.8% 9 / 102 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 55.8% 24 / 43 Podpod 61.5% 8 / 13 totaltotal 26.2% 125 / 477 SCAR 75.3
CC
62
Cov
22%
_login
306.0
_setup_connection
182.0
_start_interactive
132.0
CRAP 1861.3
« blib/lib/Net/SSH/Perl/Util/Hosts.pm ↑ Summary blib/lib/Net/SSH/Perl/Key/Ed25519.pm »
1 package Net::SSH::Perl::SSH1;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Net::SSH::Perl::Packet;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Net::SSH::Perl::Buffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Net::SSH::Perl::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Net::SSH::Perl::Constants qw( :protocol :msg :hosts );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Net::SSH::Perl::Cipher;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Net::SSH::Perl::Auth;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Net::SSH::Perl::Comp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Net::SSH::Perl::Key::RSA1;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Net::SSH::Perl::Util qw( :hosts _compute_session_id _rsa_public_encrypt );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Net::SSH::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use base qw( Net::SSH::Perl );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use Math::GMP;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use File::Spec::Functions qw( catfile );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use File::HomeDir ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶use vars qw( $VERSION $CONFIG $HOSTNAME );
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 $VERSION = $Net::SSH::Perl::VERSION;
25  
26 sub version_string {
27 1 ▶ my $class = shift;
Subroutine version_string: called CC=1 SCAR=0.0
Pod undocumented
28 1 sprintf "Net::SSH::Perl Version %s, protocol version %s.%s.",
29 $class->VERSION, PROTOCOL_MAJOR_1, PROTOCOL_MINOR_1;
30 }
31  
32 sub _proto_init {
33 1 ▶ my $ssh = shift;
Subroutine _proto_init: called CC=9 SCAR=23.3
34 1 my $home = File::HomeDir->my_home;
35 1 my $config = $ssh->{config};
36  
37 1 ▶ unless ($config->get('user_known_hosts')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config->get("user_known_hosts")) 1 0 1
38 1 ▶ defined $home or croak "Cannot determine home directory, please set the environment variable HOME";
Branch: 1 branch
BranchTrueFalseTotal
defined $home or croak("Cannot determine home directory, please set the environment variable HOME") 0 1 1
39 1 $config->set('user_known_hosts', catfile($home, '.ssh', 'known_hosts'));
40 }
41 1 ▶ unless ($config->get('global_known_hosts')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config->get("global_known_hosts")) 1 0 1
42 my $glob_known_hosts = $^O eq 'MSWin32'
43 1 ▶ ? catfile( $ENV{WINDIR}, 'ssh_known_hosts' )
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 1 1
44 : '/etc/ssh_known_hosts';
45 1 $config->set('global_known_hosts', $glob_known_hosts );
46 }
47 1 ▶ unless (my $if = $config->get('identity_files')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (my $if = $config->get("identity_files")) 1 0 1
48 1 ▶ defined $home or croak "Cannot determine home directory, please set the environment variable HOME";
Branch: 1 branch
BranchTrueFalseTotal
defined $home or croak("Cannot determine home directory, please set the environment variable HOME") 0 1 1
49 1 $config->set('identity_files', [ catfile($home, '.ssh', 'identity') ]);
50 }
51  
52 1 for my $a (qw( password rhosts rhosts_rsa rsa ch_res )) {
53 5 ▶ $config->set("auth_$a", 1)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config->get("auth_$a") 5 0 5
54 unless defined $config->get("auth_$a");
55 }
56 }
57  
58 sub _disconnect {
59 1 ▶ my $ssh = shift;
Subroutine _disconnect: called CC=3 SCAR=11.0
60 1 my $packet = $ssh->packet_start(SSH_MSG_DISCONNECT);
61 1 ▶ $packet->put_str("@_") if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 0 1
62 1 $packet->send;
63 1 $ssh->{session} = {};
64 1 for my $key (qw( _cmd_stdout _cmd_stderr _cmd_exit )) {
65 3 $ssh->{$key} = "";
66 }
67 }
68  
69 sub register_handler {
70 0 ▶ my($ssh, $type, $sub, @extra) = @_;
Subroutine register_handler: not called CC=3 SCAR=24.8
Pod documented
71 ## XXX hack
72 0 ▶ if ($type eq 'stdout') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'stdout') { } 0 0 0
elsif ($type eq 'stderr') { } 0 0 0
73 0 $type = SSH_SMSG_STDOUT_DATA;
74 } elsif ($type eq 'stderr') {
75 0 $type = SSH_SMSG_STDERR_DATA;
76 }
77 0 $ssh->{client_handlers}{$type} = { code => $sub, extra => \@extra };
78 }
79 0 ▶sub handler_for { $_[0]->{client_handlers}{$_[1]} }
Subroutine handler_for: not called CC=1 SCAR=6.9
Pod undocumented
80  
81 sub _login {
82 0 ▶ my $ssh = shift;
Subroutine _login: not called CC=17 SCAR=57.2
83 0 my $user = $ssh->{config}->get('user');
84 0 ▶ croak "No user defined" unless $user;
Branch: 1 branch
BranchTrueFalseTotal
unless $user 0 0 0
85  
86 0 $ssh->debug("Waiting for server public key.");
87 0 my $packet = Net::SSH::Perl::Packet->read_expect($ssh, SSH_SMSG_PUBLIC_KEY);
88  
89 0 my $check_bytes = $packet->bytes(0, 8, "");
90  
91 0 my %keys;
92 0 for my $which (qw( public host )) {
93 0 $keys{$which} = Net::SSH::Perl::Key::RSA1->new;
94 0 $keys{$which}{rsa}{bits} = $packet->get_int32;
95 0 $keys{$which}{rsa}{e} = $packet->get_mp_int;
96 0 $keys{$which}{rsa}{n} = $packet->get_mp_int;
97 }
98  
99 0 my $protocol_flags = $packet->get_int32;
100 0 my $supported_ciphers = $packet->get_int32;
101 0 my $supported_auth = $packet->get_int32;
102  
103 0 $ssh->debug("Received server public key ($keys{public}{rsa}{bits} " .
104 "bits) and host key ($keys{host}{rsa}{bits} bits).");
105  
106 my $session_id =
107 0 _compute_session_id($check_bytes, $keys{host}, $keys{public});
108 0 $ssh->{session}{id} = $session_id;
109  
110 0 $ssh->check_host_key($keys{host});
111  
112 0 my $session_key = join '', map chr rand(255), 1..32;
113 0 my $skey = Math::GMP->new(0);
114 0 for my $i (0..31) {
115 0 $skey *= 2**8;
116 0 ▶ $skey += $i < 16 ?
Branch: 1 branch
BranchTrueFalseTotal
$i < 16 ? : 0 0 0
117 vec($session_key, $i, 8) ^ vec($session_id, $i, 8) :
118 vec($session_key, $i, 8);
119 }
120  
121 0 ▶ if ($keys{public}{rsa}{n} < $keys{host}{rsa}{n}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keys{'public'}{'rsa'}{'n'} < $keys{'host'}{'rsa'}{'n'}) { } 0 0 0
122 0 $skey = _rsa_public_encrypt($skey, $keys{public});
123 0 $skey = _rsa_public_encrypt($skey, $keys{host});
124 }
125 else {
126 0 $skey = _rsa_public_encrypt($skey, $keys{host});
127 0 $skey = _rsa_public_encrypt($skey, $keys{public});
128 }
129  
130 0 my($cipher, $cipher_name);
131 0 ▶ if ($cipher_name = $ssh->{config}->get('cipher')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cipher_name = $ssh->{'config'}->get('cipher')) { } 0 0 0
132 0 $cipher = Net::SSH::Perl::Cipher::id($cipher_name);
133 }
134 else {
135 0 my $cid;
136 0 ▶ if (($cid = Net::SSH::Perl::Cipher::id('IDEA')) &&
Branch: 2 branches
BranchTrueFalseTotal
if ($cid = Net::SSH::Perl::Cipher::id('IDEA') and Net::SSH::Perl::Cipher::supported($cid, $supported_ciphers)) { } 0 0 0
elsif ($cid = Net::SSH::Perl::Cipher::id('DES3') and Net::SSH::Perl::Cipher::supported($cid, $supported_ciphers)) { } 0 0 0
Condition0%0/3
$cid = Net::SSH::Perl::Cipher::id("IDEA") and Net::SSH::Perl::Cipher::supported($cid, $supported_ciphers)
!ll&&!rl&&r
000
MC/DC0%0/2
$cid = Net::SSH::Perl::Cipher::id("IDEA") and Net::SSH::Perl::Cipher::supported($cid, $supported_ciphers)
$cid = Net::SSH::Perl::Cipher::id("IDEA") Net::SSH::Perl::Cipher::supported($cid, $supported_ciphers)
Truth table0%0/3
A and B
A= $cid = Net::SSH::Perl::Cipher::id("IDEA")B= Net::SSH::Perl::Cipher::supported($cid, $supported_ciphers)
ABresult
0X0
100
111
137 Net::SSH::Perl::Cipher::supported($cid, $supported_ciphers)) {
138 0 $cipher_name = 'IDEA';
139 0 $cipher = $cid;
140 }
141 ▶ elsif (($cid = Net::SSH::Perl::Cipher::id('DES3')) &&
Condition0%0/3
$cid = Net::SSH::Perl::Cipher::id("DES3") and Net::SSH::Perl::Cipher::supported($cid, $supported_ciphers)
!ll&&!rl&&r
000
MC/DC0%0/2
$cid = Net::SSH::Perl::Cipher::id("DES3") and Net::SSH::Perl::Cipher::supported($cid, $supported_ciphers)
$cid = Net::SSH::Perl::Cipher::id("DES3") Net::SSH::Perl::Cipher::supported($cid, $supported_ciphers)
Truth table0%0/3
A and B
A= $cid = Net::SSH::Perl::Cipher::id("DES3")B= Net::SSH::Perl::Cipher::supported($cid, $supported_ciphers)
ABresult
0X0
100
111
142 Net::SSH::Perl::Cipher::supported($cid, $supported_ciphers)) {
143 0 $cipher_name = 'DES3';
144 0 $cipher = $cid;
145 }
146 }
147  
148 0 ▶ unless (Net::SSH::Perl::Cipher::supported($cipher, $supported_ciphers)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Net::SSH::Perl::Cipher::supported($cipher, $supported_ciphers)) 0 0 0
149 0 croak "Selected cipher type $cipher_name not supported by server.";
150 }
151 0 $ssh->debug(sprintf "Encryption type: %s", $cipher_name);
152  
153 0 $packet = $ssh->packet_start(SSH_CMSG_SESSION_KEY);
154 0 $packet->put_int8($cipher);
155 0 $packet->put_chars($check_bytes);
156 0 $packet->put_mp_int($skey);
157 0 $packet->put_int32(0); ## No protocol flags.
158 0 $packet->send;
159 0 $ssh->debug("Sent encrypted session key.");
160  
161 0 $ssh->set_cipher($cipher_name, $session_key);
162 0 $ssh->{session}{key} = $session_key;
163  
164 0 Net::SSH::Perl::Packet->read_expect($ssh, SSH_SMSG_SUCCESS);
165 0 $ssh->debug("Received encryption confirmation.");
166  
167 0 $packet = $ssh->packet_start(SSH_CMSG_USER);
168 0 $packet->put_str($user);
169 0 $packet->send;
170  
171 0 $packet = Net::SSH::Perl::Packet->read($ssh);
172 0 ▶ return 1 if $packet->type == SSH_SMSG_SUCCESS;
Branch: 1 branch
BranchTrueFalseTotal
if $packet->type == &SSH_SMSG_SUCCESS() 0 0 0
173  
174 0 ▶ if ($packet->type != SSH_SMSG_FAILURE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($packet->type != &SSH_SMSG_FAILURE()) 0 0 0
175 0 $ssh->fatal_disconnect(sprintf
176 "Protocol error: got %d in response to SSH_CMSG_USER", $packet->type);
177 }
178  
179 0 my $auth_order = Net::SSH::Perl::Auth::auth_order();
180 0 for my $auth_id (@$auth_order) {
181 0 ▶ next unless Net::SSH::Perl::Auth::supported($auth_id, $supported_auth);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::SSH::Perl::Auth::supported($auth_id, $supported_auth) 0 0 0
182 0 my $auth = Net::SSH::Perl::Auth->new(Net::SSH::Perl::Auth::name($auth_id), $ssh);
183 0 my $valid = $auth->authenticate;
184 0 ▶ return 1 if $valid;
Branch: 1 branch
BranchTrueFalseTotal
if $valid 0 0 0
185 }
186 }
187  
188 sub compression {
189 10 ▶ my $ssh = shift;
Subroutine compression: called CC=2 SCAR=9.2
Pod documented
190 10 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 10 10
191 0 my $level = shift;
192 0 $ssh->debug("Enabling compression at level $level.");
193 0 $ssh->{session}{compression} = Net::SSH::Perl::Comp->new('Zlib', $level);
194 }
195 10 $ssh->{session}{compression};
196 }
197  
198 sub _setup_connection {
199 0 ▶ my $ssh = shift;
Subroutine _setup_connection: not called CC=13 SCAR=52.0
200  
201 0 ▶ $ssh->_connect unless $ssh->sock;
Branch: 1 branch
BranchTrueFalseTotal
unless $ssh->sock 0 0 0
202 0 ▶ $ssh->_login or
Branch: 1 branch
BranchTrueFalseTotal
$ssh->_login or $ssh->fatal_disconnect("Permission denied") 0 0 0
203 $ssh->fatal_disconnect("Permission denied");
204  
205 0 ▶ if ($ssh->{config}->get('compression')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ssh->{"config"}->get("compression")) 0 0 0
206 0 eval { require Compress::Zlib; };
207 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
208 0 $ssh->debug("Compression is disabled because Compress::Zlib can't be loaded.");
209 }
210 else {
211 0 ▶ my $level = $ssh->{config}->get('compression_level') || 6;
Condition0%0/2
$ssh->{'config'}->get('compression_level') || 6
l!l
00
MC/DC0%0/1
$ssh->{'config'}->get('compression_level') || 6
$ssh->{'config'}->get('compression_level')
Truth table0%0/2
A
A= $ssh->{'config'}->get('compression_level')
Aresult
11
00
212 0 $ssh->debug("Requesting compression at level $level.");
213 0 my $packet = $ssh->packet_start(SSH_CMSG_REQUEST_COMPRESSION);
214 0 $packet->put_int32($level);
215 0 $packet->send;
216  
217 0 $packet = Net::SSH::Perl::Packet->read($ssh);
218 0 ▶ if ($packet->type == SSH_SMSG_SUCCESS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($packet->type == &SSH_SMSG_SUCCESS()) { } 0 0 0
219 0 $ssh->compression($level);
220 }
221 else {
222 0 $ssh->debug("Warning: Remote host refused compression.");
223 }
224 }
225 }
226  
227 0 ▶ if ($ssh->{config}->get('use_pty')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ssh->{"config"}->get("use_pty")) 0 0 0
228 0 $ssh->debug("Requesting pty.");
229 0 my($packet);
230 0 $packet = $ssh->packet_start(SSH_CMSG_REQUEST_PTY);
231 0 my($term) = $ENV{TERM} =~ /(\S+)/;
232 0 $packet->put_str($term);
233 0 my $foundsize = 0;
234 0 ▶ if (eval "require Term::ReadKey") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "require Term::ReadKey") 0 0 0
235 0 my @sz = Term::ReadKey::GetTerminalSize($ssh->sock);
236 0 ▶ if (defined $sz[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sz[0]) 0 0 0
237 0 $foundsize = 1;
238 0 $packet->put_int32($sz[0]); # width
239 0 $packet->put_int32($sz[1]); # height
240 0 $packet->put_int32($sz[2]); # xpix
241 0 $packet->put_int32($sz[3]); # ypix
242 }
243 }
244 0 ▶ if (!$foundsize) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($foundsize) 0 0 0
245 0 $packet->put_int32(0) for 1..4;
246 }
247 0 $packet->put_int8(0);
248 0 $packet->send;
249  
250 0 $packet = Net::SSH::Perl::Packet->read($ssh);
251 0 ▶ unless ($packet->type == SSH_SMSG_SUCCESS) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($packet->type == &SSH_SMSG_SUCCESS()) 0 0 0
252 0 $ssh->debug("Warning: couldn't allocate a pseudo tty.");
253 }
254 }
255 }
256  
257 sub cmd {
258 0 ▶ my $ssh = shift;
Subroutine cmd: not called CC=7 SCAR=40.3
Pod documented
259 0 my $cmd = shift;
260 0 my $stdin = shift;
261  
262 0 $ssh->_setup_connection;
263  
264 0 my($packet);
265  
266 0 $ssh->debug("Sending command: $cmd");
267 0 $packet = $ssh->packet_start(SSH_CMSG_EXEC_CMD);
268 0 $packet->put_str($cmd);
269 0 $packet->send;
270  
271 0 ▶ if (defined $stdin) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stdin) 0 0 0
272 0 my $chunk_size = 32000;
273 0 ▶ while ($stdin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stdin) 0 0 0
274 0 my $chunk = substr($stdin, 0, $chunk_size, '');
275 0 $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
276 0 $packet->put_str($chunk);
277 0 $packet->send;
278 }
279  
280 0 $packet = $ssh->packet_start(SSH_CMSG_EOF);
281 0 $packet->send;
282 }
283  
284 0 ▶ unless ($ssh->handler_for(SSH_SMSG_STDOUT_DATA)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ssh->handler_for(&SSH_SMSG_STDOUT_DATA())) 0 0 0
285 $ssh->register_handler(SSH_SMSG_STDOUT_DATA,
286 0 ▶ sub { $ssh->{_cmd_stdout} .= $_[1]->get_str });
Subroutine __ANON__: not called CC=1 SCAR=6.9
287 }
288 0 ▶ unless ($ssh->handler_for(SSH_SMSG_STDERR_DATA)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ssh->handler_for(&SSH_SMSG_STDERR_DATA())) 0 0 0
289 $ssh->register_handler(SSH_SMSG_STDERR_DATA,
290 0 ▶ sub { $ssh->{_cmd_stderr} .= $_[1]->get_str });
Subroutine __ANON__: not called CC=1 SCAR=6.9
291 }
292 0 ▶ unless ($ssh->handler_for(SSH_SMSG_EXITSTATUS)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ssh->handler_for(&SSH_SMSG_EXITSTATUS())) 0 0 0
293 $ssh->register_handler(SSH_SMSG_EXITSTATUS,
294 0 ▶ sub { $ssh->{_cmd_exit} = $_[1]->get_int32 });
Subroutine __ANON__: not called CC=1 SCAR=6.9
295 }
296  
297 0 $ssh->debug("Entering interactive session.");
298 0 ▶ $ssh->_start_interactive(defined $stdin ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $stdin ? : 0 0 0
299 my($stdout, $stderr, $exit) =
300 0 map $ssh->{"_cmd_$_"}, qw( stdout stderr exit );
301  
302 0 $ssh->_disconnect;
303 0 ($stdout, $stderr, $exit);
304 }
305  
306 sub shell {
307 0 ▶ my $ssh = shift;
Subroutine shell: not called CC=2 SCAR=17.9
Pod documented
308  
309 $ssh->{config}->set('use_pty', 1)
310 0 ▶ unless defined $ssh->{config}->get('use_pty');
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ssh->{"config"}->get("use_pty") 0 0 0
311 0 $ssh->_setup_connection;
312  
313 0 $ssh->debug("Requesting shell.");
314 0 my $packet = $ssh->packet_start(SSH_CMSG_EXEC_SHELL);
315 0 $packet->send;
316  
317 $ssh->register_handler(SSH_SMSG_STDOUT_DATA,
318 0 ▶ sub { syswrite STDOUT, $_[1]->get_str });
Subroutine __ANON__: not called CC=1 SCAR=6.9
319 $ssh->register_handler(SSH_SMSG_STDERR_DATA,
320 0 ▶ sub { syswrite STDERR, $_[1]->get_str });
Subroutine __ANON__: not called CC=1 SCAR=6.9
321 0 ▶ $ssh->register_handler(SSH_SMSG_EXITSTATUS, sub {});
Subroutine __ANON__: not called CC=1 SCAR=6.9
322  
323 0 $ssh->debug("Entering interactive session.");
324 0 $ssh->_start_interactive(0);
325  
326 0 $ssh->_disconnect;
327 }
328  
329 sub open2 {
330 0 ▶ my $ssh = shift;
Subroutine open2: not called CC=4 SCAR=30.0
Pod undocumented
331 0 my($cmd) = @_;
332  
333 0 require Net::SSH::Perl::Handle::SSH1;
334  
335 0 ▶ unless ($cmd) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmd) 0 0 0
336 $ssh->{config}->set('use_pty', 1)
337 0 ▶ unless defined $ssh->{config}->get('use_pty');
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ssh->{"config"}->get("use_pty") 0 0 0
338 }
339 0 $ssh->_setup_connection;
340  
341 0 ▶ if ($cmd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd) { } 0 0 0
342 0 $ssh->debug("Sending command: $cmd");
343 0 my $packet = $ssh->packet_start(SSH_CMSG_EXEC_CMD);
344 0 $packet->put_str($cmd);
345 0 $packet->send;
346 }
347 else {
348 0 $ssh->debug("Requesting shell.");
349 0 my $packet = $ssh->packet_start(SSH_CMSG_EXEC_SHELL);
350 0 $packet->send;
351 }
352  
353 0 my $read = Symbol::gensym;
354 0 my $write = Symbol::gensym;
355 0 tie *$read, 'Net::SSH::Perl::Handle::SSH1', 'r', $ssh;
356 0 tie *$write, 'Net::SSH::Perl::Handle::SSH1', 'w', $ssh;
357  
358 0 $ssh->debug("Entering interactive session.");
359 0 return ($read, $write);
360 }
361  
362 0 ▶sub break_client_loop { $_[0]->{_cl_quit_pending} = 1 }
Subroutine break_client_loop: not called CC=1 SCAR=6.9
Pod undocumented
363 0 ▶sub _quit_pending { $_[0]->{_cl_quit_pending} }
Subroutine _quit_pending: not called CC=1 SCAR=6.9
364  
365 sub _start_interactive {
366 0 ▶ my $ssh = shift;
Subroutine _start_interactive: not called CC=11 SCAR=48.8
367 0 my($sent_stdin) = @_;
368  
369 0 my $s = IO::Select->new;
370 0 $s->add($ssh->{session}{sock});
371 0 ▶ $s->add(\*STDIN) unless $sent_stdin;
Branch: 1 branch
BranchTrueFalseTotal
unless $sent_stdin 0 0 0
372  
373 CLOOP:
374 0 $ssh->{_cl_quit_pending} = 0;
375 0 ▶ while (!$ssh->_quit_pending) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ssh->_quit_pending) 0 0 0
376 0 my @ready = $s->can_read;
377 0 for my $a (@ready) {
378 0 ▶ if ($a == $ssh->{session}{sock}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($a == $ssh->{'session'}{'sock'}) { } 0 0 0
elsif ($a == \*STDIN) { } 0 0 0
379 0 my $buf;
380 0 my $len = sysread $a, $buf, 8192;
381 0 ▶ $ssh->break_client_loop unless $len;
Branch: 1 branch
BranchTrueFalseTotal
unless $len 0 0 0
382 0 ($buf) = $buf =~ /(.*)/s; ## Untaint data. Anything allowed.
383 0 $ssh->incoming_data->append($buf);
384 }
385 elsif ($a == \*STDIN) {
386 0 my $buf;
387 0 sysread STDIN, $buf, 8192;
388 0 ($buf) = $buf =~ /(.*)/s; ## Untaint data. Anything allowed.
389 0 my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
390 0 $packet->put_str($buf);
391 0 $packet->send;
392 }
393 }
394  
395 0 ▶ while (my $packet = Net::SSH::Perl::Packet->read_poll($ssh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $packet = "Net::SSH::Perl::Packet"->read_poll($ssh)) 0 0 0
396 0 ▶ if (my $r = $ssh->handler_for($packet->type)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = $ssh->handler_for($packet->type)) { } 0 0 0
397 0 $r->{code}->($ssh, $packet, @{ $r->{extra} });
398 }
399 else {
400 0 $ssh->debug(sprintf
401 "Warning: ignoring packet of type %d", $packet->type);
402 }
403  
404 0 ▶ if ($packet->type == SSH_SMSG_EXITSTATUS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($packet->type == &SSH_SMSG_EXITSTATUS()) 0 0 0
405 0 my $packet = $ssh->packet_start(SSH_CMSG_EXIT_CONFIRMATION);
406 0 $packet->send;
407 0 $ssh->break_client_loop;
408 }
409 }
410  
411 0 ▶ last if $ssh->_quit_pending;
Branch: 1 branch
BranchTrueFalseTotal
if $ssh->_quit_pending 0 0 0
412 }
413 }
414  
415 sub send_data {
416 0 ▶ my $ssh = shift;
Subroutine send_data: not called CC=1 SCAR=6.9
Pod undocumented
417 0 my($data) = @_;
418 0 my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
419 0 $packet->put_str($data);
420 0 $packet->send;
421 }
422  
423 sub set_cipher {
424 0 ▶ my $ssh = shift;
Subroutine set_cipher: not called CC=1 SCAR=6.9
Pod documented
425 0 my $ciph = shift;
426 0 $ssh->{session}{receive} = Net::SSH::Perl::Cipher->new($ciph, @_);
427 0 $ssh->{session}{send} = Net::SSH::Perl::Cipher->new($ciph, @_);
428 }
429  
430 5 ▶sub send_cipher { $_[0]->{session}{send} }
Subroutine send_cipher: called CC=1 SCAR=0.0
Pod documented
431 5 ▶sub receive_cipher { $_[0]->{session}{receive} }
Subroutine receive_cipher: called CC=1 SCAR=0.0
Pod documented
432 0 ▶sub session_key { $_[0]->{session}{key} }
Subroutine session_key: not called CC=1 SCAR=6.9
Pod documented
433  
434 1 1;
435 __END__
« blib/lib/Net/SSH/Perl/Util/Hosts.pm ↑ Summary blib/lib/Net/SSH/Perl/Key/Ed25519.pm »