1 # $OpenBSD: dynamic-forward.sh,v 1.2 2003/07/03 08:21:46 markus Exp $
2 # Placed in the Public Domain.
4 tid="dynamic forwarding"
9 if [ -x "`which nc 2>&1`" ] && nc -h 2>&1 | grep "x proxy address" >/dev/null; then
10 proxycmd="nc -x 127.0.0.1:$FWDPORT -X"
11 elif [ -x "`which connect 2>&1`" ]; then
12 proxycmd="connect -S 127.0.0.1:$FWDPORT -"
14 echo "skipped (no suitable ProxyCommand found)"
17 trace "will use ProxyCommand $proxycmd"
22 trace "start dynamic forwarding, fork to background"
23 ${SSH} -$p -F $OBJ/ssh_config -f -D $FWDPORT -q somehost \
24 exec sh -c \'"echo \$\$ > $OBJ/remote_pid; exec sleep 444"\'
27 for h in 127.0.0.1 localhost; do
28 trace "testing ssh protocol $p socks version $s host $h"
29 ${SSH} -F $OBJ/ssh_config \
30 -o "ProxyCommand ${proxycmd}${s} $h $PORT" \
31 somehost cat /bin/ls > $OBJ/ls.copy
32 test -f $OBJ/ls.copy || fail "failed copy /bin/ls"
33 cmp /bin/ls $OBJ/ls.copy || fail "corrupted copy of /bin/ls"
37 if [ -f $OBJ/remote_pid ]; then
38 remote=`cat $OBJ/remote_pid`
39 trace "terminate remote shell, pid $remote"
40 if [ $remote -gt 1 ]; then
44 fail "no pid file: $OBJ/remote_pid"