2010-07-22 10:22:51 +02:00
|
|
|
/* Copyright (c) 2001 Matej Pfajfar.
|
|
|
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2014-10-28 20:28:14 +01:00
|
|
|
* Copyright (c) 2007-2014, The Tor Project, Inc. */
|
2010-07-22 10:22:51 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file config.h
|
|
|
|
* \brief Header file for config.c.
|
|
|
|
**/
|
|
|
|
|
2012-10-12 18:13:10 +02:00
|
|
|
#ifndef TOR_CONFIG_H
|
|
|
|
#define TOR_CONFIG_H
|
2010-07-22 10:22:51 +02:00
|
|
|
|
2014-04-15 14:20:34 +02:00
|
|
|
#include "testsupport.h"
|
|
|
|
|
2010-07-22 10:22:51 +02:00
|
|
|
const char *get_dirportfrontpage(void);
|
2014-04-15 14:20:34 +02:00
|
|
|
MOCK_DECL(const or_options_t *,get_options,(void));
|
2011-06-14 19:01:38 +02:00
|
|
|
or_options_t *get_options_mutable(void);
|
2010-07-22 10:22:51 +02:00
|
|
|
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);
|
|
|
|
const char *get_version(void);
|
2012-05-12 00:06:12 +02:00
|
|
|
const char *get_short_version(void);
|
2010-07-22 10:22:51 +02:00
|
|
|
setopt_err_t options_trial_assign(config_line_t *list, int use_defaults,
|
|
|
|
int clear_first, char **msg);
|
2012-09-12 23:34:50 +02:00
|
|
|
|
2013-02-12 10:25:42 +01:00
|
|
|
uint32_t get_last_resolved_addr(void);
|
2014-09-29 19:46:30 +02:00
|
|
|
void reset_last_resolved_addr(void);
|
2011-06-14 19:01:38 +02:00
|
|
|
int resolve_my_address(int warn_severity, const or_options_t *options,
|
2013-02-10 22:45:48 +01:00
|
|
|
uint32_t *addr_out,
|
2013-02-12 10:25:42 +01:00
|
|
|
const char **method_out, char **hostname_out);
|
2014-01-23 13:52:59 +01:00
|
|
|
MOCK_DECL(int, is_local_addr, (const tor_addr_t *addr));
|
2010-07-22 10:22:51 +02:00
|
|
|
void options_init(or_options_t *options);
|
2013-09-02 21:00:09 +02:00
|
|
|
|
|
|
|
#define OPTIONS_DUMP_MINIMAL 1
|
|
|
|
#define OPTIONS_DUMP_DEFAULTS 2
|
|
|
|
#define OPTIONS_DUMP_ALL 3
|
|
|
|
char *options_dump(const or_options_t *options, int how_to_dump);
|
2010-07-22 10:22:51 +02:00
|
|
|
int options_init_from_torrc(int argc, char **argv);
|
2011-11-28 04:25:52 +01:00
|
|
|
setopt_err_t options_init_from_string(const char *cf_defaults, const char *cf,
|
2010-07-22 10:22:51 +02:00
|
|
|
int command, const char *command_arg, char **msg);
|
|
|
|
int option_is_recognized(const char *key);
|
|
|
|
const char *option_get_canonical_name(const char *key);
|
2011-06-14 19:01:38 +02:00
|
|
|
config_line_t *option_get_assignment(const or_options_t *options,
|
2010-07-22 10:22:51 +02:00
|
|
|
const char *key);
|
|
|
|
int options_save_current(void);
|
2011-11-28 04:25:52 +01:00
|
|
|
const char *get_torrc_fname(int defaults_fname);
|
2011-06-14 19:01:38 +02:00
|
|
|
char *options_get_datadir_fname2_suffix(const or_options_t *options,
|
2010-07-22 10:22:51 +02:00
|
|
|
const char *sub1, const char *sub2,
|
|
|
|
const char *suffix);
|
|
|
|
#define get_datadir_fname2_suffix(sub1, sub2, suffix) \
|
|
|
|
options_get_datadir_fname2_suffix(get_options(), (sub1), (sub2), (suffix))
|
|
|
|
/** Return a newly allocated string containing datadir/sub1. See
|
|
|
|
* get_datadir_fname2_suffix. */
|
|
|
|
#define get_datadir_fname(sub1) get_datadir_fname2_suffix((sub1), NULL, NULL)
|
|
|
|
/** Return a newly allocated string containing datadir/sub1/sub2. See
|
|
|
|
* get_datadir_fname2_suffix. */
|
|
|
|
#define get_datadir_fname2(sub1,sub2) \
|
|
|
|
get_datadir_fname2_suffix((sub1), (sub2), NULL)
|
|
|
|
/** Return a newly allocated string containing datadir/sub1suffix. See
|
|
|
|
* get_datadir_fname2_suffix. */
|
|
|
|
#define get_datadir_fname_suffix(sub1, suffix) \
|
|
|
|
get_datadir_fname2_suffix((sub1), NULL, (suffix))
|
|
|
|
|
2013-01-25 11:49:33 +01:00
|
|
|
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);
|
|
|
|
|
2010-09-28 20:36:28 +02:00
|
|
|
int get_num_cpus(const or_options_t *options);
|
|
|
|
|
2011-11-08 22:10:38 +01:00
|
|
|
const smartlist_t *get_configured_ports(void);
|
2011-11-29 11:00:43 +01:00
|
|
|
int get_first_advertised_port_by_type_af(int listener_type,
|
|
|
|
int address_family);
|
2011-11-08 22:10:38 +01:00
|
|
|
#define get_primary_or_port() \
|
2011-11-24 17:49:31 +01:00
|
|
|
(get_first_advertised_port_by_type_af(CONN_TYPE_OR_LISTENER, AF_INET))
|
2011-11-08 22:10:38 +01:00
|
|
|
#define get_primary_dir_port() \
|
2011-11-24 17:49:31 +01:00
|
|
|
(get_first_advertised_port_by_type_af(CONN_TYPE_DIR_LISTENER, AF_INET))
|
Parse prop171 options; refactor listener/port option code
Proposal 171 gives us a new syntax for parsing client port options.
You can now have as many FooPort options as you want (for Foo in
Socks, Trans, DNS, NATD), and they can have address:port arguments,
and you can specify the level of isolation on those ports.
Additionally, this patch refactors the client port parsing logic to
use a new type, port_cfg_t. Previously, ports to be bound were
half-parsed in config.c, and later re-parsed in connection.c when
we're about to bind them. Now, parsing a port means converting it
into a port_cfg_t, and binding it uses only a port_cfg_t, without
needing to parse the user-provided strings at all.
We should do a related refactoring on other port types. For
control ports, that'll be easy enough. For ORPort and DirPort,
we'll want to do this when we solve proposal 118 (letting servers
bind to and advertise multiple ports).
This implements tickets 3514 and 3515.
2011-06-30 20:01:02 +02:00
|
|
|
|
2012-04-12 22:42:37 +02:00
|
|
|
char *get_first_listener_addrport_string(int listener_type);
|
2012-03-31 14:04:58 +02:00
|
|
|
|
2011-06-14 19:01:38 +02:00
|
|
|
int options_need_geoip_info(const or_options_t *options,
|
|
|
|
const char **reason_out);
|
2011-10-07 22:05:13 +02:00
|
|
|
|
2012-06-29 18:32:34 +02:00
|
|
|
smartlist_t *get_list_of_ports_to_forward(void);
|
|
|
|
|
2010-07-22 10:22:51 +02:00
|
|
|
int getinfo_helper_config(control_connection_t *conn,
|
|
|
|
const char *question, char **answer,
|
|
|
|
const char **errmsg);
|
|
|
|
|
|
|
|
const char *tor_get_digests(void);
|
2011-06-14 19:01:38 +02:00
|
|
|
uint32_t get_effective_bwrate(const or_options_t *options);
|
|
|
|
uint32_t get_effective_bwburst(const or_options_t *options);
|
2010-07-22 10:22:51 +02:00
|
|
|
|
2012-10-30 03:17:13 +01:00
|
|
|
char *get_transport_bindaddr_from_config(const char *transport);
|
|
|
|
|
2013-06-04 19:00:28 +02:00
|
|
|
int init_cookie_authentication(const char *fname, const char *header,
|
2014-08-15 14:30:44 +02:00
|
|
|
int cookie_len, int group_readable,
|
2013-06-04 19:00:28 +02:00
|
|
|
uint8_t **cookie_out, int *cookie_is_set_out);
|
|
|
|
|
2010-07-22 10:22:51 +02:00
|
|
|
or_options_t *options_new(void);
|
|
|
|
|
2013-08-25 18:49:16 +02:00
|
|
|
int config_parse_commandline(int argc, char **argv, int ignore_errors,
|
|
|
|
config_line_t **result,
|
|
|
|
config_line_t **cmdline_result);
|
|
|
|
|
2011-07-13 18:12:16 +02:00
|
|
|
void config_register_addressmaps(const or_options_t *options);
|
2012-08-15 23:49:18 +02:00
|
|
|
/* XXXX024 move to connection_edge.h */
|
|
|
|
int addressmap_register_auto(const char *from, const char *to,
|
|
|
|
time_t expires,
|
|
|
|
addressmap_entry_source_t addrmap_source,
|
|
|
|
const char **msg);
|
|
|
|
|
2013-02-11 14:43:20 +01:00
|
|
|
/** Represents the information stored in a torrc Bridge line. */
|
|
|
|
typedef struct bridge_line_t {
|
|
|
|
tor_addr_t addr; /* The IP address of the bridge. */
|
|
|
|
uint16_t port; /* The TCP port of the bridge. */
|
|
|
|
char *transport_name; /* The name of the pluggable transport that
|
|
|
|
should be used to connect to the bridge. */
|
|
|
|
char digest[DIGEST_LEN]; /* The bridge's identity key digest. */
|
2013-07-11 21:53:35 +02:00
|
|
|
smartlist_t *socks_args; /* SOCKS arguments for the pluggable
|
2013-02-11 14:43:20 +01:00
|
|
|
transport proxy. */
|
|
|
|
} bridge_line_t;
|
|
|
|
|
|
|
|
void bridge_line_free(bridge_line_t *bridge_line);
|
|
|
|
bridge_line_t *parse_bridge_line(const char *line);
|
2013-06-12 14:28:31 +02:00
|
|
|
smartlist_t *get_options_from_transport_options_line(const char *line,
|
|
|
|
const char *transport);
|
2013-06-12 16:12:39 +02:00
|
|
|
smartlist_t *get_options_for_server_transport(const char *transport);
|
2013-02-11 14:43:20 +01:00
|
|
|
|
2013-07-18 20:38:31 +02:00
|
|
|
#ifdef CONFIG_PRIVATE
|
|
|
|
#ifdef TOR_UNIT_TESTS
|
|
|
|
extern struct config_format_t options_format;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
STATIC void or_options_free(or_options_t *options);
|
|
|
|
STATIC int options_validate(or_options_t *old_options,
|
|
|
|
or_options_t *options,
|
|
|
|
or_options_t *default_options,
|
|
|
|
int from_setconf, char **msg);
|
2014-07-29 04:32:23 +02:00
|
|
|
STATIC int parse_transport_line(const or_options_t *options,
|
|
|
|
const char *line, int validate_only,
|
|
|
|
int server);
|
2013-07-18 20:38:31 +02:00
|
|
|
#endif
|
|
|
|
|
2010-07-22 10:22:51 +02:00
|
|
|
#endif
|
|
|
|
|