mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-26 07:31:33 +01:00
Let's be smarter while parsing {Client,Server}TransportPlugin lines.
This commit is contained in:
parent
14c5a24fe7
commit
51cdd30c01
2 changed files with 29 additions and 36 deletions
|
@ -4702,22 +4702,25 @@ parse_client_transport_line(const char *line, int validate_only)
|
||||||
/* managed proxy options */
|
/* managed proxy options */
|
||||||
int is_managed=0;
|
int is_managed=0;
|
||||||
char **proxy_argv=NULL;
|
char **proxy_argv=NULL;
|
||||||
|
char **tmp=NULL;
|
||||||
|
int proxy_argc,i;
|
||||||
|
|
||||||
|
int line_length;
|
||||||
|
|
||||||
items = smartlist_create();
|
items = smartlist_create();
|
||||||
smartlist_split_string(items, line, NULL,
|
smartlist_split_string(items, line, NULL,
|
||||||
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, -1);
|
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, -1);
|
||||||
|
|
||||||
if (smartlist_len(items) < 3) {
|
line_length = smartlist_len(items);
|
||||||
|
if (line_length < 3) {
|
||||||
log_warn(LD_CONFIG, "Too few arguments on ClientTransportPlugin line.");
|
log_warn(LD_CONFIG, "Too few arguments on ClientTransportPlugin line.");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = smartlist_get(items, 0);
|
name = smartlist_get(items, 0);
|
||||||
smartlist_del_keeporder(items, 0);
|
|
||||||
|
|
||||||
/* field2 is either a SOCKS version or "exec" */
|
/* field2 is either a SOCKS version or "exec" */
|
||||||
field2 = smartlist_get(items, 0);
|
field2 = smartlist_get(items, 1);
|
||||||
smartlist_del_keeporder(items, 0);
|
|
||||||
|
|
||||||
if (!strcmp(field2,"socks4")) {
|
if (!strcmp(field2,"socks4")) {
|
||||||
socks_ver = PROXY_SOCKS4;
|
socks_ver = PROXY_SOCKS4;
|
||||||
|
@ -4735,16 +4738,12 @@ parse_client_transport_line(const char *line, int validate_only)
|
||||||
if (!validate_only) { /* if we are not just validating, use the
|
if (!validate_only) { /* if we are not just validating, use the
|
||||||
rest of the line as the argv of the proxy
|
rest of the line as the argv of the proxy
|
||||||
to be launched */
|
to be launched */
|
||||||
char **tmp;
|
proxy_argc = line_length-2;
|
||||||
char *tmp_arg;
|
tor_assert(proxy_argc > 0);
|
||||||
proxy_argv = tor_malloc_zero(sizeof(char*)*(smartlist_len(items)+1));
|
proxy_argv = tor_malloc_zero(sizeof(char*)*(proxy_argc+1));
|
||||||
tmp = proxy_argv;
|
tmp = proxy_argv;
|
||||||
while (smartlist_len(items)) {
|
for (i=0;i<proxy_argc;i++) /* store arguments */
|
||||||
tmp_arg = smartlist_get(items, 0);
|
*tmp++ = smartlist_get(items, 2+i);
|
||||||
smartlist_del_keeporder(items, 0);
|
|
||||||
*tmp++ = tor_strdup(tmp_arg);
|
|
||||||
tor_free(tmp_arg);
|
|
||||||
}
|
|
||||||
*tmp = NULL; /*terminated with NUL pointer, just like execve() likes it*/
|
*tmp = NULL; /*terminated with NUL pointer, just like execve() likes it*/
|
||||||
|
|
||||||
if (pt_managed_launch_client_proxy(name, proxy_argv) < 0) {
|
if (pt_managed_launch_client_proxy(name, proxy_argv) < 0) {
|
||||||
|
@ -4754,8 +4753,7 @@ parse_client_transport_line(const char *line, int validate_only)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { /* external */
|
} else { /* external */
|
||||||
addrport = smartlist_get(items, 0);
|
addrport = smartlist_get(items, 2);
|
||||||
smartlist_del_keeporder(items, 0);
|
|
||||||
|
|
||||||
if (tor_addr_port_parse(addrport, &addr, &port)<0) {
|
if (tor_addr_port_parse(addrport, &addr, &port)<0) {
|
||||||
log_warn(LD_CONFIG, "Error parsing transport "
|
log_warn(LD_CONFIG, "Error parsing transport "
|
||||||
|
@ -4788,9 +4786,7 @@ parse_client_transport_line(const char *line, int validate_only)
|
||||||
done:
|
done:
|
||||||
SMARTLIST_FOREACH(items, char*, s, tor_free(s));
|
SMARTLIST_FOREACH(items, char*, s, tor_free(s));
|
||||||
smartlist_free(items);
|
smartlist_free(items);
|
||||||
tor_free(name);
|
tor_free(proxy_argv);
|
||||||
tor_free(field2);
|
|
||||||
tor_free(addrport);
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4813,21 +4809,24 @@ parse_server_transport_line(const char *line, int validate_only)
|
||||||
/* managed proxy options */
|
/* managed proxy options */
|
||||||
int is_managed=0;
|
int is_managed=0;
|
||||||
char **proxy_argv=NULL;
|
char **proxy_argv=NULL;
|
||||||
|
char **tmp=NULL;
|
||||||
|
int proxy_argc,i;
|
||||||
|
|
||||||
|
int line_length;
|
||||||
|
|
||||||
items = smartlist_create();
|
items = smartlist_create();
|
||||||
smartlist_split_string(items, line, NULL,
|
smartlist_split_string(items, line, NULL,
|
||||||
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, -1);
|
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, -1);
|
||||||
|
|
||||||
if (smartlist_len(items) < 3) {
|
line_length = smartlist_len(items);
|
||||||
|
if (line_length < 3) {
|
||||||
log_warn(LD_CONFIG, "Too few arguments on ServerTransportPlugin line.");
|
log_warn(LD_CONFIG, "Too few arguments on ServerTransportPlugin line.");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = smartlist_get(items, 0);
|
name = smartlist_get(items, 0);
|
||||||
smartlist_del_keeporder(items, 0);
|
|
||||||
|
|
||||||
type = smartlist_get(items, 0);
|
type = smartlist_get(items, 1);
|
||||||
smartlist_del_keeporder(items, 0);
|
|
||||||
|
|
||||||
if (!strcmp(type, "exec")) {
|
if (!strcmp(type, "exec")) {
|
||||||
is_managed=1;
|
is_managed=1;
|
||||||
|
@ -4840,16 +4839,13 @@ parse_server_transport_line(const char *line, int validate_only)
|
||||||
|
|
||||||
if (is_managed) { /* managed */
|
if (is_managed) { /* managed */
|
||||||
if (!validate_only) {
|
if (!validate_only) {
|
||||||
char **tmp;
|
proxy_argc = line_length-2;
|
||||||
char *tmp_arg;
|
tor_assert(proxy_argc > 0);
|
||||||
proxy_argv = tor_malloc_zero(sizeof(char*)*(smartlist_len(items)+1));
|
proxy_argv = tor_malloc_zero(sizeof(char*)*(proxy_argc+1));
|
||||||
tmp = proxy_argv;
|
tmp = proxy_argv;
|
||||||
while (smartlist_len(items)) {
|
|
||||||
tmp_arg = smartlist_get(items, 0);
|
for (i=0;i<proxy_argc;i++) /* store arguments */
|
||||||
smartlist_del_keeporder(items, 0);
|
*tmp++ = smartlist_get(items, 2+i);
|
||||||
*tmp++ = tor_strdup(tmp_arg);
|
|
||||||
tor_free(tmp_arg);
|
|
||||||
}
|
|
||||||
*tmp = NULL; /*terminated with NUL pointer, just like execve() likes it*/
|
*tmp = NULL; /*terminated with NUL pointer, just like execve() likes it*/
|
||||||
|
|
||||||
if (pt_managed_launch_server_proxy(name, proxy_argv) < 0) { /* launch it! */
|
if (pt_managed_launch_server_proxy(name, proxy_argv) < 0) { /* launch it! */
|
||||||
|
@ -4859,8 +4855,7 @@ parse_server_transport_line(const char *line, int validate_only)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { /* external */
|
} else { /* external */
|
||||||
addrport = smartlist_get(items, 0);
|
addrport = smartlist_get(items, 2);
|
||||||
smartlist_del_keeporder(items, 0);
|
|
||||||
|
|
||||||
if (tor_addr_port_parse(addrport, &addr, &port)<0) {
|
if (tor_addr_port_parse(addrport, &addr, &port)<0) {
|
||||||
log_warn(LD_CONFIG, "Error parsing transport "
|
log_warn(LD_CONFIG, "Error parsing transport "
|
||||||
|
@ -4888,8 +4883,7 @@ parse_server_transport_line(const char *line, int validate_only)
|
||||||
done:
|
done:
|
||||||
SMARTLIST_FOREACH(items, char*, s, tor_free(s));
|
SMARTLIST_FOREACH(items, char*, s, tor_free(s));
|
||||||
smartlist_free(items);
|
smartlist_free(items);
|
||||||
tor_free(name);
|
tor_free(proxy_argv);
|
||||||
tor_free(type);
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,6 @@ pt_managed_launch_proxy(const char *method,
|
||||||
|
|
||||||
/* free the memory allocated for the execve() */
|
/* free the memory allocated for the execve() */
|
||||||
free_execve_args(envp);
|
free_execve_args(envp);
|
||||||
free_execve_args(proxy_argv);
|
|
||||||
|
|
||||||
/* Set stdout/stderr pipes to be non-blocking */
|
/* Set stdout/stderr pipes to be non-blocking */
|
||||||
fcntl(stdout_pipe, F_SETFL, O_NONBLOCK);
|
fcntl(stdout_pipe, F_SETFL, O_NONBLOCK);
|
||||||
|
|
Loading…
Add table
Reference in a new issue