summaryrefslogtreecommitdiff
path: root/contrib/torify.in
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/torify.in')
-rwxr-xr-xcontrib/torify.in78
1 files changed, 52 insertions, 26 deletions
diff --git a/contrib/torify.in b/contrib/torify.in
index 05645fd07c..d430da8ce7 100755
--- a/contrib/torify.in
+++ b/contrib/torify.in
@@ -3,43 +3,69 @@
# Wrapper script for use of the tsocks(8) transparent socksification library
# 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
# May be distributed under the same terms as Tor itself
+# taken from Debian's Developer's Reference, 6.4
+pathfind() {
+ OLDIFS="$IFS"
+ IFS=:
+ for p in $PATH; do
+ if [ -x "$p/$*" ]; then
+ IFS="$OLDIFS"
+ return 0
+ fi
+ done
+ IFS="$OLDIFS"
+ return 1
+}
-# Define and ensure we have tsocks
-# XXX: what if we don't have which?
-TSOCKS="`which tsocks`"
-if [ ! -x "$TSOCKS" ]
-then
- echo "$0: Can't find tsocks in PATH. Perhaps you haven't installed it?" >&2
- exit 1
+# Check for any argument list
+if [ "$#" = 0 ]; then
+ echo "Usage: $0 [-hv] <command> [<options>...]" >&2
+ exit 1
fi
-# Check for any argument list
-if [ "$#" = 0 ]
-then
- echo "Usage: $0 <command> [<options>...]" >&2
- exit 1
+if [ "$#" = 1 ] && ( [ "$1" = "-h" ] || [ "$1" = "--help" ] ); then
+ echo "Usage: $0 [-hv] <command> [<options>...]"
+ exit 0
fi
-if [ "$#" = 1 ] && ( [ "$1" = "-h" ] || [ "$1" = "--help" ] )
-then
- echo "Usage: $0 <command> [<options>...]"
- exit 0
+
+if [ "$1" = "-v" ] || [ "$1" = "--verbose" ]; then
+ verbose=1
+ shift 1
+else
+ verbose=0
fi
-# Define our tsocks config file
-TSOCKS_CONF_FILE="@CONFDIR@/tor-tsocks.conf"
-export TSOCKS_CONF_FILE
+if pathfind torsocks; then
+ ! [ "$verbose" -ge 1 ] || echo "Using torsocks as socksifier." >&2
-# Check that we've got a tsocks config file
-if [ -r "$TSOCKS_CONF_FILE" ]
-then
- exec tsocks "$@"
- echo "$0: Failed to exec tsocks $@" >&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
+ TSOCKS_CONF_FILE="/etc/tor/tor-tsocks.conf"
+ export TSOCKS_CONF_FILE
+
+ # Check that we've got a tsocks config file
+ if [ -r "$TSOCKS_CONF_FILE" ]
+ then
+ echo "WARNING: tsocks is known to leak DNS and UDP data. If you had torsocks we would use that." >&2
+ exec tsocks "$@"
+ echo "$0: Failed to exec tsocks $@" >&2
+ exit 1
+ else
+ echo "$0: Missing tsocks configuration file \"$TSOCKS_CONF_FILE\"." >&2
+ exit 1
+ fi
+
else
- echo "$0: Missing tsocks configuration file \"$TSOCKS_CONF_FILE\"." >&2
+ echo "$0: Can't find either tsocks or torsocks in your PATH. Perhaps you haven't installed either?" >&2
exit 1
fi