tizen 2.3.1 release
[external/curl.git] / tests / sshserver.pl
index b439015..d8c2d6f 100755 (executable)
@@ -6,7 +6,7 @@
 #                            | (__| |_| |  _ <| |___
 #                             \___|\___/|_| \_\_____|
 #
-# Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+# Copyright (C) 1998 - 2014, 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
@@ -27,6 +27,7 @@
 use strict;
 use warnings;
 use Cwd;
+use Cwd 'abs_path';
 
 #***************************************************************************
 # Variables and subs imported from sshhelp module
@@ -88,6 +89,7 @@ my $path = getcwd();          # current working directory
 my $logdir = $path .'/log';   # directory for log files
 my $username = $ENV{USER};    # default user
 my $pidfile;                  # ssh daemon pid file
+my $identity = 'curl_client_key'; # default identity file
 
 my $error;
 my @cfgarr;
@@ -362,17 +364,19 @@ if((($sshid =~ /OpenSSH/) && ($sshvernum < 299)) ||
 #***************************************************************************
 # Generate host and client key files for curl's tests
 #
-if((! -e $hstprvkeyf) || (! -e $hstpubkeyf) ||
-   (! -e $cliprvkeyf) || (! -e $clipubkeyf)) {
+if((! -e $hstprvkeyf) || (! -s $hstprvkeyf) ||
+   (! -e $hstpubkeyf) || (! -s $hstpubkeyf) ||
+   (! -e $cliprvkeyf) || (! -s $cliprvkeyf) ||
+   (! -e $clipubkeyf) || (! -s $clipubkeyf)) {
     # Make sure all files are gone so ssh-keygen doesn't complain
     unlink($hstprvkeyf, $hstpubkeyf, $cliprvkeyf, $clipubkeyf);
     logmsg 'generating host keys...' if($verbose);
-    if(system "$sshkeygen -q -t dsa -f $hstprvkeyf -C 'curl test server' -N ''") {
+    if(system "\"$sshkeygen\" -q -t dsa -f $hstprvkeyf -C 'curl test server' -N ''") {
         logmsg 'Could not generate host key';
         exit 1;
     }
     logmsg 'generating client keys...' if($verbose);
-    if(system "$sshkeygen -q -t dsa -f $cliprvkeyf -C 'curl test client' -N ''") {
+    if(system "\"$sshkeygen\" -q -t dsa -f $cliprvkeyf -C 'curl test client' -N ''") {
         logmsg 'Could not generate client key';
         exit 1;
     }
@@ -380,6 +384,22 @@ if((! -e $hstprvkeyf) || (! -e $hstpubkeyf) ||
 
 
 #***************************************************************************
+# Convert paths for curl's tests running on Windows using Cygwin OpenSSH
+#
+my $clipubkeyf_config = abs_path("$path/$clipubkeyf");
+my $hstprvkeyf_config = abs_path("$path/$hstprvkeyf");
+my $pidfile_config = $pidfile;
+my $sftpsrv_config = $sftpsrv;
+
+if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') {
+    # convert MinGW drive paths to Cygwin drive paths
+    $clipubkeyf_config =~ s/^\/(\w)\//\/cygdrive\/$1\//;
+    $hstprvkeyf_config =~ s/^\/(\w)\//\/cygdrive\/$1\//;
+    $pidfile_config =~ s/^\/(\w)\//\/cygdrive\/$1\//;
+    $sftpsrv_config = "internal-sftp";
+}
+
+#***************************************************************************
 #  ssh daemon configuration file options we might use and version support
 #
 #  AFSTokenPassing                  : OpenSSH 1.2.1 and later [1]
@@ -477,10 +497,10 @@ push @cfgarr, "AllowUsers $username";
 push @cfgarr, 'DenyGroups';
 push @cfgarr, 'AllowGroups';
 push @cfgarr, '#';
-push @cfgarr, "AuthorizedKeysFile $path/$clipubkeyf";
-push @cfgarr, "AuthorizedKeysFile2 $path/$clipubkeyf";
-push @cfgarr, "HostKey $path/$hstprvkeyf";
-push @cfgarr, "PidFile $pidfile";
+push @cfgarr, "AuthorizedKeysFile $clipubkeyf_config";
+push @cfgarr, "AuthorizedKeysFile2 $clipubkeyf_config";
+push @cfgarr, "HostKey $hstprvkeyf_config";
+push @cfgarr, "PidFile $pidfile_config";
 push @cfgarr, '#';
 push @cfgarr, "Port $port";
 push @cfgarr, "ListenAddress $listenaddr";
@@ -510,7 +530,7 @@ push @cfgarr, 'RhostsRSAAuthentication no';
 push @cfgarr, 'RSAAuthentication no';
 push @cfgarr, 'ServerKeyBits 768';
 push @cfgarr, 'StrictModes no';
-push @cfgarr, "Subsystem sftp $sftpsrv";
+push @cfgarr, "Subsystem sftp \"$sftpsrv_config\"";
 push @cfgarr, 'SyslogFacility AUTH';
 push @cfgarr, 'UseLogin no';
 push @cfgarr, 'X11Forwarding no';
@@ -538,7 +558,7 @@ sub sshd_supports_opt {
         ($sshdid =~ /SunSSH/)) {
         # ssh daemon supports command line options -t -f and -o
         $err = grep /((Unsupported)|(Bad configuration)|(Deprecated)) option.*$option/,
-                    qx($sshd -t -f $sshdconfig -o $option=$value 2>&1);
+                    qx("$sshd" -t -f $sshdconfig -o $option=$value 2>&1);
         return !$err;
     }
     if(($sshdid =~ /OpenSSH/) && ($sshdvernum >= 299)) {
@@ -549,7 +569,7 @@ sub sshd_supports_opt {
             return 0;
         }
         $err = grep /((Unsupported)|(Bad configuration)|(Deprecated)) option.*$option/,
-                    qx($sshd -t -f $sshdconfig 2>&1);
+                    qx("$sshd" -t -f $sshdconfig 2>&1);
         unlink $sshdconfig;
         return !$err;
     }
@@ -695,7 +715,7 @@ if($error) {
 #***************************************************************************
 # Verify that sshd actually supports our generated configuration file
 #
-if(system "$sshd -t -f $sshdconfig > $sshdlog 2>&1") {
+if(system "\"$sshd\" -t -f $sshdconfig > $sshdlog 2>&1") {
     logmsg "sshd configuration file $sshdconfig failed verification";
     display_sshdlog();
     display_sshdconfig();
@@ -706,8 +726,9 @@ if(system "$sshd -t -f $sshdconfig > $sshdlog 2>&1") {
 #***************************************************************************
 # Generate ssh client host key database file for curl's tests
 #
-if(! -e $knownhosts) {
+if((! -e $knownhosts) || (! -s $knownhosts)) {
     logmsg 'generating ssh client known hosts file...' if($verbose);
+    unlink($knownhosts);
     if(open(DSAKEYFILE, "<$hstpubkeyf")) {
         my @dsahostkey = do { local $/ = ' '; <DSAKEYFILE> };
         if(close(DSAKEYFILE)) {
@@ -736,6 +757,19 @@ if(! -e $knownhosts) {
 
 
 #***************************************************************************
+# Convert paths for curl's tests running on Windows using Cygwin OpenSSH
+#
+my $identity_config = abs_path("$path/$identity");
+my $knownhosts_config = abs_path("$path/$knownhosts");
+
+if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') {
+    # convert MinGW drive paths to Cygwin drive paths
+    $identity_config =~ s/^\/(\w)\//\/cygdrive\/$1\//;
+    $knownhosts_config =~ s/^\/(\w)\//\/cygdrive\/$1\//;
+}
+
+
+#***************************************************************************
 #  ssh client configuration file options we might use and version support
 #
 #  AddressFamily                     : OpenSSH 3.7.0 and later
@@ -831,8 +865,8 @@ push @cfgarr, '#';
 push @cfgarr, "BindAddress $listenaddr";
 push @cfgarr, "DynamicForward $socksport";
 push @cfgarr, '#';
-push @cfgarr, "IdentityFile $path/curl_client_key";
-push @cfgarr, "UserKnownHostsFile $path/$knownhosts";
+push @cfgarr, "IdentityFile $identity_config";
+push @cfgarr, "UserKnownHostsFile $knownhosts_config";
 push @cfgarr, '#';
 push @cfgarr, 'BatchMode yes';
 push @cfgarr, 'ChallengeResponseAuthentication no';
@@ -853,7 +887,10 @@ push @cfgarr, 'PreferredAuthentications publickey';
 push @cfgarr, 'PubkeyAuthentication yes';
 push @cfgarr, 'RhostsRSAAuthentication no';
 push @cfgarr, 'RSAAuthentication no';
-push @cfgarr, 'StrictHostKeyChecking yes';
+
+# Disabled StrictHostKeyChecking since it makes the tests fail on my
+# OpenSSH_6.0p1 on Debian Linux / Daniel
+push @cfgarr, 'StrictHostKeyChecking no';
 push @cfgarr, 'UsePrivilegedPort no';
 push @cfgarr, '#';
 
@@ -1019,16 +1056,16 @@ if($error) {
 # Start the ssh server daemon without forking it
 #
 logmsg "SCP/SFTP server listening on port $port" if($verbose);
-my $rc = system "$sshd -e -D -f $sshdconfig > $sshdlog 2>&1";
+my $rc = system "\"$sshd\" -e -D -f $sshdconfig > $sshdlog 2>&1";
 if($rc == -1) {
-    logmsg "$sshd failed with: $!";
+    logmsg "\"$sshd\" failed with: $!";
 }
 elsif($rc & 127) {
-    logmsg sprintf("$sshd died with signal %d, and %s coredump",
+    logmsg sprintf("\"$sshd\" died with signal %d, and %s coredump",
                    ($rc & 127), ($rc & 128)?'a':'no');
 }
 elsif($verbose && ($rc >> 8)) {
-    logmsg sprintf("$sshd exited with %d", $rc >> 8);
+    logmsg sprintf("\"$sshd\" exited with %d", $rc >> 8);
 }