1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.148 2016/03/17 10:40:53 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-2016 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>
61 # endif /* ndef _WIN_CONSOLE */
63 #else /* ifndef _WIN32 */
67 # include <sys/wait.h>
69 # include <sys/time.h>
70 # include <sys/stat.h>
89 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
92 /* Privoxy is enabled by default. */
93 int global_toggle_state = 1;
94 #endif /* def FEATURE_TOGGLE */
96 /* The filename of the configfile */
97 const char *configfile = NULL;
100 * CGI functions will later need access to the invocation args,
101 * so we will make argc and argv global.
104 char * const * Argv = NULL;
106 static struct file_list *current_configfile = NULL;
110 * This takes the "cryptic" hash of each keyword and aliases them to
111 * something a little more readable. This also makes changing the
112 * hash values easier if they should change or the hash algorthm changes.
113 * Use the included "hash" program to find out what the hash will be
114 * for any string supplied on the command line. (Or just put it in the
115 * config file and read the number from the error message in the log).
117 * Please keep this list sorted alphabetically (but with the Windows
118 * console and GUI specific options last).
121 #define hash_actions_file 1196306641U /* "actionsfile" */
122 #define hash_accept_intercepted_requests 1513024973U /* "accept-intercepted-requests" */
123 #define hash_admin_address 4112573064U /* "admin-address" */
124 #define hash_allow_cgi_request_crunching 258915987U /* "allow-cgi-request-crunching" */
125 #define hash_buffer_limit 1881726070U /* "buffer-limit */
126 #define hash_client_header_order 2701453514U /* "client-header-order" */
127 #define hash_client_specific_tag 3353703383U /* "client-specific-tag" */
128 #define hash_client_tag_lifetime 647957580U /* "client-tag-lifetime" */
129 #define hash_compression_level 2464423563U /* "compression-level" */
130 #define hash_confdir 1978389U /* "confdir" */
131 #define hash_connection_sharing 1348841265U /* "connection-sharing" */
132 #define hash_debug 78263U /* "debug" */
133 #define hash_default_server_timeout 2530089913U /* "default-server-timeout" */
134 #define hash_deny_access 1227333715U /* "deny-access" */
135 #define hash_enable_edit_actions 2517097536U /* "enable-edit-actions" */
136 #define hash_enable_compression 3943696946U /* "enable-compression" */
137 #define hash_enable_proxy_authentication_forwarding 4040610791U /* enable-proxy-authentication-forwarding */
138 #define hash_enable_remote_toggle 2979744683U /* "enable-remote-toggle" */
139 #define hash_enable_remote_http_toggle 110543988U /* "enable-remote-http-toggle" */
140 #define hash_enforce_blocks 1862427469U /* "enforce-blocks" */
141 #define hash_filterfile 250887266U /* "filterfile" */
142 #define hash_forward 2029845U /* "forward" */
143 #define hash_forward_socks4 3963965521U /* "forward-socks4" */
144 #define hash_forward_socks4a 2639958518U /* "forward-socks4a" */
145 #define hash_forward_socks5 3963965522U /* "forward-socks5" */
146 #define hash_forward_socks5t 2639958542U /* "forward-socks5t" */
147 #define hash_forwarded_connect_retries 101465292U /* "forwarded-connect-retries" */
148 #define hash_handle_as_empty_returns_ok 1444873247U /* "handle-as-empty-doc-returns-ok" */
149 #define hash_hostname 10308071U /* "hostname" */
150 #define hash_keep_alive_timeout 3878599515U /* "keep-alive-timeout" */
151 #define hash_listen_address 1255650842U /* "listen-address" */
152 #define hash_logdir 422889U /* "logdir" */
153 #define hash_logfile 2114766U /* "logfile" */
154 #define hash_max_client_connections 3595884446U /* "max-client-connections" */
155 #define hash_permit_access 3587953268U /* "permit-access" */
156 #define hash_proxy_info_url 3903079059U /* "proxy-info-url" */
157 #define hash_single_threaded 4250084780U /* "single-threaded" */
158 #define hash_socket_timeout 1809001761U /* "socket-timeout" */
159 #define hash_split_large_cgi_forms 671658948U /* "split-large-cgi-forms" */
160 #define hash_suppress_blocklists 1948693308U /* "suppress-blocklists" */
161 #define hash_templdir 11067889U /* "templdir" */
162 #define hash_temporary_directory 1824125181U /* "temporary-directory" */
163 #define hash_tolerate_pipelining 1360286620U /* "tolerate-pipelining" */
164 #define hash_toggle 447966U /* "toggle" */
165 #define hash_trust_info_url 430331967U /* "trust-info-url" */
166 #define hash_trustfile 56494766U /* "trustfile" */
167 #define hash_usermanual 1416668518U /* "user-manual" */
168 #define hash_activity_animation 1817904738U /* "activity-animation" */
169 #define hash_close_button_minimizes 3651284693U /* "close-button-minimizes" */
170 #define hash_hide_console 2048809870U /* "hide-console" */
171 #define hash_log_buffer_size 2918070425U /* "log-buffer-size" */
172 #define hash_log_font_name 2866730124U /* "log-font-name" */
173 #define hash_log_font_size 2866731014U /* "log-font-size" */
174 #define hash_log_highlight_messages 4032101240U /* "log-highlight-messages" */
175 #define hash_log_max_lines 2868344173U /* "log-max-lines" */
176 #define hash_log_messages 2291744899U /* "log-messages" */
177 #define hash_show_on_task_bar 215410365U /* "show-on-task-bar" */
180 static void savearg(char *command, char *argument, struct configuration_spec * config);
181 #ifdef FEATURE_CLIENT_TAGS
182 static void free_client_specific_tags(struct client_tag_spec *tag_list);
185 /*********************************************************************
187 * Function : unload_configfile
189 * Description : Free the config structure and all components.
192 * 1 : data: struct configuration_spec to unload
196 *********************************************************************/
197 static void unload_configfile (void * data)
199 struct configuration_spec * config = (struct configuration_spec *)data;
200 struct forward_spec *cur_fwd = config->forward;
204 struct access_control_list *cur_acl = config->acl;
206 while (cur_acl != NULL)
208 struct access_control_list * next_acl = cur_acl->next;
213 #endif /* def FEATURE_ACL */
215 while (cur_fwd != NULL)
217 struct forward_spec * next_fwd = cur_fwd->next;
218 free_pattern_spec(cur_fwd->url);
220 freez(cur_fwd->gateway_host);
221 freez(cur_fwd->forward_host);
225 config->forward = NULL;
227 freez(config->confdir);
228 freez(config->logdir);
229 freez(config->templdir);
230 freez(config->hostname);
231 #ifdef FEATURE_EXTERNAL_FILTERS
232 freez(config->temporary_directory);
235 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
237 freez(config->haddr[i]);
239 freez(config->logfile);
241 for (i = 0; i < MAX_AF_FILES; i++)
243 freez(config->actions_file_short[i]);
244 freez(config->actions_file[i]);
245 freez(config->re_filterfile_short[i]);
246 freez(config->re_filterfile[i]);
249 list_remove_all(config->ordered_client_headers);
251 freez(config->admin_address);
252 freez(config->proxy_info_url);
253 freez(config->proxy_args);
254 freez(config->usermanual);
257 freez(config->trustfile);
258 list_remove_all(config->trust_info);
259 #endif /* def FEATURE_TRUST */
261 #ifdef FEATURE_CLIENT_TAGS
262 free_client_specific_tags(config->client_tags);
269 #ifdef FEATURE_GRACEFUL_TERMINATION
270 /*********************************************************************
272 * Function : unload_current_config_file
274 * Description : Unloads current config file - reset to state at
275 * beginning of program.
281 *********************************************************************/
282 void unload_current_config_file(void)
284 if (current_configfile)
286 current_configfile->unloader = unload_configfile;
287 current_configfile = NULL;
293 #ifdef FEATURE_CLIENT_TAGS
294 /*********************************************************************
296 * Function : register_tag
298 * Description : Registers a client-specific-tag and its description
301 * 1 : config: The tag list
302 * 2 : name: The name of the client-specific-tag
303 * 3 : description: The human-readable description for the tag
307 *********************************************************************/
308 static void register_tag(struct client_tag_spec *tag_list,
309 const char *name, const char *description)
311 struct client_tag_spec *new_tag;
312 struct client_tag_spec *last_tag;
315 while (last_tag->next != NULL)
317 last_tag = last_tag->next;
319 if (last_tag->name == NULL)
326 new_tag = zalloc_or_die(sizeof(struct client_tag_spec));
328 new_tag->name = strdup_or_die(name);
329 new_tag->description = strdup_or_die(description);
330 if (new_tag != last_tag)
332 last_tag->next = new_tag;
337 /*********************************************************************
339 * Function : free_client_specific_tags
341 * Description : Frees client-specific tags and their descriptions
344 * 1 : tag_list: The tag list to free
348 *********************************************************************/
349 static void free_client_specific_tags(struct client_tag_spec *tag_list)
351 struct client_tag_spec *this_tag;
352 struct client_tag_spec *next_tag;
358 next_tag = next_tag->next;
360 freez(this_tag->name);
361 freez(this_tag->description);
363 if (this_tag != tag_list)
367 } while (next_tag != NULL);
369 #endif /* def FEATURE_CLIENT_TAGS */
372 /*********************************************************************
374 * Function : parse_numeric_value
376 * Description : Parse the value of a directive that can only have
377 * a single numeric value. Terminates with a fatal error
378 * if the value is NULL or not numeric.
381 * 1 : name: The name of the directive. Used for log messages.
382 * 2 : value: The value to parse
385 * Returns : The numerical value as integer
387 *********************************************************************/
388 static int parse_numeric_value(const char *name, const char *value)
393 assert(name != NULL);
394 assert(value != NULL);
396 if ((value == NULL) || (*value == '\0'))
398 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
401 number = (int)strtol(value, &endptr, 0);
404 log_error(LOG_LEVEL_FATAL,
405 "Directive '%s' used with non-numerical value: '%s'", name, value);
413 /*********************************************************************
415 * Function : parse_toggle_value
417 * Description : Parse the value of a directive that can only be
418 * enabled or disabled. Terminates with a fatal error
419 * if the value is NULL or something other than 0 or 1.
422 * 1 : name: The name of the directive. Used for log messages.
423 * 2 : value: The value to parse
426 * Returns : The numerical toggle state
428 *********************************************************************/
429 static int parse_toggle_state(const char *name, const char *value)
432 assert(name != NULL);
433 assert(value != NULL);
435 if ((value == NULL) || (*value == '\0'))
437 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
440 toggle_state = atoi(value);
443 * Also check the length as atoi() doesn't mind
444 * garbage after a valid integer, but we do.
446 if (((toggle_state != 0) && (toggle_state != 1)) || (strlen(value) != 1))
448 log_error(LOG_LEVEL_FATAL,
449 "Directive %s used with invalid argument '%s'. Use either '0' or '1'.",
458 /*********************************************************************
460 * Function : parse_client_header_order
462 * Description : Parse the value of the header-order directive
465 * 1 : ordered_header_list: List to insert the ordered
467 * 2 : ordered_headers: The ordered header names separated
473 *********************************************************************/
474 static void parse_client_header_order(struct list *ordered_header_list, const char *ordered_headers)
476 char *original_headers_copy;
479 int number_of_headers;
482 assert(ordered_header_list != NULL);
483 assert(ordered_headers != NULL);
485 if (ordered_headers == NULL)
487 log_error(LOG_LEVEL_FATAL, "header-order used without argument");
491 * XXX: This estimate is guaranteed to be high enough as we
492 * let ssplit() ignore empty fields, but also a bit wasteful.
493 * The same hack is used in get_last_url() so it looks like
494 * a real solution is needed.
496 max_segments = strlen(ordered_headers) / 2;
497 if (max_segments == 0)
501 vector = malloc_or_die(max_segments * sizeof(char *));
503 original_headers_copy = strdup_or_die(ordered_headers);
505 number_of_headers = ssplit(original_headers_copy, "\t ", vector, max_segments);
506 if (number_of_headers == -1)
508 log_error(LOG_LEVEL_FATAL, "Failed to split ordered headers");
511 for (i = 0; i < number_of_headers; i++)
513 if (JB_ERR_OK != enlist(ordered_header_list, vector[i]))
515 log_error(LOG_LEVEL_FATAL,
516 "Failed to enlist ordered header: %s", vector[i]);
521 freez(original_headers_copy);
528 /*********************************************************************
530 * Function : load_config
532 * Description : Load the config file and all parameters.
534 * XXX: more than thousand lines long
535 * and thus in serious need of refactoring.
539 * Returns : The configuration_spec, or NULL on error.
541 *********************************************************************/
542 struct configuration_spec * load_config(void)
546 FILE *configfp = NULL;
547 struct configuration_spec * config = NULL;
548 struct client_state * fake_csp;
549 struct file_list *fs;
550 unsigned long linenum = 0;
552 char *logfile = NULL;
554 if (!check_file_changed(current_configfile, configfile, &fs))
556 /* No need to load */
557 return ((struct configuration_spec *)current_configfile->f);
561 log_error(LOG_LEVEL_FATAL,
562 "can't check configuration file '%s': %E", configfile);
566 if (NULL != current_configfile)
568 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
571 #ifdef FEATURE_TOGGLE
572 global_toggle_state = 1;
573 #endif /* def FEATURE_TOGGLE */
575 fs->f = config = zalloc_or_die(sizeof(*config));
578 * This is backwards from how it's usually done.
579 * Following the usual pattern, "fs" would be stored in a member
580 * variable in "csp", and then we'd access "config" from "fs->f",
581 * using a cast. However, "config" is used so often that a
582 * cast each time would be very ugly, and the extra indirection
583 * would waste CPU cycles. Therefore we store "config" in
584 * "csp->config", and "fs" in "csp->config->config_file_list".
586 config->config_file_list = fs;
591 config->multi_threaded = 1;
592 config->buffer_limit = 4096 * 1024;
593 config->usermanual = strdup(USER_MANUAL_URL);
594 config->proxy_args = strdup("");
595 config->forwarded_connect_retries = 0;
596 config->client_tag_lifetime = 60;
598 * 128 client sockets ought to be enough for everybody who can't
599 * be bothered to read the documentation to figure out how to
600 * increase the limit.
602 config->max_client_connections = 128;
603 config->socket_timeout = 300; /* XXX: Should be a macro. */
604 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
605 config->default_server_timeout = 0;
606 config->keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
607 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
608 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
610 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
611 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
612 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
613 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
614 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
615 #ifdef FEATURE_COMPRESSION
616 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
618 * XXX: Run some benchmarks to see if there are better default values.
620 config->compression_level = 1;
622 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
624 configfp = fopen(configfile, "r");
625 if (NULL == configfp)
627 log_error(LOG_LEVEL_FATAL,
628 "can't open configuration file '%s': %E", configfile);
629 /* Never get here - LOG_LEVEL_FATAL causes program exit */
632 while (read_config_line(configfp, &linenum, &buf) != NULL)
634 char cmd[BUFFER_SIZE];
635 char arg[BUFFER_SIZE];
636 char tmp[BUFFER_SIZE];
638 struct access_control_list *cur_acl;
639 #endif /* def FEATURE_ACL */
640 struct forward_spec *cur_fwd;
643 unsigned int directive_hash;
645 strlcpy(tmp, buf, sizeof(tmp));
647 /* Copy command (i.e. up to space or tab) into cmd */
650 while (*p && (*p != ' ') && (*p != '\t'))
656 /* Skip over the whitespace in buf */
657 while (*p && ((*p == ' ') || (*p == '\t')))
662 /* Copy the argument into arg */
663 if (strlcpy(arg, p, sizeof(arg)) >= sizeof(arg))
665 log_error(LOG_LEVEL_FATAL, "Config line too long: %s", buf);
668 /* Should never happen, but check this anyway */
675 /* Make sure the command field is lower case */
676 for (p = cmd; *p; p++)
678 if (privoxy_isupper(*p))
680 *p = (char)privoxy_tolower(*p);
684 directive_hash = hash_string(cmd);
685 switch (directive_hash)
687 /* *************************************************************************
688 * actionsfile actions-file-name
689 * In confdir by default
690 * *************************************************************************/
691 case hash_actions_file :
693 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
698 if (i >= MAX_AF_FILES)
700 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
701 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
704 config->actions_file_short[i] = strdup(arg);
705 config->actions_file[i] = make_path(config->confdir, arg);
708 /* *************************************************************************
709 * accept-intercepted-requests
710 * *************************************************************************/
711 case hash_accept_intercepted_requests:
712 if (parse_toggle_state(cmd, arg) == 1)
714 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
718 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
722 /* *************************************************************************
723 * admin-address email-address
724 * *************************************************************************/
725 case hash_admin_address :
726 freez(config->admin_address);
727 config->admin_address = strdup(arg);
730 /* *************************************************************************
731 * allow-cgi-request-crunching
732 * *************************************************************************/
733 case hash_allow_cgi_request_crunching:
734 if (parse_toggle_state(cmd, arg) == 1)
736 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
740 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
744 /* *************************************************************************
746 * *************************************************************************/
747 case hash_buffer_limit :
748 config->buffer_limit = (size_t)(1024 * parse_numeric_value(cmd, arg));
751 /* *************************************************************************
752 * client-header-order header-1 header-2 ... header-n
753 * *************************************************************************/
754 case hash_client_header_order:
755 list_remove_all(config->ordered_client_headers);
756 parse_client_header_order(config->ordered_client_headers, arg);
759 /* *************************************************************************
760 * client-specific-tag tag-name description
761 * *************************************************************************/
762 #ifdef FEATURE_CLIENT_TAGS
763 case hash_client_specific_tag:
769 description = strstr(arg, " ");
770 if (description == NULL)
772 log_error(LOG_LEVEL_FATAL,
773 "client-specific-tag '%s' lacks a description.", name);
777 register_tag(config->client_tags, name, description);
780 #endif /* def FEATURE_CLIENT_TAGS */
782 /* *************************************************************************
783 * client-tag-lifetime ttl
784 * *************************************************************************/
785 #ifdef FEATURE_CLIENT_TAGS
786 case hash_client_tag_lifetime:
788 int ttl = parse_numeric_value(cmd, arg);
791 config->client_tag_lifetime = (unsigned)ttl;
795 log_error(LOG_LEVEL_FATAL,
796 "client-tag-lifetime can't be negative.");
800 #endif /* def FEATURE_CLIENT_TAGS */
802 /* *************************************************************************
803 * confdir directory-name
804 * *************************************************************************/
806 freez(config->confdir);
807 config->confdir = make_path(NULL, arg);
810 /* *************************************************************************
811 * compression-level 0-9
812 * *************************************************************************/
813 #ifdef FEATURE_COMPRESSION
814 case hash_compression_level :
816 int compression_level = parse_numeric_value(cmd, arg);
817 if (-1 <= compression_level && compression_level <= 9)
819 config->compression_level = compression_level;
823 log_error(LOG_LEVEL_FATAL,
824 "Invalid compression-level value: %s", arg);
830 /* *************************************************************************
831 * connection-sharing (0|1)
832 * *************************************************************************/
833 #ifdef FEATURE_CONNECTION_SHARING
834 case hash_connection_sharing :
835 if (parse_toggle_state(cmd, arg) == 1)
837 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_SHARING;
841 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
846 /* *************************************************************************
848 * Specifies debug level, multiple values are ORed together.
849 * *************************************************************************/
851 config->debug |= parse_numeric_value(cmd, arg);
854 /* *************************************************************************
855 * default-server-timeout timeout
856 * *************************************************************************/
857 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
858 case hash_default_server_timeout :
860 int timeout = parse_numeric_value(cmd, arg);
863 config->default_server_timeout = (unsigned int)timeout;
867 log_error(LOG_LEVEL_FATAL,
868 "Invalid default-server-timeout value: %s", arg);
874 /* *************************************************************************
875 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
876 * *************************************************************************/
878 case hash_deny_access:
879 strlcpy(tmp, arg, sizeof(tmp));
880 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
882 if ((vec_count != 1) && (vec_count != 2))
884 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
885 "deny-access directive in configuration file.");
886 string_append(&config->proxy_args,
887 "<br>\nWARNING: Wrong number of parameters for "
888 "deny-access directive in configuration file.<br><br>\n");
892 /* allocate a new node */
893 cur_acl = zalloc_or_die(sizeof(*cur_acl));
894 cur_acl->action = ACL_DENY;
896 if (acl_addr(vec[0], cur_acl->src) < 0)
898 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
899 "for deny-access directive in configuration file: \"%s\"", vec[0]);
900 string_append(&config->proxy_args,
901 "<br>\nWARNING: Invalid source address, port or netmask "
902 "for deny-access directive in configuration file: \"");
903 string_append(&config->proxy_args,
905 string_append(&config->proxy_args,
912 if (acl_addr(vec[1], cur_acl->dst) < 0)
914 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
915 "for deny-access directive in configuration file: \"%s\"", vec[1]);
916 string_append(&config->proxy_args,
917 "<br>\nWARNING: Invalid destination address, port or netmask "
918 "for deny-access directive in configuration file: \"");
919 string_append(&config->proxy_args,
921 string_append(&config->proxy_args,
930 cur_acl->wildcard_dst = 1;
932 #endif /* def HAVE_RFC2553 */
935 * Add it to the list. Note we reverse the list to get the
936 * behaviour the user expects. With both the ACL and
937 * actions file, the last match wins. However, the internal
938 * implementations are different: The actions file is stored
939 * in the same order as the file, and scanned completely.
940 * With the ACL, we reverse the order as we load it, then
941 * when we scan it we stop as soon as we get a match.
943 cur_acl->next = config->acl;
944 config->acl = cur_acl;
947 #endif /* def FEATURE_ACL */
949 /* *************************************************************************
950 * enable-edit-actions 0|1
951 * *************************************************************************/
952 #ifdef FEATURE_CGI_EDIT_ACTIONS
953 case hash_enable_edit_actions:
954 if (parse_toggle_state(cmd, arg) == 1)
956 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
960 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
963 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
965 /* *************************************************************************
966 * enable-compression 0|1
967 * *************************************************************************/
968 #ifdef FEATURE_COMPRESSION
969 case hash_enable_compression:
970 if (parse_toggle_state(cmd, arg) == 1)
972 config->feature_flags |= RUNTIME_FEATURE_COMPRESSION;
976 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
979 #endif /* def FEATURE_COMPRESSION */
981 /* *************************************************************************
982 * enable-proxy-authentication-forwarding 0|1
983 * *************************************************************************/
984 case hash_enable_proxy_authentication_forwarding:
985 if (parse_toggle_state(cmd, arg) == 1)
987 config->feature_flags |= RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
991 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
995 /* *************************************************************************
996 * enable-remote-toggle 0|1
997 * *************************************************************************/
998 #ifdef FEATURE_TOGGLE
999 case hash_enable_remote_toggle:
1000 if (parse_toggle_state(cmd, arg) == 1)
1002 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1006 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1009 #endif /* def FEATURE_TOGGLE */
1011 /* *************************************************************************
1012 * enable-remote-http-toggle 0|1
1013 * *************************************************************************/
1014 case hash_enable_remote_http_toggle:
1015 if (parse_toggle_state(cmd, arg) == 1)
1017 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1021 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1025 /* *************************************************************************
1026 * enforce-blocks 0|1
1027 * *************************************************************************/
1028 case hash_enforce_blocks:
1029 #ifdef FEATURE_FORCE_LOAD
1030 if (parse_toggle_state(cmd, arg) == 1)
1032 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1036 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1039 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1040 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1041 #endif /* def FEATURE_FORCE_LOAD */
1044 /* *************************************************************************
1045 * filterfile file-name
1046 * In confdir by default.
1047 * *************************************************************************/
1048 case hash_filterfile :
1050 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1055 if (i >= MAX_AF_FILES)
1057 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1058 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1061 config->re_filterfile_short[i] = strdup(arg);
1062 config->re_filterfile[i] = make_path(config->confdir, arg);
1066 /* *************************************************************************
1067 * forward url-pattern (.|http-proxy-host[:port])
1068 * *************************************************************************/
1070 strlcpy(tmp, arg, sizeof(tmp));
1071 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1075 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1076 "directive in configuration file.");
1077 string_append(&config->proxy_args,
1078 "<br>\nWARNING: Wrong number of parameters for "
1079 "forward directive in configuration file.");
1083 /* allocate a new node */
1084 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1085 cur_fwd->type = SOCKS_NONE;
1087 /* Save the URL pattern */
1088 if (create_pattern_spec(cur_fwd->url, vec[0]))
1090 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1091 "directive in configuration file.");
1092 string_append(&config->proxy_args,
1093 "<br>\nWARNING: Bad URL specifier for "
1094 "forward directive in configuration file.");
1099 /* Parse the parent HTTP proxy host:port */
1102 if (strcmp(p, ".") != 0)
1104 cur_fwd->forward_port = 8000;
1105 parse_forwarder_address(p, &cur_fwd->forward_host,
1106 &cur_fwd->forward_port);
1110 cur_fwd->next = config->forward;
1111 config->forward = cur_fwd;
1115 /* *************************************************************************
1116 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1117 * *************************************************************************/
1118 case hash_forward_socks4:
1119 strlcpy(tmp, arg, sizeof(tmp));
1120 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1124 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1125 "forward-socks4 directive in configuration file.");
1126 string_append(&config->proxy_args,
1127 "<br>\nWARNING: Wrong number of parameters for "
1128 "forward-socks4 directive in configuration file.");
1132 /* allocate a new node */
1133 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1134 cur_fwd->type = SOCKS_4;
1136 /* Save the URL pattern */
1137 if (create_pattern_spec(cur_fwd->url, vec[0]))
1139 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1140 "directive in configuration file.");
1141 string_append(&config->proxy_args,
1142 "<br>\nWARNING: Bad URL specifier for "
1143 "forward-socks4 directive in configuration file.");
1148 /* Parse the SOCKS proxy host[:port] */
1151 /* XXX: This check looks like a bug. */
1152 if (strcmp(p, ".") != 0)
1154 cur_fwd->gateway_port = 1080;
1155 parse_forwarder_address(p, &cur_fwd->gateway_host,
1156 &cur_fwd->gateway_port);
1159 /* Parse the parent HTTP proxy host[:port] */
1162 if (strcmp(p, ".") != 0)
1164 cur_fwd->forward_port = 8000;
1165 parse_forwarder_address(p, &cur_fwd->forward_host,
1166 &cur_fwd->forward_port);
1170 cur_fwd->next = config->forward;
1171 config->forward = cur_fwd;
1175 /* *************************************************************************
1176 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1177 * *************************************************************************/
1178 case hash_forward_socks4a:
1179 case hash_forward_socks5:
1180 case hash_forward_socks5t:
1181 strlcpy(tmp, arg, sizeof(tmp));
1182 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1186 log_error(LOG_LEVEL_ERROR,
1187 "Wrong number of parameters for %s in configuration file.",
1189 string_append(&config->proxy_args,
1190 "<br>\nWARNING: Wrong number of parameters for ");
1191 string_append(&config->proxy_args, cmd);
1192 string_append(&config->proxy_args,
1193 "directive in configuration file.");
1197 /* allocate a new node */
1198 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1200 if (directive_hash == hash_forward_socks4a)
1202 cur_fwd->type = SOCKS_4A;
1204 else if (directive_hash == hash_forward_socks5)
1206 cur_fwd->type = SOCKS_5;
1210 assert(directive_hash == hash_forward_socks5t);
1211 cur_fwd->type = SOCKS_5T;
1214 /* Save the URL pattern */
1215 if (create_pattern_spec(cur_fwd->url, vec[0]))
1217 log_error(LOG_LEVEL_ERROR,
1218 "Bad URL specifier for %s in configuration file.",
1220 string_append(&config->proxy_args,
1221 "<br>\nWARNING: Bad URL specifier for ");
1222 string_append(&config->proxy_args, cmd);
1223 string_append(&config->proxy_args,
1224 "directive in configuration file.");
1229 /* Parse the SOCKS proxy host[:port] */
1232 cur_fwd->gateway_port = 1080;
1233 parse_forwarder_address(p, &cur_fwd->gateway_host,
1234 &cur_fwd->gateway_port);
1236 /* Parse the parent HTTP proxy host[:port] */
1239 if (strcmp(p, ".") != 0)
1241 cur_fwd->forward_port = 8000;
1242 parse_forwarder_address(p, &cur_fwd->forward_host,
1243 &cur_fwd->forward_port);
1247 cur_fwd->next = config->forward;
1248 config->forward = cur_fwd;
1252 /* *************************************************************************
1253 * forwarded-connect-retries n
1254 * *************************************************************************/
1255 case hash_forwarded_connect_retries :
1256 config->forwarded_connect_retries = parse_numeric_value(cmd, arg);
1259 /* *************************************************************************
1260 * handle-as-empty-doc-returns-ok 0|1
1262 * Workaround for firefox hanging on blocked javascript pages.
1263 * Block with the "+handle-as-empty-document" flag and set the
1264 * "handle-as-empty-doc-returns-ok" run-time config flag so that
1265 * Privoxy returns a 200/OK status instead of a 403/Forbidden status
1266 * to the browser for blocked pages.
1267 ***************************************************************************/
1268 case hash_handle_as_empty_returns_ok:
1269 if (parse_toggle_state(cmd, arg) == 1)
1271 config->feature_flags |= RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1275 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1279 /* *************************************************************************
1280 * hostname hostname-to-show-on-cgi-pages
1281 * *************************************************************************/
1282 case hash_hostname :
1283 freez(config->hostname);
1284 config->hostname = strdup(arg);
1285 if (NULL == config->hostname)
1287 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1291 /* *************************************************************************
1292 * keep-alive-timeout timeout
1293 * *************************************************************************/
1294 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1295 case hash_keep_alive_timeout :
1297 int timeout = parse_numeric_value(cmd, arg);
1300 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1301 config->keep_alive_timeout = (unsigned int)timeout;
1305 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1311 /* *************************************************************************
1312 * listen-address [ip][:port]
1313 * *************************************************************************/
1314 case hash_listen_address :
1316 while ((i < MAX_LISTENING_SOCKETS) && (NULL != config->haddr[i]))
1321 if (i >= MAX_LISTENING_SOCKETS)
1323 log_error(LOG_LEVEL_FATAL, "Too many 'listen-address' directives in config file - limit is %d.\n"
1324 "(You can increase this limit by changing MAX_LISTENING_SOCKETS in project.h and recompiling).",
1325 MAX_LISTENING_SOCKETS);
1327 config->haddr[i] = strdup(arg);
1328 if (NULL == config->haddr[i])
1330 log_error(LOG_LEVEL_FATAL, "Out of memory while copying listening address");
1334 /* *************************************************************************
1335 * logdir directory-name
1336 * *************************************************************************/
1338 freez(config->logdir);
1339 config->logdir = make_path(NULL, arg);
1342 /* *************************************************************************
1343 * logfile log-file-name
1344 * In logdir by default
1345 * *************************************************************************/
1349 logfile = make_path(config->logdir, arg);
1350 if (NULL == logfile)
1352 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1357 /* *************************************************************************
1358 * max-client-connections number
1359 * *************************************************************************/
1360 case hash_max_client_connections :
1362 int max_client_connections = parse_numeric_value(cmd, arg);
1363 if (0 <= max_client_connections)
1365 /* XXX: log error */
1366 config->max_client_connections = max_client_connections;
1371 /* *************************************************************************
1372 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1373 * *************************************************************************/
1375 case hash_permit_access:
1376 strlcpy(tmp, arg, sizeof(tmp));
1377 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1379 if ((vec_count != 1) && (vec_count != 2))
1381 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1382 "permit-access directive in configuration file.");
1383 string_append(&config->proxy_args,
1384 "<br>\nWARNING: Wrong number of parameters for "
1385 "permit-access directive in configuration file.<br><br>\n");
1390 /* allocate a new node */
1391 cur_acl = zalloc_or_die(sizeof(*cur_acl));
1392 cur_acl->action = ACL_PERMIT;
1394 if (acl_addr(vec[0], cur_acl->src) < 0)
1396 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1397 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1398 string_append(&config->proxy_args,
1399 "<br>\nWARNING: Invalid source address, port or netmask for "
1400 "permit-access directive in configuration file: \"");
1401 string_append(&config->proxy_args,
1403 string_append(&config->proxy_args,
1410 if (acl_addr(vec[1], cur_acl->dst) < 0)
1412 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1413 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1414 string_append(&config->proxy_args,
1415 "<br>\nWARNING: Invalid destination address, port or netmask for "
1416 "permit-access directive in configuration file: \"");
1417 string_append(&config->proxy_args,
1419 string_append(&config->proxy_args,
1428 cur_acl->wildcard_dst = 1;
1430 #endif /* def HAVE_RFC2553 */
1433 * Add it to the list. Note we reverse the list to get the
1434 * behaviour the user expects. With both the ACL and
1435 * actions file, the last match wins. However, the internal
1436 * implementations are different: The actions file is stored
1437 * in the same order as the file, and scanned completely.
1438 * With the ACL, we reverse the order as we load it, then
1439 * when we scan it we stop as soon as we get a match.
1441 cur_acl->next = config->acl;
1442 config->acl = cur_acl;
1445 #endif /* def FEATURE_ACL */
1447 /* *************************************************************************
1448 * proxy-info-url url
1449 * *************************************************************************/
1450 case hash_proxy_info_url :
1451 freez(config->proxy_info_url);
1452 config->proxy_info_url = strdup(arg);
1455 /* *************************************************************************
1456 * single-threaded 0|1
1457 * *************************************************************************/
1458 case hash_single_threaded :
1459 config->multi_threaded = 0 == parse_toggle_state(cmd, arg);
1462 /* *************************************************************************
1463 * socket-timeout numer_of_seconds
1464 * *************************************************************************/
1465 case hash_socket_timeout :
1467 int socket_timeout = parse_numeric_value(cmd, arg);
1468 if (0 <= socket_timeout)
1470 config->socket_timeout = socket_timeout;
1474 log_error(LOG_LEVEL_FATAL, "Invalid socket-timeout: '%s'", arg);
1479 /* *************************************************************************
1480 * split-large-cgi-forms
1481 * *************************************************************************/
1482 case hash_split_large_cgi_forms :
1483 if (parse_toggle_state(cmd, arg) == 1)
1485 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1489 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1493 /* *************************************************************************
1494 * templdir directory-name
1495 * *************************************************************************/
1496 case hash_templdir :
1497 freez(config->templdir);
1498 config->templdir = make_path(NULL, arg);
1501 #ifdef FEATURE_EXTERNAL_FILTERS
1502 /* *************************************************************************
1503 * temporary-directory directory-name
1504 * *************************************************************************/
1505 case hash_temporary_directory :
1506 freez(config->temporary_directory);
1507 config->temporary_directory = make_path(NULL, arg);
1511 /* *************************************************************************
1512 * tolerate-pipelining (0|1)
1513 * *************************************************************************/
1514 case hash_tolerate_pipelining :
1515 if (parse_toggle_state(cmd, arg) == 1)
1517 config->feature_flags |= RUNTIME_FEATURE_TOLERATE_PIPELINING;
1521 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
1525 /* *************************************************************************
1527 * *************************************************************************/
1528 #ifdef FEATURE_TOGGLE
1530 global_toggle_state = parse_toggle_state(cmd, arg);
1532 #endif /* def FEATURE_TOGGLE */
1534 /* *************************************************************************
1535 * trust-info-url url
1536 * *************************************************************************/
1537 #ifdef FEATURE_TRUST
1538 case hash_trust_info_url :
1539 enlist(config->trust_info, arg);
1541 #endif /* def FEATURE_TRUST */
1543 /* *************************************************************************
1544 * trustfile filename
1545 * (In confdir by default.)
1546 * *************************************************************************/
1547 #ifdef FEATURE_TRUST
1548 case hash_trustfile :
1549 freez(config->trustfile);
1550 config->trustfile = make_path(config->confdir, arg);
1552 #endif /* def FEATURE_TRUST */
1554 /* *************************************************************************
1556 * *************************************************************************/
1557 case hash_usermanual :
1559 * XXX: If this isn't the first config directive, the
1560 * show-status page links to the website documentation
1561 * for the directives that were already parsed. Lame.
1563 freez(config->usermanual);
1564 config->usermanual = strdup(arg);
1567 /* *************************************************************************
1568 * Win32 Console options:
1569 * *************************************************************************/
1571 /* *************************************************************************
1573 * *************************************************************************/
1575 case hash_hide_console :
1578 #endif /*def _WIN_CONSOLE*/
1581 /* *************************************************************************
1582 * Win32 GUI options:
1583 * *************************************************************************/
1585 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1586 /* *************************************************************************
1587 * activity-animation (0|1)
1588 * *************************************************************************/
1589 case hash_activity_animation :
1590 g_bShowActivityAnimation = parse_toggle_state(cmd, arg);
1593 /* *************************************************************************
1594 * close-button-minimizes (0|1)
1595 * *************************************************************************/
1596 case hash_close_button_minimizes :
1597 g_bCloseHidesWindow = parse_toggle_state(cmd, arg);
1600 /* *************************************************************************
1601 * log-buffer-size (0|1)
1602 * *************************************************************************/
1603 case hash_log_buffer_size :
1604 g_bLimitBufferSize = parse_toggle_state(cmd, arg);
1607 /* *************************************************************************
1608 * log-font-name fontname
1609 * *************************************************************************/
1610 case hash_log_font_name :
1611 if (strlcpy(g_szFontFaceName, arg,
1612 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1614 log_error(LOG_LEVEL_FATAL,
1615 "log-font-name argument '%s' is longer than %u characters.",
1616 arg, sizeof(g_szFontFaceName)-1);
1620 /* *************************************************************************
1622 * *************************************************************************/
1623 case hash_log_font_size :
1624 g_nFontSize = parse_numeric_value(cmd, arg);
1627 /* *************************************************************************
1628 * log-highlight-messages (0|1)
1629 * *************************************************************************/
1630 case hash_log_highlight_messages :
1631 g_bHighlightMessages = parse_toggle_state(cmd, arg);
1634 /* *************************************************************************
1636 * *************************************************************************/
1637 case hash_log_max_lines :
1638 g_nMaxBufferLines = parse_numeric_value(cmd, arg);
1641 /* *************************************************************************
1642 * log-messages (0|1)
1643 * *************************************************************************/
1644 case hash_log_messages :
1645 g_bLogMessages = parse_toggle_state(cmd, arg);
1648 /* *************************************************************************
1649 * show-on-task-bar (0|1)
1650 * *************************************************************************/
1651 case hash_show_on_task_bar :
1652 g_bShowOnTaskBar = parse_toggle_state(cmd, arg);
1655 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1658 /* *************************************************************************
1659 * Warnings about unsupported features
1660 * *************************************************************************/
1662 case hash_deny_access:
1663 #endif /* ndef FEATURE_ACL */
1664 #ifndef FEATURE_CGI_EDIT_ACTIONS
1665 case hash_enable_edit_actions:
1666 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1667 #ifndef FEATURE_TOGGLE
1668 case hash_enable_remote_toggle:
1669 #endif /* ndef FEATURE_TOGGLE */
1671 case hash_permit_access:
1672 #endif /* ndef FEATURE_ACL */
1673 #ifndef FEATURE_TOGGLE
1675 #endif /* ndef FEATURE_TOGGLE */
1676 #ifndef FEATURE_TRUST
1677 case hash_trustfile :
1678 case hash_trust_info_url :
1679 #endif /* ndef FEATURE_TRUST */
1681 #ifndef _WIN_CONSOLE
1682 case hash_hide_console :
1683 #endif /* ndef _WIN_CONSOLE */
1685 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1686 case hash_activity_animation :
1687 case hash_close_button_minimizes :
1688 case hash_log_buffer_size :
1689 case hash_log_font_name :
1690 case hash_log_font_size :
1691 case hash_log_highlight_messages :
1692 case hash_log_max_lines :
1693 case hash_log_messages :
1694 case hash_show_on_task_bar :
1695 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1696 /* These warnings are annoying - so hide them. -- Jon */
1697 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1700 /* *************************************************************************/
1702 /* *************************************************************************/
1704 * I decided that I liked this better as a warning than an
1705 * error. To change back to an error, just change log level
1706 * to LOG_LEVEL_FATAL.
1708 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive "
1709 "'%s' (%uU) in line %lu in configuration file (%s).",
1710 buf, directive_hash, linenum, configfile);
1711 string_append(&config->proxy_args,
1712 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1715 /* *************************************************************************/
1716 } /* end switch(hash_string(cmd)) */
1718 /* Save the argument for the show-status page. */
1719 savearg(cmd, arg, config);
1721 } /* end while (read_config_line(...)) */
1725 set_debug_level(config->debug);
1727 freez(config->logfile);
1731 if (NULL != logfile)
1733 config->logfile = logfile;
1734 init_error_log(Argv[0], config->logfile);
1742 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1743 if (config->default_server_timeout > config->keep_alive_timeout)
1745 log_error(LOG_LEVEL_ERROR,
1746 "Reducing the default-server-timeout from %d to the keep-alive-timeout %d.",
1747 config->default_server_timeout, config->keep_alive_timeout);
1748 config->default_server_timeout = config->keep_alive_timeout;
1750 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
1752 #ifdef FEATURE_CONNECTION_SHARING
1753 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1755 if (config->multi_threaded)
1757 set_keep_alive_timeout(config->keep_alive_timeout);
1762 * While we could use keep-alive without multiple threads
1763 * if we didn't bother with enforcing the connection timeout,
1764 * that might make Tor users sad, even though they shouldn't
1765 * enable the single-threaded option anyway.
1767 * XXX: We could still use Proxy-Connection: keep-alive.
1769 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1770 log_error(LOG_LEVEL_ERROR,
1771 "Config option single-threaded disables connection keep-alive.");
1774 else if ((config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING))
1776 log_error(LOG_LEVEL_ERROR, "Config option connection-sharing "
1777 "has no effect if keep-alive-timeout isn't set.");
1778 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
1780 #endif /* def FEATURE_CONNECTION_SHARING */
1782 if (NULL == config->proxy_args)
1784 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1787 if (config->re_filterfile[0])
1789 add_loader(load_re_filterfiles, config);
1792 if (config->actions_file[0])
1794 add_loader(load_action_files, config);
1797 #ifdef FEATURE_TRUST
1798 if (config->trustfile)
1800 add_loader(load_trustfile, config);
1802 #endif /* def FEATURE_TRUST */
1804 if (NULL == config->haddr[0])
1806 config->haddr[0] = strdup(HADDR_DEFAULT);
1807 if (NULL == config->haddr[0])
1809 log_error(LOG_LEVEL_FATAL, "Out of memory while copying default listening address");
1813 for (i = 0; i < MAX_LISTENING_SOCKETS && NULL != config->haddr[i]; i++)
1815 if ((*config->haddr[i] == '[')
1816 && (NULL != (p = strchr(config->haddr[i], ']')))
1818 && (0 < (config->hport[i] = atoi(p + 2))))
1821 memmove((void *)config->haddr[i], config->haddr[i] + 1,
1822 (size_t)(p - config->haddr[i]));
1824 else if (NULL != (p = strchr(config->haddr[i], ':'))
1825 && (0 < (config->hport[i] = atoi(p + 1))))
1831 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr[i]);
1832 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1834 if (*config->haddr[i] == '\0')
1837 * Only the port specified. We stored it in config->hport[i]
1838 * and don't need its text representation anymore.
1839 * Use config->hport[i] == 0 to iterate listening addresses since
1842 freez(config->haddr[i]);
1847 * Want to run all the loaders once now.
1849 * Need to set up a fake csp, so they can get to the config.
1851 fake_csp = zalloc_or_die(sizeof(*fake_csp));
1852 fake_csp->config = config;
1854 if (run_loader(fake_csp))
1857 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1858 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1862 /* FIXME: this is a kludge for win32 */
1863 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1865 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1866 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1867 g_default_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1868 g_user_filterfile = config->re_filterfile[1]; /* FIXME Hope this is user.filter */
1870 #ifdef FEATURE_TRUST
1871 g_trustfile = config->trustfile;
1872 #endif /* def FEATURE_TRUST */
1875 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1876 /* FIXME: end kludge */
1879 config->need_bind = 1;
1881 if (current_configfile)
1883 struct configuration_spec * oldcfg = (struct configuration_spec *)
1884 current_configfile->f;
1886 * Check if config->haddr[i],hport[i] == oldcfg->haddr[i],hport[i]
1888 * The following could be written more compactly as a single,
1889 * (unreadably long) if statement.
1891 config->need_bind = 0;
1893 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
1895 if (config->hport[i] != oldcfg->hport[i])
1897 config->need_bind = 1;
1899 else if (config->haddr[i] == NULL)
1901 if (oldcfg->haddr[i] != NULL)
1903 config->need_bind = 1;
1906 else if (oldcfg->haddr[i] == NULL)
1908 config->need_bind = 1;
1910 else if (0 != strcmp(config->haddr[i], oldcfg->haddr[i]))
1912 config->need_bind = 1;
1916 current_configfile->unloader = unload_configfile;
1919 fs->next = files->next;
1922 current_configfile = fs;
1928 /*********************************************************************
1930 * Function : savearg
1932 * Description : Called from `load_config'. It saves each non-empty
1933 * and non-comment line from config into
1934 * config->proxy_args. This is used to create the
1935 * show-proxy-args page. On error, frees
1936 * config->proxy_args and sets it to NULL
1939 * 1 : command = config setting that was found
1940 * 2 : argument = the setting's argument (if any)
1941 * 3 : config = Configuration to save into.
1945 *********************************************************************/
1946 static void savearg(char *command, char *argument, struct configuration_spec * config)
1955 * Add config option name embedded in
1956 * link to its section in the user-manual
1958 buf = strdup("\n<a href=\"");
1959 if (!strncmpic(config->usermanual, "file://", 7) ||
1960 !strncmpic(config->usermanual, "http", 4))
1962 string_append(&buf, config->usermanual);
1966 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1968 string_append(&buf, CONFIG_HELP_PREFIX);
1969 string_join (&buf, string_toupper(command));
1970 string_append(&buf, "\">");
1971 string_append(&buf, command);
1972 string_append(&buf, "</a> ");
1976 freez(config->proxy_args);
1980 if ((NULL != argument) && ('\0' != *argument))
1982 s = html_encode(argument);
1986 freez(config->proxy_args);
1990 if (strncmpic(argument, "http://", 7) == 0)
1992 string_append(&buf, "<a href=\"");
1993 string_append(&buf, s);
1994 string_append(&buf, "\">");
1995 string_join (&buf, s);
1996 string_append(&buf, "</a>");
2000 string_join (&buf, s);
2004 string_append(&buf, "<br>");
2005 string_join(&config->proxy_args, buf);