1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.150 2016/03/27 16:54:50 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>
88 #ifdef FEATURE_CLIENT_TAGS
89 #include "client-tags.h"
92 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
95 /* Privoxy is enabled by default. */
96 int global_toggle_state = 1;
97 #endif /* def FEATURE_TOGGLE */
99 /* The filename of the configfile */
100 const char *configfile = NULL;
103 * CGI functions will later need access to the invocation args,
104 * so we will make argc and argv global.
107 char * const * Argv = NULL;
109 static struct file_list *current_configfile = NULL;
113 * This takes the "cryptic" hash of each keyword and aliases them to
114 * something a little more readable. This also makes changing the
115 * hash values easier if they should change or the hash algorthm changes.
116 * Use the included "hash" program to find out what the hash will be
117 * for any string supplied on the command line. (Or just put it in the
118 * config file and read the number from the error message in the log).
120 * Please keep this list sorted alphabetically (but with the Windows
121 * console and GUI specific options last).
124 #define hash_actions_file 1196306641U /* "actionsfile" */
125 #define hash_accept_intercepted_requests 1513024973U /* "accept-intercepted-requests" */
126 #define hash_admin_address 4112573064U /* "admin-address" */
127 #define hash_allow_cgi_request_crunching 258915987U /* "allow-cgi-request-crunching" */
128 #define hash_buffer_limit 1881726070U /* "buffer-limit */
129 #define hash_client_header_order 2701453514U /* "client-header-order" */
130 #define hash_client_specific_tag 3353703383U /* "client-specific-tag" */
131 #define hash_client_tag_lifetime 647957580U /* "client-tag-lifetime" */
132 #define hash_compression_level 2464423563U /* "compression-level" */
133 #define hash_confdir 1978389U /* "confdir" */
134 #define hash_connection_sharing 1348841265U /* "connection-sharing" */
135 #define hash_debug 78263U /* "debug" */
136 #define hash_default_server_timeout 2530089913U /* "default-server-timeout" */
137 #define hash_deny_access 1227333715U /* "deny-access" */
138 #define hash_enable_edit_actions 2517097536U /* "enable-edit-actions" */
139 #define hash_enable_compression 3943696946U /* "enable-compression" */
140 #define hash_enable_proxy_authentication_forwarding 4040610791U /* enable-proxy-authentication-forwarding */
141 #define hash_enable_remote_toggle 2979744683U /* "enable-remote-toggle" */
142 #define hash_enable_remote_http_toggle 110543988U /* "enable-remote-http-toggle" */
143 #define hash_enforce_blocks 1862427469U /* "enforce-blocks" */
144 #define hash_filterfile 250887266U /* "filterfile" */
145 #define hash_forward 2029845U /* "forward" */
146 #define hash_forward_socks4 3963965521U /* "forward-socks4" */
147 #define hash_forward_socks4a 2639958518U /* "forward-socks4a" */
148 #define hash_forward_socks5 3963965522U /* "forward-socks5" */
149 #define hash_forward_socks5t 2639958542U /* "forward-socks5t" */
150 #define hash_forwarded_connect_retries 101465292U /* "forwarded-connect-retries" */
151 #define hash_handle_as_empty_returns_ok 1444873247U /* "handle-as-empty-doc-returns-ok" */
152 #define hash_hostname 10308071U /* "hostname" */
153 #define hash_keep_alive_timeout 3878599515U /* "keep-alive-timeout" */
154 #define hash_listen_address 1255650842U /* "listen-address" */
155 #define hash_logdir 422889U /* "logdir" */
156 #define hash_logfile 2114766U /* "logfile" */
157 #define hash_max_client_connections 3595884446U /* "max-client-connections" */
158 #define hash_permit_access 3587953268U /* "permit-access" */
159 #define hash_proxy_info_url 3903079059U /* "proxy-info-url" */
160 #define hash_single_threaded 4250084780U /* "single-threaded" */
161 #define hash_socket_timeout 1809001761U /* "socket-timeout" */
162 #define hash_split_large_cgi_forms 671658948U /* "split-large-cgi-forms" */
163 #define hash_suppress_blocklists 1948693308U /* "suppress-blocklists" */
164 #define hash_templdir 11067889U /* "templdir" */
165 #define hash_temporary_directory 1824125181U /* "temporary-directory" */
166 #define hash_tolerate_pipelining 1360286620U /* "tolerate-pipelining" */
167 #define hash_toggle 447966U /* "toggle" */
168 #define hash_trust_info_url 430331967U /* "trust-info-url" */
169 #define hash_trustfile 56494766U /* "trustfile" */
170 #define hash_usermanual 1416668518U /* "user-manual" */
171 #define hash_activity_animation 1817904738U /* "activity-animation" */
172 #define hash_close_button_minimizes 3651284693U /* "close-button-minimizes" */
173 #define hash_hide_console 2048809870U /* "hide-console" */
174 #define hash_log_buffer_size 2918070425U /* "log-buffer-size" */
175 #define hash_log_font_name 2866730124U /* "log-font-name" */
176 #define hash_log_font_size 2866731014U /* "log-font-size" */
177 #define hash_log_highlight_messages 4032101240U /* "log-highlight-messages" */
178 #define hash_log_max_lines 2868344173U /* "log-max-lines" */
179 #define hash_log_messages 2291744899U /* "log-messages" */
180 #define hash_show_on_task_bar 215410365U /* "show-on-task-bar" */
183 static void savearg(char *command, char *argument, struct configuration_spec * config);
184 #ifdef FEATURE_CLIENT_TAGS
185 static void free_client_specific_tags(struct client_tag_spec *tag_list);
188 /*********************************************************************
190 * Function : unload_configfile
192 * Description : Free the config structure and all components.
195 * 1 : data: struct configuration_spec to unload
199 *********************************************************************/
200 static void unload_configfile (void * data)
202 struct configuration_spec * config = (struct configuration_spec *)data;
203 struct forward_spec *cur_fwd = config->forward;
207 struct access_control_list *cur_acl = config->acl;
209 while (cur_acl != NULL)
211 struct access_control_list * next_acl = cur_acl->next;
216 #endif /* def FEATURE_ACL */
218 while (cur_fwd != NULL)
220 struct forward_spec * next_fwd = cur_fwd->next;
221 free_pattern_spec(cur_fwd->url);
223 freez(cur_fwd->gateway_host);
224 freez(cur_fwd->forward_host);
228 config->forward = NULL;
230 freez(config->confdir);
231 freez(config->logdir);
232 freez(config->templdir);
233 freez(config->hostname);
234 #ifdef FEATURE_EXTERNAL_FILTERS
235 freez(config->temporary_directory);
238 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
240 freez(config->haddr[i]);
242 freez(config->logfile);
244 for (i = 0; i < MAX_AF_FILES; i++)
246 freez(config->actions_file_short[i]);
247 freez(config->actions_file[i]);
248 freez(config->re_filterfile_short[i]);
249 freez(config->re_filterfile[i]);
252 list_remove_all(config->ordered_client_headers);
254 freez(config->admin_address);
255 freez(config->proxy_info_url);
256 freez(config->proxy_args);
257 freez(config->usermanual);
260 freez(config->trustfile);
261 list_remove_all(config->trust_info);
262 #endif /* def FEATURE_TRUST */
264 #ifdef FEATURE_CLIENT_TAGS
265 free_client_specific_tags(config->client_tags);
272 #ifdef FEATURE_GRACEFUL_TERMINATION
273 /*********************************************************************
275 * Function : unload_current_config_file
277 * Description : Unloads current config file - reset to state at
278 * beginning of program.
284 *********************************************************************/
285 void unload_current_config_file(void)
287 if (current_configfile)
289 current_configfile->unloader = unload_configfile;
290 current_configfile = NULL;
296 #ifdef FEATURE_CLIENT_TAGS
297 /*********************************************************************
299 * Function : register_tag
301 * Description : Registers a client-specific-tag and its description
304 * 1 : config: The tag list
305 * 2 : name: The name of the client-specific-tag
306 * 3 : description: The human-readable description for the tag
310 *********************************************************************/
311 static void register_tag(struct client_tag_spec *tag_list,
312 const char *name, const char *description)
314 struct client_tag_spec *new_tag;
315 struct client_tag_spec *last_tag;
318 while (last_tag->next != NULL)
320 last_tag = last_tag->next;
322 if (last_tag->name == NULL)
329 new_tag = zalloc_or_die(sizeof(struct client_tag_spec));
331 new_tag->name = strdup_or_die(name);
332 new_tag->description = strdup_or_die(description);
333 if (new_tag != last_tag)
335 last_tag->next = new_tag;
340 /*********************************************************************
342 * Function : free_client_specific_tags
344 * Description : Frees client-specific tags and their descriptions
347 * 1 : tag_list: The tag list to free
351 *********************************************************************/
352 static void free_client_specific_tags(struct client_tag_spec *tag_list)
354 struct client_tag_spec *this_tag;
355 struct client_tag_spec *next_tag;
361 next_tag = next_tag->next;
363 freez(this_tag->name);
364 freez(this_tag->description);
366 if (this_tag != tag_list)
370 } while (next_tag != NULL);
372 #endif /* def FEATURE_CLIENT_TAGS */
375 /*********************************************************************
377 * Function : parse_numeric_value
379 * Description : Parse the value of a directive that can only have
380 * a single numeric value. Terminates with a fatal error
381 * if the value is NULL or not numeric.
384 * 1 : name: The name of the directive. Used for log messages.
385 * 2 : value: The value to parse
388 * Returns : The numerical value as integer
390 *********************************************************************/
391 static int parse_numeric_value(const char *name, const char *value)
396 assert(name != NULL);
397 assert(value != NULL);
399 if ((value == NULL) || (*value == '\0'))
401 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
404 number = (int)strtol(value, &endptr, 0);
407 log_error(LOG_LEVEL_FATAL,
408 "Directive '%s' used with non-numerical value: '%s'", name, value);
416 /*********************************************************************
418 * Function : parse_toggle_value
420 * Description : Parse the value of a directive that can only be
421 * enabled or disabled. Terminates with a fatal error
422 * if the value is NULL or something other than 0 or 1.
425 * 1 : name: The name of the directive. Used for log messages.
426 * 2 : value: The value to parse
429 * Returns : The numerical toggle state
431 *********************************************************************/
432 static int parse_toggle_state(const char *name, const char *value)
435 assert(name != NULL);
436 assert(value != NULL);
438 if ((value == NULL) || (*value == '\0'))
440 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
443 toggle_state = atoi(value);
446 * Also check the length as atoi() doesn't mind
447 * garbage after a valid integer, but we do.
449 if (((toggle_state != 0) && (toggle_state != 1)) || (strlen(value) != 1))
451 log_error(LOG_LEVEL_FATAL,
452 "Directive %s used with invalid argument '%s'. Use either '0' or '1'.",
461 /*********************************************************************
463 * Function : parse_client_header_order
465 * Description : Parse the value of the header-order directive
468 * 1 : ordered_header_list: List to insert the ordered
470 * 2 : ordered_headers: The ordered header names separated
476 *********************************************************************/
477 static void parse_client_header_order(struct list *ordered_header_list, const char *ordered_headers)
479 char *original_headers_copy;
482 int number_of_headers;
485 assert(ordered_header_list != NULL);
486 assert(ordered_headers != NULL);
488 if (ordered_headers == NULL)
490 log_error(LOG_LEVEL_FATAL, "header-order used without argument");
494 * XXX: This estimate is guaranteed to be high enough as we
495 * let ssplit() ignore empty fields, but also a bit wasteful.
496 * The same hack is used in get_last_url() so it looks like
497 * a real solution is needed.
499 max_segments = strlen(ordered_headers) / 2;
500 if (max_segments == 0)
504 vector = malloc_or_die(max_segments * sizeof(char *));
506 original_headers_copy = strdup_or_die(ordered_headers);
508 number_of_headers = ssplit(original_headers_copy, "\t ", vector, max_segments);
509 if (number_of_headers == -1)
511 log_error(LOG_LEVEL_FATAL, "Failed to split ordered headers");
514 for (i = 0; i < number_of_headers; i++)
516 if (JB_ERR_OK != enlist(ordered_header_list, vector[i]))
518 log_error(LOG_LEVEL_FATAL,
519 "Failed to enlist ordered header: %s", vector[i]);
524 freez(original_headers_copy);
531 /*********************************************************************
533 * Function : load_config
535 * Description : Load the config file and all parameters.
537 * XXX: more than thousand lines long
538 * and thus in serious need of refactoring.
542 * Returns : The configuration_spec, or NULL on error.
544 *********************************************************************/
545 struct configuration_spec * load_config(void)
549 FILE *configfp = NULL;
550 struct configuration_spec * config = NULL;
551 struct client_state * fake_csp;
552 struct file_list *fs;
553 unsigned long linenum = 0;
555 char *logfile = NULL;
557 if (!check_file_changed(current_configfile, configfile, &fs))
559 /* No need to load */
560 return ((struct configuration_spec *)current_configfile->f);
564 log_error(LOG_LEVEL_FATAL,
565 "can't check configuration file '%s': %E", configfile);
569 if (NULL != current_configfile)
571 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
574 #ifdef FEATURE_TOGGLE
575 global_toggle_state = 1;
576 #endif /* def FEATURE_TOGGLE */
578 fs->f = config = zalloc_or_die(sizeof(*config));
581 * This is backwards from how it's usually done.
582 * Following the usual pattern, "fs" would be stored in a member
583 * variable in "csp", and then we'd access "config" from "fs->f",
584 * using a cast. However, "config" is used so often that a
585 * cast each time would be very ugly, and the extra indirection
586 * would waste CPU cycles. Therefore we store "config" in
587 * "csp->config", and "fs" in "csp->config->config_file_list".
589 config->config_file_list = fs;
594 config->multi_threaded = 1;
595 config->buffer_limit = 4096 * 1024;
596 config->usermanual = strdup(USER_MANUAL_URL);
597 config->proxy_args = strdup("");
598 config->forwarded_connect_retries = 0;
599 #ifdef FEATURE_CLIENT_TAGS
600 config->client_tag_lifetime = 60;
603 * 128 client sockets ought to be enough for everybody who can't
604 * be bothered to read the documentation to figure out how to
605 * increase the limit.
607 config->max_client_connections = 128;
608 config->socket_timeout = 300; /* XXX: Should be a macro. */
609 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
610 config->default_server_timeout = 0;
611 config->keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
612 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
613 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
615 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
616 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
617 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
618 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
619 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
620 #ifdef FEATURE_COMPRESSION
621 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
623 * XXX: Run some benchmarks to see if there are better default values.
625 config->compression_level = 1;
627 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
629 configfp = fopen(configfile, "r");
630 if (NULL == configfp)
632 log_error(LOG_LEVEL_FATAL,
633 "can't open configuration file '%s': %E", configfile);
634 /* Never get here - LOG_LEVEL_FATAL causes program exit */
637 while (read_config_line(configfp, &linenum, &buf) != NULL)
639 char cmd[BUFFER_SIZE];
640 char arg[BUFFER_SIZE];
641 char tmp[BUFFER_SIZE];
643 struct access_control_list *cur_acl;
644 #endif /* def FEATURE_ACL */
645 struct forward_spec *cur_fwd;
648 unsigned int directive_hash;
650 strlcpy(tmp, buf, sizeof(tmp));
652 /* Copy command (i.e. up to space or tab) into cmd */
655 while (*p && (*p != ' ') && (*p != '\t'))
661 /* Skip over the whitespace in buf */
662 while (*p && ((*p == ' ') || (*p == '\t')))
667 /* Copy the argument into arg */
668 if (strlcpy(arg, p, sizeof(arg)) >= sizeof(arg))
670 log_error(LOG_LEVEL_FATAL, "Config line too long: %s", buf);
673 /* Should never happen, but check this anyway */
680 /* Make sure the command field is lower case */
681 for (p = cmd; *p; p++)
683 if (privoxy_isupper(*p))
685 *p = (char)privoxy_tolower(*p);
689 directive_hash = hash_string(cmd);
690 switch (directive_hash)
692 /* *************************************************************************
693 * actionsfile actions-file-name
694 * In confdir by default
695 * *************************************************************************/
696 case hash_actions_file :
698 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
703 if (i >= MAX_AF_FILES)
705 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
706 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
709 config->actions_file_short[i] = strdup(arg);
710 config->actions_file[i] = make_path(config->confdir, arg);
713 /* *************************************************************************
714 * accept-intercepted-requests
715 * *************************************************************************/
716 case hash_accept_intercepted_requests:
717 if (parse_toggle_state(cmd, arg) == 1)
719 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
723 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
727 /* *************************************************************************
728 * admin-address email-address
729 * *************************************************************************/
730 case hash_admin_address :
731 freez(config->admin_address);
732 config->admin_address = strdup(arg);
735 /* *************************************************************************
736 * allow-cgi-request-crunching
737 * *************************************************************************/
738 case hash_allow_cgi_request_crunching:
739 if (parse_toggle_state(cmd, arg) == 1)
741 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
745 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
749 /* *************************************************************************
751 * *************************************************************************/
752 case hash_buffer_limit :
753 config->buffer_limit = (size_t)(1024 * parse_numeric_value(cmd, arg));
756 /* *************************************************************************
757 * client-header-order header-1 header-2 ... header-n
758 * *************************************************************************/
759 case hash_client_header_order:
760 list_remove_all(config->ordered_client_headers);
761 parse_client_header_order(config->ordered_client_headers, arg);
764 /* *************************************************************************
765 * client-specific-tag tag-name description
766 * *************************************************************************/
767 #ifdef FEATURE_CLIENT_TAGS
768 case hash_client_specific_tag:
774 description = strstr(arg, " ");
775 if (description == NULL)
777 log_error(LOG_LEVEL_FATAL,
778 "client-specific-tag '%s' lacks a description.", name);
782 * The length is limited because we don't want truncated
783 * HTML caused by the cgi interface using static buffer
786 if (strlen(name) > CLIENT_TAG_LENGTH_MAX)
788 log_error(LOG_LEVEL_FATAL,
789 "client-specific-tag '%s' is longer than %d characters.",
790 name, CLIENT_TAG_LENGTH_MAX);
793 register_tag(config->client_tags, name, description);
796 #endif /* def FEATURE_CLIENT_TAGS */
798 /* *************************************************************************
799 * client-tag-lifetime ttl
800 * *************************************************************************/
801 #ifdef FEATURE_CLIENT_TAGS
802 case hash_client_tag_lifetime:
804 int ttl = parse_numeric_value(cmd, arg);
807 config->client_tag_lifetime = (unsigned)ttl;
811 log_error(LOG_LEVEL_FATAL,
812 "client-tag-lifetime can't be negative.");
816 #endif /* def FEATURE_CLIENT_TAGS */
818 /* *************************************************************************
819 * confdir directory-name
820 * *************************************************************************/
822 freez(config->confdir);
823 config->confdir = make_path(NULL, arg);
826 /* *************************************************************************
827 * compression-level 0-9
828 * *************************************************************************/
829 #ifdef FEATURE_COMPRESSION
830 case hash_compression_level :
832 int compression_level = parse_numeric_value(cmd, arg);
833 if (-1 <= compression_level && compression_level <= 9)
835 config->compression_level = compression_level;
839 log_error(LOG_LEVEL_FATAL,
840 "Invalid compression-level value: %s", arg);
846 /* *************************************************************************
847 * connection-sharing (0|1)
848 * *************************************************************************/
849 #ifdef FEATURE_CONNECTION_SHARING
850 case hash_connection_sharing :
851 if (parse_toggle_state(cmd, arg) == 1)
853 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_SHARING;
857 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
862 /* *************************************************************************
864 * Specifies debug level, multiple values are ORed together.
865 * *************************************************************************/
867 config->debug |= parse_numeric_value(cmd, arg);
870 /* *************************************************************************
871 * default-server-timeout timeout
872 * *************************************************************************/
873 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
874 case hash_default_server_timeout :
876 int timeout = parse_numeric_value(cmd, arg);
879 config->default_server_timeout = (unsigned int)timeout;
883 log_error(LOG_LEVEL_FATAL,
884 "Invalid default-server-timeout value: %s", arg);
890 /* *************************************************************************
891 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
892 * *************************************************************************/
894 case hash_deny_access:
895 strlcpy(tmp, arg, sizeof(tmp));
896 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
898 if ((vec_count != 1) && (vec_count != 2))
900 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
901 "deny-access directive in configuration file.");
902 string_append(&config->proxy_args,
903 "<br>\nWARNING: Wrong number of parameters for "
904 "deny-access directive in configuration file.<br><br>\n");
908 /* allocate a new node */
909 cur_acl = zalloc_or_die(sizeof(*cur_acl));
910 cur_acl->action = ACL_DENY;
912 if (acl_addr(vec[0], cur_acl->src) < 0)
914 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
915 "for deny-access directive in configuration file: \"%s\"", vec[0]);
916 string_append(&config->proxy_args,
917 "<br>\nWARNING: Invalid source address, port or netmask "
918 "for deny-access directive in configuration file: \"");
919 string_append(&config->proxy_args,
921 string_append(&config->proxy_args,
928 if (acl_addr(vec[1], cur_acl->dst) < 0)
930 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
931 "for deny-access directive in configuration file: \"%s\"", vec[1]);
932 string_append(&config->proxy_args,
933 "<br>\nWARNING: Invalid destination address, port or netmask "
934 "for deny-access directive in configuration file: \"");
935 string_append(&config->proxy_args,
937 string_append(&config->proxy_args,
946 cur_acl->wildcard_dst = 1;
948 #endif /* def HAVE_RFC2553 */
951 * Add it to the list. Note we reverse the list to get the
952 * behaviour the user expects. With both the ACL and
953 * actions file, the last match wins. However, the internal
954 * implementations are different: The actions file is stored
955 * in the same order as the file, and scanned completely.
956 * With the ACL, we reverse the order as we load it, then
957 * when we scan it we stop as soon as we get a match.
959 cur_acl->next = config->acl;
960 config->acl = cur_acl;
963 #endif /* def FEATURE_ACL */
965 /* *************************************************************************
966 * enable-edit-actions 0|1
967 * *************************************************************************/
968 #ifdef FEATURE_CGI_EDIT_ACTIONS
969 case hash_enable_edit_actions:
970 if (parse_toggle_state(cmd, arg) == 1)
972 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
976 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
979 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
981 /* *************************************************************************
982 * enable-compression 0|1
983 * *************************************************************************/
984 #ifdef FEATURE_COMPRESSION
985 case hash_enable_compression:
986 if (parse_toggle_state(cmd, arg) == 1)
988 config->feature_flags |= RUNTIME_FEATURE_COMPRESSION;
992 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
995 #endif /* def FEATURE_COMPRESSION */
997 /* *************************************************************************
998 * enable-proxy-authentication-forwarding 0|1
999 * *************************************************************************/
1000 case hash_enable_proxy_authentication_forwarding:
1001 if (parse_toggle_state(cmd, arg) == 1)
1003 config->feature_flags |= RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1007 config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1011 /* *************************************************************************
1012 * enable-remote-toggle 0|1
1013 * *************************************************************************/
1014 #ifdef FEATURE_TOGGLE
1015 case hash_enable_remote_toggle:
1016 if (parse_toggle_state(cmd, arg) == 1)
1018 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1022 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1025 #endif /* def FEATURE_TOGGLE */
1027 /* *************************************************************************
1028 * enable-remote-http-toggle 0|1
1029 * *************************************************************************/
1030 case hash_enable_remote_http_toggle:
1031 if (parse_toggle_state(cmd, arg) == 1)
1033 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1037 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1041 /* *************************************************************************
1042 * enforce-blocks 0|1
1043 * *************************************************************************/
1044 case hash_enforce_blocks:
1045 #ifdef FEATURE_FORCE_LOAD
1046 if (parse_toggle_state(cmd, arg) == 1)
1048 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1052 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1055 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1056 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1057 #endif /* def FEATURE_FORCE_LOAD */
1060 /* *************************************************************************
1061 * filterfile file-name
1062 * In confdir by default.
1063 * *************************************************************************/
1064 case hash_filterfile :
1066 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1071 if (i >= MAX_AF_FILES)
1073 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1074 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1077 config->re_filterfile_short[i] = strdup(arg);
1078 config->re_filterfile[i] = make_path(config->confdir, arg);
1082 /* *************************************************************************
1083 * forward url-pattern (.|http-proxy-host[:port])
1084 * *************************************************************************/
1086 strlcpy(tmp, arg, sizeof(tmp));
1087 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1091 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1092 "directive in configuration file.");
1093 string_append(&config->proxy_args,
1094 "<br>\nWARNING: Wrong number of parameters for "
1095 "forward directive in configuration file.");
1099 /* allocate a new node */
1100 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1101 cur_fwd->type = SOCKS_NONE;
1103 /* Save the URL pattern */
1104 if (create_pattern_spec(cur_fwd->url, vec[0]))
1106 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1107 "directive in configuration file.");
1108 string_append(&config->proxy_args,
1109 "<br>\nWARNING: Bad URL specifier for "
1110 "forward directive in configuration file.");
1115 /* Parse the parent HTTP proxy host:port */
1118 if (strcmp(p, ".") != 0)
1120 cur_fwd->forward_port = 8000;
1121 parse_forwarder_address(p, &cur_fwd->forward_host,
1122 &cur_fwd->forward_port);
1126 cur_fwd->next = config->forward;
1127 config->forward = cur_fwd;
1131 /* *************************************************************************
1132 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1133 * *************************************************************************/
1134 case hash_forward_socks4:
1135 strlcpy(tmp, arg, sizeof(tmp));
1136 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1140 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1141 "forward-socks4 directive in configuration file.");
1142 string_append(&config->proxy_args,
1143 "<br>\nWARNING: Wrong number of parameters for "
1144 "forward-socks4 directive in configuration file.");
1148 /* allocate a new node */
1149 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1150 cur_fwd->type = SOCKS_4;
1152 /* Save the URL pattern */
1153 if (create_pattern_spec(cur_fwd->url, vec[0]))
1155 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1156 "directive in configuration file.");
1157 string_append(&config->proxy_args,
1158 "<br>\nWARNING: Bad URL specifier for "
1159 "forward-socks4 directive in configuration file.");
1164 /* Parse the SOCKS proxy host[:port] */
1167 /* XXX: This check looks like a bug. */
1168 if (strcmp(p, ".") != 0)
1170 cur_fwd->gateway_port = 1080;
1171 parse_forwarder_address(p, &cur_fwd->gateway_host,
1172 &cur_fwd->gateway_port);
1175 /* Parse the parent HTTP proxy host[:port] */
1178 if (strcmp(p, ".") != 0)
1180 cur_fwd->forward_port = 8000;
1181 parse_forwarder_address(p, &cur_fwd->forward_host,
1182 &cur_fwd->forward_port);
1186 cur_fwd->next = config->forward;
1187 config->forward = cur_fwd;
1191 /* *************************************************************************
1192 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1193 * *************************************************************************/
1194 case hash_forward_socks4a:
1195 case hash_forward_socks5:
1196 case hash_forward_socks5t:
1197 strlcpy(tmp, arg, sizeof(tmp));
1198 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1202 log_error(LOG_LEVEL_ERROR,
1203 "Wrong number of parameters for %s in configuration file.",
1205 string_append(&config->proxy_args,
1206 "<br>\nWARNING: Wrong number of parameters for ");
1207 string_append(&config->proxy_args, cmd);
1208 string_append(&config->proxy_args,
1209 "directive in configuration file.");
1213 /* allocate a new node */
1214 cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1216 if (directive_hash == hash_forward_socks4a)
1218 cur_fwd->type = SOCKS_4A;
1220 else if (directive_hash == hash_forward_socks5)
1222 cur_fwd->type = SOCKS_5;
1226 assert(directive_hash == hash_forward_socks5t);
1227 cur_fwd->type = SOCKS_5T;
1230 /* Save the URL pattern */
1231 if (create_pattern_spec(cur_fwd->url, vec[0]))
1233 log_error(LOG_LEVEL_ERROR,
1234 "Bad URL specifier for %s in configuration file.",
1236 string_append(&config->proxy_args,
1237 "<br>\nWARNING: Bad URL specifier for ");
1238 string_append(&config->proxy_args, cmd);
1239 string_append(&config->proxy_args,
1240 "directive in configuration file.");
1245 /* Parse the SOCKS proxy host[:port] */
1248 cur_fwd->gateway_port = 1080;
1249 parse_forwarder_address(p, &cur_fwd->gateway_host,
1250 &cur_fwd->gateway_port);
1252 /* Parse the parent HTTP proxy host[:port] */
1255 if (strcmp(p, ".") != 0)
1257 cur_fwd->forward_port = 8000;
1258 parse_forwarder_address(p, &cur_fwd->forward_host,
1259 &cur_fwd->forward_port);
1263 cur_fwd->next = config->forward;
1264 config->forward = cur_fwd;
1268 /* *************************************************************************
1269 * forwarded-connect-retries n
1270 * *************************************************************************/
1271 case hash_forwarded_connect_retries :
1272 config->forwarded_connect_retries = parse_numeric_value(cmd, arg);
1275 /* *************************************************************************
1276 * handle-as-empty-doc-returns-ok 0|1
1278 * Workaround for firefox hanging on blocked javascript pages.
1279 * Block with the "+handle-as-empty-document" flag and set the
1280 * "handle-as-empty-doc-returns-ok" run-time config flag so that
1281 * Privoxy returns a 200/OK status instead of a 403/Forbidden status
1282 * to the browser for blocked pages.
1283 ***************************************************************************/
1284 case hash_handle_as_empty_returns_ok:
1285 if (parse_toggle_state(cmd, arg) == 1)
1287 config->feature_flags |= RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1291 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1295 /* *************************************************************************
1296 * hostname hostname-to-show-on-cgi-pages
1297 * *************************************************************************/
1298 case hash_hostname :
1299 freez(config->hostname);
1300 config->hostname = strdup(arg);
1301 if (NULL == config->hostname)
1303 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1307 /* *************************************************************************
1308 * keep-alive-timeout timeout
1309 * *************************************************************************/
1310 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1311 case hash_keep_alive_timeout :
1313 int timeout = parse_numeric_value(cmd, arg);
1316 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1317 config->keep_alive_timeout = (unsigned int)timeout;
1321 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1327 /* *************************************************************************
1328 * listen-address [ip][:port]
1329 * *************************************************************************/
1330 case hash_listen_address :
1332 while ((i < MAX_LISTENING_SOCKETS) && (NULL != config->haddr[i]))
1337 if (i >= MAX_LISTENING_SOCKETS)
1339 log_error(LOG_LEVEL_FATAL, "Too many 'listen-address' directives in config file - limit is %d.\n"
1340 "(You can increase this limit by changing MAX_LISTENING_SOCKETS in project.h and recompiling).",
1341 MAX_LISTENING_SOCKETS);
1343 config->haddr[i] = strdup(arg);
1344 if (NULL == config->haddr[i])
1346 log_error(LOG_LEVEL_FATAL, "Out of memory while copying listening address");
1350 /* *************************************************************************
1351 * logdir directory-name
1352 * *************************************************************************/
1354 freez(config->logdir);
1355 config->logdir = make_path(NULL, arg);
1358 /* *************************************************************************
1359 * logfile log-file-name
1360 * In logdir by default
1361 * *************************************************************************/
1365 logfile = make_path(config->logdir, arg);
1366 if (NULL == logfile)
1368 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1373 /* *************************************************************************
1374 * max-client-connections number
1375 * *************************************************************************/
1376 case hash_max_client_connections :
1378 int max_client_connections = parse_numeric_value(cmd, arg);
1379 if (0 <= max_client_connections)
1381 /* XXX: log error */
1382 config->max_client_connections = max_client_connections;
1387 /* *************************************************************************
1388 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1389 * *************************************************************************/
1391 case hash_permit_access:
1392 strlcpy(tmp, arg, sizeof(tmp));
1393 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1395 if ((vec_count != 1) && (vec_count != 2))
1397 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1398 "permit-access directive in configuration file.");
1399 string_append(&config->proxy_args,
1400 "<br>\nWARNING: Wrong number of parameters for "
1401 "permit-access directive in configuration file.<br><br>\n");
1406 /* allocate a new node */
1407 cur_acl = zalloc_or_die(sizeof(*cur_acl));
1408 cur_acl->action = ACL_PERMIT;
1410 if (acl_addr(vec[0], cur_acl->src) < 0)
1412 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1413 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1414 string_append(&config->proxy_args,
1415 "<br>\nWARNING: Invalid source address, port or netmask for "
1416 "permit-access directive in configuration file: \"");
1417 string_append(&config->proxy_args,
1419 string_append(&config->proxy_args,
1426 if (acl_addr(vec[1], cur_acl->dst) < 0)
1428 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1429 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1430 string_append(&config->proxy_args,
1431 "<br>\nWARNING: Invalid destination address, port or netmask for "
1432 "permit-access directive in configuration file: \"");
1433 string_append(&config->proxy_args,
1435 string_append(&config->proxy_args,
1444 cur_acl->wildcard_dst = 1;
1446 #endif /* def HAVE_RFC2553 */
1449 * Add it to the list. Note we reverse the list to get the
1450 * behaviour the user expects. With both the ACL and
1451 * actions file, the last match wins. However, the internal
1452 * implementations are different: The actions file is stored
1453 * in the same order as the file, and scanned completely.
1454 * With the ACL, we reverse the order as we load it, then
1455 * when we scan it we stop as soon as we get a match.
1457 cur_acl->next = config->acl;
1458 config->acl = cur_acl;
1461 #endif /* def FEATURE_ACL */
1463 /* *************************************************************************
1464 * proxy-info-url url
1465 * *************************************************************************/
1466 case hash_proxy_info_url :
1467 freez(config->proxy_info_url);
1468 config->proxy_info_url = strdup(arg);
1471 /* *************************************************************************
1472 * single-threaded 0|1
1473 * *************************************************************************/
1474 case hash_single_threaded :
1475 config->multi_threaded = 0 == parse_toggle_state(cmd, arg);
1478 /* *************************************************************************
1479 * socket-timeout numer_of_seconds
1480 * *************************************************************************/
1481 case hash_socket_timeout :
1483 int socket_timeout = parse_numeric_value(cmd, arg);
1484 if (0 <= socket_timeout)
1486 config->socket_timeout = socket_timeout;
1490 log_error(LOG_LEVEL_FATAL, "Invalid socket-timeout: '%s'", arg);
1495 /* *************************************************************************
1496 * split-large-cgi-forms
1497 * *************************************************************************/
1498 case hash_split_large_cgi_forms :
1499 if (parse_toggle_state(cmd, arg) == 1)
1501 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1505 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1509 /* *************************************************************************
1510 * templdir directory-name
1511 * *************************************************************************/
1512 case hash_templdir :
1513 freez(config->templdir);
1514 config->templdir = make_path(NULL, arg);
1517 #ifdef FEATURE_EXTERNAL_FILTERS
1518 /* *************************************************************************
1519 * temporary-directory directory-name
1520 * *************************************************************************/
1521 case hash_temporary_directory :
1522 freez(config->temporary_directory);
1523 config->temporary_directory = make_path(NULL, arg);
1527 /* *************************************************************************
1528 * tolerate-pipelining (0|1)
1529 * *************************************************************************/
1530 case hash_tolerate_pipelining :
1531 if (parse_toggle_state(cmd, arg) == 1)
1533 config->feature_flags |= RUNTIME_FEATURE_TOLERATE_PIPELINING;
1537 config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
1541 /* *************************************************************************
1543 * *************************************************************************/
1544 #ifdef FEATURE_TOGGLE
1546 global_toggle_state = parse_toggle_state(cmd, arg);
1548 #endif /* def FEATURE_TOGGLE */
1550 /* *************************************************************************
1551 * trust-info-url url
1552 * *************************************************************************/
1553 #ifdef FEATURE_TRUST
1554 case hash_trust_info_url :
1555 enlist(config->trust_info, arg);
1557 #endif /* def FEATURE_TRUST */
1559 /* *************************************************************************
1560 * trustfile filename
1561 * (In confdir by default.)
1562 * *************************************************************************/
1563 #ifdef FEATURE_TRUST
1564 case hash_trustfile :
1565 freez(config->trustfile);
1566 config->trustfile = make_path(config->confdir, arg);
1568 #endif /* def FEATURE_TRUST */
1570 /* *************************************************************************
1572 * *************************************************************************/
1573 case hash_usermanual :
1575 * XXX: If this isn't the first config directive, the
1576 * show-status page links to the website documentation
1577 * for the directives that were already parsed. Lame.
1579 freez(config->usermanual);
1580 config->usermanual = strdup(arg);
1583 /* *************************************************************************
1584 * Win32 Console options:
1585 * *************************************************************************/
1587 /* *************************************************************************
1589 * *************************************************************************/
1591 case hash_hide_console :
1594 #endif /*def _WIN_CONSOLE*/
1597 /* *************************************************************************
1598 * Win32 GUI options:
1599 * *************************************************************************/
1601 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1602 /* *************************************************************************
1603 * activity-animation (0|1)
1604 * *************************************************************************/
1605 case hash_activity_animation :
1606 g_bShowActivityAnimation = parse_toggle_state(cmd, arg);
1609 /* *************************************************************************
1610 * close-button-minimizes (0|1)
1611 * *************************************************************************/
1612 case hash_close_button_minimizes :
1613 g_bCloseHidesWindow = parse_toggle_state(cmd, arg);
1616 /* *************************************************************************
1617 * log-buffer-size (0|1)
1618 * *************************************************************************/
1619 case hash_log_buffer_size :
1620 g_bLimitBufferSize = parse_toggle_state(cmd, arg);
1623 /* *************************************************************************
1624 * log-font-name fontname
1625 * *************************************************************************/
1626 case hash_log_font_name :
1627 if (strlcpy(g_szFontFaceName, arg,
1628 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1630 log_error(LOG_LEVEL_FATAL,
1631 "log-font-name argument '%s' is longer than %u characters.",
1632 arg, sizeof(g_szFontFaceName)-1);
1636 /* *************************************************************************
1638 * *************************************************************************/
1639 case hash_log_font_size :
1640 g_nFontSize = parse_numeric_value(cmd, arg);
1643 /* *************************************************************************
1644 * log-highlight-messages (0|1)
1645 * *************************************************************************/
1646 case hash_log_highlight_messages :
1647 g_bHighlightMessages = parse_toggle_state(cmd, arg);
1650 /* *************************************************************************
1652 * *************************************************************************/
1653 case hash_log_max_lines :
1654 g_nMaxBufferLines = parse_numeric_value(cmd, arg);
1657 /* *************************************************************************
1658 * log-messages (0|1)
1659 * *************************************************************************/
1660 case hash_log_messages :
1661 g_bLogMessages = parse_toggle_state(cmd, arg);
1664 /* *************************************************************************
1665 * show-on-task-bar (0|1)
1666 * *************************************************************************/
1667 case hash_show_on_task_bar :
1668 g_bShowOnTaskBar = parse_toggle_state(cmd, arg);
1671 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1674 /* *************************************************************************
1675 * Warnings about unsupported features
1676 * *************************************************************************/
1678 case hash_deny_access:
1679 #endif /* ndef FEATURE_ACL */
1680 #ifndef FEATURE_CGI_EDIT_ACTIONS
1681 case hash_enable_edit_actions:
1682 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1683 #ifndef FEATURE_TOGGLE
1684 case hash_enable_remote_toggle:
1685 #endif /* ndef FEATURE_TOGGLE */
1687 case hash_permit_access:
1688 #endif /* ndef FEATURE_ACL */
1689 #ifndef FEATURE_TOGGLE
1691 #endif /* ndef FEATURE_TOGGLE */
1692 #ifndef FEATURE_TRUST
1693 case hash_trustfile :
1694 case hash_trust_info_url :
1695 #endif /* ndef FEATURE_TRUST */
1697 #ifndef _WIN_CONSOLE
1698 case hash_hide_console :
1699 #endif /* ndef _WIN_CONSOLE */
1701 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1702 case hash_activity_animation :
1703 case hash_close_button_minimizes :
1704 case hash_log_buffer_size :
1705 case hash_log_font_name :
1706 case hash_log_font_size :
1707 case hash_log_highlight_messages :
1708 case hash_log_max_lines :
1709 case hash_log_messages :
1710 case hash_show_on_task_bar :
1711 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1712 /* These warnings are annoying - so hide them. -- Jon */
1713 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1716 /* *************************************************************************/
1718 /* *************************************************************************/
1720 * I decided that I liked this better as a warning than an
1721 * error. To change back to an error, just change log level
1722 * to LOG_LEVEL_FATAL.
1724 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive "
1725 "'%s' (%uU) in line %lu in configuration file (%s).",
1726 buf, directive_hash, linenum, configfile);
1727 string_append(&config->proxy_args,
1728 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1731 /* *************************************************************************/
1732 } /* end switch(hash_string(cmd)) */
1734 /* Save the argument for the show-status page. */
1735 savearg(cmd, arg, config);
1737 } /* end while (read_config_line(...)) */
1741 set_debug_level(config->debug);
1743 freez(config->logfile);
1747 if (NULL != logfile)
1749 config->logfile = logfile;
1750 init_error_log(Argv[0], config->logfile);
1758 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1759 if (config->default_server_timeout > config->keep_alive_timeout)
1761 log_error(LOG_LEVEL_ERROR,
1762 "Reducing the default-server-timeout from %d to the keep-alive-timeout %d.",
1763 config->default_server_timeout, config->keep_alive_timeout);
1764 config->default_server_timeout = config->keep_alive_timeout;
1766 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
1768 #ifdef FEATURE_CONNECTION_SHARING
1769 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1771 if (config->multi_threaded)
1773 set_keep_alive_timeout(config->keep_alive_timeout);
1778 * While we could use keep-alive without multiple threads
1779 * if we didn't bother with enforcing the connection timeout,
1780 * that might make Tor users sad, even though they shouldn't
1781 * enable the single-threaded option anyway.
1783 * XXX: We could still use Proxy-Connection: keep-alive.
1785 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1786 log_error(LOG_LEVEL_ERROR,
1787 "Config option single-threaded disables connection keep-alive.");
1790 else if ((config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING))
1792 log_error(LOG_LEVEL_ERROR, "Config option connection-sharing "
1793 "has no effect if keep-alive-timeout isn't set.");
1794 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
1796 #endif /* def FEATURE_CONNECTION_SHARING */
1798 if (NULL == config->proxy_args)
1800 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1803 if (config->re_filterfile[0])
1805 add_loader(load_re_filterfiles, config);
1808 if (config->actions_file[0])
1810 add_loader(load_action_files, config);
1813 #ifdef FEATURE_TRUST
1814 if (config->trustfile)
1816 add_loader(load_trustfile, config);
1818 #endif /* def FEATURE_TRUST */
1820 if (NULL == config->haddr[0])
1822 config->haddr[0] = strdup(HADDR_DEFAULT);
1823 if (NULL == config->haddr[0])
1825 log_error(LOG_LEVEL_FATAL, "Out of memory while copying default listening address");
1829 for (i = 0; i < MAX_LISTENING_SOCKETS && NULL != config->haddr[i]; i++)
1831 if ((*config->haddr[i] == '[')
1832 && (NULL != (p = strchr(config->haddr[i], ']')))
1834 && (0 < (config->hport[i] = atoi(p + 2))))
1837 memmove((void *)config->haddr[i], config->haddr[i] + 1,
1838 (size_t)(p - config->haddr[i]));
1840 else if (NULL != (p = strchr(config->haddr[i], ':'))
1841 && (0 < (config->hport[i] = atoi(p + 1))))
1847 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr[i]);
1848 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1850 if (*config->haddr[i] == '\0')
1853 * Only the port specified. We stored it in config->hport[i]
1854 * and don't need its text representation anymore.
1855 * Use config->hport[i] == 0 to iterate listening addresses since
1858 freez(config->haddr[i]);
1863 * Want to run all the loaders once now.
1865 * Need to set up a fake csp, so they can get to the config.
1867 fake_csp = zalloc_or_die(sizeof(*fake_csp));
1868 fake_csp->config = config;
1870 if (run_loader(fake_csp))
1873 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1874 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1878 /* FIXME: this is a kludge for win32 */
1879 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1881 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1882 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1883 g_default_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1884 g_user_filterfile = config->re_filterfile[1]; /* FIXME Hope this is user.filter */
1886 #ifdef FEATURE_TRUST
1887 g_trustfile = config->trustfile;
1888 #endif /* def FEATURE_TRUST */
1891 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1892 /* FIXME: end kludge */
1895 config->need_bind = 1;
1897 if (current_configfile)
1899 struct configuration_spec * oldcfg = (struct configuration_spec *)
1900 current_configfile->f;
1902 * Check if config->haddr[i],hport[i] == oldcfg->haddr[i],hport[i]
1904 * The following could be written more compactly as a single,
1905 * (unreadably long) if statement.
1907 config->need_bind = 0;
1909 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
1911 if (config->hport[i] != oldcfg->hport[i])
1913 config->need_bind = 1;
1915 else if (config->haddr[i] == NULL)
1917 if (oldcfg->haddr[i] != NULL)
1919 config->need_bind = 1;
1922 else if (oldcfg->haddr[i] == NULL)
1924 config->need_bind = 1;
1926 else if (0 != strcmp(config->haddr[i], oldcfg->haddr[i]))
1928 config->need_bind = 1;
1932 current_configfile->unloader = unload_configfile;
1935 fs->next = files->next;
1938 current_configfile = fs;
1944 /*********************************************************************
1946 * Function : savearg
1948 * Description : Called from `load_config'. It saves each non-empty
1949 * and non-comment line from config into
1950 * config->proxy_args. This is used to create the
1951 * show-proxy-args page. On error, frees
1952 * config->proxy_args and sets it to NULL
1955 * 1 : command = config setting that was found
1956 * 2 : argument = the setting's argument (if any)
1957 * 3 : config = Configuration to save into.
1961 *********************************************************************/
1962 static void savearg(char *command, char *argument, struct configuration_spec * config)
1971 * Add config option name embedded in
1972 * link to its section in the user-manual
1974 buf = strdup("\n<a href=\"");
1975 if (!strncmpic(config->usermanual, "file://", 7) ||
1976 !strncmpic(config->usermanual, "http", 4))
1978 string_append(&buf, config->usermanual);
1982 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1984 string_append(&buf, CONFIG_HELP_PREFIX);
1985 string_join (&buf, string_toupper(command));
1986 string_append(&buf, "\">");
1987 string_append(&buf, command);
1988 string_append(&buf, "</a> ");
1992 freez(config->proxy_args);
1996 if ((NULL != argument) && ('\0' != *argument))
1998 s = html_encode(argument);
2002 freez(config->proxy_args);
2006 if (strncmpic(argument, "http://", 7) == 0)
2008 string_append(&buf, "<a href=\"");
2009 string_append(&buf, s);
2010 string_append(&buf, "\">");
2011 string_join (&buf, s);
2012 string_append(&buf, "</a>");
2016 string_join (&buf, s);
2020 string_append(&buf, "<br>");
2021 string_join(&config->proxy_args, buf);