1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.91 2009/03/09 17:29:08 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.91 2009/03/09 17:29:08 fabiankeil
39 * As of r1.88, the show-status page can use a single line for
40 * warnings about ignored directives and the names of the ignored
41 * directives themselves. Reminded by Lee, finally closes #1856559.
43 * Revision 1.90 2009/03/07 17:58:02 fabiankeil
44 * Fix two mingw32-only buffer overflows. Note that triggering
45 * them requires control over the configuration file in which
46 * case all bets are off anyway.
48 * Revision 1.89 2009/03/01 18:46:33 fabiankeil
49 * - Help clang understand that we aren't
50 * dereferencing NULL pointers here.
51 * - Some style fixes in the modified region.
53 * Revision 1.88 2009/02/28 10:57:10 fabiankeil
54 * Gimme a break or two. Don't let the show-status page
55 * link to the website documentation for the user-manual
58 * Revision 1.87 2009/02/15 07:56:13 fabiankeil
59 * Increase default socket timeout to 300 seconds.
61 * Revision 1.86 2009/02/08 19:18:57 fabiankeil
62 * Now that we have the match-all.action file, the other action
63 * files changed their position in config->actions_file[] back
64 * to the way it was before standard.action got removed and the
65 * changes from revision 1.84 have to be reverted.
67 * Revision 1.85 2009/01/22 12:06:26 fabiankeil
68 * Don't keep connections alive when running single-threaded.
70 * Revision 1.84 2009/01/14 16:14:36 fabiankeil
71 * Due to the standard.action file removal, the other action
72 * files changed their position in config->actions_file[].
73 * Update mingw32 kludge accordingly.
75 * Revision 1.83 2008/12/20 14:53:55 fabiankeil
76 * Add config option socket-timeout to control the time
77 * Privoxy waits for data to arrive on a socket. Useful
78 * in case of stale ssh tunnels or when fuzz-testing.
80 * Revision 1.82 2008/11/16 12:43:49 fabiankeil
81 * Turn keep-alive support into a runtime feature
82 * that is disabled by setting keep-alive-timeout
83 * to a negative value.
85 * Revision 1.81 2008/11/13 09:08:42 fabiankeil
86 * Add new config option: keep-alive-timeout.
88 * Revision 1.80 2008/08/31 15:59:03 fabiankeil
89 * There's no reason to let remote toggling support depend
90 * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
92 * Revision 1.79 2008/08/30 12:03:07 fabiankeil
93 * Remove FEATURE_COOKIE_JAR.
95 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
96 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
97 * disabled, log a message that blocks will always be enforced
98 * instead of complaining about an unrecognized directive.
99 * Reported by Pietro Leone.
101 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
102 * Reuse directive_hash and don't hash the same directive twice.
104 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
105 * - Merge three string_append() calls.
106 * - Remove useless assertion.
108 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
109 * Rename load_actions_file() and load_re_filterfile()
110 * as they load multiple files "now".
112 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
113 * Add hostname directive. Closes PR#1918189.
115 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
118 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
119 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
121 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
122 * Reword "unrecognized directive" warning, use better
123 * mark up and add a <br>. Fixes parts of #1856559.
125 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
126 * Plug memory leak if listen-address only specifies the port.
128 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
129 * Relocate daemon-mode-related log messages to make sure
130 * they aren't shown again in case of configuration reloads.
132 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
133 * Plug memory leak introduced with my last commit.
135 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
136 * When in daemon mode, close stderr after the configuration file has been
137 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
139 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
140 * #1763173 from Stefan Huehner: declare unload_configfile() static.
142 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
143 * As Hal noticed, checking dispatch_cgi() as the last cruncher
144 * looks like a bug if CGI requests are blocked unintentionally,
145 * so don't do it unless the user enabled the new config option
146 * "allow-cgi-request-crunching".
148 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
149 * - Use strlcpy() instead of strcpy().
150 * - Stop treating actions files special. Expect a complete file name
151 * (with or without path) like it's done for the rest of the files.
153 * - Remove an unnecessary temporary memory allocation.
154 * - Don't log anything to the console when running as
155 * daemon and no errors occurred.
157 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
158 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
160 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
161 * New config option: enforce-blocks.
163 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
164 * - Mention other reasons why acl directive loading might have failed.
165 * - Don't log the acl source if the acl destination is to blame.
167 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
168 * Add new config option "templdir" to
169 * change the templates directory.
171 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
172 * Added config option accept-intercepted-requests
173 * and disabled it by default.
175 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
176 * Fix gcc43 compiler warnings.
178 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
179 * Add config option "split-large-forms"
180 * to work around the browser bug reported
183 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
184 * Move the <br> in the generated HTML for the config
185 * options from the beginning of the string to its end.
186 * Keeps the white space in balance.
188 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
189 * Fix memory leak in case of config file reloads.
191 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
192 * Modified kludge for win32 to make ming32 menu
193 * "Options/Edit Filters" (sort of) work again.
194 * Same limitations as for the action files apply.
197 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
198 * Incorporate modified version of Roland Rosenfeld's patch to
199 * optionally access the user-manual via Privoxy. Closes patch 679075.
201 * Formatting changed to Privoxy style, added call to
202 * cgi_error_no_template if the requested file doesn't
203 * exist and modified check whether or not Privoxy itself
204 * should serve the manual. Should work cross-platform now.
206 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
207 * Added config option enable-remote-http-toggle
208 * to specify if Privoxy should recognize special
209 * headers (currently only X-Filter) to change its
210 * behaviour. Disabled by default.
212 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
213 * Make number of retries in case of forwarded-connect problems
214 * a config file option (forwarded-connect-retries) and use 0 as
217 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
218 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
219 * with what was really the latest development (the v_3_0_branch branch)
221 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
222 * Don't forget to malloc space for the null terminator...
224 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
225 * Multiple filter file support
227 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
228 * Closed two memory leaks; hopefully the last remaining ones
229 * (in the main execution paths, anyway).
231 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
232 * Addressed bug #719435
233 * - Extraneous filterfile directives now logged as errors
234 * - This and unrecnonised directives now really obvious on status page
236 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
237 * Cosmetic: Renamed cryptic variable
239 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
240 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
242 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
243 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
245 * Revision 1.48 2002/05/14 21:30:38 oes
246 * savearg now uses own linking code instead of (now special-cased) add_help_link
248 * Revision 1.47 2002/05/12 21:36:29 jongfoster
249 * Correcting function comments
251 * Revision 1.46 2002/04/26 12:55:14 oes
252 * - New option "user-manual", defaults to our site
253 * via project.h #define
254 * - savearg now embeds option names in help links
256 * Revision 1.45 2002/04/24 02:11:54 oes
257 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
259 * Revision 1.44 2002/04/08 20:37:13 swa
262 * Revision 1.43 2002/04/08 20:36:50 swa
265 * Revision 1.42 2002/04/05 15:50:15 oes
266 * fix for invalid HTML proxy_args
268 * Revision 1.41 2002/03/31 17:19:00 jongfoster
269 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
271 * Revision 1.40 2002/03/26 22:29:55 swa
272 * we have a new homepage!
274 * Revision 1.39 2002/03/24 13:25:43 swa
275 * name change related issues
277 * Revision 1.38 2002/03/24 13:05:48 jongfoster
278 * Renaming re_filterfile to filterfile
280 * Revision 1.37 2002/03/16 23:54:06 jongfoster
281 * Adding graceful termination feature, to help look for memory leaks.
282 * If you enable this (which, by design, has to be done by hand
283 * editing config.h) and then go to http://i.j.b/die, then the program
284 * will exit cleanly after the *next* request. It should free all the
285 * memory that was used.
287 * Revision 1.36 2002/03/13 00:27:05 jongfoster
290 * Revision 1.35 2002/03/07 03:52:44 oes
291 * Set logging to tty for --no-daemon mode
293 * Revision 1.34 2002/03/06 23:14:35 jongfoster
294 * Trivial cosmetic changes to make function comments easier to find.
296 * Revision 1.33 2002/03/05 04:52:42 oes
297 * Deleted non-errlog debugging code
299 * Revision 1.32 2002/03/04 18:24:53 oes
300 * Re-enabled output of unknown config directive hash
302 * Revision 1.31 2002/03/03 15:07:20 oes
303 * Re-enabled automatic config reloading
305 * Revision 1.30 2002/01/22 23:31:43 jongfoster
306 * Replacing strsav() with string_append()
308 * Revision 1.29 2002/01/17 21:02:30 jongfoster
309 * Moving all our URL and URL pattern parsing code to urlmatch.c.
311 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
313 * Revision 1.28 2001/12/30 14:07:32 steudten
314 * - Add signal handling (unix)
315 * - Add SIGHUP handler (unix)
316 * - Add creation of pidfile (unix)
317 * - Add action 'top' in rc file (RH)
318 * - Add entry 'SIGNALS' to manpage
319 * - Add exit message to logfile (unix)
321 * Revision 1.27 2001/11/07 00:02:13 steudten
322 * Add line number in error output for lineparsing for
323 * actionsfile and configfile.
324 * Special handling for CLF added.
326 * Revision 1.26 2001/11/05 21:41:43 steudten
327 * Add changes to be a real daemon just for unix os.
328 * (change cwd to /, detach from controlling tty, set
329 * process group and session leader to the own process.
331 * Add some fatal-error log message for failed malloc().
332 * Add '-d' if compiled with 'configure --with-debug' to
333 * enable debug output.
335 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
336 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
337 * threads to call select() simultaneously. So, it's time to do a real, live,
338 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
339 * (native). Both versions will work, but using __OS2__ offers multi-threading.
341 * Revision 1.24 2001/10/23 21:40:30 jongfoster
342 * Added support for enable-edit-actions and enable-remote-toggle config
345 * Revision 1.23 2001/10/07 15:36:00 oes
346 * Introduced new config option "buffer-limit"
348 * Revision 1.22 2001/09/22 16:36:59 jongfoster
349 * Removing unused parameter fs from read_config_line()
351 * Revision 1.21 2001/09/16 17:10:43 jongfoster
352 * Moving function savearg() here, since it was the only thing left in
355 * Revision 1.20 2001/07/30 22:08:36 jongfoster
356 * Tidying up #defines:
357 * - All feature #defines are now of the form FEATURE_xxx
358 * - Permanently turned off WIN_GUI_EDIT
359 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
361 * Revision 1.19 2001/07/15 17:45:16 jongfoster
362 * Removing some unused #includes
364 * Revision 1.18 2001/07/13 14:01:14 oes
365 * - Removed all #ifdef PCRS
366 * - Removed vim-settings
368 * Revision 1.17 2001/06/29 13:31:03 oes
369 * - Improved comments
370 * - Fixed (actionsfile) and sorted hashes
371 * - Introduced admin_address and proxy-info-url
372 * as config parameters
373 * - Renamed config->proxy_args_invocation (which didn't have
374 * the invocation but the options!) to config->proxy_args
375 * - Various adaptions
376 * - Removed logentry from cancelled commit
378 * Revision 1.16 2001/06/09 10:55:28 jongfoster
379 * Changing BUFSIZ ==> BUFFER_SIZE
381 * Revision 1.15 2001/06/07 23:13:40 jongfoster
382 * Merging ACL and forward files into config file.
383 * Cosmetic: Sorting config file options alphabetically.
384 * Cosmetic: Adding brief syntax comments to config file options.
386 * Revision 1.14 2001/06/07 14:46:25 joergs
387 * Missing make_path() added for re_filterfile.
389 * Revision 1.13 2001/06/05 22:33:54 jongfoster
391 * Fixed minor memory leak.
392 * Also now uses make_path to prepend the pathnames.
394 * Revision 1.12 2001/06/05 20:04:09 jongfoster
395 * Now uses _snprintf() in place of snprintf() under Win32.
397 * Revision 1.11 2001/06/04 18:31:58 swa
398 * files are now prefixed with either `confdir' or `logdir'.
399 * `make redhat-dist' replaces both entries confdir and logdir
402 * Revision 1.10 2001/06/03 19:11:54 oes
403 * introduced confdir option
405 * Revision 1.9 2001/06/01 20:06:24 jongfoster
406 * Removed support for "tinygif" option - moved to actions file.
408 * Revision 1.8 2001/05/31 21:27:13 jongfoster
409 * Removed many options from the config file and into the
410 * "actions" file: add_forwarded, suppress_vanilla_wafer,
411 * wafer, add_header, user_agent, referer, from
412 * Also globally replaced "permission" with "action".
414 * Revision 1.7 2001/05/29 09:50:24 jongfoster
415 * Unified blocklist/imagelist/permissionslist.
416 * File format is still under discussion, but the internal changes
419 * Also modified interceptor behaviour:
420 * - We now intercept all URLs beginning with one of the following
421 * prefixes (and *only* these prefixes):
423 * * http://ijbswa.sf.net/config/
424 * * http://ijbswa.sourceforge.net/config/
425 * - New interceptors "home page" - go to http://i.j.b/ to see it.
426 * - Internal changes so that intercepted and fast redirect pages
427 * are not replaced with an image.
428 * - Interceptors now have the option to send a binary page direct
429 * to the client. (i.e. ijb-send-banner uses this)
430 * - Implemented show-url-info interceptor. (Which is why I needed
431 * the above interceptors changes - a typical URL is
432 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
433 * The previous mechanism would not have intercepted that, and
434 * if it had been intercepted then it then it would have replaced
437 * Revision 1.6 2001/05/26 00:28:36 jongfoster
438 * Automatic reloading of config file.
439 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
440 * Most of the global variables have been moved to a new
441 * struct configuration_spec, accessed through csp->config->globalname
442 * Most of the globals remaining are used by the Win32 GUI.
444 * Revision 1.5 2001/05/25 22:34:30 jongfoster
447 * Revision 1.4 2001/05/22 18:46:04 oes
449 * - Enabled filtering banners by size rather than URL
450 * by adding patterns that replace all standard banner
451 * sizes with the "Junkbuster" gif to the re_filterfile
453 * - Enabled filtering WebBugs by providing a pattern
454 * which kills all 1x1 images
456 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
457 * which is selected by the (nonstandard and therefore
458 * capital) letter 'U' in the option string.
459 * It causes the quantifiers to be ungreedy by default.
460 * Appending a ? turns back to greedy (!).
462 * - Added a new interceptor ijb-send-banner, which
463 * sends back the "Junkbuster" gif. Without imagelist or
464 * MSIE detection support, or if tinygif = 1, or the
465 * URL isn't recognized as an imageurl, a lame HTML
466 * explanation is sent instead.
468 * - Added new feature, which permits blocking remote
469 * script redirects and firing back a local redirect
471 * The feature is conditionally compiled, i.e. it
472 * can be disabled with --disable-fast-redirects,
473 * plus it must be activated by a "fast-redirects"
474 * line in the config file, has its own log level
475 * and of course wants to be displayed by show-proxy-args
476 * Note: Boy, all the #ifdefs in 1001 locations and
477 * all the fumbling with configure.in and acconfig.h
478 * were *way* more work than the feature itself :-(
480 * - Because a generic redirect template was needed for
481 * this, tinygif = 3 now uses the same.
483 * - Moved GIFs, and other static HTTP response templates
488 * - Removed some >400 CRs again (Jon, you really worked
491 * Revision 1.3 2001/05/20 01:21:20 jongfoster
492 * Version 2.9.4 checkin.
493 * - Merged popupfile and cookiefile, and added control over PCRS
494 * filtering, in new "permissionsfile".
495 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
496 * file error you now get a message box (in the Win32 GUI) rather
497 * than the program exiting with no explanation.
498 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
500 * - Removed tabs from "config"
501 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
502 * - Bumped up version number.
504 * Revision 1.2 2001/05/17 23:01:01 oes
505 * - Cleaned CRLF's from the sources and related files
507 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
508 * Initial import of version 2.9.3 source tree
511 *********************************************************************/
517 #include <sys/types.h>
531 # include <windows.h>
534 # ifndef _WIN_CONSOLE
536 # endif /* ndef _WIN_CONSOLE */
538 #else /* ifndef _WIN32 */
542 # include <sys/wait.h>
544 # include <sys/time.h>
545 # include <sys/stat.h>
555 #include "miscutil.h"
559 #include "urlmatch.h"
563 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
566 * Fix a problem with Solaris. There should be no effect on other
568 * Solaris's isspace() is a macro which uses it's argument directly
569 * as an array index. Therefore we need to make sure that high-bit
570 * characters generate +ve values, and ideally we also want to make
571 * the argument match the declared parameter type of "int".
573 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
574 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
576 #ifdef FEATURE_TOGGLE
577 /* Privoxy is enabled by default. */
578 int global_toggle_state = 1;
579 #endif /* def FEATURE_TOGGLE */
581 /* The filename of the configfile */
582 const char *configfile = NULL;
585 * CGI functions will later need access to the invocation args,
586 * so we will make argc and argv global.
589 const char **Argv = NULL;
591 static struct file_list *current_configfile = NULL;
595 * This takes the "cryptic" hash of each keyword and aliases them to
596 * something a little more readable. This also makes changing the
597 * hash values easier if they should change or the hash algorthm changes.
598 * Use the included "hash" program to find out what the hash will be
599 * for any string supplied on the command line. (Or just put it in the
600 * config file and read the number from the error message in the log).
602 * Please keep this list sorted alphabetically (but with the Windows
603 * console and GUI specific options last).
606 #define hash_actions_file 1196306641ul /* "actionsfile" */
607 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
608 #define hash_admin_address 4112573064ul /* "admin-address" */
609 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
610 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
611 #define hash_confdir 1978389ul /* "confdir" */
612 #define hash_debug 78263ul /* "debug" */
613 #define hash_deny_access 1227333715ul /* "deny-access" */
614 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
615 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
616 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
617 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
618 #define hash_filterfile 250887266ul /* "filterfile" */
619 #define hash_forward 2029845ul /* "forward" */
620 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
621 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
622 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
623 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
624 #define hash_hostname 10308071ul /* "hostname" */
625 #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */
626 #define hash_listen_address 1255650842ul /* "listen-address" */
627 #define hash_logdir 422889ul /* "logdir" */
628 #define hash_logfile 2114766ul /* "logfile" */
629 #define hash_permit_access 3587953268ul /* "permit-access" */
630 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
631 #define hash_single_threaded 4250084780ul /* "single-threaded" */
632 #define hash_socket_timeout 1809001761ul /* "socket-timeout" */
633 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
634 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
635 #define hash_templdir 11067889ul /* "templdir" */
636 #define hash_toggle 447966ul /* "toggle" */
637 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
638 #define hash_trustfile 56494766ul /* "trustfile" */
639 #define hash_usermanual 1416668518ul /* "user-manual" */
640 #define hash_activity_animation 1817904738ul /* "activity-animation" */
641 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
642 #define hash_hide_console 2048809870ul /* "hide-console" */
643 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
644 #define hash_log_font_name 2866730124ul /* "log-font-name" */
645 #define hash_log_font_size 2866731014ul /* "log-font-size" */
646 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
647 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
648 #define hash_log_messages 2291744899ul /* "log-messages" */
649 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
652 static void savearg(char *command, char *argument, struct configuration_spec * config);
654 /*********************************************************************
656 * Function : unload_configfile
658 * Description : Free the config structure and all components.
661 * 1 : data: struct configuration_spec to unload
665 *********************************************************************/
666 static void unload_configfile (void * data)
668 struct configuration_spec * config = (struct configuration_spec *)data;
669 struct forward_spec *cur_fwd = config->forward;
673 struct access_control_list *cur_acl = config->acl;
675 while (cur_acl != NULL)
677 struct access_control_list * next_acl = cur_acl->next;
682 #endif /* def FEATURE_ACL */
684 while (cur_fwd != NULL)
686 struct forward_spec * next_fwd = cur_fwd->next;
687 free_url_spec(cur_fwd->url);
689 freez(cur_fwd->gateway_host);
690 freez(cur_fwd->forward_host);
694 config->forward = NULL;
696 freez(config->confdir);
697 freez(config->logdir);
698 freez(config->templdir);
699 freez(config->hostname);
701 freez(config->haddr);
702 freez(config->logfile);
704 for (i = 0; i < MAX_AF_FILES; i++)
706 freez(config->actions_file_short[i]);
707 freez(config->actions_file[i]);
708 freez(config->re_filterfile_short[i]);
709 freez(config->re_filterfile[i]);
712 freez(config->admin_address);
713 freez(config->proxy_info_url);
714 freez(config->proxy_args);
715 freez(config->usermanual);
718 freez(config->trustfile);
719 list_remove_all(config->trust_info);
720 #endif /* def FEATURE_TRUST */
722 for (i = 0; i < MAX_AF_FILES; i++)
724 freez(config->re_filterfile[i]);
731 #ifdef FEATURE_GRACEFUL_TERMINATION
732 /*********************************************************************
734 * Function : unload_current_config_file
736 * Description : Unloads current config file - reset to state at
737 * beginning of program.
743 *********************************************************************/
744 void unload_current_config_file(void)
746 if (current_configfile)
748 current_configfile->unloader = unload_configfile;
749 current_configfile = NULL;
755 /*********************************************************************
757 * Function : load_config
759 * Description : Load the config file and all parameters.
761 * XXX: more than thousand lines long
762 * and thus in serious need of refactoring.
766 * Returns : The configuration_spec, or NULL on error.
768 *********************************************************************/
769 struct configuration_spec * load_config(void)
771 char buf[BUFFER_SIZE];
773 FILE *configfp = NULL;
774 struct configuration_spec * config = NULL;
775 struct client_state * fake_csp;
776 struct file_list *fs;
777 unsigned long linenum = 0;
779 char *logfile = NULL;
780 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
781 int keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
784 if (!check_file_changed(current_configfile, configfile, &fs))
786 /* No need to load */
787 return ((struct configuration_spec *)current_configfile->f);
791 log_error(LOG_LEVEL_FATAL,
792 "can't check configuration file '%s': %E", configfile);
796 if (NULL != current_configfile)
798 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
801 #ifdef FEATURE_TOGGLE
802 global_toggle_state = 1;
803 #endif /* def FEATURE_TOGGLE */
805 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
811 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
816 * This is backwards from how it's usually done.
817 * Following the usual pattern, "fs" would be stored in a member
818 * variable in "csp", and then we'd access "config" from "fs->f",
819 * using a cast. However, "config" is used so often that a
820 * cast each time would be very ugly, and the extra indirection
821 * would waste CPU cycles. Therefore we store "config" in
822 * "csp->config", and "fs" in "csp->config->config_file_list".
824 config->config_file_list = fs;
829 config->multi_threaded = 1;
830 config->hport = HADDR_PORT;
831 config->buffer_limit = 4096 * 1024;
832 config->usermanual = strdup(USER_MANUAL_URL);
833 config->proxy_args = strdup("");
834 config->forwarded_connect_retries = 0;
835 config->socket_timeout = 300; /* XXX: Should be a macro. */
836 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
837 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
838 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
840 configfp = fopen(configfile, "r");
841 if (NULL == configfp)
843 log_error(LOG_LEVEL_FATAL,
844 "can't open configuration file '%s': %E", configfile);
845 /* Never get here - LOG_LEVEL_FATAL causes program exit */
848 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
850 char cmd[BUFFER_SIZE];
851 char arg[BUFFER_SIZE];
852 char tmp[BUFFER_SIZE];
854 struct access_control_list *cur_acl;
855 #endif /* def FEATURE_ACL */
856 struct forward_spec *cur_fwd;
859 unsigned long directive_hash;
861 strlcpy(tmp, buf, sizeof(tmp));
863 /* Copy command (i.e. up to space or tab) into cmd */
866 while (*p && (*p != ' ') && (*p != '\t'))
872 /* Skip over the whitespace in buf */
873 while (*p && ((*p == ' ') || (*p == '\t')))
878 /* Copy the argument into arg */
879 strlcpy(arg, p, sizeof(arg));
881 /* Should never happen, but check this anyway */
887 /* Make sure the command field is lower case */
888 for (p = cmd; *p; p++)
892 *p = (char)ijb_tolower(*p);
896 directive_hash = hash_string(cmd);
897 switch (directive_hash)
899 /* *************************************************************************
900 * actionsfile actions-file-name
901 * In confdir by default
902 * *************************************************************************/
903 case hash_actions_file :
905 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
910 if (i >= MAX_AF_FILES)
912 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
913 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
916 config->actions_file_short[i] = strdup(arg);
917 config->actions_file[i] = make_path(config->confdir, arg);
920 /* *************************************************************************
921 * accept-intercepted-requests
922 * *************************************************************************/
923 case hash_accept_intercepted_requests:
924 if ((*arg != '\0') && (0 != atoi(arg)))
926 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
930 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
934 /* *************************************************************************
935 * admin-address email-address
936 * *************************************************************************/
937 case hash_admin_address :
938 freez(config->admin_address);
939 config->admin_address = strdup(arg);
942 /* *************************************************************************
943 * allow-cgi-request-crunching
944 * *************************************************************************/
945 case hash_allow_cgi_request_crunching:
946 if ((*arg != '\0') && (0 != atoi(arg)))
948 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
952 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
956 /* *************************************************************************
958 * *************************************************************************/
959 case hash_buffer_limit :
960 config->buffer_limit = (size_t)(1024 * atoi(arg));
963 /* *************************************************************************
964 * confdir directory-name
965 * *************************************************************************/
967 freez(config->confdir);
968 config->confdir = make_path( NULL, arg);
971 /* *************************************************************************
973 * Specifies debug level, multiple values are ORed together.
974 * *************************************************************************/
976 config->debug |= atoi(arg);
979 /* *************************************************************************
980 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
981 * *************************************************************************/
983 case hash_deny_access:
984 strlcpy(tmp, arg, sizeof(tmp));
985 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
987 if ((vec_count != 1) && (vec_count != 2))
989 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
990 "deny-access directive in configuration file.");
991 string_append(&config->proxy_args,
992 "<br>\nWARNING: Wrong number of parameters for "
993 "deny-access directive in configuration file.<br><br>\n");
997 /* allocate a new node */
998 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1000 if (cur_acl == NULL)
1002 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1003 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1006 cur_acl->action = ACL_DENY;
1008 if (acl_addr(vec[0], cur_acl->src) < 0)
1010 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1011 "for deny-access directive in configuration file: \"%s\"", vec[0]);
1012 string_append(&config->proxy_args,
1013 "<br>\nWARNING: Invalid source address, port or netmask "
1014 "for deny-access directive in configuration file: \"");
1015 string_append(&config->proxy_args,
1017 string_append(&config->proxy_args,
1024 if (acl_addr(vec[1], cur_acl->dst) < 0)
1026 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1027 "for deny-access directive in configuration file: \"%s\"", vec[1]);
1028 string_append(&config->proxy_args,
1029 "<br>\nWARNING: Invalid destination address, port or netmask "
1030 "for deny-access directive in configuration file: \"");
1031 string_append(&config->proxy_args,
1033 string_append(&config->proxy_args,
1041 * Add it to the list. Note we reverse the list to get the
1042 * behaviour the user expects. With both the ACL and
1043 * actions file, the last match wins. However, the internal
1044 * implementations are different: The actions file is stored
1045 * in the same order as the file, and scanned completely.
1046 * With the ACL, we reverse the order as we load it, then
1047 * when we scan it we stop as soon as we get a match.
1049 cur_acl->next = config->acl;
1050 config->acl = cur_acl;
1053 #endif /* def FEATURE_ACL */
1055 /* *************************************************************************
1056 * enable-edit-actions 0|1
1057 * *************************************************************************/
1058 #ifdef FEATURE_CGI_EDIT_ACTIONS
1059 case hash_enable_edit_actions:
1060 if ((*arg != '\0') && (0 != atoi(arg)))
1062 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1066 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1069 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1071 /* *************************************************************************
1072 * enable-remote-toggle 0|1
1073 * *************************************************************************/
1074 #ifdef FEATURE_TOGGLE
1075 case hash_enable_remote_toggle:
1076 if ((*arg != '\0') && (0 != atoi(arg)))
1078 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1082 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1085 #endif /* def FEATURE_TOGGLE */
1087 /* *************************************************************************
1088 * enable-remote-http-toggle 0|1
1089 * *************************************************************************/
1090 case hash_enable_remote_http_toggle:
1091 if ((*arg != '\0') && (0 != atoi(arg)))
1093 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1097 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1101 /* *************************************************************************
1102 * enforce-blocks 0|1
1103 * *************************************************************************/
1104 case hash_enforce_blocks:
1105 #ifdef FEATURE_FORCE_LOAD
1106 if ((*arg != '\0') && (0 != atoi(arg)))
1108 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1112 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1115 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1116 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1117 #endif /* def FEATURE_FORCE_LOAD */
1120 /* *************************************************************************
1121 * filterfile file-name
1122 * In confdir by default.
1123 * *************************************************************************/
1124 case hash_filterfile :
1126 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1131 if (i >= MAX_AF_FILES)
1133 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1134 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1137 config->re_filterfile_short[i] = strdup(arg);
1138 config->re_filterfile[i] = make_path(config->confdir, arg);
1142 /* *************************************************************************
1143 * forward url-pattern (.|http-proxy-host[:port])
1144 * *************************************************************************/
1146 strlcpy(tmp, arg, sizeof(tmp));
1147 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1151 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1152 "directive in configuration file.");
1153 string_append(&config->proxy_args,
1154 "<br>\nWARNING: Wrong number of parameters for "
1155 "forward directive in configuration file.");
1159 /* allocate a new node */
1160 cur_fwd = zalloc(sizeof(*cur_fwd));
1161 if (cur_fwd == NULL)
1163 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1164 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1168 cur_fwd->type = SOCKS_NONE;
1170 /* Save the URL pattern */
1171 if (create_url_spec(cur_fwd->url, vec[0]))
1173 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1174 "directive in configuration file.");
1175 string_append(&config->proxy_args,
1176 "<br>\nWARNING: Bad URL specifier for "
1177 "forward directive in configuration file.");
1181 /* Parse the parent HTTP proxy host:port */
1184 if (strcmp(p, ".") != 0)
1186 cur_fwd->forward_host = strdup(p);
1188 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1191 cur_fwd->forward_port = atoi(p);
1194 if (cur_fwd->forward_port <= 0)
1196 cur_fwd->forward_port = 8000;
1201 cur_fwd->next = config->forward;
1202 config->forward = cur_fwd;
1206 /* *************************************************************************
1207 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1208 * *************************************************************************/
1209 case hash_forward_socks4:
1210 strlcpy(tmp, arg, sizeof(tmp));
1211 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1215 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1216 "forward-socks4 directive in configuration file.");
1217 string_append(&config->proxy_args,
1218 "<br>\nWARNING: Wrong number of parameters for "
1219 "forward-socks4 directive in configuration file.");
1223 /* allocate a new node */
1224 cur_fwd = zalloc(sizeof(*cur_fwd));
1225 if (cur_fwd == NULL)
1227 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1228 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1232 cur_fwd->type = SOCKS_4;
1234 /* Save the URL pattern */
1235 if (create_url_spec(cur_fwd->url, vec[0]))
1237 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1238 "directive in configuration file.");
1239 string_append(&config->proxy_args,
1240 "<br>\nWARNING: Bad URL specifier for "
1241 "forward-socks4 directive in configuration file.");
1245 /* Parse the SOCKS proxy host[:port] */
1248 if (strcmp(p, ".") != 0)
1250 cur_fwd->gateway_host = strdup(p);
1252 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1255 cur_fwd->gateway_port = atoi(p);
1257 if (cur_fwd->gateway_port <= 0)
1259 cur_fwd->gateway_port = 1080;
1263 /* Parse the parent HTTP proxy host[:port] */
1266 if (strcmp(p, ".") != 0)
1268 cur_fwd->forward_host = strdup(p);
1270 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1273 cur_fwd->forward_port = atoi(p);
1276 if (cur_fwd->forward_port <= 0)
1278 cur_fwd->forward_port = 8000;
1283 cur_fwd->next = config->forward;
1284 config->forward = cur_fwd;
1288 /* *************************************************************************
1289 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1290 * *************************************************************************/
1291 case hash_forward_socks4a:
1292 case hash_forward_socks5:
1293 strlcpy(tmp, arg, sizeof(tmp));
1294 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1298 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1299 "forward-socks4a directive in configuration file.");
1300 string_append(&config->proxy_args,
1301 "<br>\nWARNING: Wrong number of parameters for "
1302 "forward-socks4a directive in configuration file.");
1306 /* allocate a new node */
1307 cur_fwd = zalloc(sizeof(*cur_fwd));
1308 if (cur_fwd == NULL)
1310 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1311 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1315 if (directive_hash == hash_forward_socks4a)
1317 cur_fwd->type = SOCKS_4A;
1321 cur_fwd->type = SOCKS_5;
1324 /* Save the URL pattern */
1325 if (create_url_spec(cur_fwd->url, vec[0]))
1327 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1328 "directive in configuration file.");
1329 string_append(&config->proxy_args,
1330 "<br>\nWARNING: Bad URL specifier for "
1331 "forward-socks4a directive in configuration file.");
1335 /* Parse the SOCKS proxy host[:port] */
1338 cur_fwd->gateway_host = strdup(p);
1340 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1343 cur_fwd->gateway_port = atoi(p);
1345 if (cur_fwd->gateway_port <= 0)
1347 cur_fwd->gateway_port = 1080;
1350 /* Parse the parent HTTP proxy host[:port] */
1353 if (strcmp(p, ".") != 0)
1355 cur_fwd->forward_host = strdup(p);
1357 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1360 cur_fwd->forward_port = atoi(p);
1363 if (cur_fwd->forward_port <= 0)
1365 cur_fwd->forward_port = 8000;
1370 cur_fwd->next = config->forward;
1371 config->forward = cur_fwd;
1375 /* *************************************************************************
1376 * forwarded-connect-retries n
1377 * *************************************************************************/
1378 case hash_forwarded_connect_retries :
1379 config->forwarded_connect_retries = atoi(arg);
1382 /* *************************************************************************
1383 * hostname hostname-to-show-on-cgi-pages
1384 * *************************************************************************/
1385 case hash_hostname :
1386 freez(config->hostname);
1387 config->hostname = strdup(arg);
1388 if (NULL == config->hostname)
1390 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1394 /* *************************************************************************
1395 * keep-alive-timeout timeout
1396 * *************************************************************************/
1397 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1398 case hash_keep_alive_timeout :
1401 int timeout = atoi(arg);
1404 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1405 keep_alive_timeout = timeout;
1409 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1415 /* *************************************************************************
1416 * listen-address [ip][:port]
1417 * *************************************************************************/
1418 case hash_listen_address :
1419 freez(config->haddr);
1420 config->haddr = strdup(arg);
1423 /* *************************************************************************
1424 * logdir directory-name
1425 * *************************************************************************/
1427 freez(config->logdir);
1428 config->logdir = make_path(NULL, arg);
1431 /* *************************************************************************
1432 * logfile log-file-name
1433 * In logdir by default
1434 * *************************************************************************/
1438 logfile = make_path(config->logdir, arg);
1439 if (NULL == logfile)
1441 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1446 /* *************************************************************************
1447 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1448 * *************************************************************************/
1450 case hash_permit_access:
1451 strlcpy(tmp, arg, sizeof(tmp));
1452 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1454 if ((vec_count != 1) && (vec_count != 2))
1456 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1457 "permit-access directive in configuration file.");
1458 string_append(&config->proxy_args,
1459 "<br>\nWARNING: Wrong number of parameters for "
1460 "permit-access directive in configuration file.<br><br>\n");
1465 /* allocate a new node */
1466 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1468 if (cur_acl == NULL)
1470 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1471 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1474 cur_acl->action = ACL_PERMIT;
1476 if (acl_addr(vec[0], cur_acl->src) < 0)
1478 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1479 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1480 string_append(&config->proxy_args,
1481 "<br>\nWARNING: Invalid source address, port or netmask for "
1482 "permit-access directive in configuration file: \"");
1483 string_append(&config->proxy_args,
1485 string_append(&config->proxy_args,
1492 if (acl_addr(vec[1], cur_acl->dst) < 0)
1494 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1495 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1496 string_append(&config->proxy_args,
1497 "<br>\nWARNING: Invalid destination address, port or netmask for "
1498 "permit-access directive in configuration file: \"");
1499 string_append(&config->proxy_args,
1501 string_append(&config->proxy_args,
1509 * Add it to the list. Note we reverse the list to get the
1510 * behaviour the user expects. With both the ACL and
1511 * actions file, the last match wins. However, the internal
1512 * implementations are different: The actions file is stored
1513 * in the same order as the file, and scanned completely.
1514 * With the ACL, we reverse the order as we load it, then
1515 * when we scan it we stop as soon as we get a match.
1517 cur_acl->next = config->acl;
1518 config->acl = cur_acl;
1521 #endif /* def FEATURE_ACL */
1523 /* *************************************************************************
1524 * proxy-info-url url
1525 * *************************************************************************/
1526 case hash_proxy_info_url :
1527 freez(config->proxy_info_url);
1528 config->proxy_info_url = strdup(arg);
1531 /* *************************************************************************
1533 * *************************************************************************/
1534 case hash_single_threaded :
1535 config->multi_threaded = 0;
1538 /* *************************************************************************
1539 * socket-timeout numer_of_seconds
1540 * *************************************************************************/
1541 case hash_socket_timeout :
1544 int socket_timeout = atoi(arg);
1545 if (0 < socket_timeout)
1547 config->socket_timeout = socket_timeout;
1551 log_error(LOG_LEVEL_FATAL,
1552 "Invalid socket-timeout: '%s'", arg);
1557 /* *************************************************************************
1558 * split-large-cgi-forms
1559 * *************************************************************************/
1560 case hash_split_large_cgi_forms :
1561 if ((*arg != '\0') && (0 != atoi(arg)))
1563 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1567 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1571 /* *************************************************************************
1572 * templdir directory-name
1573 * *************************************************************************/
1574 case hash_templdir :
1575 freez(config->templdir);
1576 config->templdir = make_path(NULL, arg);
1579 /* *************************************************************************
1581 * *************************************************************************/
1582 #ifdef FEATURE_TOGGLE
1584 global_toggle_state = atoi(arg);
1586 #endif /* def FEATURE_TOGGLE */
1588 /* *************************************************************************
1589 * trust-info-url url
1590 * *************************************************************************/
1591 #ifdef FEATURE_TRUST
1592 case hash_trust_info_url :
1593 enlist(config->trust_info, arg);
1595 #endif /* def FEATURE_TRUST */
1597 /* *************************************************************************
1598 * trustfile filename
1599 * (In confdir by default.)
1600 * *************************************************************************/
1601 #ifdef FEATURE_TRUST
1602 case hash_trustfile :
1603 freez(config->trustfile);
1604 config->trustfile = make_path(config->confdir, arg);
1606 #endif /* def FEATURE_TRUST */
1608 /* *************************************************************************
1610 * *************************************************************************/
1611 case hash_usermanual :
1613 * XXX: If this isn't the first config directive, the
1614 * show-status page links to the website documentation
1615 * for the directives that were already parsed. Lame.
1617 freez(config->usermanual);
1618 config->usermanual = strdup(arg);
1621 /* *************************************************************************
1622 * Win32 Console options:
1623 * *************************************************************************/
1625 /* *************************************************************************
1627 * *************************************************************************/
1629 case hash_hide_console :
1632 #endif /*def _WIN_CONSOLE*/
1635 /* *************************************************************************
1636 * Win32 GUI options:
1637 * *************************************************************************/
1639 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1640 /* *************************************************************************
1641 * activity-animation (0|1)
1642 * *************************************************************************/
1643 case hash_activity_animation :
1644 g_bShowActivityAnimation = atoi(arg);
1647 /* *************************************************************************
1648 * close-button-minimizes (0|1)
1649 * *************************************************************************/
1650 case hash_close_button_minimizes :
1651 g_bCloseHidesWindow = atoi(arg);
1654 /* *************************************************************************
1655 * log-buffer-size (0|1)
1656 * *************************************************************************/
1657 case hash_log_buffer_size :
1658 g_bLimitBufferSize = atoi(arg);
1661 /* *************************************************************************
1662 * log-font-name fontname
1663 * *************************************************************************/
1664 case hash_log_font_name :
1665 if (strlcpy(g_szFontFaceName, arg,
1666 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1668 log_error(LOG_LEVEL_FATAL,
1669 "log-font-name argument '%s' is longer than %u characters.",
1670 arg, sizeof(g_szFontFaceName)-1);
1674 /* *************************************************************************
1676 * *************************************************************************/
1677 case hash_log_font_size :
1678 g_nFontSize = atoi(arg);
1681 /* *************************************************************************
1682 * log-highlight-messages (0|1)
1683 * *************************************************************************/
1684 case hash_log_highlight_messages :
1685 g_bHighlightMessages = atoi(arg);
1688 /* *************************************************************************
1690 * *************************************************************************/
1691 case hash_log_max_lines :
1692 g_nMaxBufferLines = atoi(arg);
1695 /* *************************************************************************
1696 * log-messages (0|1)
1697 * *************************************************************************/
1698 case hash_log_messages :
1699 g_bLogMessages = atoi(arg);
1702 /* *************************************************************************
1703 * show-on-task-bar (0|1)
1704 * *************************************************************************/
1705 case hash_show_on_task_bar :
1706 g_bShowOnTaskBar = atoi(arg);
1709 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1712 /* *************************************************************************
1713 * Warnings about unsupported features
1714 * *************************************************************************/
1716 case hash_deny_access:
1717 #endif /* ndef FEATURE_ACL */
1718 #ifndef FEATURE_CGI_EDIT_ACTIONS
1719 case hash_enable_edit_actions:
1720 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1721 #ifndef FEATURE_TOGGLE
1722 case hash_enable_remote_toggle:
1723 #endif /* ndef FEATURE_TOGGLE */
1725 case hash_permit_access:
1726 #endif /* ndef FEATURE_ACL */
1727 #ifndef FEATURE_TOGGLE
1729 #endif /* ndef FEATURE_TOGGLE */
1730 #ifndef FEATURE_TRUST
1731 case hash_trustfile :
1732 case hash_trust_info_url :
1733 #endif /* ndef FEATURE_TRUST */
1735 #ifndef _WIN_CONSOLE
1736 case hash_hide_console :
1737 #endif /* ndef _WIN_CONSOLE */
1739 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1740 case hash_activity_animation :
1741 case hash_close_button_minimizes :
1742 case hash_log_buffer_size :
1743 case hash_log_font_name :
1744 case hash_log_font_size :
1745 case hash_log_highlight_messages :
1746 case hash_log_max_lines :
1747 case hash_log_messages :
1748 case hash_show_on_task_bar :
1749 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1750 /* These warnings are annoying - so hide them. -- Jon */
1751 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1754 /* *************************************************************************/
1756 /* *************************************************************************/
1758 * I decided that I liked this better as a warning than an
1759 * error. To change back to an error, just change log level
1760 * to LOG_LEVEL_FATAL.
1762 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1763 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1764 string_append(&config->proxy_args,
1765 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1768 /* *************************************************************************/
1769 } /* end switch( hash_string(cmd) ) */
1771 /* Save the argument for the show-status page. */
1772 savearg(cmd, arg, config);
1774 } /* end while ( read_config_line(...) ) */
1778 freez(config->logfile);
1782 if (NULL != logfile)
1784 config->logfile = logfile;
1785 init_error_log(Argv[0], config->logfile);
1793 set_debug_level(config->debug);
1795 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1796 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1798 if (config->multi_threaded)
1800 set_keep_alive_timeout(keep_alive_timeout);
1805 * While we could use keep-alive without multiple threads
1806 * if we didn't bother with enforcing the connection timeout,
1807 * that might make Tor users sad, even though they shouldn't
1808 * enable the single-threaded option anyway.
1810 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1811 log_error(LOG_LEVEL_ERROR,
1812 "Config option single-threaded disables connection keep-alive.");
1817 if (NULL == config->proxy_args)
1819 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1822 if (config->actions_file[0])
1824 add_loader(load_action_files, config);
1827 if (config->re_filterfile[0])
1829 add_loader(load_re_filterfiles, config);
1832 #ifdef FEATURE_TRUST
1833 if (config->trustfile)
1835 add_loader(load_trustfile, config);
1837 #endif /* def FEATURE_TRUST */
1839 if ( NULL == config->haddr )
1841 config->haddr = strdup( HADDR_DEFAULT );
1844 if ( NULL != config->haddr )
1846 if (NULL != (p = strchr(config->haddr, ':')))
1851 config->hport = atoi(p);
1855 if (config->hport <= 0)
1858 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1859 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1861 if (*config->haddr == '\0')
1864 * Only the port specified. We stored it in config->hport
1865 * and don't need its text representation anymore.
1867 freez(config->haddr);
1872 * Want to run all the loaders once now.
1874 * Need to set up a fake csp, so they can get to the config.
1876 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1877 fake_csp->config = config;
1879 if (run_loader(fake_csp))
1882 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1883 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1887 /* FIXME: this is a kludge for win32 */
1888 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1890 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1891 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1892 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1894 #ifdef FEATURE_TRUST
1895 g_trustfile = config->trustfile;
1896 #endif /* def FEATURE_TRUST */
1899 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1900 /* FIXME: end kludge */
1903 config->need_bind = 1;
1905 if (current_configfile)
1907 struct configuration_spec * oldcfg = (struct configuration_spec *)
1908 current_configfile->f;
1910 * Check if config->haddr,hport == oldcfg->haddr,hport
1912 * The following could be written more compactly as a single,
1913 * (unreadably long) if statement.
1915 config->need_bind = 0;
1916 if (config->hport != oldcfg->hport)
1918 config->need_bind = 1;
1920 else if (config->haddr == NULL)
1922 if (oldcfg->haddr != NULL)
1924 config->need_bind = 1;
1927 else if (oldcfg->haddr == NULL)
1929 config->need_bind = 1;
1931 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1933 config->need_bind = 1;
1936 current_configfile->unloader = unload_configfile;
1939 fs->next = files->next;
1942 current_configfile = fs;
1948 /*********************************************************************
1950 * Function : savearg
1952 * Description : Called from `load_config'. It saves each non-empty
1953 * and non-comment line from config into
1954 * config->proxy_args. This is used to create the
1955 * show-proxy-args page. On error, frees
1956 * config->proxy_args and sets it to NULL
1959 * 1 : command = config setting that was found
1960 * 2 : argument = the setting's argument (if any)
1961 * 3 : config = Configuration to save into.
1965 *********************************************************************/
1966 static void savearg(char *command, char *argument, struct configuration_spec * config)
1975 * Add config option name embedded in
1976 * link to its section in the user-manual
1978 buf = strdup("\n<a href=\"");
1979 if (!strncmpic(config->usermanual, "file://", 7) ||
1980 !strncmpic(config->usermanual, "http", 4))
1982 string_append(&buf, config->usermanual);
1986 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1988 string_append(&buf, CONFIG_HELP_PREFIX);
1989 string_join (&buf, string_toupper(command));
1990 string_append(&buf, "\">");
1991 string_append(&buf, command);
1992 string_append(&buf, "</a> ");
1996 freez(config->proxy_args);
2000 if ( (NULL != argument) && ('\0' != *argument) )
2002 s = html_encode(argument);
2006 freez(config->proxy_args);
2010 if (strncmpic(argument, "http://", 7) == 0)
2012 string_append(&buf, "<a href=\"");
2013 string_append(&buf, s);
2014 string_append(&buf, "\">");
2015 string_join (&buf, s);
2016 string_append(&buf, "</a>");
2020 string_join (&buf, s);
2024 string_append(&buf, "<br>");
2025 string_join(&config->proxy_args, buf);