1 # $OpenBSD: test-exec.sh,v 1.14 2002/04/15 15:19:48 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 sh -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
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
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 RhostsAuthentication no
189 RhostsRSAAuthentication no
191 StrictHostKeyChecking yes
194 rm -f $OBJ/known_hosts $OBJ/authorized_keys_$USER
196 trace "generate keys"
197 for t in rsa rsa1; do
200 ${SSHKEYGEN} -q -N '' -t $t -f $OBJ/$t ||\
201 fail "ssh-keygen for $t failed"
203 # known hosts file for client
205 echon 'localhost-with-alias,127.0.0.1,::1 '
207 ) >> $OBJ/known_hosts
209 # setup authorized keys
210 cat $OBJ/$t.pub >> $OBJ/authorized_keys_$USER
211 echo IdentityFile $OBJ/$t >> $OBJ/ssh_config
213 # use key as host key, too
214 $SUDO cp $OBJ/$t $OBJ/host.$t
215 echo HostKey $OBJ/host.$t >> $OBJ/sshd_config
217 # don't use SUDO for proxy connect
218 echo HostKey $OBJ/$t >> $OBJ/sshd_proxy
220 chmod 644 $OBJ/authorized_keys_$USER
222 # create a proxy version of the client config
225 echo proxycommand ${SUDO} ${SSHD} -i -f $OBJ/sshd_proxy
229 ${SSHD} -t -f $OBJ/sshd_proxy || fatal "sshd_proxy broken"
234 $SUDO ${SSHD} -f $OBJ/sshd_config -t || fatal "sshd_config broken"
235 $SUDO ${SSHD} -f $OBJ/sshd_config
237 trace "wait for sshd"
239 while [ ! -f $PIDFILE -a $i -lt 10 ]; do
244 test -f $PIDFILE || fatal "no sshd running on port $PORT"
252 if [ $RESULT -eq 0 ]; then