1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.77 2008/05/26 16:13: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.77 2008/05/26 16:13:22 fabiankeil
39 * Reuse directive_hash and don't hash the same directive twice.
41 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
42 * - Merge three string_append() calls.
43 * - Remove useless assertion.
45 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
46 * Rename load_actions_file() and load_re_filterfile()
47 * as they load multiple files "now".
49 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
50 * Add hostname directive. Closes PR#1918189.
52 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
55 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
56 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
58 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
59 * Reword "unrecognized directive" warning, use better
60 * mark up and add a <br>. Fixes parts of #1856559.
62 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
63 * Plug memory leak if listen-address only specifies the port.
65 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
66 * Relocate daemon-mode-related log messages to make sure
67 * they aren't shown again in case of configuration reloads.
69 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
70 * Plug memory leak introduced with my last commit.
72 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
73 * When in daemon mode, close stderr after the configuration file has been
74 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
76 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
77 * #1763173 from Stefan Huehner: declare unload_configfile() static.
79 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
80 * As Hal noticed, checking dispatch_cgi() as the last cruncher
81 * looks like a bug if CGI requests are blocked unintentionally,
82 * so don't do it unless the user enabled the new config option
83 * "allow-cgi-request-crunching".
85 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
86 * - Use strlcpy() instead of strcpy().
87 * - Stop treating actions files special. Expect a complete file name
88 * (with or without path) like it's done for the rest of the files.
90 * - Remove an unnecessary temporary memory allocation.
91 * - Don't log anything to the console when running as
92 * daemon and no errors occurred.
94 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
95 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
97 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
98 * New config option: enforce-blocks.
100 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
101 * - Mention other reasons why acl directive loading might have failed.
102 * - Don't log the acl source if the acl destination is to blame.
104 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
105 * Add new config option "templdir" to
106 * change the templates directory.
108 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
109 * Added config option accept-intercepted-requests
110 * and disabled it by default.
112 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
113 * Fix gcc43 compiler warnings.
115 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
116 * Add config option "split-large-forms"
117 * to work around the browser bug reported
120 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
121 * Move the <br> in the generated HTML for the config
122 * options from the beginning of the string to its end.
123 * Keeps the white space in balance.
125 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
126 * Fix memory leak in case of config file reloads.
128 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
129 * Modified kludge for win32 to make ming32 menu
130 * "Options/Edit Filters" (sort of) work again.
131 * Same limitations as for the action files apply.
134 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
135 * Incorporate modified version of Roland Rosenfeld's patch to
136 * optionally access the user-manual via Privoxy. Closes patch 679075.
138 * Formatting changed to Privoxy style, added call to
139 * cgi_error_no_template if the requested file doesn't
140 * exist and modified check whether or not Privoxy itself
141 * should serve the manual. Should work cross-platform now.
143 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
144 * Added config option enable-remote-http-toggle
145 * to specify if Privoxy should recognize special
146 * headers (currently only X-Filter) to change its
147 * behaviour. Disabled by default.
149 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
150 * Make number of retries in case of forwarded-connect problems
151 * a config file option (forwarded-connect-retries) and use 0 as
154 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
155 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
156 * with what was really the latest development (the v_3_0_branch branch)
158 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
159 * Don't forget to malloc space for the null terminator...
161 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
162 * Multiple filter file support
164 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
165 * Closed two memory leaks; hopefully the last remaining ones
166 * (in the main execution paths, anyway).
168 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
169 * Addressed bug #719435
170 * - Extraneous filterfile directives now logged as errors
171 * - This and unrecnonised directives now really obvious on status page
173 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
174 * Cosmetic: Renamed cryptic variable
176 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
177 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
179 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
180 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
182 * Revision 1.48 2002/05/14 21:30:38 oes
183 * savearg now uses own linking code instead of (now special-cased) add_help_link
185 * Revision 1.47 2002/05/12 21:36:29 jongfoster
186 * Correcting function comments
188 * Revision 1.46 2002/04/26 12:55:14 oes
189 * - New option "user-manual", defaults to our site
190 * via project.h #define
191 * - savearg now embeds option names in help links
193 * Revision 1.45 2002/04/24 02:11:54 oes
194 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
196 * Revision 1.44 2002/04/08 20:37:13 swa
199 * Revision 1.43 2002/04/08 20:36:50 swa
202 * Revision 1.42 2002/04/05 15:50:15 oes
203 * fix for invalid HTML proxy_args
205 * Revision 1.41 2002/03/31 17:19:00 jongfoster
206 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
208 * Revision 1.40 2002/03/26 22:29:55 swa
209 * we have a new homepage!
211 * Revision 1.39 2002/03/24 13:25:43 swa
212 * name change related issues
214 * Revision 1.38 2002/03/24 13:05:48 jongfoster
215 * Renaming re_filterfile to filterfile
217 * Revision 1.37 2002/03/16 23:54:06 jongfoster
218 * Adding graceful termination feature, to help look for memory leaks.
219 * If you enable this (which, by design, has to be done by hand
220 * editing config.h) and then go to http://i.j.b/die, then the program
221 * will exit cleanly after the *next* request. It should free all the
222 * memory that was used.
224 * Revision 1.36 2002/03/13 00:27:05 jongfoster
227 * Revision 1.35 2002/03/07 03:52:44 oes
228 * Set logging to tty for --no-daemon mode
230 * Revision 1.34 2002/03/06 23:14:35 jongfoster
231 * Trivial cosmetic changes to make function comments easier to find.
233 * Revision 1.33 2002/03/05 04:52:42 oes
234 * Deleted non-errlog debugging code
236 * Revision 1.32 2002/03/04 18:24:53 oes
237 * Re-enabled output of unknown config directive hash
239 * Revision 1.31 2002/03/03 15:07:20 oes
240 * Re-enabled automatic config reloading
242 * Revision 1.30 2002/01/22 23:31:43 jongfoster
243 * Replacing strsav() with string_append()
245 * Revision 1.29 2002/01/17 21:02:30 jongfoster
246 * Moving all our URL and URL pattern parsing code to urlmatch.c.
248 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
250 * Revision 1.28 2001/12/30 14:07:32 steudten
251 * - Add signal handling (unix)
252 * - Add SIGHUP handler (unix)
253 * - Add creation of pidfile (unix)
254 * - Add action 'top' in rc file (RH)
255 * - Add entry 'SIGNALS' to manpage
256 * - Add exit message to logfile (unix)
258 * Revision 1.27 2001/11/07 00:02:13 steudten
259 * Add line number in error output for lineparsing for
260 * actionsfile and configfile.
261 * Special handling for CLF added.
263 * Revision 1.26 2001/11/05 21:41:43 steudten
264 * Add changes to be a real daemon just for unix os.
265 * (change cwd to /, detach from controlling tty, set
266 * process group and session leader to the own process.
268 * Add some fatal-error log message for failed malloc().
269 * Add '-d' if compiled with 'configure --with-debug' to
270 * enable debug output.
272 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
273 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
274 * threads to call select() simultaneously. So, it's time to do a real, live,
275 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
276 * (native). Both versions will work, but using __OS2__ offers multi-threading.
278 * Revision 1.24 2001/10/23 21:40:30 jongfoster
279 * Added support for enable-edit-actions and enable-remote-toggle config
282 * Revision 1.23 2001/10/07 15:36:00 oes
283 * Introduced new config option "buffer-limit"
285 * Revision 1.22 2001/09/22 16:36:59 jongfoster
286 * Removing unused parameter fs from read_config_line()
288 * Revision 1.21 2001/09/16 17:10:43 jongfoster
289 * Moving function savearg() here, since it was the only thing left in
292 * Revision 1.20 2001/07/30 22:08:36 jongfoster
293 * Tidying up #defines:
294 * - All feature #defines are now of the form FEATURE_xxx
295 * - Permanently turned off WIN_GUI_EDIT
296 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
298 * Revision 1.19 2001/07/15 17:45:16 jongfoster
299 * Removing some unused #includes
301 * Revision 1.18 2001/07/13 14:01:14 oes
302 * - Removed all #ifdef PCRS
303 * - Removed vim-settings
305 * Revision 1.17 2001/06/29 13:31:03 oes
306 * - Improved comments
307 * - Fixed (actionsfile) and sorted hashes
308 * - Introduced admin_address and proxy-info-url
309 * as config parameters
310 * - Renamed config->proxy_args_invocation (which didn't have
311 * the invocation but the options!) to config->proxy_args
312 * - Various adaptions
313 * - Removed logentry from cancelled commit
315 * Revision 1.16 2001/06/09 10:55:28 jongfoster
316 * Changing BUFSIZ ==> BUFFER_SIZE
318 * Revision 1.15 2001/06/07 23:13:40 jongfoster
319 * Merging ACL and forward files into config file.
320 * Cosmetic: Sorting config file options alphabetically.
321 * Cosmetic: Adding brief syntax comments to config file options.
323 * Revision 1.14 2001/06/07 14:46:25 joergs
324 * Missing make_path() added for re_filterfile.
326 * Revision 1.13 2001/06/05 22:33:54 jongfoster
328 * Fixed minor memory leak.
329 * Also now uses make_path to prepend the pathnames.
331 * Revision 1.12 2001/06/05 20:04:09 jongfoster
332 * Now uses _snprintf() in place of snprintf() under Win32.
334 * Revision 1.11 2001/06/04 18:31:58 swa
335 * files are now prefixed with either `confdir' or `logdir'.
336 * `make redhat-dist' replaces both entries confdir and logdir
339 * Revision 1.10 2001/06/03 19:11:54 oes
340 * introduced confdir option
342 * Revision 1.9 2001/06/01 20:06:24 jongfoster
343 * Removed support for "tinygif" option - moved to actions file.
345 * Revision 1.8 2001/05/31 21:27:13 jongfoster
346 * Removed many options from the config file and into the
347 * "actions" file: add_forwarded, suppress_vanilla_wafer,
348 * wafer, add_header, user_agent, referer, from
349 * Also globally replaced "permission" with "action".
351 * Revision 1.7 2001/05/29 09:50:24 jongfoster
352 * Unified blocklist/imagelist/permissionslist.
353 * File format is still under discussion, but the internal changes
356 * Also modified interceptor behaviour:
357 * - We now intercept all URLs beginning with one of the following
358 * prefixes (and *only* these prefixes):
360 * * http://ijbswa.sf.net/config/
361 * * http://ijbswa.sourceforge.net/config/
362 * - New interceptors "home page" - go to http://i.j.b/ to see it.
363 * - Internal changes so that intercepted and fast redirect pages
364 * are not replaced with an image.
365 * - Interceptors now have the option to send a binary page direct
366 * to the client. (i.e. ijb-send-banner uses this)
367 * - Implemented show-url-info interceptor. (Which is why I needed
368 * the above interceptors changes - a typical URL is
369 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
370 * The previous mechanism would not have intercepted that, and
371 * if it had been intercepted then it then it would have replaced
374 * Revision 1.6 2001/05/26 00:28:36 jongfoster
375 * Automatic reloading of config file.
376 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
377 * Most of the global variables have been moved to a new
378 * struct configuration_spec, accessed through csp->config->globalname
379 * Most of the globals remaining are used by the Win32 GUI.
381 * Revision 1.5 2001/05/25 22:34:30 jongfoster
384 * Revision 1.4 2001/05/22 18:46:04 oes
386 * - Enabled filtering banners by size rather than URL
387 * by adding patterns that replace all standard banner
388 * sizes with the "Junkbuster" gif to the re_filterfile
390 * - Enabled filtering WebBugs by providing a pattern
391 * which kills all 1x1 images
393 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
394 * which is selected by the (nonstandard and therefore
395 * capital) letter 'U' in the option string.
396 * It causes the quantifiers to be ungreedy by default.
397 * Appending a ? turns back to greedy (!).
399 * - Added a new interceptor ijb-send-banner, which
400 * sends back the "Junkbuster" gif. Without imagelist or
401 * MSIE detection support, or if tinygif = 1, or the
402 * URL isn't recognized as an imageurl, a lame HTML
403 * explanation is sent instead.
405 * - Added new feature, which permits blocking remote
406 * script redirects and firing back a local redirect
408 * The feature is conditionally compiled, i.e. it
409 * can be disabled with --disable-fast-redirects,
410 * plus it must be activated by a "fast-redirects"
411 * line in the config file, has its own log level
412 * and of course wants to be displayed by show-proxy-args
413 * Note: Boy, all the #ifdefs in 1001 locations and
414 * all the fumbling with configure.in and acconfig.h
415 * were *way* more work than the feature itself :-(
417 * - Because a generic redirect template was needed for
418 * this, tinygif = 3 now uses the same.
420 * - Moved GIFs, and other static HTTP response templates
425 * - Removed some >400 CRs again (Jon, you really worked
428 * Revision 1.3 2001/05/20 01:21:20 jongfoster
429 * Version 2.9.4 checkin.
430 * - Merged popupfile and cookiefile, and added control over PCRS
431 * filtering, in new "permissionsfile".
432 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
433 * file error you now get a message box (in the Win32 GUI) rather
434 * than the program exiting with no explanation.
435 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
437 * - Removed tabs from "config"
438 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
439 * - Bumped up version number.
441 * Revision 1.2 2001/05/17 23:01:01 oes
442 * - Cleaned CRLF's from the sources and related files
444 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
445 * Initial import of version 2.9.3 source tree
448 *********************************************************************/
454 #include <sys/types.h>
468 # include <windows.h>
471 # ifndef _WIN_CONSOLE
473 # endif /* ndef _WIN_CONSOLE */
475 #else /* ifndef _WIN32 */
479 # include <sys/wait.h>
481 # include <sys/time.h>
482 # include <sys/stat.h>
492 #include "miscutil.h"
496 #include "urlmatch.h"
499 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
502 * Fix a problem with Solaris. There should be no effect on other
504 * Solaris's isspace() is a macro which uses it's argument directly
505 * as an array index. Therefore we need to make sure that high-bit
506 * characters generate +ve values, and ideally we also want to make
507 * the argument match the declared parameter type of "int".
509 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
510 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
512 #ifdef FEATURE_TOGGLE
513 /* Privoxy is enabled by default. */
514 int global_toggle_state = 1;
515 #endif /* def FEATURE_TOGGLE */
517 /* The filename of the configfile */
518 const char *configfile = NULL;
521 * CGI functions will later need access to the invocation args,
522 * so we will make argc and argv global.
525 const char **Argv = NULL;
527 static struct file_list *current_configfile = NULL;
531 * This takes the "cryptic" hash of each keyword and aliases them to
532 * something a little more readable. This also makes changing the
533 * hash values easier if they should change or the hash algorthm changes.
534 * Use the included "hash" program to find out what the hash will be
535 * for any string supplied on the command line. (Or just put it in the
536 * config file and read the number from the error message in the log).
538 * Please keep this list sorted alphabetically (but with the Windows
539 * console and GUI specific options last).
542 #define hash_actions_file 1196306641ul /* "actionsfile" */
543 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
544 #define hash_admin_address 4112573064ul /* "admin-address" */
545 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
546 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
547 #define hash_confdir 1978389ul /* "confdir" */
548 #define hash_debug 78263ul /* "debug" */
549 #define hash_deny_access 1227333715ul /* "deny-access" */
550 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
551 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
552 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
553 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
554 #define hash_filterfile 250887266ul /* "filterfile" */
555 #define hash_forward 2029845ul /* "forward" */
556 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
557 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
558 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
559 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
560 #define hash_hostname 10308071ul /* "hostname" */
561 #define hash_jarfile 2046641ul /* "jarfile" */
562 #define hash_listen_address 1255650842ul /* "listen-address" */
563 #define hash_logdir 422889ul /* "logdir" */
564 #define hash_logfile 2114766ul /* "logfile" */
565 #define hash_permit_access 3587953268ul /* "permit-access" */
566 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
567 #define hash_single_threaded 4250084780ul /* "single-threaded" */
568 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
569 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
570 #define hash_templdir 11067889ul /* "templdir" */
571 #define hash_toggle 447966ul /* "toggle" */
572 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
573 #define hash_trustfile 56494766ul /* "trustfile" */
574 #define hash_usermanual 1416668518ul /* "user-manual" */
575 #define hash_activity_animation 1817904738ul /* "activity-animation" */
576 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
577 #define hash_hide_console 2048809870ul /* "hide-console" */
578 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
579 #define hash_log_font_name 2866730124ul /* "log-font-name" */
580 #define hash_log_font_size 2866731014ul /* "log-font-size" */
581 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
582 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
583 #define hash_log_messages 2291744899ul /* "log-messages" */
584 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
587 static void savearg(char *command, char *argument, struct configuration_spec * config);
589 /*********************************************************************
591 * Function : unload_configfile
593 * Description : Free the config structure and all components.
596 * 1 : data: struct configuration_spec to unload
600 *********************************************************************/
601 static void unload_configfile (void * data)
603 struct configuration_spec * config = (struct configuration_spec *)data;
604 struct forward_spec *cur_fwd = config->forward;
608 struct access_control_list *cur_acl = config->acl;
610 while (cur_acl != NULL)
612 struct access_control_list * next_acl = cur_acl->next;
617 #endif /* def FEATURE_ACL */
619 while (cur_fwd != NULL)
621 struct forward_spec * next_fwd = cur_fwd->next;
622 free_url_spec(cur_fwd->url);
624 freez(cur_fwd->gateway_host);
625 freez(cur_fwd->forward_host);
629 config->forward = NULL;
631 #ifdef FEATURE_COOKIE_JAR
632 if ( NULL != config->jar )
634 fclose( config->jar );
637 #endif /* def FEATURE_COOKIE_JAR */
639 freez(config->confdir);
640 freez(config->logdir);
641 freez(config->templdir);
642 freez(config->hostname);
644 freez(config->haddr);
645 freez(config->logfile);
647 for (i = 0; i < MAX_AF_FILES; i++)
649 freez(config->actions_file_short[i]);
650 freez(config->actions_file[i]);
651 freez(config->re_filterfile_short[i]);
652 freez(config->re_filterfile[i]);
655 freez(config->admin_address);
656 freez(config->proxy_info_url);
657 freez(config->proxy_args);
658 freez(config->usermanual);
660 #ifdef FEATURE_COOKIE_JAR
661 freez(config->jarfile);
662 #endif /* def FEATURE_COOKIE_JAR */
665 freez(config->trustfile);
666 list_remove_all(config->trust_info);
667 #endif /* def FEATURE_TRUST */
669 for (i = 0; i < MAX_AF_FILES; i++)
671 freez(config->re_filterfile[i]);
678 #ifdef FEATURE_GRACEFUL_TERMINATION
679 /*********************************************************************
681 * Function : unload_current_config_file
683 * Description : Unloads current config file - reset to state at
684 * beginning of program.
690 *********************************************************************/
691 void unload_current_config_file(void)
693 if (current_configfile)
695 current_configfile->unloader = unload_configfile;
696 current_configfile = NULL;
702 /*********************************************************************
704 * Function : load_config
706 * Description : Load the config file and all parameters.
708 * XXX: more than thousand lines long
709 * and thus in serious need of refactoring.
713 * Returns : The configuration_spec, or NULL on error.
715 *********************************************************************/
716 struct configuration_spec * load_config(void)
718 char buf[BUFFER_SIZE];
720 FILE *configfp = NULL;
721 struct configuration_spec * config = NULL;
722 struct client_state * fake_csp;
723 struct file_list *fs;
724 unsigned long linenum = 0;
726 char *logfile = NULL;
728 if ( !check_file_changed(current_configfile, configfile, &fs))
730 /* No need to load */
731 return ((struct configuration_spec *)current_configfile->f);
735 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
739 if (NULL != current_configfile)
741 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
744 #ifdef FEATURE_TOGGLE
745 global_toggle_state = 1;
746 #endif /* def FEATURE_TOGGLE */
748 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
754 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
755 /* Never get here - LOG_LEVEL_FATAL causes program exit */
759 * This is backwards from how it's usually done.
760 * Following the usual pattern, "fs" would be stored in a member
761 * variable in "csp", and then we'd access "config" from "fs->f",
762 * using a cast. However, "config" is used so often that a
763 * cast each time would be very ugly, and the extra indirection
764 * would waste CPU cycles. Therefore we store "config" in
765 * "csp->config", and "fs" in "csp->config->config_file_list".
767 config->config_file_list = fs;
772 config->multi_threaded = 1;
773 config->hport = HADDR_PORT;
774 config->buffer_limit = 4096 * 1024;
775 config->usermanual = strdup(USER_MANUAL_URL);
776 config->proxy_args = strdup("");
777 config->forwarded_connect_retries = 0;
778 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
779 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
780 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
782 if ((configfp = fopen(configfile, "r")) == NULL)
784 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
786 /* Never get here - LOG_LEVEL_FATAL causes program exit */
789 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
791 char cmd[BUFFER_SIZE];
792 char arg[BUFFER_SIZE];
793 char tmp[BUFFER_SIZE];
795 struct access_control_list *cur_acl;
796 #endif /* def FEATURE_ACL */
797 struct forward_spec *cur_fwd;
800 unsigned long directive_hash;
802 strlcpy(tmp, buf, sizeof(tmp));
804 /* Copy command (i.e. up to space or tab) into cmd */
807 while (*p && (*p != ' ') && (*p != '\t'))
813 /* Skip over the whitespace in buf */
814 while (*p && ((*p == ' ') || (*p == '\t')))
819 /* Copy the argument into arg */
820 strlcpy(arg, p, sizeof(arg));
822 /* Should never happen, but check this anyway */
828 /* Make sure the command field is lower case */
833 *p = (char)ijb_tolower(*p);
837 /* Save the argument for show-proxy-args */
838 savearg(cmd, arg, config);
840 directive_hash = hash_string(cmd);
841 switch (directive_hash)
843 /* *************************************************************************
844 * actionsfile actions-file-name
845 * In confdir by default
846 * *************************************************************************/
847 case hash_actions_file :
849 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
854 if (i >= MAX_AF_FILES)
856 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
857 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
860 config->actions_file_short[i] = strdup(arg);
861 config->actions_file[i] = make_path(config->confdir, arg);
864 /* *************************************************************************
865 * accept-intercepted-requests
866 * *************************************************************************/
867 case hash_accept_intercepted_requests:
868 if ((*arg != '\0') && (0 != atoi(arg)))
870 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
874 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
878 /* *************************************************************************
879 * admin-address email-address
880 * *************************************************************************/
881 case hash_admin_address :
882 freez(config->admin_address);
883 config->admin_address = strdup(arg);
886 /* *************************************************************************
887 * allow-cgi-request-crunching
888 * *************************************************************************/
889 case hash_allow_cgi_request_crunching:
890 if ((*arg != '\0') && (0 != atoi(arg)))
892 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
896 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
900 /* *************************************************************************
902 * *************************************************************************/
903 case hash_buffer_limit :
904 config->buffer_limit = (size_t)(1024 * atoi(arg));
907 /* *************************************************************************
908 * confdir directory-name
909 * *************************************************************************/
911 freez(config->confdir);
912 config->confdir = make_path( NULL, arg);
915 /* *************************************************************************
917 * Specifies debug level, multiple values are ORed together.
918 * *************************************************************************/
920 config->debug |= atoi(arg);
923 /* *************************************************************************
924 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
925 * *************************************************************************/
927 case hash_deny_access:
928 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
930 if ((vec_count != 1) && (vec_count != 2))
932 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
933 "deny-access directive in configuration file.");
934 string_append(&config->proxy_args,
935 "<br>\nWARNING: Wrong number of parameters for "
936 "deny-access directive in configuration file.<br><br>\n");
940 /* allocate a new node */
941 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
945 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
946 /* Never get here - LOG_LEVEL_FATAL causes program exit */
949 cur_acl->action = ACL_DENY;
951 if (acl_addr(vec[0], cur_acl->src) < 0)
953 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
954 "for deny-access directive in configuration file: \"%s\"", vec[0]);
955 string_append(&config->proxy_args,
956 "<br>\nWARNING: Invalid source address, port or netmask "
957 "for deny-access directive in configuration file: \"");
958 string_append(&config->proxy_args,
960 string_append(&config->proxy_args,
967 if (acl_addr(vec[1], cur_acl->dst) < 0)
969 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
970 "for deny-access directive in configuration file: \"%s\"", vec[1]);
971 string_append(&config->proxy_args,
972 "<br>\nWARNING: Invalid destination address, port or netmask "
973 "for deny-access directive in configuration file: \"");
974 string_append(&config->proxy_args,
976 string_append(&config->proxy_args,
984 * Add it to the list. Note we reverse the list to get the
985 * behaviour the user expects. With both the ACL and
986 * actions file, the last match wins. However, the internal
987 * implementations are different: The actions file is stored
988 * in the same order as the file, and scanned completely.
989 * With the ACL, we reverse the order as we load it, then
990 * when we scan it we stop as soon as we get a match.
992 cur_acl->next = config->acl;
993 config->acl = cur_acl;
996 #endif /* def FEATURE_ACL */
998 /* *************************************************************************
999 * enable-edit-actions 0|1
1000 * *************************************************************************/
1001 #ifdef FEATURE_CGI_EDIT_ACTIONS
1002 case hash_enable_edit_actions:
1003 if ((*arg != '\0') && (0 != atoi(arg)))
1005 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1009 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1012 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1014 /* *************************************************************************
1015 * enable-remote-toggle 0|1
1016 * *************************************************************************/
1017 #ifdef FEATURE_CGI_EDIT_ACTIONS
1018 case hash_enable_remote_toggle:
1019 if ((*arg != '\0') && (0 != atoi(arg)))
1021 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1025 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1028 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1030 /* *************************************************************************
1031 * enable-remote-http-toggle 0|1
1032 * *************************************************************************/
1033 case hash_enable_remote_http_toggle:
1034 if ((*arg != '\0') && (0 != atoi(arg)))
1036 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1040 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1044 /* *************************************************************************
1045 * enforce-blocks 0|1
1046 * *************************************************************************/
1047 case hash_enforce_blocks:
1048 #ifdef FEATURE_FORCE_LOAD
1049 if ((*arg != '\0') && (0 != atoi(arg)))
1051 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1055 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1058 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1059 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1060 #endif /* def FEATURE_FORCE_LOAD */
1063 /* *************************************************************************
1064 * filterfile file-name
1065 * In confdir by default.
1066 * *************************************************************************/
1067 case hash_filterfile :
1069 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1074 if (i >= MAX_AF_FILES)
1076 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1077 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1080 config->re_filterfile_short[i] = strdup(arg);
1081 config->re_filterfile[i] = make_path(config->confdir, arg);
1085 /* *************************************************************************
1086 * forward url-pattern (.|http-proxy-host[:port])
1087 * *************************************************************************/
1089 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1093 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1094 "directive in configuration file.");
1095 string_append(&config->proxy_args,
1096 "<br>\nWARNING: Wrong number of parameters for "
1097 "forward directive in configuration file.");
1101 /* allocate a new node */
1102 cur_fwd = zalloc(sizeof(*cur_fwd));
1103 if (cur_fwd == NULL)
1105 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1106 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1110 cur_fwd->type = SOCKS_NONE;
1112 /* Save the URL pattern */
1113 if (create_url_spec(cur_fwd->url, vec[0]))
1115 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1116 "directive in configuration file.");
1117 string_append(&config->proxy_args,
1118 "<br>\nWARNING: Bad URL specifier for "
1119 "forward directive in configuration file.");
1123 /* Parse the parent HTTP proxy host:port */
1126 if (strcmp(p, ".") != 0)
1128 cur_fwd->forward_host = strdup(p);
1130 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1133 cur_fwd->forward_port = atoi(p);
1136 if (cur_fwd->forward_port <= 0)
1138 cur_fwd->forward_port = 8000;
1143 cur_fwd->next = config->forward;
1144 config->forward = cur_fwd;
1148 /* *************************************************************************
1149 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1150 * *************************************************************************/
1151 case hash_forward_socks4:
1152 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1156 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1157 "forward-socks4 directive in configuration file.");
1158 string_append(&config->proxy_args,
1159 "<br>\nWARNING: Wrong number of parameters for "
1160 "forward-socks4 directive in configuration file.");
1164 /* allocate a new node */
1165 cur_fwd = zalloc(sizeof(*cur_fwd));
1166 if (cur_fwd == NULL)
1168 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1169 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1173 cur_fwd->type = SOCKS_4;
1175 /* Save the URL pattern */
1176 if (create_url_spec(cur_fwd->url, vec[0]))
1178 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1179 "directive in configuration file.");
1180 string_append(&config->proxy_args,
1181 "<br>\nWARNING: Bad URL specifier for "
1182 "forward-socks4 directive in configuration file.");
1186 /* Parse the SOCKS proxy host[:port] */
1189 if (strcmp(p, ".") != 0)
1191 cur_fwd->gateway_host = strdup(p);
1193 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1196 cur_fwd->gateway_port = atoi(p);
1198 if (cur_fwd->gateway_port <= 0)
1200 cur_fwd->gateway_port = 1080;
1204 /* Parse the parent HTTP proxy host[:port] */
1207 if (strcmp(p, ".") != 0)
1209 cur_fwd->forward_host = strdup(p);
1211 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1214 cur_fwd->forward_port = atoi(p);
1217 if (cur_fwd->forward_port <= 0)
1219 cur_fwd->forward_port = 8000;
1224 cur_fwd->next = config->forward;
1225 config->forward = cur_fwd;
1229 /* *************************************************************************
1230 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1231 * *************************************************************************/
1232 case hash_forward_socks4a:
1233 case hash_forward_socks5:
1234 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1238 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1239 "forward-socks4a directive in configuration file.");
1240 string_append(&config->proxy_args,
1241 "<br>\nWARNING: Wrong number of parameters for "
1242 "forward-socks4a directive in configuration file.");
1246 /* allocate a new node */
1247 cur_fwd = zalloc(sizeof(*cur_fwd));
1248 if (cur_fwd == NULL)
1250 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1251 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1255 if (directive_hash == hash_forward_socks4a)
1257 cur_fwd->type = SOCKS_4A;
1261 cur_fwd->type = SOCKS_5;
1264 /* Save the URL pattern */
1265 if (create_url_spec(cur_fwd->url, vec[0]))
1267 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1268 "directive in configuration file.");
1269 string_append(&config->proxy_args,
1270 "<br>\nWARNING: Bad URL specifier for "
1271 "forward-socks4a directive in configuration file.");
1275 /* Parse the SOCKS proxy host[:port] */
1278 cur_fwd->gateway_host = strdup(p);
1280 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1283 cur_fwd->gateway_port = atoi(p);
1285 if (cur_fwd->gateway_port <= 0)
1287 cur_fwd->gateway_port = 1080;
1290 /* Parse the parent HTTP proxy host[:port] */
1293 if (strcmp(p, ".") != 0)
1295 cur_fwd->forward_host = strdup(p);
1297 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1300 cur_fwd->forward_port = atoi(p);
1303 if (cur_fwd->forward_port <= 0)
1305 cur_fwd->forward_port = 8000;
1310 cur_fwd->next = config->forward;
1311 config->forward = cur_fwd;
1315 /* *************************************************************************
1316 * forwarded-connect-retries n
1317 * *************************************************************************/
1318 case hash_forwarded_connect_retries :
1319 config->forwarded_connect_retries = atoi(arg);
1322 /* *************************************************************************
1323 * hostname hostname-to-show-on-cgi-pages
1324 * *************************************************************************/
1325 case hash_hostname :
1326 freez(config->hostname);
1327 config->hostname = strdup(arg);
1328 if (NULL == config->hostname)
1330 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1334 /* *************************************************************************
1335 * jarfile jar-file-name
1336 * In logdir by default
1337 * *************************************************************************/
1338 #ifdef FEATURE_COOKIE_JAR
1340 freez(config->jarfile);
1341 config->jarfile = make_path(config->logdir, arg);
1343 #endif /* def FEATURE_COOKIE_JAR */
1345 /* *************************************************************************
1346 * listen-address [ip][:port]
1347 * *************************************************************************/
1348 case hash_listen_address :
1349 freez(config->haddr);
1350 config->haddr = strdup(arg);
1353 /* *************************************************************************
1354 * logdir directory-name
1355 * *************************************************************************/
1357 freez(config->logdir);
1358 config->logdir = make_path(NULL, arg);
1361 /* *************************************************************************
1362 * logfile log-file-name
1363 * In logdir by default
1364 * *************************************************************************/
1368 logfile = make_path(config->logdir, arg);
1369 if (NULL == logfile)
1371 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1376 /* *************************************************************************
1377 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1378 * *************************************************************************/
1380 case hash_permit_access:
1381 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1383 if ((vec_count != 1) && (vec_count != 2))
1385 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1386 "permit-access directive in configuration file.");
1387 string_append(&config->proxy_args,
1388 "<br>\nWARNING: Wrong number of parameters for "
1389 "permit-access directive in configuration file.<br><br>\n");
1394 /* allocate a new node */
1395 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1397 if (cur_acl == NULL)
1399 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1400 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1403 cur_acl->action = ACL_PERMIT;
1405 if (acl_addr(vec[0], cur_acl->src) < 0)
1407 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1408 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1409 string_append(&config->proxy_args,
1410 "<br>\nWARNING: Invalid source address, port or netmask for "
1411 "permit-access directive in configuration file: \"");
1412 string_append(&config->proxy_args,
1414 string_append(&config->proxy_args,
1421 if (acl_addr(vec[1], cur_acl->dst) < 0)
1423 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1424 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1425 string_append(&config->proxy_args,
1426 "<br>\nWARNING: Invalid destination address, port or netmask for "
1427 "permit-access directive in configuration file: \"");
1428 string_append(&config->proxy_args,
1430 string_append(&config->proxy_args,
1438 * Add it to the list. Note we reverse the list to get the
1439 * behaviour the user expects. With both the ACL and
1440 * actions file, the last match wins. However, the internal
1441 * implementations are different: The actions file is stored
1442 * in the same order as the file, and scanned completely.
1443 * With the ACL, we reverse the order as we load it, then
1444 * when we scan it we stop as soon as we get a match.
1446 cur_acl->next = config->acl;
1447 config->acl = cur_acl;
1450 #endif /* def FEATURE_ACL */
1452 /* *************************************************************************
1453 * proxy-info-url url
1454 * *************************************************************************/
1455 case hash_proxy_info_url :
1456 freez(config->proxy_info_url);
1457 config->proxy_info_url = strdup(arg);
1460 /* *************************************************************************
1462 * *************************************************************************/
1463 case hash_single_threaded :
1464 config->multi_threaded = 0;
1467 /* *************************************************************************
1468 * split-large-cgi-forms
1469 * *************************************************************************/
1470 case hash_split_large_cgi_forms :
1471 if ((*arg != '\0') && (0 != atoi(arg)))
1473 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1477 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1481 /* *************************************************************************
1482 * templdir directory-name
1483 * *************************************************************************/
1484 case hash_templdir :
1485 freez(config->templdir);
1486 config->templdir = make_path(NULL, arg);
1489 /* *************************************************************************
1491 * *************************************************************************/
1492 #ifdef FEATURE_TOGGLE
1494 global_toggle_state = atoi(arg);
1496 #endif /* def FEATURE_TOGGLE */
1498 /* *************************************************************************
1499 * trust-info-url url
1500 * *************************************************************************/
1501 #ifdef FEATURE_TRUST
1502 case hash_trust_info_url :
1503 enlist(config->trust_info, arg);
1505 #endif /* def FEATURE_TRUST */
1507 /* *************************************************************************
1508 * trustfile filename
1509 * (In confdir by default.)
1510 * *************************************************************************/
1511 #ifdef FEATURE_TRUST
1512 case hash_trustfile :
1513 freez(config->trustfile);
1514 config->trustfile = make_path(config->confdir, arg);
1516 #endif /* def FEATURE_TRUST */
1518 /* *************************************************************************
1520 * *************************************************************************/
1521 case hash_usermanual :
1522 freez(config->usermanual);
1523 config->usermanual = strdup(arg);
1526 /* *************************************************************************
1527 * Win32 Console options:
1528 * *************************************************************************/
1530 /* *************************************************************************
1532 * *************************************************************************/
1534 case hash_hide_console :
1537 #endif /*def _WIN_CONSOLE*/
1540 /* *************************************************************************
1541 * Win32 GUI options:
1542 * *************************************************************************/
1544 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1545 /* *************************************************************************
1546 * activity-animation (0|1)
1547 * *************************************************************************/
1548 case hash_activity_animation :
1549 g_bShowActivityAnimation = atoi(arg);
1552 /* *************************************************************************
1553 * close-button-minimizes (0|1)
1554 * *************************************************************************/
1555 case hash_close_button_minimizes :
1556 g_bCloseHidesWindow = atoi(arg);
1559 /* *************************************************************************
1560 * log-buffer-size (0|1)
1561 * *************************************************************************/
1562 case hash_log_buffer_size :
1563 g_bLimitBufferSize = atoi(arg);
1566 /* *************************************************************************
1567 * log-font-name fontnane
1568 * *************************************************************************/
1569 case hash_log_font_name :
1570 strcpy( g_szFontFaceName, arg );
1573 /* *************************************************************************
1575 * *************************************************************************/
1576 case hash_log_font_size :
1577 g_nFontSize = atoi(arg);
1580 /* *************************************************************************
1581 * log-highlight-messages (0|1)
1582 * *************************************************************************/
1583 case hash_log_highlight_messages :
1584 g_bHighlightMessages = atoi(arg);
1587 /* *************************************************************************
1589 * *************************************************************************/
1590 case hash_log_max_lines :
1591 g_nMaxBufferLines = atoi(arg);
1594 /* *************************************************************************
1595 * log-messages (0|1)
1596 * *************************************************************************/
1597 case hash_log_messages :
1598 g_bLogMessages = atoi(arg);
1601 /* *************************************************************************
1602 * show-on-task-bar (0|1)
1603 * *************************************************************************/
1604 case hash_show_on_task_bar :
1605 g_bShowOnTaskBar = atoi(arg);
1608 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1611 /* *************************************************************************
1612 * Warnings about unsupported features
1613 * *************************************************************************/
1615 case hash_deny_access:
1616 #endif /* ndef FEATURE_ACL */
1617 #ifndef FEATURE_CGI_EDIT_ACTIONS
1618 case hash_enable_edit_actions:
1619 case hash_enable_remote_toggle:
1620 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1621 #ifndef FEATURE_COOKIE_JAR
1623 #endif /* ndef FEATURE_COOKIE_JAR */
1625 case hash_permit_access:
1626 #endif /* ndef FEATURE_ACL */
1627 #ifndef FEATURE_TOGGLE
1629 #endif /* ndef FEATURE_TOGGLE */
1630 #ifndef FEATURE_TRUST
1631 case hash_trustfile :
1632 case hash_trust_info_url :
1633 #endif /* ndef FEATURE_TRUST */
1635 #ifndef _WIN_CONSOLE
1636 case hash_hide_console :
1637 #endif /* ndef _WIN_CONSOLE */
1639 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1640 case hash_activity_animation :
1641 case hash_close_button_minimizes :
1642 case hash_log_buffer_size :
1643 case hash_log_font_name :
1644 case hash_log_font_size :
1645 case hash_log_highlight_messages :
1646 case hash_log_max_lines :
1647 case hash_log_messages :
1648 case hash_show_on_task_bar :
1649 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1650 /* These warnings are annoying - so hide them. -- Jon */
1651 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1654 /* *************************************************************************/
1656 /* *************************************************************************/
1658 * I decided that I liked this better as a warning than an
1659 * error. To change back to an error, just change log level
1660 * to LOG_LEVEL_FATAL.
1662 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1663 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1664 string_append(&config->proxy_args,
1665 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1668 /* *************************************************************************/
1669 } /* end switch( hash_string(cmd) ) */
1670 } /* end while ( read_config_line(...) ) */
1674 set_debug_level(config->debug);
1676 freez(config->logfile);
1680 if (NULL != logfile)
1682 config->logfile = logfile;
1683 init_error_log(Argv[0], config->logfile);
1691 if (NULL == config->proxy_args)
1693 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1696 if (config->actions_file[0])
1698 add_loader(load_action_files, config);
1701 if (config->re_filterfile[0])
1703 add_loader(load_re_filterfiles, config);
1706 #ifdef FEATURE_TRUST
1707 if (config->trustfile)
1709 add_loader(load_trustfile, config);
1711 #endif /* def FEATURE_TRUST */
1713 #ifdef FEATURE_COOKIE_JAR
1714 if ( NULL != config->jarfile )
1716 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1718 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1719 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1721 setbuf(config->jar, NULL);
1723 #endif /* def FEATURE_COOKIE_JAR */
1725 if ( NULL == config->haddr )
1727 config->haddr = strdup( HADDR_DEFAULT );
1730 if ( NULL != config->haddr )
1732 if (NULL != (p = strchr(config->haddr, ':')))
1737 config->hport = atoi(p);
1741 if (config->hport <= 0)
1744 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1745 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1747 if (*config->haddr == '\0')
1750 * Only the port specified. We stored it in config->hport
1751 * and don't need its text representation anymore.
1753 freez(config->haddr);
1758 * Want to run all the loaders once now.
1760 * Need to set up a fake csp, so they can get to the config.
1762 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1763 fake_csp->config = config;
1765 if (run_loader(fake_csp))
1768 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1769 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1773 /* FIXME: this is a kludge for win32 */
1774 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1776 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1777 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1778 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1780 #ifdef FEATURE_TRUST
1781 g_trustfile = config->trustfile;
1782 #endif /* def FEATURE_TRUST */
1785 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1786 /* FIXME: end kludge */
1789 config->need_bind = 1;
1791 if (current_configfile)
1793 struct configuration_spec * oldcfg = (struct configuration_spec *)
1794 current_configfile->f;
1796 * Check if config->haddr,hport == oldcfg->haddr,hport
1798 * The following could be written more compactly as a single,
1799 * (unreadably long) if statement.
1801 config->need_bind = 0;
1802 if (config->hport != oldcfg->hport)
1804 config->need_bind = 1;
1806 else if (config->haddr == NULL)
1808 if (oldcfg->haddr != NULL)
1810 config->need_bind = 1;
1813 else if (oldcfg->haddr == NULL)
1815 config->need_bind = 1;
1817 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1819 config->need_bind = 1;
1822 current_configfile->unloader = unload_configfile;
1825 fs->next = files->next;
1828 current_configfile = fs;
1834 /*********************************************************************
1836 * Function : savearg
1838 * Description : Called from `load_config'. It saves each non-empty
1839 * and non-comment line from config into
1840 * config->proxy_args. This is used to create the
1841 * show-proxy-args page. On error, frees
1842 * config->proxy_args and sets it to NULL
1845 * 1 : command = config setting that was found
1846 * 2 : argument = the setting's argument (if any)
1847 * 3 : config = Configuration to save into.
1851 *********************************************************************/
1852 static void savearg(char *command, char *argument, struct configuration_spec * config)
1861 * Add config option name embedded in
1862 * link to its section in the user-manual
1864 buf = strdup("\n<a href=\"");
1865 if (!strncmpic(config->usermanual, "file://", 7) ||
1866 !strncmpic(config->usermanual, "http", 4))
1868 string_append(&buf, config->usermanual);
1872 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1874 string_append(&buf, CONFIG_HELP_PREFIX);
1875 string_join (&buf, string_toupper(command));
1876 string_append(&buf, "\">");
1877 string_append(&buf, command);
1878 string_append(&buf, "</a> ");
1882 freez(config->proxy_args);
1886 if ( (NULL != argument) && ('\0' != *argument) )
1888 s = html_encode(argument);
1892 freez(config->proxy_args);
1896 if (strncmpic(argument, "http://", 7) == 0)
1898 string_append(&buf, "<a href=\"");
1899 string_append(&buf, s);
1900 string_append(&buf, "\">");
1901 string_join (&buf, s);
1902 string_append(&buf, "</a>");
1906 string_join (&buf, s);
1910 string_append(&buf, "<br>");
1911 string_join(&config->proxy_args, buf);