diff -ruN tsocks-1.8/parser.c tsocks-1.8-remotepath/parser.c --- tsocks-1.8/parser.c 2002-03-13 06:34:22.000000000 -0600 +++ tsocks-1.8-remotepath/parser.c 2005-09-13 17:22:37.000000000 -0500 @@ -22,7 +22,7 @@ static int handle_line(struct parsedfile *, char *, int); static int check_server(struct serverent *); static int tokenize(char *, int, char *[]); -static int handle_path(struct parsedfile *, int, int, char *[]); +static int handle_path(struct parsedfile *, int, int, char *[], int); static int handle_endpath(struct parsedfile *, int, int, char *[]); static int handle_reaches(struct parsedfile *, int, char *); static int handle_server(struct parsedfile *, int, char *); @@ -84,6 +84,11 @@ check_server(server); server = server->next; } + server = (config->remotepaths); + while (server != NULL) { + check_server(server); + server = server->next; + } } @@ -129,7 +134,9 @@ /* ender, otherwise it has to be a pair ( = */ /* ) */ if (!strcmp(words[0], "path")) { - handle_path(config, lineno, nowords, words); + handle_path(config, lineno, nowords, words, 0); + } else if (!strcmp(words[0], "remotepath")) { + handle_path(config, lineno, nowords, words, 1); } else if (!strcmp(words[0], "}")) { handle_endpath(config, lineno, nowords, words); } else { @@ -192,7 +199,7 @@ return(tokenno + 1); } -static int handle_path(struct parsedfile *config, int lineno, int nowords, char *words[]) { +static int handle_path(struct parsedfile *config, int lineno, int nowords, char *words[], int remote) { struct serverent *newserver; if ((nowords != 2) || (strcmp(words[1], "{"))) { @@ -214,9 +221,14 @@ show_msg(MSGDEBUG, "New server structure from line %d in configuration file going " "to 0x%08x\n", lineno, newserver); memset(newserver, 0x0, sizeof(*newserver)); - newserver->next = config->paths; newserver->lineno = lineno; - config->paths = newserver; + if (remote) { + newserver->next = config->remotepaths; + config->remotepaths = newserver; + } else { + newserver->next = config->paths; + config->paths = newserver; + } currentcontext = newserver; } @@ -592,12 +604,16 @@ /* Find the appropriate server to reach an ip */ int pick_server(struct parsedfile *config, struct serverent **ent, - struct in_addr *ip, unsigned int port) { + struct in_addr *ip, unsigned int port, int remote) { struct netent *net; char ipbuf[64]; show_msg(MSGDEBUG, "Picking appropriate server for %s\n", inet_ntoa(*ip)); - *ent = (config->paths); + if (remote) { + *ent = (config->remotepaths); + } else { + *ent = (config->paths); + } while (*ent != NULL) { /* Go through all the servers looking for one */ /* with a path to this network */ diff -ruN tsocks-1.8/parser.h tsocks-1.8-remotepath/parser.h --- tsocks-1.8/parser.h 2002-02-10 01:26:27.000000000 -0600 +++ tsocks-1.8-remotepath/parser.h 2005-09-13 17:22:33.000000000 -0500 @@ -33,12 +33,13 @@ struct netent *localnets; struct serverent defaultserver; struct serverent *paths; + struct serverent *remotepaths; }; /* Functions provided by parser module */ int read_config(char *, struct parsedfile *); int is_local(struct parsedfile *, struct in_addr *); -int pick_server(struct parsedfile *, struct serverent **, struct in_addr *, unsigned int port); +int pick_server(struct parsedfile *, struct serverent **, struct in_addr *, unsigned int port, int); char *strsplit(char *separator, char **text, const char *search); #endif diff -ruN tsocks-1.8/tsocks.c tsocks-1.8-remotepath/tsocks.c --- tsocks-1.8/tsocks.c 2002-07-15 17:50:52.000000000 -0500 +++ tsocks-1.8-remotepath/tsocks.c 2005-09-13 17:27:07.000000000 -0500 @@ -277,14 +277,23 @@ show_msg(MSGDEBUG, "Got connection request for socket %d to " "%s\n", __fd, inet_ntoa(connaddr->sin_addr)); - /* If the address is local call realconnect */ - if (!(is_local(config, &(connaddr->sin_addr)))) { - show_msg(MSGDEBUG, "Connection for socket %d is local\n", __fd); - return(realconnect(__fd, __addr, __len)); - } + /* First see if there are any remote paths */ + pick_server(config, &path, &(connaddr->sin_addr), ntohs(connaddr->sin_port), 1); + + /* If no remote paths were found, check to see if it's defined as local and check for + * other paths */ + if (path == &(config->defaultserver)) { + + /* If the address is local call realconnect */ + if (!(is_local(config, &(connaddr->sin_addr)))) { + show_msg(MSGDEBUG, "Connection for socket %d is local\n", __fd); + return(realconnect(__fd, __addr, __len)); + } - /* Ok, so its not local, we need a path to the net */ - pick_server(config, &path, &(connaddr->sin_addr), ntohs(connaddr->sin_port)); + /* Ok, so its not local, we need a path to the net */ + pick_server(config, &path, &(connaddr->sin_addr), ntohs(connaddr->sin_port), 0); + + } show_msg(MSGDEBUG, "Picked server %s for connection\n", (path->address ? path->address : "(Not Provided)")); diff -ruN tsocks-1.8/validateconf.c tsocks-1.8-remotepath/validateconf.c --- tsocks-1.8/validateconf.c 2002-02-07 04:49:59.000000000 -0600 +++ tsocks-1.8-remotepath/validateconf.c 2005-09-13 17:36:07.000000000 -0500 @@ -108,17 +108,23 @@ return; } else { printf("Finding path for %s...\n", inet_ntoa(hostaddr)); - if (!(is_local(config, &(hostaddr)))) { - printf("Path is local\n"); - } else { - pick_server(config, &path, &hostaddr, portno); - if (path == &(config->defaultserver)) { - printf("Path is via default server:\n"); - show_server(config, path, 1); + pick_server(config, &path, &hostaddr, portno, 1); + if (path == &(config->defaultserver)) { + if (!(is_local(config, &(hostaddr)))) { + printf("Path is local\n"); } else { - printf("Host is reached via this path:\n"); - show_server(config, path, 0); + pick_server(config, &path, &hostaddr, portno, 0); + if (path == &(config->defaultserver)) { + printf("Path is via default server:\n"); + show_server(config, path, 1); + } else { + printf("Host is reached via this path:\n"); + show_server(config, path, 0); + } } + } else { + printf("Host is reached via this remote path:\n"); + show_server(config, path, 0); } } @@ -163,6 +169,18 @@ } } + /* Now show remote paths */ + if ((config->remotepaths) != NULL) { + server = (config->remotepaths); + while (server != NULL) { + printf("=== Remote Path (line no %d in configuration file)" + " ===\n", server->lineno); + show_server(config, server, 0); + printf("\n"); + server = server->next; + } + } + return; }