1 /*********************************************************************
3 * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
5 * Purpose : Loads settings from the configuration file into
6 * global variables. This file contains both the
7 * routine to load the configuration and the global
8 * variables it writes to.
10 * Copyright : Written by and Copyright (C) 2001-2017 the
11 * Privoxy team. https://www.privoxy.org/
13 * Based on the Internet Junkbuster originally written
14 * by and Copyright (C) 1997 Anonymous Coders and
15 * Junkbusters Corporation. http://www.junkbusters.com
17 * This program is free software; you can redistribute it
18 * and/or modify it under the terms of the GNU General
19 * Public License as published by the Free Software
20 * Foundation; either version 2 of the License, or (at
21 * your option) any later version.
23 * This program is distributed in the hope that it will
24 * be useful, but WITHOUT ANY WARRANTY; without even the
25 * implied warranty of MERCHANTABILITY or FITNESS FOR A
26 * PARTICULAR PURPOSE. See the GNU General Public
27 * License for more details.
29 * The GNU General Public License should be included with
30 * this file. If not, you can view it at
31 * http://www.gnu.org/copyleft/gpl.html
32 * or write to the Free Software Foundation, Inc., 59
33 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 *********************************************************************/
41 #include <sys/types.h>
55 # include <winsock2.h>
61 # endif /* ndef _WIN_CONSOLE */
63 #else /* ifndef _WIN32 */
66 # include <sys/wait.h>
67 # include <sys/time.h>
68 # include <sys/stat.h>
86 #ifdef FEATURE_CLIENT_TAGS
87 #include "client-tags.h"
91 * Default number of seconds after which an
92 * open connection will no longer be reused.
94 #define DEFAULT_KEEP_ALIVE_TIMEOUT 180
97 * Default backlog passed to listen().
99 #define DEFAULT_LISTEN_BACKLOG 128
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 algorithm 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_ca_cert_file 1622923720U /* "ca-cert-file" */
137 #define hash_ca_directory 1623615670U /* "ca-directory" */
138 #define hash_ca_key_file 1184187891U /* "ca-key-file" */
139 #define hash_ca_password 1184543320U /* "ca-password" */
140 #define hash_certificate_directory 1367994217U /* "certificate-directory" */
141 #define hash_cipher_list 1225729316U /* "cipher-list" */
142 #define hash_client_header_order 2701453514U /* "client-header-order" */
143 #define hash_client_specific_tag 3353703383U /* "client-specific-tag" */
144 #define hash_client_tag_lifetime 647957580U /* "client-tag-lifetime" */
145 #define hash_compression_level 2464423563U /* "compression-level" */
146 #define hash_confdir 1978389U /* "confdir" */
147 #define hash_connection_sharing 1348841265U /* "connection-sharing" */
148 #define hash_cors_allowed_origin 2769345637U /* "cors-allowed-origin" */
149 #define hash_debug 78263U /* "debug" */
150 #define hash_default_server_timeout 2530089913U /* "default-server-timeout" */
151 #define hash_deny_access 1227333715U /* "deny-access" */
152 #define hash_enable_accept_filter 2909040407U /* "enable-accept-filter" */
153 #define hash_enable_edit_actions 2517097536U /* "enable-edit-actions" */
154 #define hash_enable_compression 3943696946U /* "enable-compression" */
155 #define hash_enable_proxy_authentication_forwarding 4040610791U /* enable-proxy-authentication-forwarding */
156 #define hash_enable_remote_toggle 2979744683U /* "enable-remote-toggle" */
157 #define hash_enable_remote_http_toggle 110543988U /* "enable-remote-http-toggle" */
158 #define hash_enforce_blocks 1862427469U /* "enforce-blocks" */
159 #define hash_filterfile 250887266U /* "filterfile" */
160 #define hash_forward 2029845U /* "forward" */
161 #define hash_forward_socks4 3963965521U /* "forward-socks4" */
162 #define hash_forward_socks4a 2639958518U /* "forward-socks4a" */
163 #define hash_forward_socks5 3963965522U /* "forward-socks5" */
164 #define hash_forward_socks5t 2639958542U /* "forward-socks5t" */
165 #define hash_forwarded_connect_retries 101465292U /* "forwarded-connect-retries" */
166 #define hash_handle_as_empty_returns_ok 1444873247U /* "handle-as-empty-doc-returns-ok" */
167 #define hash_hostname 10308071U /* "hostname" */
168 #define hash_keep_alive_timeout 3878599515U /* "keep-alive-timeout" */
169 #define hash_listen_address 1255650842U /* "listen-address" */
170 #define hash_listen_backlog 1255655735U /* "listen-backlog" */
171 #define hash_logdir 422889U /* "logdir" */
172 #define hash_logfile 2114766U /* "logfile" */
173 #define hash_max_client_connections 3595884446U /* "max-client-connections" */
174 #define hash_permit_access 3587953268U /* "permit-access" */
175 #define hash_proxy_info_url 3903079059U /* "proxy-info-url" */
176 #define hash_receive_buffer_size 2880297454U /* "receive-buffer-size */
177 #define hash_single_threaded 4250084780U /* "single-threaded" */
178 #define hash_socket_timeout 1809001761U /* "socket-timeout" */
179 #define hash_split_large_cgi_forms 671658948U /* "split-large-cgi-forms" */
180 #define hash_suppress_blocklists 1948693308U /* "suppress-blocklists" */
181 #define hash_templdir 11067889U /* "templdir" */
182 #define hash_temporary_directory 1824125181U /* "temporary-directory" */
183 #define hash_tolerate_pipelining 1360286620U /* "tolerate-pipelining" */
184 #define hash_toggle 447966U /* "toggle" */
185 #define hash_trust_info_url 430331967U /* "trust-info-url" */
186 #define hash_trust_x_forwarded_for 2971537414U /* "trust-x-forwarded-for" */
187 #define hash_trusted_cgi_referrer 4270883427U /* "trusted-cgi-referrer" */
188 #define hash_trusted_cas_file 2679803024U /* "trusted-cas-files" */
189 #define hash_trustfile 56494766U /* "trustfile" */
190 #define hash_usermanual 1416668518U /* "user-manual" */
191 #define hash_activity_animation 1817904738U /* "activity-animation" */
192 #define hash_close_button_minimizes 3651284693U /* "close-button-minimizes" */
193 #define hash_hide_console 2048809870U /* "hide-console" */
194 #define hash_log_buffer_size 2918070425U /* "log-buffer-size" */
195 #define hash_log_font_name 2866730124U /* "log-font-name" */
196 #define hash_log_font_size 2866731014U /* "log-font-size" */
197 #define hash_log_highlight_messages 4032101240U /* "log-highlight-messages" */
198 #define hash_log_max_lines 2868344173U /* "log-max-lines" */
199 #define hash_log_messages 2291744899U /* "log-messages" */
200 #define hash_show_on_task_bar 215410365U /* "show-on-task-bar" */
203 static void savearg(char *command, char *argument, struct configuration_spec * config);
204 #ifdef FEATURE_CLIENT_TAGS
205 static void free_client_specific_tags(struct client_tag_spec *tag_list);
208 /*********************************************************************
210 * Function : unload_configfile
212 * Description : Free the config structure and all components.
215 * 1 : data: struct configuration_spec to unload
219 *********************************************************************/
220 static void unload_configfile (void * data)
222 struct configuration_spec * config = (struct configuration_spec *)data;
223 struct forward_spec *cur_fwd = config->forward;
227 struct access_control_list *cur_acl = config->acl;
229 while (cur_acl != NULL)
231 struct access_control_list * next_acl = cur_acl->next;
236 #endif /* def FEATURE_ACL */
238 while (cur_fwd != NULL)
240 struct forward_spec * next_fwd = cur_fwd->next;
242 unload_forward_spec(cur_fwd);
246 config->forward = NULL;
248 freez(config->confdir);
249 freez(config->logdir);
250 freez(config->templdir);
251 freez(config->hostname);
252 #ifdef FEATURE_EXTERNAL_FILTERS
253 freez(config->temporary_directory);
256 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
258 freez(config->haddr[i]);
260 freez(config->logfile);
262 for (i = 0; i < MAX_AF_FILES; i++)
264 freez(config->actions_file_short[i]);
265 freez(config->actions_file[i]);
266 freez(config->re_filterfile_short[i]);
267 freez(config->re_filterfile[i]);
270 list_remove_all(config->ordered_client_headers);
272 freez(config->admin_address);
273 freez(config->cors_allowed_origin);
274 freez(config->proxy_info_url);
275 freez(config->proxy_args);
276 freez(config->usermanual);
277 freez(config->trusted_cgi_referrer);
279 #ifdef FEATURE_HTTPS_INSPECTION
280 freez(config->ca_password);
281 freez(config->ca_directory);
282 freez(config->ca_cert_file);
283 freez(config->ca_key_file);
284 freez(config->certificate_directory);
285 freez(config->cipher_list);
286 freez(config->trusted_cas_file);
290 freez(config->trustfile);
291 list_remove_all(config->trust_info);
292 #endif /* def FEATURE_TRUST */
294 #ifdef FEATURE_CLIENT_TAGS
295 free_client_specific_tags(config->client_tags);
302 #ifdef FEATURE_GRACEFUL_TERMINATION
303 /*********************************************************************
305 * Function : unload_current_config_file
307 * Description : Unloads current config file - reset to state at
308 * beginning of program.
314 *********************************************************************/
315 void unload_current_config_file(void)
317 if (current_configfile)
319 current_configfile->unloader = unload_configfile;
320 current_configfile = NULL;
326 #ifdef FEATURE_CLIENT_TAGS
327 /*********************************************************************
329 * Function : register_tag
331 * Description : Registers a client-specific-tag and its description
334 * 1 : config: The tag list
335 * 2 : name: The name of the client-specific-tag
336 * 3 : description: The human-readable description for the tag
340 *********************************************************************/
341 static void register_tag(struct client_tag_spec *tag_list,
342 const char *name, const char *description)
344 struct client_tag_spec *new_tag;
345 struct client_tag_spec *last_tag;
348 while (last_tag->next != NULL)
350 last_tag = last_tag->next;
352 if (last_tag->name == NULL)
359 new_tag = zalloc_or_die(sizeof(struct client_tag_spec));
361 new_tag->name = strdup_or_die(name);
362 new_tag->description = strdup_or_die(description);
363 if (new_tag != last_tag)
365 last_tag->next = new_tag;
370 /*********************************************************************
372 * Function : free_client_specific_tags
374 * Description : Frees client-specific tags and their descriptions
377 * 1 : tag_list: The tag list to free
381 *********************************************************************/
382 static void free_client_specific_tags(struct client_tag_spec *tag_list)
384 struct client_tag_spec *this_tag;
385 struct client_tag_spec *next_tag;
391 next_tag = next_tag->next;
393 freez(this_tag->name);
394 freez(this_tag->description);
396 if (this_tag != tag_list)
400 } while (next_tag != NULL);
402 #endif /* def FEATURE_CLIENT_TAGS */
405 /*********************************************************************
407 * Function : parse_numeric_value
409 * Description : Parse the value of a directive that can only have
410 * a single numeric value. Terminates with a fatal error
411 * if the value is NULL or not numeric.
414 * 1 : name: The name of the directive. Used for log messages.
415 * 2 : value: The value to parse
418 * Returns : The numerical value as integer
420 *********************************************************************/
421 static int parse_numeric_value(const char *name, const char *value)
426 assert(name != NULL);
427 assert(value != NULL);
429 if ((value == NULL) || (*value == '\0'))
431 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
434 number = (int)strtol(value, &endptr, 0);
437 log_error(LOG_LEVEL_FATAL,
438 "Directive '%s' used with non-numerical value: '%s'", name, value);
446 /*********************************************************************
448 * Function : parse_toggle_value
450 * Description : Parse the value of a directive that can only be
451 * enabled or disabled. Terminates with a fatal error
452 * if the value is NULL or something other than 0 or 1.
455 * 1 : name: The name of the directive. Used for log messages.
456 * 2 : value: The value to parse
459 * Returns : The numerical toggle state
461 *********************************************************************/
462 static int parse_toggle_state(const char *name, const char *value)
465 assert(name != NULL);
466 assert(value != NULL);
468 if ((value == NULL) || (*value == '\0'))
470 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
473 toggle_state = atoi(value);
476 * Also check the length as atoi() doesn't mind
477 * garbage after a valid integer, but we do.
479 if (((toggle_state != 0) && (toggle_state != 1)) || (strlen(value) != 1))
481 log_error(LOG_LEVEL_FATAL,
482 "Directive %s used with invalid argument '%s'. Use either '0' or '1'.",
491 /*********************************************************************
493 * Function : parse_client_header_order
495 * Description : Parse the value of the header-order directive
498 * 1 : ordered_header_list: List to insert the ordered
500 * 2 : ordered_headers: The ordered header names separated
506 *********************************************************************/
507 static void parse_client_header_order(struct list *ordered_header_list, const char *ordered_headers)
509 char *original_headers_copy;
512 int number_of_headers;
515 assert(ordered_header_list != NULL);
516 assert(ordered_headers != NULL);
518 if (ordered_headers == NULL)
520 log_error(LOG_LEVEL_FATAL, "header-order used without argument");
524 * XXX: This estimate is guaranteed to be high enough as we
525 * let ssplit() ignore empty fields, but also a bit wasteful.
526 * The same hack is used in get_last_url() so it looks like
527 * a real solution is needed.
529 max_segments = strlen(ordered_headers) / 2;
530 if (max_segments == 0)
534 vector = malloc_or_die(max_segments * sizeof(char *));
536 original_headers_copy = strdup_or_die(ordered_headers);
538 number_of_headers = ssplit(original_headers_copy, "\t ", vector, max_segments);
539 if (number_of_headers == -1)
541 log_error(LOG_LEVEL_FATAL, "Failed to split ordered headers");
544 for (i = 0; i < number_of_headers; i++)
546 if (JB_ERR_OK != enlist(ordered_header_list, vector[i]))
548 log_error(LOG_LEVEL_FATAL,
549 "Failed to enlist ordered header: %s", vector[i]);
554 freez(original_headers_copy);
561 /*********************************************************************
563 * Function : load_config
565 * Description : Load the config file and all parameters.
567 * XXX: more than thousand lines long
568 * and thus in serious need of refactoring.
572 * Returns : The configuration_spec, or NULL on error.
574 *********************************************************************/
575 struct configuration_spec * load_config(void)
579 FILE *configfp = NULL;
580 struct configuration_spec * config = NULL;
581 struct client_state * fake_csp;
582 struct file_list *fs;
583 unsigned long linenum = 0;
585 char *logfile = NULL;
586 #ifdef FEATURE_HTTPS_INSPECTION
587 char *ca_cert_file = NULL;
588 char *ca_key_file = NULL;
589 char *ca_directory = NULL;
590 char *trusted_cas_file = NULL;
591 char *certificate_directory = NULL;
594 if (!check_file_changed(current_configfile, configfile, &fs))
596 /* No need to load */
597 return ((struct configuration_spec *)current_configfile->f);
601 log_error(LOG_LEVEL_FATAL,
602 "can't check configuration file '%s': %E", configfile);
606 if (NULL != current_configfile)
608 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
611 #ifdef FEATURE_TOGGLE
612 global_toggle_state = 1;
613 #endif /* def FEATURE_TOGGLE */
615 fs->f = config = zalloc_or_die(sizeof(*config));
618 * This is backwards from how it's usually done.
619 * Following the usual pattern, "fs" would be stored in a member
620 * variable in "csp", and then we'd access "config" from "fs->f",
621 * using a cast. However, "config" is used so often that a
622 * cast each time would be very ugly, and the extra indirection
623 * would waste CPU cycles. Therefore we store "config" in
624 * "csp->config", and "fs" in "csp->config->config_file_list".
626 config->config_file_list = fs;
631 config->multi_threaded = 1;
632 config->buffer_limit = 4096 * 1024;
633 config->receive_buffer_size = BUFFER_SIZE;
634 config->usermanual = strdup_or_die(USER_MANUAL_URL);
635 config->proxy_args = strdup_or_die("");
636 config->forwarded_connect_retries = 0;
637 #ifdef FEATURE_HTTPS_INSPECTION
638 config->ca_password = strdup("");
639 ca_cert_file = strdup("cacert.crt");
640 ca_key_file = strdup("cakey.pem");
641 ca_directory = strdup("./CA");
642 trusted_cas_file = strdup("trustedCAs.pem");
643 certificate_directory = strdup("./certs");
646 #ifdef FEATURE_CLIENT_TAGS
647 config->client_tag_lifetime = 60;
649 config->trust_x_forwarded_for = 0;
650 #if defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER)
651 config->enable_accept_filter = 0;
653 config->listen_backlog = DEFAULT_LISTEN_BACKLOG;
654 config->trusted_cgi_referrer = NULL;
656 * 128 client sockets ought to be enough for everybody who can't
657 * be bothered to read the documentation to figure out how to
658 * increase the limit.
660 config->max_client_connections = 128;
661 config->socket_timeout = 300; /* XXX: Should be a macro. */
662 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
663 config->default_server_timeout = 0;
664 config->keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
665 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
666 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
668 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
669 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
670 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
671 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
672 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
673 #ifdef FEATURE_COMPRESSION
674 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
676 * XXX: Run some benchmarks to see if there are better default values.
678 config->compression_level = 1;
680 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
681 config->cors_allowed_origin = NULL;
683 configfp = fopen(configfile, "r");
684 if (NULL == configfp)
686 log_error(LOG_LEVEL_FATAL,
687 "can't open configuration file '%s': %E", configfile);
688 /* Never get here - LOG_LEVEL_FATAL causes program exit */
691 while (read_config_line(configfp, &linenum, &buf) != NULL)
693 char cmd[BUFFER_SIZE];
694 char arg[BUFFER_SIZE];
695 char tmp[BUFFER_SIZE];
697 struct access_control_list *cur_acl;
698 #endif /* def FEATURE_ACL */
699 struct forward_spec *cur_fwd;
702 unsigned int directive_hash;
704 strlcpy(tmp, buf, sizeof(tmp));
706 /* Copy command (i.e. up to space or tab) into cmd */
709 while (*p && (*p != ' ') && (*p != '\t'))
715 /* Skip over the whitespace in buf */
716 while (*p && ((*p == ' ') || (*p == '\t')))
721 /* Copy the argument into arg */
722 if (strlcpy(arg, p, sizeof(arg)) >= sizeof(arg))
724 log_error(LOG_LEVEL_FATAL, "Config line too long: %s", buf);
727 /* Should never happen, but check this anyway */
734 /* Make sure the command field is lower case */
735 for (p = cmd; *p; p++)
737 if (privoxy_isupper(*p))
739 *p = (char)privoxy_tolower(*p);
743 directive_hash = hash_string(cmd);
744 switch (directive_hash)
746 /* *************************************************************************
747 * actionsfile actions-file-name
748 * In confdir by default
749 * *************************************************************************/
750 case hash_actions_file :
752 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
757 if (i >= MAX_AF_FILES)
759 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
760 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
763 config->actions_file_short[i] = strdup_or_die(arg);
764 config->actions_file[i] = make_path(config->confdir, arg);
767 /* *************************************************************************
768 * accept-intercepted-requests
769 * *************************************************************************/
770 case hash_accept_intercepted_requests:
771 if (parse_toggle_state(cmd, arg) == 1)
773 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
777 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
781 /* *************************************************************************
782 * admin-address email-address
783 * *************************************************************************/
784 case hash_admin_address :
785 freez(config->admin_address);
786 config->admin_address = strdup_or_die(arg);
789 /* *************************************************************************
790 * allow-cgi-request-crunching
791 * *************************************************************************/
792 case hash_allow_cgi_request_crunching:
793 if (parse_toggle_state(cmd, arg) == 1)
795 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
799 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
803 /* *************************************************************************
805 * *************************************************************************/
806 case hash_buffer_limit :
807 config->buffer_limit = (size_t)(1024 * parse_numeric_value(cmd, arg));
810 /* *************************************************************************
811 * client-header-order header-1 header-2 ... header-n
812 * *************************************************************************/
813 case hash_client_header_order:
814 list_remove_all(config->ordered_client_headers);
815 parse_client_header_order(config->ordered_client_headers, arg);
818 /* *************************************************************************
819 * client-specific-tag tag-name description
820 * *************************************************************************/
821 #ifdef FEATURE_CLIENT_TAGS
822 case hash_client_specific_tag:
828 description = strstr(arg, " ");
829 if (description == NULL)
831 log_error(LOG_LEVEL_FATAL,
832 "client-specific-tag '%s' lacks a description.", name);
836 * The length is limited because we don't want truncated
837 * HTML caused by the cgi interface using static buffer
840 if (strlen(name) > CLIENT_TAG_LENGTH_MAX)
842 log_error(LOG_LEVEL_FATAL,
843 "client-specific-tag '%s' is longer than %d characters.",
844 name, CLIENT_TAG_LENGTH_MAX);
847 register_tag(config->client_tags, name, description);
850 #endif /* def FEATURE_CLIENT_TAGS */
852 /* *************************************************************************
853 * client-tag-lifetime ttl
854 * *************************************************************************/
855 #ifdef FEATURE_CLIENT_TAGS
856 case hash_client_tag_lifetime:
858 int ttl = parse_numeric_value(cmd, arg);
861 config->client_tag_lifetime = (unsigned)ttl;
865 log_error(LOG_LEVEL_FATAL,
866 "client-tag-lifetime can't be negative.");
870 #endif /* def FEATURE_CLIENT_TAGS */
872 /* *************************************************************************
873 * confdir directory-name
874 * *************************************************************************/
876 freez(config->confdir);
877 config->confdir = make_path(NULL, arg);
880 /* *************************************************************************
881 * compression-level 0-9
882 * *************************************************************************/
883 #ifdef FEATURE_COMPRESSION
884 case hash_compression_level :
886 int compression_level = parse_numeric_value(cmd, arg);
887 if (-1 <= compression_level && compression_level <= 9)
889 config->compression_level = compression_level;
893 log_error(LOG_LEVEL_FATAL,
894 "Invalid compression-level value: %s", arg);
900 /* *************************************************************************
901 * connection-sharing (0|1)
902 * *************************************************************************/
903 #ifdef FEATURE_CONNECTION_SHARING
904 case hash_connection_sharing :
905 if (parse_toggle_state(cmd, arg) == 1)
907 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_SHARING;
911 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
916 /* *************************************************************************
917 * cors-allowed-origin http://www.example.org
918 * *************************************************************************/
919 case hash_cors_allowed_origin :
921 * We don't validate the specified referrer as
922 * it's only used for string comparison.
924 freez(config->cors_allowed_origin);
925 config->cors_allowed_origin = strdup_or_die(arg);
928 /* *************************************************************************
930 * Specifies debug level, multiple values are ORed together.
931 * *************************************************************************/
933 config->debug |= parse_numeric_value(cmd, arg);
936 /* *************************************************************************
937 * default-server-timeout timeout
938 * *************************************************************************/
939 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
940 case hash_default_server_timeout :
942 int timeout = parse_numeric_value(cmd, arg);
945 config->default_server_timeout = (unsigned int)timeout;
949 log_error(LOG_LEVEL_FATAL,
950 "Invalid default-server-timeout value: %s", arg);
956 /* *************************************************************************
957 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
958 * *************************************************************************/
960 case hash_deny_access:
961 strlcpy(tmp, arg, sizeof(tmp));
962 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
964 if ((vec_count != 1) && (vec_count != 2))
966 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
967 "deny-access directive in configuration file.");
968 string_append(&config->proxy_args,
969 "<br>\nWARNING: Wrong number of parameters for "
970 "deny-access directive in configuration file.<br><br>\n");
974 /* allocate a new node */
975 cur_acl = zalloc_or_die(sizeof(*cur_acl));
976 cur_acl->action = ACL_DENY;
978 if (acl_addr(vec[0], cur_acl->src) < 0)
980 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
981 "for deny-access directive in configuration file: \"%s\"", vec[0]);
982 string_append(&config->proxy_args,
983 "<br>\nWARNING: Invalid source address, port or netmask "
984 "for deny-access directive in configuration file: \"");
985 string_append(&config->proxy_args,
987 string_append(&config->proxy_args,
994 if (acl_addr(vec[1], cur_acl->dst) < 0)
996 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
997 "for deny-access directive in configuration file: \"%s\"", vec[1]);
998 string_append(&config->proxy_args,
999 "<br>\nWARNING: Invalid destination address, port or netmask "
1000 "for deny-access directive in configuration file: \"");
1001 string_append(&config->proxy_args,
1003 string_append(&config->proxy_args,
1012 cur_acl->wildcard_dst = 1;
1014 #endif /* def HAVE_RFC2553 */
1017 * Add it to the list. Note we reverse the list to get the
1018 * behaviour the user expects. With both the ACL and
1019 * actions file, the last match wins. However, the internal
1020 * implementations are different: The actions file is stored
1021 * in the same order as the file, and scanned completely.
1022 * With the ACL, we reverse the order as we load it, then
1023 * when we scan it we stop as soon as we get a match.
1025 cur_acl->next = config->acl;
1026 config->acl = cur_acl;
1029 #endif /* def FEATURE_ACL */
1031 #if defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER)
1032 /* *************************************************************************
1033 * enable-accept-filter 0|1
1034 * *************************************************************************/
1035 case hash_enable_accept_filter :
1036 config->enable_accept_filter = parse_toggle_state(cmd, arg);
1038 #endif /* defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER) */
1040 /* *************************************************************************
1041 * enable-edit-actions 0|1
1042 * *************************************************************************/
1043 #ifdef FEATURE_CGI_EDIT_ACTIONS
1044 case hash_enable_edit_actions:
1045 if (parse_toggle_state(cmd, arg) == 1)
1047 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1051 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1054 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1056 /* *************************************************************************
1057 * enable-compression 0|1
1058 * *************************************************************************/
1059 #ifdef FEATURE_COMPRESSION
1060 case hash_enable_compression:
1061 if (parse_toggle_state(cmd, arg) == 1)
1063 config->feature_flags |= RUNTIME_FEATURE_COMPRESSION;
1067 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
1070 #endif /* def FEATURE_COMPRESSION */
1072 /* *************************************************************************
1073 * enable-proxy-authentication-forwarding 0|1
1074 * *************************************************************************/
1075 case hash_enable_proxy_authentication_forwarding:
1076 if (parse_toggle_state(cmd, arg) == 1)
1078 config->feature_flags |= RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1082 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1086 /* *************************************************************************
1087 * enable-remote-toggle 0|1
1088 * *************************************************************************/
1089 #ifdef FEATURE_TOGGLE
1090 case hash_enable_remote_toggle:
1091 if (parse_toggle_state(cmd, arg) == 1)
1093 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1097 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1100 #endif /* def FEATURE_TOGGLE */
1102 /* *************************************************************************
1103 * enable-remote-http-toggle 0|1
1104 * *************************************************************************/
1105 case hash_enable_remote_http_toggle:
1106 if (parse_toggle_state(cmd, arg) == 1)
1108 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1112 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1116 /* *************************************************************************
1117 * enforce-blocks 0|1
1118 * *************************************************************************/
1119 case hash_enforce_blocks:
1120 #ifdef FEATURE_FORCE_LOAD
1121 if (parse_toggle_state(cmd, arg) == 1)
1123 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1127 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1130 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1131 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1132 #endif /* def FEATURE_FORCE_LOAD */
1135 /* *************************************************************************
1136 * filterfile file-name
1137 * In confdir by default.
1138 * *************************************************************************/
1139 case hash_filterfile :
1141 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1146 if (i >= MAX_AF_FILES)
1148 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1149 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1152 config->re_filterfile_short[i] = strdup_or_die(arg);
1153 config->re_filterfile[i] = make_path(config->confdir, arg);
1157 /* *************************************************************************
1158 * forward url-pattern (.|http-proxy-host[:port])
1159 * *************************************************************************/
1161 strlcpy(tmp, arg, sizeof(tmp));
1162 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1166 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1167 "directive in configuration file.");
1168 string_append(&config->proxy_args,
1169 "<br>\nWARNING: Wrong number of parameters for "
1170 "forward directive in configuration file.");
1174 /* allocate a new node */
1175 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1176 cur_fwd->type = SOCKS_NONE;
1178 /* Save the URL pattern */
1179 if (create_pattern_spec(cur_fwd->url, vec[0]))
1181 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1182 "directive in configuration file.");
1183 string_append(&config->proxy_args,
1184 "<br>\nWARNING: Bad URL specifier for "
1185 "forward directive in configuration file.");
1190 /* Parse the parent HTTP proxy host:port */
1193 if (strcmp(p, ".") != 0)
1195 cur_fwd->forward_port = 8000;
1196 parse_forwarder_address(p,
1197 &cur_fwd->forward_host, &cur_fwd->forward_port,
1202 cur_fwd->next = config->forward;
1203 config->forward = cur_fwd;
1207 /* *************************************************************************
1208 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1209 * *************************************************************************/
1210 case hash_forward_socks4:
1211 strlcpy(tmp, arg, sizeof(tmp));
1212 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1216 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1217 "forward-socks4 directive in configuration file.");
1218 string_append(&config->proxy_args,
1219 "<br>\nWARNING: Wrong number of parameters for "
1220 "forward-socks4 directive in configuration file.");
1224 /* allocate a new node */
1225 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1226 cur_fwd->type = SOCKS_4;
1228 /* Save the URL pattern */
1229 if (create_pattern_spec(cur_fwd->url, vec[0]))
1231 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1232 "directive in configuration file.");
1233 string_append(&config->proxy_args,
1234 "<br>\nWARNING: Bad URL specifier for "
1235 "forward-socks4 directive in configuration file.");
1240 /* Parse the SOCKS proxy host[:port] */
1243 /* XXX: This check looks like a bug. */
1244 if (strcmp(p, ".") != 0)
1246 cur_fwd->gateway_port = 1080;
1247 parse_forwarder_address(p,
1248 &cur_fwd->gateway_host, &cur_fwd->gateway_port,
1252 /* Parse the parent HTTP proxy host[:port] */
1255 if (strcmp(p, ".") != 0)
1257 cur_fwd->forward_port = 8000;
1258 parse_forwarder_address(p,
1259 &cur_fwd->forward_host, &cur_fwd->forward_port,
1264 cur_fwd->next = config->forward;
1265 config->forward = cur_fwd;
1269 /* *************************************************************************
1270 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1271 * *************************************************************************/
1272 case hash_forward_socks4a:
1273 case hash_forward_socks5:
1274 case hash_forward_socks5t:
1275 strlcpy(tmp, arg, sizeof(tmp));
1276 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1280 log_error(LOG_LEVEL_ERROR,
1281 "Wrong number of parameters for %s in configuration file.",
1283 string_append(&config->proxy_args,
1284 "<br>\nWARNING: Wrong number of parameters for ");
1285 string_append(&config->proxy_args, cmd);
1286 string_append(&config->proxy_args,
1287 "directive in configuration file.");
1291 /* allocate a new node */
1292 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1294 if (directive_hash == hash_forward_socks4a)
1296 cur_fwd->type = SOCKS_4A;
1298 else if (directive_hash == hash_forward_socks5)
1300 cur_fwd->type = SOCKS_5;
1304 assert(directive_hash == hash_forward_socks5t);
1305 cur_fwd->type = SOCKS_5T;
1308 /* Save the URL pattern */
1309 if (create_pattern_spec(cur_fwd->url, vec[0]))
1311 log_error(LOG_LEVEL_ERROR,
1312 "Bad URL specifier for %s in configuration file.",
1314 string_append(&config->proxy_args,
1315 "<br>\nWARNING: Bad URL specifier for ");
1316 string_append(&config->proxy_args, cmd);
1317 string_append(&config->proxy_args,
1318 "directive in configuration file.");
1323 /* Parse the SOCKS proxy [user:pass@]host[:port] */
1326 cur_fwd->gateway_port = 1080;
1327 parse_forwarder_address(p,
1328 &cur_fwd->gateway_host, &cur_fwd->gateway_port,
1329 &cur_fwd->auth_username, &cur_fwd->auth_password);
1331 /* Parse the parent HTTP proxy host[:port] */
1334 if (strcmp(p, ".") != 0)
1336 cur_fwd->forward_port = 8000;
1337 parse_forwarder_address(p,
1338 &cur_fwd->forward_host, &cur_fwd->forward_port,
1343 cur_fwd->next = config->forward;
1344 config->forward = cur_fwd;
1348 /* *************************************************************************
1349 * forwarded-connect-retries n
1350 * *************************************************************************/
1351 case hash_forwarded_connect_retries :
1352 config->forwarded_connect_retries = parse_numeric_value(cmd, arg);
1355 /* *************************************************************************
1356 * handle-as-empty-doc-returns-ok 0|1
1358 * Workaround for firefox hanging on blocked javascript pages.
1359 * Block with the "+handle-as-empty-document" flag and set the
1360 * "handle-as-empty-doc-returns-ok" run-time config flag so that
1361 * Privoxy returns a 200/OK status instead of a 403/Forbidden status
1362 * to the browser for blocked pages.
1363 ***************************************************************************/
1364 case hash_handle_as_empty_returns_ok:
1365 if (parse_toggle_state(cmd, arg) == 1)
1367 config->feature_flags |= RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1371 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1375 /* *************************************************************************
1376 * hostname hostname-to-show-on-cgi-pages
1377 * *************************************************************************/
1378 case hash_hostname :
1379 freez(config->hostname);
1380 config->hostname = strdup_or_die(arg);
1383 /* *************************************************************************
1384 * keep-alive-timeout timeout
1385 * *************************************************************************/
1386 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1387 case hash_keep_alive_timeout :
1389 int timeout = parse_numeric_value(cmd, arg);
1392 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1393 config->keep_alive_timeout = (unsigned int)timeout;
1397 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1403 /* *************************************************************************
1404 * listen-address [ip][:port]
1405 * *************************************************************************/
1406 case hash_listen_address :
1408 while ((i < MAX_LISTENING_SOCKETS) && (NULL != config->haddr[i]))
1413 if (i >= MAX_LISTENING_SOCKETS)
1415 log_error(LOG_LEVEL_FATAL, "Too many 'listen-address' directives in config file - limit is %d.\n"
1416 "(You can increase this limit by changing MAX_LISTENING_SOCKETS in project.h and recompiling).",
1417 MAX_LISTENING_SOCKETS);
1419 config->haddr[i] = strdup_or_die(arg);
1422 /* *************************************************************************
1424 * *************************************************************************/
1425 case hash_listen_backlog :
1427 * We don't enfore an upper or lower limit because on
1428 * many platforms all values are valid and negative
1429 * number mean "use the highest value allowed".
1431 config->listen_backlog = parse_numeric_value(cmd, arg);
1434 /* *************************************************************************
1435 * logdir directory-name
1436 * *************************************************************************/
1438 freez(config->logdir);
1439 config->logdir = make_path(NULL, arg);
1442 /* *************************************************************************
1443 * logfile log-file-name
1444 * In logdir by default
1445 * *************************************************************************/
1449 logfile = make_path(config->logdir, arg);
1450 if (NULL == logfile)
1452 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1457 /* *************************************************************************
1458 * max-client-connections number
1459 * *************************************************************************/
1460 case hash_max_client_connections :
1462 int max_client_connections = parse_numeric_value(cmd, arg);
1464 #if !defined(_WIN32) && !defined(HAVE_POLL)
1466 * Reject values below 1 for obvious reasons and values above
1467 * FD_SETSIZE/2 because Privoxy needs two sockets to serve
1468 * client connections that need forwarding.
1470 * We ignore the fact that the first three file descriptors
1471 * are usually set to /dev/null, one is used for logging
1472 * and yet another file descriptor is required to load
1475 if ((max_client_connections < 1) || (FD_SETSIZE/2 < max_client_connections))
1477 log_error(LOG_LEVEL_FATAL, "max-client-connections value %d"
1478 " is invalid. Value needs to be above 1 and below %d"
1479 " (FD_SETSIZE/2).", max_client_connections, FD_SETSIZE/2);
1483 * The Windows libc uses FD_SETSIZE for an array used
1484 * by select(), but has no problems with file descriptors
1485 * above the limit as long as no more than FD_SETSIZE are
1486 * passed to select().
1487 * https://msdn.microsoft.com/en-us/library/windows/desktop/ms739169%28v=vs.85%29.aspx
1489 * On platforms were we use poll() we don't have to enforce
1490 * an upper connection limit either.
1492 if (max_client_connections < 1)
1494 log_error(LOG_LEVEL_FATAL, "max-client-connections value"
1495 " has to be a number above 1. %d is invalid.",
1496 max_client_connections);
1499 config->max_client_connections = max_client_connections;
1503 /* *************************************************************************
1504 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1505 * *************************************************************************/
1507 case hash_permit_access:
1508 strlcpy(tmp, arg, sizeof(tmp));
1509 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1511 if ((vec_count != 1) && (vec_count != 2))
1513 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1514 "permit-access directive in configuration file.");
1515 string_append(&config->proxy_args,
1516 "<br>\nWARNING: Wrong number of parameters for "
1517 "permit-access directive in configuration file.<br><br>\n");
1522 /* allocate a new node */
1523 cur_acl = zalloc_or_die(sizeof(*cur_acl));
1524 cur_acl->action = ACL_PERMIT;
1526 if (acl_addr(vec[0], cur_acl->src) < 0)
1528 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1529 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1530 string_append(&config->proxy_args,
1531 "<br>\nWARNING: Invalid source address, port or netmask for "
1532 "permit-access directive in configuration file: \"");
1533 string_append(&config->proxy_args,
1535 string_append(&config->proxy_args,
1542 if (acl_addr(vec[1], cur_acl->dst) < 0)
1544 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1545 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1546 string_append(&config->proxy_args,
1547 "<br>\nWARNING: Invalid destination address, port or netmask for "
1548 "permit-access directive in configuration file: \"");
1549 string_append(&config->proxy_args,
1551 string_append(&config->proxy_args,
1560 cur_acl->wildcard_dst = 1;
1562 #endif /* def HAVE_RFC2553 */
1565 * Add it to the list. Note we reverse the list to get the
1566 * behaviour the user expects. With both the ACL and
1567 * actions file, the last match wins. However, the internal
1568 * implementations are different: The actions file is stored
1569 * in the same order as the file, and scanned completely.
1570 * With the ACL, we reverse the order as we load it, then
1571 * when we scan it we stop as soon as we get a match.
1573 cur_acl->next = config->acl;
1574 config->acl = cur_acl;
1577 #endif /* def FEATURE_ACL */
1579 /* *************************************************************************
1580 * proxy-info-url url
1581 * *************************************************************************/
1582 case hash_proxy_info_url :
1583 freez(config->proxy_info_url);
1584 config->proxy_info_url = strdup_or_die(arg);
1588 /* *************************************************************************
1589 * receive-buffer-size n
1590 * *************************************************************************/
1591 case hash_receive_buffer_size :
1592 config->receive_buffer_size = (size_t)parse_numeric_value(cmd, arg);
1593 if (config->receive_buffer_size < BUFFER_SIZE)
1595 log_error(LOG_LEVEL_INFO,
1596 "receive-buffer-size %lu seems low and may cause problems."
1597 "Consider setting it to at least %d.",
1598 config->receive_buffer_size, BUFFER_SIZE);
1602 /* *************************************************************************
1603 * single-threaded 0|1
1604 * *************************************************************************/
1605 case hash_single_threaded :
1606 config->multi_threaded = 0 == parse_toggle_state(cmd, arg);
1609 /* *************************************************************************
1610 * socket-timeout numer_of_seconds
1611 * *************************************************************************/
1612 case hash_socket_timeout :
1614 int socket_timeout = parse_numeric_value(cmd, arg);
1615 if (0 <= socket_timeout)
1617 config->socket_timeout = socket_timeout;
1621 log_error(LOG_LEVEL_FATAL, "Invalid socket-timeout: '%s'", arg);
1626 /* *************************************************************************
1627 * split-large-cgi-forms
1628 * *************************************************************************/
1629 case hash_split_large_cgi_forms :
1630 if (parse_toggle_state(cmd, arg) == 1)
1632 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1636 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1640 /* *************************************************************************
1641 * templdir directory-name
1642 * *************************************************************************/
1643 case hash_templdir :
1644 freez(config->templdir);
1645 config->templdir = make_path(NULL, arg);
1648 #ifdef FEATURE_EXTERNAL_FILTERS
1649 /* *************************************************************************
1650 * temporary-directory directory-name
1651 * *************************************************************************/
1652 case hash_temporary_directory :
1653 freez(config->temporary_directory);
1654 config->temporary_directory = make_path(NULL, arg);
1658 /* *************************************************************************
1659 * tolerate-pipelining (0|1)
1660 * *************************************************************************/
1661 case hash_tolerate_pipelining :
1662 if (parse_toggle_state(cmd, arg) == 1)
1664 config->feature_flags |= RUNTIME_FEATURE_TOLERATE_PIPELINING;
1668 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
1672 /* *************************************************************************
1674 * *************************************************************************/
1675 #ifdef FEATURE_TOGGLE
1677 global_toggle_state = parse_toggle_state(cmd, arg);
1679 #endif /* def FEATURE_TOGGLE */
1681 /* *************************************************************************
1682 * trust-info-url url
1683 * *************************************************************************/
1684 #ifdef FEATURE_TRUST
1685 case hash_trust_info_url :
1686 enlist(config->trust_info, arg);
1688 #endif /* def FEATURE_TRUST */
1690 /* *************************************************************************
1691 * trust-x-forwarded-for (0|1)
1692 * *************************************************************************/
1693 case hash_trust_x_forwarded_for :
1694 config->trust_x_forwarded_for = parse_toggle_state(cmd, arg);
1697 /* *************************************************************************
1698 * trusted-cgi-referrer http://www.example.org/some/path.html
1699 * *************************************************************************/
1700 case hash_trusted_cgi_referrer :
1702 * We don't validate the specified referrer as
1703 * it's only used for string comparison.
1705 freez(config->trusted_cgi_referrer);
1706 config->trusted_cgi_referrer = strdup_or_die(arg);
1709 /* *************************************************************************
1710 * trustfile filename
1711 * (In confdir by default.)
1712 * *************************************************************************/
1713 #ifdef FEATURE_TRUST
1714 case hash_trustfile :
1715 freez(config->trustfile);
1716 config->trustfile = make_path(config->confdir, arg);
1718 #endif /* def FEATURE_TRUST */
1720 /* *************************************************************************
1722 * *************************************************************************/
1723 case hash_usermanual :
1725 * XXX: If this isn't the first config directive, the
1726 * show-status page links to the website documentation
1727 * for the directives that were already parsed. Lame.
1729 freez(config->usermanual);
1730 config->usermanual = strdup_or_die(arg);
1733 #ifdef FEATURE_HTTPS_INSPECTION
1734 /* *************************************************************************
1735 * ca private key file password
1736 * *************************************************************************/
1737 case hash_ca_password:
1738 freez(config->ca_password);
1739 config->ca_password = strdup(arg);
1742 /* *************************************************************************
1743 * ca-directory directory
1744 * *************************************************************************/
1745 case hash_ca_directory:
1746 freez(ca_directory);
1747 ca_directory = make_path(NULL, arg);
1749 if (NULL == ca_directory)
1751 log_error(LOG_LEVEL_FATAL, "Out of memory while creating ca dir path");
1756 /* *************************************************************************
1757 * ca cert file ca-cert-file
1758 * In ca dir by default
1759 * *************************************************************************/
1760 case hash_ca_cert_file:
1761 freez(ca_cert_file);
1762 ca_cert_file = make_path(config->ca_directory, arg);
1764 if (NULL == ca_cert_file)
1766 log_error(LOG_LEVEL_FATAL, "Out of memory while creating ca certificate file path");
1771 /* *************************************************************************
1772 * ca key file ca-key-file
1773 * In ca dir by default
1774 * *************************************************************************/
1775 case hash_ca_key_file:
1777 ca_key_file = make_path(config->ca_directory, arg);
1779 if (NULL == ca_key_file)
1781 log_error(LOG_LEVEL_FATAL, "Out of memory while creating ca key file path");
1786 /* *************************************************************************
1787 * certificate-directory directory
1788 * *************************************************************************/
1789 case hash_certificate_directory:
1790 freez(certificate_directory);
1791 certificate_directory = make_path(NULL, arg);
1793 if (NULL == certificate_directory)
1795 log_error(LOG_LEVEL_FATAL,
1796 "Out of memory while creating certificate directory path");
1801 /* *************************************************************************
1802 * cipher-list list-of-ciphers
1803 * *************************************************************************/
1804 case hash_cipher_list:
1805 freez(config->cipher_list);
1806 config->cipher_list = strdup_or_die(arg);
1810 /* *************************************************************************
1811 * trusted CAs file name trusted-cas-file
1812 * *************************************************************************/
1813 case hash_trusted_cas_file:
1814 freez(trusted_cas_file);
1815 trusted_cas_file = make_path(config->ca_directory, arg);
1817 if (NULL == trusted_cas_file)
1819 log_error(LOG_LEVEL_FATAL, "Out of memory while creating trusted CAs file path");
1825 /* *************************************************************************
1826 * Win32 Console options:
1827 * *************************************************************************/
1829 /* *************************************************************************
1831 * *************************************************************************/
1833 case hash_hide_console :
1836 #endif /*def _WIN_CONSOLE*/
1839 /* *************************************************************************
1840 * Win32 GUI options:
1841 * *************************************************************************/
1843 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1844 /* *************************************************************************
1845 * activity-animation (0|1)
1846 * *************************************************************************/
1847 case hash_activity_animation :
1848 g_bShowActivityAnimation = parse_toggle_state(cmd, arg);
1851 /* *************************************************************************
1852 * close-button-minimizes (0|1)
1853 * *************************************************************************/
1854 case hash_close_button_minimizes :
1855 g_bCloseHidesWindow = parse_toggle_state(cmd, arg);
1858 /* *************************************************************************
1859 * log-buffer-size (0|1)
1860 * *************************************************************************/
1861 case hash_log_buffer_size :
1862 g_bLimitBufferSize = parse_toggle_state(cmd, arg);
1865 /* *************************************************************************
1866 * log-font-name fontname
1867 * *************************************************************************/
1868 case hash_log_font_name :
1869 if (strlcpy(g_szFontFaceName, arg,
1870 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1872 log_error(LOG_LEVEL_FATAL,
1873 "log-font-name argument '%s' is longer than %u characters.",
1874 arg, sizeof(g_szFontFaceName)-1);
1878 /* *************************************************************************
1880 * *************************************************************************/
1881 case hash_log_font_size :
1882 g_nFontSize = parse_numeric_value(cmd, arg);
1885 /* *************************************************************************
1886 * log-highlight-messages (0|1)
1887 * *************************************************************************/
1888 case hash_log_highlight_messages :
1889 g_bHighlightMessages = parse_toggle_state(cmd, arg);
1892 /* *************************************************************************
1894 * *************************************************************************/
1895 case hash_log_max_lines :
1896 g_nMaxBufferLines = parse_numeric_value(cmd, arg);
1899 /* *************************************************************************
1900 * log-messages (0|1)
1901 * *************************************************************************/
1902 case hash_log_messages :
1903 g_bLogMessages = parse_toggle_state(cmd, arg);
1906 /* *************************************************************************
1907 * show-on-task-bar (0|1)
1908 * *************************************************************************/
1909 case hash_show_on_task_bar :
1910 g_bShowOnTaskBar = parse_toggle_state(cmd, arg);
1913 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1916 /* *************************************************************************
1917 * Warnings about unsupported features
1918 * *************************************************************************/
1920 case hash_deny_access:
1921 #endif /* ndef FEATURE_ACL */
1922 #ifndef FEATURE_CGI_EDIT_ACTIONS
1923 case hash_enable_edit_actions:
1924 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1925 #ifndef FEATURE_TOGGLE
1926 case hash_enable_remote_toggle:
1927 #endif /* ndef FEATURE_TOGGLE */
1929 case hash_permit_access:
1930 #endif /* ndef FEATURE_ACL */
1931 #ifndef FEATURE_TOGGLE
1933 #endif /* ndef FEATURE_TOGGLE */
1934 #ifndef FEATURE_TRUST
1935 case hash_trustfile :
1936 case hash_trust_info_url :
1937 #endif /* ndef FEATURE_TRUST */
1939 #ifndef _WIN_CONSOLE
1940 case hash_hide_console :
1941 #endif /* ndef _WIN_CONSOLE */
1943 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1944 case hash_activity_animation :
1945 case hash_close_button_minimizes :
1946 case hash_log_buffer_size :
1947 case hash_log_font_name :
1948 case hash_log_font_size :
1949 case hash_log_highlight_messages :
1950 case hash_log_max_lines :
1951 case hash_log_messages :
1952 case hash_show_on_task_bar :
1953 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1954 /* These warnings are annoying - so hide them. -- Jon */
1955 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1958 /* *************************************************************************/
1960 /* *************************************************************************/
1962 * I decided that I liked this better as a warning than an
1963 * error. To change back to an error, just change log level
1964 * to LOG_LEVEL_FATAL.
1966 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive "
1967 "'%s' (%uU) in line %lu in configuration file (%s).",
1968 buf, directive_hash, linenum, configfile);
1969 string_append(&config->proxy_args,
1970 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1973 /* *************************************************************************/
1974 } /* end switch(hash_string(cmd)) */
1976 /* Save the argument for the show-status page. */
1977 savearg(cmd, arg, config);
1979 } /* end while (read_config_line(...)) */
1983 set_debug_level(config->debug);
1985 freez(config->logfile);
1989 if (NULL != logfile)
1991 config->logfile = logfile;
1992 init_error_log(Argv[0], config->logfile);
2000 #ifdef FEATURE_HTTPS_INSPECTION
2002 * Setting SSL parameters from loaded values into structures
2004 freez(config->ca_directory);
2005 config->ca_directory = make_path(NULL, ca_directory);
2006 freez(ca_directory);
2008 freez(config->ca_cert_file);
2009 config->ca_cert_file = make_path(config->ca_directory, ca_cert_file);
2010 freez(ca_cert_file);
2012 freez(config->ca_key_file);
2013 config->ca_key_file = make_path(config->ca_directory, ca_key_file);
2016 freez(config->trusted_cas_file);
2017 config->trusted_cas_file = make_path(config->ca_directory, trusted_cas_file);
2018 freez(trusted_cas_file);
2020 freez(config->certificate_directory);
2021 config->certificate_directory = make_path(NULL, certificate_directory);
2022 freez(certificate_directory);
2024 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
2025 if (config->default_server_timeout > config->keep_alive_timeout)
2027 log_error(LOG_LEVEL_ERROR,
2028 "Reducing the default-server-timeout from %d to the keep-alive-timeout %d.",
2029 config->default_server_timeout, config->keep_alive_timeout);
2030 config->default_server_timeout = config->keep_alive_timeout;
2032 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
2034 #ifdef FEATURE_CONNECTION_SHARING
2035 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
2037 if (!config->multi_threaded)
2040 * While we could use keep-alive without multiple threads
2041 * if we didn't bother with enforcing the connection timeout,
2042 * that might make Tor users sad, even though they shouldn't
2043 * enable the single-threaded option anyway.
2045 * XXX: We could still use Proxy-Connection: keep-alive.
2047 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
2048 log_error(LOG_LEVEL_ERROR,
2049 "Config option single-threaded disables connection keep-alive.");
2052 else if ((config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING))
2054 log_error(LOG_LEVEL_ERROR, "Config option connection-sharing "
2055 "has no effect if keep-alive-timeout isn't set.");
2056 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
2058 #endif /* def FEATURE_CONNECTION_SHARING */
2060 if (NULL == config->proxy_args)
2062 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
2065 if (config->re_filterfile[0])
2067 add_loader(load_re_filterfiles, config);
2070 if (config->actions_file[0])
2072 add_loader(load_action_files, config);
2075 #ifdef FEATURE_TRUST
2076 if (config->trustfile)
2078 add_loader(load_trustfile, config);
2080 #endif /* def FEATURE_TRUST */
2082 if (NULL == config->haddr[0])
2084 config->haddr[0] = strdup_or_die(HADDR_DEFAULT);
2087 for (i = 0; i < MAX_LISTENING_SOCKETS && NULL != config->haddr[i]; i++)
2089 if ((*config->haddr[i] == '[')
2090 && (NULL != (p = strchr(config->haddr[i], ']')))
2092 && (0 < (config->hport[i] = atoi(p + 2))))
2095 memmove((void *)config->haddr[i], config->haddr[i] + 1,
2096 (size_t)(p - config->haddr[i]));
2098 else if (NULL != (p = strchr(config->haddr[i], ':'))
2099 && (0 < (config->hport[i] = atoi(p + 1))))
2105 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr[i]);
2106 /* Never get here - LOG_LEVEL_FATAL causes program exit */
2108 if (*config->haddr[i] == '\0')
2111 * Only the port specified. We stored it in config->hport[i]
2112 * and don't need its text representation anymore.
2113 * Use config->hport[i] == 0 to iterate listening addresses since
2116 freez(config->haddr[i]);
2121 * Want to run all the loaders once now.
2123 * Need to set up a fake csp, so they can get to the config.
2125 fake_csp = zalloc_or_die(sizeof(*fake_csp));
2126 fake_csp->config = config;
2128 if (run_loader(fake_csp))
2131 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
2132 /* Never get here - LOG_LEVEL_FATAL causes program exit */
2136 /* FIXME: this is a kludge for win32 */
2137 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
2139 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
2140 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
2141 g_default_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
2142 g_user_filterfile = config->re_filterfile[1]; /* FIXME Hope this is user.filter */
2144 #ifdef FEATURE_TRUST
2145 g_trustfile = config->trustfile;
2146 #endif /* def FEATURE_TRUST */
2149 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
2150 /* FIXME: end kludge */
2153 if (current_configfile == NULL)
2155 config->need_bind = 1;
2159 struct configuration_spec * oldcfg = (struct configuration_spec *)
2160 current_configfile->f;
2162 * Check if config->haddr[i],hport[i] == oldcfg->haddr[i],hport[i]
2164 config->need_bind = 0;
2166 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
2168 if (config->hport[i] != oldcfg->hport[i])
2170 config->need_bind = 1;
2172 else if (config->haddr[i] == NULL)
2174 if (oldcfg->haddr[i] != NULL)
2176 config->need_bind = 1;
2179 else if (oldcfg->haddr[i] == NULL)
2181 config->need_bind = 1;
2183 else if (0 != strcmp(config->haddr[i], oldcfg->haddr[i]))
2185 config->need_bind = 1;
2189 current_configfile->unloader = unload_configfile;
2192 fs->next = files->next;
2195 current_configfile = fs;
2201 /*********************************************************************
2203 * Function : savearg
2205 * Description : Called from `load_config'. It saves each non-empty
2206 * and non-comment line from config into
2207 * config->proxy_args. This is used to create the
2208 * show-status page. On error, frees
2209 * config->proxy_args and sets it to NULL
2212 * 1 : command = config setting that was found
2213 * 2 : argument = the setting's argument (if any)
2214 * 3 : config = Configuration to save into.
2218 *********************************************************************/
2219 static void savearg(char *command, char *argument, struct configuration_spec * config)
2228 * Add config option name embedded in
2229 * link to its section in the user-manual
2231 buf = strdup_or_die("\n<a href=\"");
2232 if (!strncmpic(config->usermanual, "file://", 7) ||
2233 !strncmpic(config->usermanual, "http", 4))
2235 string_append(&buf, config->usermanual);
2239 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
2241 string_append(&buf, CONFIG_HELP_PREFIX);
2242 string_join (&buf, string_toupper(command));
2243 string_append(&buf, "\">");
2244 string_append(&buf, command);
2245 string_append(&buf, "</a> ");
2249 freez(config->proxy_args);
2253 if ((NULL != argument) && ('\0' != *argument))
2255 s = html_encode(argument);
2259 freez(config->proxy_args);
2263 if (strncmpic(argument, "http://", 7) == 0)
2265 string_append(&buf, "<a href=\"");
2266 string_append(&buf, s);
2267 string_append(&buf, "\">");
2268 string_join (&buf, s);
2269 string_append(&buf, "</a>");
2273 string_join (&buf, s);
2277 string_append(&buf, "<br>");
2278 string_join(&config->proxy_args, buf);