blob: 4674a7bafebe7058b6d8d98fd34c40ce69e01986 [file] [log] [blame]
Darren Tuckerc0dc1c92004-12-06 22:58:11 +11001# $OpenBSD: dynamic-forward.sh,v 1.4 2004/06/22 22:55:56 dtucker Exp $
Darren Tuckerb611c122003-06-28 12:42:09 +10002# Placed in the Public Domain.
3
4tid="dynamic forwarding"
5
Darren Tucker3b9c0ad2004-06-23 09:28:20 +10006FWDPORT=`expr $PORT + 1`
7
Darren Tuckerd199b6d2003-09-07 09:28:03 +10008DATA=/bin/ls${EXEEXT}
Darren Tuckerb611c122003-06-28 12:42:09 +10009
Darren Tucker68b184c2004-02-29 20:37:06 +110010if have_prog nc && nc -h 2>&1 | grep "proxy address" >/dev/null; then
Darren Tuckerb611c122003-06-28 12:42:09 +100011 proxycmd="nc -x 127.0.0.1:$FWDPORT -X"
Tim Rice23ee3592003-09-11 22:32:17 -070012elif have_prog connect; then
Darren Tuckerb611c122003-06-28 12:42:09 +100013 proxycmd="connect -S 127.0.0.1:$FWDPORT -"
14else
15 echo "skipped (no suitable ProxyCommand found)"
16 exit 0
17fi
18trace "will use ProxyCommand $proxycmd"
19
20start_sshd
21
22for p in 1 2; do
Darren Tuckerb611c122003-06-28 12:42:09 +100023 trace "start dynamic forwarding, fork to background"
Darren Tucker7a246622003-07-03 20:26:04 +100024 ${SSH} -$p -F $OBJ/ssh_config -f -D $FWDPORT -q somehost \
25 exec sh -c \'"echo \$\$ > $OBJ/remote_pid; exec sleep 444"\'
Darren Tuckerb611c122003-06-28 12:42:09 +100026
Darren Tucker7a246622003-07-03 20:26:04 +100027 for s in 4 5; do
28 for h in 127.0.0.1 localhost; do
29 trace "testing ssh protocol $p socks version $s host $h"
30 ${SSH} -F $OBJ/ssh_config \
31 -o "ProxyCommand ${proxycmd}${s} $h $PORT" \
Darren Tuckerd199b6d2003-09-07 09:28:03 +100032 somehost cat $DATA > $OBJ/ls.copy
33 test -f $OBJ/ls.copy || fail "failed copy $DATA"
34 cmp $DATA $OBJ/ls.copy || fail "corrupted copy of $DATA"
Darren Tucker7a246622003-07-03 20:26:04 +100035 done
36 done
Darren Tuckerb611c122003-06-28 12:42:09 +100037
Darren Tucker7a246622003-07-03 20:26:04 +100038 if [ -f $OBJ/remote_pid ]; then
39 remote=`cat $OBJ/remote_pid`
40 trace "terminate remote shell, pid $remote"
41 if [ $remote -gt 1 ]; then
42 kill -HUP $remote
43 fi
44 else
45 fail "no pid file: $OBJ/remote_pid"
46 fi
Darren Tucker07d30e42004-08-29 17:14:31 +100047
48 # Must allow time for connection tear-down
49 sleep 2
Darren Tuckerb611c122003-06-28 12:42:09 +100050done