- (djm) OpenBSD CVS Sync
[openssh-git.git] / regress / forwarding.sh
blob9ffbb3dd4712f67fb5f7fd580cb6f4c8c95eb009
1 # $OpenBSD: forwarding.sh,v 1.6 2006/07/11 18:51:21 markus Exp $
2 # Placed in the Public Domain.
4 tid="local and remote forwarding"
5 DATA=/bin/ls${EXEEXT}
7 start_sshd
9 base=33
10 last=$PORT
11 fwd=""
12 for 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
21 done
22 for 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
27 trace "transfer over forwarded channels and check result"
28 ${SSH} -$q -F $OBJ/ssh_config -p$last -o 'ConnectionAttempts=4' \
29 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"
33 sleep 10
34 done
36 for p in 1 2; do
37 for d in L R; do
38 trace "exit on -$d forward failure, proto $p"
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)"
63 done
64 done
66 for p in 1 2; do
67 trace "simple clear forwarding proto $p"
68 ${SSH} -$p -F $OBJ/ssh_config -oClearAllForwardings=yes somehost true
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"
81 sleep 10
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"
94 sleep 10
95 done