1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.82 2008/11/16 12:43:49 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.82 2008/11/16 12:43:49 fabiankeil
39 * Turn keep-alive support into a runtime feature
40 * that is disabled by setting keep-alive-timeout
41 * to a negative value.
43 * Revision 1.81 2008/11/13 09:08:42 fabiankeil
44 * Add new config option: keep-alive-timeout.
46 * Revision 1.80 2008/08/31 15:59:03 fabiankeil
47 * There's no reason to let remote toggling support depend
48 * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
50 * Revision 1.79 2008/08/30 12:03:07 fabiankeil
51 * Remove FEATURE_COOKIE_JAR.
53 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
54 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
55 * disabled, log a message that blocks will always be enforced
56 * instead of complaining about an unrecognized directive.
57 * Reported by Pietro Leone.
59 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
60 * Reuse directive_hash and don't hash the same directive twice.
62 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
63 * - Merge three string_append() calls.
64 * - Remove useless assertion.
66 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
67 * Rename load_actions_file() and load_re_filterfile()
68 * as they load multiple files "now".
70 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
71 * Add hostname directive. Closes PR#1918189.
73 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
76 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
77 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
79 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
80 * Reword "unrecognized directive" warning, use better
81 * mark up and add a <br>. Fixes parts of #1856559.
83 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
84 * Plug memory leak if listen-address only specifies the port.
86 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
87 * Relocate daemon-mode-related log messages to make sure
88 * they aren't shown again in case of configuration reloads.
90 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
91 * Plug memory leak introduced with my last commit.
93 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
94 * When in daemon mode, close stderr after the configuration file has been
95 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
97 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
98 * #1763173 from Stefan Huehner: declare unload_configfile() static.
100 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
101 * As Hal noticed, checking dispatch_cgi() as the last cruncher
102 * looks like a bug if CGI requests are blocked unintentionally,
103 * so don't do it unless the user enabled the new config option
104 * "allow-cgi-request-crunching".
106 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
107 * - Use strlcpy() instead of strcpy().
108 * - Stop treating actions files special. Expect a complete file name
109 * (with or without path) like it's done for the rest of the files.
111 * - Remove an unnecessary temporary memory allocation.
112 * - Don't log anything to the console when running as
113 * daemon and no errors occurred.
115 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
116 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
118 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
119 * New config option: enforce-blocks.
121 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
122 * - Mention other reasons why acl directive loading might have failed.
123 * - Don't log the acl source if the acl destination is to blame.
125 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
126 * Add new config option "templdir" to
127 * change the templates directory.
129 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
130 * Added config option accept-intercepted-requests
131 * and disabled it by default.
133 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
134 * Fix gcc43 compiler warnings.
136 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
137 * Add config option "split-large-forms"
138 * to work around the browser bug reported
141 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
142 * Move the <br> in the generated HTML for the config
143 * options from the beginning of the string to its end.
144 * Keeps the white space in balance.
146 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
147 * Fix memory leak in case of config file reloads.
149 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
150 * Modified kludge for win32 to make ming32 menu
151 * "Options/Edit Filters" (sort of) work again.
152 * Same limitations as for the action files apply.
155 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
156 * Incorporate modified version of Roland Rosenfeld's patch to
157 * optionally access the user-manual via Privoxy. Closes patch 679075.
159 * Formatting changed to Privoxy style, added call to
160 * cgi_error_no_template if the requested file doesn't
161 * exist and modified check whether or not Privoxy itself
162 * should serve the manual. Should work cross-platform now.
164 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
165 * Added config option enable-remote-http-toggle
166 * to specify if Privoxy should recognize special
167 * headers (currently only X-Filter) to change its
168 * behaviour. Disabled by default.
170 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
171 * Make number of retries in case of forwarded-connect problems
172 * a config file option (forwarded-connect-retries) and use 0 as
175 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
176 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
177 * with what was really the latest development (the v_3_0_branch branch)
179 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
180 * Don't forget to malloc space for the null terminator...
182 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
183 * Multiple filter file support
185 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
186 * Closed two memory leaks; hopefully the last remaining ones
187 * (in the main execution paths, anyway).
189 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
190 * Addressed bug #719435
191 * - Extraneous filterfile directives now logged as errors
192 * - This and unrecnonised directives now really obvious on status page
194 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
195 * Cosmetic: Renamed cryptic variable
197 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
198 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
200 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
201 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
203 * Revision 1.48 2002/05/14 21:30:38 oes
204 * savearg now uses own linking code instead of (now special-cased) add_help_link
206 * Revision 1.47 2002/05/12 21:36:29 jongfoster
207 * Correcting function comments
209 * Revision 1.46 2002/04/26 12:55:14 oes
210 * - New option "user-manual", defaults to our site
211 * via project.h #define
212 * - savearg now embeds option names in help links
214 * Revision 1.45 2002/04/24 02:11:54 oes
215 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
217 * Revision 1.44 2002/04/08 20:37:13 swa
220 * Revision 1.43 2002/04/08 20:36:50 swa
223 * Revision 1.42 2002/04/05 15:50:15 oes
224 * fix for invalid HTML proxy_args
226 * Revision 1.41 2002/03/31 17:19:00 jongfoster
227 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
229 * Revision 1.40 2002/03/26 22:29:55 swa
230 * we have a new homepage!
232 * Revision 1.39 2002/03/24 13:25:43 swa
233 * name change related issues
235 * Revision 1.38 2002/03/24 13:05:48 jongfoster
236 * Renaming re_filterfile to filterfile
238 * Revision 1.37 2002/03/16 23:54:06 jongfoster
239 * Adding graceful termination feature, to help look for memory leaks.
240 * If you enable this (which, by design, has to be done by hand
241 * editing config.h) and then go to http://i.j.b/die, then the program
242 * will exit cleanly after the *next* request. It should free all the
243 * memory that was used.
245 * Revision 1.36 2002/03/13 00:27:05 jongfoster
248 * Revision 1.35 2002/03/07 03:52:44 oes
249 * Set logging to tty for --no-daemon mode
251 * Revision 1.34 2002/03/06 23:14:35 jongfoster
252 * Trivial cosmetic changes to make function comments easier to find.
254 * Revision 1.33 2002/03/05 04:52:42 oes
255 * Deleted non-errlog debugging code
257 * Revision 1.32 2002/03/04 18:24:53 oes
258 * Re-enabled output of unknown config directive hash
260 * Revision 1.31 2002/03/03 15:07:20 oes
261 * Re-enabled automatic config reloading
263 * Revision 1.30 2002/01/22 23:31:43 jongfoster
264 * Replacing strsav() with string_append()
266 * Revision 1.29 2002/01/17 21:02:30 jongfoster
267 * Moving all our URL and URL pattern parsing code to urlmatch.c.
269 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
271 * Revision 1.28 2001/12/30 14:07:32 steudten
272 * - Add signal handling (unix)
273 * - Add SIGHUP handler (unix)
274 * - Add creation of pidfile (unix)
275 * - Add action 'top' in rc file (RH)
276 * - Add entry 'SIGNALS' to manpage
277 * - Add exit message to logfile (unix)
279 * Revision 1.27 2001/11/07 00:02:13 steudten
280 * Add line number in error output for lineparsing for
281 * actionsfile and configfile.
282 * Special handling for CLF added.
284 * Revision 1.26 2001/11/05 21:41:43 steudten
285 * Add changes to be a real daemon just for unix os.
286 * (change cwd to /, detach from controlling tty, set
287 * process group and session leader to the own process.
289 * Add some fatal-error log message for failed malloc().
290 * Add '-d' if compiled with 'configure --with-debug' to
291 * enable debug output.
293 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
294 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
295 * threads to call select() simultaneously. So, it's time to do a real, live,
296 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
297 * (native). Both versions will work, but using __OS2__ offers multi-threading.
299 * Revision 1.24 2001/10/23 21:40:30 jongfoster
300 * Added support for enable-edit-actions and enable-remote-toggle config
303 * Revision 1.23 2001/10/07 15:36:00 oes
304 * Introduced new config option "buffer-limit"
306 * Revision 1.22 2001/09/22 16:36:59 jongfoster
307 * Removing unused parameter fs from read_config_line()
309 * Revision 1.21 2001/09/16 17:10:43 jongfoster
310 * Moving function savearg() here, since it was the only thing left in
313 * Revision 1.20 2001/07/30 22:08:36 jongfoster
314 * Tidying up #defines:
315 * - All feature #defines are now of the form FEATURE_xxx
316 * - Permanently turned off WIN_GUI_EDIT
317 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
319 * Revision 1.19 2001/07/15 17:45:16 jongfoster
320 * Removing some unused #includes
322 * Revision 1.18 2001/07/13 14:01:14 oes
323 * - Removed all #ifdef PCRS
324 * - Removed vim-settings
326 * Revision 1.17 2001/06/29 13:31:03 oes
327 * - Improved comments
328 * - Fixed (actionsfile) and sorted hashes
329 * - Introduced admin_address and proxy-info-url
330 * as config parameters
331 * - Renamed config->proxy_args_invocation (which didn't have
332 * the invocation but the options!) to config->proxy_args
333 * - Various adaptions
334 * - Removed logentry from cancelled commit
336 * Revision 1.16 2001/06/09 10:55:28 jongfoster
337 * Changing BUFSIZ ==> BUFFER_SIZE
339 * Revision 1.15 2001/06/07 23:13:40 jongfoster
340 * Merging ACL and forward files into config file.
341 * Cosmetic: Sorting config file options alphabetically.
342 * Cosmetic: Adding brief syntax comments to config file options.
344 * Revision 1.14 2001/06/07 14:46:25 joergs
345 * Missing make_path() added for re_filterfile.
347 * Revision 1.13 2001/06/05 22:33:54 jongfoster
349 * Fixed minor memory leak.
350 * Also now uses make_path to prepend the pathnames.
352 * Revision 1.12 2001/06/05 20:04:09 jongfoster
353 * Now uses _snprintf() in place of snprintf() under Win32.
355 * Revision 1.11 2001/06/04 18:31:58 swa
356 * files are now prefixed with either `confdir' or `logdir'.
357 * `make redhat-dist' replaces both entries confdir and logdir
360 * Revision 1.10 2001/06/03 19:11:54 oes
361 * introduced confdir option
363 * Revision 1.9 2001/06/01 20:06:24 jongfoster
364 * Removed support for "tinygif" option - moved to actions file.
366 * Revision 1.8 2001/05/31 21:27:13 jongfoster
367 * Removed many options from the config file and into the
368 * "actions" file: add_forwarded, suppress_vanilla_wafer,
369 * wafer, add_header, user_agent, referer, from
370 * Also globally replaced "permission" with "action".
372 * Revision 1.7 2001/05/29 09:50:24 jongfoster
373 * Unified blocklist/imagelist/permissionslist.
374 * File format is still under discussion, but the internal changes
377 * Also modified interceptor behaviour:
378 * - We now intercept all URLs beginning with one of the following
379 * prefixes (and *only* these prefixes):
381 * * http://ijbswa.sf.net/config/
382 * * http://ijbswa.sourceforge.net/config/
383 * - New interceptors "home page" - go to http://i.j.b/ to see it.
384 * - Internal changes so that intercepted and fast redirect pages
385 * are not replaced with an image.
386 * - Interceptors now have the option to send a binary page direct
387 * to the client. (i.e. ijb-send-banner uses this)
388 * - Implemented show-url-info interceptor. (Which is why I needed
389 * the above interceptors changes - a typical URL is
390 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
391 * The previous mechanism would not have intercepted that, and
392 * if it had been intercepted then it then it would have replaced
395 * Revision 1.6 2001/05/26 00:28:36 jongfoster
396 * Automatic reloading of config file.
397 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
398 * Most of the global variables have been moved to a new
399 * struct configuration_spec, accessed through csp->config->globalname
400 * Most of the globals remaining are used by the Win32 GUI.
402 * Revision 1.5 2001/05/25 22:34:30 jongfoster
405 * Revision 1.4 2001/05/22 18:46:04 oes
407 * - Enabled filtering banners by size rather than URL
408 * by adding patterns that replace all standard banner
409 * sizes with the "Junkbuster" gif to the re_filterfile
411 * - Enabled filtering WebBugs by providing a pattern
412 * which kills all 1x1 images
414 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
415 * which is selected by the (nonstandard and therefore
416 * capital) letter 'U' in the option string.
417 * It causes the quantifiers to be ungreedy by default.
418 * Appending a ? turns back to greedy (!).
420 * - Added a new interceptor ijb-send-banner, which
421 * sends back the "Junkbuster" gif. Without imagelist or
422 * MSIE detection support, or if tinygif = 1, or the
423 * URL isn't recognized as an imageurl, a lame HTML
424 * explanation is sent instead.
426 * - Added new feature, which permits blocking remote
427 * script redirects and firing back a local redirect
429 * The feature is conditionally compiled, i.e. it
430 * can be disabled with --disable-fast-redirects,
431 * plus it must be activated by a "fast-redirects"
432 * line in the config file, has its own log level
433 * and of course wants to be displayed by show-proxy-args
434 * Note: Boy, all the #ifdefs in 1001 locations and
435 * all the fumbling with configure.in and acconfig.h
436 * were *way* more work than the feature itself :-(
438 * - Because a generic redirect template was needed for
439 * this, tinygif = 3 now uses the same.
441 * - Moved GIFs, and other static HTTP response templates
446 * - Removed some >400 CRs again (Jon, you really worked
449 * Revision 1.3 2001/05/20 01:21:20 jongfoster
450 * Version 2.9.4 checkin.
451 * - Merged popupfile and cookiefile, and added control over PCRS
452 * filtering, in new "permissionsfile".
453 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
454 * file error you now get a message box (in the Win32 GUI) rather
455 * than the program exiting with no explanation.
456 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
458 * - Removed tabs from "config"
459 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
460 * - Bumped up version number.
462 * Revision 1.2 2001/05/17 23:01:01 oes
463 * - Cleaned CRLF's from the sources and related files
465 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
466 * Initial import of version 2.9.3 source tree
469 *********************************************************************/
475 #include <sys/types.h>
489 # include <windows.h>
492 # ifndef _WIN_CONSOLE
494 # endif /* ndef _WIN_CONSOLE */
496 #else /* ifndef _WIN32 */
500 # include <sys/wait.h>
502 # include <sys/time.h>
503 # include <sys/stat.h>
513 #include "miscutil.h"
517 #include "urlmatch.h"
521 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
524 * Fix a problem with Solaris. There should be no effect on other
526 * Solaris's isspace() is a macro which uses it's argument directly
527 * as an array index. Therefore we need to make sure that high-bit
528 * characters generate +ve values, and ideally we also want to make
529 * the argument match the declared parameter type of "int".
531 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
532 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
534 #ifdef FEATURE_TOGGLE
535 /* Privoxy is enabled by default. */
536 int global_toggle_state = 1;
537 #endif /* def FEATURE_TOGGLE */
539 /* The filename of the configfile */
540 const char *configfile = NULL;
543 * CGI functions will later need access to the invocation args,
544 * so we will make argc and argv global.
547 const char **Argv = NULL;
549 static struct file_list *current_configfile = NULL;
553 * This takes the "cryptic" hash of each keyword and aliases them to
554 * something a little more readable. This also makes changing the
555 * hash values easier if they should change or the hash algorthm changes.
556 * Use the included "hash" program to find out what the hash will be
557 * for any string supplied on the command line. (Or just put it in the
558 * config file and read the number from the error message in the log).
560 * Please keep this list sorted alphabetically (but with the Windows
561 * console and GUI specific options last).
564 #define hash_actions_file 1196306641ul /* "actionsfile" */
565 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
566 #define hash_admin_address 4112573064ul /* "admin-address" */
567 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
568 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
569 #define hash_confdir 1978389ul /* "confdir" */
570 #define hash_debug 78263ul /* "debug" */
571 #define hash_deny_access 1227333715ul /* "deny-access" */
572 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
573 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
574 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
575 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
576 #define hash_filterfile 250887266ul /* "filterfile" */
577 #define hash_forward 2029845ul /* "forward" */
578 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
579 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
580 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
581 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
582 #define hash_hostname 10308071ul /* "hostname" */
583 #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */
584 #define hash_listen_address 1255650842ul /* "listen-address" */
585 #define hash_logdir 422889ul /* "logdir" */
586 #define hash_logfile 2114766ul /* "logfile" */
587 #define hash_permit_access 3587953268ul /* "permit-access" */
588 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
589 #define hash_single_threaded 4250084780ul /* "single-threaded" */
590 #define hash_socket_timeout 1809001761ul /* "socket-timeout" */
591 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
592 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
593 #define hash_templdir 11067889ul /* "templdir" */
594 #define hash_toggle 447966ul /* "toggle" */
595 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
596 #define hash_trustfile 56494766ul /* "trustfile" */
597 #define hash_usermanual 1416668518ul /* "user-manual" */
598 #define hash_activity_animation 1817904738ul /* "activity-animation" */
599 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
600 #define hash_hide_console 2048809870ul /* "hide-console" */
601 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
602 #define hash_log_font_name 2866730124ul /* "log-font-name" */
603 #define hash_log_font_size 2866731014ul /* "log-font-size" */
604 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
605 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
606 #define hash_log_messages 2291744899ul /* "log-messages" */
607 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
610 static void savearg(char *command, char *argument, struct configuration_spec * config);
612 /*********************************************************************
614 * Function : unload_configfile
616 * Description : Free the config structure and all components.
619 * 1 : data: struct configuration_spec to unload
623 *********************************************************************/
624 static void unload_configfile (void * data)
626 struct configuration_spec * config = (struct configuration_spec *)data;
627 struct forward_spec *cur_fwd = config->forward;
631 struct access_control_list *cur_acl = config->acl;
633 while (cur_acl != NULL)
635 struct access_control_list * next_acl = cur_acl->next;
640 #endif /* def FEATURE_ACL */
642 while (cur_fwd != NULL)
644 struct forward_spec * next_fwd = cur_fwd->next;
645 free_url_spec(cur_fwd->url);
647 freez(cur_fwd->gateway_host);
648 freez(cur_fwd->forward_host);
652 config->forward = NULL;
654 freez(config->confdir);
655 freez(config->logdir);
656 freez(config->templdir);
657 freez(config->hostname);
659 freez(config->haddr);
660 freez(config->logfile);
662 for (i = 0; i < MAX_AF_FILES; i++)
664 freez(config->actions_file_short[i]);
665 freez(config->actions_file[i]);
666 freez(config->re_filterfile_short[i]);
667 freez(config->re_filterfile[i]);
670 freez(config->admin_address);
671 freez(config->proxy_info_url);
672 freez(config->proxy_args);
673 freez(config->usermanual);
676 freez(config->trustfile);
677 list_remove_all(config->trust_info);
678 #endif /* def FEATURE_TRUST */
680 for (i = 0; i < MAX_AF_FILES; i++)
682 freez(config->re_filterfile[i]);
689 #ifdef FEATURE_GRACEFUL_TERMINATION
690 /*********************************************************************
692 * Function : unload_current_config_file
694 * Description : Unloads current config file - reset to state at
695 * beginning of program.
701 *********************************************************************/
702 void unload_current_config_file(void)
704 if (current_configfile)
706 current_configfile->unloader = unload_configfile;
707 current_configfile = NULL;
713 /*********************************************************************
715 * Function : load_config
717 * Description : Load the config file and all parameters.
719 * XXX: more than thousand lines long
720 * and thus in serious need of refactoring.
724 * Returns : The configuration_spec, or NULL on error.
726 *********************************************************************/
727 struct configuration_spec * load_config(void)
729 char buf[BUFFER_SIZE];
731 FILE *configfp = NULL;
732 struct configuration_spec * config = NULL;
733 struct client_state * fake_csp;
734 struct file_list *fs;
735 unsigned long linenum = 0;
737 char *logfile = NULL;
738 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
739 int keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
742 if ( !check_file_changed(current_configfile, configfile, &fs))
744 /* No need to load */
745 return ((struct configuration_spec *)current_configfile->f);
749 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
753 if (NULL != current_configfile)
755 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
758 #ifdef FEATURE_TOGGLE
759 global_toggle_state = 1;
760 #endif /* def FEATURE_TOGGLE */
762 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
768 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
769 /* Never get here - LOG_LEVEL_FATAL causes program exit */
773 * This is backwards from how it's usually done.
774 * Following the usual pattern, "fs" would be stored in a member
775 * variable in "csp", and then we'd access "config" from "fs->f",
776 * using a cast. However, "config" is used so often that a
777 * cast each time would be very ugly, and the extra indirection
778 * would waste CPU cycles. Therefore we store "config" in
779 * "csp->config", and "fs" in "csp->config->config_file_list".
781 config->config_file_list = fs;
786 config->multi_threaded = 1;
787 config->hport = HADDR_PORT;
788 config->buffer_limit = 4096 * 1024;
789 config->usermanual = strdup(USER_MANUAL_URL);
790 config->proxy_args = strdup("");
791 config->forwarded_connect_retries = 0;
792 config->socket_timeout = 180;
793 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
794 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
795 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
797 if ((configfp = fopen(configfile, "r")) == NULL)
799 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
801 /* Never get here - LOG_LEVEL_FATAL causes program exit */
804 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
806 char cmd[BUFFER_SIZE];
807 char arg[BUFFER_SIZE];
808 char tmp[BUFFER_SIZE];
810 struct access_control_list *cur_acl;
811 #endif /* def FEATURE_ACL */
812 struct forward_spec *cur_fwd;
815 unsigned long directive_hash;
817 strlcpy(tmp, buf, sizeof(tmp));
819 /* Copy command (i.e. up to space or tab) into cmd */
822 while (*p && (*p != ' ') && (*p != '\t'))
828 /* Skip over the whitespace in buf */
829 while (*p && ((*p == ' ') || (*p == '\t')))
834 /* Copy the argument into arg */
835 strlcpy(arg, p, sizeof(arg));
837 /* Should never happen, but check this anyway */
843 /* Make sure the command field is lower case */
848 *p = (char)ijb_tolower(*p);
852 /* Save the argument for show-proxy-args */
853 savearg(cmd, arg, config);
855 directive_hash = hash_string(cmd);
856 switch (directive_hash)
858 /* *************************************************************************
859 * actionsfile actions-file-name
860 * In confdir by default
861 * *************************************************************************/
862 case hash_actions_file :
864 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
869 if (i >= MAX_AF_FILES)
871 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
872 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
875 config->actions_file_short[i] = strdup(arg);
876 config->actions_file[i] = make_path(config->confdir, arg);
879 /* *************************************************************************
880 * accept-intercepted-requests
881 * *************************************************************************/
882 case hash_accept_intercepted_requests:
883 if ((*arg != '\0') && (0 != atoi(arg)))
885 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
889 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
893 /* *************************************************************************
894 * admin-address email-address
895 * *************************************************************************/
896 case hash_admin_address :
897 freez(config->admin_address);
898 config->admin_address = strdup(arg);
901 /* *************************************************************************
902 * allow-cgi-request-crunching
903 * *************************************************************************/
904 case hash_allow_cgi_request_crunching:
905 if ((*arg != '\0') && (0 != atoi(arg)))
907 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
911 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
915 /* *************************************************************************
917 * *************************************************************************/
918 case hash_buffer_limit :
919 config->buffer_limit = (size_t)(1024 * atoi(arg));
922 /* *************************************************************************
923 * confdir directory-name
924 * *************************************************************************/
926 freez(config->confdir);
927 config->confdir = make_path( NULL, arg);
930 /* *************************************************************************
932 * Specifies debug level, multiple values are ORed together.
933 * *************************************************************************/
935 config->debug |= atoi(arg);
938 /* *************************************************************************
939 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
940 * *************************************************************************/
942 case hash_deny_access:
943 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
945 if ((vec_count != 1) && (vec_count != 2))
947 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
948 "deny-access directive in configuration file.");
949 string_append(&config->proxy_args,
950 "<br>\nWARNING: Wrong number of parameters for "
951 "deny-access directive in configuration file.<br><br>\n");
955 /* allocate a new node */
956 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
960 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
961 /* Never get here - LOG_LEVEL_FATAL causes program exit */
964 cur_acl->action = ACL_DENY;
966 if (acl_addr(vec[0], cur_acl->src) < 0)
968 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
969 "for deny-access directive in configuration file: \"%s\"", vec[0]);
970 string_append(&config->proxy_args,
971 "<br>\nWARNING: Invalid source address, port or netmask "
972 "for deny-access directive in configuration file: \"");
973 string_append(&config->proxy_args,
975 string_append(&config->proxy_args,
982 if (acl_addr(vec[1], cur_acl->dst) < 0)
984 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
985 "for deny-access directive in configuration file: \"%s\"", vec[1]);
986 string_append(&config->proxy_args,
987 "<br>\nWARNING: Invalid destination address, port or netmask "
988 "for deny-access directive in configuration file: \"");
989 string_append(&config->proxy_args,
991 string_append(&config->proxy_args,
999 * Add it to the list. Note we reverse the list to get the
1000 * behaviour the user expects. With both the ACL and
1001 * actions file, the last match wins. However, the internal
1002 * implementations are different: The actions file is stored
1003 * in the same order as the file, and scanned completely.
1004 * With the ACL, we reverse the order as we load it, then
1005 * when we scan it we stop as soon as we get a match.
1007 cur_acl->next = config->acl;
1008 config->acl = cur_acl;
1011 #endif /* def FEATURE_ACL */
1013 /* *************************************************************************
1014 * enable-edit-actions 0|1
1015 * *************************************************************************/
1016 #ifdef FEATURE_CGI_EDIT_ACTIONS
1017 case hash_enable_edit_actions:
1018 if ((*arg != '\0') && (0 != atoi(arg)))
1020 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1024 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1027 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1029 /* *************************************************************************
1030 * enable-remote-toggle 0|1
1031 * *************************************************************************/
1032 #ifdef FEATURE_TOGGLE
1033 case hash_enable_remote_toggle:
1034 if ((*arg != '\0') && (0 != atoi(arg)))
1036 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1040 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1043 #endif /* def FEATURE_TOGGLE */
1045 /* *************************************************************************
1046 * enable-remote-http-toggle 0|1
1047 * *************************************************************************/
1048 case hash_enable_remote_http_toggle:
1049 if ((*arg != '\0') && (0 != atoi(arg)))
1051 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1055 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1059 /* *************************************************************************
1060 * enforce-blocks 0|1
1061 * *************************************************************************/
1062 case hash_enforce_blocks:
1063 #ifdef FEATURE_FORCE_LOAD
1064 if ((*arg != '\0') && (0 != atoi(arg)))
1066 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1070 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1073 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1074 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1075 #endif /* def FEATURE_FORCE_LOAD */
1078 /* *************************************************************************
1079 * filterfile file-name
1080 * In confdir by default.
1081 * *************************************************************************/
1082 case hash_filterfile :
1084 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1089 if (i >= MAX_AF_FILES)
1091 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1092 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1095 config->re_filterfile_short[i] = strdup(arg);
1096 config->re_filterfile[i] = make_path(config->confdir, arg);
1100 /* *************************************************************************
1101 * forward url-pattern (.|http-proxy-host[:port])
1102 * *************************************************************************/
1104 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1108 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1109 "directive in configuration file.");
1110 string_append(&config->proxy_args,
1111 "<br>\nWARNING: Wrong number of parameters for "
1112 "forward directive in configuration file.");
1116 /* allocate a new node */
1117 cur_fwd = zalloc(sizeof(*cur_fwd));
1118 if (cur_fwd == NULL)
1120 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1121 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1125 cur_fwd->type = SOCKS_NONE;
1127 /* Save the URL pattern */
1128 if (create_url_spec(cur_fwd->url, vec[0]))
1130 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1131 "directive in configuration file.");
1132 string_append(&config->proxy_args,
1133 "<br>\nWARNING: Bad URL specifier for "
1134 "forward directive in configuration file.");
1138 /* Parse the parent HTTP proxy host:port */
1141 if (strcmp(p, ".") != 0)
1143 cur_fwd->forward_host = strdup(p);
1145 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1148 cur_fwd->forward_port = atoi(p);
1151 if (cur_fwd->forward_port <= 0)
1153 cur_fwd->forward_port = 8000;
1158 cur_fwd->next = config->forward;
1159 config->forward = cur_fwd;
1163 /* *************************************************************************
1164 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1165 * *************************************************************************/
1166 case hash_forward_socks4:
1167 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1171 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1172 "forward-socks4 directive in configuration file.");
1173 string_append(&config->proxy_args,
1174 "<br>\nWARNING: Wrong number of parameters for "
1175 "forward-socks4 directive in configuration file.");
1179 /* allocate a new node */
1180 cur_fwd = zalloc(sizeof(*cur_fwd));
1181 if (cur_fwd == NULL)
1183 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1184 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1188 cur_fwd->type = SOCKS_4;
1190 /* Save the URL pattern */
1191 if (create_url_spec(cur_fwd->url, vec[0]))
1193 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1194 "directive in configuration file.");
1195 string_append(&config->proxy_args,
1196 "<br>\nWARNING: Bad URL specifier for "
1197 "forward-socks4 directive in configuration file.");
1201 /* Parse the SOCKS proxy host[:port] */
1204 if (strcmp(p, ".") != 0)
1206 cur_fwd->gateway_host = strdup(p);
1208 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1211 cur_fwd->gateway_port = atoi(p);
1213 if (cur_fwd->gateway_port <= 0)
1215 cur_fwd->gateway_port = 1080;
1219 /* Parse the parent HTTP proxy host[:port] */
1222 if (strcmp(p, ".") != 0)
1224 cur_fwd->forward_host = strdup(p);
1226 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1229 cur_fwd->forward_port = atoi(p);
1232 if (cur_fwd->forward_port <= 0)
1234 cur_fwd->forward_port = 8000;
1239 cur_fwd->next = config->forward;
1240 config->forward = cur_fwd;
1244 /* *************************************************************************
1245 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1246 * *************************************************************************/
1247 case hash_forward_socks4a:
1248 case hash_forward_socks5:
1249 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1253 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1254 "forward-socks4a directive in configuration file.");
1255 string_append(&config->proxy_args,
1256 "<br>\nWARNING: Wrong number of parameters for "
1257 "forward-socks4a directive in configuration file.");
1261 /* allocate a new node */
1262 cur_fwd = zalloc(sizeof(*cur_fwd));
1263 if (cur_fwd == NULL)
1265 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1266 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1270 if (directive_hash == hash_forward_socks4a)
1272 cur_fwd->type = SOCKS_4A;
1276 cur_fwd->type = SOCKS_5;
1279 /* Save the URL pattern */
1280 if (create_url_spec(cur_fwd->url, vec[0]))
1282 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1283 "directive in configuration file.");
1284 string_append(&config->proxy_args,
1285 "<br>\nWARNING: Bad URL specifier for "
1286 "forward-socks4a directive in configuration file.");
1290 /* Parse the SOCKS proxy host[:port] */
1293 cur_fwd->gateway_host = strdup(p);
1295 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1298 cur_fwd->gateway_port = atoi(p);
1300 if (cur_fwd->gateway_port <= 0)
1302 cur_fwd->gateway_port = 1080;
1305 /* Parse the parent HTTP proxy host[:port] */
1308 if (strcmp(p, ".") != 0)
1310 cur_fwd->forward_host = strdup(p);
1312 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1315 cur_fwd->forward_port = atoi(p);
1318 if (cur_fwd->forward_port <= 0)
1320 cur_fwd->forward_port = 8000;
1325 cur_fwd->next = config->forward;
1326 config->forward = cur_fwd;
1330 /* *************************************************************************
1331 * forwarded-connect-retries n
1332 * *************************************************************************/
1333 case hash_forwarded_connect_retries :
1334 config->forwarded_connect_retries = atoi(arg);
1337 /* *************************************************************************
1338 * hostname hostname-to-show-on-cgi-pages
1339 * *************************************************************************/
1340 case hash_hostname :
1341 freez(config->hostname);
1342 config->hostname = strdup(arg);
1343 if (NULL == config->hostname)
1345 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1349 /* *************************************************************************
1350 * keep-alive-timeout timeout
1351 * *************************************************************************/
1352 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1353 case hash_keep_alive_timeout :
1356 int timeout = atoi(arg);
1359 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1360 keep_alive_timeout = timeout;
1364 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1370 /* *************************************************************************
1371 * listen-address [ip][:port]
1372 * *************************************************************************/
1373 case hash_listen_address :
1374 freez(config->haddr);
1375 config->haddr = strdup(arg);
1378 /* *************************************************************************
1379 * logdir directory-name
1380 * *************************************************************************/
1382 freez(config->logdir);
1383 config->logdir = make_path(NULL, arg);
1386 /* *************************************************************************
1387 * logfile log-file-name
1388 * In logdir by default
1389 * *************************************************************************/
1393 logfile = make_path(config->logdir, arg);
1394 if (NULL == logfile)
1396 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1401 /* *************************************************************************
1402 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1403 * *************************************************************************/
1405 case hash_permit_access:
1406 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1408 if ((vec_count != 1) && (vec_count != 2))
1410 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1411 "permit-access directive in configuration file.");
1412 string_append(&config->proxy_args,
1413 "<br>\nWARNING: Wrong number of parameters for "
1414 "permit-access directive in configuration file.<br><br>\n");
1419 /* allocate a new node */
1420 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1422 if (cur_acl == NULL)
1424 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1425 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1428 cur_acl->action = ACL_PERMIT;
1430 if (acl_addr(vec[0], cur_acl->src) < 0)
1432 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1433 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1434 string_append(&config->proxy_args,
1435 "<br>\nWARNING: Invalid source address, port or netmask for "
1436 "permit-access directive in configuration file: \"");
1437 string_append(&config->proxy_args,
1439 string_append(&config->proxy_args,
1446 if (acl_addr(vec[1], cur_acl->dst) < 0)
1448 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1449 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1450 string_append(&config->proxy_args,
1451 "<br>\nWARNING: Invalid destination address, port or netmask for "
1452 "permit-access directive in configuration file: \"");
1453 string_append(&config->proxy_args,
1455 string_append(&config->proxy_args,
1463 * Add it to the list. Note we reverse the list to get the
1464 * behaviour the user expects. With both the ACL and
1465 * actions file, the last match wins. However, the internal
1466 * implementations are different: The actions file is stored
1467 * in the same order as the file, and scanned completely.
1468 * With the ACL, we reverse the order as we load it, then
1469 * when we scan it we stop as soon as we get a match.
1471 cur_acl->next = config->acl;
1472 config->acl = cur_acl;
1475 #endif /* def FEATURE_ACL */
1477 /* *************************************************************************
1478 * proxy-info-url url
1479 * *************************************************************************/
1480 case hash_proxy_info_url :
1481 freez(config->proxy_info_url);
1482 config->proxy_info_url = strdup(arg);
1485 /* *************************************************************************
1487 * *************************************************************************/
1488 case hash_single_threaded :
1489 config->multi_threaded = 0;
1492 /* *************************************************************************
1493 * socket-timeout numer_of_seconds
1494 * *************************************************************************/
1495 case hash_socket_timeout :
1498 int socket_timeout = atoi(arg);
1499 if (0 < socket_timeout)
1501 config->socket_timeout = socket_timeout;
1505 log_error(LOG_LEVEL_FATAL,
1506 "Invalid socket-timeout: '%s'", arg);
1511 /* *************************************************************************
1512 * split-large-cgi-forms
1513 * *************************************************************************/
1514 case hash_split_large_cgi_forms :
1515 if ((*arg != '\0') && (0 != atoi(arg)))
1517 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1521 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1525 /* *************************************************************************
1526 * templdir directory-name
1527 * *************************************************************************/
1528 case hash_templdir :
1529 freez(config->templdir);
1530 config->templdir = make_path(NULL, arg);
1533 /* *************************************************************************
1535 * *************************************************************************/
1536 #ifdef FEATURE_TOGGLE
1538 global_toggle_state = atoi(arg);
1540 #endif /* def FEATURE_TOGGLE */
1542 /* *************************************************************************
1543 * trust-info-url url
1544 * *************************************************************************/
1545 #ifdef FEATURE_TRUST
1546 case hash_trust_info_url :
1547 enlist(config->trust_info, arg);
1549 #endif /* def FEATURE_TRUST */
1551 /* *************************************************************************
1552 * trustfile filename
1553 * (In confdir by default.)
1554 * *************************************************************************/
1555 #ifdef FEATURE_TRUST
1556 case hash_trustfile :
1557 freez(config->trustfile);
1558 config->trustfile = make_path(config->confdir, arg);
1560 #endif /* def FEATURE_TRUST */
1562 /* *************************************************************************
1564 * *************************************************************************/
1565 case hash_usermanual :
1566 freez(config->usermanual);
1567 config->usermanual = strdup(arg);
1570 /* *************************************************************************
1571 * Win32 Console options:
1572 * *************************************************************************/
1574 /* *************************************************************************
1576 * *************************************************************************/
1578 case hash_hide_console :
1581 #endif /*def _WIN_CONSOLE*/
1584 /* *************************************************************************
1585 * Win32 GUI options:
1586 * *************************************************************************/
1588 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1589 /* *************************************************************************
1590 * activity-animation (0|1)
1591 * *************************************************************************/
1592 case hash_activity_animation :
1593 g_bShowActivityAnimation = atoi(arg);
1596 /* *************************************************************************
1597 * close-button-minimizes (0|1)
1598 * *************************************************************************/
1599 case hash_close_button_minimizes :
1600 g_bCloseHidesWindow = atoi(arg);
1603 /* *************************************************************************
1604 * log-buffer-size (0|1)
1605 * *************************************************************************/
1606 case hash_log_buffer_size :
1607 g_bLimitBufferSize = atoi(arg);
1610 /* *************************************************************************
1611 * log-font-name fontnane
1612 * *************************************************************************/
1613 case hash_log_font_name :
1614 strcpy( g_szFontFaceName, arg );
1617 /* *************************************************************************
1619 * *************************************************************************/
1620 case hash_log_font_size :
1621 g_nFontSize = atoi(arg);
1624 /* *************************************************************************
1625 * log-highlight-messages (0|1)
1626 * *************************************************************************/
1627 case hash_log_highlight_messages :
1628 g_bHighlightMessages = atoi(arg);
1631 /* *************************************************************************
1633 * *************************************************************************/
1634 case hash_log_max_lines :
1635 g_nMaxBufferLines = atoi(arg);
1638 /* *************************************************************************
1639 * log-messages (0|1)
1640 * *************************************************************************/
1641 case hash_log_messages :
1642 g_bLogMessages = atoi(arg);
1645 /* *************************************************************************
1646 * show-on-task-bar (0|1)
1647 * *************************************************************************/
1648 case hash_show_on_task_bar :
1649 g_bShowOnTaskBar = atoi(arg);
1652 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1655 /* *************************************************************************
1656 * Warnings about unsupported features
1657 * *************************************************************************/
1659 case hash_deny_access:
1660 #endif /* ndef FEATURE_ACL */
1661 #ifndef FEATURE_CGI_EDIT_ACTIONS
1662 case hash_enable_edit_actions:
1663 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1664 #ifndef FEATURE_TOGGLE
1665 case hash_enable_remote_toggle:
1666 #endif /* ndef FEATURE_TOGGLE */
1668 case hash_permit_access:
1669 #endif /* ndef FEATURE_ACL */
1670 #ifndef FEATURE_TOGGLE
1672 #endif /* ndef FEATURE_TOGGLE */
1673 #ifndef FEATURE_TRUST
1674 case hash_trustfile :
1675 case hash_trust_info_url :
1676 #endif /* ndef FEATURE_TRUST */
1678 #ifndef _WIN_CONSOLE
1679 case hash_hide_console :
1680 #endif /* ndef _WIN_CONSOLE */
1682 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1683 case hash_activity_animation :
1684 case hash_close_button_minimizes :
1685 case hash_log_buffer_size :
1686 case hash_log_font_name :
1687 case hash_log_font_size :
1688 case hash_log_highlight_messages :
1689 case hash_log_max_lines :
1690 case hash_log_messages :
1691 case hash_show_on_task_bar :
1692 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1693 /* These warnings are annoying - so hide them. -- Jon */
1694 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1697 /* *************************************************************************/
1699 /* *************************************************************************/
1701 * I decided that I liked this better as a warning than an
1702 * error. To change back to an error, just change log level
1703 * to LOG_LEVEL_FATAL.
1705 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1706 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1707 string_append(&config->proxy_args,
1708 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1711 /* *************************************************************************/
1712 } /* end switch( hash_string(cmd) ) */
1713 } /* end while ( read_config_line(...) ) */
1717 set_debug_level(config->debug);
1718 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1719 set_keep_alive_timeout(keep_alive_timeout);
1722 freez(config->logfile);
1726 if (NULL != logfile)
1728 config->logfile = logfile;
1729 init_error_log(Argv[0], config->logfile);
1737 if (NULL == config->proxy_args)
1739 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1742 if (config->actions_file[0])
1744 add_loader(load_action_files, config);
1747 if (config->re_filterfile[0])
1749 add_loader(load_re_filterfiles, config);
1752 #ifdef FEATURE_TRUST
1753 if (config->trustfile)
1755 add_loader(load_trustfile, config);
1757 #endif /* def FEATURE_TRUST */
1759 if ( NULL == config->haddr )
1761 config->haddr = strdup( HADDR_DEFAULT );
1764 if ( NULL != config->haddr )
1766 if (NULL != (p = strchr(config->haddr, ':')))
1771 config->hport = atoi(p);
1775 if (config->hport <= 0)
1778 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1779 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1781 if (*config->haddr == '\0')
1784 * Only the port specified. We stored it in config->hport
1785 * and don't need its text representation anymore.
1787 freez(config->haddr);
1792 * Want to run all the loaders once now.
1794 * Need to set up a fake csp, so they can get to the config.
1796 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1797 fake_csp->config = config;
1799 if (run_loader(fake_csp))
1802 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1803 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1807 /* FIXME: this is a kludge for win32 */
1808 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1810 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1811 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1812 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1814 #ifdef FEATURE_TRUST
1815 g_trustfile = config->trustfile;
1816 #endif /* def FEATURE_TRUST */
1819 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1820 /* FIXME: end kludge */
1823 config->need_bind = 1;
1825 if (current_configfile)
1827 struct configuration_spec * oldcfg = (struct configuration_spec *)
1828 current_configfile->f;
1830 * Check if config->haddr,hport == oldcfg->haddr,hport
1832 * The following could be written more compactly as a single,
1833 * (unreadably long) if statement.
1835 config->need_bind = 0;
1836 if (config->hport != oldcfg->hport)
1838 config->need_bind = 1;
1840 else if (config->haddr == NULL)
1842 if (oldcfg->haddr != NULL)
1844 config->need_bind = 1;
1847 else if (oldcfg->haddr == NULL)
1849 config->need_bind = 1;
1851 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1853 config->need_bind = 1;
1856 current_configfile->unloader = unload_configfile;
1859 fs->next = files->next;
1862 current_configfile = fs;
1868 /*********************************************************************
1870 * Function : savearg
1872 * Description : Called from `load_config'. It saves each non-empty
1873 * and non-comment line from config into
1874 * config->proxy_args. This is used to create the
1875 * show-proxy-args page. On error, frees
1876 * config->proxy_args and sets it to NULL
1879 * 1 : command = config setting that was found
1880 * 2 : argument = the setting's argument (if any)
1881 * 3 : config = Configuration to save into.
1885 *********************************************************************/
1886 static void savearg(char *command, char *argument, struct configuration_spec * config)
1895 * Add config option name embedded in
1896 * link to its section in the user-manual
1898 buf = strdup("\n<a href=\"");
1899 if (!strncmpic(config->usermanual, "file://", 7) ||
1900 !strncmpic(config->usermanual, "http", 4))
1902 string_append(&buf, config->usermanual);
1906 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1908 string_append(&buf, CONFIG_HELP_PREFIX);
1909 string_join (&buf, string_toupper(command));
1910 string_append(&buf, "\">");
1911 string_append(&buf, command);
1912 string_append(&buf, "</a> ");
1916 freez(config->proxy_args);
1920 if ( (NULL != argument) && ('\0' != *argument) )
1922 s = html_encode(argument);
1926 freez(config->proxy_args);
1930 if (strncmpic(argument, "http://", 7) == 0)
1932 string_append(&buf, "<a href=\"");
1933 string_append(&buf, s);
1934 string_append(&buf, "\">");
1935 string_join (&buf, s);
1936 string_append(&buf, "</a>");
1940 string_join (&buf, s);
1944 string_append(&buf, "<br>");
1945 string_join(&config->proxy_args, buf);