Dist/Tizen: Fix build breaks on GCC 13
[platform/upstream/openssh.git] / regress / forwarding.sh
1 #       $OpenBSD: forwarding.sh,v 1.20 2017/04/30 23:34:55 djm Exp $
2 #       Placed in the Public Domain.
3
4 tid="local and remote forwarding"
5
6 DATA=/bin/ls${EXEEXT}
7
8 start_sshd
9
10 base=33
11 last=$PORT
12 fwd=""
13 CTL=/tmp/openssh.regress.ctl-sock.$$
14
15 for j in 0 1 2; do
16         for i in 0 1 2; do
17                 a=$base$j$i
18                 b=`expr $a + 50`
19                 c=$last
20                 # fwd chain: $a -> $b -> $c
21                 fwd="$fwd -L$a:127.0.0.1:$b -R$b:127.0.0.1:$c"
22                 last=$a
23         done
24 done
25
26 trace "start forwarding, fork to background"
27 rm -f $CTL
28 ${SSH} -S $CTL -M -F $OBJ/ssh_config -f $fwd somehost sleep 10
29
30 trace "transfer over forwarded channels and check result"
31 ${SSH} -F $OBJ/ssh_config -p$last -o 'ConnectionAttempts=4' \
32         somehost cat ${DATA} > ${COPY}
33 test -s ${COPY}         || fail "failed copy of ${DATA}"
34 cmp ${DATA} ${COPY}     || fail "corrupted copy of ${DATA}"
35
36 ${SSH} -F $OBJ/ssh_config -S $CTL -O exit somehost
37
38 for d in L R; do
39         trace "exit on -$d forward failure"
40
41         # this one should succeed
42         ${SSH}  -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
48         if [ $? != 0 ]; then
49                 fatal "connection failed, should not"
50         else
51                 # this one should fail
52                 ${SSH} -q -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:localhost:$PORT \
57                     -$d ${base}04:127.0.0.1:$PORT \
58                     -oExitOnForwardFailure=yes somehost true
59                 r=$?
60                 if [ $r != 255 ]; then
61                         fail "connection not termintated, but should ($r)"
62                 fi
63         fi
64 done
65
66 trace "simple clear forwarding"
67 ${SSH} -F $OBJ/ssh_config -oClearAllForwardings=yes somehost true
68
69 trace "clear local forward"
70 rm -f $CTL
71 ${SSH} -S $CTL -M -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} -F $OBJ/ssh_config -p ${base}01 somehost true \
78              >>$TEST_REGRESS_LOGFILE 2>&1 && \
79                 fail "local forwarding not cleared"
80 fi
81 ${SSH} -F $OBJ/ssh_config -S $CTL -O exit somehost
82
83 trace "clear remote forward"
84 rm -f $CTL
85 ${SSH} -S $CTL -M -f -F $OBJ/ssh_config -R ${base}01:127.0.0.1:$PORT \
86     -oClearAllForwardings=yes somehost sleep 10
87 if [ $? != 0 ]; then
88         fail "connection failed with cleared remote forwarding"
89 else
90         # this one should fail
91         ${SSH} -F $OBJ/ssh_config -p ${base}01 somehost true \
92              >>$TEST_REGRESS_LOGFILE 2>&1 && \
93                 fail "remote forwarding not cleared"
94 fi
95 ${SSH} -F $OBJ/ssh_config -S $CTL -O exit somehost
96
97 trace "stdio forwarding"
98 cmd="${SSH} -F $OBJ/ssh_config"
99 $cmd -o "ProxyCommand $cmd -q -W localhost:$PORT somehost" somehost true
100 if [ $? != 0 ]; then
101         fail "stdio forwarding"
102 fi
103
104 echo "LocalForward ${base}01 127.0.0.1:$PORT" >> $OBJ/ssh_config
105 echo "RemoteForward ${base}02 127.0.0.1:${base}01" >> $OBJ/ssh_config
106
107 trace "config file: start forwarding, fork to background"
108 rm -f $CTL
109 ${SSH} -S $CTL -M -F $OBJ/ssh_config -f somehost sleep 10
110
111 trace "config file: transfer over forwarded channels and check result"
112 ${SSH} -F $OBJ/ssh_config -p${base}02 -o 'ConnectionAttempts=4' \
113         somehost cat ${DATA} > ${COPY}
114 test -s ${COPY}         || fail "failed copy of ${DATA}"
115 cmp ${DATA} ${COPY}     || fail "corrupted copy of ${DATA}"
116
117 ${SSH} -F $OBJ/ssh_config -S $CTL -O exit somehost
118
119 trace "transfer over chained unix domain socket forwards and check result"
120 rm -f $OBJ/unix-[123].fwd
121 rm -f $CTL $CTL.[123]
122 ${SSH} -S $CTL -M -f -F $OBJ/ssh_config -R${base}01:[$OBJ/unix-1.fwd] somehost sleep 10
123 ${SSH} -S $CTL.1 -M -f -F $OBJ/ssh_config -L[$OBJ/unix-1.fwd]:[$OBJ/unix-2.fwd] somehost sleep 10
124 ${SSH} -S $CTL.2 -M -f -F $OBJ/ssh_config -R[$OBJ/unix-2.fwd]:[$OBJ/unix-3.fwd] somehost sleep 10
125 ${SSH} -S $CTL.3 -M -f -F $OBJ/ssh_config -L[$OBJ/unix-3.fwd]:127.0.0.1:$PORT somehost sleep 10
126 ${SSH} -F $OBJ/ssh_config -p${base}01 -o 'ConnectionAttempts=4' \
127         somehost cat ${DATA} > ${COPY}
128 test -s ${COPY}                 || fail "failed copy ${DATA}"
129 cmp ${DATA} ${COPY}             || fail "corrupted copy of ${DATA}"
130
131 ${SSH} -F $OBJ/ssh_config -S $CTL -O exit somehost
132 ${SSH} -F $OBJ/ssh_config -S $CTL.1 -O exit somehost
133 ${SSH} -F $OBJ/ssh_config -S $CTL.2 -O exit somehost
134 ${SSH} -F $OBJ/ssh_config -S $CTL.3 -O exit somehost
135