Darren Tucker | 40aaff7 | 2013-05-17 09:36:20 +1000 | [diff] [blame^] | 1 | # $OpenBSD: multiplex.sh,v 1.19 2013/04/22 07:23:08 dtucker 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 | 5849778 | 2011-01-17 16:17:09 +1100 | [diff] [blame] | 8 | if config_defined DISABLE_FD_PASSING ; then |
Darren Tucker | 2a81adc | 2004-08-29 17:09:34 +1000 | [diff] [blame] | 9 | echo "skipped (not supported on this platform)" |
| 10 | exit 0 |
| 11 | fi |
| 12 | |
Darren Tucker | 10e7f19 | 2004-06-17 16:36:27 +1000 | [diff] [blame] | 13 | DATA=/bin/ls${EXEEXT} |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 14 | COPY=$OBJ/ls.copy |
| 15 | |
Darren Tucker | ee4ad77 | 2012-10-05 12:04:10 +1000 | [diff] [blame] | 16 | wait_for_mux_master_ready() |
| 17 | { |
| 18 | for i in 1 2 3 4 5; do |
| 19 | ${SSH} -F $OBJ/ssh_config -S $CTL -Ocheck otherhost \ |
| 20 | >/dev/null 2>&1 && return 0 |
| 21 | sleep $i |
| 22 | done |
| 23 | fatal "mux master never becomes ready" |
| 24 | } |
| 25 | |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 26 | start_sshd |
| 27 | |
Darren Tucker | 40aaff7 | 2013-05-17 09:36:20 +1000 | [diff] [blame^] | 28 | start_mux_master() |
| 29 | { |
| 30 | trace "start master, fork to background" |
| 31 | ${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost \ |
| 32 | -E $TEST_REGRESS_LOGFILE 2>&1 & |
| 33 | MASTER_PID=$! |
| 34 | wait_for_mux_master_ready |
| 35 | } |
| 36 | |
| 37 | start_mux_master |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 38 | |
Damien Miller | e826a8c | 2004-06-18 01:23:03 +1000 | [diff] [blame] | 39 | verbose "test $tid: envpass" |
| 40 | trace "env passing over multiplexed connection" |
Darren Tucker | 7988553 | 2009-10-07 10:30:57 +1100 | [diff] [blame] | 41 | _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] | 42 | test X"$_XXX_TEST" = X"blah" |
| 43 | EOF |
Damien Miller | e826a8c | 2004-06-18 01:23:03 +1000 | [diff] [blame] | 44 | if [ $? -ne 0 ]; then |
| 45 | fail "environment not found" |
| 46 | fi |
| 47 | |
| 48 | verbose "test $tid: transfer" |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 49 | rm -f ${COPY} |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 50 | trace "ssh transfer over multiplexed connection and check result" |
Darren Tucker | 7988553 | 2009-10-07 10:30:57 +1100 | [diff] [blame] | 51 | ${SSH} -F $OBJ/ssh_config -S$CTL otherhost cat ${DATA} > ${COPY} |
Darren Tucker | 3e86fc4 | 2004-06-17 16:34:02 +1000 | [diff] [blame] | 52 | test -f ${COPY} || fail "ssh -Sctl: failed copy ${DATA}" |
| 53 | cmp ${DATA} ${COPY} || fail "ssh -Sctl: corrupted copy of ${DATA}" |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 54 | |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 55 | rm -f ${COPY} |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 56 | trace "ssh transfer over multiplexed connection and check result" |
Darren Tucker | 7988553 | 2009-10-07 10:30:57 +1100 | [diff] [blame] | 57 | ${SSH} -F $OBJ/ssh_config -S $CTL otherhost cat ${DATA} > ${COPY} |
Darren Tucker | 3e86fc4 | 2004-06-17 16:34:02 +1000 | [diff] [blame] | 58 | test -f ${COPY} || fail "ssh -S ctl: failed copy ${DATA}" |
| 59 | cmp ${DATA} ${COPY} || fail "ssh -S ctl: corrupted copy of ${DATA}" |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 60 | |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 61 | rm -f ${COPY} |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 62 | trace "sftp transfer over multiplexed connection and check result" |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 63 | echo "get ${DATA} ${COPY}" | \ |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 64 | ${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] | 65 | test -f ${COPY} || fail "sftp: failed copy ${DATA}" |
| 66 | cmp ${DATA} ${COPY} || fail "sftp: corrupted copy of ${DATA}" |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 67 | |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 68 | rm -f ${COPY} |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 69 | trace "scp transfer over multiplexed connection and check result" |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 70 | ${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] | 71 | test -f ${COPY} || fail "scp: failed copy ${DATA}" |
| 72 | cmp ${DATA} ${COPY} || fail "scp: corrupted copy of ${DATA}" |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 73 | |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 74 | rm -f ${COPY} |
Darren Tucker | ddea13d | 2004-06-17 16:27:43 +1000 | [diff] [blame] | 75 | |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 76 | for s in 0 1 4 5 44; do |
| 77 | trace "exit status $s over multiplexed connection" |
| 78 | verbose "test $tid: status $s" |
Darren Tucker | 7988553 | 2009-10-07 10:30:57 +1100 | [diff] [blame] | 79 | ${SSH} -F $OBJ/ssh_config -S $CTL otherhost exit $s |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 80 | r=$? |
| 81 | if [ $r -ne $s ]; then |
| 82 | fail "exit code mismatch for protocol $p: $r != $s" |
| 83 | fi |
| 84 | |
| 85 | # same with early close of stdout/err |
| 86 | trace "exit status $s with early close over multiplexed connection" |
Darren Tucker | 7988553 | 2009-10-07 10:30:57 +1100 | [diff] [blame] | 87 | ${SSH} -F $OBJ/ssh_config -S $CTL -n otherhost \ |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 88 | exec sh -c \'"sleep 2; exec > /dev/null 2>&1; sleep 3; exit $s"\' |
| 89 | r=$? |
| 90 | if [ $r -ne $s ]; then |
| 91 | fail "exit code (with sleep) mismatch for protocol $p: $r != $s" |
| 92 | fi |
| 93 | done |
| 94 | |
Darren Tucker | 9b2c036 | 2012-10-05 11:45:39 +1000 | [diff] [blame] | 95 | verbose "test $tid: cmd check" |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 96 | ${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] | 97 | || fail "check command failed" |
Darren Tucker | 79ec66e | 2004-12-06 23:12:15 +1100 | [diff] [blame] | 98 | |
Darren Tucker | 9b2c036 | 2012-10-05 11:45:39 +1000 | [diff] [blame] | 99 | verbose "test $tid: cmd exit" |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 100 | ${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] | 101 | || fail "send exit command failed" |
Darren Tucker | 79ec66e | 2004-12-06 23:12:15 +1100 | [diff] [blame] | 102 | |
| 103 | # Wait for master to exit |
Darren Tucker | ee4ad77 | 2012-10-05 12:04:10 +1000 | [diff] [blame] | 104 | wait $MASTER_PID |
Damien Miller | d27a026 | 2012-12-03 10:06:37 +1100 | [diff] [blame] | 105 | kill -0 $MASTER_PID >/dev/null 2>&1 && fail "exit command failed" |
Darren Tucker | 6fc5aa8 | 2012-10-05 11:43:57 +1000 | [diff] [blame] | 106 | |
| 107 | # Restart master and test -O stop command with master using -N |
Darren Tucker | ee4ad77 | 2012-10-05 12:04:10 +1000 | [diff] [blame] | 108 | verbose "test $tid: cmd stop" |
| 109 | trace "restart master, fork to background" |
Darren Tucker | 40aaff7 | 2013-05-17 09:36:20 +1000 | [diff] [blame^] | 110 | start_mux_master |
Darren Tucker | ee4ad77 | 2012-10-05 12:04:10 +1000 | [diff] [blame] | 111 | |
| 112 | # start a long-running command then immediately request a stop |
| 113 | ${SSH} -F $OBJ/ssh_config -S $CTL otherhost "sleep 10; exit 0" \ |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 114 | >>$TEST_REGRESS_LOGFILE 2>&1 & |
Darren Tucker | 9b2c036 | 2012-10-05 11:45:39 +1000 | [diff] [blame] | 115 | SLEEP_PID=$! |
Darren Tucker | 7512902 | 2013-05-17 09:19:10 +1000 | [diff] [blame] | 116 | ${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] | 117 | || fail "send stop command failed" |
Darren Tucker | ee4ad77 | 2012-10-05 12:04:10 +1000 | [diff] [blame] | 118 | |
| 119 | # wait until both long-running command and master have exited. |
Darren Tucker | 9b2c036 | 2012-10-05 11:45:39 +1000 | [diff] [blame] | 120 | wait $SLEEP_PID |
Darren Tucker | ee4ad77 | 2012-10-05 12:04:10 +1000 | [diff] [blame] | 121 | [ $! != 0 ] || fail "waiting for concurrent command" |
| 122 | wait $MASTER_PID |
| 123 | [ $! != 0 ] || fail "waiting for master stop" |
Damien Miller | d27a026 | 2012-12-03 10:06:37 +1100 | [diff] [blame] | 124 | kill -0 $MASTER_PID >/dev/null 2>&1 && fail "stop command failed" |