Remove duplicate code that checks for default authorities
[tor.git] / src / or / config.h
blob1b40efc5ecb556e563b46a27e3a23f9092964b3c
1 /* Copyright (c) 2001 Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2016, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 /**
8 * \file config.h
9 * \brief Header file for config.c.
10 **/
12 #ifndef TOR_CONFIG_H
13 #define TOR_CONFIG_H
15 #include "testsupport.h"
17 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(DARWIN)
18 #define KERNEL_MAY_SUPPORT_IPFW
19 #endif
21 MOCK_DECL(const char*, get_dirportfrontpage, (void));
22 MOCK_DECL(const or_options_t *, get_options, (void));
23 MOCK_DECL(or_options_t *, get_options_mutable, (void));
24 int set_options(or_options_t *new_val, char **msg);
25 void config_free_all(void);
26 const char *safe_str_client(const char *address);
27 const char *safe_str(const char *address);
28 const char *escaped_safe_str_client(const char *address);
29 const char *escaped_safe_str(const char *address);
30 const char *get_version(void);
31 const char *get_short_version(void);
32 setopt_err_t options_trial_assign(config_line_t *list, unsigned flags,
33 char **msg);
35 uint32_t get_last_resolved_addr(void);
36 void reset_last_resolved_addr(void);
37 int resolve_my_address(int warn_severity, const or_options_t *options,
38 uint32_t *addr_out,
39 const char **method_out, char **hostname_out);
40 MOCK_DECL(int, is_local_addr, (const tor_addr_t *addr));
41 void options_init(or_options_t *options);
43 #define OPTIONS_DUMP_MINIMAL 1
44 #define OPTIONS_DUMP_DEFAULTS 2
45 #define OPTIONS_DUMP_ALL 3
46 char *options_dump(const or_options_t *options, int how_to_dump);
47 int options_init_from_torrc(int argc, char **argv);
48 setopt_err_t options_init_from_string(const char *cf_defaults, const char *cf,
49 int command, const char *command_arg, char **msg);
50 int option_is_recognized(const char *key);
51 const char *option_get_canonical_name(const char *key);
52 config_line_t *option_get_assignment(const or_options_t *options,
53 const char *key);
54 int options_save_current(void);
55 const char *get_torrc_fname(int defaults_fname);
56 MOCK_DECL(char *,
57 options_get_datadir_fname2_suffix,
58 (const or_options_t *options,
59 const char *sub1, const char *sub2,
60 const char *suffix));
61 #define get_datadir_fname2_suffix(sub1, sub2, suffix) \
62 options_get_datadir_fname2_suffix(get_options(), (sub1), (sub2), (suffix))
63 /** Return a newly allocated string containing datadir/sub1. See
64 * get_datadir_fname2_suffix. */
65 #define get_datadir_fname(sub1) get_datadir_fname2_suffix((sub1), NULL, NULL)
66 /** Return a newly allocated string containing datadir/sub1/sub2. See
67 * get_datadir_fname2_suffix. */
68 #define get_datadir_fname2(sub1,sub2) \
69 get_datadir_fname2_suffix((sub1), (sub2), NULL)
70 /** Return a newly allocated string containing datadir/sub1/sub2 relative to
71 * opts. See get_datadir_fname2_suffix. */
72 #define options_get_datadir_fname2(opts,sub1,sub2) \
73 options_get_datadir_fname2_suffix((opts),(sub1), (sub2), NULL)
74 /** Return a newly allocated string containing datadir/sub1suffix. See
75 * get_datadir_fname2_suffix. */
76 #define get_datadir_fname_suffix(sub1, suffix) \
77 get_datadir_fname2_suffix((sub1), NULL, (suffix))
79 inline int is_default_dir_authorities(const or_options_t *options);
81 int check_or_create_data_subdir(const char *subdir);
82 int write_to_data_subdir(const char* subdir, const char* fname,
83 const char* str, const char* descr);
85 int get_num_cpus(const or_options_t *options);
87 MOCK_DECL(const smartlist_t *,get_configured_ports,(void));
88 int get_first_advertised_port_by_type_af(int listener_type,
89 int address_family);
90 #define get_primary_or_port() \
91 (get_first_advertised_port_by_type_af(CONN_TYPE_OR_LISTENER, AF_INET))
92 #define get_primary_dir_port() \
93 (get_first_advertised_port_by_type_af(CONN_TYPE_DIR_LISTENER, AF_INET))
94 const tor_addr_t *get_first_advertised_addr_by_type_af(int listener_type,
95 int address_family);
96 int port_exists_by_type_addr_port(int listener_type, const tor_addr_t *addr,
97 int port, int check_wildcard);
98 int port_exists_by_type_addr32h_port(int listener_type, uint32_t addr_ipv4h,
99 int port, int check_wildcard);
101 char *get_first_listener_addrport_string(int listener_type);
103 int options_need_geoip_info(const or_options_t *options,
104 const char **reason_out);
106 smartlist_t *get_list_of_ports_to_forward(void);
108 int getinfo_helper_config(control_connection_t *conn,
109 const char *question, char **answer,
110 const char **errmsg);
112 uint32_t get_effective_bwrate(const or_options_t *options);
113 uint32_t get_effective_bwburst(const or_options_t *options);
115 char *get_transport_bindaddr_from_config(const char *transport);
117 int init_cookie_authentication(const char *fname, const char *header,
118 int cookie_len, int group_readable,
119 uint8_t **cookie_out, int *cookie_is_set_out);
121 or_options_t *options_new(void);
123 int config_parse_commandline(int argc, char **argv, int ignore_errors,
124 config_line_t **result,
125 config_line_t **cmdline_result);
127 void config_register_addressmaps(const or_options_t *options);
128 /* XXXX move to connection_edge.h */
129 int addressmap_register_auto(const char *from, const char *to,
130 time_t expires,
131 addressmap_entry_source_t addrmap_source,
132 const char **msg);
133 int config_parse_unix_port(const char *addrport, char **path_out);
135 /** Represents the information stored in a torrc Bridge line. */
136 typedef struct bridge_line_t {
137 tor_addr_t addr; /* The IP address of the bridge. */
138 uint16_t port; /* The TCP port of the bridge. */
139 char *transport_name; /* The name of the pluggable transport that
140 should be used to connect to the bridge. */
141 char digest[DIGEST_LEN]; /* The bridge's identity key digest. */
142 smartlist_t *socks_args; /* SOCKS arguments for the pluggable
143 transport proxy. */
144 } bridge_line_t;
146 void bridge_line_free(bridge_line_t *bridge_line);
147 bridge_line_t *parse_bridge_line(const char *line);
148 smartlist_t *get_options_from_transport_options_line(const char *line,
149 const char *transport);
150 smartlist_t *get_options_for_server_transport(const char *transport);
152 /* Check if we are using default authorities */
153 inline int
154 is_default_dir_authorities(const or_options_t *options)
156 return (!options->DirAuthorities &&
157 !options->AlternateDirAuthority) ? 1 : 0;
160 #ifdef CONFIG_PRIVATE
162 #define CL_PORT_NO_STREAM_OPTIONS (1u<<0)
163 #define CL_PORT_WARN_NONLOCAL (1u<<1)
164 #define CL_PORT_ALLOW_EXTRA_LISTENADDR (1u<<2)
165 #define CL_PORT_SERVER_OPTIONS (1u<<3)
166 #define CL_PORT_FORBID_NONLOCAL (1u<<4)
167 #define CL_PORT_TAKES_HOSTNAMES (1u<<5)
168 #define CL_PORT_IS_UNIXSOCKET (1u<<6)
169 #define CL_PORT_DFLT_GROUP_WRITABLE (1u<<7)
171 STATIC int options_act(const or_options_t *old_options);
172 #ifdef TOR_UNIT_TESTS
173 extern struct config_format_t options_format;
174 #endif
176 STATIC port_cfg_t *port_cfg_new(size_t namelen);
177 STATIC void port_cfg_free(port_cfg_t *port);
178 STATIC void or_options_free(or_options_t *options);
179 STATIC int options_validate_single_onion(or_options_t *options,
180 char **msg);
181 STATIC int options_validate(or_options_t *old_options,
182 or_options_t *options,
183 or_options_t *default_options,
184 int from_setconf, char **msg);
185 STATIC int parse_transport_line(const or_options_t *options,
186 const char *line, int validate_only,
187 int server);
188 STATIC int consider_adding_dir_servers(const or_options_t *options,
189 const or_options_t *old_options);
190 STATIC void add_default_trusted_dir_authorities(dirinfo_type_t type);
191 MOCK_DECL(STATIC void, add_default_fallback_dir_servers, (void));
192 STATIC int parse_dir_authority_line(const char *line,
193 dirinfo_type_t required_type,
194 int validate_only);
195 STATIC int parse_dir_fallback_line(const char *line, int validate_only);
196 STATIC int have_enough_mem_for_dircache(const or_options_t *options,
197 size_t total_mem, char **msg);
198 STATIC int parse_port_config(smartlist_t *out,
199 const config_line_t *ports,
200 const config_line_t *listenaddrs,
201 const char *portname,
202 int listener_type,
203 const char *defaultaddr,
204 int defaultport,
205 const unsigned flags);
206 #endif
208 #endif