1 /* 2 * Copyright (C) 2000-2008 - Shaun Clowes <delius@progsoc.org> 3 * 2008-2011 - Robert Hogan <robert@roberthogan.net> 4 * 2013 - David Goulet <dgoulet@ev0ke.net> 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License, version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 * 15 * You should have received a copy of the GNU General Public License along with 16 * this program; if not, write to the Free Software Foundation, Inc., 51 17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 #ifndef CONFIG_FILE_H 21 #define CONFIG_FILE_H 22 23 #include <netinet/in.h> 24 25 #include "connection.h" 26 #include "socks5.h" 27 28 /* 29 * Represent the values in a configuration file (torsocks.conf). Basically, 30 * this is the data structure of a parsed config file. 31 */ 32 struct config_file { 33 /* The tor address is inet or inet 6. */ 34 enum connection_domain tor_domain; 35 /* The IP of the Tor SOCKS. */ 36 char *tor_address; 37 /* The port of the Tor SOCKS. */ 38 in_port_t tor_port; 39 40 /* 41 * Base for onion address pool and the mask. In the config file, this is 42 * represented by BASE/MASK like so: 127.0.69.0/24 43 */ 44 in_addr_t onion_base; 45 uint8_t onion_mask; 46 47 /* 48 * Username and password for Tor stream isolation for the SOCKS5 connection 49 * method. 50 */ 51 char socks5_username[SOCKS5_USERNAME_LEN]; 52 char socks5_password[SOCKS5_PASSWORD_LEN]; 53 }; 54 55 /* 56 * Structure representing a complete parsed file. 57 */ 58 struct configuration { 59 /* 60 * Parsed config file (torsocks.conf). 61 */ 62 struct config_file conf_file; 63 64 /* 65 * Socks5 address so basically where to connect to Tor. 66 */ 67 struct connection_addr socks5_addr; 68 69 /* 70 * Indicate if we should use SOCKS5 authentication. If this value is set, 71 * both the username and password in the configuration file MUST be 72 * initialized to something of len > 0. 73 */ 74 unsigned int socks5_use_auth:1; 75 76 /* 77 * Allow inbound connections meaning listen() and accept() are permitted 78 * for non localhost addresses. 79 */ 80 unsigned int allow_inbound:1; 81 82 /* 83 * Allow outbound connections to localhost that bypass Tor. 84 */ 85 unsigned int allow_outbound_localhost; 86 87 /* 88 * Automatically set the SOCKS5 authentication to a unique per-process 89 * value. If this value is set, the user MUST NOT have provided a 90 * username or password. 91 */ 92 unsigned int isolate_pid:1; 93 }; 94 95 int config_file_read(const char *filename, struct configuration *config); 96 void config_file_destroy(struct config_file *conf); 97 int conf_file_set_tor_address(const char *addr, struct configuration *config); 98 int conf_file_set_tor_port(const char *port, struct configuration *config); 99 int conf_file_set_socks5_pass(const char *password, 100 struct configuration *config); 101 int conf_file_set_socks5_user(const char *username, 102 struct configuration *config); 103 int conf_file_set_allow_inbound(const char *val, struct configuration *config); 104 int conf_file_set_allow_outbound_localhost(const char *val, struct 105 configuration *config); 106 int conf_file_set_isolate_pid(const char *val, struct configuration *config); 107 108 int conf_apply_socks_auth(struct configuration *config); 109 110 #endif /* CONFIG_FILE_H */ 111