1 #***************************************************************************
3 # Project ___| | | | _ \| |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
8 # Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
10 # This software is licensed as described in the file COPYING, which
11 # you should have received as part of this distribution. The terms
12 # are also available at http://curl.haxx.se/docs/copyright.html.
14 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 # copies of the Software, and permit persons to whom the Software is
16 # furnished to do so, under the terms of the COPYING file.
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
21 #***************************************************************************
31 #***************************************************************************
32 # Global symbols allowed without explicit package name
58 #***************************************************************************
59 # Inherit Exporter's capabilities
64 #***************************************************************************
65 # Global symbols this module will export upon request
103 #***************************************************************************
104 # Global variables initialization
106 $sshdexe = 'sshd' .exe_ext(); # base name and ext of ssh daemon
107 $sshexe = 'ssh' .exe_ext(); # base name and ext of ssh client
108 $sftpsrvexe = 'sftp-server' .exe_ext(); # base name and ext of sftp-server
109 $sftpexe = 'sftp' .exe_ext(); # base name and ext of sftp client
110 $sshkeygenexe = 'ssh-keygen' .exe_ext(); # base name and ext of ssh-keygen
111 $sshdconfig = 'curl_sshd_config'; # ssh daemon config file
112 $sshconfig = 'curl_ssh_config'; # ssh client config file
113 $sftpconfig = 'curl_sftp_config'; # sftp client config file
114 $sshdlog = undef; # ssh daemon log file
115 $sshlog = undef; # ssh client log file
116 $sftplog = undef; # sftp client log file
117 $sftpcmds = 'curl_sftp_cmds'; # sftp client commands batch file
118 $knownhosts = 'curl_client_knownhosts'; # ssh knownhosts file
119 $hstprvkeyf = 'curl_host_dsa_key'; # host private key file
120 $hstpubkeyf = 'curl_host_dsa_key.pub'; # host public key file
121 $cliprvkeyf = 'curl_client_key'; # client private key file
122 $clipubkeyf = 'curl_client_key.pub'; # client public key file
125 #***************************************************************************
126 # Absolute paths where to look for sftp-server plugin
145 /usr/freeware/libexec
151 #***************************************************************************
152 # Return file extension for executable files on this operating system
155 if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys' ||
156 $^O eq 'dos' || $^O eq 'os2') {
162 #***************************************************************************
163 # Create or overwrite the given file with lines from an array of strings
166 my ($filename, @arr) = @_;
170 $error = 'Error: Missing argument 1 for dump_array()';
172 elsif(open(TEXTFH, ">$filename")) {
173 foreach my $line (@arr) {
174 $line .= "\n" unless($line =~ /\n$/);
178 $error = "Error: cannot close file $filename";
182 $error = "Error: cannot write file $filename";
188 #***************************************************************************
193 chomp $line if($line);
199 #***************************************************************************
200 # Display contents of the given file
203 my $filename = $_[0];
204 print "=== Start of file $filename\n";
205 if(open(DISPLAYFH, "<$filename")) {
206 while(my $line = <DISPLAYFH>) {
211 print "=== End of file $filename\n";
215 #***************************************************************************
216 # Display contents of the ssh daemon config file
218 sub display_sshdconfig {
219 display_file($sshdconfig);
223 #***************************************************************************
224 # Display contents of the ssh client config file
226 sub display_sshconfig {
227 display_file($sshconfig);
231 #***************************************************************************
232 # Display contents of the sftp client config file
234 sub display_sftpconfig {
235 display_file($sftpconfig);
239 #***************************************************************************
240 # Display contents of the ssh daemon log file
242 sub display_sshdlog {
243 die "error: \$sshdlog uninitialized" if(not defined $sshdlog);
244 display_file($sshdlog);
248 #***************************************************************************
249 # Display contents of the ssh client log file
252 die "error: \$sshlog uninitialized" if(not defined $sshlog);
253 display_file($sshlog);
257 #***************************************************************************
258 # Display contents of the sftp client log file
260 sub display_sftplog {
261 die "error: \$sftplog uninitialized" if(not defined $sftplog);
262 display_file($sftplog);
266 #***************************************************************************
267 # Find a file somewhere in the given path
274 my $file = File::Spec->catfile($_, $fn);
282 #***************************************************************************
283 # Find a file in environment path or in our sftppath
286 my $filename = $_[0];
288 push(@spath, File::Spec->path());
289 push(@spath, @sftppath);
290 return find_file($filename, @spath);
294 #***************************************************************************
295 # Find ssh daemon and return canonical filename
298 return find_sfile($sshdexe);
302 #***************************************************************************
303 # Find ssh client and return canonical filename
306 return find_sfile($sshexe);
310 #***************************************************************************
311 # Find sftp-server plugin and return canonical filename
314 return find_sfile($sftpsrvexe);
318 #***************************************************************************
319 # Find sftp client and return canonical filename
322 return find_sfile($sftpexe);
326 #***************************************************************************
327 # Find ssh-keygen and return canonical filename
330 return find_sfile($sshkeygenexe);
334 #***************************************************************************
335 # Return version info for the given ssh client or server binaries
338 my $sshbin = $_[0]; # canonical filename
348 $error = 'Error: Missing argument 1 for sshversioninfo()';
350 elsif(! -x $sshbin) {
351 $error = "Error: cannot read or execute $sshbin";
354 my $cmd = ($sshbin =~ /$sshdexe$/) ? "$sshbin -?" : "$sshbin -V";
356 foreach my $tmpstr (qx($cmd 2>&1)) {
357 if($tmpstr =~ /OpenSSH[_-](\d+)\.(\d+)(\.(\d+))*/i) {
362 $versnum = (100*$major) + (10*$minor) + $patch;
363 $versstr = "$sshid $major.$minor.$patch";
367 if($tmpstr =~ /Sun[_-]SSH[_-](\d+)\.(\d+)(\.(\d+))*/i) {
372 $versnum = (100*$major) + (10*$minor) + $patch;
373 $versstr = "$sshid $major.$minor.$patch";
379 chomp $error if($error);
381 return ($sshid, $versnum, $versstr, $error);
385 #***************************************************************************