1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.75 2008/03/30 14:52:05 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.75 2008/03/30 14:52:05 fabiankeil
39 * Rename load_actions_file() and load_re_filterfile()
40 * as they load multiple files "now".
42 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
43 * Add hostname directive. Closes PR#1918189.
45 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
48 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
49 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
51 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
52 * Reword "unrecognized directive" warning, use better
53 * mark up and add a <br>. Fixes parts of #1856559.
55 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
56 * Plug memory leak if listen-address only specifies the port.
58 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
59 * Relocate daemon-mode-related log messages to make sure
60 * they aren't shown again in case of configuration reloads.
62 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
63 * Plug memory leak introduced with my last commit.
65 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
66 * When in daemon mode, close stderr after the configuration file has been
67 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
69 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
70 * #1763173 from Stefan Huehner: declare unload_configfile() static.
72 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
73 * As Hal noticed, checking dispatch_cgi() as the last cruncher
74 * looks like a bug if CGI requests are blocked unintentionally,
75 * so don't do it unless the user enabled the new config option
76 * "allow-cgi-request-crunching".
78 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
79 * - Use strlcpy() instead of strcpy().
80 * - Stop treating actions files special. Expect a complete file name
81 * (with or without path) like it's done for the rest of the files.
83 * - Remove an unnecessary temporary memory allocation.
84 * - Don't log anything to the console when running as
85 * daemon and no errors occurred.
87 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
88 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
90 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
91 * New config option: enforce-blocks.
93 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
94 * - Mention other reasons why acl directive loading might have failed.
95 * - Don't log the acl source if the acl destination is to blame.
97 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
98 * Add new config option "templdir" to
99 * change the templates directory.
101 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
102 * Added config option accept-intercepted-requests
103 * and disabled it by default.
105 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
106 * Fix gcc43 compiler warnings.
108 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
109 * Add config option "split-large-forms"
110 * to work around the browser bug reported
113 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
114 * Move the <br> in the generated HTML for the config
115 * options from the beginning of the string to its end.
116 * Keeps the white space in balance.
118 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
119 * Fix memory leak in case of config file reloads.
121 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
122 * Modified kludge for win32 to make ming32 menu
123 * "Options/Edit Filters" (sort of) work again.
124 * Same limitations as for the action files apply.
127 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
128 * Incorporate modified version of Roland Rosenfeld's patch to
129 * optionally access the user-manual via Privoxy. Closes patch 679075.
131 * Formatting changed to Privoxy style, added call to
132 * cgi_error_no_template if the requested file doesn't
133 * exist and modified check whether or not Privoxy itself
134 * should serve the manual. Should work cross-platform now.
136 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
137 * Added config option enable-remote-http-toggle
138 * to specify if Privoxy should recognize special
139 * headers (currently only X-Filter) to change its
140 * behaviour. Disabled by default.
142 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
143 * Make number of retries in case of forwarded-connect problems
144 * a config file option (forwarded-connect-retries) and use 0 as
147 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
148 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
149 * with what was really the latest development (the v_3_0_branch branch)
151 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
152 * Don't forget to malloc space for the null terminator...
154 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
155 * Multiple filter file support
157 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
158 * Closed two memory leaks; hopefully the last remaining ones
159 * (in the main execution paths, anyway).
161 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
162 * Addressed bug #719435
163 * - Extraneous filterfile directives now logged as errors
164 * - This and unrecnonised directives now really obvious on status page
166 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
167 * Cosmetic: Renamed cryptic variable
169 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
170 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
172 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
173 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
175 * Revision 1.48 2002/05/14 21:30:38 oes
176 * savearg now uses own linking code instead of (now special-cased) add_help_link
178 * Revision 1.47 2002/05/12 21:36:29 jongfoster
179 * Correcting function comments
181 * Revision 1.46 2002/04/26 12:55:14 oes
182 * - New option "user-manual", defaults to our site
183 * via project.h #define
184 * - savearg now embeds option names in help links
186 * Revision 1.45 2002/04/24 02:11:54 oes
187 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
189 * Revision 1.44 2002/04/08 20:37:13 swa
192 * Revision 1.43 2002/04/08 20:36:50 swa
195 * Revision 1.42 2002/04/05 15:50:15 oes
196 * fix for invalid HTML proxy_args
198 * Revision 1.41 2002/03/31 17:19:00 jongfoster
199 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
201 * Revision 1.40 2002/03/26 22:29:55 swa
202 * we have a new homepage!
204 * Revision 1.39 2002/03/24 13:25:43 swa
205 * name change related issues
207 * Revision 1.38 2002/03/24 13:05:48 jongfoster
208 * Renaming re_filterfile to filterfile
210 * Revision 1.37 2002/03/16 23:54:06 jongfoster
211 * Adding graceful termination feature, to help look for memory leaks.
212 * If you enable this (which, by design, has to be done by hand
213 * editing config.h) and then go to http://i.j.b/die, then the program
214 * will exit cleanly after the *next* request. It should free all the
215 * memory that was used.
217 * Revision 1.36 2002/03/13 00:27:05 jongfoster
220 * Revision 1.35 2002/03/07 03:52:44 oes
221 * Set logging to tty for --no-daemon mode
223 * Revision 1.34 2002/03/06 23:14:35 jongfoster
224 * Trivial cosmetic changes to make function comments easier to find.
226 * Revision 1.33 2002/03/05 04:52:42 oes
227 * Deleted non-errlog debugging code
229 * Revision 1.32 2002/03/04 18:24:53 oes
230 * Re-enabled output of unknown config directive hash
232 * Revision 1.31 2002/03/03 15:07:20 oes
233 * Re-enabled automatic config reloading
235 * Revision 1.30 2002/01/22 23:31:43 jongfoster
236 * Replacing strsav() with string_append()
238 * Revision 1.29 2002/01/17 21:02:30 jongfoster
239 * Moving all our URL and URL pattern parsing code to urlmatch.c.
241 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
243 * Revision 1.28 2001/12/30 14:07:32 steudten
244 * - Add signal handling (unix)
245 * - Add SIGHUP handler (unix)
246 * - Add creation of pidfile (unix)
247 * - Add action 'top' in rc file (RH)
248 * - Add entry 'SIGNALS' to manpage
249 * - Add exit message to logfile (unix)
251 * Revision 1.27 2001/11/07 00:02:13 steudten
252 * Add line number in error output for lineparsing for
253 * actionsfile and configfile.
254 * Special handling for CLF added.
256 * Revision 1.26 2001/11/05 21:41:43 steudten
257 * Add changes to be a real daemon just for unix os.
258 * (change cwd to /, detach from controlling tty, set
259 * process group and session leader to the own process.
261 * Add some fatal-error log message for failed malloc().
262 * Add '-d' if compiled with 'configure --with-debug' to
263 * enable debug output.
265 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
266 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
267 * threads to call select() simultaneously. So, it's time to do a real, live,
268 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
269 * (native). Both versions will work, but using __OS2__ offers multi-threading.
271 * Revision 1.24 2001/10/23 21:40:30 jongfoster
272 * Added support for enable-edit-actions and enable-remote-toggle config
275 * Revision 1.23 2001/10/07 15:36:00 oes
276 * Introduced new config option "buffer-limit"
278 * Revision 1.22 2001/09/22 16:36:59 jongfoster
279 * Removing unused parameter fs from read_config_line()
281 * Revision 1.21 2001/09/16 17:10:43 jongfoster
282 * Moving function savearg() here, since it was the only thing left in
285 * Revision 1.20 2001/07/30 22:08:36 jongfoster
286 * Tidying up #defines:
287 * - All feature #defines are now of the form FEATURE_xxx
288 * - Permanently turned off WIN_GUI_EDIT
289 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
291 * Revision 1.19 2001/07/15 17:45:16 jongfoster
292 * Removing some unused #includes
294 * Revision 1.18 2001/07/13 14:01:14 oes
295 * - Removed all #ifdef PCRS
296 * - Removed vim-settings
298 * Revision 1.17 2001/06/29 13:31:03 oes
299 * - Improved comments
300 * - Fixed (actionsfile) and sorted hashes
301 * - Introduced admin_address and proxy-info-url
302 * as config parameters
303 * - Renamed config->proxy_args_invocation (which didn't have
304 * the invocation but the options!) to config->proxy_args
305 * - Various adaptions
306 * - Removed logentry from cancelled commit
308 * Revision 1.16 2001/06/09 10:55:28 jongfoster
309 * Changing BUFSIZ ==> BUFFER_SIZE
311 * Revision 1.15 2001/06/07 23:13:40 jongfoster
312 * Merging ACL and forward files into config file.
313 * Cosmetic: Sorting config file options alphabetically.
314 * Cosmetic: Adding brief syntax comments to config file options.
316 * Revision 1.14 2001/06/07 14:46:25 joergs
317 * Missing make_path() added for re_filterfile.
319 * Revision 1.13 2001/06/05 22:33:54 jongfoster
321 * Fixed minor memory leak.
322 * Also now uses make_path to prepend the pathnames.
324 * Revision 1.12 2001/06/05 20:04:09 jongfoster
325 * Now uses _snprintf() in place of snprintf() under Win32.
327 * Revision 1.11 2001/06/04 18:31:58 swa
328 * files are now prefixed with either `confdir' or `logdir'.
329 * `make redhat-dist' replaces both entries confdir and logdir
332 * Revision 1.10 2001/06/03 19:11:54 oes
333 * introduced confdir option
335 * Revision 1.9 2001/06/01 20:06:24 jongfoster
336 * Removed support for "tinygif" option - moved to actions file.
338 * Revision 1.8 2001/05/31 21:27:13 jongfoster
339 * Removed many options from the config file and into the
340 * "actions" file: add_forwarded, suppress_vanilla_wafer,
341 * wafer, add_header, user_agent, referer, from
342 * Also globally replaced "permission" with "action".
344 * Revision 1.7 2001/05/29 09:50:24 jongfoster
345 * Unified blocklist/imagelist/permissionslist.
346 * File format is still under discussion, but the internal changes
349 * Also modified interceptor behaviour:
350 * - We now intercept all URLs beginning with one of the following
351 * prefixes (and *only* these prefixes):
353 * * http://ijbswa.sf.net/config/
354 * * http://ijbswa.sourceforge.net/config/
355 * - New interceptors "home page" - go to http://i.j.b/ to see it.
356 * - Internal changes so that intercepted and fast redirect pages
357 * are not replaced with an image.
358 * - Interceptors now have the option to send a binary page direct
359 * to the client. (i.e. ijb-send-banner uses this)
360 * - Implemented show-url-info interceptor. (Which is why I needed
361 * the above interceptors changes - a typical URL is
362 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
363 * The previous mechanism would not have intercepted that, and
364 * if it had been intercepted then it then it would have replaced
367 * Revision 1.6 2001/05/26 00:28:36 jongfoster
368 * Automatic reloading of config file.
369 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
370 * Most of the global variables have been moved to a new
371 * struct configuration_spec, accessed through csp->config->globalname
372 * Most of the globals remaining are used by the Win32 GUI.
374 * Revision 1.5 2001/05/25 22:34:30 jongfoster
377 * Revision 1.4 2001/05/22 18:46:04 oes
379 * - Enabled filtering banners by size rather than URL
380 * by adding patterns that replace all standard banner
381 * sizes with the "Junkbuster" gif to the re_filterfile
383 * - Enabled filtering WebBugs by providing a pattern
384 * which kills all 1x1 images
386 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
387 * which is selected by the (nonstandard and therefore
388 * capital) letter 'U' in the option string.
389 * It causes the quantifiers to be ungreedy by default.
390 * Appending a ? turns back to greedy (!).
392 * - Added a new interceptor ijb-send-banner, which
393 * sends back the "Junkbuster" gif. Without imagelist or
394 * MSIE detection support, or if tinygif = 1, or the
395 * URL isn't recognized as an imageurl, a lame HTML
396 * explanation is sent instead.
398 * - Added new feature, which permits blocking remote
399 * script redirects and firing back a local redirect
401 * The feature is conditionally compiled, i.e. it
402 * can be disabled with --disable-fast-redirects,
403 * plus it must be activated by a "fast-redirects"
404 * line in the config file, has its own log level
405 * and of course wants to be displayed by show-proxy-args
406 * Note: Boy, all the #ifdefs in 1001 locations and
407 * all the fumbling with configure.in and acconfig.h
408 * were *way* more work than the feature itself :-(
410 * - Because a generic redirect template was needed for
411 * this, tinygif = 3 now uses the same.
413 * - Moved GIFs, and other static HTTP response templates
418 * - Removed some >400 CRs again (Jon, you really worked
421 * Revision 1.3 2001/05/20 01:21:20 jongfoster
422 * Version 2.9.4 checkin.
423 * - Merged popupfile and cookiefile, and added control over PCRS
424 * filtering, in new "permissionsfile".
425 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
426 * file error you now get a message box (in the Win32 GUI) rather
427 * than the program exiting with no explanation.
428 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
430 * - Removed tabs from "config"
431 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
432 * - Bumped up version number.
434 * Revision 1.2 2001/05/17 23:01:01 oes
435 * - Cleaned CRLF's from the sources and related files
437 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
438 * Initial import of version 2.9.3 source tree
441 *********************************************************************/
447 #include <sys/types.h>
461 # include <windows.h>
464 # ifndef _WIN_CONSOLE
466 # endif /* ndef _WIN_CONSOLE */
468 #else /* ifndef _WIN32 */
472 # include <sys/wait.h>
474 # include <sys/time.h>
475 # include <sys/stat.h>
485 #include "miscutil.h"
489 #include "urlmatch.h"
492 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
495 * Fix a problem with Solaris. There should be no effect on other
497 * Solaris's isspace() is a macro which uses it's argument directly
498 * as an array index. Therefore we need to make sure that high-bit
499 * characters generate +ve values, and ideally we also want to make
500 * the argument match the declared parameter type of "int".
502 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
503 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
505 #ifdef FEATURE_TOGGLE
506 /* Privoxy is enabled by default. */
507 int global_toggle_state = 1;
508 #endif /* def FEATURE_TOGGLE */
510 /* The filename of the configfile */
511 const char *configfile = NULL;
514 * CGI functions will later need access to the invocation args,
515 * so we will make argc and argv global.
518 const char **Argv = NULL;
520 static struct file_list *current_configfile = NULL;
524 * This takes the "cryptic" hash of each keyword and aliases them to
525 * something a little more readable. This also makes changing the
526 * hash values easier if they should change or the hash algorthm changes.
527 * Use the included "hash" program to find out what the hash will be
528 * for any string supplied on the command line. (Or just put it in the
529 * config file and read the number from the error message in the log).
531 * Please keep this list sorted alphabetically (but with the Windows
532 * console and GUI specific options last).
535 #define hash_actions_file 1196306641ul /* "actionsfile" */
536 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
537 #define hash_admin_address 4112573064ul /* "admin-address" */
538 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
539 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
540 #define hash_confdir 1978389ul /* "confdir" */
541 #define hash_debug 78263ul /* "debug" */
542 #define hash_deny_access 1227333715ul /* "deny-access" */
543 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
544 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
545 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
546 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
547 #define hash_filterfile 250887266ul /* "filterfile" */
548 #define hash_forward 2029845ul /* "forward" */
549 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
550 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
551 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
552 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
553 #define hash_hostname 10308071ul /* "hostname" */
554 #define hash_jarfile 2046641ul /* "jarfile" */
555 #define hash_listen_address 1255650842ul /* "listen-address" */
556 #define hash_logdir 422889ul /* "logdir" */
557 #define hash_logfile 2114766ul /* "logfile" */
558 #define hash_permit_access 3587953268ul /* "permit-access" */
559 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
560 #define hash_single_threaded 4250084780ul /* "single-threaded" */
561 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
562 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
563 #define hash_templdir 11067889ul /* "templdir" */
564 #define hash_toggle 447966ul /* "toggle" */
565 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
566 #define hash_trustfile 56494766ul /* "trustfile" */
567 #define hash_usermanual 1416668518ul /* "user-manual" */
568 #define hash_activity_animation 1817904738ul /* "activity-animation" */
569 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
570 #define hash_hide_console 2048809870ul /* "hide-console" */
571 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
572 #define hash_log_font_name 2866730124ul /* "log-font-name" */
573 #define hash_log_font_size 2866731014ul /* "log-font-size" */
574 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
575 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
576 #define hash_log_messages 2291744899ul /* "log-messages" */
577 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
580 static void savearg(char *command, char *argument, struct configuration_spec * config);
582 /*********************************************************************
584 * Function : unload_configfile
586 * Description : Free the config structure and all components.
589 * 1 : data: struct configuration_spec to unload
593 *********************************************************************/
594 static void unload_configfile (void * data)
596 struct configuration_spec * config = (struct configuration_spec *)data;
597 struct forward_spec *cur_fwd = config->forward;
601 struct access_control_list *cur_acl = config->acl;
603 while (cur_acl != NULL)
605 struct access_control_list * next_acl = cur_acl->next;
610 #endif /* def FEATURE_ACL */
612 while (cur_fwd != NULL)
614 struct forward_spec * next_fwd = cur_fwd->next;
615 free_url_spec(cur_fwd->url);
617 freez(cur_fwd->gateway_host);
618 freez(cur_fwd->forward_host);
622 config->forward = NULL;
624 #ifdef FEATURE_COOKIE_JAR
625 if ( NULL != config->jar )
627 fclose( config->jar );
630 #endif /* def FEATURE_COOKIE_JAR */
632 freez(config->confdir);
633 freez(config->logdir);
634 freez(config->templdir);
635 freez(config->hostname);
637 freez(config->haddr);
638 freez(config->logfile);
640 for (i = 0; i < MAX_AF_FILES; i++)
642 freez(config->actions_file_short[i]);
643 freez(config->actions_file[i]);
644 freez(config->re_filterfile_short[i]);
645 freez(config->re_filterfile[i]);
648 freez(config->admin_address);
649 freez(config->proxy_info_url);
650 freez(config->proxy_args);
651 freez(config->usermanual);
653 #ifdef FEATURE_COOKIE_JAR
654 freez(config->jarfile);
655 #endif /* def FEATURE_COOKIE_JAR */
658 freez(config->trustfile);
659 list_remove_all(config->trust_info);
660 #endif /* def FEATURE_TRUST */
662 for (i = 0; i < MAX_AF_FILES; i++)
664 freez(config->re_filterfile[i]);
671 #ifdef FEATURE_GRACEFUL_TERMINATION
672 /*********************************************************************
674 * Function : unload_current_config_file
676 * Description : Unloads current config file - reset to state at
677 * beginning of program.
683 *********************************************************************/
684 void unload_current_config_file(void)
686 if (current_configfile)
688 current_configfile->unloader = unload_configfile;
689 current_configfile = NULL;
695 /*********************************************************************
697 * Function : load_config
699 * Description : Load the config file and all parameters.
701 * XXX: more than thousand lines long
702 * and thus in serious need of refactoring.
706 * Returns : The configuration_spec, or NULL on error.
708 *********************************************************************/
709 struct configuration_spec * load_config(void)
711 char buf[BUFFER_SIZE];
713 FILE *configfp = NULL;
714 struct configuration_spec * config = NULL;
715 struct client_state * fake_csp;
716 struct file_list *fs;
717 unsigned long linenum = 0;
719 char *logfile = NULL;
721 if ( !check_file_changed(current_configfile, configfile, &fs))
723 /* No need to load */
724 return ((struct configuration_spec *)current_configfile->f);
728 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
732 if (NULL != current_configfile)
734 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
737 #ifdef FEATURE_TOGGLE
738 global_toggle_state = 1;
739 #endif /* def FEATURE_TOGGLE */
741 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
747 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
748 /* Never get here - LOG_LEVEL_FATAL causes program exit */
752 * This is backwards from how it's usually done.
753 * Following the usual pattern, "fs" would be stored in a member
754 * variable in "csp", and then we'd access "config" from "fs->f",
755 * using a cast. However, "config" is used so often that a
756 * cast each time would be very ugly, and the extra indirection
757 * would waste CPU cycles. Therefore we store "config" in
758 * "csp->config", and "fs" in "csp->config->config_file_list".
760 config->config_file_list = fs;
765 config->multi_threaded = 1;
766 config->hport = HADDR_PORT;
767 config->buffer_limit = 4096 * 1024;
768 config->usermanual = strdup(USER_MANUAL_URL);
769 config->proxy_args = strdup("");
770 config->forwarded_connect_retries = 0;
771 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
772 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
773 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
775 if ((configfp = fopen(configfile, "r")) == NULL)
777 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
779 /* Never get here - LOG_LEVEL_FATAL causes program exit */
782 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
784 char cmd[BUFFER_SIZE];
785 char arg[BUFFER_SIZE];
786 char tmp[BUFFER_SIZE];
788 struct access_control_list *cur_acl;
789 #endif /* def FEATURE_ACL */
790 struct forward_spec *cur_fwd;
793 unsigned long directive_hash;
795 strlcpy(tmp, buf, sizeof(tmp));
797 /* Copy command (i.e. up to space or tab) into cmd */
800 while (*p && (*p != ' ') && (*p != '\t'))
806 /* Skip over the whitespace in buf */
807 while (*p && ((*p == ' ') || (*p == '\t')))
812 /* Copy the argument into arg */
813 strlcpy(arg, p, sizeof(arg));
815 /* Should never happen, but check this anyway */
821 /* Make sure the command field is lower case */
826 *p = (char)ijb_tolower(*p);
830 /* Save the argument for show-proxy-args */
831 savearg(cmd, arg, config);
833 directive_hash = hash_string(cmd);
834 switch (directive_hash)
836 /* *************************************************************************
837 * actionsfile actions-file-name
838 * In confdir by default
839 * *************************************************************************/
840 case hash_actions_file :
842 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
847 if (i >= MAX_AF_FILES)
849 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
850 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
853 config->actions_file_short[i] = strdup(arg);
854 config->actions_file[i] = make_path(config->confdir, arg);
857 /* *************************************************************************
858 * accept-intercepted-requests
859 * *************************************************************************/
860 case hash_accept_intercepted_requests:
861 if ((*arg != '\0') && (0 != atoi(arg)))
863 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
867 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
871 /* *************************************************************************
872 * admin-address email-address
873 * *************************************************************************/
874 case hash_admin_address :
875 freez(config->admin_address);
876 config->admin_address = strdup(arg);
879 /* *************************************************************************
880 * allow-cgi-request-crunching
881 * *************************************************************************/
882 case hash_allow_cgi_request_crunching:
883 if ((*arg != '\0') && (0 != atoi(arg)))
885 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
889 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
893 /* *************************************************************************
895 * *************************************************************************/
896 case hash_buffer_limit :
897 config->buffer_limit = (size_t)(1024 * atoi(arg));
900 /* *************************************************************************
901 * confdir directory-name
902 * *************************************************************************/
904 freez(config->confdir);
905 config->confdir = make_path( NULL, arg);
908 /* *************************************************************************
910 * Specifies debug level, multiple values are ORed together.
911 * *************************************************************************/
913 config->debug |= atoi(arg);
916 /* *************************************************************************
917 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
918 * *************************************************************************/
920 case hash_deny_access:
921 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
923 if ((vec_count != 1) && (vec_count != 2))
925 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
926 "deny-access directive in configuration file.");
927 string_append(&config->proxy_args,
928 "<br>\nWARNING: Wrong number of parameters for "
929 "deny-access directive in configuration file.<br><br>\n");
933 /* allocate a new node */
934 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
938 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
939 /* Never get here - LOG_LEVEL_FATAL causes program exit */
942 cur_acl->action = ACL_DENY;
944 if (acl_addr(vec[0], cur_acl->src) < 0)
946 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
947 "for deny-access directive in configuration file: \"%s\"", vec[0]);
948 string_append(&config->proxy_args,
949 "<br>\nWARNING: Invalid source address, port or netmask "
950 "for deny-access directive in configuration file: \"");
951 string_append(&config->proxy_args,
953 string_append(&config->proxy_args,
960 if (acl_addr(vec[1], cur_acl->dst) < 0)
962 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
963 "for deny-access directive in configuration file: \"%s\"", vec[1]);
964 string_append(&config->proxy_args,
965 "<br>\nWARNING: Invalid destination address, port or netmask "
966 "for deny-access directive in configuration file: \"");
967 string_append(&config->proxy_args,
969 string_append(&config->proxy_args,
977 * Add it to the list. Note we reverse the list to get the
978 * behaviour the user expects. With both the ACL and
979 * actions file, the last match wins. However, the internal
980 * implementations are different: The actions file is stored
981 * in the same order as the file, and scanned completely.
982 * With the ACL, we reverse the order as we load it, then
983 * when we scan it we stop as soon as we get a match.
985 cur_acl->next = config->acl;
986 config->acl = cur_acl;
989 #endif /* def FEATURE_ACL */
991 /* *************************************************************************
992 * enable-edit-actions 0|1
993 * *************************************************************************/
994 #ifdef FEATURE_CGI_EDIT_ACTIONS
995 case hash_enable_edit_actions:
996 if ((*arg != '\0') && (0 != atoi(arg)))
998 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1002 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1005 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1007 /* *************************************************************************
1008 * enable-remote-toggle 0|1
1009 * *************************************************************************/
1010 #ifdef FEATURE_CGI_EDIT_ACTIONS
1011 case hash_enable_remote_toggle:
1012 if ((*arg != '\0') && (0 != atoi(arg)))
1014 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1018 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1021 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1023 /* *************************************************************************
1024 * enable-remote-http-toggle 0|1
1025 * *************************************************************************/
1026 case hash_enable_remote_http_toggle:
1027 if ((*arg != '\0') && (0 != atoi(arg)))
1029 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1033 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1037 /* *************************************************************************
1038 * hash_enforce_blocks 0|1
1039 * *************************************************************************/
1040 #ifdef FEATURE_FORCE_LOAD
1041 case hash_enforce_blocks:
1042 if ((*arg != '\0') && (0 != atoi(arg)))
1044 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1048 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1051 #endif /* def FEATURE_FORCE_LOAD */
1053 /* *************************************************************************
1054 * filterfile file-name
1055 * In confdir by default.
1056 * *************************************************************************/
1057 case hash_filterfile :
1059 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1064 if (i >= MAX_AF_FILES)
1066 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1067 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1070 config->re_filterfile_short[i] = strdup(arg);
1071 config->re_filterfile[i] = make_path(config->confdir, arg);
1075 /* *************************************************************************
1076 * forward url-pattern (.|http-proxy-host[:port])
1077 * *************************************************************************/
1079 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1083 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1084 "directive in configuration file.");
1085 string_append(&config->proxy_args,
1086 "<br>\nWARNING: Wrong number of parameters for "
1087 "forward directive in configuration file.");
1091 /* allocate a new node */
1092 cur_fwd = zalloc(sizeof(*cur_fwd));
1093 if (cur_fwd == NULL)
1095 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1096 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1100 cur_fwd->type = SOCKS_NONE;
1102 /* Save the URL pattern */
1103 if (create_url_spec(cur_fwd->url, vec[0]))
1105 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1106 "directive in configuration file.");
1107 string_append(&config->proxy_args,
1108 "<br>\nWARNING: Bad URL specifier for "
1109 "forward directive in configuration file.");
1113 /* Parse the parent HTTP proxy host:port */
1116 if (strcmp(p, ".") != 0)
1118 cur_fwd->forward_host = strdup(p);
1120 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1123 cur_fwd->forward_port = atoi(p);
1126 if (cur_fwd->forward_port <= 0)
1128 cur_fwd->forward_port = 8000;
1133 cur_fwd->next = config->forward;
1134 config->forward = cur_fwd;
1138 /* *************************************************************************
1139 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1140 * *************************************************************************/
1141 case hash_forward_socks4:
1142 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1146 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1147 "forward-socks4 directive in configuration file.");
1148 string_append(&config->proxy_args,
1149 "<br>\nWARNING: Wrong number of parameters for "
1150 "forward-socks4 directive in configuration file.");
1154 /* allocate a new node */
1155 cur_fwd = zalloc(sizeof(*cur_fwd));
1156 if (cur_fwd == NULL)
1158 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1159 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1163 cur_fwd->type = SOCKS_4;
1165 /* Save the URL pattern */
1166 if (create_url_spec(cur_fwd->url, vec[0]))
1168 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1169 "directive in configuration file.");
1170 string_append(&config->proxy_args,
1171 "<br>\nWARNING: Bad URL specifier for "
1172 "forward-socks4 directive in configuration file.");
1176 /* Parse the SOCKS proxy host[:port] */
1179 if (strcmp(p, ".") != 0)
1181 cur_fwd->gateway_host = strdup(p);
1183 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1186 cur_fwd->gateway_port = atoi(p);
1188 if (cur_fwd->gateway_port <= 0)
1190 cur_fwd->gateway_port = 1080;
1194 /* Parse the parent HTTP proxy host[:port] */
1197 if (strcmp(p, ".") != 0)
1199 cur_fwd->forward_host = strdup(p);
1201 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1204 cur_fwd->forward_port = atoi(p);
1207 if (cur_fwd->forward_port <= 0)
1209 cur_fwd->forward_port = 8000;
1214 cur_fwd->next = config->forward;
1215 config->forward = cur_fwd;
1219 /* *************************************************************************
1220 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1221 * *************************************************************************/
1222 case hash_forward_socks4a:
1223 case hash_forward_socks5:
1224 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1228 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1229 "forward-socks4a directive in configuration file.");
1230 string_append(&config->proxy_args,
1231 "<br>\nWARNING: Wrong number of parameters for "
1232 "forward-socks4a directive in configuration file.");
1236 /* allocate a new node */
1237 cur_fwd = zalloc(sizeof(*cur_fwd));
1238 if (cur_fwd == NULL)
1240 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1241 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1245 if (directive_hash == hash_forward_socks4a)
1247 cur_fwd->type = SOCKS_4A;
1251 cur_fwd->type = SOCKS_5;
1254 /* Save the URL pattern */
1255 if (create_url_spec(cur_fwd->url, vec[0]))
1257 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1258 "directive in configuration file.");
1259 string_append(&config->proxy_args,
1260 "<br>\nWARNING: Bad URL specifier for "
1261 "forward-socks4a directive in configuration file.");
1265 /* Parse the SOCKS proxy host[:port] */
1268 cur_fwd->gateway_host = strdup(p);
1270 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1273 cur_fwd->gateway_port = atoi(p);
1275 if (cur_fwd->gateway_port <= 0)
1277 cur_fwd->gateway_port = 1080;
1280 /* Parse the parent HTTP proxy host[:port] */
1283 if (strcmp(p, ".") != 0)
1285 cur_fwd->forward_host = strdup(p);
1287 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1290 cur_fwd->forward_port = atoi(p);
1293 if (cur_fwd->forward_port <= 0)
1295 cur_fwd->forward_port = 8000;
1300 cur_fwd->next = config->forward;
1301 config->forward = cur_fwd;
1305 /* *************************************************************************
1306 * forwarded-connect-retries n
1307 * *************************************************************************/
1308 case hash_forwarded_connect_retries :
1309 config->forwarded_connect_retries = atoi(arg);
1312 /* *************************************************************************
1313 * hostname hostname-to-show-on-cgi-pages
1314 * *************************************************************************/
1315 case hash_hostname :
1316 freez(config->hostname);
1317 config->hostname = strdup(arg);
1318 if (NULL == config->hostname)
1320 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1324 /* *************************************************************************
1325 * jarfile jar-file-name
1326 * In logdir by default
1327 * *************************************************************************/
1328 #ifdef FEATURE_COOKIE_JAR
1330 freez(config->jarfile);
1331 config->jarfile = make_path(config->logdir, arg);
1333 #endif /* def FEATURE_COOKIE_JAR */
1335 /* *************************************************************************
1336 * listen-address [ip][:port]
1337 * *************************************************************************/
1338 case hash_listen_address :
1339 freez(config->haddr);
1340 config->haddr = strdup(arg);
1343 /* *************************************************************************
1344 * logdir directory-name
1345 * *************************************************************************/
1347 freez(config->logdir);
1348 config->logdir = make_path(NULL, arg);
1351 /* *************************************************************************
1352 * logfile log-file-name
1353 * In logdir by default
1354 * *************************************************************************/
1358 logfile = make_path(config->logdir, arg);
1359 if (NULL == logfile)
1361 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1366 /* *************************************************************************
1367 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1368 * *************************************************************************/
1370 case hash_permit_access:
1371 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1373 if ((vec_count != 1) && (vec_count != 2))
1375 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1376 "permit-access directive in configuration file.");
1377 string_append(&config->proxy_args,
1378 "<br>\nWARNING: Wrong number of parameters for "
1379 "permit-access directive in configuration file.<br><br>\n");
1384 /* allocate a new node */
1385 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1387 if (cur_acl == NULL)
1389 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1390 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1393 cur_acl->action = ACL_PERMIT;
1395 if (acl_addr(vec[0], cur_acl->src) < 0)
1397 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1398 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1399 string_append(&config->proxy_args,
1400 "<br>\nWARNING: Invalid source address, port or netmask for "
1401 "permit-access directive in configuration file: \"");
1402 string_append(&config->proxy_args,
1404 string_append(&config->proxy_args,
1411 if (acl_addr(vec[1], cur_acl->dst) < 0)
1413 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1414 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1415 string_append(&config->proxy_args,
1416 "<br>\nWARNING: Invalid destination address, port or netmask for "
1417 "permit-access directive in configuration file: \"");
1418 string_append(&config->proxy_args,
1420 string_append(&config->proxy_args,
1428 * Add it to the list. Note we reverse the list to get the
1429 * behaviour the user expects. With both the ACL and
1430 * actions file, the last match wins. However, the internal
1431 * implementations are different: The actions file is stored
1432 * in the same order as the file, and scanned completely.
1433 * With the ACL, we reverse the order as we load it, then
1434 * when we scan it we stop as soon as we get a match.
1436 cur_acl->next = config->acl;
1437 config->acl = cur_acl;
1440 #endif /* def FEATURE_ACL */
1442 /* *************************************************************************
1443 * proxy-info-url url
1444 * *************************************************************************/
1445 case hash_proxy_info_url :
1446 freez(config->proxy_info_url);
1447 config->proxy_info_url = strdup(arg);
1450 /* *************************************************************************
1452 * *************************************************************************/
1453 case hash_single_threaded :
1454 config->multi_threaded = 0;
1457 /* *************************************************************************
1458 * split-large-cgi-forms
1459 * *************************************************************************/
1460 case hash_split_large_cgi_forms :
1461 if ((*arg != '\0') && (0 != atoi(arg)))
1463 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1467 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1471 /* *************************************************************************
1472 * templdir directory-name
1473 * *************************************************************************/
1474 case hash_templdir :
1475 freez(config->templdir);
1476 config->templdir = make_path(NULL, arg);
1479 /* *************************************************************************
1481 * *************************************************************************/
1482 #ifdef FEATURE_TOGGLE
1484 global_toggle_state = atoi(arg);
1486 #endif /* def FEATURE_TOGGLE */
1488 /* *************************************************************************
1489 * trust-info-url url
1490 * *************************************************************************/
1491 #ifdef FEATURE_TRUST
1492 case hash_trust_info_url :
1493 enlist(config->trust_info, arg);
1495 #endif /* def FEATURE_TRUST */
1497 /* *************************************************************************
1498 * trustfile filename
1499 * (In confdir by default.)
1500 * *************************************************************************/
1501 #ifdef FEATURE_TRUST
1502 case hash_trustfile :
1503 freez(config->trustfile);
1504 config->trustfile = make_path(config->confdir, arg);
1506 #endif /* def FEATURE_TRUST */
1508 /* *************************************************************************
1510 * *************************************************************************/
1511 case hash_usermanual :
1512 freez(config->usermanual);
1513 config->usermanual = strdup(arg);
1516 /* *************************************************************************
1517 * Win32 Console options:
1518 * *************************************************************************/
1520 /* *************************************************************************
1522 * *************************************************************************/
1524 case hash_hide_console :
1527 #endif /*def _WIN_CONSOLE*/
1530 /* *************************************************************************
1531 * Win32 GUI options:
1532 * *************************************************************************/
1534 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1535 /* *************************************************************************
1536 * activity-animation (0|1)
1537 * *************************************************************************/
1538 case hash_activity_animation :
1539 g_bShowActivityAnimation = atoi(arg);
1542 /* *************************************************************************
1543 * close-button-minimizes (0|1)
1544 * *************************************************************************/
1545 case hash_close_button_minimizes :
1546 g_bCloseHidesWindow = atoi(arg);
1549 /* *************************************************************************
1550 * log-buffer-size (0|1)
1551 * *************************************************************************/
1552 case hash_log_buffer_size :
1553 g_bLimitBufferSize = atoi(arg);
1556 /* *************************************************************************
1557 * log-font-name fontnane
1558 * *************************************************************************/
1559 case hash_log_font_name :
1560 strcpy( g_szFontFaceName, arg );
1563 /* *************************************************************************
1565 * *************************************************************************/
1566 case hash_log_font_size :
1567 g_nFontSize = atoi(arg);
1570 /* *************************************************************************
1571 * log-highlight-messages (0|1)
1572 * *************************************************************************/
1573 case hash_log_highlight_messages :
1574 g_bHighlightMessages = atoi(arg);
1577 /* *************************************************************************
1579 * *************************************************************************/
1580 case hash_log_max_lines :
1581 g_nMaxBufferLines = atoi(arg);
1584 /* *************************************************************************
1585 * log-messages (0|1)
1586 * *************************************************************************/
1587 case hash_log_messages :
1588 g_bLogMessages = atoi(arg);
1591 /* *************************************************************************
1592 * show-on-task-bar (0|1)
1593 * *************************************************************************/
1594 case hash_show_on_task_bar :
1595 g_bShowOnTaskBar = atoi(arg);
1598 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1601 /* *************************************************************************
1602 * Warnings about unsupported features
1603 * *************************************************************************/
1605 case hash_deny_access:
1606 #endif /* ndef FEATURE_ACL */
1607 #ifndef FEATURE_CGI_EDIT_ACTIONS
1608 case hash_enable_edit_actions:
1609 case hash_enable_remote_toggle:
1610 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1611 #ifndef FEATURE_COOKIE_JAR
1613 #endif /* ndef FEATURE_COOKIE_JAR */
1615 case hash_permit_access:
1616 #endif /* ndef FEATURE_ACL */
1617 #ifndef FEATURE_TOGGLE
1619 #endif /* ndef FEATURE_TOGGLE */
1620 #ifndef FEATURE_TRUST
1621 case hash_trustfile :
1622 case hash_trust_info_url :
1623 #endif /* ndef FEATURE_TRUST */
1625 #ifndef _WIN_CONSOLE
1626 case hash_hide_console :
1627 #endif /* ndef _WIN_CONSOLE */
1629 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1630 case hash_activity_animation :
1631 case hash_close_button_minimizes :
1632 case hash_log_buffer_size :
1633 case hash_log_font_name :
1634 case hash_log_font_size :
1635 case hash_log_highlight_messages :
1636 case hash_log_max_lines :
1637 case hash_log_messages :
1638 case hash_show_on_task_bar :
1639 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1640 /* These warnings are annoying - so hide them. -- Jon */
1641 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1644 /* *************************************************************************/
1646 /* *************************************************************************/
1648 * I decided that I liked this better as a warning than an
1649 * error. To change back to an error, just change log level
1650 * to LOG_LEVEL_FATAL.
1652 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1653 "in configuration file (%s).", buf, hash_string(cmd), linenum, configfile);
1654 string_append(&config->proxy_args,
1655 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1658 /* *************************************************************************/
1659 } /* end switch( hash_string(cmd) ) */
1660 } /* end while ( read_config_line(...) ) */
1664 set_debug_level(config->debug);
1666 freez(config->logfile);
1670 if (NULL != logfile)
1672 config->logfile = logfile;
1673 init_error_log(Argv[0], config->logfile);
1681 if (NULL == config->proxy_args)
1683 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1686 if (config->actions_file[0])
1688 add_loader(load_action_files, config);
1691 if (config->re_filterfile[0])
1693 add_loader(load_re_filterfiles, config);
1696 #ifdef FEATURE_TRUST
1697 if (config->trustfile)
1699 add_loader(load_trustfile, config);
1701 #endif /* def FEATURE_TRUST */
1703 #ifdef FEATURE_COOKIE_JAR
1704 if ( NULL != config->jarfile )
1706 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1708 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1709 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1711 setbuf(config->jar, NULL);
1713 #endif /* def FEATURE_COOKIE_JAR */
1715 if ( NULL == config->haddr )
1717 config->haddr = strdup( HADDR_DEFAULT );
1720 if ( NULL != config->haddr )
1722 if (NULL != (p = strchr(config->haddr, ':')))
1727 config->hport = atoi(p);
1731 if (config->hport <= 0)
1734 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1735 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1737 if (*config->haddr == '\0')
1740 * Only the port specified. We stored it in config->hport
1741 * and don't need its text representation anymore.
1743 freez(config->haddr);
1748 * Want to run all the loaders once now.
1750 * Need to set up a fake csp, so they can get to the config.
1752 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1753 fake_csp->config = config;
1755 if (run_loader(fake_csp))
1758 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1759 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1763 /* FIXME: this is a kludge for win32 */
1764 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1766 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1767 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1768 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1770 #ifdef FEATURE_TRUST
1771 g_trustfile = config->trustfile;
1772 #endif /* def FEATURE_TRUST */
1775 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1776 /* FIXME: end kludge */
1779 config->need_bind = 1;
1781 if (current_configfile)
1783 struct configuration_spec * oldcfg = (struct configuration_spec *)
1784 current_configfile->f;
1786 * Check if config->haddr,hport == oldcfg->haddr,hport
1788 * The following could be written more compactly as a single,
1789 * (unreadably long) if statement.
1791 config->need_bind = 0;
1792 if (config->hport != oldcfg->hport)
1794 config->need_bind = 1;
1796 else if (config->haddr == NULL)
1798 if (oldcfg->haddr != NULL)
1800 config->need_bind = 1;
1803 else if (oldcfg->haddr == NULL)
1805 config->need_bind = 1;
1807 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1809 config->need_bind = 1;
1812 current_configfile->unloader = unload_configfile;
1815 fs->next = files->next;
1818 current_configfile = fs;
1824 /*********************************************************************
1826 * Function : savearg
1828 * Description : Called from `load_config'. It saves each non-empty
1829 * and non-comment line from config into
1830 * config->proxy_args. This is used to create the
1831 * show-proxy-args page. On error, frees
1832 * config->proxy_args and sets it to NULL
1835 * 1 : command = config setting that was found
1836 * 2 : argument = the setting's argument (if any)
1837 * 3 : config = Configuration to save into.
1841 *********************************************************************/
1842 static void savearg(char *command, char *argument, struct configuration_spec * config)
1851 * Add config option name embedded in
1852 * link to its section in the user-manual
1854 buf = strdup("\n<a href=\"");
1855 if (!strncmpic(config->usermanual, "file://", 7) ||
1856 !strncmpic(config->usermanual, "http", 4))
1858 string_append(&buf, config->usermanual);
1862 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1864 string_append(&buf, CONFIG_HELP_PREFIX);
1865 string_join (&buf, string_toupper(command));
1866 string_append(&buf, "\">");
1867 string_append(&buf, command);
1868 string_append(&buf, "</a> ");
1872 freez(config->proxy_args);
1876 if ( (NULL != argument) && ('\0' != *argument) )
1878 s = html_encode(argument);
1882 freez(config->proxy_args);
1886 if (strncmpic(argument, "http://", 7) == 0)
1888 string_append(&buf, "<a href=\"");
1889 string_append(&buf, s);
1890 string_append(&buf, "\">");
1891 string_join (&buf, s);
1892 string_append(&buf, "</a>");
1896 string_join (&buf, s);
1900 string_append(&buf, "<br>");
1901 string_join(&config->proxy_args, buf);