tor
master
|
Header file for config.c. More...
#include "testsupport.h"
Go to the source code of this file.
Data Structures | |
struct | bridge_line_t |
Macros | |
#define | MIN_HEARTBEAT_PERIOD (30*60) |
#define | MAX_DEFAULT_MEMORY_QUEUE_SIZE (U64_LITERAL(2) << 30) |
#define | OPTIONS_DUMP_MINIMAL 1 |
#define | OPTIONS_DUMP_DEFAULTS 2 |
#define | OPTIONS_DUMP_ALL 3 |
#define | options_get_datadir_fname2_suffix(options, sub1, sub2, suffix) |
#define | options_get_cachedir_fname2_suffix(options, sub1, sub2, suffix) |
#define | options_get_keydir_fname2_suffix(options, sub1, sub2, suffix) |
#define | options_get_datadir_fname(opts, sub1) options_get_datadir_fname2_suffix((opts),(sub1), NULL, NULL) |
#define | options_get_datadir_fname2(opts, sub1, sub2) options_get_datadir_fname2_suffix((opts),(sub1), (sub2), NULL) |
#define | get_datadir_fname2_suffix(sub1, sub2, suffix) options_get_datadir_fname2_suffix(get_options(), (sub1), (sub2), (suffix)) |
#define | get_datadir_fname(sub1) get_datadir_fname2_suffix((sub1), NULL, NULL) |
#define | get_datadir_fname2(sub1, sub2) get_datadir_fname2_suffix((sub1), (sub2), NULL) |
#define | get_datadir_fname_suffix(sub1, suffix) get_datadir_fname2_suffix((sub1), NULL, (suffix)) |
#define | options_get_keydir_fname(options, sub1) options_get_keydir_fname2_suffix((options), (sub1), NULL, NULL) |
#define | get_keydir_fname_suffix(sub1, suffix) options_get_keydir_fname2_suffix(get_options(), (sub1), NULL, suffix) |
#define | get_keydir_fname(sub1) options_get_keydir_fname2_suffix(get_options(), (sub1), NULL, NULL) |
#define | get_cachedir_fname(sub1) options_get_cachedir_fname2_suffix(get_options(), (sub1), NULL, NULL) |
#define | get_cachedir_fname_suffix(sub1, suffix) options_get_cachedir_fname2_suffix(get_options(), (sub1), NULL, (suffix)) |
#define | get_primary_or_port() (get_first_advertised_port_by_type_af(CONN_TYPE_OR_LISTENER, AF_INET)) |
#define | get_primary_dir_port() (get_first_advertised_port_by_type_af(CONN_TYPE_DIR_LISTENER, AF_INET)) |
#define | bridge_line_free(line) FREE_AND_NULL(bridge_line_t, bridge_line_free_, (line)) |
Typedefs | |
typedef struct bridge_line_t | bridge_line_t |
Enumerations | |
enum | directory_root_t { DIRROOT_DATADIR, DIRROOT_CACHEDIR, DIRROOT_KEYDIR } |
Functions | |
MOCK_DECL (const char *, get_dirportfrontpage,(void)) | |
MOCK_DECL (const or_options_t *, get_options,(void)) | |
MOCK_DECL (or_options_t *, get_options_mutable,(void)) | |
int | set_options (or_options_t *new_val, char **msg) |
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) |
void | init_protocol_warning_severity_level (void) |
int | get_protocol_warning_severity_level (void) |
const char * | get_version (void) |
const char * | get_short_version (void) |
setopt_err_t | options_trial_assign (config_line_t *list, unsigned flags, char **msg) |
uint32_t | get_last_resolved_addr (void) |
void | reset_last_resolved_addr (void) |
int | resolve_my_address (int warn_severity, const or_options_t *options, uint32_t *addr_out, const char **method_out, char **hostname_out) |
MOCK_DECL (int, is_local_addr,(const tor_addr_t *addr)) | |
void | options_init (or_options_t *options) |
char * | options_dump (const or_options_t *options, int how_to_dump) |
int | options_init_from_torrc (int argc, char **argv) |
setopt_err_t | options_init_from_string (const char *cf_defaults, const char *cf, int command, const char *command_arg, char **msg) |
int | option_is_recognized (const char *key) |
const char * | option_get_canonical_name (const char *key) |
config_line_t * | option_get_assignment (const or_options_t *options, const char *key) |
int | options_save_current (void) |
const char * | get_torrc_fname (int defaults_fname) |
MOCK_DECL (char *, options_get_dir_fname2_suffix,(const or_options_t *options, directory_root_t roottype, const char *sub1, const char *sub2, const char *suffix)) | |
int | using_default_dir_authorities (const or_options_t *options) |
int | create_keys_directory (const or_options_t *options) |
int | check_or_create_data_subdir (const char *subdir) |
int | write_to_data_subdir (const char *subdir, const char *fname, const char *str, const char *descr) |
int | get_num_cpus (const or_options_t *options) |
MOCK_DECL (const smartlist_t *, get_configured_ports,(void)) | |
int | get_first_advertised_port_by_type_af (int listener_type, int address_family) |
const tor_addr_t * | get_first_advertised_addr_by_type_af (int listener_type, int address_family) |
int | port_exists_by_type_addr_port (int listener_type, const tor_addr_t *addr, int port, int check_wildcard) |
int | port_exists_by_type_addr32h_port (int listener_type, uint32_t addr_ipv4h, int port, int check_wildcard) |
char * | get_first_listener_addrport_string (int listener_type) |
int | options_need_geoip_info (const or_options_t *options, const char **reason_out) |
smartlist_t * | get_list_of_ports_to_forward (void) |
int | getinfo_helper_config (control_connection_t *conn, const char *question, char **answer, const char **errmsg) |
uint32_t | get_effective_bwrate (const or_options_t *options) |
uint32_t | get_effective_bwburst (const or_options_t *options) |
char * | get_transport_bindaddr_from_config (const char *transport) |
int | init_cookie_authentication (const char *fname, const char *header, int cookie_len, int group_readable, uint8_t **cookie_out, int *cookie_is_set_out) |
or_options_t * | options_new (void) |
int | config_parse_commandline (int argc, char **argv, int ignore_errors, config_line_t **result, config_line_t **cmdline_result) |
void | config_register_addressmaps (const or_options_t *options) |
int | addressmap_register_auto (const char *from, const char *to, time_t expires, addressmap_entry_source_t addrmap_source, const char **msg) |
int | port_cfg_line_extract_addrport (const char *line, char **addrport_out, int *is_unix_out, const char **rest_out) |
void | bridge_line_free_ (bridge_line_t *bridge_line) |
bridge_line_t * | parse_bridge_line (const char *line) |
smartlist_t * | get_options_from_transport_options_line (const char *line, const char *transport) |
smartlist_t * | get_options_for_server_transport (const char *transport) |
int | options_any_client_port_set (const or_options_t *options) |
Header file for config.c.
#define MAX_DEFAULT_MEMORY_QUEUE_SIZE (U64_LITERAL(2) << 30) |
Maximum default value for MaxMemInQueues, in bytes.
#define MIN_HEARTBEAT_PERIOD (30*60) |
Lowest allowable value for HeartbeatPeriod; if this is too low, we might expose more information than we're comfortable with.
#define options_get_cachedir_fname2_suffix | ( | options, | |
sub1, | |||
sub2, | |||
suffix | |||
) |
#define options_get_datadir_fname2_suffix | ( | options, | |
sub1, | |||
sub2, | |||
suffix | |||
) |
#define options_get_keydir_fname | ( | options, | |
sub1 | |||
) | options_get_keydir_fname2_suffix((options), (sub1), NULL, NULL) |
DOCDOC
#define options_get_keydir_fname2_suffix | ( | options, | |
sub1, | |||
sub2, | |||
suffix | |||
) |
typedef struct bridge_line_t bridge_line_t |
Represents the information stored in a torrc Bridge line.
int addressmap_register_auto | ( | const char * | from, |
const char * | to, | ||
time_t | expires, | ||
addressmap_entry_source_t | addrmap_source, | ||
const char ** | msg | ||
) |
As addressmap_register(), but detect the wildcarded status of "from" and "to", and do not steal a reference to to.
void bridge_line_free_ | ( | bridge_line_t * | bridge_line | ) |
Deallocate a bridge_line_t structure.
int check_or_create_data_subdir | ( | const char * | subdir | ) |
Check wether the data directory has a private subdirectory subdir. If not, try to create it. Return 0 on success, -1 otherwise.
void config_free_all | ( | void | ) |
Release all memory and resources held by global configuration structures.
int config_parse_commandline | ( | int | argc, |
char ** | argv, | ||
int | ignore_errors, | ||
config_line_t ** | result, | ||
config_line_t ** | cmdline_result | ||
) |
Helper: Read a list of configuration options from the command line. If successful, or if ignore_errors is set, put them in *result, put the commandline-only options in *cmdline_result, and return 0; otherwise, return -1 and leave *result and cmdline_result alone.
void config_register_addressmaps | ( | const or_options_t * | options | ) |
Adjust the address map based on the MapAddress elements in the configuration options
int create_keys_directory | ( | const or_options_t * | options | ) |
Ensure that our keys directory exists, with appropriate permissions. Return 0 on success, -1 on failure.
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.
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.
uint32_t get_effective_bwburst | ( | const or_options_t * | options | ) |
Return the bandwidthburst that we are going to report to the authorities based on the config options.
uint32_t get_effective_bwrate | ( | const or_options_t * | options | ) |
Return the bandwidthrate that we are going to report to the authorities based on the config options.
const tor_addr_t* get_first_advertised_addr_by_type_af | ( | int | listener_type, |
int | address_family | ||
) |
Return the first advertised address of type listener_type in address_family. Returns NULL if there is no advertised address, and when passed AF_UNSPEC.
int get_first_advertised_port_by_type_af | ( | int | listener_type, |
int | address_family | ||
) |
Return the first advertised port of type listener_type in address_family. Returns 0 when no port is found, and when passed AF_UNSPEC.
char* get_first_listener_addrport_string | ( | int | listener_type | ) |
Return an address:port string representation of the address where the first listener_type listener waits for connections. Return NULL if we couldn't find a listener. The string is allocated on the heap and it's the responsibility of the caller to free it after use.
This function is meant to be used by the pluggable transport proxy spawning code, please make sure that it fits your purposes before using it.
uint32_t get_last_resolved_addr | ( | void | ) |
Accessor for last_resolved_addr from outside this file.
smartlist_t* get_list_of_ports_to_forward | ( | void | ) |
Return a smartlist of ports that must be forwarded by tor-fw-helper. The smartlist contains the ports in a string format that is understandable by tor-fw-helper.
XXX TODO tor-fw-helper does not support forwarding ports to other hosts than the local one. If the user is binding to a different IP address, tor-fw-helper won't work.
int get_num_cpus | ( | const or_options_t * | options | ) |
Return the number of cpus configured in options. If we are told to auto-detect the number of cpus, return the auto-detected number.
smartlist_t* get_options_for_server_transport | ( | const char * | transport | ) |
Given the name of a pluggable transport in transport, check the configuration file to see if the user has asked us to pass any parameters to the pluggable transport. Return a smartlist containing the parameters, otherwise NULL.
smartlist_t* get_options_from_transport_options_line | ( | const char * | line, |
const char * | transport | ||
) |
Given a ServerTransportOptions line, return a smartlist with the options. Return NULL if the line was not well-formed.
If transport is set, return NULL if the line is not referring to transport.
The returned smartlist and its strings are allocated on the heap and it's the responsibility of the caller to free it.
int get_protocol_warning_severity_level | ( | void | ) |
Return the severity level that should be used for warnings of severity LOG_PROTOCOL_WARN.
const char* get_short_version | ( | void | ) |
Return the current Tor version, without any git tag.
const char* get_torrc_fname | ( | int | defaults_fname | ) |
Return the location for our configuration file. May return NULL.
char* get_transport_bindaddr_from_config | ( | const char * | transport | ) |
Given the name of a pluggable transport in transport, check the configuration file to see if the user has explicitly asked for it to listen on a specific port. Return a <address:port> string if so, otherwise NULL.
const char* get_version | ( | void | ) |
Return the current Tor version.
int getinfo_helper_config | ( | control_connection_t * | conn, |
const char * | question, | ||
char ** | answer, | ||
const char ** | errmsg | ||
) |
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.
int init_cookie_authentication | ( | const char * | fname, |
const char * | header, | ||
int | cookie_len, | ||
int | group_readable, | ||
uint8_t ** | cookie_out, | ||
int * | cookie_is_set_out | ||
) |
Initialize cookie authentication (used so far by the ControlPort and Extended ORPort).
Allocate memory and create a cookie (of length cookie_len) in cookie_out. Then write it down to fname and prepend it with header.
If group_readable is set, set fname to be readable by the default GID.
If the whole procedure was successful, set cookie_is_set_out to True.
void init_protocol_warning_severity_level | ( | void | ) |
Initialize the log warning severity level for protocol warnings. Call only once at startup.
config_line_t* option_get_assignment | ( | const or_options_t * | options, |
const char * | key | ||
) |
Return a canonical list of the options assigned for key.
const char* option_get_canonical_name | ( | const char * | key | ) |
Return the canonical name of a configuration option, or NULL if no such option exists.
int option_is_recognized | ( | const char * | key | ) |
Return true iff key is a valid configuration option.
int options_any_client_port_set | ( | const or_options_t * | options | ) |
Return true if any option is set in options to make us behave as a client.
char* options_dump | ( | const or_options_t * | options, |
int | how_to_dump | ||
) |
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.
void options_init | ( | or_options_t * | options | ) |
Set options to hold reasonable defaults for most options. Each option defaults to zero.
setopt_err_t options_init_from_string | ( | const char * | cf_defaults, |
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:
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, and 1 if we succeeded but should exit anyway.
int options_need_geoip_info | ( | const 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.
or_options_t* options_new | ( | void | ) |
Return a new empty or_options_t. Used for testing.
int options_save_current | ( | void | ) |
Save the current configuration file value to disk. Return 0 on success, -1 on failure.
setopt_err_t options_trial_assign | ( | config_line_t * | list, |
unsigned | flags, | ||
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.
bridge_line_t* parse_bridge_line | ( | const char * | line | ) |
Parse the contents of a string, line, containing a Bridge line, into a bridge_line_t.
Validates that the IP:PORT, fingerprint, and SOCKS arguments (given to the Pluggable Transport, if a one was specified) are well-formed.
Returns NULL If the Bridge line could not be validated, and returns a bridge_line_t containing the parsed information otherwise.
Bridge line format: Bridge [transport] IP:PORT [id-fingerprint] [k=v] [k=v] ...
int port_cfg_line_extract_addrport | ( | const char * | line, |
char ** | addrport_out, | ||
int * | is_unix_out, | ||
const char ** | rest_out | ||
) |
Take a string (line) that begins with either an address:port, a port, or an AF_UNIX address, optionally quoted, prefixed with "unix:". Parse that line, and on success, set addrport_out to a new string containing the beginning portion (without prefix). Iff there was a unix: prefix, set is_unix_out to true. On success, also set rest_out to point to the part of the line after the address portion.
Return 0 on success, -1 on failure.
int port_exists_by_type_addr_port | ( | int | listener_type, |
const tor_addr_t * | addr, | ||
int | port, | ||
int | check_wildcard | ||
) |
Return 1 if a port exists of type listener_type on addr and port. If check_wildcard is true, INADDR[6]_ANY and AF_UNSPEC addresses match any address of the appropriate family; and port -1 matches any port. To match auto ports, pass CFG_PORT_AUTO. (Does not match on the actual automatically chosen listener ports.)
void reset_last_resolved_addr | ( | void | ) |
Reset last_resolved_addr from outside this file.
int resolve_my_address | ( | int | warn_severity, |
const or_options_t * | options, | ||
uint32_t * | addr_out, | ||
const char ** | method_out, | ||
char ** | hostname_out | ||
) |
Attempt getting our non-local (as judged by tor_addr_is_internal() function) IP address using following techniques, listed in order from best (most desirable, try first) to worst (least desirable, try if everything else fails).
First, attempt using options->Address to get our non-local IP address.
If options->Address represents a non-local IP address, consider it ours.
If options->Address is a DNS name that resolves to a non-local IP address, consider this IP address ours.
If options->Address is NULL, fall back to getting local hostname and using it in above-described ways to try and get our IP address.
In case local hostname cannot be resolved to a non-local IP address, try getting an IP address of network interface in hopes it will be non-local one.
Fail if one or more of the following is true:
Return 0 if all is well, or -1 if we can't find a suitable public IP address.
If we are returning 0:
XXXX ipv6
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.)
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.)
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.
int write_to_data_subdir | ( | const char * | subdir, |
const char * | fname, | ||
const char * | str, | ||
const char * | descr | ||
) |
Create a file named fname with contents str in the subdirectory subdir of the data directory. descr should be a short description of the file's content and will be used for the warning message, if it's present and the write process fails. Return 0 on success, -1 otherwise.