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_debug 78263U /* "debug" */
145 #define hash_default_server_timeout 2530089913U /* "default-server-timeout" */
146 #define hash_deny_access 1227333715U /* "deny-access" */
147 #define hash_enable_accept_filter 2909040407U /* "enable-accept-filter" */
148 #define hash_enable_edit_actions 2517097536U /* "enable-edit-actions" */
149 #define hash_enable_compression 3943696946U /* "enable-compression" */
150 #define hash_enable_proxy_authentication_forwarding 4040610791U /* enable-proxy-authentication-forwarding */
151 #define hash_enable_remote_toggle 2979744683U /* "enable-remote-toggle" */
152 #define hash_enable_remote_http_toggle 110543988U /* "enable-remote-http-toggle" */
153 #define hash_enforce_blocks 1862427469U /* "enforce-blocks" */
154 #define hash_filterfile 250887266U /* "filterfile" */
155 #define hash_forward 2029845U /* "forward" */
156 #define hash_forward_socks4 3963965521U /* "forward-socks4" */
157 #define hash_forward_socks4a 2639958518U /* "forward-socks4a" */
158 #define hash_forward_socks5 3963965522U /* "forward-socks5" */
159 #define hash_forward_socks5t 2639958542U /* "forward-socks5t" */
160 #define hash_forwarded_connect_retries 101465292U /* "forwarded-connect-retries" */
161 #define hash_handle_as_empty_returns_ok 1444873247U /* "handle-as-empty-doc-returns-ok" */
162 #define hash_hostname 10308071U /* "hostname" */
163 #define hash_keep_alive_timeout 3878599515U /* "keep-alive-timeout" */
164 #define hash_listen_address 1255650842U /* "listen-address" */
165 #define hash_listen_backlog 1255655735U /* "listen-backlog" */
166 #define hash_logdir 422889U /* "logdir" */
167 #define hash_logfile 2114766U /* "logfile" */
168 #define hash_max_client_connections 3595884446U /* "max-client-connections" */
169 #define hash_permit_access 3587953268U /* "permit-access" */
170 #define hash_proxy_info_url 3903079059U /* "proxy-info-url" */
171 #define hash_receive_buffer_size 2880297454U /* "receive-buffer-size */
172 #define hash_single_threaded 4250084780U /* "single-threaded" */
173 #define hash_socket_timeout 1809001761U /* "socket-timeout" */
174 #define hash_split_large_cgi_forms 671658948U /* "split-large-cgi-forms" */
175 #define hash_suppress_blocklists 1948693308U /* "suppress-blocklists" */
176 #define hash_templdir 11067889U /* "templdir" */
177 #define hash_temporary_directory 1824125181U /* "temporary-directory" */
178 #define hash_tolerate_pipelining 1360286620U /* "tolerate-pipelining" */
179 #define hash_toggle 447966U /* "toggle" */
180 #define hash_trust_info_url 430331967U /* "trust-info-url" */
181 #define hash_trust_x_forwarded_for 2971537414U /* "trust-x-forwarded-for" */
182 #define hash_trusted_cgi_referrer 4270883427U /* "trusted-cgi-referrer" */
183 #define hash_trustfile 56494766U /* "trustfile" */
184 #define hash_usermanual 1416668518U /* "user-manual" */
185 #define hash_activity_animation 1817904738U /* "activity-animation" */
186 #define hash_close_button_minimizes 3651284693U /* "close-button-minimizes" */
187 #define hash_hide_console 2048809870U /* "hide-console" */
188 #define hash_log_buffer_size 2918070425U /* "log-buffer-size" */
189 #define hash_log_font_name 2866730124U /* "log-font-name" */
190 #define hash_log_font_size 2866731014U /* "log-font-size" */
191 #define hash_log_highlight_messages 4032101240U /* "log-highlight-messages" */
192 #define hash_log_max_lines 2868344173U /* "log-max-lines" */
193 #define hash_log_messages 2291744899U /* "log-messages" */
194 #define hash_show_on_task_bar 215410365U /* "show-on-task-bar" */
197 static void savearg(char *command, char *argument, struct configuration_spec * config);
198 #ifdef FEATURE_CLIENT_TAGS
199 static void free_client_specific_tags(struct client_tag_spec *tag_list);
202 /*********************************************************************
204 * Function : unload_configfile
206 * Description : Free the config structure and all components.
209 * 1 : data: struct configuration_spec to unload
213 *********************************************************************/
214 static void unload_configfile (void * data)
216 struct configuration_spec * config = (struct configuration_spec *)data;
217 struct forward_spec *cur_fwd = config->forward;
221 struct access_control_list *cur_acl = config->acl;
223 while (cur_acl != NULL)
225 struct access_control_list * next_acl = cur_acl->next;
230 #endif /* def FEATURE_ACL */
232 while (cur_fwd != NULL)
234 struct forward_spec * next_fwd = cur_fwd->next;
235 free_pattern_spec(cur_fwd->url);
237 freez(cur_fwd->gateway_host);
238 freez(cur_fwd->forward_host);
242 config->forward = NULL;
244 freez(config->confdir);
245 freez(config->logdir);
246 freez(config->templdir);
247 freez(config->hostname);
248 #ifdef FEATURE_EXTERNAL_FILTERS
249 freez(config->temporary_directory);
252 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
254 freez(config->haddr[i]);
256 freez(config->logfile);
258 for (i = 0; i < MAX_AF_FILES; i++)
260 freez(config->actions_file_short[i]);
261 freez(config->actions_file[i]);
262 freez(config->re_filterfile_short[i]);
263 freez(config->re_filterfile[i]);
266 list_remove_all(config->ordered_client_headers);
268 freez(config->admin_address);
269 freez(config->proxy_info_url);
270 freez(config->proxy_args);
271 freez(config->usermanual);
272 freez(config->trusted_cgi_referrer);
275 freez(config->trustfile);
276 list_remove_all(config->trust_info);
277 #endif /* def FEATURE_TRUST */
279 #ifdef FEATURE_CLIENT_TAGS
280 free_client_specific_tags(config->client_tags);
287 #ifdef FEATURE_GRACEFUL_TERMINATION
288 /*********************************************************************
290 * Function : unload_current_config_file
292 * Description : Unloads current config file - reset to state at
293 * beginning of program.
299 *********************************************************************/
300 void unload_current_config_file(void)
302 if (current_configfile)
304 current_configfile->unloader = unload_configfile;
305 current_configfile = NULL;
311 #ifdef FEATURE_CLIENT_TAGS
312 /*********************************************************************
314 * Function : register_tag
316 * Description : Registers a client-specific-tag and its description
319 * 1 : config: The tag list
320 * 2 : name: The name of the client-specific-tag
321 * 3 : description: The human-readable description for the tag
325 *********************************************************************/
326 static void register_tag(struct client_tag_spec *tag_list,
327 const char *name, const char *description)
329 struct client_tag_spec *new_tag;
330 struct client_tag_spec *last_tag;
333 while (last_tag->next != NULL)
335 last_tag = last_tag->next;
337 if (last_tag->name == NULL)
344 new_tag = zalloc_or_die(sizeof(struct client_tag_spec));
346 new_tag->name = strdup_or_die(name);
347 new_tag->description = strdup_or_die(description);
348 if (new_tag != last_tag)
350 last_tag->next = new_tag;
355 /*********************************************************************
357 * Function : free_client_specific_tags
359 * Description : Frees client-specific tags and their descriptions
362 * 1 : tag_list: The tag list to free
366 *********************************************************************/
367 static void free_client_specific_tags(struct client_tag_spec *tag_list)
369 struct client_tag_spec *this_tag;
370 struct client_tag_spec *next_tag;
376 next_tag = next_tag->next;
378 freez(this_tag->name);
379 freez(this_tag->description);
381 if (this_tag != tag_list)
385 } while (next_tag != NULL);
387 #endif /* def FEATURE_CLIENT_TAGS */
390 /*********************************************************************
392 * Function : parse_numeric_value
394 * Description : Parse the value of a directive that can only have
395 * a single numeric value. Terminates with a fatal error
396 * if the value is NULL or not numeric.
399 * 1 : name: The name of the directive. Used for log messages.
400 * 2 : value: The value to parse
403 * Returns : The numerical value as integer
405 *********************************************************************/
406 static int parse_numeric_value(const char *name, const char *value)
411 assert(name != NULL);
412 assert(value != NULL);
414 if ((value == NULL) || (*value == '\0'))
416 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
419 number = (int)strtol(value, &endptr, 0);
422 log_error(LOG_LEVEL_FATAL,
423 "Directive '%s' used with non-numerical value: '%s'", name, value);
431 /*********************************************************************
433 * Function : parse_toggle_value
435 * Description : Parse the value of a directive that can only be
436 * enabled or disabled. Terminates with a fatal error
437 * if the value is NULL or something other than 0 or 1.
440 * 1 : name: The name of the directive. Used for log messages.
441 * 2 : value: The value to parse
444 * Returns : The numerical toggle state
446 *********************************************************************/
447 static int parse_toggle_state(const char *name, const char *value)
450 assert(name != NULL);
451 assert(value != NULL);
453 if ((value == NULL) || (*value == '\0'))
455 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
458 toggle_state = atoi(value);
461 * Also check the length as atoi() doesn't mind
462 * garbage after a valid integer, but we do.
464 if (((toggle_state != 0) && (toggle_state != 1)) || (strlen(value) != 1))
466 log_error(LOG_LEVEL_FATAL,
467 "Directive %s used with invalid argument '%s'. Use either '0' or '1'.",
476 /*********************************************************************
478 * Function : parse_client_header_order
480 * Description : Parse the value of the header-order directive
483 * 1 : ordered_header_list: List to insert the ordered
485 * 2 : ordered_headers: The ordered header names separated
491 *********************************************************************/
492 static void parse_client_header_order(struct list *ordered_header_list, const char *ordered_headers)
494 char *original_headers_copy;
497 int number_of_headers;
500 assert(ordered_header_list != NULL);
501 assert(ordered_headers != NULL);
503 if (ordered_headers == NULL)
505 log_error(LOG_LEVEL_FATAL, "header-order used without argument");
509 * XXX: This estimate is guaranteed to be high enough as we
510 * let ssplit() ignore empty fields, but also a bit wasteful.
511 * The same hack is used in get_last_url() so it looks like
512 * a real solution is needed.
514 max_segments = strlen(ordered_headers) / 2;
515 if (max_segments == 0)
519 vector = malloc_or_die(max_segments * sizeof(char *));
521 original_headers_copy = strdup_or_die(ordered_headers);
523 number_of_headers = ssplit(original_headers_copy, "\t ", vector, max_segments);
524 if (number_of_headers == -1)
526 log_error(LOG_LEVEL_FATAL, "Failed to split ordered headers");
529 for (i = 0; i < number_of_headers; i++)
531 if (JB_ERR_OK != enlist(ordered_header_list, vector[i]))
533 log_error(LOG_LEVEL_FATAL,
534 "Failed to enlist ordered header: %s", vector[i]);
539 freez(original_headers_copy);
546 /*********************************************************************
548 * Function : load_config
550 * Description : Load the config file and all parameters.
552 * XXX: more than thousand lines long
553 * and thus in serious need of refactoring.
557 * Returns : The configuration_spec, or NULL on error.
559 *********************************************************************/
560 struct configuration_spec * load_config(void)
564 FILE *configfp = NULL;
565 struct configuration_spec * config = NULL;
566 struct client_state * fake_csp;
567 struct file_list *fs;
568 unsigned long linenum = 0;
570 char *logfile = NULL;
572 if (!check_file_changed(current_configfile, configfile, &fs))
574 /* No need to load */
575 return ((struct configuration_spec *)current_configfile->f);
579 log_error(LOG_LEVEL_FATAL,
580 "can't check configuration file '%s': %E", configfile);
584 if (NULL != current_configfile)
586 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
589 #ifdef FEATURE_TOGGLE
590 global_toggle_state = 1;
591 #endif /* def FEATURE_TOGGLE */
593 fs->f = config = zalloc_or_die(sizeof(*config));
596 * This is backwards from how it's usually done.
597 * Following the usual pattern, "fs" would be stored in a member
598 * variable in "csp", and then we'd access "config" from "fs->f",
599 * using a cast. However, "config" is used so often that a
600 * cast each time would be very ugly, and the extra indirection
601 * would waste CPU cycles. Therefore we store "config" in
602 * "csp->config", and "fs" in "csp->config->config_file_list".
604 config->config_file_list = fs;
609 config->multi_threaded = 1;
610 config->buffer_limit = 4096 * 1024;
611 config->receive_buffer_size = BUFFER_SIZE;
612 config->usermanual = strdup_or_die(USER_MANUAL_URL);
613 config->proxy_args = strdup_or_die("");
614 config->forwarded_connect_retries = 0;
615 #ifdef FEATURE_CLIENT_TAGS
616 config->client_tag_lifetime = 60;
618 config->trust_x_forwarded_for = 0;
619 #if defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER)
620 config->enable_accept_filter = 0;
622 config->listen_backlog = DEFAULT_LISTEN_BACKLOG;
623 config->trusted_cgi_referrer = NULL;
625 * 128 client sockets ought to be enough for everybody who can't
626 * be bothered to read the documentation to figure out how to
627 * increase the limit.
629 config->max_client_connections = 128;
630 config->socket_timeout = 300; /* XXX: Should be a macro. */
631 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
632 config->default_server_timeout = 0;
633 config->keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
634 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
635 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
637 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
638 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
639 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
640 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
641 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
642 #ifdef FEATURE_COMPRESSION
643 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
645 * XXX: Run some benchmarks to see if there are better default values.
647 config->compression_level = 1;
649 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
651 configfp = fopen(configfile, "r");
652 if (NULL == configfp)
654 log_error(LOG_LEVEL_FATAL,
655 "can't open configuration file '%s': %E", configfile);
656 /* Never get here - LOG_LEVEL_FATAL causes program exit */
659 while (read_config_line(configfp, &linenum, &buf) != NULL)
661 char cmd[BUFFER_SIZE];
662 char arg[BUFFER_SIZE];
663 char tmp[BUFFER_SIZE];
665 struct access_control_list *cur_acl;
666 #endif /* def FEATURE_ACL */
667 struct forward_spec *cur_fwd;
670 unsigned int directive_hash;
672 strlcpy(tmp, buf, sizeof(tmp));
674 /* Copy command (i.e. up to space or tab) into cmd */
677 while (*p && (*p != ' ') && (*p != '\t'))
683 /* Skip over the whitespace in buf */
684 while (*p && ((*p == ' ') || (*p == '\t')))
689 /* Copy the argument into arg */
690 if (strlcpy(arg, p, sizeof(arg)) >= sizeof(arg))
692 log_error(LOG_LEVEL_FATAL, "Config line too long: %s", buf);
695 /* Should never happen, but check this anyway */
702 /* Make sure the command field is lower case */
703 for (p = cmd; *p; p++)
705 if (privoxy_isupper(*p))
707 *p = (char)privoxy_tolower(*p);
711 directive_hash = hash_string(cmd);
712 switch (directive_hash)
714 /* *************************************************************************
715 * actionsfile actions-file-name
716 * In confdir by default
717 * *************************************************************************/
718 case hash_actions_file :
720 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
725 if (i >= MAX_AF_FILES)
727 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
728 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
731 config->actions_file_short[i] = strdup_or_die(arg);
732 config->actions_file[i] = make_path(config->confdir, arg);
735 /* *************************************************************************
736 * accept-intercepted-requests
737 * *************************************************************************/
738 case hash_accept_intercepted_requests:
739 if (parse_toggle_state(cmd, arg) == 1)
741 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
745 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
749 /* *************************************************************************
750 * admin-address email-address
751 * *************************************************************************/
752 case hash_admin_address :
753 freez(config->admin_address);
754 config->admin_address = strdup_or_die(arg);
757 /* *************************************************************************
758 * allow-cgi-request-crunching
759 * *************************************************************************/
760 case hash_allow_cgi_request_crunching:
761 if (parse_toggle_state(cmd, arg) == 1)
763 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
767 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
771 /* *************************************************************************
773 * *************************************************************************/
774 case hash_buffer_limit :
775 config->buffer_limit = (size_t)(1024 * parse_numeric_value(cmd, arg));
778 /* *************************************************************************
779 * client-header-order header-1 header-2 ... header-n
780 * *************************************************************************/
781 case hash_client_header_order:
782 list_remove_all(config->ordered_client_headers);
783 parse_client_header_order(config->ordered_client_headers, arg);
786 /* *************************************************************************
787 * client-specific-tag tag-name description
788 * *************************************************************************/
789 #ifdef FEATURE_CLIENT_TAGS
790 case hash_client_specific_tag:
796 description = strstr(arg, " ");
797 if (description == NULL)
799 log_error(LOG_LEVEL_FATAL,
800 "client-specific-tag '%s' lacks a description.", name);
804 * The length is limited because we don't want truncated
805 * HTML caused by the cgi interface using static buffer
808 if (strlen(name) > CLIENT_TAG_LENGTH_MAX)
810 log_error(LOG_LEVEL_FATAL,
811 "client-specific-tag '%s' is longer than %d characters.",
812 name, CLIENT_TAG_LENGTH_MAX);
815 register_tag(config->client_tags, name, description);
818 #endif /* def FEATURE_CLIENT_TAGS */
820 /* *************************************************************************
821 * client-tag-lifetime ttl
822 * *************************************************************************/
823 #ifdef FEATURE_CLIENT_TAGS
824 case hash_client_tag_lifetime:
826 int ttl = parse_numeric_value(cmd, arg);
829 config->client_tag_lifetime = (unsigned)ttl;
833 log_error(LOG_LEVEL_FATAL,
834 "client-tag-lifetime can't be negative.");
838 #endif /* def FEATURE_CLIENT_TAGS */
840 /* *************************************************************************
841 * confdir directory-name
842 * *************************************************************************/
844 freez(config->confdir);
845 config->confdir = make_path(NULL, arg);
848 /* *************************************************************************
849 * compression-level 0-9
850 * *************************************************************************/
851 #ifdef FEATURE_COMPRESSION
852 case hash_compression_level :
854 int compression_level = parse_numeric_value(cmd, arg);
855 if (-1 <= compression_level && compression_level <= 9)
857 config->compression_level = compression_level;
861 log_error(LOG_LEVEL_FATAL,
862 "Invalid compression-level value: %s", arg);
868 /* *************************************************************************
869 * connection-sharing (0|1)
870 * *************************************************************************/
871 #ifdef FEATURE_CONNECTION_SHARING
872 case hash_connection_sharing :
873 if (parse_toggle_state(cmd, arg) == 1)
875 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_SHARING;
879 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
884 /* *************************************************************************
886 * Specifies debug level, multiple values are ORed together.
887 * *************************************************************************/
889 config->debug |= parse_numeric_value(cmd, arg);
892 /* *************************************************************************
893 * default-server-timeout timeout
894 * *************************************************************************/
895 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
896 case hash_default_server_timeout :
898 int timeout = parse_numeric_value(cmd, arg);
901 config->default_server_timeout = (unsigned int)timeout;
905 log_error(LOG_LEVEL_FATAL,
906 "Invalid default-server-timeout value: %s", arg);
912 /* *************************************************************************
913 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
914 * *************************************************************************/
916 case hash_deny_access:
917 strlcpy(tmp, arg, sizeof(tmp));
918 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
920 if ((vec_count != 1) && (vec_count != 2))
922 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
923 "deny-access directive in configuration file.");
924 string_append(&config->proxy_args,
925 "<br>\nWARNING: Wrong number of parameters for "
926 "deny-access directive in configuration file.<br><br>\n");
930 /* allocate a new node */
931 cur_acl = zalloc_or_die(sizeof(*cur_acl));
932 cur_acl->action = ACL_DENY;
934 if (acl_addr(vec[0], cur_acl->src) < 0)
936 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
937 "for deny-access directive in configuration file: \"%s\"", vec[0]);
938 string_append(&config->proxy_args,
939 "<br>\nWARNING: Invalid source address, port or netmask "
940 "for deny-access directive in configuration file: \"");
941 string_append(&config->proxy_args,
943 string_append(&config->proxy_args,
950 if (acl_addr(vec[1], cur_acl->dst) < 0)
952 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
953 "for deny-access directive in configuration file: \"%s\"", vec[1]);
954 string_append(&config->proxy_args,
955 "<br>\nWARNING: Invalid destination address, port or netmask "
956 "for deny-access directive in configuration file: \"");
957 string_append(&config->proxy_args,
959 string_append(&config->proxy_args,
968 cur_acl->wildcard_dst = 1;
970 #endif /* def HAVE_RFC2553 */
973 * Add it to the list. Note we reverse the list to get the
974 * behaviour the user expects. With both the ACL and
975 * actions file, the last match wins. However, the internal
976 * implementations are different: The actions file is stored
977 * in the same order as the file, and scanned completely.
978 * With the ACL, we reverse the order as we load it, then
979 * when we scan it we stop as soon as we get a match.
981 cur_acl->next = config->acl;
982 config->acl = cur_acl;
985 #endif /* def FEATURE_ACL */
987 #if defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER)
988 /* *************************************************************************
989 * enable-accept-filter 0|1
990 * *************************************************************************/
991 case hash_enable_accept_filter :
992 config->enable_accept_filter = parse_toggle_state(cmd, arg);
994 #endif /* defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER) */
996 /* *************************************************************************
997 * enable-edit-actions 0|1
998 * *************************************************************************/
999 #ifdef FEATURE_CGI_EDIT_ACTIONS
1000 case hash_enable_edit_actions:
1001 if (parse_toggle_state(cmd, arg) == 1)
1003 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1007 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1010 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1012 /* *************************************************************************
1013 * enable-compression 0|1
1014 * *************************************************************************/
1015 #ifdef FEATURE_COMPRESSION
1016 case hash_enable_compression:
1017 if (parse_toggle_state(cmd, arg) == 1)
1019 config->feature_flags |= RUNTIME_FEATURE_COMPRESSION;
1023 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
1026 #endif /* def FEATURE_COMPRESSION */
1028 /* *************************************************************************
1029 * enable-proxy-authentication-forwarding 0|1
1030 * *************************************************************************/
1031 case hash_enable_proxy_authentication_forwarding:
1032 if (parse_toggle_state(cmd, arg) == 1)
1034 config->feature_flags |= RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1038 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1042 /* *************************************************************************
1043 * enable-remote-toggle 0|1
1044 * *************************************************************************/
1045 #ifdef FEATURE_TOGGLE
1046 case hash_enable_remote_toggle:
1047 if (parse_toggle_state(cmd, arg) == 1)
1049 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1053 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1056 #endif /* def FEATURE_TOGGLE */
1058 /* *************************************************************************
1059 * enable-remote-http-toggle 0|1
1060 * *************************************************************************/
1061 case hash_enable_remote_http_toggle:
1062 if (parse_toggle_state(cmd, arg) == 1)
1064 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1068 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1072 /* *************************************************************************
1073 * enforce-blocks 0|1
1074 * *************************************************************************/
1075 case hash_enforce_blocks:
1076 #ifdef FEATURE_FORCE_LOAD
1077 if (parse_toggle_state(cmd, arg) == 1)
1079 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1083 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1086 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1087 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1088 #endif /* def FEATURE_FORCE_LOAD */
1091 /* *************************************************************************
1092 * filterfile file-name
1093 * In confdir by default.
1094 * *************************************************************************/
1095 case hash_filterfile :
1097 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1102 if (i >= MAX_AF_FILES)
1104 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1105 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1108 config->re_filterfile_short[i] = strdup_or_die(arg);
1109 config->re_filterfile[i] = make_path(config->confdir, arg);
1113 /* *************************************************************************
1114 * forward url-pattern (.|http-proxy-host[:port])
1115 * *************************************************************************/
1117 strlcpy(tmp, arg, sizeof(tmp));
1118 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1122 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1123 "directive in configuration file.");
1124 string_append(&config->proxy_args,
1125 "<br>\nWARNING: Wrong number of parameters for "
1126 "forward directive in configuration file.");
1130 /* allocate a new node */
1131 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1132 cur_fwd->type = SOCKS_NONE;
1134 /* Save the URL pattern */
1135 if (create_pattern_spec(cur_fwd->url, vec[0]))
1137 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1138 "directive in configuration file.");
1139 string_append(&config->proxy_args,
1140 "<br>\nWARNING: Bad URL specifier for "
1141 "forward directive in configuration file.");
1146 /* Parse the parent HTTP proxy host:port */
1149 if (strcmp(p, ".") != 0)
1151 cur_fwd->forward_port = 8000;
1152 parse_forwarder_address(p, &cur_fwd->forward_host,
1153 &cur_fwd->forward_port);
1157 cur_fwd->next = config->forward;
1158 config->forward = cur_fwd;
1162 /* *************************************************************************
1163 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1164 * *************************************************************************/
1165 case hash_forward_socks4:
1166 strlcpy(tmp, arg, sizeof(tmp));
1167 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1171 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1172 "forward-socks4 directive in configuration file.");
1173 string_append(&config->proxy_args,
1174 "<br>\nWARNING: Wrong number of parameters for "
1175 "forward-socks4 directive in configuration file.");
1179 /* allocate a new node */
1180 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1181 cur_fwd->type = SOCKS_4;
1183 /* Save the URL pattern */
1184 if (create_pattern_spec(cur_fwd->url, vec[0]))
1186 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1187 "directive in configuration file.");
1188 string_append(&config->proxy_args,
1189 "<br>\nWARNING: Bad URL specifier for "
1190 "forward-socks4 directive in configuration file.");
1195 /* Parse the SOCKS proxy host[:port] */
1198 /* XXX: This check looks like a bug. */
1199 if (strcmp(p, ".") != 0)
1201 cur_fwd->gateway_port = 1080;
1202 parse_forwarder_address(p, &cur_fwd->gateway_host,
1203 &cur_fwd->gateway_port);
1206 /* Parse the parent HTTP proxy host[:port] */
1209 if (strcmp(p, ".") != 0)
1211 cur_fwd->forward_port = 8000;
1212 parse_forwarder_address(p, &cur_fwd->forward_host,
1213 &cur_fwd->forward_port);
1217 cur_fwd->next = config->forward;
1218 config->forward = cur_fwd;
1222 /* *************************************************************************
1223 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1224 * *************************************************************************/
1225 case hash_forward_socks4a:
1226 case hash_forward_socks5:
1227 case hash_forward_socks5t:
1228 strlcpy(tmp, arg, sizeof(tmp));
1229 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1233 log_error(LOG_LEVEL_ERROR,
1234 "Wrong number of parameters for %s in configuration file.",
1236 string_append(&config->proxy_args,
1237 "<br>\nWARNING: Wrong number of parameters for ");
1238 string_append(&config->proxy_args, cmd);
1239 string_append(&config->proxy_args,
1240 "directive in configuration file.");
1244 /* allocate a new node */
1245 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1247 if (directive_hash == hash_forward_socks4a)
1249 cur_fwd->type = SOCKS_4A;
1251 else if (directive_hash == hash_forward_socks5)
1253 cur_fwd->type = SOCKS_5;
1257 assert(directive_hash == hash_forward_socks5t);
1258 cur_fwd->type = SOCKS_5T;
1261 /* Save the URL pattern */
1262 if (create_pattern_spec(cur_fwd->url, vec[0]))
1264 log_error(LOG_LEVEL_ERROR,
1265 "Bad URL specifier for %s in configuration file.",
1267 string_append(&config->proxy_args,
1268 "<br>\nWARNING: Bad URL specifier for ");
1269 string_append(&config->proxy_args, cmd);
1270 string_append(&config->proxy_args,
1271 "directive in configuration file.");
1276 /* Parse the SOCKS proxy host[:port] */
1279 cur_fwd->gateway_port = 1080;
1280 parse_forwarder_address(p, &cur_fwd->gateway_host,
1281 &cur_fwd->gateway_port);
1283 /* Parse the parent HTTP proxy host[:port] */
1286 if (strcmp(p, ".") != 0)
1288 cur_fwd->forward_port = 8000;
1289 parse_forwarder_address(p, &cur_fwd->forward_host,
1290 &cur_fwd->forward_port);
1294 cur_fwd->next = config->forward;
1295 config->forward = cur_fwd;
1299 /* *************************************************************************
1300 * forwarded-connect-retries n
1301 * *************************************************************************/
1302 case hash_forwarded_connect_retries :
1303 config->forwarded_connect_retries = parse_numeric_value(cmd, arg);
1306 /* *************************************************************************
1307 * handle-as-empty-doc-returns-ok 0|1
1309 * Workaround for firefox hanging on blocked javascript pages.
1310 * Block with the "+handle-as-empty-document" flag and set the
1311 * "handle-as-empty-doc-returns-ok" run-time config flag so that
1312 * Privoxy returns a 200/OK status instead of a 403/Forbidden status
1313 * to the browser for blocked pages.
1314 ***************************************************************************/
1315 case hash_handle_as_empty_returns_ok:
1316 if (parse_toggle_state(cmd, arg) == 1)
1318 config->feature_flags |= RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1322 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1326 /* *************************************************************************
1327 * hostname hostname-to-show-on-cgi-pages
1328 * *************************************************************************/
1329 case hash_hostname :
1330 freez(config->hostname);
1331 config->hostname = strdup_or_die(arg);
1334 /* *************************************************************************
1335 * keep-alive-timeout timeout
1336 * *************************************************************************/
1337 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1338 case hash_keep_alive_timeout :
1340 int timeout = parse_numeric_value(cmd, arg);
1343 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1344 config->keep_alive_timeout = (unsigned int)timeout;
1348 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1354 /* *************************************************************************
1355 * listen-address [ip][:port]
1356 * *************************************************************************/
1357 case hash_listen_address :
1359 while ((i < MAX_LISTENING_SOCKETS) && (NULL != config->haddr[i]))
1364 if (i >= MAX_LISTENING_SOCKETS)
1366 log_error(LOG_LEVEL_FATAL, "Too many 'listen-address' directives in config file - limit is %d.\n"
1367 "(You can increase this limit by changing MAX_LISTENING_SOCKETS in project.h and recompiling).",
1368 MAX_LISTENING_SOCKETS);
1370 config->haddr[i] = strdup_or_die(arg);
1373 /* *************************************************************************
1375 * *************************************************************************/
1376 case hash_listen_backlog :
1378 * We don't enfore an upper or lower limit because on
1379 * many platforms all values are valid and negative
1380 * number mean "use the highest value allowed".
1382 config->listen_backlog = parse_numeric_value(cmd, arg);
1385 /* *************************************************************************
1386 * logdir directory-name
1387 * *************************************************************************/
1389 freez(config->logdir);
1390 config->logdir = make_path(NULL, arg);
1393 /* *************************************************************************
1394 * logfile log-file-name
1395 * In logdir by default
1396 * *************************************************************************/
1400 logfile = make_path(config->logdir, arg);
1401 if (NULL == logfile)
1403 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1408 /* *************************************************************************
1409 * max-client-connections number
1410 * *************************************************************************/
1411 case hash_max_client_connections :
1413 int max_client_connections = parse_numeric_value(cmd, arg);
1415 #if !defined(_WIN32) && !defined(HAVE_POLL)
1417 * Reject values below 1 for obvious reasons and values above
1418 * FD_SETSIZE/2 because Privoxy needs two sockets to serve
1419 * client connections that need forwarding.
1421 * We ignore the fact that the first three file descriptors
1422 * are usually set to /dev/null, one is used for logging
1423 * and yet another file descriptor is required to load
1426 if ((max_client_connections < 1) || (FD_SETSIZE/2 < max_client_connections))
1428 log_error(LOG_LEVEL_FATAL, "max-client-connections value %d"
1429 " is invalid. Value needs to be above 1 and below %d"
1430 " (FD_SETSIZE/2).", max_client_connections, FD_SETSIZE/2);
1434 * The Windows libc uses FD_SETSIZE for an array used
1435 * by select(), but has no problems with file descriptors
1436 * above the limit as long as no more than FD_SETSIZE are
1437 * passed to select().
1438 * https://msdn.microsoft.com/en-us/library/windows/desktop/ms739169%28v=vs.85%29.aspx
1440 * On platforms were we use poll() we don't have to enforce
1441 * an upper connection limit either.
1443 * XXX: Do OS/2, Amiga etc. belong here as well?
1445 if (max_client_connections < 1)
1447 log_error(LOG_LEVEL_FATAL, "max-client-connections value"
1448 " has to be a number above 1. %d is invalid.",
1449 max_client_connections);
1452 config->max_client_connections = max_client_connections;
1456 /* *************************************************************************
1457 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1458 * *************************************************************************/
1460 case hash_permit_access:
1461 strlcpy(tmp, arg, sizeof(tmp));
1462 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1464 if ((vec_count != 1) && (vec_count != 2))
1466 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1467 "permit-access directive in configuration file.");
1468 string_append(&config->proxy_args,
1469 "<br>\nWARNING: Wrong number of parameters for "
1470 "permit-access directive in configuration file.<br><br>\n");
1475 /* allocate a new node */
1476 cur_acl = zalloc_or_die(sizeof(*cur_acl));
1477 cur_acl->action = ACL_PERMIT;
1479 if (acl_addr(vec[0], cur_acl->src) < 0)
1481 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1482 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1483 string_append(&config->proxy_args,
1484 "<br>\nWARNING: Invalid source address, port or netmask for "
1485 "permit-access directive in configuration file: \"");
1486 string_append(&config->proxy_args,
1488 string_append(&config->proxy_args,
1495 if (acl_addr(vec[1], cur_acl->dst) < 0)
1497 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1498 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1499 string_append(&config->proxy_args,
1500 "<br>\nWARNING: Invalid destination address, port or netmask for "
1501 "permit-access directive in configuration file: \"");
1502 string_append(&config->proxy_args,
1504 string_append(&config->proxy_args,
1513 cur_acl->wildcard_dst = 1;
1515 #endif /* def HAVE_RFC2553 */
1518 * Add it to the list. Note we reverse the list to get the
1519 * behaviour the user expects. With both the ACL and
1520 * actions file, the last match wins. However, the internal
1521 * implementations are different: The actions file is stored
1522 * in the same order as the file, and scanned completely.
1523 * With the ACL, we reverse the order as we load it, then
1524 * when we scan it we stop as soon as we get a match.
1526 cur_acl->next = config->acl;
1527 config->acl = cur_acl;
1530 #endif /* def FEATURE_ACL */
1532 /* *************************************************************************
1533 * proxy-info-url url
1534 * *************************************************************************/
1535 case hash_proxy_info_url :
1536 freez(config->proxy_info_url);
1537 config->proxy_info_url = strdup_or_die(arg);
1541 /* *************************************************************************
1542 * receive-buffer-size n
1543 * *************************************************************************/
1544 case hash_receive_buffer_size :
1545 config->receive_buffer_size = (size_t)parse_numeric_value(cmd, arg);
1546 if (config->receive_buffer_size < BUFFER_SIZE)
1548 log_error(LOG_LEVEL_INFO,
1549 "receive-buffer-size %d seems low and may cause problems."
1550 "Consider setting it to at least %d.",
1551 config->receive_buffer_size, BUFFER_SIZE);
1555 /* *************************************************************************
1556 * single-threaded 0|1
1557 * *************************************************************************/
1558 case hash_single_threaded :
1559 config->multi_threaded = 0 == parse_toggle_state(cmd, arg);
1562 /* *************************************************************************
1563 * socket-timeout numer_of_seconds
1564 * *************************************************************************/
1565 case hash_socket_timeout :
1567 int socket_timeout = parse_numeric_value(cmd, arg);
1568 if (0 <= socket_timeout)
1570 config->socket_timeout = socket_timeout;
1574 log_error(LOG_LEVEL_FATAL, "Invalid socket-timeout: '%s'", arg);
1579 /* *************************************************************************
1580 * split-large-cgi-forms
1581 * *************************************************************************/
1582 case hash_split_large_cgi_forms :
1583 if (parse_toggle_state(cmd, arg) == 1)
1585 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1589 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1593 /* *************************************************************************
1594 * templdir directory-name
1595 * *************************************************************************/
1596 case hash_templdir :
1597 freez(config->templdir);
1598 config->templdir = make_path(NULL, arg);
1601 #ifdef FEATURE_EXTERNAL_FILTERS
1602 /* *************************************************************************
1603 * temporary-directory directory-name
1604 * *************************************************************************/
1605 case hash_temporary_directory :
1606 freez(config->temporary_directory);
1607 config->temporary_directory = make_path(NULL, arg);
1611 /* *************************************************************************
1612 * tolerate-pipelining (0|1)
1613 * *************************************************************************/
1614 case hash_tolerate_pipelining :
1615 if (parse_toggle_state(cmd, arg) == 1)
1617 config->feature_flags |= RUNTIME_FEATURE_TOLERATE_PIPELINING;
1621 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
1625 /* *************************************************************************
1627 * *************************************************************************/
1628 #ifdef FEATURE_TOGGLE
1630 global_toggle_state = parse_toggle_state(cmd, arg);
1632 #endif /* def FEATURE_TOGGLE */
1634 /* *************************************************************************
1635 * trust-info-url url
1636 * *************************************************************************/
1637 #ifdef FEATURE_TRUST
1638 case hash_trust_info_url :
1639 enlist(config->trust_info, arg);
1641 #endif /* def FEATURE_TRUST */
1643 /* *************************************************************************
1644 * trust-x-forwarded-for (0|1)
1645 * *************************************************************************/
1646 case hash_trust_x_forwarded_for :
1647 config->trust_x_forwarded_for = parse_toggle_state(cmd, arg);
1650 /* *************************************************************************
1651 * trusted-cgi-referrer http://www.example.org/some/path.html
1652 * *************************************************************************/
1653 case hash_trusted_cgi_referrer :
1655 * We don't validate the specified referrer as
1656 * it's only used for string comparison.
1658 freez(config->trusted_cgi_referrer);
1659 config->trusted_cgi_referrer = strdup_or_die(arg);
1662 /* *************************************************************************
1663 * trustfile filename
1664 * (In confdir by default.)
1665 * *************************************************************************/
1666 #ifdef FEATURE_TRUST
1667 case hash_trustfile :
1668 freez(config->trustfile);
1669 config->trustfile = make_path(config->confdir, arg);
1671 #endif /* def FEATURE_TRUST */
1673 /* *************************************************************************
1675 * *************************************************************************/
1676 case hash_usermanual :
1678 * XXX: If this isn't the first config directive, the
1679 * show-status page links to the website documentation
1680 * for the directives that were already parsed. Lame.
1682 freez(config->usermanual);
1683 config->usermanual = strdup_or_die(arg);
1686 /* *************************************************************************
1687 * Win32 Console options:
1688 * *************************************************************************/
1690 /* *************************************************************************
1692 * *************************************************************************/
1694 case hash_hide_console :
1697 #endif /*def _WIN_CONSOLE*/
1700 /* *************************************************************************
1701 * Win32 GUI options:
1702 * *************************************************************************/
1704 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1705 /* *************************************************************************
1706 * activity-animation (0|1)
1707 * *************************************************************************/
1708 case hash_activity_animation :
1709 g_bShowActivityAnimation = parse_toggle_state(cmd, arg);
1712 /* *************************************************************************
1713 * close-button-minimizes (0|1)
1714 * *************************************************************************/
1715 case hash_close_button_minimizes :
1716 g_bCloseHidesWindow = parse_toggle_state(cmd, arg);
1719 /* *************************************************************************
1720 * log-buffer-size (0|1)
1721 * *************************************************************************/
1722 case hash_log_buffer_size :
1723 g_bLimitBufferSize = parse_toggle_state(cmd, arg);
1726 /* *************************************************************************
1727 * log-font-name fontname
1728 * *************************************************************************/
1729 case hash_log_font_name :
1730 if (strlcpy(g_szFontFaceName, arg,
1731 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1733 log_error(LOG_LEVEL_FATAL,
1734 "log-font-name argument '%s' is longer than %u characters.",
1735 arg, sizeof(g_szFontFaceName)-1);
1739 /* *************************************************************************
1741 * *************************************************************************/
1742 case hash_log_font_size :
1743 g_nFontSize = parse_numeric_value(cmd, arg);
1746 /* *************************************************************************
1747 * log-highlight-messages (0|1)
1748 * *************************************************************************/
1749 case hash_log_highlight_messages :
1750 g_bHighlightMessages = parse_toggle_state(cmd, arg);
1753 /* *************************************************************************
1755 * *************************************************************************/
1756 case hash_log_max_lines :
1757 g_nMaxBufferLines = parse_numeric_value(cmd, arg);
1760 /* *************************************************************************
1761 * log-messages (0|1)
1762 * *************************************************************************/
1763 case hash_log_messages :
1764 g_bLogMessages = parse_toggle_state(cmd, arg);
1767 /* *************************************************************************
1768 * show-on-task-bar (0|1)
1769 * *************************************************************************/
1770 case hash_show_on_task_bar :
1771 g_bShowOnTaskBar = parse_toggle_state(cmd, arg);
1774 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1777 /* *************************************************************************
1778 * Warnings about unsupported features
1779 * *************************************************************************/
1781 case hash_deny_access:
1782 #endif /* ndef FEATURE_ACL */
1783 #ifndef FEATURE_CGI_EDIT_ACTIONS
1784 case hash_enable_edit_actions:
1785 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1786 #ifndef FEATURE_TOGGLE
1787 case hash_enable_remote_toggle:
1788 #endif /* ndef FEATURE_TOGGLE */
1790 case hash_permit_access:
1791 #endif /* ndef FEATURE_ACL */
1792 #ifndef FEATURE_TOGGLE
1794 #endif /* ndef FEATURE_TOGGLE */
1795 #ifndef FEATURE_TRUST
1796 case hash_trustfile :
1797 case hash_trust_info_url :
1798 #endif /* ndef FEATURE_TRUST */
1800 #ifndef _WIN_CONSOLE
1801 case hash_hide_console :
1802 #endif /* ndef _WIN_CONSOLE */
1804 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1805 case hash_activity_animation :
1806 case hash_close_button_minimizes :
1807 case hash_log_buffer_size :
1808 case hash_log_font_name :
1809 case hash_log_font_size :
1810 case hash_log_highlight_messages :
1811 case hash_log_max_lines :
1812 case hash_log_messages :
1813 case hash_show_on_task_bar :
1814 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1815 /* These warnings are annoying - so hide them. -- Jon */
1816 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1819 /* *************************************************************************/
1821 /* *************************************************************************/
1823 * I decided that I liked this better as a warning than an
1824 * error. To change back to an error, just change log level
1825 * to LOG_LEVEL_FATAL.
1827 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive "
1828 "'%s' (%uU) in line %lu in configuration file (%s).",
1829 buf, directive_hash, linenum, configfile);
1830 string_append(&config->proxy_args,
1831 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1834 /* *************************************************************************/
1835 } /* end switch(hash_string(cmd)) */
1837 /* Save the argument for the show-status page. */
1838 savearg(cmd, arg, config);
1840 } /* end while (read_config_line(...)) */
1844 set_debug_level(config->debug);
1846 freez(config->logfile);
1850 if (NULL != logfile)
1852 config->logfile = logfile;
1853 init_error_log(Argv[0], config->logfile);
1861 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1862 if (config->default_server_timeout > config->keep_alive_timeout)
1864 log_error(LOG_LEVEL_ERROR,
1865 "Reducing the default-server-timeout from %d to the keep-alive-timeout %d.",
1866 config->default_server_timeout, config->keep_alive_timeout);
1867 config->default_server_timeout = config->keep_alive_timeout;
1869 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
1871 #ifdef FEATURE_CONNECTION_SHARING
1872 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1874 if (!config->multi_threaded)
1877 * While we could use keep-alive without multiple threads
1878 * if we didn't bother with enforcing the connection timeout,
1879 * that might make Tor users sad, even though they shouldn't
1880 * enable the single-threaded option anyway.
1882 * XXX: We could still use Proxy-Connection: keep-alive.
1884 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1885 log_error(LOG_LEVEL_ERROR,
1886 "Config option single-threaded disables connection keep-alive.");
1889 else if ((config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING))
1891 log_error(LOG_LEVEL_ERROR, "Config option connection-sharing "
1892 "has no effect if keep-alive-timeout isn't set.");
1893 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
1895 #endif /* def FEATURE_CONNECTION_SHARING */
1897 if (NULL == config->proxy_args)
1899 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1902 if (config->re_filterfile[0])
1904 add_loader(load_re_filterfiles, config);
1907 if (config->actions_file[0])
1909 add_loader(load_action_files, config);
1912 #ifdef FEATURE_TRUST
1913 if (config->trustfile)
1915 add_loader(load_trustfile, config);
1917 #endif /* def FEATURE_TRUST */
1919 if (NULL == config->haddr[0])
1921 config->haddr[0] = strdup_or_die(HADDR_DEFAULT);
1924 for (i = 0; i < MAX_LISTENING_SOCKETS && NULL != config->haddr[i]; i++)
1926 if ((*config->haddr[i] == '[')
1927 && (NULL != (p = strchr(config->haddr[i], ']')))
1929 && (0 < (config->hport[i] = atoi(p + 2))))
1932 memmove((void *)config->haddr[i], config->haddr[i] + 1,
1933 (size_t)(p - config->haddr[i]));
1935 else if (NULL != (p = strchr(config->haddr[i], ':'))
1936 && (0 < (config->hport[i] = atoi(p + 1))))
1942 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr[i]);
1943 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1945 if (*config->haddr[i] == '\0')
1948 * Only the port specified. We stored it in config->hport[i]
1949 * and don't need its text representation anymore.
1950 * Use config->hport[i] == 0 to iterate listening addresses since
1953 freez(config->haddr[i]);
1958 * Want to run all the loaders once now.
1960 * Need to set up a fake csp, so they can get to the config.
1962 fake_csp = zalloc_or_die(sizeof(*fake_csp));
1963 fake_csp->config = config;
1965 if (run_loader(fake_csp))
1968 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1969 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1973 /* FIXME: this is a kludge for win32 */
1974 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1976 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1977 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1978 g_default_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1979 g_user_filterfile = config->re_filterfile[1]; /* FIXME Hope this is user.filter */
1981 #ifdef FEATURE_TRUST
1982 g_trustfile = config->trustfile;
1983 #endif /* def FEATURE_TRUST */
1986 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1987 /* FIXME: end kludge */
1990 if (current_configfile == NULL)
1992 config->need_bind = 1;
1996 struct configuration_spec * oldcfg = (struct configuration_spec *)
1997 current_configfile->f;
1999 * Check if config->haddr[i],hport[i] == oldcfg->haddr[i],hport[i]
2001 config->need_bind = 0;
2003 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
2005 if (config->hport[i] != oldcfg->hport[i])
2007 config->need_bind = 1;
2009 else if (config->haddr[i] == NULL)
2011 if (oldcfg->haddr[i] != NULL)
2013 config->need_bind = 1;
2016 else if (oldcfg->haddr[i] == NULL)
2018 config->need_bind = 1;
2020 else if (0 != strcmp(config->haddr[i], oldcfg->haddr[i]))
2022 config->need_bind = 1;
2026 current_configfile->unloader = unload_configfile;
2029 fs->next = files->next;
2032 current_configfile = fs;
2038 /*********************************************************************
2040 * Function : savearg
2042 * Description : Called from `load_config'. It saves each non-empty
2043 * and non-comment line from config into
2044 * config->proxy_args. This is used to create the
2045 * show-status page. On error, frees
2046 * config->proxy_args and sets it to NULL
2049 * 1 : command = config setting that was found
2050 * 2 : argument = the setting's argument (if any)
2051 * 3 : config = Configuration to save into.
2055 *********************************************************************/
2056 static void savearg(char *command, char *argument, struct configuration_spec * config)
2065 * Add config option name embedded in
2066 * link to its section in the user-manual
2068 buf = strdup_or_die("\n<a href=\"");
2069 if (!strncmpic(config->usermanual, "file://", 7) ||
2070 !strncmpic(config->usermanual, "http", 4))
2072 string_append(&buf, config->usermanual);
2076 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
2078 string_append(&buf, CONFIG_HELP_PREFIX);
2079 string_join (&buf, string_toupper(command));
2080 string_append(&buf, "\">");
2081 string_append(&buf, command);
2082 string_append(&buf, "</a> ");
2086 freez(config->proxy_args);
2090 if ((NULL != argument) && ('\0' != *argument))
2092 s = html_encode(argument);
2096 freez(config->proxy_args);
2100 if (strncmpic(argument, "http://", 7) == 0)
2102 string_append(&buf, "<a href=\"");
2103 string_append(&buf, s);
2104 string_append(&buf, "\">");
2105 string_join (&buf, s);
2106 string_append(&buf, "</a>");
2110 string_join (&buf, s);
2114 string_append(&buf, "<br>");
2115 string_join(&config->proxy_args, buf);