dynamic-forward.sh revision 1.2
1# $OpenBSD: dynamic-forward.sh,v 1.2 2003/07/03 08:21:46 markus Exp $ 2# Placed in the Public Domain. 3 4tid="dynamic forwarding" 5 6PORT=4242 7FWDPORT=4243 8 9if [ -x `which nc` ] && nc -h 2>&1 | grep "x proxy address" >/dev/null; then 10 proxycmd="nc -x 127.0.0.1:$FWDPORT -X" 11elif [ -x `which connect` ]; then 12 proxycmd="connect -S 127.0.0.1:$FWDPORT -" 13else 14 echo "skipped (no suitable ProxyCommand found)" 15 exit 0 16fi 17trace "will use ProxyCommand $proxycmd" 18 19start_sshd 20 21for p in 1 2; do 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"\' 25 26 for s in 4 5; do 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" 34 done 35 done 36 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 41 kill -HUP $remote 42 fi 43 else 44 fail "no pid file: $OBJ/remote_pid" 45 fi 46done 47