torify.in 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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, 2009 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. # taken from Debian's Developer's Reference, 6.4
  8. pathfind() {
  9. OLDIFS="$IFS"
  10. IFS=:
  11. for p in $PATH; do
  12. if [ -x "$p/$*" ]; then
  13. IFS="$OLDIFS"
  14. return 0
  15. fi
  16. done
  17. IFS="$OLDIFS"
  18. return 1
  19. }
  20. # Check for any argument list
  21. if [ "$#" = 0 ]; then
  22. echo "Usage: $0 [-hv] <command> [<options>...]" >&2
  23. exit 1
  24. fi
  25. if [ "$#" = 1 ] && ( [ "$1" = "-h" ] || [ "$1" = "--help" ] ); then
  26. echo "Usage: $0 [-hv] <command> [<options>...]"
  27. exit 0
  28. fi
  29. if [ "$1" = "-v" ] || [ "$1" = "--verbose" ]; then
  30. verbose=1
  31. shift 1
  32. else
  33. verbose=0
  34. fi
  35. if pathfind torsocks; then
  36. ! [ "$verbose" -ge 1 ] || echo "Using torsocks as socksifier." >&2
  37. exec torsocks "$@"
  38. echo "$0: Failed to exec torsocks $@" >&2
  39. exit 1
  40. elif pathfind tsocks; then
  41. ! [ "$verbose" -ge 1 ] || echo "Using tsocks as socksifier." >&2
  42. # Define our tsocks config file
  43. TSOCKS_CONF_FILE="/etc/tor/tor-tsocks.conf"
  44. export TSOCKS_CONF_FILE
  45. # Check that we've got a tsocks config file
  46. if [ -r "$TSOCKS_CONF_FILE" ]
  47. then
  48. echo "WARNING: tsocks is known to leak DNS and UDP data. If you had torsocks we would use that." >&2
  49. exec tsocks "$@"
  50. echo "$0: Failed to exec tsocks $@" >&2
  51. exit 1
  52. else
  53. echo "$0: Missing tsocks configuration file \"$TSOCKS_CONF_FILE\"." >&2
  54. exit 1
  55. fi
  56. else
  57. echo "$0: Can't find neither tsocks nor torsocks in your PATH. Perhaps you haven't installed either?" >&2
  58. exit 1
  59. fi