1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.67 2007/10/14 14:12:41 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-2007 the SourceForge
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.
38 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
39 * When in daemon mode, close stderr after the configuration file has been
40 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
42 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
43 * #1763173 from Stefan Huehner: declare unload_configfile() static.
45 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
46 * As Hal noticed, checking dispatch_cgi() as the last cruncher
47 * looks like a bug if CGI requests are blocked unintentionally,
48 * so don't do it unless the user enabled the new config option
49 * "allow-cgi-request-crunching".
51 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
52 * - Use strlcpy() instead of strcpy().
53 * - Stop treating actions files special. Expect a complete file name
54 * (with or without path) like it's done for the rest of the files.
56 * - Remove an unnecessary temporary memory allocation.
57 * - Don't log anything to the console when running as
58 * daemon and no errors occurred.
60 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
61 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
63 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
64 * New config option: enforce-blocks.
66 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
67 * - Mention other reasons why acl directive loading might have failed.
68 * - Don't log the acl source if the acl destination is to blame.
70 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
71 * Add new config option "templdir" to
72 * change the templates directory.
74 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
75 * Added config option accept-intercepted-requests
76 * and disabled it by default.
78 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
79 * Fix gcc43 compiler warnings.
81 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
82 * Add config option "split-large-forms"
83 * to work around the browser bug reported
86 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
87 * Move the <br> in the generated HTML for the config
88 * options from the beginning of the string to its end.
89 * Keeps the white space in balance.
91 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
92 * Fix memory leak in case of config file reloads.
94 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
95 * Modified kludge for win32 to make ming32 menu
96 * "Options/Edit Filters" (sort of) work again.
97 * Same limitations as for the action files apply.
100 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
101 * Incorporate modified version of Roland Rosenfeld's patch to
102 * optionally access the user-manual via Privoxy. Closes patch 679075.
104 * Formatting changed to Privoxy style, added call to
105 * cgi_error_no_template if the requested file doesn't
106 * exist and modified check whether or not Privoxy itself
107 * should serve the manual. Should work cross-platform now.
109 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
110 * Added config option enable-remote-http-toggle
111 * to specify if Privoxy should recognize special
112 * headers (currently only X-Filter) to change its
113 * behaviour. Disabled by default.
115 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
116 * Make number of retries in case of forwarded-connect problems
117 * a config file option (forwarded-connect-retries) and use 0 as
120 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
121 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
122 * with what was really the latest development (the v_3_0_branch branch)
124 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
125 * Don't forget to malloc space for the null terminator...
127 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
128 * Multiple filter file support
130 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
131 * Closed two memory leaks; hopefully the last remaining ones
132 * (in the main execution paths, anyway).
134 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
135 * Addressed bug #719435
136 * - Extraneous filterfile directives now logged as errors
137 * - This and unrecnonised directives now really obvious on status page
139 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
140 * Cosmetic: Renamed cryptic variable
142 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
143 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
145 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
146 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
148 * Revision 1.48 2002/05/14 21:30:38 oes
149 * savearg now uses own linking code instead of (now special-cased) add_help_link
151 * Revision 1.47 2002/05/12 21:36:29 jongfoster
152 * Correcting function comments
154 * Revision 1.46 2002/04/26 12:55:14 oes
155 * - New option "user-manual", defaults to our site
156 * via project.h #define
157 * - savearg now embeds option names in help links
159 * Revision 1.45 2002/04/24 02:11:54 oes
160 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
162 * Revision 1.44 2002/04/08 20:37:13 swa
165 * Revision 1.43 2002/04/08 20:36:50 swa
168 * Revision 1.42 2002/04/05 15:50:15 oes
169 * fix for invalid HTML proxy_args
171 * Revision 1.41 2002/03/31 17:19:00 jongfoster
172 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
174 * Revision 1.40 2002/03/26 22:29:55 swa
175 * we have a new homepage!
177 * Revision 1.39 2002/03/24 13:25:43 swa
178 * name change related issues
180 * Revision 1.38 2002/03/24 13:05:48 jongfoster
181 * Renaming re_filterfile to filterfile
183 * Revision 1.37 2002/03/16 23:54:06 jongfoster
184 * Adding graceful termination feature, to help look for memory leaks.
185 * If you enable this (which, by design, has to be done by hand
186 * editing config.h) and then go to http://i.j.b/die, then the program
187 * will exit cleanly after the *next* request. It should free all the
188 * memory that was used.
190 * Revision 1.36 2002/03/13 00:27:05 jongfoster
193 * Revision 1.35 2002/03/07 03:52:44 oes
194 * Set logging to tty for --no-daemon mode
196 * Revision 1.34 2002/03/06 23:14:35 jongfoster
197 * Trivial cosmetic changes to make function comments easier to find.
199 * Revision 1.33 2002/03/05 04:52:42 oes
200 * Deleted non-errlog debugging code
202 * Revision 1.32 2002/03/04 18:24:53 oes
203 * Re-enabled output of unknown config directive hash
205 * Revision 1.31 2002/03/03 15:07:20 oes
206 * Re-enabled automatic config reloading
208 * Revision 1.30 2002/01/22 23:31:43 jongfoster
209 * Replacing strsav() with string_append()
211 * Revision 1.29 2002/01/17 21:02:30 jongfoster
212 * Moving all our URL and URL pattern parsing code to urlmatch.c.
214 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
216 * Revision 1.28 2001/12/30 14:07:32 steudten
217 * - Add signal handling (unix)
218 * - Add SIGHUP handler (unix)
219 * - Add creation of pidfile (unix)
220 * - Add action 'top' in rc file (RH)
221 * - Add entry 'SIGNALS' to manpage
222 * - Add exit message to logfile (unix)
224 * Revision 1.27 2001/11/07 00:02:13 steudten
225 * Add line number in error output for lineparsing for
226 * actionsfile and configfile.
227 * Special handling for CLF added.
229 * Revision 1.26 2001/11/05 21:41:43 steudten
230 * Add changes to be a real daemon just for unix os.
231 * (change cwd to /, detach from controlling tty, set
232 * process group and session leader to the own process.
234 * Add some fatal-error log message for failed malloc().
235 * Add '-d' if compiled with 'configure --with-debug' to
236 * enable debug output.
238 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
239 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
240 * threads to call select() simultaneously. So, it's time to do a real, live,
241 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
242 * (native). Both versions will work, but using __OS2__ offers multi-threading.
244 * Revision 1.24 2001/10/23 21:40:30 jongfoster
245 * Added support for enable-edit-actions and enable-remote-toggle config
248 * Revision 1.23 2001/10/07 15:36:00 oes
249 * Introduced new config option "buffer-limit"
251 * Revision 1.22 2001/09/22 16:36:59 jongfoster
252 * Removing unused parameter fs from read_config_line()
254 * Revision 1.21 2001/09/16 17:10:43 jongfoster
255 * Moving function savearg() here, since it was the only thing left in
258 * Revision 1.20 2001/07/30 22:08:36 jongfoster
259 * Tidying up #defines:
260 * - All feature #defines are now of the form FEATURE_xxx
261 * - Permanently turned off WIN_GUI_EDIT
262 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
264 * Revision 1.19 2001/07/15 17:45:16 jongfoster
265 * Removing some unused #includes
267 * Revision 1.18 2001/07/13 14:01:14 oes
268 * - Removed all #ifdef PCRS
269 * - Removed vim-settings
271 * Revision 1.17 2001/06/29 13:31:03 oes
272 * - Improved comments
273 * - Fixed (actionsfile) and sorted hashes
274 * - Introduced admin_address and proxy-info-url
275 * as config parameters
276 * - Renamed config->proxy_args_invocation (which didn't have
277 * the invocation but the options!) to config->proxy_args
278 * - Various adaptions
279 * - Removed logentry from cancelled commit
281 * Revision 1.16 2001/06/09 10:55:28 jongfoster
282 * Changing BUFSIZ ==> BUFFER_SIZE
284 * Revision 1.15 2001/06/07 23:13:40 jongfoster
285 * Merging ACL and forward files into config file.
286 * Cosmetic: Sorting config file options alphabetically.
287 * Cosmetic: Adding brief syntax comments to config file options.
289 * Revision 1.14 2001/06/07 14:46:25 joergs
290 * Missing make_path() added for re_filterfile.
292 * Revision 1.13 2001/06/05 22:33:54 jongfoster
294 * Fixed minor memory leak.
295 * Also now uses make_path to prepend the pathnames.
297 * Revision 1.12 2001/06/05 20:04:09 jongfoster
298 * Now uses _snprintf() in place of snprintf() under Win32.
300 * Revision 1.11 2001/06/04 18:31:58 swa
301 * files are now prefixed with either `confdir' or `logdir'.
302 * `make redhat-dist' replaces both entries confdir and logdir
305 * Revision 1.10 2001/06/03 19:11:54 oes
306 * introduced confdir option
308 * Revision 1.9 2001/06/01 20:06:24 jongfoster
309 * Removed support for "tinygif" option - moved to actions file.
311 * Revision 1.8 2001/05/31 21:27:13 jongfoster
312 * Removed many options from the config file and into the
313 * "actions" file: add_forwarded, suppress_vanilla_wafer,
314 * wafer, add_header, user_agent, referer, from
315 * Also globally replaced "permission" with "action".
317 * Revision 1.7 2001/05/29 09:50:24 jongfoster
318 * Unified blocklist/imagelist/permissionslist.
319 * File format is still under discussion, but the internal changes
322 * Also modified interceptor behaviour:
323 * - We now intercept all URLs beginning with one of the following
324 * prefixes (and *only* these prefixes):
326 * * http://ijbswa.sf.net/config/
327 * * http://ijbswa.sourceforge.net/config/
328 * - New interceptors "home page" - go to http://i.j.b/ to see it.
329 * - Internal changes so that intercepted and fast redirect pages
330 * are not replaced with an image.
331 * - Interceptors now have the option to send a binary page direct
332 * to the client. (i.e. ijb-send-banner uses this)
333 * - Implemented show-url-info interceptor. (Which is why I needed
334 * the above interceptors changes - a typical URL is
335 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
336 * The previous mechanism would not have intercepted that, and
337 * if it had been intercepted then it then it would have replaced
340 * Revision 1.6 2001/05/26 00:28:36 jongfoster
341 * Automatic reloading of config file.
342 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
343 * Most of the global variables have been moved to a new
344 * struct configuration_spec, accessed through csp->config->globalname
345 * Most of the globals remaining are used by the Win32 GUI.
347 * Revision 1.5 2001/05/25 22:34:30 jongfoster
350 * Revision 1.4 2001/05/22 18:46:04 oes
352 * - Enabled filtering banners by size rather than URL
353 * by adding patterns that replace all standard banner
354 * sizes with the "Junkbuster" gif to the re_filterfile
356 * - Enabled filtering WebBugs by providing a pattern
357 * which kills all 1x1 images
359 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
360 * which is selected by the (nonstandard and therefore
361 * capital) letter 'U' in the option string.
362 * It causes the quantifiers to be ungreedy by default.
363 * Appending a ? turns back to greedy (!).
365 * - Added a new interceptor ijb-send-banner, which
366 * sends back the "Junkbuster" gif. Without imagelist or
367 * MSIE detection support, or if tinygif = 1, or the
368 * URL isn't recognized as an imageurl, a lame HTML
369 * explanation is sent instead.
371 * - Added new feature, which permits blocking remote
372 * script redirects and firing back a local redirect
374 * The feature is conditionally compiled, i.e. it
375 * can be disabled with --disable-fast-redirects,
376 * plus it must be activated by a "fast-redirects"
377 * line in the config file, has its own log level
378 * and of course wants to be displayed by show-proxy-args
379 * Note: Boy, all the #ifdefs in 1001 locations and
380 * all the fumbling with configure.in and acconfig.h
381 * were *way* more work than the feature itself :-(
383 * - Because a generic redirect template was needed for
384 * this, tinygif = 3 now uses the same.
386 * - Moved GIFs, and other static HTTP response templates
391 * - Removed some >400 CRs again (Jon, you really worked
394 * Revision 1.3 2001/05/20 01:21:20 jongfoster
395 * Version 2.9.4 checkin.
396 * - Merged popupfile and cookiefile, and added control over PCRS
397 * filtering, in new "permissionsfile".
398 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
399 * file error you now get a message box (in the Win32 GUI) rather
400 * than the program exiting with no explanation.
401 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
403 * - Removed tabs from "config"
404 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
405 * - Bumped up version number.
407 * Revision 1.2 2001/05/17 23:01:01 oes
408 * - Cleaned CRLF's from the sources and related files
410 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
411 * Initial import of version 2.9.3 source tree
414 *********************************************************************/
420 #include <sys/types.h>
434 # include <windows.h>
437 # ifndef _WIN_CONSOLE
439 # endif /* ndef _WIN_CONSOLE */
441 #else /* ifndef _WIN32 */
445 # include <sys/wait.h>
447 # include <sys/time.h>
448 # include <sys/stat.h>
458 #include "miscutil.h"
462 #include "urlmatch.h"
465 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
468 * Fix a problem with Solaris. There should be no effect on other
470 * Solaris's isspace() is a macro which uses it's argument directly
471 * as an array index. Therefore we need to make sure that high-bit
472 * characters generate +ve values, and ideally we also want to make
473 * the argument match the declared parameter type of "int".
475 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
476 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
478 #ifdef FEATURE_TOGGLE
479 /* Privoxy is enabled by default. */
480 int global_toggle_state = 1;
481 #endif /* def FEATURE_TOGGLE */
483 /* The filename of the configfile */
484 const char *configfile = NULL;
487 * CGI functions will later need access to the invocation args,
488 * so we will make argc and argv global.
491 const char **Argv = NULL;
493 static struct file_list *current_configfile = NULL;
497 * This takes the "cryptic" hash of each keyword and aliases them to
498 * something a little more readable. This also makes changing the
499 * hash values easier if they should change or the hash algorthm changes.
500 * Use the included "hash" program to find out what the hash will be
501 * for any string supplied on the command line. (Or just put it in the
502 * config file and read the number from the error message in the log).
504 * Please keep this list sorted alphabetically (but with the Windows
505 * console and GUI specific options last).
508 #define hash_actions_file 1196306641ul /* "actionsfile" */
509 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
510 #define hash_admin_address 4112573064ul /* "admin-address" */
511 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
512 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
513 #define hash_confdir 1978389ul /* "confdir" */
514 #define hash_debug 78263ul /* "debug" */
515 #define hash_deny_access 1227333715ul /* "deny-access" */
516 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
517 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
518 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
519 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
520 #define hash_filterfile 250887266ul /* "filterfile" */
521 #define hash_forward 2029845ul /* "forward" */
522 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
523 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
524 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
525 #define hash_jarfile 2046641ul /* "jarfile" */
526 #define hash_listen_address 1255650842ul /* "listen-address" */
527 #define hash_logdir 422889ul /* "logdir" */
528 #define hash_logfile 2114766ul /* "logfile" */
529 #define hash_permit_access 3587953268ul /* "permit-access" */
530 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
531 #define hash_single_threaded 4250084780ul /* "single-threaded" */
532 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
533 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
534 #define hash_templdir 11067889ul /* "templdir" */
535 #define hash_toggle 447966ul /* "toggle" */
536 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
537 #define hash_trustfile 56494766ul /* "trustfile" */
538 #define hash_usermanual 1416668518ul /* "user-manual" */
539 #define hash_activity_animation 1817904738ul /* "activity-animation" */
540 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
541 #define hash_hide_console 2048809870ul /* "hide-console" */
542 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
543 #define hash_log_font_name 2866730124ul /* "log-font-name" */
544 #define hash_log_font_size 2866731014ul /* "log-font-size" */
545 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
546 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
547 #define hash_log_messages 2291744899ul /* "log-messages" */
548 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
551 static void savearg(char *command, char *argument, struct configuration_spec * config);
553 /*********************************************************************
555 * Function : unload_configfile
557 * Description : Free the config structure and all components.
560 * 1 : data: struct configuration_spec to unload
564 *********************************************************************/
565 static void unload_configfile (void * data)
567 struct configuration_spec * config = (struct configuration_spec *)data;
568 struct forward_spec *cur_fwd = config->forward;
572 struct access_control_list *cur_acl = config->acl;
574 while (cur_acl != NULL)
576 struct access_control_list * next_acl = cur_acl->next;
581 #endif /* def FEATURE_ACL */
583 while (cur_fwd != NULL)
585 struct forward_spec * next_fwd = cur_fwd->next;
586 free_url_spec(cur_fwd->url);
588 freez(cur_fwd->gateway_host);
589 freez(cur_fwd->forward_host);
593 config->forward = NULL;
595 #ifdef FEATURE_COOKIE_JAR
596 if ( NULL != config->jar )
598 fclose( config->jar );
601 #endif /* def FEATURE_COOKIE_JAR */
603 freez(config->confdir);
604 freez(config->logdir);
605 freez(config->templdir);
607 freez(config->haddr);
608 freez(config->logfile);
610 for (i = 0; i < MAX_AF_FILES; i++)
612 freez(config->actions_file_short[i]);
613 freez(config->actions_file[i]);
614 freez(config->re_filterfile_short[i]);
615 freez(config->re_filterfile[i]);
618 freez(config->admin_address);
619 freez(config->proxy_info_url);
620 freez(config->proxy_args);
621 freez(config->usermanual);
623 #ifdef FEATURE_COOKIE_JAR
624 freez(config->jarfile);
625 #endif /* def FEATURE_COOKIE_JAR */
628 freez(config->trustfile);
629 list_remove_all(config->trust_info);
630 #endif /* def FEATURE_TRUST */
632 for (i = 0; i < MAX_AF_FILES; i++)
634 freez(config->re_filterfile[i]);
641 #ifdef FEATURE_GRACEFUL_TERMINATION
642 /*********************************************************************
644 * Function : unload_current_config_file
646 * Description : Unloads current config file - reset to state at
647 * beginning of program.
653 *********************************************************************/
654 void unload_current_config_file(void)
656 if (current_configfile)
658 current_configfile->unloader = unload_configfile;
659 current_configfile = NULL;
665 /*********************************************************************
667 * Function : load_config
669 * Description : Load the config file and all parameters.
671 * XXX: more than thousand lines long
672 * and thus in serious need of refactoring.
676 * Returns : The configuration_spec, or NULL on error.
678 *********************************************************************/
679 struct configuration_spec * load_config(void)
681 char buf[BUFFER_SIZE];
683 FILE *configfp = NULL;
684 struct configuration_spec * config = NULL;
685 struct client_state * fake_csp;
686 struct file_list *fs;
687 unsigned long linenum = 0;
689 char *logfile = NULL;
691 if ( !check_file_changed(current_configfile, configfile, &fs))
693 /* No need to load */
694 return ((struct configuration_spec *)current_configfile->f);
698 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
702 if (NULL != current_configfile)
704 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
707 #ifdef FEATURE_TOGGLE
708 global_toggle_state = 1;
709 #endif /* def FEATURE_TOGGLE */
711 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
717 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
718 /* Never get here - LOG_LEVEL_FATAL causes program exit */
722 * This is backwards from how it's usually done.
723 * Following the usual pattern, "fs" would be stored in a member
724 * variable in "csp", and then we'd access "config" from "fs->f",
725 * using a cast. However, "config" is used so often that a
726 * cast each time would be very ugly, and the extra indirection
727 * would waste CPU cycles. Therefore we store "config" in
728 * "csp->config", and "fs" in "csp->config->config_file_list".
730 config->config_file_list = fs;
735 config->multi_threaded = 1;
736 config->hport = HADDR_PORT;
737 config->buffer_limit = 4096 * 1024;
738 config->usermanual = strdup(USER_MANUAL_URL);
739 config->proxy_args = strdup("");
740 config->forwarded_connect_retries = 0;
741 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
742 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
743 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
745 if ((configfp = fopen(configfile, "r")) == NULL)
747 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
749 /* Never get here - LOG_LEVEL_FATAL causes program exit */
752 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
754 char cmd[BUFFER_SIZE];
755 char arg[BUFFER_SIZE];
756 char tmp[BUFFER_SIZE];
758 struct access_control_list *cur_acl;
759 #endif /* def FEATURE_ACL */
760 struct forward_spec *cur_fwd;
764 strlcpy(tmp, buf, sizeof(tmp));
766 /* Copy command (i.e. up to space or tab) into cmd */
769 while (*p && (*p != ' ') && (*p != '\t'))
775 /* Skip over the whitespace in buf */
776 while (*p && ((*p == ' ') || (*p == '\t')))
781 /* Copy the argument into arg */
782 strlcpy(arg, p, sizeof(arg));
784 /* Should never happen, but check this anyway */
790 /* Make sure the command field is lower case */
795 *p = (char)ijb_tolower(*p);
799 /* Save the argument for show-proxy-args */
800 savearg(cmd, arg, config);
803 switch( hash_string( cmd ) )
805 /* *************************************************************************
806 * actionsfile actions-file-name
807 * In confdir by default
808 * *************************************************************************/
809 case hash_actions_file :
811 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
816 if (i >= MAX_AF_FILES)
818 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
819 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
822 config->actions_file_short[i] = strdup(arg);
823 config->actions_file[i] = make_path(config->confdir, arg);
826 /* *************************************************************************
827 * accept-intercepted-requests
828 * *************************************************************************/
829 case hash_accept_intercepted_requests:
830 if ((*arg != '\0') && (0 != atoi(arg)))
832 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
836 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
840 /* *************************************************************************
841 * admin-address email-address
842 * *************************************************************************/
843 case hash_admin_address :
844 freez(config->admin_address);
845 config->admin_address = strdup(arg);
848 /* *************************************************************************
849 * allow-cgi-request-crunching
850 * *************************************************************************/
851 case hash_allow_cgi_request_crunching:
852 if ((*arg != '\0') && (0 != atoi(arg)))
854 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
858 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
862 /* *************************************************************************
864 * *************************************************************************/
865 case hash_buffer_limit :
866 config->buffer_limit = (size_t)(1024 * atoi(arg));
869 /* *************************************************************************
870 * confdir directory-name
871 * *************************************************************************/
873 freez(config->confdir);
874 config->confdir = make_path( NULL, arg);
877 /* *************************************************************************
879 * Specifies debug level, multiple values are ORed together.
880 * *************************************************************************/
882 config->debug |= atoi(arg);
885 /* *************************************************************************
886 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
887 * *************************************************************************/
889 case hash_deny_access:
890 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
892 if ((vec_count != 1) && (vec_count != 2))
894 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
895 "deny-access directive in configuration file.");
896 string_append(&config->proxy_args,
897 "<br>\nWARNING: Wrong number of parameters for "
898 "deny-access directive in configuration file.<br><br>\n");
902 /* allocate a new node */
903 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
907 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
908 /* Never get here - LOG_LEVEL_FATAL causes program exit */
911 cur_acl->action = ACL_DENY;
913 if (acl_addr(vec[0], cur_acl->src) < 0)
915 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
916 "for deny-access directive in configuration file: \"%s\"", vec[0]);
917 string_append(&config->proxy_args,
918 "<br>\nWARNING: Invalid source address, port or netmask "
919 "for deny-access directive in configuration file: \"");
920 string_append(&config->proxy_args,
922 string_append(&config->proxy_args,
929 if (acl_addr(vec[1], cur_acl->dst) < 0)
931 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
932 "for deny-access directive in configuration file: \"%s\"", vec[1]);
933 string_append(&config->proxy_args,
934 "<br>\nWARNING: Invalid destination address, port or netmask "
935 "for deny-access directive in configuration file: \"");
936 string_append(&config->proxy_args,
938 string_append(&config->proxy_args,
946 * Add it to the list. Note we reverse the list to get the
947 * behaviour the user expects. With both the ACL and
948 * actions file, the last match wins. However, the internal
949 * implementations are different: The actions file is stored
950 * in the same order as the file, and scanned completely.
951 * With the ACL, we reverse the order as we load it, then
952 * when we scan it we stop as soon as we get a match.
954 cur_acl->next = config->acl;
955 config->acl = cur_acl;
958 #endif /* def FEATURE_ACL */
960 /* *************************************************************************
961 * enable-edit-actions 0|1
962 * *************************************************************************/
963 #ifdef FEATURE_CGI_EDIT_ACTIONS
964 case hash_enable_edit_actions:
965 if ((*arg != '\0') && (0 != atoi(arg)))
967 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
971 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
974 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
976 /* *************************************************************************
977 * enable-remote-toggle 0|1
978 * *************************************************************************/
979 #ifdef FEATURE_CGI_EDIT_ACTIONS
980 case hash_enable_remote_toggle:
981 if ((*arg != '\0') && (0 != atoi(arg)))
983 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
987 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
990 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
992 /* *************************************************************************
993 * enable-remote-http-toggle 0|1
994 * *************************************************************************/
995 case hash_enable_remote_http_toggle:
996 if ((*arg != '\0') && (0 != atoi(arg)))
998 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1002 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1006 /* *************************************************************************
1007 * hash_enforce_blocks 0|1
1008 * *************************************************************************/
1009 #ifdef FEATURE_FORCE_LOAD
1010 case hash_enforce_blocks:
1011 if ((*arg != '\0') && (0 != atoi(arg)))
1013 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1017 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1020 #endif /* def FEATURE_FORCE_LOAD */
1022 /* *************************************************************************
1023 * filterfile file-name
1024 * In confdir by default.
1025 * *************************************************************************/
1026 case hash_filterfile :
1028 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1033 if (i >= MAX_AF_FILES)
1035 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1036 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1039 config->re_filterfile_short[i] = strdup(arg);
1040 config->re_filterfile[i] = make_path(config->confdir, arg);
1044 /* *************************************************************************
1045 * forward url-pattern (.|http-proxy-host[:port])
1046 * *************************************************************************/
1048 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1052 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1053 "directive in configuration file.");
1054 string_append(&config->proxy_args,
1055 "<br>\nWARNING: Wrong number of parameters for "
1056 "forward directive in configuration file.");
1060 /* allocate a new node */
1061 cur_fwd = zalloc(sizeof(*cur_fwd));
1062 if (cur_fwd == NULL)
1064 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1065 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1069 cur_fwd->type = SOCKS_NONE;
1071 /* Save the URL pattern */
1072 if (create_url_spec(cur_fwd->url, vec[0]))
1074 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1075 "directive in configuration file.");
1076 string_append(&config->proxy_args,
1077 "<br>\nWARNING: Bad URL specifier for "
1078 "forward directive in configuration file.");
1082 /* Parse the parent HTTP proxy host:port */
1085 if (strcmp(p, ".") != 0)
1087 cur_fwd->forward_host = strdup(p);
1089 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1092 cur_fwd->forward_port = atoi(p);
1095 if (cur_fwd->forward_port <= 0)
1097 cur_fwd->forward_port = 8000;
1102 cur_fwd->next = config->forward;
1103 config->forward = cur_fwd;
1107 /* *************************************************************************
1108 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1109 * *************************************************************************/
1110 case hash_forward_socks4:
1111 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1115 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1116 "forward-socks4 directive in configuration file.");
1117 string_append(&config->proxy_args,
1118 "<br>\nWARNING: Wrong number of parameters for "
1119 "forward-socks4 directive in configuration file.");
1123 /* allocate a new node */
1124 cur_fwd = zalloc(sizeof(*cur_fwd));
1125 if (cur_fwd == NULL)
1127 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1128 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1132 cur_fwd->type = SOCKS_4;
1134 /* Save the URL pattern */
1135 if (create_url_spec(cur_fwd->url, vec[0]))
1137 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1138 "directive in configuration file.");
1139 string_append(&config->proxy_args,
1140 "<br>\nWARNING: Bad URL specifier for "
1141 "forward-socks4 directive in configuration file.");
1145 /* Parse the SOCKS proxy host[:port] */
1148 if (strcmp(p, ".") != 0)
1150 cur_fwd->gateway_host = strdup(p);
1152 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1155 cur_fwd->gateway_port = atoi(p);
1157 if (cur_fwd->gateway_port <= 0)
1159 cur_fwd->gateway_port = 1080;
1163 /* Parse the parent HTTP proxy host[:port] */
1166 if (strcmp(p, ".") != 0)
1168 cur_fwd->forward_host = strdup(p);
1170 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1173 cur_fwd->forward_port = atoi(p);
1176 if (cur_fwd->forward_port <= 0)
1178 cur_fwd->forward_port = 8000;
1183 cur_fwd->next = config->forward;
1184 config->forward = cur_fwd;
1188 /* *************************************************************************
1189 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1190 * *************************************************************************/
1191 case hash_forward_socks4a:
1192 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1196 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1197 "forward-socks4a directive in configuration file.");
1198 string_append(&config->proxy_args,
1199 "<br>\nWARNING: Wrong number of parameters for "
1200 "forward-socks4a directive in configuration file.");
1204 /* allocate a new node */
1205 cur_fwd = zalloc(sizeof(*cur_fwd));
1206 if (cur_fwd == NULL)
1208 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1209 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1213 cur_fwd->type = SOCKS_4A;
1215 /* Save the URL pattern */
1216 if (create_url_spec(cur_fwd->url, vec[0]))
1218 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1219 "directive in configuration file.");
1220 string_append(&config->proxy_args,
1221 "<br>\nWARNING: Bad URL specifier for "
1222 "forward-socks4a directive in configuration file.");
1226 /* Parse the SOCKS proxy host[:port] */
1229 cur_fwd->gateway_host = strdup(p);
1231 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1234 cur_fwd->gateway_port = atoi(p);
1236 if (cur_fwd->gateway_port <= 0)
1238 cur_fwd->gateway_port = 1080;
1241 /* Parse the parent HTTP proxy host[:port] */
1244 if (strcmp(p, ".") != 0)
1246 cur_fwd->forward_host = strdup(p);
1248 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1251 cur_fwd->forward_port = atoi(p);
1254 if (cur_fwd->forward_port <= 0)
1256 cur_fwd->forward_port = 8000;
1261 cur_fwd->next = config->forward;
1262 config->forward = cur_fwd;
1266 /* *************************************************************************
1267 * forwarded-connect-retries n
1268 * *************************************************************************/
1269 case hash_forwarded_connect_retries :
1270 config->forwarded_connect_retries = atoi(arg);
1273 /* *************************************************************************
1274 * jarfile jar-file-name
1275 * In logdir by default
1276 * *************************************************************************/
1277 #ifdef FEATURE_COOKIE_JAR
1279 freez(config->jarfile);
1280 config->jarfile = make_path(config->logdir, arg);
1282 #endif /* def FEATURE_COOKIE_JAR */
1284 /* *************************************************************************
1285 * listen-address [ip][:port]
1286 * *************************************************************************/
1287 case hash_listen_address :
1288 freez(config->haddr);
1289 config->haddr = strdup(arg);
1292 /* *************************************************************************
1293 * logdir directory-name
1294 * *************************************************************************/
1296 freez(config->logdir);
1297 config->logdir = make_path(NULL, arg);
1300 /* *************************************************************************
1301 * logfile log-file-name
1302 * In logdir by default
1303 * *************************************************************************/
1307 logfile = make_path(config->logdir, arg);
1308 if (NULL == logfile)
1310 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1315 /* *************************************************************************
1316 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1317 * *************************************************************************/
1319 case hash_permit_access:
1320 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1322 if ((vec_count != 1) && (vec_count != 2))
1324 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1325 "permit-access directive in configuration file.");
1326 string_append(&config->proxy_args,
1327 "<br>\nWARNING: Wrong number of parameters for "
1328 "permit-access directive in configuration file.<br><br>\n");
1333 /* allocate a new node */
1334 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1336 if (cur_acl == NULL)
1338 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1339 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1342 cur_acl->action = ACL_PERMIT;
1344 if (acl_addr(vec[0], cur_acl->src) < 0)
1346 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1347 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1348 string_append(&config->proxy_args,
1349 "<br>\nWARNING: Invalid source address, port or netmask for "
1350 "permit-access directive in configuration file: \"");
1351 string_append(&config->proxy_args,
1353 string_append(&config->proxy_args,
1360 if (acl_addr(vec[1], cur_acl->dst) < 0)
1362 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1363 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1364 string_append(&config->proxy_args,
1365 "<br>\nWARNING: Invalid destination address, port or netmask for "
1366 "permit-access directive in configuration file: \"");
1367 string_append(&config->proxy_args,
1369 string_append(&config->proxy_args,
1377 * Add it to the list. Note we reverse the list to get the
1378 * behaviour the user expects. With both the ACL and
1379 * actions file, the last match wins. However, the internal
1380 * implementations are different: The actions file is stored
1381 * in the same order as the file, and scanned completely.
1382 * With the ACL, we reverse the order as we load it, then
1383 * when we scan it we stop as soon as we get a match.
1385 cur_acl->next = config->acl;
1386 config->acl = cur_acl;
1389 #endif /* def FEATURE_ACL */
1391 /* *************************************************************************
1392 * proxy-info-url url
1393 * *************************************************************************/
1394 case hash_proxy_info_url :
1395 freez(config->proxy_info_url);
1396 config->proxy_info_url = strdup(arg);
1399 /* *************************************************************************
1401 * *************************************************************************/
1402 case hash_single_threaded :
1403 config->multi_threaded = 0;
1406 /* *************************************************************************
1407 * split-large-cgi-forms
1408 * *************************************************************************/
1409 case hash_split_large_cgi_forms :
1410 if ((*arg != '\0') && (0 != atoi(arg)))
1412 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1416 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1420 /* *************************************************************************
1421 * templdir directory-name
1422 * *************************************************************************/
1423 case hash_templdir :
1424 freez(config->templdir);
1425 config->templdir = make_path(NULL, arg);
1428 /* *************************************************************************
1430 * *************************************************************************/
1431 #ifdef FEATURE_TOGGLE
1433 global_toggle_state = atoi(arg);
1435 #endif /* def FEATURE_TOGGLE */
1437 /* *************************************************************************
1438 * trust-info-url url
1439 * *************************************************************************/
1440 #ifdef FEATURE_TRUST
1441 case hash_trust_info_url :
1442 enlist(config->trust_info, arg);
1444 #endif /* def FEATURE_TRUST */
1446 /* *************************************************************************
1447 * trustfile filename
1448 * (In confdir by default.)
1449 * *************************************************************************/
1450 #ifdef FEATURE_TRUST
1451 case hash_trustfile :
1452 freez(config->trustfile);
1453 config->trustfile = make_path(config->confdir, arg);
1455 #endif /* def FEATURE_TRUST */
1457 /* *************************************************************************
1459 * *************************************************************************/
1460 case hash_usermanual :
1461 freez(config->usermanual);
1462 config->usermanual = strdup(arg);
1465 /* *************************************************************************
1466 * Win32 Console options:
1467 * *************************************************************************/
1469 /* *************************************************************************
1471 * *************************************************************************/
1473 case hash_hide_console :
1476 #endif /*def _WIN_CONSOLE*/
1479 /* *************************************************************************
1480 * Win32 GUI options:
1481 * *************************************************************************/
1483 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1484 /* *************************************************************************
1485 * activity-animation (0|1)
1486 * *************************************************************************/
1487 case hash_activity_animation :
1488 g_bShowActivityAnimation = atoi(arg);
1491 /* *************************************************************************
1492 * close-button-minimizes (0|1)
1493 * *************************************************************************/
1494 case hash_close_button_minimizes :
1495 g_bCloseHidesWindow = atoi(arg);
1498 /* *************************************************************************
1499 * log-buffer-size (0|1)
1500 * *************************************************************************/
1501 case hash_log_buffer_size :
1502 g_bLimitBufferSize = atoi(arg);
1505 /* *************************************************************************
1506 * log-font-name fontnane
1507 * *************************************************************************/
1508 case hash_log_font_name :
1509 strcpy( g_szFontFaceName, arg );
1512 /* *************************************************************************
1514 * *************************************************************************/
1515 case hash_log_font_size :
1516 g_nFontSize = atoi(arg);
1519 /* *************************************************************************
1520 * log-highlight-messages (0|1)
1521 * *************************************************************************/
1522 case hash_log_highlight_messages :
1523 g_bHighlightMessages = atoi(arg);
1526 /* *************************************************************************
1528 * *************************************************************************/
1529 case hash_log_max_lines :
1530 g_nMaxBufferLines = atoi(arg);
1533 /* *************************************************************************
1534 * log-messages (0|1)
1535 * *************************************************************************/
1536 case hash_log_messages :
1537 g_bLogMessages = atoi(arg);
1540 /* *************************************************************************
1541 * show-on-task-bar (0|1)
1542 * *************************************************************************/
1543 case hash_show_on_task_bar :
1544 g_bShowOnTaskBar = atoi(arg);
1547 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1550 /* *************************************************************************
1551 * Warnings about unsupported features
1552 * *************************************************************************/
1554 case hash_deny_access:
1555 #endif /* ndef FEATURE_ACL */
1556 #ifndef FEATURE_CGI_EDIT_ACTIONS
1557 case hash_enable_edit_actions:
1558 case hash_enable_remote_toggle:
1559 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1560 #ifndef FEATURE_COOKIE_JAR
1562 #endif /* ndef FEATURE_COOKIE_JAR */
1564 case hash_permit_access:
1565 #endif /* ndef FEATURE_ACL */
1566 #ifndef FEATURE_TOGGLE
1568 #endif /* ndef FEATURE_TOGGLE */
1569 #ifndef FEATURE_TRUST
1570 case hash_trustfile :
1571 case hash_trust_info_url :
1572 #endif /* ndef FEATURE_TRUST */
1574 #ifndef _WIN_CONSOLE
1575 case hash_hide_console :
1576 #endif /* ndef _WIN_CONSOLE */
1578 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1579 case hash_activity_animation :
1580 case hash_close_button_minimizes :
1581 case hash_log_buffer_size :
1582 case hash_log_font_name :
1583 case hash_log_font_size :
1584 case hash_log_highlight_messages :
1585 case hash_log_max_lines :
1586 case hash_log_messages :
1587 case hash_show_on_task_bar :
1588 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1589 /* These warnings are annoying - so hide them. -- Jon */
1590 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1593 /* *************************************************************************/
1595 /* *************************************************************************/
1597 * I decided that I liked this better as a warning than an
1598 * error. To change back to an error, just change log level
1599 * to LOG_LEVEL_FATAL.
1601 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1602 "in configuration file (%s).", buf, hash_string(cmd), linenum, configfile);
1603 string_append(&config->proxy_args,
1604 " <b><font color=\"red\">WARNING: unrecognized directive, ignored</font></b>");
1607 /* *************************************************************************/
1608 } /* end switch( hash_string(cmd) ) */
1609 } /* end while ( read_config_line(...) ) */
1613 set_debug_level(config->debug);
1615 freez(config->logfile);
1619 if (NULL != logfile)
1621 config->logfile = logfile;
1622 log_error(LOG_LEVEL_INFO,
1623 "Switching to daemon mode. Log messages will be written to: %s", config->logfile);
1624 init_error_log(Argv[0], config->logfile);
1628 log_error(LOG_LEVEL_INFO, "No logfile configured while in daemon mode. Logging disabled.");
1633 if (NULL == config->proxy_args)
1635 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1638 if (config->actions_file[0])
1640 add_loader(load_actions_file, config);
1643 if (config->re_filterfile)
1645 add_loader(load_re_filterfile, config);
1648 #ifdef FEATURE_TRUST
1649 if (config->trustfile)
1651 add_loader(load_trustfile, config);
1653 #endif /* def FEATURE_TRUST */
1655 #ifdef FEATURE_COOKIE_JAR
1656 if ( NULL != config->jarfile )
1658 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1660 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1661 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1663 setbuf(config->jar, NULL);
1665 #endif /* def FEATURE_COOKIE_JAR */
1667 if ( NULL == config->haddr )
1669 config->haddr = strdup( HADDR_DEFAULT );
1672 if ( NULL != config->haddr )
1674 if (NULL != (p = strchr(config->haddr, ':')))
1679 config->hport = atoi(p);
1683 if (config->hport <= 0)
1686 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1687 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1689 if (*config->haddr == '\0')
1691 config->haddr = NULL;
1696 * Want to run all the loaders once now.
1698 * Need to set up a fake csp, so they can get to the config.
1700 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1701 fake_csp->config = config;
1703 if (run_loader(fake_csp))
1706 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1707 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1711 /* FIXME: this is a kludge for win32 */
1712 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1714 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1715 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1716 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1718 #ifdef FEATURE_TRUST
1719 g_trustfile = config->trustfile;
1720 #endif /* def FEATURE_TRUST */
1723 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1724 /* FIXME: end kludge */
1727 config->need_bind = 1;
1729 if (current_configfile)
1731 struct configuration_spec * oldcfg = (struct configuration_spec *)
1732 current_configfile->f;
1734 * Check if config->haddr,hport == oldcfg->haddr,hport
1736 * The following could be written more compactly as a single,
1737 * (unreadably long) if statement.
1739 config->need_bind = 0;
1740 if (config->hport != oldcfg->hport)
1742 config->need_bind = 1;
1744 else if (config->haddr == NULL)
1746 if (oldcfg->haddr != NULL)
1748 config->need_bind = 1;
1751 else if (oldcfg->haddr == NULL)
1753 config->need_bind = 1;
1755 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1757 config->need_bind = 1;
1760 current_configfile->unloader = unload_configfile;
1763 fs->next = files->next;
1766 current_configfile = fs;
1772 /*********************************************************************
1774 * Function : savearg
1776 * Description : Called from `load_config'. It saves each non-empty
1777 * and non-comment line from config into
1778 * config->proxy_args. This is used to create the
1779 * show-proxy-args page. On error, frees
1780 * config->proxy_args and sets it to NULL
1783 * 1 : command = config setting that was found
1784 * 2 : argument = the setting's argument (if any)
1785 * 3 : config = Configuration to save into.
1789 *********************************************************************/
1790 static void savearg(char *command, char *argument, struct configuration_spec * config)
1800 * Add config option name embedded in
1801 * link to it's section in the user-manual
1803 buf = strdup("\n<a href=\"");
1804 if (!strncmpic(config->usermanual, "file://", 7) ||
1805 !strncmpic(config->usermanual, "http", 4))
1807 string_append(&buf, config->usermanual);
1811 string_append(&buf, "http://");
1812 string_append(&buf, CGI_SITE_2_HOST);
1813 string_append(&buf, "/user-manual/");
1815 string_append(&buf, CONFIG_HELP_PREFIX);
1816 string_join (&buf, string_toupper(command));
1817 string_append(&buf, "\">");
1818 string_append(&buf, command);
1819 string_append(&buf, "</a> ");
1823 freez(config->proxy_args);
1827 if ( (NULL != argument) && ('\0' != *argument) )
1829 s = html_encode(argument);
1833 freez(config->proxy_args);
1837 if (strncmpic(argument, "http://", 7) == 0)
1839 string_append(&buf, "<a href=\"");
1840 string_append(&buf, s);
1841 string_append(&buf, "\">");
1842 string_join (&buf, s);
1843 string_append(&buf, "</a>");
1847 string_join (&buf, s);
1851 string_append(&buf, "<br>");
1852 string_join(&config->proxy_args, buf);