1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.65 2007/07/21 11:51:36 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.65 2007/07/21 11:51:36 fabiankeil
39 * As Hal noticed, checking dispatch_cgi() as the last cruncher
40 * looks like a bug if CGI requests are blocked unintentionally,
41 * so don't do it unless the user enabled the new config option
42 * "allow-cgi-request-crunching".
44 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
45 * - Use strlcpy() instead of strcpy().
46 * - Stop treating actions files special. Expect a complete file name
47 * (with or without path) like it's done for the rest of the files.
49 * - Remove an unnecessary temporary memory allocation.
50 * - Don't log anything to the console when running as
51 * daemon and no errors occurred.
53 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
54 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
56 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
57 * New config option: enforce-blocks.
59 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
60 * - Mention other reasons why acl directive loading might have failed.
61 * - Don't log the acl source if the acl destination is to blame.
63 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
64 * Add new config option "templdir" to
65 * change the templates directory.
67 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
68 * Added config option accept-intercepted-requests
69 * and disabled it by default.
71 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
72 * Fix gcc43 compiler warnings.
74 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
75 * Add config option "split-large-forms"
76 * to work around the browser bug reported
79 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
80 * Move the <br> in the generated HTML for the config
81 * options from the beginning of the string to its end.
82 * Keeps the white space in balance.
84 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
85 * Fix memory leak in case of config file reloads.
87 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
88 * Modified kludge for win32 to make ming32 menu
89 * "Options/Edit Filters" (sort of) work again.
90 * Same limitations as for the action files apply.
93 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
94 * Incorporate modified version of Roland Rosenfeld's patch to
95 * optionally access the user-manual via Privoxy. Closes patch 679075.
97 * Formatting changed to Privoxy style, added call to
98 * cgi_error_no_template if the requested file doesn't
99 * exist and modified check whether or not Privoxy itself
100 * should serve the manual. Should work cross-platform now.
102 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
103 * Added config option enable-remote-http-toggle
104 * to specify if Privoxy should recognize special
105 * headers (currently only X-Filter) to change its
106 * behaviour. Disabled by default.
108 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
109 * Make number of retries in case of forwarded-connect problems
110 * a config file option (forwarded-connect-retries) and use 0 as
113 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
114 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
115 * with what was really the latest development (the v_3_0_branch branch)
117 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
118 * Don't forget to malloc space for the null terminator...
120 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
121 * Multiple filter file support
123 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
124 * Closed two memory leaks; hopefully the last remaining ones
125 * (in the main execution paths, anyway).
127 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
128 * Addressed bug #719435
129 * - Extraneous filterfile directives now logged as errors
130 * - This and unrecnonised directives now really obvious on status page
132 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
133 * Cosmetic: Renamed cryptic variable
135 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
136 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
138 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
139 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
141 * Revision 1.48 2002/05/14 21:30:38 oes
142 * savearg now uses own linking code instead of (now special-cased) add_help_link
144 * Revision 1.47 2002/05/12 21:36:29 jongfoster
145 * Correcting function comments
147 * Revision 1.46 2002/04/26 12:55:14 oes
148 * - New option "user-manual", defaults to our site
149 * via project.h #define
150 * - savearg now embeds option names in help links
152 * Revision 1.45 2002/04/24 02:11:54 oes
153 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
155 * Revision 1.44 2002/04/08 20:37:13 swa
158 * Revision 1.43 2002/04/08 20:36:50 swa
161 * Revision 1.42 2002/04/05 15:50:15 oes
162 * fix for invalid HTML proxy_args
164 * Revision 1.41 2002/03/31 17:19:00 jongfoster
165 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
167 * Revision 1.40 2002/03/26 22:29:55 swa
168 * we have a new homepage!
170 * Revision 1.39 2002/03/24 13:25:43 swa
171 * name change related issues
173 * Revision 1.38 2002/03/24 13:05:48 jongfoster
174 * Renaming re_filterfile to filterfile
176 * Revision 1.37 2002/03/16 23:54:06 jongfoster
177 * Adding graceful termination feature, to help look for memory leaks.
178 * If you enable this (which, by design, has to be done by hand
179 * editing config.h) and then go to http://i.j.b/die, then the program
180 * will exit cleanly after the *next* request. It should free all the
181 * memory that was used.
183 * Revision 1.36 2002/03/13 00:27:05 jongfoster
186 * Revision 1.35 2002/03/07 03:52:44 oes
187 * Set logging to tty for --no-daemon mode
189 * Revision 1.34 2002/03/06 23:14:35 jongfoster
190 * Trivial cosmetic changes to make function comments easier to find.
192 * Revision 1.33 2002/03/05 04:52:42 oes
193 * Deleted non-errlog debugging code
195 * Revision 1.32 2002/03/04 18:24:53 oes
196 * Re-enabled output of unknown config directive hash
198 * Revision 1.31 2002/03/03 15:07:20 oes
199 * Re-enabled automatic config reloading
201 * Revision 1.30 2002/01/22 23:31:43 jongfoster
202 * Replacing strsav() with string_append()
204 * Revision 1.29 2002/01/17 21:02:30 jongfoster
205 * Moving all our URL and URL pattern parsing code to urlmatch.c.
207 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
209 * Revision 1.28 2001/12/30 14:07:32 steudten
210 * - Add signal handling (unix)
211 * - Add SIGHUP handler (unix)
212 * - Add creation of pidfile (unix)
213 * - Add action 'top' in rc file (RH)
214 * - Add entry 'SIGNALS' to manpage
215 * - Add exit message to logfile (unix)
217 * Revision 1.27 2001/11/07 00:02:13 steudten
218 * Add line number in error output for lineparsing for
219 * actionsfile and configfile.
220 * Special handling for CLF added.
222 * Revision 1.26 2001/11/05 21:41:43 steudten
223 * Add changes to be a real daemon just for unix os.
224 * (change cwd to /, detach from controlling tty, set
225 * process group and session leader to the own process.
227 * Add some fatal-error log message for failed malloc().
228 * Add '-d' if compiled with 'configure --with-debug' to
229 * enable debug output.
231 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
232 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
233 * threads to call select() simultaneously. So, it's time to do a real, live,
234 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
235 * (native). Both versions will work, but using __OS2__ offers multi-threading.
237 * Revision 1.24 2001/10/23 21:40:30 jongfoster
238 * Added support for enable-edit-actions and enable-remote-toggle config
241 * Revision 1.23 2001/10/07 15:36:00 oes
242 * Introduced new config option "buffer-limit"
244 * Revision 1.22 2001/09/22 16:36:59 jongfoster
245 * Removing unused parameter fs from read_config_line()
247 * Revision 1.21 2001/09/16 17:10:43 jongfoster
248 * Moving function savearg() here, since it was the only thing left in
251 * Revision 1.20 2001/07/30 22:08:36 jongfoster
252 * Tidying up #defines:
253 * - All feature #defines are now of the form FEATURE_xxx
254 * - Permanently turned off WIN_GUI_EDIT
255 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
257 * Revision 1.19 2001/07/15 17:45:16 jongfoster
258 * Removing some unused #includes
260 * Revision 1.18 2001/07/13 14:01:14 oes
261 * - Removed all #ifdef PCRS
262 * - Removed vim-settings
264 * Revision 1.17 2001/06/29 13:31:03 oes
265 * - Improved comments
266 * - Fixed (actionsfile) and sorted hashes
267 * - Introduced admin_address and proxy-info-url
268 * as config parameters
269 * - Renamed config->proxy_args_invocation (which didn't have
270 * the invocation but the options!) to config->proxy_args
271 * - Various adaptions
272 * - Removed logentry from cancelled commit
274 * Revision 1.16 2001/06/09 10:55:28 jongfoster
275 * Changing BUFSIZ ==> BUFFER_SIZE
277 * Revision 1.15 2001/06/07 23:13:40 jongfoster
278 * Merging ACL and forward files into config file.
279 * Cosmetic: Sorting config file options alphabetically.
280 * Cosmetic: Adding brief syntax comments to config file options.
282 * Revision 1.14 2001/06/07 14:46:25 joergs
283 * Missing make_path() added for re_filterfile.
285 * Revision 1.13 2001/06/05 22:33:54 jongfoster
287 * Fixed minor memory leak.
288 * Also now uses make_path to prepend the pathnames.
290 * Revision 1.12 2001/06/05 20:04:09 jongfoster
291 * Now uses _snprintf() in place of snprintf() under Win32.
293 * Revision 1.11 2001/06/04 18:31:58 swa
294 * files are now prefixed with either `confdir' or `logdir'.
295 * `make redhat-dist' replaces both entries confdir and logdir
298 * Revision 1.10 2001/06/03 19:11:54 oes
299 * introduced confdir option
301 * Revision 1.9 2001/06/01 20:06:24 jongfoster
302 * Removed support for "tinygif" option - moved to actions file.
304 * Revision 1.8 2001/05/31 21:27:13 jongfoster
305 * Removed many options from the config file and into the
306 * "actions" file: add_forwarded, suppress_vanilla_wafer,
307 * wafer, add_header, user_agent, referer, from
308 * Also globally replaced "permission" with "action".
310 * Revision 1.7 2001/05/29 09:50:24 jongfoster
311 * Unified blocklist/imagelist/permissionslist.
312 * File format is still under discussion, but the internal changes
315 * Also modified interceptor behaviour:
316 * - We now intercept all URLs beginning with one of the following
317 * prefixes (and *only* these prefixes):
319 * * http://ijbswa.sf.net/config/
320 * * http://ijbswa.sourceforge.net/config/
321 * - New interceptors "home page" - go to http://i.j.b/ to see it.
322 * - Internal changes so that intercepted and fast redirect pages
323 * are not replaced with an image.
324 * - Interceptors now have the option to send a binary page direct
325 * to the client. (i.e. ijb-send-banner uses this)
326 * - Implemented show-url-info interceptor. (Which is why I needed
327 * the above interceptors changes - a typical URL is
328 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
329 * The previous mechanism would not have intercepted that, and
330 * if it had been intercepted then it then it would have replaced
333 * Revision 1.6 2001/05/26 00:28:36 jongfoster
334 * Automatic reloading of config file.
335 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
336 * Most of the global variables have been moved to a new
337 * struct configuration_spec, accessed through csp->config->globalname
338 * Most of the globals remaining are used by the Win32 GUI.
340 * Revision 1.5 2001/05/25 22:34:30 jongfoster
343 * Revision 1.4 2001/05/22 18:46:04 oes
345 * - Enabled filtering banners by size rather than URL
346 * by adding patterns that replace all standard banner
347 * sizes with the "Junkbuster" gif to the re_filterfile
349 * - Enabled filtering WebBugs by providing a pattern
350 * which kills all 1x1 images
352 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
353 * which is selected by the (nonstandard and therefore
354 * capital) letter 'U' in the option string.
355 * It causes the quantifiers to be ungreedy by default.
356 * Appending a ? turns back to greedy (!).
358 * - Added a new interceptor ijb-send-banner, which
359 * sends back the "Junkbuster" gif. Without imagelist or
360 * MSIE detection support, or if tinygif = 1, or the
361 * URL isn't recognized as an imageurl, a lame HTML
362 * explanation is sent instead.
364 * - Added new feature, which permits blocking remote
365 * script redirects and firing back a local redirect
367 * The feature is conditionally compiled, i.e. it
368 * can be disabled with --disable-fast-redirects,
369 * plus it must be activated by a "fast-redirects"
370 * line in the config file, has its own log level
371 * and of course wants to be displayed by show-proxy-args
372 * Note: Boy, all the #ifdefs in 1001 locations and
373 * all the fumbling with configure.in and acconfig.h
374 * were *way* more work than the feature itself :-(
376 * - Because a generic redirect template was needed for
377 * this, tinygif = 3 now uses the same.
379 * - Moved GIFs, and other static HTTP response templates
384 * - Removed some >400 CRs again (Jon, you really worked
387 * Revision 1.3 2001/05/20 01:21:20 jongfoster
388 * Version 2.9.4 checkin.
389 * - Merged popupfile and cookiefile, and added control over PCRS
390 * filtering, in new "permissionsfile".
391 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
392 * file error you now get a message box (in the Win32 GUI) rather
393 * than the program exiting with no explanation.
394 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
396 * - Removed tabs from "config"
397 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
398 * - Bumped up version number.
400 * Revision 1.2 2001/05/17 23:01:01 oes
401 * - Cleaned CRLF's from the sources and related files
403 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
404 * Initial import of version 2.9.3 source tree
407 *********************************************************************/
413 #include <sys/types.h>
427 # include <windows.h>
430 # ifndef _WIN_CONSOLE
432 # endif /* ndef _WIN_CONSOLE */
434 #else /* ifndef _WIN32 */
438 # include <sys/wait.h>
440 # include <sys/time.h>
441 # include <sys/stat.h>
451 #include "miscutil.h"
455 #include "urlmatch.h"
458 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
461 * Fix a problem with Solaris. There should be no effect on other
463 * Solaris's isspace() is a macro which uses it's argument directly
464 * as an array index. Therefore we need to make sure that high-bit
465 * characters generate +ve values, and ideally we also want to make
466 * the argument match the declared parameter type of "int".
468 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
469 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
471 #ifdef FEATURE_TOGGLE
472 /* Privoxy is enabled by default. */
473 int global_toggle_state = 1;
474 #endif /* def FEATURE_TOGGLE */
476 /* The filename of the configfile */
477 const char *configfile = NULL;
480 * CGI functions will later need access to the invocation args,
481 * so we will make argc and argv global.
484 const char **Argv = NULL;
486 static struct file_list *current_configfile = NULL;
490 * This takes the "cryptic" hash of each keyword and aliases them to
491 * something a little more readable. This also makes changing the
492 * hash values easier if they should change or the hash algorthm changes.
493 * Use the included "hash" program to find out what the hash will be
494 * for any string supplied on the command line. (Or just put it in the
495 * config file and read the number from the error message in the log).
497 * Please keep this list sorted alphabetically (but with the Windows
498 * console and GUI specific options last).
501 #define hash_actions_file 1196306641ul /* "actionsfile" */
502 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
503 #define hash_admin_address 4112573064ul /* "admin-address" */
504 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
505 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
506 #define hash_confdir 1978389ul /* "confdir" */
507 #define hash_debug 78263ul /* "debug" */
508 #define hash_deny_access 1227333715ul /* "deny-access" */
509 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
510 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
511 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
512 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
513 #define hash_filterfile 250887266ul /* "filterfile" */
514 #define hash_forward 2029845ul /* "forward" */
515 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
516 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
517 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
518 #define hash_jarfile 2046641ul /* "jarfile" */
519 #define hash_listen_address 1255650842ul /* "listen-address" */
520 #define hash_logdir 422889ul /* "logdir" */
521 #define hash_logfile 2114766ul /* "logfile" */
522 #define hash_permit_access 3587953268ul /* "permit-access" */
523 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
524 #define hash_single_threaded 4250084780ul /* "single-threaded" */
525 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
526 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
527 #define hash_templdir 11067889ul /* "templdir" */
528 #define hash_toggle 447966ul /* "toggle" */
529 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
530 #define hash_trustfile 56494766ul /* "trustfile" */
531 #define hash_usermanual 1416668518ul /* "user-manual" */
532 #define hash_activity_animation 1817904738ul /* "activity-animation" */
533 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
534 #define hash_hide_console 2048809870ul /* "hide-console" */
535 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
536 #define hash_log_font_name 2866730124ul /* "log-font-name" */
537 #define hash_log_font_size 2866731014ul /* "log-font-size" */
538 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
539 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
540 #define hash_log_messages 2291744899ul /* "log-messages" */
541 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
544 static void savearg(char *command, char *argument, struct configuration_spec * config);
546 /*********************************************************************
548 * Function : unload_configfile
550 * Description : Free the config structure and all components.
553 * 1 : data: struct configuration_spec to unload
557 *********************************************************************/
558 static void unload_configfile (void * data)
560 struct configuration_spec * config = (struct configuration_spec *)data;
561 struct forward_spec *cur_fwd = config->forward;
565 struct access_control_list *cur_acl = config->acl;
567 while (cur_acl != NULL)
569 struct access_control_list * next_acl = cur_acl->next;
574 #endif /* def FEATURE_ACL */
576 while (cur_fwd != NULL)
578 struct forward_spec * next_fwd = cur_fwd->next;
579 free_url_spec(cur_fwd->url);
581 freez(cur_fwd->gateway_host);
582 freez(cur_fwd->forward_host);
586 config->forward = NULL;
588 #ifdef FEATURE_COOKIE_JAR
589 if ( NULL != config->jar )
591 fclose( config->jar );
594 #endif /* def FEATURE_COOKIE_JAR */
596 freez(config->confdir);
597 freez(config->logdir);
598 freez(config->templdir);
600 freez(config->haddr);
601 freez(config->logfile);
603 for (i = 0; i < MAX_AF_FILES; i++)
605 freez(config->actions_file_short[i]);
606 freez(config->actions_file[i]);
607 freez(config->re_filterfile_short[i]);
608 freez(config->re_filterfile[i]);
611 freez(config->admin_address);
612 freez(config->proxy_info_url);
613 freez(config->proxy_args);
614 freez(config->usermanual);
616 #ifdef FEATURE_COOKIE_JAR
617 freez(config->jarfile);
618 #endif /* def FEATURE_COOKIE_JAR */
621 freez(config->trustfile);
622 list_remove_all(config->trust_info);
623 #endif /* def FEATURE_TRUST */
625 for (i = 0; i < MAX_AF_FILES; i++)
627 freez(config->re_filterfile[i]);
634 #ifdef FEATURE_GRACEFUL_TERMINATION
635 /*********************************************************************
637 * Function : unload_current_config_file
639 * Description : Unloads current config file - reset to state at
640 * beginning of program.
646 *********************************************************************/
647 void unload_current_config_file(void)
649 if (current_configfile)
651 current_configfile->unloader = unload_configfile;
652 current_configfile = NULL;
658 /*********************************************************************
660 * Function : load_config
662 * Description : Load the config file and all parameters.
666 * Returns : The configuration_spec, or NULL on error.
668 *********************************************************************/
669 struct configuration_spec * load_config(void)
671 char buf[BUFFER_SIZE];
673 FILE *configfp = NULL;
674 struct configuration_spec * config = NULL;
675 struct client_state * fake_csp;
676 struct file_list *fs;
677 unsigned long linenum = 0;
680 if ( !check_file_changed(current_configfile, configfile, &fs))
682 /* No need to load */
683 return ((struct configuration_spec *)current_configfile->f);
687 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
691 if (NULL != current_configfile)
693 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
696 #ifdef FEATURE_TOGGLE
697 global_toggle_state = 1;
698 #endif /* def FEATURE_TOGGLE */
700 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
706 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
707 /* Never get here - LOG_LEVEL_FATAL causes program exit */
711 * This is backwards from how it's usually done.
712 * Following the usual pattern, "fs" would be stored in a member
713 * variable in "csp", and then we'd access "config" from "fs->f",
714 * using a cast. However, "config" is used so often that a
715 * cast each time would be very ugly, and the extra indirection
716 * would waste CPU cycles. Therefore we store "config" in
717 * "csp->config", and "fs" in "csp->config->config_file_list".
719 config->config_file_list = fs;
724 config->multi_threaded = 1;
725 config->hport = HADDR_PORT;
726 config->buffer_limit = 4096 * 1024;
727 config->usermanual = strdup(USER_MANUAL_URL);
728 config->proxy_args = strdup("");
729 config->forwarded_connect_retries = 0;
730 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
731 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
732 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
734 if ((configfp = fopen(configfile, "r")) == NULL)
736 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
738 /* Never get here - LOG_LEVEL_FATAL causes program exit */
741 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
743 char cmd[BUFFER_SIZE];
744 char arg[BUFFER_SIZE];
745 char tmp[BUFFER_SIZE];
747 struct access_control_list *cur_acl;
748 #endif /* def FEATURE_ACL */
749 struct forward_spec *cur_fwd;
753 strlcpy(tmp, buf, sizeof(tmp));
755 /* Copy command (i.e. up to space or tab) into cmd */
758 while (*p && (*p != ' ') && (*p != '\t'))
764 /* Skip over the whitespace in buf */
765 while (*p && ((*p == ' ') || (*p == '\t')))
770 /* Copy the argument into arg */
771 strlcpy(arg, p, sizeof(arg));
773 /* Should never happen, but check this anyway */
779 /* Make sure the command field is lower case */
784 *p = (char)ijb_tolower(*p);
788 /* Save the argument for show-proxy-args */
789 savearg(cmd, arg, config);
792 switch( hash_string( cmd ) )
794 /* *************************************************************************
795 * actionsfile actions-file-name
796 * In confdir by default
797 * *************************************************************************/
798 case hash_actions_file :
800 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
805 if (i >= MAX_AF_FILES)
807 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
808 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
811 config->actions_file_short[i] = strdup(arg);
812 config->actions_file[i] = make_path(config->confdir, arg);
815 /* *************************************************************************
816 * accept-intercepted-requests
817 * *************************************************************************/
818 case hash_accept_intercepted_requests:
819 if ((*arg != '\0') && (0 != atoi(arg)))
821 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
825 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
829 /* *************************************************************************
830 * admin-address email-address
831 * *************************************************************************/
832 case hash_admin_address :
833 freez(config->admin_address);
834 config->admin_address = strdup(arg);
837 /* *************************************************************************
838 * allow-cgi-request-crunching
839 * *************************************************************************/
840 case hash_allow_cgi_request_crunching:
841 if ((*arg != '\0') && (0 != atoi(arg)))
843 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
847 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
851 /* *************************************************************************
853 * *************************************************************************/
854 case hash_buffer_limit :
855 config->buffer_limit = (size_t)(1024 * atoi(arg));
858 /* *************************************************************************
859 * confdir directory-name
860 * *************************************************************************/
862 freez(config->confdir);
863 config->confdir = make_path( NULL, arg);
866 /* *************************************************************************
868 * Specifies debug level, multiple values are ORed together.
869 * *************************************************************************/
871 config->debug |= atoi(arg);
874 /* *************************************************************************
875 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
876 * *************************************************************************/
878 case hash_deny_access:
879 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
881 if ((vec_count != 1) && (vec_count != 2))
883 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
884 "deny-access directive in configuration file.");
885 string_append(&config->proxy_args,
886 "<br>\nWARNING: Wrong number of parameters for "
887 "deny-access directive in configuration file.<br><br>\n");
891 /* allocate a new node */
892 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
896 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
897 /* Never get here - LOG_LEVEL_FATAL causes program exit */
900 cur_acl->action = ACL_DENY;
902 if (acl_addr(vec[0], cur_acl->src) < 0)
904 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
905 "for deny-access directive in configuration file: \"%s\"", vec[0]);
906 string_append(&config->proxy_args,
907 "<br>\nWARNING: Invalid source address, port or netmask "
908 "for deny-access directive in configuration file: \"");
909 string_append(&config->proxy_args,
911 string_append(&config->proxy_args,
918 if (acl_addr(vec[1], cur_acl->dst) < 0)
920 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
921 "for deny-access directive in configuration file: \"%s\"", vec[1]);
922 string_append(&config->proxy_args,
923 "<br>\nWARNING: Invalid destination address, port or netmask "
924 "for deny-access directive in configuration file: \"");
925 string_append(&config->proxy_args,
927 string_append(&config->proxy_args,
935 * Add it to the list. Note we reverse the list to get the
936 * behaviour the user expects. With both the ACL and
937 * actions file, the last match wins. However, the internal
938 * implementations are different: The actions file is stored
939 * in the same order as the file, and scanned completely.
940 * With the ACL, we reverse the order as we load it, then
941 * when we scan it we stop as soon as we get a match.
943 cur_acl->next = config->acl;
944 config->acl = cur_acl;
947 #endif /* def FEATURE_ACL */
949 /* *************************************************************************
950 * enable-edit-actions 0|1
951 * *************************************************************************/
952 #ifdef FEATURE_CGI_EDIT_ACTIONS
953 case hash_enable_edit_actions:
954 if ((*arg != '\0') && (0 != atoi(arg)))
956 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
960 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
963 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
965 /* *************************************************************************
966 * enable-remote-toggle 0|1
967 * *************************************************************************/
968 #ifdef FEATURE_CGI_EDIT_ACTIONS
969 case hash_enable_remote_toggle:
970 if ((*arg != '\0') && (0 != atoi(arg)))
972 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
976 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
979 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
981 /* *************************************************************************
982 * enable-remote-http-toggle 0|1
983 * *************************************************************************/
984 case hash_enable_remote_http_toggle:
985 if ((*arg != '\0') && (0 != atoi(arg)))
987 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
991 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
995 /* *************************************************************************
996 * hash_enforce_blocks 0|1
997 * *************************************************************************/
998 #ifdef FEATURE_FORCE_LOAD
999 case hash_enforce_blocks:
1000 if ((*arg != '\0') && (0 != atoi(arg)))
1002 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1006 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1009 #endif /* def FEATURE_FORCE_LOAD */
1011 /* *************************************************************************
1012 * filterfile file-name
1013 * In confdir by default.
1014 * *************************************************************************/
1015 case hash_filterfile :
1017 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1022 if (i >= MAX_AF_FILES)
1024 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1025 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1028 config->re_filterfile_short[i] = strdup(arg);
1029 config->re_filterfile[i] = make_path(config->confdir, arg);
1033 /* *************************************************************************
1034 * forward url-pattern (.|http-proxy-host[:port])
1035 * *************************************************************************/
1037 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1041 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1042 "directive in configuration file.");
1043 string_append(&config->proxy_args,
1044 "<br>\nWARNING: Wrong number of parameters for "
1045 "forward directive in configuration file.");
1049 /* allocate a new node */
1050 cur_fwd = zalloc(sizeof(*cur_fwd));
1051 if (cur_fwd == NULL)
1053 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1054 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1058 cur_fwd->type = SOCKS_NONE;
1060 /* Save the URL pattern */
1061 if (create_url_spec(cur_fwd->url, vec[0]))
1063 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1064 "directive in configuration file.");
1065 string_append(&config->proxy_args,
1066 "<br>\nWARNING: Bad URL specifier for "
1067 "forward directive in configuration file.");
1071 /* Parse the parent HTTP proxy host:port */
1074 if (strcmp(p, ".") != 0)
1076 cur_fwd->forward_host = strdup(p);
1078 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1081 cur_fwd->forward_port = atoi(p);
1084 if (cur_fwd->forward_port <= 0)
1086 cur_fwd->forward_port = 8000;
1091 cur_fwd->next = config->forward;
1092 config->forward = cur_fwd;
1096 /* *************************************************************************
1097 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1098 * *************************************************************************/
1099 case hash_forward_socks4:
1100 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1104 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1105 "forward-socks4 directive in configuration file.");
1106 string_append(&config->proxy_args,
1107 "<br>\nWARNING: Wrong number of parameters for "
1108 "forward-socks4 directive in configuration file.");
1112 /* allocate a new node */
1113 cur_fwd = zalloc(sizeof(*cur_fwd));
1114 if (cur_fwd == NULL)
1116 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1117 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1121 cur_fwd->type = SOCKS_4;
1123 /* Save the URL pattern */
1124 if (create_url_spec(cur_fwd->url, vec[0]))
1126 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1127 "directive in configuration file.");
1128 string_append(&config->proxy_args,
1129 "<br>\nWARNING: Bad URL specifier for "
1130 "forward-socks4 directive in configuration file.");
1134 /* Parse the SOCKS proxy host[:port] */
1137 if (strcmp(p, ".") != 0)
1139 cur_fwd->gateway_host = strdup(p);
1141 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1144 cur_fwd->gateway_port = atoi(p);
1146 if (cur_fwd->gateway_port <= 0)
1148 cur_fwd->gateway_port = 1080;
1152 /* Parse the parent HTTP proxy host[:port] */
1155 if (strcmp(p, ".") != 0)
1157 cur_fwd->forward_host = strdup(p);
1159 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1162 cur_fwd->forward_port = atoi(p);
1165 if (cur_fwd->forward_port <= 0)
1167 cur_fwd->forward_port = 8000;
1172 cur_fwd->next = config->forward;
1173 config->forward = cur_fwd;
1177 /* *************************************************************************
1178 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1179 * *************************************************************************/
1180 case hash_forward_socks4a:
1181 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1185 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1186 "forward-socks4a directive in configuration file.");
1187 string_append(&config->proxy_args,
1188 "<br>\nWARNING: Wrong number of parameters for "
1189 "forward-socks4a directive in configuration file.");
1193 /* allocate a new node */
1194 cur_fwd = zalloc(sizeof(*cur_fwd));
1195 if (cur_fwd == NULL)
1197 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1198 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1202 cur_fwd->type = SOCKS_4A;
1204 /* Save the URL pattern */
1205 if (create_url_spec(cur_fwd->url, vec[0]))
1207 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1208 "directive in configuration file.");
1209 string_append(&config->proxy_args,
1210 "<br>\nWARNING: Bad URL specifier for "
1211 "forward-socks4a directive in configuration file.");
1215 /* Parse the SOCKS proxy host[:port] */
1218 cur_fwd->gateway_host = strdup(p);
1220 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1223 cur_fwd->gateway_port = atoi(p);
1225 if (cur_fwd->gateway_port <= 0)
1227 cur_fwd->gateway_port = 1080;
1230 /* Parse the parent HTTP proxy host[:port] */
1233 if (strcmp(p, ".") != 0)
1235 cur_fwd->forward_host = strdup(p);
1237 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1240 cur_fwd->forward_port = atoi(p);
1243 if (cur_fwd->forward_port <= 0)
1245 cur_fwd->forward_port = 8000;
1250 cur_fwd->next = config->forward;
1251 config->forward = cur_fwd;
1255 /* *************************************************************************
1256 * forwarded-connect-retries n
1257 * *************************************************************************/
1258 case hash_forwarded_connect_retries :
1259 config->forwarded_connect_retries = atoi(arg);
1262 /* *************************************************************************
1263 * jarfile jar-file-name
1264 * In logdir by default
1265 * *************************************************************************/
1266 #ifdef FEATURE_COOKIE_JAR
1268 freez(config->jarfile);
1269 config->jarfile = make_path(config->logdir, arg);
1271 #endif /* def FEATURE_COOKIE_JAR */
1273 /* *************************************************************************
1274 * listen-address [ip][:port]
1275 * *************************************************************************/
1276 case hash_listen_address :
1277 freez(config->haddr);
1278 config->haddr = strdup(arg);
1281 /* *************************************************************************
1282 * logdir directory-name
1283 * *************************************************************************/
1285 freez(config->logdir);
1286 config->logdir = make_path(NULL, arg);
1289 /* *************************************************************************
1290 * logfile log-file-name
1291 * In logdir by default
1292 * *************************************************************************/
1294 freez(config->logfile);
1295 config->logfile = no_daemon ? NULL : make_path(config->logdir, arg);
1298 /* *************************************************************************
1299 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1300 * *************************************************************************/
1302 case hash_permit_access:
1303 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1305 if ((vec_count != 1) && (vec_count != 2))
1307 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1308 "permit-access directive in configuration file.");
1309 string_append(&config->proxy_args,
1310 "<br>\nWARNING: Wrong number of parameters for "
1311 "permit-access directive in configuration file.<br><br>\n");
1316 /* allocate a new node */
1317 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1319 if (cur_acl == NULL)
1321 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1322 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1325 cur_acl->action = ACL_PERMIT;
1327 if (acl_addr(vec[0], cur_acl->src) < 0)
1329 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1330 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1331 string_append(&config->proxy_args,
1332 "<br>\nWARNING: Invalid source address, port or netmask for "
1333 "permit-access directive in configuration file: \"");
1334 string_append(&config->proxy_args,
1336 string_append(&config->proxy_args,
1343 if (acl_addr(vec[1], cur_acl->dst) < 0)
1345 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1346 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1347 string_append(&config->proxy_args,
1348 "<br>\nWARNING: Invalid destination address, port or netmask for "
1349 "permit-access directive in configuration file: \"");
1350 string_append(&config->proxy_args,
1352 string_append(&config->proxy_args,
1360 * Add it to the list. Note we reverse the list to get the
1361 * behaviour the user expects. With both the ACL and
1362 * actions file, the last match wins. However, the internal
1363 * implementations are different: The actions file is stored
1364 * in the same order as the file, and scanned completely.
1365 * With the ACL, we reverse the order as we load it, then
1366 * when we scan it we stop as soon as we get a match.
1368 cur_acl->next = config->acl;
1369 config->acl = cur_acl;
1372 #endif /* def FEATURE_ACL */
1374 /* *************************************************************************
1375 * proxy-info-url url
1376 * *************************************************************************/
1377 case hash_proxy_info_url :
1378 freez(config->proxy_info_url);
1379 config->proxy_info_url = strdup(arg);
1382 /* *************************************************************************
1384 * *************************************************************************/
1385 case hash_single_threaded :
1386 config->multi_threaded = 0;
1389 /* *************************************************************************
1390 * split-large-cgi-forms
1391 * *************************************************************************/
1392 case hash_split_large_cgi_forms :
1393 if ((*arg != '\0') && (0 != atoi(arg)))
1395 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1399 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1403 /* *************************************************************************
1404 * templdir directory-name
1405 * *************************************************************************/
1406 case hash_templdir :
1407 freez(config->templdir);
1408 config->templdir = make_path(NULL, arg);
1411 /* *************************************************************************
1413 * *************************************************************************/
1414 #ifdef FEATURE_TOGGLE
1416 global_toggle_state = atoi(arg);
1418 #endif /* def FEATURE_TOGGLE */
1420 /* *************************************************************************
1421 * trust-info-url url
1422 * *************************************************************************/
1423 #ifdef FEATURE_TRUST
1424 case hash_trust_info_url :
1425 enlist(config->trust_info, arg);
1427 #endif /* def FEATURE_TRUST */
1429 /* *************************************************************************
1430 * trustfile filename
1431 * (In confdir by default.)
1432 * *************************************************************************/
1433 #ifdef FEATURE_TRUST
1434 case hash_trustfile :
1435 freez(config->trustfile);
1436 config->trustfile = make_path(config->confdir, arg);
1438 #endif /* def FEATURE_TRUST */
1440 /* *************************************************************************
1442 * *************************************************************************/
1443 case hash_usermanual :
1444 freez(config->usermanual);
1445 config->usermanual = strdup(arg);
1448 /* *************************************************************************
1449 * Win32 Console options:
1450 * *************************************************************************/
1452 /* *************************************************************************
1454 * *************************************************************************/
1456 case hash_hide_console :
1459 #endif /*def _WIN_CONSOLE*/
1462 /* *************************************************************************
1463 * Win32 GUI options:
1464 * *************************************************************************/
1466 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1467 /* *************************************************************************
1468 * activity-animation (0|1)
1469 * *************************************************************************/
1470 case hash_activity_animation :
1471 g_bShowActivityAnimation = atoi(arg);
1474 /* *************************************************************************
1475 * close-button-minimizes (0|1)
1476 * *************************************************************************/
1477 case hash_close_button_minimizes :
1478 g_bCloseHidesWindow = atoi(arg);
1481 /* *************************************************************************
1482 * log-buffer-size (0|1)
1483 * *************************************************************************/
1484 case hash_log_buffer_size :
1485 g_bLimitBufferSize = atoi(arg);
1488 /* *************************************************************************
1489 * log-font-name fontnane
1490 * *************************************************************************/
1491 case hash_log_font_name :
1492 strcpy( g_szFontFaceName, arg );
1495 /* *************************************************************************
1497 * *************************************************************************/
1498 case hash_log_font_size :
1499 g_nFontSize = atoi(arg);
1502 /* *************************************************************************
1503 * log-highlight-messages (0|1)
1504 * *************************************************************************/
1505 case hash_log_highlight_messages :
1506 g_bHighlightMessages = atoi(arg);
1509 /* *************************************************************************
1511 * *************************************************************************/
1512 case hash_log_max_lines :
1513 g_nMaxBufferLines = atoi(arg);
1516 /* *************************************************************************
1517 * log-messages (0|1)
1518 * *************************************************************************/
1519 case hash_log_messages :
1520 g_bLogMessages = atoi(arg);
1523 /* *************************************************************************
1524 * show-on-task-bar (0|1)
1525 * *************************************************************************/
1526 case hash_show_on_task_bar :
1527 g_bShowOnTaskBar = atoi(arg);
1530 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1533 /* *************************************************************************
1534 * Warnings about unsupported features
1535 * *************************************************************************/
1537 case hash_deny_access:
1538 #endif /* ndef FEATURE_ACL */
1539 #ifndef FEATURE_CGI_EDIT_ACTIONS
1540 case hash_enable_edit_actions:
1541 case hash_enable_remote_toggle:
1542 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1543 #ifndef FEATURE_COOKIE_JAR
1545 #endif /* ndef FEATURE_COOKIE_JAR */
1547 case hash_permit_access:
1548 #endif /* ndef FEATURE_ACL */
1549 #ifndef FEATURE_TOGGLE
1551 #endif /* ndef FEATURE_TOGGLE */
1552 #ifndef FEATURE_TRUST
1553 case hash_trustfile :
1554 case hash_trust_info_url :
1555 #endif /* ndef FEATURE_TRUST */
1557 #ifndef _WIN_CONSOLE
1558 case hash_hide_console :
1559 #endif /* ndef _WIN_CONSOLE */
1561 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1562 case hash_activity_animation :
1563 case hash_close_button_minimizes :
1564 case hash_log_buffer_size :
1565 case hash_log_font_name :
1566 case hash_log_font_size :
1567 case hash_log_highlight_messages :
1568 case hash_log_max_lines :
1569 case hash_log_messages :
1570 case hash_show_on_task_bar :
1571 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1572 /* These warnings are annoying - so hide them. -- Jon */
1573 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1576 /* *************************************************************************/
1578 /* *************************************************************************/
1580 * I decided that I liked this better as a warning than an
1581 * error. To change back to an error, just change log level
1582 * to LOG_LEVEL_FATAL.
1584 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1585 "in configuration file (%s).", buf, hash_string(cmd), linenum, configfile);
1586 string_append(&config->proxy_args,
1587 " <b><font color=\"red\">WARNING: unrecognized directive, ignored</font></b>");
1590 /* *************************************************************************/
1591 } /* end switch( hash_string(cmd) ) */
1592 } /* end while ( read_config_line(...) ) */
1596 if (NULL == config->proxy_args)
1598 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1601 init_error_log(Argv[0], config->logfile, config->debug);
1603 if (config->actions_file[0])
1605 add_loader(load_actions_file, config);
1608 if (config->re_filterfile)
1610 add_loader(load_re_filterfile, config);
1613 #ifdef FEATURE_TRUST
1614 if (config->trustfile)
1616 add_loader(load_trustfile, config);
1618 #endif /* def FEATURE_TRUST */
1620 #ifdef FEATURE_COOKIE_JAR
1621 if ( NULL != config->jarfile )
1623 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1625 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1626 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1628 setbuf(config->jar, NULL);
1630 #endif /* def FEATURE_COOKIE_JAR */
1632 if ( NULL == config->haddr )
1634 config->haddr = strdup( HADDR_DEFAULT );
1637 if ( NULL != config->haddr )
1639 if (NULL != (p = strchr(config->haddr, ':')))
1644 config->hport = atoi(p);
1648 if (config->hport <= 0)
1651 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1652 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1654 if (*config->haddr == '\0')
1656 config->haddr = NULL;
1661 * Want to run all the loaders once now.
1663 * Need to set up a fake csp, so they can get to the config.
1665 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1666 fake_csp->config = config;
1668 if (run_loader(fake_csp))
1671 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1672 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1676 /* FIXME: this is a kludge for win32 */
1677 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1679 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1680 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1681 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1683 #ifdef FEATURE_TRUST
1684 g_trustfile = config->trustfile;
1685 #endif /* def FEATURE_TRUST */
1688 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1689 /* FIXME: end kludge */
1692 config->need_bind = 1;
1694 if (current_configfile)
1696 struct configuration_spec * oldcfg = (struct configuration_spec *)
1697 current_configfile->f;
1699 * Check if config->haddr,hport == oldcfg->haddr,hport
1701 * The following could be written more compactly as a single,
1702 * (unreadably long) if statement.
1704 config->need_bind = 0;
1705 if (config->hport != oldcfg->hport)
1707 config->need_bind = 1;
1709 else if (config->haddr == NULL)
1711 if (oldcfg->haddr != NULL)
1713 config->need_bind = 1;
1716 else if (oldcfg->haddr == NULL)
1718 config->need_bind = 1;
1720 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1722 config->need_bind = 1;
1725 current_configfile->unloader = unload_configfile;
1728 fs->next = files->next;
1731 current_configfile = fs;
1737 /*********************************************************************
1739 * Function : savearg
1741 * Description : Called from `load_config'. It saves each non-empty
1742 * and non-comment line from config into
1743 * config->proxy_args. This is used to create the
1744 * show-proxy-args page. On error, frees
1745 * config->proxy_args and sets it to NULL
1748 * 1 : command = config setting that was found
1749 * 2 : argument = the setting's argument (if any)
1750 * 3 : config = Configuration to save into.
1754 *********************************************************************/
1755 static void savearg(char *command, char *argument, struct configuration_spec * config)
1765 * Add config option name embedded in
1766 * link to it's section in the user-manual
1768 buf = strdup("\n<a href=\"");
1769 if (!strncmpic(config->usermanual, "file://", 7) ||
1770 !strncmpic(config->usermanual, "http", 4))
1772 string_append(&buf, config->usermanual);
1776 string_append(&buf, "http://");
1777 string_append(&buf, CGI_SITE_2_HOST);
1778 string_append(&buf, "/user-manual/");
1780 string_append(&buf, CONFIG_HELP_PREFIX);
1781 string_join (&buf, string_toupper(command));
1782 string_append(&buf, "\">");
1783 string_append(&buf, command);
1784 string_append(&buf, "</a> ");
1788 freez(config->proxy_args);
1792 if ( (NULL != argument) && ('\0' != *argument) )
1794 s = html_encode(argument);
1798 freez(config->proxy_args);
1802 if (strncmpic(argument, "http://", 7) == 0)
1804 string_append(&buf, "<a href=\"");
1805 string_append(&buf, s);
1806 string_append(&buf, "\">");
1807 string_join (&buf, s);
1808 string_append(&buf, "</a>");
1812 string_join (&buf, s);
1816 string_append(&buf, "<br>");
1817 string_join(&config->proxy_args, buf);