1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.62 2007/03/17 15:20:05 fabiankeil Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
6 * Purpose : Loads settings from the configuration file into
7 * global variables. This file contains both the
8 * routine to load the configuration and the global
9 * variables it writes to.
11 * Copyright : Written by and Copyright (C) 2001-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.62 2007/03/17 15:20:05 fabiankeil
39 * New config option: enforce-blocks.
41 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
42 * - Mention other reasons why acl directive loading might have failed.
43 * - Don't log the acl source if the acl destination is to blame.
45 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
46 * Add new config option "templdir" to
47 * change the templates directory.
49 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
50 * Added config option accept-intercepted-requests
51 * and disabled it by default.
53 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
54 * Fix gcc43 compiler warnings.
56 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
57 * Add config option "split-large-forms"
58 * to work around the browser bug reported
61 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
62 * Move the <br> in the generated HTML for the config
63 * options from the beginning of the string to its end.
64 * Keeps the white space in balance.
66 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
67 * Fix memory leak in case of config file reloads.
69 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
70 * Modified kludge for win32 to make ming32 menu
71 * "Options/Edit Filters" (sort of) work again.
72 * Same limitations as for the action files apply.
75 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
76 * Incorporate modified version of Roland Rosenfeld's patch to
77 * optionally access the user-manual via Privoxy. Closes patch 679075.
79 * Formatting changed to Privoxy style, added call to
80 * cgi_error_no_template if the requested file doesn't
81 * exist and modified check whether or not Privoxy itself
82 * should serve the manual. Should work cross-platform now.
84 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
85 * Added config option enable-remote-http-toggle
86 * to specify if Privoxy should recognize special
87 * headers (currently only X-Filter) to change its
88 * behaviour. Disabled by default.
90 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
91 * Make number of retries in case of forwarded-connect problems
92 * a config file option (forwarded-connect-retries) and use 0 as
95 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
96 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
97 * with what was really the latest development (the v_3_0_branch branch)
99 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
100 * Don't forget to malloc space for the null terminator...
102 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
103 * Multiple filter file support
105 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
106 * Closed two memory leaks; hopefully the last remaining ones
107 * (in the main execution paths, anyway).
109 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
110 * Addressed bug #719435
111 * - Extraneous filterfile directives now logged as errors
112 * - This and unrecnonised directives now really obvious on status page
114 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
115 * Cosmetic: Renamed cryptic variable
117 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
118 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
120 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
121 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
123 * Revision 1.48 2002/05/14 21:30:38 oes
124 * savearg now uses own linking code instead of (now special-cased) add_help_link
126 * Revision 1.47 2002/05/12 21:36:29 jongfoster
127 * Correcting function comments
129 * Revision 1.46 2002/04/26 12:55:14 oes
130 * - New option "user-manual", defaults to our site
131 * via project.h #define
132 * - savearg now embeds option names in help links
134 * Revision 1.45 2002/04/24 02:11:54 oes
135 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
137 * Revision 1.44 2002/04/08 20:37:13 swa
140 * Revision 1.43 2002/04/08 20:36:50 swa
143 * Revision 1.42 2002/04/05 15:50:15 oes
144 * fix for invalid HTML proxy_args
146 * Revision 1.41 2002/03/31 17:19:00 jongfoster
147 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
149 * Revision 1.40 2002/03/26 22:29:55 swa
150 * we have a new homepage!
152 * Revision 1.39 2002/03/24 13:25:43 swa
153 * name change related issues
155 * Revision 1.38 2002/03/24 13:05:48 jongfoster
156 * Renaming re_filterfile to filterfile
158 * Revision 1.37 2002/03/16 23:54:06 jongfoster
159 * Adding graceful termination feature, to help look for memory leaks.
160 * If you enable this (which, by design, has to be done by hand
161 * editing config.h) and then go to http://i.j.b/die, then the program
162 * will exit cleanly after the *next* request. It should free all the
163 * memory that was used.
165 * Revision 1.36 2002/03/13 00:27:05 jongfoster
168 * Revision 1.35 2002/03/07 03:52:44 oes
169 * Set logging to tty for --no-daemon mode
171 * Revision 1.34 2002/03/06 23:14:35 jongfoster
172 * Trivial cosmetic changes to make function comments easier to find.
174 * Revision 1.33 2002/03/05 04:52:42 oes
175 * Deleted non-errlog debugging code
177 * Revision 1.32 2002/03/04 18:24:53 oes
178 * Re-enabled output of unknown config directive hash
180 * Revision 1.31 2002/03/03 15:07:20 oes
181 * Re-enabled automatic config reloading
183 * Revision 1.30 2002/01/22 23:31:43 jongfoster
184 * Replacing strsav() with string_append()
186 * Revision 1.29 2002/01/17 21:02:30 jongfoster
187 * Moving all our URL and URL pattern parsing code to urlmatch.c.
189 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
191 * Revision 1.28 2001/12/30 14:07:32 steudten
192 * - Add signal handling (unix)
193 * - Add SIGHUP handler (unix)
194 * - Add creation of pidfile (unix)
195 * - Add action 'top' in rc file (RH)
196 * - Add entry 'SIGNALS' to manpage
197 * - Add exit message to logfile (unix)
199 * Revision 1.27 2001/11/07 00:02:13 steudten
200 * Add line number in error output for lineparsing for
201 * actionsfile and configfile.
202 * Special handling for CLF added.
204 * Revision 1.26 2001/11/05 21:41:43 steudten
205 * Add changes to be a real daemon just for unix os.
206 * (change cwd to /, detach from controlling tty, set
207 * process group and session leader to the own process.
209 * Add some fatal-error log message for failed malloc().
210 * Add '-d' if compiled with 'configure --with-debug' to
211 * enable debug output.
213 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
214 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
215 * threads to call select() simultaneously. So, it's time to do a real, live,
216 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
217 * (native). Both versions will work, but using __OS2__ offers multi-threading.
219 * Revision 1.24 2001/10/23 21:40:30 jongfoster
220 * Added support for enable-edit-actions and enable-remote-toggle config
223 * Revision 1.23 2001/10/07 15:36:00 oes
224 * Introduced new config option "buffer-limit"
226 * Revision 1.22 2001/09/22 16:36:59 jongfoster
227 * Removing unused parameter fs from read_config_line()
229 * Revision 1.21 2001/09/16 17:10:43 jongfoster
230 * Moving function savearg() here, since it was the only thing left in
233 * Revision 1.20 2001/07/30 22:08:36 jongfoster
234 * Tidying up #defines:
235 * - All feature #defines are now of the form FEATURE_xxx
236 * - Permanently turned off WIN_GUI_EDIT
237 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
239 * Revision 1.19 2001/07/15 17:45:16 jongfoster
240 * Removing some unused #includes
242 * Revision 1.18 2001/07/13 14:01:14 oes
243 * - Removed all #ifdef PCRS
244 * - Removed vim-settings
246 * Revision 1.17 2001/06/29 13:31:03 oes
247 * - Improved comments
248 * - Fixed (actionsfile) and sorted hashes
249 * - Introduced admin_address and proxy-info-url
250 * as config parameters
251 * - Renamed config->proxy_args_invocation (which didn't have
252 * the invocation but the options!) to config->proxy_args
253 * - Various adaptions
254 * - Removed logentry from cancelled commit
256 * Revision 1.16 2001/06/09 10:55:28 jongfoster
257 * Changing BUFSIZ ==> BUFFER_SIZE
259 * Revision 1.15 2001/06/07 23:13:40 jongfoster
260 * Merging ACL and forward files into config file.
261 * Cosmetic: Sorting config file options alphabetically.
262 * Cosmetic: Adding brief syntax comments to config file options.
264 * Revision 1.14 2001/06/07 14:46:25 joergs
265 * Missing make_path() added for re_filterfile.
267 * Revision 1.13 2001/06/05 22:33:54 jongfoster
269 * Fixed minor memory leak.
270 * Also now uses make_path to prepend the pathnames.
272 * Revision 1.12 2001/06/05 20:04:09 jongfoster
273 * Now uses _snprintf() in place of snprintf() under Win32.
275 * Revision 1.11 2001/06/04 18:31:58 swa
276 * files are now prefixed with either `confdir' or `logdir'.
277 * `make redhat-dist' replaces both entries confdir and logdir
280 * Revision 1.10 2001/06/03 19:11:54 oes
281 * introduced confdir option
283 * Revision 1.9 2001/06/01 20:06:24 jongfoster
284 * Removed support for "tinygif" option - moved to actions file.
286 * Revision 1.8 2001/05/31 21:27:13 jongfoster
287 * Removed many options from the config file and into the
288 * "actions" file: add_forwarded, suppress_vanilla_wafer,
289 * wafer, add_header, user_agent, referer, from
290 * Also globally replaced "permission" with "action".
292 * Revision 1.7 2001/05/29 09:50:24 jongfoster
293 * Unified blocklist/imagelist/permissionslist.
294 * File format is still under discussion, but the internal changes
297 * Also modified interceptor behaviour:
298 * - We now intercept all URLs beginning with one of the following
299 * prefixes (and *only* these prefixes):
301 * * http://ijbswa.sf.net/config/
302 * * http://ijbswa.sourceforge.net/config/
303 * - New interceptors "home page" - go to http://i.j.b/ to see it.
304 * - Internal changes so that intercepted and fast redirect pages
305 * are not replaced with an image.
306 * - Interceptors now have the option to send a binary page direct
307 * to the client. (i.e. ijb-send-banner uses this)
308 * - Implemented show-url-info interceptor. (Which is why I needed
309 * the above interceptors changes - a typical URL is
310 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
311 * The previous mechanism would not have intercepted that, and
312 * if it had been intercepted then it then it would have replaced
315 * Revision 1.6 2001/05/26 00:28:36 jongfoster
316 * Automatic reloading of config file.
317 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
318 * Most of the global variables have been moved to a new
319 * struct configuration_spec, accessed through csp->config->globalname
320 * Most of the globals remaining are used by the Win32 GUI.
322 * Revision 1.5 2001/05/25 22:34:30 jongfoster
325 * Revision 1.4 2001/05/22 18:46:04 oes
327 * - Enabled filtering banners by size rather than URL
328 * by adding patterns that replace all standard banner
329 * sizes with the "Junkbuster" gif to the re_filterfile
331 * - Enabled filtering WebBugs by providing a pattern
332 * which kills all 1x1 images
334 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
335 * which is selected by the (nonstandard and therefore
336 * capital) letter 'U' in the option string.
337 * It causes the quantifiers to be ungreedy by default.
338 * Appending a ? turns back to greedy (!).
340 * - Added a new interceptor ijb-send-banner, which
341 * sends back the "Junkbuster" gif. Without imagelist or
342 * MSIE detection support, or if tinygif = 1, or the
343 * URL isn't recognized as an imageurl, a lame HTML
344 * explanation is sent instead.
346 * - Added new feature, which permits blocking remote
347 * script redirects and firing back a local redirect
349 * The feature is conditionally compiled, i.e. it
350 * can be disabled with --disable-fast-redirects,
351 * plus it must be activated by a "fast-redirects"
352 * line in the config file, has its own log level
353 * and of course wants to be displayed by show-proxy-args
354 * Note: Boy, all the #ifdefs in 1001 locations and
355 * all the fumbling with configure.in and acconfig.h
356 * were *way* more work than the feature itself :-(
358 * - Because a generic redirect template was needed for
359 * this, tinygif = 3 now uses the same.
361 * - Moved GIFs, and other static HTTP response templates
366 * - Removed some >400 CRs again (Jon, you really worked
369 * Revision 1.3 2001/05/20 01:21:20 jongfoster
370 * Version 2.9.4 checkin.
371 * - Merged popupfile and cookiefile, and added control over PCRS
372 * filtering, in new "permissionsfile".
373 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
374 * file error you now get a message box (in the Win32 GUI) rather
375 * than the program exiting with no explanation.
376 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
378 * - Removed tabs from "config"
379 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
380 * - Bumped up version number.
382 * Revision 1.2 2001/05/17 23:01:01 oes
383 * - Cleaned CRLF's from the sources and related files
385 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
386 * Initial import of version 2.9.3 source tree
389 *********************************************************************/
395 #include <sys/types.h>
409 # include <windows.h>
412 # ifndef _WIN_CONSOLE
414 # endif /* ndef _WIN_CONSOLE */
416 #else /* ifndef _WIN32 */
420 # include <sys/wait.h>
422 # include <sys/time.h>
423 # include <sys/stat.h>
433 #include "miscutil.h"
437 #include "urlmatch.h"
440 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
443 * Fix a problem with Solaris. There should be no effect on other
445 * Solaris's isspace() is a macro which uses it's argument directly
446 * as an array index. Therefore we need to make sure that high-bit
447 * characters generate +ve values, and ideally we also want to make
448 * the argument match the declared parameter type of "int".
450 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
451 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
453 #ifdef FEATURE_TOGGLE
454 /* Privoxy is enabled by default. */
455 int global_toggle_state = 1;
456 #endif /* def FEATURE_TOGGLE */
458 /* The filename of the configfile */
459 const char *configfile = NULL;
462 * CGI functions will later need access to the invocation args,
463 * so we will make argc and argv global.
466 const char **Argv = NULL;
468 static struct file_list *current_configfile = NULL;
472 * This takes the "cryptic" hash of each keyword and aliases them to
473 * something a little more readable. This also makes changing the
474 * hash values easier if they should change or the hash algorthm changes.
475 * Use the included "hash" program to find out what the hash will be
476 * for any string supplied on the command line. (Or just put it in the
477 * config file and read the number from the error message in the log).
479 * Please keep this list sorted alphabetically (but with the Windows
480 * console and GUI specific options last).
483 #define hash_actions_file 1196306641ul /* "actionsfile" */
484 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
485 #define hash_admin_address 4112573064ul /* "admin-address" */
486 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
487 #define hash_confdir 1978389ul /* "confdir" */
488 #define hash_debug 78263ul /* "debug" */
489 #define hash_deny_access 1227333715ul /* "deny-access" */
490 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
491 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
492 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
493 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
494 #define hash_filterfile 250887266ul /* "filterfile" */
495 #define hash_forward 2029845ul /* "forward" */
496 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
497 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
498 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
499 #define hash_jarfile 2046641ul /* "jarfile" */
500 #define hash_listen_address 1255650842ul /* "listen-address" */
501 #define hash_logdir 422889ul /* "logdir" */
502 #define hash_logfile 2114766ul /* "logfile" */
503 #define hash_permit_access 3587953268ul /* "permit-access" */
504 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
505 #define hash_single_threaded 4250084780ul /* "single-threaded" */
506 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
507 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
508 #define hash_templdir 11067889ul /* "templdir" */
509 #define hash_toggle 447966ul /* "toggle" */
510 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
511 #define hash_trustfile 56494766ul /* "trustfile" */
512 #define hash_usermanual 1416668518ul /* "user-manual" */
513 #define hash_activity_animation 1817904738ul /* "activity-animation" */
514 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
515 #define hash_hide_console 2048809870ul /* "hide-console" */
516 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
517 #define hash_log_font_name 2866730124ul /* "log-font-name" */
518 #define hash_log_font_size 2866731014ul /* "log-font-size" */
519 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
520 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
521 #define hash_log_messages 2291744899ul /* "log-messages" */
522 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
525 static void savearg(char *command, char *argument, struct configuration_spec * config);
527 /*********************************************************************
529 * Function : unload_configfile
531 * Description : Free the config structure and all components.
534 * 1 : data: struct configuration_spec to unload
538 *********************************************************************/
539 void unload_configfile (void * data)
541 struct configuration_spec * config = (struct configuration_spec *)data;
542 struct forward_spec *cur_fwd = config->forward;
546 struct access_control_list *cur_acl = config->acl;
548 while (cur_acl != NULL)
550 struct access_control_list * next_acl = cur_acl->next;
555 #endif /* def FEATURE_ACL */
557 while (cur_fwd != NULL)
559 struct forward_spec * next_fwd = cur_fwd->next;
560 free_url_spec(cur_fwd->url);
562 freez(cur_fwd->gateway_host);
563 freez(cur_fwd->forward_host);
567 config->forward = NULL;
569 #ifdef FEATURE_COOKIE_JAR
570 if ( NULL != config->jar )
572 fclose( config->jar );
575 #endif /* def FEATURE_COOKIE_JAR */
577 freez(config->confdir);
578 freez(config->logdir);
579 freez(config->templdir);
581 freez(config->haddr);
582 freez(config->logfile);
584 for (i = 0; i < MAX_AF_FILES; i++)
586 freez(config->actions_file_short[i]);
587 freez(config->actions_file[i]);
588 freez(config->re_filterfile_short[i]);
589 freez(config->re_filterfile[i]);
592 freez(config->admin_address);
593 freez(config->proxy_info_url);
594 freez(config->proxy_args);
595 freez(config->usermanual);
597 #ifdef FEATURE_COOKIE_JAR
598 freez(config->jarfile);
599 #endif /* def FEATURE_COOKIE_JAR */
602 freez(config->trustfile);
603 list_remove_all(config->trust_info);
604 #endif /* def FEATURE_TRUST */
606 for (i = 0; i < MAX_AF_FILES; i++)
608 freez(config->re_filterfile[i]);
615 #ifdef FEATURE_GRACEFUL_TERMINATION
616 /*********************************************************************
618 * Function : unload_current_config_file
620 * Description : Unloads current config file - reset to state at
621 * beginning of program.
627 *********************************************************************/
628 void unload_current_config_file(void)
630 if (current_configfile)
632 current_configfile->unloader = unload_configfile;
633 current_configfile = NULL;
639 /*********************************************************************
641 * Function : load_config
643 * Description : Load the config file and all parameters.
647 * Returns : The configuration_spec, or NULL on error.
649 *********************************************************************/
650 struct configuration_spec * load_config(void)
652 char buf[BUFFER_SIZE];
654 FILE *configfp = NULL;
655 struct configuration_spec * config = NULL;
656 struct client_state * fake_csp;
657 struct file_list *fs;
658 unsigned long linenum = 0;
661 if ( !check_file_changed(current_configfile, configfile, &fs))
663 /* No need to load */
664 return ((struct configuration_spec *)current_configfile->f);
668 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
672 log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
674 #ifdef FEATURE_TOGGLE
675 global_toggle_state = 1;
676 #endif /* def FEATURE_TOGGLE */
678 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
684 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
685 /* Never get here - LOG_LEVEL_FATAL causes program exit */
689 * This is backwards from how it's usually done.
690 * Following the usual pattern, "fs" would be stored in a member
691 * variable in "csp", and then we'd access "config" from "fs->f",
692 * using a cast. However, "config" is used so often that a
693 * cast each time would be very ugly, and the extra indirection
694 * would waste CPU cycles. Therefore we store "config" in
695 * "csp->config", and "fs" in "csp->config->config_file_list".
697 config->config_file_list = fs;
702 config->multi_threaded = 1;
703 config->hport = HADDR_PORT;
704 config->buffer_limit = 4096 * 1024;
705 config->usermanual = strdup(USER_MANUAL_URL);
706 config->proxy_args = strdup("");
707 config->forwarded_connect_retries = 0;
708 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
709 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
710 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
712 if ((configfp = fopen(configfile, "r")) == NULL)
714 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
716 /* Never get here - LOG_LEVEL_FATAL causes program exit */
719 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
721 char cmd[BUFFER_SIZE];
722 char arg[BUFFER_SIZE];
723 char tmp[BUFFER_SIZE];
725 struct access_control_list *cur_acl;
726 #endif /* def FEATURE_ACL */
727 struct forward_spec *cur_fwd;
733 /* Copy command (i.e. up to space or tab) into cmd */
736 while (*p && (*p != ' ') && (*p != '\t'))
742 /* Skip over the whitespace in buf */
743 while (*p && ((*p == ' ') || (*p == '\t')))
748 /* Copy the argument into arg */
751 /* Should never happen, but check this anyway */
757 /* Make sure the command field is lower case */
762 *p = (char)ijb_tolower(*p);
766 /* Save the argument for show-proxy-args */
767 savearg(cmd, arg, config);
770 switch( hash_string( cmd ) )
772 /* *************************************************************************
773 * actionsfile actions-file-name
774 * In confdir by default
775 * *************************************************************************/
776 case hash_actions_file :
778 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
783 if (i >= MAX_AF_FILES)
785 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
786 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
789 config->actions_file_short[i] = strdup(arg);
790 p = malloc(strlen(arg) + sizeof(".action"));
793 log_error(LOG_LEVEL_FATAL, "Out of memory");
796 strcat(p, ".action");
797 config->actions_file[i] = make_path(config->confdir, p);
800 /* *************************************************************************
801 * accept-intercepted-requests
802 * *************************************************************************/
803 case hash_accept_intercepted_requests:
804 if ((*arg != '\0') && (0 != atoi(arg)))
806 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
810 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
814 /* *************************************************************************
815 * admin-address email-address
816 * *************************************************************************/
817 case hash_admin_address :
818 freez(config->admin_address);
819 config->admin_address = strdup(arg);
822 /* *************************************************************************
824 * *************************************************************************/
825 case hash_buffer_limit :
826 config->buffer_limit = (size_t)(1024 * atoi(arg));
829 /* *************************************************************************
830 * confdir directory-name
831 * *************************************************************************/
833 freez(config->confdir);
834 config->confdir = make_path( NULL, arg);
837 /* *************************************************************************
839 * Specifies debug level, multiple values are ORed together.
840 * *************************************************************************/
842 config->debug |= atoi(arg);
845 /* *************************************************************************
846 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
847 * *************************************************************************/
849 case hash_deny_access:
850 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
852 if ((vec_count != 1) && (vec_count != 2))
854 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
855 "deny-access directive in configuration file.");
856 string_append(&config->proxy_args,
857 "<br>\nWARNING: Wrong number of parameters for "
858 "deny-access directive in configuration file.<br><br>\n");
862 /* allocate a new node */
863 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
867 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
868 /* Never get here - LOG_LEVEL_FATAL causes program exit */
871 cur_acl->action = ACL_DENY;
873 if (acl_addr(vec[0], cur_acl->src) < 0)
875 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
876 "for deny-access directive in configuration file: \"%s\"", vec[0]);
877 string_append(&config->proxy_args,
878 "<br>\nWARNING: Invalid source address, port or netmask "
879 "for deny-access directive in configuration file: \"");
880 string_append(&config->proxy_args,
882 string_append(&config->proxy_args,
889 if (acl_addr(vec[1], cur_acl->dst) < 0)
891 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
892 "for deny-access directive in configuration file: \"%s\"", vec[1]);
893 string_append(&config->proxy_args,
894 "<br>\nWARNING: Invalid destination address, port or netmask "
895 "for deny-access directive in configuration file: \"");
896 string_append(&config->proxy_args,
898 string_append(&config->proxy_args,
906 * Add it to the list. Note we reverse the list to get the
907 * behaviour the user expects. With both the ACL and
908 * actions file, the last match wins. However, the internal
909 * implementations are different: The actions file is stored
910 * in the same order as the file, and scanned completely.
911 * With the ACL, we reverse the order as we load it, then
912 * when we scan it we stop as soon as we get a match.
914 cur_acl->next = config->acl;
915 config->acl = cur_acl;
918 #endif /* def FEATURE_ACL */
920 /* *************************************************************************
921 * enable-edit-actions 0|1
922 * *************************************************************************/
923 #ifdef FEATURE_CGI_EDIT_ACTIONS
924 case hash_enable_edit_actions:
925 if ((*arg != '\0') && (0 != atoi(arg)))
927 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
931 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
934 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
936 /* *************************************************************************
937 * enable-remote-toggle 0|1
938 * *************************************************************************/
939 #ifdef FEATURE_CGI_EDIT_ACTIONS
940 case hash_enable_remote_toggle:
941 if ((*arg != '\0') && (0 != atoi(arg)))
943 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
947 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
950 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
952 /* *************************************************************************
953 * enable-remote-http-toggle 0|1
954 * *************************************************************************/
955 case hash_enable_remote_http_toggle:
956 if ((*arg != '\0') && (0 != atoi(arg)))
958 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
962 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
966 /* *************************************************************************
967 * hash_enforce_blocks 0|1
968 * *************************************************************************/
969 #ifdef FEATURE_FORCE_LOAD
970 case hash_enforce_blocks:
971 if ((*arg != '\0') && (0 != atoi(arg)))
973 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
977 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
980 #endif /* def FEATURE_FORCE_LOAD */
982 /* *************************************************************************
983 * filterfile file-name
984 * In confdir by default.
985 * *************************************************************************/
986 case hash_filterfile :
988 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
993 if (i >= MAX_AF_FILES)
995 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
996 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
999 config->re_filterfile_short[i] = strdup(arg);
1000 p = malloc(strlen(arg) + 1);
1003 log_error(LOG_LEVEL_FATAL, "Out of memory");
1006 config->re_filterfile[i] = make_path(config->confdir, p);
1010 /* *************************************************************************
1011 * forward url-pattern (.|http-proxy-host[:port])
1012 * *************************************************************************/
1014 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1018 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1019 "directive in configuration file.");
1020 string_append(&config->proxy_args,
1021 "<br>\nWARNING: Wrong number of parameters for "
1022 "forward directive in configuration file.");
1026 /* allocate a new node */
1027 cur_fwd = zalloc(sizeof(*cur_fwd));
1028 if (cur_fwd == NULL)
1030 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1031 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1035 cur_fwd->type = SOCKS_NONE;
1037 /* Save the URL pattern */
1038 if (create_url_spec(cur_fwd->url, vec[0]))
1040 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1041 "directive in configuration file.");
1042 string_append(&config->proxy_args,
1043 "<br>\nWARNING: Bad URL specifier for "
1044 "forward directive in configuration file.");
1048 /* Parse the parent HTTP proxy host:port */
1051 if (strcmp(p, ".") != 0)
1053 cur_fwd->forward_host = strdup(p);
1055 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1058 cur_fwd->forward_port = atoi(p);
1061 if (cur_fwd->forward_port <= 0)
1063 cur_fwd->forward_port = 8000;
1068 cur_fwd->next = config->forward;
1069 config->forward = cur_fwd;
1073 /* *************************************************************************
1074 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1075 * *************************************************************************/
1076 case hash_forward_socks4:
1077 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1081 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1082 "forward-socks4 directive in configuration file.");
1083 string_append(&config->proxy_args,
1084 "<br>\nWARNING: Wrong number of parameters for "
1085 "forward-socks4 directive in configuration file.");
1089 /* allocate a new node */
1090 cur_fwd = zalloc(sizeof(*cur_fwd));
1091 if (cur_fwd == NULL)
1093 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1094 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1098 cur_fwd->type = SOCKS_4;
1100 /* Save the URL pattern */
1101 if (create_url_spec(cur_fwd->url, vec[0]))
1103 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1104 "directive in configuration file.");
1105 string_append(&config->proxy_args,
1106 "<br>\nWARNING: Bad URL specifier for "
1107 "forward-socks4 directive in configuration file.");
1111 /* Parse the SOCKS proxy host[:port] */
1114 if (strcmp(p, ".") != 0)
1116 cur_fwd->gateway_host = strdup(p);
1118 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1121 cur_fwd->gateway_port = atoi(p);
1123 if (cur_fwd->gateway_port <= 0)
1125 cur_fwd->gateway_port = 1080;
1129 /* Parse the parent HTTP proxy host[:port] */
1132 if (strcmp(p, ".") != 0)
1134 cur_fwd->forward_host = strdup(p);
1136 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1139 cur_fwd->forward_port = atoi(p);
1142 if (cur_fwd->forward_port <= 0)
1144 cur_fwd->forward_port = 8000;
1149 cur_fwd->next = config->forward;
1150 config->forward = cur_fwd;
1154 /* *************************************************************************
1155 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1156 * *************************************************************************/
1157 case hash_forward_socks4a:
1158 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1162 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1163 "forward-socks4a directive in configuration file.");
1164 string_append(&config->proxy_args,
1165 "<br>\nWARNING: Wrong number of parameters for "
1166 "forward-socks4a directive in configuration file.");
1170 /* allocate a new node */
1171 cur_fwd = zalloc(sizeof(*cur_fwd));
1172 if (cur_fwd == NULL)
1174 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1175 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1179 cur_fwd->type = SOCKS_4A;
1181 /* Save the URL pattern */
1182 if (create_url_spec(cur_fwd->url, vec[0]))
1184 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1185 "directive in configuration file.");
1186 string_append(&config->proxy_args,
1187 "<br>\nWARNING: Bad URL specifier for "
1188 "forward-socks4a directive in configuration file.");
1192 /* Parse the SOCKS proxy host[:port] */
1195 cur_fwd->gateway_host = strdup(p);
1197 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1200 cur_fwd->gateway_port = atoi(p);
1202 if (cur_fwd->gateway_port <= 0)
1204 cur_fwd->gateway_port = 1080;
1207 /* Parse the parent HTTP proxy host[:port] */
1210 if (strcmp(p, ".") != 0)
1212 cur_fwd->forward_host = strdup(p);
1214 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1217 cur_fwd->forward_port = atoi(p);
1220 if (cur_fwd->forward_port <= 0)
1222 cur_fwd->forward_port = 8000;
1227 cur_fwd->next = config->forward;
1228 config->forward = cur_fwd;
1232 /* *************************************************************************
1233 * forwarded-connect-retries n
1234 * *************************************************************************/
1235 case hash_forwarded_connect_retries :
1236 config->forwarded_connect_retries = atoi(arg);
1239 /* *************************************************************************
1240 * jarfile jar-file-name
1241 * In logdir by default
1242 * *************************************************************************/
1243 #ifdef FEATURE_COOKIE_JAR
1245 freez(config->jarfile);
1246 config->jarfile = make_path(config->logdir, arg);
1248 #endif /* def FEATURE_COOKIE_JAR */
1250 /* *************************************************************************
1251 * listen-address [ip][:port]
1252 * *************************************************************************/
1253 case hash_listen_address :
1254 freez(config->haddr);
1255 config->haddr = strdup(arg);
1258 /* *************************************************************************
1259 * logdir directory-name
1260 * *************************************************************************/
1262 freez(config->logdir);
1263 config->logdir = make_path(NULL, arg);
1266 /* *************************************************************************
1267 * logfile log-file-name
1268 * In logdir by default
1269 * *************************************************************************/
1271 freez(config->logfile);
1272 config->logfile = no_daemon ? NULL : make_path(config->logdir, arg);
1275 /* *************************************************************************
1276 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1277 * *************************************************************************/
1279 case hash_permit_access:
1280 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1282 if ((vec_count != 1) && (vec_count != 2))
1284 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1285 "permit-access directive in configuration file.");
1286 string_append(&config->proxy_args,
1287 "<br>\nWARNING: Wrong number of parameters for "
1288 "permit-access directive in configuration file.<br><br>\n");
1293 /* allocate a new node */
1294 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1296 if (cur_acl == NULL)
1298 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1299 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1302 cur_acl->action = ACL_PERMIT;
1304 if (acl_addr(vec[0], cur_acl->src) < 0)
1306 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1307 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1308 string_append(&config->proxy_args,
1309 "<br>\nWARNING: Invalid source address, port or netmask for "
1310 "permit-access directive in configuration file: \"");
1311 string_append(&config->proxy_args,
1313 string_append(&config->proxy_args,
1320 if (acl_addr(vec[1], cur_acl->dst) < 0)
1322 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1323 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1324 string_append(&config->proxy_args,
1325 "<br>\nWARNING: Invalid destination address, port or netmask for "
1326 "permit-access directive in configuration file: \"");
1327 string_append(&config->proxy_args,
1329 string_append(&config->proxy_args,
1337 * Add it to the list. Note we reverse the list to get the
1338 * behaviour the user expects. With both the ACL and
1339 * actions file, the last match wins. However, the internal
1340 * implementations are different: The actions file is stored
1341 * in the same order as the file, and scanned completely.
1342 * With the ACL, we reverse the order as we load it, then
1343 * when we scan it we stop as soon as we get a match.
1345 cur_acl->next = config->acl;
1346 config->acl = cur_acl;
1349 #endif /* def FEATURE_ACL */
1351 /* *************************************************************************
1352 * proxy-info-url url
1353 * *************************************************************************/
1354 case hash_proxy_info_url :
1355 freez(config->proxy_info_url);
1356 config->proxy_info_url = strdup(arg);
1359 /* *************************************************************************
1361 * *************************************************************************/
1362 case hash_single_threaded :
1363 config->multi_threaded = 0;
1366 /* *************************************************************************
1367 * split-large-cgi-forms
1368 * *************************************************************************/
1369 case hash_split_large_cgi_forms :
1370 if ((*arg != '\0') && (0 != atoi(arg)))
1372 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1376 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1380 /* *************************************************************************
1381 * templdir directory-name
1382 * *************************************************************************/
1383 case hash_templdir :
1384 freez(config->templdir);
1385 config->templdir = make_path(NULL, arg);
1388 /* *************************************************************************
1390 * *************************************************************************/
1391 #ifdef FEATURE_TOGGLE
1393 global_toggle_state = atoi(arg);
1395 #endif /* def FEATURE_TOGGLE */
1397 /* *************************************************************************
1398 * trust-info-url url
1399 * *************************************************************************/
1400 #ifdef FEATURE_TRUST
1401 case hash_trust_info_url :
1402 enlist(config->trust_info, arg);
1404 #endif /* def FEATURE_TRUST */
1406 /* *************************************************************************
1407 * trustfile filename
1408 * (In confdir by default.)
1409 * *************************************************************************/
1410 #ifdef FEATURE_TRUST
1411 case hash_trustfile :
1412 freez(config->trustfile);
1413 config->trustfile = make_path(config->confdir, arg);
1415 #endif /* def FEATURE_TRUST */
1417 /* *************************************************************************
1419 * *************************************************************************/
1420 case hash_usermanual :
1421 freez(config->usermanual);
1422 config->usermanual = strdup(arg);
1425 /* *************************************************************************
1426 * Win32 Console options:
1427 * *************************************************************************/
1429 /* *************************************************************************
1431 * *************************************************************************/
1433 case hash_hide_console :
1436 #endif /*def _WIN_CONSOLE*/
1439 /* *************************************************************************
1440 * Win32 GUI options:
1441 * *************************************************************************/
1443 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1444 /* *************************************************************************
1445 * activity-animation (0|1)
1446 * *************************************************************************/
1447 case hash_activity_animation :
1448 g_bShowActivityAnimation = atoi(arg);
1451 /* *************************************************************************
1452 * close-button-minimizes (0|1)
1453 * *************************************************************************/
1454 case hash_close_button_minimizes :
1455 g_bCloseHidesWindow = atoi(arg);
1458 /* *************************************************************************
1459 * log-buffer-size (0|1)
1460 * *************************************************************************/
1461 case hash_log_buffer_size :
1462 g_bLimitBufferSize = atoi(arg);
1465 /* *************************************************************************
1466 * log-font-name fontnane
1467 * *************************************************************************/
1468 case hash_log_font_name :
1469 strcpy( g_szFontFaceName, arg );
1472 /* *************************************************************************
1474 * *************************************************************************/
1475 case hash_log_font_size :
1476 g_nFontSize = atoi(arg);
1479 /* *************************************************************************
1480 * log-highlight-messages (0|1)
1481 * *************************************************************************/
1482 case hash_log_highlight_messages :
1483 g_bHighlightMessages = atoi(arg);
1486 /* *************************************************************************
1488 * *************************************************************************/
1489 case hash_log_max_lines :
1490 g_nMaxBufferLines = atoi(arg);
1493 /* *************************************************************************
1494 * log-messages (0|1)
1495 * *************************************************************************/
1496 case hash_log_messages :
1497 g_bLogMessages = atoi(arg);
1500 /* *************************************************************************
1501 * show-on-task-bar (0|1)
1502 * *************************************************************************/
1503 case hash_show_on_task_bar :
1504 g_bShowOnTaskBar = atoi(arg);
1507 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1510 /* *************************************************************************
1511 * Warnings about unsupported features
1512 * *************************************************************************/
1514 case hash_deny_access:
1515 #endif /* ndef FEATURE_ACL */
1516 #ifndef FEATURE_CGI_EDIT_ACTIONS
1517 case hash_enable_edit_actions:
1518 case hash_enable_remote_toggle:
1519 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1520 #ifndef FEATURE_COOKIE_JAR
1522 #endif /* ndef FEATURE_COOKIE_JAR */
1524 case hash_permit_access:
1525 #endif /* ndef FEATURE_ACL */
1526 #ifndef FEATURE_TOGGLE
1528 #endif /* ndef FEATURE_TOGGLE */
1529 #ifndef FEATURE_TRUST
1530 case hash_trustfile :
1531 case hash_trust_info_url :
1532 #endif /* ndef FEATURE_TRUST */
1534 #ifndef _WIN_CONSOLE
1535 case hash_hide_console :
1536 #endif /* ndef _WIN_CONSOLE */
1538 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1539 case hash_activity_animation :
1540 case hash_close_button_minimizes :
1541 case hash_log_buffer_size :
1542 case hash_log_font_name :
1543 case hash_log_font_size :
1544 case hash_log_highlight_messages :
1545 case hash_log_max_lines :
1546 case hash_log_messages :
1547 case hash_show_on_task_bar :
1548 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1549 /* These warnings are annoying - so hide them. -- Jon */
1550 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1553 /* *************************************************************************/
1555 /* *************************************************************************/
1557 * I decided that I liked this better as a warning than an
1558 * error. To change back to an error, just change log level
1559 * to LOG_LEVEL_FATAL.
1561 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1562 "in configuration file (%s).", buf, hash_string(cmd), linenum, configfile);
1563 string_append(&config->proxy_args,
1564 " <b><font color=\"red\">WARNING: unrecognized directive, ignored</font></b>");
1567 /* *************************************************************************/
1568 } /* end switch( hash_string(cmd) ) */
1569 } /* end while ( read_config_line(...) ) */
1573 if (NULL == config->proxy_args)
1575 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1578 init_error_log(Argv[0], config->logfile, config->debug);
1580 if (config->actions_file[0])
1582 add_loader(load_actions_file, config);
1585 if (config->re_filterfile)
1587 add_loader(load_re_filterfile, config);
1590 #ifdef FEATURE_TRUST
1591 if (config->trustfile)
1593 add_loader(load_trustfile, config);
1595 #endif /* def FEATURE_TRUST */
1597 #ifdef FEATURE_COOKIE_JAR
1598 if ( NULL != config->jarfile )
1600 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1602 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1603 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1605 setbuf(config->jar, NULL);
1607 #endif /* def FEATURE_COOKIE_JAR */
1609 if ( NULL == config->haddr )
1611 config->haddr = strdup( HADDR_DEFAULT );
1614 if ( NULL != config->haddr )
1616 if (NULL != (p = strchr(config->haddr, ':')))
1621 config->hport = atoi(p);
1625 if (config->hport <= 0)
1628 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1629 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1631 if (*config->haddr == '\0')
1633 config->haddr = NULL;
1638 * Want to run all the loaders once now.
1640 * Need to set up a fake csp, so they can get to the config.
1642 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1643 fake_csp->config = config;
1645 if (run_loader(fake_csp))
1648 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1649 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1653 /* FIXME: this is a kludge for win32 */
1654 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1656 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1657 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1658 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1660 #ifdef FEATURE_TRUST
1661 g_trustfile = config->trustfile;
1662 #endif /* def FEATURE_TRUST */
1665 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1666 /* FIXME: end kludge */
1669 config->need_bind = 1;
1671 if (current_configfile)
1673 struct configuration_spec * oldcfg = (struct configuration_spec *)
1674 current_configfile->f;
1676 * Check if config->haddr,hport == oldcfg->haddr,hport
1678 * The following could be written more compactly as a single,
1679 * (unreadably long) if statement.
1681 config->need_bind = 0;
1682 if (config->hport != oldcfg->hport)
1684 config->need_bind = 1;
1686 else if (config->haddr == NULL)
1688 if (oldcfg->haddr != NULL)
1690 config->need_bind = 1;
1693 else if (oldcfg->haddr == NULL)
1695 config->need_bind = 1;
1697 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1699 config->need_bind = 1;
1702 current_configfile->unloader = unload_configfile;
1705 fs->next = files->next;
1708 current_configfile = fs;
1714 /*********************************************************************
1716 * Function : savearg
1718 * Description : Called from `load_config'. It saves each non-empty
1719 * and non-comment line from config into
1720 * config->proxy_args. This is used to create the
1721 * show-proxy-args page. On error, frees
1722 * config->proxy_args and sets it to NULL
1725 * 1 : command = config setting that was found
1726 * 2 : argument = the setting's argument (if any)
1727 * 3 : config = Configuration to save into.
1731 *********************************************************************/
1732 static void savearg(char *command, char *argument, struct configuration_spec * config)
1742 * Add config option name embedded in
1743 * link to it's section in the user-manual
1745 buf = strdup("\n<a href=\"");
1746 if (!strncmpic(config->usermanual, "file://", 7) ||
1747 !strncmpic(config->usermanual, "http", 4))
1749 string_append(&buf, config->usermanual);
1753 string_append(&buf, "http://");
1754 string_append(&buf, CGI_SITE_2_HOST);
1755 string_append(&buf, "/user-manual/");
1757 string_append(&buf, CONFIG_HELP_PREFIX);
1758 string_join (&buf, string_toupper(command));
1759 string_append(&buf, "\">");
1760 string_append(&buf, command);
1761 string_append(&buf, "</a> ");
1765 freez(config->proxy_args);
1769 if ( (NULL != argument) && ('\0' != *argument) )
1771 s = html_encode(argument);
1775 freez(config->proxy_args);
1779 if (strncmpic(argument, "http://", 7) == 0)
1781 string_append(&buf, "<a href=\"");
1782 string_append(&buf, s);
1783 string_append(&buf, "\">");
1784 string_join (&buf, s);
1785 string_append(&buf, "</a>");
1789 string_join (&buf, s);
1793 string_append(&buf, "<br>");
1794 string_join(&config->proxy_args, buf);