1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.80 2008/08/31 15:59:03 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.80 2008/08/31 15:59:03 fabiankeil
39 * There's no reason to let remote toggling support depend
40 * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
42 * Revision 1.79 2008/08/30 12:03:07 fabiankeil
43 * Remove FEATURE_COOKIE_JAR.
45 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
46 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
47 * disabled, log a message that blocks will always be enforced
48 * instead of complaining about an unrecognized directive.
49 * Reported by Pietro Leone.
51 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
52 * Reuse directive_hash and don't hash the same directive twice.
54 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
55 * - Merge three string_append() calls.
56 * - Remove useless assertion.
58 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
59 * Rename load_actions_file() and load_re_filterfile()
60 * as they load multiple files "now".
62 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
63 * Add hostname directive. Closes PR#1918189.
65 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
68 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
69 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
71 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
72 * Reword "unrecognized directive" warning, use better
73 * mark up and add a <br>. Fixes parts of #1856559.
75 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
76 * Plug memory leak if listen-address only specifies the port.
78 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
79 * Relocate daemon-mode-related log messages to make sure
80 * they aren't shown again in case of configuration reloads.
82 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
83 * Plug memory leak introduced with my last commit.
85 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
86 * When in daemon mode, close stderr after the configuration file has been
87 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
89 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
90 * #1763173 from Stefan Huehner: declare unload_configfile() static.
92 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
93 * As Hal noticed, checking dispatch_cgi() as the last cruncher
94 * looks like a bug if CGI requests are blocked unintentionally,
95 * so don't do it unless the user enabled the new config option
96 * "allow-cgi-request-crunching".
98 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
99 * - Use strlcpy() instead of strcpy().
100 * - Stop treating actions files special. Expect a complete file name
101 * (with or without path) like it's done for the rest of the files.
103 * - Remove an unnecessary temporary memory allocation.
104 * - Don't log anything to the console when running as
105 * daemon and no errors occurred.
107 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
108 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
110 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
111 * New config option: enforce-blocks.
113 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
114 * - Mention other reasons why acl directive loading might have failed.
115 * - Don't log the acl source if the acl destination is to blame.
117 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
118 * Add new config option "templdir" to
119 * change the templates directory.
121 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
122 * Added config option accept-intercepted-requests
123 * and disabled it by default.
125 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
126 * Fix gcc43 compiler warnings.
128 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
129 * Add config option "split-large-forms"
130 * to work around the browser bug reported
133 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
134 * Move the <br> in the generated HTML for the config
135 * options from the beginning of the string to its end.
136 * Keeps the white space in balance.
138 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
139 * Fix memory leak in case of config file reloads.
141 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
142 * Modified kludge for win32 to make ming32 menu
143 * "Options/Edit Filters" (sort of) work again.
144 * Same limitations as for the action files apply.
147 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
148 * Incorporate modified version of Roland Rosenfeld's patch to
149 * optionally access the user-manual via Privoxy. Closes patch 679075.
151 * Formatting changed to Privoxy style, added call to
152 * cgi_error_no_template if the requested file doesn't
153 * exist and modified check whether or not Privoxy itself
154 * should serve the manual. Should work cross-platform now.
156 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
157 * Added config option enable-remote-http-toggle
158 * to specify if Privoxy should recognize special
159 * headers (currently only X-Filter) to change its
160 * behaviour. Disabled by default.
162 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
163 * Make number of retries in case of forwarded-connect problems
164 * a config file option (forwarded-connect-retries) and use 0 as
167 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
168 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
169 * with what was really the latest development (the v_3_0_branch branch)
171 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
172 * Don't forget to malloc space for the null terminator...
174 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
175 * Multiple filter file support
177 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
178 * Closed two memory leaks; hopefully the last remaining ones
179 * (in the main execution paths, anyway).
181 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
182 * Addressed bug #719435
183 * - Extraneous filterfile directives now logged as errors
184 * - This and unrecnonised directives now really obvious on status page
186 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
187 * Cosmetic: Renamed cryptic variable
189 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
190 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
192 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
193 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
195 * Revision 1.48 2002/05/14 21:30:38 oes
196 * savearg now uses own linking code instead of (now special-cased) add_help_link
198 * Revision 1.47 2002/05/12 21:36:29 jongfoster
199 * Correcting function comments
201 * Revision 1.46 2002/04/26 12:55:14 oes
202 * - New option "user-manual", defaults to our site
203 * via project.h #define
204 * - savearg now embeds option names in help links
206 * Revision 1.45 2002/04/24 02:11:54 oes
207 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
209 * Revision 1.44 2002/04/08 20:37:13 swa
212 * Revision 1.43 2002/04/08 20:36:50 swa
215 * Revision 1.42 2002/04/05 15:50:15 oes
216 * fix for invalid HTML proxy_args
218 * Revision 1.41 2002/03/31 17:19:00 jongfoster
219 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
221 * Revision 1.40 2002/03/26 22:29:55 swa
222 * we have a new homepage!
224 * Revision 1.39 2002/03/24 13:25:43 swa
225 * name change related issues
227 * Revision 1.38 2002/03/24 13:05:48 jongfoster
228 * Renaming re_filterfile to filterfile
230 * Revision 1.37 2002/03/16 23:54:06 jongfoster
231 * Adding graceful termination feature, to help look for memory leaks.
232 * If you enable this (which, by design, has to be done by hand
233 * editing config.h) and then go to http://i.j.b/die, then the program
234 * will exit cleanly after the *next* request. It should free all the
235 * memory that was used.
237 * Revision 1.36 2002/03/13 00:27:05 jongfoster
240 * Revision 1.35 2002/03/07 03:52:44 oes
241 * Set logging to tty for --no-daemon mode
243 * Revision 1.34 2002/03/06 23:14:35 jongfoster
244 * Trivial cosmetic changes to make function comments easier to find.
246 * Revision 1.33 2002/03/05 04:52:42 oes
247 * Deleted non-errlog debugging code
249 * Revision 1.32 2002/03/04 18:24:53 oes
250 * Re-enabled output of unknown config directive hash
252 * Revision 1.31 2002/03/03 15:07:20 oes
253 * Re-enabled automatic config reloading
255 * Revision 1.30 2002/01/22 23:31:43 jongfoster
256 * Replacing strsav() with string_append()
258 * Revision 1.29 2002/01/17 21:02:30 jongfoster
259 * Moving all our URL and URL pattern parsing code to urlmatch.c.
261 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
263 * Revision 1.28 2001/12/30 14:07:32 steudten
264 * - Add signal handling (unix)
265 * - Add SIGHUP handler (unix)
266 * - Add creation of pidfile (unix)
267 * - Add action 'top' in rc file (RH)
268 * - Add entry 'SIGNALS' to manpage
269 * - Add exit message to logfile (unix)
271 * Revision 1.27 2001/11/07 00:02:13 steudten
272 * Add line number in error output for lineparsing for
273 * actionsfile and configfile.
274 * Special handling for CLF added.
276 * Revision 1.26 2001/11/05 21:41:43 steudten
277 * Add changes to be a real daemon just for unix os.
278 * (change cwd to /, detach from controlling tty, set
279 * process group and session leader to the own process.
281 * Add some fatal-error log message for failed malloc().
282 * Add '-d' if compiled with 'configure --with-debug' to
283 * enable debug output.
285 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
286 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
287 * threads to call select() simultaneously. So, it's time to do a real, live,
288 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
289 * (native). Both versions will work, but using __OS2__ offers multi-threading.
291 * Revision 1.24 2001/10/23 21:40:30 jongfoster
292 * Added support for enable-edit-actions and enable-remote-toggle config
295 * Revision 1.23 2001/10/07 15:36:00 oes
296 * Introduced new config option "buffer-limit"
298 * Revision 1.22 2001/09/22 16:36:59 jongfoster
299 * Removing unused parameter fs from read_config_line()
301 * Revision 1.21 2001/09/16 17:10:43 jongfoster
302 * Moving function savearg() here, since it was the only thing left in
305 * Revision 1.20 2001/07/30 22:08:36 jongfoster
306 * Tidying up #defines:
307 * - All feature #defines are now of the form FEATURE_xxx
308 * - Permanently turned off WIN_GUI_EDIT
309 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
311 * Revision 1.19 2001/07/15 17:45:16 jongfoster
312 * Removing some unused #includes
314 * Revision 1.18 2001/07/13 14:01:14 oes
315 * - Removed all #ifdef PCRS
316 * - Removed vim-settings
318 * Revision 1.17 2001/06/29 13:31:03 oes
319 * - Improved comments
320 * - Fixed (actionsfile) and sorted hashes
321 * - Introduced admin_address and proxy-info-url
322 * as config parameters
323 * - Renamed config->proxy_args_invocation (which didn't have
324 * the invocation but the options!) to config->proxy_args
325 * - Various adaptions
326 * - Removed logentry from cancelled commit
328 * Revision 1.16 2001/06/09 10:55:28 jongfoster
329 * Changing BUFSIZ ==> BUFFER_SIZE
331 * Revision 1.15 2001/06/07 23:13:40 jongfoster
332 * Merging ACL and forward files into config file.
333 * Cosmetic: Sorting config file options alphabetically.
334 * Cosmetic: Adding brief syntax comments to config file options.
336 * Revision 1.14 2001/06/07 14:46:25 joergs
337 * Missing make_path() added for re_filterfile.
339 * Revision 1.13 2001/06/05 22:33:54 jongfoster
341 * Fixed minor memory leak.
342 * Also now uses make_path to prepend the pathnames.
344 * Revision 1.12 2001/06/05 20:04:09 jongfoster
345 * Now uses _snprintf() in place of snprintf() under Win32.
347 * Revision 1.11 2001/06/04 18:31:58 swa
348 * files are now prefixed with either `confdir' or `logdir'.
349 * `make redhat-dist' replaces both entries confdir and logdir
352 * Revision 1.10 2001/06/03 19:11:54 oes
353 * introduced confdir option
355 * Revision 1.9 2001/06/01 20:06:24 jongfoster
356 * Removed support for "tinygif" option - moved to actions file.
358 * Revision 1.8 2001/05/31 21:27:13 jongfoster
359 * Removed many options from the config file and into the
360 * "actions" file: add_forwarded, suppress_vanilla_wafer,
361 * wafer, add_header, user_agent, referer, from
362 * Also globally replaced "permission" with "action".
364 * Revision 1.7 2001/05/29 09:50:24 jongfoster
365 * Unified blocklist/imagelist/permissionslist.
366 * File format is still under discussion, but the internal changes
369 * Also modified interceptor behaviour:
370 * - We now intercept all URLs beginning with one of the following
371 * prefixes (and *only* these prefixes):
373 * * http://ijbswa.sf.net/config/
374 * * http://ijbswa.sourceforge.net/config/
375 * - New interceptors "home page" - go to http://i.j.b/ to see it.
376 * - Internal changes so that intercepted and fast redirect pages
377 * are not replaced with an image.
378 * - Interceptors now have the option to send a binary page direct
379 * to the client. (i.e. ijb-send-banner uses this)
380 * - Implemented show-url-info interceptor. (Which is why I needed
381 * the above interceptors changes - a typical URL is
382 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
383 * The previous mechanism would not have intercepted that, and
384 * if it had been intercepted then it then it would have replaced
387 * Revision 1.6 2001/05/26 00:28:36 jongfoster
388 * Automatic reloading of config file.
389 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
390 * Most of the global variables have been moved to a new
391 * struct configuration_spec, accessed through csp->config->globalname
392 * Most of the globals remaining are used by the Win32 GUI.
394 * Revision 1.5 2001/05/25 22:34:30 jongfoster
397 * Revision 1.4 2001/05/22 18:46:04 oes
399 * - Enabled filtering banners by size rather than URL
400 * by adding patterns that replace all standard banner
401 * sizes with the "Junkbuster" gif to the re_filterfile
403 * - Enabled filtering WebBugs by providing a pattern
404 * which kills all 1x1 images
406 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
407 * which is selected by the (nonstandard and therefore
408 * capital) letter 'U' in the option string.
409 * It causes the quantifiers to be ungreedy by default.
410 * Appending a ? turns back to greedy (!).
412 * - Added a new interceptor ijb-send-banner, which
413 * sends back the "Junkbuster" gif. Without imagelist or
414 * MSIE detection support, or if tinygif = 1, or the
415 * URL isn't recognized as an imageurl, a lame HTML
416 * explanation is sent instead.
418 * - Added new feature, which permits blocking remote
419 * script redirects and firing back a local redirect
421 * The feature is conditionally compiled, i.e. it
422 * can be disabled with --disable-fast-redirects,
423 * plus it must be activated by a "fast-redirects"
424 * line in the config file, has its own log level
425 * and of course wants to be displayed by show-proxy-args
426 * Note: Boy, all the #ifdefs in 1001 locations and
427 * all the fumbling with configure.in and acconfig.h
428 * were *way* more work than the feature itself :-(
430 * - Because a generic redirect template was needed for
431 * this, tinygif = 3 now uses the same.
433 * - Moved GIFs, and other static HTTP response templates
438 * - Removed some >400 CRs again (Jon, you really worked
441 * Revision 1.3 2001/05/20 01:21:20 jongfoster
442 * Version 2.9.4 checkin.
443 * - Merged popupfile and cookiefile, and added control over PCRS
444 * filtering, in new "permissionsfile".
445 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
446 * file error you now get a message box (in the Win32 GUI) rather
447 * than the program exiting with no explanation.
448 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
450 * - Removed tabs from "config"
451 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
452 * - Bumped up version number.
454 * Revision 1.2 2001/05/17 23:01:01 oes
455 * - Cleaned CRLF's from the sources and related files
457 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
458 * Initial import of version 2.9.3 source tree
461 *********************************************************************/
467 #include <sys/types.h>
481 # include <windows.h>
484 # ifndef _WIN_CONSOLE
486 # endif /* ndef _WIN_CONSOLE */
488 #else /* ifndef _WIN32 */
492 # include <sys/wait.h>
494 # include <sys/time.h>
495 # include <sys/stat.h>
505 #include "miscutil.h"
509 #include "urlmatch.h"
513 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
516 * Fix a problem with Solaris. There should be no effect on other
518 * Solaris's isspace() is a macro which uses it's argument directly
519 * as an array index. Therefore we need to make sure that high-bit
520 * characters generate +ve values, and ideally we also want to make
521 * the argument match the declared parameter type of "int".
523 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
524 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
526 #ifdef FEATURE_TOGGLE
527 /* Privoxy is enabled by default. */
528 int global_toggle_state = 1;
529 #endif /* def FEATURE_TOGGLE */
531 /* The filename of the configfile */
532 const char *configfile = NULL;
535 * CGI functions will later need access to the invocation args,
536 * so we will make argc and argv global.
539 const char **Argv = NULL;
541 static struct file_list *current_configfile = NULL;
545 * This takes the "cryptic" hash of each keyword and aliases them to
546 * something a little more readable. This also makes changing the
547 * hash values easier if they should change or the hash algorthm changes.
548 * Use the included "hash" program to find out what the hash will be
549 * for any string supplied on the command line. (Or just put it in the
550 * config file and read the number from the error message in the log).
552 * Please keep this list sorted alphabetically (but with the Windows
553 * console and GUI specific options last).
556 #define hash_actions_file 1196306641ul /* "actionsfile" */
557 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
558 #define hash_admin_address 4112573064ul /* "admin-address" */
559 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
560 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
561 #define hash_confdir 1978389ul /* "confdir" */
562 #define hash_debug 78263ul /* "debug" */
563 #define hash_deny_access 1227333715ul /* "deny-access" */
564 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
565 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
566 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
567 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
568 #define hash_filterfile 250887266ul /* "filterfile" */
569 #define hash_forward 2029845ul /* "forward" */
570 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
571 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
572 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
573 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
574 #define hash_hostname 10308071ul /* "hostname" */
575 #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */
576 #define hash_listen_address 1255650842ul /* "listen-address" */
577 #define hash_logdir 422889ul /* "logdir" */
578 #define hash_logfile 2114766ul /* "logfile" */
579 #define hash_permit_access 3587953268ul /* "permit-access" */
580 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
581 #define hash_single_threaded 4250084780ul /* "single-threaded" */
582 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
583 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
584 #define hash_templdir 11067889ul /* "templdir" */
585 #define hash_toggle 447966ul /* "toggle" */
586 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
587 #define hash_trustfile 56494766ul /* "trustfile" */
588 #define hash_usermanual 1416668518ul /* "user-manual" */
589 #define hash_activity_animation 1817904738ul /* "activity-animation" */
590 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
591 #define hash_hide_console 2048809870ul /* "hide-console" */
592 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
593 #define hash_log_font_name 2866730124ul /* "log-font-name" */
594 #define hash_log_font_size 2866731014ul /* "log-font-size" */
595 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
596 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
597 #define hash_log_messages 2291744899ul /* "log-messages" */
598 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
601 static void savearg(char *command, char *argument, struct configuration_spec * config);
603 /*********************************************************************
605 * Function : unload_configfile
607 * Description : Free the config structure and all components.
610 * 1 : data: struct configuration_spec to unload
614 *********************************************************************/
615 static void unload_configfile (void * data)
617 struct configuration_spec * config = (struct configuration_spec *)data;
618 struct forward_spec *cur_fwd = config->forward;
622 struct access_control_list *cur_acl = config->acl;
624 while (cur_acl != NULL)
626 struct access_control_list * next_acl = cur_acl->next;
631 #endif /* def FEATURE_ACL */
633 while (cur_fwd != NULL)
635 struct forward_spec * next_fwd = cur_fwd->next;
636 free_url_spec(cur_fwd->url);
638 freez(cur_fwd->gateway_host);
639 freez(cur_fwd->forward_host);
643 config->forward = NULL;
645 freez(config->confdir);
646 freez(config->logdir);
647 freez(config->templdir);
648 freez(config->hostname);
650 freez(config->haddr);
651 freez(config->logfile);
653 for (i = 0; i < MAX_AF_FILES; i++)
655 freez(config->actions_file_short[i]);
656 freez(config->actions_file[i]);
657 freez(config->re_filterfile_short[i]);
658 freez(config->re_filterfile[i]);
661 freez(config->admin_address);
662 freez(config->proxy_info_url);
663 freez(config->proxy_args);
664 freez(config->usermanual);
667 freez(config->trustfile);
668 list_remove_all(config->trust_info);
669 #endif /* def FEATURE_TRUST */
671 for (i = 0; i < MAX_AF_FILES; i++)
673 freez(config->re_filterfile[i]);
680 #ifdef FEATURE_GRACEFUL_TERMINATION
681 /*********************************************************************
683 * Function : unload_current_config_file
685 * Description : Unloads current config file - reset to state at
686 * beginning of program.
692 *********************************************************************/
693 void unload_current_config_file(void)
695 if (current_configfile)
697 current_configfile->unloader = unload_configfile;
698 current_configfile = NULL;
704 /*********************************************************************
706 * Function : load_config
708 * Description : Load the config file and all parameters.
710 * XXX: more than thousand lines long
711 * and thus in serious need of refactoring.
715 * Returns : The configuration_spec, or NULL on error.
717 *********************************************************************/
718 struct configuration_spec * load_config(void)
720 char buf[BUFFER_SIZE];
722 FILE *configfp = NULL;
723 struct configuration_spec * config = NULL;
724 struct client_state * fake_csp;
725 struct file_list *fs;
726 unsigned long linenum = 0;
728 char *logfile = NULL;
729 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
730 int keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
733 if ( !check_file_changed(current_configfile, configfile, &fs))
735 /* No need to load */
736 return ((struct configuration_spec *)current_configfile->f);
740 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
744 if (NULL != current_configfile)
746 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
749 #ifdef FEATURE_TOGGLE
750 global_toggle_state = 1;
751 #endif /* def FEATURE_TOGGLE */
753 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
759 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
760 /* Never get here - LOG_LEVEL_FATAL causes program exit */
764 * This is backwards from how it's usually done.
765 * Following the usual pattern, "fs" would be stored in a member
766 * variable in "csp", and then we'd access "config" from "fs->f",
767 * using a cast. However, "config" is used so often that a
768 * cast each time would be very ugly, and the extra indirection
769 * would waste CPU cycles. Therefore we store "config" in
770 * "csp->config", and "fs" in "csp->config->config_file_list".
772 config->config_file_list = fs;
777 config->multi_threaded = 1;
778 config->hport = HADDR_PORT;
779 config->buffer_limit = 4096 * 1024;
780 config->usermanual = strdup(USER_MANUAL_URL);
781 config->proxy_args = strdup("");
782 config->forwarded_connect_retries = 0;
783 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
784 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
785 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
787 if ((configfp = fopen(configfile, "r")) == NULL)
789 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
791 /* Never get here - LOG_LEVEL_FATAL causes program exit */
794 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
796 char cmd[BUFFER_SIZE];
797 char arg[BUFFER_SIZE];
798 char tmp[BUFFER_SIZE];
800 struct access_control_list *cur_acl;
801 #endif /* def FEATURE_ACL */
802 struct forward_spec *cur_fwd;
805 unsigned long directive_hash;
807 strlcpy(tmp, buf, sizeof(tmp));
809 /* Copy command (i.e. up to space or tab) into cmd */
812 while (*p && (*p != ' ') && (*p != '\t'))
818 /* Skip over the whitespace in buf */
819 while (*p && ((*p == ' ') || (*p == '\t')))
824 /* Copy the argument into arg */
825 strlcpy(arg, p, sizeof(arg));
827 /* Should never happen, but check this anyway */
833 /* Make sure the command field is lower case */
838 *p = (char)ijb_tolower(*p);
842 /* Save the argument for show-proxy-args */
843 savearg(cmd, arg, config);
845 directive_hash = hash_string(cmd);
846 switch (directive_hash)
848 /* *************************************************************************
849 * actionsfile actions-file-name
850 * In confdir by default
851 * *************************************************************************/
852 case hash_actions_file :
854 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
859 if (i >= MAX_AF_FILES)
861 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
862 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
865 config->actions_file_short[i] = strdup(arg);
866 config->actions_file[i] = make_path(config->confdir, arg);
869 /* *************************************************************************
870 * accept-intercepted-requests
871 * *************************************************************************/
872 case hash_accept_intercepted_requests:
873 if ((*arg != '\0') && (0 != atoi(arg)))
875 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
879 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
883 /* *************************************************************************
884 * admin-address email-address
885 * *************************************************************************/
886 case hash_admin_address :
887 freez(config->admin_address);
888 config->admin_address = strdup(arg);
891 /* *************************************************************************
892 * allow-cgi-request-crunching
893 * *************************************************************************/
894 case hash_allow_cgi_request_crunching:
895 if ((*arg != '\0') && (0 != atoi(arg)))
897 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
901 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
905 /* *************************************************************************
907 * *************************************************************************/
908 case hash_buffer_limit :
909 config->buffer_limit = (size_t)(1024 * atoi(arg));
912 /* *************************************************************************
913 * confdir directory-name
914 * *************************************************************************/
916 freez(config->confdir);
917 config->confdir = make_path( NULL, arg);
920 /* *************************************************************************
922 * Specifies debug level, multiple values are ORed together.
923 * *************************************************************************/
925 config->debug |= atoi(arg);
928 /* *************************************************************************
929 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
930 * *************************************************************************/
932 case hash_deny_access:
933 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
935 if ((vec_count != 1) && (vec_count != 2))
937 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
938 "deny-access directive in configuration file.");
939 string_append(&config->proxy_args,
940 "<br>\nWARNING: Wrong number of parameters for "
941 "deny-access directive in configuration file.<br><br>\n");
945 /* allocate a new node */
946 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
950 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
951 /* Never get here - LOG_LEVEL_FATAL causes program exit */
954 cur_acl->action = ACL_DENY;
956 if (acl_addr(vec[0], cur_acl->src) < 0)
958 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
959 "for deny-access directive in configuration file: \"%s\"", vec[0]);
960 string_append(&config->proxy_args,
961 "<br>\nWARNING: Invalid source address, port or netmask "
962 "for deny-access directive in configuration file: \"");
963 string_append(&config->proxy_args,
965 string_append(&config->proxy_args,
972 if (acl_addr(vec[1], cur_acl->dst) < 0)
974 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
975 "for deny-access directive in configuration file: \"%s\"", vec[1]);
976 string_append(&config->proxy_args,
977 "<br>\nWARNING: Invalid destination address, port or netmask "
978 "for deny-access directive in configuration file: \"");
979 string_append(&config->proxy_args,
981 string_append(&config->proxy_args,
989 * Add it to the list. Note we reverse the list to get the
990 * behaviour the user expects. With both the ACL and
991 * actions file, the last match wins. However, the internal
992 * implementations are different: The actions file is stored
993 * in the same order as the file, and scanned completely.
994 * With the ACL, we reverse the order as we load it, then
995 * when we scan it we stop as soon as we get a match.
997 cur_acl->next = config->acl;
998 config->acl = cur_acl;
1001 #endif /* def FEATURE_ACL */
1003 /* *************************************************************************
1004 * enable-edit-actions 0|1
1005 * *************************************************************************/
1006 #ifdef FEATURE_CGI_EDIT_ACTIONS
1007 case hash_enable_edit_actions:
1008 if ((*arg != '\0') && (0 != atoi(arg)))
1010 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1014 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1017 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1019 /* *************************************************************************
1020 * enable-remote-toggle 0|1
1021 * *************************************************************************/
1022 #ifdef FEATURE_TOGGLE
1023 case hash_enable_remote_toggle:
1024 if ((*arg != '\0') && (0 != atoi(arg)))
1026 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1030 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1033 #endif /* def FEATURE_TOGGLE */
1035 /* *************************************************************************
1036 * enable-remote-http-toggle 0|1
1037 * *************************************************************************/
1038 case hash_enable_remote_http_toggle:
1039 if ((*arg != '\0') && (0 != atoi(arg)))
1041 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1045 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1049 /* *************************************************************************
1050 * enforce-blocks 0|1
1051 * *************************************************************************/
1052 case hash_enforce_blocks:
1053 #ifdef FEATURE_FORCE_LOAD
1054 if ((*arg != '\0') && (0 != atoi(arg)))
1056 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1060 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1063 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1064 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1065 #endif /* def FEATURE_FORCE_LOAD */
1068 /* *************************************************************************
1069 * filterfile file-name
1070 * In confdir by default.
1071 * *************************************************************************/
1072 case hash_filterfile :
1074 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1079 if (i >= MAX_AF_FILES)
1081 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1082 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1085 config->re_filterfile_short[i] = strdup(arg);
1086 config->re_filterfile[i] = make_path(config->confdir, arg);
1090 /* *************************************************************************
1091 * forward url-pattern (.|http-proxy-host[:port])
1092 * *************************************************************************/
1094 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1098 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1099 "directive in configuration file.");
1100 string_append(&config->proxy_args,
1101 "<br>\nWARNING: Wrong number of parameters for "
1102 "forward directive in configuration file.");
1106 /* allocate a new node */
1107 cur_fwd = zalloc(sizeof(*cur_fwd));
1108 if (cur_fwd == NULL)
1110 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1111 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1115 cur_fwd->type = SOCKS_NONE;
1117 /* Save the URL pattern */
1118 if (create_url_spec(cur_fwd->url, vec[0]))
1120 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1121 "directive in configuration file.");
1122 string_append(&config->proxy_args,
1123 "<br>\nWARNING: Bad URL specifier for "
1124 "forward directive in configuration file.");
1128 /* Parse the parent HTTP proxy host:port */
1131 if (strcmp(p, ".") != 0)
1133 cur_fwd->forward_host = strdup(p);
1135 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1138 cur_fwd->forward_port = atoi(p);
1141 if (cur_fwd->forward_port <= 0)
1143 cur_fwd->forward_port = 8000;
1148 cur_fwd->next = config->forward;
1149 config->forward = cur_fwd;
1153 /* *************************************************************************
1154 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1155 * *************************************************************************/
1156 case hash_forward_socks4:
1157 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1161 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1162 "forward-socks4 directive in configuration file.");
1163 string_append(&config->proxy_args,
1164 "<br>\nWARNING: Wrong number of parameters for "
1165 "forward-socks4 directive in configuration file.");
1169 /* allocate a new node */
1170 cur_fwd = zalloc(sizeof(*cur_fwd));
1171 if (cur_fwd == NULL)
1173 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1174 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1178 cur_fwd->type = SOCKS_4;
1180 /* Save the URL pattern */
1181 if (create_url_spec(cur_fwd->url, vec[0]))
1183 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1184 "directive in configuration file.");
1185 string_append(&config->proxy_args,
1186 "<br>\nWARNING: Bad URL specifier for "
1187 "forward-socks4 directive in configuration file.");
1191 /* Parse the SOCKS proxy host[:port] */
1194 if (strcmp(p, ".") != 0)
1196 cur_fwd->gateway_host = strdup(p);
1198 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1201 cur_fwd->gateway_port = atoi(p);
1203 if (cur_fwd->gateway_port <= 0)
1205 cur_fwd->gateway_port = 1080;
1209 /* Parse the parent HTTP proxy host[:port] */
1212 if (strcmp(p, ".") != 0)
1214 cur_fwd->forward_host = strdup(p);
1216 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1219 cur_fwd->forward_port = atoi(p);
1222 if (cur_fwd->forward_port <= 0)
1224 cur_fwd->forward_port = 8000;
1229 cur_fwd->next = config->forward;
1230 config->forward = cur_fwd;
1234 /* *************************************************************************
1235 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1236 * *************************************************************************/
1237 case hash_forward_socks4a:
1238 case hash_forward_socks5:
1239 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1243 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1244 "forward-socks4a directive in configuration file.");
1245 string_append(&config->proxy_args,
1246 "<br>\nWARNING: Wrong number of parameters for "
1247 "forward-socks4a directive in configuration file.");
1251 /* allocate a new node */
1252 cur_fwd = zalloc(sizeof(*cur_fwd));
1253 if (cur_fwd == NULL)
1255 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1256 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1260 if (directive_hash == hash_forward_socks4a)
1262 cur_fwd->type = SOCKS_4A;
1266 cur_fwd->type = SOCKS_5;
1269 /* Save the URL pattern */
1270 if (create_url_spec(cur_fwd->url, vec[0]))
1272 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1273 "directive in configuration file.");
1274 string_append(&config->proxy_args,
1275 "<br>\nWARNING: Bad URL specifier for "
1276 "forward-socks4a directive in configuration file.");
1280 /* Parse the SOCKS proxy host[:port] */
1283 cur_fwd->gateway_host = strdup(p);
1285 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1288 cur_fwd->gateway_port = atoi(p);
1290 if (cur_fwd->gateway_port <= 0)
1292 cur_fwd->gateway_port = 1080;
1295 /* Parse the parent HTTP proxy host[:port] */
1298 if (strcmp(p, ".") != 0)
1300 cur_fwd->forward_host = strdup(p);
1302 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1305 cur_fwd->forward_port = atoi(p);
1308 if (cur_fwd->forward_port <= 0)
1310 cur_fwd->forward_port = 8000;
1315 cur_fwd->next = config->forward;
1316 config->forward = cur_fwd;
1320 /* *************************************************************************
1321 * forwarded-connect-retries n
1322 * *************************************************************************/
1323 case hash_forwarded_connect_retries :
1324 config->forwarded_connect_retries = atoi(arg);
1327 /* *************************************************************************
1328 * hostname hostname-to-show-on-cgi-pages
1329 * *************************************************************************/
1330 case hash_hostname :
1331 freez(config->hostname);
1332 config->hostname = strdup(arg);
1333 if (NULL == config->hostname)
1335 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1339 /* *************************************************************************
1340 * keep-alive-timeout timeout
1341 * *************************************************************************/
1342 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1343 case hash_keep_alive_timeout :
1346 int timeout = atoi(arg);
1349 keep_alive_timeout = timeout;
1353 log_error(LOG_LEVEL_FATAL,
1354 "Invalid keep-alive-timeout value: %s.", arg);
1360 /* *************************************************************************
1361 * listen-address [ip][:port]
1362 * *************************************************************************/
1363 case hash_listen_address :
1364 freez(config->haddr);
1365 config->haddr = strdup(arg);
1368 /* *************************************************************************
1369 * logdir directory-name
1370 * *************************************************************************/
1372 freez(config->logdir);
1373 config->logdir = make_path(NULL, arg);
1376 /* *************************************************************************
1377 * logfile log-file-name
1378 * In logdir by default
1379 * *************************************************************************/
1383 logfile = make_path(config->logdir, arg);
1384 if (NULL == logfile)
1386 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1391 /* *************************************************************************
1392 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1393 * *************************************************************************/
1395 case hash_permit_access:
1396 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1398 if ((vec_count != 1) && (vec_count != 2))
1400 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1401 "permit-access directive in configuration file.");
1402 string_append(&config->proxy_args,
1403 "<br>\nWARNING: Wrong number of parameters for "
1404 "permit-access directive in configuration file.<br><br>\n");
1409 /* allocate a new node */
1410 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1412 if (cur_acl == NULL)
1414 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1415 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1418 cur_acl->action = ACL_PERMIT;
1420 if (acl_addr(vec[0], cur_acl->src) < 0)
1422 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1423 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1424 string_append(&config->proxy_args,
1425 "<br>\nWARNING: Invalid source address, port or netmask for "
1426 "permit-access directive in configuration file: \"");
1427 string_append(&config->proxy_args,
1429 string_append(&config->proxy_args,
1436 if (acl_addr(vec[1], cur_acl->dst) < 0)
1438 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1439 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1440 string_append(&config->proxy_args,
1441 "<br>\nWARNING: Invalid destination address, port or netmask for "
1442 "permit-access directive in configuration file: \"");
1443 string_append(&config->proxy_args,
1445 string_append(&config->proxy_args,
1453 * Add it to the list. Note we reverse the list to get the
1454 * behaviour the user expects. With both the ACL and
1455 * actions file, the last match wins. However, the internal
1456 * implementations are different: The actions file is stored
1457 * in the same order as the file, and scanned completely.
1458 * With the ACL, we reverse the order as we load it, then
1459 * when we scan it we stop as soon as we get a match.
1461 cur_acl->next = config->acl;
1462 config->acl = cur_acl;
1465 #endif /* def FEATURE_ACL */
1467 /* *************************************************************************
1468 * proxy-info-url url
1469 * *************************************************************************/
1470 case hash_proxy_info_url :
1471 freez(config->proxy_info_url);
1472 config->proxy_info_url = strdup(arg);
1475 /* *************************************************************************
1477 * *************************************************************************/
1478 case hash_single_threaded :
1479 config->multi_threaded = 0;
1482 /* *************************************************************************
1483 * split-large-cgi-forms
1484 * *************************************************************************/
1485 case hash_split_large_cgi_forms :
1486 if ((*arg != '\0') && (0 != atoi(arg)))
1488 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1492 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1496 /* *************************************************************************
1497 * templdir directory-name
1498 * *************************************************************************/
1499 case hash_templdir :
1500 freez(config->templdir);
1501 config->templdir = make_path(NULL, arg);
1504 /* *************************************************************************
1506 * *************************************************************************/
1507 #ifdef FEATURE_TOGGLE
1509 global_toggle_state = atoi(arg);
1511 #endif /* def FEATURE_TOGGLE */
1513 /* *************************************************************************
1514 * trust-info-url url
1515 * *************************************************************************/
1516 #ifdef FEATURE_TRUST
1517 case hash_trust_info_url :
1518 enlist(config->trust_info, arg);
1520 #endif /* def FEATURE_TRUST */
1522 /* *************************************************************************
1523 * trustfile filename
1524 * (In confdir by default.)
1525 * *************************************************************************/
1526 #ifdef FEATURE_TRUST
1527 case hash_trustfile :
1528 freez(config->trustfile);
1529 config->trustfile = make_path(config->confdir, arg);
1531 #endif /* def FEATURE_TRUST */
1533 /* *************************************************************************
1535 * *************************************************************************/
1536 case hash_usermanual :
1537 freez(config->usermanual);
1538 config->usermanual = strdup(arg);
1541 /* *************************************************************************
1542 * Win32 Console options:
1543 * *************************************************************************/
1545 /* *************************************************************************
1547 * *************************************************************************/
1549 case hash_hide_console :
1552 #endif /*def _WIN_CONSOLE*/
1555 /* *************************************************************************
1556 * Win32 GUI options:
1557 * *************************************************************************/
1559 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1560 /* *************************************************************************
1561 * activity-animation (0|1)
1562 * *************************************************************************/
1563 case hash_activity_animation :
1564 g_bShowActivityAnimation = atoi(arg);
1567 /* *************************************************************************
1568 * close-button-minimizes (0|1)
1569 * *************************************************************************/
1570 case hash_close_button_minimizes :
1571 g_bCloseHidesWindow = atoi(arg);
1574 /* *************************************************************************
1575 * log-buffer-size (0|1)
1576 * *************************************************************************/
1577 case hash_log_buffer_size :
1578 g_bLimitBufferSize = atoi(arg);
1581 /* *************************************************************************
1582 * log-font-name fontnane
1583 * *************************************************************************/
1584 case hash_log_font_name :
1585 strcpy( g_szFontFaceName, arg );
1588 /* *************************************************************************
1590 * *************************************************************************/
1591 case hash_log_font_size :
1592 g_nFontSize = atoi(arg);
1595 /* *************************************************************************
1596 * log-highlight-messages (0|1)
1597 * *************************************************************************/
1598 case hash_log_highlight_messages :
1599 g_bHighlightMessages = atoi(arg);
1602 /* *************************************************************************
1604 * *************************************************************************/
1605 case hash_log_max_lines :
1606 g_nMaxBufferLines = atoi(arg);
1609 /* *************************************************************************
1610 * log-messages (0|1)
1611 * *************************************************************************/
1612 case hash_log_messages :
1613 g_bLogMessages = atoi(arg);
1616 /* *************************************************************************
1617 * show-on-task-bar (0|1)
1618 * *************************************************************************/
1619 case hash_show_on_task_bar :
1620 g_bShowOnTaskBar = atoi(arg);
1623 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1626 /* *************************************************************************
1627 * Warnings about unsupported features
1628 * *************************************************************************/
1630 case hash_deny_access:
1631 #endif /* ndef FEATURE_ACL */
1632 #ifndef FEATURE_CGI_EDIT_ACTIONS
1633 case hash_enable_edit_actions:
1634 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1635 #ifndef FEATURE_TOGGLE
1636 case hash_enable_remote_toggle:
1637 #endif /* ndef FEATURE_TOGGLE */
1639 case hash_permit_access:
1640 #endif /* ndef FEATURE_ACL */
1641 #ifndef FEATURE_TOGGLE
1643 #endif /* ndef FEATURE_TOGGLE */
1644 #ifndef FEATURE_TRUST
1645 case hash_trustfile :
1646 case hash_trust_info_url :
1647 #endif /* ndef FEATURE_TRUST */
1649 #ifndef _WIN_CONSOLE
1650 case hash_hide_console :
1651 #endif /* ndef _WIN_CONSOLE */
1653 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1654 case hash_activity_animation :
1655 case hash_close_button_minimizes :
1656 case hash_log_buffer_size :
1657 case hash_log_font_name :
1658 case hash_log_font_size :
1659 case hash_log_highlight_messages :
1660 case hash_log_max_lines :
1661 case hash_log_messages :
1662 case hash_show_on_task_bar :
1663 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1664 /* These warnings are annoying - so hide them. -- Jon */
1665 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1668 /* *************************************************************************/
1670 /* *************************************************************************/
1672 * I decided that I liked this better as a warning than an
1673 * error. To change back to an error, just change log level
1674 * to LOG_LEVEL_FATAL.
1676 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1677 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1678 string_append(&config->proxy_args,
1679 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1682 /* *************************************************************************/
1683 } /* end switch( hash_string(cmd) ) */
1684 } /* end while ( read_config_line(...) ) */
1688 set_debug_level(config->debug);
1689 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1690 set_keep_alive_timeout(keep_alive_timeout);
1693 freez(config->logfile);
1697 if (NULL != logfile)
1699 config->logfile = logfile;
1700 init_error_log(Argv[0], config->logfile);
1708 if (NULL == config->proxy_args)
1710 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1713 if (config->actions_file[0])
1715 add_loader(load_action_files, config);
1718 if (config->re_filterfile[0])
1720 add_loader(load_re_filterfiles, config);
1723 #ifdef FEATURE_TRUST
1724 if (config->trustfile)
1726 add_loader(load_trustfile, config);
1728 #endif /* def FEATURE_TRUST */
1730 if ( NULL == config->haddr )
1732 config->haddr = strdup( HADDR_DEFAULT );
1735 if ( NULL != config->haddr )
1737 if (NULL != (p = strchr(config->haddr, ':')))
1742 config->hport = atoi(p);
1746 if (config->hport <= 0)
1749 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1750 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1752 if (*config->haddr == '\0')
1755 * Only the port specified. We stored it in config->hport
1756 * and don't need its text representation anymore.
1758 freez(config->haddr);
1763 * Want to run all the loaders once now.
1765 * Need to set up a fake csp, so they can get to the config.
1767 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1768 fake_csp->config = config;
1770 if (run_loader(fake_csp))
1773 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1774 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1778 /* FIXME: this is a kludge for win32 */
1779 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1781 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1782 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1783 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1785 #ifdef FEATURE_TRUST
1786 g_trustfile = config->trustfile;
1787 #endif /* def FEATURE_TRUST */
1790 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1791 /* FIXME: end kludge */
1794 config->need_bind = 1;
1796 if (current_configfile)
1798 struct configuration_spec * oldcfg = (struct configuration_spec *)
1799 current_configfile->f;
1801 * Check if config->haddr,hport == oldcfg->haddr,hport
1803 * The following could be written more compactly as a single,
1804 * (unreadably long) if statement.
1806 config->need_bind = 0;
1807 if (config->hport != oldcfg->hport)
1809 config->need_bind = 1;
1811 else if (config->haddr == NULL)
1813 if (oldcfg->haddr != NULL)
1815 config->need_bind = 1;
1818 else if (oldcfg->haddr == NULL)
1820 config->need_bind = 1;
1822 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1824 config->need_bind = 1;
1827 current_configfile->unloader = unload_configfile;
1830 fs->next = files->next;
1833 current_configfile = fs;
1839 /*********************************************************************
1841 * Function : savearg
1843 * Description : Called from `load_config'. It saves each non-empty
1844 * and non-comment line from config into
1845 * config->proxy_args. This is used to create the
1846 * show-proxy-args page. On error, frees
1847 * config->proxy_args and sets it to NULL
1850 * 1 : command = config setting that was found
1851 * 2 : argument = the setting's argument (if any)
1852 * 3 : config = Configuration to save into.
1856 *********************************************************************/
1857 static void savearg(char *command, char *argument, struct configuration_spec * config)
1866 * Add config option name embedded in
1867 * link to its section in the user-manual
1869 buf = strdup("\n<a href=\"");
1870 if (!strncmpic(config->usermanual, "file://", 7) ||
1871 !strncmpic(config->usermanual, "http", 4))
1873 string_append(&buf, config->usermanual);
1877 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1879 string_append(&buf, CONFIG_HELP_PREFIX);
1880 string_join (&buf, string_toupper(command));
1881 string_append(&buf, "\">");
1882 string_append(&buf, command);
1883 string_append(&buf, "</a> ");
1887 freez(config->proxy_args);
1891 if ( (NULL != argument) && ('\0' != *argument) )
1893 s = html_encode(argument);
1897 freez(config->proxy_args);
1901 if (strncmpic(argument, "http://", 7) == 0)
1903 string_append(&buf, "<a href=\"");
1904 string_append(&buf, s);
1905 string_append(&buf, "\">");
1906 string_join (&buf, s);
1907 string_append(&buf, "</a>");
1911 string_join (&buf, s);
1915 string_append(&buf, "<br>");
1916 string_join(&config->proxy_args, buf);