Commits

Markus Tzoe  committed b67efa5

Alternative config patched.

1. patched with "http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=07_config_env.dpatch;att=1;bug=480119";
2. add line_arg "--local" with env "TSOCKS_LOCAL" to specify a local subnet

  • Participants
  • Parent commits 2eb3f18
  • Branches master

Comments (0)

Files changed (4)

 		/* 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);
+        }
+        if ((env = getenv ("TSOCKS_LOCAL")) != NULL) {
+            snprintf (line, MAXLINE, "%s", env);
+            handle_local(config, 0, line);
+        }
+    }
+#endif
+
 		/* Check default server */
 		check_server(&(config->defaultserver));
 		server = (config->paths);
 		tokenno++;
 		tokens[tokenno] = line;
 		line = line + strcspn(line, " \t");
-		*line = (char) 0;
-		line++;
+		//*line = (char) 0;
+		//line++;
+        if (*line != '\0')
+            *line++ = '\0';
 
 		/* We ignore everything after a # */
 		if (*tokens[tokenno] == '#') { 
 	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)) 
+		//	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",
       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 [ "x$1" = "x--local" ]; then
+            export TSOCKS_LOCAL="$2"; shift; shift
+        fi
 		if [ -z "$LD_PRELOAD" ]
 		then
-			export LD_PRELOAD="/usr/lib/libtsocks.so"
+			export LD_PRELOAD="/lib/libtsocks.so"
 		else
-			echo $LD_PRELOAD | grep -q "/usr/lib/libtsocks\.so" || \
-			export LD_PRELOAD="/usr/lib/libtsocks.so $LD_PRELOAD"
+			echo $LD_PRELOAD | grep -q "/lib/libtsocks\.so" || \
+			export LD_PRELOAD="/lib/libtsocks.so $LD_PRELOAD"
 		fi
 
 		if [ $# = 0 ]
 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
 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
 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