1 # $OpenBSD: test-exec.sh,v 1.28 2005/05/20 23:14:15 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
72 if [ "x$TEST_SSH_SSH" != "x" ]; then
75 if [ "x$TEST_SSH_SSHD" != "x" ]; then
76 SSHD
="${TEST_SSH_SSHD}"
78 if [ "x$TEST_SSH_SSHAGENT" != "x" ]; then
79 SSHAGENT
="${TEST_SSH_SSHAGENT}"
81 if [ "x$TEST_SSH_SSHADD" != "x" ]; then
82 SSHADD
="${TEST_SSH_SSHADD}"
84 if [ "x$TEST_SSH_SSHKEYGEN" != "x" ]; then
85 SSHKEYGEN
="${TEST_SSH_SSHKEYGEN}"
87 if [ "x$TEST_SSH_SSHKEYSCAN" != "x" ]; then
88 SSHKEYSCAN
="${TEST_SSH_SSHKEYSCAN}"
90 if [ "x$TEST_SSH_SFTP" != "x" ]; then
91 SFTP
="${TEST_SSH_SFTP}"
93 if [ "x$TEST_SSH_SFTPSERVER" != "x" ]; then
94 SFTPSERVER
="${TEST_SSH_SFTPSERVER}"
96 if [ "x$TEST_SSH_SCP" != "x" ]; then
100 # Path to sshd must be absolute for rexec
103 *) SSHD
=`which sshd` ;;
106 if [ "x$TEST_SSH_LOGFILE" = "x" ]; then
107 TEST_SSH_LOGFILE
=/dev
/null
110 # these should be used in tests
111 export SSH SSHD SSHAGENT SSHADD SSHKEYGEN SSHKEYSCAN SFTP SFTPSERVER SCP
112 #echo $SSH $SSHD $SSHAGENT $SSHADD $SSHKEYGEN $SSHKEYSCAN $SFTP $SFTPSERVER $SCP
117 if [ "x`echo -n`" = "x" ]; then
119 elif [ "x`echo '\c'`" = "x" ]; then
122 fatal
"Don't know how to echo without newline."
132 if [ -x $i/$1 ]; then
143 if [ -f $PIDFILE ]; then
145 if [ "X$pid" = "X" ]; then
148 if [ $pid -lt 2 ]; then
149 echo bad pid
for ssd
: $pid
159 echo "trace: $@" >>$TEST_SSH_LOGFILE
160 if [ "X$TEST_SSH_TRACE" = "Xyes" ]; then
167 echo "verbose: $@" >>$TEST_SSH_LOGFILE
168 if [ "X$TEST_SSH_QUIET" != "Xyes" ]; then
176 echo "FAIL: $@" >>$TEST_SSH_LOGFILE
183 echo "FATAL: $@" >>$TEST_SSH_LOGFILE
195 # create server config
196 cat << EOF > $OBJ/sshd_config
200 ListenAddress 127.0.0.1
203 AuthorizedKeysFile $OBJ/authorized_keys_%u
205 AcceptEnv _XXX_TEST_*
207 Subsystem sftp $SFTPSERVER
210 if [ ! -z "$TEST_SSH_SSHD_CONFOPTS" ]; then
211 trace
"adding sshd_config option $TEST_SSH_SSHD_CONFOPTS"
212 echo "$TEST_SSH_SSHD_CONFOPTS" >> $OBJ/sshd_config
215 # server config for proxy connects
216 cp $OBJ/sshd_config
$OBJ/sshd_proxy
218 # allow group-writable directories in proxy-mode
219 echo 'StrictModes no' >> $OBJ/sshd_proxy
221 # create client config
222 cat << EOF > $OBJ/ssh_config
225 HostKeyAlias localhost-with-alias
228 GlobalKnownHostsFile $OBJ/known_hosts
229 UserKnownHostsFile $OBJ/known_hosts
230 RSAAuthentication yes
231 PubkeyAuthentication yes
232 ChallengeResponseAuthentication no
233 HostbasedAuthentication no
234 PasswordAuthentication no
236 StrictHostKeyChecking yes
239 if [ ! -z "$TEST_SSH_SSH_CONFOPTS" ]; then
240 trace
"adding ssh_config option $TEST_SSH_SSHD_CONFOPTS"
241 echo "$TEST_SSH_SSH_CONFOPTS" >> $OBJ/ssh_config
244 rm -f $OBJ/known_hosts
$OBJ/authorized_keys_
$USER
246 trace
"generate keys"
247 for t
in rsa rsa1
; do
250 ${SSHKEYGEN} -b 1024 -q -N '' -t $t -f $OBJ/$t ||\
251 fail
"ssh-keygen for $t failed"
253 # known hosts file for client
255 echon
'localhost-with-alias,127.0.0.1,::1 '
257 ) >> $OBJ/known_hosts
259 # setup authorized keys
260 cat $OBJ/$t.pub
>> $OBJ/authorized_keys_
$USER
261 echo IdentityFile
$OBJ/$t >> $OBJ/ssh_config
263 # use key as host key, too
264 $SUDO cp $OBJ/$t $OBJ/host.
$t
265 echo HostKey
$OBJ/host.
$t >> $OBJ/sshd_config
267 # don't use SUDO for proxy connect
268 echo HostKey
$OBJ/$t >> $OBJ/sshd_proxy
270 chmod 644 $OBJ/authorized_keys_
$USER
272 # create a proxy version of the client config
275 echo proxycommand
${SUDO} sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSH_LOGFILE} -i -f $OBJ/sshd_proxy
279 ${SSHD} -t -f $OBJ/sshd_proxy || fatal
"sshd_proxy broken"
284 $SUDO ${SSHD} -f $OBJ/sshd_config
-t || fatal
"sshd_config broken"
285 $SUDO ${SSHD} -f $OBJ/sshd_config
-e >>$TEST_SSH_LOGFILE 2>&1
287 trace
"wait for sshd"
289 while [ ! -f $PIDFILE -a $i -lt 10 ]; do
294 test -f $PIDFILE || fatal
"no sshd running on port $PORT"
302 if [ $RESULT -eq 0 ]; then