[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [torsocks/master] Add -u/-p/-d to torsocks script



commit f0250901ac3ecef397bd86782ebbc3ced7f0d502
Author: David Goulet <dgoulet@xxxxxxxxx>
Date:   Mon Mar 3 15:04:43 2014 -0500

    Add -u/-p/-d to torsocks script
    
    The -u, --user and -p, --pass are for the SOCKS5 authentication where
    -d, --debug is to set torsocks in DEBUG mode.
    
    Improve the usage output and make sure torsocks on/off is being sourced
    else exit with error.
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxx>
---
 src/bin/torsocks.in |  125 ++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 90 insertions(+), 35 deletions(-)

diff --git a/src/bin/torsocks.in b/src/bin/torsocks.in
index 9abc5e8..a392d0b 100644
--- a/src/bin/torsocks.in
+++ b/src/bin/torsocks.in
@@ -100,7 +100,9 @@ torify_app ()
 	# NEVER remove that line or else nothing it torified.
 	set_ld_preload
 
-	if [ -z $app_path ]; then
+	if [ -z $1 ]; then
+		echo "Please provide an application to torify." >&2
+	elif [ -z $app_path ]; then
 		echo "ERROR: $1 cannot be found." >&2
 		exit 1
 	elif [ -u $app_path -o -g $app_path ]; then
@@ -123,14 +125,32 @@ usage ()
 	echo "  -h, --help      Show this help"
 	echo "      --shell     Spawn a torified shell"
 	echo "      --version   Show version"
-	echo "  on, off         Add or remove torsocks library from @LDPRELOAD@"
-	echo "  show, sh        Show the current value of the @LDPRELOAD@"
+	echo "  -d, --debug     Set debug mode."
+	echo "  -u, --user NAME Username for the SOCKS5 authentication"
+	echo "  -p, --pass NAME Password for the SOCKS5 authentication"
+	echo "  on, off         Set/Unset your shell to use Torsocks by default"
+	echo "                  Make sure to source the call when using this option. (See Examples)"
+	echo "  show, sh        Show the current value of the LD_PRELOAD"
 	echo ""
-	echo "Example:"
+	echo "Examples:"
+	echo ""
+	echo "Simple use of torsocks with SSH"
 	echo "    $ torsocks ssh user@xxxxxxxx -p 1234"
 	echo ""
+	echo "Set your current shell in Tor mode."
+	echo "    $ . torsocks on"
+	echo ""
 	echo "Please see torsocks(1), torsocks.conf(5) and torsocks(8) for more information."
+}
 
+# Check if we are being sourced.
+check_script_sourced()
+{
+	if [ "$_" = "$0" ]; then
+		echo "Torsocks MUST be sourced for this command to work" >&2
+		echo "  $ . torsocks $1" >&2
+		exit 1
+	fi
 }
 
 if [ $# -eq 0 ] ; then
@@ -144,34 +164,69 @@ if [ ! -f $SHLIB ]; then
    exit
 fi
 
-case "$1" in
-	on)
-		set_ld_preload
-		;;
-	off)
-		export @LDPRELOAD@=`echo -n $@LDPRELOAD@ | sed "s#$SHLIB *##"`
-		if [ -z "$@LDPRELOAD@" ]; then
-			unset @LDPRELOAD@
-			case "$OSTYPE" in
-				darwin*)
-					unset DYLD_FORCE_FLAT_NAMESPACE
-					;;
-			esac
-		fi
-		;;
-	show|sh)
-		echo "@LDPRELOAD@=\"$@LDPRELOAD@\""
-		;;
-	-h|--help|-?)
-		usage
-		;;
-	--shell)
-		tor_shell
-		;;
-	--version)
-		echo "Torsocks @VERSION@"
-		;;
-	*)
-		torify_app "$@"
-		;;
-esac
+while true;
+do
+	case "$1" in
+		on)
+			check_script_sourced $1
+			set_ld_preload
+			echo "Tor mode activated. Every command will be torified for this shell."
+			break
+			;;
+		off)
+			check_script_sourced $1
+			export @LDPRELOAD@=`echo -n $@LDPRELOAD@ | sed "s#$SHLIB *##"`
+			if [ -z "$@LDPRELOAD@" ]; then
+				unset @LDPRELOAD@
+				case "$OSTYPE" in
+					darwin*)
+						unset DYLD_FORCE_FLAT_NAMESPACE
+						;;
+				esac
+			fi
+			echo "Tor mode deactivated. Command will NOT go through Tor anymore."
+			break
+			;;
+		show|sh)
+			echo "@LDPRELOAD@=\"$@LDPRELOAD@\""
+			break
+			;;
+		-h|--help)
+			usage
+			break
+			;;
+		-u|--user)
+			if [ -z $2 ]; then
+				echo "Missing username to -u" >&2
+				exit 1
+			fi
+			export TORSOCKS_USERNAME=$2
+			shift
+			;;
+		-p|--pass)
+			if [ -z $2 ]; then
+				echo "Missing password to -p" >&2
+				exit 1
+			fi
+			export TORSOCKS_PASSWORD=$2
+			shift
+			;;
+		-d|--debug)
+			# Set full DEBUG with 5 being the highest possible level.
+			export TORSOCKS_LOG_LEVEL=5
+			;;
+		--shell)
+			tor_shell
+			break
+			;;
+		--version)
+			echo "Torsocks @VERSION@"
+			break
+			;;
+		*)
+			torify_app "$@"
+			break
+			;;
+	esac
+	shift
+done



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits