1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.92 2009/03/18 20:43:19 fabiankeil Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
6 * Purpose : Loads settings from the configuration file into
7 * global variables. This file contains both the
8 * routine to load the configuration and the global
9 * variables it writes to.
11 * Copyright : Written by and Copyright (C) 2001-2009 the
12 * Privoxy team. http://www.privoxy.org/
14 * Based on the Internet Junkbuster originally written
15 * by and Copyright (C) 1997 Anonymous Coders and
16 * Junkbusters Corporation. http://www.junkbusters.com
18 * This program is free software; you can redistribute it
19 * and/or modify it under the terms of the GNU General
20 * Public License as published by the Free Software
21 * Foundation; either version 2 of the License, or (at
22 * your option) any later version.
24 * This program is distributed in the hope that it will
25 * be useful, but WITHOUT ANY WARRANTY; without even the
26 * implied warranty of MERCHANTABILITY or FITNESS FOR A
27 * PARTICULAR PURPOSE. See the GNU General Public
28 * License for more details.
30 * The GNU General Public License should be included with
31 * this file. If not, you can view it at
32 * http://www.gnu.org/copyleft/gpl.html
33 * or write to the Free Software Foundation, Inc., 59
34 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 * Revision 1.92 2009/03/18 20:43:19 fabiankeil
39 * Don't enable LOG_LEVEL_INFO by default and don't apply the user's
40 * debug settings until the logfile has been opened (if there is one).
41 * Patch submitted by Roland in #2624120.
43 * Revision 1.91 2009/03/09 17:29:08 fabiankeil
44 * As of r1.88, the show-status page can use a single line for
45 * warnings about ignored directives and the names of the ignored
46 * directives themselves. Reminded by Lee, finally closes #1856559.
48 * Revision 1.90 2009/03/07 17:58:02 fabiankeil
49 * Fix two mingw32-only buffer overflows. Note that triggering
50 * them requires control over the configuration file in which
51 * case all bets are off anyway.
53 * Revision 1.89 2009/03/01 18:46:33 fabiankeil
54 * - Help clang understand that we aren't
55 * dereferencing NULL pointers here.
56 * - Some style fixes in the modified region.
58 * Revision 1.88 2009/02/28 10:57:10 fabiankeil
59 * Gimme a break or two. Don't let the show-status page
60 * link to the website documentation for the user-manual
63 * Revision 1.87 2009/02/15 07:56:13 fabiankeil
64 * Increase default socket timeout to 300 seconds.
66 * Revision 1.86 2009/02/08 19:18:57 fabiankeil
67 * Now that we have the match-all.action file, the other action
68 * files changed their position in config->actions_file[] back
69 * to the way it was before standard.action got removed and the
70 * changes from revision 1.84 have to be reverted.
72 * Revision 1.85 2009/01/22 12:06:26 fabiankeil
73 * Don't keep connections alive when running single-threaded.
75 * Revision 1.84 2009/01/14 16:14:36 fabiankeil
76 * Due to the standard.action file removal, the other action
77 * files changed their position in config->actions_file[].
78 * Update mingw32 kludge accordingly.
80 * Revision 1.83 2008/12/20 14:53:55 fabiankeil
81 * Add config option socket-timeout to control the time
82 * Privoxy waits for data to arrive on a socket. Useful
83 * in case of stale ssh tunnels or when fuzz-testing.
85 * Revision 1.82 2008/11/16 12:43:49 fabiankeil
86 * Turn keep-alive support into a runtime feature
87 * that is disabled by setting keep-alive-timeout
88 * to a negative value.
90 * Revision 1.81 2008/11/13 09:08:42 fabiankeil
91 * Add new config option: keep-alive-timeout.
93 * Revision 1.80 2008/08/31 15:59:03 fabiankeil
94 * There's no reason to let remote toggling support depend
95 * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
97 * Revision 1.79 2008/08/30 12:03:07 fabiankeil
98 * Remove FEATURE_COOKIE_JAR.
100 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
101 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
102 * disabled, log a message that blocks will always be enforced
103 * instead of complaining about an unrecognized directive.
104 * Reported by Pietro Leone.
106 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
107 * Reuse directive_hash and don't hash the same directive twice.
109 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
110 * - Merge three string_append() calls.
111 * - Remove useless assertion.
113 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
114 * Rename load_actions_file() and load_re_filterfile()
115 * as they load multiple files "now".
117 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
118 * Add hostname directive. Closes PR#1918189.
120 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
123 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
124 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
126 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
127 * Reword "unrecognized directive" warning, use better
128 * mark up and add a <br>. Fixes parts of #1856559.
130 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
131 * Plug memory leak if listen-address only specifies the port.
133 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
134 * Relocate daemon-mode-related log messages to make sure
135 * they aren't shown again in case of configuration reloads.
137 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
138 * Plug memory leak introduced with my last commit.
140 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
141 * When in daemon mode, close stderr after the configuration file has been
142 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
144 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
145 * #1763173 from Stefan Huehner: declare unload_configfile() static.
147 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
148 * As Hal noticed, checking dispatch_cgi() as the last cruncher
149 * looks like a bug if CGI requests are blocked unintentionally,
150 * so don't do it unless the user enabled the new config option
151 * "allow-cgi-request-crunching".
153 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
154 * - Use strlcpy() instead of strcpy().
155 * - Stop treating actions files special. Expect a complete file name
156 * (with or without path) like it's done for the rest of the files.
158 * - Remove an unnecessary temporary memory allocation.
159 * - Don't log anything to the console when running as
160 * daemon and no errors occurred.
162 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
163 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
165 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
166 * New config option: enforce-blocks.
168 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
169 * - Mention other reasons why acl directive loading might have failed.
170 * - Don't log the acl source if the acl destination is to blame.
172 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
173 * Add new config option "templdir" to
174 * change the templates directory.
176 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
177 * Added config option accept-intercepted-requests
178 * and disabled it by default.
180 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
181 * Fix gcc43 compiler warnings.
183 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
184 * Add config option "split-large-forms"
185 * to work around the browser bug reported
188 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
189 * Move the <br> in the generated HTML for the config
190 * options from the beginning of the string to its end.
191 * Keeps the white space in balance.
193 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
194 * Fix memory leak in case of config file reloads.
196 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
197 * Modified kludge for win32 to make ming32 menu
198 * "Options/Edit Filters" (sort of) work again.
199 * Same limitations as for the action files apply.
202 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
203 * Incorporate modified version of Roland Rosenfeld's patch to
204 * optionally access the user-manual via Privoxy. Closes patch 679075.
206 * Formatting changed to Privoxy style, added call to
207 * cgi_error_no_template if the requested file doesn't
208 * exist and modified check whether or not Privoxy itself
209 * should serve the manual. Should work cross-platform now.
211 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
212 * Added config option enable-remote-http-toggle
213 * to specify if Privoxy should recognize special
214 * headers (currently only X-Filter) to change its
215 * behaviour. Disabled by default.
217 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
218 * Make number of retries in case of forwarded-connect problems
219 * a config file option (forwarded-connect-retries) and use 0 as
222 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
223 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
224 * with what was really the latest development (the v_3_0_branch branch)
226 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
227 * Don't forget to malloc space for the null terminator...
229 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
230 * Multiple filter file support
232 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
233 * Closed two memory leaks; hopefully the last remaining ones
234 * (in the main execution paths, anyway).
236 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
237 * Addressed bug #719435
238 * - Extraneous filterfile directives now logged as errors
239 * - This and unrecnonised directives now really obvious on status page
241 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
242 * Cosmetic: Renamed cryptic variable
244 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
245 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
247 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
248 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
250 * Revision 1.48 2002/05/14 21:30:38 oes
251 * savearg now uses own linking code instead of (now special-cased) add_help_link
253 * Revision 1.47 2002/05/12 21:36:29 jongfoster
254 * Correcting function comments
256 * Revision 1.46 2002/04/26 12:55:14 oes
257 * - New option "user-manual", defaults to our site
258 * via project.h #define
259 * - savearg now embeds option names in help links
261 * Revision 1.45 2002/04/24 02:11:54 oes
262 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
264 * Revision 1.44 2002/04/08 20:37:13 swa
267 * Revision 1.43 2002/04/08 20:36:50 swa
270 * Revision 1.42 2002/04/05 15:50:15 oes
271 * fix for invalid HTML proxy_args
273 * Revision 1.41 2002/03/31 17:19:00 jongfoster
274 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
276 * Revision 1.40 2002/03/26 22:29:55 swa
277 * we have a new homepage!
279 * Revision 1.39 2002/03/24 13:25:43 swa
280 * name change related issues
282 * Revision 1.38 2002/03/24 13:05:48 jongfoster
283 * Renaming re_filterfile to filterfile
285 * Revision 1.37 2002/03/16 23:54:06 jongfoster
286 * Adding graceful termination feature, to help look for memory leaks.
287 * If you enable this (which, by design, has to be done by hand
288 * editing config.h) and then go to http://i.j.b/die, then the program
289 * will exit cleanly after the *next* request. It should free all the
290 * memory that was used.
292 * Revision 1.36 2002/03/13 00:27:05 jongfoster
295 * Revision 1.35 2002/03/07 03:52:44 oes
296 * Set logging to tty for --no-daemon mode
298 * Revision 1.34 2002/03/06 23:14:35 jongfoster
299 * Trivial cosmetic changes to make function comments easier to find.
301 * Revision 1.33 2002/03/05 04:52:42 oes
302 * Deleted non-errlog debugging code
304 * Revision 1.32 2002/03/04 18:24:53 oes
305 * Re-enabled output of unknown config directive hash
307 * Revision 1.31 2002/03/03 15:07:20 oes
308 * Re-enabled automatic config reloading
310 * Revision 1.30 2002/01/22 23:31:43 jongfoster
311 * Replacing strsav() with string_append()
313 * Revision 1.29 2002/01/17 21:02:30 jongfoster
314 * Moving all our URL and URL pattern parsing code to urlmatch.c.
316 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
318 * Revision 1.28 2001/12/30 14:07:32 steudten
319 * - Add signal handling (unix)
320 * - Add SIGHUP handler (unix)
321 * - Add creation of pidfile (unix)
322 * - Add action 'top' in rc file (RH)
323 * - Add entry 'SIGNALS' to manpage
324 * - Add exit message to logfile (unix)
326 * Revision 1.27 2001/11/07 00:02:13 steudten
327 * Add line number in error output for lineparsing for
328 * actionsfile and configfile.
329 * Special handling for CLF added.
331 * Revision 1.26 2001/11/05 21:41:43 steudten
332 * Add changes to be a real daemon just for unix os.
333 * (change cwd to /, detach from controlling tty, set
334 * process group and session leader to the own process.
336 * Add some fatal-error log message for failed malloc().
337 * Add '-d' if compiled with 'configure --with-debug' to
338 * enable debug output.
340 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
341 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
342 * threads to call select() simultaneously. So, it's time to do a real, live,
343 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
344 * (native). Both versions will work, but using __OS2__ offers multi-threading.
346 * Revision 1.24 2001/10/23 21:40:30 jongfoster
347 * Added support for enable-edit-actions and enable-remote-toggle config
350 * Revision 1.23 2001/10/07 15:36:00 oes
351 * Introduced new config option "buffer-limit"
353 * Revision 1.22 2001/09/22 16:36:59 jongfoster
354 * Removing unused parameter fs from read_config_line()
356 * Revision 1.21 2001/09/16 17:10:43 jongfoster
357 * Moving function savearg() here, since it was the only thing left in
360 * Revision 1.20 2001/07/30 22:08:36 jongfoster
361 * Tidying up #defines:
362 * - All feature #defines are now of the form FEATURE_xxx
363 * - Permanently turned off WIN_GUI_EDIT
364 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
366 * Revision 1.19 2001/07/15 17:45:16 jongfoster
367 * Removing some unused #includes
369 * Revision 1.18 2001/07/13 14:01:14 oes
370 * - Removed all #ifdef PCRS
371 * - Removed vim-settings
373 * Revision 1.17 2001/06/29 13:31:03 oes
374 * - Improved comments
375 * - Fixed (actionsfile) and sorted hashes
376 * - Introduced admin_address and proxy-info-url
377 * as config parameters
378 * - Renamed config->proxy_args_invocation (which didn't have
379 * the invocation but the options!) to config->proxy_args
380 * - Various adaptions
381 * - Removed logentry from cancelled commit
383 * Revision 1.16 2001/06/09 10:55:28 jongfoster
384 * Changing BUFSIZ ==> BUFFER_SIZE
386 * Revision 1.15 2001/06/07 23:13:40 jongfoster
387 * Merging ACL and forward files into config file.
388 * Cosmetic: Sorting config file options alphabetically.
389 * Cosmetic: Adding brief syntax comments to config file options.
391 * Revision 1.14 2001/06/07 14:46:25 joergs
392 * Missing make_path() added for re_filterfile.
394 * Revision 1.13 2001/06/05 22:33:54 jongfoster
396 * Fixed minor memory leak.
397 * Also now uses make_path to prepend the pathnames.
399 * Revision 1.12 2001/06/05 20:04:09 jongfoster
400 * Now uses _snprintf() in place of snprintf() under Win32.
402 * Revision 1.11 2001/06/04 18:31:58 swa
403 * files are now prefixed with either `confdir' or `logdir'.
404 * `make redhat-dist' replaces both entries confdir and logdir
407 * Revision 1.10 2001/06/03 19:11:54 oes
408 * introduced confdir option
410 * Revision 1.9 2001/06/01 20:06:24 jongfoster
411 * Removed support for "tinygif" option - moved to actions file.
413 * Revision 1.8 2001/05/31 21:27:13 jongfoster
414 * Removed many options from the config file and into the
415 * "actions" file: add_forwarded, suppress_vanilla_wafer,
416 * wafer, add_header, user_agent, referer, from
417 * Also globally replaced "permission" with "action".
419 * Revision 1.7 2001/05/29 09:50:24 jongfoster
420 * Unified blocklist/imagelist/permissionslist.
421 * File format is still under discussion, but the internal changes
424 * Also modified interceptor behaviour:
425 * - We now intercept all URLs beginning with one of the following
426 * prefixes (and *only* these prefixes):
428 * * http://ijbswa.sf.net/config/
429 * * http://ijbswa.sourceforge.net/config/
430 * - New interceptors "home page" - go to http://i.j.b/ to see it.
431 * - Internal changes so that intercepted and fast redirect pages
432 * are not replaced with an image.
433 * - Interceptors now have the option to send a binary page direct
434 * to the client. (i.e. ijb-send-banner uses this)
435 * - Implemented show-url-info interceptor. (Which is why I needed
436 * the above interceptors changes - a typical URL is
437 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
438 * The previous mechanism would not have intercepted that, and
439 * if it had been intercepted then it then it would have replaced
442 * Revision 1.6 2001/05/26 00:28:36 jongfoster
443 * Automatic reloading of config file.
444 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
445 * Most of the global variables have been moved to a new
446 * struct configuration_spec, accessed through csp->config->globalname
447 * Most of the globals remaining are used by the Win32 GUI.
449 * Revision 1.5 2001/05/25 22:34:30 jongfoster
452 * Revision 1.4 2001/05/22 18:46:04 oes
454 * - Enabled filtering banners by size rather than URL
455 * by adding patterns that replace all standard banner
456 * sizes with the "Junkbuster" gif to the re_filterfile
458 * - Enabled filtering WebBugs by providing a pattern
459 * which kills all 1x1 images
461 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
462 * which is selected by the (nonstandard and therefore
463 * capital) letter 'U' in the option string.
464 * It causes the quantifiers to be ungreedy by default.
465 * Appending a ? turns back to greedy (!).
467 * - Added a new interceptor ijb-send-banner, which
468 * sends back the "Junkbuster" gif. Without imagelist or
469 * MSIE detection support, or if tinygif = 1, or the
470 * URL isn't recognized as an imageurl, a lame HTML
471 * explanation is sent instead.
473 * - Added new feature, which permits blocking remote
474 * script redirects and firing back a local redirect
476 * The feature is conditionally compiled, i.e. it
477 * can be disabled with --disable-fast-redirects,
478 * plus it must be activated by a "fast-redirects"
479 * line in the config file, has its own log level
480 * and of course wants to be displayed by show-proxy-args
481 * Note: Boy, all the #ifdefs in 1001 locations and
482 * all the fumbling with configure.in and acconfig.h
483 * were *way* more work than the feature itself :-(
485 * - Because a generic redirect template was needed for
486 * this, tinygif = 3 now uses the same.
488 * - Moved GIFs, and other static HTTP response templates
493 * - Removed some >400 CRs again (Jon, you really worked
496 * Revision 1.3 2001/05/20 01:21:20 jongfoster
497 * Version 2.9.4 checkin.
498 * - Merged popupfile and cookiefile, and added control over PCRS
499 * filtering, in new "permissionsfile".
500 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
501 * file error you now get a message box (in the Win32 GUI) rather
502 * than the program exiting with no explanation.
503 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
505 * - Removed tabs from "config"
506 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
507 * - Bumped up version number.
509 * Revision 1.2 2001/05/17 23:01:01 oes
510 * - Cleaned CRLF's from the sources and related files
512 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
513 * Initial import of version 2.9.3 source tree
516 *********************************************************************/
522 #include <sys/types.h>
536 # include <windows.h>
539 # ifndef _WIN_CONSOLE
541 # endif /* ndef _WIN_CONSOLE */
543 #else /* ifndef _WIN32 */
547 # include <sys/wait.h>
549 # include <sys/time.h>
550 # include <sys/stat.h>
560 #include "miscutil.h"
564 #include "urlmatch.h"
568 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
571 * Fix a problem with Solaris. There should be no effect on other
573 * Solaris's isspace() is a macro which uses it's argument directly
574 * as an array index. Therefore we need to make sure that high-bit
575 * characters generate +ve values, and ideally we also want to make
576 * the argument match the declared parameter type of "int".
578 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
579 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
581 #ifdef FEATURE_TOGGLE
582 /* Privoxy is enabled by default. */
583 int global_toggle_state = 1;
584 #endif /* def FEATURE_TOGGLE */
586 /* The filename of the configfile */
587 const char *configfile = NULL;
590 * CGI functions will later need access to the invocation args,
591 * so we will make argc and argv global.
594 const char **Argv = NULL;
596 static struct file_list *current_configfile = NULL;
600 * This takes the "cryptic" hash of each keyword and aliases them to
601 * something a little more readable. This also makes changing the
602 * hash values easier if they should change or the hash algorthm changes.
603 * Use the included "hash" program to find out what the hash will be
604 * for any string supplied on the command line. (Or just put it in the
605 * config file and read the number from the error message in the log).
607 * Please keep this list sorted alphabetically (but with the Windows
608 * console and GUI specific options last).
611 #define hash_actions_file 1196306641ul /* "actionsfile" */
612 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
613 #define hash_admin_address 4112573064ul /* "admin-address" */
614 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
615 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
616 #define hash_confdir 1978389ul /* "confdir" */
617 #define hash_debug 78263ul /* "debug" */
618 #define hash_deny_access 1227333715ul /* "deny-access" */
619 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
620 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
621 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
622 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
623 #define hash_filterfile 250887266ul /* "filterfile" */
624 #define hash_forward 2029845ul /* "forward" */
625 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
626 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
627 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
628 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
629 #define hash_hostname 10308071ul /* "hostname" */
630 #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */
631 #define hash_listen_address 1255650842ul /* "listen-address" */
632 #define hash_logdir 422889ul /* "logdir" */
633 #define hash_logfile 2114766ul /* "logfile" */
634 #define hash_permit_access 3587953268ul /* "permit-access" */
635 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
636 #define hash_single_threaded 4250084780ul /* "single-threaded" */
637 #define hash_socket_timeout 1809001761ul /* "socket-timeout" */
638 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
639 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
640 #define hash_templdir 11067889ul /* "templdir" */
641 #define hash_toggle 447966ul /* "toggle" */
642 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
643 #define hash_trustfile 56494766ul /* "trustfile" */
644 #define hash_usermanual 1416668518ul /* "user-manual" */
645 #define hash_activity_animation 1817904738ul /* "activity-animation" */
646 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
647 #define hash_hide_console 2048809870ul /* "hide-console" */
648 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
649 #define hash_log_font_name 2866730124ul /* "log-font-name" */
650 #define hash_log_font_size 2866731014ul /* "log-font-size" */
651 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
652 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
653 #define hash_log_messages 2291744899ul /* "log-messages" */
654 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
657 static void savearg(char *command, char *argument, struct configuration_spec * config);
659 /*********************************************************************
661 * Function : unload_configfile
663 * Description : Free the config structure and all components.
666 * 1 : data: struct configuration_spec to unload
670 *********************************************************************/
671 static void unload_configfile (void * data)
673 struct configuration_spec * config = (struct configuration_spec *)data;
674 struct forward_spec *cur_fwd = config->forward;
678 struct access_control_list *cur_acl = config->acl;
680 while (cur_acl != NULL)
682 struct access_control_list * next_acl = cur_acl->next;
687 #endif /* def FEATURE_ACL */
689 while (cur_fwd != NULL)
691 struct forward_spec * next_fwd = cur_fwd->next;
692 free_url_spec(cur_fwd->url);
694 freez(cur_fwd->gateway_host);
695 freez(cur_fwd->forward_host);
699 config->forward = NULL;
701 freez(config->confdir);
702 freez(config->logdir);
703 freez(config->templdir);
704 freez(config->hostname);
706 freez(config->haddr);
707 freez(config->logfile);
709 for (i = 0; i < MAX_AF_FILES; i++)
711 freez(config->actions_file_short[i]);
712 freez(config->actions_file[i]);
713 freez(config->re_filterfile_short[i]);
714 freez(config->re_filterfile[i]);
717 freez(config->admin_address);
718 freez(config->proxy_info_url);
719 freez(config->proxy_args);
720 freez(config->usermanual);
723 freez(config->trustfile);
724 list_remove_all(config->trust_info);
725 #endif /* def FEATURE_TRUST */
727 for (i = 0; i < MAX_AF_FILES; i++)
729 freez(config->re_filterfile[i]);
736 #ifdef FEATURE_GRACEFUL_TERMINATION
737 /*********************************************************************
739 * Function : unload_current_config_file
741 * Description : Unloads current config file - reset to state at
742 * beginning of program.
748 *********************************************************************/
749 void unload_current_config_file(void)
751 if (current_configfile)
753 current_configfile->unloader = unload_configfile;
754 current_configfile = NULL;
760 /*********************************************************************
762 * Function : load_config
764 * Description : Load the config file and all parameters.
766 * XXX: more than thousand lines long
767 * and thus in serious need of refactoring.
771 * Returns : The configuration_spec, or NULL on error.
773 *********************************************************************/
774 struct configuration_spec * load_config(void)
776 char buf[BUFFER_SIZE];
778 FILE *configfp = NULL;
779 struct configuration_spec * config = NULL;
780 struct client_state * fake_csp;
781 struct file_list *fs;
782 unsigned long linenum = 0;
784 char *logfile = NULL;
785 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
786 int keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
789 if (!check_file_changed(current_configfile, configfile, &fs))
791 /* No need to load */
792 return ((struct configuration_spec *)current_configfile->f);
796 log_error(LOG_LEVEL_FATAL,
797 "can't check configuration file '%s': %E", configfile);
801 if (NULL != current_configfile)
803 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
806 #ifdef FEATURE_TOGGLE
807 global_toggle_state = 1;
808 #endif /* def FEATURE_TOGGLE */
810 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
816 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
821 * This is backwards from how it's usually done.
822 * Following the usual pattern, "fs" would be stored in a member
823 * variable in "csp", and then we'd access "config" from "fs->f",
824 * using a cast. However, "config" is used so often that a
825 * cast each time would be very ugly, and the extra indirection
826 * would waste CPU cycles. Therefore we store "config" in
827 * "csp->config", and "fs" in "csp->config->config_file_list".
829 config->config_file_list = fs;
834 config->multi_threaded = 1;
835 config->hport = HADDR_PORT;
836 config->buffer_limit = 4096 * 1024;
837 config->usermanual = strdup(USER_MANUAL_URL);
838 config->proxy_args = strdup("");
839 config->forwarded_connect_retries = 0;
840 config->socket_timeout = 300; /* XXX: Should be a macro. */
841 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
842 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
843 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
845 configfp = fopen(configfile, "r");
846 if (NULL == configfp)
848 log_error(LOG_LEVEL_FATAL,
849 "can't open configuration file '%s': %E", configfile);
850 /* Never get here - LOG_LEVEL_FATAL causes program exit */
853 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
855 char cmd[BUFFER_SIZE];
856 char arg[BUFFER_SIZE];
857 char tmp[BUFFER_SIZE];
859 struct access_control_list *cur_acl;
860 #endif /* def FEATURE_ACL */
861 struct forward_spec *cur_fwd;
864 unsigned long directive_hash;
866 strlcpy(tmp, buf, sizeof(tmp));
868 /* Copy command (i.e. up to space or tab) into cmd */
871 while (*p && (*p != ' ') && (*p != '\t'))
877 /* Skip over the whitespace in buf */
878 while (*p && ((*p == ' ') || (*p == '\t')))
883 /* Copy the argument into arg */
884 strlcpy(arg, p, sizeof(arg));
886 /* Should never happen, but check this anyway */
892 /* Make sure the command field is lower case */
893 for (p = cmd; *p; p++)
897 *p = (char)ijb_tolower(*p);
901 directive_hash = hash_string(cmd);
902 switch (directive_hash)
904 /* *************************************************************************
905 * actionsfile actions-file-name
906 * In confdir by default
907 * *************************************************************************/
908 case hash_actions_file :
910 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
915 if (i >= MAX_AF_FILES)
917 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
918 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
921 config->actions_file_short[i] = strdup(arg);
922 config->actions_file[i] = make_path(config->confdir, arg);
925 /* *************************************************************************
926 * accept-intercepted-requests
927 * *************************************************************************/
928 case hash_accept_intercepted_requests:
929 if ((*arg != '\0') && (0 != atoi(arg)))
931 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
935 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
939 /* *************************************************************************
940 * admin-address email-address
941 * *************************************************************************/
942 case hash_admin_address :
943 freez(config->admin_address);
944 config->admin_address = strdup(arg);
947 /* *************************************************************************
948 * allow-cgi-request-crunching
949 * *************************************************************************/
950 case hash_allow_cgi_request_crunching:
951 if ((*arg != '\0') && (0 != atoi(arg)))
953 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
957 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
961 /* *************************************************************************
963 * *************************************************************************/
964 case hash_buffer_limit :
965 config->buffer_limit = (size_t)(1024 * atoi(arg));
968 /* *************************************************************************
969 * confdir directory-name
970 * *************************************************************************/
972 freez(config->confdir);
973 config->confdir = make_path( NULL, arg);
976 /* *************************************************************************
978 * Specifies debug level, multiple values are ORed together.
979 * *************************************************************************/
981 config->debug |= atoi(arg);
984 /* *************************************************************************
985 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
986 * *************************************************************************/
988 case hash_deny_access:
989 strlcpy(tmp, arg, sizeof(tmp));
990 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
992 if ((vec_count != 1) && (vec_count != 2))
994 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
995 "deny-access directive in configuration file.");
996 string_append(&config->proxy_args,
997 "<br>\nWARNING: Wrong number of parameters for "
998 "deny-access directive in configuration file.<br><br>\n");
1002 /* allocate a new node */
1003 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1005 if (cur_acl == NULL)
1007 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1008 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1011 cur_acl->action = ACL_DENY;
1013 if (acl_addr(vec[0], cur_acl->src) < 0)
1015 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1016 "for deny-access directive in configuration file: \"%s\"", vec[0]);
1017 string_append(&config->proxy_args,
1018 "<br>\nWARNING: Invalid source address, port or netmask "
1019 "for deny-access directive in configuration file: \"");
1020 string_append(&config->proxy_args,
1022 string_append(&config->proxy_args,
1029 if (acl_addr(vec[1], cur_acl->dst) < 0)
1031 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1032 "for deny-access directive in configuration file: \"%s\"", vec[1]);
1033 string_append(&config->proxy_args,
1034 "<br>\nWARNING: Invalid destination address, port or netmask "
1035 "for deny-access directive in configuration file: \"");
1036 string_append(&config->proxy_args,
1038 string_append(&config->proxy_args,
1046 * Add it to the list. Note we reverse the list to get the
1047 * behaviour the user expects. With both the ACL and
1048 * actions file, the last match wins. However, the internal
1049 * implementations are different: The actions file is stored
1050 * in the same order as the file, and scanned completely.
1051 * With the ACL, we reverse the order as we load it, then
1052 * when we scan it we stop as soon as we get a match.
1054 cur_acl->next = config->acl;
1055 config->acl = cur_acl;
1058 #endif /* def FEATURE_ACL */
1060 /* *************************************************************************
1061 * enable-edit-actions 0|1
1062 * *************************************************************************/
1063 #ifdef FEATURE_CGI_EDIT_ACTIONS
1064 case hash_enable_edit_actions:
1065 if ((*arg != '\0') && (0 != atoi(arg)))
1067 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1071 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1074 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1076 /* *************************************************************************
1077 * enable-remote-toggle 0|1
1078 * *************************************************************************/
1079 #ifdef FEATURE_TOGGLE
1080 case hash_enable_remote_toggle:
1081 if ((*arg != '\0') && (0 != atoi(arg)))
1083 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1087 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1090 #endif /* def FEATURE_TOGGLE */
1092 /* *************************************************************************
1093 * enable-remote-http-toggle 0|1
1094 * *************************************************************************/
1095 case hash_enable_remote_http_toggle:
1096 if ((*arg != '\0') && (0 != atoi(arg)))
1098 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1102 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1106 /* *************************************************************************
1107 * enforce-blocks 0|1
1108 * *************************************************************************/
1109 case hash_enforce_blocks:
1110 #ifdef FEATURE_FORCE_LOAD
1111 if ((*arg != '\0') && (0 != atoi(arg)))
1113 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1117 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1120 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1121 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1122 #endif /* def FEATURE_FORCE_LOAD */
1125 /* *************************************************************************
1126 * filterfile file-name
1127 * In confdir by default.
1128 * *************************************************************************/
1129 case hash_filterfile :
1131 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1136 if (i >= MAX_AF_FILES)
1138 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1139 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1142 config->re_filterfile_short[i] = strdup(arg);
1143 config->re_filterfile[i] = make_path(config->confdir, arg);
1147 /* *************************************************************************
1148 * forward url-pattern (.|http-proxy-host[:port])
1149 * *************************************************************************/
1151 strlcpy(tmp, arg, sizeof(tmp));
1152 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1156 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1157 "directive in configuration file.");
1158 string_append(&config->proxy_args,
1159 "<br>\nWARNING: Wrong number of parameters for "
1160 "forward directive in configuration file.");
1164 /* allocate a new node */
1165 cur_fwd = zalloc(sizeof(*cur_fwd));
1166 if (cur_fwd == NULL)
1168 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1169 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1173 cur_fwd->type = SOCKS_NONE;
1175 /* Save the URL pattern */
1176 if (create_url_spec(cur_fwd->url, vec[0]))
1178 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1179 "directive in configuration file.");
1180 string_append(&config->proxy_args,
1181 "<br>\nWARNING: Bad URL specifier for "
1182 "forward directive in configuration file.");
1186 /* Parse the parent HTTP proxy host:port */
1189 if (strcmp(p, ".") != 0)
1191 cur_fwd->forward_host = strdup(p);
1193 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1196 cur_fwd->forward_port = atoi(p);
1199 if (cur_fwd->forward_port <= 0)
1201 cur_fwd->forward_port = 8000;
1206 cur_fwd->next = config->forward;
1207 config->forward = cur_fwd;
1211 /* *************************************************************************
1212 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1213 * *************************************************************************/
1214 case hash_forward_socks4:
1215 strlcpy(tmp, arg, sizeof(tmp));
1216 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1220 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1221 "forward-socks4 directive in configuration file.");
1222 string_append(&config->proxy_args,
1223 "<br>\nWARNING: Wrong number of parameters for "
1224 "forward-socks4 directive in configuration file.");
1228 /* allocate a new node */
1229 cur_fwd = zalloc(sizeof(*cur_fwd));
1230 if (cur_fwd == NULL)
1232 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1233 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1237 cur_fwd->type = SOCKS_4;
1239 /* Save the URL pattern */
1240 if (create_url_spec(cur_fwd->url, vec[0]))
1242 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1243 "directive in configuration file.");
1244 string_append(&config->proxy_args,
1245 "<br>\nWARNING: Bad URL specifier for "
1246 "forward-socks4 directive in configuration file.");
1250 /* Parse the SOCKS proxy host[:port] */
1253 if (strcmp(p, ".") != 0)
1255 cur_fwd->gateway_host = strdup(p);
1257 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1260 cur_fwd->gateway_port = atoi(p);
1262 if (cur_fwd->gateway_port <= 0)
1264 cur_fwd->gateway_port = 1080;
1268 /* Parse the parent HTTP proxy host[:port] */
1271 if (strcmp(p, ".") != 0)
1273 cur_fwd->forward_host = strdup(p);
1275 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1278 cur_fwd->forward_port = atoi(p);
1281 if (cur_fwd->forward_port <= 0)
1283 cur_fwd->forward_port = 8000;
1288 cur_fwd->next = config->forward;
1289 config->forward = cur_fwd;
1293 /* *************************************************************************
1294 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1295 * *************************************************************************/
1296 case hash_forward_socks4a:
1297 case hash_forward_socks5:
1298 strlcpy(tmp, arg, sizeof(tmp));
1299 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1303 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1304 "forward-socks4a directive in configuration file.");
1305 string_append(&config->proxy_args,
1306 "<br>\nWARNING: Wrong number of parameters for "
1307 "forward-socks4a directive in configuration file.");
1311 /* allocate a new node */
1312 cur_fwd = zalloc(sizeof(*cur_fwd));
1313 if (cur_fwd == NULL)
1315 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1316 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1320 if (directive_hash == hash_forward_socks4a)
1322 cur_fwd->type = SOCKS_4A;
1326 cur_fwd->type = SOCKS_5;
1329 /* Save the URL pattern */
1330 if (create_url_spec(cur_fwd->url, vec[0]))
1332 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1333 "directive in configuration file.");
1334 string_append(&config->proxy_args,
1335 "<br>\nWARNING: Bad URL specifier for "
1336 "forward-socks4a directive in configuration file.");
1340 /* Parse the SOCKS proxy host[:port] */
1343 cur_fwd->gateway_host = strdup(p);
1345 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1348 cur_fwd->gateway_port = atoi(p);
1350 if (cur_fwd->gateway_port <= 0)
1352 cur_fwd->gateway_port = 1080;
1355 /* Parse the parent HTTP proxy host[:port] */
1358 if (strcmp(p, ".") != 0)
1360 cur_fwd->forward_host = strdup(p);
1362 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1365 cur_fwd->forward_port = atoi(p);
1368 if (cur_fwd->forward_port <= 0)
1370 cur_fwd->forward_port = 8000;
1375 cur_fwd->next = config->forward;
1376 config->forward = cur_fwd;
1380 /* *************************************************************************
1381 * forwarded-connect-retries n
1382 * *************************************************************************/
1383 case hash_forwarded_connect_retries :
1384 config->forwarded_connect_retries = atoi(arg);
1387 /* *************************************************************************
1388 * hostname hostname-to-show-on-cgi-pages
1389 * *************************************************************************/
1390 case hash_hostname :
1391 freez(config->hostname);
1392 config->hostname = strdup(arg);
1393 if (NULL == config->hostname)
1395 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1399 /* *************************************************************************
1400 * keep-alive-timeout timeout
1401 * *************************************************************************/
1402 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1403 case hash_keep_alive_timeout :
1406 int timeout = atoi(arg);
1409 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1410 keep_alive_timeout = timeout;
1414 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1420 /* *************************************************************************
1421 * listen-address [ip][:port]
1422 * *************************************************************************/
1423 case hash_listen_address :
1424 freez(config->haddr);
1425 config->haddr = strdup(arg);
1428 /* *************************************************************************
1429 * logdir directory-name
1430 * *************************************************************************/
1432 freez(config->logdir);
1433 config->logdir = make_path(NULL, arg);
1436 /* *************************************************************************
1437 * logfile log-file-name
1438 * In logdir by default
1439 * *************************************************************************/
1443 logfile = make_path(config->logdir, arg);
1444 if (NULL == logfile)
1446 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1451 /* *************************************************************************
1452 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1453 * *************************************************************************/
1455 case hash_permit_access:
1456 strlcpy(tmp, arg, sizeof(tmp));
1457 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1459 if ((vec_count != 1) && (vec_count != 2))
1461 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1462 "permit-access directive in configuration file.");
1463 string_append(&config->proxy_args,
1464 "<br>\nWARNING: Wrong number of parameters for "
1465 "permit-access directive in configuration file.<br><br>\n");
1470 /* allocate a new node */
1471 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1473 if (cur_acl == NULL)
1475 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1476 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1479 cur_acl->action = ACL_PERMIT;
1481 if (acl_addr(vec[0], cur_acl->src) < 0)
1483 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1484 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1485 string_append(&config->proxy_args,
1486 "<br>\nWARNING: Invalid source address, port or netmask for "
1487 "permit-access directive in configuration file: \"");
1488 string_append(&config->proxy_args,
1490 string_append(&config->proxy_args,
1497 if (acl_addr(vec[1], cur_acl->dst) < 0)
1499 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1500 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1501 string_append(&config->proxy_args,
1502 "<br>\nWARNING: Invalid destination address, port or netmask for "
1503 "permit-access directive in configuration file: \"");
1504 string_append(&config->proxy_args,
1506 string_append(&config->proxy_args,
1514 * Add it to the list. Note we reverse the list to get the
1515 * behaviour the user expects. With both the ACL and
1516 * actions file, the last match wins. However, the internal
1517 * implementations are different: The actions file is stored
1518 * in the same order as the file, and scanned completely.
1519 * With the ACL, we reverse the order as we load it, then
1520 * when we scan it we stop as soon as we get a match.
1522 cur_acl->next = config->acl;
1523 config->acl = cur_acl;
1526 #endif /* def FEATURE_ACL */
1528 /* *************************************************************************
1529 * proxy-info-url url
1530 * *************************************************************************/
1531 case hash_proxy_info_url :
1532 freez(config->proxy_info_url);
1533 config->proxy_info_url = strdup(arg);
1536 /* *************************************************************************
1538 * *************************************************************************/
1539 case hash_single_threaded :
1540 config->multi_threaded = 0;
1543 /* *************************************************************************
1544 * socket-timeout numer_of_seconds
1545 * *************************************************************************/
1546 case hash_socket_timeout :
1549 int socket_timeout = atoi(arg);
1550 if (0 < socket_timeout)
1552 config->socket_timeout = socket_timeout;
1556 log_error(LOG_LEVEL_FATAL,
1557 "Invalid socket-timeout: '%s'", arg);
1562 /* *************************************************************************
1563 * split-large-cgi-forms
1564 * *************************************************************************/
1565 case hash_split_large_cgi_forms :
1566 if ((*arg != '\0') && (0 != atoi(arg)))
1568 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1572 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1576 /* *************************************************************************
1577 * templdir directory-name
1578 * *************************************************************************/
1579 case hash_templdir :
1580 freez(config->templdir);
1581 config->templdir = make_path(NULL, arg);
1584 /* *************************************************************************
1586 * *************************************************************************/
1587 #ifdef FEATURE_TOGGLE
1589 global_toggle_state = atoi(arg);
1591 #endif /* def FEATURE_TOGGLE */
1593 /* *************************************************************************
1594 * trust-info-url url
1595 * *************************************************************************/
1596 #ifdef FEATURE_TRUST
1597 case hash_trust_info_url :
1598 enlist(config->trust_info, arg);
1600 #endif /* def FEATURE_TRUST */
1602 /* *************************************************************************
1603 * trustfile filename
1604 * (In confdir by default.)
1605 * *************************************************************************/
1606 #ifdef FEATURE_TRUST
1607 case hash_trustfile :
1608 freez(config->trustfile);
1609 config->trustfile = make_path(config->confdir, arg);
1611 #endif /* def FEATURE_TRUST */
1613 /* *************************************************************************
1615 * *************************************************************************/
1616 case hash_usermanual :
1618 * XXX: If this isn't the first config directive, the
1619 * show-status page links to the website documentation
1620 * for the directives that were already parsed. Lame.
1622 freez(config->usermanual);
1623 config->usermanual = strdup(arg);
1626 /* *************************************************************************
1627 * Win32 Console options:
1628 * *************************************************************************/
1630 /* *************************************************************************
1632 * *************************************************************************/
1634 case hash_hide_console :
1637 #endif /*def _WIN_CONSOLE*/
1640 /* *************************************************************************
1641 * Win32 GUI options:
1642 * *************************************************************************/
1644 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1645 /* *************************************************************************
1646 * activity-animation (0|1)
1647 * *************************************************************************/
1648 case hash_activity_animation :
1649 g_bShowActivityAnimation = atoi(arg);
1652 /* *************************************************************************
1653 * close-button-minimizes (0|1)
1654 * *************************************************************************/
1655 case hash_close_button_minimizes :
1656 g_bCloseHidesWindow = atoi(arg);
1659 /* *************************************************************************
1660 * log-buffer-size (0|1)
1661 * *************************************************************************/
1662 case hash_log_buffer_size :
1663 g_bLimitBufferSize = atoi(arg);
1666 /* *************************************************************************
1667 * log-font-name fontname
1668 * *************************************************************************/
1669 case hash_log_font_name :
1670 if (strlcpy(g_szFontFaceName, arg,
1671 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1673 log_error(LOG_LEVEL_FATAL,
1674 "log-font-name argument '%s' is longer than %u characters.",
1675 arg, sizeof(g_szFontFaceName)-1);
1679 /* *************************************************************************
1681 * *************************************************************************/
1682 case hash_log_font_size :
1683 g_nFontSize = atoi(arg);
1686 /* *************************************************************************
1687 * log-highlight-messages (0|1)
1688 * *************************************************************************/
1689 case hash_log_highlight_messages :
1690 g_bHighlightMessages = atoi(arg);
1693 /* *************************************************************************
1695 * *************************************************************************/
1696 case hash_log_max_lines :
1697 g_nMaxBufferLines = atoi(arg);
1700 /* *************************************************************************
1701 * log-messages (0|1)
1702 * *************************************************************************/
1703 case hash_log_messages :
1704 g_bLogMessages = atoi(arg);
1707 /* *************************************************************************
1708 * show-on-task-bar (0|1)
1709 * *************************************************************************/
1710 case hash_show_on_task_bar :
1711 g_bShowOnTaskBar = atoi(arg);
1714 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1717 /* *************************************************************************
1718 * Warnings about unsupported features
1719 * *************************************************************************/
1721 case hash_deny_access:
1722 #endif /* ndef FEATURE_ACL */
1723 #ifndef FEATURE_CGI_EDIT_ACTIONS
1724 case hash_enable_edit_actions:
1725 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1726 #ifndef FEATURE_TOGGLE
1727 case hash_enable_remote_toggle:
1728 #endif /* ndef FEATURE_TOGGLE */
1730 case hash_permit_access:
1731 #endif /* ndef FEATURE_ACL */
1732 #ifndef FEATURE_TOGGLE
1734 #endif /* ndef FEATURE_TOGGLE */
1735 #ifndef FEATURE_TRUST
1736 case hash_trustfile :
1737 case hash_trust_info_url :
1738 #endif /* ndef FEATURE_TRUST */
1740 #ifndef _WIN_CONSOLE
1741 case hash_hide_console :
1742 #endif /* ndef _WIN_CONSOLE */
1744 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1745 case hash_activity_animation :
1746 case hash_close_button_minimizes :
1747 case hash_log_buffer_size :
1748 case hash_log_font_name :
1749 case hash_log_font_size :
1750 case hash_log_highlight_messages :
1751 case hash_log_max_lines :
1752 case hash_log_messages :
1753 case hash_show_on_task_bar :
1754 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1755 /* These warnings are annoying - so hide them. -- Jon */
1756 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1759 /* *************************************************************************/
1761 /* *************************************************************************/
1763 * I decided that I liked this better as a warning than an
1764 * error. To change back to an error, just change log level
1765 * to LOG_LEVEL_FATAL.
1767 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1768 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1769 string_append(&config->proxy_args,
1770 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1773 /* *************************************************************************/
1774 } /* end switch( hash_string(cmd) ) */
1776 /* Save the argument for the show-status page. */
1777 savearg(cmd, arg, config);
1779 } /* end while ( read_config_line(...) ) */
1783 set_debug_level(config->debug);
1785 freez(config->logfile);
1789 if (NULL != logfile)
1791 config->logfile = logfile;
1792 init_error_log(Argv[0], config->logfile);
1800 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1801 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1803 if (config->multi_threaded)
1805 set_keep_alive_timeout(keep_alive_timeout);
1810 * While we could use keep-alive without multiple threads
1811 * if we didn't bother with enforcing the connection timeout,
1812 * that might make Tor users sad, even though they shouldn't
1813 * enable the single-threaded option anyway.
1815 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1816 log_error(LOG_LEVEL_ERROR,
1817 "Config option single-threaded disables connection keep-alive.");
1822 if (NULL == config->proxy_args)
1824 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1827 if (config->actions_file[0])
1829 add_loader(load_action_files, config);
1832 if (config->re_filterfile[0])
1834 add_loader(load_re_filterfiles, config);
1837 #ifdef FEATURE_TRUST
1838 if (config->trustfile)
1840 add_loader(load_trustfile, config);
1842 #endif /* def FEATURE_TRUST */
1844 if ( NULL == config->haddr )
1846 config->haddr = strdup( HADDR_DEFAULT );
1849 if ( NULL != config->haddr )
1851 if (NULL != (p = strchr(config->haddr, ':')))
1856 config->hport = atoi(p);
1860 if (config->hport <= 0)
1863 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1864 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1866 if (*config->haddr == '\0')
1869 * Only the port specified. We stored it in config->hport
1870 * and don't need its text representation anymore.
1872 freez(config->haddr);
1877 * Want to run all the loaders once now.
1879 * Need to set up a fake csp, so they can get to the config.
1881 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1882 fake_csp->config = config;
1884 if (run_loader(fake_csp))
1887 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1888 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1892 /* FIXME: this is a kludge for win32 */
1893 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1895 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1896 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1897 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1899 #ifdef FEATURE_TRUST
1900 g_trustfile = config->trustfile;
1901 #endif /* def FEATURE_TRUST */
1904 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1905 /* FIXME: end kludge */
1908 config->need_bind = 1;
1910 if (current_configfile)
1912 struct configuration_spec * oldcfg = (struct configuration_spec *)
1913 current_configfile->f;
1915 * Check if config->haddr,hport == oldcfg->haddr,hport
1917 * The following could be written more compactly as a single,
1918 * (unreadably long) if statement.
1920 config->need_bind = 0;
1921 if (config->hport != oldcfg->hport)
1923 config->need_bind = 1;
1925 else if (config->haddr == NULL)
1927 if (oldcfg->haddr != NULL)
1929 config->need_bind = 1;
1932 else if (oldcfg->haddr == NULL)
1934 config->need_bind = 1;
1936 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1938 config->need_bind = 1;
1941 current_configfile->unloader = unload_configfile;
1944 fs->next = files->next;
1947 current_configfile = fs;
1953 /*********************************************************************
1955 * Function : savearg
1957 * Description : Called from `load_config'. It saves each non-empty
1958 * and non-comment line from config into
1959 * config->proxy_args. This is used to create the
1960 * show-proxy-args page. On error, frees
1961 * config->proxy_args and sets it to NULL
1964 * 1 : command = config setting that was found
1965 * 2 : argument = the setting's argument (if any)
1966 * 3 : config = Configuration to save into.
1970 *********************************************************************/
1971 static void savearg(char *command, char *argument, struct configuration_spec * config)
1980 * Add config option name embedded in
1981 * link to its section in the user-manual
1983 buf = strdup("\n<a href=\"");
1984 if (!strncmpic(config->usermanual, "file://", 7) ||
1985 !strncmpic(config->usermanual, "http", 4))
1987 string_append(&buf, config->usermanual);
1991 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1993 string_append(&buf, CONFIG_HELP_PREFIX);
1994 string_join (&buf, string_toupper(command));
1995 string_append(&buf, "\">");
1996 string_append(&buf, command);
1997 string_append(&buf, "</a> ");
2001 freez(config->proxy_args);
2005 if ( (NULL != argument) && ('\0' != *argument) )
2007 s = html_encode(argument);
2011 freez(config->proxy_args);
2015 if (strncmpic(argument, "http://", 7) == 0)
2017 string_append(&buf, "<a href=\"");
2018 string_append(&buf, s);
2019 string_append(&buf, "\">");
2020 string_join (&buf, s);
2021 string_append(&buf, "</a>");
2025 string_join (&buf, s);
2029 string_append(&buf, "<br>");
2030 string_join(&config->proxy_args, buf);