blob: 9ffbb3dd4712f67fb5f7fd580cb6f4c8c95eb009 [file] [log] [blame]
Damien Miller7b1877c2006-07-24 15:31:41 +10001# $OpenBSD: forwarding.sh,v 1.6 2006/07/11 18:51:21 markus Exp $
Damien Miller38cd4352002-05-01 13:17:33 +10002# Placed in the Public Domain.
3
4tid="local and remote forwarding"
Darren Tuckerd199b6d2003-09-07 09:28:03 +10005DATA=/bin/ls${EXEEXT}
Damien Miller38cd4352002-05-01 13:17:33 +10006
7start_sshd
8
9base=33
10last=$PORT
11fwd=""
12for j in 0 1 2; do
13 for i in 0 1 2; do
14 a=$base$j$i
15 b=`expr $a + 50`
16 c=$last
17 # fwd chain: $a -> $b -> $c
18 fwd="$fwd -L$a:127.0.0.1:$b -R$b:127.0.0.1:$c"
19 last=$a
20 done
21done
22for p in 1 2; do
23 q=`expr 3 - $p`
24 trace "start forwarding, fork to background"
25 ${SSH} -$p -F $OBJ/ssh_config -f $fwd somehost sleep 10
26
27 trace "transfer over forwarded channels and check result"
28 ${SSH} -$q -F $OBJ/ssh_config -p$last -o 'ConnectionAttempts=4' \
Darren Tuckerd199b6d2003-09-07 09:28:03 +100029 somehost cat $DATA > $OBJ/ls.copy
30 test -f $OBJ/ls.copy || fail "failed copy $DATA"
31 cmp $DATA $OBJ/ls.copy || fail "corrupted copy of $DATA"
Damien Miller38cd4352002-05-01 13:17:33 +100032
33 sleep 10
34done
Damien Milleredaeff52006-01-31 21:56:24 +110035
36for p in 1 2; do
Damien Miller7b1877c2006-07-24 15:31:41 +100037for d in L R; do
38 trace "exit on -$d forward failure, proto $p"
39
40 # this one should succeed
41 ${SSH} -$p -F $OBJ/ssh_config \
42 -$d ${base}01:127.0.0.1:$PORT \
43 -$d ${base}02:127.0.0.1:$PORT \
44 -$d ${base}03:127.0.0.1:$PORT \
45 -$d ${base}04:127.0.0.1:$PORT \
46 -oExitOnForwardFailure=yes somehost true
47 if [ $? != 0 ]; then
48 fail "connection failed, should not"
49 else
50 # this one should fail
51 ${SSH} -q -$p -F $OBJ/ssh_config \
52 -$d ${base}01:127.0.0.1:$PORT \
53 -$d ${base}02:127.0.0.1:$PORT \
54 -$d ${base}03:127.0.0.1:$PORT \
55 -$d ${base}01:127.0.0.1:$PORT \
56 -$d ${base}04:127.0.0.1:$PORT \
57 -oExitOnForwardFailure=yes somehost true
58 r=$?
59 if [ $r != 255 ]; then
60 fail "connection not termintated, but should ($r)"
61 fi
62 fi
63done
64done
65
66for p in 1 2; do
Damien Milleredaeff52006-01-31 21:56:24 +110067 trace "simple clear forwarding proto $p"
68 ${SSH} -$p -F $OBJ/ssh_config -oClearAllForwardings=yes somehost true
69
70 trace "clear local forward proto $p"
71 ${SSH} -$p -f -F $OBJ/ssh_config -L ${base}01:127.0.0.1:$PORT \
72 -oClearAllForwardings=yes somehost sleep 10
73 if [ $? != 0 ]; then
74 fail "connection failed with cleared local forwarding"
75 else
76 # this one should fail
77 ${SSH} -$p -F $OBJ/ssh_config -p ${base}01 true \
78 2>${TEST_SSH_LOGFILE} && \
79 fail "local forwarding not cleared"
80 fi
81 sleep 10
82
83 trace "clear remote forward proto $p"
84 ${SSH} -$p -f -F $OBJ/ssh_config -R ${base}01:127.0.0.1:$PORT \
85 -oClearAllForwardings=yes somehost sleep 10
86 if [ $? != 0 ]; then
87 fail "connection failed with cleared remote forwarding"
88 else
89 # this one should fail
90 ${SSH} -$p -F $OBJ/ssh_config -p ${base}01 true \
91 2>${TEST_SSH_LOGFILE} && \
92 fail "remote forwarding not cleared"
93 fi
94 sleep 10
95done