1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.97 2009/04/17 11:45:19 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.97 2009/04/17 11:45:19 fabiankeil
39 * Replace HAVE_GETADDRINFO and HAVE_GETNAMEINFO macros
40 * with HAVE_RFC2553 macro. Original patch by Petr Pisar.
42 * Revision 1.96 2009/04/17 11:38:28 fabiankeil
43 * Add and use parse_forwarder_address() to reduce code duplication.
45 * Revision 1.95 2009/04/17 11:34:34 fabiankeil
46 * Style cosmetics for the IPv6 code.
48 * Revision 1.94 2009/04/17 11:27:49 fabiankeil
49 * Petr Pisar's privoxy-3.0.12-ipv6-3.diff.
51 * Revision 1.93 2009/03/18 21:46:26 fabiankeil
52 * Revert the last commit as there's a better way.
54 * Revision 1.92 2009/03/18 20:43:19 fabiankeil
55 * Don't enable LOG_LEVEL_INFO by default and don't apply the user's
56 * debug settings until the logfile has been opened (if there is one).
57 * Patch submitted by Roland in #2624120.
59 * Revision 1.91 2009/03/09 17:29:08 fabiankeil
60 * As of r1.88, the show-status page can use a single line for
61 * warnings about ignored directives and the names of the ignored
62 * directives themselves. Reminded by Lee, finally closes #1856559.
64 * Revision 1.90 2009/03/07 17:58:02 fabiankeil
65 * Fix two mingw32-only buffer overflows. Note that triggering
66 * them requires control over the configuration file in which
67 * case all bets are off anyway.
69 * Revision 1.89 2009/03/01 18:46:33 fabiankeil
70 * - Help clang understand that we aren't
71 * dereferencing NULL pointers here.
72 * - Some style fixes in the modified region.
74 * Revision 1.88 2009/02/28 10:57:10 fabiankeil
75 * Gimme a break or two. Don't let the show-status page
76 * link to the website documentation for the user-manual
79 * Revision 1.87 2009/02/15 07:56:13 fabiankeil
80 * Increase default socket timeout to 300 seconds.
82 * Revision 1.86 2009/02/08 19:18:57 fabiankeil
83 * Now that we have the match-all.action file, the other action
84 * files changed their position in config->actions_file[] back
85 * to the way it was before standard.action got removed and the
86 * changes from revision 1.84 have to be reverted.
88 * Revision 1.85 2009/01/22 12:06:26 fabiankeil
89 * Don't keep connections alive when running single-threaded.
91 * Revision 1.84 2009/01/14 16:14:36 fabiankeil
92 * Due to the standard.action file removal, the other action
93 * files changed their position in config->actions_file[].
94 * Update mingw32 kludge accordingly.
96 * Revision 1.83 2008/12/20 14:53:55 fabiankeil
97 * Add config option socket-timeout to control the time
98 * Privoxy waits for data to arrive on a socket. Useful
99 * in case of stale ssh tunnels or when fuzz-testing.
101 * Revision 1.82 2008/11/16 12:43:49 fabiankeil
102 * Turn keep-alive support into a runtime feature
103 * that is disabled by setting keep-alive-timeout
104 * to a negative value.
106 * Revision 1.81 2008/11/13 09:08:42 fabiankeil
107 * Add new config option: keep-alive-timeout.
109 * Revision 1.80 2008/08/31 15:59:03 fabiankeil
110 * There's no reason to let remote toggling support depend
111 * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
113 * Revision 1.79 2008/08/30 12:03:07 fabiankeil
114 * Remove FEATURE_COOKIE_JAR.
116 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
117 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
118 * disabled, log a message that blocks will always be enforced
119 * instead of complaining about an unrecognized directive.
120 * Reported by Pietro Leone.
122 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
123 * Reuse directive_hash and don't hash the same directive twice.
125 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
126 * - Merge three string_append() calls.
127 * - Remove useless assertion.
129 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
130 * Rename load_actions_file() and load_re_filterfile()
131 * as they load multiple files "now".
133 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
134 * Add hostname directive. Closes PR#1918189.
136 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
139 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
140 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
142 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
143 * Reword "unrecognized directive" warning, use better
144 * mark up and add a <br>. Fixes parts of #1856559.
146 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
147 * Plug memory leak if listen-address only specifies the port.
149 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
150 * Relocate daemon-mode-related log messages to make sure
151 * they aren't shown again in case of configuration reloads.
153 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
154 * Plug memory leak introduced with my last commit.
156 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
157 * When in daemon mode, close stderr after the configuration file has been
158 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
160 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
161 * #1763173 from Stefan Huehner: declare unload_configfile() static.
163 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
164 * As Hal noticed, checking dispatch_cgi() as the last cruncher
165 * looks like a bug if CGI requests are blocked unintentionally,
166 * so don't do it unless the user enabled the new config option
167 * "allow-cgi-request-crunching".
169 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
170 * - Use strlcpy() instead of strcpy().
171 * - Stop treating actions files special. Expect a complete file name
172 * (with or without path) like it's done for the rest of the files.
174 * - Remove an unnecessary temporary memory allocation.
175 * - Don't log anything to the console when running as
176 * daemon and no errors occurred.
178 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
179 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
181 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
182 * New config option: enforce-blocks.
184 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
185 * - Mention other reasons why acl directive loading might have failed.
186 * - Don't log the acl source if the acl destination is to blame.
188 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
189 * Add new config option "templdir" to
190 * change the templates directory.
192 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
193 * Added config option accept-intercepted-requests
194 * and disabled it by default.
196 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
197 * Fix gcc43 compiler warnings.
199 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
200 * Add config option "split-large-forms"
201 * to work around the browser bug reported
204 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
205 * Move the <br> in the generated HTML for the config
206 * options from the beginning of the string to its end.
207 * Keeps the white space in balance.
209 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
210 * Fix memory leak in case of config file reloads.
212 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
213 * Modified kludge for win32 to make ming32 menu
214 * "Options/Edit Filters" (sort of) work again.
215 * Same limitations as for the action files apply.
218 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
219 * Incorporate modified version of Roland Rosenfeld's patch to
220 * optionally access the user-manual via Privoxy. Closes patch 679075.
222 * Formatting changed to Privoxy style, added call to
223 * cgi_error_no_template if the requested file doesn't
224 * exist and modified check whether or not Privoxy itself
225 * should serve the manual. Should work cross-platform now.
227 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
228 * Added config option enable-remote-http-toggle
229 * to specify if Privoxy should recognize special
230 * headers (currently only X-Filter) to change its
231 * behaviour. Disabled by default.
233 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
234 * Make number of retries in case of forwarded-connect problems
235 * a config file option (forwarded-connect-retries) and use 0 as
238 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
239 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
240 * with what was really the latest development (the v_3_0_branch branch)
242 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
243 * Don't forget to malloc space for the null terminator...
245 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
246 * Multiple filter file support
248 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
249 * Closed two memory leaks; hopefully the last remaining ones
250 * (in the main execution paths, anyway).
252 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
253 * Addressed bug #719435
254 * - Extraneous filterfile directives now logged as errors
255 * - This and unrecnonised directives now really obvious on status page
257 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
258 * Cosmetic: Renamed cryptic variable
260 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
261 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
263 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
264 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
266 * Revision 1.48 2002/05/14 21:30:38 oes
267 * savearg now uses own linking code instead of (now special-cased) add_help_link
269 * Revision 1.47 2002/05/12 21:36:29 jongfoster
270 * Correcting function comments
272 * Revision 1.46 2002/04/26 12:55:14 oes
273 * - New option "user-manual", defaults to our site
274 * via project.h #define
275 * - savearg now embeds option names in help links
277 * Revision 1.45 2002/04/24 02:11:54 oes
278 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
280 * Revision 1.44 2002/04/08 20:37:13 swa
283 * Revision 1.43 2002/04/08 20:36:50 swa
286 * Revision 1.42 2002/04/05 15:50:15 oes
287 * fix for invalid HTML proxy_args
289 * Revision 1.41 2002/03/31 17:19:00 jongfoster
290 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
292 * Revision 1.40 2002/03/26 22:29:55 swa
293 * we have a new homepage!
295 * Revision 1.39 2002/03/24 13:25:43 swa
296 * name change related issues
298 * Revision 1.38 2002/03/24 13:05:48 jongfoster
299 * Renaming re_filterfile to filterfile
301 * Revision 1.37 2002/03/16 23:54:06 jongfoster
302 * Adding graceful termination feature, to help look for memory leaks.
303 * If you enable this (which, by design, has to be done by hand
304 * editing config.h) and then go to http://i.j.b/die, then the program
305 * will exit cleanly after the *next* request. It should free all the
306 * memory that was used.
308 * Revision 1.36 2002/03/13 00:27:05 jongfoster
311 * Revision 1.35 2002/03/07 03:52:44 oes
312 * Set logging to tty for --no-daemon mode
314 * Revision 1.34 2002/03/06 23:14:35 jongfoster
315 * Trivial cosmetic changes to make function comments easier to find.
317 * Revision 1.33 2002/03/05 04:52:42 oes
318 * Deleted non-errlog debugging code
320 * Revision 1.32 2002/03/04 18:24:53 oes
321 * Re-enabled output of unknown config directive hash
323 * Revision 1.31 2002/03/03 15:07:20 oes
324 * Re-enabled automatic config reloading
326 * Revision 1.30 2002/01/22 23:31:43 jongfoster
327 * Replacing strsav() with string_append()
329 * Revision 1.29 2002/01/17 21:02:30 jongfoster
330 * Moving all our URL and URL pattern parsing code to urlmatch.c.
332 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
334 * Revision 1.28 2001/12/30 14:07:32 steudten
335 * - Add signal handling (unix)
336 * - Add SIGHUP handler (unix)
337 * - Add creation of pidfile (unix)
338 * - Add action 'top' in rc file (RH)
339 * - Add entry 'SIGNALS' to manpage
340 * - Add exit message to logfile (unix)
342 * Revision 1.27 2001/11/07 00:02:13 steudten
343 * Add line number in error output for lineparsing for
344 * actionsfile and configfile.
345 * Special handling for CLF added.
347 * Revision 1.26 2001/11/05 21:41:43 steudten
348 * Add changes to be a real daemon just for unix os.
349 * (change cwd to /, detach from controlling tty, set
350 * process group and session leader to the own process.
352 * Add some fatal-error log message for failed malloc().
353 * Add '-d' if compiled with 'configure --with-debug' to
354 * enable debug output.
356 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
357 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
358 * threads to call select() simultaneously. So, it's time to do a real, live,
359 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
360 * (native). Both versions will work, but using __OS2__ offers multi-threading.
362 * Revision 1.24 2001/10/23 21:40:30 jongfoster
363 * Added support for enable-edit-actions and enable-remote-toggle config
366 * Revision 1.23 2001/10/07 15:36:00 oes
367 * Introduced new config option "buffer-limit"
369 * Revision 1.22 2001/09/22 16:36:59 jongfoster
370 * Removing unused parameter fs from read_config_line()
372 * Revision 1.21 2001/09/16 17:10:43 jongfoster
373 * Moving function savearg() here, since it was the only thing left in
376 * Revision 1.20 2001/07/30 22:08:36 jongfoster
377 * Tidying up #defines:
378 * - All feature #defines are now of the form FEATURE_xxx
379 * - Permanently turned off WIN_GUI_EDIT
380 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
382 * Revision 1.19 2001/07/15 17:45:16 jongfoster
383 * Removing some unused #includes
385 * Revision 1.18 2001/07/13 14:01:14 oes
386 * - Removed all #ifdef PCRS
387 * - Removed vim-settings
389 * Revision 1.17 2001/06/29 13:31:03 oes
390 * - Improved comments
391 * - Fixed (actionsfile) and sorted hashes
392 * - Introduced admin_address and proxy-info-url
393 * as config parameters
394 * - Renamed config->proxy_args_invocation (which didn't have
395 * the invocation but the options!) to config->proxy_args
396 * - Various adaptions
397 * - Removed logentry from cancelled commit
399 * Revision 1.16 2001/06/09 10:55:28 jongfoster
400 * Changing BUFSIZ ==> BUFFER_SIZE
402 * Revision 1.15 2001/06/07 23:13:40 jongfoster
403 * Merging ACL and forward files into config file.
404 * Cosmetic: Sorting config file options alphabetically.
405 * Cosmetic: Adding brief syntax comments to config file options.
407 * Revision 1.14 2001/06/07 14:46:25 joergs
408 * Missing make_path() added for re_filterfile.
410 * Revision 1.13 2001/06/05 22:33:54 jongfoster
412 * Fixed minor memory leak.
413 * Also now uses make_path to prepend the pathnames.
415 * Revision 1.12 2001/06/05 20:04:09 jongfoster
416 * Now uses _snprintf() in place of snprintf() under Win32.
418 * Revision 1.11 2001/06/04 18:31:58 swa
419 * files are now prefixed with either `confdir' or `logdir'.
420 * `make redhat-dist' replaces both entries confdir and logdir
423 * Revision 1.10 2001/06/03 19:11:54 oes
424 * introduced confdir option
426 * Revision 1.9 2001/06/01 20:06:24 jongfoster
427 * Removed support for "tinygif" option - moved to actions file.
429 * Revision 1.8 2001/05/31 21:27:13 jongfoster
430 * Removed many options from the config file and into the
431 * "actions" file: add_forwarded, suppress_vanilla_wafer,
432 * wafer, add_header, user_agent, referer, from
433 * Also globally replaced "permission" with "action".
435 * Revision 1.7 2001/05/29 09:50:24 jongfoster
436 * Unified blocklist/imagelist/permissionslist.
437 * File format is still under discussion, but the internal changes
440 * Also modified interceptor behaviour:
441 * - We now intercept all URLs beginning with one of the following
442 * prefixes (and *only* these prefixes):
444 * * http://ijbswa.sf.net/config/
445 * * http://ijbswa.sourceforge.net/config/
446 * - New interceptors "home page" - go to http://i.j.b/ to see it.
447 * - Internal changes so that intercepted and fast redirect pages
448 * are not replaced with an image.
449 * - Interceptors now have the option to send a binary page direct
450 * to the client. (i.e. ijb-send-banner uses this)
451 * - Implemented show-url-info interceptor. (Which is why I needed
452 * the above interceptors changes - a typical URL is
453 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
454 * The previous mechanism would not have intercepted that, and
455 * if it had been intercepted then it then it would have replaced
458 * Revision 1.6 2001/05/26 00:28:36 jongfoster
459 * Automatic reloading of config file.
460 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
461 * Most of the global variables have been moved to a new
462 * struct configuration_spec, accessed through csp->config->globalname
463 * Most of the globals remaining are used by the Win32 GUI.
465 * Revision 1.5 2001/05/25 22:34:30 jongfoster
468 * Revision 1.4 2001/05/22 18:46:04 oes
470 * - Enabled filtering banners by size rather than URL
471 * by adding patterns that replace all standard banner
472 * sizes with the "Junkbuster" gif to the re_filterfile
474 * - Enabled filtering WebBugs by providing a pattern
475 * which kills all 1x1 images
477 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
478 * which is selected by the (nonstandard and therefore
479 * capital) letter 'U' in the option string.
480 * It causes the quantifiers to be ungreedy by default.
481 * Appending a ? turns back to greedy (!).
483 * - Added a new interceptor ijb-send-banner, which
484 * sends back the "Junkbuster" gif. Without imagelist or
485 * MSIE detection support, or if tinygif = 1, or the
486 * URL isn't recognized as an imageurl, a lame HTML
487 * explanation is sent instead.
489 * - Added new feature, which permits blocking remote
490 * script redirects and firing back a local redirect
492 * The feature is conditionally compiled, i.e. it
493 * can be disabled with --disable-fast-redirects,
494 * plus it must be activated by a "fast-redirects"
495 * line in the config file, has its own log level
496 * and of course wants to be displayed by show-proxy-args
497 * Note: Boy, all the #ifdefs in 1001 locations and
498 * all the fumbling with configure.in and acconfig.h
499 * were *way* more work than the feature itself :-(
501 * - Because a generic redirect template was needed for
502 * this, tinygif = 3 now uses the same.
504 * - Moved GIFs, and other static HTTP response templates
509 * - Removed some >400 CRs again (Jon, you really worked
512 * Revision 1.3 2001/05/20 01:21:20 jongfoster
513 * Version 2.9.4 checkin.
514 * - Merged popupfile and cookiefile, and added control over PCRS
515 * filtering, in new "permissionsfile".
516 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
517 * file error you now get a message box (in the Win32 GUI) rather
518 * than the program exiting with no explanation.
519 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
521 * - Removed tabs from "config"
522 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
523 * - Bumped up version number.
525 * Revision 1.2 2001/05/17 23:01:01 oes
526 * - Cleaned CRLF's from the sources and related files
528 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
529 * Initial import of version 2.9.3 source tree
532 *********************************************************************/
538 #include <sys/types.h>
552 # include <windows.h>
555 # ifndef _WIN_CONSOLE
557 # endif /* ndef _WIN_CONSOLE */
559 #else /* ifndef _WIN32 */
563 # include <sys/wait.h>
565 # include <sys/time.h>
566 # include <sys/stat.h>
576 #include "miscutil.h"
580 #include "urlmatch.h"
584 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
587 * Fix a problem with Solaris. There should be no effect on other
589 * Solaris's isspace() is a macro which uses it's argument directly
590 * as an array index. Therefore we need to make sure that high-bit
591 * characters generate +ve values, and ideally we also want to make
592 * the argument match the declared parameter type of "int".
594 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
595 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
597 #ifdef FEATURE_TOGGLE
598 /* Privoxy is enabled by default. */
599 int global_toggle_state = 1;
600 #endif /* def FEATURE_TOGGLE */
602 /* The filename of the configfile */
603 const char *configfile = NULL;
606 * CGI functions will later need access to the invocation args,
607 * so we will make argc and argv global.
610 const char **Argv = NULL;
612 static struct file_list *current_configfile = NULL;
616 * This takes the "cryptic" hash of each keyword and aliases them to
617 * something a little more readable. This also makes changing the
618 * hash values easier if they should change or the hash algorthm changes.
619 * Use the included "hash" program to find out what the hash will be
620 * for any string supplied on the command line. (Or just put it in the
621 * config file and read the number from the error message in the log).
623 * Please keep this list sorted alphabetically (but with the Windows
624 * console and GUI specific options last).
627 #define hash_actions_file 1196306641ul /* "actionsfile" */
628 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
629 #define hash_admin_address 4112573064ul /* "admin-address" */
630 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
631 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
632 #define hash_confdir 1978389ul /* "confdir" */
633 #define hash_debug 78263ul /* "debug" */
634 #define hash_deny_access 1227333715ul /* "deny-access" */
635 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
636 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
637 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
638 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
639 #define hash_filterfile 250887266ul /* "filterfile" */
640 #define hash_forward 2029845ul /* "forward" */
641 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
642 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
643 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
644 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
645 #define hash_hostname 10308071ul /* "hostname" */
646 #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */
647 #define hash_listen_address 1255650842ul /* "listen-address" */
648 #define hash_logdir 422889ul /* "logdir" */
649 #define hash_logfile 2114766ul /* "logfile" */
650 #define hash_max_client_connections 3595884446ul /* "max-client-connections" */
651 #define hash_permit_access 3587953268ul /* "permit-access" */
652 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
653 #define hash_single_threaded 4250084780ul /* "single-threaded" */
654 #define hash_socket_timeout 1809001761ul /* "socket-timeout" */
655 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
656 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
657 #define hash_templdir 11067889ul /* "templdir" */
658 #define hash_toggle 447966ul /* "toggle" */
659 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
660 #define hash_trustfile 56494766ul /* "trustfile" */
661 #define hash_usermanual 1416668518ul /* "user-manual" */
662 #define hash_activity_animation 1817904738ul /* "activity-animation" */
663 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
664 #define hash_hide_console 2048809870ul /* "hide-console" */
665 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
666 #define hash_log_font_name 2866730124ul /* "log-font-name" */
667 #define hash_log_font_size 2866731014ul /* "log-font-size" */
668 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
669 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
670 #define hash_log_messages 2291744899ul /* "log-messages" */
671 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
674 static void savearg(char *command, char *argument, struct configuration_spec * config);
676 /*********************************************************************
678 * Function : unload_configfile
680 * Description : Free the config structure and all components.
683 * 1 : data: struct configuration_spec to unload
687 *********************************************************************/
688 static void unload_configfile (void * data)
690 struct configuration_spec * config = (struct configuration_spec *)data;
691 struct forward_spec *cur_fwd = config->forward;
695 struct access_control_list *cur_acl = config->acl;
697 while (cur_acl != NULL)
699 struct access_control_list * next_acl = cur_acl->next;
704 #endif /* def FEATURE_ACL */
706 while (cur_fwd != NULL)
708 struct forward_spec * next_fwd = cur_fwd->next;
709 free_url_spec(cur_fwd->url);
711 freez(cur_fwd->gateway_host);
712 freez(cur_fwd->forward_host);
716 config->forward = NULL;
718 freez(config->confdir);
719 freez(config->logdir);
720 freez(config->templdir);
721 freez(config->hostname);
723 freez(config->haddr);
724 freez(config->logfile);
726 for (i = 0; i < MAX_AF_FILES; i++)
728 freez(config->actions_file_short[i]);
729 freez(config->actions_file[i]);
730 freez(config->re_filterfile_short[i]);
731 freez(config->re_filterfile[i]);
734 freez(config->admin_address);
735 freez(config->proxy_info_url);
736 freez(config->proxy_args);
737 freez(config->usermanual);
740 freez(config->trustfile);
741 list_remove_all(config->trust_info);
742 #endif /* def FEATURE_TRUST */
744 for (i = 0; i < MAX_AF_FILES; i++)
746 freez(config->re_filterfile[i]);
753 #ifdef FEATURE_GRACEFUL_TERMINATION
754 /*********************************************************************
756 * Function : unload_current_config_file
758 * Description : Unloads current config file - reset to state at
759 * beginning of program.
765 *********************************************************************/
766 void unload_current_config_file(void)
768 if (current_configfile)
770 current_configfile->unloader = unload_configfile;
771 current_configfile = NULL;
777 /*********************************************************************
779 * Function : load_config
781 * Description : Load the config file and all parameters.
783 * XXX: more than thousand lines long
784 * and thus in serious need of refactoring.
788 * Returns : The configuration_spec, or NULL on error.
790 *********************************************************************/
791 struct configuration_spec * load_config(void)
793 char buf[BUFFER_SIZE];
795 FILE *configfp = NULL;
796 struct configuration_spec * config = NULL;
797 struct client_state * fake_csp;
798 struct file_list *fs;
799 unsigned long linenum = 0;
801 char *logfile = NULL;
802 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
803 int keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
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 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
859 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
860 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
862 configfp = fopen(configfile, "r");
863 if (NULL == configfp)
865 log_error(LOG_LEVEL_FATAL,
866 "can't open configuration file '%s': %E", configfile);
867 /* Never get here - LOG_LEVEL_FATAL causes program exit */
870 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
872 char cmd[BUFFER_SIZE];
873 char arg[BUFFER_SIZE];
874 char tmp[BUFFER_SIZE];
876 struct access_control_list *cur_acl;
877 #endif /* def FEATURE_ACL */
878 struct forward_spec *cur_fwd;
881 unsigned long directive_hash;
883 strlcpy(tmp, buf, sizeof(tmp));
885 /* Copy command (i.e. up to space or tab) into cmd */
888 while (*p && (*p != ' ') && (*p != '\t'))
894 /* Skip over the whitespace in buf */
895 while (*p && ((*p == ' ') || (*p == '\t')))
900 /* Copy the argument into arg */
901 strlcpy(arg, p, sizeof(arg));
903 /* Should never happen, but check this anyway */
909 /* Make sure the command field is lower case */
910 for (p = cmd; *p; p++)
914 *p = (char)ijb_tolower(*p);
918 directive_hash = hash_string(cmd);
919 switch (directive_hash)
921 /* *************************************************************************
922 * actionsfile actions-file-name
923 * In confdir by default
924 * *************************************************************************/
925 case hash_actions_file :
927 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
932 if (i >= MAX_AF_FILES)
934 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
935 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
938 config->actions_file_short[i] = strdup(arg);
939 config->actions_file[i] = make_path(config->confdir, arg);
942 /* *************************************************************************
943 * accept-intercepted-requests
944 * *************************************************************************/
945 case hash_accept_intercepted_requests:
946 if ((*arg != '\0') && (0 != atoi(arg)))
948 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
952 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
956 /* *************************************************************************
957 * admin-address email-address
958 * *************************************************************************/
959 case hash_admin_address :
960 freez(config->admin_address);
961 config->admin_address = strdup(arg);
964 /* *************************************************************************
965 * allow-cgi-request-crunching
966 * *************************************************************************/
967 case hash_allow_cgi_request_crunching:
968 if ((*arg != '\0') && (0 != atoi(arg)))
970 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
974 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
978 /* *************************************************************************
980 * *************************************************************************/
981 case hash_buffer_limit :
982 config->buffer_limit = (size_t)(1024 * atoi(arg));
985 /* *************************************************************************
986 * confdir directory-name
987 * *************************************************************************/
989 freez(config->confdir);
990 config->confdir = make_path( NULL, arg);
993 /* *************************************************************************
995 * Specifies debug level, multiple values are ORed together.
996 * *************************************************************************/
998 config->debug |= atoi(arg);
1001 /* *************************************************************************
1002 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1003 * *************************************************************************/
1005 case hash_deny_access:
1006 strlcpy(tmp, arg, sizeof(tmp));
1007 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1009 if ((vec_count != 1) && (vec_count != 2))
1011 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1012 "deny-access directive in configuration file.");
1013 string_append(&config->proxy_args,
1014 "<br>\nWARNING: Wrong number of parameters for "
1015 "deny-access directive in configuration file.<br><br>\n");
1019 /* allocate a new node */
1020 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1022 if (cur_acl == NULL)
1024 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1025 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1028 cur_acl->action = ACL_DENY;
1030 if (acl_addr(vec[0], cur_acl->src) < 0)
1032 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1033 "for deny-access directive in configuration file: \"%s\"", vec[0]);
1034 string_append(&config->proxy_args,
1035 "<br>\nWARNING: Invalid source address, port or netmask "
1036 "for deny-access directive in configuration file: \"");
1037 string_append(&config->proxy_args,
1039 string_append(&config->proxy_args,
1046 if (acl_addr(vec[1], cur_acl->dst) < 0)
1048 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1049 "for deny-access directive in configuration file: \"%s\"", vec[1]);
1050 string_append(&config->proxy_args,
1051 "<br>\nWARNING: Invalid destination address, port or netmask "
1052 "for deny-access directive in configuration file: \"");
1053 string_append(&config->proxy_args,
1055 string_append(&config->proxy_args,
1064 cur_acl->wildcard_dst = 1;
1066 #endif /* def HAVE_RFC2553 */
1069 * Add it to the list. Note we reverse the list to get the
1070 * behaviour the user expects. With both the ACL and
1071 * actions file, the last match wins. However, the internal
1072 * implementations are different: The actions file is stored
1073 * in the same order as the file, and scanned completely.
1074 * With the ACL, we reverse the order as we load it, then
1075 * when we scan it we stop as soon as we get a match.
1077 cur_acl->next = config->acl;
1078 config->acl = cur_acl;
1081 #endif /* def FEATURE_ACL */
1083 /* *************************************************************************
1084 * enable-edit-actions 0|1
1085 * *************************************************************************/
1086 #ifdef FEATURE_CGI_EDIT_ACTIONS
1087 case hash_enable_edit_actions:
1088 if ((*arg != '\0') && (0 != atoi(arg)))
1090 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1094 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1097 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1099 /* *************************************************************************
1100 * enable-remote-toggle 0|1
1101 * *************************************************************************/
1102 #ifdef FEATURE_TOGGLE
1103 case hash_enable_remote_toggle:
1104 if ((*arg != '\0') && (0 != atoi(arg)))
1106 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1110 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1113 #endif /* def FEATURE_TOGGLE */
1115 /* *************************************************************************
1116 * enable-remote-http-toggle 0|1
1117 * *************************************************************************/
1118 case hash_enable_remote_http_toggle:
1119 if ((*arg != '\0') && (0 != atoi(arg)))
1121 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1125 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1129 /* *************************************************************************
1130 * enforce-blocks 0|1
1131 * *************************************************************************/
1132 case hash_enforce_blocks:
1133 #ifdef FEATURE_FORCE_LOAD
1134 if ((*arg != '\0') && (0 != atoi(arg)))
1136 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1140 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1143 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1144 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1145 #endif /* def FEATURE_FORCE_LOAD */
1148 /* *************************************************************************
1149 * filterfile file-name
1150 * In confdir by default.
1151 * *************************************************************************/
1152 case hash_filterfile :
1154 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1159 if (i >= MAX_AF_FILES)
1161 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1162 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1165 config->re_filterfile_short[i] = strdup(arg);
1166 config->re_filterfile[i] = make_path(config->confdir, arg);
1170 /* *************************************************************************
1171 * forward url-pattern (.|http-proxy-host[:port])
1172 * *************************************************************************/
1174 strlcpy(tmp, arg, sizeof(tmp));
1175 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1179 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1180 "directive in configuration file.");
1181 string_append(&config->proxy_args,
1182 "<br>\nWARNING: Wrong number of parameters for "
1183 "forward directive in configuration file.");
1187 /* allocate a new node */
1188 cur_fwd = zalloc(sizeof(*cur_fwd));
1189 if (cur_fwd == NULL)
1191 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1192 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1196 cur_fwd->type = SOCKS_NONE;
1198 /* Save the URL pattern */
1199 if (create_url_spec(cur_fwd->url, vec[0]))
1201 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1202 "directive in configuration file.");
1203 string_append(&config->proxy_args,
1204 "<br>\nWARNING: Bad URL specifier for "
1205 "forward directive in configuration file.");
1209 /* Parse the parent HTTP proxy host:port */
1212 if (strcmp(p, ".") != 0)
1214 cur_fwd->forward_port = 8000;
1215 parse_forwarder_address(p, &cur_fwd->forward_host,
1216 &cur_fwd->forward_port);
1220 cur_fwd->next = config->forward;
1221 config->forward = cur_fwd;
1225 /* *************************************************************************
1226 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1227 * *************************************************************************/
1228 case hash_forward_socks4:
1229 strlcpy(tmp, arg, sizeof(tmp));
1230 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1234 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1235 "forward-socks4 directive in configuration file.");
1236 string_append(&config->proxy_args,
1237 "<br>\nWARNING: Wrong number of parameters for "
1238 "forward-socks4 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 cur_fwd->type = SOCKS_4;
1253 /* Save the URL pattern */
1254 if (create_url_spec(cur_fwd->url, vec[0]))
1256 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1257 "directive in configuration file.");
1258 string_append(&config->proxy_args,
1259 "<br>\nWARNING: Bad URL specifier for "
1260 "forward-socks4 directive in configuration file.");
1264 /* Parse the SOCKS proxy host[:port] */
1267 /* XXX: This check looks like a bug. */
1268 if (strcmp(p, ".") != 0)
1270 cur_fwd->gateway_port = 1080;
1271 parse_forwarder_address(p, &cur_fwd->gateway_host,
1272 &cur_fwd->gateway_port);
1275 /* Parse the parent HTTP proxy host[:port] */
1278 if (strcmp(p, ".") != 0)
1280 cur_fwd->forward_port = 8000;
1281 parse_forwarder_address(p, &cur_fwd->forward_host,
1282 &cur_fwd->forward_port);
1286 cur_fwd->next = config->forward;
1287 config->forward = cur_fwd;
1291 /* *************************************************************************
1292 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1293 * *************************************************************************/
1294 case hash_forward_socks4a:
1295 case hash_forward_socks5:
1296 strlcpy(tmp, arg, sizeof(tmp));
1297 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1301 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1302 "forward-socks4a directive in configuration file.");
1303 string_append(&config->proxy_args,
1304 "<br>\nWARNING: Wrong number of parameters for "
1305 "forward-socks4a directive in configuration file.");
1309 /* allocate a new node */
1310 cur_fwd = zalloc(sizeof(*cur_fwd));
1311 if (cur_fwd == NULL)
1313 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1314 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1318 if (directive_hash == hash_forward_socks4a)
1320 cur_fwd->type = SOCKS_4A;
1324 cur_fwd->type = SOCKS_5;
1327 /* Save the URL pattern */
1328 if (create_url_spec(cur_fwd->url, vec[0]))
1330 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1331 "directive in configuration file.");
1332 string_append(&config->proxy_args,
1333 "<br>\nWARNING: Bad URL specifier for "
1334 "forward-socks4a directive in configuration file.");
1338 /* Parse the SOCKS proxy host[:port] */
1341 cur_fwd->gateway_port = 1080;
1342 parse_forwarder_address(p, &cur_fwd->gateway_host,
1343 &cur_fwd->gateway_port);
1345 /* Parse the parent HTTP proxy host[:port] */
1348 if (strcmp(p, ".") != 0)
1350 cur_fwd->forward_port = 8000;
1351 parse_forwarder_address(p, &cur_fwd->forward_host,
1352 &cur_fwd->forward_port);
1356 cur_fwd->next = config->forward;
1357 config->forward = cur_fwd;
1361 /* *************************************************************************
1362 * forwarded-connect-retries n
1363 * *************************************************************************/
1364 case hash_forwarded_connect_retries :
1365 config->forwarded_connect_retries = atoi(arg);
1368 /* *************************************************************************
1369 * hostname hostname-to-show-on-cgi-pages
1370 * *************************************************************************/
1371 case hash_hostname :
1372 freez(config->hostname);
1373 config->hostname = strdup(arg);
1374 if (NULL == config->hostname)
1376 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1380 /* *************************************************************************
1381 * keep-alive-timeout timeout
1382 * *************************************************************************/
1383 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1384 case hash_keep_alive_timeout :
1387 int timeout = atoi(arg);
1390 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1391 keep_alive_timeout = timeout;
1395 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1401 /* *************************************************************************
1402 * listen-address [ip][:port]
1403 * *************************************************************************/
1404 case hash_listen_address :
1405 freez(config->haddr);
1406 config->haddr = strdup(arg);
1409 /* *************************************************************************
1410 * logdir directory-name
1411 * *************************************************************************/
1413 freez(config->logdir);
1414 config->logdir = make_path(NULL, arg);
1417 /* *************************************************************************
1418 * logfile log-file-name
1419 * In logdir by default
1420 * *************************************************************************/
1424 logfile = make_path(config->logdir, arg);
1425 if (NULL == logfile)
1427 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1432 /* *************************************************************************
1433 * max-client-connections number
1434 * *************************************************************************/
1435 case hash_max_client_connections :
1438 int max_client_connections = atoi(arg);
1439 if (0 <= max_client_connections)
1441 config->max_client_connections = max_client_connections;
1446 /* *************************************************************************
1447 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1448 * *************************************************************************/
1450 case hash_permit_access:
1451 strlcpy(tmp, arg, sizeof(tmp));
1452 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1454 if ((vec_count != 1) && (vec_count != 2))
1456 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1457 "permit-access directive in configuration file.");
1458 string_append(&config->proxy_args,
1459 "<br>\nWARNING: Wrong number of parameters for "
1460 "permit-access directive in configuration file.<br><br>\n");
1465 /* allocate a new node */
1466 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1468 if (cur_acl == NULL)
1470 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1471 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1474 cur_acl->action = ACL_PERMIT;
1476 if (acl_addr(vec[0], cur_acl->src) < 0)
1478 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1479 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1480 string_append(&config->proxy_args,
1481 "<br>\nWARNING: Invalid source address, port or netmask for "
1482 "permit-access directive in configuration file: \"");
1483 string_append(&config->proxy_args,
1485 string_append(&config->proxy_args,
1492 if (acl_addr(vec[1], cur_acl->dst) < 0)
1494 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1495 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1496 string_append(&config->proxy_args,
1497 "<br>\nWARNING: Invalid destination address, port or netmask for "
1498 "permit-access directive in configuration file: \"");
1499 string_append(&config->proxy_args,
1501 string_append(&config->proxy_args,
1510 cur_acl->wildcard_dst = 1;
1512 #endif /* def HAVE_RFC2553 */
1515 * Add it to the list. Note we reverse the list to get the
1516 * behaviour the user expects. With both the ACL and
1517 * actions file, the last match wins. However, the internal
1518 * implementations are different: The actions file is stored
1519 * in the same order as the file, and scanned completely.
1520 * With the ACL, we reverse the order as we load it, then
1521 * when we scan it we stop as soon as we get a match.
1523 cur_acl->next = config->acl;
1524 config->acl = cur_acl;
1527 #endif /* def FEATURE_ACL */
1529 /* *************************************************************************
1530 * proxy-info-url url
1531 * *************************************************************************/
1532 case hash_proxy_info_url :
1533 freez(config->proxy_info_url);
1534 config->proxy_info_url = strdup(arg);
1537 /* *************************************************************************
1539 * *************************************************************************/
1540 case hash_single_threaded :
1541 config->multi_threaded = 0;
1544 /* *************************************************************************
1545 * socket-timeout numer_of_seconds
1546 * *************************************************************************/
1547 case hash_socket_timeout :
1550 int socket_timeout = atoi(arg);
1551 if (0 < socket_timeout)
1553 config->socket_timeout = socket_timeout;
1557 log_error(LOG_LEVEL_FATAL,
1558 "Invalid socket-timeout: '%s'", arg);
1563 /* *************************************************************************
1564 * split-large-cgi-forms
1565 * *************************************************************************/
1566 case hash_split_large_cgi_forms :
1567 if ((*arg != '\0') && (0 != atoi(arg)))
1569 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1573 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1577 /* *************************************************************************
1578 * templdir directory-name
1579 * *************************************************************************/
1580 case hash_templdir :
1581 freez(config->templdir);
1582 config->templdir = make_path(NULL, arg);
1585 /* *************************************************************************
1587 * *************************************************************************/
1588 #ifdef FEATURE_TOGGLE
1590 global_toggle_state = atoi(arg);
1592 #endif /* def FEATURE_TOGGLE */
1594 /* *************************************************************************
1595 * trust-info-url url
1596 * *************************************************************************/
1597 #ifdef FEATURE_TRUST
1598 case hash_trust_info_url :
1599 enlist(config->trust_info, arg);
1601 #endif /* def FEATURE_TRUST */
1603 /* *************************************************************************
1604 * trustfile filename
1605 * (In confdir by default.)
1606 * *************************************************************************/
1607 #ifdef FEATURE_TRUST
1608 case hash_trustfile :
1609 freez(config->trustfile);
1610 config->trustfile = make_path(config->confdir, arg);
1612 #endif /* def FEATURE_TRUST */
1614 /* *************************************************************************
1616 * *************************************************************************/
1617 case hash_usermanual :
1619 * XXX: If this isn't the first config directive, the
1620 * show-status page links to the website documentation
1621 * for the directives that were already parsed. Lame.
1623 freez(config->usermanual);
1624 config->usermanual = strdup(arg);
1627 /* *************************************************************************
1628 * Win32 Console options:
1629 * *************************************************************************/
1631 /* *************************************************************************
1633 * *************************************************************************/
1635 case hash_hide_console :
1638 #endif /*def _WIN_CONSOLE*/
1641 /* *************************************************************************
1642 * Win32 GUI options:
1643 * *************************************************************************/
1645 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1646 /* *************************************************************************
1647 * activity-animation (0|1)
1648 * *************************************************************************/
1649 case hash_activity_animation :
1650 g_bShowActivityAnimation = atoi(arg);
1653 /* *************************************************************************
1654 * close-button-minimizes (0|1)
1655 * *************************************************************************/
1656 case hash_close_button_minimizes :
1657 g_bCloseHidesWindow = atoi(arg);
1660 /* *************************************************************************
1661 * log-buffer-size (0|1)
1662 * *************************************************************************/
1663 case hash_log_buffer_size :
1664 g_bLimitBufferSize = atoi(arg);
1667 /* *************************************************************************
1668 * log-font-name fontname
1669 * *************************************************************************/
1670 case hash_log_font_name :
1671 if (strlcpy(g_szFontFaceName, arg,
1672 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1674 log_error(LOG_LEVEL_FATAL,
1675 "log-font-name argument '%s' is longer than %u characters.",
1676 arg, sizeof(g_szFontFaceName)-1);
1680 /* *************************************************************************
1682 * *************************************************************************/
1683 case hash_log_font_size :
1684 g_nFontSize = atoi(arg);
1687 /* *************************************************************************
1688 * log-highlight-messages (0|1)
1689 * *************************************************************************/
1690 case hash_log_highlight_messages :
1691 g_bHighlightMessages = atoi(arg);
1694 /* *************************************************************************
1696 * *************************************************************************/
1697 case hash_log_max_lines :
1698 g_nMaxBufferLines = atoi(arg);
1701 /* *************************************************************************
1702 * log-messages (0|1)
1703 * *************************************************************************/
1704 case hash_log_messages :
1705 g_bLogMessages = atoi(arg);
1708 /* *************************************************************************
1709 * show-on-task-bar (0|1)
1710 * *************************************************************************/
1711 case hash_show_on_task_bar :
1712 g_bShowOnTaskBar = atoi(arg);
1715 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1718 /* *************************************************************************
1719 * Warnings about unsupported features
1720 * *************************************************************************/
1722 case hash_deny_access:
1723 #endif /* ndef FEATURE_ACL */
1724 #ifndef FEATURE_CGI_EDIT_ACTIONS
1725 case hash_enable_edit_actions:
1726 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1727 #ifndef FEATURE_TOGGLE
1728 case hash_enable_remote_toggle:
1729 #endif /* ndef FEATURE_TOGGLE */
1731 case hash_permit_access:
1732 #endif /* ndef FEATURE_ACL */
1733 #ifndef FEATURE_TOGGLE
1735 #endif /* ndef FEATURE_TOGGLE */
1736 #ifndef FEATURE_TRUST
1737 case hash_trustfile :
1738 case hash_trust_info_url :
1739 #endif /* ndef FEATURE_TRUST */
1741 #ifndef _WIN_CONSOLE
1742 case hash_hide_console :
1743 #endif /* ndef _WIN_CONSOLE */
1745 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1746 case hash_activity_animation :
1747 case hash_close_button_minimizes :
1748 case hash_log_buffer_size :
1749 case hash_log_font_name :
1750 case hash_log_font_size :
1751 case hash_log_highlight_messages :
1752 case hash_log_max_lines :
1753 case hash_log_messages :
1754 case hash_show_on_task_bar :
1755 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1756 /* These warnings are annoying - so hide them. -- Jon */
1757 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1760 /* *************************************************************************/
1762 /* *************************************************************************/
1764 * I decided that I liked this better as a warning than an
1765 * error. To change back to an error, just change log level
1766 * to LOG_LEVEL_FATAL.
1768 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1769 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1770 string_append(&config->proxy_args,
1771 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1774 /* *************************************************************************/
1775 } /* end switch( hash_string(cmd) ) */
1777 /* Save the argument for the show-status page. */
1778 savearg(cmd, arg, config);
1780 } /* end while ( read_config_line(...) ) */
1784 set_debug_level(config->debug);
1786 freez(config->logfile);
1790 if (NULL != logfile)
1792 config->logfile = logfile;
1793 init_error_log(Argv[0], config->logfile);
1801 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1802 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1804 if (config->multi_threaded)
1806 set_keep_alive_timeout(keep_alive_timeout);
1811 * While we could use keep-alive without multiple threads
1812 * if we didn't bother with enforcing the connection timeout,
1813 * that might make Tor users sad, even though they shouldn't
1814 * enable the single-threaded option anyway.
1816 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1817 log_error(LOG_LEVEL_ERROR,
1818 "Config option single-threaded disables connection keep-alive.");
1823 if (NULL == config->proxy_args)
1825 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1828 if (config->actions_file[0])
1830 add_loader(load_action_files, config);
1833 if (config->re_filterfile[0])
1835 add_loader(load_re_filterfiles, config);
1838 #ifdef FEATURE_TRUST
1839 if (config->trustfile)
1841 add_loader(load_trustfile, config);
1843 #endif /* def FEATURE_TRUST */
1845 if ( NULL == config->haddr )
1847 config->haddr = strdup( HADDR_DEFAULT );
1850 if ( NULL != config->haddr )
1852 if ((*config->haddr == '[')
1853 && (NULL != (p = strchr(config->haddr, ']')))
1855 && (0 < (config->hport = atoi(p + 2))))
1858 memmove((void *)config->haddr, config->haddr + 1,
1859 (size_t)(p - config->haddr));
1861 else if (NULL != (p = strchr(config->haddr, ':'))
1862 && (0 < (config->hport = atoi(p + 1))))
1868 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1869 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1871 if (*config->haddr == '\0')
1874 * Only the port specified. We stored it in config->hport
1875 * and don't need its text representation anymore.
1877 freez(config->haddr);
1882 * Want to run all the loaders once now.
1884 * Need to set up a fake csp, so they can get to the config.
1886 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1887 fake_csp->config = config;
1889 if (run_loader(fake_csp))
1892 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1893 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1897 /* FIXME: this is a kludge for win32 */
1898 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1900 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1901 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1902 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1904 #ifdef FEATURE_TRUST
1905 g_trustfile = config->trustfile;
1906 #endif /* def FEATURE_TRUST */
1909 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1910 /* FIXME: end kludge */
1913 config->need_bind = 1;
1915 if (current_configfile)
1917 struct configuration_spec * oldcfg = (struct configuration_spec *)
1918 current_configfile->f;
1920 * Check if config->haddr,hport == oldcfg->haddr,hport
1922 * The following could be written more compactly as a single,
1923 * (unreadably long) if statement.
1925 config->need_bind = 0;
1926 if (config->hport != oldcfg->hport)
1928 config->need_bind = 1;
1930 else if (config->haddr == NULL)
1932 if (oldcfg->haddr != NULL)
1934 config->need_bind = 1;
1937 else if (oldcfg->haddr == NULL)
1939 config->need_bind = 1;
1941 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1943 config->need_bind = 1;
1946 current_configfile->unloader = unload_configfile;
1949 fs->next = files->next;
1952 current_configfile = fs;
1958 /*********************************************************************
1960 * Function : savearg
1962 * Description : Called from `load_config'. It saves each non-empty
1963 * and non-comment line from config into
1964 * config->proxy_args. This is used to create the
1965 * show-proxy-args page. On error, frees
1966 * config->proxy_args and sets it to NULL
1969 * 1 : command = config setting that was found
1970 * 2 : argument = the setting's argument (if any)
1971 * 3 : config = Configuration to save into.
1975 *********************************************************************/
1976 static void savearg(char *command, char *argument, struct configuration_spec * config)
1985 * Add config option name embedded in
1986 * link to its section in the user-manual
1988 buf = strdup("\n<a href=\"");
1989 if (!strncmpic(config->usermanual, "file://", 7) ||
1990 !strncmpic(config->usermanual, "http", 4))
1992 string_append(&buf, config->usermanual);
1996 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1998 string_append(&buf, CONFIG_HELP_PREFIX);
1999 string_join (&buf, string_toupper(command));
2000 string_append(&buf, "\">");
2001 string_append(&buf, command);
2002 string_append(&buf, "</a> ");
2006 freez(config->proxy_args);
2010 if ( (NULL != argument) && ('\0' != *argument) )
2012 s = html_encode(argument);
2016 freez(config->proxy_args);
2020 if (strncmpic(argument, "http://", 7) == 0)
2022 string_append(&buf, "<a href=\"");
2023 string_append(&buf, s);
2024 string_append(&buf, "\">");
2025 string_join (&buf, s);
2026 string_append(&buf, "</a>");
2030 string_join (&buf, s);
2034 string_append(&buf, "<br>");
2035 string_join(&config->proxy_args, buf);