1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.81 2008/11/13 09:08:42 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-2008 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.81 2008/11/13 09:08:42 fabiankeil
39 * Add new config option: keep-alive-timeout.
41 * Revision 1.80 2008/08/31 15:59:03 fabiankeil
42 * There's no reason to let remote toggling support depend
43 * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
45 * Revision 1.79 2008/08/30 12:03:07 fabiankeil
46 * Remove FEATURE_COOKIE_JAR.
48 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
49 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
50 * disabled, log a message that blocks will always be enforced
51 * instead of complaining about an unrecognized directive.
52 * Reported by Pietro Leone.
54 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
55 * Reuse directive_hash and don't hash the same directive twice.
57 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
58 * - Merge three string_append() calls.
59 * - Remove useless assertion.
61 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
62 * Rename load_actions_file() and load_re_filterfile()
63 * as they load multiple files "now".
65 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
66 * Add hostname directive. Closes PR#1918189.
68 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
71 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
72 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
74 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
75 * Reword "unrecognized directive" warning, use better
76 * mark up and add a <br>. Fixes parts of #1856559.
78 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
79 * Plug memory leak if listen-address only specifies the port.
81 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
82 * Relocate daemon-mode-related log messages to make sure
83 * they aren't shown again in case of configuration reloads.
85 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
86 * Plug memory leak introduced with my last commit.
88 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
89 * When in daemon mode, close stderr after the configuration file has been
90 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
92 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
93 * #1763173 from Stefan Huehner: declare unload_configfile() static.
95 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
96 * As Hal noticed, checking dispatch_cgi() as the last cruncher
97 * looks like a bug if CGI requests are blocked unintentionally,
98 * so don't do it unless the user enabled the new config option
99 * "allow-cgi-request-crunching".
101 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
102 * - Use strlcpy() instead of strcpy().
103 * - Stop treating actions files special. Expect a complete file name
104 * (with or without path) like it's done for the rest of the files.
106 * - Remove an unnecessary temporary memory allocation.
107 * - Don't log anything to the console when running as
108 * daemon and no errors occurred.
110 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
111 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
113 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
114 * New config option: enforce-blocks.
116 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
117 * - Mention other reasons why acl directive loading might have failed.
118 * - Don't log the acl source if the acl destination is to blame.
120 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
121 * Add new config option "templdir" to
122 * change the templates directory.
124 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
125 * Added config option accept-intercepted-requests
126 * and disabled it by default.
128 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
129 * Fix gcc43 compiler warnings.
131 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
132 * Add config option "split-large-forms"
133 * to work around the browser bug reported
136 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
137 * Move the <br> in the generated HTML for the config
138 * options from the beginning of the string to its end.
139 * Keeps the white space in balance.
141 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
142 * Fix memory leak in case of config file reloads.
144 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
145 * Modified kludge for win32 to make ming32 menu
146 * "Options/Edit Filters" (sort of) work again.
147 * Same limitations as for the action files apply.
150 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
151 * Incorporate modified version of Roland Rosenfeld's patch to
152 * optionally access the user-manual via Privoxy. Closes patch 679075.
154 * Formatting changed to Privoxy style, added call to
155 * cgi_error_no_template if the requested file doesn't
156 * exist and modified check whether or not Privoxy itself
157 * should serve the manual. Should work cross-platform now.
159 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
160 * Added config option enable-remote-http-toggle
161 * to specify if Privoxy should recognize special
162 * headers (currently only X-Filter) to change its
163 * behaviour. Disabled by default.
165 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
166 * Make number of retries in case of forwarded-connect problems
167 * a config file option (forwarded-connect-retries) and use 0 as
170 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
171 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
172 * with what was really the latest development (the v_3_0_branch branch)
174 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
175 * Don't forget to malloc space for the null terminator...
177 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
178 * Multiple filter file support
180 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
181 * Closed two memory leaks; hopefully the last remaining ones
182 * (in the main execution paths, anyway).
184 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
185 * Addressed bug #719435
186 * - Extraneous filterfile directives now logged as errors
187 * - This and unrecnonised directives now really obvious on status page
189 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
190 * Cosmetic: Renamed cryptic variable
192 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
193 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
195 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
196 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
198 * Revision 1.48 2002/05/14 21:30:38 oes
199 * savearg now uses own linking code instead of (now special-cased) add_help_link
201 * Revision 1.47 2002/05/12 21:36:29 jongfoster
202 * Correcting function comments
204 * Revision 1.46 2002/04/26 12:55:14 oes
205 * - New option "user-manual", defaults to our site
206 * via project.h #define
207 * - savearg now embeds option names in help links
209 * Revision 1.45 2002/04/24 02:11:54 oes
210 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
212 * Revision 1.44 2002/04/08 20:37:13 swa
215 * Revision 1.43 2002/04/08 20:36:50 swa
218 * Revision 1.42 2002/04/05 15:50:15 oes
219 * fix for invalid HTML proxy_args
221 * Revision 1.41 2002/03/31 17:19:00 jongfoster
222 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
224 * Revision 1.40 2002/03/26 22:29:55 swa
225 * we have a new homepage!
227 * Revision 1.39 2002/03/24 13:25:43 swa
228 * name change related issues
230 * Revision 1.38 2002/03/24 13:05:48 jongfoster
231 * Renaming re_filterfile to filterfile
233 * Revision 1.37 2002/03/16 23:54:06 jongfoster
234 * Adding graceful termination feature, to help look for memory leaks.
235 * If you enable this (which, by design, has to be done by hand
236 * editing config.h) and then go to http://i.j.b/die, then the program
237 * will exit cleanly after the *next* request. It should free all the
238 * memory that was used.
240 * Revision 1.36 2002/03/13 00:27:05 jongfoster
243 * Revision 1.35 2002/03/07 03:52:44 oes
244 * Set logging to tty for --no-daemon mode
246 * Revision 1.34 2002/03/06 23:14:35 jongfoster
247 * Trivial cosmetic changes to make function comments easier to find.
249 * Revision 1.33 2002/03/05 04:52:42 oes
250 * Deleted non-errlog debugging code
252 * Revision 1.32 2002/03/04 18:24:53 oes
253 * Re-enabled output of unknown config directive hash
255 * Revision 1.31 2002/03/03 15:07:20 oes
256 * Re-enabled automatic config reloading
258 * Revision 1.30 2002/01/22 23:31:43 jongfoster
259 * Replacing strsav() with string_append()
261 * Revision 1.29 2002/01/17 21:02:30 jongfoster
262 * Moving all our URL and URL pattern parsing code to urlmatch.c.
264 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
266 * Revision 1.28 2001/12/30 14:07:32 steudten
267 * - Add signal handling (unix)
268 * - Add SIGHUP handler (unix)
269 * - Add creation of pidfile (unix)
270 * - Add action 'top' in rc file (RH)
271 * - Add entry 'SIGNALS' to manpage
272 * - Add exit message to logfile (unix)
274 * Revision 1.27 2001/11/07 00:02:13 steudten
275 * Add line number in error output for lineparsing for
276 * actionsfile and configfile.
277 * Special handling for CLF added.
279 * Revision 1.26 2001/11/05 21:41:43 steudten
280 * Add changes to be a real daemon just for unix os.
281 * (change cwd to /, detach from controlling tty, set
282 * process group and session leader to the own process.
284 * Add some fatal-error log message for failed malloc().
285 * Add '-d' if compiled with 'configure --with-debug' to
286 * enable debug output.
288 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
289 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
290 * threads to call select() simultaneously. So, it's time to do a real, live,
291 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
292 * (native). Both versions will work, but using __OS2__ offers multi-threading.
294 * Revision 1.24 2001/10/23 21:40:30 jongfoster
295 * Added support for enable-edit-actions and enable-remote-toggle config
298 * Revision 1.23 2001/10/07 15:36:00 oes
299 * Introduced new config option "buffer-limit"
301 * Revision 1.22 2001/09/22 16:36:59 jongfoster
302 * Removing unused parameter fs from read_config_line()
304 * Revision 1.21 2001/09/16 17:10:43 jongfoster
305 * Moving function savearg() here, since it was the only thing left in
308 * Revision 1.20 2001/07/30 22:08:36 jongfoster
309 * Tidying up #defines:
310 * - All feature #defines are now of the form FEATURE_xxx
311 * - Permanently turned off WIN_GUI_EDIT
312 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
314 * Revision 1.19 2001/07/15 17:45:16 jongfoster
315 * Removing some unused #includes
317 * Revision 1.18 2001/07/13 14:01:14 oes
318 * - Removed all #ifdef PCRS
319 * - Removed vim-settings
321 * Revision 1.17 2001/06/29 13:31:03 oes
322 * - Improved comments
323 * - Fixed (actionsfile) and sorted hashes
324 * - Introduced admin_address and proxy-info-url
325 * as config parameters
326 * - Renamed config->proxy_args_invocation (which didn't have
327 * the invocation but the options!) to config->proxy_args
328 * - Various adaptions
329 * - Removed logentry from cancelled commit
331 * Revision 1.16 2001/06/09 10:55:28 jongfoster
332 * Changing BUFSIZ ==> BUFFER_SIZE
334 * Revision 1.15 2001/06/07 23:13:40 jongfoster
335 * Merging ACL and forward files into config file.
336 * Cosmetic: Sorting config file options alphabetically.
337 * Cosmetic: Adding brief syntax comments to config file options.
339 * Revision 1.14 2001/06/07 14:46:25 joergs
340 * Missing make_path() added for re_filterfile.
342 * Revision 1.13 2001/06/05 22:33:54 jongfoster
344 * Fixed minor memory leak.
345 * Also now uses make_path to prepend the pathnames.
347 * Revision 1.12 2001/06/05 20:04:09 jongfoster
348 * Now uses _snprintf() in place of snprintf() under Win32.
350 * Revision 1.11 2001/06/04 18:31:58 swa
351 * files are now prefixed with either `confdir' or `logdir'.
352 * `make redhat-dist' replaces both entries confdir and logdir
355 * Revision 1.10 2001/06/03 19:11:54 oes
356 * introduced confdir option
358 * Revision 1.9 2001/06/01 20:06:24 jongfoster
359 * Removed support for "tinygif" option - moved to actions file.
361 * Revision 1.8 2001/05/31 21:27:13 jongfoster
362 * Removed many options from the config file and into the
363 * "actions" file: add_forwarded, suppress_vanilla_wafer,
364 * wafer, add_header, user_agent, referer, from
365 * Also globally replaced "permission" with "action".
367 * Revision 1.7 2001/05/29 09:50:24 jongfoster
368 * Unified blocklist/imagelist/permissionslist.
369 * File format is still under discussion, but the internal changes
372 * Also modified interceptor behaviour:
373 * - We now intercept all URLs beginning with one of the following
374 * prefixes (and *only* these prefixes):
376 * * http://ijbswa.sf.net/config/
377 * * http://ijbswa.sourceforge.net/config/
378 * - New interceptors "home page" - go to http://i.j.b/ to see it.
379 * - Internal changes so that intercepted and fast redirect pages
380 * are not replaced with an image.
381 * - Interceptors now have the option to send a binary page direct
382 * to the client. (i.e. ijb-send-banner uses this)
383 * - Implemented show-url-info interceptor. (Which is why I needed
384 * the above interceptors changes - a typical URL is
385 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
386 * The previous mechanism would not have intercepted that, and
387 * if it had been intercepted then it then it would have replaced
390 * Revision 1.6 2001/05/26 00:28:36 jongfoster
391 * Automatic reloading of config file.
392 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
393 * Most of the global variables have been moved to a new
394 * struct configuration_spec, accessed through csp->config->globalname
395 * Most of the globals remaining are used by the Win32 GUI.
397 * Revision 1.5 2001/05/25 22:34:30 jongfoster
400 * Revision 1.4 2001/05/22 18:46:04 oes
402 * - Enabled filtering banners by size rather than URL
403 * by adding patterns that replace all standard banner
404 * sizes with the "Junkbuster" gif to the re_filterfile
406 * - Enabled filtering WebBugs by providing a pattern
407 * which kills all 1x1 images
409 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
410 * which is selected by the (nonstandard and therefore
411 * capital) letter 'U' in the option string.
412 * It causes the quantifiers to be ungreedy by default.
413 * Appending a ? turns back to greedy (!).
415 * - Added a new interceptor ijb-send-banner, which
416 * sends back the "Junkbuster" gif. Without imagelist or
417 * MSIE detection support, or if tinygif = 1, or the
418 * URL isn't recognized as an imageurl, a lame HTML
419 * explanation is sent instead.
421 * - Added new feature, which permits blocking remote
422 * script redirects and firing back a local redirect
424 * The feature is conditionally compiled, i.e. it
425 * can be disabled with --disable-fast-redirects,
426 * plus it must be activated by a "fast-redirects"
427 * line in the config file, has its own log level
428 * and of course wants to be displayed by show-proxy-args
429 * Note: Boy, all the #ifdefs in 1001 locations and
430 * all the fumbling with configure.in and acconfig.h
431 * were *way* more work than the feature itself :-(
433 * - Because a generic redirect template was needed for
434 * this, tinygif = 3 now uses the same.
436 * - Moved GIFs, and other static HTTP response templates
441 * - Removed some >400 CRs again (Jon, you really worked
444 * Revision 1.3 2001/05/20 01:21:20 jongfoster
445 * Version 2.9.4 checkin.
446 * - Merged popupfile and cookiefile, and added control over PCRS
447 * filtering, in new "permissionsfile".
448 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
449 * file error you now get a message box (in the Win32 GUI) rather
450 * than the program exiting with no explanation.
451 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
453 * - Removed tabs from "config"
454 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
455 * - Bumped up version number.
457 * Revision 1.2 2001/05/17 23:01:01 oes
458 * - Cleaned CRLF's from the sources and related files
460 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
461 * Initial import of version 2.9.3 source tree
464 *********************************************************************/
470 #include <sys/types.h>
484 # include <windows.h>
487 # ifndef _WIN_CONSOLE
489 # endif /* ndef _WIN_CONSOLE */
491 #else /* ifndef _WIN32 */
495 # include <sys/wait.h>
497 # include <sys/time.h>
498 # include <sys/stat.h>
508 #include "miscutil.h"
512 #include "urlmatch.h"
516 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
519 * Fix a problem with Solaris. There should be no effect on other
521 * Solaris's isspace() is a macro which uses it's argument directly
522 * as an array index. Therefore we need to make sure that high-bit
523 * characters generate +ve values, and ideally we also want to make
524 * the argument match the declared parameter type of "int".
526 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
527 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
529 #ifdef FEATURE_TOGGLE
530 /* Privoxy is enabled by default. */
531 int global_toggle_state = 1;
532 #endif /* def FEATURE_TOGGLE */
534 /* The filename of the configfile */
535 const char *configfile = NULL;
538 * CGI functions will later need access to the invocation args,
539 * so we will make argc and argv global.
542 const char **Argv = NULL;
544 static struct file_list *current_configfile = NULL;
548 * This takes the "cryptic" hash of each keyword and aliases them to
549 * something a little more readable. This also makes changing the
550 * hash values easier if they should change or the hash algorthm changes.
551 * Use the included "hash" program to find out what the hash will be
552 * for any string supplied on the command line. (Or just put it in the
553 * config file and read the number from the error message in the log).
555 * Please keep this list sorted alphabetically (but with the Windows
556 * console and GUI specific options last).
559 #define hash_actions_file 1196306641ul /* "actionsfile" */
560 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
561 #define hash_admin_address 4112573064ul /* "admin-address" */
562 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
563 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
564 #define hash_confdir 1978389ul /* "confdir" */
565 #define hash_debug 78263ul /* "debug" */
566 #define hash_deny_access 1227333715ul /* "deny-access" */
567 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
568 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
569 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
570 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
571 #define hash_filterfile 250887266ul /* "filterfile" */
572 #define hash_forward 2029845ul /* "forward" */
573 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
574 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
575 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
576 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
577 #define hash_hostname 10308071ul /* "hostname" */
578 #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */
579 #define hash_listen_address 1255650842ul /* "listen-address" */
580 #define hash_logdir 422889ul /* "logdir" */
581 #define hash_logfile 2114766ul /* "logfile" */
582 #define hash_permit_access 3587953268ul /* "permit-access" */
583 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
584 #define hash_single_threaded 4250084780ul /* "single-threaded" */
585 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
586 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
587 #define hash_templdir 11067889ul /* "templdir" */
588 #define hash_toggle 447966ul /* "toggle" */
589 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
590 #define hash_trustfile 56494766ul /* "trustfile" */
591 #define hash_usermanual 1416668518ul /* "user-manual" */
592 #define hash_activity_animation 1817904738ul /* "activity-animation" */
593 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
594 #define hash_hide_console 2048809870ul /* "hide-console" */
595 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
596 #define hash_log_font_name 2866730124ul /* "log-font-name" */
597 #define hash_log_font_size 2866731014ul /* "log-font-size" */
598 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
599 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
600 #define hash_log_messages 2291744899ul /* "log-messages" */
601 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
604 static void savearg(char *command, char *argument, struct configuration_spec * config);
606 /*********************************************************************
608 * Function : unload_configfile
610 * Description : Free the config structure and all components.
613 * 1 : data: struct configuration_spec to unload
617 *********************************************************************/
618 static void unload_configfile (void * data)
620 struct configuration_spec * config = (struct configuration_spec *)data;
621 struct forward_spec *cur_fwd = config->forward;
625 struct access_control_list *cur_acl = config->acl;
627 while (cur_acl != NULL)
629 struct access_control_list * next_acl = cur_acl->next;
634 #endif /* def FEATURE_ACL */
636 while (cur_fwd != NULL)
638 struct forward_spec * next_fwd = cur_fwd->next;
639 free_url_spec(cur_fwd->url);
641 freez(cur_fwd->gateway_host);
642 freez(cur_fwd->forward_host);
646 config->forward = NULL;
648 freez(config->confdir);
649 freez(config->logdir);
650 freez(config->templdir);
651 freez(config->hostname);
653 freez(config->haddr);
654 freez(config->logfile);
656 for (i = 0; i < MAX_AF_FILES; i++)
658 freez(config->actions_file_short[i]);
659 freez(config->actions_file[i]);
660 freez(config->re_filterfile_short[i]);
661 freez(config->re_filterfile[i]);
664 freez(config->admin_address);
665 freez(config->proxy_info_url);
666 freez(config->proxy_args);
667 freez(config->usermanual);
670 freez(config->trustfile);
671 list_remove_all(config->trust_info);
672 #endif /* def FEATURE_TRUST */
674 for (i = 0; i < MAX_AF_FILES; i++)
676 freez(config->re_filterfile[i]);
683 #ifdef FEATURE_GRACEFUL_TERMINATION
684 /*********************************************************************
686 * Function : unload_current_config_file
688 * Description : Unloads current config file - reset to state at
689 * beginning of program.
695 *********************************************************************/
696 void unload_current_config_file(void)
698 if (current_configfile)
700 current_configfile->unloader = unload_configfile;
701 current_configfile = NULL;
707 /*********************************************************************
709 * Function : load_config
711 * Description : Load the config file and all parameters.
713 * XXX: more than thousand lines long
714 * and thus in serious need of refactoring.
718 * Returns : The configuration_spec, or NULL on error.
720 *********************************************************************/
721 struct configuration_spec * load_config(void)
723 char buf[BUFFER_SIZE];
725 FILE *configfp = NULL;
726 struct configuration_spec * config = NULL;
727 struct client_state * fake_csp;
728 struct file_list *fs;
729 unsigned long linenum = 0;
731 char *logfile = NULL;
732 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
733 int keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
736 if ( !check_file_changed(current_configfile, configfile, &fs))
738 /* No need to load */
739 return ((struct configuration_spec *)current_configfile->f);
743 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
747 if (NULL != current_configfile)
749 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
752 #ifdef FEATURE_TOGGLE
753 global_toggle_state = 1;
754 #endif /* def FEATURE_TOGGLE */
756 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
762 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
763 /* Never get here - LOG_LEVEL_FATAL causes program exit */
767 * This is backwards from how it's usually done.
768 * Following the usual pattern, "fs" would be stored in a member
769 * variable in "csp", and then we'd access "config" from "fs->f",
770 * using a cast. However, "config" is used so often that a
771 * cast each time would be very ugly, and the extra indirection
772 * would waste CPU cycles. Therefore we store "config" in
773 * "csp->config", and "fs" in "csp->config->config_file_list".
775 config->config_file_list = fs;
780 config->multi_threaded = 1;
781 config->hport = HADDR_PORT;
782 config->buffer_limit = 4096 * 1024;
783 config->usermanual = strdup(USER_MANUAL_URL);
784 config->proxy_args = strdup("");
785 config->forwarded_connect_retries = 0;
786 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
787 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
788 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
790 if ((configfp = fopen(configfile, "r")) == NULL)
792 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
794 /* Never get here - LOG_LEVEL_FATAL causes program exit */
797 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
799 char cmd[BUFFER_SIZE];
800 char arg[BUFFER_SIZE];
801 char tmp[BUFFER_SIZE];
803 struct access_control_list *cur_acl;
804 #endif /* def FEATURE_ACL */
805 struct forward_spec *cur_fwd;
808 unsigned long directive_hash;
810 strlcpy(tmp, buf, sizeof(tmp));
812 /* Copy command (i.e. up to space or tab) into cmd */
815 while (*p && (*p != ' ') && (*p != '\t'))
821 /* Skip over the whitespace in buf */
822 while (*p && ((*p == ' ') || (*p == '\t')))
827 /* Copy the argument into arg */
828 strlcpy(arg, p, sizeof(arg));
830 /* Should never happen, but check this anyway */
836 /* Make sure the command field is lower case */
841 *p = (char)ijb_tolower(*p);
845 /* Save the argument for show-proxy-args */
846 savearg(cmd, arg, config);
848 directive_hash = hash_string(cmd);
849 switch (directive_hash)
851 /* *************************************************************************
852 * actionsfile actions-file-name
853 * In confdir by default
854 * *************************************************************************/
855 case hash_actions_file :
857 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
862 if (i >= MAX_AF_FILES)
864 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
865 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
868 config->actions_file_short[i] = strdup(arg);
869 config->actions_file[i] = make_path(config->confdir, arg);
872 /* *************************************************************************
873 * accept-intercepted-requests
874 * *************************************************************************/
875 case hash_accept_intercepted_requests:
876 if ((*arg != '\0') && (0 != atoi(arg)))
878 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
882 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
886 /* *************************************************************************
887 * admin-address email-address
888 * *************************************************************************/
889 case hash_admin_address :
890 freez(config->admin_address);
891 config->admin_address = strdup(arg);
894 /* *************************************************************************
895 * allow-cgi-request-crunching
896 * *************************************************************************/
897 case hash_allow_cgi_request_crunching:
898 if ((*arg != '\0') && (0 != atoi(arg)))
900 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
904 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
908 /* *************************************************************************
910 * *************************************************************************/
911 case hash_buffer_limit :
912 config->buffer_limit = (size_t)(1024 * atoi(arg));
915 /* *************************************************************************
916 * confdir directory-name
917 * *************************************************************************/
919 freez(config->confdir);
920 config->confdir = make_path( NULL, arg);
923 /* *************************************************************************
925 * Specifies debug level, multiple values are ORed together.
926 * *************************************************************************/
928 config->debug |= atoi(arg);
931 /* *************************************************************************
932 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
933 * *************************************************************************/
935 case hash_deny_access:
936 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
938 if ((vec_count != 1) && (vec_count != 2))
940 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
941 "deny-access directive in configuration file.");
942 string_append(&config->proxy_args,
943 "<br>\nWARNING: Wrong number of parameters for "
944 "deny-access directive in configuration file.<br><br>\n");
948 /* allocate a new node */
949 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
953 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
954 /* Never get here - LOG_LEVEL_FATAL causes program exit */
957 cur_acl->action = ACL_DENY;
959 if (acl_addr(vec[0], cur_acl->src) < 0)
961 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
962 "for deny-access directive in configuration file: \"%s\"", vec[0]);
963 string_append(&config->proxy_args,
964 "<br>\nWARNING: Invalid source address, port or netmask "
965 "for deny-access directive in configuration file: \"");
966 string_append(&config->proxy_args,
968 string_append(&config->proxy_args,
975 if (acl_addr(vec[1], cur_acl->dst) < 0)
977 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
978 "for deny-access directive in configuration file: \"%s\"", vec[1]);
979 string_append(&config->proxy_args,
980 "<br>\nWARNING: Invalid destination address, port or netmask "
981 "for deny-access directive in configuration file: \"");
982 string_append(&config->proxy_args,
984 string_append(&config->proxy_args,
992 * Add it to the list. Note we reverse the list to get the
993 * behaviour the user expects. With both the ACL and
994 * actions file, the last match wins. However, the internal
995 * implementations are different: The actions file is stored
996 * in the same order as the file, and scanned completely.
997 * With the ACL, we reverse the order as we load it, then
998 * when we scan it we stop as soon as we get a match.
1000 cur_acl->next = config->acl;
1001 config->acl = cur_acl;
1004 #endif /* def FEATURE_ACL */
1006 /* *************************************************************************
1007 * enable-edit-actions 0|1
1008 * *************************************************************************/
1009 #ifdef FEATURE_CGI_EDIT_ACTIONS
1010 case hash_enable_edit_actions:
1011 if ((*arg != '\0') && (0 != atoi(arg)))
1013 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1017 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1020 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1022 /* *************************************************************************
1023 * enable-remote-toggle 0|1
1024 * *************************************************************************/
1025 #ifdef FEATURE_TOGGLE
1026 case hash_enable_remote_toggle:
1027 if ((*arg != '\0') && (0 != atoi(arg)))
1029 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1033 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1036 #endif /* def FEATURE_TOGGLE */
1038 /* *************************************************************************
1039 * enable-remote-http-toggle 0|1
1040 * *************************************************************************/
1041 case hash_enable_remote_http_toggle:
1042 if ((*arg != '\0') && (0 != atoi(arg)))
1044 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1048 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1052 /* *************************************************************************
1053 * enforce-blocks 0|1
1054 * *************************************************************************/
1055 case hash_enforce_blocks:
1056 #ifdef FEATURE_FORCE_LOAD
1057 if ((*arg != '\0') && (0 != atoi(arg)))
1059 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1063 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1066 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1067 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1068 #endif /* def FEATURE_FORCE_LOAD */
1071 /* *************************************************************************
1072 * filterfile file-name
1073 * In confdir by default.
1074 * *************************************************************************/
1075 case hash_filterfile :
1077 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1082 if (i >= MAX_AF_FILES)
1084 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1085 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1088 config->re_filterfile_short[i] = strdup(arg);
1089 config->re_filterfile[i] = make_path(config->confdir, arg);
1093 /* *************************************************************************
1094 * forward url-pattern (.|http-proxy-host[:port])
1095 * *************************************************************************/
1097 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1101 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1102 "directive in configuration file.");
1103 string_append(&config->proxy_args,
1104 "<br>\nWARNING: Wrong number of parameters for "
1105 "forward directive in configuration file.");
1109 /* allocate a new node */
1110 cur_fwd = zalloc(sizeof(*cur_fwd));
1111 if (cur_fwd == NULL)
1113 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1114 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1118 cur_fwd->type = SOCKS_NONE;
1120 /* Save the URL pattern */
1121 if (create_url_spec(cur_fwd->url, vec[0]))
1123 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1124 "directive in configuration file.");
1125 string_append(&config->proxy_args,
1126 "<br>\nWARNING: Bad URL specifier for "
1127 "forward directive in configuration file.");
1131 /* Parse the parent HTTP proxy host:port */
1134 if (strcmp(p, ".") != 0)
1136 cur_fwd->forward_host = strdup(p);
1138 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1141 cur_fwd->forward_port = atoi(p);
1144 if (cur_fwd->forward_port <= 0)
1146 cur_fwd->forward_port = 8000;
1151 cur_fwd->next = config->forward;
1152 config->forward = cur_fwd;
1156 /* *************************************************************************
1157 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1158 * *************************************************************************/
1159 case hash_forward_socks4:
1160 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1164 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1165 "forward-socks4 directive in configuration file.");
1166 string_append(&config->proxy_args,
1167 "<br>\nWARNING: Wrong number of parameters for "
1168 "forward-socks4 directive in configuration file.");
1172 /* allocate a new node */
1173 cur_fwd = zalloc(sizeof(*cur_fwd));
1174 if (cur_fwd == NULL)
1176 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1177 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1181 cur_fwd->type = SOCKS_4;
1183 /* Save the URL pattern */
1184 if (create_url_spec(cur_fwd->url, vec[0]))
1186 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1187 "directive in configuration file.");
1188 string_append(&config->proxy_args,
1189 "<br>\nWARNING: Bad URL specifier for "
1190 "forward-socks4 directive in configuration file.");
1194 /* Parse the SOCKS proxy host[:port] */
1197 if (strcmp(p, ".") != 0)
1199 cur_fwd->gateway_host = strdup(p);
1201 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1204 cur_fwd->gateway_port = atoi(p);
1206 if (cur_fwd->gateway_port <= 0)
1208 cur_fwd->gateway_port = 1080;
1212 /* Parse the parent HTTP proxy host[:port] */
1215 if (strcmp(p, ".") != 0)
1217 cur_fwd->forward_host = strdup(p);
1219 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1222 cur_fwd->forward_port = atoi(p);
1225 if (cur_fwd->forward_port <= 0)
1227 cur_fwd->forward_port = 8000;
1232 cur_fwd->next = config->forward;
1233 config->forward = cur_fwd;
1237 /* *************************************************************************
1238 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1239 * *************************************************************************/
1240 case hash_forward_socks4a:
1241 case hash_forward_socks5:
1242 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1246 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1247 "forward-socks4a directive in configuration file.");
1248 string_append(&config->proxy_args,
1249 "<br>\nWARNING: Wrong number of parameters for "
1250 "forward-socks4a directive in configuration file.");
1254 /* allocate a new node */
1255 cur_fwd = zalloc(sizeof(*cur_fwd));
1256 if (cur_fwd == NULL)
1258 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1259 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1263 if (directive_hash == hash_forward_socks4a)
1265 cur_fwd->type = SOCKS_4A;
1269 cur_fwd->type = SOCKS_5;
1272 /* Save the URL pattern */
1273 if (create_url_spec(cur_fwd->url, vec[0]))
1275 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1276 "directive in configuration file.");
1277 string_append(&config->proxy_args,
1278 "<br>\nWARNING: Bad URL specifier for "
1279 "forward-socks4a directive in configuration file.");
1283 /* Parse the SOCKS proxy host[:port] */
1286 cur_fwd->gateway_host = strdup(p);
1288 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1291 cur_fwd->gateway_port = atoi(p);
1293 if (cur_fwd->gateway_port <= 0)
1295 cur_fwd->gateway_port = 1080;
1298 /* Parse the parent HTTP proxy host[:port] */
1301 if (strcmp(p, ".") != 0)
1303 cur_fwd->forward_host = strdup(p);
1305 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1308 cur_fwd->forward_port = atoi(p);
1311 if (cur_fwd->forward_port <= 0)
1313 cur_fwd->forward_port = 8000;
1318 cur_fwd->next = config->forward;
1319 config->forward = cur_fwd;
1323 /* *************************************************************************
1324 * forwarded-connect-retries n
1325 * *************************************************************************/
1326 case hash_forwarded_connect_retries :
1327 config->forwarded_connect_retries = atoi(arg);
1330 /* *************************************************************************
1331 * hostname hostname-to-show-on-cgi-pages
1332 * *************************************************************************/
1333 case hash_hostname :
1334 freez(config->hostname);
1335 config->hostname = strdup(arg);
1336 if (NULL == config->hostname)
1338 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1342 /* *************************************************************************
1343 * keep-alive-timeout timeout
1344 * *************************************************************************/
1345 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1346 case hash_keep_alive_timeout :
1349 int timeout = atoi(arg);
1352 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1353 keep_alive_timeout = timeout;
1357 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1363 /* *************************************************************************
1364 * listen-address [ip][:port]
1365 * *************************************************************************/
1366 case hash_listen_address :
1367 freez(config->haddr);
1368 config->haddr = strdup(arg);
1371 /* *************************************************************************
1372 * logdir directory-name
1373 * *************************************************************************/
1375 freez(config->logdir);
1376 config->logdir = make_path(NULL, arg);
1379 /* *************************************************************************
1380 * logfile log-file-name
1381 * In logdir by default
1382 * *************************************************************************/
1386 logfile = make_path(config->logdir, arg);
1387 if (NULL == logfile)
1389 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1394 /* *************************************************************************
1395 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1396 * *************************************************************************/
1398 case hash_permit_access:
1399 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1401 if ((vec_count != 1) && (vec_count != 2))
1403 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1404 "permit-access directive in configuration file.");
1405 string_append(&config->proxy_args,
1406 "<br>\nWARNING: Wrong number of parameters for "
1407 "permit-access directive in configuration file.<br><br>\n");
1412 /* allocate a new node */
1413 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1415 if (cur_acl == NULL)
1417 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1418 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1421 cur_acl->action = ACL_PERMIT;
1423 if (acl_addr(vec[0], cur_acl->src) < 0)
1425 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1426 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1427 string_append(&config->proxy_args,
1428 "<br>\nWARNING: Invalid source address, port or netmask for "
1429 "permit-access directive in configuration file: \"");
1430 string_append(&config->proxy_args,
1432 string_append(&config->proxy_args,
1439 if (acl_addr(vec[1], cur_acl->dst) < 0)
1441 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1442 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1443 string_append(&config->proxy_args,
1444 "<br>\nWARNING: Invalid destination address, port or netmask for "
1445 "permit-access directive in configuration file: \"");
1446 string_append(&config->proxy_args,
1448 string_append(&config->proxy_args,
1456 * Add it to the list. Note we reverse the list to get the
1457 * behaviour the user expects. With both the ACL and
1458 * actions file, the last match wins. However, the internal
1459 * implementations are different: The actions file is stored
1460 * in the same order as the file, and scanned completely.
1461 * With the ACL, we reverse the order as we load it, then
1462 * when we scan it we stop as soon as we get a match.
1464 cur_acl->next = config->acl;
1465 config->acl = cur_acl;
1468 #endif /* def FEATURE_ACL */
1470 /* *************************************************************************
1471 * proxy-info-url url
1472 * *************************************************************************/
1473 case hash_proxy_info_url :
1474 freez(config->proxy_info_url);
1475 config->proxy_info_url = strdup(arg);
1478 /* *************************************************************************
1480 * *************************************************************************/
1481 case hash_single_threaded :
1482 config->multi_threaded = 0;
1485 /* *************************************************************************
1486 * split-large-cgi-forms
1487 * *************************************************************************/
1488 case hash_split_large_cgi_forms :
1489 if ((*arg != '\0') && (0 != atoi(arg)))
1491 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1495 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1499 /* *************************************************************************
1500 * templdir directory-name
1501 * *************************************************************************/
1502 case hash_templdir :
1503 freez(config->templdir);
1504 config->templdir = make_path(NULL, arg);
1507 /* *************************************************************************
1509 * *************************************************************************/
1510 #ifdef FEATURE_TOGGLE
1512 global_toggle_state = atoi(arg);
1514 #endif /* def FEATURE_TOGGLE */
1516 /* *************************************************************************
1517 * trust-info-url url
1518 * *************************************************************************/
1519 #ifdef FEATURE_TRUST
1520 case hash_trust_info_url :
1521 enlist(config->trust_info, arg);
1523 #endif /* def FEATURE_TRUST */
1525 /* *************************************************************************
1526 * trustfile filename
1527 * (In confdir by default.)
1528 * *************************************************************************/
1529 #ifdef FEATURE_TRUST
1530 case hash_trustfile :
1531 freez(config->trustfile);
1532 config->trustfile = make_path(config->confdir, arg);
1534 #endif /* def FEATURE_TRUST */
1536 /* *************************************************************************
1538 * *************************************************************************/
1539 case hash_usermanual :
1540 freez(config->usermanual);
1541 config->usermanual = strdup(arg);
1544 /* *************************************************************************
1545 * Win32 Console options:
1546 * *************************************************************************/
1548 /* *************************************************************************
1550 * *************************************************************************/
1552 case hash_hide_console :
1555 #endif /*def _WIN_CONSOLE*/
1558 /* *************************************************************************
1559 * Win32 GUI options:
1560 * *************************************************************************/
1562 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1563 /* *************************************************************************
1564 * activity-animation (0|1)
1565 * *************************************************************************/
1566 case hash_activity_animation :
1567 g_bShowActivityAnimation = atoi(arg);
1570 /* *************************************************************************
1571 * close-button-minimizes (0|1)
1572 * *************************************************************************/
1573 case hash_close_button_minimizes :
1574 g_bCloseHidesWindow = atoi(arg);
1577 /* *************************************************************************
1578 * log-buffer-size (0|1)
1579 * *************************************************************************/
1580 case hash_log_buffer_size :
1581 g_bLimitBufferSize = atoi(arg);
1584 /* *************************************************************************
1585 * log-font-name fontnane
1586 * *************************************************************************/
1587 case hash_log_font_name :
1588 strcpy( g_szFontFaceName, arg );
1591 /* *************************************************************************
1593 * *************************************************************************/
1594 case hash_log_font_size :
1595 g_nFontSize = atoi(arg);
1598 /* *************************************************************************
1599 * log-highlight-messages (0|1)
1600 * *************************************************************************/
1601 case hash_log_highlight_messages :
1602 g_bHighlightMessages = atoi(arg);
1605 /* *************************************************************************
1607 * *************************************************************************/
1608 case hash_log_max_lines :
1609 g_nMaxBufferLines = atoi(arg);
1612 /* *************************************************************************
1613 * log-messages (0|1)
1614 * *************************************************************************/
1615 case hash_log_messages :
1616 g_bLogMessages = atoi(arg);
1619 /* *************************************************************************
1620 * show-on-task-bar (0|1)
1621 * *************************************************************************/
1622 case hash_show_on_task_bar :
1623 g_bShowOnTaskBar = atoi(arg);
1626 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1629 /* *************************************************************************
1630 * Warnings about unsupported features
1631 * *************************************************************************/
1633 case hash_deny_access:
1634 #endif /* ndef FEATURE_ACL */
1635 #ifndef FEATURE_CGI_EDIT_ACTIONS
1636 case hash_enable_edit_actions:
1637 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1638 #ifndef FEATURE_TOGGLE
1639 case hash_enable_remote_toggle:
1640 #endif /* ndef FEATURE_TOGGLE */
1642 case hash_permit_access:
1643 #endif /* ndef FEATURE_ACL */
1644 #ifndef FEATURE_TOGGLE
1646 #endif /* ndef FEATURE_TOGGLE */
1647 #ifndef FEATURE_TRUST
1648 case hash_trustfile :
1649 case hash_trust_info_url :
1650 #endif /* ndef FEATURE_TRUST */
1652 #ifndef _WIN_CONSOLE
1653 case hash_hide_console :
1654 #endif /* ndef _WIN_CONSOLE */
1656 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1657 case hash_activity_animation :
1658 case hash_close_button_minimizes :
1659 case hash_log_buffer_size :
1660 case hash_log_font_name :
1661 case hash_log_font_size :
1662 case hash_log_highlight_messages :
1663 case hash_log_max_lines :
1664 case hash_log_messages :
1665 case hash_show_on_task_bar :
1666 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1667 /* These warnings are annoying - so hide them. -- Jon */
1668 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1671 /* *************************************************************************/
1673 /* *************************************************************************/
1675 * I decided that I liked this better as a warning than an
1676 * error. To change back to an error, just change log level
1677 * to LOG_LEVEL_FATAL.
1679 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1680 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1681 string_append(&config->proxy_args,
1682 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1685 /* *************************************************************************/
1686 } /* end switch( hash_string(cmd) ) */
1687 } /* end while ( read_config_line(...) ) */
1691 set_debug_level(config->debug);
1692 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1693 set_keep_alive_timeout(keep_alive_timeout);
1696 freez(config->logfile);
1700 if (NULL != logfile)
1702 config->logfile = logfile;
1703 init_error_log(Argv[0], config->logfile);
1711 if (NULL == config->proxy_args)
1713 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1716 if (config->actions_file[0])
1718 add_loader(load_action_files, config);
1721 if (config->re_filterfile[0])
1723 add_loader(load_re_filterfiles, config);
1726 #ifdef FEATURE_TRUST
1727 if (config->trustfile)
1729 add_loader(load_trustfile, config);
1731 #endif /* def FEATURE_TRUST */
1733 if ( NULL == config->haddr )
1735 config->haddr = strdup( HADDR_DEFAULT );
1738 if ( NULL != config->haddr )
1740 if (NULL != (p = strchr(config->haddr, ':')))
1745 config->hport = atoi(p);
1749 if (config->hport <= 0)
1752 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1753 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1755 if (*config->haddr == '\0')
1758 * Only the port specified. We stored it in config->hport
1759 * and don't need its text representation anymore.
1761 freez(config->haddr);
1766 * Want to run all the loaders once now.
1768 * Need to set up a fake csp, so they can get to the config.
1770 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1771 fake_csp->config = config;
1773 if (run_loader(fake_csp))
1776 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1777 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1781 /* FIXME: this is a kludge for win32 */
1782 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1784 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1785 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1786 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1788 #ifdef FEATURE_TRUST
1789 g_trustfile = config->trustfile;
1790 #endif /* def FEATURE_TRUST */
1793 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1794 /* FIXME: end kludge */
1797 config->need_bind = 1;
1799 if (current_configfile)
1801 struct configuration_spec * oldcfg = (struct configuration_spec *)
1802 current_configfile->f;
1804 * Check if config->haddr,hport == oldcfg->haddr,hport
1806 * The following could be written more compactly as a single,
1807 * (unreadably long) if statement.
1809 config->need_bind = 0;
1810 if (config->hport != oldcfg->hport)
1812 config->need_bind = 1;
1814 else if (config->haddr == NULL)
1816 if (oldcfg->haddr != NULL)
1818 config->need_bind = 1;
1821 else if (oldcfg->haddr == NULL)
1823 config->need_bind = 1;
1825 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1827 config->need_bind = 1;
1830 current_configfile->unloader = unload_configfile;
1833 fs->next = files->next;
1836 current_configfile = fs;
1842 /*********************************************************************
1844 * Function : savearg
1846 * Description : Called from `load_config'. It saves each non-empty
1847 * and non-comment line from config into
1848 * config->proxy_args. This is used to create the
1849 * show-proxy-args page. On error, frees
1850 * config->proxy_args and sets it to NULL
1853 * 1 : command = config setting that was found
1854 * 2 : argument = the setting's argument (if any)
1855 * 3 : config = Configuration to save into.
1859 *********************************************************************/
1860 static void savearg(char *command, char *argument, struct configuration_spec * config)
1869 * Add config option name embedded in
1870 * link to its section in the user-manual
1872 buf = strdup("\n<a href=\"");
1873 if (!strncmpic(config->usermanual, "file://", 7) ||
1874 !strncmpic(config->usermanual, "http", 4))
1876 string_append(&buf, config->usermanual);
1880 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1882 string_append(&buf, CONFIG_HELP_PREFIX);
1883 string_join (&buf, string_toupper(command));
1884 string_append(&buf, "\">");
1885 string_append(&buf, command);
1886 string_append(&buf, "</a> ");
1890 freez(config->proxy_args);
1894 if ( (NULL != argument) && ('\0' != *argument) )
1896 s = html_encode(argument);
1900 freez(config->proxy_args);
1904 if (strncmpic(argument, "http://", 7) == 0)
1906 string_append(&buf, "<a href=\"");
1907 string_append(&buf, s);
1908 string_append(&buf, "\">");
1909 string_join (&buf, s);
1910 string_append(&buf, "</a>");
1914 string_join (&buf, s);
1918 string_append(&buf, "<br>");
1919 string_join(&config->proxy_args, buf);