@@ -34,7 +34,7 @@ sub disconnect {
34
34
if ($self -> {_ssh2 }) {
35
35
$self -> {_ssh2 }-> disconnect() if $self -> {_ssh2 }-> sock;
36
36
delete $self -> {_ssh2 };
37
- $self -> {logger }-> debug2(" Disconnected from '" .$self -> host()." ' remote host..." );
37
+ $self -> {logger }-> debug2(" [libssh2] Disconnected from '" .$self -> host()." ' remote host..." );
38
38
}
39
39
40
40
# Cleanup cache
@@ -73,18 +73,18 @@ sub _connect {
73
73
my $host = $self -> host();
74
74
my $port = $self -> port();
75
75
my $remote = $host . ($port && $port == 22 ? " " : " :$port " );
76
- $self -> {logger }-> debug2(" Connecting to '$remote ' remote host..." );
76
+ $self -> {logger }-> debug2(" [libssh2] Connecting to '$remote ' remote host..." );
77
77
if (!$ssh2 -> connect ($host , $port // 22)) {
78
78
my @error = $ssh2 -> error;
79
- $self -> {logger }-> debug(" Can't reach $remote for ssh remoteinventory via libssh2 : @error " );
79
+ $self -> {logger }-> debug(" [libssh2] Can't reach $remote for ssh remoteinventory: @error " );
80
80
undef $self -> {_ssh2 };
81
81
# Don't retry to connect with libssh2 before a minute
82
82
$self -> {_ssh2_dont_retry_before } = time + 60;
83
83
return 0;
84
84
}
85
85
86
86
# Use Trust On First Use policy to verify remote host
87
- $self -> {logger }-> debug2(" Check remote host key..." );
87
+ $self -> {logger }-> debug2(" [libssh2] Check remote host key..." );
88
88
if ($OSNAME eq ' MSWin32' ) {
89
89
# On windows, use vardir as HOME to store known_hosts file
90
90
my $home = $self -> config-> {vardir };
@@ -122,23 +122,23 @@ sub _connect {
122
122
123
123
# Support authentication by password
124
124
if ($self -> pass()) {
125
- $self -> {logger }-> debug2(" Try authentication by password..." );
125
+ $self -> {logger }-> debug2(" [libssh2] Trying password authentication ..." );
126
126
my $user = $self -> user();
127
127
unless ($user ) {
128
128
if ($ENV {USER }) {
129
129
$user = $ENV {USER };
130
- $self -> {logger }-> debug2(" Trying '$user ' as login" );
130
+ $self -> {logger }-> debug2(" [libssh2] Trying '$user ' as login" );
131
131
} else {
132
- $self -> {logger }-> error(" No user given for password authentication" );
132
+ $self -> {logger }-> error(" [libssh2] No user given for password authentication" );
133
133
}
134
134
}
135
135
if ($user ) {
136
136
unless ($ssh2 -> auth_password($user , $self -> pass())) {
137
137
my @error = $ssh2 -> error;
138
- $self -> {logger }-> debug(" Can't authenticate to $remote with given password for ssh remoteinventory: @error " );
138
+ $self -> {logger }-> debug(" [libssh2] Can't authenticate to $remote with given password for ssh remoteinventory: @error " );
139
139
}
140
140
if ($ssh2 -> auth_ok) {
141
- $self -> {logger }-> debug2(" Authenticated on $remote remote with given password" );
141
+ $self -> {logger }-> debug2(" [libssh2] Authenticated on $remote remote with given password" );
142
142
$self -> user($user );
143
143
return 1;
144
144
}
@@ -159,21 +159,21 @@ sub _connect {
159
159
$self -> {_private_keys_lastscan } = time ;
160
160
}
161
161
162
- # Support public key athentication
162
+ # Support public key authentication
163
163
my $user = $self -> user() // $ENV {USER };
164
164
foreach my $private (sort (keys (%{$self -> {_private_keys }}))) {
165
- $self -> {logger }-> debug2(" Try authentication using $private key..." );
165
+ $self -> {logger }-> debug2(" [libssh2] Trying publickey authentication using $private key..." );
166
166
my $file = $self -> {_private_keys }-> {$private };
167
167
my $pubkey ;
168
168
$pubkey = $file ." .pub" if -e $file ." .pub" ;
169
169
next unless $ssh2 -> auth_publickey($user , $pubkey , $file , $self -> pass());
170
170
if ($ssh2 -> auth_ok) {
171
- $self -> {logger }-> debug2(" Authenticated on $remote remote with $private key" );
171
+ $self -> {logger }-> debug2(" [libssh2] Authenticated on $remote remote with $private key" );
172
172
return 1;
173
173
}
174
174
}
175
175
176
- $self -> {logger }-> error(" Can't authenticate on $remote remote host via libssh2 " );
176
+ $self -> {logger }-> error(" [libssh2] Can't authenticate on $remote remote host" );
177
177
undef $self -> {_ssh2 };
178
178
179
179
# Don't retry libssh2 before a minute
@@ -196,7 +196,7 @@ sub _ssh2_exec_status {
196
196
$ret = $chan -> exit_status();
197
197
$chan -> close ;
198
198
} else {
199
- $self -> {logger }-> debug2(" Failed to start '$command ' using ssh2 lib " );
199
+ $self -> {logger }-> debug2(" [libssh2] Failed to start '$command '" );
200
200
}
201
201
202
202
return $ret ;
@@ -223,7 +223,7 @@ sub checking_error {
223
223
my ($self ) = @_ ;
224
224
225
225
my $libssh2 = $self -> _connect();
226
- return " Can't run simple command on remote via libssh2 , check server is up and ssh access is setup"
226
+ return " [libssh2] Can't run simple command on remote, check server is up and ssh access is setup"
227
227
if $self -> mode(' libssh2' ) && !$self -> mode(' ssh' ) && !$libssh2 ;
228
228
229
229
my $root = $self -> getRemoteFirstLine(command => " id -u" );
@@ -252,18 +252,18 @@ sub checking_error {
252
252
my $ret = $self -> _ssh2_exec_status($command );
253
253
if (defined ($ret )) {
254
254
if ($ret ) {
255
- $self -> {logger }-> warning(" Failed to store deviceid using ssh2 " );
255
+ $self -> {logger }-> warning(" [libssh2] Failed to store deviceid" );
256
256
} else {
257
257
return ' ' ;
258
258
}
259
259
}
260
260
261
261
# Don't try ssh command if mode has been set to libssh2 only
262
- return " Failed to store deviceid on remote with libssh2 "
262
+ return " [libssh2] Failed to store deviceid on remote"
263
263
if $self -> mode(' libssh2' ) && !$self -> mode(' ssh' );
264
264
265
265
system ($self -> _ssh(), " sh" , " -c" , " '$command '" ) == 0
266
- or return " Can't store deviceid on remote" ;
266
+ or return " [ssh] Can't store deviceid on remote" ;
267
267
}
268
268
269
269
return ' ' ;
@@ -280,19 +280,19 @@ sub getRemoteFileHandle {
280
280
$self -> _connect();
281
281
my $sftp = $self -> {_ssh2 }-> sftp();
282
282
if ($sftp ) {
283
- $self -> {logger }-> debug2(" Trying to read '$params {file}' via sftp subsystem" );
283
+ $self -> {logger }-> debug2(" [libssh2] Trying to read '$params {file}' via sftp subsystem" );
284
284
my $fh = $sftp -> open ($params {file });
285
285
return $fh if $fh ;
286
286
my @error = $sftp -> error;
287
287
if (@error && $error [0]) {
288
288
if ($error [0] == 2) { # SSH_FX_NO_SUCH_FILE
289
- $self -> {logger }-> debug2(" '$params {file}' file not found" );
289
+ $self -> {logger }-> debug2(" [libssh2] '$params {file}' file not found" );
290
290
return ;
291
291
} elsif ($error [0] == 3) { # SSH_FX_PERMISSION_DENIED
292
- $self -> {logger }-> debug2(" Not authorized to read '$params {file}'" );
292
+ $self -> {logger }-> debug2(" [libssh2] Not authorized to read '$params {file}'" );
293
293
return ;
294
294
} else {
295
- $self -> {logger }-> debug2(" Unsupported SFTP error (@error )" );
295
+ $self -> {logger }-> debug2(" [libssh2] Unsupported SFTP error (@error )" );
296
296
}
297
297
}
298
298
@@ -317,7 +317,7 @@ sub getRemoteFileHandle {
317
317
my $chan = $self -> {_ssh2 }-> channel();
318
318
if ($chan ) {
319
319
$chan -> ext_data(' ignore' );
320
- $self -> {logger }-> debug2(" Running \" $command \" ..." );
320
+ $self -> {logger }-> debug2(" [libssh2] Running \" $command \" ..." );
321
321
if ($chan -> exec (" LANG=C $command " )) {
322
322
return $chan ;
323
323
}
@@ -326,7 +326,7 @@ sub getRemoteFileHandle {
326
326
327
327
# Don't try ssh command if mode has been set to libssh2 only
328
328
if ($self -> mode(' libssh2' ) && !$self -> mode(' ssh' )) {
329
- $self -> {logger }-> debug(" Failed to run \" $command \" in libssh2 mode only" );
329
+ $self -> {logger }-> debug(" [libssh2] Failed to run \" $command \" in libssh2 mode only" );
330
330
return ;
331
331
}
332
332
@@ -447,24 +447,24 @@ sub remoteTestFile {
447
447
my $sftp = $self -> {_ssh2 }-> sftp();
448
448
if ($sftp ) {
449
449
if ($filetest && $filetest eq " r" ) {
450
- $self -> {logger }-> debug2(" Trying to stat if '$file ' is readable via sftp subsystem" );
450
+ $self -> {logger }-> debug2(" [libssh2] Trying to stat if '$file ' is readable via sftp subsystem" );
451
451
my $fh = $sftp -> open ($file );
452
452
return 0 unless $fh ;
453
453
close ($fh );
454
454
return 1;
455
455
}
456
- $self -> {logger }-> debug2(" Trying to stat '$file ' via sftp subsystem" );
456
+ $self -> {logger }-> debug2(" [libssh2] Trying to stat '$file ' via sftp subsystem" );
457
457
my $stat = $sftp -> stat ($file );
458
458
return 1 if defined ($stat );
459
459
my @error = $sftp -> error;
460
460
if (@error && $error [0]) {
461
461
if ($error [0] == 2) { # SSH_FX_NO_SUCH_FILE
462
462
return 0;
463
463
} elsif ($error [0] == 3) { # SSH_FX_PERMISSION_DENIED
464
- $self -> {logger }-> debug2(" Not authorized to access '$file '" );
464
+ $self -> {logger }-> debug2(" [libssh2] Not authorized to access '$file '" );
465
465
return 0;
466
466
} else {
467
- $self -> {logger }-> debug2(" Unsupported SFTP error (@error )" );
467
+ $self -> {logger }-> debug2(" [libssh2] Unsupported SFTP error (@error )" );
468
468
}
469
469
}
470
470
@@ -514,7 +514,7 @@ sub remoteFileStat {
514
514
$self -> _connect();
515
515
my $sftp = $self -> {_ssh2 }-> sftp();
516
516
if ($sftp ) {
517
- $self -> {logger }-> debug2(" Trying to stat '$file ' via sftp subsystem" );
517
+ $self -> {logger }-> debug2(" [libssh2] Trying to stat '$file ' via sftp subsystem" );
518
518
my $stat = $sftp -> stat ($file );
519
519
if (ref ($stat ) eq ' HASH' ) {
520
520
return (
@@ -537,10 +537,10 @@ sub remoteFileStat {
537
537
if ($error [0] == 2) { # SSH_FX_NO_SUCH_FILE
538
538
return ;
539
539
} elsif ($error [0] == 3) { # SSH_FX_PERMISSION_DENIED
540
- $self -> {logger }-> debug2(" Not authorized to access '$file '" );
540
+ $self -> {logger }-> debug2(" [libssh2] Not authorized to access '$file '" );
541
541
return ;
542
542
} else {
543
- $self -> {logger }-> debug2(" Unsupported SFTP error (@error )" );
543
+ $self -> {logger }-> debug2(" [libssh2] Unsupported SFTP error (@error )" );
544
544
}
545
545
}
546
546
0 commit comments