1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.70 2007/12/15 14:24:05 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.70 2007/12/15 14:24:05 fabiankeil
39 * Plug memory leak if listen-address only specifies the port.
41 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
42 * Relocate daemon-mode-related log messages to make sure
43 * they aren't shown again in case of configuration reloads.
45 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
46 * Plug memory leak introduced with my last commit.
48 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
49 * When in daemon mode, close stderr after the configuration file has been
50 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
52 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
53 * #1763173 from Stefan Huehner: declare unload_configfile() static.
55 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
56 * As Hal noticed, checking dispatch_cgi() as the last cruncher
57 * looks like a bug if CGI requests are blocked unintentionally,
58 * so don't do it unless the user enabled the new config option
59 * "allow-cgi-request-crunching".
61 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
62 * - Use strlcpy() instead of strcpy().
63 * - Stop treating actions files special. Expect a complete file name
64 * (with or without path) like it's done for the rest of the files.
66 * - Remove an unnecessary temporary memory allocation.
67 * - Don't log anything to the console when running as
68 * daemon and no errors occurred.
70 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
71 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
73 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
74 * New config option: enforce-blocks.
76 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
77 * - Mention other reasons why acl directive loading might have failed.
78 * - Don't log the acl source if the acl destination is to blame.
80 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
81 * Add new config option "templdir" to
82 * change the templates directory.
84 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
85 * Added config option accept-intercepted-requests
86 * and disabled it by default.
88 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
89 * Fix gcc43 compiler warnings.
91 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
92 * Add config option "split-large-forms"
93 * to work around the browser bug reported
96 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
97 * Move the <br> in the generated HTML for the config
98 * options from the beginning of the string to its end.
99 * Keeps the white space in balance.
101 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
102 * Fix memory leak in case of config file reloads.
104 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
105 * Modified kludge for win32 to make ming32 menu
106 * "Options/Edit Filters" (sort of) work again.
107 * Same limitations as for the action files apply.
110 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
111 * Incorporate modified version of Roland Rosenfeld's patch to
112 * optionally access the user-manual via Privoxy. Closes patch 679075.
114 * Formatting changed to Privoxy style, added call to
115 * cgi_error_no_template if the requested file doesn't
116 * exist and modified check whether or not Privoxy itself
117 * should serve the manual. Should work cross-platform now.
119 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
120 * Added config option enable-remote-http-toggle
121 * to specify if Privoxy should recognize special
122 * headers (currently only X-Filter) to change its
123 * behaviour. Disabled by default.
125 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
126 * Make number of retries in case of forwarded-connect problems
127 * a config file option (forwarded-connect-retries) and use 0 as
130 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
131 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
132 * with what was really the latest development (the v_3_0_branch branch)
134 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
135 * Don't forget to malloc space for the null terminator...
137 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
138 * Multiple filter file support
140 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
141 * Closed two memory leaks; hopefully the last remaining ones
142 * (in the main execution paths, anyway).
144 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
145 * Addressed bug #719435
146 * - Extraneous filterfile directives now logged as errors
147 * - This and unrecnonised directives now really obvious on status page
149 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
150 * Cosmetic: Renamed cryptic variable
152 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
153 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
155 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
156 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
158 * Revision 1.48 2002/05/14 21:30:38 oes
159 * savearg now uses own linking code instead of (now special-cased) add_help_link
161 * Revision 1.47 2002/05/12 21:36:29 jongfoster
162 * Correcting function comments
164 * Revision 1.46 2002/04/26 12:55:14 oes
165 * - New option "user-manual", defaults to our site
166 * via project.h #define
167 * - savearg now embeds option names in help links
169 * Revision 1.45 2002/04/24 02:11:54 oes
170 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
172 * Revision 1.44 2002/04/08 20:37:13 swa
175 * Revision 1.43 2002/04/08 20:36:50 swa
178 * Revision 1.42 2002/04/05 15:50:15 oes
179 * fix for invalid HTML proxy_args
181 * Revision 1.41 2002/03/31 17:19:00 jongfoster
182 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
184 * Revision 1.40 2002/03/26 22:29:55 swa
185 * we have a new homepage!
187 * Revision 1.39 2002/03/24 13:25:43 swa
188 * name change related issues
190 * Revision 1.38 2002/03/24 13:05:48 jongfoster
191 * Renaming re_filterfile to filterfile
193 * Revision 1.37 2002/03/16 23:54:06 jongfoster
194 * Adding graceful termination feature, to help look for memory leaks.
195 * If you enable this (which, by design, has to be done by hand
196 * editing config.h) and then go to http://i.j.b/die, then the program
197 * will exit cleanly after the *next* request. It should free all the
198 * memory that was used.
200 * Revision 1.36 2002/03/13 00:27:05 jongfoster
203 * Revision 1.35 2002/03/07 03:52:44 oes
204 * Set logging to tty for --no-daemon mode
206 * Revision 1.34 2002/03/06 23:14:35 jongfoster
207 * Trivial cosmetic changes to make function comments easier to find.
209 * Revision 1.33 2002/03/05 04:52:42 oes
210 * Deleted non-errlog debugging code
212 * Revision 1.32 2002/03/04 18:24:53 oes
213 * Re-enabled output of unknown config directive hash
215 * Revision 1.31 2002/03/03 15:07:20 oes
216 * Re-enabled automatic config reloading
218 * Revision 1.30 2002/01/22 23:31:43 jongfoster
219 * Replacing strsav() with string_append()
221 * Revision 1.29 2002/01/17 21:02:30 jongfoster
222 * Moving all our URL and URL pattern parsing code to urlmatch.c.
224 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
226 * Revision 1.28 2001/12/30 14:07:32 steudten
227 * - Add signal handling (unix)
228 * - Add SIGHUP handler (unix)
229 * - Add creation of pidfile (unix)
230 * - Add action 'top' in rc file (RH)
231 * - Add entry 'SIGNALS' to manpage
232 * - Add exit message to logfile (unix)
234 * Revision 1.27 2001/11/07 00:02:13 steudten
235 * Add line number in error output for lineparsing for
236 * actionsfile and configfile.
237 * Special handling for CLF added.
239 * Revision 1.26 2001/11/05 21:41:43 steudten
240 * Add changes to be a real daemon just for unix os.
241 * (change cwd to /, detach from controlling tty, set
242 * process group and session leader to the own process.
244 * Add some fatal-error log message for failed malloc().
245 * Add '-d' if compiled with 'configure --with-debug' to
246 * enable debug output.
248 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
249 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
250 * threads to call select() simultaneously. So, it's time to do a real, live,
251 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
252 * (native). Both versions will work, but using __OS2__ offers multi-threading.
254 * Revision 1.24 2001/10/23 21:40:30 jongfoster
255 * Added support for enable-edit-actions and enable-remote-toggle config
258 * Revision 1.23 2001/10/07 15:36:00 oes
259 * Introduced new config option "buffer-limit"
261 * Revision 1.22 2001/09/22 16:36:59 jongfoster
262 * Removing unused parameter fs from read_config_line()
264 * Revision 1.21 2001/09/16 17:10:43 jongfoster
265 * Moving function savearg() here, since it was the only thing left in
268 * Revision 1.20 2001/07/30 22:08:36 jongfoster
269 * Tidying up #defines:
270 * - All feature #defines are now of the form FEATURE_xxx
271 * - Permanently turned off WIN_GUI_EDIT
272 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
274 * Revision 1.19 2001/07/15 17:45:16 jongfoster
275 * Removing some unused #includes
277 * Revision 1.18 2001/07/13 14:01:14 oes
278 * - Removed all #ifdef PCRS
279 * - Removed vim-settings
281 * Revision 1.17 2001/06/29 13:31:03 oes
282 * - Improved comments
283 * - Fixed (actionsfile) and sorted hashes
284 * - Introduced admin_address and proxy-info-url
285 * as config parameters
286 * - Renamed config->proxy_args_invocation (which didn't have
287 * the invocation but the options!) to config->proxy_args
288 * - Various adaptions
289 * - Removed logentry from cancelled commit
291 * Revision 1.16 2001/06/09 10:55:28 jongfoster
292 * Changing BUFSIZ ==> BUFFER_SIZE
294 * Revision 1.15 2001/06/07 23:13:40 jongfoster
295 * Merging ACL and forward files into config file.
296 * Cosmetic: Sorting config file options alphabetically.
297 * Cosmetic: Adding brief syntax comments to config file options.
299 * Revision 1.14 2001/06/07 14:46:25 joergs
300 * Missing make_path() added for re_filterfile.
302 * Revision 1.13 2001/06/05 22:33:54 jongfoster
304 * Fixed minor memory leak.
305 * Also now uses make_path to prepend the pathnames.
307 * Revision 1.12 2001/06/05 20:04:09 jongfoster
308 * Now uses _snprintf() in place of snprintf() under Win32.
310 * Revision 1.11 2001/06/04 18:31:58 swa
311 * files are now prefixed with either `confdir' or `logdir'.
312 * `make redhat-dist' replaces both entries confdir and logdir
315 * Revision 1.10 2001/06/03 19:11:54 oes
316 * introduced confdir option
318 * Revision 1.9 2001/06/01 20:06:24 jongfoster
319 * Removed support for "tinygif" option - moved to actions file.
321 * Revision 1.8 2001/05/31 21:27:13 jongfoster
322 * Removed many options from the config file and into the
323 * "actions" file: add_forwarded, suppress_vanilla_wafer,
324 * wafer, add_header, user_agent, referer, from
325 * Also globally replaced "permission" with "action".
327 * Revision 1.7 2001/05/29 09:50:24 jongfoster
328 * Unified blocklist/imagelist/permissionslist.
329 * File format is still under discussion, but the internal changes
332 * Also modified interceptor behaviour:
333 * - We now intercept all URLs beginning with one of the following
334 * prefixes (and *only* these prefixes):
336 * * http://ijbswa.sf.net/config/
337 * * http://ijbswa.sourceforge.net/config/
338 * - New interceptors "home page" - go to http://i.j.b/ to see it.
339 * - Internal changes so that intercepted and fast redirect pages
340 * are not replaced with an image.
341 * - Interceptors now have the option to send a binary page direct
342 * to the client. (i.e. ijb-send-banner uses this)
343 * - Implemented show-url-info interceptor. (Which is why I needed
344 * the above interceptors changes - a typical URL is
345 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
346 * The previous mechanism would not have intercepted that, and
347 * if it had been intercepted then it then it would have replaced
350 * Revision 1.6 2001/05/26 00:28:36 jongfoster
351 * Automatic reloading of config file.
352 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
353 * Most of the global variables have been moved to a new
354 * struct configuration_spec, accessed through csp->config->globalname
355 * Most of the globals remaining are used by the Win32 GUI.
357 * Revision 1.5 2001/05/25 22:34:30 jongfoster
360 * Revision 1.4 2001/05/22 18:46:04 oes
362 * - Enabled filtering banners by size rather than URL
363 * by adding patterns that replace all standard banner
364 * sizes with the "Junkbuster" gif to the re_filterfile
366 * - Enabled filtering WebBugs by providing a pattern
367 * which kills all 1x1 images
369 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
370 * which is selected by the (nonstandard and therefore
371 * capital) letter 'U' in the option string.
372 * It causes the quantifiers to be ungreedy by default.
373 * Appending a ? turns back to greedy (!).
375 * - Added a new interceptor ijb-send-banner, which
376 * sends back the "Junkbuster" gif. Without imagelist or
377 * MSIE detection support, or if tinygif = 1, or the
378 * URL isn't recognized as an imageurl, a lame HTML
379 * explanation is sent instead.
381 * - Added new feature, which permits blocking remote
382 * script redirects and firing back a local redirect
384 * The feature is conditionally compiled, i.e. it
385 * can be disabled with --disable-fast-redirects,
386 * plus it must be activated by a "fast-redirects"
387 * line in the config file, has its own log level
388 * and of course wants to be displayed by show-proxy-args
389 * Note: Boy, all the #ifdefs in 1001 locations and
390 * all the fumbling with configure.in and acconfig.h
391 * were *way* more work than the feature itself :-(
393 * - Because a generic redirect template was needed for
394 * this, tinygif = 3 now uses the same.
396 * - Moved GIFs, and other static HTTP response templates
401 * - Removed some >400 CRs again (Jon, you really worked
404 * Revision 1.3 2001/05/20 01:21:20 jongfoster
405 * Version 2.9.4 checkin.
406 * - Merged popupfile and cookiefile, and added control over PCRS
407 * filtering, in new "permissionsfile".
408 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
409 * file error you now get a message box (in the Win32 GUI) rather
410 * than the program exiting with no explanation.
411 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
413 * - Removed tabs from "config"
414 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
415 * - Bumped up version number.
417 * Revision 1.2 2001/05/17 23:01:01 oes
418 * - Cleaned CRLF's from the sources and related files
420 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
421 * Initial import of version 2.9.3 source tree
424 *********************************************************************/
430 #include <sys/types.h>
444 # include <windows.h>
447 # ifndef _WIN_CONSOLE
449 # endif /* ndef _WIN_CONSOLE */
451 #else /* ifndef _WIN32 */
455 # include <sys/wait.h>
457 # include <sys/time.h>
458 # include <sys/stat.h>
468 #include "miscutil.h"
472 #include "urlmatch.h"
475 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
478 * Fix a problem with Solaris. There should be no effect on other
480 * Solaris's isspace() is a macro which uses it's argument directly
481 * as an array index. Therefore we need to make sure that high-bit
482 * characters generate +ve values, and ideally we also want to make
483 * the argument match the declared parameter type of "int".
485 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
486 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
488 #ifdef FEATURE_TOGGLE
489 /* Privoxy is enabled by default. */
490 int global_toggle_state = 1;
491 #endif /* def FEATURE_TOGGLE */
493 /* The filename of the configfile */
494 const char *configfile = NULL;
497 * CGI functions will later need access to the invocation args,
498 * so we will make argc and argv global.
501 const char **Argv = NULL;
503 static struct file_list *current_configfile = NULL;
507 * This takes the "cryptic" hash of each keyword and aliases them to
508 * something a little more readable. This also makes changing the
509 * hash values easier if they should change or the hash algorthm changes.
510 * Use the included "hash" program to find out what the hash will be
511 * for any string supplied on the command line. (Or just put it in the
512 * config file and read the number from the error message in the log).
514 * Please keep this list sorted alphabetically (but with the Windows
515 * console and GUI specific options last).
518 #define hash_actions_file 1196306641ul /* "actionsfile" */
519 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
520 #define hash_admin_address 4112573064ul /* "admin-address" */
521 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
522 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
523 #define hash_confdir 1978389ul /* "confdir" */
524 #define hash_debug 78263ul /* "debug" */
525 #define hash_deny_access 1227333715ul /* "deny-access" */
526 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
527 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
528 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
529 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
530 #define hash_filterfile 250887266ul /* "filterfile" */
531 #define hash_forward 2029845ul /* "forward" */
532 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
533 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
534 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
535 #define hash_jarfile 2046641ul /* "jarfile" */
536 #define hash_listen_address 1255650842ul /* "listen-address" */
537 #define hash_logdir 422889ul /* "logdir" */
538 #define hash_logfile 2114766ul /* "logfile" */
539 #define hash_permit_access 3587953268ul /* "permit-access" */
540 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
541 #define hash_single_threaded 4250084780ul /* "single-threaded" */
542 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
543 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
544 #define hash_templdir 11067889ul /* "templdir" */
545 #define hash_toggle 447966ul /* "toggle" */
546 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
547 #define hash_trustfile 56494766ul /* "trustfile" */
548 #define hash_usermanual 1416668518ul /* "user-manual" */
549 #define hash_activity_animation 1817904738ul /* "activity-animation" */
550 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
551 #define hash_hide_console 2048809870ul /* "hide-console" */
552 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
553 #define hash_log_font_name 2866730124ul /* "log-font-name" */
554 #define hash_log_font_size 2866731014ul /* "log-font-size" */
555 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
556 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
557 #define hash_log_messages 2291744899ul /* "log-messages" */
558 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
561 static void savearg(char *command, char *argument, struct configuration_spec * config);
563 /*********************************************************************
565 * Function : unload_configfile
567 * Description : Free the config structure and all components.
570 * 1 : data: struct configuration_spec to unload
574 *********************************************************************/
575 static void unload_configfile (void * data)
577 struct configuration_spec * config = (struct configuration_spec *)data;
578 struct forward_spec *cur_fwd = config->forward;
582 struct access_control_list *cur_acl = config->acl;
584 while (cur_acl != NULL)
586 struct access_control_list * next_acl = cur_acl->next;
591 #endif /* def FEATURE_ACL */
593 while (cur_fwd != NULL)
595 struct forward_spec * next_fwd = cur_fwd->next;
596 free_url_spec(cur_fwd->url);
598 freez(cur_fwd->gateway_host);
599 freez(cur_fwd->forward_host);
603 config->forward = NULL;
605 #ifdef FEATURE_COOKIE_JAR
606 if ( NULL != config->jar )
608 fclose( config->jar );
611 #endif /* def FEATURE_COOKIE_JAR */
613 freez(config->confdir);
614 freez(config->logdir);
615 freez(config->templdir);
617 freez(config->haddr);
618 freez(config->logfile);
620 for (i = 0; i < MAX_AF_FILES; i++)
622 freez(config->actions_file_short[i]);
623 freez(config->actions_file[i]);
624 freez(config->re_filterfile_short[i]);
625 freez(config->re_filterfile[i]);
628 freez(config->admin_address);
629 freez(config->proxy_info_url);
630 freez(config->proxy_args);
631 freez(config->usermanual);
633 #ifdef FEATURE_COOKIE_JAR
634 freez(config->jarfile);
635 #endif /* def FEATURE_COOKIE_JAR */
638 freez(config->trustfile);
639 list_remove_all(config->trust_info);
640 #endif /* def FEATURE_TRUST */
642 for (i = 0; i < MAX_AF_FILES; i++)
644 freez(config->re_filterfile[i]);
651 #ifdef FEATURE_GRACEFUL_TERMINATION
652 /*********************************************************************
654 * Function : unload_current_config_file
656 * Description : Unloads current config file - reset to state at
657 * beginning of program.
663 *********************************************************************/
664 void unload_current_config_file(void)
666 if (current_configfile)
668 current_configfile->unloader = unload_configfile;
669 current_configfile = NULL;
675 /*********************************************************************
677 * Function : load_config
679 * Description : Load the config file and all parameters.
681 * XXX: more than thousand lines long
682 * and thus in serious need of refactoring.
686 * Returns : The configuration_spec, or NULL on error.
688 *********************************************************************/
689 struct configuration_spec * load_config(void)
691 char buf[BUFFER_SIZE];
693 FILE *configfp = NULL;
694 struct configuration_spec * config = NULL;
695 struct client_state * fake_csp;
696 struct file_list *fs;
697 unsigned long linenum = 0;
699 char *logfile = NULL;
701 if ( !check_file_changed(current_configfile, configfile, &fs))
703 /* No need to load */
704 return ((struct configuration_spec *)current_configfile->f);
708 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
712 if (NULL != current_configfile)
714 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
717 #ifdef FEATURE_TOGGLE
718 global_toggle_state = 1;
719 #endif /* def FEATURE_TOGGLE */
721 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
727 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
728 /* Never get here - LOG_LEVEL_FATAL causes program exit */
732 * This is backwards from how it's usually done.
733 * Following the usual pattern, "fs" would be stored in a member
734 * variable in "csp", and then we'd access "config" from "fs->f",
735 * using a cast. However, "config" is used so often that a
736 * cast each time would be very ugly, and the extra indirection
737 * would waste CPU cycles. Therefore we store "config" in
738 * "csp->config", and "fs" in "csp->config->config_file_list".
740 config->config_file_list = fs;
745 config->multi_threaded = 1;
746 config->hport = HADDR_PORT;
747 config->buffer_limit = 4096 * 1024;
748 config->usermanual = strdup(USER_MANUAL_URL);
749 config->proxy_args = strdup("");
750 config->forwarded_connect_retries = 0;
751 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
752 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
753 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
755 if ((configfp = fopen(configfile, "r")) == NULL)
757 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
759 /* Never get here - LOG_LEVEL_FATAL causes program exit */
762 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
764 char cmd[BUFFER_SIZE];
765 char arg[BUFFER_SIZE];
766 char tmp[BUFFER_SIZE];
768 struct access_control_list *cur_acl;
769 #endif /* def FEATURE_ACL */
770 struct forward_spec *cur_fwd;
774 strlcpy(tmp, buf, sizeof(tmp));
776 /* Copy command (i.e. up to space or tab) into cmd */
779 while (*p && (*p != ' ') && (*p != '\t'))
785 /* Skip over the whitespace in buf */
786 while (*p && ((*p == ' ') || (*p == '\t')))
791 /* Copy the argument into arg */
792 strlcpy(arg, p, sizeof(arg));
794 /* Should never happen, but check this anyway */
800 /* Make sure the command field is lower case */
805 *p = (char)ijb_tolower(*p);
809 /* Save the argument for show-proxy-args */
810 savearg(cmd, arg, config);
813 switch( hash_string( cmd ) )
815 /* *************************************************************************
816 * actionsfile actions-file-name
817 * In confdir by default
818 * *************************************************************************/
819 case hash_actions_file :
821 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
826 if (i >= MAX_AF_FILES)
828 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
829 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
832 config->actions_file_short[i] = strdup(arg);
833 config->actions_file[i] = make_path(config->confdir, arg);
836 /* *************************************************************************
837 * accept-intercepted-requests
838 * *************************************************************************/
839 case hash_accept_intercepted_requests:
840 if ((*arg != '\0') && (0 != atoi(arg)))
842 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
846 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
850 /* *************************************************************************
851 * admin-address email-address
852 * *************************************************************************/
853 case hash_admin_address :
854 freez(config->admin_address);
855 config->admin_address = strdup(arg);
858 /* *************************************************************************
859 * allow-cgi-request-crunching
860 * *************************************************************************/
861 case hash_allow_cgi_request_crunching:
862 if ((*arg != '\0') && (0 != atoi(arg)))
864 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
868 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
872 /* *************************************************************************
874 * *************************************************************************/
875 case hash_buffer_limit :
876 config->buffer_limit = (size_t)(1024 * atoi(arg));
879 /* *************************************************************************
880 * confdir directory-name
881 * *************************************************************************/
883 freez(config->confdir);
884 config->confdir = make_path( NULL, arg);
887 /* *************************************************************************
889 * Specifies debug level, multiple values are ORed together.
890 * *************************************************************************/
892 config->debug |= atoi(arg);
895 /* *************************************************************************
896 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
897 * *************************************************************************/
899 case hash_deny_access:
900 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
902 if ((vec_count != 1) && (vec_count != 2))
904 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
905 "deny-access directive in configuration file.");
906 string_append(&config->proxy_args,
907 "<br>\nWARNING: Wrong number of parameters for "
908 "deny-access directive in configuration file.<br><br>\n");
912 /* allocate a new node */
913 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
917 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
918 /* Never get here - LOG_LEVEL_FATAL causes program exit */
921 cur_acl->action = ACL_DENY;
923 if (acl_addr(vec[0], cur_acl->src) < 0)
925 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
926 "for deny-access directive in configuration file: \"%s\"", vec[0]);
927 string_append(&config->proxy_args,
928 "<br>\nWARNING: Invalid source address, port or netmask "
929 "for deny-access directive in configuration file: \"");
930 string_append(&config->proxy_args,
932 string_append(&config->proxy_args,
939 if (acl_addr(vec[1], cur_acl->dst) < 0)
941 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
942 "for deny-access directive in configuration file: \"%s\"", vec[1]);
943 string_append(&config->proxy_args,
944 "<br>\nWARNING: Invalid destination address, port or netmask "
945 "for deny-access directive in configuration file: \"");
946 string_append(&config->proxy_args,
948 string_append(&config->proxy_args,
956 * Add it to the list. Note we reverse the list to get the
957 * behaviour the user expects. With both the ACL and
958 * actions file, the last match wins. However, the internal
959 * implementations are different: The actions file is stored
960 * in the same order as the file, and scanned completely.
961 * With the ACL, we reverse the order as we load it, then
962 * when we scan it we stop as soon as we get a match.
964 cur_acl->next = config->acl;
965 config->acl = cur_acl;
968 #endif /* def FEATURE_ACL */
970 /* *************************************************************************
971 * enable-edit-actions 0|1
972 * *************************************************************************/
973 #ifdef FEATURE_CGI_EDIT_ACTIONS
974 case hash_enable_edit_actions:
975 if ((*arg != '\0') && (0 != atoi(arg)))
977 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
981 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
984 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
986 /* *************************************************************************
987 * enable-remote-toggle 0|1
988 * *************************************************************************/
989 #ifdef FEATURE_CGI_EDIT_ACTIONS
990 case hash_enable_remote_toggle:
991 if ((*arg != '\0') && (0 != atoi(arg)))
993 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
997 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1000 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1002 /* *************************************************************************
1003 * enable-remote-http-toggle 0|1
1004 * *************************************************************************/
1005 case hash_enable_remote_http_toggle:
1006 if ((*arg != '\0') && (0 != atoi(arg)))
1008 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1012 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1016 /* *************************************************************************
1017 * hash_enforce_blocks 0|1
1018 * *************************************************************************/
1019 #ifdef FEATURE_FORCE_LOAD
1020 case hash_enforce_blocks:
1021 if ((*arg != '\0') && (0 != atoi(arg)))
1023 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1027 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1030 #endif /* def FEATURE_FORCE_LOAD */
1032 /* *************************************************************************
1033 * filterfile file-name
1034 * In confdir by default.
1035 * *************************************************************************/
1036 case hash_filterfile :
1038 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1043 if (i >= MAX_AF_FILES)
1045 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1046 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1049 config->re_filterfile_short[i] = strdup(arg);
1050 config->re_filterfile[i] = make_path(config->confdir, arg);
1054 /* *************************************************************************
1055 * forward url-pattern (.|http-proxy-host[:port])
1056 * *************************************************************************/
1058 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1062 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1063 "directive in configuration file.");
1064 string_append(&config->proxy_args,
1065 "<br>\nWARNING: Wrong number of parameters for "
1066 "forward directive in configuration file.");
1070 /* allocate a new node */
1071 cur_fwd = zalloc(sizeof(*cur_fwd));
1072 if (cur_fwd == NULL)
1074 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1075 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1079 cur_fwd->type = SOCKS_NONE;
1081 /* Save the URL pattern */
1082 if (create_url_spec(cur_fwd->url, vec[0]))
1084 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1085 "directive in configuration file.");
1086 string_append(&config->proxy_args,
1087 "<br>\nWARNING: Bad URL specifier for "
1088 "forward directive in configuration file.");
1092 /* Parse the parent HTTP proxy host:port */
1095 if (strcmp(p, ".") != 0)
1097 cur_fwd->forward_host = strdup(p);
1099 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1102 cur_fwd->forward_port = atoi(p);
1105 if (cur_fwd->forward_port <= 0)
1107 cur_fwd->forward_port = 8000;
1112 cur_fwd->next = config->forward;
1113 config->forward = cur_fwd;
1117 /* *************************************************************************
1118 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1119 * *************************************************************************/
1120 case hash_forward_socks4:
1121 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1125 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1126 "forward-socks4 directive in configuration file.");
1127 string_append(&config->proxy_args,
1128 "<br>\nWARNING: Wrong number of parameters for "
1129 "forward-socks4 directive in configuration file.");
1133 /* allocate a new node */
1134 cur_fwd = zalloc(sizeof(*cur_fwd));
1135 if (cur_fwd == NULL)
1137 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1138 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1142 cur_fwd->type = SOCKS_4;
1144 /* Save the URL pattern */
1145 if (create_url_spec(cur_fwd->url, vec[0]))
1147 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1148 "directive in configuration file.");
1149 string_append(&config->proxy_args,
1150 "<br>\nWARNING: Bad URL specifier for "
1151 "forward-socks4 directive in configuration file.");
1155 /* Parse the SOCKS proxy host[:port] */
1158 if (strcmp(p, ".") != 0)
1160 cur_fwd->gateway_host = strdup(p);
1162 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1165 cur_fwd->gateway_port = atoi(p);
1167 if (cur_fwd->gateway_port <= 0)
1169 cur_fwd->gateway_port = 1080;
1173 /* Parse the parent HTTP proxy host[:port] */
1176 if (strcmp(p, ".") != 0)
1178 cur_fwd->forward_host = strdup(p);
1180 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1183 cur_fwd->forward_port = atoi(p);
1186 if (cur_fwd->forward_port <= 0)
1188 cur_fwd->forward_port = 8000;
1193 cur_fwd->next = config->forward;
1194 config->forward = cur_fwd;
1198 /* *************************************************************************
1199 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1200 * *************************************************************************/
1201 case hash_forward_socks4a:
1202 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1206 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1207 "forward-socks4a directive in configuration file.");
1208 string_append(&config->proxy_args,
1209 "<br>\nWARNING: Wrong number of parameters for "
1210 "forward-socks4a directive in configuration file.");
1214 /* allocate a new node */
1215 cur_fwd = zalloc(sizeof(*cur_fwd));
1216 if (cur_fwd == NULL)
1218 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1219 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1223 cur_fwd->type = SOCKS_4A;
1225 /* Save the URL pattern */
1226 if (create_url_spec(cur_fwd->url, vec[0]))
1228 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1229 "directive in configuration file.");
1230 string_append(&config->proxy_args,
1231 "<br>\nWARNING: Bad URL specifier for "
1232 "forward-socks4a directive in configuration file.");
1236 /* Parse the SOCKS proxy host[:port] */
1239 cur_fwd->gateway_host = strdup(p);
1241 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1244 cur_fwd->gateway_port = atoi(p);
1246 if (cur_fwd->gateway_port <= 0)
1248 cur_fwd->gateway_port = 1080;
1251 /* Parse the parent HTTP proxy host[:port] */
1254 if (strcmp(p, ".") != 0)
1256 cur_fwd->forward_host = strdup(p);
1258 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1261 cur_fwd->forward_port = atoi(p);
1264 if (cur_fwd->forward_port <= 0)
1266 cur_fwd->forward_port = 8000;
1271 cur_fwd->next = config->forward;
1272 config->forward = cur_fwd;
1276 /* *************************************************************************
1277 * forwarded-connect-retries n
1278 * *************************************************************************/
1279 case hash_forwarded_connect_retries :
1280 config->forwarded_connect_retries = atoi(arg);
1283 /* *************************************************************************
1284 * jarfile jar-file-name
1285 * In logdir by default
1286 * *************************************************************************/
1287 #ifdef FEATURE_COOKIE_JAR
1289 freez(config->jarfile);
1290 config->jarfile = make_path(config->logdir, arg);
1292 #endif /* def FEATURE_COOKIE_JAR */
1294 /* *************************************************************************
1295 * listen-address [ip][:port]
1296 * *************************************************************************/
1297 case hash_listen_address :
1298 freez(config->haddr);
1299 config->haddr = strdup(arg);
1302 /* *************************************************************************
1303 * logdir directory-name
1304 * *************************************************************************/
1306 freez(config->logdir);
1307 config->logdir = make_path(NULL, arg);
1310 /* *************************************************************************
1311 * logfile log-file-name
1312 * In logdir by default
1313 * *************************************************************************/
1317 logfile = make_path(config->logdir, arg);
1318 if (NULL == logfile)
1320 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1325 /* *************************************************************************
1326 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1327 * *************************************************************************/
1329 case hash_permit_access:
1330 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1332 if ((vec_count != 1) && (vec_count != 2))
1334 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1335 "permit-access directive in configuration file.");
1336 string_append(&config->proxy_args,
1337 "<br>\nWARNING: Wrong number of parameters for "
1338 "permit-access directive in configuration file.<br><br>\n");
1343 /* allocate a new node */
1344 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1346 if (cur_acl == NULL)
1348 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1349 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1352 cur_acl->action = ACL_PERMIT;
1354 if (acl_addr(vec[0], cur_acl->src) < 0)
1356 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1357 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1358 string_append(&config->proxy_args,
1359 "<br>\nWARNING: Invalid source address, port or netmask for "
1360 "permit-access directive in configuration file: \"");
1361 string_append(&config->proxy_args,
1363 string_append(&config->proxy_args,
1370 if (acl_addr(vec[1], cur_acl->dst) < 0)
1372 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1373 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1374 string_append(&config->proxy_args,
1375 "<br>\nWARNING: Invalid destination address, port or netmask for "
1376 "permit-access directive in configuration file: \"");
1377 string_append(&config->proxy_args,
1379 string_append(&config->proxy_args,
1387 * Add it to the list. Note we reverse the list to get the
1388 * behaviour the user expects. With both the ACL and
1389 * actions file, the last match wins. However, the internal
1390 * implementations are different: The actions file is stored
1391 * in the same order as the file, and scanned completely.
1392 * With the ACL, we reverse the order as we load it, then
1393 * when we scan it we stop as soon as we get a match.
1395 cur_acl->next = config->acl;
1396 config->acl = cur_acl;
1399 #endif /* def FEATURE_ACL */
1401 /* *************************************************************************
1402 * proxy-info-url url
1403 * *************************************************************************/
1404 case hash_proxy_info_url :
1405 freez(config->proxy_info_url);
1406 config->proxy_info_url = strdup(arg);
1409 /* *************************************************************************
1411 * *************************************************************************/
1412 case hash_single_threaded :
1413 config->multi_threaded = 0;
1416 /* *************************************************************************
1417 * split-large-cgi-forms
1418 * *************************************************************************/
1419 case hash_split_large_cgi_forms :
1420 if ((*arg != '\0') && (0 != atoi(arg)))
1422 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1426 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1430 /* *************************************************************************
1431 * templdir directory-name
1432 * *************************************************************************/
1433 case hash_templdir :
1434 freez(config->templdir);
1435 config->templdir = make_path(NULL, arg);
1438 /* *************************************************************************
1440 * *************************************************************************/
1441 #ifdef FEATURE_TOGGLE
1443 global_toggle_state = atoi(arg);
1445 #endif /* def FEATURE_TOGGLE */
1447 /* *************************************************************************
1448 * trust-info-url url
1449 * *************************************************************************/
1450 #ifdef FEATURE_TRUST
1451 case hash_trust_info_url :
1452 enlist(config->trust_info, arg);
1454 #endif /* def FEATURE_TRUST */
1456 /* *************************************************************************
1457 * trustfile filename
1458 * (In confdir by default.)
1459 * *************************************************************************/
1460 #ifdef FEATURE_TRUST
1461 case hash_trustfile :
1462 freez(config->trustfile);
1463 config->trustfile = make_path(config->confdir, arg);
1465 #endif /* def FEATURE_TRUST */
1467 /* *************************************************************************
1469 * *************************************************************************/
1470 case hash_usermanual :
1471 freez(config->usermanual);
1472 config->usermanual = strdup(arg);
1475 /* *************************************************************************
1476 * Win32 Console options:
1477 * *************************************************************************/
1479 /* *************************************************************************
1481 * *************************************************************************/
1483 case hash_hide_console :
1486 #endif /*def _WIN_CONSOLE*/
1489 /* *************************************************************************
1490 * Win32 GUI options:
1491 * *************************************************************************/
1493 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1494 /* *************************************************************************
1495 * activity-animation (0|1)
1496 * *************************************************************************/
1497 case hash_activity_animation :
1498 g_bShowActivityAnimation = atoi(arg);
1501 /* *************************************************************************
1502 * close-button-minimizes (0|1)
1503 * *************************************************************************/
1504 case hash_close_button_minimizes :
1505 g_bCloseHidesWindow = atoi(arg);
1508 /* *************************************************************************
1509 * log-buffer-size (0|1)
1510 * *************************************************************************/
1511 case hash_log_buffer_size :
1512 g_bLimitBufferSize = atoi(arg);
1515 /* *************************************************************************
1516 * log-font-name fontnane
1517 * *************************************************************************/
1518 case hash_log_font_name :
1519 strcpy( g_szFontFaceName, arg );
1522 /* *************************************************************************
1524 * *************************************************************************/
1525 case hash_log_font_size :
1526 g_nFontSize = atoi(arg);
1529 /* *************************************************************************
1530 * log-highlight-messages (0|1)
1531 * *************************************************************************/
1532 case hash_log_highlight_messages :
1533 g_bHighlightMessages = atoi(arg);
1536 /* *************************************************************************
1538 * *************************************************************************/
1539 case hash_log_max_lines :
1540 g_nMaxBufferLines = atoi(arg);
1543 /* *************************************************************************
1544 * log-messages (0|1)
1545 * *************************************************************************/
1546 case hash_log_messages :
1547 g_bLogMessages = atoi(arg);
1550 /* *************************************************************************
1551 * show-on-task-bar (0|1)
1552 * *************************************************************************/
1553 case hash_show_on_task_bar :
1554 g_bShowOnTaskBar = atoi(arg);
1557 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1560 /* *************************************************************************
1561 * Warnings about unsupported features
1562 * *************************************************************************/
1564 case hash_deny_access:
1565 #endif /* ndef FEATURE_ACL */
1566 #ifndef FEATURE_CGI_EDIT_ACTIONS
1567 case hash_enable_edit_actions:
1568 case hash_enable_remote_toggle:
1569 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1570 #ifndef FEATURE_COOKIE_JAR
1572 #endif /* ndef FEATURE_COOKIE_JAR */
1574 case hash_permit_access:
1575 #endif /* ndef FEATURE_ACL */
1576 #ifndef FEATURE_TOGGLE
1578 #endif /* ndef FEATURE_TOGGLE */
1579 #ifndef FEATURE_TRUST
1580 case hash_trustfile :
1581 case hash_trust_info_url :
1582 #endif /* ndef FEATURE_TRUST */
1584 #ifndef _WIN_CONSOLE
1585 case hash_hide_console :
1586 #endif /* ndef _WIN_CONSOLE */
1588 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1589 case hash_activity_animation :
1590 case hash_close_button_minimizes :
1591 case hash_log_buffer_size :
1592 case hash_log_font_name :
1593 case hash_log_font_size :
1594 case hash_log_highlight_messages :
1595 case hash_log_max_lines :
1596 case hash_log_messages :
1597 case hash_show_on_task_bar :
1598 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1599 /* These warnings are annoying - so hide them. -- Jon */
1600 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1603 /* *************************************************************************/
1605 /* *************************************************************************/
1607 * I decided that I liked this better as a warning than an
1608 * error. To change back to an error, just change log level
1609 * to LOG_LEVEL_FATAL.
1611 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1612 "in configuration file (%s).", buf, hash_string(cmd), linenum, configfile);
1613 string_append(&config->proxy_args,
1614 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1617 /* *************************************************************************/
1618 } /* end switch( hash_string(cmd) ) */
1619 } /* end while ( read_config_line(...) ) */
1623 set_debug_level(config->debug);
1625 freez(config->logfile);
1629 if (NULL != logfile)
1631 config->logfile = logfile;
1632 init_error_log(Argv[0], config->logfile);
1640 if (NULL == config->proxy_args)
1642 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1645 if (config->actions_file[0])
1647 add_loader(load_actions_file, config);
1650 if (config->re_filterfile)
1652 add_loader(load_re_filterfile, config);
1655 #ifdef FEATURE_TRUST
1656 if (config->trustfile)
1658 add_loader(load_trustfile, config);
1660 #endif /* def FEATURE_TRUST */
1662 #ifdef FEATURE_COOKIE_JAR
1663 if ( NULL != config->jarfile )
1665 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1667 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1668 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1670 setbuf(config->jar, NULL);
1672 #endif /* def FEATURE_COOKIE_JAR */
1674 if ( NULL == config->haddr )
1676 config->haddr = strdup( HADDR_DEFAULT );
1679 if ( NULL != config->haddr )
1681 if (NULL != (p = strchr(config->haddr, ':')))
1686 config->hport = atoi(p);
1690 if (config->hport <= 0)
1693 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1694 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1696 if (*config->haddr == '\0')
1699 * Only the port specified. We stored it in config->hport
1700 * and don't need its text representation anymore.
1702 freez(config->haddr);
1707 * Want to run all the loaders once now.
1709 * Need to set up a fake csp, so they can get to the config.
1711 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1712 fake_csp->config = config;
1714 if (run_loader(fake_csp))
1717 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1718 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1722 /* FIXME: this is a kludge for win32 */
1723 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1725 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1726 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1727 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1729 #ifdef FEATURE_TRUST
1730 g_trustfile = config->trustfile;
1731 #endif /* def FEATURE_TRUST */
1734 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1735 /* FIXME: end kludge */
1738 config->need_bind = 1;
1740 if (current_configfile)
1742 struct configuration_spec * oldcfg = (struct configuration_spec *)
1743 current_configfile->f;
1745 * Check if config->haddr,hport == oldcfg->haddr,hport
1747 * The following could be written more compactly as a single,
1748 * (unreadably long) if statement.
1750 config->need_bind = 0;
1751 if (config->hport != oldcfg->hport)
1753 config->need_bind = 1;
1755 else if (config->haddr == NULL)
1757 if (oldcfg->haddr != NULL)
1759 config->need_bind = 1;
1762 else if (oldcfg->haddr == NULL)
1764 config->need_bind = 1;
1766 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1768 config->need_bind = 1;
1771 current_configfile->unloader = unload_configfile;
1774 fs->next = files->next;
1777 current_configfile = fs;
1783 /*********************************************************************
1785 * Function : savearg
1787 * Description : Called from `load_config'. It saves each non-empty
1788 * and non-comment line from config into
1789 * config->proxy_args. This is used to create the
1790 * show-proxy-args page. On error, frees
1791 * config->proxy_args and sets it to NULL
1794 * 1 : command = config setting that was found
1795 * 2 : argument = the setting's argument (if any)
1796 * 3 : config = Configuration to save into.
1800 *********************************************************************/
1801 static void savearg(char *command, char *argument, struct configuration_spec * config)
1811 * Add config option name embedded in
1812 * link to it's section in the user-manual
1814 buf = strdup("\n<a href=\"");
1815 if (!strncmpic(config->usermanual, "file://", 7) ||
1816 !strncmpic(config->usermanual, "http", 4))
1818 string_append(&buf, config->usermanual);
1822 string_append(&buf, "http://");
1823 string_append(&buf, CGI_SITE_2_HOST);
1824 string_append(&buf, "/user-manual/");
1826 string_append(&buf, CONFIG_HELP_PREFIX);
1827 string_join (&buf, string_toupper(command));
1828 string_append(&buf, "\">");
1829 string_append(&buf, command);
1830 string_append(&buf, "</a> ");
1834 freez(config->proxy_args);
1838 if ( (NULL != argument) && ('\0' != *argument) )
1840 s = html_encode(argument);
1844 freez(config->proxy_args);
1848 if (strncmpic(argument, "http://", 7) == 0)
1850 string_append(&buf, "<a href=\"");
1851 string_append(&buf, s);
1852 string_append(&buf, "\">");
1853 string_join (&buf, s);
1854 string_append(&buf, "</a>");
1858 string_join (&buf, s);
1862 string_append(&buf, "<br>");
1863 string_join(&config->proxy_args, buf);