1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.162 2017/06/04 14:42:32 fabiankeil Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
6 * Purpose : Loads settings from the configuration file into
7 * global variables. This file contains both the
8 * routine to load the configuration and the global
9 * variables it writes to.
11 * Copyright : Written by and Copyright (C) 2001-2017 the
12 * Privoxy team. http://www.privoxy.org/
14 * Based on the Internet Junkbuster originally written
15 * by and Copyright (C) 1997 Anonymous Coders and
16 * Junkbusters Corporation. http://www.junkbusters.com
18 * This program is free software; you can redistribute it
19 * and/or modify it under the terms of the GNU General
20 * Public License as published by the Free Software
21 * Foundation; either version 2 of the License, or (at
22 * your option) any later version.
24 * This program is distributed in the hope that it will
25 * be useful, but WITHOUT ANY WARRANTY; without even the
26 * implied warranty of MERCHANTABILITY or FITNESS FOR A
27 * PARTICULAR PURPOSE. See the GNU General Public
28 * License for more details.
30 * The GNU General Public License should be included with
31 * this file. If not, you can view it at
32 * http://www.gnu.org/copyleft/gpl.html
33 * or write to the Free Software Foundation, Inc., 59
34 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 *********************************************************************/
42 #include <sys/types.h>
56 # include <winsock2.h>
62 # endif /* ndef _WIN_CONSOLE */
64 #else /* ifndef _WIN32 */
68 # include <sys/wait.h>
70 # include <sys/time.h>
71 # include <sys/stat.h>
89 #ifdef FEATURE_CLIENT_TAGS
90 #include "client-tags.h"
94 * Default number of seconds after which an
95 * open connection will no longer be reused.
97 #define DEFAULT_KEEP_ALIVE_TIMEOUT 180
99 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
101 #ifdef FEATURE_TOGGLE
102 /* Privoxy is enabled by default. */
103 int global_toggle_state = 1;
104 #endif /* def FEATURE_TOGGLE */
106 /* The filename of the configfile */
107 const char *configfile = NULL;
110 * CGI functions will later need access to the invocation args,
111 * so we will make argc and argv global.
114 char * const * Argv = NULL;
116 static struct file_list *current_configfile = NULL;
120 * This takes the "cryptic" hash of each keyword and aliases them to
121 * something a little more readable. This also makes changing the
122 * hash values easier if they should change or the hash algorthm changes.
123 * Use the included "hash" program to find out what the hash will be
124 * for any string supplied on the command line. (Or just put it in the
125 * config file and read the number from the error message in the log).
127 * Please keep this list sorted alphabetically (but with the Windows
128 * console and GUI specific options last).
131 #define hash_actions_file 1196306641U /* "actionsfile" */
132 #define hash_accept_intercepted_requests 1513024973U /* "accept-intercepted-requests" */
133 #define hash_admin_address 4112573064U /* "admin-address" */
134 #define hash_allow_cgi_request_crunching 258915987U /* "allow-cgi-request-crunching" */
135 #define hash_buffer_limit 1881726070U /* "buffer-limit */
136 #define hash_client_header_order 2701453514U /* "client-header-order" */
137 #define hash_client_specific_tag 3353703383U /* "client-specific-tag" */
138 #define hash_client_tag_lifetime 647957580U /* "client-tag-lifetime" */
139 #define hash_compression_level 2464423563U /* "compression-level" */
140 #define hash_confdir 1978389U /* "confdir" */
141 #define hash_connection_sharing 1348841265U /* "connection-sharing" */
142 #define hash_debug 78263U /* "debug" */
143 #define hash_default_server_timeout 2530089913U /* "default-server-timeout" */
144 #define hash_deny_access 1227333715U /* "deny-access" */
145 #define hash_enable_edit_actions 2517097536U /* "enable-edit-actions" */
146 #define hash_enable_compression 3943696946U /* "enable-compression" */
147 #define hash_enable_proxy_authentication_forwarding 4040610791U /* enable-proxy-authentication-forwarding */
148 #define hash_enable_remote_toggle 2979744683U /* "enable-remote-toggle" */
149 #define hash_enable_remote_http_toggle 110543988U /* "enable-remote-http-toggle" */
150 #define hash_enforce_blocks 1862427469U /* "enforce-blocks" */
151 #define hash_filterfile 250887266U /* "filterfile" */
152 #define hash_forward 2029845U /* "forward" */
153 #define hash_forward_socks4 3963965521U /* "forward-socks4" */
154 #define hash_forward_socks4a 2639958518U /* "forward-socks4a" */
155 #define hash_forward_socks5 3963965522U /* "forward-socks5" */
156 #define hash_forward_socks5t 2639958542U /* "forward-socks5t" */
157 #define hash_forwarded_connect_retries 101465292U /* "forwarded-connect-retries" */
158 #define hash_handle_as_empty_returns_ok 1444873247U /* "handle-as-empty-doc-returns-ok" */
159 #define hash_hostname 10308071U /* "hostname" */
160 #define hash_keep_alive_timeout 3878599515U /* "keep-alive-timeout" */
161 #define hash_listen_address 1255650842U /* "listen-address" */
162 #define hash_logdir 422889U /* "logdir" */
163 #define hash_logfile 2114766U /* "logfile" */
164 #define hash_max_client_connections 3595884446U /* "max-client-connections" */
165 #define hash_permit_access 3587953268U /* "permit-access" */
166 #define hash_proxy_info_url 3903079059U /* "proxy-info-url" */
167 #define hash_receive_buffer_size 2880297454U /* "receive-buffer-size */
168 #define hash_single_threaded 4250084780U /* "single-threaded" */
169 #define hash_socket_timeout 1809001761U /* "socket-timeout" */
170 #define hash_split_large_cgi_forms 671658948U /* "split-large-cgi-forms" */
171 #define hash_suppress_blocklists 1948693308U /* "suppress-blocklists" */
172 #define hash_templdir 11067889U /* "templdir" */
173 #define hash_temporary_directory 1824125181U /* "temporary-directory" */
174 #define hash_tolerate_pipelining 1360286620U /* "tolerate-pipelining" */
175 #define hash_toggle 447966U /* "toggle" */
176 #define hash_trust_info_url 430331967U /* "trust-info-url" */
177 #define hash_trust_x_forwarded_for 2971537414U /* "trust-x-forwarded-for" */
178 #define hash_trusted_cgi_referrer 4270883427U /* "trusted-cgi-referrer" */
179 #define hash_trustfile 56494766U /* "trustfile" */
180 #define hash_usermanual 1416668518U /* "user-manual" */
181 #define hash_activity_animation 1817904738U /* "activity-animation" */
182 #define hash_close_button_minimizes 3651284693U /* "close-button-minimizes" */
183 #define hash_hide_console 2048809870U /* "hide-console" */
184 #define hash_log_buffer_size 2918070425U /* "log-buffer-size" */
185 #define hash_log_font_name 2866730124U /* "log-font-name" */
186 #define hash_log_font_size 2866731014U /* "log-font-size" */
187 #define hash_log_highlight_messages 4032101240U /* "log-highlight-messages" */
188 #define hash_log_max_lines 2868344173U /* "log-max-lines" */
189 #define hash_log_messages 2291744899U /* "log-messages" */
190 #define hash_show_on_task_bar 215410365U /* "show-on-task-bar" */
193 static void savearg(char *command, char *argument, struct configuration_spec * config);
194 #ifdef FEATURE_CLIENT_TAGS
195 static void free_client_specific_tags(struct client_tag_spec *tag_list);
198 /*********************************************************************
200 * Function : unload_configfile
202 * Description : Free the config structure and all components.
205 * 1 : data: struct configuration_spec to unload
209 *********************************************************************/
210 static void unload_configfile (void * data)
212 struct configuration_spec * config = (struct configuration_spec *)data;
213 struct forward_spec *cur_fwd = config->forward;
217 struct access_control_list *cur_acl = config->acl;
219 while (cur_acl != NULL)
221 struct access_control_list * next_acl = cur_acl->next;
226 #endif /* def FEATURE_ACL */
228 while (cur_fwd != NULL)
230 struct forward_spec * next_fwd = cur_fwd->next;
231 free_pattern_spec(cur_fwd->url);
233 freez(cur_fwd->gateway_host);
234 freez(cur_fwd->forward_host);
238 config->forward = NULL;
240 freez(config->confdir);
241 freez(config->logdir);
242 freez(config->templdir);
243 freez(config->hostname);
244 #ifdef FEATURE_EXTERNAL_FILTERS
245 freez(config->temporary_directory);
248 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
250 freez(config->haddr[i]);
252 freez(config->logfile);
254 for (i = 0; i < MAX_AF_FILES; i++)
256 freez(config->actions_file_short[i]);
257 freez(config->actions_file[i]);
258 freez(config->re_filterfile_short[i]);
259 freez(config->re_filterfile[i]);
262 list_remove_all(config->ordered_client_headers);
264 freez(config->admin_address);
265 freez(config->proxy_info_url);
266 freez(config->proxy_args);
267 freez(config->usermanual);
268 freez(config->trusted_cgi_referrer);
271 freez(config->trustfile);
272 list_remove_all(config->trust_info);
273 #endif /* def FEATURE_TRUST */
275 #ifdef FEATURE_CLIENT_TAGS
276 free_client_specific_tags(config->client_tags);
283 #ifdef FEATURE_GRACEFUL_TERMINATION
284 /*********************************************************************
286 * Function : unload_current_config_file
288 * Description : Unloads current config file - reset to state at
289 * beginning of program.
295 *********************************************************************/
296 void unload_current_config_file(void)
298 if (current_configfile)
300 current_configfile->unloader = unload_configfile;
301 current_configfile = NULL;
307 #ifdef FEATURE_CLIENT_TAGS
308 /*********************************************************************
310 * Function : register_tag
312 * Description : Registers a client-specific-tag and its description
315 * 1 : config: The tag list
316 * 2 : name: The name of the client-specific-tag
317 * 3 : description: The human-readable description for the tag
321 *********************************************************************/
322 static void register_tag(struct client_tag_spec *tag_list,
323 const char *name, const char *description)
325 struct client_tag_spec *new_tag;
326 struct client_tag_spec *last_tag;
329 while (last_tag->next != NULL)
331 last_tag = last_tag->next;
333 if (last_tag->name == NULL)
340 new_tag = zalloc_or_die(sizeof(struct client_tag_spec));
342 new_tag->name = strdup_or_die(name);
343 new_tag->description = strdup_or_die(description);
344 if (new_tag != last_tag)
346 last_tag->next = new_tag;
351 /*********************************************************************
353 * Function : free_client_specific_tags
355 * Description : Frees client-specific tags and their descriptions
358 * 1 : tag_list: The tag list to free
362 *********************************************************************/
363 static void free_client_specific_tags(struct client_tag_spec *tag_list)
365 struct client_tag_spec *this_tag;
366 struct client_tag_spec *next_tag;
372 next_tag = next_tag->next;
374 freez(this_tag->name);
375 freez(this_tag->description);
377 if (this_tag != tag_list)
381 } while (next_tag != NULL);
383 #endif /* def FEATURE_CLIENT_TAGS */
386 /*********************************************************************
388 * Function : parse_numeric_value
390 * Description : Parse the value of a directive that can only have
391 * a single numeric value. Terminates with a fatal error
392 * if the value is NULL or not numeric.
395 * 1 : name: The name of the directive. Used for log messages.
396 * 2 : value: The value to parse
399 * Returns : The numerical value as integer
401 *********************************************************************/
402 static int parse_numeric_value(const char *name, const char *value)
407 assert(name != NULL);
408 assert(value != NULL);
410 if ((value == NULL) || (*value == '\0'))
412 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
415 number = (int)strtol(value, &endptr, 0);
418 log_error(LOG_LEVEL_FATAL,
419 "Directive '%s' used with non-numerical value: '%s'", name, value);
427 /*********************************************************************
429 * Function : parse_toggle_value
431 * Description : Parse the value of a directive that can only be
432 * enabled or disabled. Terminates with a fatal error
433 * if the value is NULL or something other than 0 or 1.
436 * 1 : name: The name of the directive. Used for log messages.
437 * 2 : value: The value to parse
440 * Returns : The numerical toggle state
442 *********************************************************************/
443 static int parse_toggle_state(const char *name, const char *value)
446 assert(name != NULL);
447 assert(value != NULL);
449 if ((value == NULL) || (*value == '\0'))
451 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
454 toggle_state = atoi(value);
457 * Also check the length as atoi() doesn't mind
458 * garbage after a valid integer, but we do.
460 if (((toggle_state != 0) && (toggle_state != 1)) || (strlen(value) != 1))
462 log_error(LOG_LEVEL_FATAL,
463 "Directive %s used with invalid argument '%s'. Use either '0' or '1'.",
472 /*********************************************************************
474 * Function : parse_client_header_order
476 * Description : Parse the value of the header-order directive
479 * 1 : ordered_header_list: List to insert the ordered
481 * 2 : ordered_headers: The ordered header names separated
487 *********************************************************************/
488 static void parse_client_header_order(struct list *ordered_header_list, const char *ordered_headers)
490 char *original_headers_copy;
493 int number_of_headers;
496 assert(ordered_header_list != NULL);
497 assert(ordered_headers != NULL);
499 if (ordered_headers == NULL)
501 log_error(LOG_LEVEL_FATAL, "header-order used without argument");
505 * XXX: This estimate is guaranteed to be high enough as we
506 * let ssplit() ignore empty fields, but also a bit wasteful.
507 * The same hack is used in get_last_url() so it looks like
508 * a real solution is needed.
510 max_segments = strlen(ordered_headers) / 2;
511 if (max_segments == 0)
515 vector = malloc_or_die(max_segments * sizeof(char *));
517 original_headers_copy = strdup_or_die(ordered_headers);
519 number_of_headers = ssplit(original_headers_copy, "\t ", vector, max_segments);
520 if (number_of_headers == -1)
522 log_error(LOG_LEVEL_FATAL, "Failed to split ordered headers");
525 for (i = 0; i < number_of_headers; i++)
527 if (JB_ERR_OK != enlist(ordered_header_list, vector[i]))
529 log_error(LOG_LEVEL_FATAL,
530 "Failed to enlist ordered header: %s", vector[i]);
535 freez(original_headers_copy);
542 /*********************************************************************
544 * Function : load_config
546 * Description : Load the config file and all parameters.
548 * XXX: more than thousand lines long
549 * and thus in serious need of refactoring.
553 * Returns : The configuration_spec, or NULL on error.
555 *********************************************************************/
556 struct configuration_spec * load_config(void)
560 FILE *configfp = NULL;
561 struct configuration_spec * config = NULL;
562 struct client_state * fake_csp;
563 struct file_list *fs;
564 unsigned long linenum = 0;
566 char *logfile = NULL;
568 if (!check_file_changed(current_configfile, configfile, &fs))
570 /* No need to load */
571 return ((struct configuration_spec *)current_configfile->f);
575 log_error(LOG_LEVEL_FATAL,
576 "can't check configuration file '%s': %E", configfile);
580 if (NULL != current_configfile)
582 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
585 #ifdef FEATURE_TOGGLE
586 global_toggle_state = 1;
587 #endif /* def FEATURE_TOGGLE */
589 fs->f = config = zalloc_or_die(sizeof(*config));
592 * This is backwards from how it's usually done.
593 * Following the usual pattern, "fs" would be stored in a member
594 * variable in "csp", and then we'd access "config" from "fs->f",
595 * using a cast. However, "config" is used so often that a
596 * cast each time would be very ugly, and the extra indirection
597 * would waste CPU cycles. Therefore we store "config" in
598 * "csp->config", and "fs" in "csp->config->config_file_list".
600 config->config_file_list = fs;
605 config->multi_threaded = 1;
606 config->buffer_limit = 4096 * 1024;
607 config->receive_buffer_size = BUFFER_SIZE;
608 config->usermanual = strdup_or_die(USER_MANUAL_URL);
609 config->proxy_args = strdup_or_die("");
610 config->forwarded_connect_retries = 0;
611 #ifdef FEATURE_CLIENT_TAGS
612 config->client_tag_lifetime = 60;
614 config->trust_x_forwarded_for = 0;
615 config->trusted_cgi_referrer = NULL;
617 * 128 client sockets ought to be enough for everybody who can't
618 * be bothered to read the documentation to figure out how to
619 * increase the limit.
621 config->max_client_connections = 128;
622 config->socket_timeout = 300; /* XXX: Should be a macro. */
623 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
624 config->default_server_timeout = 0;
625 config->keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
626 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
627 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
629 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
630 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
631 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
632 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
633 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
634 #ifdef FEATURE_COMPRESSION
635 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
637 * XXX: Run some benchmarks to see if there are better default values.
639 config->compression_level = 1;
641 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
643 configfp = fopen(configfile, "r");
644 if (NULL == configfp)
646 log_error(LOG_LEVEL_FATAL,
647 "can't open configuration file '%s': %E", configfile);
648 /* Never get here - LOG_LEVEL_FATAL causes program exit */
651 while (read_config_line(configfp, &linenum, &buf) != NULL)
653 char cmd[BUFFER_SIZE];
654 char arg[BUFFER_SIZE];
655 char tmp[BUFFER_SIZE];
657 struct access_control_list *cur_acl;
658 #endif /* def FEATURE_ACL */
659 struct forward_spec *cur_fwd;
662 unsigned int directive_hash;
664 strlcpy(tmp, buf, sizeof(tmp));
666 /* Copy command (i.e. up to space or tab) into cmd */
669 while (*p && (*p != ' ') && (*p != '\t'))
675 /* Skip over the whitespace in buf */
676 while (*p && ((*p == ' ') || (*p == '\t')))
681 /* Copy the argument into arg */
682 if (strlcpy(arg, p, sizeof(arg)) >= sizeof(arg))
684 log_error(LOG_LEVEL_FATAL, "Config line too long: %s", buf);
687 /* Should never happen, but check this anyway */
694 /* Make sure the command field is lower case */
695 for (p = cmd; *p; p++)
697 if (privoxy_isupper(*p))
699 *p = (char)privoxy_tolower(*p);
703 directive_hash = hash_string(cmd);
704 switch (directive_hash)
706 /* *************************************************************************
707 * actionsfile actions-file-name
708 * In confdir by default
709 * *************************************************************************/
710 case hash_actions_file :
712 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
717 if (i >= MAX_AF_FILES)
719 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
720 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
723 config->actions_file_short[i] = strdup_or_die(arg);
724 config->actions_file[i] = make_path(config->confdir, arg);
727 /* *************************************************************************
728 * accept-intercepted-requests
729 * *************************************************************************/
730 case hash_accept_intercepted_requests:
731 if (parse_toggle_state(cmd, arg) == 1)
733 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
737 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
741 /* *************************************************************************
742 * admin-address email-address
743 * *************************************************************************/
744 case hash_admin_address :
745 freez(config->admin_address);
746 config->admin_address = strdup_or_die(arg);
749 /* *************************************************************************
750 * allow-cgi-request-crunching
751 * *************************************************************************/
752 case hash_allow_cgi_request_crunching:
753 if (parse_toggle_state(cmd, arg) == 1)
755 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
759 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
763 /* *************************************************************************
765 * *************************************************************************/
766 case hash_buffer_limit :
767 config->buffer_limit = (size_t)(1024 * parse_numeric_value(cmd, arg));
770 /* *************************************************************************
771 * client-header-order header-1 header-2 ... header-n
772 * *************************************************************************/
773 case hash_client_header_order:
774 list_remove_all(config->ordered_client_headers);
775 parse_client_header_order(config->ordered_client_headers, arg);
778 /* *************************************************************************
779 * client-specific-tag tag-name description
780 * *************************************************************************/
781 #ifdef FEATURE_CLIENT_TAGS
782 case hash_client_specific_tag:
788 description = strstr(arg, " ");
789 if (description == NULL)
791 log_error(LOG_LEVEL_FATAL,
792 "client-specific-tag '%s' lacks a description.", name);
796 * The length is limited because we don't want truncated
797 * HTML caused by the cgi interface using static buffer
800 if (strlen(name) > CLIENT_TAG_LENGTH_MAX)
802 log_error(LOG_LEVEL_FATAL,
803 "client-specific-tag '%s' is longer than %d characters.",
804 name, CLIENT_TAG_LENGTH_MAX);
807 register_tag(config->client_tags, name, description);
810 #endif /* def FEATURE_CLIENT_TAGS */
812 /* *************************************************************************
813 * client-tag-lifetime ttl
814 * *************************************************************************/
815 #ifdef FEATURE_CLIENT_TAGS
816 case hash_client_tag_lifetime:
818 int ttl = parse_numeric_value(cmd, arg);
821 config->client_tag_lifetime = (unsigned)ttl;
825 log_error(LOG_LEVEL_FATAL,
826 "client-tag-lifetime can't be negative.");
830 #endif /* def FEATURE_CLIENT_TAGS */
832 /* *************************************************************************
833 * confdir directory-name
834 * *************************************************************************/
836 freez(config->confdir);
837 config->confdir = make_path(NULL, arg);
840 /* *************************************************************************
841 * compression-level 0-9
842 * *************************************************************************/
843 #ifdef FEATURE_COMPRESSION
844 case hash_compression_level :
846 int compression_level = parse_numeric_value(cmd, arg);
847 if (-1 <= compression_level && compression_level <= 9)
849 config->compression_level = compression_level;
853 log_error(LOG_LEVEL_FATAL,
854 "Invalid compression-level value: %s", arg);
860 /* *************************************************************************
861 * connection-sharing (0|1)
862 * *************************************************************************/
863 #ifdef FEATURE_CONNECTION_SHARING
864 case hash_connection_sharing :
865 if (parse_toggle_state(cmd, arg) == 1)
867 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_SHARING;
871 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
876 /* *************************************************************************
878 * Specifies debug level, multiple values are ORed together.
879 * *************************************************************************/
881 config->debug |= parse_numeric_value(cmd, arg);
884 /* *************************************************************************
885 * default-server-timeout timeout
886 * *************************************************************************/
887 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
888 case hash_default_server_timeout :
890 int timeout = parse_numeric_value(cmd, arg);
893 config->default_server_timeout = (unsigned int)timeout;
897 log_error(LOG_LEVEL_FATAL,
898 "Invalid default-server-timeout value: %s", arg);
904 /* *************************************************************************
905 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
906 * *************************************************************************/
908 case hash_deny_access:
909 strlcpy(tmp, arg, sizeof(tmp));
910 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
912 if ((vec_count != 1) && (vec_count != 2))
914 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
915 "deny-access directive in configuration file.");
916 string_append(&config->proxy_args,
917 "<br>\nWARNING: Wrong number of parameters for "
918 "deny-access directive in configuration file.<br><br>\n");
922 /* allocate a new node */
923 cur_acl = zalloc_or_die(sizeof(*cur_acl));
924 cur_acl->action = ACL_DENY;
926 if (acl_addr(vec[0], cur_acl->src) < 0)
928 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
929 "for deny-access directive in configuration file: \"%s\"", vec[0]);
930 string_append(&config->proxy_args,
931 "<br>\nWARNING: Invalid source address, port or netmask "
932 "for deny-access directive in configuration file: \"");
933 string_append(&config->proxy_args,
935 string_append(&config->proxy_args,
942 if (acl_addr(vec[1], cur_acl->dst) < 0)
944 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
945 "for deny-access directive in configuration file: \"%s\"", vec[1]);
946 string_append(&config->proxy_args,
947 "<br>\nWARNING: Invalid destination address, port or netmask "
948 "for deny-access directive in configuration file: \"");
949 string_append(&config->proxy_args,
951 string_append(&config->proxy_args,
960 cur_acl->wildcard_dst = 1;
962 #endif /* def HAVE_RFC2553 */
965 * Add it to the list. Note we reverse the list to get the
966 * behaviour the user expects. With both the ACL and
967 * actions file, the last match wins. However, the internal
968 * implementations are different: The actions file is stored
969 * in the same order as the file, and scanned completely.
970 * With the ACL, we reverse the order as we load it, then
971 * when we scan it we stop as soon as we get a match.
973 cur_acl->next = config->acl;
974 config->acl = cur_acl;
977 #endif /* def FEATURE_ACL */
979 /* *************************************************************************
980 * enable-edit-actions 0|1
981 * *************************************************************************/
982 #ifdef FEATURE_CGI_EDIT_ACTIONS
983 case hash_enable_edit_actions:
984 if (parse_toggle_state(cmd, arg) == 1)
986 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
990 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
993 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
995 /* *************************************************************************
996 * enable-compression 0|1
997 * *************************************************************************/
998 #ifdef FEATURE_COMPRESSION
999 case hash_enable_compression:
1000 if (parse_toggle_state(cmd, arg) == 1)
1002 config->feature_flags |= RUNTIME_FEATURE_COMPRESSION;
1006 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
1009 #endif /* def FEATURE_COMPRESSION */
1011 /* *************************************************************************
1012 * enable-proxy-authentication-forwarding 0|1
1013 * *************************************************************************/
1014 case hash_enable_proxy_authentication_forwarding:
1015 if (parse_toggle_state(cmd, arg) == 1)
1017 config->feature_flags |= RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1021 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1025 /* *************************************************************************
1026 * enable-remote-toggle 0|1
1027 * *************************************************************************/
1028 #ifdef FEATURE_TOGGLE
1029 case hash_enable_remote_toggle:
1030 if (parse_toggle_state(cmd, arg) == 1)
1032 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1036 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1039 #endif /* def FEATURE_TOGGLE */
1041 /* *************************************************************************
1042 * enable-remote-http-toggle 0|1
1043 * *************************************************************************/
1044 case hash_enable_remote_http_toggle:
1045 if (parse_toggle_state(cmd, arg) == 1)
1047 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1051 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1055 /* *************************************************************************
1056 * enforce-blocks 0|1
1057 * *************************************************************************/
1058 case hash_enforce_blocks:
1059 #ifdef FEATURE_FORCE_LOAD
1060 if (parse_toggle_state(cmd, arg) == 1)
1062 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1066 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1069 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1070 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1071 #endif /* def FEATURE_FORCE_LOAD */
1074 /* *************************************************************************
1075 * filterfile file-name
1076 * In confdir by default.
1077 * *************************************************************************/
1078 case hash_filterfile :
1080 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1085 if (i >= MAX_AF_FILES)
1087 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1088 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1091 config->re_filterfile_short[i] = strdup_or_die(arg);
1092 config->re_filterfile[i] = make_path(config->confdir, arg);
1096 /* *************************************************************************
1097 * forward url-pattern (.|http-proxy-host[:port])
1098 * *************************************************************************/
1100 strlcpy(tmp, arg, sizeof(tmp));
1101 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1105 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1106 "directive in configuration file.");
1107 string_append(&config->proxy_args,
1108 "<br>\nWARNING: Wrong number of parameters for "
1109 "forward directive in configuration file.");
1113 /* allocate a new node */
1114 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1115 cur_fwd->type = SOCKS_NONE;
1117 /* Save the URL pattern */
1118 if (create_pattern_spec(cur_fwd->url, vec[0]))
1120 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1121 "directive in configuration file.");
1122 string_append(&config->proxy_args,
1123 "<br>\nWARNING: Bad URL specifier for "
1124 "forward directive in configuration file.");
1129 /* Parse the parent HTTP proxy host:port */
1132 if (strcmp(p, ".") != 0)
1134 cur_fwd->forward_port = 8000;
1135 parse_forwarder_address(p, &cur_fwd->forward_host,
1136 &cur_fwd->forward_port);
1140 cur_fwd->next = config->forward;
1141 config->forward = cur_fwd;
1145 /* *************************************************************************
1146 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1147 * *************************************************************************/
1148 case hash_forward_socks4:
1149 strlcpy(tmp, arg, sizeof(tmp));
1150 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1154 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1155 "forward-socks4 directive in configuration file.");
1156 string_append(&config->proxy_args,
1157 "<br>\nWARNING: Wrong number of parameters for "
1158 "forward-socks4 directive in configuration file.");
1162 /* allocate a new node */
1163 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1164 cur_fwd->type = SOCKS_4;
1166 /* Save the URL pattern */
1167 if (create_pattern_spec(cur_fwd->url, vec[0]))
1169 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1170 "directive in configuration file.");
1171 string_append(&config->proxy_args,
1172 "<br>\nWARNING: Bad URL specifier for "
1173 "forward-socks4 directive in configuration file.");
1178 /* Parse the SOCKS proxy host[:port] */
1181 /* XXX: This check looks like a bug. */
1182 if (strcmp(p, ".") != 0)
1184 cur_fwd->gateway_port = 1080;
1185 parse_forwarder_address(p, &cur_fwd->gateway_host,
1186 &cur_fwd->gateway_port);
1189 /* Parse the parent HTTP proxy host[:port] */
1192 if (strcmp(p, ".") != 0)
1194 cur_fwd->forward_port = 8000;
1195 parse_forwarder_address(p, &cur_fwd->forward_host,
1196 &cur_fwd->forward_port);
1200 cur_fwd->next = config->forward;
1201 config->forward = cur_fwd;
1205 /* *************************************************************************
1206 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1207 * *************************************************************************/
1208 case hash_forward_socks4a:
1209 case hash_forward_socks5:
1210 case hash_forward_socks5t:
1211 strlcpy(tmp, arg, sizeof(tmp));
1212 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1216 log_error(LOG_LEVEL_ERROR,
1217 "Wrong number of parameters for %s in configuration file.",
1219 string_append(&config->proxy_args,
1220 "<br>\nWARNING: Wrong number of parameters for ");
1221 string_append(&config->proxy_args, cmd);
1222 string_append(&config->proxy_args,
1223 "directive in configuration file.");
1227 /* allocate a new node */
1228 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1230 if (directive_hash == hash_forward_socks4a)
1232 cur_fwd->type = SOCKS_4A;
1234 else if (directive_hash == hash_forward_socks5)
1236 cur_fwd->type = SOCKS_5;
1240 assert(directive_hash == hash_forward_socks5t);
1241 cur_fwd->type = SOCKS_5T;
1244 /* Save the URL pattern */
1245 if (create_pattern_spec(cur_fwd->url, vec[0]))
1247 log_error(LOG_LEVEL_ERROR,
1248 "Bad URL specifier for %s in configuration file.",
1250 string_append(&config->proxy_args,
1251 "<br>\nWARNING: Bad URL specifier for ");
1252 string_append(&config->proxy_args, cmd);
1253 string_append(&config->proxy_args,
1254 "directive in configuration file.");
1259 /* Parse the SOCKS proxy host[:port] */
1262 cur_fwd->gateway_port = 1080;
1263 parse_forwarder_address(p, &cur_fwd->gateway_host,
1264 &cur_fwd->gateway_port);
1266 /* Parse the parent HTTP proxy host[:port] */
1269 if (strcmp(p, ".") != 0)
1271 cur_fwd->forward_port = 8000;
1272 parse_forwarder_address(p, &cur_fwd->forward_host,
1273 &cur_fwd->forward_port);
1277 cur_fwd->next = config->forward;
1278 config->forward = cur_fwd;
1282 /* *************************************************************************
1283 * forwarded-connect-retries n
1284 * *************************************************************************/
1285 case hash_forwarded_connect_retries :
1286 config->forwarded_connect_retries = parse_numeric_value(cmd, arg);
1289 /* *************************************************************************
1290 * handle-as-empty-doc-returns-ok 0|1
1292 * Workaround for firefox hanging on blocked javascript pages.
1293 * Block with the "+handle-as-empty-document" flag and set the
1294 * "handle-as-empty-doc-returns-ok" run-time config flag so that
1295 * Privoxy returns a 200/OK status instead of a 403/Forbidden status
1296 * to the browser for blocked pages.
1297 ***************************************************************************/
1298 case hash_handle_as_empty_returns_ok:
1299 if (parse_toggle_state(cmd, arg) == 1)
1301 config->feature_flags |= RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1305 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1309 /* *************************************************************************
1310 * hostname hostname-to-show-on-cgi-pages
1311 * *************************************************************************/
1312 case hash_hostname :
1313 freez(config->hostname);
1314 config->hostname = strdup_or_die(arg);
1317 /* *************************************************************************
1318 * keep-alive-timeout timeout
1319 * *************************************************************************/
1320 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1321 case hash_keep_alive_timeout :
1323 int timeout = parse_numeric_value(cmd, arg);
1326 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1327 config->keep_alive_timeout = (unsigned int)timeout;
1331 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1337 /* *************************************************************************
1338 * listen-address [ip][:port]
1339 * *************************************************************************/
1340 case hash_listen_address :
1342 while ((i < MAX_LISTENING_SOCKETS) && (NULL != config->haddr[i]))
1347 if (i >= MAX_LISTENING_SOCKETS)
1349 log_error(LOG_LEVEL_FATAL, "Too many 'listen-address' directives in config file - limit is %d.\n"
1350 "(You can increase this limit by changing MAX_LISTENING_SOCKETS in project.h and recompiling).",
1351 MAX_LISTENING_SOCKETS);
1353 config->haddr[i] = strdup_or_die(arg);
1356 /* *************************************************************************
1357 * logdir directory-name
1358 * *************************************************************************/
1360 freez(config->logdir);
1361 config->logdir = make_path(NULL, arg);
1364 /* *************************************************************************
1365 * logfile log-file-name
1366 * In logdir by default
1367 * *************************************************************************/
1371 logfile = make_path(config->logdir, arg);
1372 if (NULL == logfile)
1374 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1379 /* *************************************************************************
1380 * max-client-connections number
1381 * *************************************************************************/
1382 case hash_max_client_connections :
1384 int max_client_connections = parse_numeric_value(cmd, arg);
1386 #if !defined(_WIN32) && !defined(HAVE_POLL)
1388 * Reject values below 1 for obvious reasons and values above
1389 * FD_SETSIZE/2 because Privoxy needs two sockets to serve
1390 * client connections that need forwarding.
1392 * We ignore the fact that the first three file descriptors
1393 * are usually set to /dev/null, one is used for logging
1394 * and yet another file descriptor is required to load
1397 if ((max_client_connections < 1) || (FD_SETSIZE/2 < max_client_connections))
1399 log_error(LOG_LEVEL_FATAL, "max-client-connections value %d"
1400 " is invalid. Value needs to be above 1 and below %d"
1401 " (FD_SETSIZE/2).", max_client_connections, FD_SETSIZE/2);
1405 * The Windows libc uses FD_SETSIZE for an array used
1406 * by select(), but has no problems with file descriptors
1407 * above the limit as long as no more than FD_SETSIZE are
1408 * passed to select().
1409 * https://msdn.microsoft.com/en-us/library/windows/desktop/ms739169%28v=vs.85%29.aspx
1411 * On platforms were we use poll() we don't have to enforce
1412 * an upper connection limit either.
1414 * XXX: Do OS/2, Amiga etc. belong here as well?
1416 if (max_client_connections < 1)
1418 log_error(LOG_LEVEL_FATAL, "max-client-connections value"
1419 " has to be a number above 1. %d is invalid.",
1420 max_client_connections);
1423 config->max_client_connections = max_client_connections;
1427 /* *************************************************************************
1428 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1429 * *************************************************************************/
1431 case hash_permit_access:
1432 strlcpy(tmp, arg, sizeof(tmp));
1433 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1435 if ((vec_count != 1) && (vec_count != 2))
1437 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1438 "permit-access directive in configuration file.");
1439 string_append(&config->proxy_args,
1440 "<br>\nWARNING: Wrong number of parameters for "
1441 "permit-access directive in configuration file.<br><br>\n");
1446 /* allocate a new node */
1447 cur_acl = zalloc_or_die(sizeof(*cur_acl));
1448 cur_acl->action = ACL_PERMIT;
1450 if (acl_addr(vec[0], cur_acl->src) < 0)
1452 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1453 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1454 string_append(&config->proxy_args,
1455 "<br>\nWARNING: Invalid source address, port or netmask for "
1456 "permit-access directive in configuration file: \"");
1457 string_append(&config->proxy_args,
1459 string_append(&config->proxy_args,
1466 if (acl_addr(vec[1], cur_acl->dst) < 0)
1468 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1469 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1470 string_append(&config->proxy_args,
1471 "<br>\nWARNING: Invalid destination address, port or netmask for "
1472 "permit-access directive in configuration file: \"");
1473 string_append(&config->proxy_args,
1475 string_append(&config->proxy_args,
1484 cur_acl->wildcard_dst = 1;
1486 #endif /* def HAVE_RFC2553 */
1489 * Add it to the list. Note we reverse the list to get the
1490 * behaviour the user expects. With both the ACL and
1491 * actions file, the last match wins. However, the internal
1492 * implementations are different: The actions file is stored
1493 * in the same order as the file, and scanned completely.
1494 * With the ACL, we reverse the order as we load it, then
1495 * when we scan it we stop as soon as we get a match.
1497 cur_acl->next = config->acl;
1498 config->acl = cur_acl;
1501 #endif /* def FEATURE_ACL */
1503 /* *************************************************************************
1504 * proxy-info-url url
1505 * *************************************************************************/
1506 case hash_proxy_info_url :
1507 freez(config->proxy_info_url);
1508 config->proxy_info_url = strdup_or_die(arg);
1512 /* *************************************************************************
1513 * receive-buffer-size n
1514 * *************************************************************************/
1515 case hash_receive_buffer_size :
1516 config->receive_buffer_size = (size_t)parse_numeric_value(cmd, arg);
1517 if (config->receive_buffer_size < BUFFER_SIZE)
1519 log_error(LOG_LEVEL_INFO,
1520 "receive-buffer-size %d seems low and may cause problems."
1521 "Consider setting it to at least %d.",
1522 config->receive_buffer_size, BUFFER_SIZE);
1526 /* *************************************************************************
1527 * single-threaded 0|1
1528 * *************************************************************************/
1529 case hash_single_threaded :
1530 config->multi_threaded = 0 == parse_toggle_state(cmd, arg);
1533 /* *************************************************************************
1534 * socket-timeout numer_of_seconds
1535 * *************************************************************************/
1536 case hash_socket_timeout :
1538 int socket_timeout = parse_numeric_value(cmd, arg);
1539 if (0 <= socket_timeout)
1541 config->socket_timeout = socket_timeout;
1545 log_error(LOG_LEVEL_FATAL, "Invalid socket-timeout: '%s'", arg);
1550 /* *************************************************************************
1551 * split-large-cgi-forms
1552 * *************************************************************************/
1553 case hash_split_large_cgi_forms :
1554 if (parse_toggle_state(cmd, arg) == 1)
1556 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1560 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1564 /* *************************************************************************
1565 * templdir directory-name
1566 * *************************************************************************/
1567 case hash_templdir :
1568 freez(config->templdir);
1569 config->templdir = make_path(NULL, arg);
1572 #ifdef FEATURE_EXTERNAL_FILTERS
1573 /* *************************************************************************
1574 * temporary-directory directory-name
1575 * *************************************************************************/
1576 case hash_temporary_directory :
1577 freez(config->temporary_directory);
1578 config->temporary_directory = make_path(NULL, arg);
1582 /* *************************************************************************
1583 * tolerate-pipelining (0|1)
1584 * *************************************************************************/
1585 case hash_tolerate_pipelining :
1586 if (parse_toggle_state(cmd, arg) == 1)
1588 config->feature_flags |= RUNTIME_FEATURE_TOLERATE_PIPELINING;
1592 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
1596 /* *************************************************************************
1598 * *************************************************************************/
1599 #ifdef FEATURE_TOGGLE
1601 global_toggle_state = parse_toggle_state(cmd, arg);
1603 #endif /* def FEATURE_TOGGLE */
1605 /* *************************************************************************
1606 * trust-info-url url
1607 * *************************************************************************/
1608 #ifdef FEATURE_TRUST
1609 case hash_trust_info_url :
1610 enlist(config->trust_info, arg);
1612 #endif /* def FEATURE_TRUST */
1614 /* *************************************************************************
1615 * trust-x-forwarded-for (0|1)
1616 * *************************************************************************/
1617 case hash_trust_x_forwarded_for :
1618 config->trust_x_forwarded_for = parse_toggle_state(cmd, arg);
1621 /* *************************************************************************
1622 * trusted-cgi-referrer http://www.example.org/some/path.html
1623 * *************************************************************************/
1624 case hash_trusted_cgi_referrer :
1626 * We don't validate the specified referrer as
1627 * it's only used for string comparison.
1629 freez(config->trusted_cgi_referrer);
1630 config->trusted_cgi_referrer = strdup_or_die(arg);
1633 /* *************************************************************************
1634 * trustfile filename
1635 * (In confdir by default.)
1636 * *************************************************************************/
1637 #ifdef FEATURE_TRUST
1638 case hash_trustfile :
1639 freez(config->trustfile);
1640 config->trustfile = make_path(config->confdir, arg);
1642 #endif /* def FEATURE_TRUST */
1644 /* *************************************************************************
1646 * *************************************************************************/
1647 case hash_usermanual :
1649 * XXX: If this isn't the first config directive, the
1650 * show-status page links to the website documentation
1651 * for the directives that were already parsed. Lame.
1653 freez(config->usermanual);
1654 config->usermanual = strdup_or_die(arg);
1657 /* *************************************************************************
1658 * Win32 Console options:
1659 * *************************************************************************/
1661 /* *************************************************************************
1663 * *************************************************************************/
1665 case hash_hide_console :
1668 #endif /*def _WIN_CONSOLE*/
1671 /* *************************************************************************
1672 * Win32 GUI options:
1673 * *************************************************************************/
1675 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1676 /* *************************************************************************
1677 * activity-animation (0|1)
1678 * *************************************************************************/
1679 case hash_activity_animation :
1680 g_bShowActivityAnimation = parse_toggle_state(cmd, arg);
1683 /* *************************************************************************
1684 * close-button-minimizes (0|1)
1685 * *************************************************************************/
1686 case hash_close_button_minimizes :
1687 g_bCloseHidesWindow = parse_toggle_state(cmd, arg);
1690 /* *************************************************************************
1691 * log-buffer-size (0|1)
1692 * *************************************************************************/
1693 case hash_log_buffer_size :
1694 g_bLimitBufferSize = parse_toggle_state(cmd, arg);
1697 /* *************************************************************************
1698 * log-font-name fontname
1699 * *************************************************************************/
1700 case hash_log_font_name :
1701 if (strlcpy(g_szFontFaceName, arg,
1702 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1704 log_error(LOG_LEVEL_FATAL,
1705 "log-font-name argument '%s' is longer than %u characters.",
1706 arg, sizeof(g_szFontFaceName)-1);
1710 /* *************************************************************************
1712 * *************************************************************************/
1713 case hash_log_font_size :
1714 g_nFontSize = parse_numeric_value(cmd, arg);
1717 /* *************************************************************************
1718 * log-highlight-messages (0|1)
1719 * *************************************************************************/
1720 case hash_log_highlight_messages :
1721 g_bHighlightMessages = parse_toggle_state(cmd, arg);
1724 /* *************************************************************************
1726 * *************************************************************************/
1727 case hash_log_max_lines :
1728 g_nMaxBufferLines = parse_numeric_value(cmd, arg);
1731 /* *************************************************************************
1732 * log-messages (0|1)
1733 * *************************************************************************/
1734 case hash_log_messages :
1735 g_bLogMessages = parse_toggle_state(cmd, arg);
1738 /* *************************************************************************
1739 * show-on-task-bar (0|1)
1740 * *************************************************************************/
1741 case hash_show_on_task_bar :
1742 g_bShowOnTaskBar = parse_toggle_state(cmd, arg);
1745 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1748 /* *************************************************************************
1749 * Warnings about unsupported features
1750 * *************************************************************************/
1752 case hash_deny_access:
1753 #endif /* ndef FEATURE_ACL */
1754 #ifndef FEATURE_CGI_EDIT_ACTIONS
1755 case hash_enable_edit_actions:
1756 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1757 #ifndef FEATURE_TOGGLE
1758 case hash_enable_remote_toggle:
1759 #endif /* ndef FEATURE_TOGGLE */
1761 case hash_permit_access:
1762 #endif /* ndef FEATURE_ACL */
1763 #ifndef FEATURE_TOGGLE
1765 #endif /* ndef FEATURE_TOGGLE */
1766 #ifndef FEATURE_TRUST
1767 case hash_trustfile :
1768 case hash_trust_info_url :
1769 #endif /* ndef FEATURE_TRUST */
1771 #ifndef _WIN_CONSOLE
1772 case hash_hide_console :
1773 #endif /* ndef _WIN_CONSOLE */
1775 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1776 case hash_activity_animation :
1777 case hash_close_button_minimizes :
1778 case hash_log_buffer_size :
1779 case hash_log_font_name :
1780 case hash_log_font_size :
1781 case hash_log_highlight_messages :
1782 case hash_log_max_lines :
1783 case hash_log_messages :
1784 case hash_show_on_task_bar :
1785 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1786 /* These warnings are annoying - so hide them. -- Jon */
1787 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1790 /* *************************************************************************/
1792 /* *************************************************************************/
1794 * I decided that I liked this better as a warning than an
1795 * error. To change back to an error, just change log level
1796 * to LOG_LEVEL_FATAL.
1798 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive "
1799 "'%s' (%uU) in line %lu in configuration file (%s).",
1800 buf, directive_hash, linenum, configfile);
1801 string_append(&config->proxy_args,
1802 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1805 /* *************************************************************************/
1806 } /* end switch(hash_string(cmd)) */
1808 /* Save the argument for the show-status page. */
1809 savearg(cmd, arg, config);
1811 } /* end while (read_config_line(...)) */
1815 set_debug_level(config->debug);
1817 freez(config->logfile);
1821 if (NULL != logfile)
1823 config->logfile = logfile;
1824 init_error_log(Argv[0], config->logfile);
1832 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1833 if (config->default_server_timeout > config->keep_alive_timeout)
1835 log_error(LOG_LEVEL_ERROR,
1836 "Reducing the default-server-timeout from %d to the keep-alive-timeout %d.",
1837 config->default_server_timeout, config->keep_alive_timeout);
1838 config->default_server_timeout = config->keep_alive_timeout;
1840 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
1842 #ifdef FEATURE_CONNECTION_SHARING
1843 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1845 if (!config->multi_threaded)
1848 * While we could use keep-alive without multiple threads
1849 * if we didn't bother with enforcing the connection timeout,
1850 * that might make Tor users sad, even though they shouldn't
1851 * enable the single-threaded option anyway.
1853 * XXX: We could still use Proxy-Connection: keep-alive.
1855 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1856 log_error(LOG_LEVEL_ERROR,
1857 "Config option single-threaded disables connection keep-alive.");
1860 else if ((config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING))
1862 log_error(LOG_LEVEL_ERROR, "Config option connection-sharing "
1863 "has no effect if keep-alive-timeout isn't set.");
1864 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
1866 #endif /* def FEATURE_CONNECTION_SHARING */
1868 if (NULL == config->proxy_args)
1870 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1873 if (config->re_filterfile[0])
1875 add_loader(load_re_filterfiles, config);
1878 if (config->actions_file[0])
1880 add_loader(load_action_files, config);
1883 #ifdef FEATURE_TRUST
1884 if (config->trustfile)
1886 add_loader(load_trustfile, config);
1888 #endif /* def FEATURE_TRUST */
1890 if (NULL == config->haddr[0])
1892 config->haddr[0] = strdup_or_die(HADDR_DEFAULT);
1895 for (i = 0; i < MAX_LISTENING_SOCKETS && NULL != config->haddr[i]; i++)
1897 if ((*config->haddr[i] == '[')
1898 && (NULL != (p = strchr(config->haddr[i], ']')))
1900 && (0 < (config->hport[i] = atoi(p + 2))))
1903 memmove((void *)config->haddr[i], config->haddr[i] + 1,
1904 (size_t)(p - config->haddr[i]));
1906 else if (NULL != (p = strchr(config->haddr[i], ':'))
1907 && (0 < (config->hport[i] = atoi(p + 1))))
1913 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr[i]);
1914 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1916 if (*config->haddr[i] == '\0')
1919 * Only the port specified. We stored it in config->hport[i]
1920 * and don't need its text representation anymore.
1921 * Use config->hport[i] == 0 to iterate listening addresses since
1924 freez(config->haddr[i]);
1929 * Want to run all the loaders once now.
1931 * Need to set up a fake csp, so they can get to the config.
1933 fake_csp = zalloc_or_die(sizeof(*fake_csp));
1934 fake_csp->config = config;
1936 if (run_loader(fake_csp))
1939 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1940 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1944 /* FIXME: this is a kludge for win32 */
1945 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1947 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1948 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1949 g_default_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1950 g_user_filterfile = config->re_filterfile[1]; /* FIXME Hope this is user.filter */
1952 #ifdef FEATURE_TRUST
1953 g_trustfile = config->trustfile;
1954 #endif /* def FEATURE_TRUST */
1957 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1958 /* FIXME: end kludge */
1961 config->need_bind = 1;
1963 if (current_configfile)
1965 struct configuration_spec * oldcfg = (struct configuration_spec *)
1966 current_configfile->f;
1968 * Check if config->haddr[i],hport[i] == oldcfg->haddr[i],hport[i]
1970 config->need_bind = 0;
1972 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
1974 if (config->hport[i] != oldcfg->hport[i])
1976 config->need_bind = 1;
1978 else if (config->haddr[i] == NULL)
1980 if (oldcfg->haddr[i] != NULL)
1982 config->need_bind = 1;
1985 else if (oldcfg->haddr[i] == NULL)
1987 config->need_bind = 1;
1989 else if (0 != strcmp(config->haddr[i], oldcfg->haddr[i]))
1991 config->need_bind = 1;
1995 current_configfile->unloader = unload_configfile;
1998 fs->next = files->next;
2001 current_configfile = fs;
2007 /*********************************************************************
2009 * Function : savearg
2011 * Description : Called from `load_config'. It saves each non-empty
2012 * and non-comment line from config into
2013 * config->proxy_args. This is used to create the
2014 * show-status page. On error, frees
2015 * config->proxy_args and sets it to NULL
2018 * 1 : command = config setting that was found
2019 * 2 : argument = the setting's argument (if any)
2020 * 3 : config = Configuration to save into.
2024 *********************************************************************/
2025 static void savearg(char *command, char *argument, struct configuration_spec * config)
2034 * Add config option name embedded in
2035 * link to its section in the user-manual
2037 buf = strdup_or_die("\n<a href=\"");
2038 if (!strncmpic(config->usermanual, "file://", 7) ||
2039 !strncmpic(config->usermanual, "http", 4))
2041 string_append(&buf, config->usermanual);
2045 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
2047 string_append(&buf, CONFIG_HELP_PREFIX);
2048 string_join (&buf, string_toupper(command));
2049 string_append(&buf, "\">");
2050 string_append(&buf, command);
2051 string_append(&buf, "</a> ");
2055 freez(config->proxy_args);
2059 if ((NULL != argument) && ('\0' != *argument))
2061 s = html_encode(argument);
2065 freez(config->proxy_args);
2069 if (strncmpic(argument, "http://", 7) == 0)
2071 string_append(&buf, "<a href=\"");
2072 string_append(&buf, s);
2073 string_append(&buf, "\">");
2074 string_join (&buf, s);
2075 string_append(&buf, "</a>");
2079 string_join (&buf, s);
2083 string_append(&buf, "<br>");
2084 string_join(&config->proxy_args, buf);