1 # $OpenBSD: multiplex.sh,v 1.21 2013/05/17 04:29:14 dtucker Exp $
2 # Placed in the Public Domain.
4 CTL=/tmp/openssh.regress.ctl-sock.$$
6 tid="connection multiplexing"
8 if config_defined DISABLE_FD_PASSING ; then
9 echo "skipped (not supported on this platform)"
15 wait_for_mux_master_ready()
17 for i in 1 2 3 4 5; do
18 ${SSH} -F $OBJ/ssh_config -S $CTL -Ocheck otherhost \
19 >/dev/null 2>&1 && return 0
22 fatal "mux master never becomes ready"
29 trace "start master, fork to background"
30 ${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost \
31 -E $TEST_REGRESS_LOGFILE 2>&1 &
33 wait_for_mux_master_ready
38 verbose "test $tid: envpass"
39 trace "env passing over multiplexed connection"
40 _XXX_TEST=blah ${SSH} -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" -S$CTL otherhost sh << 'EOF'
41 test X"$_XXX_TEST" = X"blah"
44 fail "environment not found"
47 verbose "test $tid: transfer"
49 trace "ssh transfer over multiplexed connection and check result"
50 ${SSH} -F $OBJ/ssh_config -S$CTL otherhost cat ${DATA} > ${COPY}
51 test -f ${COPY} || fail "ssh -Sctl: failed copy ${DATA}"
52 cmp ${DATA} ${COPY} || fail "ssh -Sctl: corrupted copy of ${DATA}"
55 trace "ssh transfer over multiplexed connection and check result"
56 ${SSH} -F $OBJ/ssh_config -S $CTL otherhost cat ${DATA} > ${COPY}
57 test -f ${COPY} || fail "ssh -S ctl: failed copy ${DATA}"
58 cmp ${DATA} ${COPY} || fail "ssh -S ctl: corrupted copy of ${DATA}"
61 trace "sftp transfer over multiplexed connection and check result"
62 echo "get ${DATA} ${COPY}" | \
63 ${SFTP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost >>$TEST_REGRESS_LOGFILE 2>&1
64 test -f ${COPY} || fail "sftp: failed copy ${DATA}"
65 cmp ${DATA} ${COPY} || fail "sftp: corrupted copy of ${DATA}"
68 trace "scp transfer over multiplexed connection and check result"
69 ${SCP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost:${DATA} ${COPY} >>$TEST_REGRESS_LOGFILE 2>&1
70 test -f ${COPY} || fail "scp: failed copy ${DATA}"
71 cmp ${DATA} ${COPY} || fail "scp: corrupted copy of ${DATA}"
75 for s in 0 1 4 5 44; do
76 trace "exit status $s over multiplexed connection"
77 verbose "test $tid: status $s"
78 ${SSH} -F $OBJ/ssh_config -S $CTL otherhost exit $s
80 if [ $r -ne $s ]; then
81 fail "exit code mismatch for protocol $p: $r != $s"
84 # same with early close of stdout/err
85 trace "exit status $s with early close over multiplexed connection"
86 ${SSH} -F $OBJ/ssh_config -S $CTL -n otherhost \
87 exec sh -c \'"sleep 2; exec > /dev/null 2>&1; sleep 3; exit $s"\'
89 if [ $r -ne $s ]; then
90 fail "exit code (with sleep) mismatch for protocol $p: $r != $s"
94 verbose "test $tid: cmd check"
95 ${SSH} -F $OBJ/ssh_config -S $CTL -Ocheck otherhost >>$TEST_REGRESS_LOGFILE 2>&1 \
96 || fail "check command failed"
98 verbose "test $tid: cmd forward local"
99 ${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -L $P:localhost:$PORT otherhost \
100 || fail "request local forward failed"
101 ${SSH} -F $OBJ/ssh_config -p$P otherhost true \
102 || fail "connect to local forward port failed"
103 ${SSH} -F $OBJ/ssh_config -S $CTL -Ocancel -L $P:localhost:$PORT otherhost \
104 || fail "cancel local forward failed"
105 ${SSH} -F $OBJ/ssh_config -p$P otherhost true \
106 && fail "local forward port still listening"
108 verbose "test $tid: cmd forward remote"
109 ${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -R $P:localhost:$PORT otherhost \
110 || fail "request remote forward failed"
111 ${SSH} -F $OBJ/ssh_config -p$P otherhost true \
112 || fail "connect to remote forwarded port failed"
113 ${SSH} -F $OBJ/ssh_config -S $CTL -Ocancel -R $P:localhost:$PORT otherhost \
114 || fail "cancel remote forward failed"
115 ${SSH} -F $OBJ/ssh_config -p$P otherhost true \
116 && fail "remote forward port still listening"
118 verbose "test $tid: cmd exit"
119 ${SSH} -F $OBJ/ssh_config -S $CTL -Oexit otherhost >>$TEST_REGRESS_LOGFILE 2>&1 \
120 || fail "send exit command failed"
122 # Wait for master to exit
124 kill -0 $MASTER_PID >/dev/null 2>&1 && fail "exit command failed"
126 # Restart master and test -O stop command with master using -N
127 verbose "test $tid: cmd stop"
128 trace "restart master, fork to background"
131 # start a long-running command then immediately request a stop
132 ${SSH} -F $OBJ/ssh_config -S $CTL otherhost "sleep 10; exit 0" \
133 >>$TEST_REGRESS_LOGFILE 2>&1 &
135 ${SSH} -F $OBJ/ssh_config -S $CTL -Ostop otherhost >>$TEST_REGRESS_LOGFILE 2>&1 \
136 || fail "send stop command failed"
138 # wait until both long-running command and master have exited.
140 [ $! != 0 ] || fail "waiting for concurrent command"
142 [ $! != 0 ] || fail "waiting for master stop"
143 kill -0 $MASTER_PID >/dev/null 2>&1 && fail "stop command failed"