#! /bin/sh /usr/share/dpatch/dpatch-run ## 07_config_env.dpatch by Dan Muresan ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: Parse some config options from environment (TSOCKS_SERVER) @DPATCH@ diff -urNad tsocks-1.8beta5~/debian/plus/tsocks tsocks-1.8beta5/debian/plus/tsocks --- tsocks-1.8beta5~/debian/plus/tsocks 2008-05-08 09:42:36.000000000 +0300 +++ tsocks-1.8beta5/debian/plus/tsocks 2008-05-08 09:42:37.704774910 +0300 @@ -66,6 +66,12 @@ echo "$0: Please see tsocks(1) or read comment at top of $0" ;; *) + if [ "x$1" = "x--server" ]; then + export TSOCKS_SERVER="$2"; shift; shift + fi + if [ "x$1" = "x--server-port" ]; then + export TSOCKS_SERVER_PORT="$2"; shift; shift + fi if [ -z "$LD_PRELOAD" ] then export LD_PRELOAD="/usr/lib/libtsocks.so" diff -urNad tsocks-1.8beta5~/debian/plus/tsocks.1 tsocks-1.8beta5/debian/plus/tsocks.1 --- tsocks-1.8beta5~/debian/plus/tsocks.1 2008-05-08 09:42:36.000000000 +0300 +++ tsocks-1.8beta5/debian/plus/tsocks.1 2008-05-08 09:49:43.620392115 +0300 @@ -6,7 +6,7 @@ transparently allow an application to use a SOCKS proxy .SH SYNOPSIS .B tsocks -.RB [application\ [application's\ arguments]] +.RB [options]\ [application\ [application's\ arguments]] .br or .B tsocks @@ -19,10 +19,11 @@ is a wrapper between the tsocks library and the application what you would like to run socksified. .SH OPTIONS -.IP \fB[application\ \fB[application's\ arguments]] +.IP \fB[options]\ \fB[application\ \fB[application's\ arguments]] run the application as specified with the environment (LD_PRELOAD) set such that tsocks(8) will transparently proxy SOCKS connections in -that program +that program. The initial options arguments can override some +configuration settings: "\-\-server\ server" and "\-\-server\-port\ port" .IP \fB[\-on|\-off] this option adds or removes tsocks(8) from the LD_PRELOAD environment variable. When tsocks(8) is in this variable all executed diff -urNad tsocks-1.8beta5~/parser.c tsocks-1.8beta5/parser.c --- tsocks-1.8beta5~/parser.c 2008-05-08 09:42:37.620775094 +0300 +++ tsocks-1.8beta5/parser.c 2008-05-08 09:42:37.704774910 +0300 @@ -107,6 +107,23 @@ /* Always add the 127.0.0.1/255.0.0.0 subnet to local */ handle_local(config, 0, "127.0.0.0/255.0.0.0"); +#ifdef ALLOW_ENV_CONFIG + /* Add settings from env */ + { + const char *env; + + /* create appropriate lines */ + if ((env = getenv ("TSOCKS_SERVER")) != NULL) { + snprintf (line, MAXLINE, "server = %s", env); + handle_line (config, line, 0); + } + if ((env = getenv ("TSOCKS_SERVER_PORT")) != NULL) { + snprintf (line, MAXLINE, "server_port = %s", env); + handle_line (config, line, 0); + } + } +#endif + /* Check default server */ check_server(&(config->defaultserver)); server = (config->paths); @@ -211,8 +228,8 @@ tokenno++; tokens[tokenno] = line; line = line + strcspn(line, " \t"); - *line = (char) 0; - line++; + if (*line != '\0') + *line++ = '\0'; /* We ignore everything after a # */ if (*tokens[tokenno] == '#') { @@ -343,11 +360,10 @@ if (currentcontext->address == NULL) currentcontext->address = strdup(ip); else { - if (currentcontext == &(config->defaultserver)) - show_msg(MSGERR, "Only one default SOCKS server " - "may be specified at line %d in " - "configuration file\n", lineno); - else + if (currentcontext == &(config->defaultserver)) { + free (currentcontext->address); + currentcontext->address = strdup(ip); + } else show_msg(MSGERR, "Only one SOCKS server may be specified " "per path on line %d in configuration " "file. (Path begins on line %d)\n", diff -urNad tsocks-1.8beta5~/tsocks.8 tsocks-1.8beta5/tsocks.8 --- tsocks-1.8beta5~/tsocks.8 2008-05-08 09:42:37.576750260 +0300 +++ tsocks-1.8beta5/tsocks.8 2008-05-08 09:42:37.704774910 +0300 @@ -67,6 +67,14 @@ configure at build time .TP +.I TSOCKS_SERVER +This environment variable overrides the default server setting. + +.TP +.I TSOCKS_SERVER_PORT +This environment variable overrides the default server port setting. + +.TP .I TSOCKS_DEBUG This environment variable sets the level of debug output that should be generated by tsocks (debug output is generated in the form of output to