Revert "Update to 7.40.1"
[platform/upstream/curl.git] / tests / sshhelp.pm
index b36adb7..ced9a01 100644 (file)
@@ -5,7 +5,7 @@
 #                            | (__| |_| |  _ <| |___
 #                             \___|\___/|_| \_\_____|
 #
-# Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
+# 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
 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 # KIND, either express or implied.
 #
-# $Id: 
 #***************************************************************************
 
 package sshhelp;
 
 use strict;
-#use warnings;
+use warnings;
 use Exporter;
 use File::Spec;
 
@@ -37,18 +36,24 @@ use vars qw(
     @EXPORT_OK
     $sshdexe
     $sshexe
+    $sftpsrvexe
     $sftpexe
     $sshkeygenexe
+    $httptlssrvexe
     $sshdconfig
     $sshconfig
+    $sftpconfig
     $knownhosts
     $sshdlog
     $sshlog
+    $sftplog
+    $sftpcmds
     $hstprvkeyf
     $hstpubkeyf
     $cliprvkeyf
     $clipubkeyf
     @sftppath
+    @httptlssrvpath
     );
 
 
@@ -64,26 +69,35 @@ use vars qw(
 @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
     );
@@ -92,23 +106,28 @@ use vars qw(
 #***************************************************************************
 # 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
-$sftpexe      = 'sftp-server' .exe_ext(); # base name and ext of sftp-server
-$sshkeygenexe = 'ssh-keygen'  .exe_ext(); # base name and ext of ssh-keygen
-$sshdconfig   = 'curl_sshd_config';       # ssh daemon config file
-$sshconfig    = 'curl_ssh_config';        # ssh client config file
-$sshdlog      = 'log/sshd.log';           # ssh daemon log file
-$sshlog       = 'log/ssh.log';            # ssh client log 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
+$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
+# Absolute paths where to look for sftp-server plugin, when not in PATH
 #
 @sftppath = qw(
     /usr/lib/openssh
@@ -134,6 +153,30 @@ $clipubkeyf   = 'curl_client_key.pub';    # client public key file
 
 
 #***************************************************************************
+# 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 {
@@ -214,9 +257,18 @@ sub display_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);
 }
 
@@ -225,11 +277,21 @@ sub display_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 {
@@ -238,7 +300,7 @@ sub find_file {
     my @path = @_;
     foreach (@path) {
         my $file = File::Spec->catfile($_, $fn);
-        if(-e $file) {
+        if(-e $file && ! -d $file) {
             return $file;
         }
     }
@@ -246,9 +308,27 @@ sub find_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_sfile {
+sub find_file_spath {
     my $filename = $_[0];
     my @spath;
     push(@spath, File::Spec->path());
@@ -258,10 +338,22 @@ sub find_sfile {
 
 
 #***************************************************************************
+# 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_sfile($sshdexe);
+    return find_file_spath($sshdexe);
 }
 
 
@@ -269,15 +361,23 @@ sub find_sshd {
 # Find ssh client and return canonical filename
 #
 sub find_ssh {
-    return find_sfile($sshexe);
+    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_sfile($sftpexe);
+    return find_file_spath($sftpexe);
 }
 
 
@@ -285,7 +385,15 @@ sub find_sftp {
 # Find ssh-keygen and return canonical filename
 #
 sub find_sshkeygen {
-    return find_sfile($sshkeygenexe);
+    return find_file_spath($sshkeygenexe);
+}
+
+
+#***************************************************************************
+# Find httptlssrv (gnutls-serv) and return canonical filename
+#
+sub find_httptlssrv {
+    return find_exe_file_hpath($httptlssrvexe);
 }