diff options
Diffstat (limited to 'other/bootstrap_daemon/src/config.c')
-rw-r--r-- | other/bootstrap_daemon/src/config.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c index 861a3803..12ae693d 100644 --- a/other/bootstrap_daemon/src/config.c +++ b/other/bootstrap_daemon/src/config.c | |||
@@ -72,7 +72,7 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int | |||
72 | if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT | 72 | if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT |
73 | || (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) { | 73 | || (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) { |
74 | write_log(LOG_LEVEL_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, | 74 | write_log(LOG_LEVEL_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, |
75 | (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); | 75 | (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); |
76 | continue; | 76 | continue; |
77 | } | 77 | } |
78 | 78 | ||
@@ -92,7 +92,7 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int | |||
92 | 92 | ||
93 | if (config_setting_is_array(ports_array) == CONFIG_FALSE) { | 93 | if (config_setting_is_array(ports_array) == CONFIG_FALSE) { |
94 | write_log(LOG_LEVEL_ERROR, "'%s' setting should be an array. Array syntax: 'setting = [value1, value2, ...]'.\n", | 94 | write_log(LOG_LEVEL_ERROR, "'%s' setting should be an array. Array syntax: 'setting = [value1, value2, ...]'.\n", |
95 | NAME_TCP_RELAY_PORTS); | 95 | NAME_TCP_RELAY_PORTS); |
96 | return; | 96 | return; |
97 | } | 97 | } |
98 | 98 | ||
@@ -126,7 +126,7 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int | |||
126 | if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT | 126 | if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT |
127 | || (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) { | 127 | || (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) { |
128 | write_log(LOG_LEVEL_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, | 128 | write_log(LOG_LEVEL_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, |
129 | (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); | 129 | (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); |
130 | continue; | 130 | continue; |
131 | } | 131 | } |
132 | 132 | ||
@@ -142,7 +142,8 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int | |||
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | ||
145 | int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6, | 145 | int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, |
146 | int *enable_ipv6, | ||
146 | int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay, uint16_t **tcp_relay_ports, | 147 | int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay, uint16_t **tcp_relay_ports, |
147 | int *tcp_relay_port_count, int *enable_motd, char **motd) | 148 | int *tcp_relay_port_count, int *enable_motd, char **motd) |
148 | { | 149 | { |
@@ -209,7 +210,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
209 | if (config_lookup_bool(&cfg, NAME_ENABLE_IPV4_FALLBACK, enable_ipv4_fallback) == CONFIG_FALSE) { | 210 | if (config_lookup_bool(&cfg, NAME_ENABLE_IPV4_FALLBACK, enable_ipv4_fallback) == CONFIG_FALSE) { |
210 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_IPV4_FALLBACK); | 211 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_IPV4_FALLBACK); |
211 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, | 212 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, |
212 | DEFAULT_ENABLE_IPV4_FALLBACK ? "true" : "false"); | 213 | DEFAULT_ENABLE_IPV4_FALLBACK ? "true" : "false"); |
213 | *enable_ipv4_fallback = DEFAULT_ENABLE_IPV4_FALLBACK; | 214 | *enable_ipv4_fallback = DEFAULT_ENABLE_IPV4_FALLBACK; |
214 | } | 215 | } |
215 | 216 | ||
@@ -217,7 +218,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
217 | if (config_lookup_bool(&cfg, NAME_ENABLE_LAN_DISCOVERY, enable_lan_discovery) == CONFIG_FALSE) { | 218 | if (config_lookup_bool(&cfg, NAME_ENABLE_LAN_DISCOVERY, enable_lan_discovery) == CONFIG_FALSE) { |
218 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_LAN_DISCOVERY); | 219 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_LAN_DISCOVERY); |
219 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, | 220 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, |
220 | DEFAULT_ENABLE_LAN_DISCOVERY ? "true" : "false"); | 221 | DEFAULT_ENABLE_LAN_DISCOVERY ? "true" : "false"); |
221 | *enable_lan_discovery = DEFAULT_ENABLE_LAN_DISCOVERY; | 222 | *enable_lan_discovery = DEFAULT_ENABLE_LAN_DISCOVERY; |
222 | } | 223 | } |
223 | 224 | ||
@@ -225,7 +226,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
225 | if (config_lookup_bool(&cfg, NAME_ENABLE_TCP_RELAY, enable_tcp_relay) == CONFIG_FALSE) { | 226 | if (config_lookup_bool(&cfg, NAME_ENABLE_TCP_RELAY, enable_tcp_relay) == CONFIG_FALSE) { |
226 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_TCP_RELAY); | 227 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_TCP_RELAY); |
227 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_ENABLE_TCP_RELAY, | 228 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_ENABLE_TCP_RELAY, |
228 | DEFAULT_ENABLE_TCP_RELAY ? "true" : "false"); | 229 | DEFAULT_ENABLE_TCP_RELAY ? "true" : "false"); |
229 | *enable_tcp_relay = DEFAULT_ENABLE_TCP_RELAY; | 230 | *enable_tcp_relay = DEFAULT_ENABLE_TCP_RELAY; |
230 | } | 231 | } |
231 | 232 | ||
@@ -239,7 +240,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
239 | if (config_lookup_bool(&cfg, NAME_ENABLE_MOTD, enable_motd) == CONFIG_FALSE) { | 240 | if (config_lookup_bool(&cfg, NAME_ENABLE_MOTD, enable_motd) == CONFIG_FALSE) { |
240 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_MOTD); | 241 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_MOTD); |
241 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_ENABLE_MOTD, | 242 | write_log(LOG_LEVEL_WARNING, "Using default '%s': %s\n", NAME_ENABLE_MOTD, |
242 | DEFAULT_ENABLE_MOTD ? "true" : "false"); | 243 | DEFAULT_ENABLE_MOTD ? "true" : "false"); |
243 | *enable_motd = DEFAULT_ENABLE_MOTD; | 244 | *enable_motd = DEFAULT_ENABLE_MOTD; |
244 | } | 245 | } |
245 | 246 | ||
@@ -315,6 +316,7 @@ uint8_t *hex_string_to_bin(char *hex_string) | |||
315 | 316 | ||
316 | char *pos = hex_string; | 317 | char *pos = hex_string; |
317 | size_t i; | 318 | size_t i; |
319 | |||
318 | for (i = 0; i < len; ++i, pos += 2) { | 320 | for (i = 0; i < len; ++i, pos += 2) { |
319 | sscanf(pos, "%2hhx", &ret[i]); | 321 | sscanf(pos, "%2hhx", &ret[i]); |
320 | } | 322 | } |
@@ -343,7 +345,8 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
343 | config_setting_t *node_list = config_lookup(&cfg, NAME_BOOTSTRAP_NODES); | 345 | config_setting_t *node_list = config_lookup(&cfg, NAME_BOOTSTRAP_NODES); |
344 | 346 | ||
345 | if (node_list == NULL) { | 347 | if (node_list == NULL) { |
346 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n", NAME_BOOTSTRAP_NODES); | 348 | write_log(LOG_LEVEL_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n", |
349 | NAME_BOOTSTRAP_NODES); | ||
347 | config_destroy(&cfg); | 350 | config_destroy(&cfg); |
348 | return 1; | 351 | return 1; |
349 | } | 352 | } |
@@ -373,7 +376,8 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
373 | 376 | ||
374 | // Check that all settings are present | 377 | // Check that all settings are present |
375 | if (config_setting_lookup_string(node, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE) { | 378 | if (config_setting_lookup_string(node, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE) { |
376 | write_log(LOG_LEVEL_WARNING, "Bootstrap node #%d: Couldn't find '%s' setting. Skipping the node.\n", i, NAME_PUBLIC_KEY); | 379 | write_log(LOG_LEVEL_WARNING, "Bootstrap node #%d: Couldn't find '%s' setting. Skipping the node.\n", i, |
380 | NAME_PUBLIC_KEY); | ||
377 | goto next; | 381 | goto next; |
378 | } | 382 | } |
379 | 383 | ||
@@ -390,13 +394,14 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
390 | // Process settings | 394 | // Process settings |
391 | if (strlen(bs_public_key) != crypto_box_PUBLICKEYBYTES * 2) { | 395 | if (strlen(bs_public_key) != crypto_box_PUBLICKEYBYTES * 2) { |
392 | write_log(LOG_LEVEL_WARNING, "Bootstrap node #%d: Invalid '%s': %s. Skipping the node.\n", i, NAME_PUBLIC_KEY, | 396 | write_log(LOG_LEVEL_WARNING, "Bootstrap node #%d: Invalid '%s': %s. Skipping the node.\n", i, NAME_PUBLIC_KEY, |
393 | bs_public_key); | 397 | bs_public_key); |
394 | goto next; | 398 | goto next; |
395 | } | 399 | } |
396 | 400 | ||
397 | if (bs_port < MIN_ALLOWED_PORT || bs_port > MAX_ALLOWED_PORT) { | 401 | if (bs_port < MIN_ALLOWED_PORT || bs_port > MAX_ALLOWED_PORT) { |
398 | write_log(LOG_LEVEL_WARNING, "Bootstrap node #%d: Invalid '%s': %d, should be in [%d, %d]. Skipping the node.\n", i, NAME_PORT, | 402 | write_log(LOG_LEVEL_WARNING, "Bootstrap node #%d: Invalid '%s': %d, should be in [%d, %d]. Skipping the node.\n", i, |
399 | bs_port, MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); | 403 | NAME_PORT, |
404 | bs_port, MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); | ||
400 | goto next; | 405 | goto next; |
401 | } | 406 | } |
402 | 407 | ||