1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.72 2008/02/03 13:46:15 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.72 2008/02/03 13:46:15 fabiankeil
39 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
41 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
42 * Reword "unrecognized directive" warning, use better
43 * mark up and add a <br>. Fixes parts of #1856559.
45 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
46 * Plug memory leak if listen-address only specifies the port.
48 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
49 * Relocate daemon-mode-related log messages to make sure
50 * they aren't shown again in case of configuration reloads.
52 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
53 * Plug memory leak introduced with my last commit.
55 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
56 * When in daemon mode, close stderr after the configuration file has been
57 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
59 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
60 * #1763173 from Stefan Huehner: declare unload_configfile() static.
62 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
63 * As Hal noticed, checking dispatch_cgi() as the last cruncher
64 * looks like a bug if CGI requests are blocked unintentionally,
65 * so don't do it unless the user enabled the new config option
66 * "allow-cgi-request-crunching".
68 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
69 * - Use strlcpy() instead of strcpy().
70 * - Stop treating actions files special. Expect a complete file name
71 * (with or without path) like it's done for the rest of the files.
73 * - Remove an unnecessary temporary memory allocation.
74 * - Don't log anything to the console when running as
75 * daemon and no errors occurred.
77 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
78 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
80 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
81 * New config option: enforce-blocks.
83 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
84 * - Mention other reasons why acl directive loading might have failed.
85 * - Don't log the acl source if the acl destination is to blame.
87 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
88 * Add new config option "templdir" to
89 * change the templates directory.
91 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
92 * Added config option accept-intercepted-requests
93 * and disabled it by default.
95 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
96 * Fix gcc43 compiler warnings.
98 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
99 * Add config option "split-large-forms"
100 * to work around the browser bug reported
103 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
104 * Move the <br> in the generated HTML for the config
105 * options from the beginning of the string to its end.
106 * Keeps the white space in balance.
108 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
109 * Fix memory leak in case of config file reloads.
111 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
112 * Modified kludge for win32 to make ming32 menu
113 * "Options/Edit Filters" (sort of) work again.
114 * Same limitations as for the action files apply.
117 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
118 * Incorporate modified version of Roland Rosenfeld's patch to
119 * optionally access the user-manual via Privoxy. Closes patch 679075.
121 * Formatting changed to Privoxy style, added call to
122 * cgi_error_no_template if the requested file doesn't
123 * exist and modified check whether or not Privoxy itself
124 * should serve the manual. Should work cross-platform now.
126 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
127 * Added config option enable-remote-http-toggle
128 * to specify if Privoxy should recognize special
129 * headers (currently only X-Filter) to change its
130 * behaviour. Disabled by default.
132 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
133 * Make number of retries in case of forwarded-connect problems
134 * a config file option (forwarded-connect-retries) and use 0 as
137 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
138 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
139 * with what was really the latest development (the v_3_0_branch branch)
141 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
142 * Don't forget to malloc space for the null terminator...
144 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
145 * Multiple filter file support
147 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
148 * Closed two memory leaks; hopefully the last remaining ones
149 * (in the main execution paths, anyway).
151 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
152 * Addressed bug #719435
153 * - Extraneous filterfile directives now logged as errors
154 * - This and unrecnonised directives now really obvious on status page
156 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
157 * Cosmetic: Renamed cryptic variable
159 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
160 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
162 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
163 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
165 * Revision 1.48 2002/05/14 21:30:38 oes
166 * savearg now uses own linking code instead of (now special-cased) add_help_link
168 * Revision 1.47 2002/05/12 21:36:29 jongfoster
169 * Correcting function comments
171 * Revision 1.46 2002/04/26 12:55:14 oes
172 * - New option "user-manual", defaults to our site
173 * via project.h #define
174 * - savearg now embeds option names in help links
176 * Revision 1.45 2002/04/24 02:11:54 oes
177 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
179 * Revision 1.44 2002/04/08 20:37:13 swa
182 * Revision 1.43 2002/04/08 20:36:50 swa
185 * Revision 1.42 2002/04/05 15:50:15 oes
186 * fix for invalid HTML proxy_args
188 * Revision 1.41 2002/03/31 17:19:00 jongfoster
189 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
191 * Revision 1.40 2002/03/26 22:29:55 swa
192 * we have a new homepage!
194 * Revision 1.39 2002/03/24 13:25:43 swa
195 * name change related issues
197 * Revision 1.38 2002/03/24 13:05:48 jongfoster
198 * Renaming re_filterfile to filterfile
200 * Revision 1.37 2002/03/16 23:54:06 jongfoster
201 * Adding graceful termination feature, to help look for memory leaks.
202 * If you enable this (which, by design, has to be done by hand
203 * editing config.h) and then go to http://i.j.b/die, then the program
204 * will exit cleanly after the *next* request. It should free all the
205 * memory that was used.
207 * Revision 1.36 2002/03/13 00:27:05 jongfoster
210 * Revision 1.35 2002/03/07 03:52:44 oes
211 * Set logging to tty for --no-daemon mode
213 * Revision 1.34 2002/03/06 23:14:35 jongfoster
214 * Trivial cosmetic changes to make function comments easier to find.
216 * Revision 1.33 2002/03/05 04:52:42 oes
217 * Deleted non-errlog debugging code
219 * Revision 1.32 2002/03/04 18:24:53 oes
220 * Re-enabled output of unknown config directive hash
222 * Revision 1.31 2002/03/03 15:07:20 oes
223 * Re-enabled automatic config reloading
225 * Revision 1.30 2002/01/22 23:31:43 jongfoster
226 * Replacing strsav() with string_append()
228 * Revision 1.29 2002/01/17 21:02:30 jongfoster
229 * Moving all our URL and URL pattern parsing code to urlmatch.c.
231 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
233 * Revision 1.28 2001/12/30 14:07:32 steudten
234 * - Add signal handling (unix)
235 * - Add SIGHUP handler (unix)
236 * - Add creation of pidfile (unix)
237 * - Add action 'top' in rc file (RH)
238 * - Add entry 'SIGNALS' to manpage
239 * - Add exit message to logfile (unix)
241 * Revision 1.27 2001/11/07 00:02:13 steudten
242 * Add line number in error output for lineparsing for
243 * actionsfile and configfile.
244 * Special handling for CLF added.
246 * Revision 1.26 2001/11/05 21:41:43 steudten
247 * Add changes to be a real daemon just for unix os.
248 * (change cwd to /, detach from controlling tty, set
249 * process group and session leader to the own process.
251 * Add some fatal-error log message for failed malloc().
252 * Add '-d' if compiled with 'configure --with-debug' to
253 * enable debug output.
255 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
256 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
257 * threads to call select() simultaneously. So, it's time to do a real, live,
258 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
259 * (native). Both versions will work, but using __OS2__ offers multi-threading.
261 * Revision 1.24 2001/10/23 21:40:30 jongfoster
262 * Added support for enable-edit-actions and enable-remote-toggle config
265 * Revision 1.23 2001/10/07 15:36:00 oes
266 * Introduced new config option "buffer-limit"
268 * Revision 1.22 2001/09/22 16:36:59 jongfoster
269 * Removing unused parameter fs from read_config_line()
271 * Revision 1.21 2001/09/16 17:10:43 jongfoster
272 * Moving function savearg() here, since it was the only thing left in
275 * Revision 1.20 2001/07/30 22:08:36 jongfoster
276 * Tidying up #defines:
277 * - All feature #defines are now of the form FEATURE_xxx
278 * - Permanently turned off WIN_GUI_EDIT
279 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
281 * Revision 1.19 2001/07/15 17:45:16 jongfoster
282 * Removing some unused #includes
284 * Revision 1.18 2001/07/13 14:01:14 oes
285 * - Removed all #ifdef PCRS
286 * - Removed vim-settings
288 * Revision 1.17 2001/06/29 13:31:03 oes
289 * - Improved comments
290 * - Fixed (actionsfile) and sorted hashes
291 * - Introduced admin_address and proxy-info-url
292 * as config parameters
293 * - Renamed config->proxy_args_invocation (which didn't have
294 * the invocation but the options!) to config->proxy_args
295 * - Various adaptions
296 * - Removed logentry from cancelled commit
298 * Revision 1.16 2001/06/09 10:55:28 jongfoster
299 * Changing BUFSIZ ==> BUFFER_SIZE
301 * Revision 1.15 2001/06/07 23:13:40 jongfoster
302 * Merging ACL and forward files into config file.
303 * Cosmetic: Sorting config file options alphabetically.
304 * Cosmetic: Adding brief syntax comments to config file options.
306 * Revision 1.14 2001/06/07 14:46:25 joergs
307 * Missing make_path() added for re_filterfile.
309 * Revision 1.13 2001/06/05 22:33:54 jongfoster
311 * Fixed minor memory leak.
312 * Also now uses make_path to prepend the pathnames.
314 * Revision 1.12 2001/06/05 20:04:09 jongfoster
315 * Now uses _snprintf() in place of snprintf() under Win32.
317 * Revision 1.11 2001/06/04 18:31:58 swa
318 * files are now prefixed with either `confdir' or `logdir'.
319 * `make redhat-dist' replaces both entries confdir and logdir
322 * Revision 1.10 2001/06/03 19:11:54 oes
323 * introduced confdir option
325 * Revision 1.9 2001/06/01 20:06:24 jongfoster
326 * Removed support for "tinygif" option - moved to actions file.
328 * Revision 1.8 2001/05/31 21:27:13 jongfoster
329 * Removed many options from the config file and into the
330 * "actions" file: add_forwarded, suppress_vanilla_wafer,
331 * wafer, add_header, user_agent, referer, from
332 * Also globally replaced "permission" with "action".
334 * Revision 1.7 2001/05/29 09:50:24 jongfoster
335 * Unified blocklist/imagelist/permissionslist.
336 * File format is still under discussion, but the internal changes
339 * Also modified interceptor behaviour:
340 * - We now intercept all URLs beginning with one of the following
341 * prefixes (and *only* these prefixes):
343 * * http://ijbswa.sf.net/config/
344 * * http://ijbswa.sourceforge.net/config/
345 * - New interceptors "home page" - go to http://i.j.b/ to see it.
346 * - Internal changes so that intercepted and fast redirect pages
347 * are not replaced with an image.
348 * - Interceptors now have the option to send a binary page direct
349 * to the client. (i.e. ijb-send-banner uses this)
350 * - Implemented show-url-info interceptor. (Which is why I needed
351 * the above interceptors changes - a typical URL is
352 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
353 * The previous mechanism would not have intercepted that, and
354 * if it had been intercepted then it then it would have replaced
357 * Revision 1.6 2001/05/26 00:28:36 jongfoster
358 * Automatic reloading of config file.
359 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
360 * Most of the global variables have been moved to a new
361 * struct configuration_spec, accessed through csp->config->globalname
362 * Most of the globals remaining are used by the Win32 GUI.
364 * Revision 1.5 2001/05/25 22:34:30 jongfoster
367 * Revision 1.4 2001/05/22 18:46:04 oes
369 * - Enabled filtering banners by size rather than URL
370 * by adding patterns that replace all standard banner
371 * sizes with the "Junkbuster" gif to the re_filterfile
373 * - Enabled filtering WebBugs by providing a pattern
374 * which kills all 1x1 images
376 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
377 * which is selected by the (nonstandard and therefore
378 * capital) letter 'U' in the option string.
379 * It causes the quantifiers to be ungreedy by default.
380 * Appending a ? turns back to greedy (!).
382 * - Added a new interceptor ijb-send-banner, which
383 * sends back the "Junkbuster" gif. Without imagelist or
384 * MSIE detection support, or if tinygif = 1, or the
385 * URL isn't recognized as an imageurl, a lame HTML
386 * explanation is sent instead.
388 * - Added new feature, which permits blocking remote
389 * script redirects and firing back a local redirect
391 * The feature is conditionally compiled, i.e. it
392 * can be disabled with --disable-fast-redirects,
393 * plus it must be activated by a "fast-redirects"
394 * line in the config file, has its own log level
395 * and of course wants to be displayed by show-proxy-args
396 * Note: Boy, all the #ifdefs in 1001 locations and
397 * all the fumbling with configure.in and acconfig.h
398 * were *way* more work than the feature itself :-(
400 * - Because a generic redirect template was needed for
401 * this, tinygif = 3 now uses the same.
403 * - Moved GIFs, and other static HTTP response templates
408 * - Removed some >400 CRs again (Jon, you really worked
411 * Revision 1.3 2001/05/20 01:21:20 jongfoster
412 * Version 2.9.4 checkin.
413 * - Merged popupfile and cookiefile, and added control over PCRS
414 * filtering, in new "permissionsfile".
415 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
416 * file error you now get a message box (in the Win32 GUI) rather
417 * than the program exiting with no explanation.
418 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
420 * - Removed tabs from "config"
421 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
422 * - Bumped up version number.
424 * Revision 1.2 2001/05/17 23:01:01 oes
425 * - Cleaned CRLF's from the sources and related files
427 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
428 * Initial import of version 2.9.3 source tree
431 *********************************************************************/
437 #include <sys/types.h>
451 # include <windows.h>
454 # ifndef _WIN_CONSOLE
456 # endif /* ndef _WIN_CONSOLE */
458 #else /* ifndef _WIN32 */
462 # include <sys/wait.h>
464 # include <sys/time.h>
465 # include <sys/stat.h>
475 #include "miscutil.h"
479 #include "urlmatch.h"
482 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
485 * Fix a problem with Solaris. There should be no effect on other
487 * Solaris's isspace() is a macro which uses it's argument directly
488 * as an array index. Therefore we need to make sure that high-bit
489 * characters generate +ve values, and ideally we also want to make
490 * the argument match the declared parameter type of "int".
492 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
493 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
495 #ifdef FEATURE_TOGGLE
496 /* Privoxy is enabled by default. */
497 int global_toggle_state = 1;
498 #endif /* def FEATURE_TOGGLE */
500 /* The filename of the configfile */
501 const char *configfile = NULL;
504 * CGI functions will later need access to the invocation args,
505 * so we will make argc and argv global.
508 const char **Argv = NULL;
510 static struct file_list *current_configfile = NULL;
514 * This takes the "cryptic" hash of each keyword and aliases them to
515 * something a little more readable. This also makes changing the
516 * hash values easier if they should change or the hash algorthm changes.
517 * Use the included "hash" program to find out what the hash will be
518 * for any string supplied on the command line. (Or just put it in the
519 * config file and read the number from the error message in the log).
521 * Please keep this list sorted alphabetically (but with the Windows
522 * console and GUI specific options last).
525 #define hash_actions_file 1196306641ul /* "actionsfile" */
526 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
527 #define hash_admin_address 4112573064ul /* "admin-address" */
528 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
529 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
530 #define hash_confdir 1978389ul /* "confdir" */
531 #define hash_debug 78263ul /* "debug" */
532 #define hash_deny_access 1227333715ul /* "deny-access" */
533 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
534 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
535 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
536 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
537 #define hash_filterfile 250887266ul /* "filterfile" */
538 #define hash_forward 2029845ul /* "forward" */
539 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
540 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
541 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
542 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
543 #define hash_jarfile 2046641ul /* "jarfile" */
544 #define hash_listen_address 1255650842ul /* "listen-address" */
545 #define hash_logdir 422889ul /* "logdir" */
546 #define hash_logfile 2114766ul /* "logfile" */
547 #define hash_permit_access 3587953268ul /* "permit-access" */
548 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
549 #define hash_single_threaded 4250084780ul /* "single-threaded" */
550 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
551 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
552 #define hash_templdir 11067889ul /* "templdir" */
553 #define hash_toggle 447966ul /* "toggle" */
554 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
555 #define hash_trustfile 56494766ul /* "trustfile" */
556 #define hash_usermanual 1416668518ul /* "user-manual" */
557 #define hash_activity_animation 1817904738ul /* "activity-animation" */
558 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
559 #define hash_hide_console 2048809870ul /* "hide-console" */
560 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
561 #define hash_log_font_name 2866730124ul /* "log-font-name" */
562 #define hash_log_font_size 2866731014ul /* "log-font-size" */
563 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
564 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
565 #define hash_log_messages 2291744899ul /* "log-messages" */
566 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
569 static void savearg(char *command, char *argument, struct configuration_spec * config);
571 /*********************************************************************
573 * Function : unload_configfile
575 * Description : Free the config structure and all components.
578 * 1 : data: struct configuration_spec to unload
582 *********************************************************************/
583 static void unload_configfile (void * data)
585 struct configuration_spec * config = (struct configuration_spec *)data;
586 struct forward_spec *cur_fwd = config->forward;
590 struct access_control_list *cur_acl = config->acl;
592 while (cur_acl != NULL)
594 struct access_control_list * next_acl = cur_acl->next;
599 #endif /* def FEATURE_ACL */
601 while (cur_fwd != NULL)
603 struct forward_spec * next_fwd = cur_fwd->next;
604 free_url_spec(cur_fwd->url);
606 freez(cur_fwd->gateway_host);
607 freez(cur_fwd->forward_host);
611 config->forward = NULL;
613 #ifdef FEATURE_COOKIE_JAR
614 if ( NULL != config->jar )
616 fclose( config->jar );
619 #endif /* def FEATURE_COOKIE_JAR */
621 freez(config->confdir);
622 freez(config->logdir);
623 freez(config->templdir);
625 freez(config->haddr);
626 freez(config->logfile);
628 for (i = 0; i < MAX_AF_FILES; i++)
630 freez(config->actions_file_short[i]);
631 freez(config->actions_file[i]);
632 freez(config->re_filterfile_short[i]);
633 freez(config->re_filterfile[i]);
636 freez(config->admin_address);
637 freez(config->proxy_info_url);
638 freez(config->proxy_args);
639 freez(config->usermanual);
641 #ifdef FEATURE_COOKIE_JAR
642 freez(config->jarfile);
643 #endif /* def FEATURE_COOKIE_JAR */
646 freez(config->trustfile);
647 list_remove_all(config->trust_info);
648 #endif /* def FEATURE_TRUST */
650 for (i = 0; i < MAX_AF_FILES; i++)
652 freez(config->re_filterfile[i]);
659 #ifdef FEATURE_GRACEFUL_TERMINATION
660 /*********************************************************************
662 * Function : unload_current_config_file
664 * Description : Unloads current config file - reset to state at
665 * beginning of program.
671 *********************************************************************/
672 void unload_current_config_file(void)
674 if (current_configfile)
676 current_configfile->unloader = unload_configfile;
677 current_configfile = NULL;
683 /*********************************************************************
685 * Function : load_config
687 * Description : Load the config file and all parameters.
689 * XXX: more than thousand lines long
690 * and thus in serious need of refactoring.
694 * Returns : The configuration_spec, or NULL on error.
696 *********************************************************************/
697 struct configuration_spec * load_config(void)
699 char buf[BUFFER_SIZE];
701 FILE *configfp = NULL;
702 struct configuration_spec * config = NULL;
703 struct client_state * fake_csp;
704 struct file_list *fs;
705 unsigned long linenum = 0;
707 char *logfile = NULL;
709 if ( !check_file_changed(current_configfile, configfile, &fs))
711 /* No need to load */
712 return ((struct configuration_spec *)current_configfile->f);
716 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
720 if (NULL != current_configfile)
722 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
725 #ifdef FEATURE_TOGGLE
726 global_toggle_state = 1;
727 #endif /* def FEATURE_TOGGLE */
729 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
735 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
736 /* Never get here - LOG_LEVEL_FATAL causes program exit */
740 * This is backwards from how it's usually done.
741 * Following the usual pattern, "fs" would be stored in a member
742 * variable in "csp", and then we'd access "config" from "fs->f",
743 * using a cast. However, "config" is used so often that a
744 * cast each time would be very ugly, and the extra indirection
745 * would waste CPU cycles. Therefore we store "config" in
746 * "csp->config", and "fs" in "csp->config->config_file_list".
748 config->config_file_list = fs;
753 config->multi_threaded = 1;
754 config->hport = HADDR_PORT;
755 config->buffer_limit = 4096 * 1024;
756 config->usermanual = strdup(USER_MANUAL_URL);
757 config->proxy_args = strdup("");
758 config->forwarded_connect_retries = 0;
759 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
760 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
761 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
763 if ((configfp = fopen(configfile, "r")) == NULL)
765 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
767 /* Never get here - LOG_LEVEL_FATAL causes program exit */
770 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
772 char cmd[BUFFER_SIZE];
773 char arg[BUFFER_SIZE];
774 char tmp[BUFFER_SIZE];
776 struct access_control_list *cur_acl;
777 #endif /* def FEATURE_ACL */
778 struct forward_spec *cur_fwd;
781 unsigned long directive_hash;
783 strlcpy(tmp, buf, sizeof(tmp));
785 /* Copy command (i.e. up to space or tab) into cmd */
788 while (*p && (*p != ' ') && (*p != '\t'))
794 /* Skip over the whitespace in buf */
795 while (*p && ((*p == ' ') || (*p == '\t')))
800 /* Copy the argument into arg */
801 strlcpy(arg, p, sizeof(arg));
803 /* Should never happen, but check this anyway */
809 /* Make sure the command field is lower case */
814 *p = (char)ijb_tolower(*p);
818 /* Save the argument for show-proxy-args */
819 savearg(cmd, arg, config);
821 directive_hash = hash_string(cmd);
822 switch (directive_hash)
824 /* *************************************************************************
825 * actionsfile actions-file-name
826 * In confdir by default
827 * *************************************************************************/
828 case hash_actions_file :
830 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
835 if (i >= MAX_AF_FILES)
837 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
838 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
841 config->actions_file_short[i] = strdup(arg);
842 config->actions_file[i] = make_path(config->confdir, arg);
845 /* *************************************************************************
846 * accept-intercepted-requests
847 * *************************************************************************/
848 case hash_accept_intercepted_requests:
849 if ((*arg != '\0') && (0 != atoi(arg)))
851 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
855 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
859 /* *************************************************************************
860 * admin-address email-address
861 * *************************************************************************/
862 case hash_admin_address :
863 freez(config->admin_address);
864 config->admin_address = strdup(arg);
867 /* *************************************************************************
868 * allow-cgi-request-crunching
869 * *************************************************************************/
870 case hash_allow_cgi_request_crunching:
871 if ((*arg != '\0') && (0 != atoi(arg)))
873 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
877 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
881 /* *************************************************************************
883 * *************************************************************************/
884 case hash_buffer_limit :
885 config->buffer_limit = (size_t)(1024 * atoi(arg));
888 /* *************************************************************************
889 * confdir directory-name
890 * *************************************************************************/
892 freez(config->confdir);
893 config->confdir = make_path( NULL, arg);
896 /* *************************************************************************
898 * Specifies debug level, multiple values are ORed together.
899 * *************************************************************************/
901 config->debug |= atoi(arg);
904 /* *************************************************************************
905 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
906 * *************************************************************************/
908 case hash_deny_access:
909 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
911 if ((vec_count != 1) && (vec_count != 2))
913 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
914 "deny-access directive in configuration file.");
915 string_append(&config->proxy_args,
916 "<br>\nWARNING: Wrong number of parameters for "
917 "deny-access directive in configuration file.<br><br>\n");
921 /* allocate a new node */
922 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
926 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
927 /* Never get here - LOG_LEVEL_FATAL causes program exit */
930 cur_acl->action = ACL_DENY;
932 if (acl_addr(vec[0], cur_acl->src) < 0)
934 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
935 "for deny-access directive in configuration file: \"%s\"", vec[0]);
936 string_append(&config->proxy_args,
937 "<br>\nWARNING: Invalid source address, port or netmask "
938 "for deny-access directive in configuration file: \"");
939 string_append(&config->proxy_args,
941 string_append(&config->proxy_args,
948 if (acl_addr(vec[1], cur_acl->dst) < 0)
950 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
951 "for deny-access directive in configuration file: \"%s\"", vec[1]);
952 string_append(&config->proxy_args,
953 "<br>\nWARNING: Invalid destination address, port or netmask "
954 "for deny-access directive in configuration file: \"");
955 string_append(&config->proxy_args,
957 string_append(&config->proxy_args,
965 * Add it to the list. Note we reverse the list to get the
966 * behaviour the user expects. With both the ACL and
967 * actions file, the last match wins. However, the internal
968 * implementations are different: The actions file is stored
969 * in the same order as the file, and scanned completely.
970 * With the ACL, we reverse the order as we load it, then
971 * when we scan it we stop as soon as we get a match.
973 cur_acl->next = config->acl;
974 config->acl = cur_acl;
977 #endif /* def FEATURE_ACL */
979 /* *************************************************************************
980 * enable-edit-actions 0|1
981 * *************************************************************************/
982 #ifdef FEATURE_CGI_EDIT_ACTIONS
983 case hash_enable_edit_actions:
984 if ((*arg != '\0') && (0 != atoi(arg)))
986 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
990 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
993 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
995 /* *************************************************************************
996 * enable-remote-toggle 0|1
997 * *************************************************************************/
998 #ifdef FEATURE_CGI_EDIT_ACTIONS
999 case hash_enable_remote_toggle:
1000 if ((*arg != '\0') && (0 != atoi(arg)))
1002 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1006 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1009 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1011 /* *************************************************************************
1012 * enable-remote-http-toggle 0|1
1013 * *************************************************************************/
1014 case hash_enable_remote_http_toggle:
1015 if ((*arg != '\0') && (0 != atoi(arg)))
1017 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1021 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1025 /* *************************************************************************
1026 * hash_enforce_blocks 0|1
1027 * *************************************************************************/
1028 #ifdef FEATURE_FORCE_LOAD
1029 case hash_enforce_blocks:
1030 if ((*arg != '\0') && (0 != atoi(arg)))
1032 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1036 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1039 #endif /* def FEATURE_FORCE_LOAD */
1041 /* *************************************************************************
1042 * filterfile file-name
1043 * In confdir by default.
1044 * *************************************************************************/
1045 case hash_filterfile :
1047 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1052 if (i >= MAX_AF_FILES)
1054 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1055 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1058 config->re_filterfile_short[i] = strdup(arg);
1059 config->re_filterfile[i] = make_path(config->confdir, arg);
1063 /* *************************************************************************
1064 * forward url-pattern (.|http-proxy-host[:port])
1065 * *************************************************************************/
1067 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1071 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1072 "directive in configuration file.");
1073 string_append(&config->proxy_args,
1074 "<br>\nWARNING: Wrong number of parameters for "
1075 "forward directive in configuration file.");
1079 /* allocate a new node */
1080 cur_fwd = zalloc(sizeof(*cur_fwd));
1081 if (cur_fwd == NULL)
1083 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1084 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1088 cur_fwd->type = SOCKS_NONE;
1090 /* Save the URL pattern */
1091 if (create_url_spec(cur_fwd->url, vec[0]))
1093 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1094 "directive in configuration file.");
1095 string_append(&config->proxy_args,
1096 "<br>\nWARNING: Bad URL specifier for "
1097 "forward directive in configuration file.");
1101 /* Parse the parent HTTP proxy host:port */
1104 if (strcmp(p, ".") != 0)
1106 cur_fwd->forward_host = strdup(p);
1108 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1111 cur_fwd->forward_port = atoi(p);
1114 if (cur_fwd->forward_port <= 0)
1116 cur_fwd->forward_port = 8000;
1121 cur_fwd->next = config->forward;
1122 config->forward = cur_fwd;
1126 /* *************************************************************************
1127 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1128 * *************************************************************************/
1129 case hash_forward_socks4:
1130 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1134 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1135 "forward-socks4 directive in configuration file.");
1136 string_append(&config->proxy_args,
1137 "<br>\nWARNING: Wrong number of parameters for "
1138 "forward-socks4 directive in configuration file.");
1142 /* allocate a new node */
1143 cur_fwd = zalloc(sizeof(*cur_fwd));
1144 if (cur_fwd == NULL)
1146 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1147 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1151 cur_fwd->type = SOCKS_4;
1153 /* Save the URL pattern */
1154 if (create_url_spec(cur_fwd->url, vec[0]))
1156 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1157 "directive in configuration file.");
1158 string_append(&config->proxy_args,
1159 "<br>\nWARNING: Bad URL specifier for "
1160 "forward-socks4 directive in configuration file.");
1164 /* Parse the SOCKS proxy host[:port] */
1167 if (strcmp(p, ".") != 0)
1169 cur_fwd->gateway_host = strdup(p);
1171 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1174 cur_fwd->gateway_port = atoi(p);
1176 if (cur_fwd->gateway_port <= 0)
1178 cur_fwd->gateway_port = 1080;
1182 /* Parse the parent HTTP proxy host[:port] */
1185 if (strcmp(p, ".") != 0)
1187 cur_fwd->forward_host = strdup(p);
1189 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1192 cur_fwd->forward_port = atoi(p);
1195 if (cur_fwd->forward_port <= 0)
1197 cur_fwd->forward_port = 8000;
1202 cur_fwd->next = config->forward;
1203 config->forward = cur_fwd;
1207 /* *************************************************************************
1208 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1209 * *************************************************************************/
1210 case hash_forward_socks4a:
1211 case hash_forward_socks5:
1212 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1216 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1217 "forward-socks4a directive in configuration file.");
1218 string_append(&config->proxy_args,
1219 "<br>\nWARNING: Wrong number of parameters for "
1220 "forward-socks4a directive in configuration file.");
1224 /* allocate a new node */
1225 cur_fwd = zalloc(sizeof(*cur_fwd));
1226 if (cur_fwd == NULL)
1228 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1229 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1233 if (directive_hash == hash_forward_socks4a)
1235 cur_fwd->type = SOCKS_4A;
1239 cur_fwd->type = SOCKS_5;
1242 /* Save the URL pattern */
1243 if (create_url_spec(cur_fwd->url, vec[0]))
1245 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1246 "directive in configuration file.");
1247 string_append(&config->proxy_args,
1248 "<br>\nWARNING: Bad URL specifier for "
1249 "forward-socks4a directive in configuration file.");
1253 /* Parse the SOCKS proxy host[:port] */
1256 cur_fwd->gateway_host = strdup(p);
1258 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1261 cur_fwd->gateway_port = atoi(p);
1263 if (cur_fwd->gateway_port <= 0)
1265 cur_fwd->gateway_port = 1080;
1268 /* Parse the parent HTTP proxy host[:port] */
1271 if (strcmp(p, ".") != 0)
1273 cur_fwd->forward_host = strdup(p);
1275 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1278 cur_fwd->forward_port = atoi(p);
1281 if (cur_fwd->forward_port <= 0)
1283 cur_fwd->forward_port = 8000;
1288 cur_fwd->next = config->forward;
1289 config->forward = cur_fwd;
1293 /* *************************************************************************
1294 * forwarded-connect-retries n
1295 * *************************************************************************/
1296 case hash_forwarded_connect_retries :
1297 config->forwarded_connect_retries = atoi(arg);
1300 /* *************************************************************************
1301 * jarfile jar-file-name
1302 * In logdir by default
1303 * *************************************************************************/
1304 #ifdef FEATURE_COOKIE_JAR
1306 freez(config->jarfile);
1307 config->jarfile = make_path(config->logdir, arg);
1309 #endif /* def FEATURE_COOKIE_JAR */
1311 /* *************************************************************************
1312 * listen-address [ip][:port]
1313 * *************************************************************************/
1314 case hash_listen_address :
1315 freez(config->haddr);
1316 config->haddr = strdup(arg);
1319 /* *************************************************************************
1320 * logdir directory-name
1321 * *************************************************************************/
1323 freez(config->logdir);
1324 config->logdir = make_path(NULL, arg);
1327 /* *************************************************************************
1328 * logfile log-file-name
1329 * In logdir by default
1330 * *************************************************************************/
1334 logfile = make_path(config->logdir, arg);
1335 if (NULL == logfile)
1337 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1342 /* *************************************************************************
1343 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1344 * *************************************************************************/
1346 case hash_permit_access:
1347 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1349 if ((vec_count != 1) && (vec_count != 2))
1351 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1352 "permit-access directive in configuration file.");
1353 string_append(&config->proxy_args,
1354 "<br>\nWARNING: Wrong number of parameters for "
1355 "permit-access directive in configuration file.<br><br>\n");
1360 /* allocate a new node */
1361 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1363 if (cur_acl == NULL)
1365 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1366 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1369 cur_acl->action = ACL_PERMIT;
1371 if (acl_addr(vec[0], cur_acl->src) < 0)
1373 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1374 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1375 string_append(&config->proxy_args,
1376 "<br>\nWARNING: Invalid source address, port or netmask for "
1377 "permit-access directive in configuration file: \"");
1378 string_append(&config->proxy_args,
1380 string_append(&config->proxy_args,
1387 if (acl_addr(vec[1], cur_acl->dst) < 0)
1389 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1390 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1391 string_append(&config->proxy_args,
1392 "<br>\nWARNING: Invalid destination address, port or netmask for "
1393 "permit-access directive in configuration file: \"");
1394 string_append(&config->proxy_args,
1396 string_append(&config->proxy_args,
1404 * Add it to the list. Note we reverse the list to get the
1405 * behaviour the user expects. With both the ACL and
1406 * actions file, the last match wins. However, the internal
1407 * implementations are different: The actions file is stored
1408 * in the same order as the file, and scanned completely.
1409 * With the ACL, we reverse the order as we load it, then
1410 * when we scan it we stop as soon as we get a match.
1412 cur_acl->next = config->acl;
1413 config->acl = cur_acl;
1416 #endif /* def FEATURE_ACL */
1418 /* *************************************************************************
1419 * proxy-info-url url
1420 * *************************************************************************/
1421 case hash_proxy_info_url :
1422 freez(config->proxy_info_url);
1423 config->proxy_info_url = strdup(arg);
1426 /* *************************************************************************
1428 * *************************************************************************/
1429 case hash_single_threaded :
1430 config->multi_threaded = 0;
1433 /* *************************************************************************
1434 * split-large-cgi-forms
1435 * *************************************************************************/
1436 case hash_split_large_cgi_forms :
1437 if ((*arg != '\0') && (0 != atoi(arg)))
1439 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1443 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1447 /* *************************************************************************
1448 * templdir directory-name
1449 * *************************************************************************/
1450 case hash_templdir :
1451 freez(config->templdir);
1452 config->templdir = make_path(NULL, arg);
1455 /* *************************************************************************
1457 * *************************************************************************/
1458 #ifdef FEATURE_TOGGLE
1460 global_toggle_state = atoi(arg);
1462 #endif /* def FEATURE_TOGGLE */
1464 /* *************************************************************************
1465 * trust-info-url url
1466 * *************************************************************************/
1467 #ifdef FEATURE_TRUST
1468 case hash_trust_info_url :
1469 enlist(config->trust_info, arg);
1471 #endif /* def FEATURE_TRUST */
1473 /* *************************************************************************
1474 * trustfile filename
1475 * (In confdir by default.)
1476 * *************************************************************************/
1477 #ifdef FEATURE_TRUST
1478 case hash_trustfile :
1479 freez(config->trustfile);
1480 config->trustfile = make_path(config->confdir, arg);
1482 #endif /* def FEATURE_TRUST */
1484 /* *************************************************************************
1486 * *************************************************************************/
1487 case hash_usermanual :
1488 freez(config->usermanual);
1489 config->usermanual = strdup(arg);
1492 /* *************************************************************************
1493 * Win32 Console options:
1494 * *************************************************************************/
1496 /* *************************************************************************
1498 * *************************************************************************/
1500 case hash_hide_console :
1503 #endif /*def _WIN_CONSOLE*/
1506 /* *************************************************************************
1507 * Win32 GUI options:
1508 * *************************************************************************/
1510 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1511 /* *************************************************************************
1512 * activity-animation (0|1)
1513 * *************************************************************************/
1514 case hash_activity_animation :
1515 g_bShowActivityAnimation = atoi(arg);
1518 /* *************************************************************************
1519 * close-button-minimizes (0|1)
1520 * *************************************************************************/
1521 case hash_close_button_minimizes :
1522 g_bCloseHidesWindow = atoi(arg);
1525 /* *************************************************************************
1526 * log-buffer-size (0|1)
1527 * *************************************************************************/
1528 case hash_log_buffer_size :
1529 g_bLimitBufferSize = atoi(arg);
1532 /* *************************************************************************
1533 * log-font-name fontnane
1534 * *************************************************************************/
1535 case hash_log_font_name :
1536 strcpy( g_szFontFaceName, arg );
1539 /* *************************************************************************
1541 * *************************************************************************/
1542 case hash_log_font_size :
1543 g_nFontSize = atoi(arg);
1546 /* *************************************************************************
1547 * log-highlight-messages (0|1)
1548 * *************************************************************************/
1549 case hash_log_highlight_messages :
1550 g_bHighlightMessages = atoi(arg);
1553 /* *************************************************************************
1555 * *************************************************************************/
1556 case hash_log_max_lines :
1557 g_nMaxBufferLines = atoi(arg);
1560 /* *************************************************************************
1561 * log-messages (0|1)
1562 * *************************************************************************/
1563 case hash_log_messages :
1564 g_bLogMessages = atoi(arg);
1567 /* *************************************************************************
1568 * show-on-task-bar (0|1)
1569 * *************************************************************************/
1570 case hash_show_on_task_bar :
1571 g_bShowOnTaskBar = atoi(arg);
1574 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1577 /* *************************************************************************
1578 * Warnings about unsupported features
1579 * *************************************************************************/
1581 case hash_deny_access:
1582 #endif /* ndef FEATURE_ACL */
1583 #ifndef FEATURE_CGI_EDIT_ACTIONS
1584 case hash_enable_edit_actions:
1585 case hash_enable_remote_toggle:
1586 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1587 #ifndef FEATURE_COOKIE_JAR
1589 #endif /* ndef FEATURE_COOKIE_JAR */
1591 case hash_permit_access:
1592 #endif /* ndef FEATURE_ACL */
1593 #ifndef FEATURE_TOGGLE
1595 #endif /* ndef FEATURE_TOGGLE */
1596 #ifndef FEATURE_TRUST
1597 case hash_trustfile :
1598 case hash_trust_info_url :
1599 #endif /* ndef FEATURE_TRUST */
1601 #ifndef _WIN_CONSOLE
1602 case hash_hide_console :
1603 #endif /* ndef _WIN_CONSOLE */
1605 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1606 case hash_activity_animation :
1607 case hash_close_button_minimizes :
1608 case hash_log_buffer_size :
1609 case hash_log_font_name :
1610 case hash_log_font_size :
1611 case hash_log_highlight_messages :
1612 case hash_log_max_lines :
1613 case hash_log_messages :
1614 case hash_show_on_task_bar :
1615 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1616 /* These warnings are annoying - so hide them. -- Jon */
1617 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1620 /* *************************************************************************/
1622 /* *************************************************************************/
1624 * I decided that I liked this better as a warning than an
1625 * error. To change back to an error, just change log level
1626 * to LOG_LEVEL_FATAL.
1628 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1629 "in configuration file (%s).", buf, hash_string(cmd), linenum, configfile);
1630 string_append(&config->proxy_args,
1631 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1634 /* *************************************************************************/
1635 } /* end switch( hash_string(cmd) ) */
1636 } /* end while ( read_config_line(...) ) */
1640 set_debug_level(config->debug);
1642 freez(config->logfile);
1646 if (NULL != logfile)
1648 config->logfile = logfile;
1649 init_error_log(Argv[0], config->logfile);
1657 if (NULL == config->proxy_args)
1659 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1662 if (config->actions_file[0])
1664 add_loader(load_actions_file, config);
1667 if (config->re_filterfile)
1669 add_loader(load_re_filterfile, config);
1672 #ifdef FEATURE_TRUST
1673 if (config->trustfile)
1675 add_loader(load_trustfile, config);
1677 #endif /* def FEATURE_TRUST */
1679 #ifdef FEATURE_COOKIE_JAR
1680 if ( NULL != config->jarfile )
1682 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1684 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1685 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1687 setbuf(config->jar, NULL);
1689 #endif /* def FEATURE_COOKIE_JAR */
1691 if ( NULL == config->haddr )
1693 config->haddr = strdup( HADDR_DEFAULT );
1696 if ( NULL != config->haddr )
1698 if (NULL != (p = strchr(config->haddr, ':')))
1703 config->hport = atoi(p);
1707 if (config->hport <= 0)
1710 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1711 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1713 if (*config->haddr == '\0')
1716 * Only the port specified. We stored it in config->hport
1717 * and don't need its text representation anymore.
1719 freez(config->haddr);
1724 * Want to run all the loaders once now.
1726 * Need to set up a fake csp, so they can get to the config.
1728 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1729 fake_csp->config = config;
1731 if (run_loader(fake_csp))
1734 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1735 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1739 /* FIXME: this is a kludge for win32 */
1740 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1742 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1743 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1744 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1746 #ifdef FEATURE_TRUST
1747 g_trustfile = config->trustfile;
1748 #endif /* def FEATURE_TRUST */
1751 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1752 /* FIXME: end kludge */
1755 config->need_bind = 1;
1757 if (current_configfile)
1759 struct configuration_spec * oldcfg = (struct configuration_spec *)
1760 current_configfile->f;
1762 * Check if config->haddr,hport == oldcfg->haddr,hport
1764 * The following could be written more compactly as a single,
1765 * (unreadably long) if statement.
1767 config->need_bind = 0;
1768 if (config->hport != oldcfg->hport)
1770 config->need_bind = 1;
1772 else if (config->haddr == NULL)
1774 if (oldcfg->haddr != NULL)
1776 config->need_bind = 1;
1779 else if (oldcfg->haddr == NULL)
1781 config->need_bind = 1;
1783 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1785 config->need_bind = 1;
1788 current_configfile->unloader = unload_configfile;
1791 fs->next = files->next;
1794 current_configfile = fs;
1800 /*********************************************************************
1802 * Function : savearg
1804 * Description : Called from `load_config'. It saves each non-empty
1805 * and non-comment line from config into
1806 * config->proxy_args. This is used to create the
1807 * show-proxy-args page. On error, frees
1808 * config->proxy_args and sets it to NULL
1811 * 1 : command = config setting that was found
1812 * 2 : argument = the setting's argument (if any)
1813 * 3 : config = Configuration to save into.
1817 *********************************************************************/
1818 static void savearg(char *command, char *argument, struct configuration_spec * config)
1828 * Add config option name embedded in
1829 * link to its section in the user-manual
1831 buf = strdup("\n<a href=\"");
1832 if (!strncmpic(config->usermanual, "file://", 7) ||
1833 !strncmpic(config->usermanual, "http", 4))
1835 string_append(&buf, config->usermanual);
1839 string_append(&buf, "http://");
1840 string_append(&buf, CGI_SITE_2_HOST);
1841 string_append(&buf, "/user-manual/");
1843 string_append(&buf, CONFIG_HELP_PREFIX);
1844 string_join (&buf, string_toupper(command));
1845 string_append(&buf, "\">");
1846 string_append(&buf, command);
1847 string_append(&buf, "</a> ");
1851 freez(config->proxy_args);
1855 if ( (NULL != argument) && ('\0' != *argument) )
1857 s = html_encode(argument);
1861 freez(config->proxy_args);
1865 if (strncmpic(argument, "http://", 7) == 0)
1867 string_append(&buf, "<a href=\"");
1868 string_append(&buf, s);
1869 string_append(&buf, "\">");
1870 string_join (&buf, s);
1871 string_append(&buf, "</a>");
1875 string_join (&buf, s);
1879 string_append(&buf, "<br>");
1880 string_join(&config->proxy_args, buf);