summaryrefslogtreecommitdiff
path: root/contrib/torify.in
blob: 6b1e440dc1ec40f855e57de83129b38f700d2b96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#! /bin/sh

# 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
# Modified by Jacob Appelbaum <jacob@appelbaum.net> April 16th 2006
# May be distributed under the same terms as Tor itself


# Define and ensure we have tsocks
# XXX: what if we don't have which?
TORSOCKS="`which torsocks`"
TSOCKS="`which tsocks`"
PROG=""
if [ ! -x "$TSOCKS" ]
then
	echo "$0: Can't find tsocks in PATH. Perhaps you haven't installed it?" >&2
else
	PROG=$TSOCKS
fi
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
if [ "$#" = 0 ]
then
	echo "Usage: $0 [-hv] <command> [<options>...]" >&2
	exit 1
fi
if [ "$#" = 1 ] && ( [ "$1" = "-h" ] || [ "$1" = "--help" ] )
then
	echo "Usage: $0 [-hv] <command> [<options>...]"
	exit 0
fi

if [ "$1" = "-v" ] || [ "$1" = "--verbose" ]
then
	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
fi

if [ "$PROG" == "$TSOCKS" ]
then
	# 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." >&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
fi
if [ "$PROG" == "$TORSOCKS" ]
then
	exec torsocks "$@"
fi