1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.100 2009/05/10 10:19:23 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.100 2009/05/10 10:19:23 fabiankeil
39 * Reenable server-side-only keep-alive support, but only share
40 * outgoing connections if the connection-sharing option is set.
42 * Revision 1.99 2009/05/10 10:12:30 fabiankeil
43 * Initial keep-alive support for the client socket.
44 * Temporarily disable the server-side-only keep-alive code.
46 * Revision 1.98 2009/04/24 15:29:43 fabiankeil
47 * Allow to limit the number of of client connections.
49 * Revision 1.97 2009/04/17 11:45:19 fabiankeil
50 * Replace HAVE_GETADDRINFO and HAVE_GETNAMEINFO macros
51 * with HAVE_RFC2553 macro. Original patch by Petr Pisar.
53 * Revision 1.96 2009/04/17 11:38:28 fabiankeil
54 * Add and use parse_forwarder_address() to reduce code duplication.
56 * Revision 1.95 2009/04/17 11:34:34 fabiankeil
57 * Style cosmetics for the IPv6 code.
59 * Revision 1.94 2009/04/17 11:27:49 fabiankeil
60 * Petr Pisar's privoxy-3.0.12-ipv6-3.diff.
62 * Revision 1.93 2009/03/18 21:46:26 fabiankeil
63 * Revert the last commit as there's a better way.
65 * Revision 1.92 2009/03/18 20:43:19 fabiankeil
66 * Don't enable LOG_LEVEL_INFO by default and don't apply the user's
67 * debug settings until the logfile has been opened (if there is one).
68 * Patch submitted by Roland in #2624120.
70 * Revision 1.91 2009/03/09 17:29:08 fabiankeil
71 * As of r1.88, the show-status page can use a single line for
72 * warnings about ignored directives and the names of the ignored
73 * directives themselves. Reminded by Lee, finally closes #1856559.
75 * Revision 1.90 2009/03/07 17:58:02 fabiankeil
76 * Fix two mingw32-only buffer overflows. Note that triggering
77 * them requires control over the configuration file in which
78 * case all bets are off anyway.
80 * Revision 1.89 2009/03/01 18:46:33 fabiankeil
81 * - Help clang understand that we aren't
82 * dereferencing NULL pointers here.
83 * - Some style fixes in the modified region.
85 * Revision 1.88 2009/02/28 10:57:10 fabiankeil
86 * Gimme a break or two. Don't let the show-status page
87 * link to the website documentation for the user-manual
90 * Revision 1.87 2009/02/15 07:56:13 fabiankeil
91 * Increase default socket timeout to 300 seconds.
93 * Revision 1.86 2009/02/08 19:18:57 fabiankeil
94 * Now that we have the match-all.action file, the other action
95 * files changed their position in config->actions_file[] back
96 * to the way it was before standard.action got removed and the
97 * changes from revision 1.84 have to be reverted.
99 * Revision 1.85 2009/01/22 12:06:26 fabiankeil
100 * Don't keep connections alive when running single-threaded.
102 * Revision 1.84 2009/01/14 16:14:36 fabiankeil
103 * Due to the standard.action file removal, the other action
104 * files changed their position in config->actions_file[].
105 * Update mingw32 kludge accordingly.
107 * Revision 1.83 2008/12/20 14:53:55 fabiankeil
108 * Add config option socket-timeout to control the time
109 * Privoxy waits for data to arrive on a socket. Useful
110 * in case of stale ssh tunnels or when fuzz-testing.
112 * Revision 1.82 2008/11/16 12:43:49 fabiankeil
113 * Turn keep-alive support into a runtime feature
114 * that is disabled by setting keep-alive-timeout
115 * to a negative value.
117 * Revision 1.81 2008/11/13 09:08:42 fabiankeil
118 * Add new config option: keep-alive-timeout.
120 * Revision 1.80 2008/08/31 15:59:03 fabiankeil
121 * There's no reason to let remote toggling support depend
122 * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
124 * Revision 1.79 2008/08/30 12:03:07 fabiankeil
125 * Remove FEATURE_COOKIE_JAR.
127 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
128 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
129 * disabled, log a message that blocks will always be enforced
130 * instead of complaining about an unrecognized directive.
131 * Reported by Pietro Leone.
133 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
134 * Reuse directive_hash and don't hash the same directive twice.
136 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
137 * - Merge three string_append() calls.
138 * - Remove useless assertion.
140 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
141 * Rename load_actions_file() and load_re_filterfile()
142 * as they load multiple files "now".
144 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
145 * Add hostname directive. Closes PR#1918189.
147 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
150 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
151 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
153 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
154 * Reword "unrecognized directive" warning, use better
155 * mark up and add a <br>. Fixes parts of #1856559.
157 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
158 * Plug memory leak if listen-address only specifies the port.
160 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
161 * Relocate daemon-mode-related log messages to make sure
162 * they aren't shown again in case of configuration reloads.
164 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
165 * Plug memory leak introduced with my last commit.
167 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
168 * When in daemon mode, close stderr after the configuration file has been
169 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
171 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
172 * #1763173 from Stefan Huehner: declare unload_configfile() static.
174 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
175 * As Hal noticed, checking dispatch_cgi() as the last cruncher
176 * looks like a bug if CGI requests are blocked unintentionally,
177 * so don't do it unless the user enabled the new config option
178 * "allow-cgi-request-crunching".
180 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
181 * - Use strlcpy() instead of strcpy().
182 * - Stop treating actions files special. Expect a complete file name
183 * (with or without path) like it's done for the rest of the files.
185 * - Remove an unnecessary temporary memory allocation.
186 * - Don't log anything to the console when running as
187 * daemon and no errors occurred.
189 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
190 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
192 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
193 * New config option: enforce-blocks.
195 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
196 * - Mention other reasons why acl directive loading might have failed.
197 * - Don't log the acl source if the acl destination is to blame.
199 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
200 * Add new config option "templdir" to
201 * change the templates directory.
203 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
204 * Added config option accept-intercepted-requests
205 * and disabled it by default.
207 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
208 * Fix gcc43 compiler warnings.
210 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
211 * Add config option "split-large-forms"
212 * to work around the browser bug reported
215 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
216 * Move the <br> in the generated HTML for the config
217 * options from the beginning of the string to its end.
218 * Keeps the white space in balance.
220 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
221 * Fix memory leak in case of config file reloads.
223 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
224 * Modified kludge for win32 to make ming32 menu
225 * "Options/Edit Filters" (sort of) work again.
226 * Same limitations as for the action files apply.
229 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
230 * Incorporate modified version of Roland Rosenfeld's patch to
231 * optionally access the user-manual via Privoxy. Closes patch 679075.
233 * Formatting changed to Privoxy style, added call to
234 * cgi_error_no_template if the requested file doesn't
235 * exist and modified check whether or not Privoxy itself
236 * should serve the manual. Should work cross-platform now.
238 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
239 * Added config option enable-remote-http-toggle
240 * to specify if Privoxy should recognize special
241 * headers (currently only X-Filter) to change its
242 * behaviour. Disabled by default.
244 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
245 * Make number of retries in case of forwarded-connect problems
246 * a config file option (forwarded-connect-retries) and use 0 as
249 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
250 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
251 * with what was really the latest development (the v_3_0_branch branch)
253 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
254 * Don't forget to malloc space for the null terminator...
256 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
257 * Multiple filter file support
259 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
260 * Closed two memory leaks; hopefully the last remaining ones
261 * (in the main execution paths, anyway).
263 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
264 * Addressed bug #719435
265 * - Extraneous filterfile directives now logged as errors
266 * - This and unrecnonised directives now really obvious on status page
268 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
269 * Cosmetic: Renamed cryptic variable
271 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
272 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
274 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
275 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
277 * Revision 1.48 2002/05/14 21:30:38 oes
278 * savearg now uses own linking code instead of (now special-cased) add_help_link
280 * Revision 1.47 2002/05/12 21:36:29 jongfoster
281 * Correcting function comments
283 * Revision 1.46 2002/04/26 12:55:14 oes
284 * - New option "user-manual", defaults to our site
285 * via project.h #define
286 * - savearg now embeds option names in help links
288 * Revision 1.45 2002/04/24 02:11:54 oes
289 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
291 * Revision 1.44 2002/04/08 20:37:13 swa
294 * Revision 1.43 2002/04/08 20:36:50 swa
297 * Revision 1.42 2002/04/05 15:50:15 oes
298 * fix for invalid HTML proxy_args
300 * Revision 1.41 2002/03/31 17:19:00 jongfoster
301 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
303 * Revision 1.40 2002/03/26 22:29:55 swa
304 * we have a new homepage!
306 * Revision 1.39 2002/03/24 13:25:43 swa
307 * name change related issues
309 * Revision 1.38 2002/03/24 13:05:48 jongfoster
310 * Renaming re_filterfile to filterfile
312 * Revision 1.37 2002/03/16 23:54:06 jongfoster
313 * Adding graceful termination feature, to help look for memory leaks.
314 * If you enable this (which, by design, has to be done by hand
315 * editing config.h) and then go to http://i.j.b/die, then the program
316 * will exit cleanly after the *next* request. It should free all the
317 * memory that was used.
319 * Revision 1.36 2002/03/13 00:27:05 jongfoster
322 * Revision 1.35 2002/03/07 03:52:44 oes
323 * Set logging to tty for --no-daemon mode
325 * Revision 1.34 2002/03/06 23:14:35 jongfoster
326 * Trivial cosmetic changes to make function comments easier to find.
328 * Revision 1.33 2002/03/05 04:52:42 oes
329 * Deleted non-errlog debugging code
331 * Revision 1.32 2002/03/04 18:24:53 oes
332 * Re-enabled output of unknown config directive hash
334 * Revision 1.31 2002/03/03 15:07:20 oes
335 * Re-enabled automatic config reloading
337 * Revision 1.30 2002/01/22 23:31:43 jongfoster
338 * Replacing strsav() with string_append()
340 * Revision 1.29 2002/01/17 21:02:30 jongfoster
341 * Moving all our URL and URL pattern parsing code to urlmatch.c.
343 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
345 * Revision 1.28 2001/12/30 14:07:32 steudten
346 * - Add signal handling (unix)
347 * - Add SIGHUP handler (unix)
348 * - Add creation of pidfile (unix)
349 * - Add action 'top' in rc file (RH)
350 * - Add entry 'SIGNALS' to manpage
351 * - Add exit message to logfile (unix)
353 * Revision 1.27 2001/11/07 00:02:13 steudten
354 * Add line number in error output for lineparsing for
355 * actionsfile and configfile.
356 * Special handling for CLF added.
358 * Revision 1.26 2001/11/05 21:41:43 steudten
359 * Add changes to be a real daemon just for unix os.
360 * (change cwd to /, detach from controlling tty, set
361 * process group and session leader to the own process.
363 * Add some fatal-error log message for failed malloc().
364 * Add '-d' if compiled with 'configure --with-debug' to
365 * enable debug output.
367 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
368 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
369 * threads to call select() simultaneously. So, it's time to do a real, live,
370 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
371 * (native). Both versions will work, but using __OS2__ offers multi-threading.
373 * Revision 1.24 2001/10/23 21:40:30 jongfoster
374 * Added support for enable-edit-actions and enable-remote-toggle config
377 * Revision 1.23 2001/10/07 15:36:00 oes
378 * Introduced new config option "buffer-limit"
380 * Revision 1.22 2001/09/22 16:36:59 jongfoster
381 * Removing unused parameter fs from read_config_line()
383 * Revision 1.21 2001/09/16 17:10:43 jongfoster
384 * Moving function savearg() here, since it was the only thing left in
387 * Revision 1.20 2001/07/30 22:08:36 jongfoster
388 * Tidying up #defines:
389 * - All feature #defines are now of the form FEATURE_xxx
390 * - Permanently turned off WIN_GUI_EDIT
391 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
393 * Revision 1.19 2001/07/15 17:45:16 jongfoster
394 * Removing some unused #includes
396 * Revision 1.18 2001/07/13 14:01:14 oes
397 * - Removed all #ifdef PCRS
398 * - Removed vim-settings
400 * Revision 1.17 2001/06/29 13:31:03 oes
401 * - Improved comments
402 * - Fixed (actionsfile) and sorted hashes
403 * - Introduced admin_address and proxy-info-url
404 * as config parameters
405 * - Renamed config->proxy_args_invocation (which didn't have
406 * the invocation but the options!) to config->proxy_args
407 * - Various adaptions
408 * - Removed logentry from cancelled commit
410 * Revision 1.16 2001/06/09 10:55:28 jongfoster
411 * Changing BUFSIZ ==> BUFFER_SIZE
413 * Revision 1.15 2001/06/07 23:13:40 jongfoster
414 * Merging ACL and forward files into config file.
415 * Cosmetic: Sorting config file options alphabetically.
416 * Cosmetic: Adding brief syntax comments to config file options.
418 * Revision 1.14 2001/06/07 14:46:25 joergs
419 * Missing make_path() added for re_filterfile.
421 * Revision 1.13 2001/06/05 22:33:54 jongfoster
423 * Fixed minor memory leak.
424 * Also now uses make_path to prepend the pathnames.
426 * Revision 1.12 2001/06/05 20:04:09 jongfoster
427 * Now uses _snprintf() in place of snprintf() under Win32.
429 * Revision 1.11 2001/06/04 18:31:58 swa
430 * files are now prefixed with either `confdir' or `logdir'.
431 * `make redhat-dist' replaces both entries confdir and logdir
434 * Revision 1.10 2001/06/03 19:11:54 oes
435 * introduced confdir option
437 * Revision 1.9 2001/06/01 20:06:24 jongfoster
438 * Removed support for "tinygif" option - moved to actions file.
440 * Revision 1.8 2001/05/31 21:27:13 jongfoster
441 * Removed many options from the config file and into the
442 * "actions" file: add_forwarded, suppress_vanilla_wafer,
443 * wafer, add_header, user_agent, referer, from
444 * Also globally replaced "permission" with "action".
446 * Revision 1.7 2001/05/29 09:50:24 jongfoster
447 * Unified blocklist/imagelist/permissionslist.
448 * File format is still under discussion, but the internal changes
451 * Also modified interceptor behaviour:
452 * - We now intercept all URLs beginning with one of the following
453 * prefixes (and *only* these prefixes):
455 * * http://ijbswa.sf.net/config/
456 * * http://ijbswa.sourceforge.net/config/
457 * - New interceptors "home page" - go to http://i.j.b/ to see it.
458 * - Internal changes so that intercepted and fast redirect pages
459 * are not replaced with an image.
460 * - Interceptors now have the option to send a binary page direct
461 * to the client. (i.e. ijb-send-banner uses this)
462 * - Implemented show-url-info interceptor. (Which is why I needed
463 * the above interceptors changes - a typical URL is
464 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
465 * The previous mechanism would not have intercepted that, and
466 * if it had been intercepted then it then it would have replaced
469 * Revision 1.6 2001/05/26 00:28:36 jongfoster
470 * Automatic reloading of config file.
471 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
472 * Most of the global variables have been moved to a new
473 * struct configuration_spec, accessed through csp->config->globalname
474 * Most of the globals remaining are used by the Win32 GUI.
476 * Revision 1.5 2001/05/25 22:34:30 jongfoster
479 * Revision 1.4 2001/05/22 18:46:04 oes
481 * - Enabled filtering banners by size rather than URL
482 * by adding patterns that replace all standard banner
483 * sizes with the "Junkbuster" gif to the re_filterfile
485 * - Enabled filtering WebBugs by providing a pattern
486 * which kills all 1x1 images
488 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
489 * which is selected by the (nonstandard and therefore
490 * capital) letter 'U' in the option string.
491 * It causes the quantifiers to be ungreedy by default.
492 * Appending a ? turns back to greedy (!).
494 * - Added a new interceptor ijb-send-banner, which
495 * sends back the "Junkbuster" gif. Without imagelist or
496 * MSIE detection support, or if tinygif = 1, or the
497 * URL isn't recognized as an imageurl, a lame HTML
498 * explanation is sent instead.
500 * - Added new feature, which permits blocking remote
501 * script redirects and firing back a local redirect
503 * The feature is conditionally compiled, i.e. it
504 * can be disabled with --disable-fast-redirects,
505 * plus it must be activated by a "fast-redirects"
506 * line in the config file, has its own log level
507 * and of course wants to be displayed by show-proxy-args
508 * Note: Boy, all the #ifdefs in 1001 locations and
509 * all the fumbling with configure.in and acconfig.h
510 * were *way* more work than the feature itself :-(
512 * - Because a generic redirect template was needed for
513 * this, tinygif = 3 now uses the same.
515 * - Moved GIFs, and other static HTTP response templates
520 * - Removed some >400 CRs again (Jon, you really worked
523 * Revision 1.3 2001/05/20 01:21:20 jongfoster
524 * Version 2.9.4 checkin.
525 * - Merged popupfile and cookiefile, and added control over PCRS
526 * filtering, in new "permissionsfile".
527 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
528 * file error you now get a message box (in the Win32 GUI) rather
529 * than the program exiting with no explanation.
530 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
532 * - Removed tabs from "config"
533 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
534 * - Bumped up version number.
536 * Revision 1.2 2001/05/17 23:01:01 oes
537 * - Cleaned CRLF's from the sources and related files
539 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
540 * Initial import of version 2.9.3 source tree
543 *********************************************************************/
549 #include <sys/types.h>
563 # include <windows.h>
566 # ifndef _WIN_CONSOLE
568 # endif /* ndef _WIN_CONSOLE */
570 #else /* ifndef _WIN32 */
574 # include <sys/wait.h>
576 # include <sys/time.h>
577 # include <sys/stat.h>
587 #include "miscutil.h"
591 #include "urlmatch.h"
595 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
598 * Fix a problem with Solaris. There should be no effect on other
600 * Solaris's isspace() is a macro which uses it's argument directly
601 * as an array index. Therefore we need to make sure that high-bit
602 * characters generate +ve values, and ideally we also want to make
603 * the argument match the declared parameter type of "int".
605 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
606 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
608 #ifdef FEATURE_TOGGLE
609 /* Privoxy is enabled by default. */
610 int global_toggle_state = 1;
611 #endif /* def FEATURE_TOGGLE */
613 /* The filename of the configfile */
614 const char *configfile = NULL;
617 * CGI functions will later need access to the invocation args,
618 * so we will make argc and argv global.
621 const char **Argv = NULL;
623 static struct file_list *current_configfile = NULL;
627 * This takes the "cryptic" hash of each keyword and aliases them to
628 * something a little more readable. This also makes changing the
629 * hash values easier if they should change or the hash algorthm changes.
630 * Use the included "hash" program to find out what the hash will be
631 * for any string supplied on the command line. (Or just put it in the
632 * config file and read the number from the error message in the log).
634 * Please keep this list sorted alphabetically (but with the Windows
635 * console and GUI specific options last).
638 #define hash_actions_file 1196306641ul /* "actionsfile" */
639 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
640 #define hash_admin_address 4112573064ul /* "admin-address" */
641 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
642 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
643 #define hash_confdir 1978389ul /* "confdir" */
644 #define hash_connection_sharing 1348841265ul /* "connection-sharing" */
645 #define hash_debug 78263ul /* "debug" */
646 #define hash_deny_access 1227333715ul /* "deny-access" */
647 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
648 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
649 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
650 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
651 #define hash_filterfile 250887266ul /* "filterfile" */
652 #define hash_forward 2029845ul /* "forward" */
653 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
654 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
655 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
656 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
657 #define hash_hostname 10308071ul /* "hostname" */
658 #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */
659 #define hash_listen_address 1255650842ul /* "listen-address" */
660 #define hash_logdir 422889ul /* "logdir" */
661 #define hash_logfile 2114766ul /* "logfile" */
662 #define hash_max_client_connections 3595884446ul /* "max-client-connections" */
663 #define hash_permit_access 3587953268ul /* "permit-access" */
664 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
665 #define hash_single_threaded 4250084780ul /* "single-threaded" */
666 #define hash_socket_timeout 1809001761ul /* "socket-timeout" */
667 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
668 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
669 #define hash_templdir 11067889ul /* "templdir" */
670 #define hash_toggle 447966ul /* "toggle" */
671 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
672 #define hash_trustfile 56494766ul /* "trustfile" */
673 #define hash_usermanual 1416668518ul /* "user-manual" */
674 #define hash_activity_animation 1817904738ul /* "activity-animation" */
675 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
676 #define hash_hide_console 2048809870ul /* "hide-console" */
677 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
678 #define hash_log_font_name 2866730124ul /* "log-font-name" */
679 #define hash_log_font_size 2866731014ul /* "log-font-size" */
680 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
681 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
682 #define hash_log_messages 2291744899ul /* "log-messages" */
683 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
686 static void savearg(char *command, char *argument, struct configuration_spec * config);
688 /*********************************************************************
690 * Function : unload_configfile
692 * Description : Free the config structure and all components.
695 * 1 : data: struct configuration_spec to unload
699 *********************************************************************/
700 static void unload_configfile (void * data)
702 struct configuration_spec * config = (struct configuration_spec *)data;
703 struct forward_spec *cur_fwd = config->forward;
707 struct access_control_list *cur_acl = config->acl;
709 while (cur_acl != NULL)
711 struct access_control_list * next_acl = cur_acl->next;
716 #endif /* def FEATURE_ACL */
718 while (cur_fwd != NULL)
720 struct forward_spec * next_fwd = cur_fwd->next;
721 free_url_spec(cur_fwd->url);
723 freez(cur_fwd->gateway_host);
724 freez(cur_fwd->forward_host);
728 config->forward = NULL;
730 freez(config->confdir);
731 freez(config->logdir);
732 freez(config->templdir);
733 freez(config->hostname);
735 freez(config->haddr);
736 freez(config->logfile);
738 for (i = 0; i < MAX_AF_FILES; i++)
740 freez(config->actions_file_short[i]);
741 freez(config->actions_file[i]);
742 freez(config->re_filterfile_short[i]);
743 freez(config->re_filterfile[i]);
746 freez(config->admin_address);
747 freez(config->proxy_info_url);
748 freez(config->proxy_args);
749 freez(config->usermanual);
752 freez(config->trustfile);
753 list_remove_all(config->trust_info);
754 #endif /* def FEATURE_TRUST */
756 for (i = 0; i < MAX_AF_FILES; i++)
758 freez(config->re_filterfile[i]);
765 #ifdef FEATURE_GRACEFUL_TERMINATION
766 /*********************************************************************
768 * Function : unload_current_config_file
770 * Description : Unloads current config file - reset to state at
771 * beginning of program.
777 *********************************************************************/
778 void unload_current_config_file(void)
780 if (current_configfile)
782 current_configfile->unloader = unload_configfile;
783 current_configfile = NULL;
789 /*********************************************************************
791 * Function : load_config
793 * Description : Load the config file and all parameters.
795 * XXX: more than thousand lines long
796 * and thus in serious need of refactoring.
800 * Returns : The configuration_spec, or NULL on error.
802 *********************************************************************/
803 struct configuration_spec * load_config(void)
805 char buf[BUFFER_SIZE];
807 FILE *configfp = NULL;
808 struct configuration_spec * config = NULL;
809 struct client_state * fake_csp;
810 struct file_list *fs;
811 unsigned long linenum = 0;
813 char *logfile = NULL;
815 if (!check_file_changed(current_configfile, configfile, &fs))
817 /* No need to load */
818 return ((struct configuration_spec *)current_configfile->f);
822 log_error(LOG_LEVEL_FATAL,
823 "can't check configuration file '%s': %E", configfile);
827 if (NULL != current_configfile)
829 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
832 #ifdef FEATURE_TOGGLE
833 global_toggle_state = 1;
834 #endif /* def FEATURE_TOGGLE */
836 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
842 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
847 * This is backwards from how it's usually done.
848 * Following the usual pattern, "fs" would be stored in a member
849 * variable in "csp", and then we'd access "config" from "fs->f",
850 * using a cast. However, "config" is used so often that a
851 * cast each time would be very ugly, and the extra indirection
852 * would waste CPU cycles. Therefore we store "config" in
853 * "csp->config", and "fs" in "csp->config->config_file_list".
855 config->config_file_list = fs;
860 config->multi_threaded = 1;
861 config->buffer_limit = 4096 * 1024;
862 config->usermanual = strdup(USER_MANUAL_URL);
863 config->proxy_args = strdup("");
864 config->forwarded_connect_retries = 0;
865 config->max_client_connections = 0;
866 config->socket_timeout = 300; /* XXX: Should be a macro. */
867 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
868 config->keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
869 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
870 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
872 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
873 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
874 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
876 configfp = fopen(configfile, "r");
877 if (NULL == configfp)
879 log_error(LOG_LEVEL_FATAL,
880 "can't open configuration file '%s': %E", configfile);
881 /* Never get here - LOG_LEVEL_FATAL causes program exit */
884 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
886 char cmd[BUFFER_SIZE];
887 char arg[BUFFER_SIZE];
888 char tmp[BUFFER_SIZE];
890 struct access_control_list *cur_acl;
891 #endif /* def FEATURE_ACL */
892 struct forward_spec *cur_fwd;
895 unsigned long directive_hash;
897 strlcpy(tmp, buf, sizeof(tmp));
899 /* Copy command (i.e. up to space or tab) into cmd */
902 while (*p && (*p != ' ') && (*p != '\t'))
908 /* Skip over the whitespace in buf */
909 while (*p && ((*p == ' ') || (*p == '\t')))
914 /* Copy the argument into arg */
915 strlcpy(arg, p, sizeof(arg));
917 /* Should never happen, but check this anyway */
923 /* Make sure the command field is lower case */
924 for (p = cmd; *p; p++)
928 *p = (char)ijb_tolower(*p);
932 directive_hash = hash_string(cmd);
933 switch (directive_hash)
935 /* *************************************************************************
936 * actionsfile actions-file-name
937 * In confdir by default
938 * *************************************************************************/
939 case hash_actions_file :
941 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
946 if (i >= MAX_AF_FILES)
948 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
949 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
952 config->actions_file_short[i] = strdup(arg);
953 config->actions_file[i] = make_path(config->confdir, arg);
956 /* *************************************************************************
957 * accept-intercepted-requests
958 * *************************************************************************/
959 case hash_accept_intercepted_requests:
960 if ((*arg != '\0') && (0 != atoi(arg)))
962 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
966 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
970 /* *************************************************************************
971 * admin-address email-address
972 * *************************************************************************/
973 case hash_admin_address :
974 freez(config->admin_address);
975 config->admin_address = strdup(arg);
978 /* *************************************************************************
979 * allow-cgi-request-crunching
980 * *************************************************************************/
981 case hash_allow_cgi_request_crunching:
982 if ((*arg != '\0') && (0 != atoi(arg)))
984 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
988 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
992 /* *************************************************************************
994 * *************************************************************************/
995 case hash_buffer_limit :
996 config->buffer_limit = (size_t)(1024 * atoi(arg));
999 /* *************************************************************************
1000 * confdir directory-name
1001 * *************************************************************************/
1003 freez(config->confdir);
1004 config->confdir = make_path( NULL, arg);
1007 /* *************************************************************************
1008 * connection-sharing (0|1)
1009 * *************************************************************************/
1010 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1011 case hash_connection_sharing :
1012 if ((*arg != '\0') && (0 != atoi(arg)))
1014 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_SHARING;
1018 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
1023 /* *************************************************************************
1025 * Specifies debug level, multiple values are ORed together.
1026 * *************************************************************************/
1028 config->debug |= atoi(arg);
1031 /* *************************************************************************
1032 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1033 * *************************************************************************/
1035 case hash_deny_access:
1036 strlcpy(tmp, arg, sizeof(tmp));
1037 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1039 if ((vec_count != 1) && (vec_count != 2))
1041 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1042 "deny-access directive in configuration file.");
1043 string_append(&config->proxy_args,
1044 "<br>\nWARNING: Wrong number of parameters for "
1045 "deny-access directive in configuration file.<br><br>\n");
1049 /* allocate a new node */
1050 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1052 if (cur_acl == NULL)
1054 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1055 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1058 cur_acl->action = ACL_DENY;
1060 if (acl_addr(vec[0], cur_acl->src) < 0)
1062 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1063 "for deny-access directive in configuration file: \"%s\"", vec[0]);
1064 string_append(&config->proxy_args,
1065 "<br>\nWARNING: Invalid source address, port or netmask "
1066 "for deny-access directive in configuration file: \"");
1067 string_append(&config->proxy_args,
1069 string_append(&config->proxy_args,
1076 if (acl_addr(vec[1], cur_acl->dst) < 0)
1078 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1079 "for deny-access directive in configuration file: \"%s\"", vec[1]);
1080 string_append(&config->proxy_args,
1081 "<br>\nWARNING: Invalid destination address, port or netmask "
1082 "for deny-access directive in configuration file: \"");
1083 string_append(&config->proxy_args,
1085 string_append(&config->proxy_args,
1094 cur_acl->wildcard_dst = 1;
1096 #endif /* def HAVE_RFC2553 */
1099 * Add it to the list. Note we reverse the list to get the
1100 * behaviour the user expects. With both the ACL and
1101 * actions file, the last match wins. However, the internal
1102 * implementations are different: The actions file is stored
1103 * in the same order as the file, and scanned completely.
1104 * With the ACL, we reverse the order as we load it, then
1105 * when we scan it we stop as soon as we get a match.
1107 cur_acl->next = config->acl;
1108 config->acl = cur_acl;
1111 #endif /* def FEATURE_ACL */
1113 /* *************************************************************************
1114 * enable-edit-actions 0|1
1115 * *************************************************************************/
1116 #ifdef FEATURE_CGI_EDIT_ACTIONS
1117 case hash_enable_edit_actions:
1118 if ((*arg != '\0') && (0 != atoi(arg)))
1120 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1124 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1127 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1129 /* *************************************************************************
1130 * enable-remote-toggle 0|1
1131 * *************************************************************************/
1132 #ifdef FEATURE_TOGGLE
1133 case hash_enable_remote_toggle:
1134 if ((*arg != '\0') && (0 != atoi(arg)))
1136 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1140 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1143 #endif /* def FEATURE_TOGGLE */
1145 /* *************************************************************************
1146 * enable-remote-http-toggle 0|1
1147 * *************************************************************************/
1148 case hash_enable_remote_http_toggle:
1149 if ((*arg != '\0') && (0 != atoi(arg)))
1151 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1155 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1159 /* *************************************************************************
1160 * enforce-blocks 0|1
1161 * *************************************************************************/
1162 case hash_enforce_blocks:
1163 #ifdef FEATURE_FORCE_LOAD
1164 if ((*arg != '\0') && (0 != atoi(arg)))
1166 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1170 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1173 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1174 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1175 #endif /* def FEATURE_FORCE_LOAD */
1178 /* *************************************************************************
1179 * filterfile file-name
1180 * In confdir by default.
1181 * *************************************************************************/
1182 case hash_filterfile :
1184 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1189 if (i >= MAX_AF_FILES)
1191 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1192 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1195 config->re_filterfile_short[i] = strdup(arg);
1196 config->re_filterfile[i] = make_path(config->confdir, arg);
1200 /* *************************************************************************
1201 * forward url-pattern (.|http-proxy-host[:port])
1202 * *************************************************************************/
1204 strlcpy(tmp, arg, sizeof(tmp));
1205 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1209 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1210 "directive in configuration file.");
1211 string_append(&config->proxy_args,
1212 "<br>\nWARNING: Wrong number of parameters for "
1213 "forward directive in configuration file.");
1217 /* allocate a new node */
1218 cur_fwd = zalloc(sizeof(*cur_fwd));
1219 if (cur_fwd == NULL)
1221 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1222 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1226 cur_fwd->type = SOCKS_NONE;
1228 /* Save the URL pattern */
1229 if (create_url_spec(cur_fwd->url, vec[0]))
1231 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1232 "directive in configuration file.");
1233 string_append(&config->proxy_args,
1234 "<br>\nWARNING: Bad URL specifier for "
1235 "forward directive in configuration file.");
1239 /* Parse the parent HTTP proxy host:port */
1242 if (strcmp(p, ".") != 0)
1244 cur_fwd->forward_port = 8000;
1245 parse_forwarder_address(p, &cur_fwd->forward_host,
1246 &cur_fwd->forward_port);
1250 cur_fwd->next = config->forward;
1251 config->forward = cur_fwd;
1255 /* *************************************************************************
1256 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1257 * *************************************************************************/
1258 case hash_forward_socks4:
1259 strlcpy(tmp, arg, sizeof(tmp));
1260 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1264 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1265 "forward-socks4 directive in configuration file.");
1266 string_append(&config->proxy_args,
1267 "<br>\nWARNING: Wrong number of parameters for "
1268 "forward-socks4 directive in configuration file.");
1272 /* allocate a new node */
1273 cur_fwd = zalloc(sizeof(*cur_fwd));
1274 if (cur_fwd == NULL)
1276 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1277 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1281 cur_fwd->type = SOCKS_4;
1283 /* Save the URL pattern */
1284 if (create_url_spec(cur_fwd->url, vec[0]))
1286 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1287 "directive in configuration file.");
1288 string_append(&config->proxy_args,
1289 "<br>\nWARNING: Bad URL specifier for "
1290 "forward-socks4 directive in configuration file.");
1294 /* Parse the SOCKS proxy host[:port] */
1297 /* XXX: This check looks like a bug. */
1298 if (strcmp(p, ".") != 0)
1300 cur_fwd->gateway_port = 1080;
1301 parse_forwarder_address(p, &cur_fwd->gateway_host,
1302 &cur_fwd->gateway_port);
1305 /* Parse the parent HTTP proxy host[:port] */
1308 if (strcmp(p, ".") != 0)
1310 cur_fwd->forward_port = 8000;
1311 parse_forwarder_address(p, &cur_fwd->forward_host,
1312 &cur_fwd->forward_port);
1316 cur_fwd->next = config->forward;
1317 config->forward = cur_fwd;
1321 /* *************************************************************************
1322 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1323 * *************************************************************************/
1324 case hash_forward_socks4a:
1325 case hash_forward_socks5:
1326 strlcpy(tmp, arg, sizeof(tmp));
1327 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1331 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1332 "forward-socks4a directive in configuration file.");
1333 string_append(&config->proxy_args,
1334 "<br>\nWARNING: Wrong number of parameters for "
1335 "forward-socks4a directive in configuration file.");
1339 /* allocate a new node */
1340 cur_fwd = zalloc(sizeof(*cur_fwd));
1341 if (cur_fwd == NULL)
1343 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1344 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1348 if (directive_hash == hash_forward_socks4a)
1350 cur_fwd->type = SOCKS_4A;
1354 cur_fwd->type = SOCKS_5;
1357 /* Save the URL pattern */
1358 if (create_url_spec(cur_fwd->url, vec[0]))
1360 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1361 "directive in configuration file.");
1362 string_append(&config->proxy_args,
1363 "<br>\nWARNING: Bad URL specifier for "
1364 "forward-socks4a directive in configuration file.");
1368 /* Parse the SOCKS proxy host[:port] */
1371 cur_fwd->gateway_port = 1080;
1372 parse_forwarder_address(p, &cur_fwd->gateway_host,
1373 &cur_fwd->gateway_port);
1375 /* Parse the parent HTTP proxy host[:port] */
1378 if (strcmp(p, ".") != 0)
1380 cur_fwd->forward_port = 8000;
1381 parse_forwarder_address(p, &cur_fwd->forward_host,
1382 &cur_fwd->forward_port);
1386 cur_fwd->next = config->forward;
1387 config->forward = cur_fwd;
1391 /* *************************************************************************
1392 * forwarded-connect-retries n
1393 * *************************************************************************/
1394 case hash_forwarded_connect_retries :
1395 config->forwarded_connect_retries = atoi(arg);
1398 /* *************************************************************************
1399 * hostname hostname-to-show-on-cgi-pages
1400 * *************************************************************************/
1401 case hash_hostname :
1402 freez(config->hostname);
1403 config->hostname = strdup(arg);
1404 if (NULL == config->hostname)
1406 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1410 /* *************************************************************************
1411 * keep-alive-timeout timeout
1412 * *************************************************************************/
1413 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1414 case hash_keep_alive_timeout :
1417 int timeout = atoi(arg);
1420 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1421 config->keep_alive_timeout = (unsigned int)timeout;
1425 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1431 /* *************************************************************************
1432 * listen-address [ip][:port]
1433 * *************************************************************************/
1434 case hash_listen_address :
1435 freez(config->haddr);
1436 config->haddr = strdup(arg);
1439 /* *************************************************************************
1440 * logdir directory-name
1441 * *************************************************************************/
1443 freez(config->logdir);
1444 config->logdir = make_path(NULL, arg);
1447 /* *************************************************************************
1448 * logfile log-file-name
1449 * In logdir by default
1450 * *************************************************************************/
1454 logfile = make_path(config->logdir, arg);
1455 if (NULL == logfile)
1457 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1462 /* *************************************************************************
1463 * max-client-connections number
1464 * *************************************************************************/
1465 case hash_max_client_connections :
1468 int max_client_connections = atoi(arg);
1469 if (0 <= max_client_connections)
1471 config->max_client_connections = max_client_connections;
1476 /* *************************************************************************
1477 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1478 * *************************************************************************/
1480 case hash_permit_access:
1481 strlcpy(tmp, arg, sizeof(tmp));
1482 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1484 if ((vec_count != 1) && (vec_count != 2))
1486 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1487 "permit-access directive in configuration file.");
1488 string_append(&config->proxy_args,
1489 "<br>\nWARNING: Wrong number of parameters for "
1490 "permit-access directive in configuration file.<br><br>\n");
1495 /* allocate a new node */
1496 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1498 if (cur_acl == NULL)
1500 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1501 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1504 cur_acl->action = ACL_PERMIT;
1506 if (acl_addr(vec[0], cur_acl->src) < 0)
1508 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1509 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1510 string_append(&config->proxy_args,
1511 "<br>\nWARNING: Invalid source address, port or netmask for "
1512 "permit-access directive in configuration file: \"");
1513 string_append(&config->proxy_args,
1515 string_append(&config->proxy_args,
1522 if (acl_addr(vec[1], cur_acl->dst) < 0)
1524 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1525 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1526 string_append(&config->proxy_args,
1527 "<br>\nWARNING: Invalid destination address, port or netmask for "
1528 "permit-access directive in configuration file: \"");
1529 string_append(&config->proxy_args,
1531 string_append(&config->proxy_args,
1540 cur_acl->wildcard_dst = 1;
1542 #endif /* def HAVE_RFC2553 */
1545 * Add it to the list. Note we reverse the list to get the
1546 * behaviour the user expects. With both the ACL and
1547 * actions file, the last match wins. However, the internal
1548 * implementations are different: The actions file is stored
1549 * in the same order as the file, and scanned completely.
1550 * With the ACL, we reverse the order as we load it, then
1551 * when we scan it we stop as soon as we get a match.
1553 cur_acl->next = config->acl;
1554 config->acl = cur_acl;
1557 #endif /* def FEATURE_ACL */
1559 /* *************************************************************************
1560 * proxy-info-url url
1561 * *************************************************************************/
1562 case hash_proxy_info_url :
1563 freez(config->proxy_info_url);
1564 config->proxy_info_url = strdup(arg);
1567 /* *************************************************************************
1569 * *************************************************************************/
1570 case hash_single_threaded :
1571 config->multi_threaded = 0;
1574 /* *************************************************************************
1575 * socket-timeout numer_of_seconds
1576 * *************************************************************************/
1577 case hash_socket_timeout :
1580 int socket_timeout = atoi(arg);
1581 if (0 < socket_timeout)
1583 config->socket_timeout = socket_timeout;
1587 log_error(LOG_LEVEL_FATAL,
1588 "Invalid socket-timeout: '%s'", arg);
1593 /* *************************************************************************
1594 * split-large-cgi-forms
1595 * *************************************************************************/
1596 case hash_split_large_cgi_forms :
1597 if ((*arg != '\0') && (0 != atoi(arg)))
1599 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1603 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1607 /* *************************************************************************
1608 * templdir directory-name
1609 * *************************************************************************/
1610 case hash_templdir :
1611 freez(config->templdir);
1612 config->templdir = make_path(NULL, arg);
1615 /* *************************************************************************
1617 * *************************************************************************/
1618 #ifdef FEATURE_TOGGLE
1620 global_toggle_state = atoi(arg);
1622 #endif /* def FEATURE_TOGGLE */
1624 /* *************************************************************************
1625 * trust-info-url url
1626 * *************************************************************************/
1627 #ifdef FEATURE_TRUST
1628 case hash_trust_info_url :
1629 enlist(config->trust_info, arg);
1631 #endif /* def FEATURE_TRUST */
1633 /* *************************************************************************
1634 * trustfile filename
1635 * (In confdir by default.)
1636 * *************************************************************************/
1637 #ifdef FEATURE_TRUST
1638 case hash_trustfile :
1639 freez(config->trustfile);
1640 config->trustfile = make_path(config->confdir, arg);
1642 #endif /* def FEATURE_TRUST */
1644 /* *************************************************************************
1646 * *************************************************************************/
1647 case hash_usermanual :
1649 * XXX: If this isn't the first config directive, the
1650 * show-status page links to the website documentation
1651 * for the directives that were already parsed. Lame.
1653 freez(config->usermanual);
1654 config->usermanual = strdup(arg);
1657 /* *************************************************************************
1658 * Win32 Console options:
1659 * *************************************************************************/
1661 /* *************************************************************************
1663 * *************************************************************************/
1665 case hash_hide_console :
1668 #endif /*def _WIN_CONSOLE*/
1671 /* *************************************************************************
1672 * Win32 GUI options:
1673 * *************************************************************************/
1675 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1676 /* *************************************************************************
1677 * activity-animation (0|1)
1678 * *************************************************************************/
1679 case hash_activity_animation :
1680 g_bShowActivityAnimation = atoi(arg);
1683 /* *************************************************************************
1684 * close-button-minimizes (0|1)
1685 * *************************************************************************/
1686 case hash_close_button_minimizes :
1687 g_bCloseHidesWindow = atoi(arg);
1690 /* *************************************************************************
1691 * log-buffer-size (0|1)
1692 * *************************************************************************/
1693 case hash_log_buffer_size :
1694 g_bLimitBufferSize = atoi(arg);
1697 /* *************************************************************************
1698 * log-font-name fontname
1699 * *************************************************************************/
1700 case hash_log_font_name :
1701 if (strlcpy(g_szFontFaceName, arg,
1702 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1704 log_error(LOG_LEVEL_FATAL,
1705 "log-font-name argument '%s' is longer than %u characters.",
1706 arg, sizeof(g_szFontFaceName)-1);
1710 /* *************************************************************************
1712 * *************************************************************************/
1713 case hash_log_font_size :
1714 g_nFontSize = atoi(arg);
1717 /* *************************************************************************
1718 * log-highlight-messages (0|1)
1719 * *************************************************************************/
1720 case hash_log_highlight_messages :
1721 g_bHighlightMessages = atoi(arg);
1724 /* *************************************************************************
1726 * *************************************************************************/
1727 case hash_log_max_lines :
1728 g_nMaxBufferLines = atoi(arg);
1731 /* *************************************************************************
1732 * log-messages (0|1)
1733 * *************************************************************************/
1734 case hash_log_messages :
1735 g_bLogMessages = atoi(arg);
1738 /* *************************************************************************
1739 * show-on-task-bar (0|1)
1740 * *************************************************************************/
1741 case hash_show_on_task_bar :
1742 g_bShowOnTaskBar = atoi(arg);
1745 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1748 /* *************************************************************************
1749 * Warnings about unsupported features
1750 * *************************************************************************/
1752 case hash_deny_access:
1753 #endif /* ndef FEATURE_ACL */
1754 #ifndef FEATURE_CGI_EDIT_ACTIONS
1755 case hash_enable_edit_actions:
1756 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1757 #ifndef FEATURE_TOGGLE
1758 case hash_enable_remote_toggle:
1759 #endif /* ndef FEATURE_TOGGLE */
1761 case hash_permit_access:
1762 #endif /* ndef FEATURE_ACL */
1763 #ifndef FEATURE_TOGGLE
1765 #endif /* ndef FEATURE_TOGGLE */
1766 #ifndef FEATURE_TRUST
1767 case hash_trustfile :
1768 case hash_trust_info_url :
1769 #endif /* ndef FEATURE_TRUST */
1771 #ifndef _WIN_CONSOLE
1772 case hash_hide_console :
1773 #endif /* ndef _WIN_CONSOLE */
1775 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1776 case hash_activity_animation :
1777 case hash_close_button_minimizes :
1778 case hash_log_buffer_size :
1779 case hash_log_font_name :
1780 case hash_log_font_size :
1781 case hash_log_highlight_messages :
1782 case hash_log_max_lines :
1783 case hash_log_messages :
1784 case hash_show_on_task_bar :
1785 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1786 /* These warnings are annoying - so hide them. -- Jon */
1787 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1790 /* *************************************************************************/
1792 /* *************************************************************************/
1794 * I decided that I liked this better as a warning than an
1795 * error. To change back to an error, just change log level
1796 * to LOG_LEVEL_FATAL.
1798 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1799 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1800 string_append(&config->proxy_args,
1801 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1804 /* *************************************************************************/
1805 } /* end switch( hash_string(cmd) ) */
1807 /* Save the argument for the show-status page. */
1808 savearg(cmd, arg, config);
1810 } /* end while ( read_config_line(...) ) */
1814 set_debug_level(config->debug);
1816 freez(config->logfile);
1820 if (NULL != logfile)
1822 config->logfile = logfile;
1823 init_error_log(Argv[0], config->logfile);
1831 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1832 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1834 if (config->multi_threaded)
1836 set_keep_alive_timeout(config->keep_alive_timeout);
1841 * While we could use keep-alive without multiple threads
1842 * if we didn't bother with enforcing the connection timeout,
1843 * that might make Tor users sad, even though they shouldn't
1844 * enable the single-threaded option anyway.
1846 * XXX: We could still use Proxy-Connection: keep-alive.
1848 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1849 log_error(LOG_LEVEL_ERROR,
1850 "Config option single-threaded disables connection keep-alive.");
1855 if (NULL == config->proxy_args)
1857 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1860 if (config->actions_file[0])
1862 add_loader(load_action_files, config);
1865 if (config->re_filterfile[0])
1867 add_loader(load_re_filterfiles, config);
1870 #ifdef FEATURE_TRUST
1871 if (config->trustfile)
1873 add_loader(load_trustfile, config);
1875 #endif /* def FEATURE_TRUST */
1877 if ( NULL == config->haddr )
1879 config->haddr = strdup( HADDR_DEFAULT );
1882 if ( NULL != config->haddr )
1884 if ((*config->haddr == '[')
1885 && (NULL != (p = strchr(config->haddr, ']')))
1887 && (0 < (config->hport = atoi(p + 2))))
1890 memmove((void *)config->haddr, config->haddr + 1,
1891 (size_t)(p - config->haddr));
1893 else if (NULL != (p = strchr(config->haddr, ':'))
1894 && (0 < (config->hport = atoi(p + 1))))
1900 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1901 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1903 if (*config->haddr == '\0')
1906 * Only the port specified. We stored it in config->hport
1907 * and don't need its text representation anymore.
1909 freez(config->haddr);
1914 * Want to run all the loaders once now.
1916 * Need to set up a fake csp, so they can get to the config.
1918 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1919 fake_csp->config = config;
1921 if (run_loader(fake_csp))
1924 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1925 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1929 /* FIXME: this is a kludge for win32 */
1930 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1932 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1933 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1934 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1936 #ifdef FEATURE_TRUST
1937 g_trustfile = config->trustfile;
1938 #endif /* def FEATURE_TRUST */
1941 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1942 /* FIXME: end kludge */
1945 config->need_bind = 1;
1947 if (current_configfile)
1949 struct configuration_spec * oldcfg = (struct configuration_spec *)
1950 current_configfile->f;
1952 * Check if config->haddr,hport == oldcfg->haddr,hport
1954 * The following could be written more compactly as a single,
1955 * (unreadably long) if statement.
1957 config->need_bind = 0;
1958 if (config->hport != oldcfg->hport)
1960 config->need_bind = 1;
1962 else if (config->haddr == NULL)
1964 if (oldcfg->haddr != NULL)
1966 config->need_bind = 1;
1969 else if (oldcfg->haddr == NULL)
1971 config->need_bind = 1;
1973 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1975 config->need_bind = 1;
1978 current_configfile->unloader = unload_configfile;
1981 fs->next = files->next;
1984 current_configfile = fs;
1990 /*********************************************************************
1992 * Function : savearg
1994 * Description : Called from `load_config'. It saves each non-empty
1995 * and non-comment line from config into
1996 * config->proxy_args. This is used to create the
1997 * show-proxy-args page. On error, frees
1998 * config->proxy_args and sets it to NULL
2001 * 1 : command = config setting that was found
2002 * 2 : argument = the setting's argument (if any)
2003 * 3 : config = Configuration to save into.
2007 *********************************************************************/
2008 static void savearg(char *command, char *argument, struct configuration_spec * config)
2017 * Add config option name embedded in
2018 * link to its section in the user-manual
2020 buf = strdup("\n<a href=\"");
2021 if (!strncmpic(config->usermanual, "file://", 7) ||
2022 !strncmpic(config->usermanual, "http", 4))
2024 string_append(&buf, config->usermanual);
2028 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
2030 string_append(&buf, CONFIG_HELP_PREFIX);
2031 string_join (&buf, string_toupper(command));
2032 string_append(&buf, "\">");
2033 string_append(&buf, command);
2034 string_append(&buf, "</a> ");
2038 freez(config->proxy_args);
2042 if ( (NULL != argument) && ('\0' != *argument) )
2044 s = html_encode(argument);
2048 freez(config->proxy_args);
2052 if (strncmpic(argument, "http://", 7) == 0)
2054 string_append(&buf, "<a href=\"");
2055 string_append(&buf, s);
2056 string_append(&buf, "\">");
2057 string_join (&buf, s);
2058 string_append(&buf, "</a>");
2062 string_join (&buf, s);
2066 string_append(&buf, "<br>");
2067 string_join(&config->proxy_args, buf);