1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.69 2007/10/27 13:02:27 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.69 2007/10/27 13:02:27 fabiankeil
39 * Relocate daemon-mode-related log messages to make sure
40 * they aren't shown again in case of configuration reloads.
42 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
43 * Plug memory leak introduced with my last commit.
45 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
46 * When in daemon mode, close stderr after the configuration file has been
47 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
49 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
50 * #1763173 from Stefan Huehner: declare unload_configfile() static.
52 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
53 * As Hal noticed, checking dispatch_cgi() as the last cruncher
54 * looks like a bug if CGI requests are blocked unintentionally,
55 * so don't do it unless the user enabled the new config option
56 * "allow-cgi-request-crunching".
58 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
59 * - Use strlcpy() instead of strcpy().
60 * - Stop treating actions files special. Expect a complete file name
61 * (with or without path) like it's done for the rest of the files.
63 * - Remove an unnecessary temporary memory allocation.
64 * - Don't log anything to the console when running as
65 * daemon and no errors occurred.
67 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
68 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
70 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
71 * New config option: enforce-blocks.
73 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
74 * - Mention other reasons why acl directive loading might have failed.
75 * - Don't log the acl source if the acl destination is to blame.
77 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
78 * Add new config option "templdir" to
79 * change the templates directory.
81 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
82 * Added config option accept-intercepted-requests
83 * and disabled it by default.
85 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
86 * Fix gcc43 compiler warnings.
88 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
89 * Add config option "split-large-forms"
90 * to work around the browser bug reported
93 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
94 * Move the <br> in the generated HTML for the config
95 * options from the beginning of the string to its end.
96 * Keeps the white space in balance.
98 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
99 * Fix memory leak in case of config file reloads.
101 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
102 * Modified kludge for win32 to make ming32 menu
103 * "Options/Edit Filters" (sort of) work again.
104 * Same limitations as for the action files apply.
107 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
108 * Incorporate modified version of Roland Rosenfeld's patch to
109 * optionally access the user-manual via Privoxy. Closes patch 679075.
111 * Formatting changed to Privoxy style, added call to
112 * cgi_error_no_template if the requested file doesn't
113 * exist and modified check whether or not Privoxy itself
114 * should serve the manual. Should work cross-platform now.
116 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
117 * Added config option enable-remote-http-toggle
118 * to specify if Privoxy should recognize special
119 * headers (currently only X-Filter) to change its
120 * behaviour. Disabled by default.
122 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
123 * Make number of retries in case of forwarded-connect problems
124 * a config file option (forwarded-connect-retries) and use 0 as
127 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
128 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
129 * with what was really the latest development (the v_3_0_branch branch)
131 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
132 * Don't forget to malloc space for the null terminator...
134 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
135 * Multiple filter file support
137 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
138 * Closed two memory leaks; hopefully the last remaining ones
139 * (in the main execution paths, anyway).
141 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
142 * Addressed bug #719435
143 * - Extraneous filterfile directives now logged as errors
144 * - This and unrecnonised directives now really obvious on status page
146 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
147 * Cosmetic: Renamed cryptic variable
149 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
150 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
152 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
153 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
155 * Revision 1.48 2002/05/14 21:30:38 oes
156 * savearg now uses own linking code instead of (now special-cased) add_help_link
158 * Revision 1.47 2002/05/12 21:36:29 jongfoster
159 * Correcting function comments
161 * Revision 1.46 2002/04/26 12:55:14 oes
162 * - New option "user-manual", defaults to our site
163 * via project.h #define
164 * - savearg now embeds option names in help links
166 * Revision 1.45 2002/04/24 02:11:54 oes
167 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
169 * Revision 1.44 2002/04/08 20:37:13 swa
172 * Revision 1.43 2002/04/08 20:36:50 swa
175 * Revision 1.42 2002/04/05 15:50:15 oes
176 * fix for invalid HTML proxy_args
178 * Revision 1.41 2002/03/31 17:19:00 jongfoster
179 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
181 * Revision 1.40 2002/03/26 22:29:55 swa
182 * we have a new homepage!
184 * Revision 1.39 2002/03/24 13:25:43 swa
185 * name change related issues
187 * Revision 1.38 2002/03/24 13:05:48 jongfoster
188 * Renaming re_filterfile to filterfile
190 * Revision 1.37 2002/03/16 23:54:06 jongfoster
191 * Adding graceful termination feature, to help look for memory leaks.
192 * If you enable this (which, by design, has to be done by hand
193 * editing config.h) and then go to http://i.j.b/die, then the program
194 * will exit cleanly after the *next* request. It should free all the
195 * memory that was used.
197 * Revision 1.36 2002/03/13 00:27:05 jongfoster
200 * Revision 1.35 2002/03/07 03:52:44 oes
201 * Set logging to tty for --no-daemon mode
203 * Revision 1.34 2002/03/06 23:14:35 jongfoster
204 * Trivial cosmetic changes to make function comments easier to find.
206 * Revision 1.33 2002/03/05 04:52:42 oes
207 * Deleted non-errlog debugging code
209 * Revision 1.32 2002/03/04 18:24:53 oes
210 * Re-enabled output of unknown config directive hash
212 * Revision 1.31 2002/03/03 15:07:20 oes
213 * Re-enabled automatic config reloading
215 * Revision 1.30 2002/01/22 23:31:43 jongfoster
216 * Replacing strsav() with string_append()
218 * Revision 1.29 2002/01/17 21:02:30 jongfoster
219 * Moving all our URL and URL pattern parsing code to urlmatch.c.
221 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
223 * Revision 1.28 2001/12/30 14:07:32 steudten
224 * - Add signal handling (unix)
225 * - Add SIGHUP handler (unix)
226 * - Add creation of pidfile (unix)
227 * - Add action 'top' in rc file (RH)
228 * - Add entry 'SIGNALS' to manpage
229 * - Add exit message to logfile (unix)
231 * Revision 1.27 2001/11/07 00:02:13 steudten
232 * Add line number in error output for lineparsing for
233 * actionsfile and configfile.
234 * Special handling for CLF added.
236 * Revision 1.26 2001/11/05 21:41:43 steudten
237 * Add changes to be a real daemon just for unix os.
238 * (change cwd to /, detach from controlling tty, set
239 * process group and session leader to the own process.
241 * Add some fatal-error log message for failed malloc().
242 * Add '-d' if compiled with 'configure --with-debug' to
243 * enable debug output.
245 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
246 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
247 * threads to call select() simultaneously. So, it's time to do a real, live,
248 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
249 * (native). Both versions will work, but using __OS2__ offers multi-threading.
251 * Revision 1.24 2001/10/23 21:40:30 jongfoster
252 * Added support for enable-edit-actions and enable-remote-toggle config
255 * Revision 1.23 2001/10/07 15:36:00 oes
256 * Introduced new config option "buffer-limit"
258 * Revision 1.22 2001/09/22 16:36:59 jongfoster
259 * Removing unused parameter fs from read_config_line()
261 * Revision 1.21 2001/09/16 17:10:43 jongfoster
262 * Moving function savearg() here, since it was the only thing left in
265 * Revision 1.20 2001/07/30 22:08:36 jongfoster
266 * Tidying up #defines:
267 * - All feature #defines are now of the form FEATURE_xxx
268 * - Permanently turned off WIN_GUI_EDIT
269 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
271 * Revision 1.19 2001/07/15 17:45:16 jongfoster
272 * Removing some unused #includes
274 * Revision 1.18 2001/07/13 14:01:14 oes
275 * - Removed all #ifdef PCRS
276 * - Removed vim-settings
278 * Revision 1.17 2001/06/29 13:31:03 oes
279 * - Improved comments
280 * - Fixed (actionsfile) and sorted hashes
281 * - Introduced admin_address and proxy-info-url
282 * as config parameters
283 * - Renamed config->proxy_args_invocation (which didn't have
284 * the invocation but the options!) to config->proxy_args
285 * - Various adaptions
286 * - Removed logentry from cancelled commit
288 * Revision 1.16 2001/06/09 10:55:28 jongfoster
289 * Changing BUFSIZ ==> BUFFER_SIZE
291 * Revision 1.15 2001/06/07 23:13:40 jongfoster
292 * Merging ACL and forward files into config file.
293 * Cosmetic: Sorting config file options alphabetically.
294 * Cosmetic: Adding brief syntax comments to config file options.
296 * Revision 1.14 2001/06/07 14:46:25 joergs
297 * Missing make_path() added for re_filterfile.
299 * Revision 1.13 2001/06/05 22:33:54 jongfoster
301 * Fixed minor memory leak.
302 * Also now uses make_path to prepend the pathnames.
304 * Revision 1.12 2001/06/05 20:04:09 jongfoster
305 * Now uses _snprintf() in place of snprintf() under Win32.
307 * Revision 1.11 2001/06/04 18:31:58 swa
308 * files are now prefixed with either `confdir' or `logdir'.
309 * `make redhat-dist' replaces both entries confdir and logdir
312 * Revision 1.10 2001/06/03 19:11:54 oes
313 * introduced confdir option
315 * Revision 1.9 2001/06/01 20:06:24 jongfoster
316 * Removed support for "tinygif" option - moved to actions file.
318 * Revision 1.8 2001/05/31 21:27:13 jongfoster
319 * Removed many options from the config file and into the
320 * "actions" file: add_forwarded, suppress_vanilla_wafer,
321 * wafer, add_header, user_agent, referer, from
322 * Also globally replaced "permission" with "action".
324 * Revision 1.7 2001/05/29 09:50:24 jongfoster
325 * Unified blocklist/imagelist/permissionslist.
326 * File format is still under discussion, but the internal changes
329 * Also modified interceptor behaviour:
330 * - We now intercept all URLs beginning with one of the following
331 * prefixes (and *only* these prefixes):
333 * * http://ijbswa.sf.net/config/
334 * * http://ijbswa.sourceforge.net/config/
335 * - New interceptors "home page" - go to http://i.j.b/ to see it.
336 * - Internal changes so that intercepted and fast redirect pages
337 * are not replaced with an image.
338 * - Interceptors now have the option to send a binary page direct
339 * to the client. (i.e. ijb-send-banner uses this)
340 * - Implemented show-url-info interceptor. (Which is why I needed
341 * the above interceptors changes - a typical URL is
342 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
343 * The previous mechanism would not have intercepted that, and
344 * if it had been intercepted then it then it would have replaced
347 * Revision 1.6 2001/05/26 00:28:36 jongfoster
348 * Automatic reloading of config file.
349 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
350 * Most of the global variables have been moved to a new
351 * struct configuration_spec, accessed through csp->config->globalname
352 * Most of the globals remaining are used by the Win32 GUI.
354 * Revision 1.5 2001/05/25 22:34:30 jongfoster
357 * Revision 1.4 2001/05/22 18:46:04 oes
359 * - Enabled filtering banners by size rather than URL
360 * by adding patterns that replace all standard banner
361 * sizes with the "Junkbuster" gif to the re_filterfile
363 * - Enabled filtering WebBugs by providing a pattern
364 * which kills all 1x1 images
366 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
367 * which is selected by the (nonstandard and therefore
368 * capital) letter 'U' in the option string.
369 * It causes the quantifiers to be ungreedy by default.
370 * Appending a ? turns back to greedy (!).
372 * - Added a new interceptor ijb-send-banner, which
373 * sends back the "Junkbuster" gif. Without imagelist or
374 * MSIE detection support, or if tinygif = 1, or the
375 * URL isn't recognized as an imageurl, a lame HTML
376 * explanation is sent instead.
378 * - Added new feature, which permits blocking remote
379 * script redirects and firing back a local redirect
381 * The feature is conditionally compiled, i.e. it
382 * can be disabled with --disable-fast-redirects,
383 * plus it must be activated by a "fast-redirects"
384 * line in the config file, has its own log level
385 * and of course wants to be displayed by show-proxy-args
386 * Note: Boy, all the #ifdefs in 1001 locations and
387 * all the fumbling with configure.in and acconfig.h
388 * were *way* more work than the feature itself :-(
390 * - Because a generic redirect template was needed for
391 * this, tinygif = 3 now uses the same.
393 * - Moved GIFs, and other static HTTP response templates
398 * - Removed some >400 CRs again (Jon, you really worked
401 * Revision 1.3 2001/05/20 01:21:20 jongfoster
402 * Version 2.9.4 checkin.
403 * - Merged popupfile and cookiefile, and added control over PCRS
404 * filtering, in new "permissionsfile".
405 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
406 * file error you now get a message box (in the Win32 GUI) rather
407 * than the program exiting with no explanation.
408 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
410 * - Removed tabs from "config"
411 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
412 * - Bumped up version number.
414 * Revision 1.2 2001/05/17 23:01:01 oes
415 * - Cleaned CRLF's from the sources and related files
417 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
418 * Initial import of version 2.9.3 source tree
421 *********************************************************************/
427 #include <sys/types.h>
441 # include <windows.h>
444 # ifndef _WIN_CONSOLE
446 # endif /* ndef _WIN_CONSOLE */
448 #else /* ifndef _WIN32 */
452 # include <sys/wait.h>
454 # include <sys/time.h>
455 # include <sys/stat.h>
465 #include "miscutil.h"
469 #include "urlmatch.h"
472 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
475 * Fix a problem with Solaris. There should be no effect on other
477 * Solaris's isspace() is a macro which uses it's argument directly
478 * as an array index. Therefore we need to make sure that high-bit
479 * characters generate +ve values, and ideally we also want to make
480 * the argument match the declared parameter type of "int".
482 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
483 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
485 #ifdef FEATURE_TOGGLE
486 /* Privoxy is enabled by default. */
487 int global_toggle_state = 1;
488 #endif /* def FEATURE_TOGGLE */
490 /* The filename of the configfile */
491 const char *configfile = NULL;
494 * CGI functions will later need access to the invocation args,
495 * so we will make argc and argv global.
498 const char **Argv = NULL;
500 static struct file_list *current_configfile = NULL;
504 * This takes the "cryptic" hash of each keyword and aliases them to
505 * something a little more readable. This also makes changing the
506 * hash values easier if they should change or the hash algorthm changes.
507 * Use the included "hash" program to find out what the hash will be
508 * for any string supplied on the command line. (Or just put it in the
509 * config file and read the number from the error message in the log).
511 * Please keep this list sorted alphabetically (but with the Windows
512 * console and GUI specific options last).
515 #define hash_actions_file 1196306641ul /* "actionsfile" */
516 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
517 #define hash_admin_address 4112573064ul /* "admin-address" */
518 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
519 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
520 #define hash_confdir 1978389ul /* "confdir" */
521 #define hash_debug 78263ul /* "debug" */
522 #define hash_deny_access 1227333715ul /* "deny-access" */
523 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
524 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
525 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
526 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
527 #define hash_filterfile 250887266ul /* "filterfile" */
528 #define hash_forward 2029845ul /* "forward" */
529 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
530 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
531 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
532 #define hash_jarfile 2046641ul /* "jarfile" */
533 #define hash_listen_address 1255650842ul /* "listen-address" */
534 #define hash_logdir 422889ul /* "logdir" */
535 #define hash_logfile 2114766ul /* "logfile" */
536 #define hash_permit_access 3587953268ul /* "permit-access" */
537 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
538 #define hash_single_threaded 4250084780ul /* "single-threaded" */
539 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
540 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
541 #define hash_templdir 11067889ul /* "templdir" */
542 #define hash_toggle 447966ul /* "toggle" */
543 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
544 #define hash_trustfile 56494766ul /* "trustfile" */
545 #define hash_usermanual 1416668518ul /* "user-manual" */
546 #define hash_activity_animation 1817904738ul /* "activity-animation" */
547 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
548 #define hash_hide_console 2048809870ul /* "hide-console" */
549 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
550 #define hash_log_font_name 2866730124ul /* "log-font-name" */
551 #define hash_log_font_size 2866731014ul /* "log-font-size" */
552 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
553 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
554 #define hash_log_messages 2291744899ul /* "log-messages" */
555 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
558 static void savearg(char *command, char *argument, struct configuration_spec * config);
560 /*********************************************************************
562 * Function : unload_configfile
564 * Description : Free the config structure and all components.
567 * 1 : data: struct configuration_spec to unload
571 *********************************************************************/
572 static void unload_configfile (void * data)
574 struct configuration_spec * config = (struct configuration_spec *)data;
575 struct forward_spec *cur_fwd = config->forward;
579 struct access_control_list *cur_acl = config->acl;
581 while (cur_acl != NULL)
583 struct access_control_list * next_acl = cur_acl->next;
588 #endif /* def FEATURE_ACL */
590 while (cur_fwd != NULL)
592 struct forward_spec * next_fwd = cur_fwd->next;
593 free_url_spec(cur_fwd->url);
595 freez(cur_fwd->gateway_host);
596 freez(cur_fwd->forward_host);
600 config->forward = NULL;
602 #ifdef FEATURE_COOKIE_JAR
603 if ( NULL != config->jar )
605 fclose( config->jar );
608 #endif /* def FEATURE_COOKIE_JAR */
610 freez(config->confdir);
611 freez(config->logdir);
612 freez(config->templdir);
614 freez(config->haddr);
615 freez(config->logfile);
617 for (i = 0; i < MAX_AF_FILES; i++)
619 freez(config->actions_file_short[i]);
620 freez(config->actions_file[i]);
621 freez(config->re_filterfile_short[i]);
622 freez(config->re_filterfile[i]);
625 freez(config->admin_address);
626 freez(config->proxy_info_url);
627 freez(config->proxy_args);
628 freez(config->usermanual);
630 #ifdef FEATURE_COOKIE_JAR
631 freez(config->jarfile);
632 #endif /* def FEATURE_COOKIE_JAR */
635 freez(config->trustfile);
636 list_remove_all(config->trust_info);
637 #endif /* def FEATURE_TRUST */
639 for (i = 0; i < MAX_AF_FILES; i++)
641 freez(config->re_filterfile[i]);
648 #ifdef FEATURE_GRACEFUL_TERMINATION
649 /*********************************************************************
651 * Function : unload_current_config_file
653 * Description : Unloads current config file - reset to state at
654 * beginning of program.
660 *********************************************************************/
661 void unload_current_config_file(void)
663 if (current_configfile)
665 current_configfile->unloader = unload_configfile;
666 current_configfile = NULL;
672 /*********************************************************************
674 * Function : load_config
676 * Description : Load the config file and all parameters.
678 * XXX: more than thousand lines long
679 * and thus in serious need of refactoring.
683 * Returns : The configuration_spec, or NULL on error.
685 *********************************************************************/
686 struct configuration_spec * load_config(void)
688 char buf[BUFFER_SIZE];
690 FILE *configfp = NULL;
691 struct configuration_spec * config = NULL;
692 struct client_state * fake_csp;
693 struct file_list *fs;
694 unsigned long linenum = 0;
696 char *logfile = NULL;
698 if ( !check_file_changed(current_configfile, configfile, &fs))
700 /* No need to load */
701 return ((struct configuration_spec *)current_configfile->f);
705 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
709 if (NULL != current_configfile)
711 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
714 #ifdef FEATURE_TOGGLE
715 global_toggle_state = 1;
716 #endif /* def FEATURE_TOGGLE */
718 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
724 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
725 /* Never get here - LOG_LEVEL_FATAL causes program exit */
729 * This is backwards from how it's usually done.
730 * Following the usual pattern, "fs" would be stored in a member
731 * variable in "csp", and then we'd access "config" from "fs->f",
732 * using a cast. However, "config" is used so often that a
733 * cast each time would be very ugly, and the extra indirection
734 * would waste CPU cycles. Therefore we store "config" in
735 * "csp->config", and "fs" in "csp->config->config_file_list".
737 config->config_file_list = fs;
742 config->multi_threaded = 1;
743 config->hport = HADDR_PORT;
744 config->buffer_limit = 4096 * 1024;
745 config->usermanual = strdup(USER_MANUAL_URL);
746 config->proxy_args = strdup("");
747 config->forwarded_connect_retries = 0;
748 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
749 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
750 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
752 if ((configfp = fopen(configfile, "r")) == NULL)
754 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
756 /* Never get here - LOG_LEVEL_FATAL causes program exit */
759 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
761 char cmd[BUFFER_SIZE];
762 char arg[BUFFER_SIZE];
763 char tmp[BUFFER_SIZE];
765 struct access_control_list *cur_acl;
766 #endif /* def FEATURE_ACL */
767 struct forward_spec *cur_fwd;
771 strlcpy(tmp, buf, sizeof(tmp));
773 /* Copy command (i.e. up to space or tab) into cmd */
776 while (*p && (*p != ' ') && (*p != '\t'))
782 /* Skip over the whitespace in buf */
783 while (*p && ((*p == ' ') || (*p == '\t')))
788 /* Copy the argument into arg */
789 strlcpy(arg, p, sizeof(arg));
791 /* Should never happen, but check this anyway */
797 /* Make sure the command field is lower case */
802 *p = (char)ijb_tolower(*p);
806 /* Save the argument for show-proxy-args */
807 savearg(cmd, arg, config);
810 switch( hash_string( cmd ) )
812 /* *************************************************************************
813 * actionsfile actions-file-name
814 * In confdir by default
815 * *************************************************************************/
816 case hash_actions_file :
818 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
823 if (i >= MAX_AF_FILES)
825 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
826 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
829 config->actions_file_short[i] = strdup(arg);
830 config->actions_file[i] = make_path(config->confdir, arg);
833 /* *************************************************************************
834 * accept-intercepted-requests
835 * *************************************************************************/
836 case hash_accept_intercepted_requests:
837 if ((*arg != '\0') && (0 != atoi(arg)))
839 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
843 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
847 /* *************************************************************************
848 * admin-address email-address
849 * *************************************************************************/
850 case hash_admin_address :
851 freez(config->admin_address);
852 config->admin_address = strdup(arg);
855 /* *************************************************************************
856 * allow-cgi-request-crunching
857 * *************************************************************************/
858 case hash_allow_cgi_request_crunching:
859 if ((*arg != '\0') && (0 != atoi(arg)))
861 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
865 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
869 /* *************************************************************************
871 * *************************************************************************/
872 case hash_buffer_limit :
873 config->buffer_limit = (size_t)(1024 * atoi(arg));
876 /* *************************************************************************
877 * confdir directory-name
878 * *************************************************************************/
880 freez(config->confdir);
881 config->confdir = make_path( NULL, arg);
884 /* *************************************************************************
886 * Specifies debug level, multiple values are ORed together.
887 * *************************************************************************/
889 config->debug |= atoi(arg);
892 /* *************************************************************************
893 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
894 * *************************************************************************/
896 case hash_deny_access:
897 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
899 if ((vec_count != 1) && (vec_count != 2))
901 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
902 "deny-access directive in configuration file.");
903 string_append(&config->proxy_args,
904 "<br>\nWARNING: Wrong number of parameters for "
905 "deny-access directive in configuration file.<br><br>\n");
909 /* allocate a new node */
910 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
914 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
915 /* Never get here - LOG_LEVEL_FATAL causes program exit */
918 cur_acl->action = ACL_DENY;
920 if (acl_addr(vec[0], cur_acl->src) < 0)
922 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
923 "for deny-access directive in configuration file: \"%s\"", vec[0]);
924 string_append(&config->proxy_args,
925 "<br>\nWARNING: Invalid source address, port or netmask "
926 "for deny-access directive in configuration file: \"");
927 string_append(&config->proxy_args,
929 string_append(&config->proxy_args,
936 if (acl_addr(vec[1], cur_acl->dst) < 0)
938 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
939 "for deny-access directive in configuration file: \"%s\"", vec[1]);
940 string_append(&config->proxy_args,
941 "<br>\nWARNING: Invalid destination address, port or netmask "
942 "for deny-access directive in configuration file: \"");
943 string_append(&config->proxy_args,
945 string_append(&config->proxy_args,
953 * Add it to the list. Note we reverse the list to get the
954 * behaviour the user expects. With both the ACL and
955 * actions file, the last match wins. However, the internal
956 * implementations are different: The actions file is stored
957 * in the same order as the file, and scanned completely.
958 * With the ACL, we reverse the order as we load it, then
959 * when we scan it we stop as soon as we get a match.
961 cur_acl->next = config->acl;
962 config->acl = cur_acl;
965 #endif /* def FEATURE_ACL */
967 /* *************************************************************************
968 * enable-edit-actions 0|1
969 * *************************************************************************/
970 #ifdef FEATURE_CGI_EDIT_ACTIONS
971 case hash_enable_edit_actions:
972 if ((*arg != '\0') && (0 != atoi(arg)))
974 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
978 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
981 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
983 /* *************************************************************************
984 * enable-remote-toggle 0|1
985 * *************************************************************************/
986 #ifdef FEATURE_CGI_EDIT_ACTIONS
987 case hash_enable_remote_toggle:
988 if ((*arg != '\0') && (0 != atoi(arg)))
990 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
994 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
997 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
999 /* *************************************************************************
1000 * enable-remote-http-toggle 0|1
1001 * *************************************************************************/
1002 case hash_enable_remote_http_toggle:
1003 if ((*arg != '\0') && (0 != atoi(arg)))
1005 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1009 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1013 /* *************************************************************************
1014 * hash_enforce_blocks 0|1
1015 * *************************************************************************/
1016 #ifdef FEATURE_FORCE_LOAD
1017 case hash_enforce_blocks:
1018 if ((*arg != '\0') && (0 != atoi(arg)))
1020 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1024 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1027 #endif /* def FEATURE_FORCE_LOAD */
1029 /* *************************************************************************
1030 * filterfile file-name
1031 * In confdir by default.
1032 * *************************************************************************/
1033 case hash_filterfile :
1035 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1040 if (i >= MAX_AF_FILES)
1042 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1043 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1046 config->re_filterfile_short[i] = strdup(arg);
1047 config->re_filterfile[i] = make_path(config->confdir, arg);
1051 /* *************************************************************************
1052 * forward url-pattern (.|http-proxy-host[:port])
1053 * *************************************************************************/
1055 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1059 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1060 "directive in configuration file.");
1061 string_append(&config->proxy_args,
1062 "<br>\nWARNING: Wrong number of parameters for "
1063 "forward directive in configuration file.");
1067 /* allocate a new node */
1068 cur_fwd = zalloc(sizeof(*cur_fwd));
1069 if (cur_fwd == NULL)
1071 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1072 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1076 cur_fwd->type = SOCKS_NONE;
1078 /* Save the URL pattern */
1079 if (create_url_spec(cur_fwd->url, vec[0]))
1081 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1082 "directive in configuration file.");
1083 string_append(&config->proxy_args,
1084 "<br>\nWARNING: Bad URL specifier for "
1085 "forward directive in configuration file.");
1089 /* Parse the parent HTTP proxy host:port */
1092 if (strcmp(p, ".") != 0)
1094 cur_fwd->forward_host = strdup(p);
1096 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1099 cur_fwd->forward_port = atoi(p);
1102 if (cur_fwd->forward_port <= 0)
1104 cur_fwd->forward_port = 8000;
1109 cur_fwd->next = config->forward;
1110 config->forward = cur_fwd;
1114 /* *************************************************************************
1115 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1116 * *************************************************************************/
1117 case hash_forward_socks4:
1118 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1122 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1123 "forward-socks4 directive in configuration file.");
1124 string_append(&config->proxy_args,
1125 "<br>\nWARNING: Wrong number of parameters for "
1126 "forward-socks4 directive in configuration file.");
1130 /* allocate a new node */
1131 cur_fwd = zalloc(sizeof(*cur_fwd));
1132 if (cur_fwd == NULL)
1134 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1135 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1139 cur_fwd->type = SOCKS_4;
1141 /* Save the URL pattern */
1142 if (create_url_spec(cur_fwd->url, vec[0]))
1144 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1145 "directive in configuration file.");
1146 string_append(&config->proxy_args,
1147 "<br>\nWARNING: Bad URL specifier for "
1148 "forward-socks4 directive in configuration file.");
1152 /* Parse the SOCKS proxy host[:port] */
1155 if (strcmp(p, ".") != 0)
1157 cur_fwd->gateway_host = strdup(p);
1159 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1162 cur_fwd->gateway_port = atoi(p);
1164 if (cur_fwd->gateway_port <= 0)
1166 cur_fwd->gateway_port = 1080;
1170 /* Parse the parent HTTP proxy host[:port] */
1173 if (strcmp(p, ".") != 0)
1175 cur_fwd->forward_host = strdup(p);
1177 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1180 cur_fwd->forward_port = atoi(p);
1183 if (cur_fwd->forward_port <= 0)
1185 cur_fwd->forward_port = 8000;
1190 cur_fwd->next = config->forward;
1191 config->forward = cur_fwd;
1195 /* *************************************************************************
1196 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1197 * *************************************************************************/
1198 case hash_forward_socks4a:
1199 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1203 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1204 "forward-socks4a directive in configuration file.");
1205 string_append(&config->proxy_args,
1206 "<br>\nWARNING: Wrong number of parameters for "
1207 "forward-socks4a directive in configuration file.");
1211 /* allocate a new node */
1212 cur_fwd = zalloc(sizeof(*cur_fwd));
1213 if (cur_fwd == NULL)
1215 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1216 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1220 cur_fwd->type = SOCKS_4A;
1222 /* Save the URL pattern */
1223 if (create_url_spec(cur_fwd->url, vec[0]))
1225 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1226 "directive in configuration file.");
1227 string_append(&config->proxy_args,
1228 "<br>\nWARNING: Bad URL specifier for "
1229 "forward-socks4a directive in configuration file.");
1233 /* Parse the SOCKS proxy host[:port] */
1236 cur_fwd->gateway_host = strdup(p);
1238 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1241 cur_fwd->gateway_port = atoi(p);
1243 if (cur_fwd->gateway_port <= 0)
1245 cur_fwd->gateway_port = 1080;
1248 /* Parse the parent HTTP proxy host[:port] */
1251 if (strcmp(p, ".") != 0)
1253 cur_fwd->forward_host = strdup(p);
1255 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1258 cur_fwd->forward_port = atoi(p);
1261 if (cur_fwd->forward_port <= 0)
1263 cur_fwd->forward_port = 8000;
1268 cur_fwd->next = config->forward;
1269 config->forward = cur_fwd;
1273 /* *************************************************************************
1274 * forwarded-connect-retries n
1275 * *************************************************************************/
1276 case hash_forwarded_connect_retries :
1277 config->forwarded_connect_retries = atoi(arg);
1280 /* *************************************************************************
1281 * jarfile jar-file-name
1282 * In logdir by default
1283 * *************************************************************************/
1284 #ifdef FEATURE_COOKIE_JAR
1286 freez(config->jarfile);
1287 config->jarfile = make_path(config->logdir, arg);
1289 #endif /* def FEATURE_COOKIE_JAR */
1291 /* *************************************************************************
1292 * listen-address [ip][:port]
1293 * *************************************************************************/
1294 case hash_listen_address :
1295 freez(config->haddr);
1296 config->haddr = strdup(arg);
1299 /* *************************************************************************
1300 * logdir directory-name
1301 * *************************************************************************/
1303 freez(config->logdir);
1304 config->logdir = make_path(NULL, arg);
1307 /* *************************************************************************
1308 * logfile log-file-name
1309 * In logdir by default
1310 * *************************************************************************/
1314 logfile = make_path(config->logdir, arg);
1315 if (NULL == logfile)
1317 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1322 /* *************************************************************************
1323 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1324 * *************************************************************************/
1326 case hash_permit_access:
1327 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1329 if ((vec_count != 1) && (vec_count != 2))
1331 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1332 "permit-access directive in configuration file.");
1333 string_append(&config->proxy_args,
1334 "<br>\nWARNING: Wrong number of parameters for "
1335 "permit-access directive in configuration file.<br><br>\n");
1340 /* allocate a new node */
1341 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1343 if (cur_acl == NULL)
1345 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1346 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1349 cur_acl->action = ACL_PERMIT;
1351 if (acl_addr(vec[0], cur_acl->src) < 0)
1353 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1354 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1355 string_append(&config->proxy_args,
1356 "<br>\nWARNING: Invalid source address, port or netmask for "
1357 "permit-access directive in configuration file: \"");
1358 string_append(&config->proxy_args,
1360 string_append(&config->proxy_args,
1367 if (acl_addr(vec[1], cur_acl->dst) < 0)
1369 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1370 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1371 string_append(&config->proxy_args,
1372 "<br>\nWARNING: Invalid destination address, port or netmask for "
1373 "permit-access directive in configuration file: \"");
1374 string_append(&config->proxy_args,
1376 string_append(&config->proxy_args,
1384 * Add it to the list. Note we reverse the list to get the
1385 * behaviour the user expects. With both the ACL and
1386 * actions file, the last match wins. However, the internal
1387 * implementations are different: The actions file is stored
1388 * in the same order as the file, and scanned completely.
1389 * With the ACL, we reverse the order as we load it, then
1390 * when we scan it we stop as soon as we get a match.
1392 cur_acl->next = config->acl;
1393 config->acl = cur_acl;
1396 #endif /* def FEATURE_ACL */
1398 /* *************************************************************************
1399 * proxy-info-url url
1400 * *************************************************************************/
1401 case hash_proxy_info_url :
1402 freez(config->proxy_info_url);
1403 config->proxy_info_url = strdup(arg);
1406 /* *************************************************************************
1408 * *************************************************************************/
1409 case hash_single_threaded :
1410 config->multi_threaded = 0;
1413 /* *************************************************************************
1414 * split-large-cgi-forms
1415 * *************************************************************************/
1416 case hash_split_large_cgi_forms :
1417 if ((*arg != '\0') && (0 != atoi(arg)))
1419 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1423 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1427 /* *************************************************************************
1428 * templdir directory-name
1429 * *************************************************************************/
1430 case hash_templdir :
1431 freez(config->templdir);
1432 config->templdir = make_path(NULL, arg);
1435 /* *************************************************************************
1437 * *************************************************************************/
1438 #ifdef FEATURE_TOGGLE
1440 global_toggle_state = atoi(arg);
1442 #endif /* def FEATURE_TOGGLE */
1444 /* *************************************************************************
1445 * trust-info-url url
1446 * *************************************************************************/
1447 #ifdef FEATURE_TRUST
1448 case hash_trust_info_url :
1449 enlist(config->trust_info, arg);
1451 #endif /* def FEATURE_TRUST */
1453 /* *************************************************************************
1454 * trustfile filename
1455 * (In confdir by default.)
1456 * *************************************************************************/
1457 #ifdef FEATURE_TRUST
1458 case hash_trustfile :
1459 freez(config->trustfile);
1460 config->trustfile = make_path(config->confdir, arg);
1462 #endif /* def FEATURE_TRUST */
1464 /* *************************************************************************
1466 * *************************************************************************/
1467 case hash_usermanual :
1468 freez(config->usermanual);
1469 config->usermanual = strdup(arg);
1472 /* *************************************************************************
1473 * Win32 Console options:
1474 * *************************************************************************/
1476 /* *************************************************************************
1478 * *************************************************************************/
1480 case hash_hide_console :
1483 #endif /*def _WIN_CONSOLE*/
1486 /* *************************************************************************
1487 * Win32 GUI options:
1488 * *************************************************************************/
1490 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1491 /* *************************************************************************
1492 * activity-animation (0|1)
1493 * *************************************************************************/
1494 case hash_activity_animation :
1495 g_bShowActivityAnimation = atoi(arg);
1498 /* *************************************************************************
1499 * close-button-minimizes (0|1)
1500 * *************************************************************************/
1501 case hash_close_button_minimizes :
1502 g_bCloseHidesWindow = atoi(arg);
1505 /* *************************************************************************
1506 * log-buffer-size (0|1)
1507 * *************************************************************************/
1508 case hash_log_buffer_size :
1509 g_bLimitBufferSize = atoi(arg);
1512 /* *************************************************************************
1513 * log-font-name fontnane
1514 * *************************************************************************/
1515 case hash_log_font_name :
1516 strcpy( g_szFontFaceName, arg );
1519 /* *************************************************************************
1521 * *************************************************************************/
1522 case hash_log_font_size :
1523 g_nFontSize = atoi(arg);
1526 /* *************************************************************************
1527 * log-highlight-messages (0|1)
1528 * *************************************************************************/
1529 case hash_log_highlight_messages :
1530 g_bHighlightMessages = atoi(arg);
1533 /* *************************************************************************
1535 * *************************************************************************/
1536 case hash_log_max_lines :
1537 g_nMaxBufferLines = atoi(arg);
1540 /* *************************************************************************
1541 * log-messages (0|1)
1542 * *************************************************************************/
1543 case hash_log_messages :
1544 g_bLogMessages = atoi(arg);
1547 /* *************************************************************************
1548 * show-on-task-bar (0|1)
1549 * *************************************************************************/
1550 case hash_show_on_task_bar :
1551 g_bShowOnTaskBar = atoi(arg);
1554 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1557 /* *************************************************************************
1558 * Warnings about unsupported features
1559 * *************************************************************************/
1561 case hash_deny_access:
1562 #endif /* ndef FEATURE_ACL */
1563 #ifndef FEATURE_CGI_EDIT_ACTIONS
1564 case hash_enable_edit_actions:
1565 case hash_enable_remote_toggle:
1566 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1567 #ifndef FEATURE_COOKIE_JAR
1569 #endif /* ndef FEATURE_COOKIE_JAR */
1571 case hash_permit_access:
1572 #endif /* ndef FEATURE_ACL */
1573 #ifndef FEATURE_TOGGLE
1575 #endif /* ndef FEATURE_TOGGLE */
1576 #ifndef FEATURE_TRUST
1577 case hash_trustfile :
1578 case hash_trust_info_url :
1579 #endif /* ndef FEATURE_TRUST */
1581 #ifndef _WIN_CONSOLE
1582 case hash_hide_console :
1583 #endif /* ndef _WIN_CONSOLE */
1585 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1586 case hash_activity_animation :
1587 case hash_close_button_minimizes :
1588 case hash_log_buffer_size :
1589 case hash_log_font_name :
1590 case hash_log_font_size :
1591 case hash_log_highlight_messages :
1592 case hash_log_max_lines :
1593 case hash_log_messages :
1594 case hash_show_on_task_bar :
1595 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1596 /* These warnings are annoying - so hide them. -- Jon */
1597 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1600 /* *************************************************************************/
1602 /* *************************************************************************/
1604 * I decided that I liked this better as a warning than an
1605 * error. To change back to an error, just change log level
1606 * to LOG_LEVEL_FATAL.
1608 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1609 "in configuration file (%s).", buf, hash_string(cmd), linenum, configfile);
1610 string_append(&config->proxy_args,
1611 " <b><font color=\"red\">WARNING: unrecognized directive, ignored</font></b>");
1614 /* *************************************************************************/
1615 } /* end switch( hash_string(cmd) ) */
1616 } /* end while ( read_config_line(...) ) */
1620 set_debug_level(config->debug);
1622 freez(config->logfile);
1626 if (NULL != logfile)
1628 config->logfile = logfile;
1629 init_error_log(Argv[0], config->logfile);
1637 if (NULL == config->proxy_args)
1639 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1642 if (config->actions_file[0])
1644 add_loader(load_actions_file, config);
1647 if (config->re_filterfile)
1649 add_loader(load_re_filterfile, config);
1652 #ifdef FEATURE_TRUST
1653 if (config->trustfile)
1655 add_loader(load_trustfile, config);
1657 #endif /* def FEATURE_TRUST */
1659 #ifdef FEATURE_COOKIE_JAR
1660 if ( NULL != config->jarfile )
1662 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1664 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1665 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1667 setbuf(config->jar, NULL);
1669 #endif /* def FEATURE_COOKIE_JAR */
1671 if ( NULL == config->haddr )
1673 config->haddr = strdup( HADDR_DEFAULT );
1676 if ( NULL != config->haddr )
1678 if (NULL != (p = strchr(config->haddr, ':')))
1683 config->hport = atoi(p);
1687 if (config->hport <= 0)
1690 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1691 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1693 if (*config->haddr == '\0')
1696 * Only the port specified. We stored it in config->hport
1697 * and don't need its text representation anymore.
1699 freez(config->haddr);
1704 * Want to run all the loaders once now.
1706 * Need to set up a fake csp, so they can get to the config.
1708 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1709 fake_csp->config = config;
1711 if (run_loader(fake_csp))
1714 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1715 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1719 /* FIXME: this is a kludge for win32 */
1720 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1722 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1723 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1724 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1726 #ifdef FEATURE_TRUST
1727 g_trustfile = config->trustfile;
1728 #endif /* def FEATURE_TRUST */
1731 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1732 /* FIXME: end kludge */
1735 config->need_bind = 1;
1737 if (current_configfile)
1739 struct configuration_spec * oldcfg = (struct configuration_spec *)
1740 current_configfile->f;
1742 * Check if config->haddr,hport == oldcfg->haddr,hport
1744 * The following could be written more compactly as a single,
1745 * (unreadably long) if statement.
1747 config->need_bind = 0;
1748 if (config->hport != oldcfg->hport)
1750 config->need_bind = 1;
1752 else if (config->haddr == NULL)
1754 if (oldcfg->haddr != NULL)
1756 config->need_bind = 1;
1759 else if (oldcfg->haddr == NULL)
1761 config->need_bind = 1;
1763 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1765 config->need_bind = 1;
1768 current_configfile->unloader = unload_configfile;
1771 fs->next = files->next;
1774 current_configfile = fs;
1780 /*********************************************************************
1782 * Function : savearg
1784 * Description : Called from `load_config'. It saves each non-empty
1785 * and non-comment line from config into
1786 * config->proxy_args. This is used to create the
1787 * show-proxy-args page. On error, frees
1788 * config->proxy_args and sets it to NULL
1791 * 1 : command = config setting that was found
1792 * 2 : argument = the setting's argument (if any)
1793 * 3 : config = Configuration to save into.
1797 *********************************************************************/
1798 static void savearg(char *command, char *argument, struct configuration_spec * config)
1808 * Add config option name embedded in
1809 * link to it's section in the user-manual
1811 buf = strdup("\n<a href=\"");
1812 if (!strncmpic(config->usermanual, "file://", 7) ||
1813 !strncmpic(config->usermanual, "http", 4))
1815 string_append(&buf, config->usermanual);
1819 string_append(&buf, "http://");
1820 string_append(&buf, CGI_SITE_2_HOST);
1821 string_append(&buf, "/user-manual/");
1823 string_append(&buf, CONFIG_HELP_PREFIX);
1824 string_join (&buf, string_toupper(command));
1825 string_append(&buf, "\">");
1826 string_append(&buf, command);
1827 string_append(&buf, "</a> ");
1831 freez(config->proxy_args);
1835 if ( (NULL != argument) && ('\0' != *argument) )
1837 s = html_encode(argument);
1841 freez(config->proxy_args);
1845 if (strncmpic(argument, "http://", 7) == 0)
1847 string_append(&buf, "<a href=\"");
1848 string_append(&buf, s);
1849 string_append(&buf, "\">");
1850 string_join (&buf, s);
1851 string_append(&buf, "</a>");
1855 string_join (&buf, s);
1859 string_append(&buf, "<br>");
1860 string_join(&config->proxy_args, buf);