1 # $OpenBSD: test-exec.sh,v 1.15 2004/02/24 16:56:30 markus Exp $
2 # Placed in the Public Domain.
7 if [ -x /usr/ucb/whoami ]; then
9 elif whoami >/dev/null 2>&1; then
16 if [ "x$OBJ" = "x" ]; then
17 echo '$OBJ not defined'
20 if [ ! -d $OBJ ]; then
21 echo "not a directory: $OBJ"
25 if [ "x$SCRIPT" = "x" ]; then
26 echo '$SCRIPT not defined'
29 if [ ! -f $SCRIPT ]; then
30 echo "not a file: $SCRIPT"
33 if $TEST_SHELL -n $SCRIPT; then
36 echo "syntax error in $SCRIPT"
47 SSHKEYSCAN=ssh-keyscan
49 SFTPSERVER=/usr/libexec/openssh/sftp-server
51 if [ "x$TEST_SSH_SSH" != "x" ]; then
54 if [ "x$TEST_SSH_SSHD" != "x" ]; then
55 SSHD="${TEST_SSH_SSHD}"
57 if [ "x$TEST_SSH_SSHAGENT" != "x" ]; then
58 SSHAGENT="${TEST_SSH_SSHAGENT}"
60 if [ "x$TEST_SSH_SSHADD" != "x" ]; then
61 SSHADD="${TEST_SSH_SSHADD}"
63 if [ "x$TEST_SSH_SSHKEYGEN" != "x" ]; then
64 SSHKEYGEN="${TEST_SSH_SSHKEYGEN}"
66 if [ "x$TEST_SSH_SSHKEYSCAN" != "x" ]; then
67 SSHKEYSCAN="${TEST_SSH_SSHKEYSCAN}"
69 if [ "x$TEST_SSH_SFTP" != "x" ]; then
70 SFTP="${TEST_SSH_SFTP}"
72 if [ "x$TEST_SSH_SFTPSERVER" != "x" ]; then
73 SFTPSERVER="${TEST_SSH_SFTPSERVER}"
76 # these should be used in tests
77 export SSH SSHD SSHAGENT SSHADD SSHKEYGEN SSHKEYSCAN SFTP SFTPSERVER
78 #echo $SSH $SSHD $SSHAGENT $SSHADD $SSHKEYGEN $SSHKEYSCAN $SFTP $SFTPSERVER
83 if [ "x`echo -n`" = "x" ]; then
85 elif [ "x`echo '\c'`" = "x" ]; then
88 fatal "Don't know how to echo without newline."
109 if [ -f $PIDFILE ]; then
111 if [ "X$pid" = "X" ]; then
114 if [ $pid -lt 2 ]; then
115 echo bad pid for ssd: $pid
125 if [ "X$TEST_SSH_TRACE" = "Xyes" ]; then
132 if [ "X$TEST_SSH_QUIET" != "Xyes" ]; then
157 # create server config
158 cat << EOF > $OBJ/sshd_config
160 ListenAddress 127.0.0.1
163 AuthorizedKeysFile $OBJ/authorized_keys_%u
168 # server config for proxy connects
169 cp $OBJ/sshd_config $OBJ/sshd_proxy
171 # allow group-writable directories in proxy-mode
172 echo 'StrictModes no' >> $OBJ/sshd_proxy
174 # create client config
175 cat << EOF > $OBJ/ssh_config
178 HostKeyAlias localhost-with-alias
181 GlobalKnownHostsFile $OBJ/known_hosts
182 UserKnownHostsFile $OBJ/known_hosts
183 RSAAuthentication yes
184 PubkeyAuthentication yes
185 ChallengeResponseAuthentication no
186 HostbasedAuthentication no
187 PasswordAuthentication no
188 RhostsRSAAuthentication no
190 StrictHostKeyChecking yes
193 rm -f $OBJ/known_hosts $OBJ/authorized_keys_$USER
195 trace "generate keys"
196 for t in rsa rsa1; do
199 ${SSHKEYGEN} -q -N '' -t $t -f $OBJ/$t ||\
200 fail "ssh-keygen for $t failed"
202 # known hosts file for client
204 echon 'localhost-with-alias,127.0.0.1,::1 '
206 ) >> $OBJ/known_hosts
208 # setup authorized keys
209 cat $OBJ/$t.pub >> $OBJ/authorized_keys_$USER
210 echo IdentityFile $OBJ/$t >> $OBJ/ssh_config
212 # use key as host key, too
213 $SUDO cp $OBJ/$t $OBJ/host.$t
214 echo HostKey $OBJ/host.$t >> $OBJ/sshd_config
216 # don't use SUDO for proxy connect
217 echo HostKey $OBJ/$t >> $OBJ/sshd_proxy
219 chmod 644 $OBJ/authorized_keys_$USER
221 # create a proxy version of the client config
224 echo proxycommand ${SUDO} ${SSHD} -i -f $OBJ/sshd_proxy
228 ${SSHD} -t -f $OBJ/sshd_proxy || fatal "sshd_proxy broken"
233 $SUDO ${SSHD} -f $OBJ/sshd_config -t || fatal "sshd_config broken"
234 $SUDO ${SSHD} -f $OBJ/sshd_config
236 trace "wait for sshd"
238 while [ ! -f $PIDFILE -a $i -lt 10 ]; do
243 test -f $PIDFILE || fatal "no sshd running on port $PORT"
251 if [ $RESULT -eq 0 ]; then