1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.78 2008/08/02 08:23:22 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.78 2008/08/02 08:23:22 fabiankeil
39 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
40 * disabled, log a message that blocks will always be enforced
41 * instead of complaining about an unrecognized directive.
42 * Reported by Pietro Leone.
44 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
45 * Reuse directive_hash and don't hash the same directive twice.
47 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
48 * - Merge three string_append() calls.
49 * - Remove useless assertion.
51 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
52 * Rename load_actions_file() and load_re_filterfile()
53 * as they load multiple files "now".
55 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
56 * Add hostname directive. Closes PR#1918189.
58 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
61 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
62 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
64 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
65 * Reword "unrecognized directive" warning, use better
66 * mark up and add a <br>. Fixes parts of #1856559.
68 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
69 * Plug memory leak if listen-address only specifies the port.
71 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
72 * Relocate daemon-mode-related log messages to make sure
73 * they aren't shown again in case of configuration reloads.
75 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
76 * Plug memory leak introduced with my last commit.
78 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
79 * When in daemon mode, close stderr after the configuration file has been
80 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
82 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
83 * #1763173 from Stefan Huehner: declare unload_configfile() static.
85 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
86 * As Hal noticed, checking dispatch_cgi() as the last cruncher
87 * looks like a bug if CGI requests are blocked unintentionally,
88 * so don't do it unless the user enabled the new config option
89 * "allow-cgi-request-crunching".
91 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
92 * - Use strlcpy() instead of strcpy().
93 * - Stop treating actions files special. Expect a complete file name
94 * (with or without path) like it's done for the rest of the files.
96 * - Remove an unnecessary temporary memory allocation.
97 * - Don't log anything to the console when running as
98 * daemon and no errors occurred.
100 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
101 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
103 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
104 * New config option: enforce-blocks.
106 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
107 * - Mention other reasons why acl directive loading might have failed.
108 * - Don't log the acl source if the acl destination is to blame.
110 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
111 * Add new config option "templdir" to
112 * change the templates directory.
114 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
115 * Added config option accept-intercepted-requests
116 * and disabled it by default.
118 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
119 * Fix gcc43 compiler warnings.
121 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
122 * Add config option "split-large-forms"
123 * to work around the browser bug reported
126 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
127 * Move the <br> in the generated HTML for the config
128 * options from the beginning of the string to its end.
129 * Keeps the white space in balance.
131 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
132 * Fix memory leak in case of config file reloads.
134 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
135 * Modified kludge for win32 to make ming32 menu
136 * "Options/Edit Filters" (sort of) work again.
137 * Same limitations as for the action files apply.
140 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
141 * Incorporate modified version of Roland Rosenfeld's patch to
142 * optionally access the user-manual via Privoxy. Closes patch 679075.
144 * Formatting changed to Privoxy style, added call to
145 * cgi_error_no_template if the requested file doesn't
146 * exist and modified check whether or not Privoxy itself
147 * should serve the manual. Should work cross-platform now.
149 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
150 * Added config option enable-remote-http-toggle
151 * to specify if Privoxy should recognize special
152 * headers (currently only X-Filter) to change its
153 * behaviour. Disabled by default.
155 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
156 * Make number of retries in case of forwarded-connect problems
157 * a config file option (forwarded-connect-retries) and use 0 as
160 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
161 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
162 * with what was really the latest development (the v_3_0_branch branch)
164 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
165 * Don't forget to malloc space for the null terminator...
167 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
168 * Multiple filter file support
170 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
171 * Closed two memory leaks; hopefully the last remaining ones
172 * (in the main execution paths, anyway).
174 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
175 * Addressed bug #719435
176 * - Extraneous filterfile directives now logged as errors
177 * - This and unrecnonised directives now really obvious on status page
179 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
180 * Cosmetic: Renamed cryptic variable
182 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
183 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
185 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
186 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
188 * Revision 1.48 2002/05/14 21:30:38 oes
189 * savearg now uses own linking code instead of (now special-cased) add_help_link
191 * Revision 1.47 2002/05/12 21:36:29 jongfoster
192 * Correcting function comments
194 * Revision 1.46 2002/04/26 12:55:14 oes
195 * - New option "user-manual", defaults to our site
196 * via project.h #define
197 * - savearg now embeds option names in help links
199 * Revision 1.45 2002/04/24 02:11:54 oes
200 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
202 * Revision 1.44 2002/04/08 20:37:13 swa
205 * Revision 1.43 2002/04/08 20:36:50 swa
208 * Revision 1.42 2002/04/05 15:50:15 oes
209 * fix for invalid HTML proxy_args
211 * Revision 1.41 2002/03/31 17:19:00 jongfoster
212 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
214 * Revision 1.40 2002/03/26 22:29:55 swa
215 * we have a new homepage!
217 * Revision 1.39 2002/03/24 13:25:43 swa
218 * name change related issues
220 * Revision 1.38 2002/03/24 13:05:48 jongfoster
221 * Renaming re_filterfile to filterfile
223 * Revision 1.37 2002/03/16 23:54:06 jongfoster
224 * Adding graceful termination feature, to help look for memory leaks.
225 * If you enable this (which, by design, has to be done by hand
226 * editing config.h) and then go to http://i.j.b/die, then the program
227 * will exit cleanly after the *next* request. It should free all the
228 * memory that was used.
230 * Revision 1.36 2002/03/13 00:27:05 jongfoster
233 * Revision 1.35 2002/03/07 03:52:44 oes
234 * Set logging to tty for --no-daemon mode
236 * Revision 1.34 2002/03/06 23:14:35 jongfoster
237 * Trivial cosmetic changes to make function comments easier to find.
239 * Revision 1.33 2002/03/05 04:52:42 oes
240 * Deleted non-errlog debugging code
242 * Revision 1.32 2002/03/04 18:24:53 oes
243 * Re-enabled output of unknown config directive hash
245 * Revision 1.31 2002/03/03 15:07:20 oes
246 * Re-enabled automatic config reloading
248 * Revision 1.30 2002/01/22 23:31:43 jongfoster
249 * Replacing strsav() with string_append()
251 * Revision 1.29 2002/01/17 21:02:30 jongfoster
252 * Moving all our URL and URL pattern parsing code to urlmatch.c.
254 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
256 * Revision 1.28 2001/12/30 14:07:32 steudten
257 * - Add signal handling (unix)
258 * - Add SIGHUP handler (unix)
259 * - Add creation of pidfile (unix)
260 * - Add action 'top' in rc file (RH)
261 * - Add entry 'SIGNALS' to manpage
262 * - Add exit message to logfile (unix)
264 * Revision 1.27 2001/11/07 00:02:13 steudten
265 * Add line number in error output for lineparsing for
266 * actionsfile and configfile.
267 * Special handling for CLF added.
269 * Revision 1.26 2001/11/05 21:41:43 steudten
270 * Add changes to be a real daemon just for unix os.
271 * (change cwd to /, detach from controlling tty, set
272 * process group and session leader to the own process.
274 * Add some fatal-error log message for failed malloc().
275 * Add '-d' if compiled with 'configure --with-debug' to
276 * enable debug output.
278 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
279 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
280 * threads to call select() simultaneously. So, it's time to do a real, live,
281 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
282 * (native). Both versions will work, but using __OS2__ offers multi-threading.
284 * Revision 1.24 2001/10/23 21:40:30 jongfoster
285 * Added support for enable-edit-actions and enable-remote-toggle config
288 * Revision 1.23 2001/10/07 15:36:00 oes
289 * Introduced new config option "buffer-limit"
291 * Revision 1.22 2001/09/22 16:36:59 jongfoster
292 * Removing unused parameter fs from read_config_line()
294 * Revision 1.21 2001/09/16 17:10:43 jongfoster
295 * Moving function savearg() here, since it was the only thing left in
298 * Revision 1.20 2001/07/30 22:08:36 jongfoster
299 * Tidying up #defines:
300 * - All feature #defines are now of the form FEATURE_xxx
301 * - Permanently turned off WIN_GUI_EDIT
302 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
304 * Revision 1.19 2001/07/15 17:45:16 jongfoster
305 * Removing some unused #includes
307 * Revision 1.18 2001/07/13 14:01:14 oes
308 * - Removed all #ifdef PCRS
309 * - Removed vim-settings
311 * Revision 1.17 2001/06/29 13:31:03 oes
312 * - Improved comments
313 * - Fixed (actionsfile) and sorted hashes
314 * - Introduced admin_address and proxy-info-url
315 * as config parameters
316 * - Renamed config->proxy_args_invocation (which didn't have
317 * the invocation but the options!) to config->proxy_args
318 * - Various adaptions
319 * - Removed logentry from cancelled commit
321 * Revision 1.16 2001/06/09 10:55:28 jongfoster
322 * Changing BUFSIZ ==> BUFFER_SIZE
324 * Revision 1.15 2001/06/07 23:13:40 jongfoster
325 * Merging ACL and forward files into config file.
326 * Cosmetic: Sorting config file options alphabetically.
327 * Cosmetic: Adding brief syntax comments to config file options.
329 * Revision 1.14 2001/06/07 14:46:25 joergs
330 * Missing make_path() added for re_filterfile.
332 * Revision 1.13 2001/06/05 22:33:54 jongfoster
334 * Fixed minor memory leak.
335 * Also now uses make_path to prepend the pathnames.
337 * Revision 1.12 2001/06/05 20:04:09 jongfoster
338 * Now uses _snprintf() in place of snprintf() under Win32.
340 * Revision 1.11 2001/06/04 18:31:58 swa
341 * files are now prefixed with either `confdir' or `logdir'.
342 * `make redhat-dist' replaces both entries confdir and logdir
345 * Revision 1.10 2001/06/03 19:11:54 oes
346 * introduced confdir option
348 * Revision 1.9 2001/06/01 20:06:24 jongfoster
349 * Removed support for "tinygif" option - moved to actions file.
351 * Revision 1.8 2001/05/31 21:27:13 jongfoster
352 * Removed many options from the config file and into the
353 * "actions" file: add_forwarded, suppress_vanilla_wafer,
354 * wafer, add_header, user_agent, referer, from
355 * Also globally replaced "permission" with "action".
357 * Revision 1.7 2001/05/29 09:50:24 jongfoster
358 * Unified blocklist/imagelist/permissionslist.
359 * File format is still under discussion, but the internal changes
362 * Also modified interceptor behaviour:
363 * - We now intercept all URLs beginning with one of the following
364 * prefixes (and *only* these prefixes):
366 * * http://ijbswa.sf.net/config/
367 * * http://ijbswa.sourceforge.net/config/
368 * - New interceptors "home page" - go to http://i.j.b/ to see it.
369 * - Internal changes so that intercepted and fast redirect pages
370 * are not replaced with an image.
371 * - Interceptors now have the option to send a binary page direct
372 * to the client. (i.e. ijb-send-banner uses this)
373 * - Implemented show-url-info interceptor. (Which is why I needed
374 * the above interceptors changes - a typical URL is
375 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
376 * The previous mechanism would not have intercepted that, and
377 * if it had been intercepted then it then it would have replaced
380 * Revision 1.6 2001/05/26 00:28:36 jongfoster
381 * Automatic reloading of config file.
382 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
383 * Most of the global variables have been moved to a new
384 * struct configuration_spec, accessed through csp->config->globalname
385 * Most of the globals remaining are used by the Win32 GUI.
387 * Revision 1.5 2001/05/25 22:34:30 jongfoster
390 * Revision 1.4 2001/05/22 18:46:04 oes
392 * - Enabled filtering banners by size rather than URL
393 * by adding patterns that replace all standard banner
394 * sizes with the "Junkbuster" gif to the re_filterfile
396 * - Enabled filtering WebBugs by providing a pattern
397 * which kills all 1x1 images
399 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
400 * which is selected by the (nonstandard and therefore
401 * capital) letter 'U' in the option string.
402 * It causes the quantifiers to be ungreedy by default.
403 * Appending a ? turns back to greedy (!).
405 * - Added a new interceptor ijb-send-banner, which
406 * sends back the "Junkbuster" gif. Without imagelist or
407 * MSIE detection support, or if tinygif = 1, or the
408 * URL isn't recognized as an imageurl, a lame HTML
409 * explanation is sent instead.
411 * - Added new feature, which permits blocking remote
412 * script redirects and firing back a local redirect
414 * The feature is conditionally compiled, i.e. it
415 * can be disabled with --disable-fast-redirects,
416 * plus it must be activated by a "fast-redirects"
417 * line in the config file, has its own log level
418 * and of course wants to be displayed by show-proxy-args
419 * Note: Boy, all the #ifdefs in 1001 locations and
420 * all the fumbling with configure.in and acconfig.h
421 * were *way* more work than the feature itself :-(
423 * - Because a generic redirect template was needed for
424 * this, tinygif = 3 now uses the same.
426 * - Moved GIFs, and other static HTTP response templates
431 * - Removed some >400 CRs again (Jon, you really worked
434 * Revision 1.3 2001/05/20 01:21:20 jongfoster
435 * Version 2.9.4 checkin.
436 * - Merged popupfile and cookiefile, and added control over PCRS
437 * filtering, in new "permissionsfile".
438 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
439 * file error you now get a message box (in the Win32 GUI) rather
440 * than the program exiting with no explanation.
441 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
443 * - Removed tabs from "config"
444 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
445 * - Bumped up version number.
447 * Revision 1.2 2001/05/17 23:01:01 oes
448 * - Cleaned CRLF's from the sources and related files
450 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
451 * Initial import of version 2.9.3 source tree
454 *********************************************************************/
460 #include <sys/types.h>
474 # include <windows.h>
477 # ifndef _WIN_CONSOLE
479 # endif /* ndef _WIN_CONSOLE */
481 #else /* ifndef _WIN32 */
485 # include <sys/wait.h>
487 # include <sys/time.h>
488 # include <sys/stat.h>
498 #include "miscutil.h"
502 #include "urlmatch.h"
505 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
508 * Fix a problem with Solaris. There should be no effect on other
510 * Solaris's isspace() is a macro which uses it's argument directly
511 * as an array index. Therefore we need to make sure that high-bit
512 * characters generate +ve values, and ideally we also want to make
513 * the argument match the declared parameter type of "int".
515 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
516 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
518 #ifdef FEATURE_TOGGLE
519 /* Privoxy is enabled by default. */
520 int global_toggle_state = 1;
521 #endif /* def FEATURE_TOGGLE */
523 /* The filename of the configfile */
524 const char *configfile = NULL;
527 * CGI functions will later need access to the invocation args,
528 * so we will make argc and argv global.
531 const char **Argv = NULL;
533 static struct file_list *current_configfile = NULL;
537 * This takes the "cryptic" hash of each keyword and aliases them to
538 * something a little more readable. This also makes changing the
539 * hash values easier if they should change or the hash algorthm changes.
540 * Use the included "hash" program to find out what the hash will be
541 * for any string supplied on the command line. (Or just put it in the
542 * config file and read the number from the error message in the log).
544 * Please keep this list sorted alphabetically (but with the Windows
545 * console and GUI specific options last).
548 #define hash_actions_file 1196306641ul /* "actionsfile" */
549 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
550 #define hash_admin_address 4112573064ul /* "admin-address" */
551 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
552 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
553 #define hash_confdir 1978389ul /* "confdir" */
554 #define hash_debug 78263ul /* "debug" */
555 #define hash_deny_access 1227333715ul /* "deny-access" */
556 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
557 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
558 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
559 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
560 #define hash_filterfile 250887266ul /* "filterfile" */
561 #define hash_forward 2029845ul /* "forward" */
562 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
563 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
564 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
565 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
566 #define hash_hostname 10308071ul /* "hostname" */
567 #define hash_listen_address 1255650842ul /* "listen-address" */
568 #define hash_logdir 422889ul /* "logdir" */
569 #define hash_logfile 2114766ul /* "logfile" */
570 #define hash_permit_access 3587953268ul /* "permit-access" */
571 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
572 #define hash_single_threaded 4250084780ul /* "single-threaded" */
573 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
574 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
575 #define hash_templdir 11067889ul /* "templdir" */
576 #define hash_toggle 447966ul /* "toggle" */
577 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
578 #define hash_trustfile 56494766ul /* "trustfile" */
579 #define hash_usermanual 1416668518ul /* "user-manual" */
580 #define hash_activity_animation 1817904738ul /* "activity-animation" */
581 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
582 #define hash_hide_console 2048809870ul /* "hide-console" */
583 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
584 #define hash_log_font_name 2866730124ul /* "log-font-name" */
585 #define hash_log_font_size 2866731014ul /* "log-font-size" */
586 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
587 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
588 #define hash_log_messages 2291744899ul /* "log-messages" */
589 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
592 static void savearg(char *command, char *argument, struct configuration_spec * config);
594 /*********************************************************************
596 * Function : unload_configfile
598 * Description : Free the config structure and all components.
601 * 1 : data: struct configuration_spec to unload
605 *********************************************************************/
606 static void unload_configfile (void * data)
608 struct configuration_spec * config = (struct configuration_spec *)data;
609 struct forward_spec *cur_fwd = config->forward;
613 struct access_control_list *cur_acl = config->acl;
615 while (cur_acl != NULL)
617 struct access_control_list * next_acl = cur_acl->next;
622 #endif /* def FEATURE_ACL */
624 while (cur_fwd != NULL)
626 struct forward_spec * next_fwd = cur_fwd->next;
627 free_url_spec(cur_fwd->url);
629 freez(cur_fwd->gateway_host);
630 freez(cur_fwd->forward_host);
634 config->forward = NULL;
636 freez(config->confdir);
637 freez(config->logdir);
638 freez(config->templdir);
639 freez(config->hostname);
641 freez(config->haddr);
642 freez(config->logfile);
644 for (i = 0; i < MAX_AF_FILES; i++)
646 freez(config->actions_file_short[i]);
647 freez(config->actions_file[i]);
648 freez(config->re_filterfile_short[i]);
649 freez(config->re_filterfile[i]);
652 freez(config->admin_address);
653 freez(config->proxy_info_url);
654 freez(config->proxy_args);
655 freez(config->usermanual);
658 freez(config->trustfile);
659 list_remove_all(config->trust_info);
660 #endif /* def FEATURE_TRUST */
662 for (i = 0; i < MAX_AF_FILES; i++)
664 freez(config->re_filterfile[i]);
671 #ifdef FEATURE_GRACEFUL_TERMINATION
672 /*********************************************************************
674 * Function : unload_current_config_file
676 * Description : Unloads current config file - reset to state at
677 * beginning of program.
683 *********************************************************************/
684 void unload_current_config_file(void)
686 if (current_configfile)
688 current_configfile->unloader = unload_configfile;
689 current_configfile = NULL;
695 /*********************************************************************
697 * Function : load_config
699 * Description : Load the config file and all parameters.
701 * XXX: more than thousand lines long
702 * and thus in serious need of refactoring.
706 * Returns : The configuration_spec, or NULL on error.
708 *********************************************************************/
709 struct configuration_spec * load_config(void)
711 char buf[BUFFER_SIZE];
713 FILE *configfp = NULL;
714 struct configuration_spec * config = NULL;
715 struct client_state * fake_csp;
716 struct file_list *fs;
717 unsigned long linenum = 0;
719 char *logfile = NULL;
721 if ( !check_file_changed(current_configfile, configfile, &fs))
723 /* No need to load */
724 return ((struct configuration_spec *)current_configfile->f);
728 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
732 if (NULL != current_configfile)
734 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
737 #ifdef FEATURE_TOGGLE
738 global_toggle_state = 1;
739 #endif /* def FEATURE_TOGGLE */
741 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
747 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
748 /* Never get here - LOG_LEVEL_FATAL causes program exit */
752 * This is backwards from how it's usually done.
753 * Following the usual pattern, "fs" would be stored in a member
754 * variable in "csp", and then we'd access "config" from "fs->f",
755 * using a cast. However, "config" is used so often that a
756 * cast each time would be very ugly, and the extra indirection
757 * would waste CPU cycles. Therefore we store "config" in
758 * "csp->config", and "fs" in "csp->config->config_file_list".
760 config->config_file_list = fs;
765 config->multi_threaded = 1;
766 config->hport = HADDR_PORT;
767 config->buffer_limit = 4096 * 1024;
768 config->usermanual = strdup(USER_MANUAL_URL);
769 config->proxy_args = strdup("");
770 config->forwarded_connect_retries = 0;
771 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
772 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
773 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
775 if ((configfp = fopen(configfile, "r")) == NULL)
777 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
779 /* Never get here - LOG_LEVEL_FATAL causes program exit */
782 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
784 char cmd[BUFFER_SIZE];
785 char arg[BUFFER_SIZE];
786 char tmp[BUFFER_SIZE];
788 struct access_control_list *cur_acl;
789 #endif /* def FEATURE_ACL */
790 struct forward_spec *cur_fwd;
793 unsigned long directive_hash;
795 strlcpy(tmp, buf, sizeof(tmp));
797 /* Copy command (i.e. up to space or tab) into cmd */
800 while (*p && (*p != ' ') && (*p != '\t'))
806 /* Skip over the whitespace in buf */
807 while (*p && ((*p == ' ') || (*p == '\t')))
812 /* Copy the argument into arg */
813 strlcpy(arg, p, sizeof(arg));
815 /* Should never happen, but check this anyway */
821 /* Make sure the command field is lower case */
826 *p = (char)ijb_tolower(*p);
830 /* Save the argument for show-proxy-args */
831 savearg(cmd, arg, config);
833 directive_hash = hash_string(cmd);
834 switch (directive_hash)
836 /* *************************************************************************
837 * actionsfile actions-file-name
838 * In confdir by default
839 * *************************************************************************/
840 case hash_actions_file :
842 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
847 if (i >= MAX_AF_FILES)
849 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
850 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
853 config->actions_file_short[i] = strdup(arg);
854 config->actions_file[i] = make_path(config->confdir, arg);
857 /* *************************************************************************
858 * accept-intercepted-requests
859 * *************************************************************************/
860 case hash_accept_intercepted_requests:
861 if ((*arg != '\0') && (0 != atoi(arg)))
863 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
867 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
871 /* *************************************************************************
872 * admin-address email-address
873 * *************************************************************************/
874 case hash_admin_address :
875 freez(config->admin_address);
876 config->admin_address = strdup(arg);
879 /* *************************************************************************
880 * allow-cgi-request-crunching
881 * *************************************************************************/
882 case hash_allow_cgi_request_crunching:
883 if ((*arg != '\0') && (0 != atoi(arg)))
885 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
889 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
893 /* *************************************************************************
895 * *************************************************************************/
896 case hash_buffer_limit :
897 config->buffer_limit = (size_t)(1024 * atoi(arg));
900 /* *************************************************************************
901 * confdir directory-name
902 * *************************************************************************/
904 freez(config->confdir);
905 config->confdir = make_path( NULL, arg);
908 /* *************************************************************************
910 * Specifies debug level, multiple values are ORed together.
911 * *************************************************************************/
913 config->debug |= atoi(arg);
916 /* *************************************************************************
917 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
918 * *************************************************************************/
920 case hash_deny_access:
921 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
923 if ((vec_count != 1) && (vec_count != 2))
925 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
926 "deny-access directive in configuration file.");
927 string_append(&config->proxy_args,
928 "<br>\nWARNING: Wrong number of parameters for "
929 "deny-access directive in configuration file.<br><br>\n");
933 /* allocate a new node */
934 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
938 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
939 /* Never get here - LOG_LEVEL_FATAL causes program exit */
942 cur_acl->action = ACL_DENY;
944 if (acl_addr(vec[0], cur_acl->src) < 0)
946 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
947 "for deny-access directive in configuration file: \"%s\"", vec[0]);
948 string_append(&config->proxy_args,
949 "<br>\nWARNING: Invalid source address, port or netmask "
950 "for deny-access directive in configuration file: \"");
951 string_append(&config->proxy_args,
953 string_append(&config->proxy_args,
960 if (acl_addr(vec[1], cur_acl->dst) < 0)
962 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
963 "for deny-access directive in configuration file: \"%s\"", vec[1]);
964 string_append(&config->proxy_args,
965 "<br>\nWARNING: Invalid destination address, port or netmask "
966 "for deny-access directive in configuration file: \"");
967 string_append(&config->proxy_args,
969 string_append(&config->proxy_args,
977 * Add it to the list. Note we reverse the list to get the
978 * behaviour the user expects. With both the ACL and
979 * actions file, the last match wins. However, the internal
980 * implementations are different: The actions file is stored
981 * in the same order as the file, and scanned completely.
982 * With the ACL, we reverse the order as we load it, then
983 * when we scan it we stop as soon as we get a match.
985 cur_acl->next = config->acl;
986 config->acl = cur_acl;
989 #endif /* def FEATURE_ACL */
991 /* *************************************************************************
992 * enable-edit-actions 0|1
993 * *************************************************************************/
994 #ifdef FEATURE_CGI_EDIT_ACTIONS
995 case hash_enable_edit_actions:
996 if ((*arg != '\0') && (0 != atoi(arg)))
998 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1002 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1005 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1007 /* *************************************************************************
1008 * enable-remote-toggle 0|1
1009 * *************************************************************************/
1010 #ifdef FEATURE_CGI_EDIT_ACTIONS
1011 case hash_enable_remote_toggle:
1012 if ((*arg != '\0') && (0 != atoi(arg)))
1014 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1018 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1021 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1023 /* *************************************************************************
1024 * enable-remote-http-toggle 0|1
1025 * *************************************************************************/
1026 case hash_enable_remote_http_toggle:
1027 if ((*arg != '\0') && (0 != atoi(arg)))
1029 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1033 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1037 /* *************************************************************************
1038 * enforce-blocks 0|1
1039 * *************************************************************************/
1040 case hash_enforce_blocks:
1041 #ifdef FEATURE_FORCE_LOAD
1042 if ((*arg != '\0') && (0 != atoi(arg)))
1044 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1048 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1051 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1052 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1053 #endif /* def FEATURE_FORCE_LOAD */
1056 /* *************************************************************************
1057 * filterfile file-name
1058 * In confdir by default.
1059 * *************************************************************************/
1060 case hash_filterfile :
1062 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1067 if (i >= MAX_AF_FILES)
1069 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1070 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1073 config->re_filterfile_short[i] = strdup(arg);
1074 config->re_filterfile[i] = make_path(config->confdir, arg);
1078 /* *************************************************************************
1079 * forward url-pattern (.|http-proxy-host[:port])
1080 * *************************************************************************/
1082 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1086 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1087 "directive in configuration file.");
1088 string_append(&config->proxy_args,
1089 "<br>\nWARNING: Wrong number of parameters for "
1090 "forward directive in configuration file.");
1094 /* allocate a new node */
1095 cur_fwd = zalloc(sizeof(*cur_fwd));
1096 if (cur_fwd == NULL)
1098 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1099 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1103 cur_fwd->type = SOCKS_NONE;
1105 /* Save the URL pattern */
1106 if (create_url_spec(cur_fwd->url, vec[0]))
1108 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1109 "directive in configuration file.");
1110 string_append(&config->proxy_args,
1111 "<br>\nWARNING: Bad URL specifier for "
1112 "forward directive in configuration file.");
1116 /* Parse the parent HTTP proxy host:port */
1119 if (strcmp(p, ".") != 0)
1121 cur_fwd->forward_host = strdup(p);
1123 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1126 cur_fwd->forward_port = atoi(p);
1129 if (cur_fwd->forward_port <= 0)
1131 cur_fwd->forward_port = 8000;
1136 cur_fwd->next = config->forward;
1137 config->forward = cur_fwd;
1141 /* *************************************************************************
1142 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1143 * *************************************************************************/
1144 case hash_forward_socks4:
1145 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1149 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1150 "forward-socks4 directive in configuration file.");
1151 string_append(&config->proxy_args,
1152 "<br>\nWARNING: Wrong number of parameters for "
1153 "forward-socks4 directive in configuration file.");
1157 /* allocate a new node */
1158 cur_fwd = zalloc(sizeof(*cur_fwd));
1159 if (cur_fwd == NULL)
1161 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1162 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1166 cur_fwd->type = SOCKS_4;
1168 /* Save the URL pattern */
1169 if (create_url_spec(cur_fwd->url, vec[0]))
1171 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1172 "directive in configuration file.");
1173 string_append(&config->proxy_args,
1174 "<br>\nWARNING: Bad URL specifier for "
1175 "forward-socks4 directive in configuration file.");
1179 /* Parse the SOCKS proxy host[:port] */
1182 if (strcmp(p, ".") != 0)
1184 cur_fwd->gateway_host = strdup(p);
1186 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1189 cur_fwd->gateway_port = atoi(p);
1191 if (cur_fwd->gateway_port <= 0)
1193 cur_fwd->gateway_port = 1080;
1197 /* Parse the parent HTTP proxy host[:port] */
1200 if (strcmp(p, ".") != 0)
1202 cur_fwd->forward_host = strdup(p);
1204 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1207 cur_fwd->forward_port = atoi(p);
1210 if (cur_fwd->forward_port <= 0)
1212 cur_fwd->forward_port = 8000;
1217 cur_fwd->next = config->forward;
1218 config->forward = cur_fwd;
1222 /* *************************************************************************
1223 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1224 * *************************************************************************/
1225 case hash_forward_socks4a:
1226 case hash_forward_socks5:
1227 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1231 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1232 "forward-socks4a directive in configuration file.");
1233 string_append(&config->proxy_args,
1234 "<br>\nWARNING: Wrong number of parameters for "
1235 "forward-socks4a directive in configuration file.");
1239 /* allocate a new node */
1240 cur_fwd = zalloc(sizeof(*cur_fwd));
1241 if (cur_fwd == NULL)
1243 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1244 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1248 if (directive_hash == hash_forward_socks4a)
1250 cur_fwd->type = SOCKS_4A;
1254 cur_fwd->type = SOCKS_5;
1257 /* Save the URL pattern */
1258 if (create_url_spec(cur_fwd->url, vec[0]))
1260 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1261 "directive in configuration file.");
1262 string_append(&config->proxy_args,
1263 "<br>\nWARNING: Bad URL specifier for "
1264 "forward-socks4a directive in configuration file.");
1268 /* Parse the SOCKS proxy host[:port] */
1271 cur_fwd->gateway_host = strdup(p);
1273 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1276 cur_fwd->gateway_port = atoi(p);
1278 if (cur_fwd->gateway_port <= 0)
1280 cur_fwd->gateway_port = 1080;
1283 /* Parse the parent HTTP proxy host[:port] */
1286 if (strcmp(p, ".") != 0)
1288 cur_fwd->forward_host = strdup(p);
1290 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1293 cur_fwd->forward_port = atoi(p);
1296 if (cur_fwd->forward_port <= 0)
1298 cur_fwd->forward_port = 8000;
1303 cur_fwd->next = config->forward;
1304 config->forward = cur_fwd;
1308 /* *************************************************************************
1309 * forwarded-connect-retries n
1310 * *************************************************************************/
1311 case hash_forwarded_connect_retries :
1312 config->forwarded_connect_retries = atoi(arg);
1315 /* *************************************************************************
1316 * hostname hostname-to-show-on-cgi-pages
1317 * *************************************************************************/
1318 case hash_hostname :
1319 freez(config->hostname);
1320 config->hostname = strdup(arg);
1321 if (NULL == config->hostname)
1323 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1327 /* *************************************************************************
1328 * listen-address [ip][:port]
1329 * *************************************************************************/
1330 case hash_listen_address :
1331 freez(config->haddr);
1332 config->haddr = strdup(arg);
1335 /* *************************************************************************
1336 * logdir directory-name
1337 * *************************************************************************/
1339 freez(config->logdir);
1340 config->logdir = make_path(NULL, arg);
1343 /* *************************************************************************
1344 * logfile log-file-name
1345 * In logdir by default
1346 * *************************************************************************/
1350 logfile = make_path(config->logdir, arg);
1351 if (NULL == logfile)
1353 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1358 /* *************************************************************************
1359 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1360 * *************************************************************************/
1362 case hash_permit_access:
1363 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1365 if ((vec_count != 1) && (vec_count != 2))
1367 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1368 "permit-access directive in configuration file.");
1369 string_append(&config->proxy_args,
1370 "<br>\nWARNING: Wrong number of parameters for "
1371 "permit-access directive in configuration file.<br><br>\n");
1376 /* allocate a new node */
1377 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1379 if (cur_acl == NULL)
1381 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1382 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1385 cur_acl->action = ACL_PERMIT;
1387 if (acl_addr(vec[0], cur_acl->src) < 0)
1389 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1390 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1391 string_append(&config->proxy_args,
1392 "<br>\nWARNING: Invalid source address, port or netmask for "
1393 "permit-access directive in configuration file: \"");
1394 string_append(&config->proxy_args,
1396 string_append(&config->proxy_args,
1403 if (acl_addr(vec[1], cur_acl->dst) < 0)
1405 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1406 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1407 string_append(&config->proxy_args,
1408 "<br>\nWARNING: Invalid destination address, port or netmask for "
1409 "permit-access directive in configuration file: \"");
1410 string_append(&config->proxy_args,
1412 string_append(&config->proxy_args,
1420 * Add it to the list. Note we reverse the list to get the
1421 * behaviour the user expects. With both the ACL and
1422 * actions file, the last match wins. However, the internal
1423 * implementations are different: The actions file is stored
1424 * in the same order as the file, and scanned completely.
1425 * With the ACL, we reverse the order as we load it, then
1426 * when we scan it we stop as soon as we get a match.
1428 cur_acl->next = config->acl;
1429 config->acl = cur_acl;
1432 #endif /* def FEATURE_ACL */
1434 /* *************************************************************************
1435 * proxy-info-url url
1436 * *************************************************************************/
1437 case hash_proxy_info_url :
1438 freez(config->proxy_info_url);
1439 config->proxy_info_url = strdup(arg);
1442 /* *************************************************************************
1444 * *************************************************************************/
1445 case hash_single_threaded :
1446 config->multi_threaded = 0;
1449 /* *************************************************************************
1450 * split-large-cgi-forms
1451 * *************************************************************************/
1452 case hash_split_large_cgi_forms :
1453 if ((*arg != '\0') && (0 != atoi(arg)))
1455 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1459 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1463 /* *************************************************************************
1464 * templdir directory-name
1465 * *************************************************************************/
1466 case hash_templdir :
1467 freez(config->templdir);
1468 config->templdir = make_path(NULL, arg);
1471 /* *************************************************************************
1473 * *************************************************************************/
1474 #ifdef FEATURE_TOGGLE
1476 global_toggle_state = atoi(arg);
1478 #endif /* def FEATURE_TOGGLE */
1480 /* *************************************************************************
1481 * trust-info-url url
1482 * *************************************************************************/
1483 #ifdef FEATURE_TRUST
1484 case hash_trust_info_url :
1485 enlist(config->trust_info, arg);
1487 #endif /* def FEATURE_TRUST */
1489 /* *************************************************************************
1490 * trustfile filename
1491 * (In confdir by default.)
1492 * *************************************************************************/
1493 #ifdef FEATURE_TRUST
1494 case hash_trustfile :
1495 freez(config->trustfile);
1496 config->trustfile = make_path(config->confdir, arg);
1498 #endif /* def FEATURE_TRUST */
1500 /* *************************************************************************
1502 * *************************************************************************/
1503 case hash_usermanual :
1504 freez(config->usermanual);
1505 config->usermanual = strdup(arg);
1508 /* *************************************************************************
1509 * Win32 Console options:
1510 * *************************************************************************/
1512 /* *************************************************************************
1514 * *************************************************************************/
1516 case hash_hide_console :
1519 #endif /*def _WIN_CONSOLE*/
1522 /* *************************************************************************
1523 * Win32 GUI options:
1524 * *************************************************************************/
1526 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1527 /* *************************************************************************
1528 * activity-animation (0|1)
1529 * *************************************************************************/
1530 case hash_activity_animation :
1531 g_bShowActivityAnimation = atoi(arg);
1534 /* *************************************************************************
1535 * close-button-minimizes (0|1)
1536 * *************************************************************************/
1537 case hash_close_button_minimizes :
1538 g_bCloseHidesWindow = atoi(arg);
1541 /* *************************************************************************
1542 * log-buffer-size (0|1)
1543 * *************************************************************************/
1544 case hash_log_buffer_size :
1545 g_bLimitBufferSize = atoi(arg);
1548 /* *************************************************************************
1549 * log-font-name fontnane
1550 * *************************************************************************/
1551 case hash_log_font_name :
1552 strcpy( g_szFontFaceName, arg );
1555 /* *************************************************************************
1557 * *************************************************************************/
1558 case hash_log_font_size :
1559 g_nFontSize = atoi(arg);
1562 /* *************************************************************************
1563 * log-highlight-messages (0|1)
1564 * *************************************************************************/
1565 case hash_log_highlight_messages :
1566 g_bHighlightMessages = atoi(arg);
1569 /* *************************************************************************
1571 * *************************************************************************/
1572 case hash_log_max_lines :
1573 g_nMaxBufferLines = atoi(arg);
1576 /* *************************************************************************
1577 * log-messages (0|1)
1578 * *************************************************************************/
1579 case hash_log_messages :
1580 g_bLogMessages = atoi(arg);
1583 /* *************************************************************************
1584 * show-on-task-bar (0|1)
1585 * *************************************************************************/
1586 case hash_show_on_task_bar :
1587 g_bShowOnTaskBar = atoi(arg);
1590 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1593 /* *************************************************************************
1594 * Warnings about unsupported features
1595 * *************************************************************************/
1597 case hash_deny_access:
1598 #endif /* ndef FEATURE_ACL */
1599 #ifndef FEATURE_CGI_EDIT_ACTIONS
1600 case hash_enable_edit_actions:
1601 case hash_enable_remote_toggle:
1602 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1604 case hash_permit_access:
1605 #endif /* ndef FEATURE_ACL */
1606 #ifndef FEATURE_TOGGLE
1608 #endif /* ndef FEATURE_TOGGLE */
1609 #ifndef FEATURE_TRUST
1610 case hash_trustfile :
1611 case hash_trust_info_url :
1612 #endif /* ndef FEATURE_TRUST */
1614 #ifndef _WIN_CONSOLE
1615 case hash_hide_console :
1616 #endif /* ndef _WIN_CONSOLE */
1618 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1619 case hash_activity_animation :
1620 case hash_close_button_minimizes :
1621 case hash_log_buffer_size :
1622 case hash_log_font_name :
1623 case hash_log_font_size :
1624 case hash_log_highlight_messages :
1625 case hash_log_max_lines :
1626 case hash_log_messages :
1627 case hash_show_on_task_bar :
1628 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1629 /* These warnings are annoying - so hide them. -- Jon */
1630 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1633 /* *************************************************************************/
1635 /* *************************************************************************/
1637 * I decided that I liked this better as a warning than an
1638 * error. To change back to an error, just change log level
1639 * to LOG_LEVEL_FATAL.
1641 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1642 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1643 string_append(&config->proxy_args,
1644 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1647 /* *************************************************************************/
1648 } /* end switch( hash_string(cmd) ) */
1649 } /* end while ( read_config_line(...) ) */
1653 set_debug_level(config->debug);
1655 freez(config->logfile);
1659 if (NULL != logfile)
1661 config->logfile = logfile;
1662 init_error_log(Argv[0], config->logfile);
1670 if (NULL == config->proxy_args)
1672 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1675 if (config->actions_file[0])
1677 add_loader(load_action_files, config);
1680 if (config->re_filterfile[0])
1682 add_loader(load_re_filterfiles, config);
1685 #ifdef FEATURE_TRUST
1686 if (config->trustfile)
1688 add_loader(load_trustfile, config);
1690 #endif /* def FEATURE_TRUST */
1692 if ( NULL == config->haddr )
1694 config->haddr = strdup( HADDR_DEFAULT );
1697 if ( NULL != config->haddr )
1699 if (NULL != (p = strchr(config->haddr, ':')))
1704 config->hport = atoi(p);
1708 if (config->hport <= 0)
1711 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1712 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1714 if (*config->haddr == '\0')
1717 * Only the port specified. We stored it in config->hport
1718 * and don't need its text representation anymore.
1720 freez(config->haddr);
1725 * Want to run all the loaders once now.
1727 * Need to set up a fake csp, so they can get to the config.
1729 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1730 fake_csp->config = config;
1732 if (run_loader(fake_csp))
1735 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1736 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1740 /* FIXME: this is a kludge for win32 */
1741 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1743 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1744 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1745 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1747 #ifdef FEATURE_TRUST
1748 g_trustfile = config->trustfile;
1749 #endif /* def FEATURE_TRUST */
1752 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1753 /* FIXME: end kludge */
1756 config->need_bind = 1;
1758 if (current_configfile)
1760 struct configuration_spec * oldcfg = (struct configuration_spec *)
1761 current_configfile->f;
1763 * Check if config->haddr,hport == oldcfg->haddr,hport
1765 * The following could be written more compactly as a single,
1766 * (unreadably long) if statement.
1768 config->need_bind = 0;
1769 if (config->hport != oldcfg->hport)
1771 config->need_bind = 1;
1773 else if (config->haddr == NULL)
1775 if (oldcfg->haddr != NULL)
1777 config->need_bind = 1;
1780 else if (oldcfg->haddr == NULL)
1782 config->need_bind = 1;
1784 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1786 config->need_bind = 1;
1789 current_configfile->unloader = unload_configfile;
1792 fs->next = files->next;
1795 current_configfile = fs;
1801 /*********************************************************************
1803 * Function : savearg
1805 * Description : Called from `load_config'. It saves each non-empty
1806 * and non-comment line from config into
1807 * config->proxy_args. This is used to create the
1808 * show-proxy-args page. On error, frees
1809 * config->proxy_args and sets it to NULL
1812 * 1 : command = config setting that was found
1813 * 2 : argument = the setting's argument (if any)
1814 * 3 : config = Configuration to save into.
1818 *********************************************************************/
1819 static void savearg(char *command, char *argument, struct configuration_spec * config)
1828 * Add config option name embedded in
1829 * link to its section in the user-manual
1831 buf = strdup("\n<a href=\"");
1832 if (!strncmpic(config->usermanual, "file://", 7) ||
1833 !strncmpic(config->usermanual, "http", 4))
1835 string_append(&buf, config->usermanual);
1839 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1841 string_append(&buf, CONFIG_HELP_PREFIX);
1842 string_join (&buf, string_toupper(command));
1843 string_append(&buf, "\">");
1844 string_append(&buf, command);
1845 string_append(&buf, "</a> ");
1849 freez(config->proxy_args);
1853 if ( (NULL != argument) && ('\0' != *argument) )
1855 s = html_encode(argument);
1859 freez(config->proxy_args);
1863 if (strncmpic(argument, "http://", 7) == 0)
1865 string_append(&buf, "<a href=\"");
1866 string_append(&buf, s);
1867 string_append(&buf, "\">");
1868 string_join (&buf, s);
1869 string_append(&buf, "</a>");
1873 string_join (&buf, s);
1877 string_append(&buf, "<br>");
1878 string_join(&config->proxy_args, buf);