1 # $OpenBSD: multiplex.sh,v 1.9 2004/11/07 00:32:41 djm Exp $
2 # Placed in the Public Domain.
6 tid="connection multiplexing"
8 if grep "#define.*DISABLE_FD_PASSING" ${BUILDDIR}/config.h >/dev/null 2>&1
10 echo "skipped (not supported on this platform)"
19 trace "start master, fork to background"
20 ${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost &
23 # Wait for master to start and authenticate
26 verbose "test $tid: envpass"
27 trace "env passing over multiplexed connection"
28 _XXX_TEST=blah ${SSH} -oSendEnv="_XXX_TEST" -S$CTL otherhost sh << 'EOF'
29 test X"$_XXX_TEST" = X"blah"
32 fail "environment not found"
35 verbose "test $tid: transfer"
37 trace "ssh transfer over multiplexed connection and check result"
38 ${SSH} -S$CTL otherhost cat ${DATA} > ${COPY}
39 test -f ${COPY} || fail "ssh -Sctl: failed copy ${DATA}"
40 cmp ${DATA} ${COPY} || fail "ssh -Sctl: corrupted copy of ${DATA}"
43 trace "ssh transfer over multiplexed connection and check result"
44 ${SSH} -S $CTL otherhost cat ${DATA} > ${COPY}
45 test -f ${COPY} || fail "ssh -S ctl: failed copy ${DATA}"
46 cmp ${DATA} ${COPY} || fail "ssh -S ctl: corrupted copy of ${DATA}"
49 trace "sftp transfer over multiplexed connection and check result"
50 echo "get ${DATA} ${COPY}" | \
51 ${SFTP} -S ${SSH} -oControlPath=$CTL otherhost >/dev/null 2>&1
52 test -f ${COPY} || fail "sftp: failed copy ${DATA}"
53 cmp ${DATA} ${COPY} || fail "sftp: corrupted copy of ${DATA}"
56 trace "scp transfer over multiplexed connection and check result"
57 ${SCP} -S ${SSH} -oControlPath=$CTL otherhost:${DATA} ${COPY} >/dev/null 2>&1
58 test -f ${COPY} || fail "scp: failed copy ${DATA}"
59 cmp ${DATA} ${COPY} || fail "scp: corrupted copy of ${DATA}"
63 for s in 0 1 4 5 44; do
64 trace "exit status $s over multiplexed connection"
65 verbose "test $tid: status $s"
66 ${SSH} -S $CTL otherhost exit $s
68 if [ $r -ne $s ]; then
69 fail "exit code mismatch for protocol $p: $r != $s"
72 # same with early close of stdout/err
73 trace "exit status $s with early close over multiplexed connection"
74 ${SSH} -S $CTL -n otherhost \
75 exec sh -c \'"sleep 2; exec > /dev/null 2>&1; sleep 3; exit $s"\'
77 if [ $r -ne $s ]; then
78 fail "exit code (with sleep) mismatch for protocol $p: $r != $s"
82 trace "test check command"
83 ${SSH} -S $CTL -Ocheck otherhost || fail "check command failed"
85 trace "test exit command"
86 ${SSH} -S $CTL -Oexit otherhost || fail "send exit command failed"
88 # Wait for master to exit
91 ps -p $MASTER_PID >/dev/null && fail "exit command failed"