dynamic-forward.sh revision 1.4
1# $OpenBSD: dynamic-forward.sh,v 1.4 2004/06/22 22:55:56 dtucker Exp $ 2# Placed in the Public Domain. 3 4tid="dynamic forwarding" 5 6FWDPORT=`expr $PORT + 1` 7 8if [ -x "`which nc`" ] && nc -h 2>&1 | grep "proxy address" >/dev/null; then 9 proxycmd="nc -x 127.0.0.1:$FWDPORT -X" 10elif [ -x "`which connect`" ]; then 11 proxycmd="connect -S 127.0.0.1:$FWDPORT -" 12else 13 echo "skipped (no suitable ProxyCommand found)" 14 exit 0 15fi 16trace "will use ProxyCommand $proxycmd" 17 18start_sshd 19 20for p in 1 2; do 21 trace "start dynamic forwarding, fork to background" 22 ${SSH} -$p -F $OBJ/ssh_config -f -D $FWDPORT -q somehost \ 23 exec sh -c \'"echo \$\$ > $OBJ/remote_pid; exec sleep 444"\' 24 25 for s in 4 5; do 26 for h in 127.0.0.1 localhost; do 27 trace "testing ssh protocol $p socks version $s host $h" 28 ${SSH} -F $OBJ/ssh_config \ 29 -o "ProxyCommand ${proxycmd}${s} $h $PORT" \ 30 somehost cat /bin/ls > $OBJ/ls.copy 31 test -f $OBJ/ls.copy || fail "failed copy /bin/ls" 32 cmp /bin/ls $OBJ/ls.copy || fail "corrupted copy of /bin/ls" 33 done 34 done 35 36 if [ -f $OBJ/remote_pid ]; then 37 remote=`cat $OBJ/remote_pid` 38 trace "terminate remote shell, pid $remote" 39 if [ $remote -gt 1 ]; then 40 kill -HUP $remote 41 fi 42 else 43 fail "no pid file: $OBJ/remote_pid" 44 fi 45done 46