3 # Start sshd for use in the SCP and SFTP curl test harness tests
13 my $verbose=0; # set to 1 for debugging
15 my $port = 8999; # just our default, weird enough
21 if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys' || $^O eq 'dos' || $^O eq 'os2') {
25 # Where to look for sftp-server
26 my @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);
28 my $username = $ENV{USER};
30 # Find a file somewhere in the given path
32 my $fn = $_[0] . $exeext;
36 my $file = File::Spec->catfile($_, $fn);
45 if($ARGV[0] eq "-v") {
48 elsif($ARGV[0] eq "-u") {
52 elsif($ARGV[0] =~ /^(\d+)$/) {
57 my $conffile="curl_sshd_config"; # sshd configuration data
59 # Search the PATH for sshd. sshd insists on being called with an absolute
60 # path for some reason.
61 my $sshd = searchpath("sshd", File::Spec->path());
63 print "sshd is not available\n";
67 print STDERR "SSH server found at $sshd\n";
70 my $sftp = searchpath("sftp-server", @sftppath);
72 print "Could not find sftp-server plugin\n";
76 print STDERR "SFTP server plugin found at $sftp\n";
79 if (! -e "curl_client_key.pub") {
81 print STDERR "Generating host and client keys...\n";
83 # Make sure all files are gone so ssh-keygen doesn't complain
84 unlink("curl_host_dsa_key", "curl_client_key","curl_host_dsa_key.pub", "curl_client_key.pub");
85 system "ssh-keygen -q -t dsa -f curl_host_dsa_key -C 'curl test server' -N ''" and die "Could not generate key";
86 system "ssh-keygen -q -t dsa -f curl_client_key -C 'curl test client' -N ''" and die "Could not generate key";
89 open(FILE, ">$conffile") || die "Could not write $conffile";
91 # This is a generated file! Do not edit!
92 # OpenSSH sshd configuration file for curl testing
96 AuthorizedKeysFile $path/curl_client_key.pub
97 HostKey $path/curl_host_dsa_key
98 PidFile $path/.ssh.pid
100 ListenAddress localhost
102 AllowTcpForwarding no
104 HostbasedAuthentication no
106 IgnoreUserKnownHosts yes
108 PasswordAuthentication no
109 PermitEmptyPasswords no
117 UsePrivilegeSeparation no
118 # Newer OpenSSH options
121 ChallengeResponseAuthentication no
126 if (system "$sshd -t -q -f $conffile") {
127 # This is likely due to missing support for UsePam
128 print "$sshd is too old and is not supported\n";
134 my $rc = system "$sshd -e -D -f $conffile > log/ssh.log 2>&1";
136 if($rc && $verbose) {
137 print STDERR "$sshd exited with $rc!\n";