1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 06_fallback.dpatch by Tamas SZERB <toma@rulez.org>
4 ## All lines beginning with `## DP:' are a description of the patch.
5 ## DP: Establish direct connection instead of sockified if
6 ## DP: there is no default server specified and the
11 @@
-33,6 +33,7 @@ struct parsedfile
{
12 struct netent
*localnets
;
13 struct serverent defaultserver
;
14 struct serverent
*paths
;
18 /* Functions provided by parser module
*/
21 @@
-35,6 +35,7 @@ static int handle_local
(struct parsedfil
22 static int handle_defuser
(struct parsedfile
*, int
, char
*);
23 static int handle_defpass
(struct parsedfile
*, int
, char
*);
24 static int make_netent
(char
*value
, struct netent
**ent
);
25 +static int handle_fallback
(struct parsedfile
*, int
, char
*);
27 char __attribute__
((visibility
("hidden")))
28 *find_config
(char
*line
) {
29 @@
-181,6 +182,8 @@ static int handle_line
(struct parsedfile
30 handle_defpass
(config
, lineno
, words
[2]);
31 } else if (!strcmp
(words
[0], "local")) {
32 handle_local
(config
, lineno
, words
[2]);
33 + } else if (!strcmp
(words
[0], "fallback")) {
34 + handle_fallback
(config
, lineno
, words
[2]);
36 show_msg
(MSGERR
, "Invalid pair type (%s) specified "
37 "on line %d in configuration file, "
38 @@
-512,6 +515,19 @@ static int handle_local
(struct parsedfil
42 +static int handle_fallback
(struct parsedfile
*config
, int lineno
, char
*value
) {
43 + char
*v
= strsplit
(NULL
, &value
, " ");
44 + if (config-
>fallback
!=0) {
45 + show_msg
(MSGERR
, "Fallback may only be specified "
46 + "once in configuration file.\n",
47 + lineno
, currentcontext-
>lineno
);
49 + if(!strcmp
(v
, "yes")) config-
>fallback
= 1;
50 + if(!strcmp
(v
, "no")) config-
>fallback
= 0;
55 /* Construct a netent given a string like
*/
56 /* "198.126.0.1[:portno[-portno]]/255.255.255.0" */
57 int make_netent
(char
*value
, struct netent
**ent
) {
60 @@
-294,11 +294,20 @@ int connect
(CONNECT_SIGNATURE
) {
61 (path-
>address ? path-
>address
: "(Not Provided)"));
62 if (path-
>address
== NULL
) {
63 if (path
== &(config-
>defaultserver
)) {
64 - show_msg
(MSGERR
, "Connection needs to be made "
65 - "via default server but "
66 - "the default server has not "
67 - "been specified. Falling back to direct connection.\n");
68 - return(realconnect
(__fd
, __addr
, __len
));
69 + if (config-
>fallback
) {
70 + show_msg
(MSGERR
, "Connection needs to be made "
71 + "via default server but "
72 + "the default server has not "
73 + "been specified. Fallback is 'yes' so "
74 + "Falling back to direct connection.\n");
75 + return(realconnect
(__fd
, __addr
, __len
));
77 + show_msg
(MSGERR
, "Connection needs to be made "
78 + "via default server but "
79 + "the default server has not "
80 + "been specified. Fallback is 'no' so "
81 + "coudln't establish the connection.\n");
85 show_msg
(MSGERR
, "Connection needs to be made "
88 @@
-135,6 +135,15 @@ tsocks gives an error message and aborts
89 This parameter protects the user against accidentally establishing
90 unwanted unsockified
(ie. direct
) connection.
94 +This directive allows to fall back to direct connection
if no default
95 +server present
in the configuration and fallback
= yes.
96 +If fallback
= no or not specified and there is no default server
, the
97 +tsocks gives an error message and aborts.
98 +This parameter protects the user against accidentally establishing
99 +unwanted unsockified
(ie. direct
) connection.
102 tsocks comes with two utilities that can be useful
in creating and verifying
103 the tsocks configuration
file.