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