1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.87 2009/02/15 07:56:13 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.87 2009/02/15 07:56:13 fabiankeil
39 * Increase default socket timeout to 300 seconds.
41 * Revision 1.86 2009/02/08 19:18:57 fabiankeil
42 * Now that we have the match-all.action file, the other action
43 * files changed their position in config->actions_file[] back
44 * to the way it was before standard.action got removed and the
45 * changes from revision 1.84 have to be reverted.
47 * Revision 1.85 2009/01/22 12:06:26 fabiankeil
48 * Don't keep connections alive when running single-threaded.
50 * Revision 1.84 2009/01/14 16:14:36 fabiankeil
51 * Due to the standard.action file removal, the other action
52 * files changed their position in config->actions_file[].
53 * Update mingw32 kludge accordingly.
55 * Revision 1.83 2008/12/20 14:53:55 fabiankeil
56 * Add config option socket-timeout to control the time
57 * Privoxy waits for data to arrive on a socket. Useful
58 * in case of stale ssh tunnels or when fuzz-testing.
60 * Revision 1.82 2008/11/16 12:43:49 fabiankeil
61 * Turn keep-alive support into a runtime feature
62 * that is disabled by setting keep-alive-timeout
63 * to a negative value.
65 * Revision 1.81 2008/11/13 09:08:42 fabiankeil
66 * Add new config option: keep-alive-timeout.
68 * Revision 1.80 2008/08/31 15:59:03 fabiankeil
69 * There's no reason to let remote toggling support depend
70 * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
72 * Revision 1.79 2008/08/30 12:03:07 fabiankeil
73 * Remove FEATURE_COOKIE_JAR.
75 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
76 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
77 * disabled, log a message that blocks will always be enforced
78 * instead of complaining about an unrecognized directive.
79 * Reported by Pietro Leone.
81 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
82 * Reuse directive_hash and don't hash the same directive twice.
84 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
85 * - Merge three string_append() calls.
86 * - Remove useless assertion.
88 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
89 * Rename load_actions_file() and load_re_filterfile()
90 * as they load multiple files "now".
92 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
93 * Add hostname directive. Closes PR#1918189.
95 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
98 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
99 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
101 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
102 * Reword "unrecognized directive" warning, use better
103 * mark up and add a <br>. Fixes parts of #1856559.
105 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
106 * Plug memory leak if listen-address only specifies the port.
108 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
109 * Relocate daemon-mode-related log messages to make sure
110 * they aren't shown again in case of configuration reloads.
112 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
113 * Plug memory leak introduced with my last commit.
115 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
116 * When in daemon mode, close stderr after the configuration file has been
117 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
119 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
120 * #1763173 from Stefan Huehner: declare unload_configfile() static.
122 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
123 * As Hal noticed, checking dispatch_cgi() as the last cruncher
124 * looks like a bug if CGI requests are blocked unintentionally,
125 * so don't do it unless the user enabled the new config option
126 * "allow-cgi-request-crunching".
128 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
129 * - Use strlcpy() instead of strcpy().
130 * - Stop treating actions files special. Expect a complete file name
131 * (with or without path) like it's done for the rest of the files.
133 * - Remove an unnecessary temporary memory allocation.
134 * - Don't log anything to the console when running as
135 * daemon and no errors occurred.
137 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
138 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
140 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
141 * New config option: enforce-blocks.
143 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
144 * - Mention other reasons why acl directive loading might have failed.
145 * - Don't log the acl source if the acl destination is to blame.
147 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
148 * Add new config option "templdir" to
149 * change the templates directory.
151 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
152 * Added config option accept-intercepted-requests
153 * and disabled it by default.
155 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
156 * Fix gcc43 compiler warnings.
158 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
159 * Add config option "split-large-forms"
160 * to work around the browser bug reported
163 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
164 * Move the <br> in the generated HTML for the config
165 * options from the beginning of the string to its end.
166 * Keeps the white space in balance.
168 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
169 * Fix memory leak in case of config file reloads.
171 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
172 * Modified kludge for win32 to make ming32 menu
173 * "Options/Edit Filters" (sort of) work again.
174 * Same limitations as for the action files apply.
177 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
178 * Incorporate modified version of Roland Rosenfeld's patch to
179 * optionally access the user-manual via Privoxy. Closes patch 679075.
181 * Formatting changed to Privoxy style, added call to
182 * cgi_error_no_template if the requested file doesn't
183 * exist and modified check whether or not Privoxy itself
184 * should serve the manual. Should work cross-platform now.
186 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
187 * Added config option enable-remote-http-toggle
188 * to specify if Privoxy should recognize special
189 * headers (currently only X-Filter) to change its
190 * behaviour. Disabled by default.
192 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
193 * Make number of retries in case of forwarded-connect problems
194 * a config file option (forwarded-connect-retries) and use 0 as
197 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
198 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
199 * with what was really the latest development (the v_3_0_branch branch)
201 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
202 * Don't forget to malloc space for the null terminator...
204 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
205 * Multiple filter file support
207 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
208 * Closed two memory leaks; hopefully the last remaining ones
209 * (in the main execution paths, anyway).
211 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
212 * Addressed bug #719435
213 * - Extraneous filterfile directives now logged as errors
214 * - This and unrecnonised directives now really obvious on status page
216 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
217 * Cosmetic: Renamed cryptic variable
219 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
220 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
222 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
223 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
225 * Revision 1.48 2002/05/14 21:30:38 oes
226 * savearg now uses own linking code instead of (now special-cased) add_help_link
228 * Revision 1.47 2002/05/12 21:36:29 jongfoster
229 * Correcting function comments
231 * Revision 1.46 2002/04/26 12:55:14 oes
232 * - New option "user-manual", defaults to our site
233 * via project.h #define
234 * - savearg now embeds option names in help links
236 * Revision 1.45 2002/04/24 02:11:54 oes
237 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
239 * Revision 1.44 2002/04/08 20:37:13 swa
242 * Revision 1.43 2002/04/08 20:36:50 swa
245 * Revision 1.42 2002/04/05 15:50:15 oes
246 * fix for invalid HTML proxy_args
248 * Revision 1.41 2002/03/31 17:19:00 jongfoster
249 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
251 * Revision 1.40 2002/03/26 22:29:55 swa
252 * we have a new homepage!
254 * Revision 1.39 2002/03/24 13:25:43 swa
255 * name change related issues
257 * Revision 1.38 2002/03/24 13:05:48 jongfoster
258 * Renaming re_filterfile to filterfile
260 * Revision 1.37 2002/03/16 23:54:06 jongfoster
261 * Adding graceful termination feature, to help look for memory leaks.
262 * If you enable this (which, by design, has to be done by hand
263 * editing config.h) and then go to http://i.j.b/die, then the program
264 * will exit cleanly after the *next* request. It should free all the
265 * memory that was used.
267 * Revision 1.36 2002/03/13 00:27:05 jongfoster
270 * Revision 1.35 2002/03/07 03:52:44 oes
271 * Set logging to tty for --no-daemon mode
273 * Revision 1.34 2002/03/06 23:14:35 jongfoster
274 * Trivial cosmetic changes to make function comments easier to find.
276 * Revision 1.33 2002/03/05 04:52:42 oes
277 * Deleted non-errlog debugging code
279 * Revision 1.32 2002/03/04 18:24:53 oes
280 * Re-enabled output of unknown config directive hash
282 * Revision 1.31 2002/03/03 15:07:20 oes
283 * Re-enabled automatic config reloading
285 * Revision 1.30 2002/01/22 23:31:43 jongfoster
286 * Replacing strsav() with string_append()
288 * Revision 1.29 2002/01/17 21:02:30 jongfoster
289 * Moving all our URL and URL pattern parsing code to urlmatch.c.
291 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
293 * Revision 1.28 2001/12/30 14:07:32 steudten
294 * - Add signal handling (unix)
295 * - Add SIGHUP handler (unix)
296 * - Add creation of pidfile (unix)
297 * - Add action 'top' in rc file (RH)
298 * - Add entry 'SIGNALS' to manpage
299 * - Add exit message to logfile (unix)
301 * Revision 1.27 2001/11/07 00:02:13 steudten
302 * Add line number in error output for lineparsing for
303 * actionsfile and configfile.
304 * Special handling for CLF added.
306 * Revision 1.26 2001/11/05 21:41:43 steudten
307 * Add changes to be a real daemon just for unix os.
308 * (change cwd to /, detach from controlling tty, set
309 * process group and session leader to the own process.
311 * Add some fatal-error log message for failed malloc().
312 * Add '-d' if compiled with 'configure --with-debug' to
313 * enable debug output.
315 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
316 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
317 * threads to call select() simultaneously. So, it's time to do a real, live,
318 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
319 * (native). Both versions will work, but using __OS2__ offers multi-threading.
321 * Revision 1.24 2001/10/23 21:40:30 jongfoster
322 * Added support for enable-edit-actions and enable-remote-toggle config
325 * Revision 1.23 2001/10/07 15:36:00 oes
326 * Introduced new config option "buffer-limit"
328 * Revision 1.22 2001/09/22 16:36:59 jongfoster
329 * Removing unused parameter fs from read_config_line()
331 * Revision 1.21 2001/09/16 17:10:43 jongfoster
332 * Moving function savearg() here, since it was the only thing left in
335 * Revision 1.20 2001/07/30 22:08:36 jongfoster
336 * Tidying up #defines:
337 * - All feature #defines are now of the form FEATURE_xxx
338 * - Permanently turned off WIN_GUI_EDIT
339 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
341 * Revision 1.19 2001/07/15 17:45:16 jongfoster
342 * Removing some unused #includes
344 * Revision 1.18 2001/07/13 14:01:14 oes
345 * - Removed all #ifdef PCRS
346 * - Removed vim-settings
348 * Revision 1.17 2001/06/29 13:31:03 oes
349 * - Improved comments
350 * - Fixed (actionsfile) and sorted hashes
351 * - Introduced admin_address and proxy-info-url
352 * as config parameters
353 * - Renamed config->proxy_args_invocation (which didn't have
354 * the invocation but the options!) to config->proxy_args
355 * - Various adaptions
356 * - Removed logentry from cancelled commit
358 * Revision 1.16 2001/06/09 10:55:28 jongfoster
359 * Changing BUFSIZ ==> BUFFER_SIZE
361 * Revision 1.15 2001/06/07 23:13:40 jongfoster
362 * Merging ACL and forward files into config file.
363 * Cosmetic: Sorting config file options alphabetically.
364 * Cosmetic: Adding brief syntax comments to config file options.
366 * Revision 1.14 2001/06/07 14:46:25 joergs
367 * Missing make_path() added for re_filterfile.
369 * Revision 1.13 2001/06/05 22:33:54 jongfoster
371 * Fixed minor memory leak.
372 * Also now uses make_path to prepend the pathnames.
374 * Revision 1.12 2001/06/05 20:04:09 jongfoster
375 * Now uses _snprintf() in place of snprintf() under Win32.
377 * Revision 1.11 2001/06/04 18:31:58 swa
378 * files are now prefixed with either `confdir' or `logdir'.
379 * `make redhat-dist' replaces both entries confdir and logdir
382 * Revision 1.10 2001/06/03 19:11:54 oes
383 * introduced confdir option
385 * Revision 1.9 2001/06/01 20:06:24 jongfoster
386 * Removed support for "tinygif" option - moved to actions file.
388 * Revision 1.8 2001/05/31 21:27:13 jongfoster
389 * Removed many options from the config file and into the
390 * "actions" file: add_forwarded, suppress_vanilla_wafer,
391 * wafer, add_header, user_agent, referer, from
392 * Also globally replaced "permission" with "action".
394 * Revision 1.7 2001/05/29 09:50:24 jongfoster
395 * Unified blocklist/imagelist/permissionslist.
396 * File format is still under discussion, but the internal changes
399 * Also modified interceptor behaviour:
400 * - We now intercept all URLs beginning with one of the following
401 * prefixes (and *only* these prefixes):
403 * * http://ijbswa.sf.net/config/
404 * * http://ijbswa.sourceforge.net/config/
405 * - New interceptors "home page" - go to http://i.j.b/ to see it.
406 * - Internal changes so that intercepted and fast redirect pages
407 * are not replaced with an image.
408 * - Interceptors now have the option to send a binary page direct
409 * to the client. (i.e. ijb-send-banner uses this)
410 * - Implemented show-url-info interceptor. (Which is why I needed
411 * the above interceptors changes - a typical URL is
412 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
413 * The previous mechanism would not have intercepted that, and
414 * if it had been intercepted then it then it would have replaced
417 * Revision 1.6 2001/05/26 00:28:36 jongfoster
418 * Automatic reloading of config file.
419 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
420 * Most of the global variables have been moved to a new
421 * struct configuration_spec, accessed through csp->config->globalname
422 * Most of the globals remaining are used by the Win32 GUI.
424 * Revision 1.5 2001/05/25 22:34:30 jongfoster
427 * Revision 1.4 2001/05/22 18:46:04 oes
429 * - Enabled filtering banners by size rather than URL
430 * by adding patterns that replace all standard banner
431 * sizes with the "Junkbuster" gif to the re_filterfile
433 * - Enabled filtering WebBugs by providing a pattern
434 * which kills all 1x1 images
436 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
437 * which is selected by the (nonstandard and therefore
438 * capital) letter 'U' in the option string.
439 * It causes the quantifiers to be ungreedy by default.
440 * Appending a ? turns back to greedy (!).
442 * - Added a new interceptor ijb-send-banner, which
443 * sends back the "Junkbuster" gif. Without imagelist or
444 * MSIE detection support, or if tinygif = 1, or the
445 * URL isn't recognized as an imageurl, a lame HTML
446 * explanation is sent instead.
448 * - Added new feature, which permits blocking remote
449 * script redirects and firing back a local redirect
451 * The feature is conditionally compiled, i.e. it
452 * can be disabled with --disable-fast-redirects,
453 * plus it must be activated by a "fast-redirects"
454 * line in the config file, has its own log level
455 * and of course wants to be displayed by show-proxy-args
456 * Note: Boy, all the #ifdefs in 1001 locations and
457 * all the fumbling with configure.in and acconfig.h
458 * were *way* more work than the feature itself :-(
460 * - Because a generic redirect template was needed for
461 * this, tinygif = 3 now uses the same.
463 * - Moved GIFs, and other static HTTP response templates
468 * - Removed some >400 CRs again (Jon, you really worked
471 * Revision 1.3 2001/05/20 01:21:20 jongfoster
472 * Version 2.9.4 checkin.
473 * - Merged popupfile and cookiefile, and added control over PCRS
474 * filtering, in new "permissionsfile".
475 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
476 * file error you now get a message box (in the Win32 GUI) rather
477 * than the program exiting with no explanation.
478 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
480 * - Removed tabs from "config"
481 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
482 * - Bumped up version number.
484 * Revision 1.2 2001/05/17 23:01:01 oes
485 * - Cleaned CRLF's from the sources and related files
487 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
488 * Initial import of version 2.9.3 source tree
491 *********************************************************************/
497 #include <sys/types.h>
511 # include <windows.h>
514 # ifndef _WIN_CONSOLE
516 # endif /* ndef _WIN_CONSOLE */
518 #else /* ifndef _WIN32 */
522 # include <sys/wait.h>
524 # include <sys/time.h>
525 # include <sys/stat.h>
535 #include "miscutil.h"
539 #include "urlmatch.h"
543 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
546 * Fix a problem with Solaris. There should be no effect on other
548 * Solaris's isspace() is a macro which uses it's argument directly
549 * as an array index. Therefore we need to make sure that high-bit
550 * characters generate +ve values, and ideally we also want to make
551 * the argument match the declared parameter type of "int".
553 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
554 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
556 #ifdef FEATURE_TOGGLE
557 /* Privoxy is enabled by default. */
558 int global_toggle_state = 1;
559 #endif /* def FEATURE_TOGGLE */
561 /* The filename of the configfile */
562 const char *configfile = NULL;
565 * CGI functions will later need access to the invocation args,
566 * so we will make argc and argv global.
569 const char **Argv = NULL;
571 static struct file_list *current_configfile = NULL;
575 * This takes the "cryptic" hash of each keyword and aliases them to
576 * something a little more readable. This also makes changing the
577 * hash values easier if they should change or the hash algorthm changes.
578 * Use the included "hash" program to find out what the hash will be
579 * for any string supplied on the command line. (Or just put it in the
580 * config file and read the number from the error message in the log).
582 * Please keep this list sorted alphabetically (but with the Windows
583 * console and GUI specific options last).
586 #define hash_actions_file 1196306641ul /* "actionsfile" */
587 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
588 #define hash_admin_address 4112573064ul /* "admin-address" */
589 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
590 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
591 #define hash_confdir 1978389ul /* "confdir" */
592 #define hash_debug 78263ul /* "debug" */
593 #define hash_deny_access 1227333715ul /* "deny-access" */
594 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
595 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
596 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
597 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
598 #define hash_filterfile 250887266ul /* "filterfile" */
599 #define hash_forward 2029845ul /* "forward" */
600 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
601 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
602 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
603 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
604 #define hash_hostname 10308071ul /* "hostname" */
605 #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */
606 #define hash_listen_address 1255650842ul /* "listen-address" */
607 #define hash_logdir 422889ul /* "logdir" */
608 #define hash_logfile 2114766ul /* "logfile" */
609 #define hash_permit_access 3587953268ul /* "permit-access" */
610 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
611 #define hash_single_threaded 4250084780ul /* "single-threaded" */
612 #define hash_socket_timeout 1809001761ul /* "socket-timeout" */
613 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
614 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
615 #define hash_templdir 11067889ul /* "templdir" */
616 #define hash_toggle 447966ul /* "toggle" */
617 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
618 #define hash_trustfile 56494766ul /* "trustfile" */
619 #define hash_usermanual 1416668518ul /* "user-manual" */
620 #define hash_activity_animation 1817904738ul /* "activity-animation" */
621 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
622 #define hash_hide_console 2048809870ul /* "hide-console" */
623 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
624 #define hash_log_font_name 2866730124ul /* "log-font-name" */
625 #define hash_log_font_size 2866731014ul /* "log-font-size" */
626 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
627 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
628 #define hash_log_messages 2291744899ul /* "log-messages" */
629 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
632 static void savearg(char *command, char *argument, struct configuration_spec * config);
634 /*********************************************************************
636 * Function : unload_configfile
638 * Description : Free the config structure and all components.
641 * 1 : data: struct configuration_spec to unload
645 *********************************************************************/
646 static void unload_configfile (void * data)
648 struct configuration_spec * config = (struct configuration_spec *)data;
649 struct forward_spec *cur_fwd = config->forward;
653 struct access_control_list *cur_acl = config->acl;
655 while (cur_acl != NULL)
657 struct access_control_list * next_acl = cur_acl->next;
662 #endif /* def FEATURE_ACL */
664 while (cur_fwd != NULL)
666 struct forward_spec * next_fwd = cur_fwd->next;
667 free_url_spec(cur_fwd->url);
669 freez(cur_fwd->gateway_host);
670 freez(cur_fwd->forward_host);
674 config->forward = NULL;
676 freez(config->confdir);
677 freez(config->logdir);
678 freez(config->templdir);
679 freez(config->hostname);
681 freez(config->haddr);
682 freez(config->logfile);
684 for (i = 0; i < MAX_AF_FILES; i++)
686 freez(config->actions_file_short[i]);
687 freez(config->actions_file[i]);
688 freez(config->re_filterfile_short[i]);
689 freez(config->re_filterfile[i]);
692 freez(config->admin_address);
693 freez(config->proxy_info_url);
694 freez(config->proxy_args);
695 freez(config->usermanual);
698 freez(config->trustfile);
699 list_remove_all(config->trust_info);
700 #endif /* def FEATURE_TRUST */
702 for (i = 0; i < MAX_AF_FILES; i++)
704 freez(config->re_filterfile[i]);
711 #ifdef FEATURE_GRACEFUL_TERMINATION
712 /*********************************************************************
714 * Function : unload_current_config_file
716 * Description : Unloads current config file - reset to state at
717 * beginning of program.
723 *********************************************************************/
724 void unload_current_config_file(void)
726 if (current_configfile)
728 current_configfile->unloader = unload_configfile;
729 current_configfile = NULL;
735 /*********************************************************************
737 * Function : load_config
739 * Description : Load the config file and all parameters.
741 * XXX: more than thousand lines long
742 * and thus in serious need of refactoring.
746 * Returns : The configuration_spec, or NULL on error.
748 *********************************************************************/
749 struct configuration_spec * load_config(void)
751 char buf[BUFFER_SIZE];
753 FILE *configfp = NULL;
754 struct configuration_spec * config = NULL;
755 struct client_state * fake_csp;
756 struct file_list *fs;
757 unsigned long linenum = 0;
759 char *logfile = NULL;
760 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
761 int keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
764 if ( !check_file_changed(current_configfile, configfile, &fs))
766 /* No need to load */
767 return ((struct configuration_spec *)current_configfile->f);
771 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
775 if (NULL != current_configfile)
777 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
780 #ifdef FEATURE_TOGGLE
781 global_toggle_state = 1;
782 #endif /* def FEATURE_TOGGLE */
784 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
790 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
791 /* Never get here - LOG_LEVEL_FATAL causes program exit */
795 * This is backwards from how it's usually done.
796 * Following the usual pattern, "fs" would be stored in a member
797 * variable in "csp", and then we'd access "config" from "fs->f",
798 * using a cast. However, "config" is used so often that a
799 * cast each time would be very ugly, and the extra indirection
800 * would waste CPU cycles. Therefore we store "config" in
801 * "csp->config", and "fs" in "csp->config->config_file_list".
803 config->config_file_list = fs;
808 config->multi_threaded = 1;
809 config->hport = HADDR_PORT;
810 config->buffer_limit = 4096 * 1024;
811 config->usermanual = strdup(USER_MANUAL_URL);
812 config->proxy_args = strdup("");
813 config->forwarded_connect_retries = 0;
814 config->socket_timeout = 300; /* XXX: Should be a macro. */
815 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
816 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
817 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
819 if ((configfp = fopen(configfile, "r")) == NULL)
821 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
823 /* Never get here - LOG_LEVEL_FATAL causes program exit */
826 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
828 char cmd[BUFFER_SIZE];
829 char arg[BUFFER_SIZE];
830 char tmp[BUFFER_SIZE];
832 struct access_control_list *cur_acl;
833 #endif /* def FEATURE_ACL */
834 struct forward_spec *cur_fwd;
837 unsigned long directive_hash;
839 strlcpy(tmp, buf, sizeof(tmp));
841 /* Copy command (i.e. up to space or tab) into cmd */
844 while (*p && (*p != ' ') && (*p != '\t'))
850 /* Skip over the whitespace in buf */
851 while (*p && ((*p == ' ') || (*p == '\t')))
856 /* Copy the argument into arg */
857 strlcpy(arg, p, sizeof(arg));
859 /* Should never happen, but check this anyway */
865 /* Make sure the command field is lower case */
870 *p = (char)ijb_tolower(*p);
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 strlcpy(tmp, arg, sizeof(tmp));
963 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
965 if ((vec_count != 1) && (vec_count != 2))
967 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
968 "deny-access directive in configuration file.");
969 string_append(&config->proxy_args,
970 "<br>\nWARNING: Wrong number of parameters for "
971 "deny-access directive in configuration file.<br><br>\n");
975 /* allocate a new node */
976 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
980 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
981 /* Never get here - LOG_LEVEL_FATAL causes program exit */
984 cur_acl->action = ACL_DENY;
986 if (acl_addr(vec[0], cur_acl->src) < 0)
988 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
989 "for deny-access directive in configuration file: \"%s\"", vec[0]);
990 string_append(&config->proxy_args,
991 "<br>\nWARNING: Invalid source address, port or netmask "
992 "for deny-access directive in configuration file: \"");
993 string_append(&config->proxy_args,
995 string_append(&config->proxy_args,
1002 if (acl_addr(vec[1], cur_acl->dst) < 0)
1004 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1005 "for deny-access directive in configuration file: \"%s\"", vec[1]);
1006 string_append(&config->proxy_args,
1007 "<br>\nWARNING: Invalid destination address, port or netmask "
1008 "for deny-access directive in configuration file: \"");
1009 string_append(&config->proxy_args,
1011 string_append(&config->proxy_args,
1019 * Add it to the list. Note we reverse the list to get the
1020 * behaviour the user expects. With both the ACL and
1021 * actions file, the last match wins. However, the internal
1022 * implementations are different: The actions file is stored
1023 * in the same order as the file, and scanned completely.
1024 * With the ACL, we reverse the order as we load it, then
1025 * when we scan it we stop as soon as we get a match.
1027 cur_acl->next = config->acl;
1028 config->acl = cur_acl;
1031 #endif /* def FEATURE_ACL */
1033 /* *************************************************************************
1034 * enable-edit-actions 0|1
1035 * *************************************************************************/
1036 #ifdef FEATURE_CGI_EDIT_ACTIONS
1037 case hash_enable_edit_actions:
1038 if ((*arg != '\0') && (0 != atoi(arg)))
1040 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1044 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1047 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1049 /* *************************************************************************
1050 * enable-remote-toggle 0|1
1051 * *************************************************************************/
1052 #ifdef FEATURE_TOGGLE
1053 case hash_enable_remote_toggle:
1054 if ((*arg != '\0') && (0 != atoi(arg)))
1056 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1060 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1063 #endif /* def FEATURE_TOGGLE */
1065 /* *************************************************************************
1066 * enable-remote-http-toggle 0|1
1067 * *************************************************************************/
1068 case hash_enable_remote_http_toggle:
1069 if ((*arg != '\0') && (0 != atoi(arg)))
1071 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1075 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1079 /* *************************************************************************
1080 * enforce-blocks 0|1
1081 * *************************************************************************/
1082 case hash_enforce_blocks:
1083 #ifdef FEATURE_FORCE_LOAD
1084 if ((*arg != '\0') && (0 != atoi(arg)))
1086 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1090 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1093 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1094 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1095 #endif /* def FEATURE_FORCE_LOAD */
1098 /* *************************************************************************
1099 * filterfile file-name
1100 * In confdir by default.
1101 * *************************************************************************/
1102 case hash_filterfile :
1104 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1109 if (i >= MAX_AF_FILES)
1111 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1112 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1115 config->re_filterfile_short[i] = strdup(arg);
1116 config->re_filterfile[i] = make_path(config->confdir, arg);
1120 /* *************************************************************************
1121 * forward url-pattern (.|http-proxy-host[:port])
1122 * *************************************************************************/
1124 strlcpy(tmp, arg, sizeof(tmp));
1125 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1129 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1130 "directive in configuration file.");
1131 string_append(&config->proxy_args,
1132 "<br>\nWARNING: Wrong number of parameters for "
1133 "forward directive in configuration file.");
1137 /* allocate a new node */
1138 cur_fwd = zalloc(sizeof(*cur_fwd));
1139 if (cur_fwd == NULL)
1141 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1142 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1146 cur_fwd->type = SOCKS_NONE;
1148 /* Save the URL pattern */
1149 if (create_url_spec(cur_fwd->url, vec[0]))
1151 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1152 "directive in configuration file.");
1153 string_append(&config->proxy_args,
1154 "<br>\nWARNING: Bad URL specifier for "
1155 "forward directive in configuration file.");
1159 /* Parse the parent HTTP proxy host:port */
1162 if (strcmp(p, ".") != 0)
1164 cur_fwd->forward_host = strdup(p);
1166 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1169 cur_fwd->forward_port = atoi(p);
1172 if (cur_fwd->forward_port <= 0)
1174 cur_fwd->forward_port = 8000;
1179 cur_fwd->next = config->forward;
1180 config->forward = cur_fwd;
1184 /* *************************************************************************
1185 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1186 * *************************************************************************/
1187 case hash_forward_socks4:
1188 strlcpy(tmp, arg, sizeof(tmp));
1189 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1193 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1194 "forward-socks4 directive in configuration file.");
1195 string_append(&config->proxy_args,
1196 "<br>\nWARNING: Wrong number of parameters for "
1197 "forward-socks4 directive in configuration file.");
1201 /* allocate a new node */
1202 cur_fwd = zalloc(sizeof(*cur_fwd));
1203 if (cur_fwd == NULL)
1205 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1206 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1210 cur_fwd->type = SOCKS_4;
1212 /* Save the URL pattern */
1213 if (create_url_spec(cur_fwd->url, vec[0]))
1215 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1216 "directive in configuration file.");
1217 string_append(&config->proxy_args,
1218 "<br>\nWARNING: Bad URL specifier for "
1219 "forward-socks4 directive in configuration file.");
1223 /* Parse the SOCKS proxy host[:port] */
1226 if (strcmp(p, ".") != 0)
1228 cur_fwd->gateway_host = strdup(p);
1230 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1233 cur_fwd->gateway_port = atoi(p);
1235 if (cur_fwd->gateway_port <= 0)
1237 cur_fwd->gateway_port = 1080;
1241 /* Parse the parent HTTP proxy host[:port] */
1244 if (strcmp(p, ".") != 0)
1246 cur_fwd->forward_host = strdup(p);
1248 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1251 cur_fwd->forward_port = atoi(p);
1254 if (cur_fwd->forward_port <= 0)
1256 cur_fwd->forward_port = 8000;
1261 cur_fwd->next = config->forward;
1262 config->forward = cur_fwd;
1266 /* *************************************************************************
1267 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1268 * *************************************************************************/
1269 case hash_forward_socks4a:
1270 case hash_forward_socks5:
1271 strlcpy(tmp, arg, sizeof(tmp));
1272 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1276 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1277 "forward-socks4a directive in configuration file.");
1278 string_append(&config->proxy_args,
1279 "<br>\nWARNING: Wrong number of parameters for "
1280 "forward-socks4a directive in configuration file.");
1284 /* allocate a new node */
1285 cur_fwd = zalloc(sizeof(*cur_fwd));
1286 if (cur_fwd == NULL)
1288 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1289 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1293 if (directive_hash == hash_forward_socks4a)
1295 cur_fwd->type = SOCKS_4A;
1299 cur_fwd->type = SOCKS_5;
1302 /* Save the URL pattern */
1303 if (create_url_spec(cur_fwd->url, vec[0]))
1305 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1306 "directive in configuration file.");
1307 string_append(&config->proxy_args,
1308 "<br>\nWARNING: Bad URL specifier for "
1309 "forward-socks4a directive in configuration file.");
1313 /* Parse the SOCKS proxy host[:port] */
1316 cur_fwd->gateway_host = strdup(p);
1318 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1321 cur_fwd->gateway_port = atoi(p);
1323 if (cur_fwd->gateway_port <= 0)
1325 cur_fwd->gateway_port = 1080;
1328 /* Parse the parent HTTP proxy host[:port] */
1331 if (strcmp(p, ".") != 0)
1333 cur_fwd->forward_host = strdup(p);
1335 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1338 cur_fwd->forward_port = atoi(p);
1341 if (cur_fwd->forward_port <= 0)
1343 cur_fwd->forward_port = 8000;
1348 cur_fwd->next = config->forward;
1349 config->forward = cur_fwd;
1353 /* *************************************************************************
1354 * forwarded-connect-retries n
1355 * *************************************************************************/
1356 case hash_forwarded_connect_retries :
1357 config->forwarded_connect_retries = atoi(arg);
1360 /* *************************************************************************
1361 * hostname hostname-to-show-on-cgi-pages
1362 * *************************************************************************/
1363 case hash_hostname :
1364 freez(config->hostname);
1365 config->hostname = strdup(arg);
1366 if (NULL == config->hostname)
1368 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1372 /* *************************************************************************
1373 * keep-alive-timeout timeout
1374 * *************************************************************************/
1375 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1376 case hash_keep_alive_timeout :
1379 int timeout = atoi(arg);
1382 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1383 keep_alive_timeout = timeout;
1387 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1393 /* *************************************************************************
1394 * listen-address [ip][:port]
1395 * *************************************************************************/
1396 case hash_listen_address :
1397 freez(config->haddr);
1398 config->haddr = strdup(arg);
1401 /* *************************************************************************
1402 * logdir directory-name
1403 * *************************************************************************/
1405 freez(config->logdir);
1406 config->logdir = make_path(NULL, arg);
1409 /* *************************************************************************
1410 * logfile log-file-name
1411 * In logdir by default
1412 * *************************************************************************/
1416 logfile = make_path(config->logdir, arg);
1417 if (NULL == logfile)
1419 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1424 /* *************************************************************************
1425 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1426 * *************************************************************************/
1428 case hash_permit_access:
1429 strlcpy(tmp, arg, sizeof(tmp));
1430 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1432 if ((vec_count != 1) && (vec_count != 2))
1434 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1435 "permit-access directive in configuration file.");
1436 string_append(&config->proxy_args,
1437 "<br>\nWARNING: Wrong number of parameters for "
1438 "permit-access directive in configuration file.<br><br>\n");
1443 /* allocate a new node */
1444 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1446 if (cur_acl == NULL)
1448 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1449 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1452 cur_acl->action = ACL_PERMIT;
1454 if (acl_addr(vec[0], cur_acl->src) < 0)
1456 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1457 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1458 string_append(&config->proxy_args,
1459 "<br>\nWARNING: Invalid source address, port or netmask for "
1460 "permit-access directive in configuration file: \"");
1461 string_append(&config->proxy_args,
1463 string_append(&config->proxy_args,
1470 if (acl_addr(vec[1], cur_acl->dst) < 0)
1472 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1473 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1474 string_append(&config->proxy_args,
1475 "<br>\nWARNING: Invalid destination address, port or netmask for "
1476 "permit-access directive in configuration file: \"");
1477 string_append(&config->proxy_args,
1479 string_append(&config->proxy_args,
1487 * Add it to the list. Note we reverse the list to get the
1488 * behaviour the user expects. With both the ACL and
1489 * actions file, the last match wins. However, the internal
1490 * implementations are different: The actions file is stored
1491 * in the same order as the file, and scanned completely.
1492 * With the ACL, we reverse the order as we load it, then
1493 * when we scan it we stop as soon as we get a match.
1495 cur_acl->next = config->acl;
1496 config->acl = cur_acl;
1499 #endif /* def FEATURE_ACL */
1501 /* *************************************************************************
1502 * proxy-info-url url
1503 * *************************************************************************/
1504 case hash_proxy_info_url :
1505 freez(config->proxy_info_url);
1506 config->proxy_info_url = strdup(arg);
1509 /* *************************************************************************
1511 * *************************************************************************/
1512 case hash_single_threaded :
1513 config->multi_threaded = 0;
1516 /* *************************************************************************
1517 * socket-timeout numer_of_seconds
1518 * *************************************************************************/
1519 case hash_socket_timeout :
1522 int socket_timeout = atoi(arg);
1523 if (0 < socket_timeout)
1525 config->socket_timeout = socket_timeout;
1529 log_error(LOG_LEVEL_FATAL,
1530 "Invalid socket-timeout: '%s'", arg);
1535 /* *************************************************************************
1536 * split-large-cgi-forms
1537 * *************************************************************************/
1538 case hash_split_large_cgi_forms :
1539 if ((*arg != '\0') && (0 != atoi(arg)))
1541 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1545 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1549 /* *************************************************************************
1550 * templdir directory-name
1551 * *************************************************************************/
1552 case hash_templdir :
1553 freez(config->templdir);
1554 config->templdir = make_path(NULL, arg);
1557 /* *************************************************************************
1559 * *************************************************************************/
1560 #ifdef FEATURE_TOGGLE
1562 global_toggle_state = atoi(arg);
1564 #endif /* def FEATURE_TOGGLE */
1566 /* *************************************************************************
1567 * trust-info-url url
1568 * *************************************************************************/
1569 #ifdef FEATURE_TRUST
1570 case hash_trust_info_url :
1571 enlist(config->trust_info, arg);
1573 #endif /* def FEATURE_TRUST */
1575 /* *************************************************************************
1576 * trustfile filename
1577 * (In confdir by default.)
1578 * *************************************************************************/
1579 #ifdef FEATURE_TRUST
1580 case hash_trustfile :
1581 freez(config->trustfile);
1582 config->trustfile = make_path(config->confdir, arg);
1584 #endif /* def FEATURE_TRUST */
1586 /* *************************************************************************
1588 * *************************************************************************/
1589 case hash_usermanual :
1591 * XXX: If this isn't the first config directive, the
1592 * show-status page links to the website documentation
1593 * for the directives that were already parsed. Lame.
1595 freez(config->usermanual);
1596 config->usermanual = strdup(arg);
1599 /* *************************************************************************
1600 * Win32 Console options:
1601 * *************************************************************************/
1603 /* *************************************************************************
1605 * *************************************************************************/
1607 case hash_hide_console :
1610 #endif /*def _WIN_CONSOLE*/
1613 /* *************************************************************************
1614 * Win32 GUI options:
1615 * *************************************************************************/
1617 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1618 /* *************************************************************************
1619 * activity-animation (0|1)
1620 * *************************************************************************/
1621 case hash_activity_animation :
1622 g_bShowActivityAnimation = atoi(arg);
1625 /* *************************************************************************
1626 * close-button-minimizes (0|1)
1627 * *************************************************************************/
1628 case hash_close_button_minimizes :
1629 g_bCloseHidesWindow = atoi(arg);
1632 /* *************************************************************************
1633 * log-buffer-size (0|1)
1634 * *************************************************************************/
1635 case hash_log_buffer_size :
1636 g_bLimitBufferSize = atoi(arg);
1639 /* *************************************************************************
1640 * log-font-name fontnane
1641 * *************************************************************************/
1642 case hash_log_font_name :
1643 strcpy( g_szFontFaceName, arg );
1646 /* *************************************************************************
1648 * *************************************************************************/
1649 case hash_log_font_size :
1650 g_nFontSize = atoi(arg);
1653 /* *************************************************************************
1654 * log-highlight-messages (0|1)
1655 * *************************************************************************/
1656 case hash_log_highlight_messages :
1657 g_bHighlightMessages = atoi(arg);
1660 /* *************************************************************************
1662 * *************************************************************************/
1663 case hash_log_max_lines :
1664 g_nMaxBufferLines = atoi(arg);
1667 /* *************************************************************************
1668 * log-messages (0|1)
1669 * *************************************************************************/
1670 case hash_log_messages :
1671 g_bLogMessages = atoi(arg);
1674 /* *************************************************************************
1675 * show-on-task-bar (0|1)
1676 * *************************************************************************/
1677 case hash_show_on_task_bar :
1678 g_bShowOnTaskBar = atoi(arg);
1681 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1684 /* *************************************************************************
1685 * Warnings about unsupported features
1686 * *************************************************************************/
1688 case hash_deny_access:
1689 #endif /* ndef FEATURE_ACL */
1690 #ifndef FEATURE_CGI_EDIT_ACTIONS
1691 case hash_enable_edit_actions:
1692 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1693 #ifndef FEATURE_TOGGLE
1694 case hash_enable_remote_toggle:
1695 #endif /* ndef FEATURE_TOGGLE */
1697 case hash_permit_access:
1698 #endif /* ndef FEATURE_ACL */
1699 #ifndef FEATURE_TOGGLE
1701 #endif /* ndef FEATURE_TOGGLE */
1702 #ifndef FEATURE_TRUST
1703 case hash_trustfile :
1704 case hash_trust_info_url :
1705 #endif /* ndef FEATURE_TRUST */
1707 #ifndef _WIN_CONSOLE
1708 case hash_hide_console :
1709 #endif /* ndef _WIN_CONSOLE */
1711 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1712 case hash_activity_animation :
1713 case hash_close_button_minimizes :
1714 case hash_log_buffer_size :
1715 case hash_log_font_name :
1716 case hash_log_font_size :
1717 case hash_log_highlight_messages :
1718 case hash_log_max_lines :
1719 case hash_log_messages :
1720 case hash_show_on_task_bar :
1721 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1722 /* These warnings are annoying - so hide them. -- Jon */
1723 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1726 /* *************************************************************************/
1728 /* *************************************************************************/
1730 * I decided that I liked this better as a warning than an
1731 * error. To change back to an error, just change log level
1732 * to LOG_LEVEL_FATAL.
1734 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1735 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1736 string_append(&config->proxy_args,
1737 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1740 /* *************************************************************************/
1741 } /* end switch( hash_string(cmd) ) */
1743 /* Save the argument for the show-status page. */
1744 savearg(cmd, arg, config);
1746 } /* end while ( read_config_line(...) ) */
1750 set_debug_level(config->debug);
1752 freez(config->logfile);
1756 if (NULL != logfile)
1758 config->logfile = logfile;
1759 init_error_log(Argv[0], config->logfile);
1767 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1768 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1770 if (config->multi_threaded)
1772 set_keep_alive_timeout(keep_alive_timeout);
1777 * While we could use keep-alive without multiple threads
1778 * if we didn't bother with enforcing the connection timeout,
1779 * that might make Tor users sad, even though they shouldn't
1780 * enable the single-threaded option anyway.
1782 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1783 log_error(LOG_LEVEL_ERROR,
1784 "Config option single-threaded disables connection keep-alive.");
1789 if (NULL == config->proxy_args)
1791 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1794 if (config->actions_file[0])
1796 add_loader(load_action_files, config);
1799 if (config->re_filterfile[0])
1801 add_loader(load_re_filterfiles, config);
1804 #ifdef FEATURE_TRUST
1805 if (config->trustfile)
1807 add_loader(load_trustfile, config);
1809 #endif /* def FEATURE_TRUST */
1811 if ( NULL == config->haddr )
1813 config->haddr = strdup( HADDR_DEFAULT );
1816 if ( NULL != config->haddr )
1818 if (NULL != (p = strchr(config->haddr, ':')))
1823 config->hport = atoi(p);
1827 if (config->hport <= 0)
1830 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1831 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1833 if (*config->haddr == '\0')
1836 * Only the port specified. We stored it in config->hport
1837 * and don't need its text representation anymore.
1839 freez(config->haddr);
1844 * Want to run all the loaders once now.
1846 * Need to set up a fake csp, so they can get to the config.
1848 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1849 fake_csp->config = config;
1851 if (run_loader(fake_csp))
1854 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1855 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1859 /* FIXME: this is a kludge for win32 */
1860 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1862 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1863 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1864 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1866 #ifdef FEATURE_TRUST
1867 g_trustfile = config->trustfile;
1868 #endif /* def FEATURE_TRUST */
1871 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1872 /* FIXME: end kludge */
1875 config->need_bind = 1;
1877 if (current_configfile)
1879 struct configuration_spec * oldcfg = (struct configuration_spec *)
1880 current_configfile->f;
1882 * Check if config->haddr,hport == oldcfg->haddr,hport
1884 * The following could be written more compactly as a single,
1885 * (unreadably long) if statement.
1887 config->need_bind = 0;
1888 if (config->hport != oldcfg->hport)
1890 config->need_bind = 1;
1892 else if (config->haddr == NULL)
1894 if (oldcfg->haddr != NULL)
1896 config->need_bind = 1;
1899 else if (oldcfg->haddr == NULL)
1901 config->need_bind = 1;
1903 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1905 config->need_bind = 1;
1908 current_configfile->unloader = unload_configfile;
1911 fs->next = files->next;
1914 current_configfile = fs;
1920 /*********************************************************************
1922 * Function : savearg
1924 * Description : Called from `load_config'. It saves each non-empty
1925 * and non-comment line from config into
1926 * config->proxy_args. This is used to create the
1927 * show-proxy-args page. On error, frees
1928 * config->proxy_args and sets it to NULL
1931 * 1 : command = config setting that was found
1932 * 2 : argument = the setting's argument (if any)
1933 * 3 : config = Configuration to save into.
1937 *********************************************************************/
1938 static void savearg(char *command, char *argument, struct configuration_spec * config)
1947 * Add config option name embedded in
1948 * link to its section in the user-manual
1950 buf = strdup("\n<a href=\"");
1951 if (!strncmpic(config->usermanual, "file://", 7) ||
1952 !strncmpic(config->usermanual, "http", 4))
1954 string_append(&buf, config->usermanual);
1958 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1960 string_append(&buf, CONFIG_HELP_PREFIX);
1961 string_join (&buf, string_toupper(command));
1962 string_append(&buf, "\">");
1963 string_append(&buf, command);
1964 string_append(&buf, "</a> ");
1968 freez(config->proxy_args);
1972 if ( (NULL != argument) && ('\0' != *argument) )
1974 s = html_encode(argument);
1978 freez(config->proxy_args);
1982 if (strncmpic(argument, "http://", 7) == 0)
1984 string_append(&buf, "<a href=\"");
1985 string_append(&buf, s);
1986 string_append(&buf, "\">");
1987 string_join (&buf, s);
1988 string_append(&buf, "</a>");
1992 string_join (&buf, s);
1996 string_append(&buf, "<br>");
1997 string_join(&config->proxy_args, buf);