1 /*********************************************************************
3 * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
5 * Purpose : Loads settings from the configuration file into
6 * global variables. This file contains both the
7 * routine to load the configuration and the global
8 * variables it writes to.
10 * Copyright : Written by and Copyright (C) 2001-2017 the
11 * Privoxy team. http://www.privoxy.org/
13 * Based on the Internet Junkbuster originally written
14 * by and Copyright (C) 1997 Anonymous Coders and
15 * Junkbusters Corporation. http://www.junkbusters.com
17 * This program is free software; you can redistribute it
18 * and/or modify it under the terms of the GNU General
19 * Public License as published by the Free Software
20 * Foundation; either version 2 of the License, or (at
21 * your option) any later version.
23 * This program is distributed in the hope that it will
24 * be useful, but WITHOUT ANY WARRANTY; without even the
25 * implied warranty of MERCHANTABILITY or FITNESS FOR A
26 * PARTICULAR PURPOSE. See the GNU General Public
27 * License for more details.
29 * The GNU General Public License should be included with
30 * this file. If not, you can view it at
31 * http://www.gnu.org/copyleft/gpl.html
32 * or write to the Free Software Foundation, Inc., 59
33 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 *********************************************************************/
41 #include <sys/types.h>
55 # include <winsock2.h>
61 # endif /* ndef _WIN_CONSOLE */
63 #else /* ifndef _WIN32 */
67 # include <sys/wait.h>
69 # include <sys/time.h>
70 # include <sys/stat.h>
88 #ifdef FEATURE_CLIENT_TAGS
89 #include "client-tags.h"
93 * Default number of seconds after which an
94 * open connection will no longer be reused.
96 #define DEFAULT_KEEP_ALIVE_TIMEOUT 180
99 * Default backlog passed to listen().
101 #define DEFAULT_LISTEN_BACKLOG 128
103 #ifdef FEATURE_TOGGLE
104 /* Privoxy is enabled by default. */
105 int global_toggle_state = 1;
106 #endif /* def FEATURE_TOGGLE */
108 /* The filename of the configfile */
109 const char *configfile = NULL;
112 * CGI functions will later need access to the invocation args,
113 * so we will make argc and argv global.
116 char * const * Argv = NULL;
118 static struct file_list *current_configfile = NULL;
122 * This takes the "cryptic" hash of each keyword and aliases them to
123 * something a little more readable. This also makes changing the
124 * hash values easier if they should change or the hash algorthm changes.
125 * Use the included "hash" program to find out what the hash will be
126 * for any string supplied on the command line. (Or just put it in the
127 * config file and read the number from the error message in the log).
129 * Please keep this list sorted alphabetically (but with the Windows
130 * console and GUI specific options last).
133 #define hash_actions_file 1196306641U /* "actionsfile" */
134 #define hash_accept_intercepted_requests 1513024973U /* "accept-intercepted-requests" */
135 #define hash_admin_address 4112573064U /* "admin-address" */
136 #define hash_allow_cgi_request_crunching 258915987U /* "allow-cgi-request-crunching" */
137 #define hash_buffer_limit 1881726070U /* "buffer-limit */
138 #define hash_client_header_order 2701453514U /* "client-header-order" */
139 #define hash_client_specific_tag 3353703383U /* "client-specific-tag" */
140 #define hash_client_tag_lifetime 647957580U /* "client-tag-lifetime" */
141 #define hash_compression_level 2464423563U /* "compression-level" */
142 #define hash_confdir 1978389U /* "confdir" */
143 #define hash_connection_sharing 1348841265U /* "connection-sharing" */
144 #define hash_cors_allowed_origin 2769345637U /* "cors-allowed-origin" */
145 #define hash_debug 78263U /* "debug" */
146 #define hash_default_server_timeout 2530089913U /* "default-server-timeout" */
147 #define hash_deny_access 1227333715U /* "deny-access" */
148 #define hash_enable_accept_filter 2909040407U /* "enable-accept-filter" */
149 #define hash_enable_edit_actions 2517097536U /* "enable-edit-actions" */
150 #define hash_enable_compression 3943696946U /* "enable-compression" */
151 #define hash_enable_proxy_authentication_forwarding 4040610791U /* enable-proxy-authentication-forwarding */
152 #define hash_enable_remote_toggle 2979744683U /* "enable-remote-toggle" */
153 #define hash_enable_remote_http_toggle 110543988U /* "enable-remote-http-toggle" */
154 #define hash_enforce_blocks 1862427469U /* "enforce-blocks" */
155 #define hash_filterfile 250887266U /* "filterfile" */
156 #define hash_forward 2029845U /* "forward" */
157 #define hash_forward_socks4 3963965521U /* "forward-socks4" */
158 #define hash_forward_socks4a 2639958518U /* "forward-socks4a" */
159 #define hash_forward_socks5 3963965522U /* "forward-socks5" */
160 #define hash_forward_socks5t 2639958542U /* "forward-socks5t" */
161 #define hash_forwarded_connect_retries 101465292U /* "forwarded-connect-retries" */
162 #define hash_handle_as_empty_returns_ok 1444873247U /* "handle-as-empty-doc-returns-ok" */
163 #define hash_hostname 10308071U /* "hostname" */
164 #define hash_keep_alive_timeout 3878599515U /* "keep-alive-timeout" */
165 #define hash_listen_address 1255650842U /* "listen-address" */
166 #define hash_listen_backlog 1255655735U /* "listen-backlog" */
167 #define hash_logdir 422889U /* "logdir" */
168 #define hash_logfile 2114766U /* "logfile" */
169 #define hash_max_client_connections 3595884446U /* "max-client-connections" */
170 #define hash_permit_access 3587953268U /* "permit-access" */
171 #define hash_proxy_info_url 3903079059U /* "proxy-info-url" */
172 #define hash_receive_buffer_size 2880297454U /* "receive-buffer-size */
173 #define hash_single_threaded 4250084780U /* "single-threaded" */
174 #define hash_socket_timeout 1809001761U /* "socket-timeout" */
175 #define hash_split_large_cgi_forms 671658948U /* "split-large-cgi-forms" */
176 #define hash_suppress_blocklists 1948693308U /* "suppress-blocklists" */
177 #define hash_templdir 11067889U /* "templdir" */
178 #define hash_temporary_directory 1824125181U /* "temporary-directory" */
179 #define hash_tolerate_pipelining 1360286620U /* "tolerate-pipelining" */
180 #define hash_toggle 447966U /* "toggle" */
181 #define hash_trust_info_url 430331967U /* "trust-info-url" */
182 #define hash_trust_x_forwarded_for 2971537414U /* "trust-x-forwarded-for" */
183 #define hash_trusted_cgi_referrer 4270883427U /* "trusted-cgi-referrer" */
184 #define hash_trustfile 56494766U /* "trustfile" */
185 #define hash_usermanual 1416668518U /* "user-manual" */
186 #define hash_activity_animation 1817904738U /* "activity-animation" */
187 #define hash_close_button_minimizes 3651284693U /* "close-button-minimizes" */
188 #define hash_hide_console 2048809870U /* "hide-console" */
189 #define hash_log_buffer_size 2918070425U /* "log-buffer-size" */
190 #define hash_log_font_name 2866730124U /* "log-font-name" */
191 #define hash_log_font_size 2866731014U /* "log-font-size" */
192 #define hash_log_highlight_messages 4032101240U /* "log-highlight-messages" */
193 #define hash_log_max_lines 2868344173U /* "log-max-lines" */
194 #define hash_log_messages 2291744899U /* "log-messages" */
195 #define hash_show_on_task_bar 215410365U /* "show-on-task-bar" */
198 static void savearg(char *command, char *argument, struct configuration_spec * config);
199 #ifdef FEATURE_CLIENT_TAGS
200 static void free_client_specific_tags(struct client_tag_spec *tag_list);
203 /*********************************************************************
205 * Function : unload_configfile
207 * Description : Free the config structure and all components.
210 * 1 : data: struct configuration_spec to unload
214 *********************************************************************/
215 static void unload_configfile (void * data)
217 struct configuration_spec * config = (struct configuration_spec *)data;
218 struct forward_spec *cur_fwd = config->forward;
222 struct access_control_list *cur_acl = config->acl;
224 while (cur_acl != NULL)
226 struct access_control_list * next_acl = cur_acl->next;
231 #endif /* def FEATURE_ACL */
233 while (cur_fwd != NULL)
235 struct forward_spec * next_fwd = cur_fwd->next;
236 free_pattern_spec(cur_fwd->url);
238 freez(cur_fwd->gateway_host);
239 freez(cur_fwd->forward_host);
243 config->forward = NULL;
245 freez(config->confdir);
246 freez(config->logdir);
247 freez(config->templdir);
248 freez(config->hostname);
249 #ifdef FEATURE_EXTERNAL_FILTERS
250 freez(config->temporary_directory);
253 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
255 freez(config->haddr[i]);
257 freez(config->logfile);
259 for (i = 0; i < MAX_AF_FILES; i++)
261 freez(config->actions_file_short[i]);
262 freez(config->actions_file[i]);
263 freez(config->re_filterfile_short[i]);
264 freez(config->re_filterfile[i]);
267 list_remove_all(config->ordered_client_headers);
269 freez(config->admin_address);
270 freez(config->proxy_info_url);
271 freez(config->proxy_args);
272 freez(config->usermanual);
273 freez(config->trusted_cgi_referrer);
276 freez(config->trustfile);
277 list_remove_all(config->trust_info);
278 #endif /* def FEATURE_TRUST */
280 #ifdef FEATURE_CLIENT_TAGS
281 free_client_specific_tags(config->client_tags);
288 #ifdef FEATURE_GRACEFUL_TERMINATION
289 /*********************************************************************
291 * Function : unload_current_config_file
293 * Description : Unloads current config file - reset to state at
294 * beginning of program.
300 *********************************************************************/
301 void unload_current_config_file(void)
303 if (current_configfile)
305 current_configfile->unloader = unload_configfile;
306 current_configfile = NULL;
312 #ifdef FEATURE_CLIENT_TAGS
313 /*********************************************************************
315 * Function : register_tag
317 * Description : Registers a client-specific-tag and its description
320 * 1 : config: The tag list
321 * 2 : name: The name of the client-specific-tag
322 * 3 : description: The human-readable description for the tag
326 *********************************************************************/
327 static void register_tag(struct client_tag_spec *tag_list,
328 const char *name, const char *description)
330 struct client_tag_spec *new_tag;
331 struct client_tag_spec *last_tag;
334 while (last_tag->next != NULL)
336 last_tag = last_tag->next;
338 if (last_tag->name == NULL)
345 new_tag = zalloc_or_die(sizeof(struct client_tag_spec));
347 new_tag->name = strdup_or_die(name);
348 new_tag->description = strdup_or_die(description);
349 if (new_tag != last_tag)
351 last_tag->next = new_tag;
356 /*********************************************************************
358 * Function : free_client_specific_tags
360 * Description : Frees client-specific tags and their descriptions
363 * 1 : tag_list: The tag list to free
367 *********************************************************************/
368 static void free_client_specific_tags(struct client_tag_spec *tag_list)
370 struct client_tag_spec *this_tag;
371 struct client_tag_spec *next_tag;
377 next_tag = next_tag->next;
379 freez(this_tag->name);
380 freez(this_tag->description);
382 if (this_tag != tag_list)
386 } while (next_tag != NULL);
388 #endif /* def FEATURE_CLIENT_TAGS */
391 /*********************************************************************
393 * Function : parse_numeric_value
395 * Description : Parse the value of a directive that can only have
396 * a single numeric value. Terminates with a fatal error
397 * if the value is NULL or not numeric.
400 * 1 : name: The name of the directive. Used for log messages.
401 * 2 : value: The value to parse
404 * Returns : The numerical value as integer
406 *********************************************************************/
407 static int parse_numeric_value(const char *name, const char *value)
412 assert(name != NULL);
413 assert(value != NULL);
415 if ((value == NULL) || (*value == '\0'))
417 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
420 number = (int)strtol(value, &endptr, 0);
423 log_error(LOG_LEVEL_FATAL,
424 "Directive '%s' used with non-numerical value: '%s'", name, value);
432 /*********************************************************************
434 * Function : parse_toggle_value
436 * Description : Parse the value of a directive that can only be
437 * enabled or disabled. Terminates with a fatal error
438 * if the value is NULL or something other than 0 or 1.
441 * 1 : name: The name of the directive. Used for log messages.
442 * 2 : value: The value to parse
445 * Returns : The numerical toggle state
447 *********************************************************************/
448 static int parse_toggle_state(const char *name, const char *value)
451 assert(name != NULL);
452 assert(value != NULL);
454 if ((value == NULL) || (*value == '\0'))
456 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
459 toggle_state = atoi(value);
462 * Also check the length as atoi() doesn't mind
463 * garbage after a valid integer, but we do.
465 if (((toggle_state != 0) && (toggle_state != 1)) || (strlen(value) != 1))
467 log_error(LOG_LEVEL_FATAL,
468 "Directive %s used with invalid argument '%s'. Use either '0' or '1'.",
477 /*********************************************************************
479 * Function : parse_client_header_order
481 * Description : Parse the value of the header-order directive
484 * 1 : ordered_header_list: List to insert the ordered
486 * 2 : ordered_headers: The ordered header names separated
492 *********************************************************************/
493 static void parse_client_header_order(struct list *ordered_header_list, const char *ordered_headers)
495 char *original_headers_copy;
498 int number_of_headers;
501 assert(ordered_header_list != NULL);
502 assert(ordered_headers != NULL);
504 if (ordered_headers == NULL)
506 log_error(LOG_LEVEL_FATAL, "header-order used without argument");
510 * XXX: This estimate is guaranteed to be high enough as we
511 * let ssplit() ignore empty fields, but also a bit wasteful.
512 * The same hack is used in get_last_url() so it looks like
513 * a real solution is needed.
515 max_segments = strlen(ordered_headers) / 2;
516 if (max_segments == 0)
520 vector = malloc_or_die(max_segments * sizeof(char *));
522 original_headers_copy = strdup_or_die(ordered_headers);
524 number_of_headers = ssplit(original_headers_copy, "\t ", vector, max_segments);
525 if (number_of_headers == -1)
527 log_error(LOG_LEVEL_FATAL, "Failed to split ordered headers");
530 for (i = 0; i < number_of_headers; i++)
532 if (JB_ERR_OK != enlist(ordered_header_list, vector[i]))
534 log_error(LOG_LEVEL_FATAL,
535 "Failed to enlist ordered header: %s", vector[i]);
540 freez(original_headers_copy);
547 /*********************************************************************
549 * Function : load_config
551 * Description : Load the config file and all parameters.
553 * XXX: more than thousand lines long
554 * and thus in serious need of refactoring.
558 * Returns : The configuration_spec, or NULL on error.
560 *********************************************************************/
561 struct configuration_spec * load_config(void)
565 FILE *configfp = NULL;
566 struct configuration_spec * config = NULL;
567 struct client_state * fake_csp;
568 struct file_list *fs;
569 unsigned long linenum = 0;
571 char *logfile = NULL;
573 if (!check_file_changed(current_configfile, configfile, &fs))
575 /* No need to load */
576 return ((struct configuration_spec *)current_configfile->f);
580 log_error(LOG_LEVEL_FATAL,
581 "can't check configuration file '%s': %E", configfile);
585 if (NULL != current_configfile)
587 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
590 #ifdef FEATURE_TOGGLE
591 global_toggle_state = 1;
592 #endif /* def FEATURE_TOGGLE */
594 fs->f = config = zalloc_or_die(sizeof(*config));
597 * This is backwards from how it's usually done.
598 * Following the usual pattern, "fs" would be stored in a member
599 * variable in "csp", and then we'd access "config" from "fs->f",
600 * using a cast. However, "config" is used so often that a
601 * cast each time would be very ugly, and the extra indirection
602 * would waste CPU cycles. Therefore we store "config" in
603 * "csp->config", and "fs" in "csp->config->config_file_list".
605 config->config_file_list = fs;
610 config->multi_threaded = 1;
611 config->buffer_limit = 4096 * 1024;
612 config->receive_buffer_size = BUFFER_SIZE;
613 config->usermanual = strdup_or_die(USER_MANUAL_URL);
614 config->proxy_args = strdup_or_die("");
615 config->forwarded_connect_retries = 0;
616 #ifdef FEATURE_CLIENT_TAGS
617 config->client_tag_lifetime = 60;
619 config->trust_x_forwarded_for = 0;
620 #if defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER)
621 config->enable_accept_filter = 0;
623 config->listen_backlog = DEFAULT_LISTEN_BACKLOG;
624 config->trusted_cgi_referrer = NULL;
626 * 128 client sockets ought to be enough for everybody who can't
627 * be bothered to read the documentation to figure out how to
628 * increase the limit.
630 config->max_client_connections = 128;
631 config->socket_timeout = 300; /* XXX: Should be a macro. */
632 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
633 config->default_server_timeout = 0;
634 config->keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
635 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
636 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
638 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
639 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
640 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
641 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
642 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
643 #ifdef FEATURE_COMPRESSION
644 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
646 * XXX: Run some benchmarks to see if there are better default values.
648 config->compression_level = 1;
650 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
651 config->cors_allowed_origin = NULL;
653 configfp = fopen(configfile, "r");
654 if (NULL == configfp)
656 log_error(LOG_LEVEL_FATAL,
657 "can't open configuration file '%s': %E", configfile);
658 /* Never get here - LOG_LEVEL_FATAL causes program exit */
661 while (read_config_line(configfp, &linenum, &buf) != NULL)
663 char cmd[BUFFER_SIZE];
664 char arg[BUFFER_SIZE];
665 char tmp[BUFFER_SIZE];
667 struct access_control_list *cur_acl;
668 #endif /* def FEATURE_ACL */
669 struct forward_spec *cur_fwd;
672 unsigned int directive_hash;
674 strlcpy(tmp, buf, sizeof(tmp));
676 /* Copy command (i.e. up to space or tab) into cmd */
679 while (*p && (*p != ' ') && (*p != '\t'))
685 /* Skip over the whitespace in buf */
686 while (*p && ((*p == ' ') || (*p == '\t')))
691 /* Copy the argument into arg */
692 if (strlcpy(arg, p, sizeof(arg)) >= sizeof(arg))
694 log_error(LOG_LEVEL_FATAL, "Config line too long: %s", buf);
697 /* Should never happen, but check this anyway */
704 /* Make sure the command field is lower case */
705 for (p = cmd; *p; p++)
707 if (privoxy_isupper(*p))
709 *p = (char)privoxy_tolower(*p);
713 directive_hash = hash_string(cmd);
714 switch (directive_hash)
716 /* *************************************************************************
717 * actionsfile actions-file-name
718 * In confdir by default
719 * *************************************************************************/
720 case hash_actions_file :
722 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
727 if (i >= MAX_AF_FILES)
729 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
730 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
733 config->actions_file_short[i] = strdup_or_die(arg);
734 config->actions_file[i] = make_path(config->confdir, arg);
737 /* *************************************************************************
738 * accept-intercepted-requests
739 * *************************************************************************/
740 case hash_accept_intercepted_requests:
741 if (parse_toggle_state(cmd, arg) == 1)
743 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
747 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
751 /* *************************************************************************
752 * admin-address email-address
753 * *************************************************************************/
754 case hash_admin_address :
755 freez(config->admin_address);
756 config->admin_address = strdup_or_die(arg);
759 /* *************************************************************************
760 * allow-cgi-request-crunching
761 * *************************************************************************/
762 case hash_allow_cgi_request_crunching:
763 if (parse_toggle_state(cmd, arg) == 1)
765 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
769 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
773 /* *************************************************************************
775 * *************************************************************************/
776 case hash_buffer_limit :
777 config->buffer_limit = (size_t)(1024 * parse_numeric_value(cmd, arg));
780 /* *************************************************************************
781 * client-header-order header-1 header-2 ... header-n
782 * *************************************************************************/
783 case hash_client_header_order:
784 list_remove_all(config->ordered_client_headers);
785 parse_client_header_order(config->ordered_client_headers, arg);
788 /* *************************************************************************
789 * client-specific-tag tag-name description
790 * *************************************************************************/
791 #ifdef FEATURE_CLIENT_TAGS
792 case hash_client_specific_tag:
798 description = strstr(arg, " ");
799 if (description == NULL)
801 log_error(LOG_LEVEL_FATAL,
802 "client-specific-tag '%s' lacks a description.", name);
806 * The length is limited because we don't want truncated
807 * HTML caused by the cgi interface using static buffer
810 if (strlen(name) > CLIENT_TAG_LENGTH_MAX)
812 log_error(LOG_LEVEL_FATAL,
813 "client-specific-tag '%s' is longer than %d characters.",
814 name, CLIENT_TAG_LENGTH_MAX);
817 register_tag(config->client_tags, name, description);
820 #endif /* def FEATURE_CLIENT_TAGS */
822 /* *************************************************************************
823 * client-tag-lifetime ttl
824 * *************************************************************************/
825 #ifdef FEATURE_CLIENT_TAGS
826 case hash_client_tag_lifetime:
828 int ttl = parse_numeric_value(cmd, arg);
831 config->client_tag_lifetime = (unsigned)ttl;
835 log_error(LOG_LEVEL_FATAL,
836 "client-tag-lifetime can't be negative.");
840 #endif /* def FEATURE_CLIENT_TAGS */
842 /* *************************************************************************
843 * confdir directory-name
844 * *************************************************************************/
846 freez(config->confdir);
847 config->confdir = make_path(NULL, arg);
850 /* *************************************************************************
851 * compression-level 0-9
852 * *************************************************************************/
853 #ifdef FEATURE_COMPRESSION
854 case hash_compression_level :
856 int compression_level = parse_numeric_value(cmd, arg);
857 if (-1 <= compression_level && compression_level <= 9)
859 config->compression_level = compression_level;
863 log_error(LOG_LEVEL_FATAL,
864 "Invalid compression-level value: %s", arg);
870 /* *************************************************************************
871 * connection-sharing (0|1)
872 * *************************************************************************/
873 #ifdef FEATURE_CONNECTION_SHARING
874 case hash_connection_sharing :
875 if (parse_toggle_state(cmd, arg) == 1)
877 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_SHARING;
881 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
886 /* *************************************************************************
887 * cors-allowed-origin http://www.example.org
888 * *************************************************************************/
889 case hash_cors_allowed_origin :
891 * We don't validate the specified referrer as
892 * it's only used for string comparison.
894 freez(config->cors_allowed_origin);
895 config->cors_allowed_origin = strdup_or_die(arg);
898 /* *************************************************************************
900 * Specifies debug level, multiple values are ORed together.
901 * *************************************************************************/
903 config->debug |= parse_numeric_value(cmd, arg);
906 /* *************************************************************************
907 * default-server-timeout timeout
908 * *************************************************************************/
909 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
910 case hash_default_server_timeout :
912 int timeout = parse_numeric_value(cmd, arg);
915 config->default_server_timeout = (unsigned int)timeout;
919 log_error(LOG_LEVEL_FATAL,
920 "Invalid default-server-timeout value: %s", arg);
926 /* *************************************************************************
927 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
928 * *************************************************************************/
930 case hash_deny_access:
931 strlcpy(tmp, arg, sizeof(tmp));
932 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
934 if ((vec_count != 1) && (vec_count != 2))
936 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
937 "deny-access directive in configuration file.");
938 string_append(&config->proxy_args,
939 "<br>\nWARNING: Wrong number of parameters for "
940 "deny-access directive in configuration file.<br><br>\n");
944 /* allocate a new node */
945 cur_acl = zalloc_or_die(sizeof(*cur_acl));
946 cur_acl->action = ACL_DENY;
948 if (acl_addr(vec[0], cur_acl->src) < 0)
950 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
951 "for deny-access directive in configuration file: \"%s\"", vec[0]);
952 string_append(&config->proxy_args,
953 "<br>\nWARNING: Invalid source address, port or netmask "
954 "for deny-access directive in configuration file: \"");
955 string_append(&config->proxy_args,
957 string_append(&config->proxy_args,
964 if (acl_addr(vec[1], cur_acl->dst) < 0)
966 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
967 "for deny-access directive in configuration file: \"%s\"", vec[1]);
968 string_append(&config->proxy_args,
969 "<br>\nWARNING: Invalid destination address, port or netmask "
970 "for deny-access directive in configuration file: \"");
971 string_append(&config->proxy_args,
973 string_append(&config->proxy_args,
982 cur_acl->wildcard_dst = 1;
984 #endif /* def HAVE_RFC2553 */
987 * Add it to the list. Note we reverse the list to get the
988 * behaviour the user expects. With both the ACL and
989 * actions file, the last match wins. However, the internal
990 * implementations are different: The actions file is stored
991 * in the same order as the file, and scanned completely.
992 * With the ACL, we reverse the order as we load it, then
993 * when we scan it we stop as soon as we get a match.
995 cur_acl->next = config->acl;
996 config->acl = cur_acl;
999 #endif /* def FEATURE_ACL */
1001 #if defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER)
1002 /* *************************************************************************
1003 * enable-accept-filter 0|1
1004 * *************************************************************************/
1005 case hash_enable_accept_filter :
1006 config->enable_accept_filter = parse_toggle_state(cmd, arg);
1008 #endif /* defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER) */
1010 /* *************************************************************************
1011 * enable-edit-actions 0|1
1012 * *************************************************************************/
1013 #ifdef FEATURE_CGI_EDIT_ACTIONS
1014 case hash_enable_edit_actions:
1015 if (parse_toggle_state(cmd, arg) == 1)
1017 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1021 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1024 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1026 /* *************************************************************************
1027 * enable-compression 0|1
1028 * *************************************************************************/
1029 #ifdef FEATURE_COMPRESSION
1030 case hash_enable_compression:
1031 if (parse_toggle_state(cmd, arg) == 1)
1033 config->feature_flags |= RUNTIME_FEATURE_COMPRESSION;
1037 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
1040 #endif /* def FEATURE_COMPRESSION */
1042 /* *************************************************************************
1043 * enable-proxy-authentication-forwarding 0|1
1044 * *************************************************************************/
1045 case hash_enable_proxy_authentication_forwarding:
1046 if (parse_toggle_state(cmd, arg) == 1)
1048 config->feature_flags |= RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1052 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1056 /* *************************************************************************
1057 * enable-remote-toggle 0|1
1058 * *************************************************************************/
1059 #ifdef FEATURE_TOGGLE
1060 case hash_enable_remote_toggle:
1061 if (parse_toggle_state(cmd, arg) == 1)
1063 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1067 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1070 #endif /* def FEATURE_TOGGLE */
1072 /* *************************************************************************
1073 * enable-remote-http-toggle 0|1
1074 * *************************************************************************/
1075 case hash_enable_remote_http_toggle:
1076 if (parse_toggle_state(cmd, arg) == 1)
1078 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1082 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1086 /* *************************************************************************
1087 * enforce-blocks 0|1
1088 * *************************************************************************/
1089 case hash_enforce_blocks:
1090 #ifdef FEATURE_FORCE_LOAD
1091 if (parse_toggle_state(cmd, arg) == 1)
1093 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1097 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1100 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1101 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1102 #endif /* def FEATURE_FORCE_LOAD */
1105 /* *************************************************************************
1106 * filterfile file-name
1107 * In confdir by default.
1108 * *************************************************************************/
1109 case hash_filterfile :
1111 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1116 if (i >= MAX_AF_FILES)
1118 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1119 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1122 config->re_filterfile_short[i] = strdup_or_die(arg);
1123 config->re_filterfile[i] = make_path(config->confdir, arg);
1127 /* *************************************************************************
1128 * forward url-pattern (.|http-proxy-host[:port])
1129 * *************************************************************************/
1131 strlcpy(tmp, arg, sizeof(tmp));
1132 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1136 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1137 "directive in configuration file.");
1138 string_append(&config->proxy_args,
1139 "<br>\nWARNING: Wrong number of parameters for "
1140 "forward directive in configuration file.");
1144 /* allocate a new node */
1145 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1146 cur_fwd->type = SOCKS_NONE;
1148 /* Save the URL pattern */
1149 if (create_pattern_spec(cur_fwd->url, vec[0]))
1151 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1152 "directive in configuration file.");
1153 string_append(&config->proxy_args,
1154 "<br>\nWARNING: Bad URL specifier for "
1155 "forward directive in configuration file.");
1160 /* Parse the parent HTTP proxy host:port */
1163 if (strcmp(p, ".") != 0)
1165 cur_fwd->forward_port = 8000;
1166 parse_forwarder_address(p, &cur_fwd->forward_host,
1167 &cur_fwd->forward_port);
1171 cur_fwd->next = config->forward;
1172 config->forward = cur_fwd;
1176 /* *************************************************************************
1177 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1178 * *************************************************************************/
1179 case hash_forward_socks4:
1180 strlcpy(tmp, arg, sizeof(tmp));
1181 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1185 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1186 "forward-socks4 directive in configuration file.");
1187 string_append(&config->proxy_args,
1188 "<br>\nWARNING: Wrong number of parameters for "
1189 "forward-socks4 directive in configuration file.");
1193 /* allocate a new node */
1194 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1195 cur_fwd->type = SOCKS_4;
1197 /* Save the URL pattern */
1198 if (create_pattern_spec(cur_fwd->url, vec[0]))
1200 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1201 "directive in configuration file.");
1202 string_append(&config->proxy_args,
1203 "<br>\nWARNING: Bad URL specifier for "
1204 "forward-socks4 directive in configuration file.");
1209 /* Parse the SOCKS proxy host[:port] */
1212 /* XXX: This check looks like a bug. */
1213 if (strcmp(p, ".") != 0)
1215 cur_fwd->gateway_port = 1080;
1216 parse_forwarder_address(p, &cur_fwd->gateway_host,
1217 &cur_fwd->gateway_port);
1220 /* Parse the parent HTTP proxy host[:port] */
1223 if (strcmp(p, ".") != 0)
1225 cur_fwd->forward_port = 8000;
1226 parse_forwarder_address(p, &cur_fwd->forward_host,
1227 &cur_fwd->forward_port);
1231 cur_fwd->next = config->forward;
1232 config->forward = cur_fwd;
1236 /* *************************************************************************
1237 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1238 * *************************************************************************/
1239 case hash_forward_socks4a:
1240 case hash_forward_socks5:
1241 case hash_forward_socks5t:
1242 strlcpy(tmp, arg, sizeof(tmp));
1243 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1247 log_error(LOG_LEVEL_ERROR,
1248 "Wrong number of parameters for %s in configuration file.",
1250 string_append(&config->proxy_args,
1251 "<br>\nWARNING: Wrong number of parameters for ");
1252 string_append(&config->proxy_args, cmd);
1253 string_append(&config->proxy_args,
1254 "directive in configuration file.");
1258 /* allocate a new node */
1259 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1261 if (directive_hash == hash_forward_socks4a)
1263 cur_fwd->type = SOCKS_4A;
1265 else if (directive_hash == hash_forward_socks5)
1267 cur_fwd->type = SOCKS_5;
1271 assert(directive_hash == hash_forward_socks5t);
1272 cur_fwd->type = SOCKS_5T;
1275 /* Save the URL pattern */
1276 if (create_pattern_spec(cur_fwd->url, vec[0]))
1278 log_error(LOG_LEVEL_ERROR,
1279 "Bad URL specifier for %s in configuration file.",
1281 string_append(&config->proxy_args,
1282 "<br>\nWARNING: Bad URL specifier for ");
1283 string_append(&config->proxy_args, cmd);
1284 string_append(&config->proxy_args,
1285 "directive in configuration file.");
1290 /* Parse the SOCKS proxy host[:port] */
1293 cur_fwd->gateway_port = 1080;
1294 parse_forwarder_address(p, &cur_fwd->gateway_host,
1295 &cur_fwd->gateway_port);
1297 /* Parse the parent HTTP proxy host[:port] */
1300 if (strcmp(p, ".") != 0)
1302 cur_fwd->forward_port = 8000;
1303 parse_forwarder_address(p, &cur_fwd->forward_host,
1304 &cur_fwd->forward_port);
1308 cur_fwd->next = config->forward;
1309 config->forward = cur_fwd;
1313 /* *************************************************************************
1314 * forwarded-connect-retries n
1315 * *************************************************************************/
1316 case hash_forwarded_connect_retries :
1317 config->forwarded_connect_retries = parse_numeric_value(cmd, arg);
1320 /* *************************************************************************
1321 * handle-as-empty-doc-returns-ok 0|1
1323 * Workaround for firefox hanging on blocked javascript pages.
1324 * Block with the "+handle-as-empty-document" flag and set the
1325 * "handle-as-empty-doc-returns-ok" run-time config flag so that
1326 * Privoxy returns a 200/OK status instead of a 403/Forbidden status
1327 * to the browser for blocked pages.
1328 ***************************************************************************/
1329 case hash_handle_as_empty_returns_ok:
1330 if (parse_toggle_state(cmd, arg) == 1)
1332 config->feature_flags |= RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1336 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1340 /* *************************************************************************
1341 * hostname hostname-to-show-on-cgi-pages
1342 * *************************************************************************/
1343 case hash_hostname :
1344 freez(config->hostname);
1345 config->hostname = strdup_or_die(arg);
1348 /* *************************************************************************
1349 * keep-alive-timeout timeout
1350 * *************************************************************************/
1351 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1352 case hash_keep_alive_timeout :
1354 int timeout = parse_numeric_value(cmd, arg);
1357 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1358 config->keep_alive_timeout = (unsigned int)timeout;
1362 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1368 /* *************************************************************************
1369 * listen-address [ip][:port]
1370 * *************************************************************************/
1371 case hash_listen_address :
1373 while ((i < MAX_LISTENING_SOCKETS) && (NULL != config->haddr[i]))
1378 if (i >= MAX_LISTENING_SOCKETS)
1380 log_error(LOG_LEVEL_FATAL, "Too many 'listen-address' directives in config file - limit is %d.\n"
1381 "(You can increase this limit by changing MAX_LISTENING_SOCKETS in project.h and recompiling).",
1382 MAX_LISTENING_SOCKETS);
1384 config->haddr[i] = strdup_or_die(arg);
1387 /* *************************************************************************
1389 * *************************************************************************/
1390 case hash_listen_backlog :
1392 * We don't enfore an upper or lower limit because on
1393 * many platforms all values are valid and negative
1394 * number mean "use the highest value allowed".
1396 config->listen_backlog = parse_numeric_value(cmd, arg);
1399 /* *************************************************************************
1400 * logdir directory-name
1401 * *************************************************************************/
1403 freez(config->logdir);
1404 config->logdir = make_path(NULL, arg);
1407 /* *************************************************************************
1408 * logfile log-file-name
1409 * In logdir by default
1410 * *************************************************************************/
1414 logfile = make_path(config->logdir, arg);
1415 if (NULL == logfile)
1417 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1422 /* *************************************************************************
1423 * max-client-connections number
1424 * *************************************************************************/
1425 case hash_max_client_connections :
1427 int max_client_connections = parse_numeric_value(cmd, arg);
1429 #if !defined(_WIN32) && !defined(HAVE_POLL)
1431 * Reject values below 1 for obvious reasons and values above
1432 * FD_SETSIZE/2 because Privoxy needs two sockets to serve
1433 * client connections that need forwarding.
1435 * We ignore the fact that the first three file descriptors
1436 * are usually set to /dev/null, one is used for logging
1437 * and yet another file descriptor is required to load
1440 if ((max_client_connections < 1) || (FD_SETSIZE/2 < max_client_connections))
1442 log_error(LOG_LEVEL_FATAL, "max-client-connections value %d"
1443 " is invalid. Value needs to be above 1 and below %d"
1444 " (FD_SETSIZE/2).", max_client_connections, FD_SETSIZE/2);
1448 * The Windows libc uses FD_SETSIZE for an array used
1449 * by select(), but has no problems with file descriptors
1450 * above the limit as long as no more than FD_SETSIZE are
1451 * passed to select().
1452 * https://msdn.microsoft.com/en-us/library/windows/desktop/ms739169%28v=vs.85%29.aspx
1454 * On platforms were we use poll() we don't have to enforce
1455 * an upper connection limit either.
1457 * XXX: Do OS/2 etc. belong here as well?
1459 if (max_client_connections < 1)
1461 log_error(LOG_LEVEL_FATAL, "max-client-connections value"
1462 " has to be a number above 1. %d is invalid.",
1463 max_client_connections);
1466 config->max_client_connections = max_client_connections;
1470 /* *************************************************************************
1471 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1472 * *************************************************************************/
1474 case hash_permit_access:
1475 strlcpy(tmp, arg, sizeof(tmp));
1476 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1478 if ((vec_count != 1) && (vec_count != 2))
1480 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1481 "permit-access directive in configuration file.");
1482 string_append(&config->proxy_args,
1483 "<br>\nWARNING: Wrong number of parameters for "
1484 "permit-access directive in configuration file.<br><br>\n");
1489 /* allocate a new node */
1490 cur_acl = zalloc_or_die(sizeof(*cur_acl));
1491 cur_acl->action = ACL_PERMIT;
1493 if (acl_addr(vec[0], cur_acl->src) < 0)
1495 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1496 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1497 string_append(&config->proxy_args,
1498 "<br>\nWARNING: Invalid source address, port or netmask for "
1499 "permit-access directive in configuration file: \"");
1500 string_append(&config->proxy_args,
1502 string_append(&config->proxy_args,
1509 if (acl_addr(vec[1], cur_acl->dst) < 0)
1511 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1512 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1513 string_append(&config->proxy_args,
1514 "<br>\nWARNING: Invalid destination address, port or netmask for "
1515 "permit-access directive in configuration file: \"");
1516 string_append(&config->proxy_args,
1518 string_append(&config->proxy_args,
1527 cur_acl->wildcard_dst = 1;
1529 #endif /* def HAVE_RFC2553 */
1532 * Add it to the list. Note we reverse the list to get the
1533 * behaviour the user expects. With both the ACL and
1534 * actions file, the last match wins. However, the internal
1535 * implementations are different: The actions file is stored
1536 * in the same order as the file, and scanned completely.
1537 * With the ACL, we reverse the order as we load it, then
1538 * when we scan it we stop as soon as we get a match.
1540 cur_acl->next = config->acl;
1541 config->acl = cur_acl;
1544 #endif /* def FEATURE_ACL */
1546 /* *************************************************************************
1547 * proxy-info-url url
1548 * *************************************************************************/
1549 case hash_proxy_info_url :
1550 freez(config->proxy_info_url);
1551 config->proxy_info_url = strdup_or_die(arg);
1555 /* *************************************************************************
1556 * receive-buffer-size n
1557 * *************************************************************************/
1558 case hash_receive_buffer_size :
1559 config->receive_buffer_size = (size_t)parse_numeric_value(cmd, arg);
1560 if (config->receive_buffer_size < BUFFER_SIZE)
1562 log_error(LOG_LEVEL_INFO,
1563 "receive-buffer-size %d seems low and may cause problems."
1564 "Consider setting it to at least %d.",
1565 config->receive_buffer_size, BUFFER_SIZE);
1569 /* *************************************************************************
1570 * single-threaded 0|1
1571 * *************************************************************************/
1572 case hash_single_threaded :
1573 config->multi_threaded = 0 == parse_toggle_state(cmd, arg);
1576 /* *************************************************************************
1577 * socket-timeout numer_of_seconds
1578 * *************************************************************************/
1579 case hash_socket_timeout :
1581 int socket_timeout = parse_numeric_value(cmd, arg);
1582 if (0 <= socket_timeout)
1584 config->socket_timeout = socket_timeout;
1588 log_error(LOG_LEVEL_FATAL, "Invalid socket-timeout: '%s'", arg);
1593 /* *************************************************************************
1594 * split-large-cgi-forms
1595 * *************************************************************************/
1596 case hash_split_large_cgi_forms :
1597 if (parse_toggle_state(cmd, arg) == 1)
1599 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1603 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1607 /* *************************************************************************
1608 * templdir directory-name
1609 * *************************************************************************/
1610 case hash_templdir :
1611 freez(config->templdir);
1612 config->templdir = make_path(NULL, arg);
1615 #ifdef FEATURE_EXTERNAL_FILTERS
1616 /* *************************************************************************
1617 * temporary-directory directory-name
1618 * *************************************************************************/
1619 case hash_temporary_directory :
1620 freez(config->temporary_directory);
1621 config->temporary_directory = make_path(NULL, arg);
1625 /* *************************************************************************
1626 * tolerate-pipelining (0|1)
1627 * *************************************************************************/
1628 case hash_tolerate_pipelining :
1629 if (parse_toggle_state(cmd, arg) == 1)
1631 config->feature_flags |= RUNTIME_FEATURE_TOLERATE_PIPELINING;
1635 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
1639 /* *************************************************************************
1641 * *************************************************************************/
1642 #ifdef FEATURE_TOGGLE
1644 global_toggle_state = parse_toggle_state(cmd, arg);
1646 #endif /* def FEATURE_TOGGLE */
1648 /* *************************************************************************
1649 * trust-info-url url
1650 * *************************************************************************/
1651 #ifdef FEATURE_TRUST
1652 case hash_trust_info_url :
1653 enlist(config->trust_info, arg);
1655 #endif /* def FEATURE_TRUST */
1657 /* *************************************************************************
1658 * trust-x-forwarded-for (0|1)
1659 * *************************************************************************/
1660 case hash_trust_x_forwarded_for :
1661 config->trust_x_forwarded_for = parse_toggle_state(cmd, arg);
1664 /* *************************************************************************
1665 * trusted-cgi-referrer http://www.example.org/some/path.html
1666 * *************************************************************************/
1667 case hash_trusted_cgi_referrer :
1669 * We don't validate the specified referrer as
1670 * it's only used for string comparison.
1672 freez(config->trusted_cgi_referrer);
1673 config->trusted_cgi_referrer = strdup_or_die(arg);
1676 /* *************************************************************************
1677 * trustfile filename
1678 * (In confdir by default.)
1679 * *************************************************************************/
1680 #ifdef FEATURE_TRUST
1681 case hash_trustfile :
1682 freez(config->trustfile);
1683 config->trustfile = make_path(config->confdir, arg);
1685 #endif /* def FEATURE_TRUST */
1687 /* *************************************************************************
1689 * *************************************************************************/
1690 case hash_usermanual :
1692 * XXX: If this isn't the first config directive, the
1693 * show-status page links to the website documentation
1694 * for the directives that were already parsed. Lame.
1696 freez(config->usermanual);
1697 config->usermanual = strdup_or_die(arg);
1700 /* *************************************************************************
1701 * Win32 Console options:
1702 * *************************************************************************/
1704 /* *************************************************************************
1706 * *************************************************************************/
1708 case hash_hide_console :
1711 #endif /*def _WIN_CONSOLE*/
1714 /* *************************************************************************
1715 * Win32 GUI options:
1716 * *************************************************************************/
1718 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1719 /* *************************************************************************
1720 * activity-animation (0|1)
1721 * *************************************************************************/
1722 case hash_activity_animation :
1723 g_bShowActivityAnimation = parse_toggle_state(cmd, arg);
1726 /* *************************************************************************
1727 * close-button-minimizes (0|1)
1728 * *************************************************************************/
1729 case hash_close_button_minimizes :
1730 g_bCloseHidesWindow = parse_toggle_state(cmd, arg);
1733 /* *************************************************************************
1734 * log-buffer-size (0|1)
1735 * *************************************************************************/
1736 case hash_log_buffer_size :
1737 g_bLimitBufferSize = parse_toggle_state(cmd, arg);
1740 /* *************************************************************************
1741 * log-font-name fontname
1742 * *************************************************************************/
1743 case hash_log_font_name :
1744 if (strlcpy(g_szFontFaceName, arg,
1745 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1747 log_error(LOG_LEVEL_FATAL,
1748 "log-font-name argument '%s' is longer than %u characters.",
1749 arg, sizeof(g_szFontFaceName)-1);
1753 /* *************************************************************************
1755 * *************************************************************************/
1756 case hash_log_font_size :
1757 g_nFontSize = parse_numeric_value(cmd, arg);
1760 /* *************************************************************************
1761 * log-highlight-messages (0|1)
1762 * *************************************************************************/
1763 case hash_log_highlight_messages :
1764 g_bHighlightMessages = parse_toggle_state(cmd, arg);
1767 /* *************************************************************************
1769 * *************************************************************************/
1770 case hash_log_max_lines :
1771 g_nMaxBufferLines = parse_numeric_value(cmd, arg);
1774 /* *************************************************************************
1775 * log-messages (0|1)
1776 * *************************************************************************/
1777 case hash_log_messages :
1778 g_bLogMessages = parse_toggle_state(cmd, arg);
1781 /* *************************************************************************
1782 * show-on-task-bar (0|1)
1783 * *************************************************************************/
1784 case hash_show_on_task_bar :
1785 g_bShowOnTaskBar = parse_toggle_state(cmd, arg);
1788 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1791 /* *************************************************************************
1792 * Warnings about unsupported features
1793 * *************************************************************************/
1795 case hash_deny_access:
1796 #endif /* ndef FEATURE_ACL */
1797 #ifndef FEATURE_CGI_EDIT_ACTIONS
1798 case hash_enable_edit_actions:
1799 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1800 #ifndef FEATURE_TOGGLE
1801 case hash_enable_remote_toggle:
1802 #endif /* ndef FEATURE_TOGGLE */
1804 case hash_permit_access:
1805 #endif /* ndef FEATURE_ACL */
1806 #ifndef FEATURE_TOGGLE
1808 #endif /* ndef FEATURE_TOGGLE */
1809 #ifndef FEATURE_TRUST
1810 case hash_trustfile :
1811 case hash_trust_info_url :
1812 #endif /* ndef FEATURE_TRUST */
1814 #ifndef _WIN_CONSOLE
1815 case hash_hide_console :
1816 #endif /* ndef _WIN_CONSOLE */
1818 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1819 case hash_activity_animation :
1820 case hash_close_button_minimizes :
1821 case hash_log_buffer_size :
1822 case hash_log_font_name :
1823 case hash_log_font_size :
1824 case hash_log_highlight_messages :
1825 case hash_log_max_lines :
1826 case hash_log_messages :
1827 case hash_show_on_task_bar :
1828 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1829 /* These warnings are annoying - so hide them. -- Jon */
1830 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1833 /* *************************************************************************/
1835 /* *************************************************************************/
1837 * I decided that I liked this better as a warning than an
1838 * error. To change back to an error, just change log level
1839 * to LOG_LEVEL_FATAL.
1841 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive "
1842 "'%s' (%uU) in line %lu in configuration file (%s).",
1843 buf, directive_hash, linenum, configfile);
1844 string_append(&config->proxy_args,
1845 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1848 /* *************************************************************************/
1849 } /* end switch(hash_string(cmd)) */
1851 /* Save the argument for the show-status page. */
1852 savearg(cmd, arg, config);
1854 } /* end while (read_config_line(...)) */
1858 set_debug_level(config->debug);
1860 freez(config->logfile);
1864 if (NULL != logfile)
1866 config->logfile = logfile;
1867 init_error_log(Argv[0], config->logfile);
1875 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1876 if (config->default_server_timeout > config->keep_alive_timeout)
1878 log_error(LOG_LEVEL_ERROR,
1879 "Reducing the default-server-timeout from %d to the keep-alive-timeout %d.",
1880 config->default_server_timeout, config->keep_alive_timeout);
1881 config->default_server_timeout = config->keep_alive_timeout;
1883 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
1885 #ifdef FEATURE_CONNECTION_SHARING
1886 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1888 if (!config->multi_threaded)
1891 * While we could use keep-alive without multiple threads
1892 * if we didn't bother with enforcing the connection timeout,
1893 * that might make Tor users sad, even though they shouldn't
1894 * enable the single-threaded option anyway.
1896 * XXX: We could still use Proxy-Connection: keep-alive.
1898 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1899 log_error(LOG_LEVEL_ERROR,
1900 "Config option single-threaded disables connection keep-alive.");
1903 else if ((config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING))
1905 log_error(LOG_LEVEL_ERROR, "Config option connection-sharing "
1906 "has no effect if keep-alive-timeout isn't set.");
1907 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
1909 #endif /* def FEATURE_CONNECTION_SHARING */
1911 if (NULL == config->proxy_args)
1913 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1916 if (config->re_filterfile[0])
1918 add_loader(load_re_filterfiles, config);
1921 if (config->actions_file[0])
1923 add_loader(load_action_files, config);
1926 #ifdef FEATURE_TRUST
1927 if (config->trustfile)
1929 add_loader(load_trustfile, config);
1931 #endif /* def FEATURE_TRUST */
1933 if (NULL == config->haddr[0])
1935 config->haddr[0] = strdup_or_die(HADDR_DEFAULT);
1938 for (i = 0; i < MAX_LISTENING_SOCKETS && NULL != config->haddr[i]; i++)
1940 if ((*config->haddr[i] == '[')
1941 && (NULL != (p = strchr(config->haddr[i], ']')))
1943 && (0 < (config->hport[i] = atoi(p + 2))))
1946 memmove((void *)config->haddr[i], config->haddr[i] + 1,
1947 (size_t)(p - config->haddr[i]));
1949 else if (NULL != (p = strchr(config->haddr[i], ':'))
1950 && (0 < (config->hport[i] = atoi(p + 1))))
1956 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr[i]);
1957 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1959 if (*config->haddr[i] == '\0')
1962 * Only the port specified. We stored it in config->hport[i]
1963 * and don't need its text representation anymore.
1964 * Use config->hport[i] == 0 to iterate listening addresses since
1967 freez(config->haddr[i]);
1972 * Want to run all the loaders once now.
1974 * Need to set up a fake csp, so they can get to the config.
1976 fake_csp = zalloc_or_die(sizeof(*fake_csp));
1977 fake_csp->config = config;
1979 if (run_loader(fake_csp))
1982 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1983 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1987 /* FIXME: this is a kludge for win32 */
1988 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1990 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1991 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1992 g_default_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1993 g_user_filterfile = config->re_filterfile[1]; /* FIXME Hope this is user.filter */
1995 #ifdef FEATURE_TRUST
1996 g_trustfile = config->trustfile;
1997 #endif /* def FEATURE_TRUST */
2000 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
2001 /* FIXME: end kludge */
2004 if (current_configfile == NULL)
2006 config->need_bind = 1;
2010 struct configuration_spec * oldcfg = (struct configuration_spec *)
2011 current_configfile->f;
2013 * Check if config->haddr[i],hport[i] == oldcfg->haddr[i],hport[i]
2015 config->need_bind = 0;
2017 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
2019 if (config->hport[i] != oldcfg->hport[i])
2021 config->need_bind = 1;
2023 else if (config->haddr[i] == NULL)
2025 if (oldcfg->haddr[i] != NULL)
2027 config->need_bind = 1;
2030 else if (oldcfg->haddr[i] == NULL)
2032 config->need_bind = 1;
2034 else if (0 != strcmp(config->haddr[i], oldcfg->haddr[i]))
2036 config->need_bind = 1;
2040 current_configfile->unloader = unload_configfile;
2043 fs->next = files->next;
2046 current_configfile = fs;
2052 /*********************************************************************
2054 * Function : savearg
2056 * Description : Called from `load_config'. It saves each non-empty
2057 * and non-comment line from config into
2058 * config->proxy_args. This is used to create the
2059 * show-status page. On error, frees
2060 * config->proxy_args and sets it to NULL
2063 * 1 : command = config setting that was found
2064 * 2 : argument = the setting's argument (if any)
2065 * 3 : config = Configuration to save into.
2069 *********************************************************************/
2070 static void savearg(char *command, char *argument, struct configuration_spec * config)
2079 * Add config option name embedded in
2080 * link to its section in the user-manual
2082 buf = strdup_or_die("\n<a href=\"");
2083 if (!strncmpic(config->usermanual, "file://", 7) ||
2084 !strncmpic(config->usermanual, "http", 4))
2086 string_append(&buf, config->usermanual);
2090 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
2092 string_append(&buf, CONFIG_HELP_PREFIX);
2093 string_join (&buf, string_toupper(command));
2094 string_append(&buf, "\">");
2095 string_append(&buf, command);
2096 string_append(&buf, "</a> ");
2100 freez(config->proxy_args);
2104 if ((NULL != argument) && ('\0' != *argument))
2106 s = html_encode(argument);
2110 freez(config->proxy_args);
2114 if (strncmpic(argument, "http://", 7) == 0)
2116 string_append(&buf, "<a href=\"");
2117 string_append(&buf, s);
2118 string_append(&buf, "\">");
2119 string_join (&buf, s);
2120 string_append(&buf, "</a>");
2124 string_join (&buf, s);
2128 string_append(&buf, "<br>");
2129 string_join(&config->proxy_args, buf);