tor  master
Data Structures | Macros | Typedefs | Enumerations | Functions
config.h File Reference

Header file for config.c. More...

#include "testsupport.h"
Include dependency graph for config.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_toption_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_tget_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_tget_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_toptions_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_tparse_bridge_line (const char *line)
 
smartlist_tget_options_from_transport_options_line (const char *line, const char *transport)
 
smartlist_tget_options_for_server_transport (const char *transport)
 
int options_any_client_port_set (const or_options_t *options)
 

Detailed Description

Header file for config.c.

Macro Definition Documentation

◆ MAX_DEFAULT_MEMORY_QUEUE_SIZE

#define MAX_DEFAULT_MEMORY_QUEUE_SIZE   (U64_LITERAL(2) << 30)

Maximum default value for MaxMemInQueues, in bytes.

◆ MIN_HEARTBEAT_PERIOD

#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.

◆ options_get_cachedir_fname2_suffix

#define options_get_cachedir_fname2_suffix (   options,
  sub1,
  sub2,
  suffix 
)
Value:
options_get_dir_fname2_suffix((options), DIRROOT_CACHEDIR, \
(sub1), (sub2), (suffix))

◆ options_get_datadir_fname2_suffix

#define options_get_datadir_fname2_suffix (   options,
  sub1,
  sub2,
  suffix 
)
Value:
options_get_dir_fname2_suffix((options), DIRROOT_DATADIR, \
(sub1), (sub2), (suffix))

◆ options_get_keydir_fname

#define options_get_keydir_fname (   options,
  sub1 
)    options_get_keydir_fname2_suffix((options), (sub1), NULL, NULL)

DOCDOC

◆ options_get_keydir_fname2_suffix

#define options_get_keydir_fname2_suffix (   options,
  sub1,
  sub2,
  suffix 
)
Value:
options_get_dir_fname2_suffix((options), DIRROOT_KEYDIR, \
(sub1), (sub2), (suffix))

Typedef Documentation

◆ bridge_line_t

typedef struct bridge_line_t bridge_line_t

Represents the information stored in a torrc Bridge line.

Function Documentation

◆ addressmap_register_auto()

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.

Here is the call graph for this function:

◆ bridge_line_free_()

void bridge_line_free_ ( bridge_line_t bridge_line)

Deallocate a bridge_line_t structure.

◆ check_or_create_data_subdir()

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.

◆ config_free_all()

void config_free_all ( void  )

Release all memory and resources held by global configuration structures.

◆ config_parse_commandline()

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.

◆ config_register_addressmaps()

void config_register_addressmaps ( const or_options_t options)

Adjust the address map based on the MapAddress elements in the configuration options

Here is the call graph for this function:

◆ create_keys_directory()

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.

◆ escaped_safe_str()

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.

Here is the call graph for this function:

◆ escaped_safe_str_client()

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.

Here is the call graph for this function:

◆ get_effective_bwburst()

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.

◆ get_effective_bwrate()

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.

◆ get_first_advertised_addr_by_type_af()

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.

◆ get_first_advertised_port_by_type_af()

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.

Here is the caller graph for this function:

◆ get_first_listener_addrport_string()

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.

◆ get_last_resolved_addr()

uint32_t get_last_resolved_addr ( void  )

Accessor for last_resolved_addr from outside this file.

Here is the caller graph for this function:

◆ get_list_of_ports_to_forward()

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.

Here is the call graph for this function:

◆ get_num_cpus()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_options_for_server_transport()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_options_from_transport_options_line()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_protocol_warning_severity_level()

int get_protocol_warning_severity_level ( void  )

Return the severity level that should be used for warnings of severity LOG_PROTOCOL_WARN.

Here is the call graph for this function:

◆ get_short_version()

const char* get_short_version ( void  )

Return the current Tor version, without any git tag.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_torrc_fname()

const char* get_torrc_fname ( int  defaults_fname)

Return the location for our configuration file. May return NULL.

◆ get_transport_bindaddr_from_config()

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.

Here is the caller graph for this function:

◆ get_version()

const char* get_version ( void  )

Return the current Tor version.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getinfo_helper_config()

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.

◆ init_cookie_authentication()

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.

◆ init_protocol_warning_severity_level()

void init_protocol_warning_severity_level ( void  )

Initialize the log warning severity level for protocol warnings. Call only once at startup.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ option_get_assignment()

config_line_t* option_get_assignment ( const or_options_t options,
const char *  key 
)

Return a canonical list of the options assigned for key.

Here is the call graph for this function:

◆ option_get_canonical_name()

const char* option_get_canonical_name ( const char *  key)

Return the canonical name of a configuration option, or NULL if no such option exists.

Here is the call graph for this function:

◆ option_is_recognized()

int option_is_recognized ( const char *  key)

Return true iff key is a valid configuration option.

Here is the call graph for this function:

◆ options_any_client_port_set()

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.

Here is the caller graph for this function:

◆ options_dump()

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.

◆ options_init()

void options_init ( or_options_t options)

Set options to hold reasonable defaults for most options. Each option defaults to zero.

Here is the call graph for this function:

◆ options_init_from_string()

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:

  • -1 for general errors.
  • -2 for failure to parse/validate,
  • -3 for transition not allowed
  • -4 for error while setting the new options

◆ 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, and 1 if we succeeded but should exit anyway.

◆ options_need_geoip_info()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ options_new()

or_options_t* options_new ( void  )

Return a new empty or_options_t. Used for testing.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ options_save_current()

int options_save_current ( void  )

Save the current configuration file value to disk. Return 0 on success, -1 on failure.

◆ options_trial_assign()

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.

Here is the call graph for this function:

◆ parse_bridge_line()

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] ...

◆ port_cfg_line_extract_addrport()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ port_exists_by_type_addr_port()

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.)

◆ reset_last_resolved_addr()

void reset_last_resolved_addr ( void  )

Reset last_resolved_addr from outside this file.

◆ resolve_my_address()

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:

  • DNS name in options->Address cannot be resolved.
  • options->Address is a local host address.
  • Attempt at getting local hostname fails.
  • Attempt at getting network interface address fails.

Return 0 if all is well, or -1 if we can't find a suitable public IP address.

If we are returning 0:

  • Put our public IP address (in host order) into *addr_out.
  • If method_out is non-NULL, set *method_out to a static string describing how we arrived at our answer.
    • "CONFIGURED" - parsed from IP address string in options->Address
    • "RESOLVED" - resolved from DNS name in options->Address
    • "GETHOSTNAME" - resolved from a local hostname.
    • "INTERFACE" - retrieved from a network interface.
  • If hostname_out is non-NULL, and we resolved a hostname to get our address, set *hostname_out to a newly allocated string holding that hostname. (If we didn't get our address by resolving a hostname, set *hostname_out to NULL.)

XXXX ipv6

Here is the caller graph for this function:

◆ safe_str()

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.)

◆ safe_str_client()

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.)

Here is the caller graph for this function:

◆ set_options()

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.

◆ write_to_data_subdir()

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.