1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.79 2008/08/30 12:03:07 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-2008 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.79 2008/08/30 12:03:07 fabiankeil
39 * Remove FEATURE_COOKIE_JAR.
41 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
42 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
43 * disabled, log a message that blocks will always be enforced
44 * instead of complaining about an unrecognized directive.
45 * Reported by Pietro Leone.
47 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
48 * Reuse directive_hash and don't hash the same directive twice.
50 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
51 * - Merge three string_append() calls.
52 * - Remove useless assertion.
54 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
55 * Rename load_actions_file() and load_re_filterfile()
56 * as they load multiple files "now".
58 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
59 * Add hostname directive. Closes PR#1918189.
61 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
64 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
65 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
67 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
68 * Reword "unrecognized directive" warning, use better
69 * mark up and add a <br>. Fixes parts of #1856559.
71 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
72 * Plug memory leak if listen-address only specifies the port.
74 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
75 * Relocate daemon-mode-related log messages to make sure
76 * they aren't shown again in case of configuration reloads.
78 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
79 * Plug memory leak introduced with my last commit.
81 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
82 * When in daemon mode, close stderr after the configuration file has been
83 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
85 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
86 * #1763173 from Stefan Huehner: declare unload_configfile() static.
88 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
89 * As Hal noticed, checking dispatch_cgi() as the last cruncher
90 * looks like a bug if CGI requests are blocked unintentionally,
91 * so don't do it unless the user enabled the new config option
92 * "allow-cgi-request-crunching".
94 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
95 * - Use strlcpy() instead of strcpy().
96 * - Stop treating actions files special. Expect a complete file name
97 * (with or without path) like it's done for the rest of the files.
99 * - Remove an unnecessary temporary memory allocation.
100 * - Don't log anything to the console when running as
101 * daemon and no errors occurred.
103 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
104 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
106 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
107 * New config option: enforce-blocks.
109 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
110 * - Mention other reasons why acl directive loading might have failed.
111 * - Don't log the acl source if the acl destination is to blame.
113 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
114 * Add new config option "templdir" to
115 * change the templates directory.
117 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
118 * Added config option accept-intercepted-requests
119 * and disabled it by default.
121 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
122 * Fix gcc43 compiler warnings.
124 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
125 * Add config option "split-large-forms"
126 * to work around the browser bug reported
129 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
130 * Move the <br> in the generated HTML for the config
131 * options from the beginning of the string to its end.
132 * Keeps the white space in balance.
134 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
135 * Fix memory leak in case of config file reloads.
137 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
138 * Modified kludge for win32 to make ming32 menu
139 * "Options/Edit Filters" (sort of) work again.
140 * Same limitations as for the action files apply.
143 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
144 * Incorporate modified version of Roland Rosenfeld's patch to
145 * optionally access the user-manual via Privoxy. Closes patch 679075.
147 * Formatting changed to Privoxy style, added call to
148 * cgi_error_no_template if the requested file doesn't
149 * exist and modified check whether or not Privoxy itself
150 * should serve the manual. Should work cross-platform now.
152 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
153 * Added config option enable-remote-http-toggle
154 * to specify if Privoxy should recognize special
155 * headers (currently only X-Filter) to change its
156 * behaviour. Disabled by default.
158 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
159 * Make number of retries in case of forwarded-connect problems
160 * a config file option (forwarded-connect-retries) and use 0 as
163 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
164 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
165 * with what was really the latest development (the v_3_0_branch branch)
167 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
168 * Don't forget to malloc space for the null terminator...
170 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
171 * Multiple filter file support
173 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
174 * Closed two memory leaks; hopefully the last remaining ones
175 * (in the main execution paths, anyway).
177 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
178 * Addressed bug #719435
179 * - Extraneous filterfile directives now logged as errors
180 * - This and unrecnonised directives now really obvious on status page
182 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
183 * Cosmetic: Renamed cryptic variable
185 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
186 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
188 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
189 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
191 * Revision 1.48 2002/05/14 21:30:38 oes
192 * savearg now uses own linking code instead of (now special-cased) add_help_link
194 * Revision 1.47 2002/05/12 21:36:29 jongfoster
195 * Correcting function comments
197 * Revision 1.46 2002/04/26 12:55:14 oes
198 * - New option "user-manual", defaults to our site
199 * via project.h #define
200 * - savearg now embeds option names in help links
202 * Revision 1.45 2002/04/24 02:11:54 oes
203 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
205 * Revision 1.44 2002/04/08 20:37:13 swa
208 * Revision 1.43 2002/04/08 20:36:50 swa
211 * Revision 1.42 2002/04/05 15:50:15 oes
212 * fix for invalid HTML proxy_args
214 * Revision 1.41 2002/03/31 17:19:00 jongfoster
215 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
217 * Revision 1.40 2002/03/26 22:29:55 swa
218 * we have a new homepage!
220 * Revision 1.39 2002/03/24 13:25:43 swa
221 * name change related issues
223 * Revision 1.38 2002/03/24 13:05:48 jongfoster
224 * Renaming re_filterfile to filterfile
226 * Revision 1.37 2002/03/16 23:54:06 jongfoster
227 * Adding graceful termination feature, to help look for memory leaks.
228 * If you enable this (which, by design, has to be done by hand
229 * editing config.h) and then go to http://i.j.b/die, then the program
230 * will exit cleanly after the *next* request. It should free all the
231 * memory that was used.
233 * Revision 1.36 2002/03/13 00:27:05 jongfoster
236 * Revision 1.35 2002/03/07 03:52:44 oes
237 * Set logging to tty for --no-daemon mode
239 * Revision 1.34 2002/03/06 23:14:35 jongfoster
240 * Trivial cosmetic changes to make function comments easier to find.
242 * Revision 1.33 2002/03/05 04:52:42 oes
243 * Deleted non-errlog debugging code
245 * Revision 1.32 2002/03/04 18:24:53 oes
246 * Re-enabled output of unknown config directive hash
248 * Revision 1.31 2002/03/03 15:07:20 oes
249 * Re-enabled automatic config reloading
251 * Revision 1.30 2002/01/22 23:31:43 jongfoster
252 * Replacing strsav() with string_append()
254 * Revision 1.29 2002/01/17 21:02:30 jongfoster
255 * Moving all our URL and URL pattern parsing code to urlmatch.c.
257 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
259 * Revision 1.28 2001/12/30 14:07:32 steudten
260 * - Add signal handling (unix)
261 * - Add SIGHUP handler (unix)
262 * - Add creation of pidfile (unix)
263 * - Add action 'top' in rc file (RH)
264 * - Add entry 'SIGNALS' to manpage
265 * - Add exit message to logfile (unix)
267 * Revision 1.27 2001/11/07 00:02:13 steudten
268 * Add line number in error output for lineparsing for
269 * actionsfile and configfile.
270 * Special handling for CLF added.
272 * Revision 1.26 2001/11/05 21:41:43 steudten
273 * Add changes to be a real daemon just for unix os.
274 * (change cwd to /, detach from controlling tty, set
275 * process group and session leader to the own process.
277 * Add some fatal-error log message for failed malloc().
278 * Add '-d' if compiled with 'configure --with-debug' to
279 * enable debug output.
281 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
282 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
283 * threads to call select() simultaneously. So, it's time to do a real, live,
284 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
285 * (native). Both versions will work, but using __OS2__ offers multi-threading.
287 * Revision 1.24 2001/10/23 21:40:30 jongfoster
288 * Added support for enable-edit-actions and enable-remote-toggle config
291 * Revision 1.23 2001/10/07 15:36:00 oes
292 * Introduced new config option "buffer-limit"
294 * Revision 1.22 2001/09/22 16:36:59 jongfoster
295 * Removing unused parameter fs from read_config_line()
297 * Revision 1.21 2001/09/16 17:10:43 jongfoster
298 * Moving function savearg() here, since it was the only thing left in
301 * Revision 1.20 2001/07/30 22:08:36 jongfoster
302 * Tidying up #defines:
303 * - All feature #defines are now of the form FEATURE_xxx
304 * - Permanently turned off WIN_GUI_EDIT
305 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
307 * Revision 1.19 2001/07/15 17:45:16 jongfoster
308 * Removing some unused #includes
310 * Revision 1.18 2001/07/13 14:01:14 oes
311 * - Removed all #ifdef PCRS
312 * - Removed vim-settings
314 * Revision 1.17 2001/06/29 13:31:03 oes
315 * - Improved comments
316 * - Fixed (actionsfile) and sorted hashes
317 * - Introduced admin_address and proxy-info-url
318 * as config parameters
319 * - Renamed config->proxy_args_invocation (which didn't have
320 * the invocation but the options!) to config->proxy_args
321 * - Various adaptions
322 * - Removed logentry from cancelled commit
324 * Revision 1.16 2001/06/09 10:55:28 jongfoster
325 * Changing BUFSIZ ==> BUFFER_SIZE
327 * Revision 1.15 2001/06/07 23:13:40 jongfoster
328 * Merging ACL and forward files into config file.
329 * Cosmetic: Sorting config file options alphabetically.
330 * Cosmetic: Adding brief syntax comments to config file options.
332 * Revision 1.14 2001/06/07 14:46:25 joergs
333 * Missing make_path() added for re_filterfile.
335 * Revision 1.13 2001/06/05 22:33:54 jongfoster
337 * Fixed minor memory leak.
338 * Also now uses make_path to prepend the pathnames.
340 * Revision 1.12 2001/06/05 20:04:09 jongfoster
341 * Now uses _snprintf() in place of snprintf() under Win32.
343 * Revision 1.11 2001/06/04 18:31:58 swa
344 * files are now prefixed with either `confdir' or `logdir'.
345 * `make redhat-dist' replaces both entries confdir and logdir
348 * Revision 1.10 2001/06/03 19:11:54 oes
349 * introduced confdir option
351 * Revision 1.9 2001/06/01 20:06:24 jongfoster
352 * Removed support for "tinygif" option - moved to actions file.
354 * Revision 1.8 2001/05/31 21:27:13 jongfoster
355 * Removed many options from the config file and into the
356 * "actions" file: add_forwarded, suppress_vanilla_wafer,
357 * wafer, add_header, user_agent, referer, from
358 * Also globally replaced "permission" with "action".
360 * Revision 1.7 2001/05/29 09:50:24 jongfoster
361 * Unified blocklist/imagelist/permissionslist.
362 * File format is still under discussion, but the internal changes
365 * Also modified interceptor behaviour:
366 * - We now intercept all URLs beginning with one of the following
367 * prefixes (and *only* these prefixes):
369 * * http://ijbswa.sf.net/config/
370 * * http://ijbswa.sourceforge.net/config/
371 * - New interceptors "home page" - go to http://i.j.b/ to see it.
372 * - Internal changes so that intercepted and fast redirect pages
373 * are not replaced with an image.
374 * - Interceptors now have the option to send a binary page direct
375 * to the client. (i.e. ijb-send-banner uses this)
376 * - Implemented show-url-info interceptor. (Which is why I needed
377 * the above interceptors changes - a typical URL is
378 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
379 * The previous mechanism would not have intercepted that, and
380 * if it had been intercepted then it then it would have replaced
383 * Revision 1.6 2001/05/26 00:28:36 jongfoster
384 * Automatic reloading of config file.
385 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
386 * Most of the global variables have been moved to a new
387 * struct configuration_spec, accessed through csp->config->globalname
388 * Most of the globals remaining are used by the Win32 GUI.
390 * Revision 1.5 2001/05/25 22:34:30 jongfoster
393 * Revision 1.4 2001/05/22 18:46:04 oes
395 * - Enabled filtering banners by size rather than URL
396 * by adding patterns that replace all standard banner
397 * sizes with the "Junkbuster" gif to the re_filterfile
399 * - Enabled filtering WebBugs by providing a pattern
400 * which kills all 1x1 images
402 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
403 * which is selected by the (nonstandard and therefore
404 * capital) letter 'U' in the option string.
405 * It causes the quantifiers to be ungreedy by default.
406 * Appending a ? turns back to greedy (!).
408 * - Added a new interceptor ijb-send-banner, which
409 * sends back the "Junkbuster" gif. Without imagelist or
410 * MSIE detection support, or if tinygif = 1, or the
411 * URL isn't recognized as an imageurl, a lame HTML
412 * explanation is sent instead.
414 * - Added new feature, which permits blocking remote
415 * script redirects and firing back a local redirect
417 * The feature is conditionally compiled, i.e. it
418 * can be disabled with --disable-fast-redirects,
419 * plus it must be activated by a "fast-redirects"
420 * line in the config file, has its own log level
421 * and of course wants to be displayed by show-proxy-args
422 * Note: Boy, all the #ifdefs in 1001 locations and
423 * all the fumbling with configure.in and acconfig.h
424 * were *way* more work than the feature itself :-(
426 * - Because a generic redirect template was needed for
427 * this, tinygif = 3 now uses the same.
429 * - Moved GIFs, and other static HTTP response templates
434 * - Removed some >400 CRs again (Jon, you really worked
437 * Revision 1.3 2001/05/20 01:21:20 jongfoster
438 * Version 2.9.4 checkin.
439 * - Merged popupfile and cookiefile, and added control over PCRS
440 * filtering, in new "permissionsfile".
441 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
442 * file error you now get a message box (in the Win32 GUI) rather
443 * than the program exiting with no explanation.
444 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
446 * - Removed tabs from "config"
447 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
448 * - Bumped up version number.
450 * Revision 1.2 2001/05/17 23:01:01 oes
451 * - Cleaned CRLF's from the sources and related files
453 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
454 * Initial import of version 2.9.3 source tree
457 *********************************************************************/
463 #include <sys/types.h>
477 # include <windows.h>
480 # ifndef _WIN_CONSOLE
482 # endif /* ndef _WIN_CONSOLE */
484 #else /* ifndef _WIN32 */
488 # include <sys/wait.h>
490 # include <sys/time.h>
491 # include <sys/stat.h>
501 #include "miscutil.h"
505 #include "urlmatch.h"
508 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
511 * Fix a problem with Solaris. There should be no effect on other
513 * Solaris's isspace() is a macro which uses it's argument directly
514 * as an array index. Therefore we need to make sure that high-bit
515 * characters generate +ve values, and ideally we also want to make
516 * the argument match the declared parameter type of "int".
518 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
519 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
521 #ifdef FEATURE_TOGGLE
522 /* Privoxy is enabled by default. */
523 int global_toggle_state = 1;
524 #endif /* def FEATURE_TOGGLE */
526 /* The filename of the configfile */
527 const char *configfile = NULL;
530 * CGI functions will later need access to the invocation args,
531 * so we will make argc and argv global.
534 const char **Argv = NULL;
536 static struct file_list *current_configfile = NULL;
540 * This takes the "cryptic" hash of each keyword and aliases them to
541 * something a little more readable. This also makes changing the
542 * hash values easier if they should change or the hash algorthm changes.
543 * Use the included "hash" program to find out what the hash will be
544 * for any string supplied on the command line. (Or just put it in the
545 * config file and read the number from the error message in the log).
547 * Please keep this list sorted alphabetically (but with the Windows
548 * console and GUI specific options last).
551 #define hash_actions_file 1196306641ul /* "actionsfile" */
552 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
553 #define hash_admin_address 4112573064ul /* "admin-address" */
554 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
555 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
556 #define hash_confdir 1978389ul /* "confdir" */
557 #define hash_debug 78263ul /* "debug" */
558 #define hash_deny_access 1227333715ul /* "deny-access" */
559 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
560 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
561 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
562 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
563 #define hash_filterfile 250887266ul /* "filterfile" */
564 #define hash_forward 2029845ul /* "forward" */
565 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
566 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
567 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
568 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
569 #define hash_hostname 10308071ul /* "hostname" */
570 #define hash_listen_address 1255650842ul /* "listen-address" */
571 #define hash_logdir 422889ul /* "logdir" */
572 #define hash_logfile 2114766ul /* "logfile" */
573 #define hash_permit_access 3587953268ul /* "permit-access" */
574 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
575 #define hash_single_threaded 4250084780ul /* "single-threaded" */
576 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
577 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
578 #define hash_templdir 11067889ul /* "templdir" */
579 #define hash_toggle 447966ul /* "toggle" */
580 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
581 #define hash_trustfile 56494766ul /* "trustfile" */
582 #define hash_usermanual 1416668518ul /* "user-manual" */
583 #define hash_activity_animation 1817904738ul /* "activity-animation" */
584 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
585 #define hash_hide_console 2048809870ul /* "hide-console" */
586 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
587 #define hash_log_font_name 2866730124ul /* "log-font-name" */
588 #define hash_log_font_size 2866731014ul /* "log-font-size" */
589 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
590 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
591 #define hash_log_messages 2291744899ul /* "log-messages" */
592 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
595 static void savearg(char *command, char *argument, struct configuration_spec * config);
597 /*********************************************************************
599 * Function : unload_configfile
601 * Description : Free the config structure and all components.
604 * 1 : data: struct configuration_spec to unload
608 *********************************************************************/
609 static void unload_configfile (void * data)
611 struct configuration_spec * config = (struct configuration_spec *)data;
612 struct forward_spec *cur_fwd = config->forward;
616 struct access_control_list *cur_acl = config->acl;
618 while (cur_acl != NULL)
620 struct access_control_list * next_acl = cur_acl->next;
625 #endif /* def FEATURE_ACL */
627 while (cur_fwd != NULL)
629 struct forward_spec * next_fwd = cur_fwd->next;
630 free_url_spec(cur_fwd->url);
632 freez(cur_fwd->gateway_host);
633 freez(cur_fwd->forward_host);
637 config->forward = NULL;
639 freez(config->confdir);
640 freez(config->logdir);
641 freez(config->templdir);
642 freez(config->hostname);
644 freez(config->haddr);
645 freez(config->logfile);
647 for (i = 0; i < MAX_AF_FILES; i++)
649 freez(config->actions_file_short[i]);
650 freez(config->actions_file[i]);
651 freez(config->re_filterfile_short[i]);
652 freez(config->re_filterfile[i]);
655 freez(config->admin_address);
656 freez(config->proxy_info_url);
657 freez(config->proxy_args);
658 freez(config->usermanual);
661 freez(config->trustfile);
662 list_remove_all(config->trust_info);
663 #endif /* def FEATURE_TRUST */
665 for (i = 0; i < MAX_AF_FILES; i++)
667 freez(config->re_filterfile[i]);
674 #ifdef FEATURE_GRACEFUL_TERMINATION
675 /*********************************************************************
677 * Function : unload_current_config_file
679 * Description : Unloads current config file - reset to state at
680 * beginning of program.
686 *********************************************************************/
687 void unload_current_config_file(void)
689 if (current_configfile)
691 current_configfile->unloader = unload_configfile;
692 current_configfile = NULL;
698 /*********************************************************************
700 * Function : load_config
702 * Description : Load the config file and all parameters.
704 * XXX: more than thousand lines long
705 * and thus in serious need of refactoring.
709 * Returns : The configuration_spec, or NULL on error.
711 *********************************************************************/
712 struct configuration_spec * load_config(void)
714 char buf[BUFFER_SIZE];
716 FILE *configfp = NULL;
717 struct configuration_spec * config = NULL;
718 struct client_state * fake_csp;
719 struct file_list *fs;
720 unsigned long linenum = 0;
722 char *logfile = NULL;
724 if ( !check_file_changed(current_configfile, configfile, &fs))
726 /* No need to load */
727 return ((struct configuration_spec *)current_configfile->f);
731 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
735 if (NULL != current_configfile)
737 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
740 #ifdef FEATURE_TOGGLE
741 global_toggle_state = 1;
742 #endif /* def FEATURE_TOGGLE */
744 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
750 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
751 /* Never get here - LOG_LEVEL_FATAL causes program exit */
755 * This is backwards from how it's usually done.
756 * Following the usual pattern, "fs" would be stored in a member
757 * variable in "csp", and then we'd access "config" from "fs->f",
758 * using a cast. However, "config" is used so often that a
759 * cast each time would be very ugly, and the extra indirection
760 * would waste CPU cycles. Therefore we store "config" in
761 * "csp->config", and "fs" in "csp->config->config_file_list".
763 config->config_file_list = fs;
768 config->multi_threaded = 1;
769 config->hport = HADDR_PORT;
770 config->buffer_limit = 4096 * 1024;
771 config->usermanual = strdup(USER_MANUAL_URL);
772 config->proxy_args = strdup("");
773 config->forwarded_connect_retries = 0;
774 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
775 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
776 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
778 if ((configfp = fopen(configfile, "r")) == NULL)
780 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
782 /* Never get here - LOG_LEVEL_FATAL causes program exit */
785 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
787 char cmd[BUFFER_SIZE];
788 char arg[BUFFER_SIZE];
789 char tmp[BUFFER_SIZE];
791 struct access_control_list *cur_acl;
792 #endif /* def FEATURE_ACL */
793 struct forward_spec *cur_fwd;
796 unsigned long directive_hash;
798 strlcpy(tmp, buf, sizeof(tmp));
800 /* Copy command (i.e. up to space or tab) into cmd */
803 while (*p && (*p != ' ') && (*p != '\t'))
809 /* Skip over the whitespace in buf */
810 while (*p && ((*p == ' ') || (*p == '\t')))
815 /* Copy the argument into arg */
816 strlcpy(arg, p, sizeof(arg));
818 /* Should never happen, but check this anyway */
824 /* Make sure the command field is lower case */
829 *p = (char)ijb_tolower(*p);
833 /* Save the argument for show-proxy-args */
834 savearg(cmd, arg, config);
836 directive_hash = hash_string(cmd);
837 switch (directive_hash)
839 /* *************************************************************************
840 * actionsfile actions-file-name
841 * In confdir by default
842 * *************************************************************************/
843 case hash_actions_file :
845 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
850 if (i >= MAX_AF_FILES)
852 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
853 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
856 config->actions_file_short[i] = strdup(arg);
857 config->actions_file[i] = make_path(config->confdir, arg);
860 /* *************************************************************************
861 * accept-intercepted-requests
862 * *************************************************************************/
863 case hash_accept_intercepted_requests:
864 if ((*arg != '\0') && (0 != atoi(arg)))
866 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
870 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
874 /* *************************************************************************
875 * admin-address email-address
876 * *************************************************************************/
877 case hash_admin_address :
878 freez(config->admin_address);
879 config->admin_address = strdup(arg);
882 /* *************************************************************************
883 * allow-cgi-request-crunching
884 * *************************************************************************/
885 case hash_allow_cgi_request_crunching:
886 if ((*arg != '\0') && (0 != atoi(arg)))
888 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
892 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
896 /* *************************************************************************
898 * *************************************************************************/
899 case hash_buffer_limit :
900 config->buffer_limit = (size_t)(1024 * atoi(arg));
903 /* *************************************************************************
904 * confdir directory-name
905 * *************************************************************************/
907 freez(config->confdir);
908 config->confdir = make_path( NULL, arg);
911 /* *************************************************************************
913 * Specifies debug level, multiple values are ORed together.
914 * *************************************************************************/
916 config->debug |= atoi(arg);
919 /* *************************************************************************
920 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
921 * *************************************************************************/
923 case hash_deny_access:
924 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
926 if ((vec_count != 1) && (vec_count != 2))
928 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
929 "deny-access directive in configuration file.");
930 string_append(&config->proxy_args,
931 "<br>\nWARNING: Wrong number of parameters for "
932 "deny-access directive in configuration file.<br><br>\n");
936 /* allocate a new node */
937 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
941 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
942 /* Never get here - LOG_LEVEL_FATAL causes program exit */
945 cur_acl->action = ACL_DENY;
947 if (acl_addr(vec[0], cur_acl->src) < 0)
949 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
950 "for deny-access directive in configuration file: \"%s\"", vec[0]);
951 string_append(&config->proxy_args,
952 "<br>\nWARNING: Invalid source address, port or netmask "
953 "for deny-access directive in configuration file: \"");
954 string_append(&config->proxy_args,
956 string_append(&config->proxy_args,
963 if (acl_addr(vec[1], cur_acl->dst) < 0)
965 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
966 "for deny-access directive in configuration file: \"%s\"", vec[1]);
967 string_append(&config->proxy_args,
968 "<br>\nWARNING: Invalid destination address, port or netmask "
969 "for deny-access directive in configuration file: \"");
970 string_append(&config->proxy_args,
972 string_append(&config->proxy_args,
980 * Add it to the list. Note we reverse the list to get the
981 * behaviour the user expects. With both the ACL and
982 * actions file, the last match wins. However, the internal
983 * implementations are different: The actions file is stored
984 * in the same order as the file, and scanned completely.
985 * With the ACL, we reverse the order as we load it, then
986 * when we scan it we stop as soon as we get a match.
988 cur_acl->next = config->acl;
989 config->acl = cur_acl;
992 #endif /* def FEATURE_ACL */
994 /* *************************************************************************
995 * enable-edit-actions 0|1
996 * *************************************************************************/
997 #ifdef FEATURE_CGI_EDIT_ACTIONS
998 case hash_enable_edit_actions:
999 if ((*arg != '\0') && (0 != atoi(arg)))
1001 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1005 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1008 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1010 /* *************************************************************************
1011 * enable-remote-toggle 0|1
1012 * *************************************************************************/
1013 #ifdef FEATURE_TOGGLE
1014 case hash_enable_remote_toggle:
1015 if ((*arg != '\0') && (0 != atoi(arg)))
1017 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1021 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1024 #endif /* def FEATURE_TOGGLE */
1026 /* *************************************************************************
1027 * enable-remote-http-toggle 0|1
1028 * *************************************************************************/
1029 case hash_enable_remote_http_toggle:
1030 if ((*arg != '\0') && (0 != atoi(arg)))
1032 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1036 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1040 /* *************************************************************************
1041 * enforce-blocks 0|1
1042 * *************************************************************************/
1043 case hash_enforce_blocks:
1044 #ifdef FEATURE_FORCE_LOAD
1045 if ((*arg != '\0') && (0 != atoi(arg)))
1047 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1051 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1054 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1055 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1056 #endif /* def FEATURE_FORCE_LOAD */
1059 /* *************************************************************************
1060 * filterfile file-name
1061 * In confdir by default.
1062 * *************************************************************************/
1063 case hash_filterfile :
1065 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1070 if (i >= MAX_AF_FILES)
1072 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1073 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1076 config->re_filterfile_short[i] = strdup(arg);
1077 config->re_filterfile[i] = make_path(config->confdir, arg);
1081 /* *************************************************************************
1082 * forward url-pattern (.|http-proxy-host[:port])
1083 * *************************************************************************/
1085 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1089 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1090 "directive in configuration file.");
1091 string_append(&config->proxy_args,
1092 "<br>\nWARNING: Wrong number of parameters for "
1093 "forward directive in configuration file.");
1097 /* allocate a new node */
1098 cur_fwd = zalloc(sizeof(*cur_fwd));
1099 if (cur_fwd == NULL)
1101 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1102 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1106 cur_fwd->type = SOCKS_NONE;
1108 /* Save the URL pattern */
1109 if (create_url_spec(cur_fwd->url, vec[0]))
1111 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1112 "directive in configuration file.");
1113 string_append(&config->proxy_args,
1114 "<br>\nWARNING: Bad URL specifier for "
1115 "forward directive in configuration file.");
1119 /* Parse the parent HTTP proxy host:port */
1122 if (strcmp(p, ".") != 0)
1124 cur_fwd->forward_host = strdup(p);
1126 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1129 cur_fwd->forward_port = atoi(p);
1132 if (cur_fwd->forward_port <= 0)
1134 cur_fwd->forward_port = 8000;
1139 cur_fwd->next = config->forward;
1140 config->forward = cur_fwd;
1144 /* *************************************************************************
1145 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1146 * *************************************************************************/
1147 case hash_forward_socks4:
1148 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1152 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1153 "forward-socks4 directive in configuration file.");
1154 string_append(&config->proxy_args,
1155 "<br>\nWARNING: Wrong number of parameters for "
1156 "forward-socks4 directive in configuration file.");
1160 /* allocate a new node */
1161 cur_fwd = zalloc(sizeof(*cur_fwd));
1162 if (cur_fwd == NULL)
1164 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1165 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1169 cur_fwd->type = SOCKS_4;
1171 /* Save the URL pattern */
1172 if (create_url_spec(cur_fwd->url, vec[0]))
1174 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1175 "directive in configuration file.");
1176 string_append(&config->proxy_args,
1177 "<br>\nWARNING: Bad URL specifier for "
1178 "forward-socks4 directive in configuration file.");
1182 /* Parse the SOCKS proxy host[:port] */
1185 if (strcmp(p, ".") != 0)
1187 cur_fwd->gateway_host = strdup(p);
1189 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1192 cur_fwd->gateway_port = atoi(p);
1194 if (cur_fwd->gateway_port <= 0)
1196 cur_fwd->gateway_port = 1080;
1200 /* Parse the parent HTTP proxy host[:port] */
1203 if (strcmp(p, ".") != 0)
1205 cur_fwd->forward_host = strdup(p);
1207 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1210 cur_fwd->forward_port = atoi(p);
1213 if (cur_fwd->forward_port <= 0)
1215 cur_fwd->forward_port = 8000;
1220 cur_fwd->next = config->forward;
1221 config->forward = cur_fwd;
1225 /* *************************************************************************
1226 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1227 * *************************************************************************/
1228 case hash_forward_socks4a:
1229 case hash_forward_socks5:
1230 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1234 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1235 "forward-socks4a directive in configuration file.");
1236 string_append(&config->proxy_args,
1237 "<br>\nWARNING: Wrong number of parameters for "
1238 "forward-socks4a directive in configuration file.");
1242 /* allocate a new node */
1243 cur_fwd = zalloc(sizeof(*cur_fwd));
1244 if (cur_fwd == NULL)
1246 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1247 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1251 if (directive_hash == hash_forward_socks4a)
1253 cur_fwd->type = SOCKS_4A;
1257 cur_fwd->type = SOCKS_5;
1260 /* Save the URL pattern */
1261 if (create_url_spec(cur_fwd->url, vec[0]))
1263 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1264 "directive in configuration file.");
1265 string_append(&config->proxy_args,
1266 "<br>\nWARNING: Bad URL specifier for "
1267 "forward-socks4a directive in configuration file.");
1271 /* Parse the SOCKS proxy host[:port] */
1274 cur_fwd->gateway_host = strdup(p);
1276 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1279 cur_fwd->gateway_port = atoi(p);
1281 if (cur_fwd->gateway_port <= 0)
1283 cur_fwd->gateway_port = 1080;
1286 /* Parse the parent HTTP proxy host[:port] */
1289 if (strcmp(p, ".") != 0)
1291 cur_fwd->forward_host = strdup(p);
1293 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1296 cur_fwd->forward_port = atoi(p);
1299 if (cur_fwd->forward_port <= 0)
1301 cur_fwd->forward_port = 8000;
1306 cur_fwd->next = config->forward;
1307 config->forward = cur_fwd;
1311 /* *************************************************************************
1312 * forwarded-connect-retries n
1313 * *************************************************************************/
1314 case hash_forwarded_connect_retries :
1315 config->forwarded_connect_retries = atoi(arg);
1318 /* *************************************************************************
1319 * hostname hostname-to-show-on-cgi-pages
1320 * *************************************************************************/
1321 case hash_hostname :
1322 freez(config->hostname);
1323 config->hostname = strdup(arg);
1324 if (NULL == config->hostname)
1326 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1330 /* *************************************************************************
1331 * listen-address [ip][:port]
1332 * *************************************************************************/
1333 case hash_listen_address :
1334 freez(config->haddr);
1335 config->haddr = strdup(arg);
1338 /* *************************************************************************
1339 * logdir directory-name
1340 * *************************************************************************/
1342 freez(config->logdir);
1343 config->logdir = make_path(NULL, arg);
1346 /* *************************************************************************
1347 * logfile log-file-name
1348 * In logdir by default
1349 * *************************************************************************/
1353 logfile = make_path(config->logdir, arg);
1354 if (NULL == logfile)
1356 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1361 /* *************************************************************************
1362 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1363 * *************************************************************************/
1365 case hash_permit_access:
1366 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1368 if ((vec_count != 1) && (vec_count != 2))
1370 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1371 "permit-access directive in configuration file.");
1372 string_append(&config->proxy_args,
1373 "<br>\nWARNING: Wrong number of parameters for "
1374 "permit-access directive in configuration file.<br><br>\n");
1379 /* allocate a new node */
1380 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1382 if (cur_acl == NULL)
1384 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1385 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1388 cur_acl->action = ACL_PERMIT;
1390 if (acl_addr(vec[0], cur_acl->src) < 0)
1392 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1393 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1394 string_append(&config->proxy_args,
1395 "<br>\nWARNING: Invalid source address, port or netmask for "
1396 "permit-access directive in configuration file: \"");
1397 string_append(&config->proxy_args,
1399 string_append(&config->proxy_args,
1406 if (acl_addr(vec[1], cur_acl->dst) < 0)
1408 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1409 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1410 string_append(&config->proxy_args,
1411 "<br>\nWARNING: Invalid destination address, port or netmask for "
1412 "permit-access directive in configuration file: \"");
1413 string_append(&config->proxy_args,
1415 string_append(&config->proxy_args,
1423 * Add it to the list. Note we reverse the list to get the
1424 * behaviour the user expects. With both the ACL and
1425 * actions file, the last match wins. However, the internal
1426 * implementations are different: The actions file is stored
1427 * in the same order as the file, and scanned completely.
1428 * With the ACL, we reverse the order as we load it, then
1429 * when we scan it we stop as soon as we get a match.
1431 cur_acl->next = config->acl;
1432 config->acl = cur_acl;
1435 #endif /* def FEATURE_ACL */
1437 /* *************************************************************************
1438 * proxy-info-url url
1439 * *************************************************************************/
1440 case hash_proxy_info_url :
1441 freez(config->proxy_info_url);
1442 config->proxy_info_url = strdup(arg);
1445 /* *************************************************************************
1447 * *************************************************************************/
1448 case hash_single_threaded :
1449 config->multi_threaded = 0;
1452 /* *************************************************************************
1453 * split-large-cgi-forms
1454 * *************************************************************************/
1455 case hash_split_large_cgi_forms :
1456 if ((*arg != '\0') && (0 != atoi(arg)))
1458 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1462 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1466 /* *************************************************************************
1467 * templdir directory-name
1468 * *************************************************************************/
1469 case hash_templdir :
1470 freez(config->templdir);
1471 config->templdir = make_path(NULL, arg);
1474 /* *************************************************************************
1476 * *************************************************************************/
1477 #ifdef FEATURE_TOGGLE
1479 global_toggle_state = atoi(arg);
1481 #endif /* def FEATURE_TOGGLE */
1483 /* *************************************************************************
1484 * trust-info-url url
1485 * *************************************************************************/
1486 #ifdef FEATURE_TRUST
1487 case hash_trust_info_url :
1488 enlist(config->trust_info, arg);
1490 #endif /* def FEATURE_TRUST */
1492 /* *************************************************************************
1493 * trustfile filename
1494 * (In confdir by default.)
1495 * *************************************************************************/
1496 #ifdef FEATURE_TRUST
1497 case hash_trustfile :
1498 freez(config->trustfile);
1499 config->trustfile = make_path(config->confdir, arg);
1501 #endif /* def FEATURE_TRUST */
1503 /* *************************************************************************
1505 * *************************************************************************/
1506 case hash_usermanual :
1507 freez(config->usermanual);
1508 config->usermanual = strdup(arg);
1511 /* *************************************************************************
1512 * Win32 Console options:
1513 * *************************************************************************/
1515 /* *************************************************************************
1517 * *************************************************************************/
1519 case hash_hide_console :
1522 #endif /*def _WIN_CONSOLE*/
1525 /* *************************************************************************
1526 * Win32 GUI options:
1527 * *************************************************************************/
1529 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1530 /* *************************************************************************
1531 * activity-animation (0|1)
1532 * *************************************************************************/
1533 case hash_activity_animation :
1534 g_bShowActivityAnimation = atoi(arg);
1537 /* *************************************************************************
1538 * close-button-minimizes (0|1)
1539 * *************************************************************************/
1540 case hash_close_button_minimizes :
1541 g_bCloseHidesWindow = atoi(arg);
1544 /* *************************************************************************
1545 * log-buffer-size (0|1)
1546 * *************************************************************************/
1547 case hash_log_buffer_size :
1548 g_bLimitBufferSize = atoi(arg);
1551 /* *************************************************************************
1552 * log-font-name fontnane
1553 * *************************************************************************/
1554 case hash_log_font_name :
1555 strcpy( g_szFontFaceName, arg );
1558 /* *************************************************************************
1560 * *************************************************************************/
1561 case hash_log_font_size :
1562 g_nFontSize = atoi(arg);
1565 /* *************************************************************************
1566 * log-highlight-messages (0|1)
1567 * *************************************************************************/
1568 case hash_log_highlight_messages :
1569 g_bHighlightMessages = atoi(arg);
1572 /* *************************************************************************
1574 * *************************************************************************/
1575 case hash_log_max_lines :
1576 g_nMaxBufferLines = atoi(arg);
1579 /* *************************************************************************
1580 * log-messages (0|1)
1581 * *************************************************************************/
1582 case hash_log_messages :
1583 g_bLogMessages = atoi(arg);
1586 /* *************************************************************************
1587 * show-on-task-bar (0|1)
1588 * *************************************************************************/
1589 case hash_show_on_task_bar :
1590 g_bShowOnTaskBar = atoi(arg);
1593 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1596 /* *************************************************************************
1597 * Warnings about unsupported features
1598 * *************************************************************************/
1600 case hash_deny_access:
1601 #endif /* ndef FEATURE_ACL */
1602 #ifndef FEATURE_CGI_EDIT_ACTIONS
1603 case hash_enable_edit_actions:
1604 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1605 #ifndef FEATURE_TOGGLE
1606 case hash_enable_remote_toggle:
1607 #endif /* ndef FEATURE_TOGGLE */
1609 case hash_permit_access:
1610 #endif /* ndef FEATURE_ACL */
1611 #ifndef FEATURE_TOGGLE
1613 #endif /* ndef FEATURE_TOGGLE */
1614 #ifndef FEATURE_TRUST
1615 case hash_trustfile :
1616 case hash_trust_info_url :
1617 #endif /* ndef FEATURE_TRUST */
1619 #ifndef _WIN_CONSOLE
1620 case hash_hide_console :
1621 #endif /* ndef _WIN_CONSOLE */
1623 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1624 case hash_activity_animation :
1625 case hash_close_button_minimizes :
1626 case hash_log_buffer_size :
1627 case hash_log_font_name :
1628 case hash_log_font_size :
1629 case hash_log_highlight_messages :
1630 case hash_log_max_lines :
1631 case hash_log_messages :
1632 case hash_show_on_task_bar :
1633 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1634 /* These warnings are annoying - so hide them. -- Jon */
1635 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1638 /* *************************************************************************/
1640 /* *************************************************************************/
1642 * I decided that I liked this better as a warning than an
1643 * error. To change back to an error, just change log level
1644 * to LOG_LEVEL_FATAL.
1646 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1647 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1648 string_append(&config->proxy_args,
1649 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1652 /* *************************************************************************/
1653 } /* end switch( hash_string(cmd) ) */
1654 } /* end while ( read_config_line(...) ) */
1658 set_debug_level(config->debug);
1660 freez(config->logfile);
1664 if (NULL != logfile)
1666 config->logfile = logfile;
1667 init_error_log(Argv[0], config->logfile);
1675 if (NULL == config->proxy_args)
1677 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1680 if (config->actions_file[0])
1682 add_loader(load_action_files, config);
1685 if (config->re_filterfile[0])
1687 add_loader(load_re_filterfiles, config);
1690 #ifdef FEATURE_TRUST
1691 if (config->trustfile)
1693 add_loader(load_trustfile, config);
1695 #endif /* def FEATURE_TRUST */
1697 if ( NULL == config->haddr )
1699 config->haddr = strdup( HADDR_DEFAULT );
1702 if ( NULL != config->haddr )
1704 if (NULL != (p = strchr(config->haddr, ':')))
1709 config->hport = atoi(p);
1713 if (config->hport <= 0)
1716 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1717 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1719 if (*config->haddr == '\0')
1722 * Only the port specified. We stored it in config->hport
1723 * and don't need its text representation anymore.
1725 freez(config->haddr);
1730 * Want to run all the loaders once now.
1732 * Need to set up a fake csp, so they can get to the config.
1734 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1735 fake_csp->config = config;
1737 if (run_loader(fake_csp))
1740 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1741 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1745 /* FIXME: this is a kludge for win32 */
1746 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1748 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1749 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1750 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1752 #ifdef FEATURE_TRUST
1753 g_trustfile = config->trustfile;
1754 #endif /* def FEATURE_TRUST */
1757 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1758 /* FIXME: end kludge */
1761 config->need_bind = 1;
1763 if (current_configfile)
1765 struct configuration_spec * oldcfg = (struct configuration_spec *)
1766 current_configfile->f;
1768 * Check if config->haddr,hport == oldcfg->haddr,hport
1770 * The following could be written more compactly as a single,
1771 * (unreadably long) if statement.
1773 config->need_bind = 0;
1774 if (config->hport != oldcfg->hport)
1776 config->need_bind = 1;
1778 else if (config->haddr == NULL)
1780 if (oldcfg->haddr != NULL)
1782 config->need_bind = 1;
1785 else if (oldcfg->haddr == NULL)
1787 config->need_bind = 1;
1789 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1791 config->need_bind = 1;
1794 current_configfile->unloader = unload_configfile;
1797 fs->next = files->next;
1800 current_configfile = fs;
1806 /*********************************************************************
1808 * Function : savearg
1810 * Description : Called from `load_config'. It saves each non-empty
1811 * and non-comment line from config into
1812 * config->proxy_args. This is used to create the
1813 * show-proxy-args page. On error, frees
1814 * config->proxy_args and sets it to NULL
1817 * 1 : command = config setting that was found
1818 * 2 : argument = the setting's argument (if any)
1819 * 3 : config = Configuration to save into.
1823 *********************************************************************/
1824 static void savearg(char *command, char *argument, struct configuration_spec * config)
1833 * Add config option name embedded in
1834 * link to its section in the user-manual
1836 buf = strdup("\n<a href=\"");
1837 if (!strncmpic(config->usermanual, "file://", 7) ||
1838 !strncmpic(config->usermanual, "http", 4))
1840 string_append(&buf, config->usermanual);
1844 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1846 string_append(&buf, CONFIG_HELP_PREFIX);
1847 string_join (&buf, string_toupper(command));
1848 string_append(&buf, "\">");
1849 string_append(&buf, command);
1850 string_append(&buf, "</a> ");
1854 freez(config->proxy_args);
1858 if ( (NULL != argument) && ('\0' != *argument) )
1860 s = html_encode(argument);
1864 freez(config->proxy_args);
1868 if (strncmpic(argument, "http://", 7) == 0)
1870 string_append(&buf, "<a href=\"");
1871 string_append(&buf, s);
1872 string_append(&buf, "\">");
1873 string_join (&buf, s);
1874 string_append(&buf, "</a>");
1878 string_join (&buf, s);
1882 string_append(&buf, "<br>");
1883 string_join(&config->proxy_args, buf);