Damien Miller | d1e26cf | 2013-07-25 12:11:18 +1000 | [diff] [blame] | 1 | # $OpenBSD: test-exec.sh,v 1.46 2013/06/21 02:26:26 djm 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 | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 158 | # Create wrapper ssh with logging. We can't just specify "SSH=ssh -E..." |
| 159 | # because sftp and scp don't handle spaces in arguments. |
| 160 | SSHLOGWRAP=$OBJ/ssh-log-wrapper.sh |
| 161 | echo "#!/bin/sh" > $SSHLOGWRAP |
| 162 | echo "exec ${SSH} -E${TEST_SSH_LOGFILE} "'"$@"' >>$SSHLOGWRAP |
| 163 | |
| 164 | chmod a+rx $OBJ/ssh-log-wrapper.sh |
| 165 | SSH="$SSHLOGWRAP" |
| 166 | |
Darren Tucker | 59d928d | 2013-05-17 15:32:29 +1000 | [diff] [blame] | 167 | # Some test data. We make a copy because some tests will overwrite it. |
| 168 | # The tests may assume that $DATA exists and is writable and $COPY does |
| 169 | # not exist. |
Damien Miller | d1e26cf | 2013-07-25 12:11:18 +1000 | [diff] [blame] | 170 | DATANAME=data |
| 171 | DATA=$OBJ/${DATANAME} |
Darren Tucker | 59d928d | 2013-05-17 15:32:29 +1000 | [diff] [blame] | 172 | cat $SSHD $SSHD $SSHD $SSHD >${DATA} |
| 173 | chmod u+w ${DATA} |
| 174 | COPY=$OBJ/copy |
| 175 | rm -f ${COPY} |
| 176 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 177 | # these should be used in tests |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 178 | export SSH SSHD SSHAGENT SSHADD SSHKEYGEN SSHKEYSCAN SFTP SFTPSERVER SCP |
| 179 | #echo $SSH $SSHD $SSHAGENT $SSHADD $SSHKEYGEN $SSHKEYSCAN $SFTP $SFTPSERVER $SCP |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 180 | |
Darren Tucker | 5f1a89a | 2013-05-17 19:17:58 +1000 | [diff] [blame] | 181 | # Portable specific functions |
Tim Rice | 23ee359 | 2003-09-11 22:32:17 -0700 | [diff] [blame] | 182 | have_prog() |
| 183 | { |
| 184 | saved_IFS="$IFS" |
| 185 | IFS=":" |
| 186 | for i in $PATH |
| 187 | do |
| 188 | if [ -x $i/$1 ]; then |
| 189 | IFS="$saved_IFS" |
| 190 | return 0 |
| 191 | fi |
| 192 | done |
| 193 | IFS="$saved_IFS" |
| 194 | return 1 |
| 195 | } |
| 196 | |
Darren Tucker | 5f1a89a | 2013-05-17 19:17:58 +1000 | [diff] [blame] | 197 | jot() { |
| 198 | awk "BEGIN { for (i = $2; i < $2 + $1; i++) { printf \"%d\n\", i } exit }" |
| 199 | } |
Darren Tucker | 6f66981 | 2013-05-17 19:28:51 +1000 | [diff] [blame] | 200 | |
| 201 | # Check whether preprocessor symbols are defined in config.h. |
| 202 | config_defined () |
| 203 | { |
| 204 | str=$1 |
| 205 | while test "x$2" != "x" ; do |
| 206 | str="$str|$2" |
| 207 | shift |
| 208 | done |
| 209 | egrep "^#define.*($str)" ${BUILDDIR}/config.h >/dev/null 2>&1 |
| 210 | } |
Darren Tucker | f8d5b34 | 2013-05-17 19:53:25 +1000 | [diff] [blame] | 211 | |
| 212 | md5 () { |
| 213 | if have_prog md5sum; then |
| 214 | md5sum |
| 215 | elif have_prog openssl; then |
| 216 | openssl md5 |
| 217 | elif have_prog cksum; then |
| 218 | cksum |
| 219 | elif have_prog sum; then |
| 220 | sum |
| 221 | else |
| 222 | wc -c |
| 223 | fi |
| 224 | } |
Darren Tucker | 5f1a89a | 2013-05-17 19:17:58 +1000 | [diff] [blame] | 225 | # End of portable specific functions |
| 226 | |
Darren Tucker | 6f66981 | 2013-05-17 19:28:51 +1000 | [diff] [blame] | 227 | # helper |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 228 | cleanup () |
| 229 | { |
| 230 | if [ -f $PIDFILE ]; then |
Tim Rice | 722b8d1 | 2010-08-12 09:43:13 -0700 | [diff] [blame] | 231 | pid=`$SUDO cat $PIDFILE` |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 232 | if [ "X$pid" = "X" ]; then |
| 233 | echo no sshd running |
| 234 | else |
| 235 | if [ $pid -lt 2 ]; then |
Damien Miller | c173921 | 2010-02-24 17:29:34 +1100 | [diff] [blame] | 236 | echo bad pid for ssh: $pid |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 237 | else |
| 238 | $SUDO kill $pid |
Damien Miller | c173921 | 2010-02-24 17:29:34 +1100 | [diff] [blame] | 239 | trace "wait for sshd to exit" |
| 240 | i=0; |
| 241 | while [ -f $PIDFILE -a $i -lt 5 ]; do |
| 242 | i=`expr $i + 1` |
| 243 | sleep $i |
| 244 | done |
| 245 | test -f $PIDFILE && \ |
| 246 | fatal "sshd didn't exit port $PORT pid $pid" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 247 | fi |
| 248 | fi |
| 249 | fi |
| 250 | } |
| 251 | |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 252 | start_debug_log () |
| 253 | { |
| 254 | echo "trace: $@" >$TEST_REGRESS_LOGFILE |
| 255 | echo "trace: $@" >$TEST_SSH_LOGFILE |
| 256 | echo "trace: $@" >$TEST_SSHD_LOGFILE |
| 257 | } |
| 258 | |
| 259 | save_debug_log () |
| 260 | { |
| 261 | echo $@ >>$TEST_REGRESS_LOGFILE |
| 262 | echo $@ >>$TEST_SSH_LOGFILE |
| 263 | echo $@ >>$TEST_SSHD_LOGFILE |
| 264 | (cat $TEST_REGRESS_LOGFILE; echo) >>$OBJ/failed-regress.log |
| 265 | (cat $TEST_SSH_LOGFILE; echo) >>$OBJ/failed-ssh.log |
| 266 | (cat $TEST_SSHD_LOGFILE; echo) >>$OBJ/failed-sshd.log |
| 267 | } |
| 268 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 269 | trace () |
| 270 | { |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 271 | start_debug_log $@ |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 272 | if [ "X$TEST_SSH_TRACE" = "Xyes" ]; then |
Damien Miller | da1e4bd | 2007-10-26 15:35:54 +1000 | [diff] [blame] | 273 | echo "$@" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 274 | fi |
| 275 | } |
| 276 | |
| 277 | verbose () |
| 278 | { |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 279 | start_debug_log $@ |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 280 | if [ "X$TEST_SSH_QUIET" != "Xyes" ]; then |
Damien Miller | da1e4bd | 2007-10-26 15:35:54 +1000 | [diff] [blame] | 281 | echo "$@" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 282 | fi |
| 283 | } |
| 284 | |
Damien Miller | 6efd94f | 2011-09-04 19:04:16 +1000 | [diff] [blame] | 285 | warn () |
| 286 | { |
| 287 | echo "WARNING: $@" >>$TEST_SSH_LOGFILE |
| 288 | echo "WARNING: $@" |
| 289 | } |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 290 | |
| 291 | fail () |
| 292 | { |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 293 | save_debug_log "FAIL: $@" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 294 | RESULT=1 |
Damien Miller | da1e4bd | 2007-10-26 15:35:54 +1000 | [diff] [blame] | 295 | echo "$@" |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 296 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | fatal () |
| 300 | { |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 301 | save_debug_log "FATAL: $@" |
Darren Tucker | 56347ef | 2013-05-17 13:28:36 +1000 | [diff] [blame] | 302 | printf "FATAL: " |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 303 | fail "$@" |
| 304 | cleanup |
| 305 | exit $RESULT |
| 306 | } |
| 307 | |
| 308 | RESULT=0 |
| 309 | PIDFILE=$OBJ/pidfile |
| 310 | |
| 311 | trap fatal 3 2 |
| 312 | |
| 313 | # create server config |
| 314 | cat << EOF > $OBJ/sshd_config |
Darren Tucker | 0e6868e | 2004-06-16 20:36:16 +1000 | [diff] [blame] | 315 | StrictModes no |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 316 | Port $PORT |
Darren Tucker | e23a79c | 2009-10-12 09:37:22 +1100 | [diff] [blame] | 317 | Protocol 2,1 |
Damien Miller | 76be6b8 | 2006-01-31 21:59:01 +1100 | [diff] [blame] | 318 | AddressFamily inet |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 319 | ListenAddress 127.0.0.1 |
| 320 | #ListenAddress ::1 |
| 321 | PidFile $PIDFILE |
| 322 | AuthorizedKeysFile $OBJ/authorized_keys_%u |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 323 | LogLevel DEBUG3 |
Darren Tucker | 4c37ef0 | 2004-06-16 20:08:56 +1000 | [diff] [blame] | 324 | AcceptEnv _XXX_TEST_* |
| 325 | AcceptEnv _XXX_TEST |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 326 | Subsystem sftp $SFTPSERVER |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 327 | EOF |
| 328 | |
Darren Tucker | 6223eea | 2004-06-23 09:25:02 +1000 | [diff] [blame] | 329 | if [ ! -z "$TEST_SSH_SSHD_CONFOPTS" ]; then |
| 330 | trace "adding sshd_config option $TEST_SSH_SSHD_CONFOPTS" |
| 331 | echo "$TEST_SSH_SSHD_CONFOPTS" >> $OBJ/sshd_config |
| 332 | fi |
| 333 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 334 | # server config for proxy connects |
| 335 | cp $OBJ/sshd_config $OBJ/sshd_proxy |
| 336 | |
| 337 | # allow group-writable directories in proxy-mode |
| 338 | echo 'StrictModes no' >> $OBJ/sshd_proxy |
| 339 | |
| 340 | # create client config |
| 341 | cat << EOF > $OBJ/ssh_config |
| 342 | Host * |
Darren Tucker | e23a79c | 2009-10-12 09:37:22 +1100 | [diff] [blame] | 343 | Protocol 2,1 |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 344 | Hostname 127.0.0.1 |
| 345 | HostKeyAlias localhost-with-alias |
| 346 | Port $PORT |
| 347 | User $USER |
| 348 | GlobalKnownHostsFile $OBJ/known_hosts |
| 349 | UserKnownHostsFile $OBJ/known_hosts |
| 350 | RSAAuthentication yes |
| 351 | PubkeyAuthentication yes |
| 352 | ChallengeResponseAuthentication no |
| 353 | HostbasedAuthentication no |
| 354 | PasswordAuthentication no |
Darren Tucker | 6f66981 | 2013-05-17 19:28:51 +1000 | [diff] [blame] | 355 | RhostsRSAAuthentication no |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 356 | BatchMode yes |
| 357 | StrictHostKeyChecking yes |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 358 | LogLevel DEBUG3 |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 359 | EOF |
| 360 | |
Darren Tucker | 6223eea | 2004-06-23 09:25:02 +1000 | [diff] [blame] | 361 | if [ ! -z "$TEST_SSH_SSH_CONFOPTS" ]; then |
| 362 | trace "adding ssh_config option $TEST_SSH_SSHD_CONFOPTS" |
| 363 | echo "$TEST_SSH_SSH_CONFOPTS" >> $OBJ/ssh_config |
| 364 | fi |
| 365 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 366 | rm -f $OBJ/known_hosts $OBJ/authorized_keys_$USER |
| 367 | |
| 368 | trace "generate keys" |
| 369 | for t in rsa rsa1; do |
| 370 | # generate user key |
Darren Tucker | acd2060 | 2013-08-08 17:02:12 +1000 | [diff] [blame] | 371 | if [ ! -f $OBJ/$t ] || [ ${SSHKEYGEN} -nt $OBJ/$t ]; then |
Darren Tucker | 7c8b1e7 | 2013-05-17 09:10:20 +1000 | [diff] [blame] | 372 | rm -f $OBJ/$t |
| 373 | ${SSHKEYGEN} -q -N '' -t $t -f $OBJ/$t ||\ |
| 374 | fail "ssh-keygen for $t failed" |
| 375 | fi |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 376 | |
| 377 | # known hosts file for client |
| 378 | ( |
Darren Tucker | 56347ef | 2013-05-17 13:28:36 +1000 | [diff] [blame] | 379 | printf 'localhost-with-alias,127.0.0.1,::1 ' |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 380 | cat $OBJ/$t.pub |
| 381 | ) >> $OBJ/known_hosts |
| 382 | |
| 383 | # setup authorized keys |
| 384 | cat $OBJ/$t.pub >> $OBJ/authorized_keys_$USER |
| 385 | echo IdentityFile $OBJ/$t >> $OBJ/ssh_config |
| 386 | |
| 387 | # use key as host key, too |
| 388 | $SUDO cp $OBJ/$t $OBJ/host.$t |
| 389 | echo HostKey $OBJ/host.$t >> $OBJ/sshd_config |
| 390 | |
| 391 | # don't use SUDO for proxy connect |
| 392 | echo HostKey $OBJ/$t >> $OBJ/sshd_proxy |
| 393 | done |
| 394 | chmod 644 $OBJ/authorized_keys_$USER |
| 395 | |
Damien Miller | 4268a13 | 2008-06-30 08:07:56 +1000 | [diff] [blame] | 396 | # Activate Twisted Conch tests if the binary is present |
| 397 | REGRESS_INTEROP_CONCH=no |
| 398 | if test -x "$CONCH" ; then |
| 399 | REGRESS_INTEROP_CONCH=yes |
| 400 | fi |
| 401 | |
Darren Tucker | d788b7c | 2008-06-10 23:15:54 +1000 | [diff] [blame] | 402 | # If PuTTY is present and we are running a PuTTY test, prepare keys and |
| 403 | # configuration |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 404 | REGRESS_INTEROP_PUTTY=no |
Darren Tucker | d8bafea | 2008-06-11 01:39:38 +1000 | [diff] [blame] | 405 | if test -x "$PUTTYGEN" -a -x "$PLINK" ; then |
Darren Tucker | 5f34664 | 2008-06-11 01:38:52 +1000 | [diff] [blame] | 406 | REGRESS_INTEROP_PUTTY=yes |
| 407 | fi |
| 408 | case "$SCRIPT" in |
| 409 | *putty*) ;; |
| 410 | *) REGRESS_INTEROP_PUTTY=no ;; |
| 411 | esac |
| 412 | |
| 413 | if test "$REGRESS_INTEROP_PUTTY" = "yes" ; then |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 414 | mkdir -p ${OBJ}/.putty |
| 415 | |
| 416 | # Add a PuTTY key to authorized_keys |
| 417 | rm -f ${OBJ}/putty.rsa2 |
| 418 | puttygen -t rsa -o ${OBJ}/putty.rsa2 < /dev/null > /dev/null |
| 419 | puttygen -O public-openssh ${OBJ}/putty.rsa2 \ |
| 420 | >> $OBJ/authorized_keys_$USER |
| 421 | |
| 422 | # Convert rsa2 host key to PuTTY format |
| 423 | ${SRC}/ssh2putty.sh 127.0.0.1 $PORT $OBJ/rsa > \ |
| 424 | ${OBJ}/.putty/sshhostkeys |
| 425 | ${SRC}/ssh2putty.sh 127.0.0.1 22 $OBJ/rsa >> \ |
| 426 | ${OBJ}/.putty/sshhostkeys |
| 427 | |
| 428 | # Setup proxied session |
| 429 | mkdir -p ${OBJ}/.putty/sessions |
| 430 | rm -f ${OBJ}/.putty/sessions/localhost_proxy |
| 431 | echo "Hostname=127.0.0.1" >> ${OBJ}/.putty/sessions/localhost_proxy |
| 432 | echo "PortNumber=$PORT" >> ${OBJ}/.putty/sessions/localhost_proxy |
| 433 | echo "ProxyMethod=5" >> ${OBJ}/.putty/sessions/localhost_proxy |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 434 | 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] | 435 | |
| 436 | REGRESS_INTEROP_PUTTY=yes |
| 437 | fi |
| 438 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 439 | # create a proxy version of the client config |
| 440 | ( |
| 441 | cat $OBJ/ssh_config |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 442 | 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] | 443 | ) > $OBJ/ssh_proxy |
| 444 | |
| 445 | # check proxy config |
| 446 | ${SSHD} -t -f $OBJ/sshd_proxy || fatal "sshd_proxy broken" |
| 447 | |
| 448 | start_sshd () |
| 449 | { |
| 450 | # start sshd |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 451 | $SUDO ${SSHD} -f $OBJ/sshd_config "$@" -t || fatal "sshd_config broken" |
Darren Tucker | dfea3bc | 2013-05-17 09:31:39 +1000 | [diff] [blame] | 452 | $SUDO ${SSHD} -f $OBJ/sshd_config "$@" -E$TEST_SSHD_LOGFILE |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 453 | |
| 454 | trace "wait for sshd" |
| 455 | i=0; |
Darren Tucker | 6d3921f | 2003-09-04 15:35:48 +1000 | [diff] [blame] | 456 | while [ ! -f $PIDFILE -a $i -lt 10 ]; do |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 457 | i=`expr $i + 1` |
| 458 | sleep $i |
| 459 | done |
| 460 | |
| 461 | test -f $PIDFILE || fatal "no sshd running on port $PORT" |
| 462 | } |
| 463 | |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 464 | # source test body |
| 465 | . $SCRIPT |
| 466 | |
| 467 | # kill sshd |
| 468 | cleanup |
| 469 | if [ $RESULT -eq 0 ]; then |
| 470 | verbose ok $tid |
| 471 | else |
| 472 | echo failed $tid |
| 473 | fi |
| 474 | exit $RESULT |