torify.in 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #! /bin/sh
  2. # Wrapper script for use of the tsocks(8) transparent socksification library
  3. # See the tsocks(1) and torify(1) manpages.
  4. # Copyright (c) 2004, 2006 Peter Palfrader
  5. # Modified by Jacob Appelbaum <jacob@appelbaum.net> April 16th 2006
  6. # May be distributed under the same terms as Tor itself
  7. # Define and ensure we have tsocks
  8. # XXX: what if we don't have which?
  9. TORSOCKS="`which torsocks`"
  10. TSOCKS="`which tsocks`"
  11. PROG=""
  12. if [ ! -x "$TSOCKS" ]
  13. then
  14. echo "$0: Can't find tsocks in PATH. Perhaps you haven't installed it?" >&2
  15. else
  16. PROG=$TSOCKS
  17. fi
  18. if [ ! -x "$TORSOCKS" ]
  19. then
  20. echo "$0: Can't find torsocks in PATH. Perhaps you haven't installed it?" >&2
  21. else
  22. PROG=$TORSOCKS
  23. fi
  24. if [ ! -x "$PROG" ]
  25. then
  26. echo "$0: Can't find the required tor helpers in our PATH. Perhaps you haven't installed them?" >&2
  27. exit 1;
  28. fi
  29. # Check for any argument list
  30. if [ "$#" = 0 ]
  31. then
  32. echo "Usage: $0 [-hv] <command> [<options>...]" >&2
  33. exit 1
  34. fi
  35. if [ "$#" = 1 ] && ( [ "$1" = "-h" ] || [ "$1" = "--help" ] )
  36. then
  37. echo "Usage: $0 [-hv] <command> [<options>...]"
  38. exit 0
  39. fi
  40. if [ "$1" = "-v" ] || [ "$1" = "--verbose" ]
  41. then
  42. echo "We're armed with the following tsocks: $TSOCKS"
  43. echo "We're armed with the following torsocks: $TORSOCKS"
  44. echo "We're attempting to use $PROG for all tor action."
  45. shift 1
  46. fi
  47. if [ "$PROG" = "$TSOCKS" ]
  48. then
  49. # Define our tsocks config file
  50. TSOCKS_CONF_FILE="/etc/tor/tor-tsocks.conf"
  51. export TSOCKS_CONF_FILE
  52. # Check that we've got a tsocks config file
  53. if [ -r "$TSOCKS_CONF_FILE" ]
  54. then
  55. echo "WARNING: tsocks is known to leak DNS and UDP data." >&2
  56. exec tsocks "$@"
  57. echo "$0: Failed to exec tsocks $@" >&2
  58. exit 1
  59. else
  60. echo "$0: Missing tsocks configuration file \"$TSOCKS_CONF_FILE\"." >&2
  61. exit 1
  62. fi
  63. fi
  64. if [ "$PROG" = "$TORSOCKS" ]
  65. then
  66. exec torsocks "$@"
  67. fi