1 # $OpenBSD: multiplex.sh,v 1.13 2012/06/01 00:47:36 djm 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)"
18 trace "start master, fork to background"
19 ${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost &
22 # Wait for master to start and authenticate
25 verbose "test $tid: envpass"
26 trace "env passing over multiplexed connection"
27 _XXX_TEST=blah ${SSH} -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" -S$CTL otherhost sh << 'EOF'
28 test X"$_XXX_TEST" = X"blah"
31 fail "environment not found"
34 verbose "test $tid: transfer"
36 trace "ssh transfer over multiplexed connection and check result"
37 ${SSH} -F $OBJ/ssh_config -S$CTL otherhost cat ${DATA} > ${COPY}
38 test -f ${COPY} || fail "ssh -Sctl: failed copy ${DATA}"
39 cmp ${DATA} ${COPY} || fail "ssh -Sctl: corrupted copy of ${DATA}"
42 trace "ssh transfer over multiplexed connection and check result"
43 ${SSH} -F $OBJ/ssh_config -S $CTL otherhost cat ${DATA} > ${COPY}
44 test -f ${COPY} || fail "ssh -S ctl: failed copy ${DATA}"
45 cmp ${DATA} ${COPY} || fail "ssh -S ctl: corrupted copy of ${DATA}"
48 trace "sftp transfer over multiplexed connection and check result"
49 echo "get ${DATA} ${COPY}" | \
50 ${SFTP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost >>$TEST_SSH_LOGFILE 2>&1
51 test -f ${COPY} || fail "sftp: failed copy ${DATA}"
52 cmp ${DATA} ${COPY} || fail "sftp: corrupted copy of ${DATA}"
55 trace "scp transfer over multiplexed connection and check result"
56 ${SCP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost:${DATA} ${COPY} >>$TEST_SSH_LOGFILE 2>&1
57 test -f ${COPY} || fail "scp: failed copy ${DATA}"
58 cmp ${DATA} ${COPY} || fail "scp: corrupted copy of ${DATA}"
62 for s in 0 1 4 5 44; do
63 trace "exit status $s over multiplexed connection"
64 verbose "test $tid: status $s"
65 ${SSH} -F $OBJ/ssh_config -S $CTL otherhost exit $s
67 if [ $r -ne $s ]; then
68 fail "exit code mismatch for protocol $p: $r != $s"
71 # same with early close of stdout/err
72 trace "exit status $s with early close over multiplexed connection"
73 ${SSH} -F $OBJ/ssh_config -S $CTL -n otherhost \
74 exec sh -c \'"sleep 2; exec > /dev/null 2>&1; sleep 3; exit $s"\'
76 if [ $r -ne $s ]; then
77 fail "exit code (with sleep) mismatch for protocol $p: $r != $s"
81 trace "test check command"
82 ${SSH} -F $OBJ/ssh_config -S $CTL -Ocheck otherhost || fail "check command failed"
84 trace "test exit command"
85 ${SSH} -F $OBJ/ssh_config -S $CTL -Oexit otherhost || fail "send exit command failed"
87 # Wait for master to exit
90 kill -0 $MASTER_PID >/dev/null 2>&1 && fail "exit command failed"