1# $OpenBSD: multiplex.sh,v 1.11 2005/04/25 09:54:09 dtucker Exp $ 2# Placed in the Public Domain. 3 4CTL=/tmp/openssh.regress.ctl-sock.$$ 5 6tid="connection multiplexing" 7 8if grep "#define.*DISABLE_FD_PASSING" ${BUILDDIR}/config.h >/dev/null 2>&1 9then 10 echo "skipped (not supported on this platform)" 11 exit 0 12fi 13 14DATA=/bin/ls${EXEEXT} 15COPY=$OBJ/ls.copy 16LOG=$TEST_SSH_LOGFILE 17 18start_sshd 19 20trace "start master, fork to background" 21${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost & 22MASTER_PID=$! 23 24# Wait for master to start and authenticate 25sleep 5 26 27verbose "test $tid: envpass" 28trace "env passing over multiplexed connection" 29_XXX_TEST=blah ${SSH} -oSendEnv="_XXX_TEST" -S$CTL otherhost sh << 'EOF' 30 test X"$_XXX_TEST" = X"blah" 31EOF 32if [ $? -ne 0 ]; then 33 fail "environment not found" 34fi 35 36verbose "test $tid: transfer" 37rm -f ${COPY} 38trace "ssh transfer over multiplexed connection and check result" 39${SSH} -S$CTL otherhost cat ${DATA} > ${COPY} 40test -f ${COPY} || fail "ssh -Sctl: failed copy ${DATA}" 41cmp ${DATA} ${COPY} || fail "ssh -Sctl: corrupted copy of ${DATA}" 42 43rm -f ${COPY} 44trace "ssh transfer over multiplexed connection and check result" 45${SSH} -S $CTL otherhost cat ${DATA} > ${COPY} 46test -f ${COPY} || fail "ssh -S ctl: failed copy ${DATA}" 47cmp ${DATA} ${COPY} || fail "ssh -S ctl: corrupted copy of ${DATA}" 48 49rm -f ${COPY} 50trace "sftp transfer over multiplexed connection and check result" 51echo "get ${DATA} ${COPY}" | \ 52 ${SFTP} -S ${SSH} -oControlPath=$CTL otherhost >$LOG 2>&1 53test -f ${COPY} || fail "sftp: failed copy ${DATA}" 54cmp ${DATA} ${COPY} || fail "sftp: corrupted copy of ${DATA}" 55 56rm -f ${COPY} 57trace "scp transfer over multiplexed connection and check result" 58${SCP} -S ${SSH} -oControlPath=$CTL otherhost:${DATA} ${COPY} >$LOG 2>&1 59test -f ${COPY} || fail "scp: failed copy ${DATA}" 60cmp ${DATA} ${COPY} || fail "scp: corrupted copy of ${DATA}" 61 62rm -f ${COPY} 63 64for s in 0 1 4 5 44; do 65 trace "exit status $s over multiplexed connection" 66 verbose "test $tid: status $s" 67 ${SSH} -S $CTL otherhost exit $s 68 r=$? 69 if [ $r -ne $s ]; then 70 fail "exit code mismatch for protocol $p: $r != $s" 71 fi 72 73 # same with early close of stdout/err 74 trace "exit status $s with early close over multiplexed connection" 75 ${SSH} -S $CTL -n otherhost \ 76 exec sh -c \'"sleep 2; exec > /dev/null 2>&1; sleep 3; exit $s"\' 77 r=$? 78 if [ $r -ne $s ]; then 79 fail "exit code (with sleep) mismatch for protocol $p: $r != $s" 80 fi 81done 82 83trace "test check command" 84${SSH} -S $CTL -Ocheck otherhost || fail "check command failed" 85 86trace "test exit command" 87${SSH} -S $CTL -Oexit otherhost || fail "send exit command failed" 88 89# Wait for master to exit 90sleep 2 91 92kill -0 $MASTER_PID >/dev/null 2>&1 && fail "exit command failed" 93