1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.74 2008/03/26 18:07:07 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.74 2008/03/26 18:07:07 fabiankeil
39 * Add hostname directive. Closes PR#1918189.
41 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
44 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
45 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
47 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
48 * Reword "unrecognized directive" warning, use better
49 * mark up and add a <br>. Fixes parts of #1856559.
51 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
52 * Plug memory leak if listen-address only specifies the port.
54 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
55 * Relocate daemon-mode-related log messages to make sure
56 * they aren't shown again in case of configuration reloads.
58 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
59 * Plug memory leak introduced with my last commit.
61 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
62 * When in daemon mode, close stderr after the configuration file has been
63 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
65 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
66 * #1763173 from Stefan Huehner: declare unload_configfile() static.
68 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
69 * As Hal noticed, checking dispatch_cgi() as the last cruncher
70 * looks like a bug if CGI requests are blocked unintentionally,
71 * so don't do it unless the user enabled the new config option
72 * "allow-cgi-request-crunching".
74 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
75 * - Use strlcpy() instead of strcpy().
76 * - Stop treating actions files special. Expect a complete file name
77 * (with or without path) like it's done for the rest of the files.
79 * - Remove an unnecessary temporary memory allocation.
80 * - Don't log anything to the console when running as
81 * daemon and no errors occurred.
83 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
84 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
86 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
87 * New config option: enforce-blocks.
89 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
90 * - Mention other reasons why acl directive loading might have failed.
91 * - Don't log the acl source if the acl destination is to blame.
93 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
94 * Add new config option "templdir" to
95 * change the templates directory.
97 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
98 * Added config option accept-intercepted-requests
99 * and disabled it by default.
101 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
102 * Fix gcc43 compiler warnings.
104 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
105 * Add config option "split-large-forms"
106 * to work around the browser bug reported
109 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
110 * Move the <br> in the generated HTML for the config
111 * options from the beginning of the string to its end.
112 * Keeps the white space in balance.
114 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
115 * Fix memory leak in case of config file reloads.
117 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
118 * Modified kludge for win32 to make ming32 menu
119 * "Options/Edit Filters" (sort of) work again.
120 * Same limitations as for the action files apply.
123 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
124 * Incorporate modified version of Roland Rosenfeld's patch to
125 * optionally access the user-manual via Privoxy. Closes patch 679075.
127 * Formatting changed to Privoxy style, added call to
128 * cgi_error_no_template if the requested file doesn't
129 * exist and modified check whether or not Privoxy itself
130 * should serve the manual. Should work cross-platform now.
132 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
133 * Added config option enable-remote-http-toggle
134 * to specify if Privoxy should recognize special
135 * headers (currently only X-Filter) to change its
136 * behaviour. Disabled by default.
138 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
139 * Make number of retries in case of forwarded-connect problems
140 * a config file option (forwarded-connect-retries) and use 0 as
143 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
144 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
145 * with what was really the latest development (the v_3_0_branch branch)
147 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
148 * Don't forget to malloc space for the null terminator...
150 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
151 * Multiple filter file support
153 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
154 * Closed two memory leaks; hopefully the last remaining ones
155 * (in the main execution paths, anyway).
157 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
158 * Addressed bug #719435
159 * - Extraneous filterfile directives now logged as errors
160 * - This and unrecnonised directives now really obvious on status page
162 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
163 * Cosmetic: Renamed cryptic variable
165 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
166 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
168 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
169 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
171 * Revision 1.48 2002/05/14 21:30:38 oes
172 * savearg now uses own linking code instead of (now special-cased) add_help_link
174 * Revision 1.47 2002/05/12 21:36:29 jongfoster
175 * Correcting function comments
177 * Revision 1.46 2002/04/26 12:55:14 oes
178 * - New option "user-manual", defaults to our site
179 * via project.h #define
180 * - savearg now embeds option names in help links
182 * Revision 1.45 2002/04/24 02:11:54 oes
183 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
185 * Revision 1.44 2002/04/08 20:37:13 swa
188 * Revision 1.43 2002/04/08 20:36:50 swa
191 * Revision 1.42 2002/04/05 15:50:15 oes
192 * fix for invalid HTML proxy_args
194 * Revision 1.41 2002/03/31 17:19:00 jongfoster
195 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
197 * Revision 1.40 2002/03/26 22:29:55 swa
198 * we have a new homepage!
200 * Revision 1.39 2002/03/24 13:25:43 swa
201 * name change related issues
203 * Revision 1.38 2002/03/24 13:05:48 jongfoster
204 * Renaming re_filterfile to filterfile
206 * Revision 1.37 2002/03/16 23:54:06 jongfoster
207 * Adding graceful termination feature, to help look for memory leaks.
208 * If you enable this (which, by design, has to be done by hand
209 * editing config.h) and then go to http://i.j.b/die, then the program
210 * will exit cleanly after the *next* request. It should free all the
211 * memory that was used.
213 * Revision 1.36 2002/03/13 00:27:05 jongfoster
216 * Revision 1.35 2002/03/07 03:52:44 oes
217 * Set logging to tty for --no-daemon mode
219 * Revision 1.34 2002/03/06 23:14:35 jongfoster
220 * Trivial cosmetic changes to make function comments easier to find.
222 * Revision 1.33 2002/03/05 04:52:42 oes
223 * Deleted non-errlog debugging code
225 * Revision 1.32 2002/03/04 18:24:53 oes
226 * Re-enabled output of unknown config directive hash
228 * Revision 1.31 2002/03/03 15:07:20 oes
229 * Re-enabled automatic config reloading
231 * Revision 1.30 2002/01/22 23:31:43 jongfoster
232 * Replacing strsav() with string_append()
234 * Revision 1.29 2002/01/17 21:02:30 jongfoster
235 * Moving all our URL and URL pattern parsing code to urlmatch.c.
237 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
239 * Revision 1.28 2001/12/30 14:07:32 steudten
240 * - Add signal handling (unix)
241 * - Add SIGHUP handler (unix)
242 * - Add creation of pidfile (unix)
243 * - Add action 'top' in rc file (RH)
244 * - Add entry 'SIGNALS' to manpage
245 * - Add exit message to logfile (unix)
247 * Revision 1.27 2001/11/07 00:02:13 steudten
248 * Add line number in error output for lineparsing for
249 * actionsfile and configfile.
250 * Special handling for CLF added.
252 * Revision 1.26 2001/11/05 21:41:43 steudten
253 * Add changes to be a real daemon just for unix os.
254 * (change cwd to /, detach from controlling tty, set
255 * process group and session leader to the own process.
257 * Add some fatal-error log message for failed malloc().
258 * Add '-d' if compiled with 'configure --with-debug' to
259 * enable debug output.
261 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
262 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
263 * threads to call select() simultaneously. So, it's time to do a real, live,
264 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
265 * (native). Both versions will work, but using __OS2__ offers multi-threading.
267 * Revision 1.24 2001/10/23 21:40:30 jongfoster
268 * Added support for enable-edit-actions and enable-remote-toggle config
271 * Revision 1.23 2001/10/07 15:36:00 oes
272 * Introduced new config option "buffer-limit"
274 * Revision 1.22 2001/09/22 16:36:59 jongfoster
275 * Removing unused parameter fs from read_config_line()
277 * Revision 1.21 2001/09/16 17:10:43 jongfoster
278 * Moving function savearg() here, since it was the only thing left in
281 * Revision 1.20 2001/07/30 22:08:36 jongfoster
282 * Tidying up #defines:
283 * - All feature #defines are now of the form FEATURE_xxx
284 * - Permanently turned off WIN_GUI_EDIT
285 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
287 * Revision 1.19 2001/07/15 17:45:16 jongfoster
288 * Removing some unused #includes
290 * Revision 1.18 2001/07/13 14:01:14 oes
291 * - Removed all #ifdef PCRS
292 * - Removed vim-settings
294 * Revision 1.17 2001/06/29 13:31:03 oes
295 * - Improved comments
296 * - Fixed (actionsfile) and sorted hashes
297 * - Introduced admin_address and proxy-info-url
298 * as config parameters
299 * - Renamed config->proxy_args_invocation (which didn't have
300 * the invocation but the options!) to config->proxy_args
301 * - Various adaptions
302 * - Removed logentry from cancelled commit
304 * Revision 1.16 2001/06/09 10:55:28 jongfoster
305 * Changing BUFSIZ ==> BUFFER_SIZE
307 * Revision 1.15 2001/06/07 23:13:40 jongfoster
308 * Merging ACL and forward files into config file.
309 * Cosmetic: Sorting config file options alphabetically.
310 * Cosmetic: Adding brief syntax comments to config file options.
312 * Revision 1.14 2001/06/07 14:46:25 joergs
313 * Missing make_path() added for re_filterfile.
315 * Revision 1.13 2001/06/05 22:33:54 jongfoster
317 * Fixed minor memory leak.
318 * Also now uses make_path to prepend the pathnames.
320 * Revision 1.12 2001/06/05 20:04:09 jongfoster
321 * Now uses _snprintf() in place of snprintf() under Win32.
323 * Revision 1.11 2001/06/04 18:31:58 swa
324 * files are now prefixed with either `confdir' or `logdir'.
325 * `make redhat-dist' replaces both entries confdir and logdir
328 * Revision 1.10 2001/06/03 19:11:54 oes
329 * introduced confdir option
331 * Revision 1.9 2001/06/01 20:06:24 jongfoster
332 * Removed support for "tinygif" option - moved to actions file.
334 * Revision 1.8 2001/05/31 21:27:13 jongfoster
335 * Removed many options from the config file and into the
336 * "actions" file: add_forwarded, suppress_vanilla_wafer,
337 * wafer, add_header, user_agent, referer, from
338 * Also globally replaced "permission" with "action".
340 * Revision 1.7 2001/05/29 09:50:24 jongfoster
341 * Unified blocklist/imagelist/permissionslist.
342 * File format is still under discussion, but the internal changes
345 * Also modified interceptor behaviour:
346 * - We now intercept all URLs beginning with one of the following
347 * prefixes (and *only* these prefixes):
349 * * http://ijbswa.sf.net/config/
350 * * http://ijbswa.sourceforge.net/config/
351 * - New interceptors "home page" - go to http://i.j.b/ to see it.
352 * - Internal changes so that intercepted and fast redirect pages
353 * are not replaced with an image.
354 * - Interceptors now have the option to send a binary page direct
355 * to the client. (i.e. ijb-send-banner uses this)
356 * - Implemented show-url-info interceptor. (Which is why I needed
357 * the above interceptors changes - a typical URL is
358 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
359 * The previous mechanism would not have intercepted that, and
360 * if it had been intercepted then it then it would have replaced
363 * Revision 1.6 2001/05/26 00:28:36 jongfoster
364 * Automatic reloading of config file.
365 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
366 * Most of the global variables have been moved to a new
367 * struct configuration_spec, accessed through csp->config->globalname
368 * Most of the globals remaining are used by the Win32 GUI.
370 * Revision 1.5 2001/05/25 22:34:30 jongfoster
373 * Revision 1.4 2001/05/22 18:46:04 oes
375 * - Enabled filtering banners by size rather than URL
376 * by adding patterns that replace all standard banner
377 * sizes with the "Junkbuster" gif to the re_filterfile
379 * - Enabled filtering WebBugs by providing a pattern
380 * which kills all 1x1 images
382 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
383 * which is selected by the (nonstandard and therefore
384 * capital) letter 'U' in the option string.
385 * It causes the quantifiers to be ungreedy by default.
386 * Appending a ? turns back to greedy (!).
388 * - Added a new interceptor ijb-send-banner, which
389 * sends back the "Junkbuster" gif. Without imagelist or
390 * MSIE detection support, or if tinygif = 1, or the
391 * URL isn't recognized as an imageurl, a lame HTML
392 * explanation is sent instead.
394 * - Added new feature, which permits blocking remote
395 * script redirects and firing back a local redirect
397 * The feature is conditionally compiled, i.e. it
398 * can be disabled with --disable-fast-redirects,
399 * plus it must be activated by a "fast-redirects"
400 * line in the config file, has its own log level
401 * and of course wants to be displayed by show-proxy-args
402 * Note: Boy, all the #ifdefs in 1001 locations and
403 * all the fumbling with configure.in and acconfig.h
404 * were *way* more work than the feature itself :-(
406 * - Because a generic redirect template was needed for
407 * this, tinygif = 3 now uses the same.
409 * - Moved GIFs, and other static HTTP response templates
414 * - Removed some >400 CRs again (Jon, you really worked
417 * Revision 1.3 2001/05/20 01:21:20 jongfoster
418 * Version 2.9.4 checkin.
419 * - Merged popupfile and cookiefile, and added control over PCRS
420 * filtering, in new "permissionsfile".
421 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
422 * file error you now get a message box (in the Win32 GUI) rather
423 * than the program exiting with no explanation.
424 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
426 * - Removed tabs from "config"
427 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
428 * - Bumped up version number.
430 * Revision 1.2 2001/05/17 23:01:01 oes
431 * - Cleaned CRLF's from the sources and related files
433 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
434 * Initial import of version 2.9.3 source tree
437 *********************************************************************/
443 #include <sys/types.h>
457 # include <windows.h>
460 # ifndef _WIN_CONSOLE
462 # endif /* ndef _WIN_CONSOLE */
464 #else /* ifndef _WIN32 */
468 # include <sys/wait.h>
470 # include <sys/time.h>
471 # include <sys/stat.h>
481 #include "miscutil.h"
485 #include "urlmatch.h"
488 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
491 * Fix a problem with Solaris. There should be no effect on other
493 * Solaris's isspace() is a macro which uses it's argument directly
494 * as an array index. Therefore we need to make sure that high-bit
495 * characters generate +ve values, and ideally we also want to make
496 * the argument match the declared parameter type of "int".
498 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
499 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
501 #ifdef FEATURE_TOGGLE
502 /* Privoxy is enabled by default. */
503 int global_toggle_state = 1;
504 #endif /* def FEATURE_TOGGLE */
506 /* The filename of the configfile */
507 const char *configfile = NULL;
510 * CGI functions will later need access to the invocation args,
511 * so we will make argc and argv global.
514 const char **Argv = NULL;
516 static struct file_list *current_configfile = NULL;
520 * This takes the "cryptic" hash of each keyword and aliases them to
521 * something a little more readable. This also makes changing the
522 * hash values easier if they should change or the hash algorthm changes.
523 * Use the included "hash" program to find out what the hash will be
524 * for any string supplied on the command line. (Or just put it in the
525 * config file and read the number from the error message in the log).
527 * Please keep this list sorted alphabetically (but with the Windows
528 * console and GUI specific options last).
531 #define hash_actions_file 1196306641ul /* "actionsfile" */
532 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
533 #define hash_admin_address 4112573064ul /* "admin-address" */
534 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
535 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
536 #define hash_confdir 1978389ul /* "confdir" */
537 #define hash_debug 78263ul /* "debug" */
538 #define hash_deny_access 1227333715ul /* "deny-access" */
539 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
540 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
541 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
542 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
543 #define hash_filterfile 250887266ul /* "filterfile" */
544 #define hash_forward 2029845ul /* "forward" */
545 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
546 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
547 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
548 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
549 #define hash_hostname 10308071ul /* "hostname" */
550 #define hash_jarfile 2046641ul /* "jarfile" */
551 #define hash_listen_address 1255650842ul /* "listen-address" */
552 #define hash_logdir 422889ul /* "logdir" */
553 #define hash_logfile 2114766ul /* "logfile" */
554 #define hash_permit_access 3587953268ul /* "permit-access" */
555 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
556 #define hash_single_threaded 4250084780ul /* "single-threaded" */
557 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
558 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
559 #define hash_templdir 11067889ul /* "templdir" */
560 #define hash_toggle 447966ul /* "toggle" */
561 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
562 #define hash_trustfile 56494766ul /* "trustfile" */
563 #define hash_usermanual 1416668518ul /* "user-manual" */
564 #define hash_activity_animation 1817904738ul /* "activity-animation" */
565 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
566 #define hash_hide_console 2048809870ul /* "hide-console" */
567 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
568 #define hash_log_font_name 2866730124ul /* "log-font-name" */
569 #define hash_log_font_size 2866731014ul /* "log-font-size" */
570 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
571 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
572 #define hash_log_messages 2291744899ul /* "log-messages" */
573 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
576 static void savearg(char *command, char *argument, struct configuration_spec * config);
578 /*********************************************************************
580 * Function : unload_configfile
582 * Description : Free the config structure and all components.
585 * 1 : data: struct configuration_spec to unload
589 *********************************************************************/
590 static void unload_configfile (void * data)
592 struct configuration_spec * config = (struct configuration_spec *)data;
593 struct forward_spec *cur_fwd = config->forward;
597 struct access_control_list *cur_acl = config->acl;
599 while (cur_acl != NULL)
601 struct access_control_list * next_acl = cur_acl->next;
606 #endif /* def FEATURE_ACL */
608 while (cur_fwd != NULL)
610 struct forward_spec * next_fwd = cur_fwd->next;
611 free_url_spec(cur_fwd->url);
613 freez(cur_fwd->gateway_host);
614 freez(cur_fwd->forward_host);
618 config->forward = NULL;
620 #ifdef FEATURE_COOKIE_JAR
621 if ( NULL != config->jar )
623 fclose( config->jar );
626 #endif /* def FEATURE_COOKIE_JAR */
628 freez(config->confdir);
629 freez(config->logdir);
630 freez(config->templdir);
631 freez(config->hostname);
633 freez(config->haddr);
634 freez(config->logfile);
636 for (i = 0; i < MAX_AF_FILES; i++)
638 freez(config->actions_file_short[i]);
639 freez(config->actions_file[i]);
640 freez(config->re_filterfile_short[i]);
641 freez(config->re_filterfile[i]);
644 freez(config->admin_address);
645 freez(config->proxy_info_url);
646 freez(config->proxy_args);
647 freez(config->usermanual);
649 #ifdef FEATURE_COOKIE_JAR
650 freez(config->jarfile);
651 #endif /* def FEATURE_COOKIE_JAR */
654 freez(config->trustfile);
655 list_remove_all(config->trust_info);
656 #endif /* def FEATURE_TRUST */
658 for (i = 0; i < MAX_AF_FILES; i++)
660 freez(config->re_filterfile[i]);
667 #ifdef FEATURE_GRACEFUL_TERMINATION
668 /*********************************************************************
670 * Function : unload_current_config_file
672 * Description : Unloads current config file - reset to state at
673 * beginning of program.
679 *********************************************************************/
680 void unload_current_config_file(void)
682 if (current_configfile)
684 current_configfile->unloader = unload_configfile;
685 current_configfile = NULL;
691 /*********************************************************************
693 * Function : load_config
695 * Description : Load the config file and all parameters.
697 * XXX: more than thousand lines long
698 * and thus in serious need of refactoring.
702 * Returns : The configuration_spec, or NULL on error.
704 *********************************************************************/
705 struct configuration_spec * load_config(void)
707 char buf[BUFFER_SIZE];
709 FILE *configfp = NULL;
710 struct configuration_spec * config = NULL;
711 struct client_state * fake_csp;
712 struct file_list *fs;
713 unsigned long linenum = 0;
715 char *logfile = NULL;
717 if ( !check_file_changed(current_configfile, configfile, &fs))
719 /* No need to load */
720 return ((struct configuration_spec *)current_configfile->f);
724 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
728 if (NULL != current_configfile)
730 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
733 #ifdef FEATURE_TOGGLE
734 global_toggle_state = 1;
735 #endif /* def FEATURE_TOGGLE */
737 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
743 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
744 /* Never get here - LOG_LEVEL_FATAL causes program exit */
748 * This is backwards from how it's usually done.
749 * Following the usual pattern, "fs" would be stored in a member
750 * variable in "csp", and then we'd access "config" from "fs->f",
751 * using a cast. However, "config" is used so often that a
752 * cast each time would be very ugly, and the extra indirection
753 * would waste CPU cycles. Therefore we store "config" in
754 * "csp->config", and "fs" in "csp->config->config_file_list".
756 config->config_file_list = fs;
761 config->multi_threaded = 1;
762 config->hport = HADDR_PORT;
763 config->buffer_limit = 4096 * 1024;
764 config->usermanual = strdup(USER_MANUAL_URL);
765 config->proxy_args = strdup("");
766 config->forwarded_connect_retries = 0;
767 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
768 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
769 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
771 if ((configfp = fopen(configfile, "r")) == NULL)
773 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
775 /* Never get here - LOG_LEVEL_FATAL causes program exit */
778 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
780 char cmd[BUFFER_SIZE];
781 char arg[BUFFER_SIZE];
782 char tmp[BUFFER_SIZE];
784 struct access_control_list *cur_acl;
785 #endif /* def FEATURE_ACL */
786 struct forward_spec *cur_fwd;
789 unsigned long directive_hash;
791 strlcpy(tmp, buf, sizeof(tmp));
793 /* Copy command (i.e. up to space or tab) into cmd */
796 while (*p && (*p != ' ') && (*p != '\t'))
802 /* Skip over the whitespace in buf */
803 while (*p && ((*p == ' ') || (*p == '\t')))
808 /* Copy the argument into arg */
809 strlcpy(arg, p, sizeof(arg));
811 /* Should never happen, but check this anyway */
817 /* Make sure the command field is lower case */
822 *p = (char)ijb_tolower(*p);
826 /* Save the argument for show-proxy-args */
827 savearg(cmd, arg, config);
829 directive_hash = hash_string(cmd);
830 switch (directive_hash)
832 /* *************************************************************************
833 * actionsfile actions-file-name
834 * In confdir by default
835 * *************************************************************************/
836 case hash_actions_file :
838 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
843 if (i >= MAX_AF_FILES)
845 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
846 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
849 config->actions_file_short[i] = strdup(arg);
850 config->actions_file[i] = make_path(config->confdir, arg);
853 /* *************************************************************************
854 * accept-intercepted-requests
855 * *************************************************************************/
856 case hash_accept_intercepted_requests:
857 if ((*arg != '\0') && (0 != atoi(arg)))
859 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
863 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
867 /* *************************************************************************
868 * admin-address email-address
869 * *************************************************************************/
870 case hash_admin_address :
871 freez(config->admin_address);
872 config->admin_address = strdup(arg);
875 /* *************************************************************************
876 * allow-cgi-request-crunching
877 * *************************************************************************/
878 case hash_allow_cgi_request_crunching:
879 if ((*arg != '\0') && (0 != atoi(arg)))
881 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
885 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
889 /* *************************************************************************
891 * *************************************************************************/
892 case hash_buffer_limit :
893 config->buffer_limit = (size_t)(1024 * atoi(arg));
896 /* *************************************************************************
897 * confdir directory-name
898 * *************************************************************************/
900 freez(config->confdir);
901 config->confdir = make_path( NULL, arg);
904 /* *************************************************************************
906 * Specifies debug level, multiple values are ORed together.
907 * *************************************************************************/
909 config->debug |= atoi(arg);
912 /* *************************************************************************
913 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
914 * *************************************************************************/
916 case hash_deny_access:
917 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
919 if ((vec_count != 1) && (vec_count != 2))
921 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
922 "deny-access directive in configuration file.");
923 string_append(&config->proxy_args,
924 "<br>\nWARNING: Wrong number of parameters for "
925 "deny-access directive in configuration file.<br><br>\n");
929 /* allocate a new node */
930 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
934 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
935 /* Never get here - LOG_LEVEL_FATAL causes program exit */
938 cur_acl->action = ACL_DENY;
940 if (acl_addr(vec[0], cur_acl->src) < 0)
942 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
943 "for deny-access directive in configuration file: \"%s\"", vec[0]);
944 string_append(&config->proxy_args,
945 "<br>\nWARNING: Invalid source address, port or netmask "
946 "for deny-access directive in configuration file: \"");
947 string_append(&config->proxy_args,
949 string_append(&config->proxy_args,
956 if (acl_addr(vec[1], cur_acl->dst) < 0)
958 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
959 "for deny-access directive in configuration file: \"%s\"", vec[1]);
960 string_append(&config->proxy_args,
961 "<br>\nWARNING: Invalid destination address, port or netmask "
962 "for deny-access directive in configuration file: \"");
963 string_append(&config->proxy_args,
965 string_append(&config->proxy_args,
973 * Add it to the list. Note we reverse the list to get the
974 * behaviour the user expects. With both the ACL and
975 * actions file, the last match wins. However, the internal
976 * implementations are different: The actions file is stored
977 * in the same order as the file, and scanned completely.
978 * With the ACL, we reverse the order as we load it, then
979 * when we scan it we stop as soon as we get a match.
981 cur_acl->next = config->acl;
982 config->acl = cur_acl;
985 #endif /* def FEATURE_ACL */
987 /* *************************************************************************
988 * enable-edit-actions 0|1
989 * *************************************************************************/
990 #ifdef FEATURE_CGI_EDIT_ACTIONS
991 case hash_enable_edit_actions:
992 if ((*arg != '\0') && (0 != atoi(arg)))
994 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
998 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1001 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1003 /* *************************************************************************
1004 * enable-remote-toggle 0|1
1005 * *************************************************************************/
1006 #ifdef FEATURE_CGI_EDIT_ACTIONS
1007 case hash_enable_remote_toggle:
1008 if ((*arg != '\0') && (0 != atoi(arg)))
1010 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1014 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1017 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1019 /* *************************************************************************
1020 * enable-remote-http-toggle 0|1
1021 * *************************************************************************/
1022 case hash_enable_remote_http_toggle:
1023 if ((*arg != '\0') && (0 != atoi(arg)))
1025 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1029 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1033 /* *************************************************************************
1034 * hash_enforce_blocks 0|1
1035 * *************************************************************************/
1036 #ifdef FEATURE_FORCE_LOAD
1037 case hash_enforce_blocks:
1038 if ((*arg != '\0') && (0 != atoi(arg)))
1040 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1044 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1047 #endif /* def FEATURE_FORCE_LOAD */
1049 /* *************************************************************************
1050 * filterfile file-name
1051 * In confdir by default.
1052 * *************************************************************************/
1053 case hash_filterfile :
1055 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1060 if (i >= MAX_AF_FILES)
1062 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1063 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1066 config->re_filterfile_short[i] = strdup(arg);
1067 config->re_filterfile[i] = make_path(config->confdir, arg);
1071 /* *************************************************************************
1072 * forward url-pattern (.|http-proxy-host[:port])
1073 * *************************************************************************/
1075 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1079 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1080 "directive in configuration file.");
1081 string_append(&config->proxy_args,
1082 "<br>\nWARNING: Wrong number of parameters for "
1083 "forward directive in configuration file.");
1087 /* allocate a new node */
1088 cur_fwd = zalloc(sizeof(*cur_fwd));
1089 if (cur_fwd == NULL)
1091 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1092 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1096 cur_fwd->type = SOCKS_NONE;
1098 /* Save the URL pattern */
1099 if (create_url_spec(cur_fwd->url, vec[0]))
1101 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1102 "directive in configuration file.");
1103 string_append(&config->proxy_args,
1104 "<br>\nWARNING: Bad URL specifier for "
1105 "forward directive in configuration file.");
1109 /* Parse the parent HTTP proxy host:port */
1112 if (strcmp(p, ".") != 0)
1114 cur_fwd->forward_host = strdup(p);
1116 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1119 cur_fwd->forward_port = atoi(p);
1122 if (cur_fwd->forward_port <= 0)
1124 cur_fwd->forward_port = 8000;
1129 cur_fwd->next = config->forward;
1130 config->forward = cur_fwd;
1134 /* *************************************************************************
1135 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1136 * *************************************************************************/
1137 case hash_forward_socks4:
1138 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1142 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1143 "forward-socks4 directive in configuration file.");
1144 string_append(&config->proxy_args,
1145 "<br>\nWARNING: Wrong number of parameters for "
1146 "forward-socks4 directive in configuration file.");
1150 /* allocate a new node */
1151 cur_fwd = zalloc(sizeof(*cur_fwd));
1152 if (cur_fwd == NULL)
1154 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1155 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1159 cur_fwd->type = SOCKS_4;
1161 /* Save the URL pattern */
1162 if (create_url_spec(cur_fwd->url, vec[0]))
1164 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1165 "directive in configuration file.");
1166 string_append(&config->proxy_args,
1167 "<br>\nWARNING: Bad URL specifier for "
1168 "forward-socks4 directive in configuration file.");
1172 /* Parse the SOCKS proxy host[:port] */
1175 if (strcmp(p, ".") != 0)
1177 cur_fwd->gateway_host = strdup(p);
1179 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1182 cur_fwd->gateway_port = atoi(p);
1184 if (cur_fwd->gateway_port <= 0)
1186 cur_fwd->gateway_port = 1080;
1190 /* Parse the parent HTTP proxy host[:port] */
1193 if (strcmp(p, ".") != 0)
1195 cur_fwd->forward_host = strdup(p);
1197 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1200 cur_fwd->forward_port = atoi(p);
1203 if (cur_fwd->forward_port <= 0)
1205 cur_fwd->forward_port = 8000;
1210 cur_fwd->next = config->forward;
1211 config->forward = cur_fwd;
1215 /* *************************************************************************
1216 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1217 * *************************************************************************/
1218 case hash_forward_socks4a:
1219 case hash_forward_socks5:
1220 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1224 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1225 "forward-socks4a directive in configuration file.");
1226 string_append(&config->proxy_args,
1227 "<br>\nWARNING: Wrong number of parameters for "
1228 "forward-socks4a directive in configuration file.");
1232 /* allocate a new node */
1233 cur_fwd = zalloc(sizeof(*cur_fwd));
1234 if (cur_fwd == NULL)
1236 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1237 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1241 if (directive_hash == hash_forward_socks4a)
1243 cur_fwd->type = SOCKS_4A;
1247 cur_fwd->type = SOCKS_5;
1250 /* Save the URL pattern */
1251 if (create_url_spec(cur_fwd->url, vec[0]))
1253 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1254 "directive in configuration file.");
1255 string_append(&config->proxy_args,
1256 "<br>\nWARNING: Bad URL specifier for "
1257 "forward-socks4a directive in configuration file.");
1261 /* Parse the SOCKS proxy host[:port] */
1264 cur_fwd->gateway_host = strdup(p);
1266 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1269 cur_fwd->gateway_port = atoi(p);
1271 if (cur_fwd->gateway_port <= 0)
1273 cur_fwd->gateway_port = 1080;
1276 /* Parse the parent HTTP proxy host[:port] */
1279 if (strcmp(p, ".") != 0)
1281 cur_fwd->forward_host = strdup(p);
1283 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1286 cur_fwd->forward_port = atoi(p);
1289 if (cur_fwd->forward_port <= 0)
1291 cur_fwd->forward_port = 8000;
1296 cur_fwd->next = config->forward;
1297 config->forward = cur_fwd;
1301 /* *************************************************************************
1302 * forwarded-connect-retries n
1303 * *************************************************************************/
1304 case hash_forwarded_connect_retries :
1305 config->forwarded_connect_retries = atoi(arg);
1308 /* *************************************************************************
1309 * hostname hostname-to-show-on-cgi-pages
1310 * *************************************************************************/
1311 case hash_hostname :
1312 freez(config->hostname);
1313 config->hostname = strdup(arg);
1314 if (NULL == config->hostname)
1316 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1320 /* *************************************************************************
1321 * jarfile jar-file-name
1322 * In logdir by default
1323 * *************************************************************************/
1324 #ifdef FEATURE_COOKIE_JAR
1326 freez(config->jarfile);
1327 config->jarfile = make_path(config->logdir, arg);
1329 #endif /* def FEATURE_COOKIE_JAR */
1331 /* *************************************************************************
1332 * listen-address [ip][:port]
1333 * *************************************************************************/
1334 case hash_listen_address :
1335 freez(config->haddr);
1336 config->haddr = strdup(arg);
1339 /* *************************************************************************
1340 * logdir directory-name
1341 * *************************************************************************/
1343 freez(config->logdir);
1344 config->logdir = make_path(NULL, arg);
1347 /* *************************************************************************
1348 * logfile log-file-name
1349 * In logdir by default
1350 * *************************************************************************/
1354 logfile = make_path(config->logdir, arg);
1355 if (NULL == logfile)
1357 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1362 /* *************************************************************************
1363 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1364 * *************************************************************************/
1366 case hash_permit_access:
1367 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1369 if ((vec_count != 1) && (vec_count != 2))
1371 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1372 "permit-access directive in configuration file.");
1373 string_append(&config->proxy_args,
1374 "<br>\nWARNING: Wrong number of parameters for "
1375 "permit-access directive in configuration file.<br><br>\n");
1380 /* allocate a new node */
1381 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1383 if (cur_acl == NULL)
1385 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1386 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1389 cur_acl->action = ACL_PERMIT;
1391 if (acl_addr(vec[0], cur_acl->src) < 0)
1393 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1394 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1395 string_append(&config->proxy_args,
1396 "<br>\nWARNING: Invalid source address, port or netmask for "
1397 "permit-access directive in configuration file: \"");
1398 string_append(&config->proxy_args,
1400 string_append(&config->proxy_args,
1407 if (acl_addr(vec[1], cur_acl->dst) < 0)
1409 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1410 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1411 string_append(&config->proxy_args,
1412 "<br>\nWARNING: Invalid destination address, port or netmask for "
1413 "permit-access directive in configuration file: \"");
1414 string_append(&config->proxy_args,
1416 string_append(&config->proxy_args,
1424 * Add it to the list. Note we reverse the list to get the
1425 * behaviour the user expects. With both the ACL and
1426 * actions file, the last match wins. However, the internal
1427 * implementations are different: The actions file is stored
1428 * in the same order as the file, and scanned completely.
1429 * With the ACL, we reverse the order as we load it, then
1430 * when we scan it we stop as soon as we get a match.
1432 cur_acl->next = config->acl;
1433 config->acl = cur_acl;
1436 #endif /* def FEATURE_ACL */
1438 /* *************************************************************************
1439 * proxy-info-url url
1440 * *************************************************************************/
1441 case hash_proxy_info_url :
1442 freez(config->proxy_info_url);
1443 config->proxy_info_url = strdup(arg);
1446 /* *************************************************************************
1448 * *************************************************************************/
1449 case hash_single_threaded :
1450 config->multi_threaded = 0;
1453 /* *************************************************************************
1454 * split-large-cgi-forms
1455 * *************************************************************************/
1456 case hash_split_large_cgi_forms :
1457 if ((*arg != '\0') && (0 != atoi(arg)))
1459 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1463 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1467 /* *************************************************************************
1468 * templdir directory-name
1469 * *************************************************************************/
1470 case hash_templdir :
1471 freez(config->templdir);
1472 config->templdir = make_path(NULL, arg);
1475 /* *************************************************************************
1477 * *************************************************************************/
1478 #ifdef FEATURE_TOGGLE
1480 global_toggle_state = atoi(arg);
1482 #endif /* def FEATURE_TOGGLE */
1484 /* *************************************************************************
1485 * trust-info-url url
1486 * *************************************************************************/
1487 #ifdef FEATURE_TRUST
1488 case hash_trust_info_url :
1489 enlist(config->trust_info, arg);
1491 #endif /* def FEATURE_TRUST */
1493 /* *************************************************************************
1494 * trustfile filename
1495 * (In confdir by default.)
1496 * *************************************************************************/
1497 #ifdef FEATURE_TRUST
1498 case hash_trustfile :
1499 freez(config->trustfile);
1500 config->trustfile = make_path(config->confdir, arg);
1502 #endif /* def FEATURE_TRUST */
1504 /* *************************************************************************
1506 * *************************************************************************/
1507 case hash_usermanual :
1508 freez(config->usermanual);
1509 config->usermanual = strdup(arg);
1512 /* *************************************************************************
1513 * Win32 Console options:
1514 * *************************************************************************/
1516 /* *************************************************************************
1518 * *************************************************************************/
1520 case hash_hide_console :
1523 #endif /*def _WIN_CONSOLE*/
1526 /* *************************************************************************
1527 * Win32 GUI options:
1528 * *************************************************************************/
1530 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1531 /* *************************************************************************
1532 * activity-animation (0|1)
1533 * *************************************************************************/
1534 case hash_activity_animation :
1535 g_bShowActivityAnimation = atoi(arg);
1538 /* *************************************************************************
1539 * close-button-minimizes (0|1)
1540 * *************************************************************************/
1541 case hash_close_button_minimizes :
1542 g_bCloseHidesWindow = atoi(arg);
1545 /* *************************************************************************
1546 * log-buffer-size (0|1)
1547 * *************************************************************************/
1548 case hash_log_buffer_size :
1549 g_bLimitBufferSize = atoi(arg);
1552 /* *************************************************************************
1553 * log-font-name fontnane
1554 * *************************************************************************/
1555 case hash_log_font_name :
1556 strcpy( g_szFontFaceName, arg );
1559 /* *************************************************************************
1561 * *************************************************************************/
1562 case hash_log_font_size :
1563 g_nFontSize = atoi(arg);
1566 /* *************************************************************************
1567 * log-highlight-messages (0|1)
1568 * *************************************************************************/
1569 case hash_log_highlight_messages :
1570 g_bHighlightMessages = atoi(arg);
1573 /* *************************************************************************
1575 * *************************************************************************/
1576 case hash_log_max_lines :
1577 g_nMaxBufferLines = atoi(arg);
1580 /* *************************************************************************
1581 * log-messages (0|1)
1582 * *************************************************************************/
1583 case hash_log_messages :
1584 g_bLogMessages = atoi(arg);
1587 /* *************************************************************************
1588 * show-on-task-bar (0|1)
1589 * *************************************************************************/
1590 case hash_show_on_task_bar :
1591 g_bShowOnTaskBar = atoi(arg);
1594 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1597 /* *************************************************************************
1598 * Warnings about unsupported features
1599 * *************************************************************************/
1601 case hash_deny_access:
1602 #endif /* ndef FEATURE_ACL */
1603 #ifndef FEATURE_CGI_EDIT_ACTIONS
1604 case hash_enable_edit_actions:
1605 case hash_enable_remote_toggle:
1606 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1607 #ifndef FEATURE_COOKIE_JAR
1609 #endif /* ndef FEATURE_COOKIE_JAR */
1611 case hash_permit_access:
1612 #endif /* ndef FEATURE_ACL */
1613 #ifndef FEATURE_TOGGLE
1615 #endif /* ndef FEATURE_TOGGLE */
1616 #ifndef FEATURE_TRUST
1617 case hash_trustfile :
1618 case hash_trust_info_url :
1619 #endif /* ndef FEATURE_TRUST */
1621 #ifndef _WIN_CONSOLE
1622 case hash_hide_console :
1623 #endif /* ndef _WIN_CONSOLE */
1625 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1626 case hash_activity_animation :
1627 case hash_close_button_minimizes :
1628 case hash_log_buffer_size :
1629 case hash_log_font_name :
1630 case hash_log_font_size :
1631 case hash_log_highlight_messages :
1632 case hash_log_max_lines :
1633 case hash_log_messages :
1634 case hash_show_on_task_bar :
1635 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1636 /* These warnings are annoying - so hide them. -- Jon */
1637 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1640 /* *************************************************************************/
1642 /* *************************************************************************/
1644 * I decided that I liked this better as a warning than an
1645 * error. To change back to an error, just change log level
1646 * to LOG_LEVEL_FATAL.
1648 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1649 "in configuration file (%s).", buf, hash_string(cmd), linenum, configfile);
1650 string_append(&config->proxy_args,
1651 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1654 /* *************************************************************************/
1655 } /* end switch( hash_string(cmd) ) */
1656 } /* end while ( read_config_line(...) ) */
1660 set_debug_level(config->debug);
1662 freez(config->logfile);
1666 if (NULL != logfile)
1668 config->logfile = logfile;
1669 init_error_log(Argv[0], config->logfile);
1677 if (NULL == config->proxy_args)
1679 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1682 if (config->actions_file[0])
1684 add_loader(load_action_files, config);
1687 if (config->re_filterfile[0])
1689 add_loader(load_re_filterfiles, config);
1692 #ifdef FEATURE_TRUST
1693 if (config->trustfile)
1695 add_loader(load_trustfile, config);
1697 #endif /* def FEATURE_TRUST */
1699 #ifdef FEATURE_COOKIE_JAR
1700 if ( NULL != config->jarfile )
1702 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1704 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1705 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1707 setbuf(config->jar, NULL);
1709 #endif /* def FEATURE_COOKIE_JAR */
1711 if ( NULL == config->haddr )
1713 config->haddr = strdup( HADDR_DEFAULT );
1716 if ( NULL != config->haddr )
1718 if (NULL != (p = strchr(config->haddr, ':')))
1723 config->hport = atoi(p);
1727 if (config->hport <= 0)
1730 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1731 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1733 if (*config->haddr == '\0')
1736 * Only the port specified. We stored it in config->hport
1737 * and don't need its text representation anymore.
1739 freez(config->haddr);
1744 * Want to run all the loaders once now.
1746 * Need to set up a fake csp, so they can get to the config.
1748 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1749 fake_csp->config = config;
1751 if (run_loader(fake_csp))
1754 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1755 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1759 /* FIXME: this is a kludge for win32 */
1760 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1762 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1763 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1764 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1766 #ifdef FEATURE_TRUST
1767 g_trustfile = config->trustfile;
1768 #endif /* def FEATURE_TRUST */
1771 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1772 /* FIXME: end kludge */
1775 config->need_bind = 1;
1777 if (current_configfile)
1779 struct configuration_spec * oldcfg = (struct configuration_spec *)
1780 current_configfile->f;
1782 * Check if config->haddr,hport == oldcfg->haddr,hport
1784 * The following could be written more compactly as a single,
1785 * (unreadably long) if statement.
1787 config->need_bind = 0;
1788 if (config->hport != oldcfg->hport)
1790 config->need_bind = 1;
1792 else if (config->haddr == NULL)
1794 if (oldcfg->haddr != NULL)
1796 config->need_bind = 1;
1799 else if (oldcfg->haddr == NULL)
1801 config->need_bind = 1;
1803 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1805 config->need_bind = 1;
1808 current_configfile->unloader = unload_configfile;
1811 fs->next = files->next;
1814 current_configfile = fs;
1820 /*********************************************************************
1822 * Function : savearg
1824 * Description : Called from `load_config'. It saves each non-empty
1825 * and non-comment line from config into
1826 * config->proxy_args. This is used to create the
1827 * show-proxy-args page. On error, frees
1828 * config->proxy_args and sets it to NULL
1831 * 1 : command = config setting that was found
1832 * 2 : argument = the setting's argument (if any)
1833 * 3 : config = Configuration to save into.
1837 *********************************************************************/
1838 static void savearg(char *command, char *argument, struct configuration_spec * config)
1848 * Add config option name embedded in
1849 * link to its section in the user-manual
1851 buf = strdup("\n<a href=\"");
1852 if (!strncmpic(config->usermanual, "file://", 7) ||
1853 !strncmpic(config->usermanual, "http", 4))
1855 string_append(&buf, config->usermanual);
1859 string_append(&buf, "http://");
1860 string_append(&buf, CGI_SITE_2_HOST);
1861 string_append(&buf, "/user-manual/");
1863 string_append(&buf, CONFIG_HELP_PREFIX);
1864 string_join (&buf, string_toupper(command));
1865 string_append(&buf, "\">");
1866 string_append(&buf, command);
1867 string_append(&buf, "</a> ");
1871 freez(config->proxy_args);
1875 if ( (NULL != argument) && ('\0' != *argument) )
1877 s = html_encode(argument);
1881 freez(config->proxy_args);
1885 if (strncmpic(argument, "http://", 7) == 0)
1887 string_append(&buf, "<a href=\"");
1888 string_append(&buf, s);
1889 string_append(&buf, "\">");
1890 string_join (&buf, s);
1891 string_append(&buf, "</a>");
1895 string_join (&buf, s);
1899 string_append(&buf, "<br>");
1900 string_join(&config->proxy_args, buf);