1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.66 2007/08/05 14:02:09 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-2007 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.66 2007/08/05 14:02:09 fabiankeil
39 * #1763173 from Stefan Huehner: declare unload_configfile() static.
41 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
42 * As Hal noticed, checking dispatch_cgi() as the last cruncher
43 * looks like a bug if CGI requests are blocked unintentionally,
44 * so don't do it unless the user enabled the new config option
45 * "allow-cgi-request-crunching".
47 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
48 * - Use strlcpy() instead of strcpy().
49 * - Stop treating actions files special. Expect a complete file name
50 * (with or without path) like it's done for the rest of the files.
52 * - Remove an unnecessary temporary memory allocation.
53 * - Don't log anything to the console when running as
54 * daemon and no errors occurred.
56 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
57 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
59 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
60 * New config option: enforce-blocks.
62 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
63 * - Mention other reasons why acl directive loading might have failed.
64 * - Don't log the acl source if the acl destination is to blame.
66 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
67 * Add new config option "templdir" to
68 * change the templates directory.
70 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
71 * Added config option accept-intercepted-requests
72 * and disabled it by default.
74 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
75 * Fix gcc43 compiler warnings.
77 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
78 * Add config option "split-large-forms"
79 * to work around the browser bug reported
82 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
83 * Move the <br> in the generated HTML for the config
84 * options from the beginning of the string to its end.
85 * Keeps the white space in balance.
87 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
88 * Fix memory leak in case of config file reloads.
90 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
91 * Modified kludge for win32 to make ming32 menu
92 * "Options/Edit Filters" (sort of) work again.
93 * Same limitations as for the action files apply.
96 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
97 * Incorporate modified version of Roland Rosenfeld's patch to
98 * optionally access the user-manual via Privoxy. Closes patch 679075.
100 * Formatting changed to Privoxy style, added call to
101 * cgi_error_no_template if the requested file doesn't
102 * exist and modified check whether or not Privoxy itself
103 * should serve the manual. Should work cross-platform now.
105 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
106 * Added config option enable-remote-http-toggle
107 * to specify if Privoxy should recognize special
108 * headers (currently only X-Filter) to change its
109 * behaviour. Disabled by default.
111 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
112 * Make number of retries in case of forwarded-connect problems
113 * a config file option (forwarded-connect-retries) and use 0 as
116 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
117 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
118 * with what was really the latest development (the v_3_0_branch branch)
120 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
121 * Don't forget to malloc space for the null terminator...
123 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
124 * Multiple filter file support
126 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
127 * Closed two memory leaks; hopefully the last remaining ones
128 * (in the main execution paths, anyway).
130 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
131 * Addressed bug #719435
132 * - Extraneous filterfile directives now logged as errors
133 * - This and unrecnonised directives now really obvious on status page
135 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
136 * Cosmetic: Renamed cryptic variable
138 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
139 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
141 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
142 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
144 * Revision 1.48 2002/05/14 21:30:38 oes
145 * savearg now uses own linking code instead of (now special-cased) add_help_link
147 * Revision 1.47 2002/05/12 21:36:29 jongfoster
148 * Correcting function comments
150 * Revision 1.46 2002/04/26 12:55:14 oes
151 * - New option "user-manual", defaults to our site
152 * via project.h #define
153 * - savearg now embeds option names in help links
155 * Revision 1.45 2002/04/24 02:11:54 oes
156 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
158 * Revision 1.44 2002/04/08 20:37:13 swa
161 * Revision 1.43 2002/04/08 20:36:50 swa
164 * Revision 1.42 2002/04/05 15:50:15 oes
165 * fix for invalid HTML proxy_args
167 * Revision 1.41 2002/03/31 17:19:00 jongfoster
168 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
170 * Revision 1.40 2002/03/26 22:29:55 swa
171 * we have a new homepage!
173 * Revision 1.39 2002/03/24 13:25:43 swa
174 * name change related issues
176 * Revision 1.38 2002/03/24 13:05:48 jongfoster
177 * Renaming re_filterfile to filterfile
179 * Revision 1.37 2002/03/16 23:54:06 jongfoster
180 * Adding graceful termination feature, to help look for memory leaks.
181 * If you enable this (which, by design, has to be done by hand
182 * editing config.h) and then go to http://i.j.b/die, then the program
183 * will exit cleanly after the *next* request. It should free all the
184 * memory that was used.
186 * Revision 1.36 2002/03/13 00:27:05 jongfoster
189 * Revision 1.35 2002/03/07 03:52:44 oes
190 * Set logging to tty for --no-daemon mode
192 * Revision 1.34 2002/03/06 23:14:35 jongfoster
193 * Trivial cosmetic changes to make function comments easier to find.
195 * Revision 1.33 2002/03/05 04:52:42 oes
196 * Deleted non-errlog debugging code
198 * Revision 1.32 2002/03/04 18:24:53 oes
199 * Re-enabled output of unknown config directive hash
201 * Revision 1.31 2002/03/03 15:07:20 oes
202 * Re-enabled automatic config reloading
204 * Revision 1.30 2002/01/22 23:31:43 jongfoster
205 * Replacing strsav() with string_append()
207 * Revision 1.29 2002/01/17 21:02:30 jongfoster
208 * Moving all our URL and URL pattern parsing code to urlmatch.c.
210 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
212 * Revision 1.28 2001/12/30 14:07:32 steudten
213 * - Add signal handling (unix)
214 * - Add SIGHUP handler (unix)
215 * - Add creation of pidfile (unix)
216 * - Add action 'top' in rc file (RH)
217 * - Add entry 'SIGNALS' to manpage
218 * - Add exit message to logfile (unix)
220 * Revision 1.27 2001/11/07 00:02:13 steudten
221 * Add line number in error output for lineparsing for
222 * actionsfile and configfile.
223 * Special handling for CLF added.
225 * Revision 1.26 2001/11/05 21:41:43 steudten
226 * Add changes to be a real daemon just for unix os.
227 * (change cwd to /, detach from controlling tty, set
228 * process group and session leader to the own process.
230 * Add some fatal-error log message for failed malloc().
231 * Add '-d' if compiled with 'configure --with-debug' to
232 * enable debug output.
234 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
235 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
236 * threads to call select() simultaneously. So, it's time to do a real, live,
237 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
238 * (native). Both versions will work, but using __OS2__ offers multi-threading.
240 * Revision 1.24 2001/10/23 21:40:30 jongfoster
241 * Added support for enable-edit-actions and enable-remote-toggle config
244 * Revision 1.23 2001/10/07 15:36:00 oes
245 * Introduced new config option "buffer-limit"
247 * Revision 1.22 2001/09/22 16:36:59 jongfoster
248 * Removing unused parameter fs from read_config_line()
250 * Revision 1.21 2001/09/16 17:10:43 jongfoster
251 * Moving function savearg() here, since it was the only thing left in
254 * Revision 1.20 2001/07/30 22:08:36 jongfoster
255 * Tidying up #defines:
256 * - All feature #defines are now of the form FEATURE_xxx
257 * - Permanently turned off WIN_GUI_EDIT
258 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
260 * Revision 1.19 2001/07/15 17:45:16 jongfoster
261 * Removing some unused #includes
263 * Revision 1.18 2001/07/13 14:01:14 oes
264 * - Removed all #ifdef PCRS
265 * - Removed vim-settings
267 * Revision 1.17 2001/06/29 13:31:03 oes
268 * - Improved comments
269 * - Fixed (actionsfile) and sorted hashes
270 * - Introduced admin_address and proxy-info-url
271 * as config parameters
272 * - Renamed config->proxy_args_invocation (which didn't have
273 * the invocation but the options!) to config->proxy_args
274 * - Various adaptions
275 * - Removed logentry from cancelled commit
277 * Revision 1.16 2001/06/09 10:55:28 jongfoster
278 * Changing BUFSIZ ==> BUFFER_SIZE
280 * Revision 1.15 2001/06/07 23:13:40 jongfoster
281 * Merging ACL and forward files into config file.
282 * Cosmetic: Sorting config file options alphabetically.
283 * Cosmetic: Adding brief syntax comments to config file options.
285 * Revision 1.14 2001/06/07 14:46:25 joergs
286 * Missing make_path() added for re_filterfile.
288 * Revision 1.13 2001/06/05 22:33:54 jongfoster
290 * Fixed minor memory leak.
291 * Also now uses make_path to prepend the pathnames.
293 * Revision 1.12 2001/06/05 20:04:09 jongfoster
294 * Now uses _snprintf() in place of snprintf() under Win32.
296 * Revision 1.11 2001/06/04 18:31:58 swa
297 * files are now prefixed with either `confdir' or `logdir'.
298 * `make redhat-dist' replaces both entries confdir and logdir
301 * Revision 1.10 2001/06/03 19:11:54 oes
302 * introduced confdir option
304 * Revision 1.9 2001/06/01 20:06:24 jongfoster
305 * Removed support for "tinygif" option - moved to actions file.
307 * Revision 1.8 2001/05/31 21:27:13 jongfoster
308 * Removed many options from the config file and into the
309 * "actions" file: add_forwarded, suppress_vanilla_wafer,
310 * wafer, add_header, user_agent, referer, from
311 * Also globally replaced "permission" with "action".
313 * Revision 1.7 2001/05/29 09:50:24 jongfoster
314 * Unified blocklist/imagelist/permissionslist.
315 * File format is still under discussion, but the internal changes
318 * Also modified interceptor behaviour:
319 * - We now intercept all URLs beginning with one of the following
320 * prefixes (and *only* these prefixes):
322 * * http://ijbswa.sf.net/config/
323 * * http://ijbswa.sourceforge.net/config/
324 * - New interceptors "home page" - go to http://i.j.b/ to see it.
325 * - Internal changes so that intercepted and fast redirect pages
326 * are not replaced with an image.
327 * - Interceptors now have the option to send a binary page direct
328 * to the client. (i.e. ijb-send-banner uses this)
329 * - Implemented show-url-info interceptor. (Which is why I needed
330 * the above interceptors changes - a typical URL is
331 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
332 * The previous mechanism would not have intercepted that, and
333 * if it had been intercepted then it then it would have replaced
336 * Revision 1.6 2001/05/26 00:28:36 jongfoster
337 * Automatic reloading of config file.
338 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
339 * Most of the global variables have been moved to a new
340 * struct configuration_spec, accessed through csp->config->globalname
341 * Most of the globals remaining are used by the Win32 GUI.
343 * Revision 1.5 2001/05/25 22:34:30 jongfoster
346 * Revision 1.4 2001/05/22 18:46:04 oes
348 * - Enabled filtering banners by size rather than URL
349 * by adding patterns that replace all standard banner
350 * sizes with the "Junkbuster" gif to the re_filterfile
352 * - Enabled filtering WebBugs by providing a pattern
353 * which kills all 1x1 images
355 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
356 * which is selected by the (nonstandard and therefore
357 * capital) letter 'U' in the option string.
358 * It causes the quantifiers to be ungreedy by default.
359 * Appending a ? turns back to greedy (!).
361 * - Added a new interceptor ijb-send-banner, which
362 * sends back the "Junkbuster" gif. Without imagelist or
363 * MSIE detection support, or if tinygif = 1, or the
364 * URL isn't recognized as an imageurl, a lame HTML
365 * explanation is sent instead.
367 * - Added new feature, which permits blocking remote
368 * script redirects and firing back a local redirect
370 * The feature is conditionally compiled, i.e. it
371 * can be disabled with --disable-fast-redirects,
372 * plus it must be activated by a "fast-redirects"
373 * line in the config file, has its own log level
374 * and of course wants to be displayed by show-proxy-args
375 * Note: Boy, all the #ifdefs in 1001 locations and
376 * all the fumbling with configure.in and acconfig.h
377 * were *way* more work than the feature itself :-(
379 * - Because a generic redirect template was needed for
380 * this, tinygif = 3 now uses the same.
382 * - Moved GIFs, and other static HTTP response templates
387 * - Removed some >400 CRs again (Jon, you really worked
390 * Revision 1.3 2001/05/20 01:21:20 jongfoster
391 * Version 2.9.4 checkin.
392 * - Merged popupfile and cookiefile, and added control over PCRS
393 * filtering, in new "permissionsfile".
394 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
395 * file error you now get a message box (in the Win32 GUI) rather
396 * than the program exiting with no explanation.
397 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
399 * - Removed tabs from "config"
400 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
401 * - Bumped up version number.
403 * Revision 1.2 2001/05/17 23:01:01 oes
404 * - Cleaned CRLF's from the sources and related files
406 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
407 * Initial import of version 2.9.3 source tree
410 *********************************************************************/
416 #include <sys/types.h>
430 # include <windows.h>
433 # ifndef _WIN_CONSOLE
435 # endif /* ndef _WIN_CONSOLE */
437 #else /* ifndef _WIN32 */
441 # include <sys/wait.h>
443 # include <sys/time.h>
444 # include <sys/stat.h>
454 #include "miscutil.h"
458 #include "urlmatch.h"
461 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
464 * Fix a problem with Solaris. There should be no effect on other
466 * Solaris's isspace() is a macro which uses it's argument directly
467 * as an array index. Therefore we need to make sure that high-bit
468 * characters generate +ve values, and ideally we also want to make
469 * the argument match the declared parameter type of "int".
471 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
472 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
474 #ifdef FEATURE_TOGGLE
475 /* Privoxy is enabled by default. */
476 int global_toggle_state = 1;
477 #endif /* def FEATURE_TOGGLE */
479 /* The filename of the configfile */
480 const char *configfile = NULL;
483 * CGI functions will later need access to the invocation args,
484 * so we will make argc and argv global.
487 const char **Argv = NULL;
489 static struct file_list *current_configfile = NULL;
493 * This takes the "cryptic" hash of each keyword and aliases them to
494 * something a little more readable. This also makes changing the
495 * hash values easier if they should change or the hash algorthm changes.
496 * Use the included "hash" program to find out what the hash will be
497 * for any string supplied on the command line. (Or just put it in the
498 * config file and read the number from the error message in the log).
500 * Please keep this list sorted alphabetically (but with the Windows
501 * console and GUI specific options last).
504 #define hash_actions_file 1196306641ul /* "actionsfile" */
505 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
506 #define hash_admin_address 4112573064ul /* "admin-address" */
507 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
508 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
509 #define hash_confdir 1978389ul /* "confdir" */
510 #define hash_debug 78263ul /* "debug" */
511 #define hash_deny_access 1227333715ul /* "deny-access" */
512 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
513 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
514 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
515 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
516 #define hash_filterfile 250887266ul /* "filterfile" */
517 #define hash_forward 2029845ul /* "forward" */
518 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
519 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
520 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
521 #define hash_jarfile 2046641ul /* "jarfile" */
522 #define hash_listen_address 1255650842ul /* "listen-address" */
523 #define hash_logdir 422889ul /* "logdir" */
524 #define hash_logfile 2114766ul /* "logfile" */
525 #define hash_permit_access 3587953268ul /* "permit-access" */
526 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
527 #define hash_single_threaded 4250084780ul /* "single-threaded" */
528 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
529 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
530 #define hash_templdir 11067889ul /* "templdir" */
531 #define hash_toggle 447966ul /* "toggle" */
532 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
533 #define hash_trustfile 56494766ul /* "trustfile" */
534 #define hash_usermanual 1416668518ul /* "user-manual" */
535 #define hash_activity_animation 1817904738ul /* "activity-animation" */
536 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
537 #define hash_hide_console 2048809870ul /* "hide-console" */
538 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
539 #define hash_log_font_name 2866730124ul /* "log-font-name" */
540 #define hash_log_font_size 2866731014ul /* "log-font-size" */
541 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
542 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
543 #define hash_log_messages 2291744899ul /* "log-messages" */
544 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
547 static void savearg(char *command, char *argument, struct configuration_spec * config);
549 /*********************************************************************
551 * Function : unload_configfile
553 * Description : Free the config structure and all components.
556 * 1 : data: struct configuration_spec to unload
560 *********************************************************************/
561 static void unload_configfile (void * data)
563 struct configuration_spec * config = (struct configuration_spec *)data;
564 struct forward_spec *cur_fwd = config->forward;
568 struct access_control_list *cur_acl = config->acl;
570 while (cur_acl != NULL)
572 struct access_control_list * next_acl = cur_acl->next;
577 #endif /* def FEATURE_ACL */
579 while (cur_fwd != NULL)
581 struct forward_spec * next_fwd = cur_fwd->next;
582 free_url_spec(cur_fwd->url);
584 freez(cur_fwd->gateway_host);
585 freez(cur_fwd->forward_host);
589 config->forward = NULL;
591 #ifdef FEATURE_COOKIE_JAR
592 if ( NULL != config->jar )
594 fclose( config->jar );
597 #endif /* def FEATURE_COOKIE_JAR */
599 freez(config->confdir);
600 freez(config->logdir);
601 freez(config->templdir);
603 freez(config->haddr);
604 freez(config->logfile);
606 for (i = 0; i < MAX_AF_FILES; i++)
608 freez(config->actions_file_short[i]);
609 freez(config->actions_file[i]);
610 freez(config->re_filterfile_short[i]);
611 freez(config->re_filterfile[i]);
614 freez(config->admin_address);
615 freez(config->proxy_info_url);
616 freez(config->proxy_args);
617 freez(config->usermanual);
619 #ifdef FEATURE_COOKIE_JAR
620 freez(config->jarfile);
621 #endif /* def FEATURE_COOKIE_JAR */
624 freez(config->trustfile);
625 list_remove_all(config->trust_info);
626 #endif /* def FEATURE_TRUST */
628 for (i = 0; i < MAX_AF_FILES; i++)
630 freez(config->re_filterfile[i]);
637 #ifdef FEATURE_GRACEFUL_TERMINATION
638 /*********************************************************************
640 * Function : unload_current_config_file
642 * Description : Unloads current config file - reset to state at
643 * beginning of program.
649 *********************************************************************/
650 void unload_current_config_file(void)
652 if (current_configfile)
654 current_configfile->unloader = unload_configfile;
655 current_configfile = NULL;
661 /*********************************************************************
663 * Function : load_config
665 * Description : Load the config file and all parameters.
667 * XXX: more than thousand lines long
668 * and thus in serious need of refactoring.
672 * Returns : The configuration_spec, or NULL on error.
674 *********************************************************************/
675 struct configuration_spec * load_config(void)
677 char buf[BUFFER_SIZE];
679 FILE *configfp = NULL;
680 struct configuration_spec * config = NULL;
681 struct client_state * fake_csp;
682 struct file_list *fs;
683 unsigned long linenum = 0;
685 char *logfile = NULL;
687 if ( !check_file_changed(current_configfile, configfile, &fs))
689 /* No need to load */
690 return ((struct configuration_spec *)current_configfile->f);
694 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
698 if (NULL != current_configfile)
700 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
703 #ifdef FEATURE_TOGGLE
704 global_toggle_state = 1;
705 #endif /* def FEATURE_TOGGLE */
707 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
713 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
714 /* Never get here - LOG_LEVEL_FATAL causes program exit */
718 * This is backwards from how it's usually done.
719 * Following the usual pattern, "fs" would be stored in a member
720 * variable in "csp", and then we'd access "config" from "fs->f",
721 * using a cast. However, "config" is used so often that a
722 * cast each time would be very ugly, and the extra indirection
723 * would waste CPU cycles. Therefore we store "config" in
724 * "csp->config", and "fs" in "csp->config->config_file_list".
726 config->config_file_list = fs;
731 config->multi_threaded = 1;
732 config->hport = HADDR_PORT;
733 config->buffer_limit = 4096 * 1024;
734 config->usermanual = strdup(USER_MANUAL_URL);
735 config->proxy_args = strdup("");
736 config->forwarded_connect_retries = 0;
737 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
738 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
739 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
741 if ((configfp = fopen(configfile, "r")) == NULL)
743 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
745 /* Never get here - LOG_LEVEL_FATAL causes program exit */
748 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
750 char cmd[BUFFER_SIZE];
751 char arg[BUFFER_SIZE];
752 char tmp[BUFFER_SIZE];
754 struct access_control_list *cur_acl;
755 #endif /* def FEATURE_ACL */
756 struct forward_spec *cur_fwd;
760 strlcpy(tmp, buf, sizeof(tmp));
762 /* Copy command (i.e. up to space or tab) into cmd */
765 while (*p && (*p != ' ') && (*p != '\t'))
771 /* Skip over the whitespace in buf */
772 while (*p && ((*p == ' ') || (*p == '\t')))
777 /* Copy the argument into arg */
778 strlcpy(arg, p, sizeof(arg));
780 /* Should never happen, but check this anyway */
786 /* Make sure the command field is lower case */
791 *p = (char)ijb_tolower(*p);
795 /* Save the argument for show-proxy-args */
796 savearg(cmd, arg, config);
799 switch( hash_string( cmd ) )
801 /* *************************************************************************
802 * actionsfile actions-file-name
803 * In confdir by default
804 * *************************************************************************/
805 case hash_actions_file :
807 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
812 if (i >= MAX_AF_FILES)
814 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
815 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
818 config->actions_file_short[i] = strdup(arg);
819 config->actions_file[i] = make_path(config->confdir, arg);
822 /* *************************************************************************
823 * accept-intercepted-requests
824 * *************************************************************************/
825 case hash_accept_intercepted_requests:
826 if ((*arg != '\0') && (0 != atoi(arg)))
828 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
832 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
836 /* *************************************************************************
837 * admin-address email-address
838 * *************************************************************************/
839 case hash_admin_address :
840 freez(config->admin_address);
841 config->admin_address = strdup(arg);
844 /* *************************************************************************
845 * allow-cgi-request-crunching
846 * *************************************************************************/
847 case hash_allow_cgi_request_crunching:
848 if ((*arg != '\0') && (0 != atoi(arg)))
850 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
854 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
858 /* *************************************************************************
860 * *************************************************************************/
861 case hash_buffer_limit :
862 config->buffer_limit = (size_t)(1024 * atoi(arg));
865 /* *************************************************************************
866 * confdir directory-name
867 * *************************************************************************/
869 freez(config->confdir);
870 config->confdir = make_path( NULL, arg);
873 /* *************************************************************************
875 * Specifies debug level, multiple values are ORed together.
876 * *************************************************************************/
878 config->debug |= atoi(arg);
881 /* *************************************************************************
882 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
883 * *************************************************************************/
885 case hash_deny_access:
886 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
888 if ((vec_count != 1) && (vec_count != 2))
890 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
891 "deny-access directive in configuration file.");
892 string_append(&config->proxy_args,
893 "<br>\nWARNING: Wrong number of parameters for "
894 "deny-access directive in configuration file.<br><br>\n");
898 /* allocate a new node */
899 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
903 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
904 /* Never get here - LOG_LEVEL_FATAL causes program exit */
907 cur_acl->action = ACL_DENY;
909 if (acl_addr(vec[0], cur_acl->src) < 0)
911 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
912 "for deny-access directive in configuration file: \"%s\"", vec[0]);
913 string_append(&config->proxy_args,
914 "<br>\nWARNING: Invalid source address, port or netmask "
915 "for deny-access directive in configuration file: \"");
916 string_append(&config->proxy_args,
918 string_append(&config->proxy_args,
925 if (acl_addr(vec[1], cur_acl->dst) < 0)
927 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
928 "for deny-access directive in configuration file: \"%s\"", vec[1]);
929 string_append(&config->proxy_args,
930 "<br>\nWARNING: Invalid destination address, port or netmask "
931 "for deny-access directive in configuration file: \"");
932 string_append(&config->proxy_args,
934 string_append(&config->proxy_args,
942 * Add it to the list. Note we reverse the list to get the
943 * behaviour the user expects. With both the ACL and
944 * actions file, the last match wins. However, the internal
945 * implementations are different: The actions file is stored
946 * in the same order as the file, and scanned completely.
947 * With the ACL, we reverse the order as we load it, then
948 * when we scan it we stop as soon as we get a match.
950 cur_acl->next = config->acl;
951 config->acl = cur_acl;
954 #endif /* def FEATURE_ACL */
956 /* *************************************************************************
957 * enable-edit-actions 0|1
958 * *************************************************************************/
959 #ifdef FEATURE_CGI_EDIT_ACTIONS
960 case hash_enable_edit_actions:
961 if ((*arg != '\0') && (0 != atoi(arg)))
963 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
967 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
970 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
972 /* *************************************************************************
973 * enable-remote-toggle 0|1
974 * *************************************************************************/
975 #ifdef FEATURE_CGI_EDIT_ACTIONS
976 case hash_enable_remote_toggle:
977 if ((*arg != '\0') && (0 != atoi(arg)))
979 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
983 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
986 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
988 /* *************************************************************************
989 * enable-remote-http-toggle 0|1
990 * *************************************************************************/
991 case hash_enable_remote_http_toggle:
992 if ((*arg != '\0') && (0 != atoi(arg)))
994 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
998 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1002 /* *************************************************************************
1003 * hash_enforce_blocks 0|1
1004 * *************************************************************************/
1005 #ifdef FEATURE_FORCE_LOAD
1006 case hash_enforce_blocks:
1007 if ((*arg != '\0') && (0 != atoi(arg)))
1009 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1013 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1016 #endif /* def FEATURE_FORCE_LOAD */
1018 /* *************************************************************************
1019 * filterfile file-name
1020 * In confdir by default.
1021 * *************************************************************************/
1022 case hash_filterfile :
1024 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1029 if (i >= MAX_AF_FILES)
1031 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1032 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1035 config->re_filterfile_short[i] = strdup(arg);
1036 config->re_filterfile[i] = make_path(config->confdir, arg);
1040 /* *************************************************************************
1041 * forward url-pattern (.|http-proxy-host[:port])
1042 * *************************************************************************/
1044 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1048 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1049 "directive in configuration file.");
1050 string_append(&config->proxy_args,
1051 "<br>\nWARNING: Wrong number of parameters for "
1052 "forward directive in configuration file.");
1056 /* allocate a new node */
1057 cur_fwd = zalloc(sizeof(*cur_fwd));
1058 if (cur_fwd == NULL)
1060 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1061 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1065 cur_fwd->type = SOCKS_NONE;
1067 /* Save the URL pattern */
1068 if (create_url_spec(cur_fwd->url, vec[0]))
1070 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1071 "directive in configuration file.");
1072 string_append(&config->proxy_args,
1073 "<br>\nWARNING: Bad URL specifier for "
1074 "forward directive in configuration file.");
1078 /* Parse the parent HTTP proxy host:port */
1081 if (strcmp(p, ".") != 0)
1083 cur_fwd->forward_host = strdup(p);
1085 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1088 cur_fwd->forward_port = atoi(p);
1091 if (cur_fwd->forward_port <= 0)
1093 cur_fwd->forward_port = 8000;
1098 cur_fwd->next = config->forward;
1099 config->forward = cur_fwd;
1103 /* *************************************************************************
1104 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1105 * *************************************************************************/
1106 case hash_forward_socks4:
1107 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1111 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1112 "forward-socks4 directive in configuration file.");
1113 string_append(&config->proxy_args,
1114 "<br>\nWARNING: Wrong number of parameters for "
1115 "forward-socks4 directive in configuration file.");
1119 /* allocate a new node */
1120 cur_fwd = zalloc(sizeof(*cur_fwd));
1121 if (cur_fwd == NULL)
1123 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1124 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1128 cur_fwd->type = SOCKS_4;
1130 /* Save the URL pattern */
1131 if (create_url_spec(cur_fwd->url, vec[0]))
1133 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1134 "directive in configuration file.");
1135 string_append(&config->proxy_args,
1136 "<br>\nWARNING: Bad URL specifier for "
1137 "forward-socks4 directive in configuration file.");
1141 /* Parse the SOCKS proxy host[:port] */
1144 if (strcmp(p, ".") != 0)
1146 cur_fwd->gateway_host = strdup(p);
1148 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1151 cur_fwd->gateway_port = atoi(p);
1153 if (cur_fwd->gateway_port <= 0)
1155 cur_fwd->gateway_port = 1080;
1159 /* Parse the parent HTTP proxy host[:port] */
1162 if (strcmp(p, ".") != 0)
1164 cur_fwd->forward_host = strdup(p);
1166 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1169 cur_fwd->forward_port = atoi(p);
1172 if (cur_fwd->forward_port <= 0)
1174 cur_fwd->forward_port = 8000;
1179 cur_fwd->next = config->forward;
1180 config->forward = cur_fwd;
1184 /* *************************************************************************
1185 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1186 * *************************************************************************/
1187 case hash_forward_socks4a:
1188 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1192 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1193 "forward-socks4a directive in configuration file.");
1194 string_append(&config->proxy_args,
1195 "<br>\nWARNING: Wrong number of parameters for "
1196 "forward-socks4a directive in configuration file.");
1200 /* allocate a new node */
1201 cur_fwd = zalloc(sizeof(*cur_fwd));
1202 if (cur_fwd == NULL)
1204 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1205 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1209 cur_fwd->type = SOCKS_4A;
1211 /* Save the URL pattern */
1212 if (create_url_spec(cur_fwd->url, vec[0]))
1214 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1215 "directive in configuration file.");
1216 string_append(&config->proxy_args,
1217 "<br>\nWARNING: Bad URL specifier for "
1218 "forward-socks4a directive in configuration file.");
1222 /* Parse the SOCKS proxy host[:port] */
1225 cur_fwd->gateway_host = strdup(p);
1227 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1230 cur_fwd->gateway_port = atoi(p);
1232 if (cur_fwd->gateway_port <= 0)
1234 cur_fwd->gateway_port = 1080;
1237 /* Parse the parent HTTP proxy host[:port] */
1240 if (strcmp(p, ".") != 0)
1242 cur_fwd->forward_host = strdup(p);
1244 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1247 cur_fwd->forward_port = atoi(p);
1250 if (cur_fwd->forward_port <= 0)
1252 cur_fwd->forward_port = 8000;
1257 cur_fwd->next = config->forward;
1258 config->forward = cur_fwd;
1262 /* *************************************************************************
1263 * forwarded-connect-retries n
1264 * *************************************************************************/
1265 case hash_forwarded_connect_retries :
1266 config->forwarded_connect_retries = atoi(arg);
1269 /* *************************************************************************
1270 * jarfile jar-file-name
1271 * In logdir by default
1272 * *************************************************************************/
1273 #ifdef FEATURE_COOKIE_JAR
1275 freez(config->jarfile);
1276 config->jarfile = make_path(config->logdir, arg);
1278 #endif /* def FEATURE_COOKIE_JAR */
1280 /* *************************************************************************
1281 * listen-address [ip][:port]
1282 * *************************************************************************/
1283 case hash_listen_address :
1284 freez(config->haddr);
1285 config->haddr = strdup(arg);
1288 /* *************************************************************************
1289 * logdir directory-name
1290 * *************************************************************************/
1292 freez(config->logdir);
1293 config->logdir = make_path(NULL, arg);
1296 /* *************************************************************************
1297 * logfile log-file-name
1298 * In logdir by default
1299 * *************************************************************************/
1301 logfile = make_path(config->logdir, arg);
1302 if (NULL == logfile)
1304 log_error(LOG_LEVEL_FATAL, "Out of memore while creating logfile path");
1308 /* *************************************************************************
1309 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1310 * *************************************************************************/
1312 case hash_permit_access:
1313 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1315 if ((vec_count != 1) && (vec_count != 2))
1317 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1318 "permit-access directive in configuration file.");
1319 string_append(&config->proxy_args,
1320 "<br>\nWARNING: Wrong number of parameters for "
1321 "permit-access directive in configuration file.<br><br>\n");
1326 /* allocate a new node */
1327 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1329 if (cur_acl == NULL)
1331 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1332 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1335 cur_acl->action = ACL_PERMIT;
1337 if (acl_addr(vec[0], cur_acl->src) < 0)
1339 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1340 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1341 string_append(&config->proxy_args,
1342 "<br>\nWARNING: Invalid source address, port or netmask for "
1343 "permit-access directive in configuration file: \"");
1344 string_append(&config->proxy_args,
1346 string_append(&config->proxy_args,
1353 if (acl_addr(vec[1], cur_acl->dst) < 0)
1355 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1356 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1357 string_append(&config->proxy_args,
1358 "<br>\nWARNING: Invalid destination address, port or netmask for "
1359 "permit-access directive in configuration file: \"");
1360 string_append(&config->proxy_args,
1362 string_append(&config->proxy_args,
1370 * Add it to the list. Note we reverse the list to get the
1371 * behaviour the user expects. With both the ACL and
1372 * actions file, the last match wins. However, the internal
1373 * implementations are different: The actions file is stored
1374 * in the same order as the file, and scanned completely.
1375 * With the ACL, we reverse the order as we load it, then
1376 * when we scan it we stop as soon as we get a match.
1378 cur_acl->next = config->acl;
1379 config->acl = cur_acl;
1382 #endif /* def FEATURE_ACL */
1384 /* *************************************************************************
1385 * proxy-info-url url
1386 * *************************************************************************/
1387 case hash_proxy_info_url :
1388 freez(config->proxy_info_url);
1389 config->proxy_info_url = strdup(arg);
1392 /* *************************************************************************
1394 * *************************************************************************/
1395 case hash_single_threaded :
1396 config->multi_threaded = 0;
1399 /* *************************************************************************
1400 * split-large-cgi-forms
1401 * *************************************************************************/
1402 case hash_split_large_cgi_forms :
1403 if ((*arg != '\0') && (0 != atoi(arg)))
1405 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1409 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1413 /* *************************************************************************
1414 * templdir directory-name
1415 * *************************************************************************/
1416 case hash_templdir :
1417 freez(config->templdir);
1418 config->templdir = make_path(NULL, arg);
1421 /* *************************************************************************
1423 * *************************************************************************/
1424 #ifdef FEATURE_TOGGLE
1426 global_toggle_state = atoi(arg);
1428 #endif /* def FEATURE_TOGGLE */
1430 /* *************************************************************************
1431 * trust-info-url url
1432 * *************************************************************************/
1433 #ifdef FEATURE_TRUST
1434 case hash_trust_info_url :
1435 enlist(config->trust_info, arg);
1437 #endif /* def FEATURE_TRUST */
1439 /* *************************************************************************
1440 * trustfile filename
1441 * (In confdir by default.)
1442 * *************************************************************************/
1443 #ifdef FEATURE_TRUST
1444 case hash_trustfile :
1445 freez(config->trustfile);
1446 config->trustfile = make_path(config->confdir, arg);
1448 #endif /* def FEATURE_TRUST */
1450 /* *************************************************************************
1452 * *************************************************************************/
1453 case hash_usermanual :
1454 freez(config->usermanual);
1455 config->usermanual = strdup(arg);
1458 /* *************************************************************************
1459 * Win32 Console options:
1460 * *************************************************************************/
1462 /* *************************************************************************
1464 * *************************************************************************/
1466 case hash_hide_console :
1469 #endif /*def _WIN_CONSOLE*/
1472 /* *************************************************************************
1473 * Win32 GUI options:
1474 * *************************************************************************/
1476 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1477 /* *************************************************************************
1478 * activity-animation (0|1)
1479 * *************************************************************************/
1480 case hash_activity_animation :
1481 g_bShowActivityAnimation = atoi(arg);
1484 /* *************************************************************************
1485 * close-button-minimizes (0|1)
1486 * *************************************************************************/
1487 case hash_close_button_minimizes :
1488 g_bCloseHidesWindow = atoi(arg);
1491 /* *************************************************************************
1492 * log-buffer-size (0|1)
1493 * *************************************************************************/
1494 case hash_log_buffer_size :
1495 g_bLimitBufferSize = atoi(arg);
1498 /* *************************************************************************
1499 * log-font-name fontnane
1500 * *************************************************************************/
1501 case hash_log_font_name :
1502 strcpy( g_szFontFaceName, arg );
1505 /* *************************************************************************
1507 * *************************************************************************/
1508 case hash_log_font_size :
1509 g_nFontSize = atoi(arg);
1512 /* *************************************************************************
1513 * log-highlight-messages (0|1)
1514 * *************************************************************************/
1515 case hash_log_highlight_messages :
1516 g_bHighlightMessages = atoi(arg);
1519 /* *************************************************************************
1521 * *************************************************************************/
1522 case hash_log_max_lines :
1523 g_nMaxBufferLines = atoi(arg);
1526 /* *************************************************************************
1527 * log-messages (0|1)
1528 * *************************************************************************/
1529 case hash_log_messages :
1530 g_bLogMessages = atoi(arg);
1533 /* *************************************************************************
1534 * show-on-task-bar (0|1)
1535 * *************************************************************************/
1536 case hash_show_on_task_bar :
1537 g_bShowOnTaskBar = atoi(arg);
1540 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1543 /* *************************************************************************
1544 * Warnings about unsupported features
1545 * *************************************************************************/
1547 case hash_deny_access:
1548 #endif /* ndef FEATURE_ACL */
1549 #ifndef FEATURE_CGI_EDIT_ACTIONS
1550 case hash_enable_edit_actions:
1551 case hash_enable_remote_toggle:
1552 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1553 #ifndef FEATURE_COOKIE_JAR
1555 #endif /* ndef FEATURE_COOKIE_JAR */
1557 case hash_permit_access:
1558 #endif /* ndef FEATURE_ACL */
1559 #ifndef FEATURE_TOGGLE
1561 #endif /* ndef FEATURE_TOGGLE */
1562 #ifndef FEATURE_TRUST
1563 case hash_trustfile :
1564 case hash_trust_info_url :
1565 #endif /* ndef FEATURE_TRUST */
1567 #ifndef _WIN_CONSOLE
1568 case hash_hide_console :
1569 #endif /* ndef _WIN_CONSOLE */
1571 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1572 case hash_activity_animation :
1573 case hash_close_button_minimizes :
1574 case hash_log_buffer_size :
1575 case hash_log_font_name :
1576 case hash_log_font_size :
1577 case hash_log_highlight_messages :
1578 case hash_log_max_lines :
1579 case hash_log_messages :
1580 case hash_show_on_task_bar :
1581 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1582 /* These warnings are annoying - so hide them. -- Jon */
1583 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1586 /* *************************************************************************/
1588 /* *************************************************************************/
1590 * I decided that I liked this better as a warning than an
1591 * error. To change back to an error, just change log level
1592 * to LOG_LEVEL_FATAL.
1594 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1595 "in configuration file (%s).", buf, hash_string(cmd), linenum, configfile);
1596 string_append(&config->proxy_args,
1597 " <b><font color=\"red\">WARNING: unrecognized directive, ignored</font></b>");
1600 /* *************************************************************************/
1601 } /* end switch( hash_string(cmd) ) */
1602 } /* end while ( read_config_line(...) ) */
1606 set_debug_level(config->debug);
1608 freez(config->logfile);
1612 if (NULL != logfile)
1614 config->logfile = logfile;
1615 log_error(LOG_LEVEL_INFO,
1616 "Switching to daemon mode. Log messages will be written to: %s", config->logfile);
1617 init_error_log(Argv[0], config->logfile);
1621 log_error(LOG_LEVEL_INFO, "No logfile configured while in daemon mode. Logging disabled.");
1626 if (NULL == config->proxy_args)
1628 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1631 if (config->actions_file[0])
1633 add_loader(load_actions_file, config);
1636 if (config->re_filterfile)
1638 add_loader(load_re_filterfile, config);
1641 #ifdef FEATURE_TRUST
1642 if (config->trustfile)
1644 add_loader(load_trustfile, config);
1646 #endif /* def FEATURE_TRUST */
1648 #ifdef FEATURE_COOKIE_JAR
1649 if ( NULL != config->jarfile )
1651 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1653 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1654 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1656 setbuf(config->jar, NULL);
1658 #endif /* def FEATURE_COOKIE_JAR */
1660 if ( NULL == config->haddr )
1662 config->haddr = strdup( HADDR_DEFAULT );
1665 if ( NULL != config->haddr )
1667 if (NULL != (p = strchr(config->haddr, ':')))
1672 config->hport = atoi(p);
1676 if (config->hport <= 0)
1679 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1680 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1682 if (*config->haddr == '\0')
1684 config->haddr = NULL;
1689 * Want to run all the loaders once now.
1691 * Need to set up a fake csp, so they can get to the config.
1693 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1694 fake_csp->config = config;
1696 if (run_loader(fake_csp))
1699 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1700 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1704 /* FIXME: this is a kludge for win32 */
1705 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1707 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1708 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1709 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1711 #ifdef FEATURE_TRUST
1712 g_trustfile = config->trustfile;
1713 #endif /* def FEATURE_TRUST */
1716 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1717 /* FIXME: end kludge */
1720 config->need_bind = 1;
1722 if (current_configfile)
1724 struct configuration_spec * oldcfg = (struct configuration_spec *)
1725 current_configfile->f;
1727 * Check if config->haddr,hport == oldcfg->haddr,hport
1729 * The following could be written more compactly as a single,
1730 * (unreadably long) if statement.
1732 config->need_bind = 0;
1733 if (config->hport != oldcfg->hport)
1735 config->need_bind = 1;
1737 else if (config->haddr == NULL)
1739 if (oldcfg->haddr != NULL)
1741 config->need_bind = 1;
1744 else if (oldcfg->haddr == NULL)
1746 config->need_bind = 1;
1748 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1750 config->need_bind = 1;
1753 current_configfile->unloader = unload_configfile;
1756 fs->next = files->next;
1759 current_configfile = fs;
1765 /*********************************************************************
1767 * Function : savearg
1769 * Description : Called from `load_config'. It saves each non-empty
1770 * and non-comment line from config into
1771 * config->proxy_args. This is used to create the
1772 * show-proxy-args page. On error, frees
1773 * config->proxy_args and sets it to NULL
1776 * 1 : command = config setting that was found
1777 * 2 : argument = the setting's argument (if any)
1778 * 3 : config = Configuration to save into.
1782 *********************************************************************/
1783 static void savearg(char *command, char *argument, struct configuration_spec * config)
1793 * Add config option name embedded in
1794 * link to it's section in the user-manual
1796 buf = strdup("\n<a href=\"");
1797 if (!strncmpic(config->usermanual, "file://", 7) ||
1798 !strncmpic(config->usermanual, "http", 4))
1800 string_append(&buf, config->usermanual);
1804 string_append(&buf, "http://");
1805 string_append(&buf, CGI_SITE_2_HOST);
1806 string_append(&buf, "/user-manual/");
1808 string_append(&buf, CONFIG_HELP_PREFIX);
1809 string_join (&buf, string_toupper(command));
1810 string_append(&buf, "\">");
1811 string_append(&buf, command);
1812 string_append(&buf, "</a> ");
1816 freez(config->proxy_args);
1820 if ( (NULL != argument) && ('\0' != *argument) )
1822 s = html_encode(argument);
1826 freez(config->proxy_args);
1830 if (strncmpic(argument, "http://", 7) == 0)
1832 string_append(&buf, "<a href=\"");
1833 string_append(&buf, s);
1834 string_append(&buf, "\">");
1835 string_join (&buf, s);
1836 string_append(&buf, "</a>");
1840 string_join (&buf, s);
1844 string_append(&buf, "<br>");
1845 string_join(&config->proxy_args, buf);