multiplex.sh revision 180720
11590Srgrimes#	$OpenBSD: multiplex.sh,v 1.11 2005/04/25 09:54:09 dtucker Exp $
21590Srgrimes#	Placed in the Public Domain.
31590Srgrimes
41590SrgrimesCTL=/tmp/openssh.regress.ctl-sock.$$
51590Srgrimes
61590Srgrimestid="connection multiplexing"
71590Srgrimes
81590Srgrimesif grep "#define.*DISABLE_FD_PASSING" ${BUILDDIR}/config.h >/dev/null 2>&1
91590Srgrimesthen
101590Srgrimes	echo "skipped (not supported on this platform)"
111590Srgrimes	exit 0
121590Srgrimesfi
131590Srgrimes
141590SrgrimesDATA=/bin/ls${EXEEXT}
151590SrgrimesCOPY=$OBJ/ls.copy
161590SrgrimesLOG=$TEST_SSH_LOGFILE
171590Srgrimes
181590Srgrimesstart_sshd
191590Srgrimes
201590Srgrimestrace "start master, fork to background"
211590Srgrimes${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost &
221590SrgrimesMASTER_PID=$!
231590Srgrimes
241590Srgrimes# Wait for master to start and authenticate
251590Srgrimessleep 5
261590Srgrimes
271590Srgrimesverbose "test $tid: envpass"
281590Srgrimestrace "env passing over multiplexed connection"
291590Srgrimes_XXX_TEST=blah ${SSH} -oSendEnv="_XXX_TEST" -S$CTL otherhost sh << 'EOF'
301590Srgrimes	test X"$_XXX_TEST" = X"blah"
311590SrgrimesEOF
321590Srgrimesif [ $? -ne 0 ]; then
331590Srgrimes	fail "environment not found"
341590Srgrimesfi
351590Srgrimes
361590Srgrimesverbose "test $tid: transfer"
371590Srgrimesrm -f ${COPY}
381590Srgrimestrace "ssh transfer over multiplexed connection and check result"
391590Srgrimes${SSH} -S$CTL otherhost cat ${DATA} > ${COPY}
401590Srgrimestest -f ${COPY}			|| fail "ssh -Sctl: failed copy ${DATA}" 
411590Srgrimescmp ${DATA} ${COPY}		|| fail "ssh -Sctl: corrupted copy of ${DATA}"
421590Srgrimes
431590Srgrimesrm -f ${COPY}
4461575Srobertotrace "ssh transfer over multiplexed connection and check result"
4523695Speter${SSH} -S $CTL otherhost cat ${DATA} > ${COPY}
4661575Srobertotest -f ${COPY}			|| fail "ssh -S ctl: failed copy ${DATA}" 
4761575Srobertocmp ${DATA} ${COPY}		|| fail "ssh -S ctl: corrupted copy of ${DATA}"
4861575Sroberto
4961575Srobertorm -f ${COPY}
501590Srgrimestrace "sftp transfer over multiplexed connection and check result"
511590Srgrimesecho "get ${DATA} ${COPY}" | \
521590Srgrimes	${SFTP} -S ${SSH} -oControlPath=$CTL otherhost >$LOG 2>&1
531590Srgrimestest -f ${COPY}			|| fail "sftp: failed copy ${DATA}" 
541590Srgrimescmp ${DATA} ${COPY}		|| fail "sftp: corrupted copy of ${DATA}"
551590Srgrimes
561590Srgrimesrm -f ${COPY}
571590Srgrimestrace "scp transfer over multiplexed connection and check result"
581590Srgrimes${SCP} -S ${SSH} -oControlPath=$CTL otherhost:${DATA} ${COPY} >$LOG 2>&1
5917534Sachetest -f ${COPY}			|| fail "scp: failed copy ${DATA}" 
6072945Sknucmp ${DATA} ${COPY}		|| fail "scp: corrupted copy of ${DATA}"
611590Srgrimes
621590Srgrimesrm -f ${COPY}
631590Srgrimes
6423695Speterfor s in 0 1 4 5 44; do
651590Srgrimes	trace "exit status $s over multiplexed connection"
661590Srgrimes	verbose "test $tid: status $s"
671590Srgrimes	${SSH} -S $CTL otherhost exit $s
681590Srgrimes	r=$?
691590Srgrimes	if [ $r -ne $s ]; then
701590Srgrimes		fail "exit code mismatch for protocol $p: $r != $s"
711590Srgrimes	fi
721590Srgrimes
731590Srgrimes	# same with early close of stdout/err
7441399Sbde	trace "exit status $s with early close over multiplexed connection"
751590Srgrimes	${SSH} -S $CTL -n otherhost \
7661575Sroberto                exec sh -c \'"sleep 2; exec > /dev/null 2>&1; sleep 3; exit $s"\'
7772945Sknu	r=$?
781590Srgrimes	if [ $r -ne $s ]; then
7992786Smarkm		fail "exit code (with sleep) mismatch for protocol $p: $r != $s"
801590Srgrimes	fi
811590Srgrimesdone
821590Srgrimes
831590Srgrimestrace "test check command"
841590Srgrimes${SSH} -S $CTL -Ocheck otherhost || fail "check command failed" 
851590Srgrimes
8691400Sdwmalonetrace "test exit command"
8725942Sjdp${SSH} -S $CTL -Oexit otherhost || fail "send exit command failed" 
881590Srgrimes
8917534Sache# Wait for master to exit
9017534Sachesleep 2
911590Srgrimes
921590Srgrimeskill -0 $MASTER_PID >/dev/null 2>&1 && fail "exit command failed" 
931590Srgrimes