1 # $OpenBSD: forwarding.sh,v 1.11 2013/06/10 21:56:43 dtucker Exp $
2 # Placed in the Public Domain.
4 tid="local and remote forwarding"
18 # fwd chain: $a -> $b -> $c
19 fwd="$fwd -L$a:127.0.0.1:$b -R$b:127.0.0.1:$c"
25 trace "start forwarding, fork to background"
26 ${SSH} -$p -F $OBJ/ssh_config -f $fwd somehost sleep 10
28 trace "transfer over forwarded channels and check result"
29 ${SSH} -$q -F $OBJ/ssh_config -p$last -o 'ConnectionAttempts=4' \
30 somehost cat ${DATA} > ${COPY}
31 test -f ${COPY} || fail "failed copy of ${DATA}"
32 cmp ${DATA} ${COPY} || fail "corrupted copy of ${DATA}"
39 trace "exit on -$d forward failure, proto $p"
41 # this one should succeed
42 ${SSH} -$p -F $OBJ/ssh_config \
43 -$d ${base}01:127.0.0.1:$PORT \
44 -$d ${base}02:127.0.0.1:$PORT \
45 -$d ${base}03:127.0.0.1:$PORT \
46 -$d ${base}04:127.0.0.1:$PORT \
47 -oExitOnForwardFailure=yes somehost true
49 fail "connection failed, should not"
51 # this one should fail
52 ${SSH} -q -$p -F $OBJ/ssh_config \
53 -$d ${base}01:127.0.0.1:$PORT \
54 -$d ${base}02:127.0.0.1:$PORT \
55 -$d ${base}03:127.0.0.1:$PORT \
56 -$d ${base}01:127.0.0.1:$PORT \
57 -$d ${base}04:127.0.0.1:$PORT \
58 -oExitOnForwardFailure=yes somehost true
60 if [ $r != 255 ]; then
61 fail "connection not termintated, but should ($r)"
68 trace "simple clear forwarding proto $p"
69 ${SSH} -$p -F $OBJ/ssh_config -oClearAllForwardings=yes somehost true
71 trace "clear local forward proto $p"
72 ${SSH} -$p -f -F $OBJ/ssh_config -L ${base}01:127.0.0.1:$PORT \
73 -oClearAllForwardings=yes somehost sleep 10
75 fail "connection failed with cleared local forwarding"
77 # this one should fail
78 ${SSH} -$p -F $OBJ/ssh_config -p ${base}01 true \
79 >>$TEST_REGRESS_LOGFILE 2>&1 && \
80 fail "local forwarding not cleared"
84 trace "clear remote forward proto $p"
85 ${SSH} -$p -f -F $OBJ/ssh_config -R ${base}01:127.0.0.1:$PORT \
86 -oClearAllForwardings=yes somehost sleep 10
88 fail "connection failed with cleared remote forwarding"
90 # this one should fail
91 ${SSH} -$p -F $OBJ/ssh_config -p ${base}01 true \
92 >>$TEST_REGRESS_LOGFILE 2>&1 && \
93 fail "remote forwarding not cleared"
99 trace "stdio forwarding proto $p"
100 cmd="${SSH} -$p -F $OBJ/ssh_config"
101 $cmd -o "ProxyCommand $cmd -q -W localhost:$PORT somehost" \
104 fail "stdio forwarding proto $p"
108 echo "LocalForward ${base}01 127.0.0.1:$PORT" >> $OBJ/ssh_config
109 echo "RemoteForward ${base}02 127.0.0.1:${base}01" >> $OBJ/ssh_config
111 trace "config file: start forwarding, fork to background"
112 ${SSH} -$p -F $OBJ/ssh_config -f somehost sleep 10
114 trace "config file: transfer over forwarded channels and check result"
115 ${SSH} -F $OBJ/ssh_config -p${base}02 -o 'ConnectionAttempts=4' \
116 somehost cat ${DATA} > ${COPY}
117 test -f ${COPY} || fail "failed copy of ${DATA}"
118 cmp ${DATA} ${COPY} || fail "corrupted copy of ${DATA}"