blob: dbf2025be9af36657869b600d176cef9ff865882 [file] [log] [blame]
Darren Tucker430c6a12004-06-22 13:38:56 +10001# $OpenBSD: multiplex.sh,v 1.8 2004/06/22 03:12:13 markus Exp $
Darren Tuckere7d05832004-06-16 20:22:22 +10002# Placed in the Public Domain.
3
4CTL=$OBJ/ctl-sock
5
6tid="connection multiplexing"
7
Darren Tucker10e7f192004-06-17 16:36:27 +10008DATA=/bin/ls${EXEEXT}
Darren Tuckerffaa6a52004-06-17 16:32:45 +10009COPY=$OBJ/ls.copy
10
Darren Tuckere7d05832004-06-16 20:22:22 +100011start_sshd
12
13trace "start master, fork to background"
Darren Tucker430c6a12004-06-22 13:38:56 +100014${SSH} -2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" -f somehost sleep 120
Darren Tuckere7d05832004-06-16 20:22:22 +100015
Damien Millere826a8c2004-06-18 01:23:03 +100016verbose "test $tid: envpass"
17trace "env passing over multiplexed connection"
Darren Tucker430c6a12004-06-22 13:38:56 +100018_XXX_TEST=blah ${SSH} -oSendEnv="_XXX_TEST" -S$CTL otherhost sh << 'EOF'
19 test X"$_XXX_TEST" = X"blah"
20EOF
Damien Millere826a8c2004-06-18 01:23:03 +100021if [ $? -ne 0 ]; then
22 fail "environment not found"
23fi
24
25verbose "test $tid: transfer"
Darren Tuckerffaa6a52004-06-17 16:32:45 +100026rm -f ${COPY}
Darren Tuckere7d05832004-06-16 20:22:22 +100027trace "ssh transfer over multiplexed connection and check result"
Darren Tuckerffaa6a52004-06-17 16:32:45 +100028${SSH} -S$CTL otherhost cat ${DATA} > ${COPY}
Darren Tucker3e86fc42004-06-17 16:34:02 +100029test -f ${COPY} || fail "ssh -Sctl: failed copy ${DATA}"
30cmp ${DATA} ${COPY} || fail "ssh -Sctl: corrupted copy of ${DATA}"
Darren Tuckere7d05832004-06-16 20:22:22 +100031
Darren Tuckerffaa6a52004-06-17 16:32:45 +100032rm -f ${COPY}
Darren Tuckere7d05832004-06-16 20:22:22 +100033trace "ssh transfer over multiplexed connection and check result"
Darren Tuckerffaa6a52004-06-17 16:32:45 +100034${SSH} -S $CTL otherhost cat ${DATA} > ${COPY}
Darren Tucker3e86fc42004-06-17 16:34:02 +100035test -f ${COPY} || fail "ssh -S ctl: failed copy ${DATA}"
36cmp ${DATA} ${COPY} || fail "ssh -S ctl: corrupted copy of ${DATA}"
Darren Tuckere7d05832004-06-16 20:22:22 +100037
Darren Tuckerffaa6a52004-06-17 16:32:45 +100038rm -f ${COPY}
Darren Tuckere7d05832004-06-16 20:22:22 +100039trace "sftp transfer over multiplexed connection and check result"
Darren Tuckerffaa6a52004-06-17 16:32:45 +100040echo "get ${DATA} ${COPY}" | \
Darren Tucker6288dc12004-06-18 16:25:35 +100041 ${SFTP} -S ${SSH} -oControlPath=$CTL otherhost >/dev/null 2>&1
Darren Tucker3e86fc42004-06-17 16:34:02 +100042test -f ${COPY} || fail "sftp: failed copy ${DATA}"
43cmp ${DATA} ${COPY} || fail "sftp: corrupted copy of ${DATA}"
Darren Tuckere7d05832004-06-16 20:22:22 +100044
Darren Tuckerffaa6a52004-06-17 16:32:45 +100045rm -f ${COPY}
Darren Tuckere7d05832004-06-16 20:22:22 +100046trace "scp transfer over multiplexed connection and check result"
Darren Tucker6288dc12004-06-18 16:25:35 +100047${SCP} -S ${SSH} -oControlPath=$CTL otherhost:${DATA} ${COPY} >/dev/null 2>&1
Darren Tucker3e86fc42004-06-17 16:34:02 +100048test -f ${COPY} || fail "scp: failed copy ${DATA}"
49cmp ${DATA} ${COPY} || fail "scp: corrupted copy of ${DATA}"
Darren Tuckere7d05832004-06-16 20:22:22 +100050
Darren Tuckerffaa6a52004-06-17 16:32:45 +100051rm -f ${COPY}
Darren Tuckerddea13d2004-06-17 16:27:43 +100052
Darren Tuckere7d05832004-06-16 20:22:22 +100053for s in 0 1 4 5 44; do
54 trace "exit status $s over multiplexed connection"
55 verbose "test $tid: status $s"
56 ${SSH} -S $CTL otherhost exit $s
57 r=$?
58 if [ $r -ne $s ]; then
59 fail "exit code mismatch for protocol $p: $r != $s"
60 fi
61
62 # same with early close of stdout/err
63 trace "exit status $s with early close over multiplexed connection"
64 ${SSH} -S $CTL -n otherhost \
65 exec sh -c \'"sleep 2; exec > /dev/null 2>&1; sleep 3; exit $s"\'
66 r=$?
67 if [ $r -ne $s ]; then
68 fail "exit code (with sleep) mismatch for protocol $p: $r != $s"
69 fi
70done
71
Darren Tuckerddea13d2004-06-17 16:27:43 +100072# kill master, remove control socket. ssh -MS will exit when sleep exits
73$SUDO kill `cat $PIDFILE`
74rm -f $CTL