1 #***************************************************************************
3 # Project ___| | | | _ \| |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
8 # Copyright (C) 1998 - 2008, 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 # $Id: sshhelp.pm,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
22 #***************************************************************************
32 #***************************************************************************
33 # Global symbols allowed without explicit package name
59 #***************************************************************************
60 # Inherit Exporter's capabilities
65 #***************************************************************************
66 # 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 = 'log/sshd.log'; # ssh daemon log file
115 $sshlog = 'log/ssh.log'; # ssh client log file
116 $sftplog = 'log/sftp.log'; # 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 display_file
($sshdlog);
247 #***************************************************************************
248 # Display contents of the ssh client log file
251 display_file
($sshlog);
255 #***************************************************************************
256 # Display contents of the sftp client log file
258 sub display_sftplog
{
259 display_file
($sftplog);
263 #***************************************************************************
264 # Find a file somewhere in the given path
271 my $file = File
::Spec
->catfile($_, $fn);
279 #***************************************************************************
280 # Find a file in environment path or in our sftppath
283 my $filename = $_[0];
285 push(@spath, File
::Spec
->path());
286 push(@spath, @sftppath);
287 return find_file
($filename, @spath);
291 #***************************************************************************
292 # Find ssh daemon and return canonical filename
295 return find_sfile
($sshdexe);
299 #***************************************************************************
300 # Find ssh client and return canonical filename
303 return find_sfile
($sshexe);
307 #***************************************************************************
308 # Find sftp-server plugin and return canonical filename
311 return find_sfile
($sftpsrvexe);
315 #***************************************************************************
316 # Find sftp client and return canonical filename
319 return find_sfile
($sftpexe);
323 #***************************************************************************
324 # Find ssh-keygen and return canonical filename
327 return find_sfile
($sshkeygenexe);
331 #***************************************************************************
332 # Return version info for the given ssh client or server binaries
335 my $sshbin = $_[0]; # canonical filename
345 $error = 'Error: Missing argument 1 for sshversioninfo()';
347 elsif(! -x
$sshbin) {
348 $error = "Error: cannot read or execute $sshbin";
351 my $cmd = ($sshbin =~ /$sshdexe$/) ?
"$sshbin -?" : "$sshbin -V";
353 foreach my $tmpstr (qx($cmd 2>&1)) {
354 if($tmpstr =~ /OpenSSH[_-](\d+)\.(\d+)(\.(\d+))*/i) {
359 $versnum = (100*$major) + (10*$minor) + $patch;
360 $versstr = "$sshid $major.$minor.$patch";
364 if($tmpstr =~ /Sun[_-]SSH[_-](\d+)\.(\d+)(\.(\d+))*/i) {
369 $versnum = (100*$major) + (10*$minor) + $patch;
370 $versstr = "$sshid $major.$minor.$patch";
376 chomp $error if($error);
378 return ($sshid, $versnum, $versstr, $error);
382 #***************************************************************************