1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.88 2009/02/28 10:57:10 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.88 2009/02/28 10:57:10 fabiankeil
39 * Gimme a break or two. Don't let the show-status page
40 * link to the website documentation for the user-manual
43 * Revision 1.87 2009/02/15 07:56:13 fabiankeil
44 * Increase default socket timeout to 300 seconds.
46 * Revision 1.86 2009/02/08 19:18:57 fabiankeil
47 * Now that we have the match-all.action file, the other action
48 * files changed their position in config->actions_file[] back
49 * to the way it was before standard.action got removed and the
50 * changes from revision 1.84 have to be reverted.
52 * Revision 1.85 2009/01/22 12:06:26 fabiankeil
53 * Don't keep connections alive when running single-threaded.
55 * Revision 1.84 2009/01/14 16:14:36 fabiankeil
56 * Due to the standard.action file removal, the other action
57 * files changed their position in config->actions_file[].
58 * Update mingw32 kludge accordingly.
60 * Revision 1.83 2008/12/20 14:53:55 fabiankeil
61 * Add config option socket-timeout to control the time
62 * Privoxy waits for data to arrive on a socket. Useful
63 * in case of stale ssh tunnels or when fuzz-testing.
65 * Revision 1.82 2008/11/16 12:43:49 fabiankeil
66 * Turn keep-alive support into a runtime feature
67 * that is disabled by setting keep-alive-timeout
68 * to a negative value.
70 * Revision 1.81 2008/11/13 09:08:42 fabiankeil
71 * Add new config option: keep-alive-timeout.
73 * Revision 1.80 2008/08/31 15:59:03 fabiankeil
74 * There's no reason to let remote toggling support depend
75 * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
77 * Revision 1.79 2008/08/30 12:03:07 fabiankeil
78 * Remove FEATURE_COOKIE_JAR.
80 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
81 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
82 * disabled, log a message that blocks will always be enforced
83 * instead of complaining about an unrecognized directive.
84 * Reported by Pietro Leone.
86 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
87 * Reuse directive_hash and don't hash the same directive twice.
89 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
90 * - Merge three string_append() calls.
91 * - Remove useless assertion.
93 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
94 * Rename load_actions_file() and load_re_filterfile()
95 * as they load multiple files "now".
97 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
98 * Add hostname directive. Closes PR#1918189.
100 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
103 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
104 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
106 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
107 * Reword "unrecognized directive" warning, use better
108 * mark up and add a <br>. Fixes parts of #1856559.
110 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
111 * Plug memory leak if listen-address only specifies the port.
113 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
114 * Relocate daemon-mode-related log messages to make sure
115 * they aren't shown again in case of configuration reloads.
117 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
118 * Plug memory leak introduced with my last commit.
120 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
121 * When in daemon mode, close stderr after the configuration file has been
122 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
124 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
125 * #1763173 from Stefan Huehner: declare unload_configfile() static.
127 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
128 * As Hal noticed, checking dispatch_cgi() as the last cruncher
129 * looks like a bug if CGI requests are blocked unintentionally,
130 * so don't do it unless the user enabled the new config option
131 * "allow-cgi-request-crunching".
133 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
134 * - Use strlcpy() instead of strcpy().
135 * - Stop treating actions files special. Expect a complete file name
136 * (with or without path) like it's done for the rest of the files.
138 * - Remove an unnecessary temporary memory allocation.
139 * - Don't log anything to the console when running as
140 * daemon and no errors occurred.
142 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
143 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
145 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
146 * New config option: enforce-blocks.
148 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
149 * - Mention other reasons why acl directive loading might have failed.
150 * - Don't log the acl source if the acl destination is to blame.
152 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
153 * Add new config option "templdir" to
154 * change the templates directory.
156 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
157 * Added config option accept-intercepted-requests
158 * and disabled it by default.
160 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
161 * Fix gcc43 compiler warnings.
163 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
164 * Add config option "split-large-forms"
165 * to work around the browser bug reported
168 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
169 * Move the <br> in the generated HTML for the config
170 * options from the beginning of the string to its end.
171 * Keeps the white space in balance.
173 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
174 * Fix memory leak in case of config file reloads.
176 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
177 * Modified kludge for win32 to make ming32 menu
178 * "Options/Edit Filters" (sort of) work again.
179 * Same limitations as for the action files apply.
182 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
183 * Incorporate modified version of Roland Rosenfeld's patch to
184 * optionally access the user-manual via Privoxy. Closes patch 679075.
186 * Formatting changed to Privoxy style, added call to
187 * cgi_error_no_template if the requested file doesn't
188 * exist and modified check whether or not Privoxy itself
189 * should serve the manual. Should work cross-platform now.
191 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
192 * Added config option enable-remote-http-toggle
193 * to specify if Privoxy should recognize special
194 * headers (currently only X-Filter) to change its
195 * behaviour. Disabled by default.
197 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
198 * Make number of retries in case of forwarded-connect problems
199 * a config file option (forwarded-connect-retries) and use 0 as
202 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
203 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
204 * with what was really the latest development (the v_3_0_branch branch)
206 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
207 * Don't forget to malloc space for the null terminator...
209 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
210 * Multiple filter file support
212 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
213 * Closed two memory leaks; hopefully the last remaining ones
214 * (in the main execution paths, anyway).
216 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
217 * Addressed bug #719435
218 * - Extraneous filterfile directives now logged as errors
219 * - This and unrecnonised directives now really obvious on status page
221 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
222 * Cosmetic: Renamed cryptic variable
224 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
225 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
227 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
228 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
230 * Revision 1.48 2002/05/14 21:30:38 oes
231 * savearg now uses own linking code instead of (now special-cased) add_help_link
233 * Revision 1.47 2002/05/12 21:36:29 jongfoster
234 * Correcting function comments
236 * Revision 1.46 2002/04/26 12:55:14 oes
237 * - New option "user-manual", defaults to our site
238 * via project.h #define
239 * - savearg now embeds option names in help links
241 * Revision 1.45 2002/04/24 02:11:54 oes
242 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
244 * Revision 1.44 2002/04/08 20:37:13 swa
247 * Revision 1.43 2002/04/08 20:36:50 swa
250 * Revision 1.42 2002/04/05 15:50:15 oes
251 * fix for invalid HTML proxy_args
253 * Revision 1.41 2002/03/31 17:19:00 jongfoster
254 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
256 * Revision 1.40 2002/03/26 22:29:55 swa
257 * we have a new homepage!
259 * Revision 1.39 2002/03/24 13:25:43 swa
260 * name change related issues
262 * Revision 1.38 2002/03/24 13:05:48 jongfoster
263 * Renaming re_filterfile to filterfile
265 * Revision 1.37 2002/03/16 23:54:06 jongfoster
266 * Adding graceful termination feature, to help look for memory leaks.
267 * If you enable this (which, by design, has to be done by hand
268 * editing config.h) and then go to http://i.j.b/die, then the program
269 * will exit cleanly after the *next* request. It should free all the
270 * memory that was used.
272 * Revision 1.36 2002/03/13 00:27:05 jongfoster
275 * Revision 1.35 2002/03/07 03:52:44 oes
276 * Set logging to tty for --no-daemon mode
278 * Revision 1.34 2002/03/06 23:14:35 jongfoster
279 * Trivial cosmetic changes to make function comments easier to find.
281 * Revision 1.33 2002/03/05 04:52:42 oes
282 * Deleted non-errlog debugging code
284 * Revision 1.32 2002/03/04 18:24:53 oes
285 * Re-enabled output of unknown config directive hash
287 * Revision 1.31 2002/03/03 15:07:20 oes
288 * Re-enabled automatic config reloading
290 * Revision 1.30 2002/01/22 23:31:43 jongfoster
291 * Replacing strsav() with string_append()
293 * Revision 1.29 2002/01/17 21:02:30 jongfoster
294 * Moving all our URL and URL pattern parsing code to urlmatch.c.
296 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
298 * Revision 1.28 2001/12/30 14:07:32 steudten
299 * - Add signal handling (unix)
300 * - Add SIGHUP handler (unix)
301 * - Add creation of pidfile (unix)
302 * - Add action 'top' in rc file (RH)
303 * - Add entry 'SIGNALS' to manpage
304 * - Add exit message to logfile (unix)
306 * Revision 1.27 2001/11/07 00:02:13 steudten
307 * Add line number in error output for lineparsing for
308 * actionsfile and configfile.
309 * Special handling for CLF added.
311 * Revision 1.26 2001/11/05 21:41:43 steudten
312 * Add changes to be a real daemon just for unix os.
313 * (change cwd to /, detach from controlling tty, set
314 * process group and session leader to the own process.
316 * Add some fatal-error log message for failed malloc().
317 * Add '-d' if compiled with 'configure --with-debug' to
318 * enable debug output.
320 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
321 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
322 * threads to call select() simultaneously. So, it's time to do a real, live,
323 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
324 * (native). Both versions will work, but using __OS2__ offers multi-threading.
326 * Revision 1.24 2001/10/23 21:40:30 jongfoster
327 * Added support for enable-edit-actions and enable-remote-toggle config
330 * Revision 1.23 2001/10/07 15:36:00 oes
331 * Introduced new config option "buffer-limit"
333 * Revision 1.22 2001/09/22 16:36:59 jongfoster
334 * Removing unused parameter fs from read_config_line()
336 * Revision 1.21 2001/09/16 17:10:43 jongfoster
337 * Moving function savearg() here, since it was the only thing left in
340 * Revision 1.20 2001/07/30 22:08:36 jongfoster
341 * Tidying up #defines:
342 * - All feature #defines are now of the form FEATURE_xxx
343 * - Permanently turned off WIN_GUI_EDIT
344 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
346 * Revision 1.19 2001/07/15 17:45:16 jongfoster
347 * Removing some unused #includes
349 * Revision 1.18 2001/07/13 14:01:14 oes
350 * - Removed all #ifdef PCRS
351 * - Removed vim-settings
353 * Revision 1.17 2001/06/29 13:31:03 oes
354 * - Improved comments
355 * - Fixed (actionsfile) and sorted hashes
356 * - Introduced admin_address and proxy-info-url
357 * as config parameters
358 * - Renamed config->proxy_args_invocation (which didn't have
359 * the invocation but the options!) to config->proxy_args
360 * - Various adaptions
361 * - Removed logentry from cancelled commit
363 * Revision 1.16 2001/06/09 10:55:28 jongfoster
364 * Changing BUFSIZ ==> BUFFER_SIZE
366 * Revision 1.15 2001/06/07 23:13:40 jongfoster
367 * Merging ACL and forward files into config file.
368 * Cosmetic: Sorting config file options alphabetically.
369 * Cosmetic: Adding brief syntax comments to config file options.
371 * Revision 1.14 2001/06/07 14:46:25 joergs
372 * Missing make_path() added for re_filterfile.
374 * Revision 1.13 2001/06/05 22:33:54 jongfoster
376 * Fixed minor memory leak.
377 * Also now uses make_path to prepend the pathnames.
379 * Revision 1.12 2001/06/05 20:04:09 jongfoster
380 * Now uses _snprintf() in place of snprintf() under Win32.
382 * Revision 1.11 2001/06/04 18:31:58 swa
383 * files are now prefixed with either `confdir' or `logdir'.
384 * `make redhat-dist' replaces both entries confdir and logdir
387 * Revision 1.10 2001/06/03 19:11:54 oes
388 * introduced confdir option
390 * Revision 1.9 2001/06/01 20:06:24 jongfoster
391 * Removed support for "tinygif" option - moved to actions file.
393 * Revision 1.8 2001/05/31 21:27:13 jongfoster
394 * Removed many options from the config file and into the
395 * "actions" file: add_forwarded, suppress_vanilla_wafer,
396 * wafer, add_header, user_agent, referer, from
397 * Also globally replaced "permission" with "action".
399 * Revision 1.7 2001/05/29 09:50:24 jongfoster
400 * Unified blocklist/imagelist/permissionslist.
401 * File format is still under discussion, but the internal changes
404 * Also modified interceptor behaviour:
405 * - We now intercept all URLs beginning with one of the following
406 * prefixes (and *only* these prefixes):
408 * * http://ijbswa.sf.net/config/
409 * * http://ijbswa.sourceforge.net/config/
410 * - New interceptors "home page" - go to http://i.j.b/ to see it.
411 * - Internal changes so that intercepted and fast redirect pages
412 * are not replaced with an image.
413 * - Interceptors now have the option to send a binary page direct
414 * to the client. (i.e. ijb-send-banner uses this)
415 * - Implemented show-url-info interceptor. (Which is why I needed
416 * the above interceptors changes - a typical URL is
417 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
418 * The previous mechanism would not have intercepted that, and
419 * if it had been intercepted then it then it would have replaced
422 * Revision 1.6 2001/05/26 00:28:36 jongfoster
423 * Automatic reloading of config file.
424 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
425 * Most of the global variables have been moved to a new
426 * struct configuration_spec, accessed through csp->config->globalname
427 * Most of the globals remaining are used by the Win32 GUI.
429 * Revision 1.5 2001/05/25 22:34:30 jongfoster
432 * Revision 1.4 2001/05/22 18:46:04 oes
434 * - Enabled filtering banners by size rather than URL
435 * by adding patterns that replace all standard banner
436 * sizes with the "Junkbuster" gif to the re_filterfile
438 * - Enabled filtering WebBugs by providing a pattern
439 * which kills all 1x1 images
441 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
442 * which is selected by the (nonstandard and therefore
443 * capital) letter 'U' in the option string.
444 * It causes the quantifiers to be ungreedy by default.
445 * Appending a ? turns back to greedy (!).
447 * - Added a new interceptor ijb-send-banner, which
448 * sends back the "Junkbuster" gif. Without imagelist or
449 * MSIE detection support, or if tinygif = 1, or the
450 * URL isn't recognized as an imageurl, a lame HTML
451 * explanation is sent instead.
453 * - Added new feature, which permits blocking remote
454 * script redirects and firing back a local redirect
456 * The feature is conditionally compiled, i.e. it
457 * can be disabled with --disable-fast-redirects,
458 * plus it must be activated by a "fast-redirects"
459 * line in the config file, has its own log level
460 * and of course wants to be displayed by show-proxy-args
461 * Note: Boy, all the #ifdefs in 1001 locations and
462 * all the fumbling with configure.in and acconfig.h
463 * were *way* more work than the feature itself :-(
465 * - Because a generic redirect template was needed for
466 * this, tinygif = 3 now uses the same.
468 * - Moved GIFs, and other static HTTP response templates
473 * - Removed some >400 CRs again (Jon, you really worked
476 * Revision 1.3 2001/05/20 01:21:20 jongfoster
477 * Version 2.9.4 checkin.
478 * - Merged popupfile and cookiefile, and added control over PCRS
479 * filtering, in new "permissionsfile".
480 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
481 * file error you now get a message box (in the Win32 GUI) rather
482 * than the program exiting with no explanation.
483 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
485 * - Removed tabs from "config"
486 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
487 * - Bumped up version number.
489 * Revision 1.2 2001/05/17 23:01:01 oes
490 * - Cleaned CRLF's from the sources and related files
492 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
493 * Initial import of version 2.9.3 source tree
496 *********************************************************************/
502 #include <sys/types.h>
516 # include <windows.h>
519 # ifndef _WIN_CONSOLE
521 # endif /* ndef _WIN_CONSOLE */
523 #else /* ifndef _WIN32 */
527 # include <sys/wait.h>
529 # include <sys/time.h>
530 # include <sys/stat.h>
540 #include "miscutil.h"
544 #include "urlmatch.h"
548 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
551 * Fix a problem with Solaris. There should be no effect on other
553 * Solaris's isspace() is a macro which uses it's argument directly
554 * as an array index. Therefore we need to make sure that high-bit
555 * characters generate +ve values, and ideally we also want to make
556 * the argument match the declared parameter type of "int".
558 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
559 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
561 #ifdef FEATURE_TOGGLE
562 /* Privoxy is enabled by default. */
563 int global_toggle_state = 1;
564 #endif /* def FEATURE_TOGGLE */
566 /* The filename of the configfile */
567 const char *configfile = NULL;
570 * CGI functions will later need access to the invocation args,
571 * so we will make argc and argv global.
574 const char **Argv = NULL;
576 static struct file_list *current_configfile = NULL;
580 * This takes the "cryptic" hash of each keyword and aliases them to
581 * something a little more readable. This also makes changing the
582 * hash values easier if they should change or the hash algorthm changes.
583 * Use the included "hash" program to find out what the hash will be
584 * for any string supplied on the command line. (Or just put it in the
585 * config file and read the number from the error message in the log).
587 * Please keep this list sorted alphabetically (but with the Windows
588 * console and GUI specific options last).
591 #define hash_actions_file 1196306641ul /* "actionsfile" */
592 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
593 #define hash_admin_address 4112573064ul /* "admin-address" */
594 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
595 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
596 #define hash_confdir 1978389ul /* "confdir" */
597 #define hash_debug 78263ul /* "debug" */
598 #define hash_deny_access 1227333715ul /* "deny-access" */
599 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
600 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
601 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
602 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
603 #define hash_filterfile 250887266ul /* "filterfile" */
604 #define hash_forward 2029845ul /* "forward" */
605 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
606 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
607 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
608 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
609 #define hash_hostname 10308071ul /* "hostname" */
610 #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */
611 #define hash_listen_address 1255650842ul /* "listen-address" */
612 #define hash_logdir 422889ul /* "logdir" */
613 #define hash_logfile 2114766ul /* "logfile" */
614 #define hash_permit_access 3587953268ul /* "permit-access" */
615 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
616 #define hash_single_threaded 4250084780ul /* "single-threaded" */
617 #define hash_socket_timeout 1809001761ul /* "socket-timeout" */
618 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
619 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
620 #define hash_templdir 11067889ul /* "templdir" */
621 #define hash_toggle 447966ul /* "toggle" */
622 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
623 #define hash_trustfile 56494766ul /* "trustfile" */
624 #define hash_usermanual 1416668518ul /* "user-manual" */
625 #define hash_activity_animation 1817904738ul /* "activity-animation" */
626 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
627 #define hash_hide_console 2048809870ul /* "hide-console" */
628 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
629 #define hash_log_font_name 2866730124ul /* "log-font-name" */
630 #define hash_log_font_size 2866731014ul /* "log-font-size" */
631 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
632 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
633 #define hash_log_messages 2291744899ul /* "log-messages" */
634 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
637 static void savearg(char *command, char *argument, struct configuration_spec * config);
639 /*********************************************************************
641 * Function : unload_configfile
643 * Description : Free the config structure and all components.
646 * 1 : data: struct configuration_spec to unload
650 *********************************************************************/
651 static void unload_configfile (void * data)
653 struct configuration_spec * config = (struct configuration_spec *)data;
654 struct forward_spec *cur_fwd = config->forward;
658 struct access_control_list *cur_acl = config->acl;
660 while (cur_acl != NULL)
662 struct access_control_list * next_acl = cur_acl->next;
667 #endif /* def FEATURE_ACL */
669 while (cur_fwd != NULL)
671 struct forward_spec * next_fwd = cur_fwd->next;
672 free_url_spec(cur_fwd->url);
674 freez(cur_fwd->gateway_host);
675 freez(cur_fwd->forward_host);
679 config->forward = NULL;
681 freez(config->confdir);
682 freez(config->logdir);
683 freez(config->templdir);
684 freez(config->hostname);
686 freez(config->haddr);
687 freez(config->logfile);
689 for (i = 0; i < MAX_AF_FILES; i++)
691 freez(config->actions_file_short[i]);
692 freez(config->actions_file[i]);
693 freez(config->re_filterfile_short[i]);
694 freez(config->re_filterfile[i]);
697 freez(config->admin_address);
698 freez(config->proxy_info_url);
699 freez(config->proxy_args);
700 freez(config->usermanual);
703 freez(config->trustfile);
704 list_remove_all(config->trust_info);
705 #endif /* def FEATURE_TRUST */
707 for (i = 0; i < MAX_AF_FILES; i++)
709 freez(config->re_filterfile[i]);
716 #ifdef FEATURE_GRACEFUL_TERMINATION
717 /*********************************************************************
719 * Function : unload_current_config_file
721 * Description : Unloads current config file - reset to state at
722 * beginning of program.
728 *********************************************************************/
729 void unload_current_config_file(void)
731 if (current_configfile)
733 current_configfile->unloader = unload_configfile;
734 current_configfile = NULL;
740 /*********************************************************************
742 * Function : load_config
744 * Description : Load the config file and all parameters.
746 * XXX: more than thousand lines long
747 * and thus in serious need of refactoring.
751 * Returns : The configuration_spec, or NULL on error.
753 *********************************************************************/
754 struct configuration_spec * load_config(void)
756 char buf[BUFFER_SIZE];
758 FILE *configfp = NULL;
759 struct configuration_spec * config = NULL;
760 struct client_state * fake_csp;
761 struct file_list *fs;
762 unsigned long linenum = 0;
764 char *logfile = NULL;
765 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
766 int keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
769 if (!check_file_changed(current_configfile, configfile, &fs))
771 /* No need to load */
772 return ((struct configuration_spec *)current_configfile->f);
776 log_error(LOG_LEVEL_FATAL,
777 "can't check configuration file '%s': %E", configfile);
781 if (NULL != current_configfile)
783 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
786 #ifdef FEATURE_TOGGLE
787 global_toggle_state = 1;
788 #endif /* def FEATURE_TOGGLE */
790 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
796 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
801 * This is backwards from how it's usually done.
802 * Following the usual pattern, "fs" would be stored in a member
803 * variable in "csp", and then we'd access "config" from "fs->f",
804 * using a cast. However, "config" is used so often that a
805 * cast each time would be very ugly, and the extra indirection
806 * would waste CPU cycles. Therefore we store "config" in
807 * "csp->config", and "fs" in "csp->config->config_file_list".
809 config->config_file_list = fs;
814 config->multi_threaded = 1;
815 config->hport = HADDR_PORT;
816 config->buffer_limit = 4096 * 1024;
817 config->usermanual = strdup(USER_MANUAL_URL);
818 config->proxy_args = strdup("");
819 config->forwarded_connect_retries = 0;
820 config->socket_timeout = 300; /* XXX: Should be a macro. */
821 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
822 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
823 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
825 configfp = fopen(configfile, "r");
826 if (NULL == configfp)
828 log_error(LOG_LEVEL_FATAL,
829 "can't open configuration file '%s': %E", configfile);
830 /* Never get here - LOG_LEVEL_FATAL causes program exit */
833 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
835 char cmd[BUFFER_SIZE];
836 char arg[BUFFER_SIZE];
837 char tmp[BUFFER_SIZE];
839 struct access_control_list *cur_acl;
840 #endif /* def FEATURE_ACL */
841 struct forward_spec *cur_fwd;
844 unsigned long directive_hash;
846 strlcpy(tmp, buf, sizeof(tmp));
848 /* Copy command (i.e. up to space or tab) into cmd */
851 while (*p && (*p != ' ') && (*p != '\t'))
857 /* Skip over the whitespace in buf */
858 while (*p && ((*p == ' ') || (*p == '\t')))
863 /* Copy the argument into arg */
864 strlcpy(arg, p, sizeof(arg));
866 /* Should never happen, but check this anyway */
872 /* Make sure the command field is lower case */
873 for (p = cmd; *p; p++)
877 *p = (char)ijb_tolower(*p);
881 directive_hash = hash_string(cmd);
882 switch (directive_hash)
884 /* *************************************************************************
885 * actionsfile actions-file-name
886 * In confdir by default
887 * *************************************************************************/
888 case hash_actions_file :
890 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
895 if (i >= MAX_AF_FILES)
897 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
898 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
901 config->actions_file_short[i] = strdup(arg);
902 config->actions_file[i] = make_path(config->confdir, arg);
905 /* *************************************************************************
906 * accept-intercepted-requests
907 * *************************************************************************/
908 case hash_accept_intercepted_requests:
909 if ((*arg != '\0') && (0 != atoi(arg)))
911 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
915 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
919 /* *************************************************************************
920 * admin-address email-address
921 * *************************************************************************/
922 case hash_admin_address :
923 freez(config->admin_address);
924 config->admin_address = strdup(arg);
927 /* *************************************************************************
928 * allow-cgi-request-crunching
929 * *************************************************************************/
930 case hash_allow_cgi_request_crunching:
931 if ((*arg != '\0') && (0 != atoi(arg)))
933 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
937 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
941 /* *************************************************************************
943 * *************************************************************************/
944 case hash_buffer_limit :
945 config->buffer_limit = (size_t)(1024 * atoi(arg));
948 /* *************************************************************************
949 * confdir directory-name
950 * *************************************************************************/
952 freez(config->confdir);
953 config->confdir = make_path( NULL, arg);
956 /* *************************************************************************
958 * Specifies debug level, multiple values are ORed together.
959 * *************************************************************************/
961 config->debug |= atoi(arg);
964 /* *************************************************************************
965 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
966 * *************************************************************************/
968 case hash_deny_access:
969 strlcpy(tmp, arg, sizeof(tmp));
970 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
972 if ((vec_count != 1) && (vec_count != 2))
974 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
975 "deny-access directive in configuration file.");
976 string_append(&config->proxy_args,
977 "<br>\nWARNING: Wrong number of parameters for "
978 "deny-access directive in configuration file.<br><br>\n");
982 /* allocate a new node */
983 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
987 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
988 /* Never get here - LOG_LEVEL_FATAL causes program exit */
991 cur_acl->action = ACL_DENY;
993 if (acl_addr(vec[0], cur_acl->src) < 0)
995 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
996 "for deny-access directive in configuration file: \"%s\"", vec[0]);
997 string_append(&config->proxy_args,
998 "<br>\nWARNING: Invalid source address, port or netmask "
999 "for deny-access directive in configuration file: \"");
1000 string_append(&config->proxy_args,
1002 string_append(&config->proxy_args,
1009 if (acl_addr(vec[1], cur_acl->dst) < 0)
1011 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1012 "for deny-access directive in configuration file: \"%s\"", vec[1]);
1013 string_append(&config->proxy_args,
1014 "<br>\nWARNING: Invalid destination address, port or netmask "
1015 "for deny-access directive in configuration file: \"");
1016 string_append(&config->proxy_args,
1018 string_append(&config->proxy_args,
1026 * Add it to the list. Note we reverse the list to get the
1027 * behaviour the user expects. With both the ACL and
1028 * actions file, the last match wins. However, the internal
1029 * implementations are different: The actions file is stored
1030 * in the same order as the file, and scanned completely.
1031 * With the ACL, we reverse the order as we load it, then
1032 * when we scan it we stop as soon as we get a match.
1034 cur_acl->next = config->acl;
1035 config->acl = cur_acl;
1038 #endif /* def FEATURE_ACL */
1040 /* *************************************************************************
1041 * enable-edit-actions 0|1
1042 * *************************************************************************/
1043 #ifdef FEATURE_CGI_EDIT_ACTIONS
1044 case hash_enable_edit_actions:
1045 if ((*arg != '\0') && (0 != atoi(arg)))
1047 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1051 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1054 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1056 /* *************************************************************************
1057 * enable-remote-toggle 0|1
1058 * *************************************************************************/
1059 #ifdef FEATURE_TOGGLE
1060 case hash_enable_remote_toggle:
1061 if ((*arg != '\0') && (0 != atoi(arg)))
1063 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1067 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1070 #endif /* def FEATURE_TOGGLE */
1072 /* *************************************************************************
1073 * enable-remote-http-toggle 0|1
1074 * *************************************************************************/
1075 case hash_enable_remote_http_toggle:
1076 if ((*arg != '\0') && (0 != atoi(arg)))
1078 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1082 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1086 /* *************************************************************************
1087 * enforce-blocks 0|1
1088 * *************************************************************************/
1089 case hash_enforce_blocks:
1090 #ifdef FEATURE_FORCE_LOAD
1091 if ((*arg != '\0') && (0 != atoi(arg)))
1093 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1097 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1100 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1101 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1102 #endif /* def FEATURE_FORCE_LOAD */
1105 /* *************************************************************************
1106 * filterfile file-name
1107 * In confdir by default.
1108 * *************************************************************************/
1109 case hash_filterfile :
1111 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1116 if (i >= MAX_AF_FILES)
1118 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1119 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1122 config->re_filterfile_short[i] = strdup(arg);
1123 config->re_filterfile[i] = make_path(config->confdir, arg);
1127 /* *************************************************************************
1128 * forward url-pattern (.|http-proxy-host[:port])
1129 * *************************************************************************/
1131 strlcpy(tmp, arg, sizeof(tmp));
1132 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1136 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1137 "directive in configuration file.");
1138 string_append(&config->proxy_args,
1139 "<br>\nWARNING: Wrong number of parameters for "
1140 "forward directive in configuration file.");
1144 /* allocate a new node */
1145 cur_fwd = zalloc(sizeof(*cur_fwd));
1146 if (cur_fwd == NULL)
1148 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1149 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1153 cur_fwd->type = SOCKS_NONE;
1155 /* Save the URL pattern */
1156 if (create_url_spec(cur_fwd->url, vec[0]))
1158 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1159 "directive in configuration file.");
1160 string_append(&config->proxy_args,
1161 "<br>\nWARNING: Bad URL specifier for "
1162 "forward directive in configuration file.");
1166 /* Parse the parent HTTP proxy host:port */
1169 if (strcmp(p, ".") != 0)
1171 cur_fwd->forward_host = strdup(p);
1173 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1176 cur_fwd->forward_port = atoi(p);
1179 if (cur_fwd->forward_port <= 0)
1181 cur_fwd->forward_port = 8000;
1186 cur_fwd->next = config->forward;
1187 config->forward = cur_fwd;
1191 /* *************************************************************************
1192 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1193 * *************************************************************************/
1194 case hash_forward_socks4:
1195 strlcpy(tmp, arg, sizeof(tmp));
1196 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1200 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1201 "forward-socks4 directive in configuration file.");
1202 string_append(&config->proxy_args,
1203 "<br>\nWARNING: Wrong number of parameters for "
1204 "forward-socks4 directive in configuration file.");
1208 /* allocate a new node */
1209 cur_fwd = zalloc(sizeof(*cur_fwd));
1210 if (cur_fwd == NULL)
1212 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1213 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1217 cur_fwd->type = SOCKS_4;
1219 /* Save the URL pattern */
1220 if (create_url_spec(cur_fwd->url, vec[0]))
1222 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1223 "directive in configuration file.");
1224 string_append(&config->proxy_args,
1225 "<br>\nWARNING: Bad URL specifier for "
1226 "forward-socks4 directive in configuration file.");
1230 /* Parse the SOCKS proxy host[:port] */
1233 if (strcmp(p, ".") != 0)
1235 cur_fwd->gateway_host = strdup(p);
1237 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1240 cur_fwd->gateway_port = atoi(p);
1242 if (cur_fwd->gateway_port <= 0)
1244 cur_fwd->gateway_port = 1080;
1248 /* Parse the parent HTTP proxy host[:port] */
1251 if (strcmp(p, ".") != 0)
1253 cur_fwd->forward_host = strdup(p);
1255 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1258 cur_fwd->forward_port = atoi(p);
1261 if (cur_fwd->forward_port <= 0)
1263 cur_fwd->forward_port = 8000;
1268 cur_fwd->next = config->forward;
1269 config->forward = cur_fwd;
1273 /* *************************************************************************
1274 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1275 * *************************************************************************/
1276 case hash_forward_socks4a:
1277 case hash_forward_socks5:
1278 strlcpy(tmp, arg, sizeof(tmp));
1279 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1283 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1284 "forward-socks4a directive in configuration file.");
1285 string_append(&config->proxy_args,
1286 "<br>\nWARNING: Wrong number of parameters for "
1287 "forward-socks4a directive in configuration file.");
1291 /* allocate a new node */
1292 cur_fwd = zalloc(sizeof(*cur_fwd));
1293 if (cur_fwd == NULL)
1295 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1296 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1300 if (directive_hash == hash_forward_socks4a)
1302 cur_fwd->type = SOCKS_4A;
1306 cur_fwd->type = SOCKS_5;
1309 /* Save the URL pattern */
1310 if (create_url_spec(cur_fwd->url, vec[0]))
1312 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1313 "directive in configuration file.");
1314 string_append(&config->proxy_args,
1315 "<br>\nWARNING: Bad URL specifier for "
1316 "forward-socks4a directive in configuration file.");
1320 /* Parse the SOCKS proxy host[:port] */
1323 cur_fwd->gateway_host = strdup(p);
1325 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1328 cur_fwd->gateway_port = atoi(p);
1330 if (cur_fwd->gateway_port <= 0)
1332 cur_fwd->gateway_port = 1080;
1335 /* Parse the parent HTTP proxy host[:port] */
1338 if (strcmp(p, ".") != 0)
1340 cur_fwd->forward_host = strdup(p);
1342 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1345 cur_fwd->forward_port = atoi(p);
1348 if (cur_fwd->forward_port <= 0)
1350 cur_fwd->forward_port = 8000;
1355 cur_fwd->next = config->forward;
1356 config->forward = cur_fwd;
1360 /* *************************************************************************
1361 * forwarded-connect-retries n
1362 * *************************************************************************/
1363 case hash_forwarded_connect_retries :
1364 config->forwarded_connect_retries = atoi(arg);
1367 /* *************************************************************************
1368 * hostname hostname-to-show-on-cgi-pages
1369 * *************************************************************************/
1370 case hash_hostname :
1371 freez(config->hostname);
1372 config->hostname = strdup(arg);
1373 if (NULL == config->hostname)
1375 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1379 /* *************************************************************************
1380 * keep-alive-timeout timeout
1381 * *************************************************************************/
1382 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1383 case hash_keep_alive_timeout :
1386 int timeout = atoi(arg);
1389 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1390 keep_alive_timeout = timeout;
1394 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1400 /* *************************************************************************
1401 * listen-address [ip][:port]
1402 * *************************************************************************/
1403 case hash_listen_address :
1404 freez(config->haddr);
1405 config->haddr = strdup(arg);
1408 /* *************************************************************************
1409 * logdir directory-name
1410 * *************************************************************************/
1412 freez(config->logdir);
1413 config->logdir = make_path(NULL, arg);
1416 /* *************************************************************************
1417 * logfile log-file-name
1418 * In logdir by default
1419 * *************************************************************************/
1423 logfile = make_path(config->logdir, arg);
1424 if (NULL == logfile)
1426 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1431 /* *************************************************************************
1432 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1433 * *************************************************************************/
1435 case hash_permit_access:
1436 strlcpy(tmp, arg, sizeof(tmp));
1437 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1439 if ((vec_count != 1) && (vec_count != 2))
1441 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1442 "permit-access directive in configuration file.");
1443 string_append(&config->proxy_args,
1444 "<br>\nWARNING: Wrong number of parameters for "
1445 "permit-access directive in configuration file.<br><br>\n");
1450 /* allocate a new node */
1451 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1453 if (cur_acl == NULL)
1455 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1456 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1459 cur_acl->action = ACL_PERMIT;
1461 if (acl_addr(vec[0], cur_acl->src) < 0)
1463 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1464 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1465 string_append(&config->proxy_args,
1466 "<br>\nWARNING: Invalid source address, port or netmask for "
1467 "permit-access directive in configuration file: \"");
1468 string_append(&config->proxy_args,
1470 string_append(&config->proxy_args,
1477 if (acl_addr(vec[1], cur_acl->dst) < 0)
1479 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1480 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1481 string_append(&config->proxy_args,
1482 "<br>\nWARNING: Invalid destination address, port or netmask for "
1483 "permit-access directive in configuration file: \"");
1484 string_append(&config->proxy_args,
1486 string_append(&config->proxy_args,
1494 * Add it to the list. Note we reverse the list to get the
1495 * behaviour the user expects. With both the ACL and
1496 * actions file, the last match wins. However, the internal
1497 * implementations are different: The actions file is stored
1498 * in the same order as the file, and scanned completely.
1499 * With the ACL, we reverse the order as we load it, then
1500 * when we scan it we stop as soon as we get a match.
1502 cur_acl->next = config->acl;
1503 config->acl = cur_acl;
1506 #endif /* def FEATURE_ACL */
1508 /* *************************************************************************
1509 * proxy-info-url url
1510 * *************************************************************************/
1511 case hash_proxy_info_url :
1512 freez(config->proxy_info_url);
1513 config->proxy_info_url = strdup(arg);
1516 /* *************************************************************************
1518 * *************************************************************************/
1519 case hash_single_threaded :
1520 config->multi_threaded = 0;
1523 /* *************************************************************************
1524 * socket-timeout numer_of_seconds
1525 * *************************************************************************/
1526 case hash_socket_timeout :
1529 int socket_timeout = atoi(arg);
1530 if (0 < socket_timeout)
1532 config->socket_timeout = socket_timeout;
1536 log_error(LOG_LEVEL_FATAL,
1537 "Invalid socket-timeout: '%s'", arg);
1542 /* *************************************************************************
1543 * split-large-cgi-forms
1544 * *************************************************************************/
1545 case hash_split_large_cgi_forms :
1546 if ((*arg != '\0') && (0 != atoi(arg)))
1548 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1552 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1556 /* *************************************************************************
1557 * templdir directory-name
1558 * *************************************************************************/
1559 case hash_templdir :
1560 freez(config->templdir);
1561 config->templdir = make_path(NULL, arg);
1564 /* *************************************************************************
1566 * *************************************************************************/
1567 #ifdef FEATURE_TOGGLE
1569 global_toggle_state = atoi(arg);
1571 #endif /* def FEATURE_TOGGLE */
1573 /* *************************************************************************
1574 * trust-info-url url
1575 * *************************************************************************/
1576 #ifdef FEATURE_TRUST
1577 case hash_trust_info_url :
1578 enlist(config->trust_info, arg);
1580 #endif /* def FEATURE_TRUST */
1582 /* *************************************************************************
1583 * trustfile filename
1584 * (In confdir by default.)
1585 * *************************************************************************/
1586 #ifdef FEATURE_TRUST
1587 case hash_trustfile :
1588 freez(config->trustfile);
1589 config->trustfile = make_path(config->confdir, arg);
1591 #endif /* def FEATURE_TRUST */
1593 /* *************************************************************************
1595 * *************************************************************************/
1596 case hash_usermanual :
1598 * XXX: If this isn't the first config directive, the
1599 * show-status page links to the website documentation
1600 * for the directives that were already parsed. Lame.
1602 freez(config->usermanual);
1603 config->usermanual = strdup(arg);
1606 /* *************************************************************************
1607 * Win32 Console options:
1608 * *************************************************************************/
1610 /* *************************************************************************
1612 * *************************************************************************/
1614 case hash_hide_console :
1617 #endif /*def _WIN_CONSOLE*/
1620 /* *************************************************************************
1621 * Win32 GUI options:
1622 * *************************************************************************/
1624 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1625 /* *************************************************************************
1626 * activity-animation (0|1)
1627 * *************************************************************************/
1628 case hash_activity_animation :
1629 g_bShowActivityAnimation = atoi(arg);
1632 /* *************************************************************************
1633 * close-button-minimizes (0|1)
1634 * *************************************************************************/
1635 case hash_close_button_minimizes :
1636 g_bCloseHidesWindow = atoi(arg);
1639 /* *************************************************************************
1640 * log-buffer-size (0|1)
1641 * *************************************************************************/
1642 case hash_log_buffer_size :
1643 g_bLimitBufferSize = atoi(arg);
1646 /* *************************************************************************
1647 * log-font-name fontnane
1648 * *************************************************************************/
1649 case hash_log_font_name :
1650 strcpy( g_szFontFaceName, arg );
1653 /* *************************************************************************
1655 * *************************************************************************/
1656 case hash_log_font_size :
1657 g_nFontSize = atoi(arg);
1660 /* *************************************************************************
1661 * log-highlight-messages (0|1)
1662 * *************************************************************************/
1663 case hash_log_highlight_messages :
1664 g_bHighlightMessages = atoi(arg);
1667 /* *************************************************************************
1669 * *************************************************************************/
1670 case hash_log_max_lines :
1671 g_nMaxBufferLines = atoi(arg);
1674 /* *************************************************************************
1675 * log-messages (0|1)
1676 * *************************************************************************/
1677 case hash_log_messages :
1678 g_bLogMessages = atoi(arg);
1681 /* *************************************************************************
1682 * show-on-task-bar (0|1)
1683 * *************************************************************************/
1684 case hash_show_on_task_bar :
1685 g_bShowOnTaskBar = atoi(arg);
1688 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1691 /* *************************************************************************
1692 * Warnings about unsupported features
1693 * *************************************************************************/
1695 case hash_deny_access:
1696 #endif /* ndef FEATURE_ACL */
1697 #ifndef FEATURE_CGI_EDIT_ACTIONS
1698 case hash_enable_edit_actions:
1699 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1700 #ifndef FEATURE_TOGGLE
1701 case hash_enable_remote_toggle:
1702 #endif /* ndef FEATURE_TOGGLE */
1704 case hash_permit_access:
1705 #endif /* ndef FEATURE_ACL */
1706 #ifndef FEATURE_TOGGLE
1708 #endif /* ndef FEATURE_TOGGLE */
1709 #ifndef FEATURE_TRUST
1710 case hash_trustfile :
1711 case hash_trust_info_url :
1712 #endif /* ndef FEATURE_TRUST */
1714 #ifndef _WIN_CONSOLE
1715 case hash_hide_console :
1716 #endif /* ndef _WIN_CONSOLE */
1718 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1719 case hash_activity_animation :
1720 case hash_close_button_minimizes :
1721 case hash_log_buffer_size :
1722 case hash_log_font_name :
1723 case hash_log_font_size :
1724 case hash_log_highlight_messages :
1725 case hash_log_max_lines :
1726 case hash_log_messages :
1727 case hash_show_on_task_bar :
1728 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1729 /* These warnings are annoying - so hide them. -- Jon */
1730 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1733 /* *************************************************************************/
1735 /* *************************************************************************/
1737 * I decided that I liked this better as a warning than an
1738 * error. To change back to an error, just change log level
1739 * to LOG_LEVEL_FATAL.
1741 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1742 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1743 string_append(&config->proxy_args,
1744 " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1747 /* *************************************************************************/
1748 } /* end switch( hash_string(cmd) ) */
1750 /* Save the argument for the show-status page. */
1751 savearg(cmd, arg, config);
1753 } /* end while ( read_config_line(...) ) */
1757 set_debug_level(config->debug);
1759 freez(config->logfile);
1763 if (NULL != logfile)
1765 config->logfile = logfile;
1766 init_error_log(Argv[0], config->logfile);
1774 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1775 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1777 if (config->multi_threaded)
1779 set_keep_alive_timeout(keep_alive_timeout);
1784 * While we could use keep-alive without multiple threads
1785 * if we didn't bother with enforcing the connection timeout,
1786 * that might make Tor users sad, even though they shouldn't
1787 * enable the single-threaded option anyway.
1789 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1790 log_error(LOG_LEVEL_ERROR,
1791 "Config option single-threaded disables connection keep-alive.");
1796 if (NULL == config->proxy_args)
1798 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1801 if (config->actions_file[0])
1803 add_loader(load_action_files, config);
1806 if (config->re_filterfile[0])
1808 add_loader(load_re_filterfiles, config);
1811 #ifdef FEATURE_TRUST
1812 if (config->trustfile)
1814 add_loader(load_trustfile, config);
1816 #endif /* def FEATURE_TRUST */
1818 if ( NULL == config->haddr )
1820 config->haddr = strdup( HADDR_DEFAULT );
1823 if ( NULL != config->haddr )
1825 if (NULL != (p = strchr(config->haddr, ':')))
1830 config->hport = atoi(p);
1834 if (config->hport <= 0)
1837 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1838 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1840 if (*config->haddr == '\0')
1843 * Only the port specified. We stored it in config->hport
1844 * and don't need its text representation anymore.
1846 freez(config->haddr);
1851 * Want to run all the loaders once now.
1853 * Need to set up a fake csp, so they can get to the config.
1855 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1856 fake_csp->config = config;
1858 if (run_loader(fake_csp))
1861 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1862 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1866 /* FIXME: this is a kludge for win32 */
1867 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1869 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1870 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1871 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1873 #ifdef FEATURE_TRUST
1874 g_trustfile = config->trustfile;
1875 #endif /* def FEATURE_TRUST */
1878 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1879 /* FIXME: end kludge */
1882 config->need_bind = 1;
1884 if (current_configfile)
1886 struct configuration_spec * oldcfg = (struct configuration_spec *)
1887 current_configfile->f;
1889 * Check if config->haddr,hport == oldcfg->haddr,hport
1891 * The following could be written more compactly as a single,
1892 * (unreadably long) if statement.
1894 config->need_bind = 0;
1895 if (config->hport != oldcfg->hport)
1897 config->need_bind = 1;
1899 else if (config->haddr == NULL)
1901 if (oldcfg->haddr != NULL)
1903 config->need_bind = 1;
1906 else if (oldcfg->haddr == NULL)
1908 config->need_bind = 1;
1910 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1912 config->need_bind = 1;
1915 current_configfile->unloader = unload_configfile;
1918 fs->next = files->next;
1921 current_configfile = fs;
1927 /*********************************************************************
1929 * Function : savearg
1931 * Description : Called from `load_config'. It saves each non-empty
1932 * and non-comment line from config into
1933 * config->proxy_args. This is used to create the
1934 * show-proxy-args page. On error, frees
1935 * config->proxy_args and sets it to NULL
1938 * 1 : command = config setting that was found
1939 * 2 : argument = the setting's argument (if any)
1940 * 3 : config = Configuration to save into.
1944 *********************************************************************/
1945 static void savearg(char *command, char *argument, struct configuration_spec * config)
1954 * Add config option name embedded in
1955 * link to its section in the user-manual
1957 buf = strdup("\n<a href=\"");
1958 if (!strncmpic(config->usermanual, "file://", 7) ||
1959 !strncmpic(config->usermanual, "http", 4))
1961 string_append(&buf, config->usermanual);
1965 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1967 string_append(&buf, CONFIG_HELP_PREFIX);
1968 string_join (&buf, string_toupper(command));
1969 string_append(&buf, "\">");
1970 string_append(&buf, command);
1971 string_append(&buf, "</a> ");
1975 freez(config->proxy_args);
1979 if ( (NULL != argument) && ('\0' != *argument) )
1981 s = html_encode(argument);
1985 freez(config->proxy_args);
1989 if (strncmpic(argument, "http://", 7) == 0)
1991 string_append(&buf, "<a href=\"");
1992 string_append(&buf, s);
1993 string_append(&buf, "\">");
1994 string_join (&buf, s);
1995 string_append(&buf, "</a>");
1999 string_join (&buf, s);
2003 string_append(&buf, "<br>");
2004 string_join(&config->proxy_args, buf);