Implement Prop #260: Single Onion Services
[tor/appveyor.git] / src / or / config.h
blob208659acb71ace01dc3ab908c026e016245b6d88
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 int check_or_create_data_subdir(const char *subdir);
80 int write_to_data_subdir(const char* subdir, const char* fname,
81 const char* str, const char* descr);
83 int get_num_cpus(const or_options_t *options);
85 MOCK_DECL(const smartlist_t *,get_configured_ports,(void));
86 int get_first_advertised_port_by_type_af(int listener_type,
87 int address_family);
88 #define get_primary_or_port() \
89 (get_first_advertised_port_by_type_af(CONN_TYPE_OR_LISTENER, AF_INET))
90 #define get_primary_dir_port() \
91 (get_first_advertised_port_by_type_af(CONN_TYPE_DIR_LISTENER, AF_INET))
92 const tor_addr_t *get_first_advertised_addr_by_type_af(int listener_type,
93 int address_family);
94 int port_exists_by_type_addr_port(int listener_type, const tor_addr_t *addr,
95 int port, int check_wildcard);
96 int port_exists_by_type_addr32h_port(int listener_type, uint32_t addr_ipv4h,
97 int port, int check_wildcard);
99 char *get_first_listener_addrport_string(int listener_type);
101 int options_need_geoip_info(const or_options_t *options,
102 const char **reason_out);
104 smartlist_t *get_list_of_ports_to_forward(void);
106 int getinfo_helper_config(control_connection_t *conn,
107 const char *question, char **answer,
108 const char **errmsg);
110 uint32_t get_effective_bwrate(const or_options_t *options);
111 uint32_t get_effective_bwburst(const or_options_t *options);
113 char *get_transport_bindaddr_from_config(const char *transport);
115 int init_cookie_authentication(const char *fname, const char *header,
116 int cookie_len, int group_readable,
117 uint8_t **cookie_out, int *cookie_is_set_out);
119 or_options_t *options_new(void);
121 int config_parse_commandline(int argc, char **argv, int ignore_errors,
122 config_line_t **result,
123 config_line_t **cmdline_result);
125 void config_register_addressmaps(const or_options_t *options);
126 /* XXXX move to connection_edge.h */
127 int addressmap_register_auto(const char *from, const char *to,
128 time_t expires,
129 addressmap_entry_source_t addrmap_source,
130 const char **msg);
131 int config_parse_unix_port(const char *addrport, char **path_out);
133 /** Represents the information stored in a torrc Bridge line. */
134 typedef struct bridge_line_t {
135 tor_addr_t addr; /* The IP address of the bridge. */
136 uint16_t port; /* The TCP port of the bridge. */
137 char *transport_name; /* The name of the pluggable transport that
138 should be used to connect to the bridge. */
139 char digest[DIGEST_LEN]; /* The bridge's identity key digest. */
140 smartlist_t *socks_args; /* SOCKS arguments for the pluggable
141 transport proxy. */
142 } bridge_line_t;
144 void bridge_line_free(bridge_line_t *bridge_line);
145 bridge_line_t *parse_bridge_line(const char *line);
146 smartlist_t *get_options_from_transport_options_line(const char *line,
147 const char *transport);
148 smartlist_t *get_options_for_server_transport(const char *transport);
150 #ifdef CONFIG_PRIVATE
152 #define CL_PORT_NO_STREAM_OPTIONS (1u<<0)
153 #define CL_PORT_WARN_NONLOCAL (1u<<1)
154 #define CL_PORT_ALLOW_EXTRA_LISTENADDR (1u<<2)
155 #define CL_PORT_SERVER_OPTIONS (1u<<3)
156 #define CL_PORT_FORBID_NONLOCAL (1u<<4)
157 #define CL_PORT_TAKES_HOSTNAMES (1u<<5)
158 #define CL_PORT_IS_UNIXSOCKET (1u<<6)
159 #define CL_PORT_DFLT_GROUP_WRITABLE (1u<<7)
161 STATIC int options_act(const or_options_t *old_options);
162 #ifdef TOR_UNIT_TESTS
163 extern struct config_format_t options_format;
164 #endif
166 STATIC port_cfg_t *port_cfg_new(size_t namelen);
167 STATIC void port_cfg_free(port_cfg_t *port);
168 STATIC void or_options_free(or_options_t *options);
169 STATIC int options_validate_single_onion(or_options_t *options,
170 char **msg);
171 STATIC int options_validate(or_options_t *old_options,
172 or_options_t *options,
173 or_options_t *default_options,
174 int from_setconf, char **msg);
175 STATIC int parse_transport_line(const or_options_t *options,
176 const char *line, int validate_only,
177 int server);
178 STATIC int consider_adding_dir_servers(const or_options_t *options,
179 const or_options_t *old_options);
180 STATIC void add_default_trusted_dir_authorities(dirinfo_type_t type);
181 MOCK_DECL(STATIC void, add_default_fallback_dir_servers, (void));
182 STATIC int parse_dir_authority_line(const char *line,
183 dirinfo_type_t required_type,
184 int validate_only);
185 STATIC int parse_dir_fallback_line(const char *line, int validate_only);
186 STATIC int have_enough_mem_for_dircache(const or_options_t *options,
187 size_t total_mem, char **msg);
188 STATIC int parse_port_config(smartlist_t *out,
189 const config_line_t *ports,
190 const config_line_t *listenaddrs,
191 const char *portname,
192 int listener_type,
193 const char *defaultaddr,
194 int defaultport,
195 const unsigned flags);
196 #endif
198 #endif