1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.64 2007/05/21 10:44:08 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.64 2007/05/21 10:44:08 fabiankeil
39 * - Use strlcpy() instead of strcpy().
40 * - Stop treating actions files special. Expect a complete file name
41 * (with or without path) like it's done for the rest of the files.
43 * - Remove an unnecessary temporary memory allocation.
44 * - Don't log anything to the console when running as
45 * daemon and no errors occurred.
47 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
48 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
50 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
51 * New config option: enforce-blocks.
53 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
54 * - Mention other reasons why acl directive loading might have failed.
55 * - Don't log the acl source if the acl destination is to blame.
57 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
58 * Add new config option "templdir" to
59 * change the templates directory.
61 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
62 * Added config option accept-intercepted-requests
63 * and disabled it by default.
65 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
66 * Fix gcc43 compiler warnings.
68 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
69 * Add config option "split-large-forms"
70 * to work around the browser bug reported
73 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
74 * Move the <br> in the generated HTML for the config
75 * options from the beginning of the string to its end.
76 * Keeps the white space in balance.
78 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
79 * Fix memory leak in case of config file reloads.
81 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
82 * Modified kludge for win32 to make ming32 menu
83 * "Options/Edit Filters" (sort of) work again.
84 * Same limitations as for the action files apply.
87 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
88 * Incorporate modified version of Roland Rosenfeld's patch to
89 * optionally access the user-manual via Privoxy. Closes patch 679075.
91 * Formatting changed to Privoxy style, added call to
92 * cgi_error_no_template if the requested file doesn't
93 * exist and modified check whether or not Privoxy itself
94 * should serve the manual. Should work cross-platform now.
96 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
97 * Added config option enable-remote-http-toggle
98 * to specify if Privoxy should recognize special
99 * headers (currently only X-Filter) to change its
100 * behaviour. Disabled by default.
102 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
103 * Make number of retries in case of forwarded-connect problems
104 * a config file option (forwarded-connect-retries) and use 0 as
107 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
108 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
109 * with what was really the latest development (the v_3_0_branch branch)
111 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
112 * Don't forget to malloc space for the null terminator...
114 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
115 * Multiple filter file support
117 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
118 * Closed two memory leaks; hopefully the last remaining ones
119 * (in the main execution paths, anyway).
121 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
122 * Addressed bug #719435
123 * - Extraneous filterfile directives now logged as errors
124 * - This and unrecnonised directives now really obvious on status page
126 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
127 * Cosmetic: Renamed cryptic variable
129 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
130 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
132 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
133 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
135 * Revision 1.48 2002/05/14 21:30:38 oes
136 * savearg now uses own linking code instead of (now special-cased) add_help_link
138 * Revision 1.47 2002/05/12 21:36:29 jongfoster
139 * Correcting function comments
141 * Revision 1.46 2002/04/26 12:55:14 oes
142 * - New option "user-manual", defaults to our site
143 * via project.h #define
144 * - savearg now embeds option names in help links
146 * Revision 1.45 2002/04/24 02:11:54 oes
147 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
149 * Revision 1.44 2002/04/08 20:37:13 swa
152 * Revision 1.43 2002/04/08 20:36:50 swa
155 * Revision 1.42 2002/04/05 15:50:15 oes
156 * fix for invalid HTML proxy_args
158 * Revision 1.41 2002/03/31 17:19:00 jongfoster
159 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
161 * Revision 1.40 2002/03/26 22:29:55 swa
162 * we have a new homepage!
164 * Revision 1.39 2002/03/24 13:25:43 swa
165 * name change related issues
167 * Revision 1.38 2002/03/24 13:05:48 jongfoster
168 * Renaming re_filterfile to filterfile
170 * Revision 1.37 2002/03/16 23:54:06 jongfoster
171 * Adding graceful termination feature, to help look for memory leaks.
172 * If you enable this (which, by design, has to be done by hand
173 * editing config.h) and then go to http://i.j.b/die, then the program
174 * will exit cleanly after the *next* request. It should free all the
175 * memory that was used.
177 * Revision 1.36 2002/03/13 00:27:05 jongfoster
180 * Revision 1.35 2002/03/07 03:52:44 oes
181 * Set logging to tty for --no-daemon mode
183 * Revision 1.34 2002/03/06 23:14:35 jongfoster
184 * Trivial cosmetic changes to make function comments easier to find.
186 * Revision 1.33 2002/03/05 04:52:42 oes
187 * Deleted non-errlog debugging code
189 * Revision 1.32 2002/03/04 18:24:53 oes
190 * Re-enabled output of unknown config directive hash
192 * Revision 1.31 2002/03/03 15:07:20 oes
193 * Re-enabled automatic config reloading
195 * Revision 1.30 2002/01/22 23:31:43 jongfoster
196 * Replacing strsav() with string_append()
198 * Revision 1.29 2002/01/17 21:02:30 jongfoster
199 * Moving all our URL and URL pattern parsing code to urlmatch.c.
201 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
203 * Revision 1.28 2001/12/30 14:07:32 steudten
204 * - Add signal handling (unix)
205 * - Add SIGHUP handler (unix)
206 * - Add creation of pidfile (unix)
207 * - Add action 'top' in rc file (RH)
208 * - Add entry 'SIGNALS' to manpage
209 * - Add exit message to logfile (unix)
211 * Revision 1.27 2001/11/07 00:02:13 steudten
212 * Add line number in error output for lineparsing for
213 * actionsfile and configfile.
214 * Special handling for CLF added.
216 * Revision 1.26 2001/11/05 21:41:43 steudten
217 * Add changes to be a real daemon just for unix os.
218 * (change cwd to /, detach from controlling tty, set
219 * process group and session leader to the own process.
221 * Add some fatal-error log message for failed malloc().
222 * Add '-d' if compiled with 'configure --with-debug' to
223 * enable debug output.
225 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
226 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
227 * threads to call select() simultaneously. So, it's time to do a real, live,
228 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
229 * (native). Both versions will work, but using __OS2__ offers multi-threading.
231 * Revision 1.24 2001/10/23 21:40:30 jongfoster
232 * Added support for enable-edit-actions and enable-remote-toggle config
235 * Revision 1.23 2001/10/07 15:36:00 oes
236 * Introduced new config option "buffer-limit"
238 * Revision 1.22 2001/09/22 16:36:59 jongfoster
239 * Removing unused parameter fs from read_config_line()
241 * Revision 1.21 2001/09/16 17:10:43 jongfoster
242 * Moving function savearg() here, since it was the only thing left in
245 * Revision 1.20 2001/07/30 22:08:36 jongfoster
246 * Tidying up #defines:
247 * - All feature #defines are now of the form FEATURE_xxx
248 * - Permanently turned off WIN_GUI_EDIT
249 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
251 * Revision 1.19 2001/07/15 17:45:16 jongfoster
252 * Removing some unused #includes
254 * Revision 1.18 2001/07/13 14:01:14 oes
255 * - Removed all #ifdef PCRS
256 * - Removed vim-settings
258 * Revision 1.17 2001/06/29 13:31:03 oes
259 * - Improved comments
260 * - Fixed (actionsfile) and sorted hashes
261 * - Introduced admin_address and proxy-info-url
262 * as config parameters
263 * - Renamed config->proxy_args_invocation (which didn't have
264 * the invocation but the options!) to config->proxy_args
265 * - Various adaptions
266 * - Removed logentry from cancelled commit
268 * Revision 1.16 2001/06/09 10:55:28 jongfoster
269 * Changing BUFSIZ ==> BUFFER_SIZE
271 * Revision 1.15 2001/06/07 23:13:40 jongfoster
272 * Merging ACL and forward files into config file.
273 * Cosmetic: Sorting config file options alphabetically.
274 * Cosmetic: Adding brief syntax comments to config file options.
276 * Revision 1.14 2001/06/07 14:46:25 joergs
277 * Missing make_path() added for re_filterfile.
279 * Revision 1.13 2001/06/05 22:33:54 jongfoster
281 * Fixed minor memory leak.
282 * Also now uses make_path to prepend the pathnames.
284 * Revision 1.12 2001/06/05 20:04:09 jongfoster
285 * Now uses _snprintf() in place of snprintf() under Win32.
287 * Revision 1.11 2001/06/04 18:31:58 swa
288 * files are now prefixed with either `confdir' or `logdir'.
289 * `make redhat-dist' replaces both entries confdir and logdir
292 * Revision 1.10 2001/06/03 19:11:54 oes
293 * introduced confdir option
295 * Revision 1.9 2001/06/01 20:06:24 jongfoster
296 * Removed support for "tinygif" option - moved to actions file.
298 * Revision 1.8 2001/05/31 21:27:13 jongfoster
299 * Removed many options from the config file and into the
300 * "actions" file: add_forwarded, suppress_vanilla_wafer,
301 * wafer, add_header, user_agent, referer, from
302 * Also globally replaced "permission" with "action".
304 * Revision 1.7 2001/05/29 09:50:24 jongfoster
305 * Unified blocklist/imagelist/permissionslist.
306 * File format is still under discussion, but the internal changes
309 * Also modified interceptor behaviour:
310 * - We now intercept all URLs beginning with one of the following
311 * prefixes (and *only* these prefixes):
313 * * http://ijbswa.sf.net/config/
314 * * http://ijbswa.sourceforge.net/config/
315 * - New interceptors "home page" - go to http://i.j.b/ to see it.
316 * - Internal changes so that intercepted and fast redirect pages
317 * are not replaced with an image.
318 * - Interceptors now have the option to send a binary page direct
319 * to the client. (i.e. ijb-send-banner uses this)
320 * - Implemented show-url-info interceptor. (Which is why I needed
321 * the above interceptors changes - a typical URL is
322 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
323 * The previous mechanism would not have intercepted that, and
324 * if it had been intercepted then it then it would have replaced
327 * Revision 1.6 2001/05/26 00:28:36 jongfoster
328 * Automatic reloading of config file.
329 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
330 * Most of the global variables have been moved to a new
331 * struct configuration_spec, accessed through csp->config->globalname
332 * Most of the globals remaining are used by the Win32 GUI.
334 * Revision 1.5 2001/05/25 22:34:30 jongfoster
337 * Revision 1.4 2001/05/22 18:46:04 oes
339 * - Enabled filtering banners by size rather than URL
340 * by adding patterns that replace all standard banner
341 * sizes with the "Junkbuster" gif to the re_filterfile
343 * - Enabled filtering WebBugs by providing a pattern
344 * which kills all 1x1 images
346 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
347 * which is selected by the (nonstandard and therefore
348 * capital) letter 'U' in the option string.
349 * It causes the quantifiers to be ungreedy by default.
350 * Appending a ? turns back to greedy (!).
352 * - Added a new interceptor ijb-send-banner, which
353 * sends back the "Junkbuster" gif. Without imagelist or
354 * MSIE detection support, or if tinygif = 1, or the
355 * URL isn't recognized as an imageurl, a lame HTML
356 * explanation is sent instead.
358 * - Added new feature, which permits blocking remote
359 * script redirects and firing back a local redirect
361 * The feature is conditionally compiled, i.e. it
362 * can be disabled with --disable-fast-redirects,
363 * plus it must be activated by a "fast-redirects"
364 * line in the config file, has its own log level
365 * and of course wants to be displayed by show-proxy-args
366 * Note: Boy, all the #ifdefs in 1001 locations and
367 * all the fumbling with configure.in and acconfig.h
368 * were *way* more work than the feature itself :-(
370 * - Because a generic redirect template was needed for
371 * this, tinygif = 3 now uses the same.
373 * - Moved GIFs, and other static HTTP response templates
378 * - Removed some >400 CRs again (Jon, you really worked
381 * Revision 1.3 2001/05/20 01:21:20 jongfoster
382 * Version 2.9.4 checkin.
383 * - Merged popupfile and cookiefile, and added control over PCRS
384 * filtering, in new "permissionsfile".
385 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
386 * file error you now get a message box (in the Win32 GUI) rather
387 * than the program exiting with no explanation.
388 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
390 * - Removed tabs from "config"
391 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
392 * - Bumped up version number.
394 * Revision 1.2 2001/05/17 23:01:01 oes
395 * - Cleaned CRLF's from the sources and related files
397 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
398 * Initial import of version 2.9.3 source tree
401 *********************************************************************/
407 #include <sys/types.h>
421 # include <windows.h>
424 # ifndef _WIN_CONSOLE
426 # endif /* ndef _WIN_CONSOLE */
428 #else /* ifndef _WIN32 */
432 # include <sys/wait.h>
434 # include <sys/time.h>
435 # include <sys/stat.h>
445 #include "miscutil.h"
449 #include "urlmatch.h"
452 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
455 * Fix a problem with Solaris. There should be no effect on other
457 * Solaris's isspace() is a macro which uses it's argument directly
458 * as an array index. Therefore we need to make sure that high-bit
459 * characters generate +ve values, and ideally we also want to make
460 * the argument match the declared parameter type of "int".
462 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
463 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
465 #ifdef FEATURE_TOGGLE
466 /* Privoxy is enabled by default. */
467 int global_toggle_state = 1;
468 #endif /* def FEATURE_TOGGLE */
470 /* The filename of the configfile */
471 const char *configfile = NULL;
474 * CGI functions will later need access to the invocation args,
475 * so we will make argc and argv global.
478 const char **Argv = NULL;
480 static struct file_list *current_configfile = NULL;
484 * This takes the "cryptic" hash of each keyword and aliases them to
485 * something a little more readable. This also makes changing the
486 * hash values easier if they should change or the hash algorthm changes.
487 * Use the included "hash" program to find out what the hash will be
488 * for any string supplied on the command line. (Or just put it in the
489 * config file and read the number from the error message in the log).
491 * Please keep this list sorted alphabetically (but with the Windows
492 * console and GUI specific options last).
495 #define hash_actions_file 1196306641ul /* "actionsfile" */
496 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
497 #define hash_admin_address 4112573064ul /* "admin-address" */
498 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
499 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
500 #define hash_confdir 1978389ul /* "confdir" */
501 #define hash_debug 78263ul /* "debug" */
502 #define hash_deny_access 1227333715ul /* "deny-access" */
503 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
504 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
505 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
506 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
507 #define hash_filterfile 250887266ul /* "filterfile" */
508 #define hash_forward 2029845ul /* "forward" */
509 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
510 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
511 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
512 #define hash_jarfile 2046641ul /* "jarfile" */
513 #define hash_listen_address 1255650842ul /* "listen-address" */
514 #define hash_logdir 422889ul /* "logdir" */
515 #define hash_logfile 2114766ul /* "logfile" */
516 #define hash_permit_access 3587953268ul /* "permit-access" */
517 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
518 #define hash_single_threaded 4250084780ul /* "single-threaded" */
519 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
520 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
521 #define hash_templdir 11067889ul /* "templdir" */
522 #define hash_toggle 447966ul /* "toggle" */
523 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
524 #define hash_trustfile 56494766ul /* "trustfile" */
525 #define hash_usermanual 1416668518ul /* "user-manual" */
526 #define hash_activity_animation 1817904738ul /* "activity-animation" */
527 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
528 #define hash_hide_console 2048809870ul /* "hide-console" */
529 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
530 #define hash_log_font_name 2866730124ul /* "log-font-name" */
531 #define hash_log_font_size 2866731014ul /* "log-font-size" */
532 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
533 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
534 #define hash_log_messages 2291744899ul /* "log-messages" */
535 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
538 static void savearg(char *command, char *argument, struct configuration_spec * config);
540 /*********************************************************************
542 * Function : unload_configfile
544 * Description : Free the config structure and all components.
547 * 1 : data: struct configuration_spec to unload
551 *********************************************************************/
552 void unload_configfile (void * data)
554 struct configuration_spec * config = (struct configuration_spec *)data;
555 struct forward_spec *cur_fwd = config->forward;
559 struct access_control_list *cur_acl = config->acl;
561 while (cur_acl != NULL)
563 struct access_control_list * next_acl = cur_acl->next;
568 #endif /* def FEATURE_ACL */
570 while (cur_fwd != NULL)
572 struct forward_spec * next_fwd = cur_fwd->next;
573 free_url_spec(cur_fwd->url);
575 freez(cur_fwd->gateway_host);
576 freez(cur_fwd->forward_host);
580 config->forward = NULL;
582 #ifdef FEATURE_COOKIE_JAR
583 if ( NULL != config->jar )
585 fclose( config->jar );
588 #endif /* def FEATURE_COOKIE_JAR */
590 freez(config->confdir);
591 freez(config->logdir);
592 freez(config->templdir);
594 freez(config->haddr);
595 freez(config->logfile);
597 for (i = 0; i < MAX_AF_FILES; i++)
599 freez(config->actions_file_short[i]);
600 freez(config->actions_file[i]);
601 freez(config->re_filterfile_short[i]);
602 freez(config->re_filterfile[i]);
605 freez(config->admin_address);
606 freez(config->proxy_info_url);
607 freez(config->proxy_args);
608 freez(config->usermanual);
610 #ifdef FEATURE_COOKIE_JAR
611 freez(config->jarfile);
612 #endif /* def FEATURE_COOKIE_JAR */
615 freez(config->trustfile);
616 list_remove_all(config->trust_info);
617 #endif /* def FEATURE_TRUST */
619 for (i = 0; i < MAX_AF_FILES; i++)
621 freez(config->re_filterfile[i]);
628 #ifdef FEATURE_GRACEFUL_TERMINATION
629 /*********************************************************************
631 * Function : unload_current_config_file
633 * Description : Unloads current config file - reset to state at
634 * beginning of program.
640 *********************************************************************/
641 void unload_current_config_file(void)
643 if (current_configfile)
645 current_configfile->unloader = unload_configfile;
646 current_configfile = NULL;
652 /*********************************************************************
654 * Function : load_config
656 * Description : Load the config file and all parameters.
660 * Returns : The configuration_spec, or NULL on error.
662 *********************************************************************/
663 struct configuration_spec * load_config(void)
665 char buf[BUFFER_SIZE];
667 FILE *configfp = NULL;
668 struct configuration_spec * config = NULL;
669 struct client_state * fake_csp;
670 struct file_list *fs;
671 unsigned long linenum = 0;
674 if ( !check_file_changed(current_configfile, configfile, &fs))
676 /* No need to load */
677 return ((struct configuration_spec *)current_configfile->f);
681 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
685 if (NULL != current_configfile)
687 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
690 #ifdef FEATURE_TOGGLE
691 global_toggle_state = 1;
692 #endif /* def FEATURE_TOGGLE */
694 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
700 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
701 /* Never get here - LOG_LEVEL_FATAL causes program exit */
705 * This is backwards from how it's usually done.
706 * Following the usual pattern, "fs" would be stored in a member
707 * variable in "csp", and then we'd access "config" from "fs->f",
708 * using a cast. However, "config" is used so often that a
709 * cast each time would be very ugly, and the extra indirection
710 * would waste CPU cycles. Therefore we store "config" in
711 * "csp->config", and "fs" in "csp->config->config_file_list".
713 config->config_file_list = fs;
718 config->multi_threaded = 1;
719 config->hport = HADDR_PORT;
720 config->buffer_limit = 4096 * 1024;
721 config->usermanual = strdup(USER_MANUAL_URL);
722 config->proxy_args = strdup("");
723 config->forwarded_connect_retries = 0;
724 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
725 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
726 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
728 if ((configfp = fopen(configfile, "r")) == NULL)
730 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
732 /* Never get here - LOG_LEVEL_FATAL causes program exit */
735 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
737 char cmd[BUFFER_SIZE];
738 char arg[BUFFER_SIZE];
739 char tmp[BUFFER_SIZE];
741 struct access_control_list *cur_acl;
742 #endif /* def FEATURE_ACL */
743 struct forward_spec *cur_fwd;
747 strlcpy(tmp, buf, sizeof(tmp));
749 /* Copy command (i.e. up to space or tab) into cmd */
752 while (*p && (*p != ' ') && (*p != '\t'))
758 /* Skip over the whitespace in buf */
759 while (*p && ((*p == ' ') || (*p == '\t')))
764 /* Copy the argument into arg */
765 strlcpy(arg, p, sizeof(arg));
767 /* Should never happen, but check this anyway */
773 /* Make sure the command field is lower case */
778 *p = (char)ijb_tolower(*p);
782 /* Save the argument for show-proxy-args */
783 savearg(cmd, arg, config);
786 switch( hash_string( cmd ) )
788 /* *************************************************************************
789 * actionsfile actions-file-name
790 * In confdir by default
791 * *************************************************************************/
792 case hash_actions_file :
794 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
799 if (i >= MAX_AF_FILES)
801 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
802 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
805 config->actions_file_short[i] = strdup(arg);
806 config->actions_file[i] = make_path(config->confdir, arg);
809 /* *************************************************************************
810 * accept-intercepted-requests
811 * *************************************************************************/
812 case hash_accept_intercepted_requests:
813 if ((*arg != '\0') && (0 != atoi(arg)))
815 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
819 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
823 /* *************************************************************************
824 * admin-address email-address
825 * *************************************************************************/
826 case hash_admin_address :
827 freez(config->admin_address);
828 config->admin_address = strdup(arg);
831 /* *************************************************************************
832 * allow-cgi-request-crunching
833 * *************************************************************************/
834 case hash_allow_cgi_request_crunching:
835 if ((*arg != '\0') && (0 != atoi(arg)))
837 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
841 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
845 /* *************************************************************************
847 * *************************************************************************/
848 case hash_buffer_limit :
849 config->buffer_limit = (size_t)(1024 * atoi(arg));
852 /* *************************************************************************
853 * confdir directory-name
854 * *************************************************************************/
856 freez(config->confdir);
857 config->confdir = make_path( NULL, arg);
860 /* *************************************************************************
862 * Specifies debug level, multiple values are ORed together.
863 * *************************************************************************/
865 config->debug |= atoi(arg);
868 /* *************************************************************************
869 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
870 * *************************************************************************/
872 case hash_deny_access:
873 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
875 if ((vec_count != 1) && (vec_count != 2))
877 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
878 "deny-access directive in configuration file.");
879 string_append(&config->proxy_args,
880 "<br>\nWARNING: Wrong number of parameters for "
881 "deny-access directive in configuration file.<br><br>\n");
885 /* allocate a new node */
886 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
890 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
891 /* Never get here - LOG_LEVEL_FATAL causes program exit */
894 cur_acl->action = ACL_DENY;
896 if (acl_addr(vec[0], cur_acl->src) < 0)
898 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
899 "for deny-access directive in configuration file: \"%s\"", vec[0]);
900 string_append(&config->proxy_args,
901 "<br>\nWARNING: Invalid source address, port or netmask "
902 "for deny-access directive in configuration file: \"");
903 string_append(&config->proxy_args,
905 string_append(&config->proxy_args,
912 if (acl_addr(vec[1], cur_acl->dst) < 0)
914 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
915 "for deny-access directive in configuration file: \"%s\"", vec[1]);
916 string_append(&config->proxy_args,
917 "<br>\nWARNING: Invalid destination address, port or netmask "
918 "for deny-access directive in configuration file: \"");
919 string_append(&config->proxy_args,
921 string_append(&config->proxy_args,
929 * Add it to the list. Note we reverse the list to get the
930 * behaviour the user expects. With both the ACL and
931 * actions file, the last match wins. However, the internal
932 * implementations are different: The actions file is stored
933 * in the same order as the file, and scanned completely.
934 * With the ACL, we reverse the order as we load it, then
935 * when we scan it we stop as soon as we get a match.
937 cur_acl->next = config->acl;
938 config->acl = cur_acl;
941 #endif /* def FEATURE_ACL */
943 /* *************************************************************************
944 * enable-edit-actions 0|1
945 * *************************************************************************/
946 #ifdef FEATURE_CGI_EDIT_ACTIONS
947 case hash_enable_edit_actions:
948 if ((*arg != '\0') && (0 != atoi(arg)))
950 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
954 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
957 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
959 /* *************************************************************************
960 * enable-remote-toggle 0|1
961 * *************************************************************************/
962 #ifdef FEATURE_CGI_EDIT_ACTIONS
963 case hash_enable_remote_toggle:
964 if ((*arg != '\0') && (0 != atoi(arg)))
966 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
970 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
973 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
975 /* *************************************************************************
976 * enable-remote-http-toggle 0|1
977 * *************************************************************************/
978 case hash_enable_remote_http_toggle:
979 if ((*arg != '\0') && (0 != atoi(arg)))
981 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
985 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
989 /* *************************************************************************
990 * hash_enforce_blocks 0|1
991 * *************************************************************************/
992 #ifdef FEATURE_FORCE_LOAD
993 case hash_enforce_blocks:
994 if ((*arg != '\0') && (0 != atoi(arg)))
996 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1000 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1003 #endif /* def FEATURE_FORCE_LOAD */
1005 /* *************************************************************************
1006 * filterfile file-name
1007 * In confdir by default.
1008 * *************************************************************************/
1009 case hash_filterfile :
1011 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1016 if (i >= MAX_AF_FILES)
1018 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1019 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1022 config->re_filterfile_short[i] = strdup(arg);
1023 config->re_filterfile[i] = make_path(config->confdir, arg);
1027 /* *************************************************************************
1028 * forward url-pattern (.|http-proxy-host[:port])
1029 * *************************************************************************/
1031 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1035 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1036 "directive in configuration file.");
1037 string_append(&config->proxy_args,
1038 "<br>\nWARNING: Wrong number of parameters for "
1039 "forward directive in configuration file.");
1043 /* allocate a new node */
1044 cur_fwd = zalloc(sizeof(*cur_fwd));
1045 if (cur_fwd == NULL)
1047 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1048 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1052 cur_fwd->type = SOCKS_NONE;
1054 /* Save the URL pattern */
1055 if (create_url_spec(cur_fwd->url, vec[0]))
1057 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1058 "directive in configuration file.");
1059 string_append(&config->proxy_args,
1060 "<br>\nWARNING: Bad URL specifier for "
1061 "forward directive in configuration file.");
1065 /* Parse the parent HTTP proxy host:port */
1068 if (strcmp(p, ".") != 0)
1070 cur_fwd->forward_host = strdup(p);
1072 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1075 cur_fwd->forward_port = atoi(p);
1078 if (cur_fwd->forward_port <= 0)
1080 cur_fwd->forward_port = 8000;
1085 cur_fwd->next = config->forward;
1086 config->forward = cur_fwd;
1090 /* *************************************************************************
1091 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1092 * *************************************************************************/
1093 case hash_forward_socks4:
1094 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1098 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1099 "forward-socks4 directive in configuration file.");
1100 string_append(&config->proxy_args,
1101 "<br>\nWARNING: Wrong number of parameters for "
1102 "forward-socks4 directive in configuration file.");
1106 /* allocate a new node */
1107 cur_fwd = zalloc(sizeof(*cur_fwd));
1108 if (cur_fwd == NULL)
1110 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1111 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1115 cur_fwd->type = SOCKS_4;
1117 /* Save the URL pattern */
1118 if (create_url_spec(cur_fwd->url, vec[0]))
1120 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1121 "directive in configuration file.");
1122 string_append(&config->proxy_args,
1123 "<br>\nWARNING: Bad URL specifier for "
1124 "forward-socks4 directive in configuration file.");
1128 /* Parse the SOCKS proxy host[:port] */
1131 if (strcmp(p, ".") != 0)
1133 cur_fwd->gateway_host = strdup(p);
1135 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1138 cur_fwd->gateway_port = atoi(p);
1140 if (cur_fwd->gateway_port <= 0)
1142 cur_fwd->gateway_port = 1080;
1146 /* Parse the parent HTTP proxy host[:port] */
1149 if (strcmp(p, ".") != 0)
1151 cur_fwd->forward_host = strdup(p);
1153 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1156 cur_fwd->forward_port = atoi(p);
1159 if (cur_fwd->forward_port <= 0)
1161 cur_fwd->forward_port = 8000;
1166 cur_fwd->next = config->forward;
1167 config->forward = cur_fwd;
1171 /* *************************************************************************
1172 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1173 * *************************************************************************/
1174 case hash_forward_socks4a:
1175 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1179 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1180 "forward-socks4a directive in configuration file.");
1181 string_append(&config->proxy_args,
1182 "<br>\nWARNING: Wrong number of parameters for "
1183 "forward-socks4a directive in configuration file.");
1187 /* allocate a new node */
1188 cur_fwd = zalloc(sizeof(*cur_fwd));
1189 if (cur_fwd == NULL)
1191 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1192 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1196 cur_fwd->type = SOCKS_4A;
1198 /* Save the URL pattern */
1199 if (create_url_spec(cur_fwd->url, vec[0]))
1201 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1202 "directive in configuration file.");
1203 string_append(&config->proxy_args,
1204 "<br>\nWARNING: Bad URL specifier for "
1205 "forward-socks4a directive in configuration file.");
1209 /* Parse the SOCKS proxy host[:port] */
1212 cur_fwd->gateway_host = strdup(p);
1214 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1217 cur_fwd->gateway_port = atoi(p);
1219 if (cur_fwd->gateway_port <= 0)
1221 cur_fwd->gateway_port = 1080;
1224 /* Parse the parent HTTP proxy host[:port] */
1227 if (strcmp(p, ".") != 0)
1229 cur_fwd->forward_host = strdup(p);
1231 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1234 cur_fwd->forward_port = atoi(p);
1237 if (cur_fwd->forward_port <= 0)
1239 cur_fwd->forward_port = 8000;
1244 cur_fwd->next = config->forward;
1245 config->forward = cur_fwd;
1249 /* *************************************************************************
1250 * forwarded-connect-retries n
1251 * *************************************************************************/
1252 case hash_forwarded_connect_retries :
1253 config->forwarded_connect_retries = atoi(arg);
1256 /* *************************************************************************
1257 * jarfile jar-file-name
1258 * In logdir by default
1259 * *************************************************************************/
1260 #ifdef FEATURE_COOKIE_JAR
1262 freez(config->jarfile);
1263 config->jarfile = make_path(config->logdir, arg);
1265 #endif /* def FEATURE_COOKIE_JAR */
1267 /* *************************************************************************
1268 * listen-address [ip][:port]
1269 * *************************************************************************/
1270 case hash_listen_address :
1271 freez(config->haddr);
1272 config->haddr = strdup(arg);
1275 /* *************************************************************************
1276 * logdir directory-name
1277 * *************************************************************************/
1279 freez(config->logdir);
1280 config->logdir = make_path(NULL, arg);
1283 /* *************************************************************************
1284 * logfile log-file-name
1285 * In logdir by default
1286 * *************************************************************************/
1288 freez(config->logfile);
1289 config->logfile = no_daemon ? NULL : make_path(config->logdir, arg);
1292 /* *************************************************************************
1293 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1294 * *************************************************************************/
1296 case hash_permit_access:
1297 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1299 if ((vec_count != 1) && (vec_count != 2))
1301 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1302 "permit-access directive in configuration file.");
1303 string_append(&config->proxy_args,
1304 "<br>\nWARNING: Wrong number of parameters for "
1305 "permit-access directive in configuration file.<br><br>\n");
1310 /* allocate a new node */
1311 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1313 if (cur_acl == NULL)
1315 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1316 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1319 cur_acl->action = ACL_PERMIT;
1321 if (acl_addr(vec[0], cur_acl->src) < 0)
1323 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1324 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1325 string_append(&config->proxy_args,
1326 "<br>\nWARNING: Invalid source address, port or netmask for "
1327 "permit-access directive in configuration file: \"");
1328 string_append(&config->proxy_args,
1330 string_append(&config->proxy_args,
1337 if (acl_addr(vec[1], cur_acl->dst) < 0)
1339 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1340 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1341 string_append(&config->proxy_args,
1342 "<br>\nWARNING: Invalid destination address, port or netmask for "
1343 "permit-access directive in configuration file: \"");
1344 string_append(&config->proxy_args,
1346 string_append(&config->proxy_args,
1354 * Add it to the list. Note we reverse the list to get the
1355 * behaviour the user expects. With both the ACL and
1356 * actions file, the last match wins. However, the internal
1357 * implementations are different: The actions file is stored
1358 * in the same order as the file, and scanned completely.
1359 * With the ACL, we reverse the order as we load it, then
1360 * when we scan it we stop as soon as we get a match.
1362 cur_acl->next = config->acl;
1363 config->acl = cur_acl;
1366 #endif /* def FEATURE_ACL */
1368 /* *************************************************************************
1369 * proxy-info-url url
1370 * *************************************************************************/
1371 case hash_proxy_info_url :
1372 freez(config->proxy_info_url);
1373 config->proxy_info_url = strdup(arg);
1376 /* *************************************************************************
1378 * *************************************************************************/
1379 case hash_single_threaded :
1380 config->multi_threaded = 0;
1383 /* *************************************************************************
1384 * split-large-cgi-forms
1385 * *************************************************************************/
1386 case hash_split_large_cgi_forms :
1387 if ((*arg != '\0') && (0 != atoi(arg)))
1389 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1393 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1397 /* *************************************************************************
1398 * templdir directory-name
1399 * *************************************************************************/
1400 case hash_templdir :
1401 freez(config->templdir);
1402 config->templdir = make_path(NULL, arg);
1405 /* *************************************************************************
1407 * *************************************************************************/
1408 #ifdef FEATURE_TOGGLE
1410 global_toggle_state = atoi(arg);
1412 #endif /* def FEATURE_TOGGLE */
1414 /* *************************************************************************
1415 * trust-info-url url
1416 * *************************************************************************/
1417 #ifdef FEATURE_TRUST
1418 case hash_trust_info_url :
1419 enlist(config->trust_info, arg);
1421 #endif /* def FEATURE_TRUST */
1423 /* *************************************************************************
1424 * trustfile filename
1425 * (In confdir by default.)
1426 * *************************************************************************/
1427 #ifdef FEATURE_TRUST
1428 case hash_trustfile :
1429 freez(config->trustfile);
1430 config->trustfile = make_path(config->confdir, arg);
1432 #endif /* def FEATURE_TRUST */
1434 /* *************************************************************************
1436 * *************************************************************************/
1437 case hash_usermanual :
1438 freez(config->usermanual);
1439 config->usermanual = strdup(arg);
1442 /* *************************************************************************
1443 * Win32 Console options:
1444 * *************************************************************************/
1446 /* *************************************************************************
1448 * *************************************************************************/
1450 case hash_hide_console :
1453 #endif /*def _WIN_CONSOLE*/
1456 /* *************************************************************************
1457 * Win32 GUI options:
1458 * *************************************************************************/
1460 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1461 /* *************************************************************************
1462 * activity-animation (0|1)
1463 * *************************************************************************/
1464 case hash_activity_animation :
1465 g_bShowActivityAnimation = atoi(arg);
1468 /* *************************************************************************
1469 * close-button-minimizes (0|1)
1470 * *************************************************************************/
1471 case hash_close_button_minimizes :
1472 g_bCloseHidesWindow = atoi(arg);
1475 /* *************************************************************************
1476 * log-buffer-size (0|1)
1477 * *************************************************************************/
1478 case hash_log_buffer_size :
1479 g_bLimitBufferSize = atoi(arg);
1482 /* *************************************************************************
1483 * log-font-name fontnane
1484 * *************************************************************************/
1485 case hash_log_font_name :
1486 strcpy( g_szFontFaceName, arg );
1489 /* *************************************************************************
1491 * *************************************************************************/
1492 case hash_log_font_size :
1493 g_nFontSize = atoi(arg);
1496 /* *************************************************************************
1497 * log-highlight-messages (0|1)
1498 * *************************************************************************/
1499 case hash_log_highlight_messages :
1500 g_bHighlightMessages = atoi(arg);
1503 /* *************************************************************************
1505 * *************************************************************************/
1506 case hash_log_max_lines :
1507 g_nMaxBufferLines = atoi(arg);
1510 /* *************************************************************************
1511 * log-messages (0|1)
1512 * *************************************************************************/
1513 case hash_log_messages :
1514 g_bLogMessages = atoi(arg);
1517 /* *************************************************************************
1518 * show-on-task-bar (0|1)
1519 * *************************************************************************/
1520 case hash_show_on_task_bar :
1521 g_bShowOnTaskBar = atoi(arg);
1524 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1527 /* *************************************************************************
1528 * Warnings about unsupported features
1529 * *************************************************************************/
1531 case hash_deny_access:
1532 #endif /* ndef FEATURE_ACL */
1533 #ifndef FEATURE_CGI_EDIT_ACTIONS
1534 case hash_enable_edit_actions:
1535 case hash_enable_remote_toggle:
1536 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1537 #ifndef FEATURE_COOKIE_JAR
1539 #endif /* ndef FEATURE_COOKIE_JAR */
1541 case hash_permit_access:
1542 #endif /* ndef FEATURE_ACL */
1543 #ifndef FEATURE_TOGGLE
1545 #endif /* ndef FEATURE_TOGGLE */
1546 #ifndef FEATURE_TRUST
1547 case hash_trustfile :
1548 case hash_trust_info_url :
1549 #endif /* ndef FEATURE_TRUST */
1551 #ifndef _WIN_CONSOLE
1552 case hash_hide_console :
1553 #endif /* ndef _WIN_CONSOLE */
1555 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1556 case hash_activity_animation :
1557 case hash_close_button_minimizes :
1558 case hash_log_buffer_size :
1559 case hash_log_font_name :
1560 case hash_log_font_size :
1561 case hash_log_highlight_messages :
1562 case hash_log_max_lines :
1563 case hash_log_messages :
1564 case hash_show_on_task_bar :
1565 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1566 /* These warnings are annoying - so hide them. -- Jon */
1567 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1570 /* *************************************************************************/
1572 /* *************************************************************************/
1574 * I decided that I liked this better as a warning than an
1575 * error. To change back to an error, just change log level
1576 * to LOG_LEVEL_FATAL.
1578 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1579 "in configuration file (%s).", buf, hash_string(cmd), linenum, configfile);
1580 string_append(&config->proxy_args,
1581 " <b><font color=\"red\">WARNING: unrecognized directive, ignored</font></b>");
1584 /* *************************************************************************/
1585 } /* end switch( hash_string(cmd) ) */
1586 } /* end while ( read_config_line(...) ) */
1590 if (NULL == config->proxy_args)
1592 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1595 init_error_log(Argv[0], config->logfile, config->debug);
1597 if (config->actions_file[0])
1599 add_loader(load_actions_file, config);
1602 if (config->re_filterfile)
1604 add_loader(load_re_filterfile, config);
1607 #ifdef FEATURE_TRUST
1608 if (config->trustfile)
1610 add_loader(load_trustfile, config);
1612 #endif /* def FEATURE_TRUST */
1614 #ifdef FEATURE_COOKIE_JAR
1615 if ( NULL != config->jarfile )
1617 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1619 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1620 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1622 setbuf(config->jar, NULL);
1624 #endif /* def FEATURE_COOKIE_JAR */
1626 if ( NULL == config->haddr )
1628 config->haddr = strdup( HADDR_DEFAULT );
1631 if ( NULL != config->haddr )
1633 if (NULL != (p = strchr(config->haddr, ':')))
1638 config->hport = atoi(p);
1642 if (config->hport <= 0)
1645 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1646 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1648 if (*config->haddr == '\0')
1650 config->haddr = NULL;
1655 * Want to run all the loaders once now.
1657 * Need to set up a fake csp, so they can get to the config.
1659 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1660 fake_csp->config = config;
1662 if (run_loader(fake_csp))
1665 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1666 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1670 /* FIXME: this is a kludge for win32 */
1671 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1673 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1674 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1675 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1677 #ifdef FEATURE_TRUST
1678 g_trustfile = config->trustfile;
1679 #endif /* def FEATURE_TRUST */
1682 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1683 /* FIXME: end kludge */
1686 config->need_bind = 1;
1688 if (current_configfile)
1690 struct configuration_spec * oldcfg = (struct configuration_spec *)
1691 current_configfile->f;
1693 * Check if config->haddr,hport == oldcfg->haddr,hport
1695 * The following could be written more compactly as a single,
1696 * (unreadably long) if statement.
1698 config->need_bind = 0;
1699 if (config->hport != oldcfg->hport)
1701 config->need_bind = 1;
1703 else if (config->haddr == NULL)
1705 if (oldcfg->haddr != NULL)
1707 config->need_bind = 1;
1710 else if (oldcfg->haddr == NULL)
1712 config->need_bind = 1;
1714 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1716 config->need_bind = 1;
1719 current_configfile->unloader = unload_configfile;
1722 fs->next = files->next;
1725 current_configfile = fs;
1731 /*********************************************************************
1733 * Function : savearg
1735 * Description : Called from `load_config'. It saves each non-empty
1736 * and non-comment line from config into
1737 * config->proxy_args. This is used to create the
1738 * show-proxy-args page. On error, frees
1739 * config->proxy_args and sets it to NULL
1742 * 1 : command = config setting that was found
1743 * 2 : argument = the setting's argument (if any)
1744 * 3 : config = Configuration to save into.
1748 *********************************************************************/
1749 static void savearg(char *command, char *argument, struct configuration_spec * config)
1759 * Add config option name embedded in
1760 * link to it's section in the user-manual
1762 buf = strdup("\n<a href=\"");
1763 if (!strncmpic(config->usermanual, "file://", 7) ||
1764 !strncmpic(config->usermanual, "http", 4))
1766 string_append(&buf, config->usermanual);
1770 string_append(&buf, "http://");
1771 string_append(&buf, CGI_SITE_2_HOST);
1772 string_append(&buf, "/user-manual/");
1774 string_append(&buf, CONFIG_HELP_PREFIX);
1775 string_join (&buf, string_toupper(command));
1776 string_append(&buf, "\">");
1777 string_append(&buf, command);
1778 string_append(&buf, "</a> ");
1782 freez(config->proxy_args);
1786 if ( (NULL != argument) && ('\0' != *argument) )
1788 s = html_encode(argument);
1792 freez(config->proxy_args);
1796 if (strncmpic(argument, "http://", 7) == 0)
1798 string_append(&buf, "<a href=\"");
1799 string_append(&buf, s);
1800 string_append(&buf, "\">");
1801 string_join (&buf, s);
1802 string_append(&buf, "</a>");
1806 string_join (&buf, s);
1810 string_append(&buf, "<br>");
1811 string_join(&config->proxy_args, buf);