Fix torify: Do not complain if we cannot find all socksifiers

No longer complain if we cannot find both torify and tsocks.  As long as
we have one we are happy.

Do not rely on which, it's not POSIX.

Catch error if torsocks fails and print an error message.
This commit is contained in:
Peter Palfrader 2009-09-09 21:33:32 +02:00 committed by Sebastian Hahn
parent 3de5ac9baa
commit 5149ae57f1

View File

@ -3,57 +3,52 @@
# Wrapper script for use of the tsocks(8) transparent socksification library # Wrapper script for use of the tsocks(8) transparent socksification library
# See the tsocks(1) and torify(1) manpages. # See the tsocks(1) and torify(1) manpages.
# Copyright (c) 2004, 2006 Peter Palfrader # Copyright (c) 2004, 2006, 2009 Peter Palfrader
# Modified by Jacob Appelbaum <jacob@appelbaum.net> April 16th 2006 # Modified by Jacob Appelbaum <jacob@appelbaum.net> April 16th 2006
# May be distributed under the same terms as Tor itself # May be distributed under the same terms as Tor itself
# taken from Debian's Developer's Reference, 6.4
# Define and ensure we have tsocks pathfind() {
# XXX: what if we don't have which? OLDIFS="$IFS"
TORSOCKS="`which torsocks`" IFS=:
TSOCKS="`which tsocks`" for p in $PATH; do
PROG="" if [ -x "$p/$*" ]; then
if [ ! -x "$TSOCKS" ] IFS="$OLDIFS"
then return 0
echo "$0: Can't find tsocks in PATH. Perhaps you haven't installed it?" >&2 fi
else done
PROG=$TSOCKS IFS="$OLDIFS"
fi return 1
if [ ! -x "$TORSOCKS" ] }
then
echo "$0: Can't find torsocks in PATH. Perhaps you haven't installed it?" >&2
else
PROG=$TORSOCKS
fi
if [ ! -x "$PROG" ]
then
echo "$0: Can't find the required tor helpers in our PATH. Perhaps you haven't installed them?" >&2
exit 1;
fi
# Check for any argument list # Check for any argument list
if [ "$#" = 0 ] if [ "$#" = 0 ]; then
then
echo "Usage: $0 [-hv] <command> [<options>...]" >&2 echo "Usage: $0 [-hv] <command> [<options>...]" >&2
exit 1 exit 1
fi fi
if [ "$#" = 1 ] && ( [ "$1" = "-h" ] || [ "$1" = "--help" ] )
then if [ "$#" = 1 ] && ( [ "$1" = "-h" ] || [ "$1" = "--help" ] ); then
echo "Usage: $0 [-hv] <command> [<options>...]" echo "Usage: $0 [-hv] <command> [<options>...]"
exit 0 exit 0
fi fi
if [ "$1" = "-v" ] || [ "$1" = "--verbose" ] if [ "$1" = "-v" ] || [ "$1" = "--verbose" ]; then
then verbose=1
echo "We're armed with the following tsocks: $TSOCKS"
echo "We're armed with the following torsocks: $TORSOCKS"
echo "We're attempting to use $PROG for all tor action."
shift 1 shift 1
else
verbose=0
fi fi
if [ "$PROG" = "$TSOCKS" ] if pathfind torsocks; then
then ! [ "$verbose" -ge 1 ] || echo "Using torsocks as socksifier." >&2
exec torsocks "$@"
echo "$0: Failed to exec torsocks $@" >&2
exit 1
elif pathfind tsocks; then
! [ "$verbose" -ge 1 ] || echo "Using tsocks as socksifier." >&2
# Define our tsocks config file # Define our tsocks config file
TSOCKS_CONF_FILE="/etc/tor/tor-tsocks.conf" TSOCKS_CONF_FILE="/etc/tor/tor-tsocks.conf"
export TSOCKS_CONF_FILE export TSOCKS_CONF_FILE
@ -61,7 +56,7 @@ then
# Check that we've got a tsocks config file # Check that we've got a tsocks config file
if [ -r "$TSOCKS_CONF_FILE" ] if [ -r "$TSOCKS_CONF_FILE" ]
then then
echo "WARNING: tsocks is known to leak DNS and UDP data." >&2 echo "WARNING: tsocks is known to leak DNS and UDP data. If you had torsocks we would use that." >&2
exec tsocks "$@" exec tsocks "$@"
echo "$0: Failed to exec tsocks $@" >&2 echo "$0: Failed to exec tsocks $@" >&2
exit 1 exit 1
@ -69,8 +64,8 @@ then
echo "$0: Missing tsocks configuration file \"$TSOCKS_CONF_FILE\"." >&2 echo "$0: Missing tsocks configuration file \"$TSOCKS_CONF_FILE\"." >&2
exit 1 exit 1
fi fi
fi
if [ "$PROG" = "$TORSOCKS" ] else
then echo "$0: Can't find neither tsocks nor torsocks in your PATH. Perhaps you haven't installed either?" >&2
exec torsocks "$@" exit 1
fi fi