1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.86 2009/02/08 19:18:57 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-2008 the SourceForge
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.86 2009/02/08 19:18:57 fabiankeil
39 * Now that we have the match-all.action file, the other action
40 * files changed their position in config->actions_file[] back
41 * to the way it was before standard.action got removed and the
42 * changes from revision 1.84 have to be reverted.
44 * Revision 1.85 2009/01/22 12:06:26 fabiankeil
45 * Don't keep connections alive when running single-threaded.
47 * Revision 1.84 2009/01/14 16:14:36 fabiankeil
48 * Due to the standard.action file removal, the other action
49 * files changed their position in config->actions_file[].
50 * Update mingw32 kludge accordingly.
52 * Revision 1.83 2008/12/20 14:53:55 fabiankeil
53 * Add config option socket-timeout to control the time
54 * Privoxy waits for data to arrive on a socket. Useful
55 * in case of stale ssh tunnels or when fuzz-testing.
57 * Revision 1.82 2008/11/16 12:43:49 fabiankeil
58 * Turn keep-alive support into a runtime feature
59 * that is disabled by setting keep-alive-timeout
60 * to a negative value.
62 * Revision 1.81 2008/11/13 09:08:42 fabiankeil
63 * Add new config option: keep-alive-timeout.
65 * Revision 1.80 2008/08/31 15:59:03 fabiankeil
66 * There's no reason to let remote toggling support depend
67 * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
69 * Revision 1.79 2008/08/30 12:03:07 fabiankeil
70 * Remove FEATURE_COOKIE_JAR.
72 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
73 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
74 * disabled, log a message that blocks will always be enforced
75 * instead of complaining about an unrecognized directive.
76 * Reported by Pietro Leone.
78 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
79 * Reuse directive_hash and don't hash the same directive twice.
81 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
82 * - Merge three string_append() calls.
83 * - Remove useless assertion.
85 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
86 * Rename load_actions_file() and load_re_filterfile()
87 * as they load multiple files "now".
89 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
90 * Add hostname directive. Closes PR#1918189.
92 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
95 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
96 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
98 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
99 * Reword "unrecognized directive" warning, use better
100 * mark up and add a <br>. Fixes parts of #1856559.
102 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
103 * Plug memory leak if listen-address only specifies the port.
105 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
106 * Relocate daemon-mode-related log messages to make sure
107 * they aren't shown again in case of configuration reloads.
109 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
110 * Plug memory leak introduced with my last commit.
112 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
113 * When in daemon mode, close stderr after the configuration file has been
114 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
116 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
117 * #1763173 from Stefan Huehner: declare unload_configfile() static.
119 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
120 * As Hal noticed, checking dispatch_cgi() as the last cruncher
121 * looks like a bug if CGI requests are blocked unintentionally,
122 * so don't do it unless the user enabled the new config option
123 * "allow-cgi-request-crunching".
125 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
126 * - Use strlcpy() instead of strcpy().
127 * - Stop treating actions files special. Expect a complete file name
128 * (with or without path) like it's done for the rest of the files.
130 * - Remove an unnecessary temporary memory allocation.
131 * - Don't log anything to the console when running as
132 * daemon and no errors occurred.
134 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
135 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
137 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
138 * New config option: enforce-blocks.
140 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
141 * - Mention other reasons why acl directive loading might have failed.
142 * - Don't log the acl source if the acl destination is to blame.
144 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
145 * Add new config option "templdir" to
146 * change the templates directory.
148 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
149 * Added config option accept-intercepted-requests
150 * and disabled it by default.
152 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
153 * Fix gcc43 compiler warnings.
155 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
156 * Add config option "split-large-forms"
157 * to work around the browser bug reported
160 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
161 * Move the <br> in the generated HTML for the config
162 * options from the beginning of the string to its end.
163 * Keeps the white space in balance.
165 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
166 * Fix memory leak in case of config file reloads.
168 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
169 * Modified kludge for win32 to make ming32 menu
170 * "Options/Edit Filters" (sort of) work again.
171 * Same limitations as for the action files apply.
174 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
175 * Incorporate modified version of Roland Rosenfeld's patch to
176 * optionally access the user-manual via Privoxy. Closes patch 679075.
178 * Formatting changed to Privoxy style, added call to
179 * cgi_error_no_template if the requested file doesn't
180 * exist and modified check whether or not Privoxy itself
181 * should serve the manual. Should work cross-platform now.
183 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
184 * Added config option enable-remote-http-toggle
185 * to specify if Privoxy should recognize special
186 * headers (currently only X-Filter) to change its
187 * behaviour. Disabled by default.
189 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
190 * Make number of retries in case of forwarded-connect problems
191 * a config file option (forwarded-connect-retries) and use 0 as
194 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
195 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
196 * with what was really the latest development (the v_3_0_branch branch)
198 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
199 * Don't forget to malloc space for the null terminator...
201 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
202 * Multiple filter file support
204 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
205 * Closed two memory leaks; hopefully the last remaining ones
206 * (in the main execution paths, anyway).
208 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
209 * Addressed bug #719435
210 * - Extraneous filterfile directives now logged as errors
211 * - This and unrecnonised directives now really obvious on status page
213 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
214 * Cosmetic: Renamed cryptic variable
216 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
217 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
219 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
220 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
222 * Revision 1.48 2002/05/14 21:30:38 oes
223 * savearg now uses own linking code instead of (now special-cased) add_help_link
225 * Revision 1.47 2002/05/12 21:36:29 jongfoster
226 * Correcting function comments
228 * Revision 1.46 2002/04/26 12:55:14 oes
229 * - New option "user-manual", defaults to our site
230 * via project.h #define
231 * - savearg now embeds option names in help links
233 * Revision 1.45 2002/04/24 02:11:54 oes
234 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
236 * Revision 1.44 2002/04/08 20:37:13 swa
239 * Revision 1.43 2002/04/08 20:36:50 swa
242 * Revision 1.42 2002/04/05 15:50:15 oes
243 * fix for invalid HTML proxy_args
245 * Revision 1.41 2002/03/31 17:19:00 jongfoster
246 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
248 * Revision 1.40 2002/03/26 22:29:55 swa
249 * we have a new homepage!
251 * Revision 1.39 2002/03/24 13:25:43 swa
252 * name change related issues
254 * Revision 1.38 2002/03/24 13:05:48 jongfoster
255 * Renaming re_filterfile to filterfile
257 * Revision 1.37 2002/03/16 23:54:06 jongfoster
258 * Adding graceful termination feature, to help look for memory leaks.
259 * If you enable this (which, by design, has to be done by hand
260 * editing config.h) and then go to http://i.j.b/die, then the program
261 * will exit cleanly after the *next* request. It should free all the
262 * memory that was used.
264 * Revision 1.36 2002/03/13 00:27:05 jongfoster
267 * Revision 1.35 2002/03/07 03:52:44 oes
268 * Set logging to tty for --no-daemon mode
270 * Revision 1.34 2002/03/06 23:14:35 jongfoster
271 * Trivial cosmetic changes to make function comments easier to find.
273 * Revision 1.33 2002/03/05 04:52:42 oes
274 * Deleted non-errlog debugging code
276 * Revision 1.32 2002/03/04 18:24:53 oes
277 * Re-enabled output of unknown config directive hash
279 * Revision 1.31 2002/03/03 15:07:20 oes
280 * Re-enabled automatic config reloading
282 * Revision 1.30 2002/01/22 23:31:43 jongfoster
283 * Replacing strsav() with string_append()
285 * Revision 1.29 2002/01/17 21:02:30 jongfoster
286 * Moving all our URL and URL pattern parsing code to urlmatch.c.
288 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
290 * Revision 1.28 2001/12/30 14:07:32 steudten
291 * - Add signal handling (unix)
292 * - Add SIGHUP handler (unix)
293 * - Add creation of pidfile (unix)
294 * - Add action 'top' in rc file (RH)
295 * - Add entry 'SIGNALS' to manpage
296 * - Add exit message to logfile (unix)
298 * Revision 1.27 2001/11/07 00:02:13 steudten
299 * Add line number in error output for lineparsing for
300 * actionsfile and configfile.
301 * Special handling for CLF added.
303 * Revision 1.26 2001/11/05 21:41:43 steudten
304 * Add changes to be a real daemon just for unix os.
305 * (change cwd to /, detach from controlling tty, set
306 * process group and session leader to the own process.
308 * Add some fatal-error log message for failed malloc().
309 * Add '-d' if compiled with 'configure --with-debug' to
310 * enable debug output.
312 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
313 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
314 * threads to call select() simultaneously. So, it's time to do a real, live,
315 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
316 * (native). Both versions will work, but using __OS2__ offers multi-threading.
318 * Revision 1.24 2001/10/23 21:40:30 jongfoster
319 * Added support for enable-edit-actions and enable-remote-toggle config
322 * Revision 1.23 2001/10/07 15:36:00 oes
323 * Introduced new config option "buffer-limit"
325 * Revision 1.22 2001/09/22 16:36:59 jongfoster
326 * Removing unused parameter fs from read_config_line()
328 * Revision 1.21 2001/09/16 17:10:43 jongfoster
329 * Moving function savearg() here, since it was the only thing left in
332 * Revision 1.20 2001/07/30 22:08:36 jongfoster
333 * Tidying up #defines:
334 * - All feature #defines are now of the form FEATURE_xxx
335 * - Permanently turned off WIN_GUI_EDIT
336 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
338 * Revision 1.19 2001/07/15 17:45:16 jongfoster
339 * Removing some unused #includes
341 * Revision 1.18 2001/07/13 14:01:14 oes
342 * - Removed all #ifdef PCRS
343 * - Removed vim-settings
345 * Revision 1.17 2001/06/29 13:31:03 oes
346 * - Improved comments
347 * - Fixed (actionsfile) and sorted hashes
348 * - Introduced admin_address and proxy-info-url
349 * as config parameters
350 * - Renamed config->proxy_args_invocation (which didn't have
351 * the invocation but the options!) to config->proxy_args
352 * - Various adaptions
353 * - Removed logentry from cancelled commit
355 * Revision 1.16 2001/06/09 10:55:28 jongfoster
356 * Changing BUFSIZ ==> BUFFER_SIZE
358 * Revision 1.15 2001/06/07 23:13:40 jongfoster
359 * Merging ACL and forward files into config file.
360 * Cosmetic: Sorting config file options alphabetically.
361 * Cosmetic: Adding brief syntax comments to config file options.
363 * Revision 1.14 2001/06/07 14:46:25 joergs
364 * Missing make_path() added for re_filterfile.
366 * Revision 1.13 2001/06/05 22:33:54 jongfoster
368 * Fixed minor memory leak.
369 * Also now uses make_path to prepend the pathnames.
371 * Revision 1.12 2001/06/05 20:04:09 jongfoster
372 * Now uses _snprintf() in place of snprintf() under Win32.
374 * Revision 1.11 2001/06/04 18:31:58 swa
375 * files are now prefixed with either `confdir' or `logdir'.
376 * `make redhat-dist' replaces both entries confdir and logdir
379 * Revision 1.10 2001/06/03 19:11:54 oes
380 * introduced confdir option
382 * Revision 1.9 2001/06/01 20:06:24 jongfoster
383 * Removed support for "tinygif" option - moved to actions file.
385 * Revision 1.8 2001/05/31 21:27:13 jongfoster
386 * Removed many options from the config file and into the
387 * "actions" file: add_forwarded, suppress_vanilla_wafer,
388 * wafer, add_header, user_agent, referer, from
389 * Also globally replaced "permission" with "action".
391 * Revision 1.7 2001/05/29 09:50:24 jongfoster
392 * Unified blocklist/imagelist/permissionslist.
393 * File format is still under discussion, but the internal changes
396 * Also modified interceptor behaviour:
397 * - We now intercept all URLs beginning with one of the following
398 * prefixes (and *only* these prefixes):
400 * * http://ijbswa.sf.net/config/
401 * * http://ijbswa.sourceforge.net/config/
402 * - New interceptors "home page" - go to http://i.j.b/ to see it.
403 * - Internal changes so that intercepted and fast redirect pages
404 * are not replaced with an image.
405 * - Interceptors now have the option to send a binary page direct
406 * to the client. (i.e. ijb-send-banner uses this)
407 * - Implemented show-url-info interceptor. (Which is why I needed
408 * the above interceptors changes - a typical URL is
409 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
410 * The previous mechanism would not have intercepted that, and
411 * if it had been intercepted then it then it would have replaced
414 * Revision 1.6 2001/05/26 00:28:36 jongfoster
415 * Automatic reloading of config file.
416 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
417 * Most of the global variables have been moved to a new
418 * struct configuration_spec, accessed through csp->config->globalname
419 * Most of the globals remaining are used by the Win32 GUI.
421 * Revision 1.5 2001/05/25 22:34:30 jongfoster
424 * Revision 1.4 2001/05/22 18:46:04 oes
426 * - Enabled filtering banners by size rather than URL
427 * by adding patterns that replace all standard banner
428 * sizes with the "Junkbuster" gif to the re_filterfile
430 * - Enabled filtering WebBugs by providing a pattern
431 * which kills all 1x1 images
433 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
434 * which is selected by the (nonstandard and therefore
435 * capital) letter 'U' in the option string.
436 * It causes the quantifiers to be ungreedy by default.
437 * Appending a ? turns back to greedy (!).
439 * - Added a new interceptor ijb-send-banner, which
440 * sends back the "Junkbuster" gif. Without imagelist or
441 * MSIE detection support, or if tinygif = 1, or the
442 * URL isn't recognized as an imageurl, a lame HTML
443 * explanation is sent instead.
445 * - Added new feature, which permits blocking remote
446 * script redirects and firing back a local redirect
448 * The feature is conditionally compiled, i.e. it
449 * can be disabled with --disable-fast-redirects,
450 * plus it must be activated by a "fast-redirects"
451 * line in the config file, has its own log level
452 * and of course wants to be displayed by show-proxy-args
453 * Note: Boy, all the #ifdefs in 1001 locations and
454 * all the fumbling with configure.in and acconfig.h
455 * were *way* more work than the feature itself :-(
457 * - Because a generic redirect template was needed for
458 * this, tinygif = 3 now uses the same.
460 * - Moved GIFs, and other static HTTP response templates
465 * - Removed some >400 CRs again (Jon, you really worked
468 * Revision 1.3 2001/05/20 01:21:20 jongfoster
469 * Version 2.9.4 checkin.
470 * - Merged popupfile and cookiefile, and added control over PCRS
471 * filtering, in new "permissionsfile".
472 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
473 * file error you now get a message box (in the Win32 GUI) rather
474 * than the program exiting with no explanation.
475 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
477 * - Removed tabs from "config"
478 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
479 * - Bumped up version number.
481 * Revision 1.2 2001/05/17 23:01:01 oes
482 * - Cleaned CRLF's from the sources and related files
484 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
485 * Initial import of version 2.9.3 source tree
488 *********************************************************************/
494 #include <sys/types.h>
508 # include <windows.h>
511 # ifndef _WIN_CONSOLE
513 # endif /* ndef _WIN_CONSOLE */
515 #else /* ifndef _WIN32 */
519 # include <sys/wait.h>
521 # include <sys/time.h>
522 # include <sys/stat.h>
532 #include "miscutil.h"
536 #include "urlmatch.h"
540 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
543 * Fix a problem with Solaris. There should be no effect on other
545 * Solaris's isspace() is a macro which uses it's argument directly
546 * as an array index. Therefore we need to make sure that high-bit
547 * characters generate +ve values, and ideally we also want to make
548 * the argument match the declared parameter type of "int".
550 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
551 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
553 #ifdef FEATURE_TOGGLE
554 /* Privoxy is enabled by default. */
555 int global_toggle_state = 1;
556 #endif /* def FEATURE_TOGGLE */
558 /* The filename of the configfile */
559 const char *configfile = NULL;
562 * CGI functions will later need access to the invocation args,
563 * so we will make argc and argv global.
566 const char **Argv = NULL;
568 static struct file_list *current_configfile = NULL;
572 * This takes the "cryptic" hash of each keyword and aliases them to
573 * something a little more readable. This also makes changing the
574 * hash values easier if they should change or the hash algorthm changes.
575 * Use the included "hash" program to find out what the hash will be
576 * for any string supplied on the command line. (Or just put it in the
577 * config file and read the number from the error message in the log).
579 * Please keep this list sorted alphabetically (but with the Windows
580 * console and GUI specific options last).
583 #define hash_actions_file 1196306641ul /* "actionsfile" */
584 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
585 #define hash_admin_address 4112573064ul /* "admin-address" */
586 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
587 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
588 #define hash_confdir 1978389ul /* "confdir" */
589 #define hash_debug 78263ul /* "debug" */
590 #define hash_deny_access 1227333715ul /* "deny-access" */
591 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
592 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
593 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
594 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
595 #define hash_filterfile 250887266ul /* "filterfile" */
596 #define hash_forward 2029845ul /* "forward" */
597 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
598 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
599 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
600 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
601 #define hash_hostname 10308071ul /* "hostname" */
602 #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */
603 #define hash_listen_address 1255650842ul /* "listen-address" */
604 #define hash_logdir 422889ul /* "logdir" */
605 #define hash_logfile 2114766ul /* "logfile" */
606 #define hash_permit_access 3587953268ul /* "permit-access" */
607 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
608 #define hash_single_threaded 4250084780ul /* "single-threaded" */
609 #define hash_socket_timeout 1809001761ul /* "socket-timeout" */
610 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
611 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
612 #define hash_templdir 11067889ul /* "templdir" */
613 #define hash_toggle 447966ul /* "toggle" */
614 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
615 #define hash_trustfile 56494766ul /* "trustfile" */
616 #define hash_usermanual 1416668518ul /* "user-manual" */
617 #define hash_activity_animation 1817904738ul /* "activity-animation" */
618 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
619 #define hash_hide_console 2048809870ul /* "hide-console" */
620 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
621 #define hash_log_font_name 2866730124ul /* "log-font-name" */
622 #define hash_log_font_size 2866731014ul /* "log-font-size" */
623 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
624 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
625 #define hash_log_messages 2291744899ul /* "log-messages" */
626 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
629 static void savearg(char *command, char *argument, struct configuration_spec * config);
631 /*********************************************************************
633 * Function : unload_configfile
635 * Description : Free the config structure and all components.
638 * 1 : data: struct configuration_spec to unload
642 *********************************************************************/
643 static void unload_configfile (void * data)
645 struct configuration_spec * config = (struct configuration_spec *)data;
646 struct forward_spec *cur_fwd = config->forward;
650 struct access_control_list *cur_acl = config->acl;
652 while (cur_acl != NULL)
654 struct access_control_list * next_acl = cur_acl->next;
659 #endif /* def FEATURE_ACL */
661 while (cur_fwd != NULL)
663 struct forward_spec * next_fwd = cur_fwd->next;
664 free_url_spec(cur_fwd->url);
666 freez(cur_fwd->gateway_host);
667 freez(cur_fwd->forward_host);
671 config->forward = NULL;
673 freez(config->confdir);
674 freez(config->logdir);
675 freez(config->templdir);
676 freez(config->hostname);
678 freez(config->haddr);
679 freez(config->logfile);
681 for (i = 0; i < MAX_AF_FILES; i++)
683 freez(config->actions_file_short[i]);
684 freez(config->actions_file[i]);
685 freez(config->re_filterfile_short[i]);
686 freez(config->re_filterfile[i]);
689 freez(config->admin_address);
690 freez(config->proxy_info_url);
691 freez(config->proxy_args);
692 freez(config->usermanual);
695 freez(config->trustfile);
696 list_remove_all(config->trust_info);
697 #endif /* def FEATURE_TRUST */
699 for (i = 0; i < MAX_AF_FILES; i++)
701 freez(config->re_filterfile[i]);
708 #ifdef FEATURE_GRACEFUL_TERMINATION
709 /*********************************************************************
711 * Function : unload_current_config_file
713 * Description : Unloads current config file - reset to state at
714 * beginning of program.
720 *********************************************************************/
721 void unload_current_config_file(void)
723 if (current_configfile)
725 current_configfile->unloader = unload_configfile;
726 current_configfile = NULL;
732 /*********************************************************************
734 * Function : load_config
736 * Description : Load the config file and all parameters.
738 * XXX: more than thousand lines long
739 * and thus in serious need of refactoring.
743 * Returns : The configuration_spec, or NULL on error.
745 *********************************************************************/
746 struct configuration_spec * load_config(void)
748 char buf[BUFFER_SIZE];
750 FILE *configfp = NULL;
751 struct configuration_spec * config = NULL;
752 struct client_state * fake_csp;
753 struct file_list *fs;
754 unsigned long linenum = 0;
756 char *logfile = NULL;
757 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
758 int keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
761 if ( !check_file_changed(current_configfile, configfile, &fs))
763 /* No need to load */
764 return ((struct configuration_spec *)current_configfile->f);
768 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
772 if (NULL != current_configfile)
774 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
777 #ifdef FEATURE_TOGGLE
778 global_toggle_state = 1;
779 #endif /* def FEATURE_TOGGLE */
781 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
787 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
788 /* Never get here - LOG_LEVEL_FATAL causes program exit */
792 * This is backwards from how it's usually done.
793 * Following the usual pattern, "fs" would be stored in a member
794 * variable in "csp", and then we'd access "config" from "fs->f",
795 * using a cast. However, "config" is used so often that a
796 * cast each time would be very ugly, and the extra indirection
797 * would waste CPU cycles. Therefore we store "config" in
798 * "csp->config", and "fs" in "csp->config->config_file_list".
800 config->config_file_list = fs;
805 config->multi_threaded = 1;
806 config->hport = HADDR_PORT;
807 config->buffer_limit = 4096 * 1024;
808 config->usermanual = strdup(USER_MANUAL_URL);
809 config->proxy_args = strdup("");
810 config->forwarded_connect_retries = 0;
811 config->socket_timeout = 300; /* XXX: Should be a macro. */
812 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
813 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
814 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
816 if ((configfp = fopen(configfile, "r")) == NULL)
818 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
820 /* Never get here - LOG_LEVEL_FATAL causes program exit */
823 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
825 char cmd[BUFFER_SIZE];
826 char arg[BUFFER_SIZE];
827 char tmp[BUFFER_SIZE];
829 struct access_control_list *cur_acl;
830 #endif /* def FEATURE_ACL */
831 struct forward_spec *cur_fwd;
834 unsigned long directive_hash;
836 strlcpy(tmp, buf, sizeof(tmp));
838 /* Copy command (i.e. up to space or tab) into cmd */
841 while (*p && (*p != ' ') && (*p != '\t'))
847 /* Skip over the whitespace in buf */
848 while (*p && ((*p == ' ') || (*p == '\t')))
853 /* Copy the argument into arg */
854 strlcpy(arg, p, sizeof(arg));
856 /* Should never happen, but check this anyway */
862 /* Make sure the command field is lower case */
867 *p = (char)ijb_tolower(*p);
871 /* Save the argument for show-proxy-args */
872 savearg(cmd, arg, config);
874 directive_hash = hash_string(cmd);
875 switch (directive_hash)
877 /* *************************************************************************
878 * actionsfile actions-file-name
879 * In confdir by default
880 * *************************************************************************/
881 case hash_actions_file :
883 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
888 if (i >= MAX_AF_FILES)
890 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
891 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
894 config->actions_file_short[i] = strdup(arg);
895 config->actions_file[i] = make_path(config->confdir, arg);
898 /* *************************************************************************
899 * accept-intercepted-requests
900 * *************************************************************************/
901 case hash_accept_intercepted_requests:
902 if ((*arg != '\0') && (0 != atoi(arg)))
904 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
908 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
912 /* *************************************************************************
913 * admin-address email-address
914 * *************************************************************************/
915 case hash_admin_address :
916 freez(config->admin_address);
917 config->admin_address = strdup(arg);
920 /* *************************************************************************
921 * allow-cgi-request-crunching
922 * *************************************************************************/
923 case hash_allow_cgi_request_crunching:
924 if ((*arg != '\0') && (0 != atoi(arg)))
926 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
930 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
934 /* *************************************************************************
936 * *************************************************************************/
937 case hash_buffer_limit :
938 config->buffer_limit = (size_t)(1024 * atoi(arg));
941 /* *************************************************************************
942 * confdir directory-name
943 * *************************************************************************/
945 freez(config->confdir);
946 config->confdir = make_path( NULL, arg);
949 /* *************************************************************************
951 * Specifies debug level, multiple values are ORed together.
952 * *************************************************************************/
954 config->debug |= atoi(arg);
957 /* *************************************************************************
958 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
959 * *************************************************************************/
961 case hash_deny_access:
962 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
964 if ((vec_count != 1) && (vec_count != 2))
966 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
967 "deny-access directive in configuration file.");
968 string_append(&config->proxy_args,
969 "<br>\nWARNING: Wrong number of parameters for "
970 "deny-access directive in configuration file.<br><br>\n");
974 /* allocate a new node */
975 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
979 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
980 /* Never get here - LOG_LEVEL_FATAL causes program exit */
983 cur_acl->action = ACL_DENY;
985 if (acl_addr(vec[0], cur_acl->src) < 0)
987 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
988 "for deny-access directive in configuration file: \"%s\"", vec[0]);
989 string_append(&config->proxy_args,
990 "<br>\nWARNING: Invalid source address, port or netmask "
991 "for deny-access directive in configuration file: \"");
992 string_append(&config->proxy_args,
994 string_append(&config->proxy_args,
1001 if (acl_addr(vec[1], cur_acl->dst) < 0)
1003 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1004 "for deny-access directive in configuration file: \"%s\"", vec[1]);
1005 string_append(&config->proxy_args,
1006 "<br>\nWARNING: Invalid destination address, port or netmask "
1007 "for deny-access directive in configuration file: \"");
1008 string_append(&config->proxy_args,
1010 string_append(&config->proxy_args,
1018 * Add it to the list. Note we reverse the list to get the
1019 * behaviour the user expects. With both the ACL and
1020 * actions file, the last match wins. However, the internal
1021 * implementations are different: The actions file is stored
1022 * in the same order as the file, and scanned completely.
1023 * With the ACL, we reverse the order as we load it, then
1024 * when we scan it we stop as soon as we get a match.
1026 cur_acl->next = config->acl;
1027 config->acl = cur_acl;
1030 #endif /* def FEATURE_ACL */
1032 /* *************************************************************************
1033 * enable-edit-actions 0|1
1034 * *************************************************************************/
1035 #ifdef FEATURE_CGI_EDIT_ACTIONS
1036 case hash_enable_edit_actions:
1037 if ((*arg != '\0') && (0 != atoi(arg)))
1039 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1043 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1046 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1048 /* *************************************************************************
1049 * enable-remote-toggle 0|1
1050 * *************************************************************************/
1051 #ifdef FEATURE_TOGGLE
1052 case hash_enable_remote_toggle:
1053 if ((*arg != '\0') && (0 != atoi(arg)))
1055 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1059 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1062 #endif /* def FEATURE_TOGGLE */
1064 /* *************************************************************************
1065 * enable-remote-http-toggle 0|1
1066 * *************************************************************************/
1067 case hash_enable_remote_http_toggle:
1068 if ((*arg != '\0') && (0 != atoi(arg)))
1070 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1074 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1078 /* *************************************************************************
1079 * enforce-blocks 0|1
1080 * *************************************************************************/
1081 case hash_enforce_blocks:
1082 #ifdef FEATURE_FORCE_LOAD
1083 if ((*arg != '\0') && (0 != atoi(arg)))
1085 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1089 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1092 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1093 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1094 #endif /* def FEATURE_FORCE_LOAD */
1097 /* *************************************************************************
1098 * filterfile file-name
1099 * In confdir by default.
1100 * *************************************************************************/
1101 case hash_filterfile :
1103 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1108 if (i >= MAX_AF_FILES)
1110 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1111 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1114 config->re_filterfile_short[i] = strdup(arg);
1115 config->re_filterfile[i] = make_path(config->confdir, arg);
1119 /* *************************************************************************
1120 * forward url-pattern (.|http-proxy-host[:port])
1121 * *************************************************************************/
1123 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1127 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1128 "directive in configuration file.");
1129 string_append(&config->proxy_args,
1130 "<br>\nWARNING: Wrong number of parameters for "
1131 "forward directive in configuration file.");
1135 /* allocate a new node */
1136 cur_fwd = zalloc(sizeof(*cur_fwd));
1137 if (cur_fwd == NULL)
1139 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1140 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1144 cur_fwd->type = SOCKS_NONE;
1146 /* Save the URL pattern */
1147 if (create_url_spec(cur_fwd->url, vec[0]))
1149 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1150 "directive in configuration file.");
1151 string_append(&config->proxy_args,
1152 "<br>\nWARNING: Bad URL specifier for "
1153 "forward directive in configuration file.");
1157 /* Parse the parent HTTP proxy host:port */
1160 if (strcmp(p, ".") != 0)
1162 cur_fwd->forward_host = strdup(p);
1164 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1167 cur_fwd->forward_port = atoi(p);
1170 if (cur_fwd->forward_port <= 0)
1172 cur_fwd->forward_port = 8000;
1177 cur_fwd->next = config->forward;
1178 config->forward = cur_fwd;
1182 /* *************************************************************************
1183 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1184 * *************************************************************************/
1185 case hash_forward_socks4:
1186 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1190 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1191 "forward-socks4 directive in configuration file.");
1192 string_append(&config->proxy_args,
1193 "<br>\nWARNING: Wrong number of parameters for "
1194 "forward-socks4 directive in configuration file.");
1198 /* allocate a new node */
1199 cur_fwd = zalloc(sizeof(*cur_fwd));
1200 if (cur_fwd == NULL)
1202 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1203 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1207 cur_fwd->type = SOCKS_4;
1209 /* Save the URL pattern */
1210 if (create_url_spec(cur_fwd->url, vec[0]))
1212 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1213 "directive in configuration file.");
1214 string_append(&config->proxy_args,
1215 "<br>\nWARNING: Bad URL specifier for "
1216 "forward-socks4 directive in configuration file.");
1220 /* Parse the SOCKS proxy host[:port] */
1223 if (strcmp(p, ".") != 0)
1225 cur_fwd->gateway_host = strdup(p);
1227 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1230 cur_fwd->gateway_port = atoi(p);
1232 if (cur_fwd->gateway_port <= 0)
1234 cur_fwd->gateway_port = 1080;
1238 /* Parse the parent HTTP proxy host[:port] */
1241 if (strcmp(p, ".") != 0)
1243 cur_fwd->forward_host = strdup(p);
1245 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1248 cur_fwd->forward_port = atoi(p);
1251 if (cur_fwd->forward_port <= 0)
1253 cur_fwd->forward_port = 8000;
1258 cur_fwd->next = config->forward;
1259 config->forward = cur_fwd;
1263 /* *************************************************************************
1264 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1265 * *************************************************************************/
1266 case hash_forward_socks4a:
1267 case hash_forward_socks5:
1268 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1272 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1273 "forward-socks4a directive in configuration file.");
1274 string_append(&config->proxy_args,
1275 "<br>\nWARNING: Wrong number of parameters for "
1276 "forward-socks4a directive in configuration file.");
1280 /* allocate a new node */
1281 cur_fwd = zalloc(sizeof(*cur_fwd));
1282 if (cur_fwd == NULL)
1284 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1285 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1289 if (directive_hash == hash_forward_socks4a)
1291 cur_fwd->type = SOCKS_4A;
1295 cur_fwd->type = SOCKS_5;
1298 /* Save the URL pattern */
1299 if (create_url_spec(cur_fwd->url, vec[0]))
1301 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1302 "directive in configuration file.");
1303 string_append(&config->proxy_args,
1304 "<br>\nWARNING: Bad URL specifier for "
1305 "forward-socks4a directive in configuration file.");
1309 /* Parse the SOCKS proxy host[:port] */
1312 cur_fwd->gateway_host = strdup(p);
1314 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1317 cur_fwd->gateway_port = atoi(p);
1319 if (cur_fwd->gateway_port <= 0)
1321 cur_fwd->gateway_port = 1080;
1324 /* Parse the parent HTTP proxy host[:port] */
1327 if (strcmp(p, ".") != 0)
1329 cur_fwd->forward_host = strdup(p);
1331 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1334 cur_fwd->forward_port = atoi(p);
1337 if (cur_fwd->forward_port <= 0)
1339 cur_fwd->forward_port = 8000;
1344 cur_fwd->next = config->forward;
1345 config->forward = cur_fwd;
1349 /* *************************************************************************
1350 * forwarded-connect-retries n
1351 * *************************************************************************/
1352 case hash_forwarded_connect_retries :
1353 config->forwarded_connect_retries = atoi(arg);
1356 /* *************************************************************************
1357 * hostname hostname-to-show-on-cgi-pages
1358 * *************************************************************************/
1359 case hash_hostname :
1360 freez(config->hostname);
1361 config->hostname = strdup(arg);
1362 if (NULL == config->hostname)
1364 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1368 /* *************************************************************************
1369 * keep-alive-timeout timeout
1370 * *************************************************************************/
1371 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1372 case hash_keep_alive_timeout :
1375 int timeout = atoi(arg);
1378 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1379 keep_alive_timeout = timeout;
1383 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1389 /* *************************************************************************
1390 * listen-address [ip][:port]
1391 * *************************************************************************/
1392 case hash_listen_address :
1393 freez(config->haddr);
1394 config->haddr = strdup(arg);
1397 /* *************************************************************************
1398 * logdir directory-name
1399 * *************************************************************************/
1401 freez(config->logdir);
1402 config->logdir = make_path(NULL, arg);
1405 /* *************************************************************************
1406 * logfile log-file-name
1407 * In logdir by default
1408 * *************************************************************************/
1412 logfile = make_path(config->logdir, arg);
1413 if (NULL == logfile)
1415 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1420 /* *************************************************************************
1421 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1422 * *************************************************************************/
1424 case hash_permit_access:
1425 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1427 if ((vec_count != 1) && (vec_count != 2))
1429 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1430 "permit-access directive in configuration file.");
1431 string_append(&config->proxy_args,
1432 "<br>\nWARNING: Wrong number of parameters for "
1433 "permit-access directive in configuration file.<br><br>\n");
1438 /* allocate a new node */
1439 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1441 if (cur_acl == NULL)
1443 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1444 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1447 cur_acl->action = ACL_PERMIT;
1449 if (acl_addr(vec[0], cur_acl->src) < 0)
1451 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1452 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1453 string_append(&config->proxy_args,
1454 "<br>\nWARNING: Invalid source address, port or netmask for "
1455 "permit-access directive in configuration file: \"");
1456 string_append(&config->proxy_args,
1458 string_append(&config->proxy_args,
1465 if (acl_addr(vec[1], cur_acl->dst) < 0)
1467 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1468 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1469 string_append(&config->proxy_args,
1470 "<br>\nWARNING: Invalid destination address, port or netmask for "
1471 "permit-access directive in configuration file: \"");
1472 string_append(&config->proxy_args,
1474 string_append(&config->proxy_args,
1482 * Add it to the list. Note we reverse the list to get the
1483 * behaviour the user expects. With both the ACL and
1484 * actions file, the last match wins. However, the internal
1485 * implementations are different: The actions file is stored
1486 * in the same order as the file, and scanned completely.
1487 * With the ACL, we reverse the order as we load it, then
1488 * when we scan it we stop as soon as we get a match.
1490 cur_acl->next = config->acl;
1491 config->acl = cur_acl;
1494 #endif /* def FEATURE_ACL */
1496 /* *************************************************************************
1497 * proxy-info-url url
1498 * *************************************************************************/
1499 case hash_proxy_info_url :
1500 freez(config->proxy_info_url);
1501 config->proxy_info_url = strdup(arg);
1504 /* *************************************************************************
1506 * *************************************************************************/
1507 case hash_single_threaded :
1508 config->multi_threaded = 0;
1511 /* *************************************************************************
1512 * socket-timeout numer_of_seconds
1513 * *************************************************************************/
1514 case hash_socket_timeout :
1517 int socket_timeout = atoi(arg);
1518 if (0 < socket_timeout)
1520 config->socket_timeout = socket_timeout;
1524 log_error(LOG_LEVEL_FATAL,
1525 "Invalid socket-timeout: '%s'", arg);
1530 /* *************************************************************************
1531 * split-large-cgi-forms
1532 * *************************************************************************/
1533 case hash_split_large_cgi_forms :
1534 if ((*arg != '\0') && (0 != atoi(arg)))
1536 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1540 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1544 /* *************************************************************************
1545 * templdir directory-name
1546 * *************************************************************************/
1547 case hash_templdir :
1548 freez(config->templdir);
1549 config->templdir = make_path(NULL, arg);
1552 /* *************************************************************************
1554 * *************************************************************************/
1555 #ifdef FEATURE_TOGGLE
1557 global_toggle_state = atoi(arg);
1559 #endif /* def FEATURE_TOGGLE */
1561 /* *************************************************************************
1562 * trust-info-url url
1563 * *************************************************************************/
1564 #ifdef FEATURE_TRUST
1565 case hash_trust_info_url :
1566 enlist(config->trust_info, arg);
1568 #endif /* def FEATURE_TRUST */
1570 /* *************************************************************************
1571 * trustfile filename
1572 * (In confdir by default.)
1573 * *************************************************************************/
1574 #ifdef FEATURE_TRUST
1575 case hash_trustfile :
1576 freez(config->trustfile);
1577 config->trustfile = make_path(config->confdir, arg);
1579 #endif /* def FEATURE_TRUST */
1581 /* *************************************************************************
1583 * *************************************************************************/
1584 case hash_usermanual :
1585 freez(config->usermanual);
1586 config->usermanual = strdup(arg);
1589 /* *************************************************************************
1590 * Win32 Console options:
1591 * *************************************************************************/
1593 /* *************************************************************************
1595 * *************************************************************************/
1597 case hash_hide_console :
1600 #endif /*def _WIN_CONSOLE*/
1603 /* *************************************************************************
1604 * Win32 GUI options:
1605 * *************************************************************************/
1607 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1608 /* *************************************************************************
1609 * activity-animation (0|1)
1610 * *************************************************************************/
1611 case hash_activity_animation :
1612 g_bShowActivityAnimation = atoi(arg);
1615 /* *************************************************************************
1616 * close-button-minimizes (0|1)
1617 * *************************************************************************/
1618 case hash_close_button_minimizes :
1619 g_bCloseHidesWindow = atoi(arg);
1622 /* *************************************************************************
1623 * log-buffer-size (0|1)
1624 * *************************************************************************/
1625 case hash_log_buffer_size :
1626 g_bLimitBufferSize = atoi(arg);
1629 /* *************************************************************************
1630 * log-font-name fontnane
1631 * *************************************************************************/
1632 case hash_log_font_name :
1633 strcpy( g_szFontFaceName, arg );
1636 /* *************************************************************************
1638 * *************************************************************************/
1639 case hash_log_font_size :
1640 g_nFontSize = atoi(arg);
1643 /* *************************************************************************
1644 * log-highlight-messages (0|1)
1645 * *************************************************************************/
1646 case hash_log_highlight_messages :
1647 g_bHighlightMessages = atoi(arg);
1650 /* *************************************************************************
1652 * *************************************************************************/
1653 case hash_log_max_lines :
1654 g_nMaxBufferLines = atoi(arg);
1657 /* *************************************************************************
1658 * log-messages (0|1)
1659 * *************************************************************************/
1660 case hash_log_messages :
1661 g_bLogMessages = atoi(arg);
1664 /* *************************************************************************
1665 * show-on-task-bar (0|1)
1666 * *************************************************************************/
1667 case hash_show_on_task_bar :
1668 g_bShowOnTaskBar = atoi(arg);
1671 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1674 /* *************************************************************************
1675 * Warnings about unsupported features
1676 * *************************************************************************/
1678 case hash_deny_access:
1679 #endif /* ndef FEATURE_ACL */
1680 #ifndef FEATURE_CGI_EDIT_ACTIONS
1681 case hash_enable_edit_actions:
1682 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1683 #ifndef FEATURE_TOGGLE
1684 case hash_enable_remote_toggle:
1685 #endif /* ndef FEATURE_TOGGLE */
1687 case hash_permit_access:
1688 #endif /* ndef FEATURE_ACL */
1689 #ifndef FEATURE_TOGGLE
1691 #endif /* ndef FEATURE_TOGGLE */
1692 #ifndef FEATURE_TRUST
1693 case hash_trustfile :
1694 case hash_trust_info_url :
1695 #endif /* ndef FEATURE_TRUST */
1697 #ifndef _WIN_CONSOLE
1698 case hash_hide_console :
1699 #endif /* ndef _WIN_CONSOLE */
1701 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1702 case hash_activity_animation :
1703 case hash_close_button_minimizes :
1704 case hash_log_buffer_size :
1705 case hash_log_font_name :
1706 case hash_log_font_size :
1707 case hash_log_highlight_messages :
1708 case hash_log_max_lines :
1709 case hash_log_messages :
1710 case hash_show_on_task_bar :
1711 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1712 /* These warnings are annoying - so hide them. -- Jon */
1713 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1716 /* *************************************************************************/
1718 /* *************************************************************************/
1720 * I decided that I liked this better as a warning than an
1721 * error. To change back to an error, just change log level
1722 * to LOG_LEVEL_FATAL.
1724 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1725 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1726 string_append(&config->proxy_args,
1727 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1730 /* *************************************************************************/
1731 } /* end switch( hash_string(cmd) ) */
1732 } /* end while ( read_config_line(...) ) */
1736 set_debug_level(config->debug);
1738 freez(config->logfile);
1742 if (NULL != logfile)
1744 config->logfile = logfile;
1745 init_error_log(Argv[0], config->logfile);
1753 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1754 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1756 if (config->multi_threaded)
1758 set_keep_alive_timeout(keep_alive_timeout);
1763 * While we could use keep-alive without multiple threads
1764 * if we didn't bother with enforcing the connection timeout,
1765 * that might make Tor users sad, even though they shouldn't
1766 * enable the single-threaded option anyway.
1768 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1769 log_error(LOG_LEVEL_ERROR,
1770 "Config option single-threaded disables connection keep-alive.");
1775 if (NULL == config->proxy_args)
1777 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1780 if (config->actions_file[0])
1782 add_loader(load_action_files, config);
1785 if (config->re_filterfile[0])
1787 add_loader(load_re_filterfiles, config);
1790 #ifdef FEATURE_TRUST
1791 if (config->trustfile)
1793 add_loader(load_trustfile, config);
1795 #endif /* def FEATURE_TRUST */
1797 if ( NULL == config->haddr )
1799 config->haddr = strdup( HADDR_DEFAULT );
1802 if ( NULL != config->haddr )
1804 if (NULL != (p = strchr(config->haddr, ':')))
1809 config->hport = atoi(p);
1813 if (config->hport <= 0)
1816 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1817 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1819 if (*config->haddr == '\0')
1822 * Only the port specified. We stored it in config->hport
1823 * and don't need its text representation anymore.
1825 freez(config->haddr);
1830 * Want to run all the loaders once now.
1832 * Need to set up a fake csp, so they can get to the config.
1834 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1835 fake_csp->config = config;
1837 if (run_loader(fake_csp))
1840 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1841 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1845 /* FIXME: this is a kludge for win32 */
1846 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1848 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1849 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1850 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1852 #ifdef FEATURE_TRUST
1853 g_trustfile = config->trustfile;
1854 #endif /* def FEATURE_TRUST */
1857 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1858 /* FIXME: end kludge */
1861 config->need_bind = 1;
1863 if (current_configfile)
1865 struct configuration_spec * oldcfg = (struct configuration_spec *)
1866 current_configfile->f;
1868 * Check if config->haddr,hport == oldcfg->haddr,hport
1870 * The following could be written more compactly as a single,
1871 * (unreadably long) if statement.
1873 config->need_bind = 0;
1874 if (config->hport != oldcfg->hport)
1876 config->need_bind = 1;
1878 else if (config->haddr == NULL)
1880 if (oldcfg->haddr != NULL)
1882 config->need_bind = 1;
1885 else if (oldcfg->haddr == NULL)
1887 config->need_bind = 1;
1889 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1891 config->need_bind = 1;
1894 current_configfile->unloader = unload_configfile;
1897 fs->next = files->next;
1900 current_configfile = fs;
1906 /*********************************************************************
1908 * Function : savearg
1910 * Description : Called from `load_config'. It saves each non-empty
1911 * and non-comment line from config into
1912 * config->proxy_args. This is used to create the
1913 * show-proxy-args page. On error, frees
1914 * config->proxy_args and sets it to NULL
1917 * 1 : command = config setting that was found
1918 * 2 : argument = the setting's argument (if any)
1919 * 3 : config = Configuration to save into.
1923 *********************************************************************/
1924 static void savearg(char *command, char *argument, struct configuration_spec * config)
1933 * Add config option name embedded in
1934 * link to its section in the user-manual
1936 buf = strdup("\n<a href=\"");
1937 if (!strncmpic(config->usermanual, "file://", 7) ||
1938 !strncmpic(config->usermanual, "http", 4))
1940 string_append(&buf, config->usermanual);
1944 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1946 string_append(&buf, CONFIG_HELP_PREFIX);
1947 string_join (&buf, string_toupper(command));
1948 string_append(&buf, "\">");
1949 string_append(&buf, command);
1950 string_append(&buf, "</a> ");
1954 freez(config->proxy_args);
1958 if ( (NULL != argument) && ('\0' != *argument) )
1960 s = html_encode(argument);
1964 freez(config->proxy_args);
1968 if (strncmpic(argument, "http://", 7) == 0)
1970 string_append(&buf, "<a href=\"");
1971 string_append(&buf, s);
1972 string_append(&buf, "\">");
1973 string_join (&buf, s);
1974 string_append(&buf, "</a>");
1978 string_join (&buf, s);
1982 string_append(&buf, "<br>");
1983 string_join(&config->proxy_args, buf);