commit 4073958481faaf3220b09a3a499e1f104d969d29
Author: Alexander Færøy <[email protected]>
Date:   Mon Oct 12 23:21:25 2015 +0200

    Add --address and --port for torsocks.
    
    This patch adds two new arguments for the torsocks script: --address
    (-a), for specifying the address of the Tor instance to use, and --port
    (-P), for specifying the port of the Tor instance to use.
---
 doc/torsocks.1        |  6 ++++++
 doc/torsocks.8        |  8 ++++++++
 src/bin/torsocks.in   | 38 ++++++++++++++++++++++++++++----------
 src/common/defaults.h |  4 ++++
 src/lib/torsocks.c    | 18 +++++++++++++++++-
 5 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/doc/torsocks.1 b/doc/torsocks.1
index 0e3c341..e4ac628 100644
--- a/doc/torsocks.1
+++ b/doc/torsocks.1
@@ -47,6 +47,12 @@ Set password for the SOCKS5 authentication. Use for circuit 
isolation in Tor.
 Note that you MUST have a username set either by the command line, environment
 variable or configuration file (torsocks.conf(5)).
 .TP
+.BR "\-a, \-\-address"
+Set Tor address.
+.TP
+.BR "\-P, \-\-port"
+Set Tor port.
+.TP
 .BR "\-i, \-\-isolate"
 Automatic tor isolation. Set the username and password for the SOCKS5
 authentication method to a PID/current time based value automatically. Username
diff --git a/doc/torsocks.8 b/doc/torsocks.8
index ac3863a..c3f477f 100644
--- a/doc/torsocks.8
+++ b/doc/torsocks.8
@@ -95,6 +95,14 @@ Set the password for the SOCKS5 authentication method. 
Username MUST be set
 also with the variable above.
 
 .PP
+.IP TORSOCKS_TOR_ADDRESS
+Set the Tor address. (default: 127.0.0.1)
+
+.PP
+.IP TORSOCKS_TOR_PORT
+Set the Tor port. (default: 9050)
+
+.PP
 .IP TORSOCKS_ALLOW_INBOUND
 Allow inbound connections so the application can accept and listen for
 connections.
diff --git a/src/bin/torsocks.in b/src/bin/torsocks.in
index 5102fdc..b030ad2 100644
--- a/src/bin/torsocks.in
+++ b/src/bin/torsocks.in
@@ -140,16 +140,18 @@ usage ()
        echo "usage: $0 command args"
        echo ""
        echo "Options:"
-       echo "  -h, --help      Show this help"
-       echo "      --shell     Spawn a torified shell"
-       echo "      --version   Show version"
-       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 "  -i, --isolate   Automatic tor isolation. Can't be used with 
-u/-p"
-       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 "  -h, --help         Show this help"
+       echo "      --shell        Spawn a torified shell"
+       echo "      --version      Show version"
+       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 "  -i, --isolate      Automatic tor isolation. Can't be used with 
-u/-p"
+       echo "  -a, --address HOST Specify Tor address"
+       echo "  -P, --port PORT    Specify Tor port"
+       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 "Examples:"
        echo ""
@@ -230,6 +232,22 @@ do
                        export TORSOCKS_PASSWORD=$2
                        shift
                        ;;
+               -a|--address)
+                       if [ -z $2 ]; then
+                               echo "Missing address to -a" >&2
+                               exit 1
+                       fi
+                       export TORSOCKS_TOR_ADDRESS=$2
+                       shift
+                       ;;
+               -P|--port)
+                       if [ -z $2 ]; then
+                               echo "Missing port to -P" >&2
+                               exit 1
+                       fi
+                       export TORSOCKS_TOR_PORT=$2
+                       shift
+                       ;;
                -i|--isolate)
                        export TORSOCKS_ISOLATE_PID=1
                        ;;
diff --git a/src/common/defaults.h b/src/common/defaults.h
index ab51690..958e7cd 100644
--- a/src/common/defaults.h
+++ b/src/common/defaults.h
@@ -63,6 +63,10 @@
 #define DEFAULT_SOCKS5_USER_ENV     "TORSOCKS_USERNAME"
 #define DEFAULT_SOCKS5_PASS_ENV     "TORSOCKS_PASSWORD"
 
+/* Env. variable for Tor hostname and port. */
+#define DEFAULT_TOR_ADDRESS_ENV     "TORSOCKS_TOR_ADDRESS"
+#define DEFAULT_TOR_PORT_ENV        "TORSOCKS_TOR_PORT"
+
 /* Control if torsocks allows inbound connection or not. */
 #define DEFAULT_ALLOW_INBOUND_ENV   "TORSOCKS_ALLOW_INBOUND"
 
diff --git a/src/lib/torsocks.c b/src/lib/torsocks.c
index 7944e57..731b33c 100644
--- a/src/lib/torsocks.c
+++ b/src/lib/torsocks.c
@@ -75,7 +75,7 @@ static void clean_exit(int status)
 static void read_env(void)
 {
        int ret;
-       const char *username, *password, *allow_in, *isolate_pid;
+       const char *username, *password, *allow_in, *isolate_pid, *tor_address, 
*tor_port;
 
        if (is_suid) {
                goto end;
@@ -97,6 +97,22 @@ static void read_env(void)
                }
        }
 
+       tor_address = getenv(DEFAULT_TOR_ADDRESS_ENV);
+       if (tor_address) {
+               ret = conf_file_set_tor_address(tor_address, &tsocks_config);
+               if (ret < 0) {
+                       goto error;
+               }
+       }
+
+       tor_port = getenv(DEFAULT_TOR_PORT_ENV);
+       if (tor_port) {
+               ret = conf_file_set_tor_port(tor_port, &tsocks_config);
+               if (ret < 0) {
+                       goto error;
+               }
+       }
+
        username = getenv(DEFAULT_SOCKS5_USER_ENV);
        password = getenv(DEFAULT_SOCKS5_PASS_ENV);
        if (!username && !password) {



_______________________________________________
tor-commits mailing list
[email protected]
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to