1 # $OpenBSD: test-exec.sh,v 1.37 2010/02/24 06:21:56 djm Exp $
2 # Placed in the Public Domain.
10 case `uname -s 2>/dev/null` in
17 if [ ! -z "$TEST_SSH_PORT" ]; then
23 if [ -x /usr
/ucb
/whoami
]; then
24 USER
=`/usr/ucb/whoami`
25 elif whoami
>/dev
/null
2>&1; then
27 elif logname
>/dev
/null
2>&1; then
34 if [ "x$OBJ" = "x" ]; then
35 echo '$OBJ not defined'
38 if [ ! -d $OBJ ]; then
39 echo "not a directory: $OBJ"
43 if [ "x$SCRIPT" = "x" ]; then
44 echo '$SCRIPT not defined'
47 if [ ! -f $SCRIPT ]; then
48 echo "not a file: $SCRIPT"
51 if $TEST_SHELL -n $SCRIPT; then
54 echo "syntax error in $SCRIPT"
59 SRC
=`dirname ${SCRIPT}`
67 SSHKEYSCAN
=ssh-keyscan
69 SFTPSERVER
=/usr
/libexec
/openssh
/sftp-server
77 if [ "x$TEST_SSH_SSH" != "x" ]; then
80 if [ "x$TEST_SSH_SSHD" != "x" ]; then
81 SSHD
="${TEST_SSH_SSHD}"
83 if [ "x$TEST_SSH_SSHAGENT" != "x" ]; then
84 SSHAGENT
="${TEST_SSH_SSHAGENT}"
86 if [ "x$TEST_SSH_SSHADD" != "x" ]; then
87 SSHADD
="${TEST_SSH_SSHADD}"
89 if [ "x$TEST_SSH_SSHKEYGEN" != "x" ]; then
90 SSHKEYGEN
="${TEST_SSH_SSHKEYGEN}"
92 if [ "x$TEST_SSH_SSHKEYSCAN" != "x" ]; then
93 SSHKEYSCAN
="${TEST_SSH_SSHKEYSCAN}"
95 if [ "x$TEST_SSH_SFTP" != "x" ]; then
96 SFTP
="${TEST_SSH_SFTP}"
98 if [ "x$TEST_SSH_SFTPSERVER" != "x" ]; then
99 SFTPSERVER
="${TEST_SSH_SFTPSERVER}"
101 if [ "x$TEST_SSH_SCP" != "x" ]; then
102 SCP
="${TEST_SSH_SCP}"
104 if [ "x$TEST_SSH_PLINK" != "x" ]; then
105 # Find real binary, if it exists
106 case "${TEST_SSH_PLINK}" in
107 /*) PLINK
="${TEST_SSH_PLINK}" ;;
108 *) PLINK
=`which ${TEST_SSH_PLINK} 2>/dev/null` ;;
111 if [ "x$TEST_SSH_PUTTYGEN" != "x" ]; then
112 # Find real binary, if it exists
113 case "${TEST_SSH_PUTTYGEN}" in
114 /*) PUTTYGEN
="${TEST_SSH_PUTTYGEN}" ;;
115 *) PUTTYGEN
=`which ${TEST_SSH_PUTTYGEN} 2>/dev/null` ;;
118 if [ "x$TEST_SSH_CONCH" != "x" ]; then
119 # Find real binary, if it exists
120 case "${TEST_SSH_CONCH}" in
121 /*) CONCH
="${TEST_SSH_CONCH}" ;;
122 *) CONCH
=`which ${TEST_SSH_CONCH} 2>/dev/null` ;;
126 # Path to sshd must be absolute for rexec
129 *) SSHD
=`which sshd` ;;
132 if [ "x$TEST_SSH_LOGFILE" = "x" ]; then
133 TEST_SSH_LOGFILE
=/dev
/null
136 # these should be used in tests
137 export SSH SSHD SSHAGENT SSHADD SSHKEYGEN SSHKEYSCAN SFTP SFTPSERVER SCP
138 #echo $SSH $SSHD $SSHAGENT $SSHADD $SSHKEYGEN $SSHKEYSCAN $SFTP $SFTPSERVER $SCP
143 if [ "x`echo -n`" = "x" ]; then
145 elif [ "x`echo '\c'`" = "x" ]; then
148 fatal
"Don't know how to echo without newline."
158 if [ -x $i/$1 ]; then
169 if [ -f $PIDFILE ]; then
170 pid
=`$SUDO cat $PIDFILE`
171 if [ "X$pid" = "X" ]; then
174 if [ $pid -lt 2 ]; then
175 echo bad pid
for ssh: $pid
178 trace
"wait for sshd to exit"
180 while [ -f $PIDFILE -a $i -lt 5 ]; do
184 test -f $PIDFILE && \
185 fatal
"sshd didn't exit port $PORT pid $pid"
193 echo "trace: $@" >>$TEST_SSH_LOGFILE
194 if [ "X$TEST_SSH_TRACE" = "Xyes" ]; then
201 echo "verbose: $@" >>$TEST_SSH_LOGFILE
202 if [ "X$TEST_SSH_QUIET" != "Xyes" ]; then
210 echo "FAIL: $@" >>$TEST_SSH_LOGFILE
217 echo "FATAL: $@" >>$TEST_SSH_LOGFILE
229 # create server config
230 cat << EOF > $OBJ/sshd_config
235 ListenAddress 127.0.0.1
238 AuthorizedKeysFile $OBJ/authorized_keys_%u
240 AcceptEnv _XXX_TEST_*
242 Subsystem sftp $SFTPSERVER
245 if [ ! -z "$TEST_SSH_SSHD_CONFOPTS" ]; then
246 trace
"adding sshd_config option $TEST_SSH_SSHD_CONFOPTS"
247 echo "$TEST_SSH_SSHD_CONFOPTS" >> $OBJ/sshd_config
250 # server config for proxy connects
251 cp $OBJ/sshd_config
$OBJ/sshd_proxy
253 # allow group-writable directories in proxy-mode
254 echo 'StrictModes no' >> $OBJ/sshd_proxy
256 # create client config
257 cat << EOF > $OBJ/ssh_config
261 HostKeyAlias localhost-with-alias
264 GlobalKnownHostsFile $OBJ/known_hosts
265 UserKnownHostsFile $OBJ/known_hosts
266 RSAAuthentication yes
267 PubkeyAuthentication yes
268 ChallengeResponseAuthentication no
269 HostbasedAuthentication no
270 PasswordAuthentication no
272 StrictHostKeyChecking yes
275 if [ ! -z "$TEST_SSH_SSH_CONFOPTS" ]; then
276 trace
"adding ssh_config option $TEST_SSH_SSHD_CONFOPTS"
277 echo "$TEST_SSH_SSH_CONFOPTS" >> $OBJ/ssh_config
280 rm -f $OBJ/known_hosts
$OBJ/authorized_keys_
$USER
282 trace
"generate keys"
283 for t
in rsa rsa1
; do
286 ${SSHKEYGEN} -b 1024 -q -N '' -t $t -f $OBJ/$t ||\
287 fail
"ssh-keygen for $t failed"
289 # known hosts file for client
291 echon
'localhost-with-alias,127.0.0.1,::1 '
293 ) >> $OBJ/known_hosts
295 # setup authorized keys
296 cat $OBJ/$t.pub
>> $OBJ/authorized_keys_
$USER
297 echo IdentityFile
$OBJ/$t >> $OBJ/ssh_config
299 # use key as host key, too
300 $SUDO cp $OBJ/$t $OBJ/host.
$t
301 echo HostKey
$OBJ/host.
$t >> $OBJ/sshd_config
303 # don't use SUDO for proxy connect
304 echo HostKey
$OBJ/$t >> $OBJ/sshd_proxy
306 chmod 644 $OBJ/authorized_keys_
$USER
308 # Activate Twisted Conch tests if the binary is present
309 REGRESS_INTEROP_CONCH
=no
310 if test -x "$CONCH" ; then
311 REGRESS_INTEROP_CONCH
=yes
314 # If PuTTY is present and we are running a PuTTY test, prepare keys and
316 REGRESS_INTEROP_PUTTY
=no
317 if test -x "$PUTTYGEN" -a -x "$PLINK" ; then
318 REGRESS_INTEROP_PUTTY
=yes
322 *) REGRESS_INTEROP_PUTTY
=no
;;
325 if test "$REGRESS_INTEROP_PUTTY" = "yes" ; then
326 mkdir
-p ${OBJ}/.putty
328 # Add a PuTTY key to authorized_keys
329 rm -f ${OBJ}/putty.rsa2
330 puttygen
-t rsa
-o ${OBJ}/putty.rsa2
< /dev
/null
> /dev
/null
331 puttygen
-O public-openssh
${OBJ}/putty.rsa2 \
332 >> $OBJ/authorized_keys_
$USER
334 # Convert rsa2 host key to PuTTY format
335 ${SRC}/ssh2putty.sh
127.0.0.1 $PORT $OBJ/rsa
> \
336 ${OBJ}/.putty
/sshhostkeys
337 ${SRC}/ssh2putty.sh
127.0.0.1 22 $OBJ/rsa
>> \
338 ${OBJ}/.putty
/sshhostkeys
340 # Setup proxied session
341 mkdir
-p ${OBJ}/.putty
/sessions
342 rm -f ${OBJ}/.putty
/sessions
/localhost_proxy
343 echo "Hostname=127.0.0.1" >> ${OBJ}/.putty
/sessions
/localhost_proxy
344 echo "PortNumber=$PORT" >> ${OBJ}/.putty
/sessions
/localhost_proxy
345 echo "ProxyMethod=5" >> ${OBJ}/.putty
/sessions
/localhost_proxy
346 echo "ProxyTelnetCommand=sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSH_LOGFILE} -i -f $OBJ/sshd_proxy" >> ${OBJ}/.putty/sessions/localhost_proxy
348 REGRESS_INTEROP_PUTTY=yes
351 # create a proxy version of the client config
354 echo proxycommand ${SUDO} sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSH_LOGFILE} -i -f $OBJ/sshd_proxy
358 ${SSHD} -t -f $OBJ/sshd_proxy || fatal "sshd_proxy broken
"
363 $SUDO ${SSHD} -f $OBJ/sshd_config "$@
" -t || fatal "sshd_config broken
"
364 $SUDO ${SSHD} -f $OBJ/sshd_config -e "$@
" >>$TEST_SSH_LOGFILE 2>&1
366 trace "wait for sshd
"
368 while [ ! -f $PIDFILE -a $i -lt 10 ]; do
373 test -f $PIDFILE || fatal "no sshd running on port
$PORT"
381 if [ $RESULT -eq 0 ]; then