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