1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.68 2007/10/19 16:32:34 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.68 2007/10/19 16:32:34 fabiankeil
39 * Plug memory leak introduced with my last commit.
41 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
42 * When in daemon mode, close stderr after the configuration file has been
43 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
45 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
46 * #1763173 from Stefan Huehner: declare unload_configfile() static.
48 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
49 * As Hal noticed, checking dispatch_cgi() as the last cruncher
50 * looks like a bug if CGI requests are blocked unintentionally,
51 * so don't do it unless the user enabled the new config option
52 * "allow-cgi-request-crunching".
54 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
55 * - Use strlcpy() instead of strcpy().
56 * - Stop treating actions files special. Expect a complete file name
57 * (with or without path) like it's done for the rest of the files.
59 * - Remove an unnecessary temporary memory allocation.
60 * - Don't log anything to the console when running as
61 * daemon and no errors occurred.
63 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
64 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
66 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
67 * New config option: enforce-blocks.
69 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
70 * - Mention other reasons why acl directive loading might have failed.
71 * - Don't log the acl source if the acl destination is to blame.
73 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
74 * Add new config option "templdir" to
75 * change the templates directory.
77 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
78 * Added config option accept-intercepted-requests
79 * and disabled it by default.
81 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
82 * Fix gcc43 compiler warnings.
84 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
85 * Add config option "split-large-forms"
86 * to work around the browser bug reported
89 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
90 * Move the <br> in the generated HTML for the config
91 * options from the beginning of the string to its end.
92 * Keeps the white space in balance.
94 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
95 * Fix memory leak in case of config file reloads.
97 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
98 * Modified kludge for win32 to make ming32 menu
99 * "Options/Edit Filters" (sort of) work again.
100 * Same limitations as for the action files apply.
103 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
104 * Incorporate modified version of Roland Rosenfeld's patch to
105 * optionally access the user-manual via Privoxy. Closes patch 679075.
107 * Formatting changed to Privoxy style, added call to
108 * cgi_error_no_template if the requested file doesn't
109 * exist and modified check whether or not Privoxy itself
110 * should serve the manual. Should work cross-platform now.
112 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
113 * Added config option enable-remote-http-toggle
114 * to specify if Privoxy should recognize special
115 * headers (currently only X-Filter) to change its
116 * behaviour. Disabled by default.
118 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
119 * Make number of retries in case of forwarded-connect problems
120 * a config file option (forwarded-connect-retries) and use 0 as
123 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
124 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
125 * with what was really the latest development (the v_3_0_branch branch)
127 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
128 * Don't forget to malloc space for the null terminator...
130 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
131 * Multiple filter file support
133 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
134 * Closed two memory leaks; hopefully the last remaining ones
135 * (in the main execution paths, anyway).
137 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
138 * Addressed bug #719435
139 * - Extraneous filterfile directives now logged as errors
140 * - This and unrecnonised directives now really obvious on status page
142 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
143 * Cosmetic: Renamed cryptic variable
145 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
146 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
148 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
149 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
151 * Revision 1.48 2002/05/14 21:30:38 oes
152 * savearg now uses own linking code instead of (now special-cased) add_help_link
154 * Revision 1.47 2002/05/12 21:36:29 jongfoster
155 * Correcting function comments
157 * Revision 1.46 2002/04/26 12:55:14 oes
158 * - New option "user-manual", defaults to our site
159 * via project.h #define
160 * - savearg now embeds option names in help links
162 * Revision 1.45 2002/04/24 02:11:54 oes
163 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
165 * Revision 1.44 2002/04/08 20:37:13 swa
168 * Revision 1.43 2002/04/08 20:36:50 swa
171 * Revision 1.42 2002/04/05 15:50:15 oes
172 * fix for invalid HTML proxy_args
174 * Revision 1.41 2002/03/31 17:19:00 jongfoster
175 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
177 * Revision 1.40 2002/03/26 22:29:55 swa
178 * we have a new homepage!
180 * Revision 1.39 2002/03/24 13:25:43 swa
181 * name change related issues
183 * Revision 1.38 2002/03/24 13:05:48 jongfoster
184 * Renaming re_filterfile to filterfile
186 * Revision 1.37 2002/03/16 23:54:06 jongfoster
187 * Adding graceful termination feature, to help look for memory leaks.
188 * If you enable this (which, by design, has to be done by hand
189 * editing config.h) and then go to http://i.j.b/die, then the program
190 * will exit cleanly after the *next* request. It should free all the
191 * memory that was used.
193 * Revision 1.36 2002/03/13 00:27:05 jongfoster
196 * Revision 1.35 2002/03/07 03:52:44 oes
197 * Set logging to tty for --no-daemon mode
199 * Revision 1.34 2002/03/06 23:14:35 jongfoster
200 * Trivial cosmetic changes to make function comments easier to find.
202 * Revision 1.33 2002/03/05 04:52:42 oes
203 * Deleted non-errlog debugging code
205 * Revision 1.32 2002/03/04 18:24:53 oes
206 * Re-enabled output of unknown config directive hash
208 * Revision 1.31 2002/03/03 15:07:20 oes
209 * Re-enabled automatic config reloading
211 * Revision 1.30 2002/01/22 23:31:43 jongfoster
212 * Replacing strsav() with string_append()
214 * Revision 1.29 2002/01/17 21:02:30 jongfoster
215 * Moving all our URL and URL pattern parsing code to urlmatch.c.
217 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
219 * Revision 1.28 2001/12/30 14:07:32 steudten
220 * - Add signal handling (unix)
221 * - Add SIGHUP handler (unix)
222 * - Add creation of pidfile (unix)
223 * - Add action 'top' in rc file (RH)
224 * - Add entry 'SIGNALS' to manpage
225 * - Add exit message to logfile (unix)
227 * Revision 1.27 2001/11/07 00:02:13 steudten
228 * Add line number in error output for lineparsing for
229 * actionsfile and configfile.
230 * Special handling for CLF added.
232 * Revision 1.26 2001/11/05 21:41:43 steudten
233 * Add changes to be a real daemon just for unix os.
234 * (change cwd to /, detach from controlling tty, set
235 * process group and session leader to the own process.
237 * Add some fatal-error log message for failed malloc().
238 * Add '-d' if compiled with 'configure --with-debug' to
239 * enable debug output.
241 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
242 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
243 * threads to call select() simultaneously. So, it's time to do a real, live,
244 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
245 * (native). Both versions will work, but using __OS2__ offers multi-threading.
247 * Revision 1.24 2001/10/23 21:40:30 jongfoster
248 * Added support for enable-edit-actions and enable-remote-toggle config
251 * Revision 1.23 2001/10/07 15:36:00 oes
252 * Introduced new config option "buffer-limit"
254 * Revision 1.22 2001/09/22 16:36:59 jongfoster
255 * Removing unused parameter fs from read_config_line()
257 * Revision 1.21 2001/09/16 17:10:43 jongfoster
258 * Moving function savearg() here, since it was the only thing left in
261 * Revision 1.20 2001/07/30 22:08:36 jongfoster
262 * Tidying up #defines:
263 * - All feature #defines are now of the form FEATURE_xxx
264 * - Permanently turned off WIN_GUI_EDIT
265 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
267 * Revision 1.19 2001/07/15 17:45:16 jongfoster
268 * Removing some unused #includes
270 * Revision 1.18 2001/07/13 14:01:14 oes
271 * - Removed all #ifdef PCRS
272 * - Removed vim-settings
274 * Revision 1.17 2001/06/29 13:31:03 oes
275 * - Improved comments
276 * - Fixed (actionsfile) and sorted hashes
277 * - Introduced admin_address and proxy-info-url
278 * as config parameters
279 * - Renamed config->proxy_args_invocation (which didn't have
280 * the invocation but the options!) to config->proxy_args
281 * - Various adaptions
282 * - Removed logentry from cancelled commit
284 * Revision 1.16 2001/06/09 10:55:28 jongfoster
285 * Changing BUFSIZ ==> BUFFER_SIZE
287 * Revision 1.15 2001/06/07 23:13:40 jongfoster
288 * Merging ACL and forward files into config file.
289 * Cosmetic: Sorting config file options alphabetically.
290 * Cosmetic: Adding brief syntax comments to config file options.
292 * Revision 1.14 2001/06/07 14:46:25 joergs
293 * Missing make_path() added for re_filterfile.
295 * Revision 1.13 2001/06/05 22:33:54 jongfoster
297 * Fixed minor memory leak.
298 * Also now uses make_path to prepend the pathnames.
300 * Revision 1.12 2001/06/05 20:04:09 jongfoster
301 * Now uses _snprintf() in place of snprintf() under Win32.
303 * Revision 1.11 2001/06/04 18:31:58 swa
304 * files are now prefixed with either `confdir' or `logdir'.
305 * `make redhat-dist' replaces both entries confdir and logdir
308 * Revision 1.10 2001/06/03 19:11:54 oes
309 * introduced confdir option
311 * Revision 1.9 2001/06/01 20:06:24 jongfoster
312 * Removed support for "tinygif" option - moved to actions file.
314 * Revision 1.8 2001/05/31 21:27:13 jongfoster
315 * Removed many options from the config file and into the
316 * "actions" file: add_forwarded, suppress_vanilla_wafer,
317 * wafer, add_header, user_agent, referer, from
318 * Also globally replaced "permission" with "action".
320 * Revision 1.7 2001/05/29 09:50:24 jongfoster
321 * Unified blocklist/imagelist/permissionslist.
322 * File format is still under discussion, but the internal changes
325 * Also modified interceptor behaviour:
326 * - We now intercept all URLs beginning with one of the following
327 * prefixes (and *only* these prefixes):
329 * * http://ijbswa.sf.net/config/
330 * * http://ijbswa.sourceforge.net/config/
331 * - New interceptors "home page" - go to http://i.j.b/ to see it.
332 * - Internal changes so that intercepted and fast redirect pages
333 * are not replaced with an image.
334 * - Interceptors now have the option to send a binary page direct
335 * to the client. (i.e. ijb-send-banner uses this)
336 * - Implemented show-url-info interceptor. (Which is why I needed
337 * the above interceptors changes - a typical URL is
338 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
339 * The previous mechanism would not have intercepted that, and
340 * if it had been intercepted then it then it would have replaced
343 * Revision 1.6 2001/05/26 00:28:36 jongfoster
344 * Automatic reloading of config file.
345 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
346 * Most of the global variables have been moved to a new
347 * struct configuration_spec, accessed through csp->config->globalname
348 * Most of the globals remaining are used by the Win32 GUI.
350 * Revision 1.5 2001/05/25 22:34:30 jongfoster
353 * Revision 1.4 2001/05/22 18:46:04 oes
355 * - Enabled filtering banners by size rather than URL
356 * by adding patterns that replace all standard banner
357 * sizes with the "Junkbuster" gif to the re_filterfile
359 * - Enabled filtering WebBugs by providing a pattern
360 * which kills all 1x1 images
362 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
363 * which is selected by the (nonstandard and therefore
364 * capital) letter 'U' in the option string.
365 * It causes the quantifiers to be ungreedy by default.
366 * Appending a ? turns back to greedy (!).
368 * - Added a new interceptor ijb-send-banner, which
369 * sends back the "Junkbuster" gif. Without imagelist or
370 * MSIE detection support, or if tinygif = 1, or the
371 * URL isn't recognized as an imageurl, a lame HTML
372 * explanation is sent instead.
374 * - Added new feature, which permits blocking remote
375 * script redirects and firing back a local redirect
377 * The feature is conditionally compiled, i.e. it
378 * can be disabled with --disable-fast-redirects,
379 * plus it must be activated by a "fast-redirects"
380 * line in the config file, has its own log level
381 * and of course wants to be displayed by show-proxy-args
382 * Note: Boy, all the #ifdefs in 1001 locations and
383 * all the fumbling with configure.in and acconfig.h
384 * were *way* more work than the feature itself :-(
386 * - Because a generic redirect template was needed for
387 * this, tinygif = 3 now uses the same.
389 * - Moved GIFs, and other static HTTP response templates
394 * - Removed some >400 CRs again (Jon, you really worked
397 * Revision 1.3 2001/05/20 01:21:20 jongfoster
398 * Version 2.9.4 checkin.
399 * - Merged popupfile and cookiefile, and added control over PCRS
400 * filtering, in new "permissionsfile".
401 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
402 * file error you now get a message box (in the Win32 GUI) rather
403 * than the program exiting with no explanation.
404 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
406 * - Removed tabs from "config"
407 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
408 * - Bumped up version number.
410 * Revision 1.2 2001/05/17 23:01:01 oes
411 * - Cleaned CRLF's from the sources and related files
413 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
414 * Initial import of version 2.9.3 source tree
417 *********************************************************************/
423 #include <sys/types.h>
437 # include <windows.h>
440 # ifndef _WIN_CONSOLE
442 # endif /* ndef _WIN_CONSOLE */
444 #else /* ifndef _WIN32 */
448 # include <sys/wait.h>
450 # include <sys/time.h>
451 # include <sys/stat.h>
461 #include "miscutil.h"
465 #include "urlmatch.h"
468 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
471 * Fix a problem with Solaris. There should be no effect on other
473 * Solaris's isspace() is a macro which uses it's argument directly
474 * as an array index. Therefore we need to make sure that high-bit
475 * characters generate +ve values, and ideally we also want to make
476 * the argument match the declared parameter type of "int".
478 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
479 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
481 #ifdef FEATURE_TOGGLE
482 /* Privoxy is enabled by default. */
483 int global_toggle_state = 1;
484 #endif /* def FEATURE_TOGGLE */
486 /* The filename of the configfile */
487 const char *configfile = NULL;
490 * CGI functions will later need access to the invocation args,
491 * so we will make argc and argv global.
494 const char **Argv = NULL;
496 static struct file_list *current_configfile = NULL;
500 * This takes the "cryptic" hash of each keyword and aliases them to
501 * something a little more readable. This also makes changing the
502 * hash values easier if they should change or the hash algorthm changes.
503 * Use the included "hash" program to find out what the hash will be
504 * for any string supplied on the command line. (Or just put it in the
505 * config file and read the number from the error message in the log).
507 * Please keep this list sorted alphabetically (but with the Windows
508 * console and GUI specific options last).
511 #define hash_actions_file 1196306641ul /* "actionsfile" */
512 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
513 #define hash_admin_address 4112573064ul /* "admin-address" */
514 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
515 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
516 #define hash_confdir 1978389ul /* "confdir" */
517 #define hash_debug 78263ul /* "debug" */
518 #define hash_deny_access 1227333715ul /* "deny-access" */
519 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
520 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
521 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
522 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
523 #define hash_filterfile 250887266ul /* "filterfile" */
524 #define hash_forward 2029845ul /* "forward" */
525 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
526 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
527 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
528 #define hash_jarfile 2046641ul /* "jarfile" */
529 #define hash_listen_address 1255650842ul /* "listen-address" */
530 #define hash_logdir 422889ul /* "logdir" */
531 #define hash_logfile 2114766ul /* "logfile" */
532 #define hash_permit_access 3587953268ul /* "permit-access" */
533 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
534 #define hash_single_threaded 4250084780ul /* "single-threaded" */
535 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
536 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
537 #define hash_templdir 11067889ul /* "templdir" */
538 #define hash_toggle 447966ul /* "toggle" */
539 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
540 #define hash_trustfile 56494766ul /* "trustfile" */
541 #define hash_usermanual 1416668518ul /* "user-manual" */
542 #define hash_activity_animation 1817904738ul /* "activity-animation" */
543 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
544 #define hash_hide_console 2048809870ul /* "hide-console" */
545 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
546 #define hash_log_font_name 2866730124ul /* "log-font-name" */
547 #define hash_log_font_size 2866731014ul /* "log-font-size" */
548 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
549 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
550 #define hash_log_messages 2291744899ul /* "log-messages" */
551 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
554 static void savearg(char *command, char *argument, struct configuration_spec * config);
556 /*********************************************************************
558 * Function : unload_configfile
560 * Description : Free the config structure and all components.
563 * 1 : data: struct configuration_spec to unload
567 *********************************************************************/
568 static void unload_configfile (void * data)
570 struct configuration_spec * config = (struct configuration_spec *)data;
571 struct forward_spec *cur_fwd = config->forward;
575 struct access_control_list *cur_acl = config->acl;
577 while (cur_acl != NULL)
579 struct access_control_list * next_acl = cur_acl->next;
584 #endif /* def FEATURE_ACL */
586 while (cur_fwd != NULL)
588 struct forward_spec * next_fwd = cur_fwd->next;
589 free_url_spec(cur_fwd->url);
591 freez(cur_fwd->gateway_host);
592 freez(cur_fwd->forward_host);
596 config->forward = NULL;
598 #ifdef FEATURE_COOKIE_JAR
599 if ( NULL != config->jar )
601 fclose( config->jar );
604 #endif /* def FEATURE_COOKIE_JAR */
606 freez(config->confdir);
607 freez(config->logdir);
608 freez(config->templdir);
610 freez(config->haddr);
611 freez(config->logfile);
613 for (i = 0; i < MAX_AF_FILES; i++)
615 freez(config->actions_file_short[i]);
616 freez(config->actions_file[i]);
617 freez(config->re_filterfile_short[i]);
618 freez(config->re_filterfile[i]);
621 freez(config->admin_address);
622 freez(config->proxy_info_url);
623 freez(config->proxy_args);
624 freez(config->usermanual);
626 #ifdef FEATURE_COOKIE_JAR
627 freez(config->jarfile);
628 #endif /* def FEATURE_COOKIE_JAR */
631 freez(config->trustfile);
632 list_remove_all(config->trust_info);
633 #endif /* def FEATURE_TRUST */
635 for (i = 0; i < MAX_AF_FILES; i++)
637 freez(config->re_filterfile[i]);
644 #ifdef FEATURE_GRACEFUL_TERMINATION
645 /*********************************************************************
647 * Function : unload_current_config_file
649 * Description : Unloads current config file - reset to state at
650 * beginning of program.
656 *********************************************************************/
657 void unload_current_config_file(void)
659 if (current_configfile)
661 current_configfile->unloader = unload_configfile;
662 current_configfile = NULL;
668 /*********************************************************************
670 * Function : load_config
672 * Description : Load the config file and all parameters.
674 * XXX: more than thousand lines long
675 * and thus in serious need of refactoring.
679 * Returns : The configuration_spec, or NULL on error.
681 *********************************************************************/
682 struct configuration_spec * load_config(void)
684 char buf[BUFFER_SIZE];
686 FILE *configfp = NULL;
687 struct configuration_spec * config = NULL;
688 struct client_state * fake_csp;
689 struct file_list *fs;
690 unsigned long linenum = 0;
692 char *logfile = NULL;
694 if ( !check_file_changed(current_configfile, configfile, &fs))
696 /* No need to load */
697 return ((struct configuration_spec *)current_configfile->f);
701 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
705 if (NULL != current_configfile)
707 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
710 #ifdef FEATURE_TOGGLE
711 global_toggle_state = 1;
712 #endif /* def FEATURE_TOGGLE */
714 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
720 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
721 /* Never get here - LOG_LEVEL_FATAL causes program exit */
725 * This is backwards from how it's usually done.
726 * Following the usual pattern, "fs" would be stored in a member
727 * variable in "csp", and then we'd access "config" from "fs->f",
728 * using a cast. However, "config" is used so often that a
729 * cast each time would be very ugly, and the extra indirection
730 * would waste CPU cycles. Therefore we store "config" in
731 * "csp->config", and "fs" in "csp->config->config_file_list".
733 config->config_file_list = fs;
738 config->multi_threaded = 1;
739 config->hport = HADDR_PORT;
740 config->buffer_limit = 4096 * 1024;
741 config->usermanual = strdup(USER_MANUAL_URL);
742 config->proxy_args = strdup("");
743 config->forwarded_connect_retries = 0;
744 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
745 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
746 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
748 if ((configfp = fopen(configfile, "r")) == NULL)
750 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
752 /* Never get here - LOG_LEVEL_FATAL causes program exit */
755 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
757 char cmd[BUFFER_SIZE];
758 char arg[BUFFER_SIZE];
759 char tmp[BUFFER_SIZE];
761 struct access_control_list *cur_acl;
762 #endif /* def FEATURE_ACL */
763 struct forward_spec *cur_fwd;
767 strlcpy(tmp, buf, sizeof(tmp));
769 /* Copy command (i.e. up to space or tab) into cmd */
772 while (*p && (*p != ' ') && (*p != '\t'))
778 /* Skip over the whitespace in buf */
779 while (*p && ((*p == ' ') || (*p == '\t')))
784 /* Copy the argument into arg */
785 strlcpy(arg, p, sizeof(arg));
787 /* Should never happen, but check this anyway */
793 /* Make sure the command field is lower case */
798 *p = (char)ijb_tolower(*p);
802 /* Save the argument for show-proxy-args */
803 savearg(cmd, arg, config);
806 switch( hash_string( cmd ) )
808 /* *************************************************************************
809 * actionsfile actions-file-name
810 * In confdir by default
811 * *************************************************************************/
812 case hash_actions_file :
814 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
819 if (i >= MAX_AF_FILES)
821 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
822 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
825 config->actions_file_short[i] = strdup(arg);
826 config->actions_file[i] = make_path(config->confdir, arg);
829 /* *************************************************************************
830 * accept-intercepted-requests
831 * *************************************************************************/
832 case hash_accept_intercepted_requests:
833 if ((*arg != '\0') && (0 != atoi(arg)))
835 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
839 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
843 /* *************************************************************************
844 * admin-address email-address
845 * *************************************************************************/
846 case hash_admin_address :
847 freez(config->admin_address);
848 config->admin_address = strdup(arg);
851 /* *************************************************************************
852 * allow-cgi-request-crunching
853 * *************************************************************************/
854 case hash_allow_cgi_request_crunching:
855 if ((*arg != '\0') && (0 != atoi(arg)))
857 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
861 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
865 /* *************************************************************************
867 * *************************************************************************/
868 case hash_buffer_limit :
869 config->buffer_limit = (size_t)(1024 * atoi(arg));
872 /* *************************************************************************
873 * confdir directory-name
874 * *************************************************************************/
876 freez(config->confdir);
877 config->confdir = make_path( NULL, arg);
880 /* *************************************************************************
882 * Specifies debug level, multiple values are ORed together.
883 * *************************************************************************/
885 config->debug |= atoi(arg);
888 /* *************************************************************************
889 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
890 * *************************************************************************/
892 case hash_deny_access:
893 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
895 if ((vec_count != 1) && (vec_count != 2))
897 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
898 "deny-access directive in configuration file.");
899 string_append(&config->proxy_args,
900 "<br>\nWARNING: Wrong number of parameters for "
901 "deny-access directive in configuration file.<br><br>\n");
905 /* allocate a new node */
906 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
910 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
911 /* Never get here - LOG_LEVEL_FATAL causes program exit */
914 cur_acl->action = ACL_DENY;
916 if (acl_addr(vec[0], cur_acl->src) < 0)
918 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
919 "for deny-access directive in configuration file: \"%s\"", vec[0]);
920 string_append(&config->proxy_args,
921 "<br>\nWARNING: Invalid source address, port or netmask "
922 "for deny-access directive in configuration file: \"");
923 string_append(&config->proxy_args,
925 string_append(&config->proxy_args,
932 if (acl_addr(vec[1], cur_acl->dst) < 0)
934 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
935 "for deny-access directive in configuration file: \"%s\"", vec[1]);
936 string_append(&config->proxy_args,
937 "<br>\nWARNING: Invalid destination address, port or netmask "
938 "for deny-access directive in configuration file: \"");
939 string_append(&config->proxy_args,
941 string_append(&config->proxy_args,
949 * Add it to the list. Note we reverse the list to get the
950 * behaviour the user expects. With both the ACL and
951 * actions file, the last match wins. However, the internal
952 * implementations are different: The actions file is stored
953 * in the same order as the file, and scanned completely.
954 * With the ACL, we reverse the order as we load it, then
955 * when we scan it we stop as soon as we get a match.
957 cur_acl->next = config->acl;
958 config->acl = cur_acl;
961 #endif /* def FEATURE_ACL */
963 /* *************************************************************************
964 * enable-edit-actions 0|1
965 * *************************************************************************/
966 #ifdef FEATURE_CGI_EDIT_ACTIONS
967 case hash_enable_edit_actions:
968 if ((*arg != '\0') && (0 != atoi(arg)))
970 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
974 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
977 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
979 /* *************************************************************************
980 * enable-remote-toggle 0|1
981 * *************************************************************************/
982 #ifdef FEATURE_CGI_EDIT_ACTIONS
983 case hash_enable_remote_toggle:
984 if ((*arg != '\0') && (0 != atoi(arg)))
986 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
990 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
993 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
995 /* *************************************************************************
996 * enable-remote-http-toggle 0|1
997 * *************************************************************************/
998 case hash_enable_remote_http_toggle:
999 if ((*arg != '\0') && (0 != atoi(arg)))
1001 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1005 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1009 /* *************************************************************************
1010 * hash_enforce_blocks 0|1
1011 * *************************************************************************/
1012 #ifdef FEATURE_FORCE_LOAD
1013 case hash_enforce_blocks:
1014 if ((*arg != '\0') && (0 != atoi(arg)))
1016 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1020 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1023 #endif /* def FEATURE_FORCE_LOAD */
1025 /* *************************************************************************
1026 * filterfile file-name
1027 * In confdir by default.
1028 * *************************************************************************/
1029 case hash_filterfile :
1031 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1036 if (i >= MAX_AF_FILES)
1038 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1039 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1042 config->re_filterfile_short[i] = strdup(arg);
1043 config->re_filterfile[i] = make_path(config->confdir, arg);
1047 /* *************************************************************************
1048 * forward url-pattern (.|http-proxy-host[:port])
1049 * *************************************************************************/
1051 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1055 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1056 "directive in configuration file.");
1057 string_append(&config->proxy_args,
1058 "<br>\nWARNING: Wrong number of parameters for "
1059 "forward directive in configuration file.");
1063 /* allocate a new node */
1064 cur_fwd = zalloc(sizeof(*cur_fwd));
1065 if (cur_fwd == NULL)
1067 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1068 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1072 cur_fwd->type = SOCKS_NONE;
1074 /* Save the URL pattern */
1075 if (create_url_spec(cur_fwd->url, vec[0]))
1077 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1078 "directive in configuration file.");
1079 string_append(&config->proxy_args,
1080 "<br>\nWARNING: Bad URL specifier for "
1081 "forward directive in configuration file.");
1085 /* Parse the parent HTTP proxy host:port */
1088 if (strcmp(p, ".") != 0)
1090 cur_fwd->forward_host = strdup(p);
1092 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1095 cur_fwd->forward_port = atoi(p);
1098 if (cur_fwd->forward_port <= 0)
1100 cur_fwd->forward_port = 8000;
1105 cur_fwd->next = config->forward;
1106 config->forward = cur_fwd;
1110 /* *************************************************************************
1111 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1112 * *************************************************************************/
1113 case hash_forward_socks4:
1114 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1118 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1119 "forward-socks4 directive in configuration file.");
1120 string_append(&config->proxy_args,
1121 "<br>\nWARNING: Wrong number of parameters for "
1122 "forward-socks4 directive in configuration file.");
1126 /* allocate a new node */
1127 cur_fwd = zalloc(sizeof(*cur_fwd));
1128 if (cur_fwd == NULL)
1130 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1131 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1135 cur_fwd->type = SOCKS_4;
1137 /* Save the URL pattern */
1138 if (create_url_spec(cur_fwd->url, vec[0]))
1140 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1141 "directive in configuration file.");
1142 string_append(&config->proxy_args,
1143 "<br>\nWARNING: Bad URL specifier for "
1144 "forward-socks4 directive in configuration file.");
1148 /* Parse the SOCKS proxy host[:port] */
1151 if (strcmp(p, ".") != 0)
1153 cur_fwd->gateway_host = strdup(p);
1155 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1158 cur_fwd->gateway_port = atoi(p);
1160 if (cur_fwd->gateway_port <= 0)
1162 cur_fwd->gateway_port = 1080;
1166 /* Parse the parent HTTP proxy host[:port] */
1169 if (strcmp(p, ".") != 0)
1171 cur_fwd->forward_host = strdup(p);
1173 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1176 cur_fwd->forward_port = atoi(p);
1179 if (cur_fwd->forward_port <= 0)
1181 cur_fwd->forward_port = 8000;
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 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1199 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1200 "forward-socks4a directive in configuration file.");
1201 string_append(&config->proxy_args,
1202 "<br>\nWARNING: Wrong number of parameters for "
1203 "forward-socks4a directive in configuration file.");
1207 /* allocate a new node */
1208 cur_fwd = zalloc(sizeof(*cur_fwd));
1209 if (cur_fwd == NULL)
1211 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1212 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1216 cur_fwd->type = SOCKS_4A;
1218 /* Save the URL pattern */
1219 if (create_url_spec(cur_fwd->url, vec[0]))
1221 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1222 "directive in configuration file.");
1223 string_append(&config->proxy_args,
1224 "<br>\nWARNING: Bad URL specifier for "
1225 "forward-socks4a directive in configuration file.");
1229 /* Parse the SOCKS proxy host[:port] */
1232 cur_fwd->gateway_host = strdup(p);
1234 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1237 cur_fwd->gateway_port = atoi(p);
1239 if (cur_fwd->gateway_port <= 0)
1241 cur_fwd->gateway_port = 1080;
1244 /* Parse the parent HTTP proxy host[:port] */
1247 if (strcmp(p, ".") != 0)
1249 cur_fwd->forward_host = strdup(p);
1251 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1254 cur_fwd->forward_port = atoi(p);
1257 if (cur_fwd->forward_port <= 0)
1259 cur_fwd->forward_port = 8000;
1264 cur_fwd->next = config->forward;
1265 config->forward = cur_fwd;
1269 /* *************************************************************************
1270 * forwarded-connect-retries n
1271 * *************************************************************************/
1272 case hash_forwarded_connect_retries :
1273 config->forwarded_connect_retries = atoi(arg);
1276 /* *************************************************************************
1277 * jarfile jar-file-name
1278 * In logdir by default
1279 * *************************************************************************/
1280 #ifdef FEATURE_COOKIE_JAR
1282 freez(config->jarfile);
1283 config->jarfile = make_path(config->logdir, arg);
1285 #endif /* def FEATURE_COOKIE_JAR */
1287 /* *************************************************************************
1288 * listen-address [ip][:port]
1289 * *************************************************************************/
1290 case hash_listen_address :
1291 freez(config->haddr);
1292 config->haddr = strdup(arg);
1295 /* *************************************************************************
1296 * logdir directory-name
1297 * *************************************************************************/
1299 freez(config->logdir);
1300 config->logdir = make_path(NULL, arg);
1303 /* *************************************************************************
1304 * logfile log-file-name
1305 * In logdir by default
1306 * *************************************************************************/
1310 logfile = make_path(config->logdir, arg);
1311 if (NULL == logfile)
1313 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1318 /* *************************************************************************
1319 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1320 * *************************************************************************/
1322 case hash_permit_access:
1323 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1325 if ((vec_count != 1) && (vec_count != 2))
1327 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1328 "permit-access directive in configuration file.");
1329 string_append(&config->proxy_args,
1330 "<br>\nWARNING: Wrong number of parameters for "
1331 "permit-access directive in configuration file.<br><br>\n");
1336 /* allocate a new node */
1337 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1339 if (cur_acl == NULL)
1341 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1342 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1345 cur_acl->action = ACL_PERMIT;
1347 if (acl_addr(vec[0], cur_acl->src) < 0)
1349 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1350 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1351 string_append(&config->proxy_args,
1352 "<br>\nWARNING: Invalid source address, port or netmask for "
1353 "permit-access directive in configuration file: \"");
1354 string_append(&config->proxy_args,
1356 string_append(&config->proxy_args,
1363 if (acl_addr(vec[1], cur_acl->dst) < 0)
1365 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1366 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1367 string_append(&config->proxy_args,
1368 "<br>\nWARNING: Invalid destination address, port or netmask for "
1369 "permit-access directive in configuration file: \"");
1370 string_append(&config->proxy_args,
1372 string_append(&config->proxy_args,
1380 * Add it to the list. Note we reverse the list to get the
1381 * behaviour the user expects. With both the ACL and
1382 * actions file, the last match wins. However, the internal
1383 * implementations are different: The actions file is stored
1384 * in the same order as the file, and scanned completely.
1385 * With the ACL, we reverse the order as we load it, then
1386 * when we scan it we stop as soon as we get a match.
1388 cur_acl->next = config->acl;
1389 config->acl = cur_acl;
1392 #endif /* def FEATURE_ACL */
1394 /* *************************************************************************
1395 * proxy-info-url url
1396 * *************************************************************************/
1397 case hash_proxy_info_url :
1398 freez(config->proxy_info_url);
1399 config->proxy_info_url = strdup(arg);
1402 /* *************************************************************************
1404 * *************************************************************************/
1405 case hash_single_threaded :
1406 config->multi_threaded = 0;
1409 /* *************************************************************************
1410 * split-large-cgi-forms
1411 * *************************************************************************/
1412 case hash_split_large_cgi_forms :
1413 if ((*arg != '\0') && (0 != atoi(arg)))
1415 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1419 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1423 /* *************************************************************************
1424 * templdir directory-name
1425 * *************************************************************************/
1426 case hash_templdir :
1427 freez(config->templdir);
1428 config->templdir = make_path(NULL, arg);
1431 /* *************************************************************************
1433 * *************************************************************************/
1434 #ifdef FEATURE_TOGGLE
1436 global_toggle_state = atoi(arg);
1438 #endif /* def FEATURE_TOGGLE */
1440 /* *************************************************************************
1441 * trust-info-url url
1442 * *************************************************************************/
1443 #ifdef FEATURE_TRUST
1444 case hash_trust_info_url :
1445 enlist(config->trust_info, arg);
1447 #endif /* def FEATURE_TRUST */
1449 /* *************************************************************************
1450 * trustfile filename
1451 * (In confdir by default.)
1452 * *************************************************************************/
1453 #ifdef FEATURE_TRUST
1454 case hash_trustfile :
1455 freez(config->trustfile);
1456 config->trustfile = make_path(config->confdir, arg);
1458 #endif /* def FEATURE_TRUST */
1460 /* *************************************************************************
1462 * *************************************************************************/
1463 case hash_usermanual :
1464 freez(config->usermanual);
1465 config->usermanual = strdup(arg);
1468 /* *************************************************************************
1469 * Win32 Console options:
1470 * *************************************************************************/
1472 /* *************************************************************************
1474 * *************************************************************************/
1476 case hash_hide_console :
1479 #endif /*def _WIN_CONSOLE*/
1482 /* *************************************************************************
1483 * Win32 GUI options:
1484 * *************************************************************************/
1486 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1487 /* *************************************************************************
1488 * activity-animation (0|1)
1489 * *************************************************************************/
1490 case hash_activity_animation :
1491 g_bShowActivityAnimation = atoi(arg);
1494 /* *************************************************************************
1495 * close-button-minimizes (0|1)
1496 * *************************************************************************/
1497 case hash_close_button_minimizes :
1498 g_bCloseHidesWindow = atoi(arg);
1501 /* *************************************************************************
1502 * log-buffer-size (0|1)
1503 * *************************************************************************/
1504 case hash_log_buffer_size :
1505 g_bLimitBufferSize = atoi(arg);
1508 /* *************************************************************************
1509 * log-font-name fontnane
1510 * *************************************************************************/
1511 case hash_log_font_name :
1512 strcpy( g_szFontFaceName, arg );
1515 /* *************************************************************************
1517 * *************************************************************************/
1518 case hash_log_font_size :
1519 g_nFontSize = atoi(arg);
1522 /* *************************************************************************
1523 * log-highlight-messages (0|1)
1524 * *************************************************************************/
1525 case hash_log_highlight_messages :
1526 g_bHighlightMessages = atoi(arg);
1529 /* *************************************************************************
1531 * *************************************************************************/
1532 case hash_log_max_lines :
1533 g_nMaxBufferLines = atoi(arg);
1536 /* *************************************************************************
1537 * log-messages (0|1)
1538 * *************************************************************************/
1539 case hash_log_messages :
1540 g_bLogMessages = atoi(arg);
1543 /* *************************************************************************
1544 * show-on-task-bar (0|1)
1545 * *************************************************************************/
1546 case hash_show_on_task_bar :
1547 g_bShowOnTaskBar = atoi(arg);
1550 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1553 /* *************************************************************************
1554 * Warnings about unsupported features
1555 * *************************************************************************/
1557 case hash_deny_access:
1558 #endif /* ndef FEATURE_ACL */
1559 #ifndef FEATURE_CGI_EDIT_ACTIONS
1560 case hash_enable_edit_actions:
1561 case hash_enable_remote_toggle:
1562 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1563 #ifndef FEATURE_COOKIE_JAR
1565 #endif /* ndef FEATURE_COOKIE_JAR */
1567 case hash_permit_access:
1568 #endif /* ndef FEATURE_ACL */
1569 #ifndef FEATURE_TOGGLE
1571 #endif /* ndef FEATURE_TOGGLE */
1572 #ifndef FEATURE_TRUST
1573 case hash_trustfile :
1574 case hash_trust_info_url :
1575 #endif /* ndef FEATURE_TRUST */
1577 #ifndef _WIN_CONSOLE
1578 case hash_hide_console :
1579 #endif /* ndef _WIN_CONSOLE */
1581 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1582 case hash_activity_animation :
1583 case hash_close_button_minimizes :
1584 case hash_log_buffer_size :
1585 case hash_log_font_name :
1586 case hash_log_font_size :
1587 case hash_log_highlight_messages :
1588 case hash_log_max_lines :
1589 case hash_log_messages :
1590 case hash_show_on_task_bar :
1591 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1592 /* These warnings are annoying - so hide them. -- Jon */
1593 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1596 /* *************************************************************************/
1598 /* *************************************************************************/
1600 * I decided that I liked this better as a warning than an
1601 * error. To change back to an error, just change log level
1602 * to LOG_LEVEL_FATAL.
1604 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1605 "in configuration file (%s).", buf, hash_string(cmd), linenum, configfile);
1606 string_append(&config->proxy_args,
1607 " <b><font color=\"red\">WARNING: unrecognized directive, ignored</font></b>");
1610 /* *************************************************************************/
1611 } /* end switch( hash_string(cmd) ) */
1612 } /* end while ( read_config_line(...) ) */
1616 set_debug_level(config->debug);
1618 freez(config->logfile);
1622 if (NULL != logfile)
1624 config->logfile = logfile;
1625 init_error_log(Argv[0], config->logfile);
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);