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