Darren Tucker | 430c6a1 | 2004-06-22 13:38:56 +1000 | [diff] [blame] | 1 | # $OpenBSD: multiplex.sh,v 1.8 2004/06/22 03:12:13 markus Exp $ |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 2 | # Placed in the Public Domain. |
| 3 | |
| 4 | CTL=$OBJ/ctl-sock |
| 5 | |
| 6 | tid="connection multiplexing" |
| 7 | |
Darren Tucker | 10e7f19 | 2004-06-17 16:36:27 +1000 | [diff] [blame] | 8 | DATA=/bin/ls${EXEEXT} |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 9 | COPY=$OBJ/ls.copy |
| 10 | |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 11 | start_sshd |
| 12 | |
| 13 | trace "start master, fork to background" |
Darren Tucker | 430c6a1 | 2004-06-22 13:38:56 +1000 | [diff] [blame] | 14 | ${SSH} -2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" -f somehost sleep 120 |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 15 | |
Damien Miller | e826a8c | 2004-06-18 01:23:03 +1000 | [diff] [blame] | 16 | verbose "test $tid: envpass" |
| 17 | trace "env passing over multiplexed connection" |
Darren Tucker | 430c6a1 | 2004-06-22 13:38:56 +1000 | [diff] [blame] | 18 | _XXX_TEST=blah ${SSH} -oSendEnv="_XXX_TEST" -S$CTL otherhost sh << 'EOF' |
| 19 | test X"$_XXX_TEST" = X"blah" |
| 20 | EOF |
Damien Miller | e826a8c | 2004-06-18 01:23:03 +1000 | [diff] [blame] | 21 | if [ $? -ne 0 ]; then |
| 22 | fail "environment not found" |
| 23 | fi |
| 24 | |
| 25 | verbose "test $tid: transfer" |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 26 | rm -f ${COPY} |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 27 | trace "ssh transfer over multiplexed connection and check result" |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 28 | ${SSH} -S$CTL otherhost cat ${DATA} > ${COPY} |
Darren Tucker | 3e86fc4 | 2004-06-17 16:34:02 +1000 | [diff] [blame] | 29 | test -f ${COPY} || fail "ssh -Sctl: failed copy ${DATA}" |
| 30 | cmp ${DATA} ${COPY} || fail "ssh -Sctl: corrupted copy of ${DATA}" |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 31 | |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 32 | rm -f ${COPY} |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 33 | trace "ssh transfer over multiplexed connection and check result" |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 34 | ${SSH} -S $CTL otherhost cat ${DATA} > ${COPY} |
Darren Tucker | 3e86fc4 | 2004-06-17 16:34:02 +1000 | [diff] [blame] | 35 | test -f ${COPY} || fail "ssh -S ctl: failed copy ${DATA}" |
| 36 | cmp ${DATA} ${COPY} || fail "ssh -S ctl: corrupted copy of ${DATA}" |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 37 | |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 38 | rm -f ${COPY} |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 39 | trace "sftp transfer over multiplexed connection and check result" |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 40 | echo "get ${DATA} ${COPY}" | \ |
Darren Tucker | 6288dc1 | 2004-06-18 16:25:35 +1000 | [diff] [blame] | 41 | ${SFTP} -S ${SSH} -oControlPath=$CTL otherhost >/dev/null 2>&1 |
Darren Tucker | 3e86fc4 | 2004-06-17 16:34:02 +1000 | [diff] [blame] | 42 | test -f ${COPY} || fail "sftp: failed copy ${DATA}" |
| 43 | cmp ${DATA} ${COPY} || fail "sftp: corrupted copy of ${DATA}" |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 44 | |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 45 | rm -f ${COPY} |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 46 | trace "scp transfer over multiplexed connection and check result" |
Darren Tucker | 6288dc1 | 2004-06-18 16:25:35 +1000 | [diff] [blame] | 47 | ${SCP} -S ${SSH} -oControlPath=$CTL otherhost:${DATA} ${COPY} >/dev/null 2>&1 |
Darren Tucker | 3e86fc4 | 2004-06-17 16:34:02 +1000 | [diff] [blame] | 48 | test -f ${COPY} || fail "scp: failed copy ${DATA}" |
| 49 | cmp ${DATA} ${COPY} || fail "scp: corrupted copy of ${DATA}" |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 50 | |
Darren Tucker | ffaa6a5 | 2004-06-17 16:32:45 +1000 | [diff] [blame] | 51 | rm -f ${COPY} |
Darren Tucker | ddea13d | 2004-06-17 16:27:43 +1000 | [diff] [blame] | 52 | |
Darren Tucker | e7d0583 | 2004-06-16 20:22:22 +1000 | [diff] [blame] | 53 | for 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 |
| 70 | done |
| 71 | |
Darren Tucker | ddea13d | 2004-06-17 16:27:43 +1000 | [diff] [blame] | 72 | # kill master, remove control socket. ssh -MS will exit when sleep exits |
| 73 | $SUDO kill `cat $PIDFILE` |
| 74 | rm -f $CTL |