1 # $OpenBSD: forwarding.sh,v 1.15 2015/03/03 22:35:19 markus Exp $
2 # Placed in the Public Domain.
4 tid="local and remote forwarding"
21 # fwd chain: $a -> $b -> $c
22 fwd="$fwd -L$a:127.0.0.1:$b -R$b:127.0.0.1:$c"
26 for p in ${SSH_PROTOCOLS}; do
28 if ! ssh_version $q; then
31 trace "start forwarding, fork to background"
32 ${SSH} -$p -F $OBJ/ssh_config -f $fwd somehost sleep 10
34 trace "transfer over forwarded channels and check result"
35 ${SSH} -$q -F $OBJ/ssh_config -p$last -o 'ConnectionAttempts=4' \
36 somehost cat ${DATA} > ${COPY}
37 test -s ${COPY} || fail "failed copy of ${DATA}"
38 cmp ${DATA} ${COPY} || fail "corrupted copy of ${DATA}"
43 for p in ${SSH_PROTOCOLS}; do
45 trace "exit on -$d forward failure, proto $p"
47 # this one should succeed
48 ${SSH} -$p -F $OBJ/ssh_config \
49 -$d ${base}01:127.0.0.1:$PORT \
50 -$d ${base}02:127.0.0.1:$PORT \
51 -$d ${base}03:127.0.0.1:$PORT \
52 -$d ${base}04:127.0.0.1:$PORT \
53 -oExitOnForwardFailure=yes somehost true
55 fail "connection failed, should not"
57 # this one should fail
58 ${SSH} -q -$p -F $OBJ/ssh_config \
59 -$d ${base}01:127.0.0.1:$PORT \
60 -$d ${base}02:127.0.0.1:$PORT \
61 -$d ${base}03:127.0.0.1:$PORT \
62 -$d ${base}01:127.0.0.1:$PORT \
63 -$d ${base}04:127.0.0.1:$PORT \
64 -oExitOnForwardFailure=yes somehost true
66 if [ $r != 255 ]; then
67 fail "connection not termintated, but should ($r)"
73 for p in ${SSH_PROTOCOLS}; do
74 trace "simple clear forwarding proto $p"
75 ${SSH} -$p -F $OBJ/ssh_config -oClearAllForwardings=yes somehost true
77 trace "clear local forward proto $p"
78 ${SSH} -$p -f -F $OBJ/ssh_config -L ${base}01:127.0.0.1:$PORT \
79 -oClearAllForwardings=yes somehost sleep 10
81 fail "connection failed with cleared local forwarding"
83 # this one should fail
84 ${SSH} -$p -F $OBJ/ssh_config -p ${base}01 true \
85 >>$TEST_REGRESS_LOGFILE 2>&1 && \
86 fail "local forwarding not cleared"
90 trace "clear remote forward proto $p"
91 ${SSH} -$p -f -F $OBJ/ssh_config -R ${base}01:127.0.0.1:$PORT \
92 -oClearAllForwardings=yes somehost sleep 10
94 fail "connection failed with cleared remote forwarding"
96 # this one should fail
97 ${SSH} -$p -F $OBJ/ssh_config -p ${base}01 true \
98 >>$TEST_REGRESS_LOGFILE 2>&1 && \
99 fail "remote forwarding not cleared"
105 trace "stdio forwarding proto $p"
106 cmd="${SSH} -$p -F $OBJ/ssh_config"
107 $cmd -o "ProxyCommand $cmd -q -W localhost:$PORT somehost" \
110 fail "stdio forwarding proto $p"
114 echo "LocalForward ${base}01 127.0.0.1:$PORT" >> $OBJ/ssh_config
115 echo "RemoteForward ${base}02 127.0.0.1:${base}01" >> $OBJ/ssh_config
116 for p in ${SSH_PROTOCOLS}; do
117 trace "config file: start forwarding, fork to background"
118 ${SSH} -S $CTL -M -$p -F $OBJ/ssh_config -f somehost sleep 10
120 trace "config file: transfer over forwarded channels and check result"
121 ${SSH} -F $OBJ/ssh_config -p${base}02 -o 'ConnectionAttempts=4' \
122 somehost cat ${DATA} > ${COPY}
123 test -s ${COPY} || fail "failed copy of ${DATA}"
124 cmp ${DATA} ${COPY} || fail "corrupted copy of ${DATA}"
126 ${SSH} -S $CTL -O exit somehost
130 trace "transfer over chained unix domain socket forwards and check result"
131 rm -f $OBJ/unix-[123].fwd
132 ${SSH} -f -F $OBJ/ssh_config -R${base}01:[$OBJ/unix-1.fwd] somehost sleep 10
133 ${SSH} -f -F $OBJ/ssh_config -L[$OBJ/unix-1.fwd]:[$OBJ/unix-2.fwd] somehost sleep 10
134 ${SSH} -f -F $OBJ/ssh_config -R[$OBJ/unix-2.fwd]:[$OBJ/unix-3.fwd] somehost sleep 10
135 ${SSH} -f -F $OBJ/ssh_config -L[$OBJ/unix-3.fwd]:127.0.0.1:$PORT somehost sleep 10
136 ${SSH} -F $OBJ/ssh_config -p${base}01 -o 'ConnectionAttempts=4' \
137 somehost cat ${DATA} > ${COPY}
138 test -s ${COPY} || fail "failed copy ${DATA}"
139 cmp ${DATA} ${COPY} || fail "corrupted copy of ${DATA}"