1 # $OpenBSD: dynamic-forward.sh,v 1.4 2004/06/22 22:55:56 dtucker Exp $
2 # Placed in the Public Domain.
4 tid
="dynamic forwarding"
6 FWDPORT
=`expr $PORT + 1`
10 if have_prog nc
&& nc
-h 2>&1 |
grep "proxy address" >/dev
/null
; then
11 proxycmd
="nc -x 127.0.0.1:$FWDPORT -X"
12 elif have_prog connect
; then
13 proxycmd
="connect -S 127.0.0.1:$FWDPORT -"
15 echo "skipped (no suitable ProxyCommand found)"
18 trace
"will use ProxyCommand $proxycmd"
23 trace
"start dynamic forwarding, fork to background"
24 ${SSH} -$p -F $OBJ/ssh_config
-f -D $FWDPORT -q somehost \
25 exec sh
-c \'"echo \$\$ > $OBJ/remote_pid; exec sleep 444"\'
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" \
32 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"
38 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
45 fail
"no pid file: $OBJ/remote_pid"
48 # Must allow time for connection tear-down