1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.95 2009/04/17 11:34:34 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.95 2009/04/17 11:34:34 fabiankeil
39 * Style cosmetics for the IPv6 code.
41 * Revision 1.94 2009/04/17 11:27:49 fabiankeil
42 * Petr Pisar's privoxy-3.0.12-ipv6-3.diff.
44 * Revision 1.93 2009/03/18 21:46:26 fabiankeil
45 * Revert the last commit as there's a better way.
47 * Revision 1.92 2009/03/18 20:43:19 fabiankeil
48 * Don't enable LOG_LEVEL_INFO by default and don't apply the user's
49 * debug settings until the logfile has been opened (if there is one).
50 * Patch submitted by Roland in #2624120.
52 * Revision 1.91 2009/03/09 17:29:08 fabiankeil
53 * As of r1.88, the show-status page can use a single line for
54 * warnings about ignored directives and the names of the ignored
55 * directives themselves. Reminded by Lee, finally closes #1856559.
57 * Revision 1.90 2009/03/07 17:58:02 fabiankeil
58 * Fix two mingw32-only buffer overflows. Note that triggering
59 * them requires control over the configuration file in which
60 * case all bets are off anyway.
62 * Revision 1.89 2009/03/01 18:46:33 fabiankeil
63 * - Help clang understand that we aren't
64 * dereferencing NULL pointers here.
65 * - Some style fixes in the modified region.
67 * Revision 1.88 2009/02/28 10:57:10 fabiankeil
68 * Gimme a break or two. Don't let the show-status page
69 * link to the website documentation for the user-manual
72 * Revision 1.87 2009/02/15 07:56:13 fabiankeil
73 * Increase default socket timeout to 300 seconds.
75 * Revision 1.86 2009/02/08 19:18:57 fabiankeil
76 * Now that we have the match-all.action file, the other action
77 * files changed their position in config->actions_file[] back
78 * to the way it was before standard.action got removed and the
79 * changes from revision 1.84 have to be reverted.
81 * Revision 1.85 2009/01/22 12:06:26 fabiankeil
82 * Don't keep connections alive when running single-threaded.
84 * Revision 1.84 2009/01/14 16:14:36 fabiankeil
85 * Due to the standard.action file removal, the other action
86 * files changed their position in config->actions_file[].
87 * Update mingw32 kludge accordingly.
89 * Revision 1.83 2008/12/20 14:53:55 fabiankeil
90 * Add config option socket-timeout to control the time
91 * Privoxy waits for data to arrive on a socket. Useful
92 * in case of stale ssh tunnels or when fuzz-testing.
94 * Revision 1.82 2008/11/16 12:43:49 fabiankeil
95 * Turn keep-alive support into a runtime feature
96 * that is disabled by setting keep-alive-timeout
97 * to a negative value.
99 * Revision 1.81 2008/11/13 09:08:42 fabiankeil
100 * Add new config option: keep-alive-timeout.
102 * Revision 1.80 2008/08/31 15:59:03 fabiankeil
103 * There's no reason to let remote toggling support depend
104 * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
106 * Revision 1.79 2008/08/30 12:03:07 fabiankeil
107 * Remove FEATURE_COOKIE_JAR.
109 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
110 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
111 * disabled, log a message that blocks will always be enforced
112 * instead of complaining about an unrecognized directive.
113 * Reported by Pietro Leone.
115 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
116 * Reuse directive_hash and don't hash the same directive twice.
118 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
119 * - Merge three string_append() calls.
120 * - Remove useless assertion.
122 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
123 * Rename load_actions_file() and load_re_filterfile()
124 * as they load multiple files "now".
126 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
127 * Add hostname directive. Closes PR#1918189.
129 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
132 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
133 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
135 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
136 * Reword "unrecognized directive" warning, use better
137 * mark up and add a <br>. Fixes parts of #1856559.
139 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
140 * Plug memory leak if listen-address only specifies the port.
142 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
143 * Relocate daemon-mode-related log messages to make sure
144 * they aren't shown again in case of configuration reloads.
146 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
147 * Plug memory leak introduced with my last commit.
149 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
150 * When in daemon mode, close stderr after the configuration file has been
151 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
153 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
154 * #1763173 from Stefan Huehner: declare unload_configfile() static.
156 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
157 * As Hal noticed, checking dispatch_cgi() as the last cruncher
158 * looks like a bug if CGI requests are blocked unintentionally,
159 * so don't do it unless the user enabled the new config option
160 * "allow-cgi-request-crunching".
162 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
163 * - Use strlcpy() instead of strcpy().
164 * - Stop treating actions files special. Expect a complete file name
165 * (with or without path) like it's done for the rest of the files.
167 * - Remove an unnecessary temporary memory allocation.
168 * - Don't log anything to the console when running as
169 * daemon and no errors occurred.
171 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
172 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
174 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
175 * New config option: enforce-blocks.
177 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
178 * - Mention other reasons why acl directive loading might have failed.
179 * - Don't log the acl source if the acl destination is to blame.
181 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
182 * Add new config option "templdir" to
183 * change the templates directory.
185 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
186 * Added config option accept-intercepted-requests
187 * and disabled it by default.
189 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
190 * Fix gcc43 compiler warnings.
192 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
193 * Add config option "split-large-forms"
194 * to work around the browser bug reported
197 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
198 * Move the <br> in the generated HTML for the config
199 * options from the beginning of the string to its end.
200 * Keeps the white space in balance.
202 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
203 * Fix memory leak in case of config file reloads.
205 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
206 * Modified kludge for win32 to make ming32 menu
207 * "Options/Edit Filters" (sort of) work again.
208 * Same limitations as for the action files apply.
211 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
212 * Incorporate modified version of Roland Rosenfeld's patch to
213 * optionally access the user-manual via Privoxy. Closes patch 679075.
215 * Formatting changed to Privoxy style, added call to
216 * cgi_error_no_template if the requested file doesn't
217 * exist and modified check whether or not Privoxy itself
218 * should serve the manual. Should work cross-platform now.
220 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
221 * Added config option enable-remote-http-toggle
222 * to specify if Privoxy should recognize special
223 * headers (currently only X-Filter) to change its
224 * behaviour. Disabled by default.
226 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
227 * Make number of retries in case of forwarded-connect problems
228 * a config file option (forwarded-connect-retries) and use 0 as
231 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
232 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
233 * with what was really the latest development (the v_3_0_branch branch)
235 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
236 * Don't forget to malloc space for the null terminator...
238 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
239 * Multiple filter file support
241 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
242 * Closed two memory leaks; hopefully the last remaining ones
243 * (in the main execution paths, anyway).
245 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
246 * Addressed bug #719435
247 * - Extraneous filterfile directives now logged as errors
248 * - This and unrecnonised directives now really obvious on status page
250 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
251 * Cosmetic: Renamed cryptic variable
253 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
254 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
256 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
257 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
259 * Revision 1.48 2002/05/14 21:30:38 oes
260 * savearg now uses own linking code instead of (now special-cased) add_help_link
262 * Revision 1.47 2002/05/12 21:36:29 jongfoster
263 * Correcting function comments
265 * Revision 1.46 2002/04/26 12:55:14 oes
266 * - New option "user-manual", defaults to our site
267 * via project.h #define
268 * - savearg now embeds option names in help links
270 * Revision 1.45 2002/04/24 02:11:54 oes
271 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
273 * Revision 1.44 2002/04/08 20:37:13 swa
276 * Revision 1.43 2002/04/08 20:36:50 swa
279 * Revision 1.42 2002/04/05 15:50:15 oes
280 * fix for invalid HTML proxy_args
282 * Revision 1.41 2002/03/31 17:19:00 jongfoster
283 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
285 * Revision 1.40 2002/03/26 22:29:55 swa
286 * we have a new homepage!
288 * Revision 1.39 2002/03/24 13:25:43 swa
289 * name change related issues
291 * Revision 1.38 2002/03/24 13:05:48 jongfoster
292 * Renaming re_filterfile to filterfile
294 * Revision 1.37 2002/03/16 23:54:06 jongfoster
295 * Adding graceful termination feature, to help look for memory leaks.
296 * If you enable this (which, by design, has to be done by hand
297 * editing config.h) and then go to http://i.j.b/die, then the program
298 * will exit cleanly after the *next* request. It should free all the
299 * memory that was used.
301 * Revision 1.36 2002/03/13 00:27:05 jongfoster
304 * Revision 1.35 2002/03/07 03:52:44 oes
305 * Set logging to tty for --no-daemon mode
307 * Revision 1.34 2002/03/06 23:14:35 jongfoster
308 * Trivial cosmetic changes to make function comments easier to find.
310 * Revision 1.33 2002/03/05 04:52:42 oes
311 * Deleted non-errlog debugging code
313 * Revision 1.32 2002/03/04 18:24:53 oes
314 * Re-enabled output of unknown config directive hash
316 * Revision 1.31 2002/03/03 15:07:20 oes
317 * Re-enabled automatic config reloading
319 * Revision 1.30 2002/01/22 23:31:43 jongfoster
320 * Replacing strsav() with string_append()
322 * Revision 1.29 2002/01/17 21:02:30 jongfoster
323 * Moving all our URL and URL pattern parsing code to urlmatch.c.
325 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
327 * Revision 1.28 2001/12/30 14:07:32 steudten
328 * - Add signal handling (unix)
329 * - Add SIGHUP handler (unix)
330 * - Add creation of pidfile (unix)
331 * - Add action 'top' in rc file (RH)
332 * - Add entry 'SIGNALS' to manpage
333 * - Add exit message to logfile (unix)
335 * Revision 1.27 2001/11/07 00:02:13 steudten
336 * Add line number in error output for lineparsing for
337 * actionsfile and configfile.
338 * Special handling for CLF added.
340 * Revision 1.26 2001/11/05 21:41:43 steudten
341 * Add changes to be a real daemon just for unix os.
342 * (change cwd to /, detach from controlling tty, set
343 * process group and session leader to the own process.
345 * Add some fatal-error log message for failed malloc().
346 * Add '-d' if compiled with 'configure --with-debug' to
347 * enable debug output.
349 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
350 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
351 * threads to call select() simultaneously. So, it's time to do a real, live,
352 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
353 * (native). Both versions will work, but using __OS2__ offers multi-threading.
355 * Revision 1.24 2001/10/23 21:40:30 jongfoster
356 * Added support for enable-edit-actions and enable-remote-toggle config
359 * Revision 1.23 2001/10/07 15:36:00 oes
360 * Introduced new config option "buffer-limit"
362 * Revision 1.22 2001/09/22 16:36:59 jongfoster
363 * Removing unused parameter fs from read_config_line()
365 * Revision 1.21 2001/09/16 17:10:43 jongfoster
366 * Moving function savearg() here, since it was the only thing left in
369 * Revision 1.20 2001/07/30 22:08:36 jongfoster
370 * Tidying up #defines:
371 * - All feature #defines are now of the form FEATURE_xxx
372 * - Permanently turned off WIN_GUI_EDIT
373 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
375 * Revision 1.19 2001/07/15 17:45:16 jongfoster
376 * Removing some unused #includes
378 * Revision 1.18 2001/07/13 14:01:14 oes
379 * - Removed all #ifdef PCRS
380 * - Removed vim-settings
382 * Revision 1.17 2001/06/29 13:31:03 oes
383 * - Improved comments
384 * - Fixed (actionsfile) and sorted hashes
385 * - Introduced admin_address and proxy-info-url
386 * as config parameters
387 * - Renamed config->proxy_args_invocation (which didn't have
388 * the invocation but the options!) to config->proxy_args
389 * - Various adaptions
390 * - Removed logentry from cancelled commit
392 * Revision 1.16 2001/06/09 10:55:28 jongfoster
393 * Changing BUFSIZ ==> BUFFER_SIZE
395 * Revision 1.15 2001/06/07 23:13:40 jongfoster
396 * Merging ACL and forward files into config file.
397 * Cosmetic: Sorting config file options alphabetically.
398 * Cosmetic: Adding brief syntax comments to config file options.
400 * Revision 1.14 2001/06/07 14:46:25 joergs
401 * Missing make_path() added for re_filterfile.
403 * Revision 1.13 2001/06/05 22:33:54 jongfoster
405 * Fixed minor memory leak.
406 * Also now uses make_path to prepend the pathnames.
408 * Revision 1.12 2001/06/05 20:04:09 jongfoster
409 * Now uses _snprintf() in place of snprintf() under Win32.
411 * Revision 1.11 2001/06/04 18:31:58 swa
412 * files are now prefixed with either `confdir' or `logdir'.
413 * `make redhat-dist' replaces both entries confdir and logdir
416 * Revision 1.10 2001/06/03 19:11:54 oes
417 * introduced confdir option
419 * Revision 1.9 2001/06/01 20:06:24 jongfoster
420 * Removed support for "tinygif" option - moved to actions file.
422 * Revision 1.8 2001/05/31 21:27:13 jongfoster
423 * Removed many options from the config file and into the
424 * "actions" file: add_forwarded, suppress_vanilla_wafer,
425 * wafer, add_header, user_agent, referer, from
426 * Also globally replaced "permission" with "action".
428 * Revision 1.7 2001/05/29 09:50:24 jongfoster
429 * Unified blocklist/imagelist/permissionslist.
430 * File format is still under discussion, but the internal changes
433 * Also modified interceptor behaviour:
434 * - We now intercept all URLs beginning with one of the following
435 * prefixes (and *only* these prefixes):
437 * * http://ijbswa.sf.net/config/
438 * * http://ijbswa.sourceforge.net/config/
439 * - New interceptors "home page" - go to http://i.j.b/ to see it.
440 * - Internal changes so that intercepted and fast redirect pages
441 * are not replaced with an image.
442 * - Interceptors now have the option to send a binary page direct
443 * to the client. (i.e. ijb-send-banner uses this)
444 * - Implemented show-url-info interceptor. (Which is why I needed
445 * the above interceptors changes - a typical URL is
446 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
447 * The previous mechanism would not have intercepted that, and
448 * if it had been intercepted then it then it would have replaced
451 * Revision 1.6 2001/05/26 00:28:36 jongfoster
452 * Automatic reloading of config file.
453 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
454 * Most of the global variables have been moved to a new
455 * struct configuration_spec, accessed through csp->config->globalname
456 * Most of the globals remaining are used by the Win32 GUI.
458 * Revision 1.5 2001/05/25 22:34:30 jongfoster
461 * Revision 1.4 2001/05/22 18:46:04 oes
463 * - Enabled filtering banners by size rather than URL
464 * by adding patterns that replace all standard banner
465 * sizes with the "Junkbuster" gif to the re_filterfile
467 * - Enabled filtering WebBugs by providing a pattern
468 * which kills all 1x1 images
470 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
471 * which is selected by the (nonstandard and therefore
472 * capital) letter 'U' in the option string.
473 * It causes the quantifiers to be ungreedy by default.
474 * Appending a ? turns back to greedy (!).
476 * - Added a new interceptor ijb-send-banner, which
477 * sends back the "Junkbuster" gif. Without imagelist or
478 * MSIE detection support, or if tinygif = 1, or the
479 * URL isn't recognized as an imageurl, a lame HTML
480 * explanation is sent instead.
482 * - Added new feature, which permits blocking remote
483 * script redirects and firing back a local redirect
485 * The feature is conditionally compiled, i.e. it
486 * can be disabled with --disable-fast-redirects,
487 * plus it must be activated by a "fast-redirects"
488 * line in the config file, has its own log level
489 * and of course wants to be displayed by show-proxy-args
490 * Note: Boy, all the #ifdefs in 1001 locations and
491 * all the fumbling with configure.in and acconfig.h
492 * were *way* more work than the feature itself :-(
494 * - Because a generic redirect template was needed for
495 * this, tinygif = 3 now uses the same.
497 * - Moved GIFs, and other static HTTP response templates
502 * - Removed some >400 CRs again (Jon, you really worked
505 * Revision 1.3 2001/05/20 01:21:20 jongfoster
506 * Version 2.9.4 checkin.
507 * - Merged popupfile and cookiefile, and added control over PCRS
508 * filtering, in new "permissionsfile".
509 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
510 * file error you now get a message box (in the Win32 GUI) rather
511 * than the program exiting with no explanation.
512 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
514 * - Removed tabs from "config"
515 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
516 * - Bumped up version number.
518 * Revision 1.2 2001/05/17 23:01:01 oes
519 * - Cleaned CRLF's from the sources and related files
521 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
522 * Initial import of version 2.9.3 source tree
525 *********************************************************************/
531 #include <sys/types.h>
545 # include <windows.h>
548 # ifndef _WIN_CONSOLE
550 # endif /* ndef _WIN_CONSOLE */
552 #else /* ifndef _WIN32 */
556 # include <sys/wait.h>
558 # include <sys/time.h>
559 # include <sys/stat.h>
569 #include "miscutil.h"
573 #include "urlmatch.h"
577 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
580 * Fix a problem with Solaris. There should be no effect on other
582 * Solaris's isspace() is a macro which uses it's argument directly
583 * as an array index. Therefore we need to make sure that high-bit
584 * characters generate +ve values, and ideally we also want to make
585 * the argument match the declared parameter type of "int".
587 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
588 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
590 #ifdef FEATURE_TOGGLE
591 /* Privoxy is enabled by default. */
592 int global_toggle_state = 1;
593 #endif /* def FEATURE_TOGGLE */
595 /* The filename of the configfile */
596 const char *configfile = NULL;
599 * CGI functions will later need access to the invocation args,
600 * so we will make argc and argv global.
603 const char **Argv = NULL;
605 static struct file_list *current_configfile = NULL;
609 * This takes the "cryptic" hash of each keyword and aliases them to
610 * something a little more readable. This also makes changing the
611 * hash values easier if they should change or the hash algorthm changes.
612 * Use the included "hash" program to find out what the hash will be
613 * for any string supplied on the command line. (Or just put it in the
614 * config file and read the number from the error message in the log).
616 * Please keep this list sorted alphabetically (but with the Windows
617 * console and GUI specific options last).
620 #define hash_actions_file 1196306641ul /* "actionsfile" */
621 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
622 #define hash_admin_address 4112573064ul /* "admin-address" */
623 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
624 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
625 #define hash_confdir 1978389ul /* "confdir" */
626 #define hash_debug 78263ul /* "debug" */
627 #define hash_deny_access 1227333715ul /* "deny-access" */
628 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
629 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
630 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
631 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
632 #define hash_filterfile 250887266ul /* "filterfile" */
633 #define hash_forward 2029845ul /* "forward" */
634 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
635 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
636 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
637 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
638 #define hash_hostname 10308071ul /* "hostname" */
639 #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */
640 #define hash_listen_address 1255650842ul /* "listen-address" */
641 #define hash_logdir 422889ul /* "logdir" */
642 #define hash_logfile 2114766ul /* "logfile" */
643 #define hash_permit_access 3587953268ul /* "permit-access" */
644 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
645 #define hash_single_threaded 4250084780ul /* "single-threaded" */
646 #define hash_socket_timeout 1809001761ul /* "socket-timeout" */
647 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
648 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
649 #define hash_templdir 11067889ul /* "templdir" */
650 #define hash_toggle 447966ul /* "toggle" */
651 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
652 #define hash_trustfile 56494766ul /* "trustfile" */
653 #define hash_usermanual 1416668518ul /* "user-manual" */
654 #define hash_activity_animation 1817904738ul /* "activity-animation" */
655 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
656 #define hash_hide_console 2048809870ul /* "hide-console" */
657 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
658 #define hash_log_font_name 2866730124ul /* "log-font-name" */
659 #define hash_log_font_size 2866731014ul /* "log-font-size" */
660 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
661 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
662 #define hash_log_messages 2291744899ul /* "log-messages" */
663 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
666 static void savearg(char *command, char *argument, struct configuration_spec * config);
668 /*********************************************************************
670 * Function : unload_configfile
672 * Description : Free the config structure and all components.
675 * 1 : data: struct configuration_spec to unload
679 *********************************************************************/
680 static void unload_configfile (void * data)
682 struct configuration_spec * config = (struct configuration_spec *)data;
683 struct forward_spec *cur_fwd = config->forward;
687 struct access_control_list *cur_acl = config->acl;
689 while (cur_acl != NULL)
691 struct access_control_list * next_acl = cur_acl->next;
696 #endif /* def FEATURE_ACL */
698 while (cur_fwd != NULL)
700 struct forward_spec * next_fwd = cur_fwd->next;
701 free_url_spec(cur_fwd->url);
703 freez(cur_fwd->gateway_host);
704 freez(cur_fwd->forward_host);
708 config->forward = NULL;
710 freez(config->confdir);
711 freez(config->logdir);
712 freez(config->templdir);
713 freez(config->hostname);
715 freez(config->haddr);
716 freez(config->logfile);
718 for (i = 0; i < MAX_AF_FILES; i++)
720 freez(config->actions_file_short[i]);
721 freez(config->actions_file[i]);
722 freez(config->re_filterfile_short[i]);
723 freez(config->re_filterfile[i]);
726 freez(config->admin_address);
727 freez(config->proxy_info_url);
728 freez(config->proxy_args);
729 freez(config->usermanual);
732 freez(config->trustfile);
733 list_remove_all(config->trust_info);
734 #endif /* def FEATURE_TRUST */
736 for (i = 0; i < MAX_AF_FILES; i++)
738 freez(config->re_filterfile[i]);
745 #ifdef FEATURE_GRACEFUL_TERMINATION
746 /*********************************************************************
748 * Function : unload_current_config_file
750 * Description : Unloads current config file - reset to state at
751 * beginning of program.
757 *********************************************************************/
758 void unload_current_config_file(void)
760 if (current_configfile)
762 current_configfile->unloader = unload_configfile;
763 current_configfile = NULL;
769 /*********************************************************************
771 * Function : load_config
773 * Description : Load the config file and all parameters.
775 * XXX: more than thousand lines long
776 * and thus in serious need of refactoring.
780 * Returns : The configuration_spec, or NULL on error.
782 *********************************************************************/
783 struct configuration_spec * load_config(void)
785 char buf[BUFFER_SIZE];
787 FILE *configfp = NULL;
788 struct configuration_spec * config = NULL;
789 struct client_state * fake_csp;
790 struct file_list *fs;
791 unsigned long linenum = 0;
793 char *logfile = NULL;
794 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
795 int keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
798 if (!check_file_changed(current_configfile, configfile, &fs))
800 /* No need to load */
801 return ((struct configuration_spec *)current_configfile->f);
805 log_error(LOG_LEVEL_FATAL,
806 "can't check configuration file '%s': %E", configfile);
810 if (NULL != current_configfile)
812 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
815 #ifdef FEATURE_TOGGLE
816 global_toggle_state = 1;
817 #endif /* def FEATURE_TOGGLE */
819 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
825 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
830 * This is backwards from how it's usually done.
831 * Following the usual pattern, "fs" would be stored in a member
832 * variable in "csp", and then we'd access "config" from "fs->f",
833 * using a cast. However, "config" is used so often that a
834 * cast each time would be very ugly, and the extra indirection
835 * would waste CPU cycles. Therefore we store "config" in
836 * "csp->config", and "fs" in "csp->config->config_file_list".
838 config->config_file_list = fs;
843 config->multi_threaded = 1;
844 config->buffer_limit = 4096 * 1024;
845 config->usermanual = strdup(USER_MANUAL_URL);
846 config->proxy_args = strdup("");
847 config->forwarded_connect_retries = 0;
848 config->socket_timeout = 300; /* XXX: Should be a macro. */
849 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
850 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
851 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
853 configfp = fopen(configfile, "r");
854 if (NULL == configfp)
856 log_error(LOG_LEVEL_FATAL,
857 "can't open configuration file '%s': %E", configfile);
858 /* Never get here - LOG_LEVEL_FATAL causes program exit */
861 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
863 char cmd[BUFFER_SIZE];
864 char arg[BUFFER_SIZE];
865 char tmp[BUFFER_SIZE];
867 struct access_control_list *cur_acl;
868 #endif /* def FEATURE_ACL */
869 struct forward_spec *cur_fwd;
872 unsigned long directive_hash;
874 strlcpy(tmp, buf, sizeof(tmp));
876 /* Copy command (i.e. up to space or tab) into cmd */
879 while (*p && (*p != ' ') && (*p != '\t'))
885 /* Skip over the whitespace in buf */
886 while (*p && ((*p == ' ') || (*p == '\t')))
891 /* Copy the argument into arg */
892 strlcpy(arg, p, sizeof(arg));
894 /* Should never happen, but check this anyway */
900 /* Make sure the command field is lower case */
901 for (p = cmd; *p; p++)
905 *p = (char)ijb_tolower(*p);
909 directive_hash = hash_string(cmd);
910 switch (directive_hash)
912 /* *************************************************************************
913 * actionsfile actions-file-name
914 * In confdir by default
915 * *************************************************************************/
916 case hash_actions_file :
918 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
923 if (i >= MAX_AF_FILES)
925 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
926 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
929 config->actions_file_short[i] = strdup(arg);
930 config->actions_file[i] = make_path(config->confdir, arg);
933 /* *************************************************************************
934 * accept-intercepted-requests
935 * *************************************************************************/
936 case hash_accept_intercepted_requests:
937 if ((*arg != '\0') && (0 != atoi(arg)))
939 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
943 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
947 /* *************************************************************************
948 * admin-address email-address
949 * *************************************************************************/
950 case hash_admin_address :
951 freez(config->admin_address);
952 config->admin_address = strdup(arg);
955 /* *************************************************************************
956 * allow-cgi-request-crunching
957 * *************************************************************************/
958 case hash_allow_cgi_request_crunching:
959 if ((*arg != '\0') && (0 != atoi(arg)))
961 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
965 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
969 /* *************************************************************************
971 * *************************************************************************/
972 case hash_buffer_limit :
973 config->buffer_limit = (size_t)(1024 * atoi(arg));
976 /* *************************************************************************
977 * confdir directory-name
978 * *************************************************************************/
980 freez(config->confdir);
981 config->confdir = make_path( NULL, arg);
984 /* *************************************************************************
986 * Specifies debug level, multiple values are ORed together.
987 * *************************************************************************/
989 config->debug |= atoi(arg);
992 /* *************************************************************************
993 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
994 * *************************************************************************/
996 case hash_deny_access:
997 strlcpy(tmp, arg, sizeof(tmp));
998 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1000 if ((vec_count != 1) && (vec_count != 2))
1002 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1003 "deny-access directive in configuration file.");
1004 string_append(&config->proxy_args,
1005 "<br>\nWARNING: Wrong number of parameters for "
1006 "deny-access directive in configuration file.<br><br>\n");
1010 /* allocate a new node */
1011 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1013 if (cur_acl == NULL)
1015 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1016 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1019 cur_acl->action = ACL_DENY;
1021 if (acl_addr(vec[0], cur_acl->src) < 0)
1023 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1024 "for deny-access directive in configuration file: \"%s\"", vec[0]);
1025 string_append(&config->proxy_args,
1026 "<br>\nWARNING: Invalid source address, port or netmask "
1027 "for deny-access directive in configuration file: \"");
1028 string_append(&config->proxy_args,
1030 string_append(&config->proxy_args,
1037 if (acl_addr(vec[1], cur_acl->dst) < 0)
1039 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1040 "for deny-access directive in configuration file: \"%s\"", vec[1]);
1041 string_append(&config->proxy_args,
1042 "<br>\nWARNING: Invalid destination address, port or netmask "
1043 "for deny-access directive in configuration file: \"");
1044 string_append(&config->proxy_args,
1046 string_append(&config->proxy_args,
1052 #ifdef HAVE_GETADDRINFO
1055 cur_acl->wildcard_dst = 1;
1057 #endif /* def HAVE_GETADDRINFO */
1060 * Add it to the list. Note we reverse the list to get the
1061 * behaviour the user expects. With both the ACL and
1062 * actions file, the last match wins. However, the internal
1063 * implementations are different: The actions file is stored
1064 * in the same order as the file, and scanned completely.
1065 * With the ACL, we reverse the order as we load it, then
1066 * when we scan it we stop as soon as we get a match.
1068 cur_acl->next = config->acl;
1069 config->acl = cur_acl;
1072 #endif /* def FEATURE_ACL */
1074 /* *************************************************************************
1075 * enable-edit-actions 0|1
1076 * *************************************************************************/
1077 #ifdef FEATURE_CGI_EDIT_ACTIONS
1078 case hash_enable_edit_actions:
1079 if ((*arg != '\0') && (0 != atoi(arg)))
1081 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1085 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1088 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1090 /* *************************************************************************
1091 * enable-remote-toggle 0|1
1092 * *************************************************************************/
1093 #ifdef FEATURE_TOGGLE
1094 case hash_enable_remote_toggle:
1095 if ((*arg != '\0') && (0 != atoi(arg)))
1097 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1101 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1104 #endif /* def FEATURE_TOGGLE */
1106 /* *************************************************************************
1107 * enable-remote-http-toggle 0|1
1108 * *************************************************************************/
1109 case hash_enable_remote_http_toggle:
1110 if ((*arg != '\0') && (0 != atoi(arg)))
1112 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1116 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1120 /* *************************************************************************
1121 * enforce-blocks 0|1
1122 * *************************************************************************/
1123 case hash_enforce_blocks:
1124 #ifdef FEATURE_FORCE_LOAD
1125 if ((*arg != '\0') && (0 != atoi(arg)))
1127 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1131 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1134 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1135 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1136 #endif /* def FEATURE_FORCE_LOAD */
1139 /* *************************************************************************
1140 * filterfile file-name
1141 * In confdir by default.
1142 * *************************************************************************/
1143 case hash_filterfile :
1145 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1150 if (i >= MAX_AF_FILES)
1152 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1153 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1156 config->re_filterfile_short[i] = strdup(arg);
1157 config->re_filterfile[i] = make_path(config->confdir, arg);
1161 /* *************************************************************************
1162 * forward url-pattern (.|http-proxy-host[:port])
1163 * *************************************************************************/
1165 strlcpy(tmp, arg, sizeof(tmp));
1166 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1170 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1171 "directive in configuration file.");
1172 string_append(&config->proxy_args,
1173 "<br>\nWARNING: Wrong number of parameters for "
1174 "forward directive in configuration file.");
1178 /* allocate a new node */
1179 cur_fwd = zalloc(sizeof(*cur_fwd));
1180 if (cur_fwd == NULL)
1182 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1183 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1187 cur_fwd->type = SOCKS_NONE;
1189 /* Save the URL pattern */
1190 if (create_url_spec(cur_fwd->url, vec[0]))
1192 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1193 "directive in configuration file.");
1194 string_append(&config->proxy_args,
1195 "<br>\nWARNING: Bad URL specifier for "
1196 "forward directive in configuration file.");
1200 /* Parse the parent HTTP proxy host:port */
1203 if (strcmp(p, ".") != 0)
1205 cur_fwd->forward_port = 8000;
1206 parse_forwarder_address(p, &cur_fwd->forward_host,
1207 &cur_fwd->forward_port);
1211 cur_fwd->next = config->forward;
1212 config->forward = cur_fwd;
1216 /* *************************************************************************
1217 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1218 * *************************************************************************/
1219 case hash_forward_socks4:
1220 strlcpy(tmp, arg, sizeof(tmp));
1221 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1225 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1226 "forward-socks4 directive in configuration file.");
1227 string_append(&config->proxy_args,
1228 "<br>\nWARNING: Wrong number of parameters for "
1229 "forward-socks4 directive in configuration file.");
1233 /* allocate a new node */
1234 cur_fwd = zalloc(sizeof(*cur_fwd));
1235 if (cur_fwd == NULL)
1237 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1238 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1242 cur_fwd->type = SOCKS_4;
1244 /* Save the URL pattern */
1245 if (create_url_spec(cur_fwd->url, vec[0]))
1247 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1248 "directive in configuration file.");
1249 string_append(&config->proxy_args,
1250 "<br>\nWARNING: Bad URL specifier for "
1251 "forward-socks4 directive in configuration file.");
1255 /* Parse the SOCKS proxy host[:port] */
1258 /* XXX: This check looks like a bug. */
1259 if (strcmp(p, ".") != 0)
1261 cur_fwd->gateway_port = 1080;
1262 parse_forwarder_address(p, &cur_fwd->gateway_host,
1263 &cur_fwd->gateway_port);
1266 /* Parse the parent HTTP proxy host[:port] */
1269 if (strcmp(p, ".") != 0)
1271 cur_fwd->forward_port = 8000;
1272 parse_forwarder_address(p, &cur_fwd->forward_host,
1273 &cur_fwd->forward_port);
1277 cur_fwd->next = config->forward;
1278 config->forward = cur_fwd;
1282 /* *************************************************************************
1283 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1284 * *************************************************************************/
1285 case hash_forward_socks4a:
1286 case hash_forward_socks5:
1287 strlcpy(tmp, arg, sizeof(tmp));
1288 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1292 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1293 "forward-socks4a directive in configuration file.");
1294 string_append(&config->proxy_args,
1295 "<br>\nWARNING: Wrong number of parameters for "
1296 "forward-socks4a directive in configuration file.");
1300 /* allocate a new node */
1301 cur_fwd = zalloc(sizeof(*cur_fwd));
1302 if (cur_fwd == NULL)
1304 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1305 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1309 if (directive_hash == hash_forward_socks4a)
1311 cur_fwd->type = SOCKS_4A;
1315 cur_fwd->type = SOCKS_5;
1318 /* Save the URL pattern */
1319 if (create_url_spec(cur_fwd->url, vec[0]))
1321 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1322 "directive in configuration file.");
1323 string_append(&config->proxy_args,
1324 "<br>\nWARNING: Bad URL specifier for "
1325 "forward-socks4a directive in configuration file.");
1329 /* Parse the SOCKS proxy host[:port] */
1332 cur_fwd->gateway_port = 1080;
1333 parse_forwarder_address(p, &cur_fwd->gateway_host,
1334 &cur_fwd->gateway_port);
1336 /* Parse the parent HTTP proxy host[:port] */
1339 if (strcmp(p, ".") != 0)
1341 cur_fwd->forward_port = 8000;
1342 parse_forwarder_address(p, &cur_fwd->forward_host,
1343 &cur_fwd->forward_port);
1347 cur_fwd->next = config->forward;
1348 config->forward = cur_fwd;
1352 /* *************************************************************************
1353 * forwarded-connect-retries n
1354 * *************************************************************************/
1355 case hash_forwarded_connect_retries :
1356 config->forwarded_connect_retries = atoi(arg);
1359 /* *************************************************************************
1360 * hostname hostname-to-show-on-cgi-pages
1361 * *************************************************************************/
1362 case hash_hostname :
1363 freez(config->hostname);
1364 config->hostname = strdup(arg);
1365 if (NULL == config->hostname)
1367 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1371 /* *************************************************************************
1372 * keep-alive-timeout timeout
1373 * *************************************************************************/
1374 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1375 case hash_keep_alive_timeout :
1378 int timeout = atoi(arg);
1381 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1382 keep_alive_timeout = timeout;
1386 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1392 /* *************************************************************************
1393 * listen-address [ip][:port]
1394 * *************************************************************************/
1395 case hash_listen_address :
1396 freez(config->haddr);
1397 config->haddr = strdup(arg);
1400 /* *************************************************************************
1401 * logdir directory-name
1402 * *************************************************************************/
1404 freez(config->logdir);
1405 config->logdir = make_path(NULL, arg);
1408 /* *************************************************************************
1409 * logfile log-file-name
1410 * In logdir by default
1411 * *************************************************************************/
1415 logfile = make_path(config->logdir, arg);
1416 if (NULL == logfile)
1418 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1423 /* *************************************************************************
1424 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1425 * *************************************************************************/
1427 case hash_permit_access:
1428 strlcpy(tmp, arg, sizeof(tmp));
1429 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1431 if ((vec_count != 1) && (vec_count != 2))
1433 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1434 "permit-access directive in configuration file.");
1435 string_append(&config->proxy_args,
1436 "<br>\nWARNING: Wrong number of parameters for "
1437 "permit-access directive in configuration file.<br><br>\n");
1442 /* allocate a new node */
1443 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1445 if (cur_acl == NULL)
1447 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1448 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1451 cur_acl->action = ACL_PERMIT;
1453 if (acl_addr(vec[0], cur_acl->src) < 0)
1455 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1456 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1457 string_append(&config->proxy_args,
1458 "<br>\nWARNING: Invalid source address, port or netmask for "
1459 "permit-access directive in configuration file: \"");
1460 string_append(&config->proxy_args,
1462 string_append(&config->proxy_args,
1469 if (acl_addr(vec[1], cur_acl->dst) < 0)
1471 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1472 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1473 string_append(&config->proxy_args,
1474 "<br>\nWARNING: Invalid destination address, port or netmask for "
1475 "permit-access directive in configuration file: \"");
1476 string_append(&config->proxy_args,
1478 string_append(&config->proxy_args,
1484 #ifdef HAVE_GETADDRINFO
1487 cur_acl->wildcard_dst = 1;
1489 #endif /* def HAVE_GETADDRINFO */
1492 * Add it to the list. Note we reverse the list to get the
1493 * behaviour the user expects. With both the ACL and
1494 * actions file, the last match wins. However, the internal
1495 * implementations are different: The actions file is stored
1496 * in the same order as the file, and scanned completely.
1497 * With the ACL, we reverse the order as we load it, then
1498 * when we scan it we stop as soon as we get a match.
1500 cur_acl->next = config->acl;
1501 config->acl = cur_acl;
1504 #endif /* def FEATURE_ACL */
1506 /* *************************************************************************
1507 * proxy-info-url url
1508 * *************************************************************************/
1509 case hash_proxy_info_url :
1510 freez(config->proxy_info_url);
1511 config->proxy_info_url = strdup(arg);
1514 /* *************************************************************************
1516 * *************************************************************************/
1517 case hash_single_threaded :
1518 config->multi_threaded = 0;
1521 /* *************************************************************************
1522 * socket-timeout numer_of_seconds
1523 * *************************************************************************/
1524 case hash_socket_timeout :
1527 int socket_timeout = atoi(arg);
1528 if (0 < socket_timeout)
1530 config->socket_timeout = socket_timeout;
1534 log_error(LOG_LEVEL_FATAL,
1535 "Invalid socket-timeout: '%s'", arg);
1540 /* *************************************************************************
1541 * split-large-cgi-forms
1542 * *************************************************************************/
1543 case hash_split_large_cgi_forms :
1544 if ((*arg != '\0') && (0 != atoi(arg)))
1546 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1550 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1554 /* *************************************************************************
1555 * templdir directory-name
1556 * *************************************************************************/
1557 case hash_templdir :
1558 freez(config->templdir);
1559 config->templdir = make_path(NULL, arg);
1562 /* *************************************************************************
1564 * *************************************************************************/
1565 #ifdef FEATURE_TOGGLE
1567 global_toggle_state = atoi(arg);
1569 #endif /* def FEATURE_TOGGLE */
1571 /* *************************************************************************
1572 * trust-info-url url
1573 * *************************************************************************/
1574 #ifdef FEATURE_TRUST
1575 case hash_trust_info_url :
1576 enlist(config->trust_info, arg);
1578 #endif /* def FEATURE_TRUST */
1580 /* *************************************************************************
1581 * trustfile filename
1582 * (In confdir by default.)
1583 * *************************************************************************/
1584 #ifdef FEATURE_TRUST
1585 case hash_trustfile :
1586 freez(config->trustfile);
1587 config->trustfile = make_path(config->confdir, arg);
1589 #endif /* def FEATURE_TRUST */
1591 /* *************************************************************************
1593 * *************************************************************************/
1594 case hash_usermanual :
1596 * XXX: If this isn't the first config directive, the
1597 * show-status page links to the website documentation
1598 * for the directives that were already parsed. Lame.
1600 freez(config->usermanual);
1601 config->usermanual = strdup(arg);
1604 /* *************************************************************************
1605 * Win32 Console options:
1606 * *************************************************************************/
1608 /* *************************************************************************
1610 * *************************************************************************/
1612 case hash_hide_console :
1615 #endif /*def _WIN_CONSOLE*/
1618 /* *************************************************************************
1619 * Win32 GUI options:
1620 * *************************************************************************/
1622 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1623 /* *************************************************************************
1624 * activity-animation (0|1)
1625 * *************************************************************************/
1626 case hash_activity_animation :
1627 g_bShowActivityAnimation = atoi(arg);
1630 /* *************************************************************************
1631 * close-button-minimizes (0|1)
1632 * *************************************************************************/
1633 case hash_close_button_minimizes :
1634 g_bCloseHidesWindow = atoi(arg);
1637 /* *************************************************************************
1638 * log-buffer-size (0|1)
1639 * *************************************************************************/
1640 case hash_log_buffer_size :
1641 g_bLimitBufferSize = atoi(arg);
1644 /* *************************************************************************
1645 * log-font-name fontname
1646 * *************************************************************************/
1647 case hash_log_font_name :
1648 if (strlcpy(g_szFontFaceName, arg,
1649 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1651 log_error(LOG_LEVEL_FATAL,
1652 "log-font-name argument '%s' is longer than %u characters.",
1653 arg, sizeof(g_szFontFaceName)-1);
1657 /* *************************************************************************
1659 * *************************************************************************/
1660 case hash_log_font_size :
1661 g_nFontSize = atoi(arg);
1664 /* *************************************************************************
1665 * log-highlight-messages (0|1)
1666 * *************************************************************************/
1667 case hash_log_highlight_messages :
1668 g_bHighlightMessages = atoi(arg);
1671 /* *************************************************************************
1673 * *************************************************************************/
1674 case hash_log_max_lines :
1675 g_nMaxBufferLines = atoi(arg);
1678 /* *************************************************************************
1679 * log-messages (0|1)
1680 * *************************************************************************/
1681 case hash_log_messages :
1682 g_bLogMessages = atoi(arg);
1685 /* *************************************************************************
1686 * show-on-task-bar (0|1)
1687 * *************************************************************************/
1688 case hash_show_on_task_bar :
1689 g_bShowOnTaskBar = atoi(arg);
1692 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1695 /* *************************************************************************
1696 * Warnings about unsupported features
1697 * *************************************************************************/
1699 case hash_deny_access:
1700 #endif /* ndef FEATURE_ACL */
1701 #ifndef FEATURE_CGI_EDIT_ACTIONS
1702 case hash_enable_edit_actions:
1703 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1704 #ifndef FEATURE_TOGGLE
1705 case hash_enable_remote_toggle:
1706 #endif /* ndef FEATURE_TOGGLE */
1708 case hash_permit_access:
1709 #endif /* ndef FEATURE_ACL */
1710 #ifndef FEATURE_TOGGLE
1712 #endif /* ndef FEATURE_TOGGLE */
1713 #ifndef FEATURE_TRUST
1714 case hash_trustfile :
1715 case hash_trust_info_url :
1716 #endif /* ndef FEATURE_TRUST */
1718 #ifndef _WIN_CONSOLE
1719 case hash_hide_console :
1720 #endif /* ndef _WIN_CONSOLE */
1722 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1723 case hash_activity_animation :
1724 case hash_close_button_minimizes :
1725 case hash_log_buffer_size :
1726 case hash_log_font_name :
1727 case hash_log_font_size :
1728 case hash_log_highlight_messages :
1729 case hash_log_max_lines :
1730 case hash_log_messages :
1731 case hash_show_on_task_bar :
1732 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1733 /* These warnings are annoying - so hide them. -- Jon */
1734 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1737 /* *************************************************************************/
1739 /* *************************************************************************/
1741 * I decided that I liked this better as a warning than an
1742 * error. To change back to an error, just change log level
1743 * to LOG_LEVEL_FATAL.
1745 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1746 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1747 string_append(&config->proxy_args,
1748 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1751 /* *************************************************************************/
1752 } /* end switch( hash_string(cmd) ) */
1754 /* Save the argument for the show-status page. */
1755 savearg(cmd, arg, config);
1757 } /* end while ( read_config_line(...) ) */
1761 set_debug_level(config->debug);
1763 freez(config->logfile);
1767 if (NULL != logfile)
1769 config->logfile = logfile;
1770 init_error_log(Argv[0], config->logfile);
1778 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1779 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1781 if (config->multi_threaded)
1783 set_keep_alive_timeout(keep_alive_timeout);
1788 * While we could use keep-alive without multiple threads
1789 * if we didn't bother with enforcing the connection timeout,
1790 * that might make Tor users sad, even though they shouldn't
1791 * enable the single-threaded option anyway.
1793 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1794 log_error(LOG_LEVEL_ERROR,
1795 "Config option single-threaded disables connection keep-alive.");
1800 if (NULL == config->proxy_args)
1802 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1805 if (config->actions_file[0])
1807 add_loader(load_action_files, config);
1810 if (config->re_filterfile[0])
1812 add_loader(load_re_filterfiles, config);
1815 #ifdef FEATURE_TRUST
1816 if (config->trustfile)
1818 add_loader(load_trustfile, config);
1820 #endif /* def FEATURE_TRUST */
1822 if ( NULL == config->haddr )
1824 config->haddr = strdup( HADDR_DEFAULT );
1827 if ( NULL != config->haddr )
1829 if ((*config->haddr == '[')
1830 && (NULL != (p = strchr(config->haddr, ']')))
1832 && (0 < (config->hport = atoi(p + 2))))
1835 memmove((void *)config->haddr, config->haddr + 1,
1836 (size_t)(p - config->haddr));
1838 else if (NULL != (p = strchr(config->haddr, ':'))
1839 && (0 < (config->hport = atoi(p + 1))))
1845 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1846 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1848 if (*config->haddr == '\0')
1851 * Only the port specified. We stored it in config->hport
1852 * and don't need its text representation anymore.
1854 freez(config->haddr);
1859 * Want to run all the loaders once now.
1861 * Need to set up a fake csp, so they can get to the config.
1863 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1864 fake_csp->config = config;
1866 if (run_loader(fake_csp))
1869 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1870 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1874 /* FIXME: this is a kludge for win32 */
1875 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1877 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1878 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1879 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1881 #ifdef FEATURE_TRUST
1882 g_trustfile = config->trustfile;
1883 #endif /* def FEATURE_TRUST */
1886 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1887 /* FIXME: end kludge */
1890 config->need_bind = 1;
1892 if (current_configfile)
1894 struct configuration_spec * oldcfg = (struct configuration_spec *)
1895 current_configfile->f;
1897 * Check if config->haddr,hport == oldcfg->haddr,hport
1899 * The following could be written more compactly as a single,
1900 * (unreadably long) if statement.
1902 config->need_bind = 0;
1903 if (config->hport != oldcfg->hport)
1905 config->need_bind = 1;
1907 else if (config->haddr == NULL)
1909 if (oldcfg->haddr != NULL)
1911 config->need_bind = 1;
1914 else if (oldcfg->haddr == NULL)
1916 config->need_bind = 1;
1918 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1920 config->need_bind = 1;
1923 current_configfile->unloader = unload_configfile;
1926 fs->next = files->next;
1929 current_configfile = fs;
1935 /*********************************************************************
1937 * Function : savearg
1939 * Description : Called from `load_config'. It saves each non-empty
1940 * and non-comment line from config into
1941 * config->proxy_args. This is used to create the
1942 * show-proxy-args page. On error, frees
1943 * config->proxy_args and sets it to NULL
1946 * 1 : command = config setting that was found
1947 * 2 : argument = the setting's argument (if any)
1948 * 3 : config = Configuration to save into.
1952 *********************************************************************/
1953 static void savearg(char *command, char *argument, struct configuration_spec * config)
1962 * Add config option name embedded in
1963 * link to its section in the user-manual
1965 buf = strdup("\n<a href=\"");
1966 if (!strncmpic(config->usermanual, "file://", 7) ||
1967 !strncmpic(config->usermanual, "http", 4))
1969 string_append(&buf, config->usermanual);
1973 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1975 string_append(&buf, CONFIG_HELP_PREFIX);
1976 string_join (&buf, string_toupper(command));
1977 string_append(&buf, "\">");
1978 string_append(&buf, command);
1979 string_append(&buf, "</a> ");
1983 freez(config->proxy_args);
1987 if ( (NULL != argument) && ('\0' != *argument) )
1989 s = html_encode(argument);
1993 freez(config->proxy_args);
1997 if (strncmpic(argument, "http://", 7) == 0)
1999 string_append(&buf, "<a href=\"");
2000 string_append(&buf, s);
2001 string_append(&buf, "\">");
2002 string_join (&buf, s);
2003 string_append(&buf, "</a>");
2007 string_join (&buf, s);
2011 string_append(&buf, "<br>");
2012 string_join(&config->proxy_args, buf);