1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.73 2008/02/16 16:54:51 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.73 2008/02/16 16:54:51 fabiankeil
41 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
42 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
44 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
45 * Reword "unrecognized directive" warning, use better
46 * mark up and add a <br>. Fixes parts of #1856559.
48 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
49 * Plug memory leak if listen-address only specifies the port.
51 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
52 * Relocate daemon-mode-related log messages to make sure
53 * they aren't shown again in case of configuration reloads.
55 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
56 * Plug memory leak introduced with my last commit.
58 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
59 * When in daemon mode, close stderr after the configuration file has been
60 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
62 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
63 * #1763173 from Stefan Huehner: declare unload_configfile() static.
65 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
66 * As Hal noticed, checking dispatch_cgi() as the last cruncher
67 * looks like a bug if CGI requests are blocked unintentionally,
68 * so don't do it unless the user enabled the new config option
69 * "allow-cgi-request-crunching".
71 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
72 * - Use strlcpy() instead of strcpy().
73 * - Stop treating actions files special. Expect a complete file name
74 * (with or without path) like it's done for the rest of the files.
76 * - Remove an unnecessary temporary memory allocation.
77 * - Don't log anything to the console when running as
78 * daemon and no errors occurred.
80 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
81 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
83 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
84 * New config option: enforce-blocks.
86 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
87 * - Mention other reasons why acl directive loading might have failed.
88 * - Don't log the acl source if the acl destination is to blame.
90 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
91 * Add new config option "templdir" to
92 * change the templates directory.
94 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
95 * Added config option accept-intercepted-requests
96 * and disabled it by default.
98 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
99 * Fix gcc43 compiler warnings.
101 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
102 * Add config option "split-large-forms"
103 * to work around the browser bug reported
106 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
107 * Move the <br> in the generated HTML for the config
108 * options from the beginning of the string to its end.
109 * Keeps the white space in balance.
111 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
112 * Fix memory leak in case of config file reloads.
114 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
115 * Modified kludge for win32 to make ming32 menu
116 * "Options/Edit Filters" (sort of) work again.
117 * Same limitations as for the action files apply.
120 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
121 * Incorporate modified version of Roland Rosenfeld's patch to
122 * optionally access the user-manual via Privoxy. Closes patch 679075.
124 * Formatting changed to Privoxy style, added call to
125 * cgi_error_no_template if the requested file doesn't
126 * exist and modified check whether or not Privoxy itself
127 * should serve the manual. Should work cross-platform now.
129 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
130 * Added config option enable-remote-http-toggle
131 * to specify if Privoxy should recognize special
132 * headers (currently only X-Filter) to change its
133 * behaviour. Disabled by default.
135 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
136 * Make number of retries in case of forwarded-connect problems
137 * a config file option (forwarded-connect-retries) and use 0 as
140 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
141 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
142 * with what was really the latest development (the v_3_0_branch branch)
144 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
145 * Don't forget to malloc space for the null terminator...
147 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
148 * Multiple filter file support
150 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
151 * Closed two memory leaks; hopefully the last remaining ones
152 * (in the main execution paths, anyway).
154 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
155 * Addressed bug #719435
156 * - Extraneous filterfile directives now logged as errors
157 * - This and unrecnonised directives now really obvious on status page
159 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
160 * Cosmetic: Renamed cryptic variable
162 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
163 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
165 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
166 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
168 * Revision 1.48 2002/05/14 21:30:38 oes
169 * savearg now uses own linking code instead of (now special-cased) add_help_link
171 * Revision 1.47 2002/05/12 21:36:29 jongfoster
172 * Correcting function comments
174 * Revision 1.46 2002/04/26 12:55:14 oes
175 * - New option "user-manual", defaults to our site
176 * via project.h #define
177 * - savearg now embeds option names in help links
179 * Revision 1.45 2002/04/24 02:11:54 oes
180 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
182 * Revision 1.44 2002/04/08 20:37:13 swa
185 * Revision 1.43 2002/04/08 20:36:50 swa
188 * Revision 1.42 2002/04/05 15:50:15 oes
189 * fix for invalid HTML proxy_args
191 * Revision 1.41 2002/03/31 17:19:00 jongfoster
192 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
194 * Revision 1.40 2002/03/26 22:29:55 swa
195 * we have a new homepage!
197 * Revision 1.39 2002/03/24 13:25:43 swa
198 * name change related issues
200 * Revision 1.38 2002/03/24 13:05:48 jongfoster
201 * Renaming re_filterfile to filterfile
203 * Revision 1.37 2002/03/16 23:54:06 jongfoster
204 * Adding graceful termination feature, to help look for memory leaks.
205 * If you enable this (which, by design, has to be done by hand
206 * editing config.h) and then go to http://i.j.b/die, then the program
207 * will exit cleanly after the *next* request. It should free all the
208 * memory that was used.
210 * Revision 1.36 2002/03/13 00:27:05 jongfoster
213 * Revision 1.35 2002/03/07 03:52:44 oes
214 * Set logging to tty for --no-daemon mode
216 * Revision 1.34 2002/03/06 23:14:35 jongfoster
217 * Trivial cosmetic changes to make function comments easier to find.
219 * Revision 1.33 2002/03/05 04:52:42 oes
220 * Deleted non-errlog debugging code
222 * Revision 1.32 2002/03/04 18:24:53 oes
223 * Re-enabled output of unknown config directive hash
225 * Revision 1.31 2002/03/03 15:07:20 oes
226 * Re-enabled automatic config reloading
228 * Revision 1.30 2002/01/22 23:31:43 jongfoster
229 * Replacing strsav() with string_append()
231 * Revision 1.29 2002/01/17 21:02:30 jongfoster
232 * Moving all our URL and URL pattern parsing code to urlmatch.c.
234 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
236 * Revision 1.28 2001/12/30 14:07:32 steudten
237 * - Add signal handling (unix)
238 * - Add SIGHUP handler (unix)
239 * - Add creation of pidfile (unix)
240 * - Add action 'top' in rc file (RH)
241 * - Add entry 'SIGNALS' to manpage
242 * - Add exit message to logfile (unix)
244 * Revision 1.27 2001/11/07 00:02:13 steudten
245 * Add line number in error output for lineparsing for
246 * actionsfile and configfile.
247 * Special handling for CLF added.
249 * Revision 1.26 2001/11/05 21:41:43 steudten
250 * Add changes to be a real daemon just for unix os.
251 * (change cwd to /, detach from controlling tty, set
252 * process group and session leader to the own process.
254 * Add some fatal-error log message for failed malloc().
255 * Add '-d' if compiled with 'configure --with-debug' to
256 * enable debug output.
258 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
259 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
260 * threads to call select() simultaneously. So, it's time to do a real, live,
261 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
262 * (native). Both versions will work, but using __OS2__ offers multi-threading.
264 * Revision 1.24 2001/10/23 21:40:30 jongfoster
265 * Added support for enable-edit-actions and enable-remote-toggle config
268 * Revision 1.23 2001/10/07 15:36:00 oes
269 * Introduced new config option "buffer-limit"
271 * Revision 1.22 2001/09/22 16:36:59 jongfoster
272 * Removing unused parameter fs from read_config_line()
274 * Revision 1.21 2001/09/16 17:10:43 jongfoster
275 * Moving function savearg() here, since it was the only thing left in
278 * Revision 1.20 2001/07/30 22:08:36 jongfoster
279 * Tidying up #defines:
280 * - All feature #defines are now of the form FEATURE_xxx
281 * - Permanently turned off WIN_GUI_EDIT
282 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
284 * Revision 1.19 2001/07/15 17:45:16 jongfoster
285 * Removing some unused #includes
287 * Revision 1.18 2001/07/13 14:01:14 oes
288 * - Removed all #ifdef PCRS
289 * - Removed vim-settings
291 * Revision 1.17 2001/06/29 13:31:03 oes
292 * - Improved comments
293 * - Fixed (actionsfile) and sorted hashes
294 * - Introduced admin_address and proxy-info-url
295 * as config parameters
296 * - Renamed config->proxy_args_invocation (which didn't have
297 * the invocation but the options!) to config->proxy_args
298 * - Various adaptions
299 * - Removed logentry from cancelled commit
301 * Revision 1.16 2001/06/09 10:55:28 jongfoster
302 * Changing BUFSIZ ==> BUFFER_SIZE
304 * Revision 1.15 2001/06/07 23:13:40 jongfoster
305 * Merging ACL and forward files into config file.
306 * Cosmetic: Sorting config file options alphabetically.
307 * Cosmetic: Adding brief syntax comments to config file options.
309 * Revision 1.14 2001/06/07 14:46:25 joergs
310 * Missing make_path() added for re_filterfile.
312 * Revision 1.13 2001/06/05 22:33:54 jongfoster
314 * Fixed minor memory leak.
315 * Also now uses make_path to prepend the pathnames.
317 * Revision 1.12 2001/06/05 20:04:09 jongfoster
318 * Now uses _snprintf() in place of snprintf() under Win32.
320 * Revision 1.11 2001/06/04 18:31:58 swa
321 * files are now prefixed with either `confdir' or `logdir'.
322 * `make redhat-dist' replaces both entries confdir and logdir
325 * Revision 1.10 2001/06/03 19:11:54 oes
326 * introduced confdir option
328 * Revision 1.9 2001/06/01 20:06:24 jongfoster
329 * Removed support for "tinygif" option - moved to actions file.
331 * Revision 1.8 2001/05/31 21:27:13 jongfoster
332 * Removed many options from the config file and into the
333 * "actions" file: add_forwarded, suppress_vanilla_wafer,
334 * wafer, add_header, user_agent, referer, from
335 * Also globally replaced "permission" with "action".
337 * Revision 1.7 2001/05/29 09:50:24 jongfoster
338 * Unified blocklist/imagelist/permissionslist.
339 * File format is still under discussion, but the internal changes
342 * Also modified interceptor behaviour:
343 * - We now intercept all URLs beginning with one of the following
344 * prefixes (and *only* these prefixes):
346 * * http://ijbswa.sf.net/config/
347 * * http://ijbswa.sourceforge.net/config/
348 * - New interceptors "home page" - go to http://i.j.b/ to see it.
349 * - Internal changes so that intercepted and fast redirect pages
350 * are not replaced with an image.
351 * - Interceptors now have the option to send a binary page direct
352 * to the client. (i.e. ijb-send-banner uses this)
353 * - Implemented show-url-info interceptor. (Which is why I needed
354 * the above interceptors changes - a typical URL is
355 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
356 * The previous mechanism would not have intercepted that, and
357 * if it had been intercepted then it then it would have replaced
360 * Revision 1.6 2001/05/26 00:28:36 jongfoster
361 * Automatic reloading of config file.
362 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
363 * Most of the global variables have been moved to a new
364 * struct configuration_spec, accessed through csp->config->globalname
365 * Most of the globals remaining are used by the Win32 GUI.
367 * Revision 1.5 2001/05/25 22:34:30 jongfoster
370 * Revision 1.4 2001/05/22 18:46:04 oes
372 * - Enabled filtering banners by size rather than URL
373 * by adding patterns that replace all standard banner
374 * sizes with the "Junkbuster" gif to the re_filterfile
376 * - Enabled filtering WebBugs by providing a pattern
377 * which kills all 1x1 images
379 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
380 * which is selected by the (nonstandard and therefore
381 * capital) letter 'U' in the option string.
382 * It causes the quantifiers to be ungreedy by default.
383 * Appending a ? turns back to greedy (!).
385 * - Added a new interceptor ijb-send-banner, which
386 * sends back the "Junkbuster" gif. Without imagelist or
387 * MSIE detection support, or if tinygif = 1, or the
388 * URL isn't recognized as an imageurl, a lame HTML
389 * explanation is sent instead.
391 * - Added new feature, which permits blocking remote
392 * script redirects and firing back a local redirect
394 * The feature is conditionally compiled, i.e. it
395 * can be disabled with --disable-fast-redirects,
396 * plus it must be activated by a "fast-redirects"
397 * line in the config file, has its own log level
398 * and of course wants to be displayed by show-proxy-args
399 * Note: Boy, all the #ifdefs in 1001 locations and
400 * all the fumbling with configure.in and acconfig.h
401 * were *way* more work than the feature itself :-(
403 * - Because a generic redirect template was needed for
404 * this, tinygif = 3 now uses the same.
406 * - Moved GIFs, and other static HTTP response templates
411 * - Removed some >400 CRs again (Jon, you really worked
414 * Revision 1.3 2001/05/20 01:21:20 jongfoster
415 * Version 2.9.4 checkin.
416 * - Merged popupfile and cookiefile, and added control over PCRS
417 * filtering, in new "permissionsfile".
418 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
419 * file error you now get a message box (in the Win32 GUI) rather
420 * than the program exiting with no explanation.
421 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
423 * - Removed tabs from "config"
424 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
425 * - Bumped up version number.
427 * Revision 1.2 2001/05/17 23:01:01 oes
428 * - Cleaned CRLF's from the sources and related files
430 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
431 * Initial import of version 2.9.3 source tree
434 *********************************************************************/
440 #include <sys/types.h>
454 # include <windows.h>
457 # ifndef _WIN_CONSOLE
459 # endif /* ndef _WIN_CONSOLE */
461 #else /* ifndef _WIN32 */
465 # include <sys/wait.h>
467 # include <sys/time.h>
468 # include <sys/stat.h>
478 #include "miscutil.h"
482 #include "urlmatch.h"
485 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
488 * Fix a problem with Solaris. There should be no effect on other
490 * Solaris's isspace() is a macro which uses it's argument directly
491 * as an array index. Therefore we need to make sure that high-bit
492 * characters generate +ve values, and ideally we also want to make
493 * the argument match the declared parameter type of "int".
495 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
496 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
498 #ifdef FEATURE_TOGGLE
499 /* Privoxy is enabled by default. */
500 int global_toggle_state = 1;
501 #endif /* def FEATURE_TOGGLE */
503 /* The filename of the configfile */
504 const char *configfile = NULL;
507 * CGI functions will later need access to the invocation args,
508 * so we will make argc and argv global.
511 const char **Argv = NULL;
513 static struct file_list *current_configfile = NULL;
517 * This takes the "cryptic" hash of each keyword and aliases them to
518 * something a little more readable. This also makes changing the
519 * hash values easier if they should change or the hash algorthm changes.
520 * Use the included "hash" program to find out what the hash will be
521 * for any string supplied on the command line. (Or just put it in the
522 * config file and read the number from the error message in the log).
524 * Please keep this list sorted alphabetically (but with the Windows
525 * console and GUI specific options last).
528 #define hash_actions_file 1196306641ul /* "actionsfile" */
529 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
530 #define hash_admin_address 4112573064ul /* "admin-address" */
531 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
532 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
533 #define hash_confdir 1978389ul /* "confdir" */
534 #define hash_debug 78263ul /* "debug" */
535 #define hash_deny_access 1227333715ul /* "deny-access" */
536 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
537 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
538 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
539 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
540 #define hash_filterfile 250887266ul /* "filterfile" */
541 #define hash_forward 2029845ul /* "forward" */
542 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
543 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
544 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
545 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
546 #define hash_hostname 10308071ul /* "hostname" */
547 #define hash_jarfile 2046641ul /* "jarfile" */
548 #define hash_listen_address 1255650842ul /* "listen-address" */
549 #define hash_logdir 422889ul /* "logdir" */
550 #define hash_logfile 2114766ul /* "logfile" */
551 #define hash_permit_access 3587953268ul /* "permit-access" */
552 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
553 #define hash_single_threaded 4250084780ul /* "single-threaded" */
554 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
555 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
556 #define hash_templdir 11067889ul /* "templdir" */
557 #define hash_toggle 447966ul /* "toggle" */
558 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
559 #define hash_trustfile 56494766ul /* "trustfile" */
560 #define hash_usermanual 1416668518ul /* "user-manual" */
561 #define hash_activity_animation 1817904738ul /* "activity-animation" */
562 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
563 #define hash_hide_console 2048809870ul /* "hide-console" */
564 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
565 #define hash_log_font_name 2866730124ul /* "log-font-name" */
566 #define hash_log_font_size 2866731014ul /* "log-font-size" */
567 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
568 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
569 #define hash_log_messages 2291744899ul /* "log-messages" */
570 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
573 static void savearg(char *command, char *argument, struct configuration_spec * config);
575 /*********************************************************************
577 * Function : unload_configfile
579 * Description : Free the config structure and all components.
582 * 1 : data: struct configuration_spec to unload
586 *********************************************************************/
587 static void unload_configfile (void * data)
589 struct configuration_spec * config = (struct configuration_spec *)data;
590 struct forward_spec *cur_fwd = config->forward;
594 struct access_control_list *cur_acl = config->acl;
596 while (cur_acl != NULL)
598 struct access_control_list * next_acl = cur_acl->next;
603 #endif /* def FEATURE_ACL */
605 while (cur_fwd != NULL)
607 struct forward_spec * next_fwd = cur_fwd->next;
608 free_url_spec(cur_fwd->url);
610 freez(cur_fwd->gateway_host);
611 freez(cur_fwd->forward_host);
615 config->forward = NULL;
617 #ifdef FEATURE_COOKIE_JAR
618 if ( NULL != config->jar )
620 fclose( config->jar );
623 #endif /* def FEATURE_COOKIE_JAR */
625 freez(config->confdir);
626 freez(config->logdir);
627 freez(config->templdir);
628 freez(config->hostname);
630 freez(config->haddr);
631 freez(config->logfile);
633 for (i = 0; i < MAX_AF_FILES; i++)
635 freez(config->actions_file_short[i]);
636 freez(config->actions_file[i]);
637 freez(config->re_filterfile_short[i]);
638 freez(config->re_filterfile[i]);
641 freez(config->admin_address);
642 freez(config->proxy_info_url);
643 freez(config->proxy_args);
644 freez(config->usermanual);
646 #ifdef FEATURE_COOKIE_JAR
647 freez(config->jarfile);
648 #endif /* def FEATURE_COOKIE_JAR */
651 freez(config->trustfile);
652 list_remove_all(config->trust_info);
653 #endif /* def FEATURE_TRUST */
655 for (i = 0; i < MAX_AF_FILES; i++)
657 freez(config->re_filterfile[i]);
664 #ifdef FEATURE_GRACEFUL_TERMINATION
665 /*********************************************************************
667 * Function : unload_current_config_file
669 * Description : Unloads current config file - reset to state at
670 * beginning of program.
676 *********************************************************************/
677 void unload_current_config_file(void)
679 if (current_configfile)
681 current_configfile->unloader = unload_configfile;
682 current_configfile = NULL;
688 /*********************************************************************
690 * Function : load_config
692 * Description : Load the config file and all parameters.
694 * XXX: more than thousand lines long
695 * and thus in serious need of refactoring.
699 * Returns : The configuration_spec, or NULL on error.
701 *********************************************************************/
702 struct configuration_spec * load_config(void)
704 char buf[BUFFER_SIZE];
706 FILE *configfp = NULL;
707 struct configuration_spec * config = NULL;
708 struct client_state * fake_csp;
709 struct file_list *fs;
710 unsigned long linenum = 0;
712 char *logfile = NULL;
714 if ( !check_file_changed(current_configfile, configfile, &fs))
716 /* No need to load */
717 return ((struct configuration_spec *)current_configfile->f);
721 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
725 if (NULL != current_configfile)
727 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
730 #ifdef FEATURE_TOGGLE
731 global_toggle_state = 1;
732 #endif /* def FEATURE_TOGGLE */
734 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
740 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
741 /* Never get here - LOG_LEVEL_FATAL causes program exit */
745 * This is backwards from how it's usually done.
746 * Following the usual pattern, "fs" would be stored in a member
747 * variable in "csp", and then we'd access "config" from "fs->f",
748 * using a cast. However, "config" is used so often that a
749 * cast each time would be very ugly, and the extra indirection
750 * would waste CPU cycles. Therefore we store "config" in
751 * "csp->config", and "fs" in "csp->config->config_file_list".
753 config->config_file_list = fs;
758 config->multi_threaded = 1;
759 config->hport = HADDR_PORT;
760 config->buffer_limit = 4096 * 1024;
761 config->usermanual = strdup(USER_MANUAL_URL);
762 config->proxy_args = strdup("");
763 config->forwarded_connect_retries = 0;
764 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
765 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
766 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
768 if ((configfp = fopen(configfile, "r")) == NULL)
770 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
772 /* Never get here - LOG_LEVEL_FATAL causes program exit */
775 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
777 char cmd[BUFFER_SIZE];
778 char arg[BUFFER_SIZE];
779 char tmp[BUFFER_SIZE];
781 struct access_control_list *cur_acl;
782 #endif /* def FEATURE_ACL */
783 struct forward_spec *cur_fwd;
786 unsigned long directive_hash;
788 strlcpy(tmp, buf, sizeof(tmp));
790 /* Copy command (i.e. up to space or tab) into cmd */
793 while (*p && (*p != ' ') && (*p != '\t'))
799 /* Skip over the whitespace in buf */
800 while (*p && ((*p == ' ') || (*p == '\t')))
805 /* Copy the argument into arg */
806 strlcpy(arg, p, sizeof(arg));
808 /* Should never happen, but check this anyway */
814 /* Make sure the command field is lower case */
819 *p = (char)ijb_tolower(*p);
823 /* Save the argument for show-proxy-args */
824 savearg(cmd, arg, config);
826 directive_hash = hash_string(cmd);
827 switch (directive_hash)
829 /* *************************************************************************
830 * actionsfile actions-file-name
831 * In confdir by default
832 * *************************************************************************/
833 case hash_actions_file :
835 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
840 if (i >= MAX_AF_FILES)
842 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
843 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
846 config->actions_file_short[i] = strdup(arg);
847 config->actions_file[i] = make_path(config->confdir, arg);
850 /* *************************************************************************
851 * accept-intercepted-requests
852 * *************************************************************************/
853 case hash_accept_intercepted_requests:
854 if ((*arg != '\0') && (0 != atoi(arg)))
856 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
860 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
864 /* *************************************************************************
865 * admin-address email-address
866 * *************************************************************************/
867 case hash_admin_address :
868 freez(config->admin_address);
869 config->admin_address = strdup(arg);
872 /* *************************************************************************
873 * allow-cgi-request-crunching
874 * *************************************************************************/
875 case hash_allow_cgi_request_crunching:
876 if ((*arg != '\0') && (0 != atoi(arg)))
878 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
882 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
886 /* *************************************************************************
888 * *************************************************************************/
889 case hash_buffer_limit :
890 config->buffer_limit = (size_t)(1024 * atoi(arg));
893 /* *************************************************************************
894 * confdir directory-name
895 * *************************************************************************/
897 freez(config->confdir);
898 config->confdir = make_path( NULL, arg);
901 /* *************************************************************************
903 * Specifies debug level, multiple values are ORed together.
904 * *************************************************************************/
906 config->debug |= atoi(arg);
909 /* *************************************************************************
910 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
911 * *************************************************************************/
913 case hash_deny_access:
914 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
916 if ((vec_count != 1) && (vec_count != 2))
918 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
919 "deny-access directive in configuration file.");
920 string_append(&config->proxy_args,
921 "<br>\nWARNING: Wrong number of parameters for "
922 "deny-access directive in configuration file.<br><br>\n");
926 /* allocate a new node */
927 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
931 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
932 /* Never get here - LOG_LEVEL_FATAL causes program exit */
935 cur_acl->action = ACL_DENY;
937 if (acl_addr(vec[0], cur_acl->src) < 0)
939 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
940 "for deny-access directive in configuration file: \"%s\"", vec[0]);
941 string_append(&config->proxy_args,
942 "<br>\nWARNING: Invalid source address, port or netmask "
943 "for deny-access directive in configuration file: \"");
944 string_append(&config->proxy_args,
946 string_append(&config->proxy_args,
953 if (acl_addr(vec[1], cur_acl->dst) < 0)
955 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
956 "for deny-access directive in configuration file: \"%s\"", vec[1]);
957 string_append(&config->proxy_args,
958 "<br>\nWARNING: Invalid destination address, port or netmask "
959 "for deny-access directive in configuration file: \"");
960 string_append(&config->proxy_args,
962 string_append(&config->proxy_args,
970 * Add it to the list. Note we reverse the list to get the
971 * behaviour the user expects. With both the ACL and
972 * actions file, the last match wins. However, the internal
973 * implementations are different: The actions file is stored
974 * in the same order as the file, and scanned completely.
975 * With the ACL, we reverse the order as we load it, then
976 * when we scan it we stop as soon as we get a match.
978 cur_acl->next = config->acl;
979 config->acl = cur_acl;
982 #endif /* def FEATURE_ACL */
984 /* *************************************************************************
985 * enable-edit-actions 0|1
986 * *************************************************************************/
987 #ifdef FEATURE_CGI_EDIT_ACTIONS
988 case hash_enable_edit_actions:
989 if ((*arg != '\0') && (0 != atoi(arg)))
991 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
995 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
998 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1000 /* *************************************************************************
1001 * enable-remote-toggle 0|1
1002 * *************************************************************************/
1003 #ifdef FEATURE_CGI_EDIT_ACTIONS
1004 case hash_enable_remote_toggle:
1005 if ((*arg != '\0') && (0 != atoi(arg)))
1007 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1011 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1014 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1016 /* *************************************************************************
1017 * enable-remote-http-toggle 0|1
1018 * *************************************************************************/
1019 case hash_enable_remote_http_toggle:
1020 if ((*arg != '\0') && (0 != atoi(arg)))
1022 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1026 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1030 /* *************************************************************************
1031 * hash_enforce_blocks 0|1
1032 * *************************************************************************/
1033 #ifdef FEATURE_FORCE_LOAD
1034 case hash_enforce_blocks:
1035 if ((*arg != '\0') && (0 != atoi(arg)))
1037 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1041 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1044 #endif /* def FEATURE_FORCE_LOAD */
1046 /* *************************************************************************
1047 * filterfile file-name
1048 * In confdir by default.
1049 * *************************************************************************/
1050 case hash_filterfile :
1052 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1057 if (i >= MAX_AF_FILES)
1059 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1060 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1063 config->re_filterfile_short[i] = strdup(arg);
1064 config->re_filterfile[i] = make_path(config->confdir, arg);
1068 /* *************************************************************************
1069 * forward url-pattern (.|http-proxy-host[:port])
1070 * *************************************************************************/
1072 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1076 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1077 "directive in configuration file.");
1078 string_append(&config->proxy_args,
1079 "<br>\nWARNING: Wrong number of parameters for "
1080 "forward directive in configuration file.");
1084 /* allocate a new node */
1085 cur_fwd = zalloc(sizeof(*cur_fwd));
1086 if (cur_fwd == NULL)
1088 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1089 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1093 cur_fwd->type = SOCKS_NONE;
1095 /* Save the URL pattern */
1096 if (create_url_spec(cur_fwd->url, vec[0]))
1098 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1099 "directive in configuration file.");
1100 string_append(&config->proxy_args,
1101 "<br>\nWARNING: Bad URL specifier for "
1102 "forward directive in configuration file.");
1106 /* Parse the parent HTTP proxy host:port */
1109 if (strcmp(p, ".") != 0)
1111 cur_fwd->forward_host = strdup(p);
1113 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1116 cur_fwd->forward_port = atoi(p);
1119 if (cur_fwd->forward_port <= 0)
1121 cur_fwd->forward_port = 8000;
1126 cur_fwd->next = config->forward;
1127 config->forward = cur_fwd;
1131 /* *************************************************************************
1132 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1133 * *************************************************************************/
1134 case hash_forward_socks4:
1135 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1139 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1140 "forward-socks4 directive in configuration file.");
1141 string_append(&config->proxy_args,
1142 "<br>\nWARNING: Wrong number of parameters for "
1143 "forward-socks4 directive in configuration file.");
1147 /* allocate a new node */
1148 cur_fwd = zalloc(sizeof(*cur_fwd));
1149 if (cur_fwd == NULL)
1151 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1152 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1156 cur_fwd->type = SOCKS_4;
1158 /* Save the URL pattern */
1159 if (create_url_spec(cur_fwd->url, vec[0]))
1161 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1162 "directive in configuration file.");
1163 string_append(&config->proxy_args,
1164 "<br>\nWARNING: Bad URL specifier for "
1165 "forward-socks4 directive in configuration file.");
1169 /* Parse the SOCKS proxy host[:port] */
1172 if (strcmp(p, ".") != 0)
1174 cur_fwd->gateway_host = strdup(p);
1176 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1179 cur_fwd->gateway_port = atoi(p);
1181 if (cur_fwd->gateway_port <= 0)
1183 cur_fwd->gateway_port = 1080;
1187 /* Parse the parent HTTP proxy host[:port] */
1190 if (strcmp(p, ".") != 0)
1192 cur_fwd->forward_host = strdup(p);
1194 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1197 cur_fwd->forward_port = atoi(p);
1200 if (cur_fwd->forward_port <= 0)
1202 cur_fwd->forward_port = 8000;
1207 cur_fwd->next = config->forward;
1208 config->forward = cur_fwd;
1212 /* *************************************************************************
1213 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1214 * *************************************************************************/
1215 case hash_forward_socks4a:
1216 case hash_forward_socks5:
1217 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1221 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1222 "forward-socks4a directive in configuration file.");
1223 string_append(&config->proxy_args,
1224 "<br>\nWARNING: Wrong number of parameters for "
1225 "forward-socks4a directive in configuration file.");
1229 /* allocate a new node */
1230 cur_fwd = zalloc(sizeof(*cur_fwd));
1231 if (cur_fwd == NULL)
1233 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1234 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1238 if (directive_hash == hash_forward_socks4a)
1240 cur_fwd->type = SOCKS_4A;
1244 cur_fwd->type = SOCKS_5;
1247 /* Save the URL pattern */
1248 if (create_url_spec(cur_fwd->url, vec[0]))
1250 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1251 "directive in configuration file.");
1252 string_append(&config->proxy_args,
1253 "<br>\nWARNING: Bad URL specifier for "
1254 "forward-socks4a directive in configuration file.");
1258 /* Parse the SOCKS proxy host[:port] */
1261 cur_fwd->gateway_host = strdup(p);
1263 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1266 cur_fwd->gateway_port = atoi(p);
1268 if (cur_fwd->gateway_port <= 0)
1270 cur_fwd->gateway_port = 1080;
1273 /* Parse the parent HTTP proxy host[:port] */
1276 if (strcmp(p, ".") != 0)
1278 cur_fwd->forward_host = strdup(p);
1280 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1283 cur_fwd->forward_port = atoi(p);
1286 if (cur_fwd->forward_port <= 0)
1288 cur_fwd->forward_port = 8000;
1293 cur_fwd->next = config->forward;
1294 config->forward = cur_fwd;
1298 /* *************************************************************************
1299 * forwarded-connect-retries n
1300 * *************************************************************************/
1301 case hash_forwarded_connect_retries :
1302 config->forwarded_connect_retries = atoi(arg);
1305 /* *************************************************************************
1306 * hostname hostname-to-show-on-cgi-pages
1307 * *************************************************************************/
1308 case hash_hostname :
1309 freez(config->hostname);
1310 config->hostname = strdup(arg);
1311 if (NULL == config->hostname)
1313 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1317 /* *************************************************************************
1318 * jarfile jar-file-name
1319 * In logdir by default
1320 * *************************************************************************/
1321 #ifdef FEATURE_COOKIE_JAR
1323 freez(config->jarfile);
1324 config->jarfile = make_path(config->logdir, arg);
1326 #endif /* def FEATURE_COOKIE_JAR */
1328 /* *************************************************************************
1329 * listen-address [ip][:port]
1330 * *************************************************************************/
1331 case hash_listen_address :
1332 freez(config->haddr);
1333 config->haddr = strdup(arg);
1336 /* *************************************************************************
1337 * logdir directory-name
1338 * *************************************************************************/
1340 freez(config->logdir);
1341 config->logdir = make_path(NULL, arg);
1344 /* *************************************************************************
1345 * logfile log-file-name
1346 * In logdir by default
1347 * *************************************************************************/
1351 logfile = make_path(config->logdir, arg);
1352 if (NULL == logfile)
1354 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1359 /* *************************************************************************
1360 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1361 * *************************************************************************/
1363 case hash_permit_access:
1364 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1366 if ((vec_count != 1) && (vec_count != 2))
1368 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1369 "permit-access directive in configuration file.");
1370 string_append(&config->proxy_args,
1371 "<br>\nWARNING: Wrong number of parameters for "
1372 "permit-access directive in configuration file.<br><br>\n");
1377 /* allocate a new node */
1378 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1380 if (cur_acl == NULL)
1382 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1383 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1386 cur_acl->action = ACL_PERMIT;
1388 if (acl_addr(vec[0], cur_acl->src) < 0)
1390 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1391 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1392 string_append(&config->proxy_args,
1393 "<br>\nWARNING: Invalid source address, port or netmask for "
1394 "permit-access directive in configuration file: \"");
1395 string_append(&config->proxy_args,
1397 string_append(&config->proxy_args,
1404 if (acl_addr(vec[1], cur_acl->dst) < 0)
1406 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1407 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1408 string_append(&config->proxy_args,
1409 "<br>\nWARNING: Invalid destination address, port or netmask for "
1410 "permit-access directive in configuration file: \"");
1411 string_append(&config->proxy_args,
1413 string_append(&config->proxy_args,
1421 * Add it to the list. Note we reverse the list to get the
1422 * behaviour the user expects. With both the ACL and
1423 * actions file, the last match wins. However, the internal
1424 * implementations are different: The actions file is stored
1425 * in the same order as the file, and scanned completely.
1426 * With the ACL, we reverse the order as we load it, then
1427 * when we scan it we stop as soon as we get a match.
1429 cur_acl->next = config->acl;
1430 config->acl = cur_acl;
1433 #endif /* def FEATURE_ACL */
1435 /* *************************************************************************
1436 * proxy-info-url url
1437 * *************************************************************************/
1438 case hash_proxy_info_url :
1439 freez(config->proxy_info_url);
1440 config->proxy_info_url = strdup(arg);
1443 /* *************************************************************************
1445 * *************************************************************************/
1446 case hash_single_threaded :
1447 config->multi_threaded = 0;
1450 /* *************************************************************************
1451 * split-large-cgi-forms
1452 * *************************************************************************/
1453 case hash_split_large_cgi_forms :
1454 if ((*arg != '\0') && (0 != atoi(arg)))
1456 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1460 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1464 /* *************************************************************************
1465 * templdir directory-name
1466 * *************************************************************************/
1467 case hash_templdir :
1468 freez(config->templdir);
1469 config->templdir = make_path(NULL, arg);
1472 /* *************************************************************************
1474 * *************************************************************************/
1475 #ifdef FEATURE_TOGGLE
1477 global_toggle_state = atoi(arg);
1479 #endif /* def FEATURE_TOGGLE */
1481 /* *************************************************************************
1482 * trust-info-url url
1483 * *************************************************************************/
1484 #ifdef FEATURE_TRUST
1485 case hash_trust_info_url :
1486 enlist(config->trust_info, arg);
1488 #endif /* def FEATURE_TRUST */
1490 /* *************************************************************************
1491 * trustfile filename
1492 * (In confdir by default.)
1493 * *************************************************************************/
1494 #ifdef FEATURE_TRUST
1495 case hash_trustfile :
1496 freez(config->trustfile);
1497 config->trustfile = make_path(config->confdir, arg);
1499 #endif /* def FEATURE_TRUST */
1501 /* *************************************************************************
1503 * *************************************************************************/
1504 case hash_usermanual :
1505 freez(config->usermanual);
1506 config->usermanual = strdup(arg);
1509 /* *************************************************************************
1510 * Win32 Console options:
1511 * *************************************************************************/
1513 /* *************************************************************************
1515 * *************************************************************************/
1517 case hash_hide_console :
1520 #endif /*def _WIN_CONSOLE*/
1523 /* *************************************************************************
1524 * Win32 GUI options:
1525 * *************************************************************************/
1527 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1528 /* *************************************************************************
1529 * activity-animation (0|1)
1530 * *************************************************************************/
1531 case hash_activity_animation :
1532 g_bShowActivityAnimation = atoi(arg);
1535 /* *************************************************************************
1536 * close-button-minimizes (0|1)
1537 * *************************************************************************/
1538 case hash_close_button_minimizes :
1539 g_bCloseHidesWindow = atoi(arg);
1542 /* *************************************************************************
1543 * log-buffer-size (0|1)
1544 * *************************************************************************/
1545 case hash_log_buffer_size :
1546 g_bLimitBufferSize = atoi(arg);
1549 /* *************************************************************************
1550 * log-font-name fontnane
1551 * *************************************************************************/
1552 case hash_log_font_name :
1553 strcpy( g_szFontFaceName, arg );
1556 /* *************************************************************************
1558 * *************************************************************************/
1559 case hash_log_font_size :
1560 g_nFontSize = atoi(arg);
1563 /* *************************************************************************
1564 * log-highlight-messages (0|1)
1565 * *************************************************************************/
1566 case hash_log_highlight_messages :
1567 g_bHighlightMessages = atoi(arg);
1570 /* *************************************************************************
1572 * *************************************************************************/
1573 case hash_log_max_lines :
1574 g_nMaxBufferLines = atoi(arg);
1577 /* *************************************************************************
1578 * log-messages (0|1)
1579 * *************************************************************************/
1580 case hash_log_messages :
1581 g_bLogMessages = atoi(arg);
1584 /* *************************************************************************
1585 * show-on-task-bar (0|1)
1586 * *************************************************************************/
1587 case hash_show_on_task_bar :
1588 g_bShowOnTaskBar = atoi(arg);
1591 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1594 /* *************************************************************************
1595 * Warnings about unsupported features
1596 * *************************************************************************/
1598 case hash_deny_access:
1599 #endif /* ndef FEATURE_ACL */
1600 #ifndef FEATURE_CGI_EDIT_ACTIONS
1601 case hash_enable_edit_actions:
1602 case hash_enable_remote_toggle:
1603 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1604 #ifndef FEATURE_COOKIE_JAR
1606 #endif /* ndef FEATURE_COOKIE_JAR */
1608 case hash_permit_access:
1609 #endif /* ndef FEATURE_ACL */
1610 #ifndef FEATURE_TOGGLE
1612 #endif /* ndef FEATURE_TOGGLE */
1613 #ifndef FEATURE_TRUST
1614 case hash_trustfile :
1615 case hash_trust_info_url :
1616 #endif /* ndef FEATURE_TRUST */
1618 #ifndef _WIN_CONSOLE
1619 case hash_hide_console :
1620 #endif /* ndef _WIN_CONSOLE */
1622 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1623 case hash_activity_animation :
1624 case hash_close_button_minimizes :
1625 case hash_log_buffer_size :
1626 case hash_log_font_name :
1627 case hash_log_font_size :
1628 case hash_log_highlight_messages :
1629 case hash_log_max_lines :
1630 case hash_log_messages :
1631 case hash_show_on_task_bar :
1632 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1633 /* These warnings are annoying - so hide them. -- Jon */
1634 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1637 /* *************************************************************************/
1639 /* *************************************************************************/
1641 * I decided that I liked this better as a warning than an
1642 * error. To change back to an error, just change log level
1643 * to LOG_LEVEL_FATAL.
1645 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1646 "in configuration file (%s).", buf, hash_string(cmd), linenum, configfile);
1647 string_append(&config->proxy_args,
1648 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1651 /* *************************************************************************/
1652 } /* end switch( hash_string(cmd) ) */
1653 } /* end while ( read_config_line(...) ) */
1657 set_debug_level(config->debug);
1659 freez(config->logfile);
1663 if (NULL != logfile)
1665 config->logfile = logfile;
1666 init_error_log(Argv[0], config->logfile);
1674 if (NULL == config->proxy_args)
1676 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1679 if (config->actions_file[0])
1681 add_loader(load_actions_file, config);
1684 if (config->re_filterfile)
1686 add_loader(load_re_filterfile, config);
1689 #ifdef FEATURE_TRUST
1690 if (config->trustfile)
1692 add_loader(load_trustfile, config);
1694 #endif /* def FEATURE_TRUST */
1696 #ifdef FEATURE_COOKIE_JAR
1697 if ( NULL != config->jarfile )
1699 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1701 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1702 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1704 setbuf(config->jar, NULL);
1706 #endif /* def FEATURE_COOKIE_JAR */
1708 if ( NULL == config->haddr )
1710 config->haddr = strdup( HADDR_DEFAULT );
1713 if ( NULL != config->haddr )
1715 if (NULL != (p = strchr(config->haddr, ':')))
1720 config->hport = atoi(p);
1724 if (config->hport <= 0)
1727 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1728 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1730 if (*config->haddr == '\0')
1733 * Only the port specified. We stored it in config->hport
1734 * and don't need its text representation anymore.
1736 freez(config->haddr);
1741 * Want to run all the loaders once now.
1743 * Need to set up a fake csp, so they can get to the config.
1745 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1746 fake_csp->config = config;
1748 if (run_loader(fake_csp))
1751 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1752 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1756 /* FIXME: this is a kludge for win32 */
1757 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1759 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1760 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1761 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1763 #ifdef FEATURE_TRUST
1764 g_trustfile = config->trustfile;
1765 #endif /* def FEATURE_TRUST */
1768 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1769 /* FIXME: end kludge */
1772 config->need_bind = 1;
1774 if (current_configfile)
1776 struct configuration_spec * oldcfg = (struct configuration_spec *)
1777 current_configfile->f;
1779 * Check if config->haddr,hport == oldcfg->haddr,hport
1781 * The following could be written more compactly as a single,
1782 * (unreadably long) if statement.
1784 config->need_bind = 0;
1785 if (config->hport != oldcfg->hport)
1787 config->need_bind = 1;
1789 else if (config->haddr == NULL)
1791 if (oldcfg->haddr != NULL)
1793 config->need_bind = 1;
1796 else if (oldcfg->haddr == NULL)
1798 config->need_bind = 1;
1800 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1802 config->need_bind = 1;
1805 current_configfile->unloader = unload_configfile;
1808 fs->next = files->next;
1811 current_configfile = fs;
1817 /*********************************************************************
1819 * Function : savearg
1821 * Description : Called from `load_config'. It saves each non-empty
1822 * and non-comment line from config into
1823 * config->proxy_args. This is used to create the
1824 * show-proxy-args page. On error, frees
1825 * config->proxy_args and sets it to NULL
1828 * 1 : command = config setting that was found
1829 * 2 : argument = the setting's argument (if any)
1830 * 3 : config = Configuration to save into.
1834 *********************************************************************/
1835 static void savearg(char *command, char *argument, struct configuration_spec * config)
1845 * Add config option name embedded in
1846 * link to its section in the user-manual
1848 buf = strdup("\n<a href=\"");
1849 if (!strncmpic(config->usermanual, "file://", 7) ||
1850 !strncmpic(config->usermanual, "http", 4))
1852 string_append(&buf, config->usermanual);
1856 string_append(&buf, "http://");
1857 string_append(&buf, CGI_SITE_2_HOST);
1858 string_append(&buf, "/user-manual/");
1860 string_append(&buf, CONFIG_HELP_PREFIX);
1861 string_join (&buf, string_toupper(command));
1862 string_append(&buf, "\">");
1863 string_append(&buf, command);
1864 string_append(&buf, "</a> ");
1868 freez(config->proxy_args);
1872 if ( (NULL != argument) && ('\0' != *argument) )
1874 s = html_encode(argument);
1878 freez(config->proxy_args);
1882 if (strncmpic(argument, "http://", 7) == 0)
1884 string_append(&buf, "<a href=\"");
1885 string_append(&buf, s);
1886 string_append(&buf, "\">");
1887 string_join (&buf, s);
1888 string_append(&buf, "</a>");
1892 string_join (&buf, s);
1896 string_append(&buf, "<br>");
1897 string_join(&config->proxy_args, buf);