1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.164 2017/06/26 12:11:13 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
100 * Default backlog passed to listen().
102 #define DEFAULT_LISTEN_BACKLOG 128
104 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
106 #ifdef FEATURE_TOGGLE
107 /* Privoxy is enabled by default. */
108 int global_toggle_state = 1;
109 #endif /* def FEATURE_TOGGLE */
111 /* The filename of the configfile */
112 const char *configfile = NULL;
115 * CGI functions will later need access to the invocation args,
116 * so we will make argc and argv global.
119 char * const * Argv = NULL;
121 static struct file_list *current_configfile = NULL;
125 * This takes the "cryptic" hash of each keyword and aliases them to
126 * something a little more readable. This also makes changing the
127 * hash values easier if they should change or the hash algorthm changes.
128 * Use the included "hash" program to find out what the hash will be
129 * for any string supplied on the command line. (Or just put it in the
130 * config file and read the number from the error message in the log).
132 * Please keep this list sorted alphabetically (but with the Windows
133 * console and GUI specific options last).
136 #define hash_actions_file 1196306641U /* "actionsfile" */
137 #define hash_accept_intercepted_requests 1513024973U /* "accept-intercepted-requests" */
138 #define hash_admin_address 4112573064U /* "admin-address" */
139 #define hash_allow_cgi_request_crunching 258915987U /* "allow-cgi-request-crunching" */
140 #define hash_buffer_limit 1881726070U /* "buffer-limit */
141 #define hash_client_header_order 2701453514U /* "client-header-order" */
142 #define hash_client_specific_tag 3353703383U /* "client-specific-tag" */
143 #define hash_client_tag_lifetime 647957580U /* "client-tag-lifetime" */
144 #define hash_compression_level 2464423563U /* "compression-level" */
145 #define hash_confdir 1978389U /* "confdir" */
146 #define hash_connection_sharing 1348841265U /* "connection-sharing" */
147 #define hash_debug 78263U /* "debug" */
148 #define hash_default_server_timeout 2530089913U /* "default-server-timeout" */
149 #define hash_deny_access 1227333715U /* "deny-access" */
150 #define hash_enable_accept_filter 2909040407U /* "enable-accept-filter" */
151 #define hash_enable_edit_actions 2517097536U /* "enable-edit-actions" */
152 #define hash_enable_compression 3943696946U /* "enable-compression" */
153 #define hash_enable_proxy_authentication_forwarding 4040610791U /* enable-proxy-authentication-forwarding */
154 #define hash_enable_remote_toggle 2979744683U /* "enable-remote-toggle" */
155 #define hash_enable_remote_http_toggle 110543988U /* "enable-remote-http-toggle" */
156 #define hash_enforce_blocks 1862427469U /* "enforce-blocks" */
157 #define hash_filterfile 250887266U /* "filterfile" */
158 #define hash_forward 2029845U /* "forward" */
159 #define hash_forward_socks4 3963965521U /* "forward-socks4" */
160 #define hash_forward_socks4a 2639958518U /* "forward-socks4a" */
161 #define hash_forward_socks5 3963965522U /* "forward-socks5" */
162 #define hash_forward_socks5t 2639958542U /* "forward-socks5t" */
163 #define hash_forwarded_connect_retries 101465292U /* "forwarded-connect-retries" */
164 #define hash_handle_as_empty_returns_ok 1444873247U /* "handle-as-empty-doc-returns-ok" */
165 #define hash_hostname 10308071U /* "hostname" */
166 #define hash_keep_alive_timeout 3878599515U /* "keep-alive-timeout" */
167 #define hash_listen_address 1255650842U /* "listen-address" */
168 #define hash_listen_backlog 1255655735U /* "listen-backlog" */
169 #define hash_logdir 422889U /* "logdir" */
170 #define hash_logfile 2114766U /* "logfile" */
171 #define hash_max_client_connections 3595884446U /* "max-client-connections" */
172 #define hash_permit_access 3587953268U /* "permit-access" */
173 #define hash_proxy_info_url 3903079059U /* "proxy-info-url" */
174 #define hash_receive_buffer_size 2880297454U /* "receive-buffer-size */
175 #define hash_single_threaded 4250084780U /* "single-threaded" */
176 #define hash_socket_timeout 1809001761U /* "socket-timeout" */
177 #define hash_split_large_cgi_forms 671658948U /* "split-large-cgi-forms" */
178 #define hash_suppress_blocklists 1948693308U /* "suppress-blocklists" */
179 #define hash_templdir 11067889U /* "templdir" */
180 #define hash_temporary_directory 1824125181U /* "temporary-directory" */
181 #define hash_tolerate_pipelining 1360286620U /* "tolerate-pipelining" */
182 #define hash_toggle 447966U /* "toggle" */
183 #define hash_trust_info_url 430331967U /* "trust-info-url" */
184 #define hash_trust_x_forwarded_for 2971537414U /* "trust-x-forwarded-for" */
185 #define hash_trusted_cgi_referrer 4270883427U /* "trusted-cgi-referrer" */
186 #define hash_trustfile 56494766U /* "trustfile" */
187 #define hash_usermanual 1416668518U /* "user-manual" */
188 #define hash_activity_animation 1817904738U /* "activity-animation" */
189 #define hash_close_button_minimizes 3651284693U /* "close-button-minimizes" */
190 #define hash_hide_console 2048809870U /* "hide-console" */
191 #define hash_log_buffer_size 2918070425U /* "log-buffer-size" */
192 #define hash_log_font_name 2866730124U /* "log-font-name" */
193 #define hash_log_font_size 2866731014U /* "log-font-size" */
194 #define hash_log_highlight_messages 4032101240U /* "log-highlight-messages" */
195 #define hash_log_max_lines 2868344173U /* "log-max-lines" */
196 #define hash_log_messages 2291744899U /* "log-messages" */
197 #define hash_show_on_task_bar 215410365U /* "show-on-task-bar" */
200 static void savearg(char *command, char *argument, struct configuration_spec * config);
201 #ifdef FEATURE_CLIENT_TAGS
202 static void free_client_specific_tags(struct client_tag_spec *tag_list);
205 /*********************************************************************
207 * Function : unload_configfile
209 * Description : Free the config structure and all components.
212 * 1 : data: struct configuration_spec to unload
216 *********************************************************************/
217 static void unload_configfile (void * data)
219 struct configuration_spec * config = (struct configuration_spec *)data;
220 struct forward_spec *cur_fwd = config->forward;
224 struct access_control_list *cur_acl = config->acl;
226 while (cur_acl != NULL)
228 struct access_control_list * next_acl = cur_acl->next;
233 #endif /* def FEATURE_ACL */
235 while (cur_fwd != NULL)
237 struct forward_spec * next_fwd = cur_fwd->next;
238 free_pattern_spec(cur_fwd->url);
240 freez(cur_fwd->gateway_host);
241 freez(cur_fwd->forward_host);
245 config->forward = NULL;
247 freez(config->confdir);
248 freez(config->logdir);
249 freez(config->templdir);
250 freez(config->hostname);
251 #ifdef FEATURE_EXTERNAL_FILTERS
252 freez(config->temporary_directory);
255 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
257 freez(config->haddr[i]);
259 freez(config->logfile);
261 for (i = 0; i < MAX_AF_FILES; i++)
263 freez(config->actions_file_short[i]);
264 freez(config->actions_file[i]);
265 freez(config->re_filterfile_short[i]);
266 freez(config->re_filterfile[i]);
269 list_remove_all(config->ordered_client_headers);
271 freez(config->admin_address);
272 freez(config->proxy_info_url);
273 freez(config->proxy_args);
274 freez(config->usermanual);
275 freez(config->trusted_cgi_referrer);
278 freez(config->trustfile);
279 list_remove_all(config->trust_info);
280 #endif /* def FEATURE_TRUST */
282 #ifdef FEATURE_CLIENT_TAGS
283 free_client_specific_tags(config->client_tags);
290 #ifdef FEATURE_GRACEFUL_TERMINATION
291 /*********************************************************************
293 * Function : unload_current_config_file
295 * Description : Unloads current config file - reset to state at
296 * beginning of program.
302 *********************************************************************/
303 void unload_current_config_file(void)
305 if (current_configfile)
307 current_configfile->unloader = unload_configfile;
308 current_configfile = NULL;
314 #ifdef FEATURE_CLIENT_TAGS
315 /*********************************************************************
317 * Function : register_tag
319 * Description : Registers a client-specific-tag and its description
322 * 1 : config: The tag list
323 * 2 : name: The name of the client-specific-tag
324 * 3 : description: The human-readable description for the tag
328 *********************************************************************/
329 static void register_tag(struct client_tag_spec *tag_list,
330 const char *name, const char *description)
332 struct client_tag_spec *new_tag;
333 struct client_tag_spec *last_tag;
336 while (last_tag->next != NULL)
338 last_tag = last_tag->next;
340 if (last_tag->name == NULL)
347 new_tag = zalloc_or_die(sizeof(struct client_tag_spec));
349 new_tag->name = strdup_or_die(name);
350 new_tag->description = strdup_or_die(description);
351 if (new_tag != last_tag)
353 last_tag->next = new_tag;
358 /*********************************************************************
360 * Function : free_client_specific_tags
362 * Description : Frees client-specific tags and their descriptions
365 * 1 : tag_list: The tag list to free
369 *********************************************************************/
370 static void free_client_specific_tags(struct client_tag_spec *tag_list)
372 struct client_tag_spec *this_tag;
373 struct client_tag_spec *next_tag;
379 next_tag = next_tag->next;
381 freez(this_tag->name);
382 freez(this_tag->description);
384 if (this_tag != tag_list)
388 } while (next_tag != NULL);
390 #endif /* def FEATURE_CLIENT_TAGS */
393 /*********************************************************************
395 * Function : parse_numeric_value
397 * Description : Parse the value of a directive that can only have
398 * a single numeric value. Terminates with a fatal error
399 * if the value is NULL or not numeric.
402 * 1 : name: The name of the directive. Used for log messages.
403 * 2 : value: The value to parse
406 * Returns : The numerical value as integer
408 *********************************************************************/
409 static int parse_numeric_value(const char *name, const char *value)
414 assert(name != NULL);
415 assert(value != NULL);
417 if ((value == NULL) || (*value == '\0'))
419 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
422 number = (int)strtol(value, &endptr, 0);
425 log_error(LOG_LEVEL_FATAL,
426 "Directive '%s' used with non-numerical value: '%s'", name, value);
434 /*********************************************************************
436 * Function : parse_toggle_value
438 * Description : Parse the value of a directive that can only be
439 * enabled or disabled. Terminates with a fatal error
440 * if the value is NULL or something other than 0 or 1.
443 * 1 : name: The name of the directive. Used for log messages.
444 * 2 : value: The value to parse
447 * Returns : The numerical toggle state
449 *********************************************************************/
450 static int parse_toggle_state(const char *name, const char *value)
453 assert(name != NULL);
454 assert(value != NULL);
456 if ((value == NULL) || (*value == '\0'))
458 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
461 toggle_state = atoi(value);
464 * Also check the length as atoi() doesn't mind
465 * garbage after a valid integer, but we do.
467 if (((toggle_state != 0) && (toggle_state != 1)) || (strlen(value) != 1))
469 log_error(LOG_LEVEL_FATAL,
470 "Directive %s used with invalid argument '%s'. Use either '0' or '1'.",
479 /*********************************************************************
481 * Function : parse_client_header_order
483 * Description : Parse the value of the header-order directive
486 * 1 : ordered_header_list: List to insert the ordered
488 * 2 : ordered_headers: The ordered header names separated
494 *********************************************************************/
495 static void parse_client_header_order(struct list *ordered_header_list, const char *ordered_headers)
497 char *original_headers_copy;
500 int number_of_headers;
503 assert(ordered_header_list != NULL);
504 assert(ordered_headers != NULL);
506 if (ordered_headers == NULL)
508 log_error(LOG_LEVEL_FATAL, "header-order used without argument");
512 * XXX: This estimate is guaranteed to be high enough as we
513 * let ssplit() ignore empty fields, but also a bit wasteful.
514 * The same hack is used in get_last_url() so it looks like
515 * a real solution is needed.
517 max_segments = strlen(ordered_headers) / 2;
518 if (max_segments == 0)
522 vector = malloc_or_die(max_segments * sizeof(char *));
524 original_headers_copy = strdup_or_die(ordered_headers);
526 number_of_headers = ssplit(original_headers_copy, "\t ", vector, max_segments);
527 if (number_of_headers == -1)
529 log_error(LOG_LEVEL_FATAL, "Failed to split ordered headers");
532 for (i = 0; i < number_of_headers; i++)
534 if (JB_ERR_OK != enlist(ordered_header_list, vector[i]))
536 log_error(LOG_LEVEL_FATAL,
537 "Failed to enlist ordered header: %s", vector[i]);
542 freez(original_headers_copy);
549 /*********************************************************************
551 * Function : load_config
553 * Description : Load the config file and all parameters.
555 * XXX: more than thousand lines long
556 * and thus in serious need of refactoring.
560 * Returns : The configuration_spec, or NULL on error.
562 *********************************************************************/
563 struct configuration_spec * load_config(void)
567 FILE *configfp = NULL;
568 struct configuration_spec * config = NULL;
569 struct client_state * fake_csp;
570 struct file_list *fs;
571 unsigned long linenum = 0;
573 char *logfile = NULL;
575 if (!check_file_changed(current_configfile, configfile, &fs))
577 /* No need to load */
578 return ((struct configuration_spec *)current_configfile->f);
582 log_error(LOG_LEVEL_FATAL,
583 "can't check configuration file '%s': %E", configfile);
587 if (NULL != current_configfile)
589 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
592 #ifdef FEATURE_TOGGLE
593 global_toggle_state = 1;
594 #endif /* def FEATURE_TOGGLE */
596 fs->f = config = zalloc_or_die(sizeof(*config));
599 * This is backwards from how it's usually done.
600 * Following the usual pattern, "fs" would be stored in a member
601 * variable in "csp", and then we'd access "config" from "fs->f",
602 * using a cast. However, "config" is used so often that a
603 * cast each time would be very ugly, and the extra indirection
604 * would waste CPU cycles. Therefore we store "config" in
605 * "csp->config", and "fs" in "csp->config->config_file_list".
607 config->config_file_list = fs;
612 config->multi_threaded = 1;
613 config->buffer_limit = 4096 * 1024;
614 config->receive_buffer_size = BUFFER_SIZE;
615 config->usermanual = strdup_or_die(USER_MANUAL_URL);
616 config->proxy_args = strdup_or_die("");
617 config->forwarded_connect_retries = 0;
618 #ifdef FEATURE_CLIENT_TAGS
619 config->client_tag_lifetime = 60;
621 config->trust_x_forwarded_for = 0;
622 #if defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER)
623 config->enable_accept_filter = 0;
625 config->listen_backlog = DEFAULT_LISTEN_BACKLOG;
626 config->trusted_cgi_referrer = NULL;
628 * 128 client sockets ought to be enough for everybody who can't
629 * be bothered to read the documentation to figure out how to
630 * increase the limit.
632 config->max_client_connections = 128;
633 config->socket_timeout = 300; /* XXX: Should be a macro. */
634 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
635 config->default_server_timeout = 0;
636 config->keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
637 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
638 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
640 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
641 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
642 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
643 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
644 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
645 #ifdef FEATURE_COMPRESSION
646 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
648 * XXX: Run some benchmarks to see if there are better default values.
650 config->compression_level = 1;
652 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
654 configfp = fopen(configfile, "r");
655 if (NULL == configfp)
657 log_error(LOG_LEVEL_FATAL,
658 "can't open configuration file '%s': %E", configfile);
659 /* Never get here - LOG_LEVEL_FATAL causes program exit */
662 while (read_config_line(configfp, &linenum, &buf) != NULL)
664 char cmd[BUFFER_SIZE];
665 char arg[BUFFER_SIZE];
666 char tmp[BUFFER_SIZE];
668 struct access_control_list *cur_acl;
669 #endif /* def FEATURE_ACL */
670 struct forward_spec *cur_fwd;
673 unsigned int directive_hash;
675 strlcpy(tmp, buf, sizeof(tmp));
677 /* Copy command (i.e. up to space or tab) into cmd */
680 while (*p && (*p != ' ') && (*p != '\t'))
686 /* Skip over the whitespace in buf */
687 while (*p && ((*p == ' ') || (*p == '\t')))
692 /* Copy the argument into arg */
693 if (strlcpy(arg, p, sizeof(arg)) >= sizeof(arg))
695 log_error(LOG_LEVEL_FATAL, "Config line too long: %s", buf);
698 /* Should never happen, but check this anyway */
705 /* Make sure the command field is lower case */
706 for (p = cmd; *p; p++)
708 if (privoxy_isupper(*p))
710 *p = (char)privoxy_tolower(*p);
714 directive_hash = hash_string(cmd);
715 switch (directive_hash)
717 /* *************************************************************************
718 * actionsfile actions-file-name
719 * In confdir by default
720 * *************************************************************************/
721 case hash_actions_file :
723 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
728 if (i >= MAX_AF_FILES)
730 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
731 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
734 config->actions_file_short[i] = strdup_or_die(arg);
735 config->actions_file[i] = make_path(config->confdir, arg);
738 /* *************************************************************************
739 * accept-intercepted-requests
740 * *************************************************************************/
741 case hash_accept_intercepted_requests:
742 if (parse_toggle_state(cmd, arg) == 1)
744 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
748 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
752 /* *************************************************************************
753 * admin-address email-address
754 * *************************************************************************/
755 case hash_admin_address :
756 freez(config->admin_address);
757 config->admin_address = strdup_or_die(arg);
760 /* *************************************************************************
761 * allow-cgi-request-crunching
762 * *************************************************************************/
763 case hash_allow_cgi_request_crunching:
764 if (parse_toggle_state(cmd, arg) == 1)
766 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
770 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
774 /* *************************************************************************
776 * *************************************************************************/
777 case hash_buffer_limit :
778 config->buffer_limit = (size_t)(1024 * parse_numeric_value(cmd, arg));
781 /* *************************************************************************
782 * client-header-order header-1 header-2 ... header-n
783 * *************************************************************************/
784 case hash_client_header_order:
785 list_remove_all(config->ordered_client_headers);
786 parse_client_header_order(config->ordered_client_headers, arg);
789 /* *************************************************************************
790 * client-specific-tag tag-name description
791 * *************************************************************************/
792 #ifdef FEATURE_CLIENT_TAGS
793 case hash_client_specific_tag:
799 description = strstr(arg, " ");
800 if (description == NULL)
802 log_error(LOG_LEVEL_FATAL,
803 "client-specific-tag '%s' lacks a description.", name);
807 * The length is limited because we don't want truncated
808 * HTML caused by the cgi interface using static buffer
811 if (strlen(name) > CLIENT_TAG_LENGTH_MAX)
813 log_error(LOG_LEVEL_FATAL,
814 "client-specific-tag '%s' is longer than %d characters.",
815 name, CLIENT_TAG_LENGTH_MAX);
818 register_tag(config->client_tags, name, description);
821 #endif /* def FEATURE_CLIENT_TAGS */
823 /* *************************************************************************
824 * client-tag-lifetime ttl
825 * *************************************************************************/
826 #ifdef FEATURE_CLIENT_TAGS
827 case hash_client_tag_lifetime:
829 int ttl = parse_numeric_value(cmd, arg);
832 config->client_tag_lifetime = (unsigned)ttl;
836 log_error(LOG_LEVEL_FATAL,
837 "client-tag-lifetime can't be negative.");
841 #endif /* def FEATURE_CLIENT_TAGS */
843 /* *************************************************************************
844 * confdir directory-name
845 * *************************************************************************/
847 freez(config->confdir);
848 config->confdir = make_path(NULL, arg);
851 /* *************************************************************************
852 * compression-level 0-9
853 * *************************************************************************/
854 #ifdef FEATURE_COMPRESSION
855 case hash_compression_level :
857 int compression_level = parse_numeric_value(cmd, arg);
858 if (-1 <= compression_level && compression_level <= 9)
860 config->compression_level = compression_level;
864 log_error(LOG_LEVEL_FATAL,
865 "Invalid compression-level value: %s", arg);
871 /* *************************************************************************
872 * connection-sharing (0|1)
873 * *************************************************************************/
874 #ifdef FEATURE_CONNECTION_SHARING
875 case hash_connection_sharing :
876 if (parse_toggle_state(cmd, arg) == 1)
878 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_SHARING;
882 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
887 /* *************************************************************************
889 * Specifies debug level, multiple values are ORed together.
890 * *************************************************************************/
892 config->debug |= parse_numeric_value(cmd, arg);
895 /* *************************************************************************
896 * default-server-timeout timeout
897 * *************************************************************************/
898 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
899 case hash_default_server_timeout :
901 int timeout = parse_numeric_value(cmd, arg);
904 config->default_server_timeout = (unsigned int)timeout;
908 log_error(LOG_LEVEL_FATAL,
909 "Invalid default-server-timeout value: %s", arg);
915 /* *************************************************************************
916 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
917 * *************************************************************************/
919 case hash_deny_access:
920 strlcpy(tmp, arg, sizeof(tmp));
921 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
923 if ((vec_count != 1) && (vec_count != 2))
925 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
926 "deny-access directive in configuration file.");
927 string_append(&config->proxy_args,
928 "<br>\nWARNING: Wrong number of parameters for "
929 "deny-access directive in configuration file.<br><br>\n");
933 /* allocate a new node */
934 cur_acl = zalloc_or_die(sizeof(*cur_acl));
935 cur_acl->action = ACL_DENY;
937 if (acl_addr(vec[0], cur_acl->src) < 0)
939 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
940 "for deny-access directive in configuration file: \"%s\"", vec[0]);
941 string_append(&config->proxy_args,
942 "<br>\nWARNING: Invalid source address, port or netmask "
943 "for deny-access directive in configuration file: \"");
944 string_append(&config->proxy_args,
946 string_append(&config->proxy_args,
953 if (acl_addr(vec[1], cur_acl->dst) < 0)
955 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
956 "for deny-access directive in configuration file: \"%s\"", vec[1]);
957 string_append(&config->proxy_args,
958 "<br>\nWARNING: Invalid destination address, port or netmask "
959 "for deny-access directive in configuration file: \"");
960 string_append(&config->proxy_args,
962 string_append(&config->proxy_args,
971 cur_acl->wildcard_dst = 1;
973 #endif /* def HAVE_RFC2553 */
976 * Add it to the list. Note we reverse the list to get the
977 * behaviour the user expects. With both the ACL and
978 * actions file, the last match wins. However, the internal
979 * implementations are different: The actions file is stored
980 * in the same order as the file, and scanned completely.
981 * With the ACL, we reverse the order as we load it, then
982 * when we scan it we stop as soon as we get a match.
984 cur_acl->next = config->acl;
985 config->acl = cur_acl;
988 #endif /* def FEATURE_ACL */
990 #if defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER)
991 /* *************************************************************************
992 * enable-accept-filter 0|1
993 * *************************************************************************/
994 case hash_enable_accept_filter :
995 config->enable_accept_filter = parse_toggle_state(cmd, arg);
997 #endif /* defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER) */
999 /* *************************************************************************
1000 * enable-edit-actions 0|1
1001 * *************************************************************************/
1002 #ifdef FEATURE_CGI_EDIT_ACTIONS
1003 case hash_enable_edit_actions:
1004 if (parse_toggle_state(cmd, arg) == 1)
1006 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1010 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1013 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1015 /* *************************************************************************
1016 * enable-compression 0|1
1017 * *************************************************************************/
1018 #ifdef FEATURE_COMPRESSION
1019 case hash_enable_compression:
1020 if (parse_toggle_state(cmd, arg) == 1)
1022 config->feature_flags |= RUNTIME_FEATURE_COMPRESSION;
1026 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
1029 #endif /* def FEATURE_COMPRESSION */
1031 /* *************************************************************************
1032 * enable-proxy-authentication-forwarding 0|1
1033 * *************************************************************************/
1034 case hash_enable_proxy_authentication_forwarding:
1035 if (parse_toggle_state(cmd, arg) == 1)
1037 config->feature_flags |= RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1041 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1045 /* *************************************************************************
1046 * enable-remote-toggle 0|1
1047 * *************************************************************************/
1048 #ifdef FEATURE_TOGGLE
1049 case hash_enable_remote_toggle:
1050 if (parse_toggle_state(cmd, arg) == 1)
1052 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1056 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1059 #endif /* def FEATURE_TOGGLE */
1061 /* *************************************************************************
1062 * enable-remote-http-toggle 0|1
1063 * *************************************************************************/
1064 case hash_enable_remote_http_toggle:
1065 if (parse_toggle_state(cmd, arg) == 1)
1067 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1071 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1075 /* *************************************************************************
1076 * enforce-blocks 0|1
1077 * *************************************************************************/
1078 case hash_enforce_blocks:
1079 #ifdef FEATURE_FORCE_LOAD
1080 if (parse_toggle_state(cmd, arg) == 1)
1082 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1086 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1089 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1090 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1091 #endif /* def FEATURE_FORCE_LOAD */
1094 /* *************************************************************************
1095 * filterfile file-name
1096 * In confdir by default.
1097 * *************************************************************************/
1098 case hash_filterfile :
1100 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1105 if (i >= MAX_AF_FILES)
1107 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1108 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1111 config->re_filterfile_short[i] = strdup_or_die(arg);
1112 config->re_filterfile[i] = make_path(config->confdir, arg);
1116 /* *************************************************************************
1117 * forward url-pattern (.|http-proxy-host[:port])
1118 * *************************************************************************/
1120 strlcpy(tmp, arg, sizeof(tmp));
1121 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1125 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1126 "directive in configuration file.");
1127 string_append(&config->proxy_args,
1128 "<br>\nWARNING: Wrong number of parameters for "
1129 "forward directive in configuration file.");
1133 /* allocate a new node */
1134 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1135 cur_fwd->type = SOCKS_NONE;
1137 /* Save the URL pattern */
1138 if (create_pattern_spec(cur_fwd->url, vec[0]))
1140 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1141 "directive in configuration file.");
1142 string_append(&config->proxy_args,
1143 "<br>\nWARNING: Bad URL specifier for "
1144 "forward directive in configuration file.");
1149 /* Parse the parent HTTP proxy host:port */
1152 if (strcmp(p, ".") != 0)
1154 cur_fwd->forward_port = 8000;
1155 parse_forwarder_address(p, &cur_fwd->forward_host,
1156 &cur_fwd->forward_port);
1160 cur_fwd->next = config->forward;
1161 config->forward = cur_fwd;
1165 /* *************************************************************************
1166 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1167 * *************************************************************************/
1168 case hash_forward_socks4:
1169 strlcpy(tmp, arg, sizeof(tmp));
1170 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1174 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1175 "forward-socks4 directive in configuration file.");
1176 string_append(&config->proxy_args,
1177 "<br>\nWARNING: Wrong number of parameters for "
1178 "forward-socks4 directive in configuration file.");
1182 /* allocate a new node */
1183 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1184 cur_fwd->type = SOCKS_4;
1186 /* Save the URL pattern */
1187 if (create_pattern_spec(cur_fwd->url, vec[0]))
1189 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1190 "directive in configuration file.");
1191 string_append(&config->proxy_args,
1192 "<br>\nWARNING: Bad URL specifier for "
1193 "forward-socks4 directive in configuration file.");
1198 /* Parse the SOCKS proxy host[:port] */
1201 /* XXX: This check looks like a bug. */
1202 if (strcmp(p, ".") != 0)
1204 cur_fwd->gateway_port = 1080;
1205 parse_forwarder_address(p, &cur_fwd->gateway_host,
1206 &cur_fwd->gateway_port);
1209 /* Parse the parent HTTP proxy host[:port] */
1212 if (strcmp(p, ".") != 0)
1214 cur_fwd->forward_port = 8000;
1215 parse_forwarder_address(p, &cur_fwd->forward_host,
1216 &cur_fwd->forward_port);
1220 cur_fwd->next = config->forward;
1221 config->forward = cur_fwd;
1225 /* *************************************************************************
1226 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1227 * *************************************************************************/
1228 case hash_forward_socks4a:
1229 case hash_forward_socks5:
1230 case hash_forward_socks5t:
1231 strlcpy(tmp, arg, sizeof(tmp));
1232 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1236 log_error(LOG_LEVEL_ERROR,
1237 "Wrong number of parameters for %s in configuration file.",
1239 string_append(&config->proxy_args,
1240 "<br>\nWARNING: Wrong number of parameters for ");
1241 string_append(&config->proxy_args, cmd);
1242 string_append(&config->proxy_args,
1243 "directive in configuration file.");
1247 /* allocate a new node */
1248 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1250 if (directive_hash == hash_forward_socks4a)
1252 cur_fwd->type = SOCKS_4A;
1254 else if (directive_hash == hash_forward_socks5)
1256 cur_fwd->type = SOCKS_5;
1260 assert(directive_hash == hash_forward_socks5t);
1261 cur_fwd->type = SOCKS_5T;
1264 /* Save the URL pattern */
1265 if (create_pattern_spec(cur_fwd->url, vec[0]))
1267 log_error(LOG_LEVEL_ERROR,
1268 "Bad URL specifier for %s in configuration file.",
1270 string_append(&config->proxy_args,
1271 "<br>\nWARNING: Bad URL specifier for ");
1272 string_append(&config->proxy_args, cmd);
1273 string_append(&config->proxy_args,
1274 "directive in configuration file.");
1279 /* Parse the SOCKS proxy host[:port] */
1282 cur_fwd->gateway_port = 1080;
1283 parse_forwarder_address(p, &cur_fwd->gateway_host,
1284 &cur_fwd->gateway_port);
1286 /* Parse the parent HTTP proxy host[:port] */
1289 if (strcmp(p, ".") != 0)
1291 cur_fwd->forward_port = 8000;
1292 parse_forwarder_address(p, &cur_fwd->forward_host,
1293 &cur_fwd->forward_port);
1297 cur_fwd->next = config->forward;
1298 config->forward = cur_fwd;
1302 /* *************************************************************************
1303 * forwarded-connect-retries n
1304 * *************************************************************************/
1305 case hash_forwarded_connect_retries :
1306 config->forwarded_connect_retries = parse_numeric_value(cmd, arg);
1309 /* *************************************************************************
1310 * handle-as-empty-doc-returns-ok 0|1
1312 * Workaround for firefox hanging on blocked javascript pages.
1313 * Block with the "+handle-as-empty-document" flag and set the
1314 * "handle-as-empty-doc-returns-ok" run-time config flag so that
1315 * Privoxy returns a 200/OK status instead of a 403/Forbidden status
1316 * to the browser for blocked pages.
1317 ***************************************************************************/
1318 case hash_handle_as_empty_returns_ok:
1319 if (parse_toggle_state(cmd, arg) == 1)
1321 config->feature_flags |= RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1325 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1329 /* *************************************************************************
1330 * hostname hostname-to-show-on-cgi-pages
1331 * *************************************************************************/
1332 case hash_hostname :
1333 freez(config->hostname);
1334 config->hostname = strdup_or_die(arg);
1337 /* *************************************************************************
1338 * keep-alive-timeout timeout
1339 * *************************************************************************/
1340 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1341 case hash_keep_alive_timeout :
1343 int timeout = parse_numeric_value(cmd, arg);
1346 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1347 config->keep_alive_timeout = (unsigned int)timeout;
1351 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1357 /* *************************************************************************
1358 * listen-address [ip][:port]
1359 * *************************************************************************/
1360 case hash_listen_address :
1362 while ((i < MAX_LISTENING_SOCKETS) && (NULL != config->haddr[i]))
1367 if (i >= MAX_LISTENING_SOCKETS)
1369 log_error(LOG_LEVEL_FATAL, "Too many 'listen-address' directives in config file - limit is %d.\n"
1370 "(You can increase this limit by changing MAX_LISTENING_SOCKETS in project.h and recompiling).",
1371 MAX_LISTENING_SOCKETS);
1373 config->haddr[i] = strdup_or_die(arg);
1376 /* *************************************************************************
1378 * *************************************************************************/
1379 case hash_listen_backlog :
1381 * We don't enfore an upper or lower limit because on
1382 * many platforms all values are valid and negative
1383 * number mean "use the highest value allowed".
1385 config->listen_backlog = parse_numeric_value(cmd, arg);
1388 /* *************************************************************************
1389 * logdir directory-name
1390 * *************************************************************************/
1392 freez(config->logdir);
1393 config->logdir = make_path(NULL, arg);
1396 /* *************************************************************************
1397 * logfile log-file-name
1398 * In logdir by default
1399 * *************************************************************************/
1403 logfile = make_path(config->logdir, arg);
1404 if (NULL == logfile)
1406 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1411 /* *************************************************************************
1412 * max-client-connections number
1413 * *************************************************************************/
1414 case hash_max_client_connections :
1416 int max_client_connections = parse_numeric_value(cmd, arg);
1418 #if !defined(_WIN32) && !defined(HAVE_POLL)
1420 * Reject values below 1 for obvious reasons and values above
1421 * FD_SETSIZE/2 because Privoxy needs two sockets to serve
1422 * client connections that need forwarding.
1424 * We ignore the fact that the first three file descriptors
1425 * are usually set to /dev/null, one is used for logging
1426 * and yet another file descriptor is required to load
1429 if ((max_client_connections < 1) || (FD_SETSIZE/2 < max_client_connections))
1431 log_error(LOG_LEVEL_FATAL, "max-client-connections value %d"
1432 " is invalid. Value needs to be above 1 and below %d"
1433 " (FD_SETSIZE/2).", max_client_connections, FD_SETSIZE/2);
1437 * The Windows libc uses FD_SETSIZE for an array used
1438 * by select(), but has no problems with file descriptors
1439 * above the limit as long as no more than FD_SETSIZE are
1440 * passed to select().
1441 * https://msdn.microsoft.com/en-us/library/windows/desktop/ms739169%28v=vs.85%29.aspx
1443 * On platforms were we use poll() we don't have to enforce
1444 * an upper connection limit either.
1446 * XXX: Do OS/2, Amiga etc. belong here as well?
1448 if (max_client_connections < 1)
1450 log_error(LOG_LEVEL_FATAL, "max-client-connections value"
1451 " has to be a number above 1. %d is invalid.",
1452 max_client_connections);
1455 config->max_client_connections = max_client_connections;
1459 /* *************************************************************************
1460 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1461 * *************************************************************************/
1463 case hash_permit_access:
1464 strlcpy(tmp, arg, sizeof(tmp));
1465 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1467 if ((vec_count != 1) && (vec_count != 2))
1469 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1470 "permit-access directive in configuration file.");
1471 string_append(&config->proxy_args,
1472 "<br>\nWARNING: Wrong number of parameters for "
1473 "permit-access directive in configuration file.<br><br>\n");
1478 /* allocate a new node */
1479 cur_acl = zalloc_or_die(sizeof(*cur_acl));
1480 cur_acl->action = ACL_PERMIT;
1482 if (acl_addr(vec[0], cur_acl->src) < 0)
1484 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1485 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1486 string_append(&config->proxy_args,
1487 "<br>\nWARNING: Invalid source address, port or netmask for "
1488 "permit-access directive in configuration file: \"");
1489 string_append(&config->proxy_args,
1491 string_append(&config->proxy_args,
1498 if (acl_addr(vec[1], cur_acl->dst) < 0)
1500 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1501 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1502 string_append(&config->proxy_args,
1503 "<br>\nWARNING: Invalid destination address, port or netmask for "
1504 "permit-access directive in configuration file: \"");
1505 string_append(&config->proxy_args,
1507 string_append(&config->proxy_args,
1516 cur_acl->wildcard_dst = 1;
1518 #endif /* def HAVE_RFC2553 */
1521 * Add it to the list. Note we reverse the list to get the
1522 * behaviour the user expects. With both the ACL and
1523 * actions file, the last match wins. However, the internal
1524 * implementations are different: The actions file is stored
1525 * in the same order as the file, and scanned completely.
1526 * With the ACL, we reverse the order as we load it, then
1527 * when we scan it we stop as soon as we get a match.
1529 cur_acl->next = config->acl;
1530 config->acl = cur_acl;
1533 #endif /* def FEATURE_ACL */
1535 /* *************************************************************************
1536 * proxy-info-url url
1537 * *************************************************************************/
1538 case hash_proxy_info_url :
1539 freez(config->proxy_info_url);
1540 config->proxy_info_url = strdup_or_die(arg);
1544 /* *************************************************************************
1545 * receive-buffer-size n
1546 * *************************************************************************/
1547 case hash_receive_buffer_size :
1548 config->receive_buffer_size = (size_t)parse_numeric_value(cmd, arg);
1549 if (config->receive_buffer_size < BUFFER_SIZE)
1551 log_error(LOG_LEVEL_INFO,
1552 "receive-buffer-size %d seems low and may cause problems."
1553 "Consider setting it to at least %d.",
1554 config->receive_buffer_size, BUFFER_SIZE);
1558 /* *************************************************************************
1559 * single-threaded 0|1
1560 * *************************************************************************/
1561 case hash_single_threaded :
1562 config->multi_threaded = 0 == parse_toggle_state(cmd, arg);
1565 /* *************************************************************************
1566 * socket-timeout numer_of_seconds
1567 * *************************************************************************/
1568 case hash_socket_timeout :
1570 int socket_timeout = parse_numeric_value(cmd, arg);
1571 if (0 <= socket_timeout)
1573 config->socket_timeout = socket_timeout;
1577 log_error(LOG_LEVEL_FATAL, "Invalid socket-timeout: '%s'", arg);
1582 /* *************************************************************************
1583 * split-large-cgi-forms
1584 * *************************************************************************/
1585 case hash_split_large_cgi_forms :
1586 if (parse_toggle_state(cmd, arg) == 1)
1588 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1592 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1596 /* *************************************************************************
1597 * templdir directory-name
1598 * *************************************************************************/
1599 case hash_templdir :
1600 freez(config->templdir);
1601 config->templdir = make_path(NULL, arg);
1604 #ifdef FEATURE_EXTERNAL_FILTERS
1605 /* *************************************************************************
1606 * temporary-directory directory-name
1607 * *************************************************************************/
1608 case hash_temporary_directory :
1609 freez(config->temporary_directory);
1610 config->temporary_directory = make_path(NULL, arg);
1614 /* *************************************************************************
1615 * tolerate-pipelining (0|1)
1616 * *************************************************************************/
1617 case hash_tolerate_pipelining :
1618 if (parse_toggle_state(cmd, arg) == 1)
1620 config->feature_flags |= RUNTIME_FEATURE_TOLERATE_PIPELINING;
1624 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
1628 /* *************************************************************************
1630 * *************************************************************************/
1631 #ifdef FEATURE_TOGGLE
1633 global_toggle_state = parse_toggle_state(cmd, arg);
1635 #endif /* def FEATURE_TOGGLE */
1637 /* *************************************************************************
1638 * trust-info-url url
1639 * *************************************************************************/
1640 #ifdef FEATURE_TRUST
1641 case hash_trust_info_url :
1642 enlist(config->trust_info, arg);
1644 #endif /* def FEATURE_TRUST */
1646 /* *************************************************************************
1647 * trust-x-forwarded-for (0|1)
1648 * *************************************************************************/
1649 case hash_trust_x_forwarded_for :
1650 config->trust_x_forwarded_for = parse_toggle_state(cmd, arg);
1653 /* *************************************************************************
1654 * trusted-cgi-referrer http://www.example.org/some/path.html
1655 * *************************************************************************/
1656 case hash_trusted_cgi_referrer :
1658 * We don't validate the specified referrer as
1659 * it's only used for string comparison.
1661 freez(config->trusted_cgi_referrer);
1662 config->trusted_cgi_referrer = strdup_or_die(arg);
1665 /* *************************************************************************
1666 * trustfile filename
1667 * (In confdir by default.)
1668 * *************************************************************************/
1669 #ifdef FEATURE_TRUST
1670 case hash_trustfile :
1671 freez(config->trustfile);
1672 config->trustfile = make_path(config->confdir, arg);
1674 #endif /* def FEATURE_TRUST */
1676 /* *************************************************************************
1678 * *************************************************************************/
1679 case hash_usermanual :
1681 * XXX: If this isn't the first config directive, the
1682 * show-status page links to the website documentation
1683 * for the directives that were already parsed. Lame.
1685 freez(config->usermanual);
1686 config->usermanual = strdup_or_die(arg);
1689 /* *************************************************************************
1690 * Win32 Console options:
1691 * *************************************************************************/
1693 /* *************************************************************************
1695 * *************************************************************************/
1697 case hash_hide_console :
1700 #endif /*def _WIN_CONSOLE*/
1703 /* *************************************************************************
1704 * Win32 GUI options:
1705 * *************************************************************************/
1707 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1708 /* *************************************************************************
1709 * activity-animation (0|1)
1710 * *************************************************************************/
1711 case hash_activity_animation :
1712 g_bShowActivityAnimation = parse_toggle_state(cmd, arg);
1715 /* *************************************************************************
1716 * close-button-minimizes (0|1)
1717 * *************************************************************************/
1718 case hash_close_button_minimizes :
1719 g_bCloseHidesWindow = parse_toggle_state(cmd, arg);
1722 /* *************************************************************************
1723 * log-buffer-size (0|1)
1724 * *************************************************************************/
1725 case hash_log_buffer_size :
1726 g_bLimitBufferSize = parse_toggle_state(cmd, arg);
1729 /* *************************************************************************
1730 * log-font-name fontname
1731 * *************************************************************************/
1732 case hash_log_font_name :
1733 if (strlcpy(g_szFontFaceName, arg,
1734 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1736 log_error(LOG_LEVEL_FATAL,
1737 "log-font-name argument '%s' is longer than %u characters.",
1738 arg, sizeof(g_szFontFaceName)-1);
1742 /* *************************************************************************
1744 * *************************************************************************/
1745 case hash_log_font_size :
1746 g_nFontSize = parse_numeric_value(cmd, arg);
1749 /* *************************************************************************
1750 * log-highlight-messages (0|1)
1751 * *************************************************************************/
1752 case hash_log_highlight_messages :
1753 g_bHighlightMessages = parse_toggle_state(cmd, arg);
1756 /* *************************************************************************
1758 * *************************************************************************/
1759 case hash_log_max_lines :
1760 g_nMaxBufferLines = parse_numeric_value(cmd, arg);
1763 /* *************************************************************************
1764 * log-messages (0|1)
1765 * *************************************************************************/
1766 case hash_log_messages :
1767 g_bLogMessages = parse_toggle_state(cmd, arg);
1770 /* *************************************************************************
1771 * show-on-task-bar (0|1)
1772 * *************************************************************************/
1773 case hash_show_on_task_bar :
1774 g_bShowOnTaskBar = parse_toggle_state(cmd, arg);
1777 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1780 /* *************************************************************************
1781 * Warnings about unsupported features
1782 * *************************************************************************/
1784 case hash_deny_access:
1785 #endif /* ndef FEATURE_ACL */
1786 #ifndef FEATURE_CGI_EDIT_ACTIONS
1787 case hash_enable_edit_actions:
1788 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1789 #ifndef FEATURE_TOGGLE
1790 case hash_enable_remote_toggle:
1791 #endif /* ndef FEATURE_TOGGLE */
1793 case hash_permit_access:
1794 #endif /* ndef FEATURE_ACL */
1795 #ifndef FEATURE_TOGGLE
1797 #endif /* ndef FEATURE_TOGGLE */
1798 #ifndef FEATURE_TRUST
1799 case hash_trustfile :
1800 case hash_trust_info_url :
1801 #endif /* ndef FEATURE_TRUST */
1803 #ifndef _WIN_CONSOLE
1804 case hash_hide_console :
1805 #endif /* ndef _WIN_CONSOLE */
1807 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1808 case hash_activity_animation :
1809 case hash_close_button_minimizes :
1810 case hash_log_buffer_size :
1811 case hash_log_font_name :
1812 case hash_log_font_size :
1813 case hash_log_highlight_messages :
1814 case hash_log_max_lines :
1815 case hash_log_messages :
1816 case hash_show_on_task_bar :
1817 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1818 /* These warnings are annoying - so hide them. -- Jon */
1819 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1822 /* *************************************************************************/
1824 /* *************************************************************************/
1826 * I decided that I liked this better as a warning than an
1827 * error. To change back to an error, just change log level
1828 * to LOG_LEVEL_FATAL.
1830 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive "
1831 "'%s' (%uU) in line %lu in configuration file (%s).",
1832 buf, directive_hash, linenum, configfile);
1833 string_append(&config->proxy_args,
1834 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1837 /* *************************************************************************/
1838 } /* end switch(hash_string(cmd)) */
1840 /* Save the argument for the show-status page. */
1841 savearg(cmd, arg, config);
1843 } /* end while (read_config_line(...)) */
1847 set_debug_level(config->debug);
1849 freez(config->logfile);
1853 if (NULL != logfile)
1855 config->logfile = logfile;
1856 init_error_log(Argv[0], config->logfile);
1864 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1865 if (config->default_server_timeout > config->keep_alive_timeout)
1867 log_error(LOG_LEVEL_ERROR,
1868 "Reducing the default-server-timeout from %d to the keep-alive-timeout %d.",
1869 config->default_server_timeout, config->keep_alive_timeout);
1870 config->default_server_timeout = config->keep_alive_timeout;
1872 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
1874 #ifdef FEATURE_CONNECTION_SHARING
1875 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1877 if (!config->multi_threaded)
1880 * While we could use keep-alive without multiple threads
1881 * if we didn't bother with enforcing the connection timeout,
1882 * that might make Tor users sad, even though they shouldn't
1883 * enable the single-threaded option anyway.
1885 * XXX: We could still use Proxy-Connection: keep-alive.
1887 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1888 log_error(LOG_LEVEL_ERROR,
1889 "Config option single-threaded disables connection keep-alive.");
1892 else if ((config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING))
1894 log_error(LOG_LEVEL_ERROR, "Config option connection-sharing "
1895 "has no effect if keep-alive-timeout isn't set.");
1896 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
1898 #endif /* def FEATURE_CONNECTION_SHARING */
1900 if (NULL == config->proxy_args)
1902 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1905 if (config->re_filterfile[0])
1907 add_loader(load_re_filterfiles, config);
1910 if (config->actions_file[0])
1912 add_loader(load_action_files, config);
1915 #ifdef FEATURE_TRUST
1916 if (config->trustfile)
1918 add_loader(load_trustfile, config);
1920 #endif /* def FEATURE_TRUST */
1922 if (NULL == config->haddr[0])
1924 config->haddr[0] = strdup_or_die(HADDR_DEFAULT);
1927 for (i = 0; i < MAX_LISTENING_SOCKETS && NULL != config->haddr[i]; i++)
1929 if ((*config->haddr[i] == '[')
1930 && (NULL != (p = strchr(config->haddr[i], ']')))
1932 && (0 < (config->hport[i] = atoi(p + 2))))
1935 memmove((void *)config->haddr[i], config->haddr[i] + 1,
1936 (size_t)(p - config->haddr[i]));
1938 else if (NULL != (p = strchr(config->haddr[i], ':'))
1939 && (0 < (config->hport[i] = atoi(p + 1))))
1945 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr[i]);
1946 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1948 if (*config->haddr[i] == '\0')
1951 * Only the port specified. We stored it in config->hport[i]
1952 * and don't need its text representation anymore.
1953 * Use config->hport[i] == 0 to iterate listening addresses since
1956 freez(config->haddr[i]);
1961 * Want to run all the loaders once now.
1963 * Need to set up a fake csp, so they can get to the config.
1965 fake_csp = zalloc_or_die(sizeof(*fake_csp));
1966 fake_csp->config = config;
1968 if (run_loader(fake_csp))
1971 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1972 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1976 /* FIXME: this is a kludge for win32 */
1977 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1979 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1980 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1981 g_default_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1982 g_user_filterfile = config->re_filterfile[1]; /* FIXME Hope this is user.filter */
1984 #ifdef FEATURE_TRUST
1985 g_trustfile = config->trustfile;
1986 #endif /* def FEATURE_TRUST */
1989 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1990 /* FIXME: end kludge */
1993 config->need_bind = 1;
1995 if (current_configfile)
1997 struct configuration_spec * oldcfg = (struct configuration_spec *)
1998 current_configfile->f;
2000 * Check if config->haddr[i],hport[i] == oldcfg->haddr[i],hport[i]
2002 config->need_bind = 0;
2004 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
2006 if (config->hport[i] != oldcfg->hport[i])
2008 config->need_bind = 1;
2010 else if (config->haddr[i] == NULL)
2012 if (oldcfg->haddr[i] != NULL)
2014 config->need_bind = 1;
2017 else if (oldcfg->haddr[i] == NULL)
2019 config->need_bind = 1;
2021 else if (0 != strcmp(config->haddr[i], oldcfg->haddr[i]))
2023 config->need_bind = 1;
2027 current_configfile->unloader = unload_configfile;
2030 fs->next = files->next;
2033 current_configfile = fs;
2039 /*********************************************************************
2041 * Function : savearg
2043 * Description : Called from `load_config'. It saves each non-empty
2044 * and non-comment line from config into
2045 * config->proxy_args. This is used to create the
2046 * show-status page. On error, frees
2047 * config->proxy_args and sets it to NULL
2050 * 1 : command = config setting that was found
2051 * 2 : argument = the setting's argument (if any)
2052 * 3 : config = Configuration to save into.
2056 *********************************************************************/
2057 static void savearg(char *command, char *argument, struct configuration_spec * config)
2066 * Add config option name embedded in
2067 * link to its section in the user-manual
2069 buf = strdup_or_die("\n<a href=\"");
2070 if (!strncmpic(config->usermanual, "file://", 7) ||
2071 !strncmpic(config->usermanual, "http", 4))
2073 string_append(&buf, config->usermanual);
2077 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
2079 string_append(&buf, CONFIG_HELP_PREFIX);
2080 string_join (&buf, string_toupper(command));
2081 string_append(&buf, "\">");
2082 string_append(&buf, command);
2083 string_append(&buf, "</a> ");
2087 freez(config->proxy_args);
2091 if ((NULL != argument) && ('\0' != *argument))
2093 s = html_encode(argument);
2097 freez(config->proxy_args);
2101 if (strncmpic(argument, "http://", 7) == 0)
2103 string_append(&buf, "<a href=\"");
2104 string_append(&buf, s);
2105 string_append(&buf, "\">");
2106 string_join (&buf, s);
2107 string_append(&buf, "</a>");
2111 string_join (&buf, s);
2115 string_append(&buf, "<br>");
2116 string_join(&config->proxy_args, buf);