blob: eee44626491e30ff306b799665d6007ed21cf101 [file] [log] [blame]
Damien Millerd1e26cf2013-07-25 12:11:18 +10001# $OpenBSD: test-exec.sh,v 1.46 2013/06/21 02:26:26 djm Exp $
Damien Miller38cd4352002-05-01 13:17:33 +10002# Placed in the Public Domain.
3
Damien Miller38cd4352002-05-01 13:17:33 +10004#SUDO=sudo
5
Darren Tuckerfeb6f7f2005-02-08 20:17:17 +11006# Unbreak GNU head(1)
7_POSIX2_VERSION=199209
8export _POSIX2_VERSION
9
Darren Tucker50c7db92005-03-09 10:02:55 +110010case `uname -s 2>/dev/null` in
11OSF1*)
12 BIN_SH=xpg4
13 export BIN_SH
14 ;;
Darren Tucker6ea5dc62012-07-03 01:11:28 +100015CYGWIN_NT-5.0)
Darren Tuckerec1e15d2012-07-03 01:06:49 +100016 os=cygwin
17 TEST_SSH_IPV6=no
18 ;;
19CYGWIN*)
20 os=cygwin
21 ;;
Darren Tucker50c7db92005-03-09 10:02:55 +110022esac
23
Darren Tucker3b9c0ad2004-06-23 09:28:20 +100024if [ ! -z "$TEST_SSH_PORT" ]; then
25 PORT="$TEST_SSH_PORT"
26else
27 PORT=4242
28fi
29
Darren Tucker6d3921f2003-09-04 15:35:48 +100030if [ -x /usr/ucb/whoami ]; then
31 USER=`/usr/ucb/whoami`
Tim Rice23ee3592003-09-11 22:32:17 -070032elif whoami >/dev/null 2>&1; then
Darren Tucker6d3921f2003-09-04 15:35:48 +100033 USER=`whoami`
Damien Millere682cb02006-02-01 11:21:01 +110034elif logname >/dev/null 2>&1; then
35 USER=`logname`
Darren Tucker6d3921f2003-09-04 15:35:48 +100036else
37 USER=`id -un`
38fi
39
Damien Miller38cd4352002-05-01 13:17:33 +100040OBJ=$1
41if [ "x$OBJ" = "x" ]; then
42 echo '$OBJ not defined'
43 exit 2
44fi
45if [ ! -d $OBJ ]; then
46 echo "not a directory: $OBJ"
47 exit 2
48fi
49SCRIPT=$2
50if [ "x$SCRIPT" = "x" ]; then
51 echo '$SCRIPT not defined'
52 exit 2
53fi
54if [ ! -f $SCRIPT ]; then
55 echo "not a file: $SCRIPT"
56 exit 2
57fi
Tim Rice9ad7e0e2004-02-12 07:17:10 -080058if $TEST_SHELL -n $SCRIPT; then
Damien Miller38cd4352002-05-01 13:17:33 +100059 true
60else
61 echo "syntax error in $SCRIPT"
62 exit 2
63fi
64unset SSH_AUTH_SOCK
65
Darren Tuckera0f3ba72005-03-07 18:33:02 +110066SRC=`dirname ${SCRIPT}`
67
Damien Miller38cd4352002-05-01 13:17:33 +100068# defaults
69SSH=ssh
70SSHD=sshd
71SSHAGENT=ssh-agent
72SSHADD=ssh-add
73SSHKEYGEN=ssh-keygen
74SSHKEYSCAN=ssh-keyscan
75SFTP=sftp
76SFTPSERVER=/usr/libexec/openssh/sftp-server
Darren Tucker50433a92004-06-16 20:15:59 +100077SCP=scp
Damien Miller38cd4352002-05-01 13:17:33 +100078
Damien Milleraf784932008-03-13 00:17:00 +110079# Interop testing
Damien Millera766cea2008-06-30 08:12:37 +100080PLINK=plink
81PUTTYGEN=puttygen
82CONCH=conch
Damien Milleraf784932008-03-13 00:17:00 +110083
Damien Miller38cd4352002-05-01 13:17:33 +100084if [ "x$TEST_SSH_SSH" != "x" ]; then
Darren Tucker03c907a2004-02-29 20:31:08 +110085 SSH="${TEST_SSH_SSH}"
Damien Miller38cd4352002-05-01 13:17:33 +100086fi
87if [ "x$TEST_SSH_SSHD" != "x" ]; then
Darren Tucker03c907a2004-02-29 20:31:08 +110088 SSHD="${TEST_SSH_SSHD}"
Damien Miller38cd4352002-05-01 13:17:33 +100089fi
90if [ "x$TEST_SSH_SSHAGENT" != "x" ]; then
Darren Tucker03c907a2004-02-29 20:31:08 +110091 SSHAGENT="${TEST_SSH_SSHAGENT}"
Damien Miller38cd4352002-05-01 13:17:33 +100092fi
93if [ "x$TEST_SSH_SSHADD" != "x" ]; then
Darren Tucker03c907a2004-02-29 20:31:08 +110094 SSHADD="${TEST_SSH_SSHADD}"
Damien Miller38cd4352002-05-01 13:17:33 +100095fi
96if [ "x$TEST_SSH_SSHKEYGEN" != "x" ]; then
Darren Tucker03c907a2004-02-29 20:31:08 +110097 SSHKEYGEN="${TEST_SSH_SSHKEYGEN}"
Damien Miller38cd4352002-05-01 13:17:33 +100098fi
99if [ "x$TEST_SSH_SSHKEYSCAN" != "x" ]; then
Darren Tucker03c907a2004-02-29 20:31:08 +1100100 SSHKEYSCAN="${TEST_SSH_SSHKEYSCAN}"
Damien Miller38cd4352002-05-01 13:17:33 +1000101fi
102if [ "x$TEST_SSH_SFTP" != "x" ]; then
Darren Tucker03c907a2004-02-29 20:31:08 +1100103 SFTP="${TEST_SSH_SFTP}"
Damien Miller38cd4352002-05-01 13:17:33 +1000104fi
105if [ "x$TEST_SSH_SFTPSERVER" != "x" ]; then
Darren Tucker03c907a2004-02-29 20:31:08 +1100106 SFTPSERVER="${TEST_SSH_SFTPSERVER}"
Damien Miller38cd4352002-05-01 13:17:33 +1000107fi
Darren Tucker50433a92004-06-16 20:15:59 +1000108if [ "x$TEST_SSH_SCP" != "x" ]; then
109 SCP="${TEST_SSH_SCP}"
110fi
Damien Milleraf784932008-03-13 00:17:00 +1100111if [ "x$TEST_SSH_PLINK" != "x" ]; then
Damien Millerc2cefb02008-03-13 12:41:31 +1100112 # Find real binary, if it exists
113 case "${TEST_SSH_PLINK}" in
114 /*) PLINK="${TEST_SSH_PLINK}" ;;
Damien Miller8f8b1562008-03-15 09:25:54 +1100115 *) PLINK=`which ${TEST_SSH_PLINK} 2>/dev/null` ;;
Damien Millerc2cefb02008-03-13 12:41:31 +1100116 esac
Damien Milleraf784932008-03-13 00:17:00 +1100117fi
118if [ "x$TEST_SSH_PUTTYGEN" != "x" ]; then
Damien Millerc2cefb02008-03-13 12:41:31 +1100119 # Find real binary, if it exists
120 case "${TEST_SSH_PUTTYGEN}" in
121 /*) PUTTYGEN="${TEST_SSH_PUTTYGEN}" ;;
Damien Miller8f8b1562008-03-15 09:25:54 +1100122 *) PUTTYGEN=`which ${TEST_SSH_PUTTYGEN} 2>/dev/null` ;;
Damien Millerc2cefb02008-03-13 12:41:31 +1100123 esac
Damien Milleraf784932008-03-13 00:17:00 +1100124fi
Damien Miller4268a132008-06-30 08:07:56 +1000125if [ "x$TEST_SSH_CONCH" != "x" ]; then
Damien Millera766cea2008-06-30 08:12:37 +1000126 # Find real binary, if it exists
127 case "${TEST_SSH_CONCH}" in
128 /*) CONCH="${TEST_SSH_CONCH}" ;;
129 *) CONCH=`which ${TEST_SSH_CONCH} 2>/dev/null` ;;
130 esac
Damien Miller4268a132008-06-30 08:07:56 +1000131fi
Damien Miller38cd4352002-05-01 13:17:33 +1000132
Darren Tucker977a9d22004-06-25 13:45:18 +1000133# Path to sshd must be absolute for rexec
Darren Tucker114572f2005-08-23 23:32:05 +1000134case "$SSHD" in
135/*) ;;
136*) SSHD=`which sshd` ;;
137esac
Darren Tucker977a9d22004-06-25 13:45:18 +1000138
Darren Tucker75129022013-05-17 09:19:10 +1000139# Logfiles.
140# SSH_LOGFILE should be the debug output of ssh(1) only
141# SSHD_LOGFILE should be the debug output of sshd(8) only
142# REGRESS_LOGFILE is the output of the test itself stdout and stderr
Darren Tuckera0f3ba72005-03-07 18:33:02 +1100143if [ "x$TEST_SSH_LOGFILE" = "x" ]; then
Darren Tucker75129022013-05-17 09:19:10 +1000144 TEST_SSH_LOGFILE=$OBJ/ssh.log
Darren Tuckera0f3ba72005-03-07 18:33:02 +1100145fi
Darren Tucker75129022013-05-17 09:19:10 +1000146if [ "x$TEST_SSHD_LOGFILE" = "x" ]; then
147 TEST_SSHD_LOGFILE=$OBJ/sshd.log
148fi
149if [ "x$TEST_REGRESS_LOGFILE" = "x" ]; then
150 TEST_REGRESS_LOGFILE=$OBJ/regress.log
151fi
152
153# truncate logfiles
154>$TEST_SSH_LOGFILE
155>$TEST_SSHD_LOGFILE
156>$TEST_REGRESS_LOGFILE
Darren Tuckera0f3ba72005-03-07 18:33:02 +1100157
Darren Tuckerdfea3bc2013-05-17 09:31:39 +1000158# Create wrapper ssh with logging. We can't just specify "SSH=ssh -E..."
159# because sftp and scp don't handle spaces in arguments.
160SSHLOGWRAP=$OBJ/ssh-log-wrapper.sh
161echo "#!/bin/sh" > $SSHLOGWRAP
162echo "exec ${SSH} -E${TEST_SSH_LOGFILE} "'"$@"' >>$SSHLOGWRAP
163
164chmod a+rx $OBJ/ssh-log-wrapper.sh
165SSH="$SSHLOGWRAP"
166
Darren Tucker59d928d2013-05-17 15:32:29 +1000167# Some test data. We make a copy because some tests will overwrite it.
168# The tests may assume that $DATA exists and is writable and $COPY does
169# not exist.
Damien Millerd1e26cf2013-07-25 12:11:18 +1000170DATANAME=data
171DATA=$OBJ/${DATANAME}
Darren Tucker59d928d2013-05-17 15:32:29 +1000172cat $SSHD $SSHD $SSHD $SSHD >${DATA}
173chmod u+w ${DATA}
174COPY=$OBJ/copy
175rm -f ${COPY}
176
Damien Miller38cd4352002-05-01 13:17:33 +1000177# these should be used in tests
Darren Tucker50433a92004-06-16 20:15:59 +1000178export SSH SSHD SSHAGENT SSHADD SSHKEYGEN SSHKEYSCAN SFTP SFTPSERVER SCP
179#echo $SSH $SSHD $SSHAGENT $SSHADD $SSHKEYGEN $SSHKEYSCAN $SFTP $SFTPSERVER $SCP
Damien Miller38cd4352002-05-01 13:17:33 +1000180
Darren Tucker5f1a89a2013-05-17 19:17:58 +1000181# Portable specific functions
Tim Rice23ee3592003-09-11 22:32:17 -0700182have_prog()
183{
184 saved_IFS="$IFS"
185 IFS=":"
186 for i in $PATH
187 do
188 if [ -x $i/$1 ]; then
189 IFS="$saved_IFS"
190 return 0
191 fi
192 done
193 IFS="$saved_IFS"
194 return 1
195}
196
Darren Tucker5f1a89a2013-05-17 19:17:58 +1000197jot() {
198 awk "BEGIN { for (i = $2; i < $2 + $1; i++) { printf \"%d\n\", i } exit }"
199}
Darren Tucker6f669812013-05-17 19:28:51 +1000200
201# Check whether preprocessor symbols are defined in config.h.
202config_defined ()
203{
204 str=$1
205 while test "x$2" != "x" ; do
206 str="$str|$2"
207 shift
208 done
209 egrep "^#define.*($str)" ${BUILDDIR}/config.h >/dev/null 2>&1
210}
Darren Tuckerf8d5b342013-05-17 19:53:25 +1000211
212md5 () {
213 if have_prog md5sum; then
214 md5sum
215 elif have_prog openssl; then
216 openssl md5
217 elif have_prog cksum; then
218 cksum
219 elif have_prog sum; then
220 sum
221 else
222 wc -c
223 fi
224}
Darren Tucker5f1a89a2013-05-17 19:17:58 +1000225# End of portable specific functions
226
Darren Tucker6f669812013-05-17 19:28:51 +1000227# helper
Damien Miller38cd4352002-05-01 13:17:33 +1000228cleanup ()
229{
230 if [ -f $PIDFILE ]; then
Tim Rice722b8d12010-08-12 09:43:13 -0700231 pid=`$SUDO cat $PIDFILE`
Damien Miller38cd4352002-05-01 13:17:33 +1000232 if [ "X$pid" = "X" ]; then
233 echo no sshd running
234 else
235 if [ $pid -lt 2 ]; then
Damien Millerc1739212010-02-24 17:29:34 +1100236 echo bad pid for ssh: $pid
Damien Miller38cd4352002-05-01 13:17:33 +1000237 else
238 $SUDO kill $pid
Damien Millerc1739212010-02-24 17:29:34 +1100239 trace "wait for sshd to exit"
240 i=0;
241 while [ -f $PIDFILE -a $i -lt 5 ]; do
242 i=`expr $i + 1`
243 sleep $i
244 done
245 test -f $PIDFILE && \
246 fatal "sshd didn't exit port $PORT pid $pid"
Damien Miller38cd4352002-05-01 13:17:33 +1000247 fi
248 fi
249 fi
250}
251
Darren Tuckerdfea3bc2013-05-17 09:31:39 +1000252start_debug_log ()
253{
254 echo "trace: $@" >$TEST_REGRESS_LOGFILE
255 echo "trace: $@" >$TEST_SSH_LOGFILE
256 echo "trace: $@" >$TEST_SSHD_LOGFILE
257}
258
259save_debug_log ()
260{
261 echo $@ >>$TEST_REGRESS_LOGFILE
262 echo $@ >>$TEST_SSH_LOGFILE
263 echo $@ >>$TEST_SSHD_LOGFILE
264 (cat $TEST_REGRESS_LOGFILE; echo) >>$OBJ/failed-regress.log
265 (cat $TEST_SSH_LOGFILE; echo) >>$OBJ/failed-ssh.log
266 (cat $TEST_SSHD_LOGFILE; echo) >>$OBJ/failed-sshd.log
267}
268
Damien Miller38cd4352002-05-01 13:17:33 +1000269trace ()
270{
Darren Tuckerdfea3bc2013-05-17 09:31:39 +1000271 start_debug_log $@
Damien Miller38cd4352002-05-01 13:17:33 +1000272 if [ "X$TEST_SSH_TRACE" = "Xyes" ]; then
Damien Millerda1e4bd2007-10-26 15:35:54 +1000273 echo "$@"
Damien Miller38cd4352002-05-01 13:17:33 +1000274 fi
275}
276
277verbose ()
278{
Darren Tuckerdfea3bc2013-05-17 09:31:39 +1000279 start_debug_log $@
Damien Miller38cd4352002-05-01 13:17:33 +1000280 if [ "X$TEST_SSH_QUIET" != "Xyes" ]; then
Damien Millerda1e4bd2007-10-26 15:35:54 +1000281 echo "$@"
Damien Miller38cd4352002-05-01 13:17:33 +1000282 fi
283}
284
Damien Miller6efd94f2011-09-04 19:04:16 +1000285warn ()
286{
287 echo "WARNING: $@" >>$TEST_SSH_LOGFILE
288 echo "WARNING: $@"
289}
Damien Miller38cd4352002-05-01 13:17:33 +1000290
291fail ()
292{
Darren Tuckerdfea3bc2013-05-17 09:31:39 +1000293 save_debug_log "FAIL: $@"
Damien Miller38cd4352002-05-01 13:17:33 +1000294 RESULT=1
Damien Millerda1e4bd2007-10-26 15:35:54 +1000295 echo "$@"
Darren Tuckerdfea3bc2013-05-17 09:31:39 +1000296
Damien Miller38cd4352002-05-01 13:17:33 +1000297}
298
299fatal ()
300{
Darren Tuckerdfea3bc2013-05-17 09:31:39 +1000301 save_debug_log "FATAL: $@"
Darren Tucker56347ef2013-05-17 13:28:36 +1000302 printf "FATAL: "
Damien Miller38cd4352002-05-01 13:17:33 +1000303 fail "$@"
304 cleanup
305 exit $RESULT
306}
307
308RESULT=0
309PIDFILE=$OBJ/pidfile
310
311trap fatal 3 2
312
313# create server config
314cat << EOF > $OBJ/sshd_config
Darren Tucker0e6868e2004-06-16 20:36:16 +1000315 StrictModes no
Damien Miller38cd4352002-05-01 13:17:33 +1000316 Port $PORT
Darren Tuckere23a79c2009-10-12 09:37:22 +1100317 Protocol 2,1
Damien Miller76be6b82006-01-31 21:59:01 +1100318 AddressFamily inet
Damien Miller38cd4352002-05-01 13:17:33 +1000319 ListenAddress 127.0.0.1
320 #ListenAddress ::1
321 PidFile $PIDFILE
322 AuthorizedKeysFile $OBJ/authorized_keys_%u
Darren Tuckerdfea3bc2013-05-17 09:31:39 +1000323 LogLevel DEBUG3
Darren Tucker4c37ef02004-06-16 20:08:56 +1000324 AcceptEnv _XXX_TEST_*
325 AcceptEnv _XXX_TEST
Darren Tuckere7d05832004-06-16 20:22:22 +1000326 Subsystem sftp $SFTPSERVER
Damien Miller38cd4352002-05-01 13:17:33 +1000327EOF
328
Darren Tucker6223eea2004-06-23 09:25:02 +1000329if [ ! -z "$TEST_SSH_SSHD_CONFOPTS" ]; then
330 trace "adding sshd_config option $TEST_SSH_SSHD_CONFOPTS"
331 echo "$TEST_SSH_SSHD_CONFOPTS" >> $OBJ/sshd_config
332fi
333
Damien Miller38cd4352002-05-01 13:17:33 +1000334# server config for proxy connects
335cp $OBJ/sshd_config $OBJ/sshd_proxy
336
337# allow group-writable directories in proxy-mode
338echo 'StrictModes no' >> $OBJ/sshd_proxy
339
340# create client config
341cat << EOF > $OBJ/ssh_config
342Host *
Darren Tuckere23a79c2009-10-12 09:37:22 +1100343 Protocol 2,1
Damien Miller38cd4352002-05-01 13:17:33 +1000344 Hostname 127.0.0.1
345 HostKeyAlias localhost-with-alias
346 Port $PORT
347 User $USER
348 GlobalKnownHostsFile $OBJ/known_hosts
349 UserKnownHostsFile $OBJ/known_hosts
350 RSAAuthentication yes
351 PubkeyAuthentication yes
352 ChallengeResponseAuthentication no
353 HostbasedAuthentication no
354 PasswordAuthentication no
Darren Tucker6f669812013-05-17 19:28:51 +1000355 RhostsRSAAuthentication no
Damien Miller38cd4352002-05-01 13:17:33 +1000356 BatchMode yes
357 StrictHostKeyChecking yes
Darren Tuckerdfea3bc2013-05-17 09:31:39 +1000358 LogLevel DEBUG3
Damien Miller38cd4352002-05-01 13:17:33 +1000359EOF
360
Darren Tucker6223eea2004-06-23 09:25:02 +1000361if [ ! -z "$TEST_SSH_SSH_CONFOPTS" ]; then
362 trace "adding ssh_config option $TEST_SSH_SSHD_CONFOPTS"
363 echo "$TEST_SSH_SSH_CONFOPTS" >> $OBJ/ssh_config
364fi
365
Damien Miller38cd4352002-05-01 13:17:33 +1000366rm -f $OBJ/known_hosts $OBJ/authorized_keys_$USER
367
368trace "generate keys"
369for t in rsa rsa1; do
370 # generate user key
Darren Tuckeracd20602013-08-08 17:02:12 +1000371 if [ ! -f $OBJ/$t ] || [ ${SSHKEYGEN} -nt $OBJ/$t ]; then
Darren Tucker7c8b1e72013-05-17 09:10:20 +1000372 rm -f $OBJ/$t
373 ${SSHKEYGEN} -q -N '' -t $t -f $OBJ/$t ||\
374 fail "ssh-keygen for $t failed"
375 fi
Damien Miller38cd4352002-05-01 13:17:33 +1000376
377 # known hosts file for client
378 (
Darren Tucker56347ef2013-05-17 13:28:36 +1000379 printf 'localhost-with-alias,127.0.0.1,::1 '
Damien Miller38cd4352002-05-01 13:17:33 +1000380 cat $OBJ/$t.pub
381 ) >> $OBJ/known_hosts
382
383 # setup authorized keys
384 cat $OBJ/$t.pub >> $OBJ/authorized_keys_$USER
385 echo IdentityFile $OBJ/$t >> $OBJ/ssh_config
386
387 # use key as host key, too
388 $SUDO cp $OBJ/$t $OBJ/host.$t
389 echo HostKey $OBJ/host.$t >> $OBJ/sshd_config
390
391 # don't use SUDO for proxy connect
392 echo HostKey $OBJ/$t >> $OBJ/sshd_proxy
393done
394chmod 644 $OBJ/authorized_keys_$USER
395
Damien Miller4268a132008-06-30 08:07:56 +1000396# Activate Twisted Conch tests if the binary is present
397REGRESS_INTEROP_CONCH=no
398if test -x "$CONCH" ; then
399 REGRESS_INTEROP_CONCH=yes
400fi
401
Darren Tuckerd788b7c2008-06-10 23:15:54 +1000402# If PuTTY is present and we are running a PuTTY test, prepare keys and
403# configuration
Damien Milleraf784932008-03-13 00:17:00 +1100404REGRESS_INTEROP_PUTTY=no
Darren Tuckerd8bafea2008-06-11 01:39:38 +1000405if test -x "$PUTTYGEN" -a -x "$PLINK" ; then
Darren Tucker5f346642008-06-11 01:38:52 +1000406 REGRESS_INTEROP_PUTTY=yes
407fi
408case "$SCRIPT" in
409*putty*) ;;
410*) REGRESS_INTEROP_PUTTY=no ;;
411esac
412
413if test "$REGRESS_INTEROP_PUTTY" = "yes" ; then
Damien Milleraf784932008-03-13 00:17:00 +1100414 mkdir -p ${OBJ}/.putty
415
416 # Add a PuTTY key to authorized_keys
417 rm -f ${OBJ}/putty.rsa2
418 puttygen -t rsa -o ${OBJ}/putty.rsa2 < /dev/null > /dev/null
419 puttygen -O public-openssh ${OBJ}/putty.rsa2 \
420 >> $OBJ/authorized_keys_$USER
421
422 # Convert rsa2 host key to PuTTY format
423 ${SRC}/ssh2putty.sh 127.0.0.1 $PORT $OBJ/rsa > \
424 ${OBJ}/.putty/sshhostkeys
425 ${SRC}/ssh2putty.sh 127.0.0.1 22 $OBJ/rsa >> \
426 ${OBJ}/.putty/sshhostkeys
427
428 # Setup proxied session
429 mkdir -p ${OBJ}/.putty/sessions
430 rm -f ${OBJ}/.putty/sessions/localhost_proxy
431 echo "Hostname=127.0.0.1" >> ${OBJ}/.putty/sessions/localhost_proxy
432 echo "PortNumber=$PORT" >> ${OBJ}/.putty/sessions/localhost_proxy
433 echo "ProxyMethod=5" >> ${OBJ}/.putty/sessions/localhost_proxy
Darren Tucker75129022013-05-17 09:19:10 +1000434 echo "ProxyTelnetCommand=sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSHD_LOGFILE} -i -f $OBJ/sshd_proxy" >> ${OBJ}/.putty/sessions/localhost_proxy
Damien Milleraf784932008-03-13 00:17:00 +1100435
436 REGRESS_INTEROP_PUTTY=yes
437fi
438
Damien Miller38cd4352002-05-01 13:17:33 +1000439# create a proxy version of the client config
440(
441 cat $OBJ/ssh_config
Darren Tucker75129022013-05-17 09:19:10 +1000442 echo proxycommand ${SUDO} sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSHD_LOGFILE} -i -f $OBJ/sshd_proxy
Damien Miller38cd4352002-05-01 13:17:33 +1000443) > $OBJ/ssh_proxy
444
445# check proxy config
446${SSHD} -t -f $OBJ/sshd_proxy || fatal "sshd_proxy broken"
447
448start_sshd ()
449{
450 # start sshd
Damien Milleraf784932008-03-13 00:17:00 +1100451 $SUDO ${SSHD} -f $OBJ/sshd_config "$@" -t || fatal "sshd_config broken"
Darren Tuckerdfea3bc2013-05-17 09:31:39 +1000452 $SUDO ${SSHD} -f $OBJ/sshd_config "$@" -E$TEST_SSHD_LOGFILE
Damien Miller38cd4352002-05-01 13:17:33 +1000453
454 trace "wait for sshd"
455 i=0;
Darren Tucker6d3921f2003-09-04 15:35:48 +1000456 while [ ! -f $PIDFILE -a $i -lt 10 ]; do
Damien Miller38cd4352002-05-01 13:17:33 +1000457 i=`expr $i + 1`
458 sleep $i
459 done
460
461 test -f $PIDFILE || fatal "no sshd running on port $PORT"
462}
463
Damien Miller38cd4352002-05-01 13:17:33 +1000464# source test body
465. $SCRIPT
466
467# kill sshd
468cleanup
469if [ $RESULT -eq 0 ]; then
470 verbose ok $tid
471else
472 echo failed $tid
473fi
474exit $RESULT