1 # $OpenBSD: test-exec.sh,v 1.14 2002/04/15 15:19:48 markus Exp $
2 # Placed in the Public Domain.
10 if [ "x$OBJ" = "x" ]; then
11 echo '$OBJ not defined'
14 if [ ! -d $OBJ ]; then
15 echo "not a directory: $OBJ"
19 if [ "x$SCRIPT" = "x" ]; then
20 echo '$SCRIPT not defined'
23 if [ ! -f $SCRIPT ]; then
24 echo "not a file: $SCRIPT"
27 if sh -n $SCRIPT; then
30 echo "syntax error in $SCRIPT"
41 SSHKEYSCAN=ssh-keyscan
43 SFTPSERVER=/usr/libexec/openssh/sftp-server
45 if [ "x$TEST_SSH_SSH" != "x" ]; then
48 if [ "x$TEST_SSH_SSHD" != "x" ]; then
51 if [ "x$TEST_SSH_SSHAGENT" != "x" ]; then
52 SSHAGENT=${TEST_SSH_SSHAGENT}
54 if [ "x$TEST_SSH_SSHADD" != "x" ]; then
55 SSHADD=${TEST_SSH_SSHADD}
57 if [ "x$TEST_SSH_SSHKEYGEN" != "x" ]; then
58 SSHKEYGEN=${TEST_SSH_SSHKEYGEN}
60 if [ "x$TEST_SSH_SSHKEYSCAN" != "x" ]; then
61 SSHKEYSCAN=${TEST_SSH_SSHKEYSCAN}
63 if [ "x$TEST_SSH_SFTP" != "x" ]; then
66 if [ "x$TEST_SSH_SFTPSERVER" != "x" ]; then
67 SFTPSERVER=${TEST_SSH_SFTPSERVER}
70 # these should be used in tests
71 export SSH SSHD SSHAGENT SSHADD SSHKEYGEN SSHKEYSCAN SFTP SFTPSERVER
72 #echo $SSH $SSHD $SSHAGENT $SSHADD $SSHKEYGEN $SSHKEYSCAN $SFTP $SFTPSERVER
77 if [ -f $PIDFILE ]; then
79 if [ "X$pid" = "X" ]; then
82 if [ $pid -lt 2 ]; then
83 echo bad pid for ssd: $pid
93 if [ "X$TEST_SSH_TRACE" = "Xyes" ]; then
100 if [ "X$TEST_SSH_QUIET" != "Xyes" ]; then
125 # create server config
126 cat << EOF > $OBJ/sshd_config
128 ListenAddress 127.0.0.1
131 AuthorizedKeysFile $OBJ/authorized_keys_%u
135 # server config for proxy connects
136 cp $OBJ/sshd_config $OBJ/sshd_proxy
138 # allow group-writable directories in proxy-mode
139 echo 'StrictModes no' >> $OBJ/sshd_proxy
141 # create client config
142 cat << EOF > $OBJ/ssh_config
145 HostKeyAlias localhost-with-alias
148 GlobalKnownHostsFile $OBJ/known_hosts
149 UserKnownHostsFile $OBJ/known_hosts
150 RSAAuthentication yes
151 PubkeyAuthentication yes
152 ChallengeResponseAuthentication no
153 HostbasedAuthentication no
154 PasswordAuthentication no
155 RhostsAuthentication no
156 RhostsRSAAuthentication no
158 StrictHostKeyChecking yes
161 rm -f $OBJ/known_hosts $OBJ/authorized_keys_$USER
163 trace "generate keys"
164 for t in rsa rsa1; do
167 ${SSHKEYGEN} -q -N '' -t $t -f $OBJ/$t ||\
168 fail "ssh-keygen for $t failed"
170 # known hosts file for client
172 echo -n 'localhost-with-alias,127.0.0.1,::1 '
174 ) >> $OBJ/known_hosts
176 # setup authorized keys
177 cat $OBJ/$t.pub >> $OBJ/authorized_keys_$USER
178 echo IdentityFile $OBJ/$t >> $OBJ/ssh_config
180 # use key as host key, too
181 $SUDO cp $OBJ/$t $OBJ/host.$t
182 echo HostKey $OBJ/host.$t >> $OBJ/sshd_config
184 # don't use SUDO for proxy connect
185 echo HostKey $OBJ/$t >> $OBJ/sshd_proxy
187 chmod 644 $OBJ/authorized_keys_$USER
189 # create a proxy version of the client config
192 echo proxycommand ${SSHD} -i -f $OBJ/sshd_proxy
196 ${SSHD} -t -f $OBJ/sshd_proxy || fatal "sshd_proxy broken"
201 $SUDO ${SSHD} -f $OBJ/sshd_config -t || fatal "sshd_config broken"
202 $SUDO ${SSHD} -f $OBJ/sshd_config
204 trace "wait for sshd"
206 while [ ! -f $PIDFILE -a $i -lt 5 ]; do
211 test -f $PIDFILE || fatal "no sshd running on port $PORT"
219 if [ $RESULT -eq 0 ]; then