1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.83 2008/12/20 14:53:55 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.83 2008/12/20 14:53:55 fabiankeil
39 * Add config option socket-timeout to control the time
40 * Privoxy waits for data to arrive on a socket. Useful
41 * in case of stale ssh tunnels or when fuzz-testing.
43 * Revision 1.82 2008/11/16 12:43:49 fabiankeil
44 * Turn keep-alive support into a runtime feature
45 * that is disabled by setting keep-alive-timeout
46 * to a negative value.
48 * Revision 1.81 2008/11/13 09:08:42 fabiankeil
49 * Add new config option: keep-alive-timeout.
51 * Revision 1.80 2008/08/31 15:59:03 fabiankeil
52 * There's no reason to let remote toggling support depend
53 * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
55 * Revision 1.79 2008/08/30 12:03:07 fabiankeil
56 * Remove FEATURE_COOKIE_JAR.
58 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
59 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
60 * disabled, log a message that blocks will always be enforced
61 * instead of complaining about an unrecognized directive.
62 * Reported by Pietro Leone.
64 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
65 * Reuse directive_hash and don't hash the same directive twice.
67 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
68 * - Merge three string_append() calls.
69 * - Remove useless assertion.
71 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
72 * Rename load_actions_file() and load_re_filterfile()
73 * as they load multiple files "now".
75 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
76 * Add hostname directive. Closes PR#1918189.
78 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
81 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
82 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
84 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
85 * Reword "unrecognized directive" warning, use better
86 * mark up and add a <br>. Fixes parts of #1856559.
88 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
89 * Plug memory leak if listen-address only specifies the port.
91 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
92 * Relocate daemon-mode-related log messages to make sure
93 * they aren't shown again in case of configuration reloads.
95 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
96 * Plug memory leak introduced with my last commit.
98 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
99 * When in daemon mode, close stderr after the configuration file has been
100 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
102 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
103 * #1763173 from Stefan Huehner: declare unload_configfile() static.
105 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
106 * As Hal noticed, checking dispatch_cgi() as the last cruncher
107 * looks like a bug if CGI requests are blocked unintentionally,
108 * so don't do it unless the user enabled the new config option
109 * "allow-cgi-request-crunching".
111 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
112 * - Use strlcpy() instead of strcpy().
113 * - Stop treating actions files special. Expect a complete file name
114 * (with or without path) like it's done for the rest of the files.
116 * - Remove an unnecessary temporary memory allocation.
117 * - Don't log anything to the console when running as
118 * daemon and no errors occurred.
120 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
121 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
123 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
124 * New config option: enforce-blocks.
126 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
127 * - Mention other reasons why acl directive loading might have failed.
128 * - Don't log the acl source if the acl destination is to blame.
130 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
131 * Add new config option "templdir" to
132 * change the templates directory.
134 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
135 * Added config option accept-intercepted-requests
136 * and disabled it by default.
138 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
139 * Fix gcc43 compiler warnings.
141 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
142 * Add config option "split-large-forms"
143 * to work around the browser bug reported
146 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
147 * Move the <br> in the generated HTML for the config
148 * options from the beginning of the string to its end.
149 * Keeps the white space in balance.
151 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
152 * Fix memory leak in case of config file reloads.
154 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
155 * Modified kludge for win32 to make ming32 menu
156 * "Options/Edit Filters" (sort of) work again.
157 * Same limitations as for the action files apply.
160 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
161 * Incorporate modified version of Roland Rosenfeld's patch to
162 * optionally access the user-manual via Privoxy. Closes patch 679075.
164 * Formatting changed to Privoxy style, added call to
165 * cgi_error_no_template if the requested file doesn't
166 * exist and modified check whether or not Privoxy itself
167 * should serve the manual. Should work cross-platform now.
169 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
170 * Added config option enable-remote-http-toggle
171 * to specify if Privoxy should recognize special
172 * headers (currently only X-Filter) to change its
173 * behaviour. Disabled by default.
175 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
176 * Make number of retries in case of forwarded-connect problems
177 * a config file option (forwarded-connect-retries) and use 0 as
180 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
181 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
182 * with what was really the latest development (the v_3_0_branch branch)
184 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
185 * Don't forget to malloc space for the null terminator...
187 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
188 * Multiple filter file support
190 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
191 * Closed two memory leaks; hopefully the last remaining ones
192 * (in the main execution paths, anyway).
194 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
195 * Addressed bug #719435
196 * - Extraneous filterfile directives now logged as errors
197 * - This and unrecnonised directives now really obvious on status page
199 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
200 * Cosmetic: Renamed cryptic variable
202 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
203 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
205 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
206 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
208 * Revision 1.48 2002/05/14 21:30:38 oes
209 * savearg now uses own linking code instead of (now special-cased) add_help_link
211 * Revision 1.47 2002/05/12 21:36:29 jongfoster
212 * Correcting function comments
214 * Revision 1.46 2002/04/26 12:55:14 oes
215 * - New option "user-manual", defaults to our site
216 * via project.h #define
217 * - savearg now embeds option names in help links
219 * Revision 1.45 2002/04/24 02:11:54 oes
220 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
222 * Revision 1.44 2002/04/08 20:37:13 swa
225 * Revision 1.43 2002/04/08 20:36:50 swa
228 * Revision 1.42 2002/04/05 15:50:15 oes
229 * fix for invalid HTML proxy_args
231 * Revision 1.41 2002/03/31 17:19:00 jongfoster
232 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
234 * Revision 1.40 2002/03/26 22:29:55 swa
235 * we have a new homepage!
237 * Revision 1.39 2002/03/24 13:25:43 swa
238 * name change related issues
240 * Revision 1.38 2002/03/24 13:05:48 jongfoster
241 * Renaming re_filterfile to filterfile
243 * Revision 1.37 2002/03/16 23:54:06 jongfoster
244 * Adding graceful termination feature, to help look for memory leaks.
245 * If you enable this (which, by design, has to be done by hand
246 * editing config.h) and then go to http://i.j.b/die, then the program
247 * will exit cleanly after the *next* request. It should free all the
248 * memory that was used.
250 * Revision 1.36 2002/03/13 00:27:05 jongfoster
253 * Revision 1.35 2002/03/07 03:52:44 oes
254 * Set logging to tty for --no-daemon mode
256 * Revision 1.34 2002/03/06 23:14:35 jongfoster
257 * Trivial cosmetic changes to make function comments easier to find.
259 * Revision 1.33 2002/03/05 04:52:42 oes
260 * Deleted non-errlog debugging code
262 * Revision 1.32 2002/03/04 18:24:53 oes
263 * Re-enabled output of unknown config directive hash
265 * Revision 1.31 2002/03/03 15:07:20 oes
266 * Re-enabled automatic config reloading
268 * Revision 1.30 2002/01/22 23:31:43 jongfoster
269 * Replacing strsav() with string_append()
271 * Revision 1.29 2002/01/17 21:02:30 jongfoster
272 * Moving all our URL and URL pattern parsing code to urlmatch.c.
274 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
276 * Revision 1.28 2001/12/30 14:07:32 steudten
277 * - Add signal handling (unix)
278 * - Add SIGHUP handler (unix)
279 * - Add creation of pidfile (unix)
280 * - Add action 'top' in rc file (RH)
281 * - Add entry 'SIGNALS' to manpage
282 * - Add exit message to logfile (unix)
284 * Revision 1.27 2001/11/07 00:02:13 steudten
285 * Add line number in error output for lineparsing for
286 * actionsfile and configfile.
287 * Special handling for CLF added.
289 * Revision 1.26 2001/11/05 21:41:43 steudten
290 * Add changes to be a real daemon just for unix os.
291 * (change cwd to /, detach from controlling tty, set
292 * process group and session leader to the own process.
294 * Add some fatal-error log message for failed malloc().
295 * Add '-d' if compiled with 'configure --with-debug' to
296 * enable debug output.
298 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
299 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
300 * threads to call select() simultaneously. So, it's time to do a real, live,
301 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
302 * (native). Both versions will work, but using __OS2__ offers multi-threading.
304 * Revision 1.24 2001/10/23 21:40:30 jongfoster
305 * Added support for enable-edit-actions and enable-remote-toggle config
308 * Revision 1.23 2001/10/07 15:36:00 oes
309 * Introduced new config option "buffer-limit"
311 * Revision 1.22 2001/09/22 16:36:59 jongfoster
312 * Removing unused parameter fs from read_config_line()
314 * Revision 1.21 2001/09/16 17:10:43 jongfoster
315 * Moving function savearg() here, since it was the only thing left in
318 * Revision 1.20 2001/07/30 22:08:36 jongfoster
319 * Tidying up #defines:
320 * - All feature #defines are now of the form FEATURE_xxx
321 * - Permanently turned off WIN_GUI_EDIT
322 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
324 * Revision 1.19 2001/07/15 17:45:16 jongfoster
325 * Removing some unused #includes
327 * Revision 1.18 2001/07/13 14:01:14 oes
328 * - Removed all #ifdef PCRS
329 * - Removed vim-settings
331 * Revision 1.17 2001/06/29 13:31:03 oes
332 * - Improved comments
333 * - Fixed (actionsfile) and sorted hashes
334 * - Introduced admin_address and proxy-info-url
335 * as config parameters
336 * - Renamed config->proxy_args_invocation (which didn't have
337 * the invocation but the options!) to config->proxy_args
338 * - Various adaptions
339 * - Removed logentry from cancelled commit
341 * Revision 1.16 2001/06/09 10:55:28 jongfoster
342 * Changing BUFSIZ ==> BUFFER_SIZE
344 * Revision 1.15 2001/06/07 23:13:40 jongfoster
345 * Merging ACL and forward files into config file.
346 * Cosmetic: Sorting config file options alphabetically.
347 * Cosmetic: Adding brief syntax comments to config file options.
349 * Revision 1.14 2001/06/07 14:46:25 joergs
350 * Missing make_path() added for re_filterfile.
352 * Revision 1.13 2001/06/05 22:33:54 jongfoster
354 * Fixed minor memory leak.
355 * Also now uses make_path to prepend the pathnames.
357 * Revision 1.12 2001/06/05 20:04:09 jongfoster
358 * Now uses _snprintf() in place of snprintf() under Win32.
360 * Revision 1.11 2001/06/04 18:31:58 swa
361 * files are now prefixed with either `confdir' or `logdir'.
362 * `make redhat-dist' replaces both entries confdir and logdir
365 * Revision 1.10 2001/06/03 19:11:54 oes
366 * introduced confdir option
368 * Revision 1.9 2001/06/01 20:06:24 jongfoster
369 * Removed support for "tinygif" option - moved to actions file.
371 * Revision 1.8 2001/05/31 21:27:13 jongfoster
372 * Removed many options from the config file and into the
373 * "actions" file: add_forwarded, suppress_vanilla_wafer,
374 * wafer, add_header, user_agent, referer, from
375 * Also globally replaced "permission" with "action".
377 * Revision 1.7 2001/05/29 09:50:24 jongfoster
378 * Unified blocklist/imagelist/permissionslist.
379 * File format is still under discussion, but the internal changes
382 * Also modified interceptor behaviour:
383 * - We now intercept all URLs beginning with one of the following
384 * prefixes (and *only* these prefixes):
386 * * http://ijbswa.sf.net/config/
387 * * http://ijbswa.sourceforge.net/config/
388 * - New interceptors "home page" - go to http://i.j.b/ to see it.
389 * - Internal changes so that intercepted and fast redirect pages
390 * are not replaced with an image.
391 * - Interceptors now have the option to send a binary page direct
392 * to the client. (i.e. ijb-send-banner uses this)
393 * - Implemented show-url-info interceptor. (Which is why I needed
394 * the above interceptors changes - a typical URL is
395 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
396 * The previous mechanism would not have intercepted that, and
397 * if it had been intercepted then it then it would have replaced
400 * Revision 1.6 2001/05/26 00:28:36 jongfoster
401 * Automatic reloading of config file.
402 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
403 * Most of the global variables have been moved to a new
404 * struct configuration_spec, accessed through csp->config->globalname
405 * Most of the globals remaining are used by the Win32 GUI.
407 * Revision 1.5 2001/05/25 22:34:30 jongfoster
410 * Revision 1.4 2001/05/22 18:46:04 oes
412 * - Enabled filtering banners by size rather than URL
413 * by adding patterns that replace all standard banner
414 * sizes with the "Junkbuster" gif to the re_filterfile
416 * - Enabled filtering WebBugs by providing a pattern
417 * which kills all 1x1 images
419 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
420 * which is selected by the (nonstandard and therefore
421 * capital) letter 'U' in the option string.
422 * It causes the quantifiers to be ungreedy by default.
423 * Appending a ? turns back to greedy (!).
425 * - Added a new interceptor ijb-send-banner, which
426 * sends back the "Junkbuster" gif. Without imagelist or
427 * MSIE detection support, or if tinygif = 1, or the
428 * URL isn't recognized as an imageurl, a lame HTML
429 * explanation is sent instead.
431 * - Added new feature, which permits blocking remote
432 * script redirects and firing back a local redirect
434 * The feature is conditionally compiled, i.e. it
435 * can be disabled with --disable-fast-redirects,
436 * plus it must be activated by a "fast-redirects"
437 * line in the config file, has its own log level
438 * and of course wants to be displayed by show-proxy-args
439 * Note: Boy, all the #ifdefs in 1001 locations and
440 * all the fumbling with configure.in and acconfig.h
441 * were *way* more work than the feature itself :-(
443 * - Because a generic redirect template was needed for
444 * this, tinygif = 3 now uses the same.
446 * - Moved GIFs, and other static HTTP response templates
451 * - Removed some >400 CRs again (Jon, you really worked
454 * Revision 1.3 2001/05/20 01:21:20 jongfoster
455 * Version 2.9.4 checkin.
456 * - Merged popupfile and cookiefile, and added control over PCRS
457 * filtering, in new "permissionsfile".
458 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
459 * file error you now get a message box (in the Win32 GUI) rather
460 * than the program exiting with no explanation.
461 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
463 * - Removed tabs from "config"
464 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
465 * - Bumped up version number.
467 * Revision 1.2 2001/05/17 23:01:01 oes
468 * - Cleaned CRLF's from the sources and related files
470 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
471 * Initial import of version 2.9.3 source tree
474 *********************************************************************/
480 #include <sys/types.h>
494 # include <windows.h>
497 # ifndef _WIN_CONSOLE
499 # endif /* ndef _WIN_CONSOLE */
501 #else /* ifndef _WIN32 */
505 # include <sys/wait.h>
507 # include <sys/time.h>
508 # include <sys/stat.h>
518 #include "miscutil.h"
522 #include "urlmatch.h"
526 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
529 * Fix a problem with Solaris. There should be no effect on other
531 * Solaris's isspace() is a macro which uses it's argument directly
532 * as an array index. Therefore we need to make sure that high-bit
533 * characters generate +ve values, and ideally we also want to make
534 * the argument match the declared parameter type of "int".
536 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
537 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
539 #ifdef FEATURE_TOGGLE
540 /* Privoxy is enabled by default. */
541 int global_toggle_state = 1;
542 #endif /* def FEATURE_TOGGLE */
544 /* The filename of the configfile */
545 const char *configfile = NULL;
548 * CGI functions will later need access to the invocation args,
549 * so we will make argc and argv global.
552 const char **Argv = NULL;
554 static struct file_list *current_configfile = NULL;
558 * This takes the "cryptic" hash of each keyword and aliases them to
559 * something a little more readable. This also makes changing the
560 * hash values easier if they should change or the hash algorthm changes.
561 * Use the included "hash" program to find out what the hash will be
562 * for any string supplied on the command line. (Or just put it in the
563 * config file and read the number from the error message in the log).
565 * Please keep this list sorted alphabetically (but with the Windows
566 * console and GUI specific options last).
569 #define hash_actions_file 1196306641ul /* "actionsfile" */
570 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
571 #define hash_admin_address 4112573064ul /* "admin-address" */
572 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
573 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
574 #define hash_confdir 1978389ul /* "confdir" */
575 #define hash_debug 78263ul /* "debug" */
576 #define hash_deny_access 1227333715ul /* "deny-access" */
577 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
578 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
579 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
580 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
581 #define hash_filterfile 250887266ul /* "filterfile" */
582 #define hash_forward 2029845ul /* "forward" */
583 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
584 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
585 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
586 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
587 #define hash_hostname 10308071ul /* "hostname" */
588 #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */
589 #define hash_listen_address 1255650842ul /* "listen-address" */
590 #define hash_logdir 422889ul /* "logdir" */
591 #define hash_logfile 2114766ul /* "logfile" */
592 #define hash_permit_access 3587953268ul /* "permit-access" */
593 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
594 #define hash_single_threaded 4250084780ul /* "single-threaded" */
595 #define hash_socket_timeout 1809001761ul /* "socket-timeout" */
596 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
597 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
598 #define hash_templdir 11067889ul /* "templdir" */
599 #define hash_toggle 447966ul /* "toggle" */
600 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
601 #define hash_trustfile 56494766ul /* "trustfile" */
602 #define hash_usermanual 1416668518ul /* "user-manual" */
603 #define hash_activity_animation 1817904738ul /* "activity-animation" */
604 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
605 #define hash_hide_console 2048809870ul /* "hide-console" */
606 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
607 #define hash_log_font_name 2866730124ul /* "log-font-name" */
608 #define hash_log_font_size 2866731014ul /* "log-font-size" */
609 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
610 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
611 #define hash_log_messages 2291744899ul /* "log-messages" */
612 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
615 static void savearg(char *command, char *argument, struct configuration_spec * config);
617 /*********************************************************************
619 * Function : unload_configfile
621 * Description : Free the config structure and all components.
624 * 1 : data: struct configuration_spec to unload
628 *********************************************************************/
629 static void unload_configfile (void * data)
631 struct configuration_spec * config = (struct configuration_spec *)data;
632 struct forward_spec *cur_fwd = config->forward;
636 struct access_control_list *cur_acl = config->acl;
638 while (cur_acl != NULL)
640 struct access_control_list * next_acl = cur_acl->next;
645 #endif /* def FEATURE_ACL */
647 while (cur_fwd != NULL)
649 struct forward_spec * next_fwd = cur_fwd->next;
650 free_url_spec(cur_fwd->url);
652 freez(cur_fwd->gateway_host);
653 freez(cur_fwd->forward_host);
657 config->forward = NULL;
659 freez(config->confdir);
660 freez(config->logdir);
661 freez(config->templdir);
662 freez(config->hostname);
664 freez(config->haddr);
665 freez(config->logfile);
667 for (i = 0; i < MAX_AF_FILES; i++)
669 freez(config->actions_file_short[i]);
670 freez(config->actions_file[i]);
671 freez(config->re_filterfile_short[i]);
672 freez(config->re_filterfile[i]);
675 freez(config->admin_address);
676 freez(config->proxy_info_url);
677 freez(config->proxy_args);
678 freez(config->usermanual);
681 freez(config->trustfile);
682 list_remove_all(config->trust_info);
683 #endif /* def FEATURE_TRUST */
685 for (i = 0; i < MAX_AF_FILES; i++)
687 freez(config->re_filterfile[i]);
694 #ifdef FEATURE_GRACEFUL_TERMINATION
695 /*********************************************************************
697 * Function : unload_current_config_file
699 * Description : Unloads current config file - reset to state at
700 * beginning of program.
706 *********************************************************************/
707 void unload_current_config_file(void)
709 if (current_configfile)
711 current_configfile->unloader = unload_configfile;
712 current_configfile = NULL;
718 /*********************************************************************
720 * Function : load_config
722 * Description : Load the config file and all parameters.
724 * XXX: more than thousand lines long
725 * and thus in serious need of refactoring.
729 * Returns : The configuration_spec, or NULL on error.
731 *********************************************************************/
732 struct configuration_spec * load_config(void)
734 char buf[BUFFER_SIZE];
736 FILE *configfp = NULL;
737 struct configuration_spec * config = NULL;
738 struct client_state * fake_csp;
739 struct file_list *fs;
740 unsigned long linenum = 0;
742 char *logfile = NULL;
743 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
744 int keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
747 if ( !check_file_changed(current_configfile, configfile, &fs))
749 /* No need to load */
750 return ((struct configuration_spec *)current_configfile->f);
754 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
758 if (NULL != current_configfile)
760 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
763 #ifdef FEATURE_TOGGLE
764 global_toggle_state = 1;
765 #endif /* def FEATURE_TOGGLE */
767 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
773 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
774 /* Never get here - LOG_LEVEL_FATAL causes program exit */
778 * This is backwards from how it's usually done.
779 * Following the usual pattern, "fs" would be stored in a member
780 * variable in "csp", and then we'd access "config" from "fs->f",
781 * using a cast. However, "config" is used so often that a
782 * cast each time would be very ugly, and the extra indirection
783 * would waste CPU cycles. Therefore we store "config" in
784 * "csp->config", and "fs" in "csp->config->config_file_list".
786 config->config_file_list = fs;
791 config->multi_threaded = 1;
792 config->hport = HADDR_PORT;
793 config->buffer_limit = 4096 * 1024;
794 config->usermanual = strdup(USER_MANUAL_URL);
795 config->proxy_args = strdup("");
796 config->forwarded_connect_retries = 0;
797 config->socket_timeout = 180;
798 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
799 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
800 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
802 if ((configfp = fopen(configfile, "r")) == NULL)
804 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
806 /* Never get here - LOG_LEVEL_FATAL causes program exit */
809 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
811 char cmd[BUFFER_SIZE];
812 char arg[BUFFER_SIZE];
813 char tmp[BUFFER_SIZE];
815 struct access_control_list *cur_acl;
816 #endif /* def FEATURE_ACL */
817 struct forward_spec *cur_fwd;
820 unsigned long directive_hash;
822 strlcpy(tmp, buf, sizeof(tmp));
824 /* Copy command (i.e. up to space or tab) into cmd */
827 while (*p && (*p != ' ') && (*p != '\t'))
833 /* Skip over the whitespace in buf */
834 while (*p && ((*p == ' ') || (*p == '\t')))
839 /* Copy the argument into arg */
840 strlcpy(arg, p, sizeof(arg));
842 /* Should never happen, but check this anyway */
848 /* Make sure the command field is lower case */
853 *p = (char)ijb_tolower(*p);
857 /* Save the argument for show-proxy-args */
858 savearg(cmd, arg, config);
860 directive_hash = hash_string(cmd);
861 switch (directive_hash)
863 /* *************************************************************************
864 * actionsfile actions-file-name
865 * In confdir by default
866 * *************************************************************************/
867 case hash_actions_file :
869 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
874 if (i >= MAX_AF_FILES)
876 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
877 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
880 config->actions_file_short[i] = strdup(arg);
881 config->actions_file[i] = make_path(config->confdir, arg);
884 /* *************************************************************************
885 * accept-intercepted-requests
886 * *************************************************************************/
887 case hash_accept_intercepted_requests:
888 if ((*arg != '\0') && (0 != atoi(arg)))
890 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
894 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
898 /* *************************************************************************
899 * admin-address email-address
900 * *************************************************************************/
901 case hash_admin_address :
902 freez(config->admin_address);
903 config->admin_address = strdup(arg);
906 /* *************************************************************************
907 * allow-cgi-request-crunching
908 * *************************************************************************/
909 case hash_allow_cgi_request_crunching:
910 if ((*arg != '\0') && (0 != atoi(arg)))
912 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
916 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
920 /* *************************************************************************
922 * *************************************************************************/
923 case hash_buffer_limit :
924 config->buffer_limit = (size_t)(1024 * atoi(arg));
927 /* *************************************************************************
928 * confdir directory-name
929 * *************************************************************************/
931 freez(config->confdir);
932 config->confdir = make_path( NULL, arg);
935 /* *************************************************************************
937 * Specifies debug level, multiple values are ORed together.
938 * *************************************************************************/
940 config->debug |= atoi(arg);
943 /* *************************************************************************
944 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
945 * *************************************************************************/
947 case hash_deny_access:
948 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
950 if ((vec_count != 1) && (vec_count != 2))
952 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
953 "deny-access directive in configuration file.");
954 string_append(&config->proxy_args,
955 "<br>\nWARNING: Wrong number of parameters for "
956 "deny-access directive in configuration file.<br><br>\n");
960 /* allocate a new node */
961 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
965 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
966 /* Never get here - LOG_LEVEL_FATAL causes program exit */
969 cur_acl->action = ACL_DENY;
971 if (acl_addr(vec[0], cur_acl->src) < 0)
973 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
974 "for deny-access directive in configuration file: \"%s\"", vec[0]);
975 string_append(&config->proxy_args,
976 "<br>\nWARNING: Invalid source address, port or netmask "
977 "for deny-access directive in configuration file: \"");
978 string_append(&config->proxy_args,
980 string_append(&config->proxy_args,
987 if (acl_addr(vec[1], cur_acl->dst) < 0)
989 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
990 "for deny-access directive in configuration file: \"%s\"", vec[1]);
991 string_append(&config->proxy_args,
992 "<br>\nWARNING: Invalid destination address, port or netmask "
993 "for deny-access directive in configuration file: \"");
994 string_append(&config->proxy_args,
996 string_append(&config->proxy_args,
1004 * Add it to the list. Note we reverse the list to get the
1005 * behaviour the user expects. With both the ACL and
1006 * actions file, the last match wins. However, the internal
1007 * implementations are different: The actions file is stored
1008 * in the same order as the file, and scanned completely.
1009 * With the ACL, we reverse the order as we load it, then
1010 * when we scan it we stop as soon as we get a match.
1012 cur_acl->next = config->acl;
1013 config->acl = cur_acl;
1016 #endif /* def FEATURE_ACL */
1018 /* *************************************************************************
1019 * enable-edit-actions 0|1
1020 * *************************************************************************/
1021 #ifdef FEATURE_CGI_EDIT_ACTIONS
1022 case hash_enable_edit_actions:
1023 if ((*arg != '\0') && (0 != atoi(arg)))
1025 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1029 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1032 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1034 /* *************************************************************************
1035 * enable-remote-toggle 0|1
1036 * *************************************************************************/
1037 #ifdef FEATURE_TOGGLE
1038 case hash_enable_remote_toggle:
1039 if ((*arg != '\0') && (0 != atoi(arg)))
1041 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1045 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1048 #endif /* def FEATURE_TOGGLE */
1050 /* *************************************************************************
1051 * enable-remote-http-toggle 0|1
1052 * *************************************************************************/
1053 case hash_enable_remote_http_toggle:
1054 if ((*arg != '\0') && (0 != atoi(arg)))
1056 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1060 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1064 /* *************************************************************************
1065 * enforce-blocks 0|1
1066 * *************************************************************************/
1067 case hash_enforce_blocks:
1068 #ifdef FEATURE_FORCE_LOAD
1069 if ((*arg != '\0') && (0 != atoi(arg)))
1071 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1075 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1078 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1079 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1080 #endif /* def FEATURE_FORCE_LOAD */
1083 /* *************************************************************************
1084 * filterfile file-name
1085 * In confdir by default.
1086 * *************************************************************************/
1087 case hash_filterfile :
1089 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1094 if (i >= MAX_AF_FILES)
1096 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1097 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1100 config->re_filterfile_short[i] = strdup(arg);
1101 config->re_filterfile[i] = make_path(config->confdir, arg);
1105 /* *************************************************************************
1106 * forward url-pattern (.|http-proxy-host[:port])
1107 * *************************************************************************/
1109 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1113 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1114 "directive in configuration file.");
1115 string_append(&config->proxy_args,
1116 "<br>\nWARNING: Wrong number of parameters for "
1117 "forward directive in configuration file.");
1121 /* allocate a new node */
1122 cur_fwd = zalloc(sizeof(*cur_fwd));
1123 if (cur_fwd == NULL)
1125 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1126 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1130 cur_fwd->type = SOCKS_NONE;
1132 /* Save the URL pattern */
1133 if (create_url_spec(cur_fwd->url, vec[0]))
1135 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1136 "directive in configuration file.");
1137 string_append(&config->proxy_args,
1138 "<br>\nWARNING: Bad URL specifier for "
1139 "forward directive in configuration file.");
1143 /* Parse the parent HTTP proxy host:port */
1146 if (strcmp(p, ".") != 0)
1148 cur_fwd->forward_host = strdup(p);
1150 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1153 cur_fwd->forward_port = atoi(p);
1156 if (cur_fwd->forward_port <= 0)
1158 cur_fwd->forward_port = 8000;
1163 cur_fwd->next = config->forward;
1164 config->forward = cur_fwd;
1168 /* *************************************************************************
1169 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1170 * *************************************************************************/
1171 case hash_forward_socks4:
1172 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1176 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1177 "forward-socks4 directive in configuration file.");
1178 string_append(&config->proxy_args,
1179 "<br>\nWARNING: Wrong number of parameters for "
1180 "forward-socks4 directive in configuration file.");
1184 /* allocate a new node */
1185 cur_fwd = zalloc(sizeof(*cur_fwd));
1186 if (cur_fwd == NULL)
1188 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1189 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1193 cur_fwd->type = SOCKS_4;
1195 /* Save the URL pattern */
1196 if (create_url_spec(cur_fwd->url, vec[0]))
1198 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1199 "directive in configuration file.");
1200 string_append(&config->proxy_args,
1201 "<br>\nWARNING: Bad URL specifier for "
1202 "forward-socks4 directive in configuration file.");
1206 /* Parse the SOCKS proxy host[:port] */
1209 if (strcmp(p, ".") != 0)
1211 cur_fwd->gateway_host = strdup(p);
1213 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1216 cur_fwd->gateway_port = atoi(p);
1218 if (cur_fwd->gateway_port <= 0)
1220 cur_fwd->gateway_port = 1080;
1224 /* Parse the parent HTTP proxy host[:port] */
1227 if (strcmp(p, ".") != 0)
1229 cur_fwd->forward_host = strdup(p);
1231 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1234 cur_fwd->forward_port = atoi(p);
1237 if (cur_fwd->forward_port <= 0)
1239 cur_fwd->forward_port = 8000;
1244 cur_fwd->next = config->forward;
1245 config->forward = cur_fwd;
1249 /* *************************************************************************
1250 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1251 * *************************************************************************/
1252 case hash_forward_socks4a:
1253 case hash_forward_socks5:
1254 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1258 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1259 "forward-socks4a directive in configuration file.");
1260 string_append(&config->proxy_args,
1261 "<br>\nWARNING: Wrong number of parameters for "
1262 "forward-socks4a directive in configuration file.");
1266 /* allocate a new node */
1267 cur_fwd = zalloc(sizeof(*cur_fwd));
1268 if (cur_fwd == NULL)
1270 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1271 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1275 if (directive_hash == hash_forward_socks4a)
1277 cur_fwd->type = SOCKS_4A;
1281 cur_fwd->type = SOCKS_5;
1284 /* Save the URL pattern */
1285 if (create_url_spec(cur_fwd->url, vec[0]))
1287 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1288 "directive in configuration file.");
1289 string_append(&config->proxy_args,
1290 "<br>\nWARNING: Bad URL specifier for "
1291 "forward-socks4a directive in configuration file.");
1295 /* Parse the SOCKS proxy host[:port] */
1298 cur_fwd->gateway_host = strdup(p);
1300 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1303 cur_fwd->gateway_port = atoi(p);
1305 if (cur_fwd->gateway_port <= 0)
1307 cur_fwd->gateway_port = 1080;
1310 /* Parse the parent HTTP proxy host[:port] */
1313 if (strcmp(p, ".") != 0)
1315 cur_fwd->forward_host = strdup(p);
1317 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1320 cur_fwd->forward_port = atoi(p);
1323 if (cur_fwd->forward_port <= 0)
1325 cur_fwd->forward_port = 8000;
1330 cur_fwd->next = config->forward;
1331 config->forward = cur_fwd;
1335 /* *************************************************************************
1336 * forwarded-connect-retries n
1337 * *************************************************************************/
1338 case hash_forwarded_connect_retries :
1339 config->forwarded_connect_retries = atoi(arg);
1342 /* *************************************************************************
1343 * hostname hostname-to-show-on-cgi-pages
1344 * *************************************************************************/
1345 case hash_hostname :
1346 freez(config->hostname);
1347 config->hostname = strdup(arg);
1348 if (NULL == config->hostname)
1350 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1354 /* *************************************************************************
1355 * keep-alive-timeout timeout
1356 * *************************************************************************/
1357 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1358 case hash_keep_alive_timeout :
1361 int timeout = atoi(arg);
1364 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1365 keep_alive_timeout = timeout;
1369 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1375 /* *************************************************************************
1376 * listen-address [ip][:port]
1377 * *************************************************************************/
1378 case hash_listen_address :
1379 freez(config->haddr);
1380 config->haddr = strdup(arg);
1383 /* *************************************************************************
1384 * logdir directory-name
1385 * *************************************************************************/
1387 freez(config->logdir);
1388 config->logdir = make_path(NULL, arg);
1391 /* *************************************************************************
1392 * logfile log-file-name
1393 * In logdir by default
1394 * *************************************************************************/
1398 logfile = make_path(config->logdir, arg);
1399 if (NULL == logfile)
1401 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1406 /* *************************************************************************
1407 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1408 * *************************************************************************/
1410 case hash_permit_access:
1411 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1413 if ((vec_count != 1) && (vec_count != 2))
1415 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1416 "permit-access directive in configuration file.");
1417 string_append(&config->proxy_args,
1418 "<br>\nWARNING: Wrong number of parameters for "
1419 "permit-access directive in configuration file.<br><br>\n");
1424 /* allocate a new node */
1425 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1427 if (cur_acl == NULL)
1429 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1430 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1433 cur_acl->action = ACL_PERMIT;
1435 if (acl_addr(vec[0], cur_acl->src) < 0)
1437 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1438 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1439 string_append(&config->proxy_args,
1440 "<br>\nWARNING: Invalid source address, port or netmask for "
1441 "permit-access directive in configuration file: \"");
1442 string_append(&config->proxy_args,
1444 string_append(&config->proxy_args,
1451 if (acl_addr(vec[1], cur_acl->dst) < 0)
1453 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1454 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1455 string_append(&config->proxy_args,
1456 "<br>\nWARNING: Invalid destination address, port or netmask for "
1457 "permit-access directive in configuration file: \"");
1458 string_append(&config->proxy_args,
1460 string_append(&config->proxy_args,
1468 * Add it to the list. Note we reverse the list to get the
1469 * behaviour the user expects. With both the ACL and
1470 * actions file, the last match wins. However, the internal
1471 * implementations are different: The actions file is stored
1472 * in the same order as the file, and scanned completely.
1473 * With the ACL, we reverse the order as we load it, then
1474 * when we scan it we stop as soon as we get a match.
1476 cur_acl->next = config->acl;
1477 config->acl = cur_acl;
1480 #endif /* def FEATURE_ACL */
1482 /* *************************************************************************
1483 * proxy-info-url url
1484 * *************************************************************************/
1485 case hash_proxy_info_url :
1486 freez(config->proxy_info_url);
1487 config->proxy_info_url = strdup(arg);
1490 /* *************************************************************************
1492 * *************************************************************************/
1493 case hash_single_threaded :
1494 config->multi_threaded = 0;
1497 /* *************************************************************************
1498 * socket-timeout numer_of_seconds
1499 * *************************************************************************/
1500 case hash_socket_timeout :
1503 int socket_timeout = atoi(arg);
1504 if (0 < socket_timeout)
1506 config->socket_timeout = socket_timeout;
1510 log_error(LOG_LEVEL_FATAL,
1511 "Invalid socket-timeout: '%s'", arg);
1516 /* *************************************************************************
1517 * split-large-cgi-forms
1518 * *************************************************************************/
1519 case hash_split_large_cgi_forms :
1520 if ((*arg != '\0') && (0 != atoi(arg)))
1522 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1526 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1530 /* *************************************************************************
1531 * templdir directory-name
1532 * *************************************************************************/
1533 case hash_templdir :
1534 freez(config->templdir);
1535 config->templdir = make_path(NULL, arg);
1538 /* *************************************************************************
1540 * *************************************************************************/
1541 #ifdef FEATURE_TOGGLE
1543 global_toggle_state = atoi(arg);
1545 #endif /* def FEATURE_TOGGLE */
1547 /* *************************************************************************
1548 * trust-info-url url
1549 * *************************************************************************/
1550 #ifdef FEATURE_TRUST
1551 case hash_trust_info_url :
1552 enlist(config->trust_info, arg);
1554 #endif /* def FEATURE_TRUST */
1556 /* *************************************************************************
1557 * trustfile filename
1558 * (In confdir by default.)
1559 * *************************************************************************/
1560 #ifdef FEATURE_TRUST
1561 case hash_trustfile :
1562 freez(config->trustfile);
1563 config->trustfile = make_path(config->confdir, arg);
1565 #endif /* def FEATURE_TRUST */
1567 /* *************************************************************************
1569 * *************************************************************************/
1570 case hash_usermanual :
1571 freez(config->usermanual);
1572 config->usermanual = strdup(arg);
1575 /* *************************************************************************
1576 * Win32 Console options:
1577 * *************************************************************************/
1579 /* *************************************************************************
1581 * *************************************************************************/
1583 case hash_hide_console :
1586 #endif /*def _WIN_CONSOLE*/
1589 /* *************************************************************************
1590 * Win32 GUI options:
1591 * *************************************************************************/
1593 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1594 /* *************************************************************************
1595 * activity-animation (0|1)
1596 * *************************************************************************/
1597 case hash_activity_animation :
1598 g_bShowActivityAnimation = atoi(arg);
1601 /* *************************************************************************
1602 * close-button-minimizes (0|1)
1603 * *************************************************************************/
1604 case hash_close_button_minimizes :
1605 g_bCloseHidesWindow = atoi(arg);
1608 /* *************************************************************************
1609 * log-buffer-size (0|1)
1610 * *************************************************************************/
1611 case hash_log_buffer_size :
1612 g_bLimitBufferSize = atoi(arg);
1615 /* *************************************************************************
1616 * log-font-name fontnane
1617 * *************************************************************************/
1618 case hash_log_font_name :
1619 strcpy( g_szFontFaceName, arg );
1622 /* *************************************************************************
1624 * *************************************************************************/
1625 case hash_log_font_size :
1626 g_nFontSize = atoi(arg);
1629 /* *************************************************************************
1630 * log-highlight-messages (0|1)
1631 * *************************************************************************/
1632 case hash_log_highlight_messages :
1633 g_bHighlightMessages = atoi(arg);
1636 /* *************************************************************************
1638 * *************************************************************************/
1639 case hash_log_max_lines :
1640 g_nMaxBufferLines = atoi(arg);
1643 /* *************************************************************************
1644 * log-messages (0|1)
1645 * *************************************************************************/
1646 case hash_log_messages :
1647 g_bLogMessages = atoi(arg);
1650 /* *************************************************************************
1651 * show-on-task-bar (0|1)
1652 * *************************************************************************/
1653 case hash_show_on_task_bar :
1654 g_bShowOnTaskBar = atoi(arg);
1657 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1660 /* *************************************************************************
1661 * Warnings about unsupported features
1662 * *************************************************************************/
1664 case hash_deny_access:
1665 #endif /* ndef FEATURE_ACL */
1666 #ifndef FEATURE_CGI_EDIT_ACTIONS
1667 case hash_enable_edit_actions:
1668 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1669 #ifndef FEATURE_TOGGLE
1670 case hash_enable_remote_toggle:
1671 #endif /* ndef FEATURE_TOGGLE */
1673 case hash_permit_access:
1674 #endif /* ndef FEATURE_ACL */
1675 #ifndef FEATURE_TOGGLE
1677 #endif /* ndef FEATURE_TOGGLE */
1678 #ifndef FEATURE_TRUST
1679 case hash_trustfile :
1680 case hash_trust_info_url :
1681 #endif /* ndef FEATURE_TRUST */
1683 #ifndef _WIN_CONSOLE
1684 case hash_hide_console :
1685 #endif /* ndef _WIN_CONSOLE */
1687 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1688 case hash_activity_animation :
1689 case hash_close_button_minimizes :
1690 case hash_log_buffer_size :
1691 case hash_log_font_name :
1692 case hash_log_font_size :
1693 case hash_log_highlight_messages :
1694 case hash_log_max_lines :
1695 case hash_log_messages :
1696 case hash_show_on_task_bar :
1697 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1698 /* These warnings are annoying - so hide them. -- Jon */
1699 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1702 /* *************************************************************************/
1704 /* *************************************************************************/
1706 * I decided that I liked this better as a warning than an
1707 * error. To change back to an error, just change log level
1708 * to LOG_LEVEL_FATAL.
1710 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1711 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1712 string_append(&config->proxy_args,
1713 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1716 /* *************************************************************************/
1717 } /* end switch( hash_string(cmd) ) */
1718 } /* end while ( read_config_line(...) ) */
1722 set_debug_level(config->debug);
1723 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1724 set_keep_alive_timeout(keep_alive_timeout);
1727 freez(config->logfile);
1731 if (NULL != logfile)
1733 config->logfile = logfile;
1734 init_error_log(Argv[0], config->logfile);
1742 if (NULL == config->proxy_args)
1744 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1747 if (config->actions_file[0])
1749 add_loader(load_action_files, config);
1752 if (config->re_filterfile[0])
1754 add_loader(load_re_filterfiles, config);
1757 #ifdef FEATURE_TRUST
1758 if (config->trustfile)
1760 add_loader(load_trustfile, config);
1762 #endif /* def FEATURE_TRUST */
1764 if ( NULL == config->haddr )
1766 config->haddr = strdup( HADDR_DEFAULT );
1769 if ( NULL != config->haddr )
1771 if (NULL != (p = strchr(config->haddr, ':')))
1776 config->hport = atoi(p);
1780 if (config->hport <= 0)
1783 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1784 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1786 if (*config->haddr == '\0')
1789 * Only the port specified. We stored it in config->hport
1790 * and don't need its text representation anymore.
1792 freez(config->haddr);
1797 * Want to run all the loaders once now.
1799 * Need to set up a fake csp, so they can get to the config.
1801 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1802 fake_csp->config = config;
1804 if (run_loader(fake_csp))
1807 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1808 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1812 /* FIXME: this is a kludge for win32 */
1813 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1815 g_default_actions_file = config->actions_file[0]; /* FIXME Hope this is default.action */
1816 g_user_actions_file = config->actions_file[1]; /* FIXME Hope this is user.action */
1817 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1819 #ifdef FEATURE_TRUST
1820 g_trustfile = config->trustfile;
1821 #endif /* def FEATURE_TRUST */
1824 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1825 /* FIXME: end kludge */
1828 config->need_bind = 1;
1830 if (current_configfile)
1832 struct configuration_spec * oldcfg = (struct configuration_spec *)
1833 current_configfile->f;
1835 * Check if config->haddr,hport == oldcfg->haddr,hport
1837 * The following could be written more compactly as a single,
1838 * (unreadably long) if statement.
1840 config->need_bind = 0;
1841 if (config->hport != oldcfg->hport)
1843 config->need_bind = 1;
1845 else if (config->haddr == NULL)
1847 if (oldcfg->haddr != NULL)
1849 config->need_bind = 1;
1852 else if (oldcfg->haddr == NULL)
1854 config->need_bind = 1;
1856 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1858 config->need_bind = 1;
1861 current_configfile->unloader = unload_configfile;
1864 fs->next = files->next;
1867 current_configfile = fs;
1873 /*********************************************************************
1875 * Function : savearg
1877 * Description : Called from `load_config'. It saves each non-empty
1878 * and non-comment line from config into
1879 * config->proxy_args. This is used to create the
1880 * show-proxy-args page. On error, frees
1881 * config->proxy_args and sets it to NULL
1884 * 1 : command = config setting that was found
1885 * 2 : argument = the setting's argument (if any)
1886 * 3 : config = Configuration to save into.
1890 *********************************************************************/
1891 static void savearg(char *command, char *argument, struct configuration_spec * config)
1900 * Add config option name embedded in
1901 * link to its section in the user-manual
1903 buf = strdup("\n<a href=\"");
1904 if (!strncmpic(config->usermanual, "file://", 7) ||
1905 !strncmpic(config->usermanual, "http", 4))
1907 string_append(&buf, config->usermanual);
1911 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1913 string_append(&buf, CONFIG_HELP_PREFIX);
1914 string_join (&buf, string_toupper(command));
1915 string_append(&buf, "\">");
1916 string_append(&buf, command);
1917 string_append(&buf, "</a> ");
1921 freez(config->proxy_args);
1925 if ( (NULL != argument) && ('\0' != *argument) )
1927 s = html_encode(argument);
1931 freez(config->proxy_args);
1935 if (strncmpic(argument, "http://", 7) == 0)
1937 string_append(&buf, "<a href=\"");
1938 string_append(&buf, s);
1939 string_append(&buf, "\">");
1940 string_join (&buf, s);
1941 string_append(&buf, "</a>");
1945 string_join (&buf, s);
1949 string_append(&buf, "<br>");
1950 string_join(&config->proxy_args, buf);