• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#	$OpenBSD: multiplex.sh,v 1.12 2009/05/05 07:51:36 dtucker 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
15LOG=$TEST_SSH_LOGFILE
16
17start_sshd
18
19trace "start master, fork to background"
20${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost &
21MASTER_PID=$!
22
23# Wait for master to start and authenticate
24sleep 5
25
26verbose "test $tid: envpass"
27trace "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"
30EOF
31if [ $? -ne 0 ]; then
32	fail "environment not found"
33fi
34
35verbose "test $tid: transfer"
36rm -f ${COPY}
37trace "ssh transfer over multiplexed connection and check result"
38${SSH} -F $OBJ/ssh_config -S$CTL otherhost cat ${DATA} > ${COPY}
39test -f ${COPY}			|| fail "ssh -Sctl: failed copy ${DATA}"
40cmp ${DATA} ${COPY}		|| fail "ssh -Sctl: corrupted copy of ${DATA}"
41
42rm -f ${COPY}
43trace "ssh transfer over multiplexed connection and check result"
44${SSH} -F $OBJ/ssh_config -S $CTL otherhost cat ${DATA} > ${COPY}
45test -f ${COPY}			|| fail "ssh -S ctl: failed copy ${DATA}"
46cmp ${DATA} ${COPY}		|| fail "ssh -S ctl: corrupted copy of ${DATA}"
47
48rm -f ${COPY}
49trace "sftp transfer over multiplexed connection and check result"
50echo "get ${DATA} ${COPY}" | \
51	${SFTP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost >$LOG 2>&1
52test -f ${COPY}			|| fail "sftp: failed copy ${DATA}"
53cmp ${DATA} ${COPY}		|| fail "sftp: corrupted copy of ${DATA}"
54
55rm -f ${COPY}
56trace "scp transfer over multiplexed connection and check result"
57${SCP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost:${DATA} ${COPY} >$LOG 2>&1
58test -f ${COPY}			|| fail "scp: failed copy ${DATA}"
59cmp ${DATA} ${COPY}		|| fail "scp: corrupted copy of ${DATA}"
60
61rm -f ${COPY}
62
63for 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
80done
81
82trace "test check command"
83${SSH} -F $OBJ/ssh_config -S $CTL -Ocheck otherhost || fail "check command failed"
84
85trace "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
89sleep 2
90
91kill -0 $MASTER_PID >/dev/null 2>&1 && fail "exit command failed"
92