1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.98 2009/04/24 15:29:43 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-2009 the
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.98 2009/04/24 15:29:43 fabiankeil
39 * Allow to limit the number of of client connections.
41 * Revision 1.97 2009/04/17 11:45:19 fabiankeil
42 * Replace HAVE_GETADDRINFO and HAVE_GETNAMEINFO macros
43 * with HAVE_RFC2553 macro. Original patch by Petr Pisar.
45 * Revision 1.96 2009/04/17 11:38:28 fabiankeil
46 * Add and use parse_forwarder_address() to reduce code duplication.
48 * Revision 1.95 2009/04/17 11:34:34 fabiankeil
49 * Style cosmetics for the IPv6 code.
51 * Revision 1.94 2009/04/17 11:27:49 fabiankeil
52 * Petr Pisar's privoxy-3.0.12-ipv6-3.diff.
54 * Revision 1.93 2009/03/18 21:46:26 fabiankeil
55 * Revert the last commit as there's a better way.
57 * Revision 1.92 2009/03/18 20:43:19 fabiankeil
58 * Don't enable LOG_LEVEL_INFO by default and don't apply the user's
59 * debug settings until the logfile has been opened (if there is one).
60 * Patch submitted by Roland in #2624120.
62 * Revision 1.91 2009/03/09 17:29:08 fabiankeil
63 * As of r1.88, the show-status page can use a single line for
64 * warnings about ignored directives and the names of the ignored
65 * directives themselves. Reminded by Lee, finally closes #1856559.
67 * Revision 1.90 2009/03/07 17:58:02 fabiankeil
68 * Fix two mingw32-only buffer overflows. Note that triggering
69 * them requires control over the configuration file in which
70 * case all bets are off anyway.
72 * Revision 1.89 2009/03/01 18:46:33 fabiankeil
73 * - Help clang understand that we aren't
74 * dereferencing NULL pointers here.
75 * - Some style fixes in the modified region.
77 * Revision 1.88 2009/02/28 10:57:10 fabiankeil
78 * Gimme a break or two. Don't let the show-status page
79 * link to the website documentation for the user-manual
82 * Revision 1.87 2009/02/15 07:56:13 fabiankeil
83 * Increase default socket timeout to 300 seconds.
85 * Revision 1.86 2009/02/08 19:18:57 fabiankeil
86 * Now that we have the match-all.action file, the other action
87 * files changed their position in config->actions_file[] back
88 * to the way it was before standard.action got removed and the
89 * changes from revision 1.84 have to be reverted.
91 * Revision 1.85 2009/01/22 12:06:26 fabiankeil
92 * Don't keep connections alive when running single-threaded.
94 * Revision 1.84 2009/01/14 16:14:36 fabiankeil
95 * Due to the standard.action file removal, the other action
96 * files changed their position in config->actions_file[].
97 * Update mingw32 kludge accordingly.
99 * Revision 1.83 2008/12/20 14:53:55 fabiankeil
100 * Add config option socket-timeout to control the time
101 * Privoxy waits for data to arrive on a socket. Useful
102 * in case of stale ssh tunnels or when fuzz-testing.
104 * Revision 1.82 2008/11/16 12:43:49 fabiankeil
105 * Turn keep-alive support into a runtime feature
106 * that is disabled by setting keep-alive-timeout
107 * to a negative value.
109 * Revision 1.81 2008/11/13 09:08:42 fabiankeil
110 * Add new config option: keep-alive-timeout.
112 * Revision 1.80 2008/08/31 15:59:03 fabiankeil
113 * There's no reason to let remote toggling support depend
114 * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
116 * Revision 1.79 2008/08/30 12:03:07 fabiankeil
117 * Remove FEATURE_COOKIE_JAR.
119 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
120 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
121 * disabled, log a message that blocks will always be enforced
122 * instead of complaining about an unrecognized directive.
123 * Reported by Pietro Leone.
125 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
126 * Reuse directive_hash and don't hash the same directive twice.
128 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
129 * - Merge three string_append() calls.
130 * - Remove useless assertion.
132 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
133 * Rename load_actions_file() and load_re_filterfile()
134 * as they load multiple files "now".
136 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
137 * Add hostname directive. Closes PR#1918189.
139 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
142 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
143 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
145 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
146 * Reword "unrecognized directive" warning, use better
147 * mark up and add a <br>. Fixes parts of #1856559.
149 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
150 * Plug memory leak if listen-address only specifies the port.
152 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
153 * Relocate daemon-mode-related log messages to make sure
154 * they aren't shown again in case of configuration reloads.
156 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
157 * Plug memory leak introduced with my last commit.
159 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
160 * When in daemon mode, close stderr after the configuration file has been
161 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
163 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
164 * #1763173 from Stefan Huehner: declare unload_configfile() static.
166 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
167 * As Hal noticed, checking dispatch_cgi() as the last cruncher
168 * looks like a bug if CGI requests are blocked unintentionally,
169 * so don't do it unless the user enabled the new config option
170 * "allow-cgi-request-crunching".
172 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
173 * - Use strlcpy() instead of strcpy().
174 * - Stop treating actions files special. Expect a complete file name
175 * (with or without path) like it's done for the rest of the files.
177 * - Remove an unnecessary temporary memory allocation.
178 * - Don't log anything to the console when running as
179 * daemon and no errors occurred.
181 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
182 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
184 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
185 * New config option: enforce-blocks.
187 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
188 * - Mention other reasons why acl directive loading might have failed.
189 * - Don't log the acl source if the acl destination is to blame.
191 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
192 * Add new config option "templdir" to
193 * change the templates directory.
195 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
196 * Added config option accept-intercepted-requests
197 * and disabled it by default.
199 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
200 * Fix gcc43 compiler warnings.
202 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
203 * Add config option "split-large-forms"
204 * to work around the browser bug reported
207 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
208 * Move the <br> in the generated HTML for the config
209 * options from the beginning of the string to its end.
210 * Keeps the white space in balance.
212 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
213 * Fix memory leak in case of config file reloads.
215 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
216 * Modified kludge for win32 to make ming32 menu
217 * "Options/Edit Filters" (sort of) work again.
218 * Same limitations as for the action files apply.
221 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
222 * Incorporate modified version of Roland Rosenfeld's patch to
223 * optionally access the user-manual via Privoxy. Closes patch 679075.
225 * Formatting changed to Privoxy style, added call to
226 * cgi_error_no_template if the requested file doesn't
227 * exist and modified check whether or not Privoxy itself
228 * should serve the manual. Should work cross-platform now.
230 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
231 * Added config option enable-remote-http-toggle
232 * to specify if Privoxy should recognize special
233 * headers (currently only X-Filter) to change its
234 * behaviour. Disabled by default.
236 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
237 * Make number of retries in case of forwarded-connect problems
238 * a config file option (forwarded-connect-retries) and use 0 as
241 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
242 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
243 * with what was really the latest development (the v_3_0_branch branch)
245 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
246 * Don't forget to malloc space for the null terminator...
248 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
249 * Multiple filter file support
251 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
252 * Closed two memory leaks; hopefully the last remaining ones
253 * (in the main execution paths, anyway).
255 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
256 * Addressed bug #719435
257 * - Extraneous filterfile directives now logged as errors
258 * - This and unrecnonised directives now really obvious on status page
260 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
261 * Cosmetic: Renamed cryptic variable
263 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
264 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
266 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
267 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
269 * Revision 1.48 2002/05/14 21:30:38 oes
270 * savearg now uses own linking code instead of (now special-cased) add_help_link
272 * Revision 1.47 2002/05/12 21:36:29 jongfoster
273 * Correcting function comments
275 * Revision 1.46 2002/04/26 12:55:14 oes
276 * - New option "user-manual", defaults to our site
277 * via project.h #define
278 * - savearg now embeds option names in help links
280 * Revision 1.45 2002/04/24 02:11:54 oes
281 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
283 * Revision 1.44 2002/04/08 20:37:13 swa
286 * Revision 1.43 2002/04/08 20:36:50 swa
289 * Revision 1.42 2002/04/05 15:50:15 oes
290 * fix for invalid HTML proxy_args
292 * Revision 1.41 2002/03/31 17:19:00 jongfoster
293 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
295 * Revision 1.40 2002/03/26 22:29:55 swa
296 * we have a new homepage!
298 * Revision 1.39 2002/03/24 13:25:43 swa
299 * name change related issues
301 * Revision 1.38 2002/03/24 13:05:48 jongfoster
302 * Renaming re_filterfile to filterfile
304 * Revision 1.37 2002/03/16 23:54:06 jongfoster
305 * Adding graceful termination feature, to help look for memory leaks.
306 * If you enable this (which, by design, has to be done by hand
307 * editing config.h) and then go to http://i.j.b/die, then the program
308 * will exit cleanly after the *next* request. It should free all the
309 * memory that was used.
311 * Revision 1.36 2002/03/13 00:27:05 jongfoster
314 * Revision 1.35 2002/03/07 03:52:44 oes
315 * Set logging to tty for --no-daemon mode
317 * Revision 1.34 2002/03/06 23:14:35 jongfoster
318 * Trivial cosmetic changes to make function comments easier to find.
320 * Revision 1.33 2002/03/05 04:52:42 oes
321 * Deleted non-errlog debugging code
323 * Revision 1.32 2002/03/04 18:24:53 oes
324 * Re-enabled output of unknown config directive hash
326 * Revision 1.31 2002/03/03 15:07:20 oes
327 * Re-enabled automatic config reloading
329 * Revision 1.30 2002/01/22 23:31:43 jongfoster
330 * Replacing strsav() with string_append()
332 * Revision 1.29 2002/01/17 21:02:30 jongfoster
333 * Moving all our URL and URL pattern parsing code to urlmatch.c.
335 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
337 * Revision 1.28 2001/12/30 14:07:32 steudten
338 * - Add signal handling (unix)
339 * - Add SIGHUP handler (unix)
340 * - Add creation of pidfile (unix)
341 * - Add action 'top' in rc file (RH)
342 * - Add entry 'SIGNALS' to manpage
343 * - Add exit message to logfile (unix)
345 * Revision 1.27 2001/11/07 00:02:13 steudten
346 * Add line number in error output for lineparsing for
347 * actionsfile and configfile.
348 * Special handling for CLF added.
350 * Revision 1.26 2001/11/05 21:41:43 steudten
351 * Add changes to be a real daemon just for unix os.
352 * (change cwd to /, detach from controlling tty, set
353 * process group and session leader to the own process.
355 * Add some fatal-error log message for failed malloc().
356 * Add '-d' if compiled with 'configure --with-debug' to
357 * enable debug output.
359 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
360 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
361 * threads to call select() simultaneously. So, it's time to do a real, live,
362 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
363 * (native). Both versions will work, but using __OS2__ offers multi-threading.
365 * Revision 1.24 2001/10/23 21:40:30 jongfoster
366 * Added support for enable-edit-actions and enable-remote-toggle config
369 * Revision 1.23 2001/10/07 15:36:00 oes
370 * Introduced new config option "buffer-limit"
372 * Revision 1.22 2001/09/22 16:36:59 jongfoster
373 * Removing unused parameter fs from read_config_line()
375 * Revision 1.21 2001/09/16 17:10:43 jongfoster
376 * Moving function savearg() here, since it was the only thing left in
379 * Revision 1.20 2001/07/30 22:08:36 jongfoster
380 * Tidying up #defines:
381 * - All feature #defines are now of the form FEATURE_xxx
382 * - Permanently turned off WIN_GUI_EDIT
383 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
385 * Revision 1.19 2001/07/15 17:45:16 jongfoster
386 * Removing some unused #includes
388 * Revision 1.18 2001/07/13 14:01:14 oes
389 * - Removed all #ifdef PCRS
390 * - Removed vim-settings
392 * Revision 1.17 2001/06/29 13:31:03 oes
393 * - Improved comments
394 * - Fixed (actionsfile) and sorted hashes
395 * - Introduced admin_address and proxy-info-url
396 * as config parameters
397 * - Renamed config->proxy_args_invocation (which didn't have
398 * the invocation but the options!) to config->proxy_args
399 * - Various adaptions
400 * - Removed logentry from cancelled commit
402 * Revision 1.16 2001/06/09 10:55:28 jongfoster
403 * Changing BUFSIZ ==> BUFFER_SIZE
405 * Revision 1.15 2001/06/07 23:13:40 jongfoster
406 * Merging ACL and forward files into config file.
407 * Cosmetic: Sorting config file options alphabetically.
408 * Cosmetic: Adding brief syntax comments to config file options.
410 * Revision 1.14 2001/06/07 14:46:25 joergs
411 * Missing make_path() added for re_filterfile.
413 * Revision 1.13 2001/06/05 22:33:54 jongfoster
415 * Fixed minor memory leak.
416 * Also now uses make_path to prepend the pathnames.
418 * Revision 1.12 2001/06/05 20:04:09 jongfoster
419 * Now uses _snprintf() in place of snprintf() under Win32.
421 * Revision 1.11 2001/06/04 18:31:58 swa
422 * files are now prefixed with either `confdir' or `logdir'.
423 * `make redhat-dist' replaces both entries confdir and logdir
426 * Revision 1.10 2001/06/03 19:11:54 oes
427 * introduced confdir option
429 * Revision 1.9 2001/06/01 20:06:24 jongfoster
430 * Removed support for "tinygif" option - moved to actions file.
432 * Revision 1.8 2001/05/31 21:27:13 jongfoster
433 * Removed many options from the config file and into the
434 * "actions" file: add_forwarded, suppress_vanilla_wafer,
435 * wafer, add_header, user_agent, referer, from
436 * Also globally replaced "permission" with "action".
438 * Revision 1.7 2001/05/29 09:50:24 jongfoster
439 * Unified blocklist/imagelist/permissionslist.
440 * File format is still under discussion, but the internal changes
443 * Also modified interceptor behaviour:
444 * - We now intercept all URLs beginning with one of the following
445 * prefixes (and *only* these prefixes):
447 * * http://ijbswa.sf.net/config/
448 * * http://ijbswa.sourceforge.net/config/
449 * - New interceptors "home page" - go to http://i.j.b/ to see it.
450 * - Internal changes so that intercepted and fast redirect pages
451 * are not replaced with an image.
452 * - Interceptors now have the option to send a binary page direct
453 * to the client. (i.e. ijb-send-banner uses this)
454 * - Implemented show-url-info interceptor. (Which is why I needed
455 * the above interceptors changes - a typical URL is
456 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
457 * The previous mechanism would not have intercepted that, and
458 * if it had been intercepted then it then it would have replaced
461 * Revision 1.6 2001/05/26 00:28:36 jongfoster
462 * Automatic reloading of config file.
463 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
464 * Most of the global variables have been moved to a new
465 * struct configuration_spec, accessed through csp->config->globalname
466 * Most of the globals remaining are used by the Win32 GUI.
468 * Revision 1.5 2001/05/25 22:34:30 jongfoster
471 * Revision 1.4 2001/05/22 18:46:04 oes
473 * - Enabled filtering banners by size rather than URL
474 * by adding patterns that replace all standard banner
475 * sizes with the "Junkbuster" gif to the re_filterfile
477 * - Enabled filtering WebBugs by providing a pattern
478 * which kills all 1x1 images
480 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
481 * which is selected by the (nonstandard and therefore
482 * capital) letter 'U' in the option string.
483 * It causes the quantifiers to be ungreedy by default.
484 * Appending a ? turns back to greedy (!).
486 * - Added a new interceptor ijb-send-banner, which
487 * sends back the "Junkbuster" gif. Without imagelist or
488 * MSIE detection support, or if tinygif = 1, or the
489 * URL isn't recognized as an imageurl, a lame HTML
490 * explanation is sent instead.
492 * - Added new feature, which permits blocking remote
493 * script redirects and firing back a local redirect
495 * The feature is conditionally compiled, i.e. it
496 * can be disabled with --disable-fast-redirects,
497 * plus it must be activated by a "fast-redirects"
498 * line in the config file, has its own log level
499 * and of course wants to be displayed by show-proxy-args
500 * Note: Boy, all the #ifdefs in 1001 locations and
501 * all the fumbling with configure.in and acconfig.h
502 * were *way* more work than the feature itself :-(
504 * - Because a generic redirect template was needed for
505 * this, tinygif = 3 now uses the same.
507 * - Moved GIFs, and other static HTTP response templates
512 * - Removed some >400 CRs again (Jon, you really worked
515 * Revision 1.3 2001/05/20 01:21:20 jongfoster
516 * Version 2.9.4 checkin.
517 * - Merged popupfile and cookiefile, and added control over PCRS
518 * filtering, in new "permissionsfile".
519 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
520 * file error you now get a message box (in the Win32 GUI) rather
521 * than the program exiting with no explanation.
522 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
524 * - Removed tabs from "config"
525 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
526 * - Bumped up version number.
528 * Revision 1.2 2001/05/17 23:01:01 oes
529 * - Cleaned CRLF's from the sources and related files
531 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
532 * Initial import of version 2.9.3 source tree
535 *********************************************************************/
541 #include <sys/types.h>
555 # include <windows.h>
558 # ifndef _WIN_CONSOLE
560 # endif /* ndef _WIN_CONSOLE */
562 #else /* ifndef _WIN32 */
566 # include <sys/wait.h>
568 # include <sys/time.h>
569 # include <sys/stat.h>
579 #include "miscutil.h"
583 #include "urlmatch.h"
587 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
590 * Fix a problem with Solaris. There should be no effect on other
592 * Solaris's isspace() is a macro which uses it's argument directly
593 * as an array index. Therefore we need to make sure that high-bit
594 * characters generate +ve values, and ideally we also want to make
595 * the argument match the declared parameter type of "int".
597 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
598 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
600 #ifdef FEATURE_TOGGLE
601 /* Privoxy is enabled by default. */
602 int global_toggle_state = 1;
603 #endif /* def FEATURE_TOGGLE */
605 /* The filename of the configfile */
606 const char *configfile = NULL;
609 * CGI functions will later need access to the invocation args,
610 * so we will make argc and argv global.
613 const char **Argv = NULL;
615 static struct file_list *current_configfile = NULL;
619 * This takes the "cryptic" hash of each keyword and aliases them to
620 * something a little more readable. This also makes changing the
621 * hash values easier if they should change or the hash algorthm changes.
622 * Use the included "hash" program to find out what the hash will be
623 * for any string supplied on the command line. (Or just put it in the
624 * config file and read the number from the error message in the log).
626 * Please keep this list sorted alphabetically (but with the Windows
627 * console and GUI specific options last).
630 #define hash_actions_file 1196306641ul /* "actionsfile" */
631 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
632 #define hash_admin_address 4112573064ul /* "admin-address" */
633 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
634 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
635 #define hash_confdir 1978389ul /* "confdir" */
636 #define hash_debug 78263ul /* "debug" */
637 #define hash_deny_access 1227333715ul /* "deny-access" */
638 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
639 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
640 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
641 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
642 #define hash_filterfile 250887266ul /* "filterfile" */
643 #define hash_forward 2029845ul /* "forward" */
644 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
645 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
646 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
647 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
648 #define hash_hostname 10308071ul /* "hostname" */
649 #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */
650 #define hash_listen_address 1255650842ul /* "listen-address" */
651 #define hash_logdir 422889ul /* "logdir" */
652 #define hash_logfile 2114766ul /* "logfile" */
653 #define hash_max_client_connections 3595884446ul /* "max-client-connections" */
654 #define hash_permit_access 3587953268ul /* "permit-access" */
655 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
656 #define hash_single_threaded 4250084780ul /* "single-threaded" */
657 #define hash_socket_timeout 1809001761ul /* "socket-timeout" */
658 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
659 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
660 #define hash_templdir 11067889ul /* "templdir" */
661 #define hash_toggle 447966ul /* "toggle" */
662 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
663 #define hash_trustfile 56494766ul /* "trustfile" */
664 #define hash_usermanual 1416668518ul /* "user-manual" */
665 #define hash_activity_animation 1817904738ul /* "activity-animation" */
666 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
667 #define hash_hide_console 2048809870ul /* "hide-console" */
668 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
669 #define hash_log_font_name 2866730124ul /* "log-font-name" */
670 #define hash_log_font_size 2866731014ul /* "log-font-size" */
671 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
672 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
673 #define hash_log_messages 2291744899ul /* "log-messages" */
674 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
677 static void savearg(char *command, char *argument, struct configuration_spec * config);
679 /*********************************************************************
681 * Function : unload_configfile
683 * Description : Free the config structure and all components.
686 * 1 : data: struct configuration_spec to unload
690 *********************************************************************/
691 static void unload_configfile (void * data)
693 struct configuration_spec * config = (struct configuration_spec *)data;
694 struct forward_spec *cur_fwd = config->forward;
698 struct access_control_list *cur_acl = config->acl;
700 while (cur_acl != NULL)
702 struct access_control_list * next_acl = cur_acl->next;
707 #endif /* def FEATURE_ACL */
709 while (cur_fwd != NULL)
711 struct forward_spec * next_fwd = cur_fwd->next;
712 free_url_spec(cur_fwd->url);
714 freez(cur_fwd->gateway_host);
715 freez(cur_fwd->forward_host);
719 config->forward = NULL;
721 freez(config->confdir);
722 freez(config->logdir);
723 freez(config->templdir);
724 freez(config->hostname);
726 freez(config->haddr);
727 freez(config->logfile);
729 for (i = 0; i < MAX_AF_FILES; i++)
731 freez(config->actions_file_short[i]);
732 freez(config->actions_file[i]);
733 freez(config->re_filterfile_short[i]);
734 freez(config->re_filterfile[i]);
737 freez(config->admin_address);
738 freez(config->proxy_info_url);
739 freez(config->proxy_args);
740 freez(config->usermanual);
743 freez(config->trustfile);
744 list_remove_all(config->trust_info);
745 #endif /* def FEATURE_TRUST */
747 for (i = 0; i < MAX_AF_FILES; i++)
749 freez(config->re_filterfile[i]);
756 #ifdef FEATURE_GRACEFUL_TERMINATION
757 /*********************************************************************
759 * Function : unload_current_config_file
761 * Description : Unloads current config file - reset to state at
762 * beginning of program.
768 *********************************************************************/
769 void unload_current_config_file(void)
771 if (current_configfile)
773 current_configfile->unloader = unload_configfile;
774 current_configfile = NULL;
780 /*********************************************************************
782 * Function : load_config
784 * Description : Load the config file and all parameters.
786 * XXX: more than thousand lines long
787 * and thus in serious need of refactoring.
791 * Returns : The configuration_spec, or NULL on error.
793 *********************************************************************/
794 struct configuration_spec * load_config(void)
796 char buf[BUFFER_SIZE];
798 FILE *configfp = NULL;
799 struct configuration_spec * config = NULL;
800 struct client_state * fake_csp;
801 struct file_list *fs;
802 unsigned long linenum = 0;
804 char *logfile = NULL;
806 if (!check_file_changed(current_configfile, configfile, &fs))
808 /* No need to load */
809 return ((struct configuration_spec *)current_configfile->f);
813 log_error(LOG_LEVEL_FATAL,
814 "can't check configuration file '%s': %E", configfile);
818 if (NULL != current_configfile)
820 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
823 #ifdef FEATURE_TOGGLE
824 global_toggle_state = 1;
825 #endif /* def FEATURE_TOGGLE */
827 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
833 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
838 * This is backwards from how it's usually done.
839 * Following the usual pattern, "fs" would be stored in a member
840 * variable in "csp", and then we'd access "config" from "fs->f",
841 * using a cast. However, "config" is used so often that a
842 * cast each time would be very ugly, and the extra indirection
843 * would waste CPU cycles. Therefore we store "config" in
844 * "csp->config", and "fs" in "csp->config->config_file_list".
846 config->config_file_list = fs;
851 config->multi_threaded = 1;
852 config->buffer_limit = 4096 * 1024;
853 config->usermanual = strdup(USER_MANUAL_URL);
854 config->proxy_args = strdup("");
855 config->forwarded_connect_retries = 0;
856 config->max_client_connections = 0;
857 config->socket_timeout = 300; /* XXX: Should be a macro. */
858 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
859 config->keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
860 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
862 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
863 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
864 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
866 configfp = fopen(configfile, "r");
867 if (NULL == configfp)
869 log_error(LOG_LEVEL_FATAL,
870 "can't open configuration file '%s': %E", configfile);
871 /* Never get here - LOG_LEVEL_FATAL causes program exit */
874 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
876 char cmd[BUFFER_SIZE];
877 char arg[BUFFER_SIZE];
878 char tmp[BUFFER_SIZE];
880 struct access_control_list *cur_acl;
881 #endif /* def FEATURE_ACL */
882 struct forward_spec *cur_fwd;
885 unsigned long directive_hash;
887 strlcpy(tmp, buf, sizeof(tmp));
889 /* Copy command (i.e. up to space or tab) into cmd */
892 while (*p && (*p != ' ') && (*p != '\t'))
898 /* Skip over the whitespace in buf */
899 while (*p && ((*p == ' ') || (*p == '\t')))
904 /* Copy the argument into arg */
905 strlcpy(arg, p, sizeof(arg));
907 /* Should never happen, but check this anyway */
913 /* Make sure the command field is lower case */
914 for (p = cmd; *p; p++)
918 *p = (char)ijb_tolower(*p);
922 directive_hash = hash_string(cmd);
923 switch (directive_hash)
925 /* *************************************************************************
926 * actionsfile actions-file-name
927 * In confdir by default
928 * *************************************************************************/
929 case hash_actions_file :
931 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
936 if (i >= MAX_AF_FILES)
938 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
939 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
942 config->actions_file_short[i] = strdup(arg);
943 config->actions_file[i] = make_path(config->confdir, arg);
946 /* *************************************************************************
947 * accept-intercepted-requests
948 * *************************************************************************/
949 case hash_accept_intercepted_requests:
950 if ((*arg != '\0') && (0 != atoi(arg)))
952 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
956 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
960 /* *************************************************************************
961 * admin-address email-address
962 * *************************************************************************/
963 case hash_admin_address :
964 freez(config->admin_address);
965 config->admin_address = strdup(arg);
968 /* *************************************************************************
969 * allow-cgi-request-crunching
970 * *************************************************************************/
971 case hash_allow_cgi_request_crunching:
972 if ((*arg != '\0') && (0 != atoi(arg)))
974 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
978 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
982 /* *************************************************************************
984 * *************************************************************************/
985 case hash_buffer_limit :
986 config->buffer_limit = (size_t)(1024 * atoi(arg));
989 /* *************************************************************************
990 * confdir directory-name
991 * *************************************************************************/
993 freez(config->confdir);
994 config->confdir = make_path( NULL, arg);
997 /* *************************************************************************
999 * Specifies debug level, multiple values are ORed together.
1000 * *************************************************************************/
1002 config->debug |= atoi(arg);
1005 /* *************************************************************************
1006 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1007 * *************************************************************************/
1009 case hash_deny_access:
1010 strlcpy(tmp, arg, sizeof(tmp));
1011 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1013 if ((vec_count != 1) && (vec_count != 2))
1015 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1016 "deny-access directive in configuration file.");
1017 string_append(&config->proxy_args,
1018 "<br>\nWARNING: Wrong number of parameters for "
1019 "deny-access directive in configuration file.<br><br>\n");
1023 /* allocate a new node */
1024 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1026 if (cur_acl == NULL)
1028 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1029 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1032 cur_acl->action = ACL_DENY;
1034 if (acl_addr(vec[0], cur_acl->src) < 0)
1036 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1037 "for deny-access directive in configuration file: \"%s\"", vec[0]);
1038 string_append(&config->proxy_args,
1039 "<br>\nWARNING: Invalid source address, port or netmask "
1040 "for deny-access directive in configuration file: \"");
1041 string_append(&config->proxy_args,
1043 string_append(&config->proxy_args,
1050 if (acl_addr(vec[1], cur_acl->dst) < 0)
1052 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1053 "for deny-access directive in configuration file: \"%s\"", vec[1]);
1054 string_append(&config->proxy_args,
1055 "<br>\nWARNING: Invalid destination address, port or netmask "
1056 "for deny-access directive in configuration file: \"");
1057 string_append(&config->proxy_args,
1059 string_append(&config->proxy_args,
1068 cur_acl->wildcard_dst = 1;
1070 #endif /* def HAVE_RFC2553 */
1073 * Add it to the list. Note we reverse the list to get the
1074 * behaviour the user expects. With both the ACL and
1075 * actions file, the last match wins. However, the internal
1076 * implementations are different: The actions file is stored
1077 * in the same order as the file, and scanned completely.
1078 * With the ACL, we reverse the order as we load it, then
1079 * when we scan it we stop as soon as we get a match.
1081 cur_acl->next = config->acl;
1082 config->acl = cur_acl;
1085 #endif /* def FEATURE_ACL */
1087 /* *************************************************************************
1088 * enable-edit-actions 0|1
1089 * *************************************************************************/
1090 #ifdef FEATURE_CGI_EDIT_ACTIONS
1091 case hash_enable_edit_actions:
1092 if ((*arg != '\0') && (0 != atoi(arg)))
1094 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1098 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1101 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1103 /* *************************************************************************
1104 * enable-remote-toggle 0|1
1105 * *************************************************************************/
1106 #ifdef FEATURE_TOGGLE
1107 case hash_enable_remote_toggle:
1108 if ((*arg != '\0') && (0 != atoi(arg)))
1110 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1114 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1117 #endif /* def FEATURE_TOGGLE */
1119 /* *************************************************************************
1120 * enable-remote-http-toggle 0|1
1121 * *************************************************************************/
1122 case hash_enable_remote_http_toggle:
1123 if ((*arg != '\0') && (0 != atoi(arg)))
1125 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1129 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1133 /* *************************************************************************
1134 * enforce-blocks 0|1
1135 * *************************************************************************/
1136 case hash_enforce_blocks:
1137 #ifdef FEATURE_FORCE_LOAD
1138 if ((*arg != '\0') && (0 != atoi(arg)))
1140 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1144 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1147 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1148 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1149 #endif /* def FEATURE_FORCE_LOAD */
1152 /* *************************************************************************
1153 * filterfile file-name
1154 * In confdir by default.
1155 * *************************************************************************/
1156 case hash_filterfile :
1158 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1163 if (i >= MAX_AF_FILES)
1165 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1166 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1169 config->re_filterfile_short[i] = strdup(arg);
1170 config->re_filterfile[i] = make_path(config->confdir, arg);
1174 /* *************************************************************************
1175 * forward url-pattern (.|http-proxy-host[:port])
1176 * *************************************************************************/
1178 strlcpy(tmp, arg, sizeof(tmp));
1179 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1183 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1184 "directive in configuration file.");
1185 string_append(&config->proxy_args,
1186 "<br>\nWARNING: Wrong number of parameters for "
1187 "forward directive in configuration file.");
1191 /* allocate a new node */
1192 cur_fwd = zalloc(sizeof(*cur_fwd));
1193 if (cur_fwd == NULL)
1195 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1196 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1200 cur_fwd->type = SOCKS_NONE;
1202 /* Save the URL pattern */
1203 if (create_url_spec(cur_fwd->url, vec[0]))
1205 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1206 "directive in configuration file.");
1207 string_append(&config->proxy_args,
1208 "<br>\nWARNING: Bad URL specifier for "
1209 "forward directive in configuration file.");
1213 /* Parse the parent HTTP proxy host:port */
1216 if (strcmp(p, ".") != 0)
1218 cur_fwd->forward_port = 8000;
1219 parse_forwarder_address(p, &cur_fwd->forward_host,
1220 &cur_fwd->forward_port);
1224 cur_fwd->next = config->forward;
1225 config->forward = cur_fwd;
1229 /* *************************************************************************
1230 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1231 * *************************************************************************/
1232 case hash_forward_socks4:
1233 strlcpy(tmp, arg, sizeof(tmp));
1234 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1238 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1239 "forward-socks4 directive in configuration file.");
1240 string_append(&config->proxy_args,
1241 "<br>\nWARNING: Wrong number of parameters for "
1242 "forward-socks4 directive in configuration file.");
1246 /* allocate a new node */
1247 cur_fwd = zalloc(sizeof(*cur_fwd));
1248 if (cur_fwd == NULL)
1250 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1251 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1255 cur_fwd->type = SOCKS_4;
1257 /* Save the URL pattern */
1258 if (create_url_spec(cur_fwd->url, vec[0]))
1260 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1261 "directive in configuration file.");
1262 string_append(&config->proxy_args,
1263 "<br>\nWARNING: Bad URL specifier for "
1264 "forward-socks4 directive in configuration file.");
1268 /* Parse the SOCKS proxy host[:port] */
1271 /* XXX: This check looks like a bug. */
1272 if (strcmp(p, ".") != 0)
1274 cur_fwd->gateway_port = 1080;
1275 parse_forwarder_address(p, &cur_fwd->gateway_host,
1276 &cur_fwd->gateway_port);
1279 /* Parse the parent HTTP proxy host[:port] */
1282 if (strcmp(p, ".") != 0)
1284 cur_fwd->forward_port = 8000;
1285 parse_forwarder_address(p, &cur_fwd->forward_host,
1286 &cur_fwd->forward_port);
1290 cur_fwd->next = config->forward;
1291 config->forward = cur_fwd;
1295 /* *************************************************************************
1296 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1297 * *************************************************************************/
1298 case hash_forward_socks4a:
1299 case hash_forward_socks5:
1300 strlcpy(tmp, arg, sizeof(tmp));
1301 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1305 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1306 "forward-socks4a directive in configuration file.");
1307 string_append(&config->proxy_args,
1308 "<br>\nWARNING: Wrong number of parameters for "
1309 "forward-socks4a directive in configuration file.");
1313 /* allocate a new node */
1314 cur_fwd = zalloc(sizeof(*cur_fwd));
1315 if (cur_fwd == NULL)
1317 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1318 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1322 if (directive_hash == hash_forward_socks4a)
1324 cur_fwd->type = SOCKS_4A;
1328 cur_fwd->type = SOCKS_5;
1331 /* Save the URL pattern */
1332 if (create_url_spec(cur_fwd->url, vec[0]))
1334 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1335 "directive in configuration file.");
1336 string_append(&config->proxy_args,
1337 "<br>\nWARNING: Bad URL specifier for "
1338 "forward-socks4a directive in configuration file.");
1342 /* Parse the SOCKS proxy host[:port] */
1345 cur_fwd->gateway_port = 1080;
1346 parse_forwarder_address(p, &cur_fwd->gateway_host,
1347 &cur_fwd->gateway_port);
1349 /* Parse the parent HTTP proxy host[:port] */
1352 if (strcmp(p, ".") != 0)
1354 cur_fwd->forward_port = 8000;
1355 parse_forwarder_address(p, &cur_fwd->forward_host,
1356 &cur_fwd->forward_port);
1360 cur_fwd->next = config->forward;
1361 config->forward = cur_fwd;
1365 /* *************************************************************************
1366 * forwarded-connect-retries n
1367 * *************************************************************************/
1368 case hash_forwarded_connect_retries :
1369 config->forwarded_connect_retries = atoi(arg);
1372 /* *************************************************************************
1373 * hostname hostname-to-show-on-cgi-pages
1374 * *************************************************************************/
1375 case hash_hostname :
1376 freez(config->hostname);
1377 config->hostname = strdup(arg);
1378 if (NULL == config->hostname)
1380 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1384 /* *************************************************************************
1385 * keep-alive-timeout timeout
1386 * *************************************************************************/
1387 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1388 case hash_keep_alive_timeout :
1391 int timeout = atoi(arg);
1394 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1395 config->keep_alive_timeout = timeout;
1399 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1405 /* *************************************************************************
1406 * listen-address [ip][:port]
1407 * *************************************************************************/
1408 case hash_listen_address :
1409 freez(config->haddr);
1410 config->haddr = strdup(arg);
1413 /* *************************************************************************
1414 * logdir directory-name
1415 * *************************************************************************/
1417 freez(config->logdir);
1418 config->logdir = make_path(NULL, arg);
1421 /* *************************************************************************
1422 * logfile log-file-name
1423 * In logdir by default
1424 * *************************************************************************/
1428 logfile = make_path(config->logdir, arg);
1429 if (NULL == logfile)
1431 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1436 /* *************************************************************************
1437 * max-client-connections number
1438 * *************************************************************************/
1439 case hash_max_client_connections :
1442 int max_client_connections = atoi(arg);
1443 if (0 <= max_client_connections)
1445 config->max_client_connections = max_client_connections;
1450 /* *************************************************************************
1451 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1452 * *************************************************************************/
1454 case hash_permit_access:
1455 strlcpy(tmp, arg, sizeof(tmp));
1456 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1458 if ((vec_count != 1) && (vec_count != 2))
1460 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1461 "permit-access directive in configuration file.");
1462 string_append(&config->proxy_args,
1463 "<br>\nWARNING: Wrong number of parameters for "
1464 "permit-access directive in configuration file.<br><br>\n");
1469 /* allocate a new node */
1470 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1472 if (cur_acl == NULL)
1474 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1475 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1478 cur_acl->action = ACL_PERMIT;
1480 if (acl_addr(vec[0], cur_acl->src) < 0)
1482 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1483 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1484 string_append(&config->proxy_args,
1485 "<br>\nWARNING: Invalid source address, port or netmask for "
1486 "permit-access directive in configuration file: \"");
1487 string_append(&config->proxy_args,
1489 string_append(&config->proxy_args,
1496 if (acl_addr(vec[1], cur_acl->dst) < 0)
1498 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1499 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1500 string_append(&config->proxy_args,
1501 "<br>\nWARNING: Invalid destination address, port or netmask for "
1502 "permit-access directive in configuration file: \"");
1503 string_append(&config->proxy_args,
1505 string_append(&config->proxy_args,
1514 cur_acl->wildcard_dst = 1;
1516 #endif /* def HAVE_RFC2553 */
1519 * Add it to the list. Note we reverse the list to get the
1520 * behaviour the user expects. With both the ACL and
1521 * actions file, the last match wins. However, the internal
1522 * implementations are different: The actions file is stored
1523 * in the same order as the file, and scanned completely.
1524 * With the ACL, we reverse the order as we load it, then
1525 * when we scan it we stop as soon as we get a match.
1527 cur_acl->next = config->acl;
1528 config->acl = cur_acl;
1531 #endif /* def FEATURE_ACL */
1533 /* *************************************************************************
1534 * proxy-info-url url
1535 * *************************************************************************/
1536 case hash_proxy_info_url :
1537 freez(config->proxy_info_url);
1538 config->proxy_info_url = strdup(arg);
1541 /* *************************************************************************
1543 * *************************************************************************/
1544 case hash_single_threaded :
1545 config->multi_threaded = 0;
1548 /* *************************************************************************
1549 * socket-timeout numer_of_seconds
1550 * *************************************************************************/
1551 case hash_socket_timeout :
1554 int socket_timeout = atoi(arg);
1555 if (0 < socket_timeout)
1557 config->socket_timeout = socket_timeout;
1561 log_error(LOG_LEVEL_FATAL,
1562 "Invalid socket-timeout: '%s'", arg);
1567 /* *************************************************************************
1568 * split-large-cgi-forms
1569 * *************************************************************************/
1570 case hash_split_large_cgi_forms :
1571 if ((*arg != '\0') && (0 != atoi(arg)))
1573 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1577 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1581 /* *************************************************************************
1582 * templdir directory-name
1583 * *************************************************************************/
1584 case hash_templdir :
1585 freez(config->templdir);
1586 config->templdir = make_path(NULL, arg);
1589 /* *************************************************************************
1591 * *************************************************************************/
1592 #ifdef FEATURE_TOGGLE
1594 global_toggle_state = atoi(arg);
1596 #endif /* def FEATURE_TOGGLE */
1598 /* *************************************************************************
1599 * trust-info-url url
1600 * *************************************************************************/
1601 #ifdef FEATURE_TRUST
1602 case hash_trust_info_url :
1603 enlist(config->trust_info, arg);
1605 #endif /* def FEATURE_TRUST */
1607 /* *************************************************************************
1608 * trustfile filename
1609 * (In confdir by default.)
1610 * *************************************************************************/
1611 #ifdef FEATURE_TRUST
1612 case hash_trustfile :
1613 freez(config->trustfile);
1614 config->trustfile = make_path(config->confdir, arg);
1616 #endif /* def FEATURE_TRUST */
1618 /* *************************************************************************
1620 * *************************************************************************/
1621 case hash_usermanual :
1623 * XXX: If this isn't the first config directive, the
1624 * show-status page links to the website documentation
1625 * for the directives that were already parsed. Lame.
1627 freez(config->usermanual);
1628 config->usermanual = strdup(arg);
1631 /* *************************************************************************
1632 * Win32 Console options:
1633 * *************************************************************************/
1635 /* *************************************************************************
1637 * *************************************************************************/
1639 case hash_hide_console :
1642 #endif /*def _WIN_CONSOLE*/
1645 /* *************************************************************************
1646 * Win32 GUI options:
1647 * *************************************************************************/
1649 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1650 /* *************************************************************************
1651 * activity-animation (0|1)
1652 * *************************************************************************/
1653 case hash_activity_animation :
1654 g_bShowActivityAnimation = atoi(arg);
1657 /* *************************************************************************
1658 * close-button-minimizes (0|1)
1659 * *************************************************************************/
1660 case hash_close_button_minimizes :
1661 g_bCloseHidesWindow = atoi(arg);
1664 /* *************************************************************************
1665 * log-buffer-size (0|1)
1666 * *************************************************************************/
1667 case hash_log_buffer_size :
1668 g_bLimitBufferSize = atoi(arg);
1671 /* *************************************************************************
1672 * log-font-name fontname
1673 * *************************************************************************/
1674 case hash_log_font_name :
1675 if (strlcpy(g_szFontFaceName, arg,
1676 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1678 log_error(LOG_LEVEL_FATAL,
1679 "log-font-name argument '%s' is longer than %u characters.",
1680 arg, sizeof(g_szFontFaceName)-1);
1684 /* *************************************************************************
1686 * *************************************************************************/
1687 case hash_log_font_size :
1688 g_nFontSize = atoi(arg);
1691 /* *************************************************************************
1692 * log-highlight-messages (0|1)
1693 * *************************************************************************/
1694 case hash_log_highlight_messages :
1695 g_bHighlightMessages = atoi(arg);
1698 /* *************************************************************************
1700 * *************************************************************************/
1701 case hash_log_max_lines :
1702 g_nMaxBufferLines = atoi(arg);
1705 /* *************************************************************************
1706 * log-messages (0|1)
1707 * *************************************************************************/
1708 case hash_log_messages :
1709 g_bLogMessages = atoi(arg);
1712 /* *************************************************************************
1713 * show-on-task-bar (0|1)
1714 * *************************************************************************/
1715 case hash_show_on_task_bar :
1716 g_bShowOnTaskBar = atoi(arg);
1719 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1722 /* *************************************************************************
1723 * Warnings about unsupported features
1724 * *************************************************************************/
1726 case hash_deny_access:
1727 #endif /* ndef FEATURE_ACL */
1728 #ifndef FEATURE_CGI_EDIT_ACTIONS
1729 case hash_enable_edit_actions:
1730 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1731 #ifndef FEATURE_TOGGLE
1732 case hash_enable_remote_toggle:
1733 #endif /* ndef FEATURE_TOGGLE */
1735 case hash_permit_access:
1736 #endif /* ndef FEATURE_ACL */
1737 #ifndef FEATURE_TOGGLE
1739 #endif /* ndef FEATURE_TOGGLE */
1740 #ifndef FEATURE_TRUST
1741 case hash_trustfile :
1742 case hash_trust_info_url :
1743 #endif /* ndef FEATURE_TRUST */
1745 #ifndef _WIN_CONSOLE
1746 case hash_hide_console :
1747 #endif /* ndef _WIN_CONSOLE */
1749 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1750 case hash_activity_animation :
1751 case hash_close_button_minimizes :
1752 case hash_log_buffer_size :
1753 case hash_log_font_name :
1754 case hash_log_font_size :
1755 case hash_log_highlight_messages :
1756 case hash_log_max_lines :
1757 case hash_log_messages :
1758 case hash_show_on_task_bar :
1759 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1760 /* These warnings are annoying - so hide them. -- Jon */
1761 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1764 /* *************************************************************************/
1766 /* *************************************************************************/
1768 * I decided that I liked this better as a warning than an
1769 * error. To change back to an error, just change log level
1770 * to LOG_LEVEL_FATAL.
1772 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1773 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1774 string_append(&config->proxy_args,
1775 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1778 /* *************************************************************************/
1779 } /* end switch( hash_string(cmd) ) */
1781 /* Save the argument for the show-status page. */
1782 savearg(cmd, arg, config);
1784 } /* end while ( read_config_line(...) ) */
1788 set_debug_level(config->debug);
1790 freez(config->logfile);
1794 if (NULL != logfile)
1796 config->logfile = logfile;
1797 init_error_log(Argv[0], config->logfile);
1805 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1806 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1808 if (config->multi_threaded)
1810 set_keep_alive_timeout(config->keep_alive_timeout);
1815 * While we could use keep-alive without multiple threads
1816 * if we didn't bother with enforcing the connection timeout,
1817 * that might make Tor users sad, even though they shouldn't
1818 * enable the single-threaded option anyway.
1820 * XXX: We could still use Proxy-Connection: keep-alive.
1822 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1823 log_error(LOG_LEVEL_ERROR,
1824 "Config option single-threaded disables connection keep-alive.");
1829 if (NULL == config->proxy_args)
1831 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1834 if (config->actions_file[0])
1836 add_loader(load_action_files, config);
1839 if (config->re_filterfile[0])
1841 add_loader(load_re_filterfiles, config);
1844 #ifdef FEATURE_TRUST
1845 if (config->trustfile)
1847 add_loader(load_trustfile, config);
1849 #endif /* def FEATURE_TRUST */
1851 if ( NULL == config->haddr )
1853 config->haddr = strdup( HADDR_DEFAULT );
1856 if ( NULL != config->haddr )
1858 if ((*config->haddr == '[')
1859 && (NULL != (p = strchr(config->haddr, ']')))
1861 && (0 < (config->hport = atoi(p + 2))))
1864 memmove((void *)config->haddr, config->haddr + 1,
1865 (size_t)(p - config->haddr));
1867 else if (NULL != (p = strchr(config->haddr, ':'))
1868 && (0 < (config->hport = atoi(p + 1))))
1874 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1875 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1877 if (*config->haddr == '\0')
1880 * Only the port specified. We stored it in config->hport
1881 * and don't need its text representation anymore.
1883 freez(config->haddr);
1888 * Want to run all the loaders once now.
1890 * Need to set up a fake csp, so they can get to the config.
1892 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1893 fake_csp->config = config;
1895 if (run_loader(fake_csp))
1898 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1899 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1903 /* FIXME: this is a kludge for win32 */
1904 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1906 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1907 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1908 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1910 #ifdef FEATURE_TRUST
1911 g_trustfile = config->trustfile;
1912 #endif /* def FEATURE_TRUST */
1915 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1916 /* FIXME: end kludge */
1919 config->need_bind = 1;
1921 if (current_configfile)
1923 struct configuration_spec * oldcfg = (struct configuration_spec *)
1924 current_configfile->f;
1926 * Check if config->haddr,hport == oldcfg->haddr,hport
1928 * The following could be written more compactly as a single,
1929 * (unreadably long) if statement.
1931 config->need_bind = 0;
1932 if (config->hport != oldcfg->hport)
1934 config->need_bind = 1;
1936 else if (config->haddr == NULL)
1938 if (oldcfg->haddr != NULL)
1940 config->need_bind = 1;
1943 else if (oldcfg->haddr == NULL)
1945 config->need_bind = 1;
1947 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1949 config->need_bind = 1;
1952 current_configfile->unloader = unload_configfile;
1955 fs->next = files->next;
1958 current_configfile = fs;
1964 /*********************************************************************
1966 * Function : savearg
1968 * Description : Called from `load_config'. It saves each non-empty
1969 * and non-comment line from config into
1970 * config->proxy_args. This is used to create the
1971 * show-proxy-args page. On error, frees
1972 * config->proxy_args and sets it to NULL
1975 * 1 : command = config setting that was found
1976 * 2 : argument = the setting's argument (if any)
1977 * 3 : config = Configuration to save into.
1981 *********************************************************************/
1982 static void savearg(char *command, char *argument, struct configuration_spec * config)
1991 * Add config option name embedded in
1992 * link to its section in the user-manual
1994 buf = strdup("\n<a href=\"");
1995 if (!strncmpic(config->usermanual, "file://", 7) ||
1996 !strncmpic(config->usermanual, "http", 4))
1998 string_append(&buf, config->usermanual);
2002 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
2004 string_append(&buf, CONFIG_HELP_PREFIX);
2005 string_join (&buf, string_toupper(command));
2006 string_append(&buf, "\">");
2007 string_append(&buf, command);
2008 string_append(&buf, "</a> ");
2012 freez(config->proxy_args);
2016 if ( (NULL != argument) && ('\0' != *argument) )
2018 s = html_encode(argument);
2022 freez(config->proxy_args);
2026 if (strncmpic(argument, "http://", 7) == 0)
2028 string_append(&buf, "<a href=\"");
2029 string_append(&buf, s);
2030 string_append(&buf, "\">");
2031 string_join (&buf, s);
2032 string_append(&buf, "</a>");
2036 string_join (&buf, s);
2040 string_append(&buf, "<br>");
2041 string_join(&config->proxy_args, buf);