djm@openbsd.org | 0d1b241 | 2014-12-22 06:14:29 +0000 | [diff] [blame] | 1 | # $OpenBSD: multiplex.sh,v 1.27 2014/12/22 06:14:29 djm Exp $ |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 2 | # Placed in the Public Domain. |
| 3 | |
Darren Tucker | af34255 | 2005-04-25 17:01:26 +1000 | [diff] [blame] | 4 | CTL=/tmp/openssh.regress.ctl-sock.$$ |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 5 | |
| 6 | tid="connection multiplexing" |
| 7 | |
Damien Miller | 293cac5 | 2014-12-22 16:30:42 +1100 | [diff] [blame^] | 8 | NC=$OBJ/netcat |
Damien Miller | c8f610f | 2014-07-21 10:23:27 +1000 | [diff] [blame] | 9 | |
| 10 | trace "will use ProxyCommand $proxycmd" |
Damien Miller | 5849778 | 2011-01-17 16:17:09 +1100 | [diff] [blame] | 11 | if config_defined DISABLE_FD_PASSING ; then |
Darren Tucker | 2a81adc | 2004-08-29 17:09:34 +1000 | [diff] [blame] | 12 | echo "skipped (not supported on this platform)" |
| 13 | exit 0 |
| 14 | fi |
| 15 | |
Darren Tucker | a4df65b | 2013-05-17 09:37:31 +1000 | [diff] [blame] | 16 | P=3301 # test port |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 17 | |
Darren Tucker | ee4ad77 | 2012-10-05 12:04:10 +1000 | [diff] [blame] | 18 | wait_for_mux_master_ready() |
| 19 | { |
| 20 | for i in 1 2 3 4 5; do |
| 21 | ${SSH} -F $OBJ/ssh_config -S $CTL -Ocheck otherhost \ |
| 22 | >/dev/null 2>&1 && return 0 |
| 23 | sleep $i |
| 24 | done |
| 25 | fatal "mux master never becomes ready" |
| 26 | } |
| 27 | |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 28 | start_sshd |
| 29 | |
Darren Tucker | 40aaff7 | 2013-05-17 09:36:20 +1000 | [diff] [blame] | 30 | start_mux_master() |
| 31 | { |
| 32 | trace "start master, fork to background" |
Damien Miller | 5ea4fe0 | 2014-07-22 09:39:19 +1000 | [diff] [blame] | 33 | ${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost \ |
Darren Tucker | 40aaff7 | 2013-05-17 09:36:20 +1000 | [diff] [blame] | 34 | -E $TEST_REGRESS_LOGFILE 2>&1 & |
Damien Miller | 612f965 | 2014-07-09 13:22:03 +1000 | [diff] [blame] | 35 | # NB. $SSH_PID will be killed by test-exec.sh:cleanup on fatal errors. |
| 36 | SSH_PID=$! |
Darren Tucker | 40aaff7 | 2013-05-17 09:36:20 +1000 | [diff] [blame] | 37 | wait_for_mux_master_ready |
| 38 | } |
| 39 | |
| 40 | start_mux_master |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 41 | |
Damien Miller | e826a8c | 2004-06-18 01:23:03 +1000 | [diff] [blame] | 42 | verbose "test $tid: envpass" |
| 43 | trace "env passing over multiplexed connection" |
Darren Tucker | 7988553 | 2009-10-07 10:30:57 +1100 | [diff] [blame] | 44 | _XXX_TEST=blah ${SSH} -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" -S$CTL otherhost sh << 'EOF' |
Darren Tucker | 430c6a1 | 2004-06-22 13:38:56 +1000 | [diff] [blame] | 45 | test X"$_XXX_TEST" = X"blah" |
| 46 | EOF |
Damien Miller | e826a8c | 2004-06-18 01:23:03 +1000 | [diff] [blame] | 47 | if [ $? -ne 0 ]; then |
| 48 | fail "environment not found" |
| 49 | fi |
| 50 | |
| 51 | verbose "test $tid: transfer" |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 52 | rm -f ${COPY} |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 53 | trace "ssh transfer over multiplexed connection and check result" |
Darren Tucker | 7988553 | 2009-10-07 10:30:57 +1100 | [diff] [blame] | 54 | ${SSH} -F $OBJ/ssh_config -S$CTL otherhost cat ${DATA} > ${COPY} |
Darren Tucker | 3e86fc4 | 2004-06-17 16:34:02 +1000 | [diff] [blame] | 55 | test -f ${COPY} || fail "ssh -Sctl: failed copy ${DATA}" |
| 56 | cmp ${DATA} ${COPY} || fail "ssh -Sctl: corrupted copy of ${DATA}" |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 57 | |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 58 | rm -f ${COPY} |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 59 | trace "ssh transfer over multiplexed connection and check result" |
Darren Tucker | 7988553 | 2009-10-07 10:30:57 +1100 | [diff] [blame] | 60 | ${SSH} -F $OBJ/ssh_config -S $CTL otherhost cat ${DATA} > ${COPY} |
Darren Tucker | 3e86fc4 | 2004-06-17 16:34:02 +1000 | [diff] [blame] | 61 | test -f ${COPY} || fail "ssh -S ctl: failed copy ${DATA}" |
| 62 | cmp ${DATA} ${COPY} || fail "ssh -S ctl: corrupted copy of ${DATA}" |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 63 | |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 64 | rm -f ${COPY} |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 65 | trace "sftp transfer over multiplexed connection and check result" |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 66 | echo "get ${DATA} ${COPY}" | \ |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 67 | ${SFTP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost >>$TEST_REGRESS_LOGFILE 2>&1 |
Darren Tucker | 3e86fc4 | 2004-06-17 16:34:02 +1000 | [diff] [blame] | 68 | test -f ${COPY} || fail "sftp: failed copy ${DATA}" |
| 69 | cmp ${DATA} ${COPY} || fail "sftp: corrupted copy of ${DATA}" |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 70 | |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 71 | rm -f ${COPY} |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 72 | trace "scp transfer over multiplexed connection and check result" |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 73 | ${SCP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost:${DATA} ${COPY} >>$TEST_REGRESS_LOGFILE 2>&1 |
Darren Tucker | 3e86fc4 | 2004-06-17 16:34:02 +1000 | [diff] [blame] | 74 | test -f ${COPY} || fail "scp: failed copy ${DATA}" |
| 75 | cmp ${DATA} ${COPY} || fail "scp: corrupted copy of ${DATA}" |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 76 | |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 77 | rm -f ${COPY} |
Damien Miller | 0e4e955 | 2014-07-21 09:52:54 +1000 | [diff] [blame] | 78 | verbose "test $tid: forward" |
| 79 | trace "forward over TCP/IP and check result" |
Damien Miller | 293cac5 | 2014-12-22 16:30:42 +1100 | [diff] [blame^] | 80 | $NC -N -l 127.0.0.1 $((${PORT} + 1)) < ${DATA} > /dev/null & |
Damien Miller | 0e4e955 | 2014-07-21 09:52:54 +1000 | [diff] [blame] | 81 | netcat_pid=$! |
| 82 | ${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -L127.0.0.1:$((${PORT} + 2)):127.0.0.1:$((${PORT} + 1)) otherhost >>$TEST_SSH_LOGFILE 2>&1 |
Damien Miller | 293cac5 | 2014-12-22 16:30:42 +1100 | [diff] [blame^] | 83 | $NC 127.0.0.1 $((${PORT} + 2)) < /dev/null > ${COPY} |
Damien Miller | 0e4e955 | 2014-07-21 09:52:54 +1000 | [diff] [blame] | 84 | cmp ${DATA} ${COPY} || fail "ssh: corrupted copy of ${DATA}" |
| 85 | kill $netcat_pid 2>/dev/null |
| 86 | rm -f ${COPY} $OBJ/unix-[123].fwd |
| 87 | |
| 88 | trace "forward over UNIX and check result" |
Damien Miller | 293cac5 | 2014-12-22 16:30:42 +1100 | [diff] [blame^] | 89 | $NC -N -Ul $OBJ/unix-1.fwd < ${DATA} > /dev/null & |
Damien Miller | 0e4e955 | 2014-07-21 09:52:54 +1000 | [diff] [blame] | 90 | netcat_pid=$! |
| 91 | ${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -L$OBJ/unix-2.fwd:$OBJ/unix-1.fwd otherhost >>$TEST_SSH_LOGFILE 2>&1 |
| 92 | ${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -R$OBJ/unix-3.fwd:$OBJ/unix-2.fwd otherhost >>$TEST_SSH_LOGFILE 2>&1 |
Damien Miller | 293cac5 | 2014-12-22 16:30:42 +1100 | [diff] [blame^] | 93 | $NC -U $OBJ/unix-3.fwd < /dev/null > ${COPY} |
Damien Miller | 0e4e955 | 2014-07-21 09:52:54 +1000 | [diff] [blame] | 94 | cmp ${DATA} ${COPY} || fail "ssh: corrupted copy of ${DATA}" |
| 95 | kill $netcat_pid 2>/dev/null |
| 96 | rm -f ${COPY} $OBJ/unix-[123].fwd |
Darren Tucker | ddea13d | 2004-06-17 16:27:43 +1000 | [diff] [blame] | 97 | |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 98 | for s in 0 1 4 5 44; do |
| 99 | trace "exit status $s over multiplexed connection" |
| 100 | verbose "test $tid: status $s" |
Darren Tucker | 7988553 | 2009-10-07 10:30:57 +1100 | [diff] [blame] | 101 | ${SSH} -F $OBJ/ssh_config -S $CTL otherhost exit $s |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 102 | r=$? |
| 103 | if [ $r -ne $s ]; then |
| 104 | fail "exit code mismatch for protocol $p: $r != $s" |
| 105 | fi |
| 106 | |
| 107 | # same with early close of stdout/err |
| 108 | trace "exit status $s with early close over multiplexed connection" |
Darren Tucker | 7988553 | 2009-10-07 10:30:57 +1100 | [diff] [blame] | 109 | ${SSH} -F $OBJ/ssh_config -S $CTL -n otherhost \ |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 110 | exec sh -c \'"sleep 2; exec > /dev/null 2>&1; sleep 3; exit $s"\' |
| 111 | r=$? |
| 112 | if [ $r -ne $s ]; then |
| 113 | fail "exit code (with sleep) mismatch for protocol $p: $r != $s" |
| 114 | fi |
| 115 | done |
| 116 | |
Darren Tucker | 9b2c036 | 2012-10-05 11:45:39 +1000 | [diff] [blame] | 117 | verbose "test $tid: cmd check" |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 118 | ${SSH} -F $OBJ/ssh_config -S $CTL -Ocheck otherhost >>$TEST_REGRESS_LOGFILE 2>&1 \ |
Darren Tucker | 9b2c036 | 2012-10-05 11:45:39 +1000 | [diff] [blame] | 119 | || fail "check command failed" |
Darren Tucker | 79ec66e | 2004-12-06 23:12:15 +1100 | [diff] [blame] | 120 | |
Damien Miller | 0e4e955 | 2014-07-21 09:52:54 +1000 | [diff] [blame] | 121 | verbose "test $tid: cmd forward local (TCP)" |
Darren Tucker | a4df65b | 2013-05-17 09:37:31 +1000 | [diff] [blame] | 122 | ${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -L $P:localhost:$PORT otherhost \ |
| 123 | || fail "request local forward failed" |
| 124 | ${SSH} -F $OBJ/ssh_config -p$P otherhost true \ |
| 125 | || fail "connect to local forward port failed" |
| 126 | ${SSH} -F $OBJ/ssh_config -S $CTL -Ocancel -L $P:localhost:$PORT otherhost \ |
| 127 | || fail "cancel local forward failed" |
| 128 | ${SSH} -F $OBJ/ssh_config -p$P otherhost true \ |
| 129 | && fail "local forward port still listening" |
| 130 | |
Damien Miller | 0e4e955 | 2014-07-21 09:52:54 +1000 | [diff] [blame] | 131 | verbose "test $tid: cmd forward remote (TCP)" |
Darren Tucker | a4df65b | 2013-05-17 09:37:31 +1000 | [diff] [blame] | 132 | ${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -R $P:localhost:$PORT otherhost \ |
| 133 | || fail "request remote forward failed" |
| 134 | ${SSH} -F $OBJ/ssh_config -p$P otherhost true \ |
| 135 | || fail "connect to remote forwarded port failed" |
| 136 | ${SSH} -F $OBJ/ssh_config -S $CTL -Ocancel -R $P:localhost:$PORT otherhost \ |
| 137 | || fail "cancel remote forward failed" |
| 138 | ${SSH} -F $OBJ/ssh_config -p$P otherhost true \ |
| 139 | && fail "remote forward port still listening" |
| 140 | |
Damien Miller | 0e4e955 | 2014-07-21 09:52:54 +1000 | [diff] [blame] | 141 | verbose "test $tid: cmd forward local (UNIX)" |
| 142 | ${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -L $OBJ/unix-1.fwd:localhost:$PORT otherhost \ |
| 143 | || fail "request local forward failed" |
Damien Miller | c8f610f | 2014-07-21 10:23:27 +1000 | [diff] [blame] | 144 | echo "" | $NC -U $OBJ/unix-1.fwd | grep "Protocol mismatch" >/dev/null 2>&1 \ |
Damien Miller | 0e4e955 | 2014-07-21 09:52:54 +1000 | [diff] [blame] | 145 | || fail "connect to local forward path failed" |
| 146 | ${SSH} -F $OBJ/ssh_config -S $CTL -Ocancel -L $OBJ/unix-1.fwd:localhost:$PORT otherhost \ |
| 147 | || fail "cancel local forward failed" |
Damien Miller | 04f4824 | 2014-07-22 11:31:47 +1000 | [diff] [blame] | 148 | N=$(echo "xyzzy" | $NC -U $OBJ/unix-1.fwd 2>&1 | grep "xyzzy" | wc -l) |
Damien Miller | 0e4e955 | 2014-07-21 09:52:54 +1000 | [diff] [blame] | 149 | test ${N} -eq 0 || fail "local forward path still listening" |
| 150 | rm -f $OBJ/unix-1.fwd |
| 151 | |
| 152 | verbose "test $tid: cmd forward remote (UNIX)" |
| 153 | ${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -R $OBJ/unix-1.fwd:localhost:$PORT otherhost \ |
| 154 | || fail "request remote forward failed" |
Damien Miller | c8f610f | 2014-07-21 10:23:27 +1000 | [diff] [blame] | 155 | echo "" | $NC -U $OBJ/unix-1.fwd | grep "Protocol mismatch" >/dev/null 2>&1 \ |
Damien Miller | 0e4e955 | 2014-07-21 09:52:54 +1000 | [diff] [blame] | 156 | || fail "connect to remote forwarded path failed" |
| 157 | ${SSH} -F $OBJ/ssh_config -S $CTL -Ocancel -R $OBJ/unix-1.fwd:localhost:$PORT otherhost \ |
| 158 | || fail "cancel remote forward failed" |
Damien Miller | 04f4824 | 2014-07-22 11:31:47 +1000 | [diff] [blame] | 159 | N=$(echo "xyzzy" | $NC -U $OBJ/unix-1.fwd 2>&1 | grep "xyzzy" | wc -l) |
Damien Miller | 56b840f | 2014-07-25 08:11:30 +1000 | [diff] [blame] | 160 | test ${N} -eq 0 || fail "remote forward path still listening" |
Damien Miller | 0e4e955 | 2014-07-21 09:52:54 +1000 | [diff] [blame] | 161 | rm -f $OBJ/unix-1.fwd |
| 162 | |
Darren Tucker | 9b2c036 | 2012-10-05 11:45:39 +1000 | [diff] [blame] | 163 | verbose "test $tid: cmd exit" |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 164 | ${SSH} -F $OBJ/ssh_config -S $CTL -Oexit otherhost >>$TEST_REGRESS_LOGFILE 2>&1 \ |
Darren Tucker | 9b2c036 | 2012-10-05 11:45:39 +1000 | [diff] [blame] | 165 | || fail "send exit command failed" |
Darren Tucker | 79ec66e | 2004-12-06 23:12:15 +1100 | [diff] [blame] | 166 | |
| 167 | # Wait for master to exit |
Damien Miller | 612f965 | 2014-07-09 13:22:03 +1000 | [diff] [blame] | 168 | wait $SSH_PID |
| 169 | kill -0 $SSH_PID >/dev/null 2>&1 && fail "exit command failed" |
Darren Tucker | 6fc5aa8 | 2012-10-05 11:43:57 +1000 | [diff] [blame] | 170 | |
| 171 | # Restart master and test -O stop command with master using -N |
Darren Tucker | ee4ad77 | 2012-10-05 12:04:10 +1000 | [diff] [blame] | 172 | verbose "test $tid: cmd stop" |
| 173 | trace "restart master, fork to background" |
Darren Tucker | 40aaff7 | 2013-05-17 09:36:20 +1000 | [diff] [blame] | 174 | start_mux_master |
Darren Tucker | ee4ad77 | 2012-10-05 12:04:10 +1000 | [diff] [blame] | 175 | |
| 176 | # start a long-running command then immediately request a stop |
| 177 | ${SSH} -F $OBJ/ssh_config -S $CTL otherhost "sleep 10; exit 0" \ |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 178 | >>$TEST_REGRESS_LOGFILE 2>&1 & |
Darren Tucker | 9b2c036 | 2012-10-05 11:45:39 +1000 | [diff] [blame] | 179 | SLEEP_PID=$! |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 180 | ${SSH} -F $OBJ/ssh_config -S $CTL -Ostop otherhost >>$TEST_REGRESS_LOGFILE 2>&1 \ |
Darren Tucker | 9b2c036 | 2012-10-05 11:45:39 +1000 | [diff] [blame] | 181 | || fail "send stop command failed" |
Darren Tucker | ee4ad77 | 2012-10-05 12:04:10 +1000 | [diff] [blame] | 182 | |
| 183 | # wait until both long-running command and master have exited. |
Darren Tucker | 9b2c036 | 2012-10-05 11:45:39 +1000 | [diff] [blame] | 184 | wait $SLEEP_PID |
Darren Tucker | ee4ad77 | 2012-10-05 12:04:10 +1000 | [diff] [blame] | 185 | [ $! != 0 ] || fail "waiting for concurrent command" |
Damien Miller | 612f965 | 2014-07-09 13:22:03 +1000 | [diff] [blame] | 186 | wait $SSH_PID |
Darren Tucker | ee4ad77 | 2012-10-05 12:04:10 +1000 | [diff] [blame] | 187 | [ $! != 0 ] || fail "waiting for master stop" |
Damien Miller | 612f965 | 2014-07-09 13:22:03 +1000 | [diff] [blame] | 188 | kill -0 $SSH_PID >/dev/null 2>&1 && fatal "stop command failed" |
| 189 | SSH_PID="" # Already gone, so don't kill in cleanup |
| 190 | |