Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 1 | # $OpenBSD: test-exec.sh,v 1.40 2013/04/07 02:16:03 dtucker Exp $ |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 2 | # Placed in the Public Domain. |
| 3 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 4 | #SUDO=sudo |
| 5 | |
Darren Tucker | feb6f7f | 2005-02-08 20:17:17 +1100 | [diff] [blame] | 6 | # Unbreak GNU head(1) |
| 7 | _POSIX2_VERSION=199209 |
| 8 | export _POSIX2_VERSION |
| 9 | |
Darren Tucker | 50c7db9 | 2005-03-09 10:02:55 +1100 | [diff] [blame] | 10 | case `uname -s 2>/dev/null` in |
| 11 | OSF1*) |
| 12 | BIN_SH=xpg4 |
| 13 | export BIN_SH |
| 14 | ;; |
Darren Tucker | 6ea5dc6 | 2012-07-03 01:11:28 +1000 | [diff] [blame] | 15 | CYGWIN_NT-5.0) |
Darren Tucker | ec1e15d | 2012-07-03 01:06:49 +1000 | [diff] [blame] | 16 | os=cygwin |
| 17 | TEST_SSH_IPV6=no |
| 18 | ;; |
| 19 | CYGWIN*) |
| 20 | os=cygwin |
| 21 | ;; |
Darren Tucker | 50c7db9 | 2005-03-09 10:02:55 +1100 | [diff] [blame] | 22 | esac |
| 23 | |
Darren Tucker | 3b9c0ad | 2004-06-23 09:28:20 +1000 | [diff] [blame] | 24 | if [ ! -z "$TEST_SSH_PORT" ]; then |
| 25 | PORT="$TEST_SSH_PORT" |
| 26 | else |
| 27 | PORT=4242 |
| 28 | fi |
| 29 | |
Darren Tucker | 6d3921f | 2003-09-04 15:35:48 +1000 | [diff] [blame] | 30 | if [ -x /usr/ucb/whoami ]; then |
| 31 | USER=`/usr/ucb/whoami` |
Tim Rice | 23ee359 | 2003-09-11 22:32:17 -0700 | [diff] [blame] | 32 | elif whoami >/dev/null 2>&1; then |
Darren Tucker | 6d3921f | 2003-09-04 15:35:48 +1000 | [diff] [blame] | 33 | USER=`whoami` |
Damien Miller | e682cb0 | 2006-02-01 11:21:01 +1100 | [diff] [blame] | 34 | elif logname >/dev/null 2>&1; then |
| 35 | USER=`logname` |
Darren Tucker | 6d3921f | 2003-09-04 15:35:48 +1000 | [diff] [blame] | 36 | else |
| 37 | USER=`id -un` |
| 38 | fi |
| 39 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 40 | OBJ=$1 |
| 41 | if [ "x$OBJ" = "x" ]; then |
| 42 | echo '$OBJ not defined' |
| 43 | exit 2 |
| 44 | fi |
| 45 | if [ ! -d $OBJ ]; then |
| 46 | echo "not a directory: $OBJ" |
| 47 | exit 2 |
| 48 | fi |
| 49 | SCRIPT=$2 |
| 50 | if [ "x$SCRIPT" = "x" ]; then |
| 51 | echo '$SCRIPT not defined' |
| 52 | exit 2 |
| 53 | fi |
| 54 | if [ ! -f $SCRIPT ]; then |
| 55 | echo "not a file: $SCRIPT" |
| 56 | exit 2 |
| 57 | fi |
Tim Rice | 9ad7e0e | 2004-02-12 07:17:10 -0800 | [diff] [blame] | 58 | if $TEST_SHELL -n $SCRIPT; then |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 59 | true |
| 60 | else |
| 61 | echo "syntax error in $SCRIPT" |
| 62 | exit 2 |
| 63 | fi |
| 64 | unset SSH_AUTH_SOCK |
| 65 | |
Darren Tucker | a0f3ba7 | 2005-03-07 18:33:02 +1100 | [diff] [blame] | 66 | SRC=`dirname ${SCRIPT}` |
| 67 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 68 | # defaults |
| 69 | SSH=ssh |
| 70 | SSHD=sshd |
| 71 | SSHAGENT=ssh-agent |
| 72 | SSHADD=ssh-add |
| 73 | SSHKEYGEN=ssh-keygen |
| 74 | SSHKEYSCAN=ssh-keyscan |
| 75 | SFTP=sftp |
| 76 | SFTPSERVER=/usr/libexec/openssh/sftp-server |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 77 | SCP=scp |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 78 | |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 79 | # Interop testing |
Damien Miller | a766cea | 2008-06-30 08:12:37 +1000 | [diff] [blame] | 80 | PLINK=plink |
| 81 | PUTTYGEN=puttygen |
| 82 | CONCH=conch |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 83 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 84 | if [ "x$TEST_SSH_SSH" != "x" ]; then |
Darren Tucker | 03c907a | 2004-02-29 20:31:08 +1100 | [diff] [blame] | 85 | SSH="${TEST_SSH_SSH}" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 86 | fi |
| 87 | if [ "x$TEST_SSH_SSHD" != "x" ]; then |
Darren Tucker | 03c907a | 2004-02-29 20:31:08 +1100 | [diff] [blame] | 88 | SSHD="${TEST_SSH_SSHD}" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 89 | fi |
| 90 | if [ "x$TEST_SSH_SSHAGENT" != "x" ]; then |
Darren Tucker | 03c907a | 2004-02-29 20:31:08 +1100 | [diff] [blame] | 91 | SSHAGENT="${TEST_SSH_SSHAGENT}" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 92 | fi |
| 93 | if [ "x$TEST_SSH_SSHADD" != "x" ]; then |
Darren Tucker | 03c907a | 2004-02-29 20:31:08 +1100 | [diff] [blame] | 94 | SSHADD="${TEST_SSH_SSHADD}" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 95 | fi |
| 96 | if [ "x$TEST_SSH_SSHKEYGEN" != "x" ]; then |
Darren Tucker | 03c907a | 2004-02-29 20:31:08 +1100 | [diff] [blame] | 97 | SSHKEYGEN="${TEST_SSH_SSHKEYGEN}" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 98 | fi |
| 99 | if [ "x$TEST_SSH_SSHKEYSCAN" != "x" ]; then |
Darren Tucker | 03c907a | 2004-02-29 20:31:08 +1100 | [diff] [blame] | 100 | SSHKEYSCAN="${TEST_SSH_SSHKEYSCAN}" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 101 | fi |
| 102 | if [ "x$TEST_SSH_SFTP" != "x" ]; then |
Darren Tucker | 03c907a | 2004-02-29 20:31:08 +1100 | [diff] [blame] | 103 | SFTP="${TEST_SSH_SFTP}" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 104 | fi |
| 105 | if [ "x$TEST_SSH_SFTPSERVER" != "x" ]; then |
Darren Tucker | 03c907a | 2004-02-29 20:31:08 +1100 | [diff] [blame] | 106 | SFTPSERVER="${TEST_SSH_SFTPSERVER}" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 107 | fi |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 108 | if [ "x$TEST_SSH_SCP" != "x" ]; then |
| 109 | SCP="${TEST_SSH_SCP}" |
| 110 | fi |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 111 | if [ "x$TEST_SSH_PLINK" != "x" ]; then |
Damien Miller | c2cefb0 | 2008-03-13 12:41:31 +1100 | [diff] [blame] | 112 | # Find real binary, if it exists |
| 113 | case "${TEST_SSH_PLINK}" in |
| 114 | /*) PLINK="${TEST_SSH_PLINK}" ;; |
Damien Miller | 8f8b156 | 2008-03-15 09:25:54 +1100 | [diff] [blame] | 115 | *) PLINK=`which ${TEST_SSH_PLINK} 2>/dev/null` ;; |
Damien Miller | c2cefb0 | 2008-03-13 12:41:31 +1100 | [diff] [blame] | 116 | esac |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 117 | fi |
| 118 | if [ "x$TEST_SSH_PUTTYGEN" != "x" ]; then |
Damien Miller | c2cefb0 | 2008-03-13 12:41:31 +1100 | [diff] [blame] | 119 | # Find real binary, if it exists |
| 120 | case "${TEST_SSH_PUTTYGEN}" in |
| 121 | /*) PUTTYGEN="${TEST_SSH_PUTTYGEN}" ;; |
Damien Miller | 8f8b156 | 2008-03-15 09:25:54 +1100 | [diff] [blame] | 122 | *) PUTTYGEN=`which ${TEST_SSH_PUTTYGEN} 2>/dev/null` ;; |
Damien Miller | c2cefb0 | 2008-03-13 12:41:31 +1100 | [diff] [blame] | 123 | esac |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 124 | fi |
Damien Miller | 4268a13 | 2008-06-30 08:07:56 +1000 | [diff] [blame] | 125 | if [ "x$TEST_SSH_CONCH" != "x" ]; then |
Damien Miller | a766cea | 2008-06-30 08:12:37 +1000 | [diff] [blame] | 126 | # Find real binary, if it exists |
| 127 | case "${TEST_SSH_CONCH}" in |
| 128 | /*) CONCH="${TEST_SSH_CONCH}" ;; |
| 129 | *) CONCH=`which ${TEST_SSH_CONCH} 2>/dev/null` ;; |
| 130 | esac |
Damien Miller | 4268a13 | 2008-06-30 08:07:56 +1000 | [diff] [blame] | 131 | fi |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 132 | |
Darren Tucker | 977a9d2 | 2004-06-25 13:45:18 +1000 | [diff] [blame] | 133 | # Path to sshd must be absolute for rexec |
Darren Tucker | 114572f | 2005-08-23 23:32:05 +1000 | [diff] [blame] | 134 | case "$SSHD" in |
| 135 | /*) ;; |
| 136 | *) SSHD=`which sshd` ;; |
| 137 | esac |
Darren Tucker | 977a9d2 | 2004-06-25 13:45:18 +1000 | [diff] [blame] | 138 | |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 139 | # Logfiles. |
| 140 | # SSH_LOGFILE should be the debug output of ssh(1) only |
| 141 | # SSHD_LOGFILE should be the debug output of sshd(8) only |
| 142 | # REGRESS_LOGFILE is the output of the test itself stdout and stderr |
Darren Tucker | a0f3ba7 | 2005-03-07 18:33:02 +1100 | [diff] [blame] | 143 | if [ "x$TEST_SSH_LOGFILE" = "x" ]; then |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 144 | TEST_SSH_LOGFILE=$OBJ/ssh.log |
Darren Tucker | a0f3ba7 | 2005-03-07 18:33:02 +1100 | [diff] [blame] | 145 | fi |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 146 | if [ "x$TEST_SSHD_LOGFILE" = "x" ]; then |
| 147 | TEST_SSHD_LOGFILE=$OBJ/sshd.log |
| 148 | fi |
| 149 | if [ "x$TEST_REGRESS_LOGFILE" = "x" ]; then |
| 150 | TEST_REGRESS_LOGFILE=$OBJ/regress.log |
| 151 | fi |
| 152 | |
| 153 | # truncate logfiles |
| 154 | >$TEST_SSH_LOGFILE |
| 155 | >$TEST_SSHD_LOGFILE |
| 156 | >$TEST_REGRESS_LOGFILE |
Darren Tucker | a0f3ba7 | 2005-03-07 18:33:02 +1100 | [diff] [blame] | 157 | |
Darren Tucker | fe10a28 | 2013-03-12 11:19:40 +1100 | [diff] [blame] | 158 | # Some data for test copies |
| 159 | DATA=$OBJ/testdata |
| 160 | cat $SSHD${EXEEXT} $SSHD${EXEEXT} $SSHD${EXEEXT} $SSHD${EXEEXT} >$DATA |
| 161 | |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 162 | # Create wrapper ssh with logging. We can't just specify "SSH=ssh -E..." |
| 163 | # because sftp and scp don't handle spaces in arguments. |
| 164 | SSHLOGWRAP=$OBJ/ssh-log-wrapper.sh |
| 165 | echo "#!/bin/sh" > $SSHLOGWRAP |
| 166 | echo "exec ${SSH} -E${TEST_SSH_LOGFILE} "'"$@"' >>$SSHLOGWRAP |
| 167 | |
| 168 | chmod a+rx $OBJ/ssh-log-wrapper.sh |
| 169 | SSH="$SSHLOGWRAP" |
| 170 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 171 | # these should be used in tests |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 172 | export SSH SSHD SSHAGENT SSHADD SSHKEYGEN SSHKEYSCAN SFTP SFTPSERVER SCP |
| 173 | #echo $SSH $SSHD $SSHAGENT $SSHADD $SSHKEYGEN $SSHKEYSCAN $SFTP $SFTPSERVER $SCP |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 174 | |
| 175 | # helper |
Darren Tucker | 53c55f4 | 2003-09-04 15:16:56 +1000 | [diff] [blame] | 176 | echon() |
| 177 | { |
| 178 | if [ "x`echo -n`" = "x" ]; then |
| 179 | echo -n "$@" |
| 180 | elif [ "x`echo '\c'`" = "x" ]; then |
| 181 | echo "$@\c" |
| 182 | else |
| 183 | fatal "Don't know how to echo without newline." |
| 184 | fi |
| 185 | } |
| 186 | |
Tim Rice | 23ee359 | 2003-09-11 22:32:17 -0700 | [diff] [blame] | 187 | have_prog() |
| 188 | { |
| 189 | saved_IFS="$IFS" |
| 190 | IFS=":" |
| 191 | for i in $PATH |
| 192 | do |
| 193 | if [ -x $i/$1 ]; then |
| 194 | IFS="$saved_IFS" |
| 195 | return 0 |
| 196 | fi |
| 197 | done |
| 198 | IFS="$saved_IFS" |
| 199 | return 1 |
| 200 | } |
| 201 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 202 | cleanup () |
| 203 | { |
| 204 | if [ -f $PIDFILE ]; then |
Tim Rice | 722b8d1 | 2010-08-12 09:43:13 -0700 | [diff] [blame] | 205 | pid=`$SUDO cat $PIDFILE` |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 206 | if [ "X$pid" = "X" ]; then |
| 207 | echo no sshd running |
| 208 | else |
| 209 | if [ $pid -lt 2 ]; then |
Damien Miller | c173921 | 2010-02-24 17:29:34 +1100 | [diff] [blame] | 210 | echo bad pid for ssh: $pid |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 211 | else |
| 212 | $SUDO kill $pid |
Damien Miller | c173921 | 2010-02-24 17:29:34 +1100 | [diff] [blame] | 213 | trace "wait for sshd to exit" |
| 214 | i=0; |
| 215 | while [ -f $PIDFILE -a $i -lt 5 ]; do |
| 216 | i=`expr $i + 1` |
| 217 | sleep $i |
| 218 | done |
| 219 | test -f $PIDFILE && \ |
| 220 | fatal "sshd didn't exit port $PORT pid $pid" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 221 | fi |
| 222 | fi |
| 223 | fi |
| 224 | } |
| 225 | |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 226 | start_debug_log () |
| 227 | { |
| 228 | echo "trace: $@" >$TEST_REGRESS_LOGFILE |
| 229 | echo "trace: $@" >$TEST_SSH_LOGFILE |
| 230 | echo "trace: $@" >$TEST_SSHD_LOGFILE |
| 231 | } |
| 232 | |
| 233 | save_debug_log () |
| 234 | { |
| 235 | echo $@ >>$TEST_REGRESS_LOGFILE |
| 236 | echo $@ >>$TEST_SSH_LOGFILE |
| 237 | echo $@ >>$TEST_SSHD_LOGFILE |
| 238 | (cat $TEST_REGRESS_LOGFILE; echo) >>$OBJ/failed-regress.log |
| 239 | (cat $TEST_SSH_LOGFILE; echo) >>$OBJ/failed-ssh.log |
| 240 | (cat $TEST_SSHD_LOGFILE; echo) >>$OBJ/failed-sshd.log |
| 241 | } |
| 242 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 243 | trace () |
| 244 | { |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 245 | start_debug_log $@ |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 246 | if [ "X$TEST_SSH_TRACE" = "Xyes" ]; then |
Damien Miller | da1e4bd | 2007-10-26 15:35:54 +1000 | [diff] [blame] | 247 | echo "$@" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 248 | fi |
| 249 | } |
| 250 | |
| 251 | verbose () |
| 252 | { |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 253 | start_debug_log $@ |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 254 | if [ "X$TEST_SSH_QUIET" != "Xyes" ]; then |
Damien Miller | da1e4bd | 2007-10-26 15:35:54 +1000 | [diff] [blame] | 255 | echo "$@" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 256 | fi |
| 257 | } |
| 258 | |
Damien Miller | 6efd94f | 2011-09-04 19:04:16 +1000 | [diff] [blame] | 259 | warn () |
| 260 | { |
| 261 | echo "WARNING: $@" >>$TEST_SSH_LOGFILE |
| 262 | echo "WARNING: $@" |
| 263 | } |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 264 | |
| 265 | fail () |
| 266 | { |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 267 | save_debug_log "FAIL: $@" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 268 | RESULT=1 |
Damien Miller | da1e4bd | 2007-10-26 15:35:54 +1000 | [diff] [blame] | 269 | echo "$@" |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 270 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | fatal () |
| 274 | { |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 275 | save_debug_log "FATAL: $@" |
| 276 | echo -n "FATAL: " |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 277 | fail "$@" |
| 278 | cleanup |
| 279 | exit $RESULT |
| 280 | } |
| 281 | |
Damien Miller | 5849778 | 2011-01-17 16:17:09 +1100 | [diff] [blame] | 282 | # Check whether preprocessor symbols are defined in config.h. |
| 283 | config_defined () |
| 284 | { |
| 285 | str=$1 |
| 286 | while test "x$2" != "x" ; do |
| 287 | str="$str|$2" |
| 288 | shift |
| 289 | done |
| 290 | egrep "^#define.*($str)" ${BUILDDIR}/config.h >/dev/null 2>&1 |
| 291 | } |
| 292 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 293 | RESULT=0 |
| 294 | PIDFILE=$OBJ/pidfile |
| 295 | |
| 296 | trap fatal 3 2 |
| 297 | |
| 298 | # create server config |
| 299 | cat << EOF > $OBJ/sshd_config |
Darren Tucker | 0e6868e | 2004-06-16 20:36:16 +1000 | [diff] [blame] | 300 | StrictModes no |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 301 | Port $PORT |
Darren Tucker | e23a79c | 2009-10-12 09:37:22 +1100 | [diff] [blame] | 302 | Protocol 2,1 |
Damien Miller | 76be6b8 | 2006-01-31 21:59:01 +1100 | [diff] [blame] | 303 | AddressFamily inet |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 304 | ListenAddress 127.0.0.1 |
| 305 | #ListenAddress ::1 |
| 306 | PidFile $PIDFILE |
| 307 | AuthorizedKeysFile $OBJ/authorized_keys_%u |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 308 | LogLevel DEBUG3 |
Darren Tucker | 4c37ef0 | 2004-06-16 20:08:56 +1000 | [diff] [blame] | 309 | AcceptEnv _XXX_TEST_* |
| 310 | AcceptEnv _XXX_TEST |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 311 | Subsystem sftp $SFTPSERVER |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 312 | EOF |
| 313 | |
Darren Tucker | 6223eea | 2004-06-23 09:25:02 +1000 | [diff] [blame] | 314 | if [ ! -z "$TEST_SSH_SSHD_CONFOPTS" ]; then |
| 315 | trace "adding sshd_config option $TEST_SSH_SSHD_CONFOPTS" |
| 316 | echo "$TEST_SSH_SSHD_CONFOPTS" >> $OBJ/sshd_config |
| 317 | fi |
| 318 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 319 | # server config for proxy connects |
| 320 | cp $OBJ/sshd_config $OBJ/sshd_proxy |
| 321 | |
| 322 | # allow group-writable directories in proxy-mode |
| 323 | echo 'StrictModes no' >> $OBJ/sshd_proxy |
| 324 | |
| 325 | # create client config |
| 326 | cat << EOF > $OBJ/ssh_config |
| 327 | Host * |
Darren Tucker | e23a79c | 2009-10-12 09:37:22 +1100 | [diff] [blame] | 328 | Protocol 2,1 |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 329 | Hostname 127.0.0.1 |
| 330 | HostKeyAlias localhost-with-alias |
| 331 | Port $PORT |
| 332 | User $USER |
| 333 | GlobalKnownHostsFile $OBJ/known_hosts |
| 334 | UserKnownHostsFile $OBJ/known_hosts |
| 335 | RSAAuthentication yes |
| 336 | PubkeyAuthentication yes |
| 337 | ChallengeResponseAuthentication no |
| 338 | HostbasedAuthentication no |
| 339 | PasswordAuthentication no |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 340 | BatchMode yes |
| 341 | StrictHostKeyChecking yes |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 342 | LogLevel DEBUG3 |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 343 | EOF |
| 344 | |
Darren Tucker | 6223eea | 2004-06-23 09:25:02 +1000 | [diff] [blame] | 345 | if [ ! -z "$TEST_SSH_SSH_CONFOPTS" ]; then |
| 346 | trace "adding ssh_config option $TEST_SSH_SSHD_CONFOPTS" |
| 347 | echo "$TEST_SSH_SSH_CONFOPTS" >> $OBJ/ssh_config |
| 348 | fi |
| 349 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 350 | rm -f $OBJ/known_hosts $OBJ/authorized_keys_$USER |
| 351 | |
| 352 | trace "generate keys" |
| 353 | for t in rsa rsa1; do |
| 354 | # generate user key |
Darren Tucker | 7c8b1e7 | 2013-05-17 09:10:20 +1000 | [diff] [blame] | 355 | if [ ! -f $OBJ/$t ] || [ ${SSHKEYGEN} -nt $OBJ/$t ]; then |
| 356 | rm -f $OBJ/$t |
| 357 | ${SSHKEYGEN} -q -N '' -t $t -f $OBJ/$t ||\ |
| 358 | fail "ssh-keygen for $t failed" |
| 359 | fi |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 360 | |
| 361 | # known hosts file for client |
| 362 | ( |
Darren Tucker | 53c55f4 | 2003-09-04 15:16:56 +1000 | [diff] [blame] | 363 | echon 'localhost-with-alias,127.0.0.1,::1 ' |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 364 | cat $OBJ/$t.pub |
| 365 | ) >> $OBJ/known_hosts |
| 366 | |
| 367 | # setup authorized keys |
| 368 | cat $OBJ/$t.pub >> $OBJ/authorized_keys_$USER |
| 369 | echo IdentityFile $OBJ/$t >> $OBJ/ssh_config |
| 370 | |
| 371 | # use key as host key, too |
| 372 | $SUDO cp $OBJ/$t $OBJ/host.$t |
| 373 | echo HostKey $OBJ/host.$t >> $OBJ/sshd_config |
| 374 | |
| 375 | # don't use SUDO for proxy connect |
| 376 | echo HostKey $OBJ/$t >> $OBJ/sshd_proxy |
| 377 | done |
| 378 | chmod 644 $OBJ/authorized_keys_$USER |
| 379 | |
Damien Miller | 4268a13 | 2008-06-30 08:07:56 +1000 | [diff] [blame] | 380 | # Activate Twisted Conch tests if the binary is present |
| 381 | REGRESS_INTEROP_CONCH=no |
| 382 | if test -x "$CONCH" ; then |
| 383 | REGRESS_INTEROP_CONCH=yes |
| 384 | fi |
| 385 | |
Darren Tucker | d788b7c | 2008-06-10 23:15:54 +1000 | [diff] [blame] | 386 | # If PuTTY is present and we are running a PuTTY test, prepare keys and |
| 387 | # configuration |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 388 | REGRESS_INTEROP_PUTTY=no |
Darren Tucker | d8bafea | 2008-06-11 01:39:38 +1000 | [diff] [blame] | 389 | if test -x "$PUTTYGEN" -a -x "$PLINK" ; then |
Darren Tucker | 5f34664 | 2008-06-11 01:38:52 +1000 | [diff] [blame] | 390 | REGRESS_INTEROP_PUTTY=yes |
| 391 | fi |
| 392 | case "$SCRIPT" in |
| 393 | *putty*) ;; |
| 394 | *) REGRESS_INTEROP_PUTTY=no ;; |
| 395 | esac |
| 396 | |
| 397 | if test "$REGRESS_INTEROP_PUTTY" = "yes" ; then |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 398 | mkdir -p ${OBJ}/.putty |
| 399 | |
| 400 | # Add a PuTTY key to authorized_keys |
| 401 | rm -f ${OBJ}/putty.rsa2 |
| 402 | puttygen -t rsa -o ${OBJ}/putty.rsa2 < /dev/null > /dev/null |
| 403 | puttygen -O public-openssh ${OBJ}/putty.rsa2 \ |
| 404 | >> $OBJ/authorized_keys_$USER |
| 405 | |
| 406 | # Convert rsa2 host key to PuTTY format |
| 407 | ${SRC}/ssh2putty.sh 127.0.0.1 $PORT $OBJ/rsa > \ |
| 408 | ${OBJ}/.putty/sshhostkeys |
| 409 | ${SRC}/ssh2putty.sh 127.0.0.1 22 $OBJ/rsa >> \ |
| 410 | ${OBJ}/.putty/sshhostkeys |
| 411 | |
| 412 | # Setup proxied session |
| 413 | mkdir -p ${OBJ}/.putty/sessions |
| 414 | rm -f ${OBJ}/.putty/sessions/localhost_proxy |
| 415 | echo "Hostname=127.0.0.1" >> ${OBJ}/.putty/sessions/localhost_proxy |
| 416 | echo "PortNumber=$PORT" >> ${OBJ}/.putty/sessions/localhost_proxy |
| 417 | echo "ProxyMethod=5" >> ${OBJ}/.putty/sessions/localhost_proxy |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 418 | echo "ProxyTelnetCommand=sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSHD_LOGFILE} -i -f $OBJ/sshd_proxy" >> ${OBJ}/.putty/sessions/localhost_proxy |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 419 | |
| 420 | REGRESS_INTEROP_PUTTY=yes |
| 421 | fi |
| 422 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 423 | # create a proxy version of the client config |
| 424 | ( |
| 425 | cat $OBJ/ssh_config |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 426 | echo proxycommand ${SUDO} sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSHD_LOGFILE} -i -f $OBJ/sshd_proxy |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 427 | ) > $OBJ/ssh_proxy |
| 428 | |
| 429 | # check proxy config |
| 430 | ${SSHD} -t -f $OBJ/sshd_proxy || fatal "sshd_proxy broken" |
| 431 | |
| 432 | start_sshd () |
| 433 | { |
| 434 | # start sshd |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 435 | $SUDO ${SSHD} -f $OBJ/sshd_config "$@" -t || fatal "sshd_config broken" |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 436 | $SUDO ${SSHD} -f $OBJ/sshd_config "$@" -E$TEST_SSHD_LOGFILE |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 437 | |
| 438 | trace "wait for sshd" |
| 439 | i=0; |
Darren Tucker | 6d3921f | 2003-09-04 15:35:48 +1000 | [diff] [blame] | 440 | while [ ! -f $PIDFILE -a $i -lt 10 ]; do |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 441 | i=`expr $i + 1` |
| 442 | sleep $i |
| 443 | done |
| 444 | |
| 445 | test -f $PIDFILE || fatal "no sshd running on port $PORT" |
| 446 | } |
| 447 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 448 | # source test body |
| 449 | . $SCRIPT |
| 450 | |
| 451 | # kill sshd |
| 452 | cleanup |
| 453 | if [ $RESULT -eq 0 ]; then |
| 454 | verbose ok $tid |
| 455 | else |
| 456 | echo failed $tid |
| 457 | fi |
| 458 | exit $RESULT |