mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 23:21:38 +01:00
Improve the code a tad.
* Use strcmpstart() instead of strcmp(x,y,strlen(y)). * Warn the user if the managed proxy failed to launch. * Improve function documentation. * Use smartlist_len() instead of n_unconfigured_proxies. * Split managed_proxy_destroy() to managed_proxy_destroy() and managed_proxy_destroy_with_transports(). * Constification.
This commit is contained in:
parent
ea3e9416c6
commit
db4cde3810
6 changed files with 119 additions and 113 deletions
|
@ -2941,8 +2941,6 @@ format_helper_exit_status(unsigned char child_state, int saved_errno,
|
||||||
#define CHILD_STATE_EXEC 8
|
#define CHILD_STATE_EXEC 8
|
||||||
#define CHILD_STATE_FAILEXEC 9
|
#define CHILD_STATE_FAILEXEC 9
|
||||||
|
|
||||||
#define SPAWN_ERROR_MESSAGE "ERR: Failed to spawn background process - code "
|
|
||||||
|
|
||||||
/** Start a program in the background. If <b>filename</b> contains a '/',
|
/** Start a program in the background. If <b>filename</b> contains a '/',
|
||||||
* then it will be treated as an absolute or relative path. Otherwise the
|
* then it will be treated as an absolute or relative path. Otherwise the
|
||||||
* system path will be searched for <b>filename</b>. The strings in
|
* system path will be searched for <b>filename</b>. The strings in
|
||||||
|
|
|
@ -353,6 +353,7 @@ void tor_check_port_forwarding(const char *filename,
|
||||||
int tor_spawn_background(const char *const filename, int *stdout_read,
|
int tor_spawn_background(const char *const filename, int *stdout_read,
|
||||||
int *stderr_read, const char **argv,
|
int *stderr_read, const char **argv,
|
||||||
const char **envp);
|
const char **envp);
|
||||||
|
#define SPAWN_ERROR_MESSAGE "ERR: Failed to spawn background process - code "
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
HANDLE load_windows_system_library(const TCHAR *library_name);
|
HANDLE load_windows_system_library(const TCHAR *library_name);
|
||||||
|
|
|
@ -1228,7 +1228,7 @@ options_act(or_options_t *old_options)
|
||||||
|
|
||||||
/* If we have pluggable transport related options enabled, see if we
|
/* If we have pluggable transport related options enabled, see if we
|
||||||
should warn the user about potential configuration problems. */
|
should warn the user about potential configuration problems. */
|
||||||
if (options->Bridges || options->ClientTransportPlugin || options->ServerTransportPlugin)
|
if (options->Bridges || options->ClientTransportPlugin)
|
||||||
validate_pluggable_transports_config();
|
validate_pluggable_transports_config();
|
||||||
|
|
||||||
if (running_tor && rend_config_services(options, 0)<0) {
|
if (running_tor && rend_config_services(options, 0)<0) {
|
||||||
|
@ -4696,7 +4696,7 @@ parse_client_transport_line(const char *line, int validate_only)
|
||||||
int r;
|
int r;
|
||||||
char *field2=NULL;
|
char *field2=NULL;
|
||||||
|
|
||||||
char *name=NULL;
|
const char *name=NULL;
|
||||||
char *addrport=NULL;
|
char *addrport=NULL;
|
||||||
tor_addr_t addr;
|
tor_addr_t addr;
|
||||||
uint16_t port = 0;
|
uint16_t port = 0;
|
||||||
|
@ -4801,7 +4801,7 @@ parse_server_transport_line(const char *line, int validate_only)
|
||||||
{
|
{
|
||||||
smartlist_t *items = NULL;
|
smartlist_t *items = NULL;
|
||||||
int r;
|
int r;
|
||||||
char *name=NULL;
|
const char *name=NULL;
|
||||||
char *type=NULL;
|
char *type=NULL;
|
||||||
char *addrport=NULL;
|
char *addrport=NULL;
|
||||||
tor_addr_t addr;
|
tor_addr_t addr;
|
||||||
|
@ -5839,7 +5839,7 @@ get_bindaddr_for_transport(const char *transport)
|
||||||
state */
|
state */
|
||||||
void
|
void
|
||||||
save_transport_to_state(const char *transport,
|
save_transport_to_state(const char *transport,
|
||||||
tor_addr_t *addr, uint16_t port)
|
const tor_addr_t *addr, uint16_t port)
|
||||||
{
|
{
|
||||||
or_state_t *state = get_or_state();
|
or_state_t *state = get_or_state();
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ int did_last_state_file_write_fail(void);
|
||||||
int or_state_save(time_t now);
|
int or_state_save(time_t now);
|
||||||
|
|
||||||
void save_transport_to_state(const char *transport_name,
|
void save_transport_to_state(const char *transport_name,
|
||||||
tor_addr_t *addr, uint16_t port);
|
const tor_addr_t *addr, uint16_t port);
|
||||||
const char *get_bindaddr_for_transport(const char *transport);
|
const char *get_bindaddr_for_transport(const char *transport);
|
||||||
|
|
||||||
int options_need_geoip_info(or_options_t *options, const char **reason_out);
|
int options_need_geoip_info(or_options_t *options, const char **reason_out);
|
||||||
|
|
|
@ -11,19 +11,21 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "circuitbuild.h"
|
#include "circuitbuild.h"
|
||||||
#include "transports.h"
|
#include "transports.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
/* ASN TIDY THESE UP*/
|
/* ASN TIDY THESE UP*/
|
||||||
static void set_environ(char ***envp, managed_proxy_t *mp);
|
static void set_managed_proxy_environment(char ***envp, const managed_proxy_t *mp);
|
||||||
static INLINE int proxy_configuration_finished(managed_proxy_t *mp);
|
static INLINE int proxy_configuration_finished(const managed_proxy_t *mp);
|
||||||
|
|
||||||
static void managed_proxy_destroy(managed_proxy_t *mp,
|
static void managed_proxy_destroy_impl(managed_proxy_t *mp,
|
||||||
int also_free_transports);
|
int also_free_transports);
|
||||||
|
#define managed_proxy_destroy(mp) managed_proxy_destroy_impl(mp, 0)
|
||||||
|
#define managed_proxy_destroy_with_transports(mp) managed_proxy_destroy_impl(mp, 1)
|
||||||
|
|
||||||
static void handle_finished_proxy(managed_proxy_t *mp);
|
static void handle_finished_proxy(managed_proxy_t *mp);
|
||||||
static void configure_proxy(managed_proxy_t *mp);
|
static void configure_proxy(managed_proxy_t *mp);
|
||||||
|
|
||||||
static void register_server_proxy(managed_proxy_t *mp);
|
static void parse_method_error(const char *line, int is_server_method);
|
||||||
|
|
||||||
static void parse_method_error(char *line, int is_server_method);
|
|
||||||
#define parse_server_method_error(l) parse_method_error(l, 1)
|
#define parse_server_method_error(l) parse_method_error(l, 1)
|
||||||
#define parse_client_method_error(l) parse_method_error(l, 0)
|
#define parse_client_method_error(l) parse_method_error(l, 0)
|
||||||
|
|
||||||
|
@ -54,20 +56,19 @@ static INLINE void free_execve_args(char **arg);
|
||||||
|
|
||||||
/** List of unconfigured managed proxies. */
|
/** List of unconfigured managed proxies. */
|
||||||
static smartlist_t *unconfigured_proxy_list = NULL;
|
static smartlist_t *unconfigured_proxy_list = NULL;
|
||||||
/** Number of unconfigured managed proxies. */
|
|
||||||
static int n_unconfigured_proxies = 0;
|
|
||||||
|
|
||||||
/* The main idea is:
|
/* The main idea here is:
|
||||||
|
|
||||||
A managed proxy is represented by a managed_proxy_t struct and can
|
A managed proxy is represented by a managed_proxy_t struct and can
|
||||||
spawn multiple transports.
|
spawn multiple transports.
|
||||||
|
|
||||||
unconfigured_proxy_list is a list of all the unconfigured managed
|
unconfigured_proxy_list is a list of all the unconfigured managed
|
||||||
proxies; everytime we spawn a managed proxy we add it in that
|
proxies; everytime we find a managed proxy in torrc we add it in
|
||||||
list.
|
that list.
|
||||||
In every run_scheduled_event() tick, we attempt to configure each
|
In every run_scheduled_event() tick, we attempt to launch and then
|
||||||
managed proxy further, using the configuration protocol defined in
|
configure each managed proxy, using the configuration protocol
|
||||||
the 180_pluggable_transport.txt proposal.
|
defined in the 180_pluggable_transport.txt proposal. A managed
|
||||||
|
proxy might need several ticks to get fully configured.
|
||||||
|
|
||||||
When a managed proxy is fully configured, we register all its
|
When a managed proxy is fully configured, we register all its
|
||||||
transports to the circuitbuild.c subsystem - like we do with
|
transports to the circuitbuild.c subsystem - like we do with
|
||||||
|
@ -78,7 +79,8 @@ static int n_unconfigured_proxies = 0;
|
||||||
int
|
int
|
||||||
pt_proxies_configuration_pending(void)
|
pt_proxies_configuration_pending(void)
|
||||||
{
|
{
|
||||||
return !!n_unconfigured_proxies;
|
if (!unconfigured_proxy_list) return 0;
|
||||||
|
return !!smartlist_len(unconfigured_proxy_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return true if <b>mp</b> has the same argv as <b>proxy_argv</b> */
|
/** Return true if <b>mp</b> has the same argv as <b>proxy_argv</b> */
|
||||||
|
@ -120,7 +122,7 @@ get_managed_proxy_by_argv(char **proxy_argv)
|
||||||
|
|
||||||
/** Add <b>transport</b> to managed proxy <b>mp</b>. */
|
/** Add <b>transport</b> to managed proxy <b>mp</b>. */
|
||||||
static void
|
static void
|
||||||
add_transport_to_proxy(char *transport, managed_proxy_t *mp)
|
add_transport_to_proxy(const char *transport, managed_proxy_t *mp)
|
||||||
{
|
{
|
||||||
tor_assert(mp->transports_to_launch);
|
tor_assert(mp->transports_to_launch);
|
||||||
if (!smartlist_string_isin(mp->transports_to_launch, transport))
|
if (!smartlist_string_isin(mp->transports_to_launch, transport))
|
||||||
|
@ -137,14 +139,8 @@ launch_managed_proxy(managed_proxy_t *mp)
|
||||||
int stdout_pipe=-1, stderr_pipe=-1;
|
int stdout_pipe=-1, stderr_pipe=-1;
|
||||||
|
|
||||||
/* prepare the environment variables for the managed proxy */
|
/* prepare the environment variables for the managed proxy */
|
||||||
set_environ(&envp, mp);
|
set_managed_proxy_environment(&envp, mp);
|
||||||
|
|
||||||
char **tmp = envp;
|
|
||||||
printf("PRINTING ENVP\n");
|
|
||||||
while (*tmp)
|
|
||||||
printf("%s\n", *tmp++);
|
|
||||||
|
|
||||||
/* ASN we should probably check if proxy_argv[0] is executable by our user */
|
|
||||||
retval = tor_spawn_background(mp->argv[0], &stdout_pipe,
|
retval = tor_spawn_background(mp->argv[0], &stdout_pipe,
|
||||||
&stderr_pipe, (const char **)mp->argv,
|
&stderr_pipe, (const char **)mp->argv,
|
||||||
(const char **)envp);
|
(const char **)envp);
|
||||||
|
@ -153,7 +149,7 @@ launch_managed_proxy(managed_proxy_t *mp)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free the memory allocated for the execve() */
|
/* free the memory allocated by set_managed_proxy_environment(). */
|
||||||
free_execve_args(envp);
|
free_execve_args(envp);
|
||||||
|
|
||||||
/* Set stdout/stderr pipes to be non-blocking */
|
/* Set stdout/stderr pipes to be non-blocking */
|
||||||
|
@ -177,8 +173,8 @@ pt_configure_remaining_proxies(void)
|
||||||
{
|
{
|
||||||
log_warn(LD_CONFIG, "We start configuring remaining managed proxies!");
|
log_warn(LD_CONFIG, "We start configuring remaining managed proxies!");
|
||||||
SMARTLIST_FOREACH_BEGIN(unconfigured_proxy_list, managed_proxy_t *, mp) {
|
SMARTLIST_FOREACH_BEGIN(unconfigured_proxy_list, managed_proxy_t *, mp) {
|
||||||
if (proxy_configuration_finished(mp)) /* finished managed proxies
|
/* configured proxies shouldn't be in unconfigured_proxy_list. */
|
||||||
shouldn't be here */
|
if (proxy_configuration_finished(mp))
|
||||||
assert(0);
|
assert(0);
|
||||||
|
|
||||||
configure_proxy(mp);
|
configure_proxy(mp);
|
||||||
|
@ -205,15 +201,16 @@ configure_proxy(managed_proxy_t *mp)
|
||||||
r = get_string_from_pipe(mp->stdout, stdout_buf,
|
r = get_string_from_pipe(mp->stdout, stdout_buf,
|
||||||
sizeof(stdout_buf) - 1);
|
sizeof(stdout_buf) - 1);
|
||||||
|
|
||||||
if (r == IO_STREAM_CLOSED || r == IO_STREAM_TERM) {
|
if (r == IO_STREAM_OKAY) { /* got a line; handle it! */
|
||||||
|
handle_proxy_line((const char *)stdout_buf, mp);
|
||||||
|
} else if (r == IO_STREAM_EAGAIN) { /* check back later */
|
||||||
|
return;
|
||||||
|
} else if (r == IO_STREAM_CLOSED || r == IO_STREAM_TERM) { /* snap! */
|
||||||
log_warn(LD_GENERAL, "Managed proxy stream closed. "
|
log_warn(LD_GENERAL, "Managed proxy stream closed. "
|
||||||
"Most probably application stopped running");
|
"Most probably application stopped running");
|
||||||
mp->conf_state = PT_PROTO_BROKEN;
|
mp->conf_state = PT_PROTO_BROKEN;
|
||||||
} else if (r == IO_STREAM_EAGAIN) {
|
} else { /* unknown stream status */
|
||||||
return;
|
log_warn(LD_GENERAL, "Unknown stream status while configuring proxy.");
|
||||||
} else {
|
|
||||||
tor_assert(r == IO_STREAM_OKAY);
|
|
||||||
handle_proxy_line(stdout_buf, mp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if the proxy finished configuring, exit the loop. */
|
/* if the proxy finished configuring, exit the loop. */
|
||||||
|
@ -226,7 +223,7 @@ configure_proxy(managed_proxy_t *mp)
|
||||||
|
|
||||||
/** Register server managed proxy <b>mp</b> transports to state */
|
/** Register server managed proxy <b>mp</b> transports to state */
|
||||||
static void
|
static void
|
||||||
register_server_proxy(managed_proxy_t *mp)
|
register_server_proxy(const managed_proxy_t *mp)
|
||||||
{
|
{
|
||||||
if (mp->is_server) {
|
if (mp->is_server) {
|
||||||
SMARTLIST_FOREACH_BEGIN(mp->transports, transport_t *, t) {
|
SMARTLIST_FOREACH_BEGIN(mp->transports, transport_t *, t) {
|
||||||
|
@ -238,7 +235,7 @@ register_server_proxy(managed_proxy_t *mp)
|
||||||
/** Register all the transports supported by client managed proxy
|
/** Register all the transports supported by client managed proxy
|
||||||
* <b>mp</b> to the bridge subsystem. */
|
* <b>mp</b> to the bridge subsystem. */
|
||||||
static void
|
static void
|
||||||
register_client_proxy(managed_proxy_t *mp)
|
register_client_proxy(const managed_proxy_t *mp)
|
||||||
{
|
{
|
||||||
SMARTLIST_FOREACH_BEGIN(mp->transports, transport_t *, t) {
|
SMARTLIST_FOREACH_BEGIN(mp->transports, transport_t *, t) {
|
||||||
if (transport_add(t)<0) {
|
if (transport_add(t)<0) {
|
||||||
|
@ -252,7 +249,7 @@ register_client_proxy(managed_proxy_t *mp)
|
||||||
|
|
||||||
/** Register the transports of managed proxy <b>mp</b>. */
|
/** Register the transports of managed proxy <b>mp</b>. */
|
||||||
static INLINE void
|
static INLINE void
|
||||||
register_proxy(managed_proxy_t *mp)
|
register_proxy(const managed_proxy_t *mp)
|
||||||
{
|
{
|
||||||
if (mp->is_server)
|
if (mp->is_server)
|
||||||
register_server_proxy(mp);
|
register_server_proxy(mp);
|
||||||
|
@ -260,35 +257,11 @@ register_proxy(managed_proxy_t *mp)
|
||||||
register_client_proxy(mp);
|
register_client_proxy(mp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handle a configured or broken managed proxy <b>mp</b>. */
|
|
||||||
static void
|
|
||||||
handle_finished_proxy(managed_proxy_t *mp)
|
|
||||||
{
|
|
||||||
switch (mp->conf_state) {
|
|
||||||
case PT_PROTO_BROKEN: /* if broken: */
|
|
||||||
managed_proxy_destroy(mp, 1); /* destroy it and all its transports */
|
|
||||||
break;
|
|
||||||
case PT_PROTO_CONFIGURED: /* if configured correctly: */
|
|
||||||
register_proxy(mp); /* register transports */
|
|
||||||
mp->conf_state = PT_PROTO_COMPLETED; /* mark it as completed, */
|
|
||||||
managed_proxy_destroy(mp, 0); /* destroy the managed proxy struct,
|
|
||||||
keeping the transports intact */
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
log_warn(LD_CONFIG, "Unfinished managed proxy in "
|
|
||||||
"handle_finished_proxy().");
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
n_unconfigured_proxies--;
|
|
||||||
tor_assert(n_unconfigured_proxies >= 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Free memory allocated by managed proxy <b>mp</b>.
|
/** Free memory allocated by managed proxy <b>mp</b>.
|
||||||
* If <b>also_free_transports</b> is set, also free the transports
|
* If <b>also_free_transports</b> is set, also free the transports
|
||||||
* associated with this managed proxy. */
|
* associated with this managed proxy. */
|
||||||
static void
|
static void
|
||||||
managed_proxy_destroy(managed_proxy_t *mp, int also_free_transports)
|
managed_proxy_destroy_impl(managed_proxy_t *mp, int also_free_transports)
|
||||||
{
|
{
|
||||||
/* transport_free() all its transports */
|
/* transport_free() all its transports */
|
||||||
if (also_free_transports)
|
if (also_free_transports)
|
||||||
|
@ -316,19 +289,59 @@ managed_proxy_destroy(managed_proxy_t *mp, int also_free_transports)
|
||||||
tor_free(mp);
|
tor_free(mp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Handle a configured or broken managed proxy <b>mp</b>. */
|
||||||
|
static void
|
||||||
|
handle_finished_proxy(managed_proxy_t *mp)
|
||||||
|
{
|
||||||
|
switch (mp->conf_state) {
|
||||||
|
case PT_PROTO_BROKEN: /* if broken: */
|
||||||
|
managed_proxy_destroy_with_transports(mp); /* destroy it and all its transports */
|
||||||
|
break;
|
||||||
|
case PT_PROTO_CONFIGURED: /* if configured correctly: */
|
||||||
|
register_proxy(mp); /* register transports */
|
||||||
|
mp->conf_state = PT_PROTO_COMPLETED; /* mark it as completed, */
|
||||||
|
managed_proxy_destroy(mp); /* destroy the managed proxy struct,
|
||||||
|
keeping the transports intact */
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log_warn(LD_CONFIG, "Unfinished managed proxy in "
|
||||||
|
"handle_finished_proxy().");
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
tor_assert(smartlist_len(unconfigured_proxy_list) >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
/** Return true if the configuration of the managed proxy <b>mp</b> is
|
/** Return true if the configuration of the managed proxy <b>mp</b> is
|
||||||
finished. */
|
finished. */
|
||||||
static INLINE int
|
static INLINE int
|
||||||
proxy_configuration_finished(managed_proxy_t *mp)
|
proxy_configuration_finished(const managed_proxy_t *mp)
|
||||||
{
|
{
|
||||||
return (mp->conf_state == PT_PROTO_CONFIGURED ||
|
return (mp->conf_state == PT_PROTO_CONFIGURED ||
|
||||||
mp->conf_state == PT_PROTO_BROKEN);
|
mp->conf_state == PT_PROTO_BROKEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** This function is called when a proxy sends an {S,C}METHODS DONE message,
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
handle_methods_done(const managed_proxy_t *mp)
|
||||||
|
{
|
||||||
|
tor_assert(mp->transports);
|
||||||
|
|
||||||
|
if (smartlist_len(mp->transports) == 0)
|
||||||
|
log_warn(LD_GENERAL, "Proxy was spawned successfully, "
|
||||||
|
"but it didn't laucn any pluggable transport listeners!");
|
||||||
|
|
||||||
|
log_warn(LD_CONFIG, "%s managed proxy configuration completed!",
|
||||||
|
mp->is_server ? "Server" : "Client");
|
||||||
|
}
|
||||||
|
|
||||||
/** Handle a configuration protocol <b>line</b> received from a
|
/** Handle a configuration protocol <b>line</b> received from a
|
||||||
* managed proxy <b>mp</b>. */
|
* managed proxy <b>mp</b>. */
|
||||||
void
|
void
|
||||||
handle_proxy_line(char *line, managed_proxy_t *mp)
|
handle_proxy_line(const char *line, managed_proxy_t *mp)
|
||||||
{
|
{
|
||||||
printf("Judging line: %s\n", line);
|
printf("Judging line: %s\n", line);
|
||||||
|
|
||||||
|
@ -338,21 +351,20 @@ handle_proxy_line(char *line, managed_proxy_t *mp)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(line, PROTO_ENV_ERROR, strlen(PROTO_ENV_ERROR))) {
|
if (!strcmpstart(line, PROTO_ENV_ERROR)) {
|
||||||
if (mp->conf_state != PT_PROTO_LAUNCHED)
|
if (mp->conf_state != PT_PROTO_LAUNCHED)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
parse_env_error(line);
|
parse_env_error(line);
|
||||||
goto err;
|
goto err;
|
||||||
} else if (!strncmp(line, PROTO_NEG_FAIL, strlen(PROTO_NEG_FAIL))) {
|
} else if (!strcmpstart(line, PROTO_NEG_FAIL)) {
|
||||||
if (mp->conf_state != PT_PROTO_LAUNCHED)
|
if (mp->conf_state != PT_PROTO_LAUNCHED)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
log_warn(LD_CONFIG, "Managed proxy could not pick a "
|
log_warn(LD_CONFIG, "Managed proxy could not pick a "
|
||||||
"configuration protocol version.");
|
"configuration protocol version.");
|
||||||
goto err;
|
goto err;
|
||||||
} else if (!strncmp(line, PROTO_NEG_SUCCESS,
|
} else if (!strcmpstart(line, PROTO_NEG_SUCCESS)) {
|
||||||
strlen(PROTO_NEG_SUCCESS))) {
|
|
||||||
if (mp->conf_state != PT_PROTO_LAUNCHED)
|
if (mp->conf_state != PT_PROTO_LAUNCHED)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
@ -362,37 +374,35 @@ handle_proxy_line(char *line, managed_proxy_t *mp)
|
||||||
tor_assert(mp->conf_protocol != 0);
|
tor_assert(mp->conf_protocol != 0);
|
||||||
mp->conf_state = PT_PROTO_ACCEPTING_METHODS;
|
mp->conf_state = PT_PROTO_ACCEPTING_METHODS;
|
||||||
return;
|
return;
|
||||||
} else if (!strncmp(line, PROTO_CMETHODS_DONE,
|
} else if (!strcmpstart(line, PROTO_CMETHODS_DONE)) {
|
||||||
strlen(PROTO_CMETHODS_DONE))) {
|
|
||||||
if (mp->conf_state != PT_PROTO_ACCEPTING_METHODS)
|
if (mp->conf_state != PT_PROTO_ACCEPTING_METHODS)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
log_warn(LD_CONFIG, "Client managed proxy configuration completed!");
|
handle_methods_done(mp);
|
||||||
|
|
||||||
mp->conf_state = PT_PROTO_CONFIGURED;
|
mp->conf_state = PT_PROTO_CONFIGURED;
|
||||||
return;
|
return;
|
||||||
} else if (!strncmp(line, PROTO_SMETHODS_DONE,
|
} else if (!strcmpstart(line, PROTO_SMETHODS_DONE)) {
|
||||||
strlen(PROTO_SMETHODS_DONE))) {
|
|
||||||
if (mp->conf_state != PT_PROTO_ACCEPTING_METHODS)
|
if (mp->conf_state != PT_PROTO_ACCEPTING_METHODS)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
log_warn(LD_CONFIG, "Server managed proxy configuration completed!");
|
handle_methods_done(mp);
|
||||||
|
|
||||||
mp->conf_state = PT_PROTO_CONFIGURED;
|
mp->conf_state = PT_PROTO_CONFIGURED;
|
||||||
return;
|
return;
|
||||||
} else if (!strncmp(line, PROTO_CMETHOD_ERROR,
|
} else if (!strcmpstart(line, PROTO_CMETHOD_ERROR)) {
|
||||||
strlen(PROTO_CMETHOD_ERROR))) {
|
|
||||||
if (mp->conf_state != PT_PROTO_ACCEPTING_METHODS)
|
if (mp->conf_state != PT_PROTO_ACCEPTING_METHODS)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
parse_client_method_error(line);
|
parse_client_method_error(line);
|
||||||
goto err;
|
goto err;
|
||||||
} else if (!strncmp(line, PROTO_SMETHOD_ERROR,
|
} else if (!strcmpstart(line, PROTO_SMETHOD_ERROR)) {
|
||||||
strlen(PROTO_SMETHOD_ERROR))) {
|
|
||||||
if (mp->conf_state != PT_PROTO_ACCEPTING_METHODS)
|
if (mp->conf_state != PT_PROTO_ACCEPTING_METHODS)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
parse_server_method_error(line);
|
parse_server_method_error(line);
|
||||||
goto err;
|
goto err;
|
||||||
} else if (!strncmp(line, PROTO_CMETHOD, strlen(PROTO_CMETHOD))) {
|
} else if (!strcmpstart(line, PROTO_CMETHOD)) {
|
||||||
if (mp->conf_state != PT_PROTO_ACCEPTING_METHODS)
|
if (mp->conf_state != PT_PROTO_ACCEPTING_METHODS)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
@ -400,7 +410,7 @@ handle_proxy_line(char *line, managed_proxy_t *mp)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else if (!strncmp(line, PROTO_SMETHOD, strlen(PROTO_SMETHOD))) {
|
} else if (!strcmpstart(line, PROTO_SMETHOD)) {
|
||||||
if (mp->conf_state != PT_PROTO_ACCEPTING_METHODS)
|
if (mp->conf_state != PT_PROTO_ACCEPTING_METHODS)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
@ -408,6 +418,9 @@ handle_proxy_line(char *line, managed_proxy_t *mp)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
} else if (!strcmpstart(line, SPAWN_ERROR_MESSAGE)) {
|
||||||
|
log_warn(LD_GENERAL, "Could not launch managed proxy executable!");
|
||||||
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_warn(LD_CONFIG, "Unknown line received by managed proxy. (%s)", line);
|
log_warn(LD_CONFIG, "Unknown line received by managed proxy. (%s)", line);
|
||||||
|
@ -419,10 +432,8 @@ handle_proxy_line(char *line, managed_proxy_t *mp)
|
||||||
|
|
||||||
/** Parses an ENV-ERROR <b>line</b> and warns the user accordingly. */
|
/** Parses an ENV-ERROR <b>line</b> and warns the user accordingly. */
|
||||||
void
|
void
|
||||||
parse_env_error(char *line)
|
parse_env_error(const char *line)
|
||||||
{
|
{
|
||||||
tor_assert(!strncmp(line, PROTO_ENV_ERROR, strlen(PROTO_ENV_ERROR)));
|
|
||||||
|
|
||||||
/* (Length of the protocol string) plus (a space) and (the first char of
|
/* (Length of the protocol string) plus (a space) and (the first char of
|
||||||
the error message) */
|
the error message) */
|
||||||
if (strlen(line) < (strlen(PROTO_ENV_ERROR) + 2))
|
if (strlen(line) < (strlen(PROTO_ENV_ERROR) + 2))
|
||||||
|
@ -437,10 +448,8 @@ parse_env_error(char *line)
|
||||||
/** Handles a VERSION <b>line</b>. Updates the configuration protocol
|
/** Handles a VERSION <b>line</b>. Updates the configuration protocol
|
||||||
* version in <b>mp</b>. */
|
* version in <b>mp</b>. */
|
||||||
int
|
int
|
||||||
parse_version(char *line, managed_proxy_t *mp)
|
parse_version(const char *line, managed_proxy_t *mp)
|
||||||
{
|
{
|
||||||
tor_assert(!strncmp(line, PROTO_NEG_SUCCESS, strlen(PROTO_NEG_SUCCESS)));
|
|
||||||
|
|
||||||
if (strlen(line) < (strlen(PROTO_NEG_SUCCESS) + 2)) {
|
if (strlen(line) < (strlen(PROTO_NEG_SUCCESS) + 2)) {
|
||||||
log_warn(LD_CONFIG, "Managed proxy sent us malformed %s line.",
|
log_warn(LD_CONFIG, "Managed proxy sent us malformed %s line.",
|
||||||
PROTO_NEG_SUCCESS);
|
PROTO_NEG_SUCCESS);
|
||||||
|
@ -461,7 +470,7 @@ parse_version(char *line, managed_proxy_t *mp)
|
||||||
* accordingly. If <b>is_server</b> it is an SMETHOD-ERROR,
|
* accordingly. If <b>is_server</b> it is an SMETHOD-ERROR,
|
||||||
* otherwise it is a CMETHOD-ERROR. */
|
* otherwise it is a CMETHOD-ERROR. */
|
||||||
static void
|
static void
|
||||||
parse_method_error(char *line, int is_server)
|
parse_method_error(const char *line, int is_server)
|
||||||
{
|
{
|
||||||
const char* error = is_server ?
|
const char* error = is_server ?
|
||||||
PROTO_SMETHOD_ERROR : PROTO_CMETHOD_ERROR;
|
PROTO_SMETHOD_ERROR : PROTO_CMETHOD_ERROR;
|
||||||
|
@ -480,7 +489,7 @@ parse_method_error(char *line, int is_server)
|
||||||
/** Parses an SMETHOD <b>line</b> and if well-formed it registers the
|
/** Parses an SMETHOD <b>line</b> and if well-formed it registers the
|
||||||
* new transport in <b>mp</b>. */
|
* new transport in <b>mp</b>. */
|
||||||
int
|
int
|
||||||
parse_smethod_line(char *line, managed_proxy_t *mp)
|
parse_smethod_line(const char *line, managed_proxy_t *mp)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
smartlist_t *items = NULL;
|
smartlist_t *items = NULL;
|
||||||
|
@ -545,7 +554,7 @@ parse_smethod_line(char *line, managed_proxy_t *mp)
|
||||||
/** Parses a CMETHOD <b>line</b>, and if well-formed it registers
|
/** Parses a CMETHOD <b>line</b>, and if well-formed it registers
|
||||||
* the new transport in <b>mp</b>. */
|
* the new transport in <b>mp</b>. */
|
||||||
int
|
int
|
||||||
parse_cmethod_line(char *line, managed_proxy_t *mp)
|
parse_cmethod_line(const char *line, managed_proxy_t *mp)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
smartlist_t *items = NULL;
|
smartlist_t *items = NULL;
|
||||||
|
@ -622,9 +631,10 @@ parse_cmethod_line(char *line, managed_proxy_t *mp)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return a string containing the address:port that <b>transport</b>
|
/** Return a string containing the address:port that <b>transport</b>
|
||||||
* should use. */
|
* should use. It's the responsibility of the caller to free() the
|
||||||
|
* received string. */
|
||||||
static char *
|
static char *
|
||||||
get_bindaddr_for_proxy(managed_proxy_t *mp)
|
get_bindaddr_for_proxy(const managed_proxy_t *mp)
|
||||||
{
|
{
|
||||||
char *bindaddr = NULL;
|
char *bindaddr = NULL;
|
||||||
smartlist_t *string_tmp = smartlist_create();
|
smartlist_t *string_tmp = smartlist_create();
|
||||||
|
@ -646,7 +656,7 @@ get_bindaddr_for_proxy(managed_proxy_t *mp)
|
||||||
|
|
||||||
/** Prepare the <b>envp</b> of managed proxy <b>mp</b> */
|
/** Prepare the <b>envp</b> of managed proxy <b>mp</b> */
|
||||||
static void
|
static void
|
||||||
set_environ(char ***envp, managed_proxy_t *mp)
|
set_managed_proxy_environment(char ***envp, const managed_proxy_t *mp)
|
||||||
{
|
{
|
||||||
or_options_t *options = get_options();
|
or_options_t *options = get_options();
|
||||||
char **tmp=NULL;
|
char **tmp=NULL;
|
||||||
|
@ -660,7 +670,7 @@ set_environ(char ***envp, managed_proxy_t *mp)
|
||||||
*envp = tor_malloc(sizeof(char*)*(n_envs+1));
|
*envp = tor_malloc(sizeof(char*)*(n_envs+1));
|
||||||
tmp = *envp;
|
tmp = *envp;
|
||||||
|
|
||||||
state_loc = get_datadir_fname("pt_state/");
|
state_loc = get_datadir_fname("pt_state/"); /* XXX temp */
|
||||||
transports_to_launch =
|
transports_to_launch =
|
||||||
smartlist_join_strings(mp->transports_to_launch, ",", 0, NULL);
|
smartlist_join_strings(mp->transports_to_launch, ",", 0, NULL);
|
||||||
|
|
||||||
|
@ -671,10 +681,10 @@ set_environ(char ***envp, managed_proxy_t *mp)
|
||||||
if (mp->is_server) {
|
if (mp->is_server) {
|
||||||
bindaddr = get_bindaddr_for_proxy(mp);
|
bindaddr = get_bindaddr_for_proxy(mp);
|
||||||
|
|
||||||
tor_asprintf(tmp++, "TOR_PT_ORPORT=127.0.0.1:%d", options->ORPort); /* temp */
|
tor_asprintf(tmp++, "TOR_PT_ORPORT=127.0.0.1:%d", options->ORPort); /* XXX temp */
|
||||||
tor_asprintf(tmp++, "TOR_PT_SERVER_BINDADDR=%s", bindaddr);
|
tor_asprintf(tmp++, "TOR_PT_SERVER_BINDADDR=%s", bindaddr);
|
||||||
tor_asprintf(tmp++, "TOR_PT_SERVER_TRANSPORTS=%s", transports_to_launch);
|
tor_asprintf(tmp++, "TOR_PT_SERVER_TRANSPORTS=%s", transports_to_launch);
|
||||||
tor_asprintf(tmp++, "TOR_PT_EXTENDED_SERVER_PORT=127.0.0.1:4200"); /* temp*/
|
tor_asprintf(tmp++, "TOR_PT_EXTENDED_SERVER_PORT=127.0.0.1:4200"); /* XXX temp*/
|
||||||
} else {
|
} else {
|
||||||
tor_asprintf(tmp++, "TOR_PT_CLIENT_TRANSPORTS=%s", transports_to_launch);
|
tor_asprintf(tmp++, "TOR_PT_CLIENT_TRANSPORTS=%s", transports_to_launch);
|
||||||
}
|
}
|
||||||
|
@ -689,7 +699,7 @@ set_environ(char ***envp, managed_proxy_t *mp)
|
||||||
* the managed proxy subsystem.
|
* the managed proxy subsystem.
|
||||||
* If <b>is_server</b> is true, then the proxy is a server proxy. */
|
* If <b>is_server</b> is true, then the proxy is a server proxy. */
|
||||||
void
|
void
|
||||||
pt_kickstart_proxy(char *transport, char **proxy_argv, int is_server)
|
pt_kickstart_proxy(const char *transport, char **proxy_argv, int is_server)
|
||||||
{
|
{
|
||||||
managed_proxy_t *mp=NULL;
|
managed_proxy_t *mp=NULL;
|
||||||
|
|
||||||
|
@ -710,9 +720,6 @@ pt_kickstart_proxy(char *transport, char **proxy_argv, int is_server)
|
||||||
if (!unconfigured_proxy_list)
|
if (!unconfigured_proxy_list)
|
||||||
unconfigured_proxy_list = smartlist_create();
|
unconfigured_proxy_list = smartlist_create();
|
||||||
smartlist_add(unconfigured_proxy_list, mp);
|
smartlist_add(unconfigured_proxy_list, mp);
|
||||||
|
|
||||||
n_unconfigured_proxies++; /* ASN should we care about overflows here?
|
|
||||||
I say no. */
|
|
||||||
} else { /* known proxy. just add transport to its transport list */
|
} else { /* known proxy. just add transport to its transport list */
|
||||||
add_transport_to_proxy(transport, mp);
|
add_transport_to_proxy(transport, mp);
|
||||||
free_execve_args(proxy_argv);
|
free_execve_args(proxy_argv);
|
||||||
|
@ -743,9 +750,9 @@ pt_free_all(void)
|
||||||
and we should free them here. */
|
and we should free them here. */
|
||||||
SMARTLIST_FOREACH_BEGIN(unconfigured_proxy_list, managed_proxy_t *, mp) {
|
SMARTLIST_FOREACH_BEGIN(unconfigured_proxy_list, managed_proxy_t *, mp) {
|
||||||
if (mp->conf_state == PT_PROTO_COMPLETED)
|
if (mp->conf_state == PT_PROTO_COMPLETED)
|
||||||
managed_proxy_destroy(mp,0);
|
managed_proxy_destroy(mp);
|
||||||
else
|
else
|
||||||
managed_proxy_destroy(mp,1);
|
managed_proxy_destroy_with_transports(mp);
|
||||||
} SMARTLIST_FOREACH_END(mp);
|
} SMARTLIST_FOREACH_END(mp);
|
||||||
|
|
||||||
smartlist_clear(unconfigured_proxy_list);
|
smartlist_clear(unconfigured_proxy_list);
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#ifndef TOR_TRANSPORTS_H
|
#ifndef TOR_TRANSPORTS_H
|
||||||
#define TOR_TRANSPORTS_H
|
#define TOR_TRANSPORTS_H
|
||||||
|
|
||||||
void pt_kickstart_proxy(char *method, char **proxy_argv,
|
void pt_kickstart_proxy(const char *method, char **proxy_argv,
|
||||||
int is_server);
|
int is_server);
|
||||||
|
|
||||||
#define pt_kickstart_client_proxy(m, pa) \
|
#define pt_kickstart_client_proxy(m, pa) \
|
||||||
|
@ -51,12 +51,12 @@ typedef struct {
|
||||||
smartlist_t *transports; /* list of transport_t this proxy spawned */
|
smartlist_t *transports; /* list of transport_t this proxy spawned */
|
||||||
} managed_proxy_t;
|
} managed_proxy_t;
|
||||||
|
|
||||||
int parse_cmethod_line(char *line, managed_proxy_t *mp);
|
int parse_cmethod_line(const char *line, managed_proxy_t *mp);
|
||||||
int parse_smethod_line(char *line, managed_proxy_t *mp);
|
int parse_smethod_line(const char *line, managed_proxy_t *mp);
|
||||||
|
|
||||||
int parse_version(char *line, managed_proxy_t *mp);
|
int parse_version(const char *line, managed_proxy_t *mp);
|
||||||
void parse_env_error(char *line);
|
void parse_env_error(const char *line);
|
||||||
void handle_proxy_line(char *line, managed_proxy_t *mp);
|
void handle_proxy_line(const char *line, managed_proxy_t *mp);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue