1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.163 2017/06/26 12:09:56 fabiankeil Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
6 * Purpose : Loads settings from the configuration file into
7 * global variables. This file contains both the
8 * routine to load the configuration and the global
9 * variables it writes to.
11 * Copyright : Written by and Copyright (C) 2001-2017 the
12 * Privoxy team. http://www.privoxy.org/
14 * Based on the Internet Junkbuster originally written
15 * by and Copyright (C) 1997 Anonymous Coders and
16 * Junkbusters Corporation. http://www.junkbusters.com
18 * This program is free software; you can redistribute it
19 * and/or modify it under the terms of the GNU General
20 * Public License as published by the Free Software
21 * Foundation; either version 2 of the License, or (at
22 * your option) any later version.
24 * This program is distributed in the hope that it will
25 * be useful, but WITHOUT ANY WARRANTY; without even the
26 * implied warranty of MERCHANTABILITY or FITNESS FOR A
27 * PARTICULAR PURPOSE. See the GNU General Public
28 * License for more details.
30 * The GNU General Public License should be included with
31 * this file. If not, you can view it at
32 * http://www.gnu.org/copyleft/gpl.html
33 * or write to the Free Software Foundation, Inc., 59
34 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 *********************************************************************/
42 #include <sys/types.h>
56 # include <winsock2.h>
62 # endif /* ndef _WIN_CONSOLE */
64 #else /* ifndef _WIN32 */
68 # include <sys/wait.h>
70 # include <sys/time.h>
71 # include <sys/stat.h>
89 #ifdef FEATURE_CLIENT_TAGS
90 #include "client-tags.h"
94 * Default number of seconds after which an
95 * open connection will no longer be reused.
97 #define DEFAULT_KEEP_ALIVE_TIMEOUT 180
99 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
101 #ifdef FEATURE_TOGGLE
102 /* Privoxy is enabled by default. */
103 int global_toggle_state = 1;
104 #endif /* def FEATURE_TOGGLE */
106 /* The filename of the configfile */
107 const char *configfile = NULL;
110 * CGI functions will later need access to the invocation args,
111 * so we will make argc and argv global.
114 char * const * Argv = NULL;
116 static struct file_list *current_configfile = NULL;
120 * This takes the "cryptic" hash of each keyword and aliases them to
121 * something a little more readable. This also makes changing the
122 * hash values easier if they should change or the hash algorthm changes.
123 * Use the included "hash" program to find out what the hash will be
124 * for any string supplied on the command line. (Or just put it in the
125 * config file and read the number from the error message in the log).
127 * Please keep this list sorted alphabetically (but with the Windows
128 * console and GUI specific options last).
131 #define hash_actions_file 1196306641U /* "actionsfile" */
132 #define hash_accept_intercepted_requests 1513024973U /* "accept-intercepted-requests" */
133 #define hash_admin_address 4112573064U /* "admin-address" */
134 #define hash_allow_cgi_request_crunching 258915987U /* "allow-cgi-request-crunching" */
135 #define hash_buffer_limit 1881726070U /* "buffer-limit */
136 #define hash_client_header_order 2701453514U /* "client-header-order" */
137 #define hash_client_specific_tag 3353703383U /* "client-specific-tag" */
138 #define hash_client_tag_lifetime 647957580U /* "client-tag-lifetime" */
139 #define hash_compression_level 2464423563U /* "compression-level" */
140 #define hash_confdir 1978389U /* "confdir" */
141 #define hash_connection_sharing 1348841265U /* "connection-sharing" */
142 #define hash_debug 78263U /* "debug" */
143 #define hash_default_server_timeout 2530089913U /* "default-server-timeout" */
144 #define hash_deny_access 1227333715U /* "deny-access" */
145 #define hash_enable_accept_filter 2909040407U /* "enable-accept-filter" */
146 #define hash_enable_edit_actions 2517097536U /* "enable-edit-actions" */
147 #define hash_enable_compression 3943696946U /* "enable-compression" */
148 #define hash_enable_proxy_authentication_forwarding 4040610791U /* enable-proxy-authentication-forwarding */
149 #define hash_enable_remote_toggle 2979744683U /* "enable-remote-toggle" */
150 #define hash_enable_remote_http_toggle 110543988U /* "enable-remote-http-toggle" */
151 #define hash_enforce_blocks 1862427469U /* "enforce-blocks" */
152 #define hash_filterfile 250887266U /* "filterfile" */
153 #define hash_forward 2029845U /* "forward" */
154 #define hash_forward_socks4 3963965521U /* "forward-socks4" */
155 #define hash_forward_socks4a 2639958518U /* "forward-socks4a" */
156 #define hash_forward_socks5 3963965522U /* "forward-socks5" */
157 #define hash_forward_socks5t 2639958542U /* "forward-socks5t" */
158 #define hash_forwarded_connect_retries 101465292U /* "forwarded-connect-retries" */
159 #define hash_handle_as_empty_returns_ok 1444873247U /* "handle-as-empty-doc-returns-ok" */
160 #define hash_hostname 10308071U /* "hostname" */
161 #define hash_keep_alive_timeout 3878599515U /* "keep-alive-timeout" */
162 #define hash_listen_address 1255650842U /* "listen-address" */
163 #define hash_logdir 422889U /* "logdir" */
164 #define hash_logfile 2114766U /* "logfile" */
165 #define hash_max_client_connections 3595884446U /* "max-client-connections" */
166 #define hash_permit_access 3587953268U /* "permit-access" */
167 #define hash_proxy_info_url 3903079059U /* "proxy-info-url" */
168 #define hash_receive_buffer_size 2880297454U /* "receive-buffer-size */
169 #define hash_single_threaded 4250084780U /* "single-threaded" */
170 #define hash_socket_timeout 1809001761U /* "socket-timeout" */
171 #define hash_split_large_cgi_forms 671658948U /* "split-large-cgi-forms" */
172 #define hash_suppress_blocklists 1948693308U /* "suppress-blocklists" */
173 #define hash_templdir 11067889U /* "templdir" */
174 #define hash_temporary_directory 1824125181U /* "temporary-directory" */
175 #define hash_tolerate_pipelining 1360286620U /* "tolerate-pipelining" */
176 #define hash_toggle 447966U /* "toggle" */
177 #define hash_trust_info_url 430331967U /* "trust-info-url" */
178 #define hash_trust_x_forwarded_for 2971537414U /* "trust-x-forwarded-for" */
179 #define hash_trusted_cgi_referrer 4270883427U /* "trusted-cgi-referrer" */
180 #define hash_trustfile 56494766U /* "trustfile" */
181 #define hash_usermanual 1416668518U /* "user-manual" */
182 #define hash_activity_animation 1817904738U /* "activity-animation" */
183 #define hash_close_button_minimizes 3651284693U /* "close-button-minimizes" */
184 #define hash_hide_console 2048809870U /* "hide-console" */
185 #define hash_log_buffer_size 2918070425U /* "log-buffer-size" */
186 #define hash_log_font_name 2866730124U /* "log-font-name" */
187 #define hash_log_font_size 2866731014U /* "log-font-size" */
188 #define hash_log_highlight_messages 4032101240U /* "log-highlight-messages" */
189 #define hash_log_max_lines 2868344173U /* "log-max-lines" */
190 #define hash_log_messages 2291744899U /* "log-messages" */
191 #define hash_show_on_task_bar 215410365U /* "show-on-task-bar" */
194 static void savearg(char *command, char *argument, struct configuration_spec * config);
195 #ifdef FEATURE_CLIENT_TAGS
196 static void free_client_specific_tags(struct client_tag_spec *tag_list);
199 /*********************************************************************
201 * Function : unload_configfile
203 * Description : Free the config structure and all components.
206 * 1 : data: struct configuration_spec to unload
210 *********************************************************************/
211 static void unload_configfile (void * data)
213 struct configuration_spec * config = (struct configuration_spec *)data;
214 struct forward_spec *cur_fwd = config->forward;
218 struct access_control_list *cur_acl = config->acl;
220 while (cur_acl != NULL)
222 struct access_control_list * next_acl = cur_acl->next;
227 #endif /* def FEATURE_ACL */
229 while (cur_fwd != NULL)
231 struct forward_spec * next_fwd = cur_fwd->next;
232 free_pattern_spec(cur_fwd->url);
234 freez(cur_fwd->gateway_host);
235 freez(cur_fwd->forward_host);
239 config->forward = NULL;
241 freez(config->confdir);
242 freez(config->logdir);
243 freez(config->templdir);
244 freez(config->hostname);
245 #ifdef FEATURE_EXTERNAL_FILTERS
246 freez(config->temporary_directory);
249 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
251 freez(config->haddr[i]);
253 freez(config->logfile);
255 for (i = 0; i < MAX_AF_FILES; i++)
257 freez(config->actions_file_short[i]);
258 freez(config->actions_file[i]);
259 freez(config->re_filterfile_short[i]);
260 freez(config->re_filterfile[i]);
263 list_remove_all(config->ordered_client_headers);
265 freez(config->admin_address);
266 freez(config->proxy_info_url);
267 freez(config->proxy_args);
268 freez(config->usermanual);
269 freez(config->trusted_cgi_referrer);
272 freez(config->trustfile);
273 list_remove_all(config->trust_info);
274 #endif /* def FEATURE_TRUST */
276 #ifdef FEATURE_CLIENT_TAGS
277 free_client_specific_tags(config->client_tags);
284 #ifdef FEATURE_GRACEFUL_TERMINATION
285 /*********************************************************************
287 * Function : unload_current_config_file
289 * Description : Unloads current config file - reset to state at
290 * beginning of program.
296 *********************************************************************/
297 void unload_current_config_file(void)
299 if (current_configfile)
301 current_configfile->unloader = unload_configfile;
302 current_configfile = NULL;
308 #ifdef FEATURE_CLIENT_TAGS
309 /*********************************************************************
311 * Function : register_tag
313 * Description : Registers a client-specific-tag and its description
316 * 1 : config: The tag list
317 * 2 : name: The name of the client-specific-tag
318 * 3 : description: The human-readable description for the tag
322 *********************************************************************/
323 static void register_tag(struct client_tag_spec *tag_list,
324 const char *name, const char *description)
326 struct client_tag_spec *new_tag;
327 struct client_tag_spec *last_tag;
330 while (last_tag->next != NULL)
332 last_tag = last_tag->next;
334 if (last_tag->name == NULL)
341 new_tag = zalloc_or_die(sizeof(struct client_tag_spec));
343 new_tag->name = strdup_or_die(name);
344 new_tag->description = strdup_or_die(description);
345 if (new_tag != last_tag)
347 last_tag->next = new_tag;
352 /*********************************************************************
354 * Function : free_client_specific_tags
356 * Description : Frees client-specific tags and their descriptions
359 * 1 : tag_list: The tag list to free
363 *********************************************************************/
364 static void free_client_specific_tags(struct client_tag_spec *tag_list)
366 struct client_tag_spec *this_tag;
367 struct client_tag_spec *next_tag;
373 next_tag = next_tag->next;
375 freez(this_tag->name);
376 freez(this_tag->description);
378 if (this_tag != tag_list)
382 } while (next_tag != NULL);
384 #endif /* def FEATURE_CLIENT_TAGS */
387 /*********************************************************************
389 * Function : parse_numeric_value
391 * Description : Parse the value of a directive that can only have
392 * a single numeric value. Terminates with a fatal error
393 * if the value is NULL or not numeric.
396 * 1 : name: The name of the directive. Used for log messages.
397 * 2 : value: The value to parse
400 * Returns : The numerical value as integer
402 *********************************************************************/
403 static int parse_numeric_value(const char *name, const char *value)
408 assert(name != NULL);
409 assert(value != NULL);
411 if ((value == NULL) || (*value == '\0'))
413 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
416 number = (int)strtol(value, &endptr, 0);
419 log_error(LOG_LEVEL_FATAL,
420 "Directive '%s' used with non-numerical value: '%s'", name, value);
428 /*********************************************************************
430 * Function : parse_toggle_value
432 * Description : Parse the value of a directive that can only be
433 * enabled or disabled. Terminates with a fatal error
434 * if the value is NULL or something other than 0 or 1.
437 * 1 : name: The name of the directive. Used for log messages.
438 * 2 : value: The value to parse
441 * Returns : The numerical toggle state
443 *********************************************************************/
444 static int parse_toggle_state(const char *name, const char *value)
447 assert(name != NULL);
448 assert(value != NULL);
450 if ((value == NULL) || (*value == '\0'))
452 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
455 toggle_state = atoi(value);
458 * Also check the length as atoi() doesn't mind
459 * garbage after a valid integer, but we do.
461 if (((toggle_state != 0) && (toggle_state != 1)) || (strlen(value) != 1))
463 log_error(LOG_LEVEL_FATAL,
464 "Directive %s used with invalid argument '%s'. Use either '0' or '1'.",
473 /*********************************************************************
475 * Function : parse_client_header_order
477 * Description : Parse the value of the header-order directive
480 * 1 : ordered_header_list: List to insert the ordered
482 * 2 : ordered_headers: The ordered header names separated
488 *********************************************************************/
489 static void parse_client_header_order(struct list *ordered_header_list, const char *ordered_headers)
491 char *original_headers_copy;
494 int number_of_headers;
497 assert(ordered_header_list != NULL);
498 assert(ordered_headers != NULL);
500 if (ordered_headers == NULL)
502 log_error(LOG_LEVEL_FATAL, "header-order used without argument");
506 * XXX: This estimate is guaranteed to be high enough as we
507 * let ssplit() ignore empty fields, but also a bit wasteful.
508 * The same hack is used in get_last_url() so it looks like
509 * a real solution is needed.
511 max_segments = strlen(ordered_headers) / 2;
512 if (max_segments == 0)
516 vector = malloc_or_die(max_segments * sizeof(char *));
518 original_headers_copy = strdup_or_die(ordered_headers);
520 number_of_headers = ssplit(original_headers_copy, "\t ", vector, max_segments);
521 if (number_of_headers == -1)
523 log_error(LOG_LEVEL_FATAL, "Failed to split ordered headers");
526 for (i = 0; i < number_of_headers; i++)
528 if (JB_ERR_OK != enlist(ordered_header_list, vector[i]))
530 log_error(LOG_LEVEL_FATAL,
531 "Failed to enlist ordered header: %s", vector[i]);
536 freez(original_headers_copy);
543 /*********************************************************************
545 * Function : load_config
547 * Description : Load the config file and all parameters.
549 * XXX: more than thousand lines long
550 * and thus in serious need of refactoring.
554 * Returns : The configuration_spec, or NULL on error.
556 *********************************************************************/
557 struct configuration_spec * load_config(void)
561 FILE *configfp = NULL;
562 struct configuration_spec * config = NULL;
563 struct client_state * fake_csp;
564 struct file_list *fs;
565 unsigned long linenum = 0;
567 char *logfile = NULL;
569 if (!check_file_changed(current_configfile, configfile, &fs))
571 /* No need to load */
572 return ((struct configuration_spec *)current_configfile->f);
576 log_error(LOG_LEVEL_FATAL,
577 "can't check configuration file '%s': %E", configfile);
581 if (NULL != current_configfile)
583 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
586 #ifdef FEATURE_TOGGLE
587 global_toggle_state = 1;
588 #endif /* def FEATURE_TOGGLE */
590 fs->f = config = zalloc_or_die(sizeof(*config));
593 * This is backwards from how it's usually done.
594 * Following the usual pattern, "fs" would be stored in a member
595 * variable in "csp", and then we'd access "config" from "fs->f",
596 * using a cast. However, "config" is used so often that a
597 * cast each time would be very ugly, and the extra indirection
598 * would waste CPU cycles. Therefore we store "config" in
599 * "csp->config", and "fs" in "csp->config->config_file_list".
601 config->config_file_list = fs;
606 config->multi_threaded = 1;
607 config->buffer_limit = 4096 * 1024;
608 config->receive_buffer_size = BUFFER_SIZE;
609 config->usermanual = strdup_or_die(USER_MANUAL_URL);
610 config->proxy_args = strdup_or_die("");
611 config->forwarded_connect_retries = 0;
612 #ifdef FEATURE_CLIENT_TAGS
613 config->client_tag_lifetime = 60;
615 config->trust_x_forwarded_for = 0;
616 #if defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER)
617 config->enable_accept_filter = 0;
619 config->trusted_cgi_referrer = NULL;
621 * 128 client sockets ought to be enough for everybody who can't
622 * be bothered to read the documentation to figure out how to
623 * increase the limit.
625 config->max_client_connections = 128;
626 config->socket_timeout = 300; /* XXX: Should be a macro. */
627 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
628 config->default_server_timeout = 0;
629 config->keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
630 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
631 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
633 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
634 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
635 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
636 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
637 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
638 #ifdef FEATURE_COMPRESSION
639 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
641 * XXX: Run some benchmarks to see if there are better default values.
643 config->compression_level = 1;
645 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
647 configfp = fopen(configfile, "r");
648 if (NULL == configfp)
650 log_error(LOG_LEVEL_FATAL,
651 "can't open configuration file '%s': %E", configfile);
652 /* Never get here - LOG_LEVEL_FATAL causes program exit */
655 while (read_config_line(configfp, &linenum, &buf) != NULL)
657 char cmd[BUFFER_SIZE];
658 char arg[BUFFER_SIZE];
659 char tmp[BUFFER_SIZE];
661 struct access_control_list *cur_acl;
662 #endif /* def FEATURE_ACL */
663 struct forward_spec *cur_fwd;
666 unsigned int directive_hash;
668 strlcpy(tmp, buf, sizeof(tmp));
670 /* Copy command (i.e. up to space or tab) into cmd */
673 while (*p && (*p != ' ') && (*p != '\t'))
679 /* Skip over the whitespace in buf */
680 while (*p && ((*p == ' ') || (*p == '\t')))
685 /* Copy the argument into arg */
686 if (strlcpy(arg, p, sizeof(arg)) >= sizeof(arg))
688 log_error(LOG_LEVEL_FATAL, "Config line too long: %s", buf);
691 /* Should never happen, but check this anyway */
698 /* Make sure the command field is lower case */
699 for (p = cmd; *p; p++)
701 if (privoxy_isupper(*p))
703 *p = (char)privoxy_tolower(*p);
707 directive_hash = hash_string(cmd);
708 switch (directive_hash)
710 /* *************************************************************************
711 * actionsfile actions-file-name
712 * In confdir by default
713 * *************************************************************************/
714 case hash_actions_file :
716 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
721 if (i >= MAX_AF_FILES)
723 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
724 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
727 config->actions_file_short[i] = strdup_or_die(arg);
728 config->actions_file[i] = make_path(config->confdir, arg);
731 /* *************************************************************************
732 * accept-intercepted-requests
733 * *************************************************************************/
734 case hash_accept_intercepted_requests:
735 if (parse_toggle_state(cmd, arg) == 1)
737 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
741 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
745 /* *************************************************************************
746 * admin-address email-address
747 * *************************************************************************/
748 case hash_admin_address :
749 freez(config->admin_address);
750 config->admin_address = strdup_or_die(arg);
753 /* *************************************************************************
754 * allow-cgi-request-crunching
755 * *************************************************************************/
756 case hash_allow_cgi_request_crunching:
757 if (parse_toggle_state(cmd, arg) == 1)
759 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
763 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
767 /* *************************************************************************
769 * *************************************************************************/
770 case hash_buffer_limit :
771 config->buffer_limit = (size_t)(1024 * parse_numeric_value(cmd, arg));
774 /* *************************************************************************
775 * client-header-order header-1 header-2 ... header-n
776 * *************************************************************************/
777 case hash_client_header_order:
778 list_remove_all(config->ordered_client_headers);
779 parse_client_header_order(config->ordered_client_headers, arg);
782 /* *************************************************************************
783 * client-specific-tag tag-name description
784 * *************************************************************************/
785 #ifdef FEATURE_CLIENT_TAGS
786 case hash_client_specific_tag:
792 description = strstr(arg, " ");
793 if (description == NULL)
795 log_error(LOG_LEVEL_FATAL,
796 "client-specific-tag '%s' lacks a description.", name);
800 * The length is limited because we don't want truncated
801 * HTML caused by the cgi interface using static buffer
804 if (strlen(name) > CLIENT_TAG_LENGTH_MAX)
806 log_error(LOG_LEVEL_FATAL,
807 "client-specific-tag '%s' is longer than %d characters.",
808 name, CLIENT_TAG_LENGTH_MAX);
811 register_tag(config->client_tags, name, description);
814 #endif /* def FEATURE_CLIENT_TAGS */
816 /* *************************************************************************
817 * client-tag-lifetime ttl
818 * *************************************************************************/
819 #ifdef FEATURE_CLIENT_TAGS
820 case hash_client_tag_lifetime:
822 int ttl = parse_numeric_value(cmd, arg);
825 config->client_tag_lifetime = (unsigned)ttl;
829 log_error(LOG_LEVEL_FATAL,
830 "client-tag-lifetime can't be negative.");
834 #endif /* def FEATURE_CLIENT_TAGS */
836 /* *************************************************************************
837 * confdir directory-name
838 * *************************************************************************/
840 freez(config->confdir);
841 config->confdir = make_path(NULL, arg);
844 /* *************************************************************************
845 * compression-level 0-9
846 * *************************************************************************/
847 #ifdef FEATURE_COMPRESSION
848 case hash_compression_level :
850 int compression_level = parse_numeric_value(cmd, arg);
851 if (-1 <= compression_level && compression_level <= 9)
853 config->compression_level = compression_level;
857 log_error(LOG_LEVEL_FATAL,
858 "Invalid compression-level value: %s", arg);
864 /* *************************************************************************
865 * connection-sharing (0|1)
866 * *************************************************************************/
867 #ifdef FEATURE_CONNECTION_SHARING
868 case hash_connection_sharing :
869 if (parse_toggle_state(cmd, arg) == 1)
871 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_SHARING;
875 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
880 /* *************************************************************************
882 * Specifies debug level, multiple values are ORed together.
883 * *************************************************************************/
885 config->debug |= parse_numeric_value(cmd, arg);
888 /* *************************************************************************
889 * default-server-timeout timeout
890 * *************************************************************************/
891 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
892 case hash_default_server_timeout :
894 int timeout = parse_numeric_value(cmd, arg);
897 config->default_server_timeout = (unsigned int)timeout;
901 log_error(LOG_LEVEL_FATAL,
902 "Invalid default-server-timeout value: %s", arg);
908 /* *************************************************************************
909 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
910 * *************************************************************************/
912 case hash_deny_access:
913 strlcpy(tmp, arg, sizeof(tmp));
914 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
916 if ((vec_count != 1) && (vec_count != 2))
918 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
919 "deny-access directive in configuration file.");
920 string_append(&config->proxy_args,
921 "<br>\nWARNING: Wrong number of parameters for "
922 "deny-access directive in configuration file.<br><br>\n");
926 /* allocate a new node */
927 cur_acl = zalloc_or_die(sizeof(*cur_acl));
928 cur_acl->action = ACL_DENY;
930 if (acl_addr(vec[0], cur_acl->src) < 0)
932 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
933 "for deny-access directive in configuration file: \"%s\"", vec[0]);
934 string_append(&config->proxy_args,
935 "<br>\nWARNING: Invalid source address, port or netmask "
936 "for deny-access directive in configuration file: \"");
937 string_append(&config->proxy_args,
939 string_append(&config->proxy_args,
946 if (acl_addr(vec[1], cur_acl->dst) < 0)
948 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
949 "for deny-access directive in configuration file: \"%s\"", vec[1]);
950 string_append(&config->proxy_args,
951 "<br>\nWARNING: Invalid destination address, port or netmask "
952 "for deny-access directive in configuration file: \"");
953 string_append(&config->proxy_args,
955 string_append(&config->proxy_args,
964 cur_acl->wildcard_dst = 1;
966 #endif /* def HAVE_RFC2553 */
969 * Add it to the list. Note we reverse the list to get the
970 * behaviour the user expects. With both the ACL and
971 * actions file, the last match wins. However, the internal
972 * implementations are different: The actions file is stored
973 * in the same order as the file, and scanned completely.
974 * With the ACL, we reverse the order as we load it, then
975 * when we scan it we stop as soon as we get a match.
977 cur_acl->next = config->acl;
978 config->acl = cur_acl;
981 #endif /* def FEATURE_ACL */
983 #if defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER)
984 /* *************************************************************************
985 * enable-accept-filter 0|1
986 * *************************************************************************/
987 case hash_enable_accept_filter :
988 config->enable_accept_filter = parse_toggle_state(cmd, arg);
990 #endif /* defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER) */
992 /* *************************************************************************
993 * enable-edit-actions 0|1
994 * *************************************************************************/
995 #ifdef FEATURE_CGI_EDIT_ACTIONS
996 case hash_enable_edit_actions:
997 if (parse_toggle_state(cmd, arg) == 1)
999 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1003 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1006 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1008 /* *************************************************************************
1009 * enable-compression 0|1
1010 * *************************************************************************/
1011 #ifdef FEATURE_COMPRESSION
1012 case hash_enable_compression:
1013 if (parse_toggle_state(cmd, arg) == 1)
1015 config->feature_flags |= RUNTIME_FEATURE_COMPRESSION;
1019 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
1022 #endif /* def FEATURE_COMPRESSION */
1024 /* *************************************************************************
1025 * enable-proxy-authentication-forwarding 0|1
1026 * *************************************************************************/
1027 case hash_enable_proxy_authentication_forwarding:
1028 if (parse_toggle_state(cmd, arg) == 1)
1030 config->feature_flags |= RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1034 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1038 /* *************************************************************************
1039 * enable-remote-toggle 0|1
1040 * *************************************************************************/
1041 #ifdef FEATURE_TOGGLE
1042 case hash_enable_remote_toggle:
1043 if (parse_toggle_state(cmd, arg) == 1)
1045 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1049 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1052 #endif /* def FEATURE_TOGGLE */
1054 /* *************************************************************************
1055 * enable-remote-http-toggle 0|1
1056 * *************************************************************************/
1057 case hash_enable_remote_http_toggle:
1058 if (parse_toggle_state(cmd, arg) == 1)
1060 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1064 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1068 /* *************************************************************************
1069 * enforce-blocks 0|1
1070 * *************************************************************************/
1071 case hash_enforce_blocks:
1072 #ifdef FEATURE_FORCE_LOAD
1073 if (parse_toggle_state(cmd, arg) == 1)
1075 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1079 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1082 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1083 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1084 #endif /* def FEATURE_FORCE_LOAD */
1087 /* *************************************************************************
1088 * filterfile file-name
1089 * In confdir by default.
1090 * *************************************************************************/
1091 case hash_filterfile :
1093 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1098 if (i >= MAX_AF_FILES)
1100 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1101 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1104 config->re_filterfile_short[i] = strdup_or_die(arg);
1105 config->re_filterfile[i] = make_path(config->confdir, arg);
1109 /* *************************************************************************
1110 * forward url-pattern (.|http-proxy-host[:port])
1111 * *************************************************************************/
1113 strlcpy(tmp, arg, sizeof(tmp));
1114 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1118 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1119 "directive in configuration file.");
1120 string_append(&config->proxy_args,
1121 "<br>\nWARNING: Wrong number of parameters for "
1122 "forward directive in configuration file.");
1126 /* allocate a new node */
1127 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1128 cur_fwd->type = SOCKS_NONE;
1130 /* Save the URL pattern */
1131 if (create_pattern_spec(cur_fwd->url, vec[0]))
1133 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1134 "directive in configuration file.");
1135 string_append(&config->proxy_args,
1136 "<br>\nWARNING: Bad URL specifier for "
1137 "forward directive in configuration file.");
1142 /* Parse the parent HTTP proxy host:port */
1145 if (strcmp(p, ".") != 0)
1147 cur_fwd->forward_port = 8000;
1148 parse_forwarder_address(p, &cur_fwd->forward_host,
1149 &cur_fwd->forward_port);
1153 cur_fwd->next = config->forward;
1154 config->forward = cur_fwd;
1158 /* *************************************************************************
1159 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1160 * *************************************************************************/
1161 case hash_forward_socks4:
1162 strlcpy(tmp, arg, sizeof(tmp));
1163 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1167 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1168 "forward-socks4 directive in configuration file.");
1169 string_append(&config->proxy_args,
1170 "<br>\nWARNING: Wrong number of parameters for "
1171 "forward-socks4 directive in configuration file.");
1175 /* allocate a new node */
1176 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1177 cur_fwd->type = SOCKS_4;
1179 /* Save the URL pattern */
1180 if (create_pattern_spec(cur_fwd->url, vec[0]))
1182 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1183 "directive in configuration file.");
1184 string_append(&config->proxy_args,
1185 "<br>\nWARNING: Bad URL specifier for "
1186 "forward-socks4 directive in configuration file.");
1191 /* Parse the SOCKS proxy host[:port] */
1194 /* XXX: This check looks like a bug. */
1195 if (strcmp(p, ".") != 0)
1197 cur_fwd->gateway_port = 1080;
1198 parse_forwarder_address(p, &cur_fwd->gateway_host,
1199 &cur_fwd->gateway_port);
1202 /* Parse the parent HTTP proxy host[:port] */
1205 if (strcmp(p, ".") != 0)
1207 cur_fwd->forward_port = 8000;
1208 parse_forwarder_address(p, &cur_fwd->forward_host,
1209 &cur_fwd->forward_port);
1213 cur_fwd->next = config->forward;
1214 config->forward = cur_fwd;
1218 /* *************************************************************************
1219 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1220 * *************************************************************************/
1221 case hash_forward_socks4a:
1222 case hash_forward_socks5:
1223 case hash_forward_socks5t:
1224 strlcpy(tmp, arg, sizeof(tmp));
1225 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1229 log_error(LOG_LEVEL_ERROR,
1230 "Wrong number of parameters for %s in configuration file.",
1232 string_append(&config->proxy_args,
1233 "<br>\nWARNING: Wrong number of parameters for ");
1234 string_append(&config->proxy_args, cmd);
1235 string_append(&config->proxy_args,
1236 "directive in configuration file.");
1240 /* allocate a new node */
1241 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1243 if (directive_hash == hash_forward_socks4a)
1245 cur_fwd->type = SOCKS_4A;
1247 else if (directive_hash == hash_forward_socks5)
1249 cur_fwd->type = SOCKS_5;
1253 assert(directive_hash == hash_forward_socks5t);
1254 cur_fwd->type = SOCKS_5T;
1257 /* Save the URL pattern */
1258 if (create_pattern_spec(cur_fwd->url, vec[0]))
1260 log_error(LOG_LEVEL_ERROR,
1261 "Bad URL specifier for %s in configuration file.",
1263 string_append(&config->proxy_args,
1264 "<br>\nWARNING: Bad URL specifier for ");
1265 string_append(&config->proxy_args, cmd);
1266 string_append(&config->proxy_args,
1267 "directive in configuration file.");
1272 /* Parse the SOCKS proxy host[:port] */
1275 cur_fwd->gateway_port = 1080;
1276 parse_forwarder_address(p, &cur_fwd->gateway_host,
1277 &cur_fwd->gateway_port);
1279 /* Parse the parent HTTP proxy host[:port] */
1282 if (strcmp(p, ".") != 0)
1284 cur_fwd->forward_port = 8000;
1285 parse_forwarder_address(p, &cur_fwd->forward_host,
1286 &cur_fwd->forward_port);
1290 cur_fwd->next = config->forward;
1291 config->forward = cur_fwd;
1295 /* *************************************************************************
1296 * forwarded-connect-retries n
1297 * *************************************************************************/
1298 case hash_forwarded_connect_retries :
1299 config->forwarded_connect_retries = parse_numeric_value(cmd, arg);
1302 /* *************************************************************************
1303 * handle-as-empty-doc-returns-ok 0|1
1305 * Workaround for firefox hanging on blocked javascript pages.
1306 * Block with the "+handle-as-empty-document" flag and set the
1307 * "handle-as-empty-doc-returns-ok" run-time config flag so that
1308 * Privoxy returns a 200/OK status instead of a 403/Forbidden status
1309 * to the browser for blocked pages.
1310 ***************************************************************************/
1311 case hash_handle_as_empty_returns_ok:
1312 if (parse_toggle_state(cmd, arg) == 1)
1314 config->feature_flags |= RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1318 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1322 /* *************************************************************************
1323 * hostname hostname-to-show-on-cgi-pages
1324 * *************************************************************************/
1325 case hash_hostname :
1326 freez(config->hostname);
1327 config->hostname = strdup_or_die(arg);
1330 /* *************************************************************************
1331 * keep-alive-timeout timeout
1332 * *************************************************************************/
1333 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1334 case hash_keep_alive_timeout :
1336 int timeout = parse_numeric_value(cmd, arg);
1339 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1340 config->keep_alive_timeout = (unsigned int)timeout;
1344 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1350 /* *************************************************************************
1351 * listen-address [ip][:port]
1352 * *************************************************************************/
1353 case hash_listen_address :
1355 while ((i < MAX_LISTENING_SOCKETS) && (NULL != config->haddr[i]))
1360 if (i >= MAX_LISTENING_SOCKETS)
1362 log_error(LOG_LEVEL_FATAL, "Too many 'listen-address' directives in config file - limit is %d.\n"
1363 "(You can increase this limit by changing MAX_LISTENING_SOCKETS in project.h and recompiling).",
1364 MAX_LISTENING_SOCKETS);
1366 config->haddr[i] = strdup_or_die(arg);
1369 /* *************************************************************************
1370 * logdir directory-name
1371 * *************************************************************************/
1373 freez(config->logdir);
1374 config->logdir = make_path(NULL, arg);
1377 /* *************************************************************************
1378 * logfile log-file-name
1379 * In logdir by default
1380 * *************************************************************************/
1384 logfile = make_path(config->logdir, arg);
1385 if (NULL == logfile)
1387 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1392 /* *************************************************************************
1393 * max-client-connections number
1394 * *************************************************************************/
1395 case hash_max_client_connections :
1397 int max_client_connections = parse_numeric_value(cmd, arg);
1399 #if !defined(_WIN32) && !defined(HAVE_POLL)
1401 * Reject values below 1 for obvious reasons and values above
1402 * FD_SETSIZE/2 because Privoxy needs two sockets to serve
1403 * client connections that need forwarding.
1405 * We ignore the fact that the first three file descriptors
1406 * are usually set to /dev/null, one is used for logging
1407 * and yet another file descriptor is required to load
1410 if ((max_client_connections < 1) || (FD_SETSIZE/2 < max_client_connections))
1412 log_error(LOG_LEVEL_FATAL, "max-client-connections value %d"
1413 " is invalid. Value needs to be above 1 and below %d"
1414 " (FD_SETSIZE/2).", max_client_connections, FD_SETSIZE/2);
1418 * The Windows libc uses FD_SETSIZE for an array used
1419 * by select(), but has no problems with file descriptors
1420 * above the limit as long as no more than FD_SETSIZE are
1421 * passed to select().
1422 * https://msdn.microsoft.com/en-us/library/windows/desktop/ms739169%28v=vs.85%29.aspx
1424 * On platforms were we use poll() we don't have to enforce
1425 * an upper connection limit either.
1427 * XXX: Do OS/2, Amiga etc. belong here as well?
1429 if (max_client_connections < 1)
1431 log_error(LOG_LEVEL_FATAL, "max-client-connections value"
1432 " has to be a number above 1. %d is invalid.",
1433 max_client_connections);
1436 config->max_client_connections = max_client_connections;
1440 /* *************************************************************************
1441 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1442 * *************************************************************************/
1444 case hash_permit_access:
1445 strlcpy(tmp, arg, sizeof(tmp));
1446 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1448 if ((vec_count != 1) && (vec_count != 2))
1450 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1451 "permit-access directive in configuration file.");
1452 string_append(&config->proxy_args,
1453 "<br>\nWARNING: Wrong number of parameters for "
1454 "permit-access directive in configuration file.<br><br>\n");
1459 /* allocate a new node */
1460 cur_acl = zalloc_or_die(sizeof(*cur_acl));
1461 cur_acl->action = ACL_PERMIT;
1463 if (acl_addr(vec[0], cur_acl->src) < 0)
1465 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1466 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1467 string_append(&config->proxy_args,
1468 "<br>\nWARNING: Invalid source address, port or netmask for "
1469 "permit-access directive in configuration file: \"");
1470 string_append(&config->proxy_args,
1472 string_append(&config->proxy_args,
1479 if (acl_addr(vec[1], cur_acl->dst) < 0)
1481 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1482 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1483 string_append(&config->proxy_args,
1484 "<br>\nWARNING: Invalid destination address, port or netmask for "
1485 "permit-access directive in configuration file: \"");
1486 string_append(&config->proxy_args,
1488 string_append(&config->proxy_args,
1497 cur_acl->wildcard_dst = 1;
1499 #endif /* def HAVE_RFC2553 */
1502 * Add it to the list. Note we reverse the list to get the
1503 * behaviour the user expects. With both the ACL and
1504 * actions file, the last match wins. However, the internal
1505 * implementations are different: The actions file is stored
1506 * in the same order as the file, and scanned completely.
1507 * With the ACL, we reverse the order as we load it, then
1508 * when we scan it we stop as soon as we get a match.
1510 cur_acl->next = config->acl;
1511 config->acl = cur_acl;
1514 #endif /* def FEATURE_ACL */
1516 /* *************************************************************************
1517 * proxy-info-url url
1518 * *************************************************************************/
1519 case hash_proxy_info_url :
1520 freez(config->proxy_info_url);
1521 config->proxy_info_url = strdup_or_die(arg);
1525 /* *************************************************************************
1526 * receive-buffer-size n
1527 * *************************************************************************/
1528 case hash_receive_buffer_size :
1529 config->receive_buffer_size = (size_t)parse_numeric_value(cmd, arg);
1530 if (config->receive_buffer_size < BUFFER_SIZE)
1532 log_error(LOG_LEVEL_INFO,
1533 "receive-buffer-size %d seems low and may cause problems."
1534 "Consider setting it to at least %d.",
1535 config->receive_buffer_size, BUFFER_SIZE);
1539 /* *************************************************************************
1540 * single-threaded 0|1
1541 * *************************************************************************/
1542 case hash_single_threaded :
1543 config->multi_threaded = 0 == parse_toggle_state(cmd, arg);
1546 /* *************************************************************************
1547 * socket-timeout numer_of_seconds
1548 * *************************************************************************/
1549 case hash_socket_timeout :
1551 int socket_timeout = parse_numeric_value(cmd, arg);
1552 if (0 <= socket_timeout)
1554 config->socket_timeout = socket_timeout;
1558 log_error(LOG_LEVEL_FATAL, "Invalid socket-timeout: '%s'", arg);
1563 /* *************************************************************************
1564 * split-large-cgi-forms
1565 * *************************************************************************/
1566 case hash_split_large_cgi_forms :
1567 if (parse_toggle_state(cmd, arg) == 1)
1569 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1573 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1577 /* *************************************************************************
1578 * templdir directory-name
1579 * *************************************************************************/
1580 case hash_templdir :
1581 freez(config->templdir);
1582 config->templdir = make_path(NULL, arg);
1585 #ifdef FEATURE_EXTERNAL_FILTERS
1586 /* *************************************************************************
1587 * temporary-directory directory-name
1588 * *************************************************************************/
1589 case hash_temporary_directory :
1590 freez(config->temporary_directory);
1591 config->temporary_directory = make_path(NULL, arg);
1595 /* *************************************************************************
1596 * tolerate-pipelining (0|1)
1597 * *************************************************************************/
1598 case hash_tolerate_pipelining :
1599 if (parse_toggle_state(cmd, arg) == 1)
1601 config->feature_flags |= RUNTIME_FEATURE_TOLERATE_PIPELINING;
1605 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
1609 /* *************************************************************************
1611 * *************************************************************************/
1612 #ifdef FEATURE_TOGGLE
1614 global_toggle_state = parse_toggle_state(cmd, arg);
1616 #endif /* def FEATURE_TOGGLE */
1618 /* *************************************************************************
1619 * trust-info-url url
1620 * *************************************************************************/
1621 #ifdef FEATURE_TRUST
1622 case hash_trust_info_url :
1623 enlist(config->trust_info, arg);
1625 #endif /* def FEATURE_TRUST */
1627 /* *************************************************************************
1628 * trust-x-forwarded-for (0|1)
1629 * *************************************************************************/
1630 case hash_trust_x_forwarded_for :
1631 config->trust_x_forwarded_for = parse_toggle_state(cmd, arg);
1634 /* *************************************************************************
1635 * trusted-cgi-referrer http://www.example.org/some/path.html
1636 * *************************************************************************/
1637 case hash_trusted_cgi_referrer :
1639 * We don't validate the specified referrer as
1640 * it's only used for string comparison.
1642 freez(config->trusted_cgi_referrer);
1643 config->trusted_cgi_referrer = strdup_or_die(arg);
1646 /* *************************************************************************
1647 * trustfile filename
1648 * (In confdir by default.)
1649 * *************************************************************************/
1650 #ifdef FEATURE_TRUST
1651 case hash_trustfile :
1652 freez(config->trustfile);
1653 config->trustfile = make_path(config->confdir, arg);
1655 #endif /* def FEATURE_TRUST */
1657 /* *************************************************************************
1659 * *************************************************************************/
1660 case hash_usermanual :
1662 * XXX: If this isn't the first config directive, the
1663 * show-status page links to the website documentation
1664 * for the directives that were already parsed. Lame.
1666 freez(config->usermanual);
1667 config->usermanual = strdup_or_die(arg);
1670 /* *************************************************************************
1671 * Win32 Console options:
1672 * *************************************************************************/
1674 /* *************************************************************************
1676 * *************************************************************************/
1678 case hash_hide_console :
1681 #endif /*def _WIN_CONSOLE*/
1684 /* *************************************************************************
1685 * Win32 GUI options:
1686 * *************************************************************************/
1688 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1689 /* *************************************************************************
1690 * activity-animation (0|1)
1691 * *************************************************************************/
1692 case hash_activity_animation :
1693 g_bShowActivityAnimation = parse_toggle_state(cmd, arg);
1696 /* *************************************************************************
1697 * close-button-minimizes (0|1)
1698 * *************************************************************************/
1699 case hash_close_button_minimizes :
1700 g_bCloseHidesWindow = parse_toggle_state(cmd, arg);
1703 /* *************************************************************************
1704 * log-buffer-size (0|1)
1705 * *************************************************************************/
1706 case hash_log_buffer_size :
1707 g_bLimitBufferSize = parse_toggle_state(cmd, arg);
1710 /* *************************************************************************
1711 * log-font-name fontname
1712 * *************************************************************************/
1713 case hash_log_font_name :
1714 if (strlcpy(g_szFontFaceName, arg,
1715 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1717 log_error(LOG_LEVEL_FATAL,
1718 "log-font-name argument '%s' is longer than %u characters.",
1719 arg, sizeof(g_szFontFaceName)-1);
1723 /* *************************************************************************
1725 * *************************************************************************/
1726 case hash_log_font_size :
1727 g_nFontSize = parse_numeric_value(cmd, arg);
1730 /* *************************************************************************
1731 * log-highlight-messages (0|1)
1732 * *************************************************************************/
1733 case hash_log_highlight_messages :
1734 g_bHighlightMessages = parse_toggle_state(cmd, arg);
1737 /* *************************************************************************
1739 * *************************************************************************/
1740 case hash_log_max_lines :
1741 g_nMaxBufferLines = parse_numeric_value(cmd, arg);
1744 /* *************************************************************************
1745 * log-messages (0|1)
1746 * *************************************************************************/
1747 case hash_log_messages :
1748 g_bLogMessages = parse_toggle_state(cmd, arg);
1751 /* *************************************************************************
1752 * show-on-task-bar (0|1)
1753 * *************************************************************************/
1754 case hash_show_on_task_bar :
1755 g_bShowOnTaskBar = parse_toggle_state(cmd, arg);
1758 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1761 /* *************************************************************************
1762 * Warnings about unsupported features
1763 * *************************************************************************/
1765 case hash_deny_access:
1766 #endif /* ndef FEATURE_ACL */
1767 #ifndef FEATURE_CGI_EDIT_ACTIONS
1768 case hash_enable_edit_actions:
1769 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1770 #ifndef FEATURE_TOGGLE
1771 case hash_enable_remote_toggle:
1772 #endif /* ndef FEATURE_TOGGLE */
1774 case hash_permit_access:
1775 #endif /* ndef FEATURE_ACL */
1776 #ifndef FEATURE_TOGGLE
1778 #endif /* ndef FEATURE_TOGGLE */
1779 #ifndef FEATURE_TRUST
1780 case hash_trustfile :
1781 case hash_trust_info_url :
1782 #endif /* ndef FEATURE_TRUST */
1784 #ifndef _WIN_CONSOLE
1785 case hash_hide_console :
1786 #endif /* ndef _WIN_CONSOLE */
1788 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1789 case hash_activity_animation :
1790 case hash_close_button_minimizes :
1791 case hash_log_buffer_size :
1792 case hash_log_font_name :
1793 case hash_log_font_size :
1794 case hash_log_highlight_messages :
1795 case hash_log_max_lines :
1796 case hash_log_messages :
1797 case hash_show_on_task_bar :
1798 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1799 /* These warnings are annoying - so hide them. -- Jon */
1800 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1803 /* *************************************************************************/
1805 /* *************************************************************************/
1807 * I decided that I liked this better as a warning than an
1808 * error. To change back to an error, just change log level
1809 * to LOG_LEVEL_FATAL.
1811 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive "
1812 "'%s' (%uU) in line %lu in configuration file (%s).",
1813 buf, directive_hash, linenum, configfile);
1814 string_append(&config->proxy_args,
1815 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1818 /* *************************************************************************/
1819 } /* end switch(hash_string(cmd)) */
1821 /* Save the argument for the show-status page. */
1822 savearg(cmd, arg, config);
1824 } /* end while (read_config_line(...)) */
1828 set_debug_level(config->debug);
1830 freez(config->logfile);
1834 if (NULL != logfile)
1836 config->logfile = logfile;
1837 init_error_log(Argv[0], config->logfile);
1845 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1846 if (config->default_server_timeout > config->keep_alive_timeout)
1848 log_error(LOG_LEVEL_ERROR,
1849 "Reducing the default-server-timeout from %d to the keep-alive-timeout %d.",
1850 config->default_server_timeout, config->keep_alive_timeout);
1851 config->default_server_timeout = config->keep_alive_timeout;
1853 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
1855 #ifdef FEATURE_CONNECTION_SHARING
1856 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1858 if (!config->multi_threaded)
1861 * While we could use keep-alive without multiple threads
1862 * if we didn't bother with enforcing the connection timeout,
1863 * that might make Tor users sad, even though they shouldn't
1864 * enable the single-threaded option anyway.
1866 * XXX: We could still use Proxy-Connection: keep-alive.
1868 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1869 log_error(LOG_LEVEL_ERROR,
1870 "Config option single-threaded disables connection keep-alive.");
1873 else if ((config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING))
1875 log_error(LOG_LEVEL_ERROR, "Config option connection-sharing "
1876 "has no effect if keep-alive-timeout isn't set.");
1877 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
1879 #endif /* def FEATURE_CONNECTION_SHARING */
1881 if (NULL == config->proxy_args)
1883 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1886 if (config->re_filterfile[0])
1888 add_loader(load_re_filterfiles, config);
1891 if (config->actions_file[0])
1893 add_loader(load_action_files, config);
1896 #ifdef FEATURE_TRUST
1897 if (config->trustfile)
1899 add_loader(load_trustfile, config);
1901 #endif /* def FEATURE_TRUST */
1903 if (NULL == config->haddr[0])
1905 config->haddr[0] = strdup_or_die(HADDR_DEFAULT);
1908 for (i = 0; i < MAX_LISTENING_SOCKETS && NULL != config->haddr[i]; i++)
1910 if ((*config->haddr[i] == '[')
1911 && (NULL != (p = strchr(config->haddr[i], ']')))
1913 && (0 < (config->hport[i] = atoi(p + 2))))
1916 memmove((void *)config->haddr[i], config->haddr[i] + 1,
1917 (size_t)(p - config->haddr[i]));
1919 else if (NULL != (p = strchr(config->haddr[i], ':'))
1920 && (0 < (config->hport[i] = atoi(p + 1))))
1926 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr[i]);
1927 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1929 if (*config->haddr[i] == '\0')
1932 * Only the port specified. We stored it in config->hport[i]
1933 * and don't need its text representation anymore.
1934 * Use config->hport[i] == 0 to iterate listening addresses since
1937 freez(config->haddr[i]);
1942 * Want to run all the loaders once now.
1944 * Need to set up a fake csp, so they can get to the config.
1946 fake_csp = zalloc_or_die(sizeof(*fake_csp));
1947 fake_csp->config = config;
1949 if (run_loader(fake_csp))
1952 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1953 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1957 /* FIXME: this is a kludge for win32 */
1958 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1960 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1961 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1962 g_default_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1963 g_user_filterfile = config->re_filterfile[1]; /* FIXME Hope this is user.filter */
1965 #ifdef FEATURE_TRUST
1966 g_trustfile = config->trustfile;
1967 #endif /* def FEATURE_TRUST */
1970 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1971 /* FIXME: end kludge */
1974 config->need_bind = 1;
1976 if (current_configfile)
1978 struct configuration_spec * oldcfg = (struct configuration_spec *)
1979 current_configfile->f;
1981 * Check if config->haddr[i],hport[i] == oldcfg->haddr[i],hport[i]
1983 config->need_bind = 0;
1985 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
1987 if (config->hport[i] != oldcfg->hport[i])
1989 config->need_bind = 1;
1991 else if (config->haddr[i] == NULL)
1993 if (oldcfg->haddr[i] != NULL)
1995 config->need_bind = 1;
1998 else if (oldcfg->haddr[i] == NULL)
2000 config->need_bind = 1;
2002 else if (0 != strcmp(config->haddr[i], oldcfg->haddr[i]))
2004 config->need_bind = 1;
2008 current_configfile->unloader = unload_configfile;
2011 fs->next = files->next;
2014 current_configfile = fs;
2020 /*********************************************************************
2022 * Function : savearg
2024 * Description : Called from `load_config'. It saves each non-empty
2025 * and non-comment line from config into
2026 * config->proxy_args. This is used to create the
2027 * show-status page. On error, frees
2028 * config->proxy_args and sets it to NULL
2031 * 1 : command = config setting that was found
2032 * 2 : argument = the setting's argument (if any)
2033 * 3 : config = Configuration to save into.
2037 *********************************************************************/
2038 static void savearg(char *command, char *argument, struct configuration_spec * config)
2047 * Add config option name embedded in
2048 * link to its section in the user-manual
2050 buf = strdup_or_die("\n<a href=\"");
2051 if (!strncmpic(config->usermanual, "file://", 7) ||
2052 !strncmpic(config->usermanual, "http", 4))
2054 string_append(&buf, config->usermanual);
2058 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
2060 string_append(&buf, CONFIG_HELP_PREFIX);
2061 string_join (&buf, string_toupper(command));
2062 string_append(&buf, "\">");
2063 string_append(&buf, command);
2064 string_append(&buf, "</a> ");
2068 freez(config->proxy_args);
2072 if ((NULL != argument) && ('\0' != *argument))
2074 s = html_encode(argument);
2078 freez(config->proxy_args);
2082 if (strncmpic(argument, "http://", 7) == 0)
2084 string_append(&buf, "<a href=\"");
2085 string_append(&buf, s);
2086 string_append(&buf, "\">");
2087 string_join (&buf, s);
2088 string_append(&buf, "</a>");
2092 string_join (&buf, s);
2096 string_append(&buf, "<br>");
2097 string_join(&config->proxy_args, buf);