1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.93 2009/03/18 21:46:26 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.93 2009/03/18 21:46:26 fabiankeil
39 * Revert the last commit as there's a better way.
41 * Revision 1.92 2009/03/18 20:43:19 fabiankeil
42 * Don't enable LOG_LEVEL_INFO by default and don't apply the user's
43 * debug settings until the logfile has been opened (if there is one).
44 * Patch submitted by Roland in #2624120.
46 * Revision 1.91 2009/03/09 17:29:08 fabiankeil
47 * As of r1.88, the show-status page can use a single line for
48 * warnings about ignored directives and the names of the ignored
49 * directives themselves. Reminded by Lee, finally closes #1856559.
51 * Revision 1.90 2009/03/07 17:58:02 fabiankeil
52 * Fix two mingw32-only buffer overflows. Note that triggering
53 * them requires control over the configuration file in which
54 * case all bets are off anyway.
56 * Revision 1.89 2009/03/01 18:46:33 fabiankeil
57 * - Help clang understand that we aren't
58 * dereferencing NULL pointers here.
59 * - Some style fixes in the modified region.
61 * Revision 1.88 2009/02/28 10:57:10 fabiankeil
62 * Gimme a break or two. Don't let the show-status page
63 * link to the website documentation for the user-manual
66 * Revision 1.87 2009/02/15 07:56:13 fabiankeil
67 * Increase default socket timeout to 300 seconds.
69 * Revision 1.86 2009/02/08 19:18:57 fabiankeil
70 * Now that we have the match-all.action file, the other action
71 * files changed their position in config->actions_file[] back
72 * to the way it was before standard.action got removed and the
73 * changes from revision 1.84 have to be reverted.
75 * Revision 1.85 2009/01/22 12:06:26 fabiankeil
76 * Don't keep connections alive when running single-threaded.
78 * Revision 1.84 2009/01/14 16:14:36 fabiankeil
79 * Due to the standard.action file removal, the other action
80 * files changed their position in config->actions_file[].
81 * Update mingw32 kludge accordingly.
83 * Revision 1.83 2008/12/20 14:53:55 fabiankeil
84 * Add config option socket-timeout to control the time
85 * Privoxy waits for data to arrive on a socket. Useful
86 * in case of stale ssh tunnels or when fuzz-testing.
88 * Revision 1.82 2008/11/16 12:43:49 fabiankeil
89 * Turn keep-alive support into a runtime feature
90 * that is disabled by setting keep-alive-timeout
91 * to a negative value.
93 * Revision 1.81 2008/11/13 09:08:42 fabiankeil
94 * Add new config option: keep-alive-timeout.
96 * Revision 1.80 2008/08/31 15:59:03 fabiankeil
97 * There's no reason to let remote toggling support depend
98 * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
100 * Revision 1.79 2008/08/30 12:03:07 fabiankeil
101 * Remove FEATURE_COOKIE_JAR.
103 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
104 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
105 * disabled, log a message that blocks will always be enforced
106 * instead of complaining about an unrecognized directive.
107 * Reported by Pietro Leone.
109 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
110 * Reuse directive_hash and don't hash the same directive twice.
112 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
113 * - Merge three string_append() calls.
114 * - Remove useless assertion.
116 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
117 * Rename load_actions_file() and load_re_filterfile()
118 * as they load multiple files "now".
120 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
121 * Add hostname directive. Closes PR#1918189.
123 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
126 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
127 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
129 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
130 * Reword "unrecognized directive" warning, use better
131 * mark up and add a <br>. Fixes parts of #1856559.
133 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
134 * Plug memory leak if listen-address only specifies the port.
136 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
137 * Relocate daemon-mode-related log messages to make sure
138 * they aren't shown again in case of configuration reloads.
140 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
141 * Plug memory leak introduced with my last commit.
143 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
144 * When in daemon mode, close stderr after the configuration file has been
145 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
147 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
148 * #1763173 from Stefan Huehner: declare unload_configfile() static.
150 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
151 * As Hal noticed, checking dispatch_cgi() as the last cruncher
152 * looks like a bug if CGI requests are blocked unintentionally,
153 * so don't do it unless the user enabled the new config option
154 * "allow-cgi-request-crunching".
156 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
157 * - Use strlcpy() instead of strcpy().
158 * - Stop treating actions files special. Expect a complete file name
159 * (with or without path) like it's done for the rest of the files.
161 * - Remove an unnecessary temporary memory allocation.
162 * - Don't log anything to the console when running as
163 * daemon and no errors occurred.
165 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
166 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
168 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
169 * New config option: enforce-blocks.
171 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
172 * - Mention other reasons why acl directive loading might have failed.
173 * - Don't log the acl source if the acl destination is to blame.
175 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
176 * Add new config option "templdir" to
177 * change the templates directory.
179 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
180 * Added config option accept-intercepted-requests
181 * and disabled it by default.
183 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
184 * Fix gcc43 compiler warnings.
186 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
187 * Add config option "split-large-forms"
188 * to work around the browser bug reported
191 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
192 * Move the <br> in the generated HTML for the config
193 * options from the beginning of the string to its end.
194 * Keeps the white space in balance.
196 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
197 * Fix memory leak in case of config file reloads.
199 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
200 * Modified kludge for win32 to make ming32 menu
201 * "Options/Edit Filters" (sort of) work again.
202 * Same limitations as for the action files apply.
205 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
206 * Incorporate modified version of Roland Rosenfeld's patch to
207 * optionally access the user-manual via Privoxy. Closes patch 679075.
209 * Formatting changed to Privoxy style, added call to
210 * cgi_error_no_template if the requested file doesn't
211 * exist and modified check whether or not Privoxy itself
212 * should serve the manual. Should work cross-platform now.
214 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
215 * Added config option enable-remote-http-toggle
216 * to specify if Privoxy should recognize special
217 * headers (currently only X-Filter) to change its
218 * behaviour. Disabled by default.
220 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
221 * Make number of retries in case of forwarded-connect problems
222 * a config file option (forwarded-connect-retries) and use 0 as
225 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
226 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
227 * with what was really the latest development (the v_3_0_branch branch)
229 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
230 * Don't forget to malloc space for the null terminator...
232 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
233 * Multiple filter file support
235 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
236 * Closed two memory leaks; hopefully the last remaining ones
237 * (in the main execution paths, anyway).
239 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
240 * Addressed bug #719435
241 * - Extraneous filterfile directives now logged as errors
242 * - This and unrecnonised directives now really obvious on status page
244 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
245 * Cosmetic: Renamed cryptic variable
247 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
248 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
250 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
251 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
253 * Revision 1.48 2002/05/14 21:30:38 oes
254 * savearg now uses own linking code instead of (now special-cased) add_help_link
256 * Revision 1.47 2002/05/12 21:36:29 jongfoster
257 * Correcting function comments
259 * Revision 1.46 2002/04/26 12:55:14 oes
260 * - New option "user-manual", defaults to our site
261 * via project.h #define
262 * - savearg now embeds option names in help links
264 * Revision 1.45 2002/04/24 02:11:54 oes
265 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
267 * Revision 1.44 2002/04/08 20:37:13 swa
270 * Revision 1.43 2002/04/08 20:36:50 swa
273 * Revision 1.42 2002/04/05 15:50:15 oes
274 * fix for invalid HTML proxy_args
276 * Revision 1.41 2002/03/31 17:19:00 jongfoster
277 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
279 * Revision 1.40 2002/03/26 22:29:55 swa
280 * we have a new homepage!
282 * Revision 1.39 2002/03/24 13:25:43 swa
283 * name change related issues
285 * Revision 1.38 2002/03/24 13:05:48 jongfoster
286 * Renaming re_filterfile to filterfile
288 * Revision 1.37 2002/03/16 23:54:06 jongfoster
289 * Adding graceful termination feature, to help look for memory leaks.
290 * If you enable this (which, by design, has to be done by hand
291 * editing config.h) and then go to http://i.j.b/die, then the program
292 * will exit cleanly after the *next* request. It should free all the
293 * memory that was used.
295 * Revision 1.36 2002/03/13 00:27:05 jongfoster
298 * Revision 1.35 2002/03/07 03:52:44 oes
299 * Set logging to tty for --no-daemon mode
301 * Revision 1.34 2002/03/06 23:14:35 jongfoster
302 * Trivial cosmetic changes to make function comments easier to find.
304 * Revision 1.33 2002/03/05 04:52:42 oes
305 * Deleted non-errlog debugging code
307 * Revision 1.32 2002/03/04 18:24:53 oes
308 * Re-enabled output of unknown config directive hash
310 * Revision 1.31 2002/03/03 15:07:20 oes
311 * Re-enabled automatic config reloading
313 * Revision 1.30 2002/01/22 23:31:43 jongfoster
314 * Replacing strsav() with string_append()
316 * Revision 1.29 2002/01/17 21:02:30 jongfoster
317 * Moving all our URL and URL pattern parsing code to urlmatch.c.
319 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
321 * Revision 1.28 2001/12/30 14:07:32 steudten
322 * - Add signal handling (unix)
323 * - Add SIGHUP handler (unix)
324 * - Add creation of pidfile (unix)
325 * - Add action 'top' in rc file (RH)
326 * - Add entry 'SIGNALS' to manpage
327 * - Add exit message to logfile (unix)
329 * Revision 1.27 2001/11/07 00:02:13 steudten
330 * Add line number in error output for lineparsing for
331 * actionsfile and configfile.
332 * Special handling for CLF added.
334 * Revision 1.26 2001/11/05 21:41:43 steudten
335 * Add changes to be a real daemon just for unix os.
336 * (change cwd to /, detach from controlling tty, set
337 * process group and session leader to the own process.
339 * Add some fatal-error log message for failed malloc().
340 * Add '-d' if compiled with 'configure --with-debug' to
341 * enable debug output.
343 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
344 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
345 * threads to call select() simultaneously. So, it's time to do a real, live,
346 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
347 * (native). Both versions will work, but using __OS2__ offers multi-threading.
349 * Revision 1.24 2001/10/23 21:40:30 jongfoster
350 * Added support for enable-edit-actions and enable-remote-toggle config
353 * Revision 1.23 2001/10/07 15:36:00 oes
354 * Introduced new config option "buffer-limit"
356 * Revision 1.22 2001/09/22 16:36:59 jongfoster
357 * Removing unused parameter fs from read_config_line()
359 * Revision 1.21 2001/09/16 17:10:43 jongfoster
360 * Moving function savearg() here, since it was the only thing left in
363 * Revision 1.20 2001/07/30 22:08:36 jongfoster
364 * Tidying up #defines:
365 * - All feature #defines are now of the form FEATURE_xxx
366 * - Permanently turned off WIN_GUI_EDIT
367 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
369 * Revision 1.19 2001/07/15 17:45:16 jongfoster
370 * Removing some unused #includes
372 * Revision 1.18 2001/07/13 14:01:14 oes
373 * - Removed all #ifdef PCRS
374 * - Removed vim-settings
376 * Revision 1.17 2001/06/29 13:31:03 oes
377 * - Improved comments
378 * - Fixed (actionsfile) and sorted hashes
379 * - Introduced admin_address and proxy-info-url
380 * as config parameters
381 * - Renamed config->proxy_args_invocation (which didn't have
382 * the invocation but the options!) to config->proxy_args
383 * - Various adaptions
384 * - Removed logentry from cancelled commit
386 * Revision 1.16 2001/06/09 10:55:28 jongfoster
387 * Changing BUFSIZ ==> BUFFER_SIZE
389 * Revision 1.15 2001/06/07 23:13:40 jongfoster
390 * Merging ACL and forward files into config file.
391 * Cosmetic: Sorting config file options alphabetically.
392 * Cosmetic: Adding brief syntax comments to config file options.
394 * Revision 1.14 2001/06/07 14:46:25 joergs
395 * Missing make_path() added for re_filterfile.
397 * Revision 1.13 2001/06/05 22:33:54 jongfoster
399 * Fixed minor memory leak.
400 * Also now uses make_path to prepend the pathnames.
402 * Revision 1.12 2001/06/05 20:04:09 jongfoster
403 * Now uses _snprintf() in place of snprintf() under Win32.
405 * Revision 1.11 2001/06/04 18:31:58 swa
406 * files are now prefixed with either `confdir' or `logdir'.
407 * `make redhat-dist' replaces both entries confdir and logdir
410 * Revision 1.10 2001/06/03 19:11:54 oes
411 * introduced confdir option
413 * Revision 1.9 2001/06/01 20:06:24 jongfoster
414 * Removed support for "tinygif" option - moved to actions file.
416 * Revision 1.8 2001/05/31 21:27:13 jongfoster
417 * Removed many options from the config file and into the
418 * "actions" file: add_forwarded, suppress_vanilla_wafer,
419 * wafer, add_header, user_agent, referer, from
420 * Also globally replaced "permission" with "action".
422 * Revision 1.7 2001/05/29 09:50:24 jongfoster
423 * Unified blocklist/imagelist/permissionslist.
424 * File format is still under discussion, but the internal changes
427 * Also modified interceptor behaviour:
428 * - We now intercept all URLs beginning with one of the following
429 * prefixes (and *only* these prefixes):
431 * * http://ijbswa.sf.net/config/
432 * * http://ijbswa.sourceforge.net/config/
433 * - New interceptors "home page" - go to http://i.j.b/ to see it.
434 * - Internal changes so that intercepted and fast redirect pages
435 * are not replaced with an image.
436 * - Interceptors now have the option to send a binary page direct
437 * to the client. (i.e. ijb-send-banner uses this)
438 * - Implemented show-url-info interceptor. (Which is why I needed
439 * the above interceptors changes - a typical URL is
440 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
441 * The previous mechanism would not have intercepted that, and
442 * if it had been intercepted then it then it would have replaced
445 * Revision 1.6 2001/05/26 00:28:36 jongfoster
446 * Automatic reloading of config file.
447 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
448 * Most of the global variables have been moved to a new
449 * struct configuration_spec, accessed through csp->config->globalname
450 * Most of the globals remaining are used by the Win32 GUI.
452 * Revision 1.5 2001/05/25 22:34:30 jongfoster
455 * Revision 1.4 2001/05/22 18:46:04 oes
457 * - Enabled filtering banners by size rather than URL
458 * by adding patterns that replace all standard banner
459 * sizes with the "Junkbuster" gif to the re_filterfile
461 * - Enabled filtering WebBugs by providing a pattern
462 * which kills all 1x1 images
464 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
465 * which is selected by the (nonstandard and therefore
466 * capital) letter 'U' in the option string.
467 * It causes the quantifiers to be ungreedy by default.
468 * Appending a ? turns back to greedy (!).
470 * - Added a new interceptor ijb-send-banner, which
471 * sends back the "Junkbuster" gif. Without imagelist or
472 * MSIE detection support, or if tinygif = 1, or the
473 * URL isn't recognized as an imageurl, a lame HTML
474 * explanation is sent instead.
476 * - Added new feature, which permits blocking remote
477 * script redirects and firing back a local redirect
479 * The feature is conditionally compiled, i.e. it
480 * can be disabled with --disable-fast-redirects,
481 * plus it must be activated by a "fast-redirects"
482 * line in the config file, has its own log level
483 * and of course wants to be displayed by show-proxy-args
484 * Note: Boy, all the #ifdefs in 1001 locations and
485 * all the fumbling with configure.in and acconfig.h
486 * were *way* more work than the feature itself :-(
488 * - Because a generic redirect template was needed for
489 * this, tinygif = 3 now uses the same.
491 * - Moved GIFs, and other static HTTP response templates
496 * - Removed some >400 CRs again (Jon, you really worked
499 * Revision 1.3 2001/05/20 01:21:20 jongfoster
500 * Version 2.9.4 checkin.
501 * - Merged popupfile and cookiefile, and added control over PCRS
502 * filtering, in new "permissionsfile".
503 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
504 * file error you now get a message box (in the Win32 GUI) rather
505 * than the program exiting with no explanation.
506 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
508 * - Removed tabs from "config"
509 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
510 * - Bumped up version number.
512 * Revision 1.2 2001/05/17 23:01:01 oes
513 * - Cleaned CRLF's from the sources and related files
515 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
516 * Initial import of version 2.9.3 source tree
519 *********************************************************************/
525 #include <sys/types.h>
539 # include <windows.h>
542 # ifndef _WIN_CONSOLE
544 # endif /* ndef _WIN_CONSOLE */
546 #else /* ifndef _WIN32 */
550 # include <sys/wait.h>
552 # include <sys/time.h>
553 # include <sys/stat.h>
563 #include "miscutil.h"
567 #include "urlmatch.h"
571 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
574 * Fix a problem with Solaris. There should be no effect on other
576 * Solaris's isspace() is a macro which uses it's argument directly
577 * as an array index. Therefore we need to make sure that high-bit
578 * characters generate +ve values, and ideally we also want to make
579 * the argument match the declared parameter type of "int".
581 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
582 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
584 #ifdef FEATURE_TOGGLE
585 /* Privoxy is enabled by default. */
586 int global_toggle_state = 1;
587 #endif /* def FEATURE_TOGGLE */
589 /* The filename of the configfile */
590 const char *configfile = NULL;
593 * CGI functions will later need access to the invocation args,
594 * so we will make argc and argv global.
597 const char **Argv = NULL;
599 static struct file_list *current_configfile = NULL;
603 * This takes the "cryptic" hash of each keyword and aliases them to
604 * something a little more readable. This also makes changing the
605 * hash values easier if they should change or the hash algorthm changes.
606 * Use the included "hash" program to find out what the hash will be
607 * for any string supplied on the command line. (Or just put it in the
608 * config file and read the number from the error message in the log).
610 * Please keep this list sorted alphabetically (but with the Windows
611 * console and GUI specific options last).
614 #define hash_actions_file 1196306641ul /* "actionsfile" */
615 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
616 #define hash_admin_address 4112573064ul /* "admin-address" */
617 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
618 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
619 #define hash_confdir 1978389ul /* "confdir" */
620 #define hash_debug 78263ul /* "debug" */
621 #define hash_deny_access 1227333715ul /* "deny-access" */
622 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
623 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
624 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
625 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
626 #define hash_filterfile 250887266ul /* "filterfile" */
627 #define hash_forward 2029845ul /* "forward" */
628 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
629 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
630 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
631 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
632 #define hash_hostname 10308071ul /* "hostname" */
633 #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */
634 #define hash_listen_address 1255650842ul /* "listen-address" */
635 #define hash_logdir 422889ul /* "logdir" */
636 #define hash_logfile 2114766ul /* "logfile" */
637 #define hash_permit_access 3587953268ul /* "permit-access" */
638 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
639 #define hash_single_threaded 4250084780ul /* "single-threaded" */
640 #define hash_socket_timeout 1809001761ul /* "socket-timeout" */
641 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
642 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
643 #define hash_templdir 11067889ul /* "templdir" */
644 #define hash_toggle 447966ul /* "toggle" */
645 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
646 #define hash_trustfile 56494766ul /* "trustfile" */
647 #define hash_usermanual 1416668518ul /* "user-manual" */
648 #define hash_activity_animation 1817904738ul /* "activity-animation" */
649 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
650 #define hash_hide_console 2048809870ul /* "hide-console" */
651 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
652 #define hash_log_font_name 2866730124ul /* "log-font-name" */
653 #define hash_log_font_size 2866731014ul /* "log-font-size" */
654 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
655 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
656 #define hash_log_messages 2291744899ul /* "log-messages" */
657 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
660 static void savearg(char *command, char *argument, struct configuration_spec * config);
662 /*********************************************************************
664 * Function : unload_configfile
666 * Description : Free the config structure and all components.
669 * 1 : data: struct configuration_spec to unload
673 *********************************************************************/
674 static void unload_configfile (void * data)
676 struct configuration_spec * config = (struct configuration_spec *)data;
677 struct forward_spec *cur_fwd = config->forward;
681 struct access_control_list *cur_acl = config->acl;
683 while (cur_acl != NULL)
685 struct access_control_list * next_acl = cur_acl->next;
690 #endif /* def FEATURE_ACL */
692 while (cur_fwd != NULL)
694 struct forward_spec * next_fwd = cur_fwd->next;
695 free_url_spec(cur_fwd->url);
697 freez(cur_fwd->gateway_host);
698 freez(cur_fwd->forward_host);
702 config->forward = NULL;
704 freez(config->confdir);
705 freez(config->logdir);
706 freez(config->templdir);
707 freez(config->hostname);
709 freez(config->haddr);
710 freez(config->logfile);
712 for (i = 0; i < MAX_AF_FILES; i++)
714 freez(config->actions_file_short[i]);
715 freez(config->actions_file[i]);
716 freez(config->re_filterfile_short[i]);
717 freez(config->re_filterfile[i]);
720 freez(config->admin_address);
721 freez(config->proxy_info_url);
722 freez(config->proxy_args);
723 freez(config->usermanual);
726 freez(config->trustfile);
727 list_remove_all(config->trust_info);
728 #endif /* def FEATURE_TRUST */
730 for (i = 0; i < MAX_AF_FILES; i++)
732 freez(config->re_filterfile[i]);
739 #ifdef FEATURE_GRACEFUL_TERMINATION
740 /*********************************************************************
742 * Function : unload_current_config_file
744 * Description : Unloads current config file - reset to state at
745 * beginning of program.
751 *********************************************************************/
752 void unload_current_config_file(void)
754 if (current_configfile)
756 current_configfile->unloader = unload_configfile;
757 current_configfile = NULL;
763 /*********************************************************************
765 * Function : load_config
767 * Description : Load the config file and all parameters.
769 * XXX: more than thousand lines long
770 * and thus in serious need of refactoring.
774 * Returns : The configuration_spec, or NULL on error.
776 *********************************************************************/
777 struct configuration_spec * load_config(void)
779 char buf[BUFFER_SIZE];
781 FILE *configfp = NULL;
782 struct configuration_spec * config = NULL;
783 struct client_state * fake_csp;
784 struct file_list *fs;
785 unsigned long linenum = 0;
787 char *logfile = NULL;
788 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
789 int keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
792 if (!check_file_changed(current_configfile, configfile, &fs))
794 /* No need to load */
795 return ((struct configuration_spec *)current_configfile->f);
799 log_error(LOG_LEVEL_FATAL,
800 "can't check configuration file '%s': %E", configfile);
804 if (NULL != current_configfile)
806 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
809 #ifdef FEATURE_TOGGLE
810 global_toggle_state = 1;
811 #endif /* def FEATURE_TOGGLE */
813 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
819 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
824 * This is backwards from how it's usually done.
825 * Following the usual pattern, "fs" would be stored in a member
826 * variable in "csp", and then we'd access "config" from "fs->f",
827 * using a cast. However, "config" is used so often that a
828 * cast each time would be very ugly, and the extra indirection
829 * would waste CPU cycles. Therefore we store "config" in
830 * "csp->config", and "fs" in "csp->config->config_file_list".
832 config->config_file_list = fs;
837 config->multi_threaded = 1;
838 config->buffer_limit = 4096 * 1024;
839 config->usermanual = strdup(USER_MANUAL_URL);
840 config->proxy_args = strdup("");
841 config->forwarded_connect_retries = 0;
842 config->socket_timeout = 300; /* XXX: Should be a macro. */
843 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
844 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
845 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
847 configfp = fopen(configfile, "r");
848 if (NULL == configfp)
850 log_error(LOG_LEVEL_FATAL,
851 "can't open configuration file '%s': %E", configfile);
852 /* Never get here - LOG_LEVEL_FATAL causes program exit */
855 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
857 char cmd[BUFFER_SIZE];
858 char arg[BUFFER_SIZE];
859 char tmp[BUFFER_SIZE];
861 struct access_control_list *cur_acl;
862 #endif /* def FEATURE_ACL */
863 struct forward_spec *cur_fwd;
866 unsigned long directive_hash;
868 strlcpy(tmp, buf, sizeof(tmp));
870 /* Copy command (i.e. up to space or tab) into cmd */
873 while (*p && (*p != ' ') && (*p != '\t'))
879 /* Skip over the whitespace in buf */
880 while (*p && ((*p == ' ') || (*p == '\t')))
885 /* Copy the argument into arg */
886 strlcpy(arg, p, sizeof(arg));
888 /* Should never happen, but check this anyway */
894 /* Make sure the command field is lower case */
895 for (p = cmd; *p; p++)
899 *p = (char)ijb_tolower(*p);
903 directive_hash = hash_string(cmd);
904 switch (directive_hash)
906 /* *************************************************************************
907 * actionsfile actions-file-name
908 * In confdir by default
909 * *************************************************************************/
910 case hash_actions_file :
912 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
917 if (i >= MAX_AF_FILES)
919 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
920 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
923 config->actions_file_short[i] = strdup(arg);
924 config->actions_file[i] = make_path(config->confdir, arg);
927 /* *************************************************************************
928 * accept-intercepted-requests
929 * *************************************************************************/
930 case hash_accept_intercepted_requests:
931 if ((*arg != '\0') && (0 != atoi(arg)))
933 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
937 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
941 /* *************************************************************************
942 * admin-address email-address
943 * *************************************************************************/
944 case hash_admin_address :
945 freez(config->admin_address);
946 config->admin_address = strdup(arg);
949 /* *************************************************************************
950 * allow-cgi-request-crunching
951 * *************************************************************************/
952 case hash_allow_cgi_request_crunching:
953 if ((*arg != '\0') && (0 != atoi(arg)))
955 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
959 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
963 /* *************************************************************************
965 * *************************************************************************/
966 case hash_buffer_limit :
967 config->buffer_limit = (size_t)(1024 * atoi(arg));
970 /* *************************************************************************
971 * confdir directory-name
972 * *************************************************************************/
974 freez(config->confdir);
975 config->confdir = make_path( NULL, arg);
978 /* *************************************************************************
980 * Specifies debug level, multiple values are ORed together.
981 * *************************************************************************/
983 config->debug |= atoi(arg);
986 /* *************************************************************************
987 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
988 * *************************************************************************/
990 case hash_deny_access:
991 strlcpy(tmp, arg, sizeof(tmp));
992 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
994 if ((vec_count != 1) && (vec_count != 2))
996 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
997 "deny-access directive in configuration file.");
998 string_append(&config->proxy_args,
999 "<br>\nWARNING: Wrong number of parameters for "
1000 "deny-access directive in configuration file.<br><br>\n");
1004 /* allocate a new node */
1005 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1007 if (cur_acl == NULL)
1009 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1010 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1013 cur_acl->action = ACL_DENY;
1015 if (acl_addr(vec[0], cur_acl->src) < 0)
1017 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1018 "for deny-access directive in configuration file: \"%s\"", vec[0]);
1019 string_append(&config->proxy_args,
1020 "<br>\nWARNING: Invalid source address, port or netmask "
1021 "for deny-access directive in configuration file: \"");
1022 string_append(&config->proxy_args,
1024 string_append(&config->proxy_args,
1031 if (acl_addr(vec[1], cur_acl->dst) < 0)
1033 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1034 "for deny-access directive in configuration file: \"%s\"", vec[1]);
1035 string_append(&config->proxy_args,
1036 "<br>\nWARNING: Invalid destination address, port or netmask "
1037 "for deny-access directive in configuration file: \"");
1038 string_append(&config->proxy_args,
1040 string_append(&config->proxy_args,
1046 #ifdef HAVE_GETADDRINFO
1049 cur_acl->wildcard_dst = 1;
1051 #endif /* def HAVE_GETADDRINFO */
1054 * Add it to the list. Note we reverse the list to get the
1055 * behaviour the user expects. With both the ACL and
1056 * actions file, the last match wins. However, the internal
1057 * implementations are different: The actions file is stored
1058 * in the same order as the file, and scanned completely.
1059 * With the ACL, we reverse the order as we load it, then
1060 * when we scan it we stop as soon as we get a match.
1062 cur_acl->next = config->acl;
1063 config->acl = cur_acl;
1066 #endif /* def FEATURE_ACL */
1068 /* *************************************************************************
1069 * enable-edit-actions 0|1
1070 * *************************************************************************/
1071 #ifdef FEATURE_CGI_EDIT_ACTIONS
1072 case hash_enable_edit_actions:
1073 if ((*arg != '\0') && (0 != atoi(arg)))
1075 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1079 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1082 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1084 /* *************************************************************************
1085 * enable-remote-toggle 0|1
1086 * *************************************************************************/
1087 #ifdef FEATURE_TOGGLE
1088 case hash_enable_remote_toggle:
1089 if ((*arg != '\0') && (0 != atoi(arg)))
1091 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1095 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1098 #endif /* def FEATURE_TOGGLE */
1100 /* *************************************************************************
1101 * enable-remote-http-toggle 0|1
1102 * *************************************************************************/
1103 case hash_enable_remote_http_toggle:
1104 if ((*arg != '\0') && (0 != atoi(arg)))
1106 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1110 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1114 /* *************************************************************************
1115 * enforce-blocks 0|1
1116 * *************************************************************************/
1117 case hash_enforce_blocks:
1118 #ifdef FEATURE_FORCE_LOAD
1119 if ((*arg != '\0') && (0 != atoi(arg)))
1121 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1125 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1128 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1129 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1130 #endif /* def FEATURE_FORCE_LOAD */
1133 /* *************************************************************************
1134 * filterfile file-name
1135 * In confdir by default.
1136 * *************************************************************************/
1137 case hash_filterfile :
1139 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1144 if (i >= MAX_AF_FILES)
1146 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1147 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1150 config->re_filterfile_short[i] = strdup(arg);
1151 config->re_filterfile[i] = make_path(config->confdir, arg);
1155 /* *************************************************************************
1156 * forward url-pattern (.|http-proxy-host[:port])
1157 * *************************************************************************/
1159 strlcpy(tmp, arg, sizeof(tmp));
1160 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1164 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1165 "directive in configuration file.");
1166 string_append(&config->proxy_args,
1167 "<br>\nWARNING: Wrong number of parameters for "
1168 "forward directive in configuration file.");
1172 /* allocate a new node */
1173 cur_fwd = zalloc(sizeof(*cur_fwd));
1174 if (cur_fwd == NULL)
1176 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1177 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1181 cur_fwd->type = SOCKS_NONE;
1183 /* Save the URL pattern */
1184 if (create_url_spec(cur_fwd->url, vec[0]))
1186 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1187 "directive in configuration file.");
1188 string_append(&config->proxy_args,
1189 "<br>\nWARNING: Bad URL specifier for "
1190 "forward directive in configuration file.");
1194 /* Parse the parent HTTP proxy host:port */
1197 if (strcmp(p, ".") != 0)
1199 cur_fwd->forward_host = strdup(p);
1201 if (*cur_fwd->forward_host == '[' &&
1202 NULL != (p = strchr(cur_fwd->forward_host, ']')))
1205 memmove(cur_fwd->forward_host, cur_fwd->forward_host + 1,
1206 (size_t) (p - cur_fwd->forward_host));
1209 cur_fwd->forward_port = atoi(++p);
1212 else if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1215 cur_fwd->forward_port = atoi(p);
1218 if (cur_fwd->forward_port <= 0)
1220 cur_fwd->forward_port = 8000;
1225 cur_fwd->next = config->forward;
1226 config->forward = cur_fwd;
1230 /* *************************************************************************
1231 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1232 * *************************************************************************/
1233 case hash_forward_socks4:
1234 strlcpy(tmp, arg, sizeof(tmp));
1235 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1239 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1240 "forward-socks4 directive in configuration file.");
1241 string_append(&config->proxy_args,
1242 "<br>\nWARNING: Wrong number of parameters for "
1243 "forward-socks4 directive in configuration file.");
1247 /* allocate a new node */
1248 cur_fwd = zalloc(sizeof(*cur_fwd));
1249 if (cur_fwd == NULL)
1251 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1252 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1256 cur_fwd->type = SOCKS_4;
1258 /* Save the URL pattern */
1259 if (create_url_spec(cur_fwd->url, vec[0]))
1261 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1262 "directive in configuration file.");
1263 string_append(&config->proxy_args,
1264 "<br>\nWARNING: Bad URL specifier for "
1265 "forward-socks4 directive in configuration file.");
1269 /* Parse the SOCKS proxy host[:port] */
1272 if (strcmp(p, ".") != 0)
1274 cur_fwd->gateway_host = strdup(p);
1276 if (*cur_fwd->gateway_host == '[' &&
1277 NULL != (p = strchr(cur_fwd->gateway_host, ']')))
1280 memmove(cur_fwd->gateway_host, cur_fwd->gateway_host + 1,
1281 (size_t) (p - cur_fwd->gateway_host));
1284 cur_fwd->gateway_port = atoi(++p);
1287 else if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1290 cur_fwd->gateway_port = atoi(p);
1293 if (cur_fwd->gateway_port <= 0)
1295 cur_fwd->gateway_port = 1080;
1299 /* Parse the parent HTTP proxy host[:port] */
1302 if (strcmp(p, ".") != 0)
1304 cur_fwd->forward_host = strdup(p);
1306 if (*cur_fwd->forward_host == '[' &&
1307 NULL != (p = strchr(cur_fwd->forward_host, ']')))
1310 memmove(cur_fwd->forward_host, cur_fwd->forward_host + 1,
1311 (size_t) (p - cur_fwd->forward_host));
1314 cur_fwd->forward_port = atoi(++p);
1317 else if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1320 cur_fwd->forward_port = atoi(p);
1323 if (cur_fwd->forward_port <= 0)
1325 cur_fwd->forward_port = 8000;
1330 cur_fwd->next = config->forward;
1331 config->forward = cur_fwd;
1335 /* *************************************************************************
1336 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1337 * *************************************************************************/
1338 case hash_forward_socks4a:
1339 case hash_forward_socks5:
1340 strlcpy(tmp, arg, sizeof(tmp));
1341 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1345 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1346 "forward-socks4a directive in configuration file.");
1347 string_append(&config->proxy_args,
1348 "<br>\nWARNING: Wrong number of parameters for "
1349 "forward-socks4a directive in configuration file.");
1353 /* allocate a new node */
1354 cur_fwd = zalloc(sizeof(*cur_fwd));
1355 if (cur_fwd == NULL)
1357 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1358 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1362 if (directive_hash == hash_forward_socks4a)
1364 cur_fwd->type = SOCKS_4A;
1368 cur_fwd->type = SOCKS_5;
1371 /* Save the URL pattern */
1372 if (create_url_spec(cur_fwd->url, vec[0]))
1374 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1375 "directive in configuration file.");
1376 string_append(&config->proxy_args,
1377 "<br>\nWARNING: Bad URL specifier for "
1378 "forward-socks4a directive in configuration file.");
1382 /* Parse the SOCKS proxy host[:port] */
1385 cur_fwd->gateway_host = strdup(p);
1387 if (*cur_fwd->gateway_host == '[' &&
1388 NULL != (p = strchr(cur_fwd->gateway_host, ']')))
1391 memmove(cur_fwd->gateway_host, cur_fwd->gateway_host + 1,
1392 (size_t) (p - cur_fwd->gateway_host));
1395 cur_fwd->gateway_port = atoi(++p);
1398 else if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1401 cur_fwd->gateway_port = atoi(p);
1404 if (cur_fwd->gateway_port <= 0)
1406 cur_fwd->gateway_port = 1080;
1409 /* Parse the parent HTTP proxy host[:port] */
1412 if (strcmp(p, ".") != 0)
1414 cur_fwd->forward_host = strdup(p);
1416 if (*cur_fwd->forward_host == '[' &&
1417 NULL != (p = strchr(cur_fwd->forward_host, ']')))
1420 memmove(cur_fwd->forward_host, cur_fwd->forward_host + 1,
1421 (size_t) (p - cur_fwd->forward_host));
1424 cur_fwd->forward_port = atoi(++p);
1427 else if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1430 cur_fwd->forward_port = atoi(p);
1433 if (cur_fwd->forward_port <= 0)
1435 cur_fwd->forward_port = 8000;
1440 cur_fwd->next = config->forward;
1441 config->forward = cur_fwd;
1445 /* *************************************************************************
1446 * forwarded-connect-retries n
1447 * *************************************************************************/
1448 case hash_forwarded_connect_retries :
1449 config->forwarded_connect_retries = atoi(arg);
1452 /* *************************************************************************
1453 * hostname hostname-to-show-on-cgi-pages
1454 * *************************************************************************/
1455 case hash_hostname :
1456 freez(config->hostname);
1457 config->hostname = strdup(arg);
1458 if (NULL == config->hostname)
1460 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1464 /* *************************************************************************
1465 * keep-alive-timeout timeout
1466 * *************************************************************************/
1467 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1468 case hash_keep_alive_timeout :
1471 int timeout = atoi(arg);
1474 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1475 keep_alive_timeout = timeout;
1479 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1485 /* *************************************************************************
1486 * listen-address [ip][:port]
1487 * *************************************************************************/
1488 case hash_listen_address :
1489 freez(config->haddr);
1490 config->haddr = strdup(arg);
1493 /* *************************************************************************
1494 * logdir directory-name
1495 * *************************************************************************/
1497 freez(config->logdir);
1498 config->logdir = make_path(NULL, arg);
1501 /* *************************************************************************
1502 * logfile log-file-name
1503 * In logdir by default
1504 * *************************************************************************/
1508 logfile = make_path(config->logdir, arg);
1509 if (NULL == logfile)
1511 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1516 /* *************************************************************************
1517 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1518 * *************************************************************************/
1520 case hash_permit_access:
1521 strlcpy(tmp, arg, sizeof(tmp));
1522 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1524 if ((vec_count != 1) && (vec_count != 2))
1526 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1527 "permit-access directive in configuration file.");
1528 string_append(&config->proxy_args,
1529 "<br>\nWARNING: Wrong number of parameters for "
1530 "permit-access directive in configuration file.<br><br>\n");
1535 /* allocate a new node */
1536 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1538 if (cur_acl == NULL)
1540 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1541 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1544 cur_acl->action = ACL_PERMIT;
1546 if (acl_addr(vec[0], cur_acl->src) < 0)
1548 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1549 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1550 string_append(&config->proxy_args,
1551 "<br>\nWARNING: Invalid source address, port or netmask for "
1552 "permit-access directive in configuration file: \"");
1553 string_append(&config->proxy_args,
1555 string_append(&config->proxy_args,
1562 if (acl_addr(vec[1], cur_acl->dst) < 0)
1564 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1565 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1566 string_append(&config->proxy_args,
1567 "<br>\nWARNING: Invalid destination address, port or netmask for "
1568 "permit-access directive in configuration file: \"");
1569 string_append(&config->proxy_args,
1571 string_append(&config->proxy_args,
1577 #ifdef HAVE_GETADDRINFO
1580 cur_acl->wildcard_dst = 1;
1582 #endif /* def HAVE_GETADDRINFO */
1585 * Add it to the list. Note we reverse the list to get the
1586 * behaviour the user expects. With both the ACL and
1587 * actions file, the last match wins. However, the internal
1588 * implementations are different: The actions file is stored
1589 * in the same order as the file, and scanned completely.
1590 * With the ACL, we reverse the order as we load it, then
1591 * when we scan it we stop as soon as we get a match.
1593 cur_acl->next = config->acl;
1594 config->acl = cur_acl;
1597 #endif /* def FEATURE_ACL */
1599 /* *************************************************************************
1600 * proxy-info-url url
1601 * *************************************************************************/
1602 case hash_proxy_info_url :
1603 freez(config->proxy_info_url);
1604 config->proxy_info_url = strdup(arg);
1607 /* *************************************************************************
1609 * *************************************************************************/
1610 case hash_single_threaded :
1611 config->multi_threaded = 0;
1614 /* *************************************************************************
1615 * socket-timeout numer_of_seconds
1616 * *************************************************************************/
1617 case hash_socket_timeout :
1620 int socket_timeout = atoi(arg);
1621 if (0 < socket_timeout)
1623 config->socket_timeout = socket_timeout;
1627 log_error(LOG_LEVEL_FATAL,
1628 "Invalid socket-timeout: '%s'", arg);
1633 /* *************************************************************************
1634 * split-large-cgi-forms
1635 * *************************************************************************/
1636 case hash_split_large_cgi_forms :
1637 if ((*arg != '\0') && (0 != atoi(arg)))
1639 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1643 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1647 /* *************************************************************************
1648 * templdir directory-name
1649 * *************************************************************************/
1650 case hash_templdir :
1651 freez(config->templdir);
1652 config->templdir = make_path(NULL, arg);
1655 /* *************************************************************************
1657 * *************************************************************************/
1658 #ifdef FEATURE_TOGGLE
1660 global_toggle_state = atoi(arg);
1662 #endif /* def FEATURE_TOGGLE */
1664 /* *************************************************************************
1665 * trust-info-url url
1666 * *************************************************************************/
1667 #ifdef FEATURE_TRUST
1668 case hash_trust_info_url :
1669 enlist(config->trust_info, arg);
1671 #endif /* def FEATURE_TRUST */
1673 /* *************************************************************************
1674 * trustfile filename
1675 * (In confdir by default.)
1676 * *************************************************************************/
1677 #ifdef FEATURE_TRUST
1678 case hash_trustfile :
1679 freez(config->trustfile);
1680 config->trustfile = make_path(config->confdir, arg);
1682 #endif /* def FEATURE_TRUST */
1684 /* *************************************************************************
1686 * *************************************************************************/
1687 case hash_usermanual :
1689 * XXX: If this isn't the first config directive, the
1690 * show-status page links to the website documentation
1691 * for the directives that were already parsed. Lame.
1693 freez(config->usermanual);
1694 config->usermanual = strdup(arg);
1697 /* *************************************************************************
1698 * Win32 Console options:
1699 * *************************************************************************/
1701 /* *************************************************************************
1703 * *************************************************************************/
1705 case hash_hide_console :
1708 #endif /*def _WIN_CONSOLE*/
1711 /* *************************************************************************
1712 * Win32 GUI options:
1713 * *************************************************************************/
1715 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1716 /* *************************************************************************
1717 * activity-animation (0|1)
1718 * *************************************************************************/
1719 case hash_activity_animation :
1720 g_bShowActivityAnimation = atoi(arg);
1723 /* *************************************************************************
1724 * close-button-minimizes (0|1)
1725 * *************************************************************************/
1726 case hash_close_button_minimizes :
1727 g_bCloseHidesWindow = atoi(arg);
1730 /* *************************************************************************
1731 * log-buffer-size (0|1)
1732 * *************************************************************************/
1733 case hash_log_buffer_size :
1734 g_bLimitBufferSize = atoi(arg);
1737 /* *************************************************************************
1738 * log-font-name fontname
1739 * *************************************************************************/
1740 case hash_log_font_name :
1741 if (strlcpy(g_szFontFaceName, arg,
1742 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1744 log_error(LOG_LEVEL_FATAL,
1745 "log-font-name argument '%s' is longer than %u characters.",
1746 arg, sizeof(g_szFontFaceName)-1);
1750 /* *************************************************************************
1752 * *************************************************************************/
1753 case hash_log_font_size :
1754 g_nFontSize = atoi(arg);
1757 /* *************************************************************************
1758 * log-highlight-messages (0|1)
1759 * *************************************************************************/
1760 case hash_log_highlight_messages :
1761 g_bHighlightMessages = atoi(arg);
1764 /* *************************************************************************
1766 * *************************************************************************/
1767 case hash_log_max_lines :
1768 g_nMaxBufferLines = atoi(arg);
1771 /* *************************************************************************
1772 * log-messages (0|1)
1773 * *************************************************************************/
1774 case hash_log_messages :
1775 g_bLogMessages = atoi(arg);
1778 /* *************************************************************************
1779 * show-on-task-bar (0|1)
1780 * *************************************************************************/
1781 case hash_show_on_task_bar :
1782 g_bShowOnTaskBar = atoi(arg);
1785 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1788 /* *************************************************************************
1789 * Warnings about unsupported features
1790 * *************************************************************************/
1792 case hash_deny_access:
1793 #endif /* ndef FEATURE_ACL */
1794 #ifndef FEATURE_CGI_EDIT_ACTIONS
1795 case hash_enable_edit_actions:
1796 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1797 #ifndef FEATURE_TOGGLE
1798 case hash_enable_remote_toggle:
1799 #endif /* ndef FEATURE_TOGGLE */
1801 case hash_permit_access:
1802 #endif /* ndef FEATURE_ACL */
1803 #ifndef FEATURE_TOGGLE
1805 #endif /* ndef FEATURE_TOGGLE */
1806 #ifndef FEATURE_TRUST
1807 case hash_trustfile :
1808 case hash_trust_info_url :
1809 #endif /* ndef FEATURE_TRUST */
1811 #ifndef _WIN_CONSOLE
1812 case hash_hide_console :
1813 #endif /* ndef _WIN_CONSOLE */
1815 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1816 case hash_activity_animation :
1817 case hash_close_button_minimizes :
1818 case hash_log_buffer_size :
1819 case hash_log_font_name :
1820 case hash_log_font_size :
1821 case hash_log_highlight_messages :
1822 case hash_log_max_lines :
1823 case hash_log_messages :
1824 case hash_show_on_task_bar :
1825 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1826 /* These warnings are annoying - so hide them. -- Jon */
1827 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1830 /* *************************************************************************/
1832 /* *************************************************************************/
1834 * I decided that I liked this better as a warning than an
1835 * error. To change back to an error, just change log level
1836 * to LOG_LEVEL_FATAL.
1838 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1839 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1840 string_append(&config->proxy_args,
1841 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1844 /* *************************************************************************/
1845 } /* end switch( hash_string(cmd) ) */
1847 /* Save the argument for the show-status page. */
1848 savearg(cmd, arg, config);
1850 } /* end while ( read_config_line(...) ) */
1854 set_debug_level(config->debug);
1856 freez(config->logfile);
1860 if (NULL != logfile)
1862 config->logfile = logfile;
1863 init_error_log(Argv[0], config->logfile);
1871 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1872 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1874 if (config->multi_threaded)
1876 set_keep_alive_timeout(keep_alive_timeout);
1881 * While we could use keep-alive without multiple threads
1882 * if we didn't bother with enforcing the connection timeout,
1883 * that might make Tor users sad, even though they shouldn't
1884 * enable the single-threaded option anyway.
1886 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1887 log_error(LOG_LEVEL_ERROR,
1888 "Config option single-threaded disables connection keep-alive.");
1893 if (NULL == config->proxy_args)
1895 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1898 if (config->actions_file[0])
1900 add_loader(load_action_files, config);
1903 if (config->re_filterfile[0])
1905 add_loader(load_re_filterfiles, config);
1908 #ifdef FEATURE_TRUST
1909 if (config->trustfile)
1911 add_loader(load_trustfile, config);
1913 #endif /* def FEATURE_TRUST */
1915 if ( NULL == config->haddr )
1917 config->haddr = strdup( HADDR_DEFAULT );
1920 if ( NULL != config->haddr )
1922 if (*config->haddr == '[' && NULL != (p = strchr(config->haddr, ']')) &&
1923 p[1] == ':' && 0 < (config->hport = atoi(p + 2)))
1926 memmove((void *) config->haddr, config->haddr + 1,
1927 (size_t) (p - config->haddr));
1929 else if (NULL != (p = strchr(config->haddr, ':')) &&
1930 0 < (config->hport = atoi(p + 1)))
1936 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1937 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1939 if (*config->haddr == '\0')
1942 * Only the port specified. We stored it in config->hport
1943 * and don't need its text representation anymore.
1945 freez(config->haddr);
1950 * Want to run all the loaders once now.
1952 * Need to set up a fake csp, so they can get to the config.
1954 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1955 fake_csp->config = config;
1957 if (run_loader(fake_csp))
1960 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1961 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1965 /* FIXME: this is a kludge for win32 */
1966 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1968 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1969 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1970 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1972 #ifdef FEATURE_TRUST
1973 g_trustfile = config->trustfile;
1974 #endif /* def FEATURE_TRUST */
1977 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1978 /* FIXME: end kludge */
1981 config->need_bind = 1;
1983 if (current_configfile)
1985 struct configuration_spec * oldcfg = (struct configuration_spec *)
1986 current_configfile->f;
1988 * Check if config->haddr,hport == oldcfg->haddr,hport
1990 * The following could be written more compactly as a single,
1991 * (unreadably long) if statement.
1993 config->need_bind = 0;
1994 if (config->hport != oldcfg->hport)
1996 config->need_bind = 1;
1998 else if (config->haddr == NULL)
2000 if (oldcfg->haddr != NULL)
2002 config->need_bind = 1;
2005 else if (oldcfg->haddr == NULL)
2007 config->need_bind = 1;
2009 else if (0 != strcmp(config->haddr, oldcfg->haddr))
2011 config->need_bind = 1;
2014 current_configfile->unloader = unload_configfile;
2017 fs->next = files->next;
2020 current_configfile = fs;
2026 /*********************************************************************
2028 * Function : savearg
2030 * Description : Called from `load_config'. It saves each non-empty
2031 * and non-comment line from config into
2032 * config->proxy_args. This is used to create the
2033 * show-proxy-args page. On error, frees
2034 * config->proxy_args and sets it to NULL
2037 * 1 : command = config setting that was found
2038 * 2 : argument = the setting's argument (if any)
2039 * 3 : config = Configuration to save into.
2043 *********************************************************************/
2044 static void savearg(char *command, char *argument, struct configuration_spec * config)
2053 * Add config option name embedded in
2054 * link to its section in the user-manual
2056 buf = strdup("\n<a href=\"");
2057 if (!strncmpic(config->usermanual, "file://", 7) ||
2058 !strncmpic(config->usermanual, "http", 4))
2060 string_append(&buf, config->usermanual);
2064 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
2066 string_append(&buf, CONFIG_HELP_PREFIX);
2067 string_join (&buf, string_toupper(command));
2068 string_append(&buf, "\">");
2069 string_append(&buf, command);
2070 string_append(&buf, "</a> ");
2074 freez(config->proxy_args);
2078 if ( (NULL != argument) && ('\0' != *argument) )
2080 s = html_encode(argument);
2084 freez(config->proxy_args);
2088 if (strncmpic(argument, "http://", 7) == 0)
2090 string_append(&buf, "<a href=\"");
2091 string_append(&buf, s);
2092 string_append(&buf, "\">");
2093 string_join (&buf, s);
2094 string_append(&buf, "</a>");
2098 string_join (&buf, s);
2102 string_append(&buf, "<br>");
2103 string_join(&config->proxy_args, buf);
2112 vim:softtabstop=3 shiftwidth=3