xref: /openbsd/regress/usr.bin/ssh/forwarding.sh (revision 703e6eb8)
1*703e6eb8Sdtucker#	$OpenBSD: forwarding.sh,v 1.5 2005/03/10 10:20:39 dtucker Exp $
225a4fdfeSmarkus#	Placed in the Public Domain.
325a4fdfeSmarkus
455154775Smarkustid="local and remote forwarding"
555154775Smarkus
60eef944aSmarkusstart_sshd
70eef944aSmarkus
855154775Smarkusbase=33
955154775Smarkuslast=$PORT
1055154775Smarkusfwd=""
1155154775Smarkusfor j in 0 1 2; do
1255154775Smarkus	for i in 0 1 2; do
1355154775Smarkus		a=$base$j$i
1455154775Smarkus		b=`expr $a + 50`
1555154775Smarkus		c=$last
1655154775Smarkus		# fwd chain: $a -> $b -> $c
1755154775Smarkus		fwd="$fwd -L$a:127.0.0.1:$b -R$b:127.0.0.1:$c"
1855154775Smarkus		last=$a
1955154775Smarkus	done
2055154775Smarkusdone
2155154775Smarkusfor p in 1 2; do
2255154775Smarkus	q=`expr 3 - $p`
2355154775Smarkus	trace "start forwarding, fork to background"
24a6676234Smarkus	${SSH} -$p -F $OBJ/ssh_config -f $fwd somehost sleep 10
2555154775Smarkus
2655154775Smarkus	trace "transfer over forwarded channels and check result"
27a6676234Smarkus	${SSH} -$q -F $OBJ/ssh_config -p$last -o 'ConnectionAttempts=4' \
2855154775Smarkus		somehost cat /bin/ls > $OBJ/ls.copy
2955154775Smarkus	test -f $OBJ/ls.copy			|| fail "failed copy /bin/ls"
3055154775Smarkus	cmp /bin/ls $OBJ/ls.copy		|| fail "corrupted copy of /bin/ls"
3155154775Smarkus
3255154775Smarkus	sleep 10
3355154775Smarkusdone
34*703e6eb8Sdtucker
35*703e6eb8Sdtuckerfor p in 1 2; do
36*703e6eb8Sdtucker	trace "simple clear forwarding proto $p"
37*703e6eb8Sdtucker	${SSH} -$p -F $OBJ/ssh_config -oClearAllForwardings=yes somehost true
38*703e6eb8Sdtucker
39*703e6eb8Sdtucker	trace "clear local forward proto $p"
40*703e6eb8Sdtucker	${SSH} -$p -f -F $OBJ/ssh_config -L ${base}01:127.0.0.1:$PORT \
41*703e6eb8Sdtucker	    -oClearAllForwardings=yes somehost sleep 10
42*703e6eb8Sdtucker	if [ $? != 0 ]; then
43*703e6eb8Sdtucker		fail "connection failed with cleared local forwarding"
44*703e6eb8Sdtucker	else
45*703e6eb8Sdtucker		# this one should fail
46*703e6eb8Sdtucker		${SSH} -$p -F $OBJ/ssh_config -p ${base}01 true \
47*703e6eb8Sdtucker		     2>${TEST_SSH_LOGFILE} && \
48*703e6eb8Sdtucker			fail "local forwarding not cleared"
49*703e6eb8Sdtucker	fi
50*703e6eb8Sdtucker	sleep 10
51*703e6eb8Sdtucker
52*703e6eb8Sdtucker	trace "clear remote forward proto $p"
53*703e6eb8Sdtucker	${SSH} -$p -f -F $OBJ/ssh_config -R ${base}01:127.0.0.1:$PORT \
54*703e6eb8Sdtucker	    -oClearAllForwardings=yes somehost sleep 10
55*703e6eb8Sdtucker	if [ $? != 0 ]; then
56*703e6eb8Sdtucker		fail "connection failed with cleared remote forwarding"
57*703e6eb8Sdtucker	else
58*703e6eb8Sdtucker		# this one should fail
59*703e6eb8Sdtucker		${SSH} -$p -F $OBJ/ssh_config -p ${base}01 true \
60*703e6eb8Sdtucker		     2>${TEST_SSH_LOGFILE} && \
61*703e6eb8Sdtucker			fail "remote forwarding not cleared"
62*703e6eb8Sdtucker	fi
63*703e6eb8Sdtucker	sleep 10
64*703e6eb8Sdtuckerdone
65