Commit 6c61ed4f authored by Roger Dingledine's avatar Roger Dingledine
Browse files

Make options no longer a global variable.

Now we can try setting an option but back out if it fails to parse, or
  if it's disallowed (e.g. changing RunAsDaemon from 1 to 0).
Use parse_line_from_str rather than parse_line_from_file.


svn:r2692
parent f490e5cd
......@@ -9,8 +9,6 @@
#include "or.h"
extern or_options_t options; /* command-line and config-file options */
/********* START VARIABLES **********/
/** A global list of all circuits at this hop. */
......@@ -149,7 +147,7 @@ void circuit_rep_hist_note_result(circuit_t *circ) {
*/
return;
}
if (server_mode()) {
if (server_mode(get_options())) {
routerinfo_t *me = router_get_my_routerinfo();
tor_assert(me);
prev_digest = me->identity_digest;
......@@ -354,7 +352,7 @@ circuit_deliver_create_cell(circuit_t *circ, char *payload) {
* compare keys, not nicknames...but older servers will compare nicknames.
* Should we check server version from the most recent directory? Hm.
*/
circ_id_type = decide_circ_id_type(options.Nickname,
circ_id_type = decide_circ_id_type(get_options()->Nickname,
circ->n_conn->nickname);
circ->n_circ_id = get_unique_circ_id_by_conn(circ->n_conn, circ_id_type);
if(!circ->n_circ_id) {
......@@ -830,9 +828,10 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
int n_best_support=0;
smartlist_t *sl, *preferredexits, *preferredentries, *excludedexits;
routerinfo_t *router;
or_options_t *options = get_options();
preferredentries = smartlist_create();
add_nickname_list_to_smartlist(preferredentries,options.EntryNodes,1);
add_nickname_list_to_smartlist(preferredentries,options->EntryNodes,1);
get_connection_array(&carray, &n_connections);
......@@ -871,7 +870,7 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
continue; /* skip routers that are known to be down */
}
if(!router->is_verified &&
(!(options._AllowUnverified & ALLOW_UNVERIFIED_EXIT) ||
(!(options->_AllowUnverified & ALLOW_UNVERIFIED_EXIT) ||
router_is_unreliable_router(router, 1, 1))) {
/* if it's unverified, and either we don't want it or it's unsuitable */
n_supported[i] = -1;
......@@ -923,10 +922,10 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
n_best_support, best_support, n_pending_connections);
preferredexits = smartlist_create();
add_nickname_list_to_smartlist(preferredexits,options.ExitNodes,1);
add_nickname_list_to_smartlist(preferredexits,options->ExitNodes,1);
excludedexits = smartlist_create();
add_nickname_list_to_smartlist(excludedexits,options.ExcludeNodes,0);
add_nickname_list_to_smartlist(excludedexits,options->ExcludeNodes,0);
sl = smartlist_create();
......@@ -938,7 +937,7 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
smartlist_add(sl, smartlist_get(dir->routers, i));
smartlist_subtract(sl,excludedexits);
if (options.StrictExitNodes || smartlist_overlap(sl,preferredexits))
if (options->StrictExitNodes || smartlist_overlap(sl,preferredexits))
smartlist_intersect(sl,preferredexits);
router = routerlist_sl_choose_by_bandwidth(sl);
} else {
......@@ -952,7 +951,7 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
smartlist_add(sl, smartlist_get(dir->routers, i));
smartlist_subtract(sl,excludedexits);
if (options.StrictExitNodes || smartlist_overlap(sl,preferredexits))
if (options->StrictExitNodes || smartlist_overlap(sl,preferredexits))
smartlist_intersect(sl,preferredexits);
router = routerlist_sl_choose_by_bandwidth(sl);
}
......@@ -966,7 +965,7 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
log_fn(LOG_INFO, "Chose exit server '%s'", router->nickname);
return router;
}
if (options.StrictExitNodes)
if (options->StrictExitNodes)
log_fn(LOG_WARN, "No exit routers seem to be running; can't choose an exit.");
return NULL;
......@@ -985,12 +984,13 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
static routerinfo_t *choose_good_exit_server(uint8_t purpose, routerlist_t *dir)
{
routerinfo_t *r;
or_options_t *options = get_options();
switch(purpose) {
case CIRCUIT_PURPOSE_C_GENERAL:
return choose_good_exit_server_general(dir);
case CIRCUIT_PURPOSE_C_ESTABLISH_REND:
r = router_choose_random_node(options.RendNodes, options.RendExcludeNodes,
NULL, 0, 1, options._AllowUnverified & ALLOW_UNVERIFIED_RENDEZVOUS, 0);
r = router_choose_random_node(options->RendNodes, options->RendExcludeNodes,
NULL, 0, 1, options->_AllowUnverified & ALLOW_UNVERIFIED_RENDEZVOUS, 0);
return r;
}
log_fn(LOG_WARN,"Unhandled purpose %d", purpose);
......@@ -1008,10 +1008,11 @@ onion_new_cpath_build_state(uint8_t purpose, const char *exit_digest)
int r;
cpath_build_state_t *info;
routerinfo_t *exit;
router_get_routerlist(&rl);
if (!rl)
return NULL;
r = new_route_len(options.PathlenCoinWeight, purpose, rl->routers);
r = new_route_len(get_options()->PathlenCoinWeight, purpose, rl->routers);
if (r < 1) /* must be at least 1 */
return NULL;
info = tor_malloc_zero(sizeof(cpath_build_state_t));
......@@ -1112,8 +1113,8 @@ static routerinfo_t *choose_good_middle_server(cpath_build_state_t *state,
routerlist_add_family(excluded, r);
}
}
choice = router_choose_random_node(NULL, options.ExcludeNodes, excluded,
0, 1, options._AllowUnverified & ALLOW_UNVERIFIED_MIDDLE, 0);
choice = router_choose_random_node(NULL, get_options()->ExcludeNodes, excluded,
0, 1, get_options()->_AllowUnverified & ALLOW_UNVERIFIED_MIDDLE, 0);
smartlist_free(excluded);
return choice;
}
......@@ -1122,6 +1123,7 @@ static routerinfo_t *choose_good_entry_server(cpath_build_state_t *state)
{
routerinfo_t *r, *choice;
smartlist_t *excluded = smartlist_create();
or_options_t *options = get_options();
char buf[16];
if((r = router_get_by_digest(state->chosen_exit_digest))) {
......@@ -1132,7 +1134,7 @@ static routerinfo_t *choose_good_entry_server(cpath_build_state_t *state)
smartlist_add(excluded, r);
routerlist_add_family(excluded, r);
}
if(options.FascistFirewall) {
if(options->FascistFirewall) {
/* exclude all ORs that listen on the wrong port */
routerlist_t *rl;
int i;
......@@ -1144,13 +1146,13 @@ static routerinfo_t *choose_good_entry_server(cpath_build_state_t *state)
for(i=0; i < smartlist_len(rl->routers); i++) {
r = smartlist_get(rl->routers, i);
tor_snprintf(buf, sizeof(buf), "%d", r->or_port);
if (!smartlist_string_isin(options.FirewallPorts, buf))
if (!smartlist_string_isin(options->FirewallPorts, buf))
smartlist_add(excluded, r);
}
}
choice = router_choose_random_node(options.EntryNodes, options.ExcludeNodes,
excluded, 0, 1, options._AllowUnverified & ALLOW_UNVERIFIED_ENTRY,
options.StrictEntryNodes);
choice = router_choose_random_node(options->EntryNodes, options->ExcludeNodes,
excluded, 0, 1, options->_AllowUnverified & ALLOW_UNVERIFIED_ENTRY,
options->StrictEntryNodes);
smartlist_free(excluded);
return choice;
}
......@@ -1188,7 +1190,7 @@ onion_extend_cpath(crypt_path_t **head_ptr, cpath_build_state_t
state->desired_path_len);
excludednodes = smartlist_create();
add_nickname_list_to_smartlist(excludednodes,options.ExcludeNodes,0);
add_nickname_list_to_smartlist(excludednodes,get_options()->ExcludeNodes,0);
if(cur_len == state->desired_path_len - 1) { /* Picking last node */
choice = router_get_by_digest(state->chosen_exit_digest);
......
......@@ -9,8 +9,6 @@
#include "or.h"
extern or_options_t options; /* command-line and config-file options */
/********* START VARIABLES **********/
/** A global list of all circuits at this hop. */
......
......@@ -9,8 +9,6 @@
#include "or.h"
extern or_options_t options; /* command-line and config-file options */
/********* START VARIABLES **********/
extern circuit_t *global_circuitlist; /* from circuitlist.c */
......@@ -57,7 +55,7 @@ static int circuit_is_acceptable(circuit_t *circ,
if(purpose == CIRCUIT_PURPOSE_C_GENERAL)
if(circ->timestamp_dirty &&
circ->timestamp_dirty+options.NewCircuitPeriod <= now)
circ->timestamp_dirty+get_options()->NewCircuitPeriod <= now)
return 0;
if(conn) {
......@@ -264,7 +262,7 @@ int circuit_stream_is_being_handled(connection_t *conn) {
if(CIRCUIT_IS_ORIGIN(circ) && circ->state != CIRCUIT_STATE_OPEN &&
!circ->marked_for_close && circ->purpose == CIRCUIT_PURPOSE_C_GENERAL &&
(!circ->timestamp_dirty ||
circ->timestamp_dirty + options.NewCircuitPeriod < now)) {
circ->timestamp_dirty + get_options()->NewCircuitPeriod < now)) {
exitrouter = router_get_by_digest(circ->build_state->chosen_exit_digest);
if(exitrouter && connection_ap_can_use_exit(conn, exitrouter))
if(++num >= MIN_CIRCUITS_HANDLING_STREAM)
......@@ -297,12 +295,12 @@ void circuit_build_needed_circs(time_t now) {
if(time_to_new_circuit < now) {
circuit_reset_failure_count(1);
time_to_new_circuit = now + options.NewCircuitPeriod;
if(proxy_mode())
time_to_new_circuit = now + get_options()->NewCircuitPeriod;
if(proxy_mode(get_options()))
client_dns_clean();
circuit_expire_old_circuits();
if(options.RunTesting && circ &&
if(get_options()->RunTesting && circ &&
circ->timestamp_created + TESTING_CIRCUIT_INTERVAL < now) {
log_fn(LOG_INFO,"Creating a new testing circuit.");
circuit_launch_by_identity(CIRCUIT_PURPOSE_C_GENERAL, NULL);
......@@ -452,7 +450,7 @@ circuit_expire_old_circuits(void)
* on it, mark it for close.
*/
if (circ->timestamp_dirty &&
circ->timestamp_dirty + options.NewCircuitPeriod < now &&
circ->timestamp_dirty + get_options()->NewCircuitPeriod < now &&
!circ->p_conn && /* we're the origin */
!circ->p_streams /* nothing attached */ ) {
log_fn(LOG_DEBUG,"Closing n_circ_id %d (dirty %d secs ago, purp %d)",circ->n_circ_id,
......
......@@ -15,8 +15,6 @@
#include "or.h"
extern or_options_t options; /* command-line and config-file options */
/** Keep statistics about how many of each type of cell we've received. */
unsigned long stats_n_padding_cells_processed = 0;
unsigned long stats_n_create_cells_processed = 0;
......
This diff is collapsed.
......@@ -12,8 +12,6 @@
/********* START VARIABLES **********/
extern or_options_t options; /* command-line and config-file options */
/** Array of strings to make conn-\>type human-readable. */
const char *conn_type_to_string[] = {
"", /* 0 */
......@@ -488,6 +486,7 @@ static int connection_init_accepted_conn(connection_t *conn) {
int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_t port) {
int s;
struct sockaddr_in dest_addr;
or_options_t *options = get_options();
s=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
if (s < 0) {
......@@ -496,15 +495,15 @@ int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_
return -1;
}
if (options.OutboundBindAddress) {
if (options->OutboundBindAddress) {
struct sockaddr_in ext_addr;
memset(&ext_addr, 0, sizeof(ext_addr));
ext_addr.sin_family = AF_INET;
ext_addr.sin_port = 0;
if (!tor_inet_aton(options.OutboundBindAddress, &ext_addr.sin_addr)) {
if (!tor_inet_aton(options->OutboundBindAddress, &ext_addr.sin_addr)) {
log_fn(LOG_WARN,"Outbound bind address '%s' didn't parse. Ignoring.",
options.OutboundBindAddress);
options->OutboundBindAddress);
} else {
if(bind(s, (struct sockaddr*)&ext_addr, sizeof(ext_addr)) < 0) {
log_fn(LOG_WARN,"Error binding network socket: %s",
......@@ -641,18 +640,19 @@ static int retry_listeners(int type, struct config_line_t *cfg,
* connections for a given type.
*/
int retry_all_listeners(int force) {
or_options_t *options = get_options();
if (retry_listeners(CONN_TYPE_OR_LISTENER, options.ORBindAddress,
options.ORPort, "0.0.0.0", force)<0)
if (retry_listeners(CONN_TYPE_OR_LISTENER, options->ORBindAddress,
options->ORPort, "0.0.0.0", force)<0)
return -1;
if (retry_listeners(CONN_TYPE_DIR_LISTENER, options.DirBindAddress,
options.DirPort, "0.0.0.0", force)<0)
if (retry_listeners(CONN_TYPE_DIR_LISTENER, options->DirBindAddress,
options->DirPort, "0.0.0.0", force)<0)
return -1;
if (retry_listeners(CONN_TYPE_AP_LISTENER, options.SocksBindAddress,
options.SocksPort, "127.0.0.1", force)<0)
if (retry_listeners(CONN_TYPE_AP_LISTENER, options->SocksBindAddress,
options->SocksPort, "127.0.0.1", force)<0)
return -1;
if (retry_listeners(CONN_TYPE_CONTROL_LISTENER, NULL,
options.ControlPort, "127.0.0.1", force)<0)
options->ControlPort, "127.0.0.1", force)<0)
return -1;
return 0;
......@@ -702,11 +702,12 @@ static void connection_read_bucket_decrement(connection_t *conn, int num_read) {
}
}
/** Initiatialize the global read bucket to options.BandwidthBurstBytes,
/** Initiatialize the global read bucket to options->BandwidthBurstBytes,
* and current_time to the current time. */
void connection_bucket_init(void) {
global_read_bucket = options.BandwidthBurstBytes; /* start it at max traffic */
global_write_bucket = options.BandwidthBurstBytes; /* start it at max traffic */
or_options_t *options = get_options();
global_read_bucket = options->BandwidthBurstBytes; /* start it at max traffic */
global_write_bucket = options->BandwidthBurstBytes; /* start it at max traffic */
}
/** A second has rolled over; increment buckets appropriately. */
......@@ -714,14 +715,15 @@ void connection_bucket_refill(struct timeval *now) {
int i, n;
connection_t *conn;
connection_t **carray;
or_options_t *options = get_options();
/* refill the global buckets */
if(global_read_bucket < options.BandwidthBurstBytes) {
global_read_bucket += options.BandwidthRateBytes;
if(global_read_bucket < options->BandwidthBurstBytes) {
global_read_bucket += options->BandwidthRateBytes;
log_fn(LOG_DEBUG,"global_read_bucket now %d.", global_read_bucket);
}
if(global_write_bucket < options.BandwidthBurstBytes) {
global_write_bucket += options.BandwidthRateBytes;
if(global_write_bucket < options->BandwidthBurstBytes) {
global_write_bucket += options->BandwidthRateBytes;
log_fn(LOG_DEBUG,"global_write_bucket now %d.", global_write_bucket);
}
......
......@@ -10,8 +10,6 @@
#include "or.h"
#include "tree.h"
extern or_options_t options; /* command-line and config-file options */
static struct exit_policy_t *socks_policy = NULL;
static int connection_ap_handshake_process_socks(connection_t *conn);
......@@ -245,6 +243,7 @@ void connection_ap_expire_beginning(void) {
circuit_t *circ;
int n, i;
time_t now = time(NULL);
or_options_t *options = get_options();
get_connection_array(&carray, &n);
......@@ -293,7 +292,7 @@ void connection_ap_expire_beginning(void) {
* current streams on it to survive if they can: make it
* unattractive to use for new streams */
tor_assert(circ->timestamp_dirty);
circ->timestamp_dirty -= options.NewCircuitPeriod;
circ->timestamp_dirty -= options->NewCircuitPeriod;
/* give our stream another 15 seconds to try */
conn->timestamp_lastread += 15;
/* attaching to a dirty circuit is fine */
......@@ -899,6 +898,7 @@ void connection_exit_connect(connection_t *conn) {
unsigned char connected_payload[4];
uint32_t addr;
uint16_t port;
or_options_t *options = get_options();
if (!connection_edge_is_rendezvous_stream(conn) &&
router_compare_to_my_exit_policy(conn) == ADDR_POLICY_REJECTED) {
......@@ -911,7 +911,7 @@ void connection_exit_connect(connection_t *conn) {
addr = conn->addr;
port = conn->port;
SMARTLIST_FOREACH(options.RedirectExitList, exit_redirect_t *, r,
SMARTLIST_FOREACH(options->RedirectExitList, exit_redirect_t *, r,
{
if ((addr&r->mask)==(r->addr&r->mask) &&
(r->port_min <= port) && (port <= r->port_max)) {
......@@ -1003,7 +1003,7 @@ int connection_ap_can_use_exit(connection_t *conn, routerinfo_t *exit)
/** A helper function for socks_policy_permits_address() below.
*
* Parse options.SocksPolicy in the same way that the exit policy
* Parse options->SocksPolicy in the same way that the exit policy
* is parsed, and put the processed version in &socks_policy.
* Ignore port specifiers.
*/
......@@ -1014,7 +1014,7 @@ static void parse_socks_policy(void)
exit_policy_free(socks_policy);
socks_policy = NULL;
}
config_parse_exit_policy(options.SocksPolicy, &socks_policy);
config_parse_exit_policy(get_options()->SocksPolicy, &socks_policy);
/* ports aren't used. */
for (n=socks_policy; n; n = n->next) {
n->prt_min = 1;
......@@ -1028,7 +1028,8 @@ static void parse_socks_policy(void)
int socks_policy_permits_address(uint32_t addr)
{
int a;
if (options.SocksPolicy && !socks_policy)
or_options_t *options = get_options();
if (options->SocksPolicy && !socks_policy)
parse_socks_policy();
if(!socks_policy) /* 'no socks policy' means 'accept' */
......
......@@ -10,8 +10,6 @@
#include "or.h"
extern or_options_t options; /**< command-line and config-file options */
static int connection_tls_finish_handshake(connection_t *conn);
static int connection_or_process_cells_from_inbuf(connection_t *conn);
......@@ -121,10 +119,10 @@ connection_or_init_conn_from_address(connection_t *conn,
uint32_t addr, uint16_t port,
const char *id_digest)
{
routerinfo_t *r;
struct in_addr in;
const char *n;
r = router_get_by_digest(id_digest);
or_options_t *options = get_options();
routerinfo_t *r = router_get_by_digest(id_digest);
if (r) {
connection_or_init_conn_from_router(conn,r);
return;
......@@ -132,7 +130,7 @@ connection_or_init_conn_from_address(connection_t *conn,
conn->addr = addr;
conn->port = port;
/* This next part isn't really right, but it's good enough for now. */
conn->receiver_bucket = conn->bandwidth = options.BandwidthBurstBytes;
conn->receiver_bucket = conn->bandwidth = options->BandwidthBurstBytes;
memcpy(conn->identity_digest, id_digest, DIGEST_LEN);
/* If we're an authoritative directory server, we may know a
* nickname for this router. */
......@@ -203,7 +201,7 @@ connection_t *connection_or_connect(uint32_t addr, uint16_t port,
tor_assert(id_digest);
if(server_mode() && (me=router_get_my_routerinfo()) &&
if(server_mode(get_options()) && (me=router_get_my_routerinfo()) &&
!memcmp(me->identity_digest, id_digest,DIGEST_LEN)) {
log_fn(LOG_WARN,"Request to connect to myself! Failing.");
return NULL;
......@@ -334,12 +332,13 @@ connection_tls_finish_handshake(connection_t *conn) {
connection_t *c;
crypto_pk_env_t *identity_rcvd=NULL;
char digest_rcvd[DIGEST_LEN];
or_options_t *options = get_options();
conn->state = OR_CONN_STATE_OPEN;
connection_watch_events(conn, POLLIN);
log_fn(LOG_DEBUG,"tls handshake done. verifying.");
if (! tor_tls_peer_has_cert(conn->tls)) { /* It's an OP. */
if (server_mode()) { /* I'm an OR; good. */
if (server_mode(options)) { /* I'm an OR; good. */
conn->receiver_bucket = conn->bandwidth = DEFAULT_BANDWIDTH_OP;
return 0;
} else { /* Neither side sent a certificate: ouch. */
......@@ -376,7 +375,7 @@ connection_tls_finish_handshake(connection_t *conn) {
if (connection_or_nonopen_was_started_here(conn)) {
/* I initiated this connection. */
if (strcasecmp(conn->nickname, nickname)) {
log_fn(options.DirPort ? LOG_WARN : LOG_INFO,
log_fn(options->DirPort ? LOG_WARN : LOG_INFO,
"Other side (%s:%d) is '%s', but we tried to connect to '%s'",
conn->address, conn->port, nickname, conn->nickname);
control_event_or_conn_status(conn, OR_CONN_EVENT_FAILED);
......@@ -390,7 +389,7 @@ connection_tls_finish_handshake(connection_t *conn) {
connection_or_init_conn_from_address(conn,conn->addr,conn->port,digest_rcvd);
}
if (!server_mode()) { /* If I'm an OP... */
if (!server_mode(options)) { /* If I'm an OP... */
conn->receiver_bucket = conn->bandwidth = DEFAULT_BANDWIDTH_OP;
}
directory_set_dirty();
......
......@@ -43,8 +43,6 @@ static const char *CONTROL_COMMANDS[] = {
"authenticate",
};
extern or_options_t options;
static uint32_t global_event_mask = 0;
#define AUTHENTICATION_COOKIE_LEN 32
......@@ -141,26 +139,25 @@ static int
handle_control_setconf(connection_t *conn, uint16_t len,
char *body)
{
char *k, *v;
struct config_line_t *lines = NULL;
/* XXXX009 move this logic into config.c someplace. */
struct config_line_t *lines=NULL;
or_options_t *options = get_options();
do {
body = parse_line_from_str(body, &k, &v);
if (!body) {
goto err;
}
if (k && v)
lines = config_line_prepend(lines, k, v);
} while (*body);
if (config_get_lines(body, &lines) < 0) {
log_fn(LOG_WARN,"Controller gave us config lines we can't parse.");
send_control_error(conn, ERR_UNSPECIFIED, "Couldn't parse configuration");
return 0;
}
/* XXXX009 NM */
if (config_trial_assign(&options, lines, 1) < 0) {
log_fn(LOG_WARN,"Controller gave us config lines that didn't validate.");
send_control_error(conn, ERR_UNSPECIFIED, "Configuration was invalid");
config_free_lines(lines);
return 0;
}
return 0;
err:
send_control_error(conn, ERR_UNSPECIFIED, "Couldn't parse configuration");
/* config_free_lines(lines); */
set_options(options); /* put the new one into place */
config_free_lines(lines);
send_control_done(conn);
return 0;
}
......@@ -172,6 +169,7 @@ handle_control_getconf(connection_t *conn, uint16_t body_len,
smartlist_t *answers = NULL;
char *msg = NULL;
size_t msg_len;
or_options_t *options = get_options();
questions = smartlist_create();
smartlist_split_string(questions, body, "\n",
......@@ -179,7 +177,7 @@ handle_control_getconf(connection_t *conn, uint16_t body_len,
answers = smartlist_create();
SMARTLIST_FOREACH(questions, const char *, q,
{
struct config_line_t *answer = config_get_assigned_option(&options,q);
struct config_line_t *answer = config_get_assigned_option(options,q);
if (!answer) {
send_control_error(conn, ERR_UNRECOGNIZED_CONFIG_KEY, body);
goto done;
......@@ -245,16 +243,17 @@ static int handle_control_setevents(connection_t *conn, uint16_t len,
static int handle_control_authenticate(connection_t *conn, uint16_t len,
const char *body)
{
or_options_t *options = get_options();
if (len == AUTHENTICATION_COOKIE_LEN &&
authentication_cookie_is_set &&
!memcmp(authentication_cookie, body, len)) {
goto ok;
} else if (options.HashedControlPassword) {
} else if (options->HashedControlPassword) {
char expected[S2K_SPECIFIER_LEN+DIGEST_LEN];
char received[DIGEST_LEN];
if (base64_decode(expected,sizeof(expected),
options.HashedControlPassword,
strlen(options.HashedControlPassword))<0) {
options->HashedControlPassword,
strlen(options->HashedControlPassword))<0) {
/* XXXX009 NM we should warn sooner. */
log_fn(LOG_WARN,"Couldn't decode HashedControlPassword: invalid base64");
goto err;
......@@ -448,7 +447,7 @@ int init_cookie_authentication(void)
/* XXXX009 NM add config option to disable this. */
tor_snprintf(fname, sizeof(fname), "%s/control_auth_cookie",
get_data_directory(&options));
get_data_directory());
crypto_rand(authentication_cookie, AUTHENTICATION_COOKIE_LEN);
authentication_cookie_is_set = 1;
if (write_bytes_to_file(fname, authentication_cookie,
......
......@@ -11,7 +11,6 @@
**/
#include "or.h"
extern or_options_t options; /* command-line and config-file options */
/** The maximum number of cpuworker processes we will keep around. */
#define MAX_CPUWORKERS 16
......@@ -302,7 +301,7 @@ static int spawn_cpuworker(void) {
* or kill idle ones.
*/
static void spawn_enough_cpuworkers(void) {
int num_cpuworkers_needed = options.NumCpus;
int num_cpuworkers_needed = get_options()->NumCpus;
if(num_cpuworkers_needed < MIN_CPUWORKERS)
num_cpuworkers_needed = MIN_CPUWORKERS;
......
......@@ -46,8 +46,6 @@ static int directory_handle_command(connection_t *conn);
/********* START VARIABLES **********/
extern or_options_t options; /* command-line and config-file options */
static struct exit_policy_t *dir_policy = NULL;
#if 0 /* commented out for now, since for now what clients send is
......@@ -67,7 +65,7 @@ char rend_fetch_url[] = "/tor/rendezvous/";
/** A helper function for dir_policy_permits_address() below.
*
* Parse options.DirPolicy in the same way that the exit policy
* Parse options->DirPolicy in the same way that the exit policy
* is parsed, and put the processed version in &dir_policy.
* Ignore port specifiers.
*/
......@@ -78,7 +76,7 @@ static void parse_dir_policy(void)
exit_policy_free(dir_policy);
dir_policy = NULL;
}
config_parse_exit_policy(options.DirPolicy, &dir_policy);
config_parse_exit_policy(get_options()->DirPolicy, &dir_policy);
/* ports aren't used. */
for (n=dir_policy; n; n = n->next) {
n->prt_min = 1;
......@@ -92,7 +90,7 @@ static void parse_dir_policy(void)
int dir_policy_permits_address(uint32_t addr)
{
int a;
if (options.DirPolicy && !dir_policy)
if (get_options()->DirPolicy && !dir_policy)