2023-03-01 10:29:32 +01:00
|
|
|
# $OpenBSD: multiplex.sh,v 1.36 2023/03/01 09:29:32 dtucker Exp $
|
2004-06-16 12:22:22 +02:00
|
|
|
# Placed in the Public Domain.
|
|
|
|
|
2018-07-20 06:53:42 +02:00
|
|
|
make_tmpdir
|
|
|
|
CTL=${SSH_REGRESS_TMP}/ctl-sock
|
2004-06-16 12:22:22 +02:00
|
|
|
|
|
|
|
tid="connection multiplexing"
|
|
|
|
|
2014-07-21 02:23:27 +02:00
|
|
|
trace "will use ProxyCommand $proxycmd"
|
2011-01-17 06:17:09 +01:00
|
|
|
if config_defined DISABLE_FD_PASSING ; then
|
2004-08-29 09:09:34 +02:00
|
|
|
echo "skipped (not supported on this platform)"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2013-05-17 01:37:31 +02:00
|
|
|
P=3301 # test port
|
2004-06-17 08:32:45 +02:00
|
|
|
|
2012-10-05 04:04:10 +02:00
|
|
|
wait_for_mux_master_ready()
|
|
|
|
{
|
2020-01-25 01:27:56 +01:00
|
|
|
for i in 1 2 3 4 5 6 7 8 9; do
|
2012-10-05 04:04:10 +02:00
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -Ocheck otherhost \
|
|
|
|
>/dev/null 2>&1 && return 0
|
|
|
|
sleep $i
|
|
|
|
done
|
|
|
|
fatal "mux master never becomes ready"
|
|
|
|
}
|
|
|
|
|
2023-01-13 05:47:34 +01:00
|
|
|
maybe_add_scp_path_to_sshd
|
2004-06-16 12:22:22 +02:00
|
|
|
start_sshd
|
|
|
|
|
2013-05-17 01:36:20 +02:00
|
|
|
start_mux_master()
|
|
|
|
{
|
|
|
|
trace "start master, fork to background"
|
2014-07-22 01:39:19 +02:00
|
|
|
${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost \
|
2013-05-17 01:36:20 +02:00
|
|
|
-E $TEST_REGRESS_LOGFILE 2>&1 &
|
2014-07-09 05:22:03 +02:00
|
|
|
# NB. $SSH_PID will be killed by test-exec.sh:cleanup on fatal errors.
|
|
|
|
SSH_PID=$!
|
2013-05-17 01:36:20 +02:00
|
|
|
wait_for_mux_master_ready
|
|
|
|
}
|
|
|
|
|
|
|
|
start_mux_master
|
2004-06-16 12:22:22 +02:00
|
|
|
|
2022-06-03 06:31:54 +02:00
|
|
|
verbose "test $tid: setenv"
|
|
|
|
trace "setenv over multiplexed connection"
|
2009-10-07 01:30:57 +02:00
|
|
|
_XXX_TEST=blah ${SSH} -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" -S$CTL otherhost sh << 'EOF'
|
2004-06-22 05:38:56 +02:00
|
|
|
test X"$_XXX_TEST" = X"blah"
|
|
|
|
EOF
|
2004-06-17 17:23:03 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
fail "environment not found"
|
|
|
|
fi
|
|
|
|
|
2022-06-03 06:31:54 +02:00
|
|
|
verbose "test $tid: envpass"
|
|
|
|
trace "env passing over multiplexed connection"
|
|
|
|
${SSH} -F $OBJ/ssh_config -oSetEnv="_XXX_TEST=foo" -S$CTL otherhost sh << 'EOF'
|
|
|
|
test X"$_XXX_TEST" = X"foo"
|
|
|
|
EOF
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
fail "environment not found"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2004-06-17 17:23:03 +02:00
|
|
|
verbose "test $tid: transfer"
|
2004-06-17 08:32:45 +02:00
|
|
|
rm -f ${COPY}
|
2004-06-16 12:22:22 +02:00
|
|
|
trace "ssh transfer over multiplexed connection and check result"
|
2009-10-07 01:30:57 +02:00
|
|
|
${SSH} -F $OBJ/ssh_config -S$CTL otherhost cat ${DATA} > ${COPY}
|
2004-06-17 08:34:02 +02:00
|
|
|
test -f ${COPY} || fail "ssh -Sctl: failed copy ${DATA}"
|
|
|
|
cmp ${DATA} ${COPY} || fail "ssh -Sctl: corrupted copy of ${DATA}"
|
2004-06-16 12:22:22 +02:00
|
|
|
|
2004-06-17 08:32:45 +02:00
|
|
|
rm -f ${COPY}
|
2004-06-16 12:22:22 +02:00
|
|
|
trace "ssh transfer over multiplexed connection and check result"
|
2009-10-07 01:30:57 +02:00
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL otherhost cat ${DATA} > ${COPY}
|
2004-06-17 08:34:02 +02:00
|
|
|
test -f ${COPY} || fail "ssh -S ctl: failed copy ${DATA}"
|
|
|
|
cmp ${DATA} ${COPY} || fail "ssh -S ctl: corrupted copy of ${DATA}"
|
2004-06-16 12:22:22 +02:00
|
|
|
|
2004-06-17 08:32:45 +02:00
|
|
|
rm -f ${COPY}
|
2004-06-16 12:22:22 +02:00
|
|
|
trace "sftp transfer over multiplexed connection and check result"
|
2004-06-17 08:32:45 +02:00
|
|
|
echo "get ${DATA} ${COPY}" | \
|
2013-05-17 01:19:10 +02:00
|
|
|
${SFTP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost >>$TEST_REGRESS_LOGFILE 2>&1
|
2004-06-17 08:34:02 +02:00
|
|
|
test -f ${COPY} || fail "sftp: failed copy ${DATA}"
|
|
|
|
cmp ${DATA} ${COPY} || fail "sftp: corrupted copy of ${DATA}"
|
2004-06-16 12:22:22 +02:00
|
|
|
|
2004-06-17 08:32:45 +02:00
|
|
|
rm -f ${COPY}
|
2004-06-16 12:22:22 +02:00
|
|
|
trace "scp transfer over multiplexed connection and check result"
|
2013-05-17 01:19:10 +02:00
|
|
|
${SCP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost:${DATA} ${COPY} >>$TEST_REGRESS_LOGFILE 2>&1
|
2004-06-17 08:34:02 +02:00
|
|
|
test -f ${COPY} || fail "scp: failed copy ${DATA}"
|
|
|
|
cmp ${DATA} ${COPY} || fail "scp: corrupted copy of ${DATA}"
|
2004-06-16 12:22:22 +02:00
|
|
|
|
2004-06-17 08:32:45 +02:00
|
|
|
rm -f ${COPY}
|
2014-07-21 01:52:54 +02:00
|
|
|
verbose "test $tid: forward"
|
|
|
|
trace "forward over TCP/IP and check result"
|
2023-03-01 10:29:32 +01:00
|
|
|
$NC -N -l 127.0.0.1 $((${PORT} + 1)) < ${DATA} >`ssh_logfile nc` &
|
2014-07-21 01:52:54 +02:00
|
|
|
netcat_pid=$!
|
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -L127.0.0.1:$((${PORT} + 2)):127.0.0.1:$((${PORT} + 1)) otherhost >>$TEST_SSH_LOGFILE 2>&1
|
2019-07-05 06:03:13 +02:00
|
|
|
sleep 1 # XXX remove once race fixed
|
2014-12-22 06:30:42 +01:00
|
|
|
$NC 127.0.0.1 $((${PORT} + 2)) < /dev/null > ${COPY}
|
2014-07-21 01:52:54 +02:00
|
|
|
cmp ${DATA} ${COPY} || fail "ssh: corrupted copy of ${DATA}"
|
|
|
|
kill $netcat_pid 2>/dev/null
|
|
|
|
rm -f ${COPY} $OBJ/unix-[123].fwd
|
|
|
|
|
|
|
|
trace "forward over UNIX and check result"
|
2014-12-22 06:30:42 +01:00
|
|
|
$NC -N -Ul $OBJ/unix-1.fwd < ${DATA} > /dev/null &
|
2014-07-21 01:52:54 +02:00
|
|
|
netcat_pid=$!
|
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -L$OBJ/unix-2.fwd:$OBJ/unix-1.fwd otherhost >>$TEST_SSH_LOGFILE 2>&1
|
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -R$OBJ/unix-3.fwd:$OBJ/unix-2.fwd otherhost >>$TEST_SSH_LOGFILE 2>&1
|
2019-07-05 06:03:13 +02:00
|
|
|
sleep 1 # XXX remove once race fixed
|
2019-07-05 06:58:57 +02:00
|
|
|
$NC -U $OBJ/unix-3.fwd < /dev/null > ${COPY}
|
2014-07-21 01:52:54 +02:00
|
|
|
cmp ${DATA} ${COPY} || fail "ssh: corrupted copy of ${DATA}"
|
|
|
|
kill $netcat_pid 2>/dev/null
|
|
|
|
rm -f ${COPY} $OBJ/unix-[123].fwd
|
2004-06-17 08:27:43 +02:00
|
|
|
|
2004-06-16 12:22:22 +02:00
|
|
|
for s in 0 1 4 5 44; do
|
2020-06-24 17:16:23 +02:00
|
|
|
for mode in "" "-Oproxy"; do
|
|
|
|
trace "exit status $s over multiplexed connection ($mode)"
|
|
|
|
verbose "test $tid: status $s ($mode)"
|
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL $mode otherhost exit $s
|
2004-06-16 12:22:22 +02:00
|
|
|
r=$?
|
|
|
|
if [ $r -ne $s ]; then
|
2017-05-01 01:34:55 +02:00
|
|
|
fail "exit code mismatch: $r != $s"
|
2004-06-16 12:22:22 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# same with early close of stdout/err
|
2020-06-24 17:16:23 +02:00
|
|
|
trace "exit status $s with early close over multiplexed connection ($mode)"
|
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -n $mode otherhost \
|
2004-06-16 12:22:22 +02:00
|
|
|
exec sh -c \'"sleep 2; exec > /dev/null 2>&1; sleep 3; exit $s"\'
|
|
|
|
r=$?
|
|
|
|
if [ $r -ne $s ]; then
|
2017-05-01 01:34:55 +02:00
|
|
|
fail "exit code (with sleep) mismatch: $r != $s"
|
2004-06-16 12:22:22 +02:00
|
|
|
fi
|
2020-06-24 17:16:23 +02:00
|
|
|
done
|
2004-06-16 12:22:22 +02:00
|
|
|
done
|
|
|
|
|
2012-10-05 03:45:39 +02:00
|
|
|
verbose "test $tid: cmd check"
|
2013-05-17 01:19:10 +02:00
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -Ocheck otherhost >>$TEST_REGRESS_LOGFILE 2>&1 \
|
2012-10-05 03:45:39 +02:00
|
|
|
|| fail "check command failed"
|
2004-12-06 13:12:15 +01:00
|
|
|
|
2014-07-21 01:52:54 +02:00
|
|
|
verbose "test $tid: cmd forward local (TCP)"
|
2013-05-17 01:37:31 +02:00
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -L $P:localhost:$PORT otherhost \
|
|
|
|
|| fail "request local forward failed"
|
2019-07-05 06:03:13 +02:00
|
|
|
sleep 1 # XXX remove once race fixed
|
2013-05-17 01:37:31 +02:00
|
|
|
${SSH} -F $OBJ/ssh_config -p$P otherhost true \
|
|
|
|
|| fail "connect to local forward port failed"
|
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -Ocancel -L $P:localhost:$PORT otherhost \
|
|
|
|
|| fail "cancel local forward failed"
|
|
|
|
${SSH} -F $OBJ/ssh_config -p$P otherhost true \
|
|
|
|
&& fail "local forward port still listening"
|
|
|
|
|
2014-07-21 01:52:54 +02:00
|
|
|
verbose "test $tid: cmd forward remote (TCP)"
|
2013-05-17 01:37:31 +02:00
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -R $P:localhost:$PORT otherhost \
|
|
|
|
|| fail "request remote forward failed"
|
2019-07-05 06:03:13 +02:00
|
|
|
sleep 1 # XXX remove once race fixed
|
2013-05-17 01:37:31 +02:00
|
|
|
${SSH} -F $OBJ/ssh_config -p$P otherhost true \
|
|
|
|
|| fail "connect to remote forwarded port failed"
|
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -Ocancel -R $P:localhost:$PORT otherhost \
|
|
|
|
|| fail "cancel remote forward failed"
|
|
|
|
${SSH} -F $OBJ/ssh_config -p$P otherhost true \
|
|
|
|
&& fail "remote forward port still listening"
|
|
|
|
|
2014-07-21 01:52:54 +02:00
|
|
|
verbose "test $tid: cmd forward local (UNIX)"
|
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -L $OBJ/unix-1.fwd:localhost:$PORT otherhost \
|
|
|
|
|| fail "request local forward failed"
|
2019-07-05 06:03:13 +02:00
|
|
|
sleep 1 # XXX remove once race fixed
|
2019-01-01 23:20:16 +01:00
|
|
|
echo "" | $NC -U $OBJ/unix-1.fwd | \
|
|
|
|
grep "Invalid SSH identification string" >/dev/null 2>&1 \
|
2014-07-21 01:52:54 +02:00
|
|
|
|| fail "connect to local forward path failed"
|
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -Ocancel -L $OBJ/unix-1.fwd:localhost:$PORT otherhost \
|
|
|
|
|| fail "cancel local forward failed"
|
2014-07-22 03:31:47 +02:00
|
|
|
N=$(echo "xyzzy" | $NC -U $OBJ/unix-1.fwd 2>&1 | grep "xyzzy" | wc -l)
|
2014-07-21 01:52:54 +02:00
|
|
|
test ${N} -eq 0 || fail "local forward path still listening"
|
|
|
|
rm -f $OBJ/unix-1.fwd
|
|
|
|
|
|
|
|
verbose "test $tid: cmd forward remote (UNIX)"
|
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -Oforward -R $OBJ/unix-1.fwd:localhost:$PORT otherhost \
|
|
|
|
|| fail "request remote forward failed"
|
2019-07-05 06:03:13 +02:00
|
|
|
sleep 1 # XXX remove once race fixed
|
2019-01-01 23:20:16 +01:00
|
|
|
echo "" | $NC -U $OBJ/unix-1.fwd | \
|
|
|
|
grep "Invalid SSH identification string" >/dev/null 2>&1 \
|
2014-07-21 01:52:54 +02:00
|
|
|
|| fail "connect to remote forwarded path failed"
|
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -Ocancel -R $OBJ/unix-1.fwd:localhost:$PORT otherhost \
|
|
|
|
|| fail "cancel remote forward failed"
|
2014-07-22 03:31:47 +02:00
|
|
|
N=$(echo "xyzzy" | $NC -U $OBJ/unix-1.fwd 2>&1 | grep "xyzzy" | wc -l)
|
2014-07-25 00:11:30 +02:00
|
|
|
test ${N} -eq 0 || fail "remote forward path still listening"
|
2014-07-21 01:52:54 +02:00
|
|
|
rm -f $OBJ/unix-1.fwd
|
|
|
|
|
2012-10-05 03:45:39 +02:00
|
|
|
verbose "test $tid: cmd exit"
|
2013-05-17 01:19:10 +02:00
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -Oexit otherhost >>$TEST_REGRESS_LOGFILE 2>&1 \
|
2012-10-05 03:45:39 +02:00
|
|
|
|| fail "send exit command failed"
|
2004-12-06 13:12:15 +01:00
|
|
|
|
|
|
|
# Wait for master to exit
|
2014-07-09 05:22:03 +02:00
|
|
|
wait $SSH_PID
|
|
|
|
kill -0 $SSH_PID >/dev/null 2>&1 && fail "exit command failed"
|
2012-10-05 03:43:57 +02:00
|
|
|
|
|
|
|
# Restart master and test -O stop command with master using -N
|
2012-10-05 04:04:10 +02:00
|
|
|
verbose "test $tid: cmd stop"
|
|
|
|
trace "restart master, fork to background"
|
2013-05-17 01:36:20 +02:00
|
|
|
start_mux_master
|
2012-10-05 04:04:10 +02:00
|
|
|
|
|
|
|
# start a long-running command then immediately request a stop
|
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL otherhost "sleep 10; exit 0" \
|
2013-05-17 01:19:10 +02:00
|
|
|
>>$TEST_REGRESS_LOGFILE 2>&1 &
|
2012-10-05 03:45:39 +02:00
|
|
|
SLEEP_PID=$!
|
2013-05-17 01:19:10 +02:00
|
|
|
${SSH} -F $OBJ/ssh_config -S $CTL -Ostop otherhost >>$TEST_REGRESS_LOGFILE 2>&1 \
|
2012-10-05 03:45:39 +02:00
|
|
|
|| fail "send stop command failed"
|
2012-10-05 04:04:10 +02:00
|
|
|
|
|
|
|
# wait until both long-running command and master have exited.
|
2012-10-05 03:45:39 +02:00
|
|
|
wait $SLEEP_PID
|
2012-10-05 04:04:10 +02:00
|
|
|
[ $! != 0 ] || fail "waiting for concurrent command"
|
2014-07-09 05:22:03 +02:00
|
|
|
wait $SSH_PID
|
2012-10-05 04:04:10 +02:00
|
|
|
[ $! != 0 ] || fail "waiting for master stop"
|
2014-07-09 05:22:03 +02:00
|
|
|
kill -0 $SSH_PID >/dev/null 2>&1 && fatal "stop command failed"
|
|
|
|
SSH_PID="" # Already gone, so don't kill in cleanup
|
|
|
|
|