Files
@ 5f607b56220b
Branch filter:
Location: libtransport.git/msvc-deps/curl/tests/sshhelp.pm
5f607b56220b
11.8 KiB
text/plain
Handle also TextIsngleFormField in Settings command
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | #***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://curl.haxx.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
#***************************************************************************
package sshhelp;
use strict;
use warnings;
use Exporter;
use File::Spec;
#***************************************************************************
# Global symbols allowed without explicit package name
#
use vars qw(
@ISA
@EXPORT_OK
$sshdexe
$sshexe
$sftpsrvexe
$sftpexe
$sshkeygenexe
$httptlssrvexe
$sshdconfig
$sshconfig
$sftpconfig
$knownhosts
$sshdlog
$sshlog
$sftplog
$sftpcmds
$hstprvkeyf
$hstpubkeyf
$cliprvkeyf
$clipubkeyf
@sftppath
@httptlssrvpath
);
#***************************************************************************
# Inherit Exporter's capabilities
#
@ISA = qw(Exporter);
#***************************************************************************
# Global symbols this module will export upon request
#
@EXPORT_OK = qw(
$sshdexe
$sshexe
$sftpsrvexe
$sftpexe
$sshkeygenexe
$sshdconfig
$sshconfig
$sftpconfig
$knownhosts
$sshdlog
$sshlog
$sftplog
$sftpcmds
$hstprvkeyf
$hstpubkeyf
$cliprvkeyf
$clipubkeyf
display_sshdconfig
display_sshconfig
display_sftpconfig
display_sshdlog
display_sshlog
display_sftplog
dump_array
exe_ext
find_sshd
find_ssh
find_sftpsrv
find_sftp
find_sshkeygen
find_httptlssrv
logmsg
sshversioninfo
);
#***************************************************************************
# Global variables initialization
#
$sshdexe = 'sshd' .exe_ext(); # base name and ext of ssh daemon
$sshexe = 'ssh' .exe_ext(); # base name and ext of ssh client
$sftpsrvexe = 'sftp-server' .exe_ext(); # base name and ext of sftp-server
$sftpexe = 'sftp' .exe_ext(); # base name and ext of sftp client
$sshkeygenexe = 'ssh-keygen' .exe_ext(); # base name and ext of ssh-keygen
$httptlssrvexe = 'gnutls-serv' .exe_ext(); # base name and ext of gnutls-serv
$sshdconfig = 'curl_sshd_config'; # ssh daemon config file
$sshconfig = 'curl_ssh_config'; # ssh client config file
$sftpconfig = 'curl_sftp_config'; # sftp client config file
$sshdlog = undef; # ssh daemon log file
$sshlog = undef; # ssh client log file
$sftplog = undef; # sftp client log file
$sftpcmds = 'curl_sftp_cmds'; # sftp client commands batch file
$knownhosts = 'curl_client_knownhosts'; # ssh knownhosts file
$hstprvkeyf = 'curl_host_dsa_key'; # host private key file
$hstpubkeyf = 'curl_host_dsa_key.pub'; # host public key file
$cliprvkeyf = 'curl_client_key'; # client private key file
$clipubkeyf = 'curl_client_key.pub'; # client public key file
#***************************************************************************
# Absolute paths where to look for sftp-server plugin, when not in PATH
#
@sftppath = qw(
/usr/lib/openssh
/usr/libexec/openssh
/usr/libexec
/usr/local/libexec
/opt/local/libexec
/usr/lib/ssh
/usr/libexec/ssh
/usr/sbin
/usr/lib
/usr/lib/ssh/openssh
/usr/lib64/ssh
/usr/lib64/misc
/usr/lib/misc
/usr/local/sbin
/usr/freeware/bin
/usr/freeware/sbin
/usr/freeware/libexec
/opt/ssh/sbin
/opt/ssh/libexec
);
#***************************************************************************
# Absolute paths where to look for httptlssrv (gnutls-serv), when not in PATH
#
@httptlssrvpath = qw(
/usr/sbin
/usr/libexec
/usr/lib
/usr/lib/misc
/usr/lib64/misc
/usr/local/bin
/usr/local/sbin
/usr/local/libexec
/opt/local/bin
/opt/local/sbin
/opt/local/libexec
/usr/freeware/bin
/usr/freeware/sbin
/usr/freeware/libexec
/opt/gnutls/bin
/opt/gnutls/sbin
/opt/gnutls/libexec
);
#***************************************************************************
# Return file extension for executable files on this operating system
#
sub exe_ext {
if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys' ||
$^O eq 'dos' || $^O eq 'os2') {
return '.exe';
}
}
#***************************************************************************
# Create or overwrite the given file with lines from an array of strings
#
sub dump_array {
my ($filename, @arr) = @_;
my $error;
if(!$filename) {
$error = 'Error: Missing argument 1 for dump_array()';
}
elsif(open(TEXTFH, ">$filename")) {
foreach my $line (@arr) {
$line .= "\n" unless($line =~ /\n$/);
print TEXTFH $line;
}
if(!close(TEXTFH)) {
$error = "Error: cannot close file $filename";
}
}
else {
$error = "Error: cannot write file $filename";
}
return $error;
}
#***************************************************************************
# Display a message
#
sub logmsg {
my ($line) = @_;
chomp $line if($line);
$line .= "\n";
print "$line";
}
#***************************************************************************
# Display contents of the given file
#
sub display_file {
my $filename = $_[0];
print "=== Start of file $filename\n";
if(open(DISPLAYFH, "<$filename")) {
while(my $line = <DISPLAYFH>) {
print "$line";
}
close DISPLAYFH;
}
print "=== End of file $filename\n";
}
#***************************************************************************
# Display contents of the ssh daemon config file
#
sub display_sshdconfig {
display_file($sshdconfig);
}
#***************************************************************************
# Display contents of the ssh client config file
#
sub display_sshconfig {
display_file($sshconfig);
}
#***************************************************************************
# Display contents of the sftp client config file
#
sub display_sftpconfig {
display_file($sftpconfig);
}
#***************************************************************************
# Display contents of the ssh daemon log file
#
sub display_sshdlog {
die "error: \$sshdlog uninitialized" if(not defined $sshdlog);
display_file($sshdlog);
}
#***************************************************************************
# Display contents of the ssh client log file
#
sub display_sshlog {
die "error: \$sshlog uninitialized" if(not defined $sshlog);
display_file($sshlog);
}
#***************************************************************************
# Display contents of the sftp client log file
#
sub display_sftplog {
die "error: \$sftplog uninitialized" if(not defined $sftplog);
display_file($sftplog);
}
#***************************************************************************
# Find a file somewhere in the given path
#
sub find_file {
my $fn = $_[0];
shift;
my @path = @_;
foreach (@path) {
my $file = File::Spec->catfile($_, $fn);
if(-e $file && ! -d $file) {
return $file;
}
}
}
#***************************************************************************
# Find an executable file somewhere in the given path
#
sub find_exe_file {
my $fn = $_[0];
shift;
my @path = @_;
my $xext = exe_ext();
foreach (@path) {
my $file = File::Spec->catfile($_, $fn);
if(-e $file && ! -d $file) {
return $file if(-x $file);
return $file if(($xext) && (lc($file) =~ /\Q$xext\E$/));
}
}
}
#***************************************************************************
# Find a file in environment path or in our sftppath
#
sub find_file_spath {
my $filename = $_[0];
my @spath;
push(@spath, File::Spec->path());
push(@spath, @sftppath);
return find_file($filename, @spath);
}
#***************************************************************************
# Find an executable file in environment path or in our httptlssrvpath
#
sub find_exe_file_hpath {
my $filename = $_[0];
my @hpath;
push(@hpath, File::Spec->path());
push(@hpath, @httptlssrvpath);
return find_exe_file($filename, @hpath);
}
#***************************************************************************
# Find ssh daemon and return canonical filename
#
sub find_sshd {
return find_file_spath($sshdexe);
}
#***************************************************************************
# Find ssh client and return canonical filename
#
sub find_ssh {
return find_file_spath($sshexe);
}
#***************************************************************************
# Find sftp-server plugin and return canonical filename
#
sub find_sftpsrv {
return find_file_spath($sftpsrvexe);
}
#***************************************************************************
# Find sftp client and return canonical filename
#
sub find_sftp {
return find_file_spath($sftpexe);
}
#***************************************************************************
# Find ssh-keygen and return canonical filename
#
sub find_sshkeygen {
return find_file_spath($sshkeygenexe);
}
#***************************************************************************
# Find httptlssrv (gnutls-serv) and return canonical filename
#
sub find_httptlssrv {
return find_exe_file_hpath($httptlssrvexe);
}
#***************************************************************************
# Return version info for the given ssh client or server binaries
#
sub sshversioninfo {
my $sshbin = $_[0]; # canonical filename
my $major;
my $minor;
my $patch;
my $sshid;
my $versnum;
my $versstr;
my $error;
if(!$sshbin) {
$error = 'Error: Missing argument 1 for sshversioninfo()';
}
elsif(! -x $sshbin) {
$error = "Error: cannot read or execute $sshbin";
}
else {
my $cmd = ($sshbin =~ /$sshdexe$/) ? "$sshbin -?" : "$sshbin -V";
$error = "$cmd\n";
foreach my $tmpstr (qx($cmd 2>&1)) {
if($tmpstr =~ /OpenSSH[_-](\d+)\.(\d+)(\.(\d+))*/i) {
$major = $1;
$minor = $2;
$patch = $4?$4:0;
$sshid = 'OpenSSH';
$versnum = (100*$major) + (10*$minor) + $patch;
$versstr = "$sshid $major.$minor.$patch";
$error = undef;
last;
}
if($tmpstr =~ /Sun[_-]SSH[_-](\d+)\.(\d+)(\.(\d+))*/i) {
$major = $1;
$minor = $2;
$patch = $4?$4:0;
$sshid = 'SunSSH';
$versnum = (100*$major) + (10*$minor) + $patch;
$versstr = "$sshid $major.$minor.$patch";
$error = undef;
last;
}
$error .= $tmpstr;
}
chomp $error if($error);
}
return ($sshid, $versnum, $versstr, $error);
}
#***************************************************************************
# End of library
1;
|