summaryrefslogtreecommitdiff
path: root/regress/test-exec.sh
diff options
context:
space:
mode:
Diffstat (limited to 'regress/test-exec.sh')
-rw-r--r--regress/test-exec.sh143
1 files changed, 102 insertions, 41 deletions
diff --git a/regress/test-exec.sh b/regress/test-exec.sh
index aa4e6e5c0..eee446264 100644
--- a/regress/test-exec.sh
+++ b/regress/test-exec.sh
@@ -1,4 +1,4 @@
1# $OpenBSD: test-exec.sh,v 1.37 2010/02/24 06:21:56 djm Exp $ 1# $OpenBSD: test-exec.sh,v 1.46 2013/06/21 02:26:26 djm Exp $
2# Placed in the Public Domain. 2# Placed in the Public Domain.
3 3
4#SUDO=sudo 4#SUDO=sudo
@@ -136,30 +136,49 @@ case "$SSHD" in
136*) SSHD=`which sshd` ;; 136*) SSHD=`which sshd` ;;
137esac 137esac
138 138
139# 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
139if [ "x$TEST_SSH_LOGFILE" = "x" ]; then 143if [ "x$TEST_SSH_LOGFILE" = "x" ]; then
140 TEST_SSH_LOGFILE=/dev/null 144 TEST_SSH_LOGFILE=$OBJ/ssh.log
145fi
146if [ "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
141fi 151fi
142 152
143# Some data for test copies 153# truncate logfiles
144DATA=$OBJ/testdata 154>$TEST_SSH_LOGFILE
145cat $SSHD${EXEEXT} $SSHD${EXEEXT} $SSHD${EXEEXT} $SSHD${EXEEXT} >$DATA 155>$TEST_SSHD_LOGFILE
156>$TEST_REGRESS_LOGFILE
157
158# 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
167# 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.
170DATANAME=data
171DATA=$OBJ/${DATANAME}
172cat $SSHD $SSHD $SSHD $SSHD >${DATA}
173chmod u+w ${DATA}
174COPY=$OBJ/copy
175rm -f ${COPY}
146 176
147# these should be used in tests 177# these should be used in tests
148export SSH SSHD SSHAGENT SSHADD SSHKEYGEN SSHKEYSCAN SFTP SFTPSERVER SCP 178export SSH SSHD SSHAGENT SSHADD SSHKEYGEN SSHKEYSCAN SFTP SFTPSERVER SCP
149#echo $SSH $SSHD $SSHAGENT $SSHADD $SSHKEYGEN $SSHKEYSCAN $SFTP $SFTPSERVER $SCP 179#echo $SSH $SSHD $SSHAGENT $SSHADD $SSHKEYGEN $SSHKEYSCAN $SFTP $SFTPSERVER $SCP
150 180
151# helper 181# Portable specific functions
152echon()
153{
154 if [ "x`echo -n`" = "x" ]; then
155 echo -n "$@"
156 elif [ "x`echo '\c'`" = "x" ]; then
157 echo "$@\c"
158 else
159 fatal "Don't know how to echo without newline."
160 fi
161}
162
163have_prog() 182have_prog()
164{ 183{
165 saved_IFS="$IFS" 184 saved_IFS="$IFS"
@@ -175,6 +194,37 @@ have_prog()
175 return 1 194 return 1
176} 195}
177 196
197jot() {
198 awk "BEGIN { for (i = $2; i < $2 + $1; i++) { printf \"%d\n\", i } exit }"
199}
200
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}
211
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}
225# End of portable specific functions
226
227# helper
178cleanup () 228cleanup ()
179{ 229{
180 if [ -f $PIDFILE ]; then 230 if [ -f $PIDFILE ]; then
@@ -199,9 +249,26 @@ cleanup ()
199 fi 249 fi
200} 250}
201 251
252start_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
202trace () 269trace ()
203{ 270{
204 echo "trace: $@" >>$TEST_SSH_LOGFILE 271 start_debug_log $@
205 if [ "X$TEST_SSH_TRACE" = "Xyes" ]; then 272 if [ "X$TEST_SSH_TRACE" = "Xyes" ]; then
206 echo "$@" 273 echo "$@"
207 fi 274 fi
@@ -209,7 +276,7 @@ trace ()
209 276
210verbose () 277verbose ()
211{ 278{
212 echo "verbose: $@" >>$TEST_SSH_LOGFILE 279 start_debug_log $@
213 if [ "X$TEST_SSH_QUIET" != "Xyes" ]; then 280 if [ "X$TEST_SSH_QUIET" != "Xyes" ]; then
214 echo "$@" 281 echo "$@"
215 fi 282 fi
@@ -223,31 +290,21 @@ warn ()
223 290
224fail () 291fail ()
225{ 292{
226 echo "FAIL: $@" >>$TEST_SSH_LOGFILE 293 save_debug_log "FAIL: $@"
227 RESULT=1 294 RESULT=1
228 echo "$@" 295 echo "$@"
296
229} 297}
230 298
231fatal () 299fatal ()
232{ 300{
233 echo "FATAL: $@" >>$TEST_SSH_LOGFILE 301 save_debug_log "FATAL: $@"
234 echon "FATAL: " 302 printf "FATAL: "
235 fail "$@" 303 fail "$@"
236 cleanup 304 cleanup
237 exit $RESULT 305 exit $RESULT
238} 306}
239 307
240# Check whether preprocessor symbols are defined in config.h.
241config_defined ()
242{
243 str=$1
244 while test "x$2" != "x" ; do
245 str="$str|$2"
246 shift
247 done
248 egrep "^#define.*($str)" ${BUILDDIR}/config.h >/dev/null 2>&1
249}
250
251RESULT=0 308RESULT=0
252PIDFILE=$OBJ/pidfile 309PIDFILE=$OBJ/pidfile
253 310
@@ -263,7 +320,7 @@ cat << EOF > $OBJ/sshd_config
263 #ListenAddress ::1 320 #ListenAddress ::1
264 PidFile $PIDFILE 321 PidFile $PIDFILE
265 AuthorizedKeysFile $OBJ/authorized_keys_%u 322 AuthorizedKeysFile $OBJ/authorized_keys_%u
266 LogLevel VERBOSE 323 LogLevel DEBUG3
267 AcceptEnv _XXX_TEST_* 324 AcceptEnv _XXX_TEST_*
268 AcceptEnv _XXX_TEST 325 AcceptEnv _XXX_TEST
269 Subsystem sftp $SFTPSERVER 326 Subsystem sftp $SFTPSERVER
@@ -295,8 +352,10 @@ Host *
295 ChallengeResponseAuthentication no 352 ChallengeResponseAuthentication no
296 HostbasedAuthentication no 353 HostbasedAuthentication no
297 PasswordAuthentication no 354 PasswordAuthentication no
355 RhostsRSAAuthentication no
298 BatchMode yes 356 BatchMode yes
299 StrictHostKeyChecking yes 357 StrictHostKeyChecking yes
358 LogLevel DEBUG3
300EOF 359EOF
301 360
302if [ ! -z "$TEST_SSH_SSH_CONFOPTS" ]; then 361if [ ! -z "$TEST_SSH_SSH_CONFOPTS" ]; then
@@ -309,13 +368,15 @@ rm -f $OBJ/known_hosts $OBJ/authorized_keys_$USER
309trace "generate keys" 368trace "generate keys"
310for t in rsa rsa1; do 369for t in rsa rsa1; do
311 # generate user key 370 # generate user key
312 rm -f $OBJ/$t 371 if [ ! -f $OBJ/$t ] || [ ${SSHKEYGEN} -nt $OBJ/$t ]; then
313 ${SSHKEYGEN} -b 1024 -q -N '' -t $t -f $OBJ/$t ||\ 372 rm -f $OBJ/$t
314 fail "ssh-keygen for $t failed" 373 ${SSHKEYGEN} -q -N '' -t $t -f $OBJ/$t ||\
374 fail "ssh-keygen for $t failed"
375 fi
315 376
316 # known hosts file for client 377 # known hosts file for client
317 ( 378 (
318 echon 'localhost-with-alias,127.0.0.1,::1 ' 379 printf 'localhost-with-alias,127.0.0.1,::1 '
319 cat $OBJ/$t.pub 380 cat $OBJ/$t.pub
320 ) >> $OBJ/known_hosts 381 ) >> $OBJ/known_hosts
321 382
@@ -370,7 +431,7 @@ if test "$REGRESS_INTEROP_PUTTY" = "yes" ; then
370 echo "Hostname=127.0.0.1" >> ${OBJ}/.putty/sessions/localhost_proxy 431 echo "Hostname=127.0.0.1" >> ${OBJ}/.putty/sessions/localhost_proxy
371 echo "PortNumber=$PORT" >> ${OBJ}/.putty/sessions/localhost_proxy 432 echo "PortNumber=$PORT" >> ${OBJ}/.putty/sessions/localhost_proxy
372 echo "ProxyMethod=5" >> ${OBJ}/.putty/sessions/localhost_proxy 433 echo "ProxyMethod=5" >> ${OBJ}/.putty/sessions/localhost_proxy
373 echo "ProxyTelnetCommand=sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSH_LOGFILE} -i -f $OBJ/sshd_proxy" >> ${OBJ}/.putty/sessions/localhost_proxy 434 echo "ProxyTelnetCommand=sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSHD_LOGFILE} -i -f $OBJ/sshd_proxy" >> ${OBJ}/.putty/sessions/localhost_proxy
374 435
375 REGRESS_INTEROP_PUTTY=yes 436 REGRESS_INTEROP_PUTTY=yes
376fi 437fi
@@ -378,7 +439,7 @@ fi
378# create a proxy version of the client config 439# create a proxy version of the client config
379( 440(
380 cat $OBJ/ssh_config 441 cat $OBJ/ssh_config
381 echo proxycommand ${SUDO} sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSH_LOGFILE} -i -f $OBJ/sshd_proxy 442 echo proxycommand ${SUDO} sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSHD_LOGFILE} -i -f $OBJ/sshd_proxy
382) > $OBJ/ssh_proxy 443) > $OBJ/ssh_proxy
383 444
384# check proxy config 445# check proxy config
@@ -388,7 +449,7 @@ start_sshd ()
388{ 449{
389 # start sshd 450 # start sshd
390 $SUDO ${SSHD} -f $OBJ/sshd_config "$@" -t || fatal "sshd_config broken" 451 $SUDO ${SSHD} -f $OBJ/sshd_config "$@" -t || fatal "sshd_config broken"
391 $SUDO ${SSHD} -f $OBJ/sshd_config -e "$@" >>$TEST_SSH_LOGFILE 2>&1 452 $SUDO ${SSHD} -f $OBJ/sshd_config "$@" -E$TEST_SSHD_LOGFILE
392 453
393 trace "wait for sshd" 454 trace "wait for sshd"
394 i=0; 455 i=0;