1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.76 2008/05/10 09:03:16 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.76 2008/05/10 09:03:16 fabiankeil
39 * - Merge three string_append() calls.
40 * - Remove useless assertion.
42 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
43 * Rename load_actions_file() and load_re_filterfile()
44 * as they load multiple files "now".
46 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
47 * Add hostname directive. Closes PR#1918189.
49 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
52 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
53 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
55 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
56 * Reword "unrecognized directive" warning, use better
57 * mark up and add a <br>. Fixes parts of #1856559.
59 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
60 * Plug memory leak if listen-address only specifies the port.
62 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
63 * Relocate daemon-mode-related log messages to make sure
64 * they aren't shown again in case of configuration reloads.
66 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
67 * Plug memory leak introduced with my last commit.
69 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
70 * When in daemon mode, close stderr after the configuration file has been
71 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
73 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
74 * #1763173 from Stefan Huehner: declare unload_configfile() static.
76 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
77 * As Hal noticed, checking dispatch_cgi() as the last cruncher
78 * looks like a bug if CGI requests are blocked unintentionally,
79 * so don't do it unless the user enabled the new config option
80 * "allow-cgi-request-crunching".
82 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
83 * - Use strlcpy() instead of strcpy().
84 * - Stop treating actions files special. Expect a complete file name
85 * (with or without path) like it's done for the rest of the files.
87 * - Remove an unnecessary temporary memory allocation.
88 * - Don't log anything to the console when running as
89 * daemon and no errors occurred.
91 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
92 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
94 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
95 * New config option: enforce-blocks.
97 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
98 * - Mention other reasons why acl directive loading might have failed.
99 * - Don't log the acl source if the acl destination is to blame.
101 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
102 * Add new config option "templdir" to
103 * change the templates directory.
105 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
106 * Added config option accept-intercepted-requests
107 * and disabled it by default.
109 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
110 * Fix gcc43 compiler warnings.
112 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
113 * Add config option "split-large-forms"
114 * to work around the browser bug reported
117 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
118 * Move the <br> in the generated HTML for the config
119 * options from the beginning of the string to its end.
120 * Keeps the white space in balance.
122 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
123 * Fix memory leak in case of config file reloads.
125 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
126 * Modified kludge for win32 to make ming32 menu
127 * "Options/Edit Filters" (sort of) work again.
128 * Same limitations as for the action files apply.
131 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
132 * Incorporate modified version of Roland Rosenfeld's patch to
133 * optionally access the user-manual via Privoxy. Closes patch 679075.
135 * Formatting changed to Privoxy style, added call to
136 * cgi_error_no_template if the requested file doesn't
137 * exist and modified check whether or not Privoxy itself
138 * should serve the manual. Should work cross-platform now.
140 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
141 * Added config option enable-remote-http-toggle
142 * to specify if Privoxy should recognize special
143 * headers (currently only X-Filter) to change its
144 * behaviour. Disabled by default.
146 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
147 * Make number of retries in case of forwarded-connect problems
148 * a config file option (forwarded-connect-retries) and use 0 as
151 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
152 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
153 * with what was really the latest development (the v_3_0_branch branch)
155 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
156 * Don't forget to malloc space for the null terminator...
158 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
159 * Multiple filter file support
161 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
162 * Closed two memory leaks; hopefully the last remaining ones
163 * (in the main execution paths, anyway).
165 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
166 * Addressed bug #719435
167 * - Extraneous filterfile directives now logged as errors
168 * - This and unrecnonised directives now really obvious on status page
170 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
171 * Cosmetic: Renamed cryptic variable
173 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
174 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
176 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
177 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
179 * Revision 1.48 2002/05/14 21:30:38 oes
180 * savearg now uses own linking code instead of (now special-cased) add_help_link
182 * Revision 1.47 2002/05/12 21:36:29 jongfoster
183 * Correcting function comments
185 * Revision 1.46 2002/04/26 12:55:14 oes
186 * - New option "user-manual", defaults to our site
187 * via project.h #define
188 * - savearg now embeds option names in help links
190 * Revision 1.45 2002/04/24 02:11:54 oes
191 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
193 * Revision 1.44 2002/04/08 20:37:13 swa
196 * Revision 1.43 2002/04/08 20:36:50 swa
199 * Revision 1.42 2002/04/05 15:50:15 oes
200 * fix for invalid HTML proxy_args
202 * Revision 1.41 2002/03/31 17:19:00 jongfoster
203 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
205 * Revision 1.40 2002/03/26 22:29:55 swa
206 * we have a new homepage!
208 * Revision 1.39 2002/03/24 13:25:43 swa
209 * name change related issues
211 * Revision 1.38 2002/03/24 13:05:48 jongfoster
212 * Renaming re_filterfile to filterfile
214 * Revision 1.37 2002/03/16 23:54:06 jongfoster
215 * Adding graceful termination feature, to help look for memory leaks.
216 * If you enable this (which, by design, has to be done by hand
217 * editing config.h) and then go to http://i.j.b/die, then the program
218 * will exit cleanly after the *next* request. It should free all the
219 * memory that was used.
221 * Revision 1.36 2002/03/13 00:27:05 jongfoster
224 * Revision 1.35 2002/03/07 03:52:44 oes
225 * Set logging to tty for --no-daemon mode
227 * Revision 1.34 2002/03/06 23:14:35 jongfoster
228 * Trivial cosmetic changes to make function comments easier to find.
230 * Revision 1.33 2002/03/05 04:52:42 oes
231 * Deleted non-errlog debugging code
233 * Revision 1.32 2002/03/04 18:24:53 oes
234 * Re-enabled output of unknown config directive hash
236 * Revision 1.31 2002/03/03 15:07:20 oes
237 * Re-enabled automatic config reloading
239 * Revision 1.30 2002/01/22 23:31:43 jongfoster
240 * Replacing strsav() with string_append()
242 * Revision 1.29 2002/01/17 21:02:30 jongfoster
243 * Moving all our URL and URL pattern parsing code to urlmatch.c.
245 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
247 * Revision 1.28 2001/12/30 14:07:32 steudten
248 * - Add signal handling (unix)
249 * - Add SIGHUP handler (unix)
250 * - Add creation of pidfile (unix)
251 * - Add action 'top' in rc file (RH)
252 * - Add entry 'SIGNALS' to manpage
253 * - Add exit message to logfile (unix)
255 * Revision 1.27 2001/11/07 00:02:13 steudten
256 * Add line number in error output for lineparsing for
257 * actionsfile and configfile.
258 * Special handling for CLF added.
260 * Revision 1.26 2001/11/05 21:41:43 steudten
261 * Add changes to be a real daemon just for unix os.
262 * (change cwd to /, detach from controlling tty, set
263 * process group and session leader to the own process.
265 * Add some fatal-error log message for failed malloc().
266 * Add '-d' if compiled with 'configure --with-debug' to
267 * enable debug output.
269 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
270 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
271 * threads to call select() simultaneously. So, it's time to do a real, live,
272 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
273 * (native). Both versions will work, but using __OS2__ offers multi-threading.
275 * Revision 1.24 2001/10/23 21:40:30 jongfoster
276 * Added support for enable-edit-actions and enable-remote-toggle config
279 * Revision 1.23 2001/10/07 15:36:00 oes
280 * Introduced new config option "buffer-limit"
282 * Revision 1.22 2001/09/22 16:36:59 jongfoster
283 * Removing unused parameter fs from read_config_line()
285 * Revision 1.21 2001/09/16 17:10:43 jongfoster
286 * Moving function savearg() here, since it was the only thing left in
289 * Revision 1.20 2001/07/30 22:08:36 jongfoster
290 * Tidying up #defines:
291 * - All feature #defines are now of the form FEATURE_xxx
292 * - Permanently turned off WIN_GUI_EDIT
293 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
295 * Revision 1.19 2001/07/15 17:45:16 jongfoster
296 * Removing some unused #includes
298 * Revision 1.18 2001/07/13 14:01:14 oes
299 * - Removed all #ifdef PCRS
300 * - Removed vim-settings
302 * Revision 1.17 2001/06/29 13:31:03 oes
303 * - Improved comments
304 * - Fixed (actionsfile) and sorted hashes
305 * - Introduced admin_address and proxy-info-url
306 * as config parameters
307 * - Renamed config->proxy_args_invocation (which didn't have
308 * the invocation but the options!) to config->proxy_args
309 * - Various adaptions
310 * - Removed logentry from cancelled commit
312 * Revision 1.16 2001/06/09 10:55:28 jongfoster
313 * Changing BUFSIZ ==> BUFFER_SIZE
315 * Revision 1.15 2001/06/07 23:13:40 jongfoster
316 * Merging ACL and forward files into config file.
317 * Cosmetic: Sorting config file options alphabetically.
318 * Cosmetic: Adding brief syntax comments to config file options.
320 * Revision 1.14 2001/06/07 14:46:25 joergs
321 * Missing make_path() added for re_filterfile.
323 * Revision 1.13 2001/06/05 22:33:54 jongfoster
325 * Fixed minor memory leak.
326 * Also now uses make_path to prepend the pathnames.
328 * Revision 1.12 2001/06/05 20:04:09 jongfoster
329 * Now uses _snprintf() in place of snprintf() under Win32.
331 * Revision 1.11 2001/06/04 18:31:58 swa
332 * files are now prefixed with either `confdir' or `logdir'.
333 * `make redhat-dist' replaces both entries confdir and logdir
336 * Revision 1.10 2001/06/03 19:11:54 oes
337 * introduced confdir option
339 * Revision 1.9 2001/06/01 20:06:24 jongfoster
340 * Removed support for "tinygif" option - moved to actions file.
342 * Revision 1.8 2001/05/31 21:27:13 jongfoster
343 * Removed many options from the config file and into the
344 * "actions" file: add_forwarded, suppress_vanilla_wafer,
345 * wafer, add_header, user_agent, referer, from
346 * Also globally replaced "permission" with "action".
348 * Revision 1.7 2001/05/29 09:50:24 jongfoster
349 * Unified blocklist/imagelist/permissionslist.
350 * File format is still under discussion, but the internal changes
353 * Also modified interceptor behaviour:
354 * - We now intercept all URLs beginning with one of the following
355 * prefixes (and *only* these prefixes):
357 * * http://ijbswa.sf.net/config/
358 * * http://ijbswa.sourceforge.net/config/
359 * - New interceptors "home page" - go to http://i.j.b/ to see it.
360 * - Internal changes so that intercepted and fast redirect pages
361 * are not replaced with an image.
362 * - Interceptors now have the option to send a binary page direct
363 * to the client. (i.e. ijb-send-banner uses this)
364 * - Implemented show-url-info interceptor. (Which is why I needed
365 * the above interceptors changes - a typical URL is
366 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
367 * The previous mechanism would not have intercepted that, and
368 * if it had been intercepted then it then it would have replaced
371 * Revision 1.6 2001/05/26 00:28:36 jongfoster
372 * Automatic reloading of config file.
373 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
374 * Most of the global variables have been moved to a new
375 * struct configuration_spec, accessed through csp->config->globalname
376 * Most of the globals remaining are used by the Win32 GUI.
378 * Revision 1.5 2001/05/25 22:34:30 jongfoster
381 * Revision 1.4 2001/05/22 18:46:04 oes
383 * - Enabled filtering banners by size rather than URL
384 * by adding patterns that replace all standard banner
385 * sizes with the "Junkbuster" gif to the re_filterfile
387 * - Enabled filtering WebBugs by providing a pattern
388 * which kills all 1x1 images
390 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
391 * which is selected by the (nonstandard and therefore
392 * capital) letter 'U' in the option string.
393 * It causes the quantifiers to be ungreedy by default.
394 * Appending a ? turns back to greedy (!).
396 * - Added a new interceptor ijb-send-banner, which
397 * sends back the "Junkbuster" gif. Without imagelist or
398 * MSIE detection support, or if tinygif = 1, or the
399 * URL isn't recognized as an imageurl, a lame HTML
400 * explanation is sent instead.
402 * - Added new feature, which permits blocking remote
403 * script redirects and firing back a local redirect
405 * The feature is conditionally compiled, i.e. it
406 * can be disabled with --disable-fast-redirects,
407 * plus it must be activated by a "fast-redirects"
408 * line in the config file, has its own log level
409 * and of course wants to be displayed by show-proxy-args
410 * Note: Boy, all the #ifdefs in 1001 locations and
411 * all the fumbling with configure.in and acconfig.h
412 * were *way* more work than the feature itself :-(
414 * - Because a generic redirect template was needed for
415 * this, tinygif = 3 now uses the same.
417 * - Moved GIFs, and other static HTTP response templates
422 * - Removed some >400 CRs again (Jon, you really worked
425 * Revision 1.3 2001/05/20 01:21:20 jongfoster
426 * Version 2.9.4 checkin.
427 * - Merged popupfile and cookiefile, and added control over PCRS
428 * filtering, in new "permissionsfile".
429 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
430 * file error you now get a message box (in the Win32 GUI) rather
431 * than the program exiting with no explanation.
432 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
434 * - Removed tabs from "config"
435 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
436 * - Bumped up version number.
438 * Revision 1.2 2001/05/17 23:01:01 oes
439 * - Cleaned CRLF's from the sources and related files
441 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
442 * Initial import of version 2.9.3 source tree
445 *********************************************************************/
451 #include <sys/types.h>
465 # include <windows.h>
468 # ifndef _WIN_CONSOLE
470 # endif /* ndef _WIN_CONSOLE */
472 #else /* ifndef _WIN32 */
476 # include <sys/wait.h>
478 # include <sys/time.h>
479 # include <sys/stat.h>
489 #include "miscutil.h"
493 #include "urlmatch.h"
496 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
499 * Fix a problem with Solaris. There should be no effect on other
501 * Solaris's isspace() is a macro which uses it's argument directly
502 * as an array index. Therefore we need to make sure that high-bit
503 * characters generate +ve values, and ideally we also want to make
504 * the argument match the declared parameter type of "int".
506 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
507 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
509 #ifdef FEATURE_TOGGLE
510 /* Privoxy is enabled by default. */
511 int global_toggle_state = 1;
512 #endif /* def FEATURE_TOGGLE */
514 /* The filename of the configfile */
515 const char *configfile = NULL;
518 * CGI functions will later need access to the invocation args,
519 * so we will make argc and argv global.
522 const char **Argv = NULL;
524 static struct file_list *current_configfile = NULL;
528 * This takes the "cryptic" hash of each keyword and aliases them to
529 * something a little more readable. This also makes changing the
530 * hash values easier if they should change or the hash algorthm changes.
531 * Use the included "hash" program to find out what the hash will be
532 * for any string supplied on the command line. (Or just put it in the
533 * config file and read the number from the error message in the log).
535 * Please keep this list sorted alphabetically (but with the Windows
536 * console and GUI specific options last).
539 #define hash_actions_file 1196306641ul /* "actionsfile" */
540 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
541 #define hash_admin_address 4112573064ul /* "admin-address" */
542 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
543 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
544 #define hash_confdir 1978389ul /* "confdir" */
545 #define hash_debug 78263ul /* "debug" */
546 #define hash_deny_access 1227333715ul /* "deny-access" */
547 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
548 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
549 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
550 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
551 #define hash_filterfile 250887266ul /* "filterfile" */
552 #define hash_forward 2029845ul /* "forward" */
553 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
554 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
555 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
556 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
557 #define hash_hostname 10308071ul /* "hostname" */
558 #define hash_jarfile 2046641ul /* "jarfile" */
559 #define hash_listen_address 1255650842ul /* "listen-address" */
560 #define hash_logdir 422889ul /* "logdir" */
561 #define hash_logfile 2114766ul /* "logfile" */
562 #define hash_permit_access 3587953268ul /* "permit-access" */
563 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
564 #define hash_single_threaded 4250084780ul /* "single-threaded" */
565 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
566 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
567 #define hash_templdir 11067889ul /* "templdir" */
568 #define hash_toggle 447966ul /* "toggle" */
569 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
570 #define hash_trustfile 56494766ul /* "trustfile" */
571 #define hash_usermanual 1416668518ul /* "user-manual" */
572 #define hash_activity_animation 1817904738ul /* "activity-animation" */
573 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
574 #define hash_hide_console 2048809870ul /* "hide-console" */
575 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
576 #define hash_log_font_name 2866730124ul /* "log-font-name" */
577 #define hash_log_font_size 2866731014ul /* "log-font-size" */
578 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
579 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
580 #define hash_log_messages 2291744899ul /* "log-messages" */
581 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
584 static void savearg(char *command, char *argument, struct configuration_spec * config);
586 /*********************************************************************
588 * Function : unload_configfile
590 * Description : Free the config structure and all components.
593 * 1 : data: struct configuration_spec to unload
597 *********************************************************************/
598 static void unload_configfile (void * data)
600 struct configuration_spec * config = (struct configuration_spec *)data;
601 struct forward_spec *cur_fwd = config->forward;
605 struct access_control_list *cur_acl = config->acl;
607 while (cur_acl != NULL)
609 struct access_control_list * next_acl = cur_acl->next;
614 #endif /* def FEATURE_ACL */
616 while (cur_fwd != NULL)
618 struct forward_spec * next_fwd = cur_fwd->next;
619 free_url_spec(cur_fwd->url);
621 freez(cur_fwd->gateway_host);
622 freez(cur_fwd->forward_host);
626 config->forward = NULL;
628 #ifdef FEATURE_COOKIE_JAR
629 if ( NULL != config->jar )
631 fclose( config->jar );
634 #endif /* def FEATURE_COOKIE_JAR */
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);
657 #ifdef FEATURE_COOKIE_JAR
658 freez(config->jarfile);
659 #endif /* def FEATURE_COOKIE_JAR */
662 freez(config->trustfile);
663 list_remove_all(config->trust_info);
664 #endif /* def FEATURE_TRUST */
666 for (i = 0; i < MAX_AF_FILES; i++)
668 freez(config->re_filterfile[i]);
675 #ifdef FEATURE_GRACEFUL_TERMINATION
676 /*********************************************************************
678 * Function : unload_current_config_file
680 * Description : Unloads current config file - reset to state at
681 * beginning of program.
687 *********************************************************************/
688 void unload_current_config_file(void)
690 if (current_configfile)
692 current_configfile->unloader = unload_configfile;
693 current_configfile = NULL;
699 /*********************************************************************
701 * Function : load_config
703 * Description : Load the config file and all parameters.
705 * XXX: more than thousand lines long
706 * and thus in serious need of refactoring.
710 * Returns : The configuration_spec, or NULL on error.
712 *********************************************************************/
713 struct configuration_spec * load_config(void)
715 char buf[BUFFER_SIZE];
717 FILE *configfp = NULL;
718 struct configuration_spec * config = NULL;
719 struct client_state * fake_csp;
720 struct file_list *fs;
721 unsigned long linenum = 0;
723 char *logfile = NULL;
725 if ( !check_file_changed(current_configfile, configfile, &fs))
727 /* No need to load */
728 return ((struct configuration_spec *)current_configfile->f);
732 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
736 if (NULL != current_configfile)
738 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
741 #ifdef FEATURE_TOGGLE
742 global_toggle_state = 1;
743 #endif /* def FEATURE_TOGGLE */
745 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
751 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
752 /* Never get here - LOG_LEVEL_FATAL causes program exit */
756 * This is backwards from how it's usually done.
757 * Following the usual pattern, "fs" would be stored in a member
758 * variable in "csp", and then we'd access "config" from "fs->f",
759 * using a cast. However, "config" is used so often that a
760 * cast each time would be very ugly, and the extra indirection
761 * would waste CPU cycles. Therefore we store "config" in
762 * "csp->config", and "fs" in "csp->config->config_file_list".
764 config->config_file_list = fs;
769 config->multi_threaded = 1;
770 config->hport = HADDR_PORT;
771 config->buffer_limit = 4096 * 1024;
772 config->usermanual = strdup(USER_MANUAL_URL);
773 config->proxy_args = strdup("");
774 config->forwarded_connect_retries = 0;
775 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
776 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
777 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
779 if ((configfp = fopen(configfile, "r")) == NULL)
781 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
783 /* Never get here - LOG_LEVEL_FATAL causes program exit */
786 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
788 char cmd[BUFFER_SIZE];
789 char arg[BUFFER_SIZE];
790 char tmp[BUFFER_SIZE];
792 struct access_control_list *cur_acl;
793 #endif /* def FEATURE_ACL */
794 struct forward_spec *cur_fwd;
797 unsigned long directive_hash;
799 strlcpy(tmp, buf, sizeof(tmp));
801 /* Copy command (i.e. up to space or tab) into cmd */
804 while (*p && (*p != ' ') && (*p != '\t'))
810 /* Skip over the whitespace in buf */
811 while (*p && ((*p == ' ') || (*p == '\t')))
816 /* Copy the argument into arg */
817 strlcpy(arg, p, sizeof(arg));
819 /* Should never happen, but check this anyway */
825 /* Make sure the command field is lower case */
830 *p = (char)ijb_tolower(*p);
834 /* Save the argument for show-proxy-args */
835 savearg(cmd, arg, config);
837 directive_hash = hash_string(cmd);
838 switch (directive_hash)
840 /* *************************************************************************
841 * actionsfile actions-file-name
842 * In confdir by default
843 * *************************************************************************/
844 case hash_actions_file :
846 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
851 if (i >= MAX_AF_FILES)
853 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
854 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
857 config->actions_file_short[i] = strdup(arg);
858 config->actions_file[i] = make_path(config->confdir, arg);
861 /* *************************************************************************
862 * accept-intercepted-requests
863 * *************************************************************************/
864 case hash_accept_intercepted_requests:
865 if ((*arg != '\0') && (0 != atoi(arg)))
867 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
871 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
875 /* *************************************************************************
876 * admin-address email-address
877 * *************************************************************************/
878 case hash_admin_address :
879 freez(config->admin_address);
880 config->admin_address = strdup(arg);
883 /* *************************************************************************
884 * allow-cgi-request-crunching
885 * *************************************************************************/
886 case hash_allow_cgi_request_crunching:
887 if ((*arg != '\0') && (0 != atoi(arg)))
889 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
893 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
897 /* *************************************************************************
899 * *************************************************************************/
900 case hash_buffer_limit :
901 config->buffer_limit = (size_t)(1024 * atoi(arg));
904 /* *************************************************************************
905 * confdir directory-name
906 * *************************************************************************/
908 freez(config->confdir);
909 config->confdir = make_path( NULL, arg);
912 /* *************************************************************************
914 * Specifies debug level, multiple values are ORed together.
915 * *************************************************************************/
917 config->debug |= atoi(arg);
920 /* *************************************************************************
921 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
922 * *************************************************************************/
924 case hash_deny_access:
925 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
927 if ((vec_count != 1) && (vec_count != 2))
929 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
930 "deny-access directive in configuration file.");
931 string_append(&config->proxy_args,
932 "<br>\nWARNING: Wrong number of parameters for "
933 "deny-access directive in configuration file.<br><br>\n");
937 /* allocate a new node */
938 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
942 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
943 /* Never get here - LOG_LEVEL_FATAL causes program exit */
946 cur_acl->action = ACL_DENY;
948 if (acl_addr(vec[0], cur_acl->src) < 0)
950 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
951 "for deny-access directive in configuration file: \"%s\"", vec[0]);
952 string_append(&config->proxy_args,
953 "<br>\nWARNING: Invalid source address, port or netmask "
954 "for deny-access directive in configuration file: \"");
955 string_append(&config->proxy_args,
957 string_append(&config->proxy_args,
964 if (acl_addr(vec[1], cur_acl->dst) < 0)
966 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
967 "for deny-access directive in configuration file: \"%s\"", vec[1]);
968 string_append(&config->proxy_args,
969 "<br>\nWARNING: Invalid destination address, port or netmask "
970 "for deny-access directive in configuration file: \"");
971 string_append(&config->proxy_args,
973 string_append(&config->proxy_args,
981 * Add it to the list. Note we reverse the list to get the
982 * behaviour the user expects. With both the ACL and
983 * actions file, the last match wins. However, the internal
984 * implementations are different: The actions file is stored
985 * in the same order as the file, and scanned completely.
986 * With the ACL, we reverse the order as we load it, then
987 * when we scan it we stop as soon as we get a match.
989 cur_acl->next = config->acl;
990 config->acl = cur_acl;
993 #endif /* def FEATURE_ACL */
995 /* *************************************************************************
996 * enable-edit-actions 0|1
997 * *************************************************************************/
998 #ifdef FEATURE_CGI_EDIT_ACTIONS
999 case hash_enable_edit_actions:
1000 if ((*arg != '\0') && (0 != atoi(arg)))
1002 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1006 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1009 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1011 /* *************************************************************************
1012 * enable-remote-toggle 0|1
1013 * *************************************************************************/
1014 #ifdef FEATURE_CGI_EDIT_ACTIONS
1015 case hash_enable_remote_toggle:
1016 if ((*arg != '\0') && (0 != atoi(arg)))
1018 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1022 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1025 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1027 /* *************************************************************************
1028 * enable-remote-http-toggle 0|1
1029 * *************************************************************************/
1030 case hash_enable_remote_http_toggle:
1031 if ((*arg != '\0') && (0 != atoi(arg)))
1033 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1037 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1041 /* *************************************************************************
1042 * hash_enforce_blocks 0|1
1043 * *************************************************************************/
1044 #ifdef FEATURE_FORCE_LOAD
1045 case hash_enforce_blocks:
1046 if ((*arg != '\0') && (0 != atoi(arg)))
1048 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1052 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1055 #endif /* def FEATURE_FORCE_LOAD */
1057 /* *************************************************************************
1058 * filterfile file-name
1059 * In confdir by default.
1060 * *************************************************************************/
1061 case hash_filterfile :
1063 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1068 if (i >= MAX_AF_FILES)
1070 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1071 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1074 config->re_filterfile_short[i] = strdup(arg);
1075 config->re_filterfile[i] = make_path(config->confdir, arg);
1079 /* *************************************************************************
1080 * forward url-pattern (.|http-proxy-host[:port])
1081 * *************************************************************************/
1083 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1087 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1088 "directive in configuration file.");
1089 string_append(&config->proxy_args,
1090 "<br>\nWARNING: Wrong number of parameters for "
1091 "forward directive in configuration file.");
1095 /* allocate a new node */
1096 cur_fwd = zalloc(sizeof(*cur_fwd));
1097 if (cur_fwd == NULL)
1099 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1100 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1104 cur_fwd->type = SOCKS_NONE;
1106 /* Save the URL pattern */
1107 if (create_url_spec(cur_fwd->url, vec[0]))
1109 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1110 "directive in configuration file.");
1111 string_append(&config->proxy_args,
1112 "<br>\nWARNING: Bad URL specifier for "
1113 "forward directive in configuration file.");
1117 /* Parse the parent HTTP proxy host:port */
1120 if (strcmp(p, ".") != 0)
1122 cur_fwd->forward_host = strdup(p);
1124 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1127 cur_fwd->forward_port = atoi(p);
1130 if (cur_fwd->forward_port <= 0)
1132 cur_fwd->forward_port = 8000;
1137 cur_fwd->next = config->forward;
1138 config->forward = cur_fwd;
1142 /* *************************************************************************
1143 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1144 * *************************************************************************/
1145 case hash_forward_socks4:
1146 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1150 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1151 "forward-socks4 directive in configuration file.");
1152 string_append(&config->proxy_args,
1153 "<br>\nWARNING: Wrong number of parameters for "
1154 "forward-socks4 directive in configuration file.");
1158 /* allocate a new node */
1159 cur_fwd = zalloc(sizeof(*cur_fwd));
1160 if (cur_fwd == NULL)
1162 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1163 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1167 cur_fwd->type = SOCKS_4;
1169 /* Save the URL pattern */
1170 if (create_url_spec(cur_fwd->url, vec[0]))
1172 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1173 "directive in configuration file.");
1174 string_append(&config->proxy_args,
1175 "<br>\nWARNING: Bad URL specifier for "
1176 "forward-socks4 directive in configuration file.");
1180 /* Parse the SOCKS proxy host[:port] */
1183 if (strcmp(p, ".") != 0)
1185 cur_fwd->gateway_host = strdup(p);
1187 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1190 cur_fwd->gateway_port = atoi(p);
1192 if (cur_fwd->gateway_port <= 0)
1194 cur_fwd->gateway_port = 1080;
1198 /* Parse the parent HTTP proxy host[:port] */
1201 if (strcmp(p, ".") != 0)
1203 cur_fwd->forward_host = strdup(p);
1205 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1208 cur_fwd->forward_port = atoi(p);
1211 if (cur_fwd->forward_port <= 0)
1213 cur_fwd->forward_port = 8000;
1218 cur_fwd->next = config->forward;
1219 config->forward = cur_fwd;
1223 /* *************************************************************************
1224 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1225 * *************************************************************************/
1226 case hash_forward_socks4a:
1227 case hash_forward_socks5:
1228 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1232 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1233 "forward-socks4a directive in configuration file.");
1234 string_append(&config->proxy_args,
1235 "<br>\nWARNING: Wrong number of parameters for "
1236 "forward-socks4a directive in configuration file.");
1240 /* allocate a new node */
1241 cur_fwd = zalloc(sizeof(*cur_fwd));
1242 if (cur_fwd == NULL)
1244 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1245 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1249 if (directive_hash == hash_forward_socks4a)
1251 cur_fwd->type = SOCKS_4A;
1255 cur_fwd->type = SOCKS_5;
1258 /* Save the URL pattern */
1259 if (create_url_spec(cur_fwd->url, vec[0]))
1261 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1262 "directive in configuration file.");
1263 string_append(&config->proxy_args,
1264 "<br>\nWARNING: Bad URL specifier for "
1265 "forward-socks4a directive in configuration file.");
1269 /* Parse the SOCKS proxy host[:port] */
1272 cur_fwd->gateway_host = strdup(p);
1274 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1277 cur_fwd->gateway_port = atoi(p);
1279 if (cur_fwd->gateway_port <= 0)
1281 cur_fwd->gateway_port = 1080;
1284 /* Parse the parent HTTP proxy host[:port] */
1287 if (strcmp(p, ".") != 0)
1289 cur_fwd->forward_host = strdup(p);
1291 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1294 cur_fwd->forward_port = atoi(p);
1297 if (cur_fwd->forward_port <= 0)
1299 cur_fwd->forward_port = 8000;
1304 cur_fwd->next = config->forward;
1305 config->forward = cur_fwd;
1309 /* *************************************************************************
1310 * forwarded-connect-retries n
1311 * *************************************************************************/
1312 case hash_forwarded_connect_retries :
1313 config->forwarded_connect_retries = atoi(arg);
1316 /* *************************************************************************
1317 * hostname hostname-to-show-on-cgi-pages
1318 * *************************************************************************/
1319 case hash_hostname :
1320 freez(config->hostname);
1321 config->hostname = strdup(arg);
1322 if (NULL == config->hostname)
1324 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1328 /* *************************************************************************
1329 * jarfile jar-file-name
1330 * In logdir by default
1331 * *************************************************************************/
1332 #ifdef FEATURE_COOKIE_JAR
1334 freez(config->jarfile);
1335 config->jarfile = make_path(config->logdir, arg);
1337 #endif /* def FEATURE_COOKIE_JAR */
1339 /* *************************************************************************
1340 * listen-address [ip][:port]
1341 * *************************************************************************/
1342 case hash_listen_address :
1343 freez(config->haddr);
1344 config->haddr = strdup(arg);
1347 /* *************************************************************************
1348 * logdir directory-name
1349 * *************************************************************************/
1351 freez(config->logdir);
1352 config->logdir = make_path(NULL, arg);
1355 /* *************************************************************************
1356 * logfile log-file-name
1357 * In logdir by default
1358 * *************************************************************************/
1362 logfile = make_path(config->logdir, arg);
1363 if (NULL == logfile)
1365 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1370 /* *************************************************************************
1371 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1372 * *************************************************************************/
1374 case hash_permit_access:
1375 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1377 if ((vec_count != 1) && (vec_count != 2))
1379 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1380 "permit-access directive in configuration file.");
1381 string_append(&config->proxy_args,
1382 "<br>\nWARNING: Wrong number of parameters for "
1383 "permit-access directive in configuration file.<br><br>\n");
1388 /* allocate a new node */
1389 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1391 if (cur_acl == NULL)
1393 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1394 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1397 cur_acl->action = ACL_PERMIT;
1399 if (acl_addr(vec[0], cur_acl->src) < 0)
1401 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1402 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1403 string_append(&config->proxy_args,
1404 "<br>\nWARNING: Invalid source address, port or netmask for "
1405 "permit-access directive in configuration file: \"");
1406 string_append(&config->proxy_args,
1408 string_append(&config->proxy_args,
1415 if (acl_addr(vec[1], cur_acl->dst) < 0)
1417 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1418 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1419 string_append(&config->proxy_args,
1420 "<br>\nWARNING: Invalid destination address, port or netmask for "
1421 "permit-access directive in configuration file: \"");
1422 string_append(&config->proxy_args,
1424 string_append(&config->proxy_args,
1432 * Add it to the list. Note we reverse the list to get the
1433 * behaviour the user expects. With both the ACL and
1434 * actions file, the last match wins. However, the internal
1435 * implementations are different: The actions file is stored
1436 * in the same order as the file, and scanned completely.
1437 * With the ACL, we reverse the order as we load it, then
1438 * when we scan it we stop as soon as we get a match.
1440 cur_acl->next = config->acl;
1441 config->acl = cur_acl;
1444 #endif /* def FEATURE_ACL */
1446 /* *************************************************************************
1447 * proxy-info-url url
1448 * *************************************************************************/
1449 case hash_proxy_info_url :
1450 freez(config->proxy_info_url);
1451 config->proxy_info_url = strdup(arg);
1454 /* *************************************************************************
1456 * *************************************************************************/
1457 case hash_single_threaded :
1458 config->multi_threaded = 0;
1461 /* *************************************************************************
1462 * split-large-cgi-forms
1463 * *************************************************************************/
1464 case hash_split_large_cgi_forms :
1465 if ((*arg != '\0') && (0 != atoi(arg)))
1467 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1471 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1475 /* *************************************************************************
1476 * templdir directory-name
1477 * *************************************************************************/
1478 case hash_templdir :
1479 freez(config->templdir);
1480 config->templdir = make_path(NULL, arg);
1483 /* *************************************************************************
1485 * *************************************************************************/
1486 #ifdef FEATURE_TOGGLE
1488 global_toggle_state = atoi(arg);
1490 #endif /* def FEATURE_TOGGLE */
1492 /* *************************************************************************
1493 * trust-info-url url
1494 * *************************************************************************/
1495 #ifdef FEATURE_TRUST
1496 case hash_trust_info_url :
1497 enlist(config->trust_info, arg);
1499 #endif /* def FEATURE_TRUST */
1501 /* *************************************************************************
1502 * trustfile filename
1503 * (In confdir by default.)
1504 * *************************************************************************/
1505 #ifdef FEATURE_TRUST
1506 case hash_trustfile :
1507 freez(config->trustfile);
1508 config->trustfile = make_path(config->confdir, arg);
1510 #endif /* def FEATURE_TRUST */
1512 /* *************************************************************************
1514 * *************************************************************************/
1515 case hash_usermanual :
1516 freez(config->usermanual);
1517 config->usermanual = strdup(arg);
1520 /* *************************************************************************
1521 * Win32 Console options:
1522 * *************************************************************************/
1524 /* *************************************************************************
1526 * *************************************************************************/
1528 case hash_hide_console :
1531 #endif /*def _WIN_CONSOLE*/
1534 /* *************************************************************************
1535 * Win32 GUI options:
1536 * *************************************************************************/
1538 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1539 /* *************************************************************************
1540 * activity-animation (0|1)
1541 * *************************************************************************/
1542 case hash_activity_animation :
1543 g_bShowActivityAnimation = atoi(arg);
1546 /* *************************************************************************
1547 * close-button-minimizes (0|1)
1548 * *************************************************************************/
1549 case hash_close_button_minimizes :
1550 g_bCloseHidesWindow = atoi(arg);
1553 /* *************************************************************************
1554 * log-buffer-size (0|1)
1555 * *************************************************************************/
1556 case hash_log_buffer_size :
1557 g_bLimitBufferSize = atoi(arg);
1560 /* *************************************************************************
1561 * log-font-name fontnane
1562 * *************************************************************************/
1563 case hash_log_font_name :
1564 strcpy( g_szFontFaceName, arg );
1567 /* *************************************************************************
1569 * *************************************************************************/
1570 case hash_log_font_size :
1571 g_nFontSize = atoi(arg);
1574 /* *************************************************************************
1575 * log-highlight-messages (0|1)
1576 * *************************************************************************/
1577 case hash_log_highlight_messages :
1578 g_bHighlightMessages = atoi(arg);
1581 /* *************************************************************************
1583 * *************************************************************************/
1584 case hash_log_max_lines :
1585 g_nMaxBufferLines = atoi(arg);
1588 /* *************************************************************************
1589 * log-messages (0|1)
1590 * *************************************************************************/
1591 case hash_log_messages :
1592 g_bLogMessages = atoi(arg);
1595 /* *************************************************************************
1596 * show-on-task-bar (0|1)
1597 * *************************************************************************/
1598 case hash_show_on_task_bar :
1599 g_bShowOnTaskBar = atoi(arg);
1602 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1605 /* *************************************************************************
1606 * Warnings about unsupported features
1607 * *************************************************************************/
1609 case hash_deny_access:
1610 #endif /* ndef FEATURE_ACL */
1611 #ifndef FEATURE_CGI_EDIT_ACTIONS
1612 case hash_enable_edit_actions:
1613 case hash_enable_remote_toggle:
1614 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1615 #ifndef FEATURE_COOKIE_JAR
1617 #endif /* ndef FEATURE_COOKIE_JAR */
1619 case hash_permit_access:
1620 #endif /* ndef FEATURE_ACL */
1621 #ifndef FEATURE_TOGGLE
1623 #endif /* ndef FEATURE_TOGGLE */
1624 #ifndef FEATURE_TRUST
1625 case hash_trustfile :
1626 case hash_trust_info_url :
1627 #endif /* ndef FEATURE_TRUST */
1629 #ifndef _WIN_CONSOLE
1630 case hash_hide_console :
1631 #endif /* ndef _WIN_CONSOLE */
1633 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1634 case hash_activity_animation :
1635 case hash_close_button_minimizes :
1636 case hash_log_buffer_size :
1637 case hash_log_font_name :
1638 case hash_log_font_size :
1639 case hash_log_highlight_messages :
1640 case hash_log_max_lines :
1641 case hash_log_messages :
1642 case hash_show_on_task_bar :
1643 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1644 /* These warnings are annoying - so hide them. -- Jon */
1645 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1648 /* *************************************************************************/
1650 /* *************************************************************************/
1652 * I decided that I liked this better as a warning than an
1653 * error. To change back to an error, just change log level
1654 * to LOG_LEVEL_FATAL.
1656 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1657 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1658 string_append(&config->proxy_args,
1659 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1662 /* *************************************************************************/
1663 } /* end switch( hash_string(cmd) ) */
1664 } /* end while ( read_config_line(...) ) */
1668 set_debug_level(config->debug);
1670 freez(config->logfile);
1674 if (NULL != logfile)
1676 config->logfile = logfile;
1677 init_error_log(Argv[0], config->logfile);
1685 if (NULL == config->proxy_args)
1687 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1690 if (config->actions_file[0])
1692 add_loader(load_action_files, config);
1695 if (config->re_filterfile[0])
1697 add_loader(load_re_filterfiles, config);
1700 #ifdef FEATURE_TRUST
1701 if (config->trustfile)
1703 add_loader(load_trustfile, config);
1705 #endif /* def FEATURE_TRUST */
1707 #ifdef FEATURE_COOKIE_JAR
1708 if ( NULL != config->jarfile )
1710 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1712 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1713 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1715 setbuf(config->jar, NULL);
1717 #endif /* def FEATURE_COOKIE_JAR */
1719 if ( NULL == config->haddr )
1721 config->haddr = strdup( HADDR_DEFAULT );
1724 if ( NULL != config->haddr )
1726 if (NULL != (p = strchr(config->haddr, ':')))
1731 config->hport = atoi(p);
1735 if (config->hport <= 0)
1738 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1739 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1741 if (*config->haddr == '\0')
1744 * Only the port specified. We stored it in config->hport
1745 * and don't need its text representation anymore.
1747 freez(config->haddr);
1752 * Want to run all the loaders once now.
1754 * Need to set up a fake csp, so they can get to the config.
1756 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1757 fake_csp->config = config;
1759 if (run_loader(fake_csp))
1762 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1763 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1767 /* FIXME: this is a kludge for win32 */
1768 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1770 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1771 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1772 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1774 #ifdef FEATURE_TRUST
1775 g_trustfile = config->trustfile;
1776 #endif /* def FEATURE_TRUST */
1779 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1780 /* FIXME: end kludge */
1783 config->need_bind = 1;
1785 if (current_configfile)
1787 struct configuration_spec * oldcfg = (struct configuration_spec *)
1788 current_configfile->f;
1790 * Check if config->haddr,hport == oldcfg->haddr,hport
1792 * The following could be written more compactly as a single,
1793 * (unreadably long) if statement.
1795 config->need_bind = 0;
1796 if (config->hport != oldcfg->hport)
1798 config->need_bind = 1;
1800 else if (config->haddr == NULL)
1802 if (oldcfg->haddr != NULL)
1804 config->need_bind = 1;
1807 else if (oldcfg->haddr == NULL)
1809 config->need_bind = 1;
1811 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1813 config->need_bind = 1;
1816 current_configfile->unloader = unload_configfile;
1819 fs->next = files->next;
1822 current_configfile = fs;
1828 /*********************************************************************
1830 * Function : savearg
1832 * Description : Called from `load_config'. It saves each non-empty
1833 * and non-comment line from config into
1834 * config->proxy_args. This is used to create the
1835 * show-proxy-args page. On error, frees
1836 * config->proxy_args and sets it to NULL
1839 * 1 : command = config setting that was found
1840 * 2 : argument = the setting's argument (if any)
1841 * 3 : config = Configuration to save into.
1845 *********************************************************************/
1846 static void savearg(char *command, char *argument, struct configuration_spec * config)
1855 * Add config option name embedded in
1856 * link to its section in the user-manual
1858 buf = strdup("\n<a href=\"");
1859 if (!strncmpic(config->usermanual, "file://", 7) ||
1860 !strncmpic(config->usermanual, "http", 4))
1862 string_append(&buf, config->usermanual);
1866 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1868 string_append(&buf, CONFIG_HELP_PREFIX);
1869 string_join (&buf, string_toupper(command));
1870 string_append(&buf, "\">");
1871 string_append(&buf, command);
1872 string_append(&buf, "</a> ");
1876 freez(config->proxy_args);
1880 if ( (NULL != argument) && ('\0' != *argument) )
1882 s = html_encode(argument);
1886 freez(config->proxy_args);
1890 if (strncmpic(argument, "http://", 7) == 0)
1892 string_append(&buf, "<a href=\"");
1893 string_append(&buf, s);
1894 string_append(&buf, "\">");
1895 string_join (&buf, s);
1896 string_append(&buf, "</a>");
1900 string_join (&buf, s);
1904 string_append(&buf, "<br>");
1905 string_join(&config->proxy_args, buf);