#include "or.h"
Data Structures | |
struct | config_abbrev_t |
struct | config_var_t |
struct | config_var_description_t |
struct | config_format_t |
struct | unit_table_t |
Defines | |
#define | CONFIG_PRIVATE |
#define | PLURAL(tok) { #tok, #tok "s", 0, 0 } |
#define | VAR(name, conftype, member, initvalue) |
#define | V(member, conftype, initvalue) VAR(#member, conftype, member, initvalue) |
#define | OBSOLETE(name) { name, CONFIG_TYPE_OBSOLETE, 0, NULL } |
#define | VAR(name, conftype, member, initvalue) |
#define | CHECK(fmt, cfg) |
#define | OR_OPTIONS_MAGIC 9090909 |
#define | OR_STATE_MAGIC 0x57A73f57 |
#define | MIN_REND_POST_PERIOD (10*60) |
#define | MAX_DIR_PERIOD (MIN_ONION_KEY_LIFETIME/2) |
#define | MIN_MAX_CIRCUIT_DIRTINESS 10 |
#define | MIN_CIRCUIT_STREAM_TIMEOUT 10 |
#define | REJECT(arg) STMT_BEGIN *msg = tor_strdup(arg); return -1; STMT_END |
#define | COMPLAIN(arg) STMT_BEGIN log(LOG_WARN, LD_CONFIG, arg); STMT_END |
#define | GENERATED_FILE_PREFIX |
#define | GENERATED_FILE_COMMENT |
#define | VERY_OLD_FILE_AGE (28*24*60*60) |
Typedefs | |
typedef int(* | validate_fn_t )(void *, void *, int, char **) |
Enumerations | |
enum | config_type_t { CONFIG_TYPE_STRING = 0, CONFIG_TYPE_FILENAME, CONFIG_TYPE_UINT, CONFIG_TYPE_INTERVAL, CONFIG_TYPE_MEMUNIT, CONFIG_TYPE_DOUBLE, CONFIG_TYPE_BOOL, CONFIG_TYPE_ISOTIME, CONFIG_TYPE_CSV, CONFIG_TYPE_LINELIST, CONFIG_TYPE_LINELIST_S, CONFIG_TYPE_LINELIST_V, CONFIG_TYPE_ROUTERSET, CONFIG_TYPE_OBSOLETE } |
Functions | |
static void | config_line_append (config_line_t **lst, const char *key, const char *val) |
static void | option_clear (config_format_t *fmt, or_options_t *options, config_var_t *var) |
static void | option_reset (config_format_t *fmt, or_options_t *options, config_var_t *var, int use_defaults) |
static void | config_free (config_format_t *fmt, void *options) |
static int | config_lines_eq (config_line_t *a, config_line_t *b) |
static int | option_is_same (config_format_t *fmt, or_options_t *o1, or_options_t *o2, const char *name) |
static or_options_t * | options_dup (config_format_t *fmt, or_options_t *old) |
static int | options_validate (or_options_t *old_options, or_options_t *options, int from_setconf, char **msg) |
static int | options_act_reversible (or_options_t *old_options, char **msg) |
static int | options_act (or_options_t *old_options) |
static int | options_transition_allowed (or_options_t *old, or_options_t *new, char **msg) |
static int | options_transition_affects_workers (or_options_t *old_options, or_options_t *new_options) |
static int | options_transition_affects_descriptor (or_options_t *old_options, or_options_t *new_options) |
static int | check_nickname_list (const char *lst, const char *name, char **msg) |
static void | config_register_addressmaps (or_options_t *options) |
static int | parse_bridge_line (const char *line, int validate_only) |
static int | parse_dir_server_line (const char *line, authority_type_t required_type, int validate_only) |
static int | validate_data_directory (or_options_t *options) |
static int | write_configuration_file (const char *fname, or_options_t *options) |
static config_line_t * | get_assigned_option (config_format_t *fmt, void *options, const char *key, int escape_val) |
static void | config_init (config_format_t *fmt, void *options) |
static int | or_state_validate (or_state_t *old_options, or_state_t *options, int from_setconf, char **msg) |
static int | or_state_load (void) |
static int | options_init_logs (or_options_t *options, int validate_only) |
static int | is_listening_on_low_port (uint16_t port_option, const config_line_t *listen_options) |
static uint64_t | config_parse_memunit (const char *s, int *ok) |
static int | config_parse_interval (const char *s, int *ok) |
static void | init_libevent (void) |
static int | opt_streq (const char *s1, const char *s2) |
const char * | get_dirportfrontpage (void) |
static void * | config_alloc (config_format_t *fmt) |
or_options_t * | get_options (void) |
int | set_options (or_options_t *new_val, char **msg) |
const char * | get_version (void) |
static void | or_options_free (or_options_t *options) |
void | config_free_all (void) |
const char * | safe_str_client (const char *address) |
const char * | safe_str (const char *address) |
const char * | escaped_safe_str_client (const char *address) |
const char * | escaped_safe_str (const char *address) |
static void | add_default_trusted_dir_authorities (authority_type_t type) |
static int | validate_dir_authorities (or_options_t *options, or_options_t *old_options) |
static int | consider_adding_dir_authorities (or_options_t *options, or_options_t *old_options) |
int | options_need_geoip_info (or_options_t *options, const char **reason_out) |
uint32_t | get_effective_bwrate (or_options_t *options) |
uint32_t | get_effective_bwburst (or_options_t *options) |
static const char * | expand_abbrev (config_format_t *fmt, const char *option, int command_line, int warn_obsolete) |
static int | config_get_commandlines (int argc, char **argv, config_line_t **result) |
int | config_get_lines (const char *string, config_line_t **result) |
void | config_free_lines (config_line_t *front) |
static config_var_t * | config_find_option (config_format_t *fmt, const char *key) |
static int | config_assign_value (config_format_t *fmt, or_options_t *options, config_line_t *c, char **msg) |
static int | config_assign_line (config_format_t *fmt, or_options_t *options, config_line_t *c, int use_defaults, int clear_first, char **msg) |
static void | config_reset_line (config_format_t *fmt, or_options_t *options, const char *key, int use_defaults) |
int | option_is_recognized (const char *key) |
const char * | option_get_canonical_name (const char *key) |
config_line_t * | option_get_assignment (or_options_t *options, const char *key) |
static int | config_value_needs_escape (const char *value) |
static config_line_t * | config_lines_dup (const config_line_t *inp) |
static int | config_assign (config_format_t *fmt, void *options, config_line_t *list, int use_defaults, int clear_first, char **msg) |
setopt_err_t | options_trial_assign (config_line_t *list, int use_defaults, int clear_first, char **msg) |
static void | print_usage (void) |
static void | list_torrc_options (void) |
int | resolve_my_address (int warn_severity, or_options_t *options, uint32_t *addr_out, char **hostname_out) |
int | is_local_addr (const tor_addr_t *addr) |
static char * | get_default_nickname (void) |
or_options_t * | options_new (void) |
void | options_init (or_options_t *options) |
static char * | config_dump (config_format_t *fmt, void *options, int minimal, int comment_defaults) |
char * | options_dump (or_options_t *options, int minimal) |
static int | validate_ports_csv (smartlist_t *sl, const char *name, char **msg) |
static int | ensure_bandwidth_cap (uint64_t *value, const char *desc, char **msg) |
static int | compute_publishserverdescriptor (or_options_t *options) |
static const char * | get_default_conf_file (void) |
static char * | find_torrc_filename (int argc, char **argv, int *using_default_torrc, int *ignore_missing_torrc) |
static char * | load_torrc_from_disk (int argc, char **argv) |
int | options_init_from_torrc (int argc, char **argv) |
setopt_err_t | options_init_from_string (const char *cf, int command, const char *command_arg, char **msg) |
const char * | get_torrc_fname (void) |
static int | normalize_data_directory (or_options_t *options) |
int | options_save_current (void) |
static uint64_t | config_parse_units (const char *val, struct unit_table_t *u, int *ok) |
or_state_t * | get_or_state (void) |
char * | options_get_datadir_fname2_suffix (or_options_t *options, const char *sub1, const char *sub2, const char *suffix) |
static void | or_state_set (or_state_t *new_state) |
int | or_state_save (time_t now) |
void | remove_file_if_very_old (const char *fname, time_t now) |
int | getinfo_helper_config (control_connection_t *conn, const char *question, char **answer) |
Variables | |
static config_abbrev_t | _option_abbrevs [] |
static config_abbrev_t | _state_abbrevs [] |
static config_var_t | _option_vars [] |
static config_var_t | testing_tor_network_defaults [] |
static config_var_t | _state_vars [] |
static config_format_t | options_format |
static config_var_t | state_extra_var |
static config_format_t | state_format |
static or_options_t * | global_options = NULL |
static char * | torrc_fname = NULL |
static or_state_t * | global_state = NULL |
static config_line_t * | global_cmdline_options = NULL |
static char * | global_dirfrontpagecontents = NULL |
const char | tor_git_revision [] |
static char * | _version = NULL |
static uint32_t | last_resolved_addr = 0 |
static struct unit_table_t | memory_units [] |
static struct unit_table_t | time_units [] |
#define CHECK | ( | fmt, | |||
cfg | ) |
Value:
STMT_BEGIN \ tor_assert(fmt && cfg); \ tor_assert((fmt)->magic == \ *(uint32_t*)STRUCT_VAR_P(cfg,fmt->magic_offset)); \ STMT_END
Referenced by config_alloc(), config_assign(), config_assign_line(), config_assign_value(), config_init(), config_reset_line(), get_assigned_option(), option_is_same(), and option_reset().
#define GENERATED_FILE_COMMENT |
Value:
"# The old torrc file was renamed " \ "to torrc.orig.1 or similar, and Tor will ignore it"
Referenced by write_configuration_file().
#define GENERATED_FILE_PREFIX |
Value:
"# This file was generated by Tor; " \ "if you edit it, comments will not be preserved"
Referenced by write_configuration_file().
#define MAX_DIR_PERIOD (MIN_ONION_KEY_LIFETIME/2) |
Highest allowable value for RendPostPeriod.
#define MIN_CIRCUIT_STREAM_TIMEOUT 10 |
Lowest allowable value for CircuitStreamTimeout; if this is too low, Tor will generate too many circuits and potentially overload the network.
#define MIN_MAX_CIRCUIT_DIRTINESS 10 |
Lowest allowable value for MaxCircuitDirtiness; if this is too low, Tor will generate too many circuits and potentially overload the network.
#define MIN_REND_POST_PERIOD (10*60) |
Lowest allowable value for RendPostPeriod; if this is too low, hidden services can overload the directory system.
#define OBSOLETE | ( | name | ) | { name, CONFIG_TYPE_OBSOLETE, 0, NULL } |
An entry for config_vars: "The option <b>name</b> is obsolete."
#define OR_OPTIONS_MAGIC 9090909 |
Magic value for or_options_t.
Referenced by options_init_from_string().
#define OR_STATE_MAGIC 0x57A73f57 |
Magic value for or_state_t.
Referenced by or_state_load().
#define V | ( | member, | |||
conftype, | |||||
initvalue | ) | VAR(#member, conftype, member, initvalue) |
As VAR, but the option name and member name are the same.
Referenced by le_versions_compatibility(), tor_check_libevent_version(), and tor_decode_libevent_version().
#define VAR | ( | name, | |||
conftype, | |||||
member, | |||||
initvalue | ) |
Value:
{ name, CONFIG_TYPE_ ## conftype, STRUCT_OFFSET(or_state_t, member), \ initvalue }
#define VAR | ( | name, | |||
conftype, | |||||
member, | |||||
initvalue | ) |
Value:
{ name, CONFIG_TYPE_ ## conftype, STRUCT_OFFSET(or_options_t, member), \ initvalue }
typedef int(* validate_fn_t)(void *, void *, int, char **) |
Type of a callback to validate whether a given configuration is well-formed and consistent. See options_trial_assign() for documentation of arguments.
enum config_type_t |
Enumeration of types which option values can take
CONFIG_TYPE_STRING | An arbitrary string. |
CONFIG_TYPE_FILENAME | A filename: some prefixes get expanded. |
CONFIG_TYPE_UINT | A non-negative integer less than MAX_INT |
CONFIG_TYPE_INTERVAL | A number of seconds, with optional units |
CONFIG_TYPE_MEMUNIT | A number of bytes, with optional units |
CONFIG_TYPE_DOUBLE | A floating-point value |
CONFIG_TYPE_BOOL | A boolean value, expressed as 0 or 1. |
CONFIG_TYPE_ISOTIME | An ISO-formatted time relative to GMT. |
CONFIG_TYPE_CSV | A list of strings, separated by commas and optional whitespace. |
CONFIG_TYPE_LINELIST | Uninterpreted config lines |
CONFIG_TYPE_LINELIST_S | Uninterpreted, context-sensitive config lines, mixed with other keywords. |
CONFIG_TYPE_LINELIST_V | Catch-all "virtual" option to summarize context-sensitive config lines when fetching. |
CONFIG_TYPE_ROUTERSET | A list of router names, addrs, and fps, parsed into a routerset_t. |
CONFIG_TYPE_OBSOLETE | Obsolete (ignored) option. |
static void add_default_trusted_dir_authorities | ( | authority_type_t | type | ) | [static] |
Add the default directory authorities directly into the trusted dir list, but only add them insofar as they share bits with type.
References LD_BUG, and parse_dir_server_line().
Referenced by consider_adding_dir_authorities().
static int check_nickname_list | ( | const char * | lst, | |
const char * | name, | |||
char ** | msg | |||
) | [static] |
Verify whether lst is a string containing valid-looking comma-separated nicknames, or NULL. Return 0 on success. Warn and return -1 on failure.
References is_legal_nickname_or_hexdigest(), smartlist_create(), smartlist_free(), smartlist_split_string(), tor_asprintf(), and tor_free.
static int compute_publishserverdescriptor | ( | or_options_t * | options | ) | [static] |
Parse an authority type from options->PublishServerDescriptor and write it to options->_PublishServerDescriptor. Treat "1" as "v2,v3" unless BridgeRelay is 1, in which case treat it as "bridge". Treat "0" as "". Return 0 on success or -1 if not a recognized authority type (in which case the value of _PublishServerDescriptor is undefined).
References or_options_t::_PublishServerDescriptor, BRIDGE_AUTHORITY, or_options_t::BridgeRelay, HIDSERV_AUTHORITY, or_options_t::PublishServerDescriptor, V1_AUTHORITY, V2_AUTHORITY, and V3_AUTHORITY.
static void* config_alloc | ( | config_format_t * | fmt | ) | [static] |
Allocate an empty configuration object of a given format type.
References CHECK, config_format_t::magic, config_format_t::magic_offset, config_format_t::size, and STRUCT_VAR_P.
Referenced by config_dump(), options_dup(), and options_new().
static int config_assign | ( | config_format_t * | fmt, | |
void * | options, | |||
config_line_t * | list, | |||
int | use_defaults, | |||
int | clear_first, | |||
char ** | msg | |||
) | [static] |
Iterate through the linked list of requested options list. For each item, convert as appropriate and assign to options. If an item is unrecognized, set *msg and return -1 immediately, else return 0 for success.
If clear_first, interpret config options as replacing (not extending) their previous values. If clear_first is set, then use_defaults to decide if you set to defaults after clearing, or make the value 0 or NULL.
Here are the use cases: 1. A non-empty AllowInvalid line in your torrc. Appends to current if linelist, replaces current if csv. 2. An empty AllowInvalid line in your torrc. Should clear it. 3. "RESETCONF AllowInvalid" sets it to default. 4. "SETCONF AllowInvalid" makes it NULL. 5. "SETCONF AllowInvalid=foo" clears it and sets it to "foo".
Use_defaults Clear_first 0 0 "append" 1 0 undefined, don't use 0 1 "set to null first" 1 1 "set to defaults first" Return 0 on success, -1 on bad key, -2 on bad value.
As an additional special case, if a LINELIST config option has no value and clear_first is 0, then warn and ignore it.
References CHECK, config_assign_line(), config_reset_line(), expand_abbrev(), config_line_t::key, config_line_t::next, and tor_free.
Referenced by options_dup(), options_init_from_string(), options_trial_assign(), and or_state_load().
static int config_assign_line | ( | config_format_t * | fmt, | |
or_options_t * | options, | |||
config_line_t * | c, | |||
int | use_defaults, | |||
int | clear_first, | |||
char ** | msg | |||
) | [static] |
If c is a syntactically valid configuration line, update options with its value and return 0. Otherwise return -1 for bad key, -2 for bad value.
If clear_first is set, clear the value first. Then if use_defaults is set, set the value to the default.
Called from config_assign().
References CHECK, config_assign_value(), config_find_option(), config_line_append(), CONFIG_TYPE_LINELIST, CONFIG_TYPE_LINELIST_S, config_format_t::extra, config_line_t::key, LD_CONFIG, config_var_t::name, option_reset(), STRUCT_VAR_P, tor_asprintf(), tor_free, config_var_t::type, config_line_t::value, and config_var_t::var_offset.
Referenced by config_assign().
static int config_assign_value | ( | config_format_t * | fmt, | |
or_options_t * | options, | |||
config_line_t * | c, | |||
char ** | msg | |||
) | [static] |
c->key is known to be a real key. Update options with c->value and return 0, or return -1 if bad value.
Called from config_assign_line() and option_reset().
References CHECK, config_find_option(), config_line_append(), config_parse_interval(), config_parse_memunit(), CONFIG_TYPE_BOOL, CONFIG_TYPE_CSV, CONFIG_TYPE_DOUBLE, CONFIG_TYPE_FILENAME, CONFIG_TYPE_INTERVAL, CONFIG_TYPE_ISOTIME, CONFIG_TYPE_LINELIST, CONFIG_TYPE_LINELIST_S, CONFIG_TYPE_LINELIST_V, CONFIG_TYPE_MEMUNIT, CONFIG_TYPE_OBSOLETE, CONFIG_TYPE_ROUTERSET, CONFIG_TYPE_STRING, CONFIG_TYPE_UINT, config_line_t::key, LD_CONFIG, parse_iso_time(), routerset_free(), routerset_new(), routerset_parse(), smartlist_clear(), smartlist_create(), smartlist_split_string(), STRUCT_VAR_P, tor_asprintf(), tor_assert, tor_free, tor_parse_long(), config_var_t::type, config_line_t::value, and config_var_t::var_offset.
Referenced by config_assign_line(), and option_reset().
static char* config_dump | ( | config_format_t * | fmt, | |
void * | options, | |||
int | minimal, | |||
int | comment_defaults | |||
) | [static] |
Allocate and return a new string holding the written-out values of the vars in 'options'. If 'minimal', do not write out any default-valued vars. Else, if comment_defaults, write default values as comments.
References config_alloc(), config_free(), config_free_lines(), config_init(), CONFIG_TYPE_LINELIST_S, CONFIG_TYPE_OBSOLETE, config_format_t::extra, get_assigned_option(), config_line_t::key, LD_BUG, config_var_t::name, config_line_t::next, option_is_same(), smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), strcmpstart(), STRUCT_VAR_P, tor_asprintf(), tor_assert, tor_free, config_var_t::type, config_format_t::validate_fn, config_line_t::value, config_var_t::var_offset, and config_format_t::vars.
Referenced by options_dump(), and or_state_save().
static config_var_t* config_find_option | ( | config_format_t * | fmt, | |
const char * | key | |||
) | [static] |
If key is a configuration option, return the corresponding config_var_t. Otherwise, if key is a non-standard abbreviation, warn, and return the corresponding config_var_t. Otherwise return NULL.
References LD_CONFIG, config_var_t::name, and config_format_t::vars.
Referenced by config_assign_line(), config_assign_value(), config_reset_line(), get_assigned_option(), option_get_canonical_name(), option_is_recognized(), and options_init_from_string().
static void config_free | ( | config_format_t * | fmt, | |
void * | options | |||
) | [static] |
Release storage held by options.
References config_free_lines(), config_format_t::extra, config_var_t::name, option_clear(), STRUCT_VAR_P, tor_assert, tor_free, config_var_t::var_offset, and config_format_t::vars.
Referenced by config_dump(), config_free_all(), options_init_from_string(), options_trial_assign(), or_options_free(), or_state_load(), or_state_set(), and set_options().
void config_free_all | ( | void | ) |
Release all memory and resources held by global configuration structures.
References config_free(), config_free_lines(), or_options_free(), and tor_free.
Referenced by tor_free_all().
void config_free_lines | ( | config_line_t * | front | ) |
Free all the configuration lines on the linked list front.
References config_line_t::key, config_line_t::next, tor_free, and config_line_t::value.
Referenced by circuit_build_times_update_state(), config_dump(), config_free(), config_free_all(), config_get_commandlines(), config_get_lines(), control_setconf_helper(), dirserv_load_fingerprint_file(), entry_guards_update_state(), option_clear(), option_is_same(), option_reset(), options_dup(), options_init_from_string(), and or_state_load().
static int config_get_commandlines | ( | int | argc, | |
char ** | argv, | |||
config_line_t ** | result | |||
) | [static] |
Helper: Read a list of configuration options from the command line. If successful, put them in *result and return 0, and return -1 and leave *result alone.
References config_free_lines(), expand_abbrev(), and LD_CONFIG.
Referenced by options_init_from_torrc().
int config_get_lines | ( | const char * | string, | |
config_line_t ** | result | |||
) |
Helper: parse the config string and strdup into key/value strings. Set *result to the list, or NULL if parsing the string failed. Return 0 on success, -1 on failure. Warn and ignore any misformatted lines.
References config_free_lines(), parse_config_line_from_str(), and tor_free.
Referenced by control_setconf_helper(), dirserv_load_fingerprint_file(), options_init_from_string(), and or_state_load().
static void config_init | ( | config_format_t * | fmt, | |
void * | options | |||
) | [static] |
Set all vars in the configuration object options to their default values.
References CHECK, config_var_t::initvalue, config_var_t::name, option_reset(), and config_format_t::vars.
Referenced by config_dump(), options_init(), and or_state_load().
static void config_line_append | ( | config_line_t ** | lst, | |
const char * | key, | |||
const char * | val | |||
) | [static] |
Helper: allocate a new configuration option mapping 'key' to 'val', append it to *lst.
References config_line_t::key, config_line_t::next, and config_line_t::value.
Referenced by config_assign_line(), config_assign_value(), and options_validate().
static config_line_t* config_lines_dup | ( | const config_line_t * | inp | ) | [static] |
Return a newly allocated deep copy of the lines in inp.
References config_line_t::key, config_line_t::next, and config_line_t::value.
Referenced by get_assigned_option(), and options_validate().
static int config_lines_eq | ( | config_line_t * | a, | |
config_line_t * | b | |||
) | [static] |
Return true iff a and b contain identical keys and values in identical order.
References config_line_t::key, config_line_t::next, and config_line_t::value.
Referenced by consider_adding_dir_authorities(), option_is_same(), options_transition_affects_descriptor(), options_transition_affects_workers(), options_validate(), and validate_dir_authorities().
static int config_parse_interval | ( | const char * | s, | |
int * | ok | |||
) | [static] |
Parse a string in the format "number unit", where unit is a unit of time. On success, set *ok to true and return the number of seconds in the provided interval. Otherwise, set *ok to 0 and return -1.
References config_parse_units(), and LD_CONFIG.
Referenced by config_assign_value().
static uint64_t config_parse_memunit | ( | const char * | s, | |
int * | ok | |||
) | [static] |
Parse a string in the format "number unit", where unit is a unit of information (byte, KB, M, etc). On success, set *ok to true and return the number of bytes specified. Otherwise, set *ok to false and return 0.
References config_parse_units().
Referenced by config_assign_value().
static uint64_t config_parse_units | ( | const char * | val, | |
struct unit_table_t * | u, | |||
int * | ok | |||
) | [static] |
Parse a string val containing a number, zero or more spaces, and an optional unit string. If the unit appears in the table u, then multiply the number by the unit multiplier. On success, set *ok to 1 and return this product. Otherwise, set *ok to 0.
References eat_whitespace(), LD_CONFIG, unit_table_t::multiplier, tor_assert, tor_parse_double(), tor_parse_uint64(), and unit_table_t::unit.
Referenced by config_parse_interval(), and config_parse_memunit().
static void config_register_addressmaps | ( | or_options_t * | options | ) | [static] |
Adjust the address map based on the MapAddress elements in the configuration options
References address_is_invalid_destination(), or_options_t::AddressMap, addressmap_clear_configured(), addressmap_register(), ADDRMAPSRC_TORRC, LD_CONFIG, config_line_t::next, smartlist_clear(), smartlist_create(), smartlist_free(), smartlist_split_string(), tor_free, and config_line_t::value.
Referenced by options_act().
static void config_reset_line | ( | config_format_t * | fmt, | |
or_options_t * | options, | |||
const char * | key, | |||
int | use_defaults | |||
) | [static] |
Restore the option named key in options to its default value. Called from config_assign().
References CHECK, config_find_option(), and option_reset().
Referenced by config_assign().
static int config_value_needs_escape | ( | const char * | value | ) | [static] |
Return true iff value needs to be quoted and escaped to be used in a configuration file.
Referenced by get_assigned_option().
static int consider_adding_dir_authorities | ( | or_options_t * | options, | |
or_options_t * | old_options | |||
) | [static] |
Look at all the config options and assign new dir authorities as appropriate.
References add_default_trusted_dir_authorities(), or_options_t::AlternateBridgeAuthority, or_options_t::AlternateDirAuthority, or_options_t::AlternateHSAuthority, BRIDGE_AUTHORITY, clear_trusted_dir_servers(), config_lines_eq(), or_options_t::DirServers, HIDSERV_AUTHORITY, config_line_t::next, parse_dir_server_line(), router_get_trusted_dir_servers(), V1_AUTHORITY, V2_AUTHORITY, V3_AUTHORITY, and config_line_t::value.
Referenced by options_act().
static int ensure_bandwidth_cap | ( | uint64_t * | value, | |
const char * | desc, | |||
char ** | msg | |||
) | [static] |
If value exceeds ROUTER_MAX_DECLARED_BANDWIDTH, write a complaint into *msg using string desc, and return -1. Else return 0.
References tor_asprintf().
const char* escaped_safe_str | ( | const char * | address | ) |
Equivalent to escaped(safe_str(address)). See reentrancy note on escaped(): don't use this outside the main thread, or twice in the same log statement.
References escaped(), and get_options().
Referenced by connection_dns_remove(), connection_edge_finished_connecting(), connection_tls_start_handshake(), dns_cancel_pending_resolve(), dns_found_answer(), dns_resolve_impl(), evdns_callback(), launch_resolve(), launch_test_addresses(), and purge_expired_resolves().
const char* escaped_safe_str_client | ( | const char * | address | ) |
Equivalent to escaped(safe_str_client(address)). See reentrancy note on escaped(): don't use this outside the main thread, or twice in the same log statement.
References escaped(), and get_options().
Referenced by addressmap_rewrite(), addressmap_rewrite_reverse(), circuit_discard_optional_exit_enclaves(), circuit_get_open_circ_or_launch(), conn_close_if_marked(), connection_ap_handshake_rewrite_and_attach(), connection_connect(), connection_exit_connect(), directory_get_from_hs_dir(), dnsserv_launch_request(), evdns_server_callback(), rend_client_introduction_acked(), rend_client_remove_intro_point(), rend_client_send_introduction(), rend_service_introduce(), and rend_service_launch_establish_intro().
static const char* expand_abbrev | ( | config_format_t * | fmt, | |
const char * | option, | |||
int | command_line, | |||
int | warn_obsolete | |||
) | [static] |
If option is an official abbreviation for a longer option, return the longer option. Otherwise return option. If command_line is set, apply all abbreviations. Otherwise, only apply abbreviations that work for the config file and the command line. If warn_obsolete is set, warn about deprecated names.
References config_abbrev_t::abbreviated, config_format_t::abbrevs, config_abbrev_t::commandline_only, config_abbrev_t::full, LD_CONFIG, and config_abbrev_t::warn.
Referenced by config_assign(), and config_get_commandlines().
static char* find_torrc_filename | ( | int | argc, | |
char ** | argv, | |||
int * | using_default_torrc, | |||
int * | ignore_missing_torrc | |||
) | [static] |
Learn config file name from command line arguments, or use the default
References expand_filename(), file_status(), get_default_conf_file(), LD_CONFIG, and tor_free.
Referenced by load_torrc_from_disk().
static config_line_t * get_assigned_option | ( | config_format_t * | fmt, | |
void * | options, | |||
const char * | key, | |||
int | escape_val | |||
) | [static] |
Return newly allocated line or lines corresponding to key in the configuration options. If escape_val is true and a value needs to be quoted before it's put in a config file, quote and escape that value. Return NULL if no such key exists.
References CHECK, config_find_option(), config_lines_dup(), CONFIG_TYPE_BOOL, CONFIG_TYPE_CSV, CONFIG_TYPE_DOUBLE, CONFIG_TYPE_FILENAME, CONFIG_TYPE_INTERVAL, CONFIG_TYPE_ISOTIME, CONFIG_TYPE_LINELIST, CONFIG_TYPE_LINELIST_S, CONFIG_TYPE_LINELIST_V, CONFIG_TYPE_MEMUNIT, CONFIG_TYPE_OBSOLETE, CONFIG_TYPE_ROUTERSET, CONFIG_TYPE_STRING, CONFIG_TYPE_UINT, config_value_needs_escape(), esc_for_log(), format_iso_time(), config_line_t::key, LD_BUG, LD_CONFIG, config_var_t::name, config_line_t::next, routerset_to_string(), smartlist_join_strings(), STRUCT_VAR_P, tor_asprintf(), tor_assert, tor_free, config_var_t::type, config_line_t::value, and config_var_t::var_offset.
Referenced by config_dump(), option_get_assignment(), option_is_same(), and options_dup().
static const char* get_default_conf_file | ( | void | ) | [static] |
Return the default location for our torrc file.
Referenced by find_torrc_filename(), and get_torrc_fname().
static char* get_default_nickname | ( | void | ) | [static] |
Called when we don't have a nickname set. Try to guess a good nickname based on the hostname, and return it in a newly allocated string. If we can't, return NULL and let the caller warn if it wants to.
References LEGAL_NICKNAME_CHARACTERS, MAX_NICKNAME_LEN, tor_free, and tor_strlower().
Referenced by options_validate().
const char* get_dirportfrontpage | ( | void | ) |
Return the contents of our frontpage string, or NULL if not configured.
Referenced by directory_handle_command_get().
uint32_t get_effective_bwburst | ( | or_options_t * | options | ) |
Return the bandwidthburst that we are going to report to the authorities based on the config options.
References or_options_t::BandwidthBurst, and or_options_t::RelayBandwidthBurst.
Referenced by options_transition_affects_descriptor(), and router_rebuild_descriptor().
uint32_t get_effective_bwrate | ( | or_options_t * | options | ) |
Return the bandwidthrate that we are going to report to the authorities based on the config options.
References or_options_t::BandwidthRate, or_options_t::MaxAdvertisedBandwidth, and or_options_t::RelayBandwidthRate.
Referenced by options_transition_affects_descriptor(), and router_rebuild_descriptor().
or_options_t* get_options | ( | void | ) |
Return the currently configured options.
References tor_assert.
Referenced by accounting_record_bandwidth_usage(), accounting_set_wakeup_time(), add_networkstatus_to_cache(), add_trusted_dir_server(), add_wildcarded_test_address(), address_is_invalid_destination(), any_bridge_descriptors_known(), authority_certs_fetch_missing(), cell_queue_append_packed_copy(), check_descriptor_ipaddress_changed(), check_whether_dirport_reachable(), check_whether_orport_reachable(), choose_good_entry_server(), choose_good_exit_server(), choose_good_exit_server_general(), choose_good_middle_server(), choose_random_entry(), circuit_all_predicted_ports_handled(), circuit_build_needed_circs(), circuit_build_times_add_time(), circuit_build_times_get_initial_timeout(), circuit_build_times_update_state(), circuit_expire_all_dirty_circs(), circuit_expire_old_circuits_clientside(), circuit_extend(), circuit_free(), circuit_get_open_circ_or_launch(), circuit_is_acceptable(), circuit_note_clock_jumped(), circuit_rep_hist_note_result(), circuit_send_next_onion_skin(), circuit_stream_is_being_handled(), circuit_testing_failed(), command_process_create_cell(), compute_retry_timeout(), configure_nameservers(), conn_close_if_marked(), connection_about_to_close_connection(), connection_ap_can_use_exit(), connection_ap_detach_retriable(), connection_ap_expire_beginning(), connection_ap_handshake_attach_circuit(), connection_ap_handshake_process_socks(), connection_ap_handshake_rewrite_and_attach(), connection_ap_process_end_not_open(), connection_ap_process_natd(), connection_ap_process_transparent(), connection_bucket_init(), connection_bucket_refill(), connection_connect(), connection_create_listener(), connection_dir_client_reached_eof(), connection_dir_request_failed(), connection_edge_process_relay_cell_not_open(), connection_exit_begin_conn(), connection_handle_listener_read(), connection_or_check_valid_tls_handshake(), connection_or_connect(), connection_or_connect_failed(), connection_or_finished_connecting(), connection_or_flush_from_first_active_circuit(), connection_or_init_conn_from_address(), connection_proxy_connect(), connection_read_proxy_handshake(), consider_hibernation(), consider_plaintext_ports(), consider_publishable_server(), consider_recording_trackhost(), control_event_bootstrap_problem(), control_event_guard_deferred(), count_loading_descriptors_progress(), cpuworkers_rotate(), decide_if_publishable_server(), dir_routerdesc_download_failed(), directories_have_accepted_server_descriptor(), directory_get_from_dirserver(), directory_handle_command_get(), directory_handle_command_post(), directory_info_has_arrived(), directory_initiate_command_rend(), directory_send_command(), dirserv_dump_directory_to_string(), dirserv_generate_networkstatus_vote_obj(), dirserv_get_networkstatus_v2_fingerprints(), dirserv_get_status_impl(), dirserv_load_fingerprint_file(), dirserv_orconn_tls_done(), dirserv_pick_cached_dir_obj(), dirserv_router_has_valid_address(), dirserv_set_router_is_running(), dirserv_test_reachability(), dirserv_thinks_router_is_hs_dir(), dirvote_compute_consensuses(), dirvote_get_preferred_voting_intervals(), dns_init(), dns_launch_correctness_checks(), dns_reset(), dns_servers_relaunch_checks(), do_hash_password(), do_hup(), do_list_fingerprint(), do_main_loop(), download_status_reset(), entry_guards_changed(), entry_guards_compute_status(), entry_guards_prepend_from_config(), entry_guards_update_state(), entry_is_live(), escaped_safe_str(), escaped_safe_str_client(), evdns_log_cb(), extrainfo_dump_to_string(), fetch_bridge_descriptors(), generate_runningrouters(), generate_v2_networkstatus_opinion(), geoip_change_dirreq_state(), geoip_dirreq_stats_write(), geoip_entry_stats_write(), geoip_note_client_seen(), geoip_note_ns_response(), geoip_start_dirreq(), get_cookie_file(), get_possible_sybil_list(), getinfo_helper_accounting(), getinfo_helper_events(), getinfo_helper_misc(), global_write_bucket_low(), handle_control_attachstream(), handle_control_authenticate(), handle_control_getconf(), handle_control_protocolinfo(), hibernate_begin(), hibernate_go_dormant(), hibernate_hard_limit_reached(), hibernate_soft_limit_reached(), hid_serv_acting_as_directory(), hid_serv_get_responsible_directories(), init_cookie_authentication(), init_key_from_file(), init_keys(), init_libevent(), init_v3_authority_keys(), ip_address_changed(), is_local_addr(), is_test_address(), launch_resolve(), launch_router_descriptor_downloads(), launch_test_addresses(), learned_bridge_descriptor(), list_server_status_v1(), networkstatus_dump_bridge_status_to_file(), networkstatus_getinfo_by_purpose(), networkstatus_set_current_consensus(), networkstatus_v2_list_clean(), onion_pending_add(), options_act(), options_act_reversible(), options_save_current(), options_trial_assign(), or_state_save(), parse_reachable_addresses(), pick_entry_guards(), purpose_needs_anonymity(), refresh_all_country_info(), rend_client_refetch_v2_renddesc(), rend_consider_descriptor_republication(), rend_consider_services_upload(), rend_service_requires_uptime(), rend_services_introduce(), rep_hist_circbuilding_dormant(), rep_hist_dump_stats(), rep_hist_fill_bandwidth_history(), rep_hist_note_exit_bytes_read(), rep_hist_note_exit_bytes_written(), rep_hist_note_exit_stream_opened(), rep_hist_update_state(), rep_history_clean(), retry_all_listeners(), rotate_onion_key(), router_add_to_routerlist(), router_choose_random_node(), router_digest_is_trusted_dir_type(), router_dirport_found_reachable(), router_dump_router_to_string(), router_get_by_nickname(), router_get_my_extrainfo(), router_get_my_routerinfo(), router_new_address_suggestion(), router_orport_found_reachable(), router_parse_directory(), router_parse_runningrouters(), router_perform_bandwidth_test(), router_pick_directory_server(), router_pick_trusteddirserver(), router_rebuild_descriptor(), router_reload_consensus_networkstatus(), router_reload_v2_networkstatus(), router_set_networkstatus_v2(), router_upload_dir_desc_to_dirservers(), routerlist_add_family(), routerlist_remove_old_cached_routers_with_id(), routerlist_remove_old_routers(), routers_in_same_family(), routers_update_all_from_networkstatus(), routers_update_status_from_consensus_networkstatus(), run_connection_housekeeping(), run_scheduled_events(), safe_str(), safe_str_client(), second_elapsed_callback(), should_generate_v2_networkstatus(), should_use_create_fast_for_circuit(), signal_callback(), signed_desc_digest_is_recognized(), spawn_enough_cpuworkers(), tor_cleanup(), tor_init(), tor_main(), trusted_dirs_load_certs_from_string(), update_consensus_networkstatus_downloads(), update_consensus_networkstatus_fetch_time(), update_consensus_router_descriptor_downloads(), update_expected_bandwidth(), update_extrainfo_downloads(), update_networkstatus_downloads(), update_router_descriptor_cache_downloads_v2(), update_router_descriptor_downloads(), update_router_have_minimum_dir_info(), update_v2_networkstatus_cache_downloads(), upload_service_descriptor(), v3_authority_check_key_expiry(), and warn_if_last_router_excluded().
or_state_t* get_or_state | ( | void | ) |
Return the persistent state struct for this Tor.
References tor_assert.
Referenced by accounting_run_housekeeping(), circuit_build_times_add_time(), circuit_build_times_update_state(), do_hup(), entry_guards_changed(), entry_guards_update_state(), hibernate_begin(), hibernate_go_dormant(), init_keys(), read_bandwidth_usage(), rep_hist_update_state(), rotate_onion_key(), and tor_cleanup().
const char* get_torrc_fname | ( | void | ) |
Return the location for our configuration file.
References get_default_conf_file().
Referenced by getinfo_helper_misc(), options_save_current(), and parse_dir_server_line().
const char* get_version | ( | void | ) |
Return the current Tor version.
References tor_snprintf().
Referenced by get_platform_str(), getinfo_helper_misc(), options_init_from_torrc(), or_state_save(), and tor_init().
int getinfo_helper_config | ( | control_connection_t * | conn, | |
const char * | question, | |||
char ** | answer | |||
) |
Helper to implement GETINFO functions about configuration variables (not their values). Given a "config/names" question, set *answer to a new string describing the supported configuration variables and their types.
References CONFIG_TYPE_BOOL, CONFIG_TYPE_CSV, CONFIG_TYPE_DOUBLE, CONFIG_TYPE_FILENAME, CONFIG_TYPE_INTERVAL, CONFIG_TYPE_ISOTIME, CONFIG_TYPE_LINELIST, CONFIG_TYPE_LINELIST_S, CONFIG_TYPE_LINELIST_V, CONFIG_TYPE_MEMUNIT, CONFIG_TYPE_OBSOLETE, CONFIG_TYPE_ROUTERSET, CONFIG_TYPE_STRING, CONFIG_TYPE_UINT, config_var_t::name, smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), tor_asprintf(), tor_free, and config_var_t::type.
static void init_libevent | ( | void | ) | [static] |
Initialize the libevent library.
References configure_libevent_logging(), control_event_general_status(), get_options(), suppress_libevent_log_msg(), tor_check_libevent_header_compatibility(), tor_check_libevent_version(), tor_libevent_get_method(), tor_libevent_get_version_str(), and tor_libevent_initialize().
Referenced by options_act_reversible().
int is_local_addr | ( | const tor_addr_t * | addr | ) |
Return true iff addr is judged to be on the same network as us, or on a private network.
References get_options(), tor_addr_family(), tor_addr_is_internal(), and tor_addr_to_ipv4h().
Referenced by onionskin_answer(), and write_http_response_header_impl().
static void list_torrc_options | ( | void | ) | [static] |
Print all non-obsolete torrc options.
References CONFIG_TYPE_LINELIST_V, CONFIG_TYPE_OBSOLETE, config_var_t::name, smartlist_create(), smartlist_free(), and config_var_t::type.
Referenced by options_init_from_torrc().
static char* load_torrc_from_disk | ( | int | argc, | |
char ** | argv | |||
) | [static] |
Load torrc from disk, setting torrc_fname if successful
References file_status(), find_torrc_filename(), LD_CONFIG, read_file_to_str(), tor_assert, and tor_free.
Referenced by options_init_from_torrc().
static int normalize_data_directory | ( | or_options_t * | options | ) | [static] |
Adjust the value of options->DataDirectory, or fill it in if it's absent. Return 0 on success, -1 on failure.
References or_options_t::DataDirectory, expand_filename(), LD_CONFIG, and tor_free.
Referenced by validate_data_directory().
static int opt_streq | ( | const char * | s1, | |
const char * | s2 | |||
) | [static] |
Helper: return true iff s1 and s2 are both NULL, or both non-NULL equal strings.
Referenced by options_act(), options_transition_affects_descriptor(), options_transition_affects_workers(), and options_transition_allowed().
static void option_clear | ( | config_format_t * | fmt, | |
or_options_t * | options, | |||
config_var_t * | var | |||
) | [static] |
Reset config option var to 0, 0.0, NULL, or the equivalent. Called from option_reset() and config_free().
References config_free_lines(), CONFIG_TYPE_BOOL, CONFIG_TYPE_CSV, CONFIG_TYPE_DOUBLE, CONFIG_TYPE_FILENAME, CONFIG_TYPE_INTERVAL, CONFIG_TYPE_ISOTIME, CONFIG_TYPE_LINELIST, CONFIG_TYPE_LINELIST_S, CONFIG_TYPE_LINELIST_V, CONFIG_TYPE_MEMUNIT, CONFIG_TYPE_OBSOLETE, CONFIG_TYPE_ROUTERSET, CONFIG_TYPE_STRING, CONFIG_TYPE_UINT, routerset_free(), smartlist_free(), STRUCT_VAR_P, tor_free, config_var_t::type, and config_var_t::var_offset.
Referenced by config_free(), and option_reset().
config_line_t* option_get_assignment | ( | or_options_t * | options, | |
const char * | key | |||
) |
Return a canonical list of the options assigned for key.
References get_assigned_option().
Referenced by handle_control_getconf().
const char* option_get_canonical_name | ( | const char * | key | ) |
Return the canonical name of a configuration option, or NULL if no such option exists.
References config_find_option(), and config_var_t::name.
Referenced by handle_control_getconf().
int option_is_recognized | ( | const char * | key | ) |
Return true iff key is a valid configuration option.
References config_find_option().
Referenced by handle_control_getconf().
static int option_is_same | ( | config_format_t * | fmt, | |
or_options_t * | o1, | |||
or_options_t * | o2, | |||
const char * | name | |||
) | [static] |
Return true iff the option name has the same value in o1 and o2. Must not be called for LINELIST_S or OBSOLETE options.
References CHECK, config_free_lines(), config_lines_eq(), and get_assigned_option().
Referenced by config_dump().
static void option_reset | ( | config_format_t * | fmt, | |
or_options_t * | options, | |||
config_var_t * | var, | |||
int | use_defaults | |||
) | [static] |
Clear the option indexed by var in options. Then if use_defaults, set it to its default value. Called by config_init() and option_reset_line() and option_assign_line().
References CHECK, config_assign_value(), config_free_lines(), config_var_t::initvalue, config_line_t::key, LD_BUG, config_var_t::name, option_clear(), tor_free, and config_line_t::value.
Referenced by config_assign_line(), config_init(), and config_reset_line().
static int options_act | ( | or_options_t * | old_options | ) | [static] |
Fetch the active option list, and take actions based on it. All of the things we do should survive being done repeatedly. If present, old_options contains the previous value of the options.
Return 0 if all goes well, return -1 if it's time to die.
Note: We haven't moved all the "act on new configuration" logic here yet. Some is still in do_hup() and other places.
References accounting_is_enabled(), accounting_parse_options(), any_predicted_circuits(), authdir_mode_v3(), bool_eq, or_options_t::BridgeRelay, or_options_t::Bridges, cell_ewma_set_scale_factor(), circuit_expire_all_dirty_circs(), circuit_mark_all_unused_circs(), clear_bridge_list(), or_options_t::command, config_register_addressmaps(), configure_accounting(), consider_adding_dir_authorities(), or_options_t::CookieAuthentication, cpuworkers_rotate(), or_options_t::DataDirectory, directory_fetches_dir_info_early(), directory_fetches_dir_info_later(), or_options_t::DirPortFrontPage, or_options_t::DirReqStatistics, dirvote_recalculate_timing(), dns_reset(), entry_nodes_should_be_added(), or_options_t::EntryNodes, or_options_t::EntryStatistics, or_options_t::ExcludeExitNodes, or_options_t::ExcludeNodes, or_options_t::ExitNodes, finish_daemon(), geoip_is_loaded(), geoip_load_file(), geoip_remove_old_clients(), or_options_t::GeoIPFile, get_options(), has_completed_circuit, have_lockfile(), inform_testing_reachability(), init_cookie_authentication(), init_keys(), ip_address_changed(), LD_BUG, LD_CIRC, LD_CONFIG, LD_GENERAL, mark_my_descriptor_dirty(), networkstatus_get_latest_consensus(), config_line_t::next, opt_streq(), options_transition_affects_descriptor(), options_transition_affects_workers(), or_state_load(), parse_bridge_line(), parse_virtual_addr_network(), or_options_t::PidFile, policies_parse_from_options(), read_file_to_str(), rend_config_services(), rend_parse_service_authorization(), rend_service_load_keys(), rep_hist_load_mtbf_data(), router_dir_info_changed(), routerset_equal(), or_options_t::RunAsDaemon, server_mode(), should_record_bridge_info(), or_options_t::StrictNodes, tor_free, tor_snprintf(), try_locking(), update_consensus_networkstatus_fetch_time(), or_options_t::UseEntryGuards, or_options_t::V3AuthoritativeDir, config_line_t::value, or_options_t::VirtualAddrNetwork, and write_pidfile().
Referenced by set_options().
static int options_act_reversible | ( | or_options_t * | old_options, | |
char ** | msg | |||
) | [static] |
Fetch the active option list, and take actions based on it. All of the things we do should survive being done repeatedly. If present, old_options contains the previous value of the options.
Return 0 if all goes well, return -1 if things went badly.
References or_options_t::_ConnLimit, add_callback_log(), check_private_dir(), close_temp_logs(), or_options_t::command, conn_type_to_string(), connection_close_immediate(), or_options_t::ConnLimit, control_adjust_event_log_severity(), control_event_logmsg(), or_options_t::ControlSocket, or_options_t::DataDirectory, directory_caches_v2_dir_info(), or_options_t::DisableAllSwap, get_options(), init_libevent(), LD_NET, mark_logs_temp(), options_init_logs(), retry_all_listeners(), rollback_log_changes(), or_options_t::RunAsDaemon, set_max_file_descriptors(), smartlist_create(), smartlist_free(), start_daemon(), switch_id(), tor_asprintf(), tor_assert, tor_free, tor_mlockall(), tor_snprintf(), or_options_t::TransPort, and or_options_t::User.
Referenced by set_options().
char* options_dump | ( | or_options_t * | options, | |
int | minimal | |||
) |
Return a string containing a possible configuration file that would give the configuration in options. If minimal is true, do not include options that are the same as Tor's defaults.
References config_dump().
Referenced by getinfo_helper_misc(), and write_configuration_file().
static or_options_t * options_dup | ( | config_format_t * | fmt, | |
or_options_t * | old | |||
) | [static] |
Copy storage held by old into a new or_options_t and return it.
References config_alloc(), config_assign(), config_free_lines(), CONFIG_TYPE_LINELIST_S, CONFIG_TYPE_OBSOLETE, get_assigned_option(), LD_BUG, config_var_t::name, tor_assert, tor_free, config_var_t::type, and config_format_t::vars.
Referenced by options_trial_assign().
char* options_get_datadir_fname2_suffix | ( | or_options_t * | options, | |
const char * | sub1, | |||
const char * | sub2, | |||
const char * | suffix | |||
) |
Return a newly allocated string holding a filename relative to the data directory. If sub1 is present, it is the first path component after the data directory. If sub2 is also present, it is the second path component after the data directory. If suffix is present, it is appended to the filename.
Examples: get_datadir_fname2_suffix("a", NULL, NULL) -> $DATADIR/a get_datadir_fname2_suffix("a", NULL, ".tmp") -> $DATADIR/a.tmp get_datadir_fname2_suffix("a", "b", ".tmp") -> $DATADIR/a/b/.tmp get_datadir_fname2_suffix("a", "b", NULL) -> $DATADIR/a/b
Note: Consider using the get_datadir_fname* macros in or.h.
References or_options_t::DataDirectory, tor_assert, and tor_snprintf().
Referenced by try_locking().
void options_init | ( | or_options_t * | options | ) |
Set options to hold reasonable defaults for most options. Each option defaults to zero.
References config_init().
Referenced by options_init_from_string().
setopt_err_t options_init_from_string | ( | const char * | cf, | |
int | command, | |||
const char * | command_arg, | |||
char ** | msg | |||
) |
Load the options from the configuration in cf, validate them for consistency and take actions based on them.
Return 0 if success, negative on error: * -1 for general errors. * -2 for failure to parse/validate, * -3 for transition not allowed * -4 for error while setting the new options
References or_options_t::_magic, or_options_t::command, or_options_t::command_arg, config_assign(), config_find_option(), config_free(), config_free_lines(), config_get_lines(), config_var_t::initvalue, config_var_t::name, options_init(), options_transition_allowed(), options_validate(), OR_OPTIONS_MAGIC, set_options(), or_options_t::TestingTorNetwork, tor_asprintf(), tor_assert, and tor_free.
Referenced by handle_control_loadconf(), and options_init_from_torrc().
int options_init_from_torrc | ( | int | argc, | |
char ** | argv | |||
) |
Read a configuration file into options, finding the configuration file location based on the command line. After loading the file call options_init_from_string() to load the config. Return 0 if success, -1 if failure.
References config_get_commandlines(), get_version(), LD_CONFIG, list_torrc_options(), load_torrc_from_disk(), options_init_from_string(), print_usage(), and tor_free.
Referenced by do_hup(), and tor_init().
static int options_init_logs | ( | or_options_t * | options, | |
int | validate_only | |||
) | [static] |
Initialize the logs based on the configuration file.
References add_file_log(), add_stream_log(), add_syslog_log(), LD_CONFIG, or_options_t::Logs, config_line_t::next, parse_log_severity_config(), or_options_t::RunAsDaemon, smartlist_add(), smartlist_clear(), smartlist_create(), smartlist_free(), smartlist_split_string(), tor_free, and config_line_t::value.
Referenced by options_act_reversible(), and options_validate().
int options_need_geoip_info | ( | or_options_t * | options, | |
const char ** | reason_out | |||
) |
If we need to have a GEOIP ip-to-country map to run with our configured options, return 1 and set *reason_out to a description of why.
References or_options_t::BridgeRecordUsageByCountry, or_options_t::BridgeRelay, or_options_t::EntryNodes, or_options_t::ExcludeExitNodes, or_options_t::ExcludeNodes, or_options_t::ExitNodes, and routerset_needs_geoip().
Referenced by geoip_load_file().
or_options_t* options_new | ( | void | ) |
Return a new empty or_options_t. Used for testing.
References config_alloc().
int options_save_current | ( | void | ) |
Save the current configuration file value to disk. Return 0 on success, -1 on failure.
References get_options(), get_torrc_fname(), and write_configuration_file().
Referenced by handle_control_saveconf().
static int options_transition_affects_descriptor | ( | or_options_t * | old_options, | |
or_options_t * | new_options | |||
) | [static] |
Return 1 if any change from old_options to new_options will require us to generate a new descriptor; else return 0.
References or_options_t::_PublishServerDescriptor, or_options_t::AccountingMax, or_options_t::AccountingStart, or_options_t::Address, or_options_t::ClientOnly, config_lines_eq(), or_options_t::ContactInfo, or_options_t::DataDirectory, or_options_t::DirPort, or_options_t::ExitPolicy, or_options_t::ExitPolicyRejectPrivate, get_effective_bwburst(), get_effective_bwrate(), or_options_t::MyFamily, or_options_t::Nickname, or_options_t::NoPublish, opt_streq(), and or_options_t::ORPort.
Referenced by options_act().
static int options_transition_affects_workers | ( | or_options_t * | old_options, | |
or_options_t * | new_options | |||
) | [static] |
Return 1 if any change from old_options to new_options will require us to rotate the CPU and DNS workers; else return 0.
References or_options_t::ClientOnly, config_lines_eq(), or_options_t::DataDirectory, or_options_t::Logs, or_options_t::NumCpus, opt_streq(), or_options_t::ORPort, or_options_t::SafeLogging, and or_options_t::ServerDNSSearchDomains.
Referenced by options_act().
static int options_transition_allowed | ( | or_options_t * | old, | |
or_options_t * | new_val, | |||
char ** | msg | |||
) | [static] |
Check if any of the previous options have changed but aren't allowed to.
References or_options_t::AccelDir, or_options_t::AccelName, or_options_t::CellStatistics, or_options_t::DataDirectory, or_options_t::DirReqStatistics, or_options_t::DisableAllSwap, or_options_t::EntryStatistics, or_options_t::ExitPortStatistics, or_options_t::Group, or_options_t::HardwareAccel, opt_streq(), or_options_t::PidFile, or_options_t::RunAsDaemon, or_options_t::TestingTorNetwork, tor_asprintf(), and or_options_t::User.
Referenced by options_init_from_string(), and options_trial_assign().
setopt_err_t options_trial_assign | ( | config_line_t * | list, | |
int | use_defaults, | |||
int | clear_first, | |||
char ** | msg | |||
) |
Try assigning list to the global options. You do this by duping options, assigning list to the new one, then validating it. If it's ok, then throw out the old one and stick with the new one. Else, revert to old and return failure. Return SETOPT_OK on success, or a setopt_err_t on failure.
If not success, point *msg to a newly allocated string describing what went wrong.
References config_assign(), config_free(), get_options(), options_dup(), options_transition_allowed(), options_validate(), and set_options().
Referenced by control_setconf_helper().
static int options_validate | ( | or_options_t * | old_options, | |
or_options_t * | options, | |||
int | from_setconf, | |||
char ** | msg | |||
) | [static] |
Return 0 if every setting in options is reasonable, and a permissible transition from old_options. Else return -1. Should have no side effects, except for normalizing the contents of options.
On error, tor_strdup an error explanation into *msg.
XXX If from_setconf, we were called by the controller, and our Log line should stay empty. If it's 0, then give us a default log if there are no logs defined.
References or_options_t::_ExcludeExitNodesUnion, or_options_t::AccountingMax, authdir_mode(), authdir_mode_any_main(), or_options_t::AuthoritativeDir, or_options_t::BridgeAuthoritativeDir, or_options_t::ClientOnly, config_line_append(), config_lines_dup(), config_lines_eq(), or_options_t::ConnLimit, or_options_t::ContactInfo, or_options_t::ControlListenAddress, or_options_t::ControlPort, or_options_t::DirListenAddress, or_options_t::DirPort, dirserv_read_measured_bandwidths(), or_options_t::DNSListenAddress, or_options_t::DNSPort, or_options_t::DownloadExtraInfo, or_options_t::EntryNodes, or_options_t::ExcludeExitNodes, or_options_t::ExcludeNodes, or_options_t::FascistFirewall, or_options_t::FetchDirInfoEarly, or_options_t::FetchDirInfoExtraEarly, or_options_t::FirewallPorts, get_default_nickname(), get_uname(), or_options_t::HSAuthoritativeDir, is_internal_IP(), is_legal_nickname(), config_line_t::key, LD_CONFIG, or_options_t::Logs, or_options_t::LongLivedPorts, or_options_t::NatdListenAddress, or_options_t::NatdPort, config_line_t::next, or_options_t::Nickname, or_options_t::NoPublish, options_init_logs(), or_options_t::ORListenAddress, or_options_t::ORPort, parse_addr_port(), path_is_relative(), or_options_t::PublishServerDescriptor, or_options_t::ReachableAddresses, or_options_t::ReachableDirAddresses, or_options_t::ReachableORAddresses, or_options_t::RecommendedClientVersions, or_options_t::RecommendedServerVersions, or_options_t::RecommendedVersions, or_options_t::RejectPlaintextPorts, or_options_t::RendConfigLines, resolve_my_address(), routerset_is_list(), routerset_new(), routerset_union(), or_options_t::RunAsDaemon, server_mode(), smartlist_add(), smartlist_clear(), smartlist_create(), smartlist_free(), smartlist_join_strings(), or_options_t::SocksListenAddress, or_options_t::SocksPort, strcmpstart(), or_options_t::StrictNodes, or_options_t::TestingTorNetwork, tor_asprintf(), tor_assert, tor_free, tor_snprintf(), or_options_t::TransListenAddress, or_options_t::TransPort, or_options_t::UseEntryGuards, or_options_t::V1AuthoritativeDir, or_options_t::V2AuthoritativeDir, or_options_t::V3AuthoritativeDir, or_options_t::V3BandwidthsFile, validate_data_directory(), validate_ports_csv(), config_line_t::value, or_options_t::VersioningAuthoritativeDir, and or_options_t::WarnPlaintextPorts.
Referenced by options_init_from_string(), and options_trial_assign().
static void or_options_free | ( | or_options_t * | options | ) | [static] |
Release additional memory allocated in options
References or_options_t::_ExcludeExitNodesUnion, config_free(), and routerset_free().
Referenced by config_free_all().
static int or_state_load | ( | void | ) | [static] |
Reload the persistent state from disk, generating a new state as needed. Return 0 on success, less than 0 on failure.
References or_state_t::_magic, config_assign(), config_free(), config_free_lines(), config_get_lines(), config_init(), file_status(), get_datadir_fname, LD_BUG, LD_FS, LD_GENERAL, or_state_t::next_write, OR_STATE_MAGIC, or_state_save(), or_state_set(), or_state_validate(), read_file_to_str(), tor_free, and tor_snprintf().
Referenced by options_act().
int or_state_save | ( | time_t | now | ) |
Write the persistent state to disk. Return 0 for success, <0 on failure.
References accounting_is_enabled(), accounting_run_housekeeping(), circ_times, circuit_build_times_update_state(), config_dump(), entry_guards_update_state(), format_local_iso_time(), get_datadir_fname, get_options(), get_version(), or_state_t::LastWritten, LD_FS, LD_GENERAL, or_state_t::next_write, rep_hist_update_state(), tor_asprintf(), tor_assert, tor_free, or_state_t::TorVersion, and write_str_to_file().
Referenced by or_state_load(), run_scheduled_events(), and tor_cleanup().
static void or_state_set | ( | or_state_t * | new_state | ) | [static] |
Replace the current persistent state with new_state
References circ_times, circuit_build_times_parse_state(), config_free(), entry_guards_parse_state(), LD_GENERAL, rep_hist_load_state(), tor_assert, and tor_free.
Referenced by or_state_load().
static int or_state_validate | ( | or_state_t * | old_state, | |
or_state_t * | state, | |||
int | from_setconf, | |||
char ** | msg | |||
) | [static] |
Return 0 if every setting in state is reasonable, and a permissible transition from old_state. Else warn and return -1. Should have no side effects, except for normalizing the contents of state.
References entry_guards_parse_state().
Referenced by or_state_load().
static int parse_bridge_line | ( | const char * | line, | |
int | validate_only | |||
) | [static] |
Read the contents of a Bridge line from line. Return 0 if the line is well-formed, and -1 if it isn't. If validate_only is 0, and the line is well-formed, then add the bridge described in the line to our internal bridge list.
References base16_decode(), bridge_add_from_config(), DIGEST_LEN, fmt_addr(), HEX_DIGEST_LEN, LD_CONFIG, LD_DIR, smartlist_create(), smartlist_del_keeporder(), smartlist_free(), smartlist_join_strings(), smartlist_split_string(), tor_addr_port_parse(), and tor_free.
Referenced by options_act().
static int parse_dir_server_line | ( | const char * | line, | |
authority_type_t | required_type, | |||
int | validate_only | |||
) | [static] |
Read the contents of a DirServer line from line. If validate_only is 0, and the line is well-formed, and it shares any bits with required_type or required_type is 0, then add the dirserver described in the line (minus whatever bits it's missing) as a valid authority. Return 0 on success, or -1 if the line isn't well-formed or if we can't add it.
References add_trusted_dir_server(), base16_decode(), BRIDGE_AUTHORITY, DIGEST_LEN, get_torrc_fname(), HEX_DIGEST_LEN, HIDSERV_AUTHORITY, is_legal_nickname(), LD_CONFIG, LD_DIR, parse_addr_port(), smartlist_create(), smartlist_del_keeporder(), smartlist_free(), smartlist_join_strings(), smartlist_split_string(), strcasecmpstart(), tor_free, tor_parse_long(), V1_AUTHORITY, V2_AUTHORITY, and V3_AUTHORITY.
Referenced by add_default_trusted_dir_authorities(), consider_adding_dir_authorities(), and validate_dir_authorities().
static void print_usage | ( | void | ) | [static] |
Print a usage message for tor.
Referenced by options_init_from_torrc().
void remove_file_if_very_old | ( | const char * | fname, | |
time_t | now | |||
) |
Given a file name check to see whether the file exists but has not been modified for a very long time. If so, remove it.
References format_local_iso_time(), and LD_GENERAL.
Referenced by router_reload_router_list_impl(), and router_reload_v2_networkstatus().
int resolve_my_address | ( | int | warn_severity, | |
or_options_t * | options, | |||
uint32_t * | addr_out, | |||
char ** | hostname_out | |||
) |
Based on options->Address, guess our public IP address and put it (in host order) into *addr_out. If hostname_out is provided, set *hostname_out to a new string holding the hostname we used to get the address. Return 0 if all is well, or -1 if we can't find a suitable public IP address.
References or_options_t::_PublishServerDescriptor, or_options_t::Address, or_options_t::AlternateDirAuthority, control_event_server_status(), or_options_t::DirServers, get_interface_address(), INET_NTOA_BUF_LEN, ip_address_changed(), is_internal_IP(), LD_CONFIG, LD_NET, tor_assert, tor_inet_aton(), tor_inet_ntoa(), and tor_lookup_hostname().
Referenced by add_trusted_dir_server(), check_descriptor_ipaddress_changed(), dirserv_generate_networkstatus_vote_obj(), generate_v2_networkstatus_opinion(), options_validate(), router_new_address_suggestion(), and router_pick_published_address().
const char* safe_str | ( | const char * | address | ) |
Make address -- a piece of information of unspecified sensitivity -- safe to log according to the settings in options->SafeLogging, and return it.
(We return "[scrubbed]" if SafeLogging is anything besides "0", and address otherwise.)
References get_options(), and tor_assert.
Referenced by command_process_relay_cell(), connection_ap_process_end_not_open(), connection_edge_finished_connecting(), connection_exit_begin_conn(), directory_handle_command(), directory_handle_command_get(), evdns_callback(), rend_cache_lookup_v2_desc_as_dir(), rend_cache_store_v2_desc_as_dir(), rend_compute_v2_desc_id(), rend_mid_establish_intro(), and rend_mid_introduce().
const char* safe_str_client | ( | const char * | address | ) |
Make address -- a piece of information related to our operation as a client -- safe to log according to the settings in options->SafeLogging, and return it.
(We return "[scrubbed]" if SafeLogging is "1", and address otherwise.)
References get_options(), and tor_assert.
Referenced by _circuit_mark_for_close(), addressmap_register(), addressmap_register_virtual_address(), circuit_discard_optional_exit_enclaves(), circuit_get_open_circ_or_launch(), circuit_handle_first_hop(), client_dns_incr_failures(), command_process_netinfo_cell(), command_process_versions_cell(), connection_ap_expire_beginning(), connection_ap_handshake_attach_circuit(), connection_ap_handshake_rewrite_and_attach(), connection_ap_handshake_send_resolve(), connection_ap_make_link(), connection_or_check_valid_tls_handshake(), connection_tls_finish_handshake(), directory_all_unreachable(), directory_post_to_hs_dir(), dumpstats(), fetch_from_buf_socks(), handle_control_mapaddress(), rend_cache_clean_v2_descs_as_dir(), rend_cache_store(), rend_cache_store_v2_desc_as_client(), rend_cache_store_v2_desc_as_dir(), rend_client_desc_trynow(), rend_client_get_random_intro(), rend_client_refetch_v2_renddesc(), rend_compute_v2_desc_id(), rend_config_services(), and rend_service_dump_stats().
int set_options | ( | or_options_t * | new_val, | |
char ** | msg | |||
) |
Change the current global options to contain new_val instead of their current value; take action based on the new value; free the old value as necessary. Returns 0 on success, -1 on failure.
References config_free(), LD_BUG, options_act(), options_act_reversible(), and tor_assert.
Referenced by options_init_from_string(), and options_trial_assign().
static int validate_data_directory | ( | or_options_t * | options | ) | [static] |
Check and normalize the value of options->DataDirectory; return 0 if it is sane, -1 otherwise.
References or_options_t::DataDirectory, LD_CONFIG, normalize_data_directory(), and tor_assert.
Referenced by options_validate().
static int validate_dir_authorities | ( | or_options_t * | options, | |
or_options_t * | old_options | |||
) | [static] |
Look at all the config options for using alternate directory authorities, and make sure none of them are broken. Also, warn the user if we changed any dangerous ones.
References or_options_t::AlternateBridgeAuthority, or_options_t::AlternateDirAuthority, or_options_t::AlternateHSAuthority, config_lines_eq(), or_options_t::DirServers, LD_CONFIG, config_line_t::next, parse_dir_server_line(), and config_line_t::value.
static int validate_ports_csv | ( | smartlist_t * | sl, | |
const char * | name, | |||
char ** | msg | |||
) | [static] |
Return 0 if every element of sl is a string holding a decimal representation of a port number, or if sl is NULL. Otherwise set *msg and return -1.
References tor_asprintf(), and tor_assert.
Referenced by options_validate().
static int write_configuration_file | ( | const char * | fname, | |
or_options_t * | options | |||
) | [static] |
Save a configuration file for the configuration in options into the file fname. If the file already exists, and doesn't begin with GENERATED_FILE_PREFIX, rename it. Otherwise replace it. Return 0 on success, -1 on failure.
References file_status(), GENERATED_FILE_COMMENT, GENERATED_FILE_PREFIX, LD_BUG, LD_CONFIG, LD_FS, options_dump(), read_file_to_str(), strcmpstart(), tor_asprintf(), tor_assert, tor_free, tor_snprintf(), and write_str_to_file().
Referenced by options_save_current().
config_abbrev_t _option_abbrevs[] [static] |
A list of abbreviations and aliases to map command-line options, obsolete option names, or alternative option names, to their current values.
config_var_t _option_vars[] [static] |
Array of configuration options. Until we disallow nonstandard abbreviations, order is significant, since the first matching option will be chosen first.
config_abbrev_t _state_abbrevs[] [static] |
Initial value:
{ { "AccountingBytesReadInterval", "AccountingBytesReadInInterval", 0, 0 }, { "HelperNode", "EntryGuard", 0, 0 }, { "HelperNodeDownSince", "EntryGuardDownSince", 0, 0 }, { "HelperNodeUnlistedSince", "EntryGuardUnlistedSince", 0, 0 }, { "EntryNode", "EntryGuard", 0, 0 }, { "EntryNodeDownSince", "EntryGuardDownSince", 0, 0 }, { "EntryNodeUnlistedSince", "EntryGuardUnlistedSince", 0, 0 }, { NULL, NULL, 0, 0}, }
config_var_t _state_vars[] [static] |
Array of "state" variables saved to the ~/.tor/state file.
char* _version = NULL [static] |
The version of this Tor process, as parsed.
config_line_t* global_cmdline_options = NULL [static] |
Configuration Options set by command line.
char* global_dirfrontpagecontents = NULL [static] |
Contents of most recently read DirPortFrontPage file.
or_options_t* global_options = NULL [static] |
Command-line and config-file options.
or_state_t* global_state = NULL [static] |
Persistent serialized state.
uint32_t last_resolved_addr = 0 [static] |
Last value actually set by resolve_my_address.
struct unit_table_t memory_units[] [static] |
Initial value:
{ { "", 1 }, { "b", 1<< 0 }, { "byte", 1<< 0 }, { "bytes", 1<< 0 }, { "kb", 1<<10 }, { "kbyte", 1<<10 }, { "kbytes", 1<<10 }, { "kilobyte", 1<<10 }, { "kilobytes", 1<<10 }, { "m", 1<<20 }, { "mb", 1<<20 }, { "mbyte", 1<<20 }, { "mbytes", 1<<20 }, { "megabyte", 1<<20 }, { "megabytes", 1<<20 }, { "gb", 1<<30 }, { "gbyte", 1<<30 }, { "gbytes", 1<<30 }, { "gigabyte", 1<<30 }, { "gigabytes", 1<<30 }, { "tb", U64_LITERAL(1)<<40 }, { "terabyte", U64_LITERAL(1)<<40 }, { "terabytes", U64_LITERAL(1)<<40 }, { NULL, 0 }, }
config_format_t options_format [static] |
Initial value:
{ sizeof(or_options_t), OR_OPTIONS_MAGIC, STRUCT_OFFSET(or_options_t, _magic), _option_abbrevs, _option_vars, (validate_fn_t)options_validate, NULL }
config_var_t state_extra_var [static] |
Initial value:
{ "__extra", CONFIG_TYPE_LINELIST, STRUCT_OFFSET(or_state_t, ExtraLines), NULL }
config_format_t state_format [static] |
Initial value:
{ sizeof(or_state_t), OR_STATE_MAGIC, STRUCT_OFFSET(or_state_t, _magic), _state_abbrevs, _state_vars, (validate_fn_t)or_state_validate, &state_extra_var, }
config_var_t testing_tor_network_defaults[] [static] |
Initial value:
{ V(ServerDNSAllowBrokenConfig, BOOL, "1"), V(DirAllowPrivateAddresses, BOOL, "1"), V(EnforceDistinctSubnets, BOOL, "0"), V(AssumeReachable, BOOL, "1"), V(AuthDirMaxServersPerAddr, UINT, "0"), V(AuthDirMaxServersPerAuthAddr,UINT, "0"), V(ClientDNSRejectInternalAddresses, BOOL,"0"), V(ExitPolicyRejectPrivate, BOOL, "0"), V(V3AuthVotingInterval, INTERVAL, "5 minutes"), V(V3AuthVoteDelay, INTERVAL, "20 seconds"), V(V3AuthDistDelay, INTERVAL, "20 seconds"), V(TestingV3AuthInitialVotingInterval, INTERVAL, "5 minutes"), V(TestingV3AuthInitialVoteDelay, INTERVAL, "20 seconds"), V(TestingV3AuthInitialDistDelay, INTERVAL, "20 seconds"), V(TestingAuthDirTimeToLearnReachability, INTERVAL, "0 minutes"), V(TestingEstimatedDescriptorPropagationTime, INTERVAL, "0 minutes"), { NULL, CONFIG_TYPE_OBSOLETE, 0, NULL } }
struct unit_table_t time_units[] [static] |
Initial value:
{ { "", 1 }, { "second", 1 }, { "seconds", 1 }, { "minute", 60 }, { "minutes", 60 }, { "hour", 60*60 }, { "hours", 60*60 }, { "day", 24*60*60 }, { "days", 24*60*60 }, { "week", 7*24*60*60 }, { "weeks", 7*24*60*60 }, { NULL, 0 }, }
const char tor_git_revision[] |
String describing which Tor subversion repository version the source was built from. This string is generated by a bit of shell kludging int src/or/Makefile.am, and is usually right.
char* torrc_fname = NULL [static] |
Name of most recently read torrc file.