diff options
Diffstat (limited to 'src/ot_config.c')
| -rw-r--r-- | src/ot_config.c | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/ot_config.c b/src/ot_config.c index 95136b5..e689314 100644 --- a/src/ot_config.c +++ b/src/ot_config.c | |||
| @@ -79,10 +79,12 @@ static listen_option_kind parse_listen_option(char **p) { | |||
| 79 | 79 | ||
| 80 | for (i = 0; i < listen_option_count; ++i) { | 80 | for (i = 0; i < listen_option_count; ++i) { |
| 81 | const listen_option_key *key = &listen_option_keys[i]; | 81 | const listen_option_key *key = &listen_option_keys[i]; |
| 82 | char delimiter = (*p)[key->len]; | 82 | char delimiter; |
| 83 | 83 | ||
| 84 | if (strncmp(*p, key->name, key->len)) | 84 | if (strncmp(*p, key->name, key->len)) |
| 85 | continue; | 85 | continue; |
| 86 | /* The match guarantees *p is at least key->len bytes, so this is in bounds */ | ||
| 87 | delimiter = (*p)[key->len]; | ||
| 86 | if (key->takes_value ? delimiter != '=' : (delimiter && !isspace((unsigned char)delimiter))) | 88 | if (key->takes_value ? delimiter != '=' : (delimiter && !isspace((unsigned char)delimiter))) |
| 87 | continue; | 89 | continue; |
| 88 | 90 | ||
| @@ -126,7 +128,7 @@ static const char *set_config_option(const char **option, char *value) { | |||
| 126 | #ifdef _DEBUG | 128 | #ifdef _DEBUG |
| 127 | fprintf(stderr, "Setting config option: %s\n", value); | 129 | fprintf(stderr, "Setting config option: %s\n", value); |
| 128 | #endif | 130 | #endif |
| 129 | while (isspace(*value)) | 131 | while (isspace((unsigned char)*value)) |
| 130 | ++value; | 132 | ++value; |
| 131 | free((char *)*option); | 133 | free((char *)*option); |
| 132 | return *option = strdup(value); | 134 | return *option = strdup(value); |
| @@ -136,7 +138,7 @@ static int scan_ip6_port(const char *src, ot_ip6 ip, uint16_t *port) { | |||
| 136 | const char *s = src; | 138 | const char *s = src; |
| 137 | uint64_t value; | 139 | uint64_t value; |
| 138 | int off, bracket = 0; | 140 | int off, bracket = 0; |
| 139 | while (isspace(*s)) | 141 | while (isspace((unsigned char)*s)) |
| 140 | ++s; | 142 | ++s; |
| 141 | if (*s == '[') | 143 | if (*s == '[') |
| 142 | ++s, ++bracket; /* for v6 style notation */ | 144 | ++s, ++bracket; /* for v6 style notation */ |
| @@ -145,7 +147,7 @@ static int scan_ip6_port(const char *src, ot_ip6 ip, uint16_t *port) { | |||
| 145 | s += off; | 147 | s += off; |
| 146 | if (bracket && *s == ']') | 148 | if (bracket && *s == ']') |
| 147 | ++s; | 149 | ++s; |
| 148 | if (*s == 0 || isspace(*s)) | 150 | if (*s == 0 || isspace((unsigned char)*s)) |
| 149 | return s - src; | 151 | return s - src; |
| 150 | if (!ip_is_v4mapped(ip)) { | 152 | if (!ip_is_v4mapped(ip)) { |
| 151 | if (*s != ':' && *s != '.') | 153 | if (*s != ':' && *s != '.') |
| @@ -167,7 +169,7 @@ static int scan_ip6_net(const char *src, ot_net *net) { | |||
| 167 | const char *s = src; | 169 | const char *s = src; |
| 168 | uint64_t value; | 170 | uint64_t value; |
| 169 | int off; | 171 | int off; |
| 170 | while (isspace(*s)) | 172 | while (isspace((unsigned char)*s)) |
| 171 | ++s; | 173 | ++s; |
| 172 | if (!(off = ip_parse(s, net->address))) | 174 | if (!(off = ip_parse(s, net->address))) |
| 173 | return 0; | 175 | return 0; |
| @@ -192,6 +194,7 @@ typedef enum { | |||
| 192 | CONFIG_UNKNOWN, | 194 | CONFIG_UNKNOWN, |
| 193 | CONFIG_TRACKER_ROOTDIR, | 195 | CONFIG_TRACKER_ROOTDIR, |
| 194 | CONFIG_TRACKER_USER, | 196 | CONFIG_TRACKER_USER, |
| 197 | CONFIG_TRACKER_EMPTY_TIMEOUT, | ||
| 195 | CONFIG_LISTEN_TCP_UDP, | 198 | CONFIG_LISTEN_TCP_UDP, |
| 196 | CONFIG_LISTEN_TCP, | 199 | CONFIG_LISTEN_TCP, |
| 197 | CONFIG_LISTEN_UDP, | 200 | CONFIG_LISTEN_UDP, |
| @@ -205,9 +208,11 @@ typedef enum { | |||
| 205 | CONFIG_ACCESS_STATS, | 208 | CONFIG_ACCESS_STATS, |
| 206 | CONFIG_ACCESS_STATS_PATH, | 209 | CONFIG_ACCESS_STATS_PATH, |
| 207 | CONFIG_ACCESS_PROXY, | 210 | CONFIG_ACCESS_PROXY, |
| 211 | CONFIG_ACCESS_FULLSCRAPE, | ||
| 208 | CONFIG_TRACKER_REDIRECT_URL, | 212 | CONFIG_TRACKER_REDIRECT_URL, |
| 209 | CONFIG_LIVESYNC_CLUSTER_NODE_IP, | 213 | CONFIG_LIVESYNC_CLUSTER_NODE_IP, |
| 210 | CONFIG_LIVESYNC_CLUSTER_LISTEN, | 214 | CONFIG_LIVESYNC_CLUSTER_LISTEN, |
| 215 | CONFIG_LIVESYNC_CLUSTER_GROUP, | ||
| 211 | } config_kind; | 216 | } config_kind; |
| 212 | 217 | ||
| 213 | typedef struct { | 218 | typedef struct { |
| @@ -221,6 +226,7 @@ typedef struct { | |||
| 221 | static const config_key config_keys[] = { | 226 | static const config_key config_keys[] = { |
| 222 | CONFIG_KEY("tracker.rootdir", CONFIG_TRACKER_ROOTDIR), | 227 | CONFIG_KEY("tracker.rootdir", CONFIG_TRACKER_ROOTDIR), |
| 223 | CONFIG_KEY("tracker.user", CONFIG_TRACKER_USER), | 228 | CONFIG_KEY("tracker.user", CONFIG_TRACKER_USER), |
| 229 | CONFIG_KEY("tracker.empty_torrent_timeout", CONFIG_TRACKER_EMPTY_TIMEOUT), | ||
| 224 | CONFIG_KEY("listen.tcp_udp", CONFIG_LISTEN_TCP_UDP), | 230 | CONFIG_KEY("listen.tcp_udp", CONFIG_LISTEN_TCP_UDP), |
| 225 | CONFIG_KEY("listen.tcp", CONFIG_LISTEN_TCP), | 231 | CONFIG_KEY("listen.tcp", CONFIG_LISTEN_TCP), |
| 226 | CONFIG_KEY("listen.udp", CONFIG_LISTEN_UDP), | 232 | CONFIG_KEY("listen.udp", CONFIG_LISTEN_UDP), |
| @@ -243,10 +249,14 @@ static const config_key config_keys[] = { | |||
| 243 | #ifdef WANT_IP_FROM_PROXY | 249 | #ifdef WANT_IP_FROM_PROXY |
| 244 | CONFIG_KEY("access.proxy", CONFIG_ACCESS_PROXY), | 250 | CONFIG_KEY("access.proxy", CONFIG_ACCESS_PROXY), |
| 245 | #endif | 251 | #endif |
| 252 | #ifdef WANT_RESTRICT_FULLSCRAPE | ||
| 253 | CONFIG_KEY("access.fullscrape", CONFIG_ACCESS_FULLSCRAPE), | ||
| 254 | #endif | ||
| 246 | CONFIG_KEY("tracker.redirect_url", CONFIG_TRACKER_REDIRECT_URL), | 255 | CONFIG_KEY("tracker.redirect_url", CONFIG_TRACKER_REDIRECT_URL), |
| 247 | #ifdef WANT_SYNC_LIVE | 256 | #ifdef WANT_SYNC_LIVE |
| 248 | CONFIG_KEY("livesync.cluster.node_ip", CONFIG_LIVESYNC_CLUSTER_NODE_IP), | 257 | CONFIG_KEY("livesync.cluster.node_ip", CONFIG_LIVESYNC_CLUSTER_NODE_IP), |
| 249 | CONFIG_KEY("livesync.cluster.listen", CONFIG_LIVESYNC_CLUSTER_LISTEN), | 258 | CONFIG_KEY("livesync.cluster.listen", CONFIG_LIVESYNC_CLUSTER_LISTEN), |
| 259 | CONFIG_KEY("livesync.cluster.group", CONFIG_LIVESYNC_CLUSTER_GROUP), | ||
| 250 | #endif | 260 | #endif |
| 251 | }; | 261 | }; |
| 252 | static const size_t config_entry_count = sizeof(config_keys) / sizeof(config_keys[0]); | 262 | static const size_t config_entry_count = sizeof(config_keys) / sizeof(config_keys[0]); |
| @@ -270,7 +280,7 @@ static int parse_configfile(char *config_filename) { | |||
| 270 | FILE *config_file_handle; | 280 | FILE *config_file_handle; |
| 271 | char inbuf[512]; | 281 | char inbuf[512]; |
| 272 | ot_ip6 tmpip; | 282 | ot_ip6 tmpip; |
| 273 | #if defined(WANT_RESTRICT_STATS) || defined(WANT_IP_FROM_PROXY) || defined(WANT_SYNC_LIVE) | 283 | #if defined(WANT_RESTRICT_STATS) || defined(WANT_RESTRICT_FULLSCRAPE) || defined(WANT_IP_FROM_PROXY) || defined(WANT_SYNC_LIVE) |
| 274 | ot_net tmpnet; | 284 | ot_net tmpnet; |
| 275 | #endif | 285 | #endif |
| 276 | int bound = 0; | 286 | int bound = 0; |
| @@ -310,6 +320,11 @@ static int parse_configfile(char *config_filename) { | |||
| 310 | case CONFIG_TRACKER_USER: | 320 | case CONFIG_TRACKER_USER: |
| 311 | set_config_option(&g_serveruser, p); | 321 | set_config_option(&g_serveruser, p); |
| 312 | break; | 322 | break; |
| 323 | case CONFIG_TRACKER_EMPTY_TIMEOUT: | ||
| 324 | if (!scan_uint(p, &value, UINT_MAX)) | ||
| 325 | goto parse_error; | ||
| 326 | g_empty_torrent_timeout = (ot_time)value; | ||
| 327 | break; | ||
| 313 | case CONFIG_LISTEN_TCP_UDP: | 328 | case CONFIG_LISTEN_TCP_UDP: |
| 314 | case CONFIG_LISTEN_TCP: | 329 | case CONFIG_LISTEN_TCP: |
| 315 | case CONFIG_LISTEN_UDP: { | 330 | case CONFIG_LISTEN_UDP: { |
| @@ -318,7 +333,7 @@ static int parse_configfile(char *config_filename) { | |||
| 318 | int off = scan_ip6_port(p, tmpip, &tmpport); | 333 | int off = scan_ip6_port(p, tmpip, &tmpport); |
| 319 | 334 | ||
| 320 | if (!off || !listen_scan_options(p + off, &shared, &workers)) | 335 | if (!off || !listen_scan_options(p + off, &shared, &workers)) |
| 321 | goto parse_error; | 336 | exerr("listen.tcp, listen.udp and listen.tcp_udp want an address, optionally a port and options."); |
| 322 | if (kind != CONFIG_LISTEN_UDP) | 337 | if (kind != CONFIG_LISTEN_UDP) |
| 323 | listen_append(tmpip, tmpport, FLAG_TCP, shared, workers), ++bound; | 338 | listen_append(tmpip, tmpport, FLAG_TCP, shared, workers), ++bound; |
| 324 | if (kind != CONFIG_LISTEN_TCP) | 339 | if (kind != CONFIG_LISTEN_TCP) |
| @@ -374,10 +389,21 @@ static int parse_configfile(char *config_filename) { | |||
| 374 | accesslist_bless_net(&tmpnet, OT_PERMISSION_MAY_PROXY); | 389 | accesslist_bless_net(&tmpnet, OT_PERMISSION_MAY_PROXY); |
| 375 | break; | 390 | break; |
| 376 | #endif | 391 | #endif |
| 392 | #ifdef WANT_RESTRICT_FULLSCRAPE | ||
| 393 | case CONFIG_ACCESS_FULLSCRAPE: | ||
| 394 | if (!scan_ip6_net(p, &tmpnet)) | ||
| 395 | goto parse_error; | ||
| 396 | accesslist_bless_net(&tmpnet, OT_PERMISSION_MAY_FULLSCRAPE); | ||
| 397 | break; | ||
| 398 | #endif | ||
| 377 | case CONFIG_TRACKER_REDIRECT_URL: | 399 | case CONFIG_TRACKER_REDIRECT_URL: |
| 378 | set_config_option(&g_redirecturl, p); | 400 | set_config_option(&g_redirecturl, p); |
| 379 | break; | 401 | break; |
| 380 | #ifdef WANT_SYNC_LIVE | 402 | #ifdef WANT_SYNC_LIVE |
| 403 | case CONFIG_LIVESYNC_CLUSTER_GROUP: | ||
| 404 | if (!ip_parse(p, tmpip) || livesync_set_group(tmpip) == -1) | ||
| 405 | exerr("livesync.cluster.group wants a multicast address, out of 224.0.0.0/4."); | ||
| 406 | break; | ||
| 381 | case CONFIG_LIVESYNC_CLUSTER_NODE_IP: | 407 | case CONFIG_LIVESYNC_CLUSTER_NODE_IP: |
| 382 | if (!scan_ip6_net(p, &tmpnet)) | 408 | if (!scan_ip6_net(p, &tmpnet)) |
| 383 | goto parse_error; | 409 | goto parse_error; |
| @@ -440,7 +466,7 @@ static void help(char *name) { | |||
| 440 | fprintf(stderr, "\nExample: ./opentracker -i 127.0.0.1 -p 6969 -P 6969 -f ./opentracker.conf -i 10.1.1.23 -p 2710 -p 80\n"); | 466 | fprintf(stderr, "\nExample: ./opentracker -i 127.0.0.1 -p 6969 -P 6969 -f ./opentracker.conf -i 10.1.1.23 -p 2710 -p 80\n"); |
| 441 | fprintf(stderr, " Here -i 127.0.0.1 selects the ip address for the next -p 6969 and -P 6969.\n"); | 467 | fprintf(stderr, " Here -i 127.0.0.1 selects the ip address for the next -p 6969 and -P 6969.\n"); |
| 442 | fprintf(stderr, " If no port is bound from config file or command line, the last address given\n"); | 468 | fprintf(stderr, " If no port is bound from config file or command line, the last address given\n"); |
| 443 | fprintf(stderr, " (or ::1 if none is set) will be used on port 6969.\n"); | 469 | fprintf(stderr, " is used on port 6969, and every interface if none was given.\n"); |
| 444 | } | 470 | } |
| 445 | #undef HELPLINE | 471 | #undef HELPLINE |
| 446 | 472 | ||
| @@ -459,10 +485,10 @@ static void listen_resolve_defaults(void) { | |||
| 459 | /* A tcp worker hands a connection it cannot finish to the event loop, | 485 | /* A tcp worker hands a connection it cannot finish to the event loop, |
| 460 | which only one thread may touch where the set is ours rather than the | 486 | which only one thread may touch where the set is ours rather than the |
| 461 | kernel's */ | 487 | kernel's */ |
| 462 | if (entry->proto == FLAG_TCP && entry->workers > 1 && !event_can_share()) { | 488 | if (entry->proto == FLAG_TCP && entry->workers > 0 && !event_can_share()) { |
| 463 | fprintf(stderr, "Warning: Multiple workers impossible on this platform with event mechanism %s chosen.\n", | 489 | fprintf(stderr, "Warning: tcp workers impossible on this platform with event mechanism %s chosen.\n", |
| 464 | event_mechanism()); | 490 | event_mechanism()); |
| 465 | entry->workers = 1; | 491 | entry->workers = 0; |
| 466 | } | 492 | } |
| 467 | } | 493 | } |
| 468 | } | 494 | } |
