1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.99 2009/05/10 10:12:30 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.99 2009/05/10 10:12:30 fabiankeil
39 * Initial keep-alive support for the client socket.
40 * Temporarily disable the server-side-only keep-alive code.
42 * Revision 1.98 2009/04/24 15:29:43 fabiankeil
43 * Allow to limit the number of of client connections.
45 * Revision 1.97 2009/04/17 11:45:19 fabiankeil
46 * Replace HAVE_GETADDRINFO and HAVE_GETNAMEINFO macros
47 * with HAVE_RFC2553 macro. Original patch by Petr Pisar.
49 * Revision 1.96 2009/04/17 11:38:28 fabiankeil
50 * Add and use parse_forwarder_address() to reduce code duplication.
52 * Revision 1.95 2009/04/17 11:34:34 fabiankeil
53 * Style cosmetics for the IPv6 code.
55 * Revision 1.94 2009/04/17 11:27:49 fabiankeil
56 * Petr Pisar's privoxy-3.0.12-ipv6-3.diff.
58 * Revision 1.93 2009/03/18 21:46:26 fabiankeil
59 * Revert the last commit as there's a better way.
61 * Revision 1.92 2009/03/18 20:43:19 fabiankeil
62 * Don't enable LOG_LEVEL_INFO by default and don't apply the user's
63 * debug settings until the logfile has been opened (if there is one).
64 * Patch submitted by Roland in #2624120.
66 * Revision 1.91 2009/03/09 17:29:08 fabiankeil
67 * As of r1.88, the show-status page can use a single line for
68 * warnings about ignored directives and the names of the ignored
69 * directives themselves. Reminded by Lee, finally closes #1856559.
71 * Revision 1.90 2009/03/07 17:58:02 fabiankeil
72 * Fix two mingw32-only buffer overflows. Note that triggering
73 * them requires control over the configuration file in which
74 * case all bets are off anyway.
76 * Revision 1.89 2009/03/01 18:46:33 fabiankeil
77 * - Help clang understand that we aren't
78 * dereferencing NULL pointers here.
79 * - Some style fixes in the modified region.
81 * Revision 1.88 2009/02/28 10:57:10 fabiankeil
82 * Gimme a break or two. Don't let the show-status page
83 * link to the website documentation for the user-manual
86 * Revision 1.87 2009/02/15 07:56:13 fabiankeil
87 * Increase default socket timeout to 300 seconds.
89 * Revision 1.86 2009/02/08 19:18:57 fabiankeil
90 * Now that we have the match-all.action file, the other action
91 * files changed their position in config->actions_file[] back
92 * to the way it was before standard.action got removed and the
93 * changes from revision 1.84 have to be reverted.
95 * Revision 1.85 2009/01/22 12:06:26 fabiankeil
96 * Don't keep connections alive when running single-threaded.
98 * Revision 1.84 2009/01/14 16:14:36 fabiankeil
99 * Due to the standard.action file removal, the other action
100 * files changed their position in config->actions_file[].
101 * Update mingw32 kludge accordingly.
103 * Revision 1.83 2008/12/20 14:53:55 fabiankeil
104 * Add config option socket-timeout to control the time
105 * Privoxy waits for data to arrive on a socket. Useful
106 * in case of stale ssh tunnels or when fuzz-testing.
108 * Revision 1.82 2008/11/16 12:43:49 fabiankeil
109 * Turn keep-alive support into a runtime feature
110 * that is disabled by setting keep-alive-timeout
111 * to a negative value.
113 * Revision 1.81 2008/11/13 09:08:42 fabiankeil
114 * Add new config option: keep-alive-timeout.
116 * Revision 1.80 2008/08/31 15:59:03 fabiankeil
117 * There's no reason to let remote toggling support depend
118 * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
120 * Revision 1.79 2008/08/30 12:03:07 fabiankeil
121 * Remove FEATURE_COOKIE_JAR.
123 * Revision 1.78 2008/08/02 08:23:22 fabiankeil
124 * If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
125 * disabled, log a message that blocks will always be enforced
126 * instead of complaining about an unrecognized directive.
127 * Reported by Pietro Leone.
129 * Revision 1.77 2008/05/26 16:13:22 fabiankeil
130 * Reuse directive_hash and don't hash the same directive twice.
132 * Revision 1.76 2008/05/10 09:03:16 fabiankeil
133 * - Merge three string_append() calls.
134 * - Remove useless assertion.
136 * Revision 1.75 2008/03/30 14:52:05 fabiankeil
137 * Rename load_actions_file() and load_re_filterfile()
138 * as they load multiple files "now".
140 * Revision 1.74 2008/03/26 18:07:07 fabiankeil
141 * Add hostname directive. Closes PR#1918189.
143 * Revision 1.73 2008/02/16 16:54:51 fabiankeil
146 * Revision 1.72 2008/02/03 13:46:15 fabiankeil
147 * Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
149 * Revision 1.71 2007/12/23 15:24:56 fabiankeil
150 * Reword "unrecognized directive" warning, use better
151 * mark up and add a <br>. Fixes parts of #1856559.
153 * Revision 1.70 2007/12/15 14:24:05 fabiankeil
154 * Plug memory leak if listen-address only specifies the port.
156 * Revision 1.69 2007/10/27 13:02:27 fabiankeil
157 * Relocate daemon-mode-related log messages to make sure
158 * they aren't shown again in case of configuration reloads.
160 * Revision 1.68 2007/10/19 16:32:34 fabiankeil
161 * Plug memory leak introduced with my last commit.
163 * Revision 1.67 2007/10/14 14:12:41 fabiankeil
164 * When in daemon mode, close stderr after the configuration file has been
165 * parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
167 * Revision 1.66 2007/08/05 14:02:09 fabiankeil
168 * #1763173 from Stefan Huehner: declare unload_configfile() static.
170 * Revision 1.65 2007/07/21 11:51:36 fabiankeil
171 * As Hal noticed, checking dispatch_cgi() as the last cruncher
172 * looks like a bug if CGI requests are blocked unintentionally,
173 * so don't do it unless the user enabled the new config option
174 * "allow-cgi-request-crunching".
176 * Revision 1.64 2007/05/21 10:44:08 fabiankeil
177 * - Use strlcpy() instead of strcpy().
178 * - Stop treating actions files special. Expect a complete file name
179 * (with or without path) like it's done for the rest of the files.
181 * - Remove an unnecessary temporary memory allocation.
182 * - Don't log anything to the console when running as
183 * daemon and no errors occurred.
185 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
186 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
188 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
189 * New config option: enforce-blocks.
191 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
192 * - Mention other reasons why acl directive loading might have failed.
193 * - Don't log the acl source if the acl destination is to blame.
195 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
196 * Add new config option "templdir" to
197 * change the templates directory.
199 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
200 * Added config option accept-intercepted-requests
201 * and disabled it by default.
203 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
204 * Fix gcc43 compiler warnings.
206 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
207 * Add config option "split-large-forms"
208 * to work around the browser bug reported
211 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
212 * Move the <br> in the generated HTML for the config
213 * options from the beginning of the string to its end.
214 * Keeps the white space in balance.
216 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
217 * Fix memory leak in case of config file reloads.
219 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
220 * Modified kludge for win32 to make ming32 menu
221 * "Options/Edit Filters" (sort of) work again.
222 * Same limitations as for the action files apply.
225 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
226 * Incorporate modified version of Roland Rosenfeld's patch to
227 * optionally access the user-manual via Privoxy. Closes patch 679075.
229 * Formatting changed to Privoxy style, added call to
230 * cgi_error_no_template if the requested file doesn't
231 * exist and modified check whether or not Privoxy itself
232 * should serve the manual. Should work cross-platform now.
234 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
235 * Added config option enable-remote-http-toggle
236 * to specify if Privoxy should recognize special
237 * headers (currently only X-Filter) to change its
238 * behaviour. Disabled by default.
240 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
241 * Make number of retries in case of forwarded-connect problems
242 * a config file option (forwarded-connect-retries) and use 0 as
245 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
246 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
247 * with what was really the latest development (the v_3_0_branch branch)
249 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
250 * Don't forget to malloc space for the null terminator...
252 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
253 * Multiple filter file support
255 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
256 * Closed two memory leaks; hopefully the last remaining ones
257 * (in the main execution paths, anyway).
259 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
260 * Addressed bug #719435
261 * - Extraneous filterfile directives now logged as errors
262 * - This and unrecnonised directives now really obvious on status page
264 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
265 * Cosmetic: Renamed cryptic variable
267 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
268 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
270 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
271 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
273 * Revision 1.48 2002/05/14 21:30:38 oes
274 * savearg now uses own linking code instead of (now special-cased) add_help_link
276 * Revision 1.47 2002/05/12 21:36:29 jongfoster
277 * Correcting function comments
279 * Revision 1.46 2002/04/26 12:55:14 oes
280 * - New option "user-manual", defaults to our site
281 * via project.h #define
282 * - savearg now embeds option names in help links
284 * Revision 1.45 2002/04/24 02:11:54 oes
285 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
287 * Revision 1.44 2002/04/08 20:37:13 swa
290 * Revision 1.43 2002/04/08 20:36:50 swa
293 * Revision 1.42 2002/04/05 15:50:15 oes
294 * fix for invalid HTML proxy_args
296 * Revision 1.41 2002/03/31 17:19:00 jongfoster
297 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
299 * Revision 1.40 2002/03/26 22:29:55 swa
300 * we have a new homepage!
302 * Revision 1.39 2002/03/24 13:25:43 swa
303 * name change related issues
305 * Revision 1.38 2002/03/24 13:05:48 jongfoster
306 * Renaming re_filterfile to filterfile
308 * Revision 1.37 2002/03/16 23:54:06 jongfoster
309 * Adding graceful termination feature, to help look for memory leaks.
310 * If you enable this (which, by design, has to be done by hand
311 * editing config.h) and then go to http://i.j.b/die, then the program
312 * will exit cleanly after the *next* request. It should free all the
313 * memory that was used.
315 * Revision 1.36 2002/03/13 00:27:05 jongfoster
318 * Revision 1.35 2002/03/07 03:52:44 oes
319 * Set logging to tty for --no-daemon mode
321 * Revision 1.34 2002/03/06 23:14:35 jongfoster
322 * Trivial cosmetic changes to make function comments easier to find.
324 * Revision 1.33 2002/03/05 04:52:42 oes
325 * Deleted non-errlog debugging code
327 * Revision 1.32 2002/03/04 18:24:53 oes
328 * Re-enabled output of unknown config directive hash
330 * Revision 1.31 2002/03/03 15:07:20 oes
331 * Re-enabled automatic config reloading
333 * Revision 1.30 2002/01/22 23:31:43 jongfoster
334 * Replacing strsav() with string_append()
336 * Revision 1.29 2002/01/17 21:02:30 jongfoster
337 * Moving all our URL and URL pattern parsing code to urlmatch.c.
339 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
341 * Revision 1.28 2001/12/30 14:07:32 steudten
342 * - Add signal handling (unix)
343 * - Add SIGHUP handler (unix)
344 * - Add creation of pidfile (unix)
345 * - Add action 'top' in rc file (RH)
346 * - Add entry 'SIGNALS' to manpage
347 * - Add exit message to logfile (unix)
349 * Revision 1.27 2001/11/07 00:02:13 steudten
350 * Add line number in error output for lineparsing for
351 * actionsfile and configfile.
352 * Special handling for CLF added.
354 * Revision 1.26 2001/11/05 21:41:43 steudten
355 * Add changes to be a real daemon just for unix os.
356 * (change cwd to /, detach from controlling tty, set
357 * process group and session leader to the own process.
359 * Add some fatal-error log message for failed malloc().
360 * Add '-d' if compiled with 'configure --with-debug' to
361 * enable debug output.
363 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
364 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
365 * threads to call select() simultaneously. So, it's time to do a real, live,
366 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
367 * (native). Both versions will work, but using __OS2__ offers multi-threading.
369 * Revision 1.24 2001/10/23 21:40:30 jongfoster
370 * Added support for enable-edit-actions and enable-remote-toggle config
373 * Revision 1.23 2001/10/07 15:36:00 oes
374 * Introduced new config option "buffer-limit"
376 * Revision 1.22 2001/09/22 16:36:59 jongfoster
377 * Removing unused parameter fs from read_config_line()
379 * Revision 1.21 2001/09/16 17:10:43 jongfoster
380 * Moving function savearg() here, since it was the only thing left in
383 * Revision 1.20 2001/07/30 22:08:36 jongfoster
384 * Tidying up #defines:
385 * - All feature #defines are now of the form FEATURE_xxx
386 * - Permanently turned off WIN_GUI_EDIT
387 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
389 * Revision 1.19 2001/07/15 17:45:16 jongfoster
390 * Removing some unused #includes
392 * Revision 1.18 2001/07/13 14:01:14 oes
393 * - Removed all #ifdef PCRS
394 * - Removed vim-settings
396 * Revision 1.17 2001/06/29 13:31:03 oes
397 * - Improved comments
398 * - Fixed (actionsfile) and sorted hashes
399 * - Introduced admin_address and proxy-info-url
400 * as config parameters
401 * - Renamed config->proxy_args_invocation (which didn't have
402 * the invocation but the options!) to config->proxy_args
403 * - Various adaptions
404 * - Removed logentry from cancelled commit
406 * Revision 1.16 2001/06/09 10:55:28 jongfoster
407 * Changing BUFSIZ ==> BUFFER_SIZE
409 * Revision 1.15 2001/06/07 23:13:40 jongfoster
410 * Merging ACL and forward files into config file.
411 * Cosmetic: Sorting config file options alphabetically.
412 * Cosmetic: Adding brief syntax comments to config file options.
414 * Revision 1.14 2001/06/07 14:46:25 joergs
415 * Missing make_path() added for re_filterfile.
417 * Revision 1.13 2001/06/05 22:33:54 jongfoster
419 * Fixed minor memory leak.
420 * Also now uses make_path to prepend the pathnames.
422 * Revision 1.12 2001/06/05 20:04:09 jongfoster
423 * Now uses _snprintf() in place of snprintf() under Win32.
425 * Revision 1.11 2001/06/04 18:31:58 swa
426 * files are now prefixed with either `confdir' or `logdir'.
427 * `make redhat-dist' replaces both entries confdir and logdir
430 * Revision 1.10 2001/06/03 19:11:54 oes
431 * introduced confdir option
433 * Revision 1.9 2001/06/01 20:06:24 jongfoster
434 * Removed support for "tinygif" option - moved to actions file.
436 * Revision 1.8 2001/05/31 21:27:13 jongfoster
437 * Removed many options from the config file and into the
438 * "actions" file: add_forwarded, suppress_vanilla_wafer,
439 * wafer, add_header, user_agent, referer, from
440 * Also globally replaced "permission" with "action".
442 * Revision 1.7 2001/05/29 09:50:24 jongfoster
443 * Unified blocklist/imagelist/permissionslist.
444 * File format is still under discussion, but the internal changes
447 * Also modified interceptor behaviour:
448 * - We now intercept all URLs beginning with one of the following
449 * prefixes (and *only* these prefixes):
451 * * http://ijbswa.sf.net/config/
452 * * http://ijbswa.sourceforge.net/config/
453 * - New interceptors "home page" - go to http://i.j.b/ to see it.
454 * - Internal changes so that intercepted and fast redirect pages
455 * are not replaced with an image.
456 * - Interceptors now have the option to send a binary page direct
457 * to the client. (i.e. ijb-send-banner uses this)
458 * - Implemented show-url-info interceptor. (Which is why I needed
459 * the above interceptors changes - a typical URL is
460 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
461 * The previous mechanism would not have intercepted that, and
462 * if it had been intercepted then it then it would have replaced
465 * Revision 1.6 2001/05/26 00:28:36 jongfoster
466 * Automatic reloading of config file.
467 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
468 * Most of the global variables have been moved to a new
469 * struct configuration_spec, accessed through csp->config->globalname
470 * Most of the globals remaining are used by the Win32 GUI.
472 * Revision 1.5 2001/05/25 22:34:30 jongfoster
475 * Revision 1.4 2001/05/22 18:46:04 oes
477 * - Enabled filtering banners by size rather than URL
478 * by adding patterns that replace all standard banner
479 * sizes with the "Junkbuster" gif to the re_filterfile
481 * - Enabled filtering WebBugs by providing a pattern
482 * which kills all 1x1 images
484 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
485 * which is selected by the (nonstandard and therefore
486 * capital) letter 'U' in the option string.
487 * It causes the quantifiers to be ungreedy by default.
488 * Appending a ? turns back to greedy (!).
490 * - Added a new interceptor ijb-send-banner, which
491 * sends back the "Junkbuster" gif. Without imagelist or
492 * MSIE detection support, or if tinygif = 1, or the
493 * URL isn't recognized as an imageurl, a lame HTML
494 * explanation is sent instead.
496 * - Added new feature, which permits blocking remote
497 * script redirects and firing back a local redirect
499 * The feature is conditionally compiled, i.e. it
500 * can be disabled with --disable-fast-redirects,
501 * plus it must be activated by a "fast-redirects"
502 * line in the config file, has its own log level
503 * and of course wants to be displayed by show-proxy-args
504 * Note: Boy, all the #ifdefs in 1001 locations and
505 * all the fumbling with configure.in and acconfig.h
506 * were *way* more work than the feature itself :-(
508 * - Because a generic redirect template was needed for
509 * this, tinygif = 3 now uses the same.
511 * - Moved GIFs, and other static HTTP response templates
516 * - Removed some >400 CRs again (Jon, you really worked
519 * Revision 1.3 2001/05/20 01:21:20 jongfoster
520 * Version 2.9.4 checkin.
521 * - Merged popupfile and cookiefile, and added control over PCRS
522 * filtering, in new "permissionsfile".
523 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
524 * file error you now get a message box (in the Win32 GUI) rather
525 * than the program exiting with no explanation.
526 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
528 * - Removed tabs from "config"
529 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
530 * - Bumped up version number.
532 * Revision 1.2 2001/05/17 23:01:01 oes
533 * - Cleaned CRLF's from the sources and related files
535 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
536 * Initial import of version 2.9.3 source tree
539 *********************************************************************/
545 #include <sys/types.h>
559 # include <windows.h>
562 # ifndef _WIN_CONSOLE
564 # endif /* ndef _WIN_CONSOLE */
566 #else /* ifndef _WIN32 */
570 # include <sys/wait.h>
572 # include <sys/time.h>
573 # include <sys/stat.h>
583 #include "miscutil.h"
587 #include "urlmatch.h"
591 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
594 * Fix a problem with Solaris. There should be no effect on other
596 * Solaris's isspace() is a macro which uses it's argument directly
597 * as an array index. Therefore we need to make sure that high-bit
598 * characters generate +ve values, and ideally we also want to make
599 * the argument match the declared parameter type of "int".
601 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
602 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
604 #ifdef FEATURE_TOGGLE
605 /* Privoxy is enabled by default. */
606 int global_toggle_state = 1;
607 #endif /* def FEATURE_TOGGLE */
609 /* The filename of the configfile */
610 const char *configfile = NULL;
613 * CGI functions will later need access to the invocation args,
614 * so we will make argc and argv global.
617 const char **Argv = NULL;
619 static struct file_list *current_configfile = NULL;
623 * This takes the "cryptic" hash of each keyword and aliases them to
624 * something a little more readable. This also makes changing the
625 * hash values easier if they should change or the hash algorthm changes.
626 * Use the included "hash" program to find out what the hash will be
627 * for any string supplied on the command line. (Or just put it in the
628 * config file and read the number from the error message in the log).
630 * Please keep this list sorted alphabetically (but with the Windows
631 * console and GUI specific options last).
634 #define hash_actions_file 1196306641ul /* "actionsfile" */
635 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
636 #define hash_admin_address 4112573064ul /* "admin-address" */
637 #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */
638 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
639 #define hash_confdir 1978389ul /* "confdir" */
640 #define hash_connection_sharing 1348841265ul /* "connection-sharing" */
641 #define hash_debug 78263ul /* "debug" */
642 #define hash_deny_access 1227333715ul /* "deny-access" */
643 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
644 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
645 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
646 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
647 #define hash_filterfile 250887266ul /* "filterfile" */
648 #define hash_forward 2029845ul /* "forward" */
649 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
650 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
651 #define hash_forward_socks5 3963965522ul /* "forward-socks5" */
652 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
653 #define hash_hostname 10308071ul /* "hostname" */
654 #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */
655 #define hash_listen_address 1255650842ul /* "listen-address" */
656 #define hash_logdir 422889ul /* "logdir" */
657 #define hash_logfile 2114766ul /* "logfile" */
658 #define hash_max_client_connections 3595884446ul /* "max-client-connections" */
659 #define hash_permit_access 3587953268ul /* "permit-access" */
660 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
661 #define hash_single_threaded 4250084780ul /* "single-threaded" */
662 #define hash_socket_timeout 1809001761ul /* "socket-timeout" */
663 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
664 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
665 #define hash_templdir 11067889ul /* "templdir" */
666 #define hash_toggle 447966ul /* "toggle" */
667 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
668 #define hash_trustfile 56494766ul /* "trustfile" */
669 #define hash_usermanual 1416668518ul /* "user-manual" */
670 #define hash_activity_animation 1817904738ul /* "activity-animation" */
671 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
672 #define hash_hide_console 2048809870ul /* "hide-console" */
673 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
674 #define hash_log_font_name 2866730124ul /* "log-font-name" */
675 #define hash_log_font_size 2866731014ul /* "log-font-size" */
676 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
677 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
678 #define hash_log_messages 2291744899ul /* "log-messages" */
679 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
682 static void savearg(char *command, char *argument, struct configuration_spec * config);
684 /*********************************************************************
686 * Function : unload_configfile
688 * Description : Free the config structure and all components.
691 * 1 : data: struct configuration_spec to unload
695 *********************************************************************/
696 static void unload_configfile (void * data)
698 struct configuration_spec * config = (struct configuration_spec *)data;
699 struct forward_spec *cur_fwd = config->forward;
703 struct access_control_list *cur_acl = config->acl;
705 while (cur_acl != NULL)
707 struct access_control_list * next_acl = cur_acl->next;
712 #endif /* def FEATURE_ACL */
714 while (cur_fwd != NULL)
716 struct forward_spec * next_fwd = cur_fwd->next;
717 free_url_spec(cur_fwd->url);
719 freez(cur_fwd->gateway_host);
720 freez(cur_fwd->forward_host);
724 config->forward = NULL;
726 freez(config->confdir);
727 freez(config->logdir);
728 freez(config->templdir);
729 freez(config->hostname);
731 freez(config->haddr);
732 freez(config->logfile);
734 for (i = 0; i < MAX_AF_FILES; i++)
736 freez(config->actions_file_short[i]);
737 freez(config->actions_file[i]);
738 freez(config->re_filterfile_short[i]);
739 freez(config->re_filterfile[i]);
742 freez(config->admin_address);
743 freez(config->proxy_info_url);
744 freez(config->proxy_args);
745 freez(config->usermanual);
748 freez(config->trustfile);
749 list_remove_all(config->trust_info);
750 #endif /* def FEATURE_TRUST */
752 for (i = 0; i < MAX_AF_FILES; i++)
754 freez(config->re_filterfile[i]);
761 #ifdef FEATURE_GRACEFUL_TERMINATION
762 /*********************************************************************
764 * Function : unload_current_config_file
766 * Description : Unloads current config file - reset to state at
767 * beginning of program.
773 *********************************************************************/
774 void unload_current_config_file(void)
776 if (current_configfile)
778 current_configfile->unloader = unload_configfile;
779 current_configfile = NULL;
785 /*********************************************************************
787 * Function : load_config
789 * Description : Load the config file and all parameters.
791 * XXX: more than thousand lines long
792 * and thus in serious need of refactoring.
796 * Returns : The configuration_spec, or NULL on error.
798 *********************************************************************/
799 struct configuration_spec * load_config(void)
801 char buf[BUFFER_SIZE];
803 FILE *configfp = NULL;
804 struct configuration_spec * config = NULL;
805 struct client_state * fake_csp;
806 struct file_list *fs;
807 unsigned long linenum = 0;
809 char *logfile = NULL;
811 if (!check_file_changed(current_configfile, configfile, &fs))
813 /* No need to load */
814 return ((struct configuration_spec *)current_configfile->f);
818 log_error(LOG_LEVEL_FATAL,
819 "can't check configuration file '%s': %E", configfile);
823 if (NULL != current_configfile)
825 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
828 #ifdef FEATURE_TOGGLE
829 global_toggle_state = 1;
830 #endif /* def FEATURE_TOGGLE */
832 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
838 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
843 * This is backwards from how it's usually done.
844 * Following the usual pattern, "fs" would be stored in a member
845 * variable in "csp", and then we'd access "config" from "fs->f",
846 * using a cast. However, "config" is used so often that a
847 * cast each time would be very ugly, and the extra indirection
848 * would waste CPU cycles. Therefore we store "config" in
849 * "csp->config", and "fs" in "csp->config->config_file_list".
851 config->config_file_list = fs;
856 config->multi_threaded = 1;
857 config->buffer_limit = 4096 * 1024;
858 config->usermanual = strdup(USER_MANUAL_URL);
859 config->proxy_args = strdup("");
860 config->forwarded_connect_retries = 0;
861 config->max_client_connections = 0;
862 config->socket_timeout = 300; /* XXX: Should be a macro. */
863 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
864 config->keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
865 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
866 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
868 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
869 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
870 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
872 configfp = fopen(configfile, "r");
873 if (NULL == configfp)
875 log_error(LOG_LEVEL_FATAL,
876 "can't open configuration file '%s': %E", configfile);
877 /* Never get here - LOG_LEVEL_FATAL causes program exit */
880 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
882 char cmd[BUFFER_SIZE];
883 char arg[BUFFER_SIZE];
884 char tmp[BUFFER_SIZE];
886 struct access_control_list *cur_acl;
887 #endif /* def FEATURE_ACL */
888 struct forward_spec *cur_fwd;
891 unsigned long directive_hash;
893 strlcpy(tmp, buf, sizeof(tmp));
895 /* Copy command (i.e. up to space or tab) into cmd */
898 while (*p && (*p != ' ') && (*p != '\t'))
904 /* Skip over the whitespace in buf */
905 while (*p && ((*p == ' ') || (*p == '\t')))
910 /* Copy the argument into arg */
911 strlcpy(arg, p, sizeof(arg));
913 /* Should never happen, but check this anyway */
919 /* Make sure the command field is lower case */
920 for (p = cmd; *p; p++)
924 *p = (char)ijb_tolower(*p);
928 directive_hash = hash_string(cmd);
929 switch (directive_hash)
931 /* *************************************************************************
932 * actionsfile actions-file-name
933 * In confdir by default
934 * *************************************************************************/
935 case hash_actions_file :
937 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
942 if (i >= MAX_AF_FILES)
944 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
945 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
948 config->actions_file_short[i] = strdup(arg);
949 config->actions_file[i] = make_path(config->confdir, arg);
952 /* *************************************************************************
953 * accept-intercepted-requests
954 * *************************************************************************/
955 case hash_accept_intercepted_requests:
956 if ((*arg != '\0') && (0 != atoi(arg)))
958 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
962 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
966 /* *************************************************************************
967 * admin-address email-address
968 * *************************************************************************/
969 case hash_admin_address :
970 freez(config->admin_address);
971 config->admin_address = strdup(arg);
974 /* *************************************************************************
975 * allow-cgi-request-crunching
976 * *************************************************************************/
977 case hash_allow_cgi_request_crunching:
978 if ((*arg != '\0') && (0 != atoi(arg)))
980 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
984 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
988 /* *************************************************************************
990 * *************************************************************************/
991 case hash_buffer_limit :
992 config->buffer_limit = (size_t)(1024 * atoi(arg));
995 /* *************************************************************************
996 * confdir directory-name
997 * *************************************************************************/
999 freez(config->confdir);
1000 config->confdir = make_path( NULL, arg);
1003 /* *************************************************************************
1004 * connection-sharing (0|1)
1005 * *************************************************************************/
1006 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1007 case hash_connection_sharing :
1008 if ((*arg != '\0') && (0 != atoi(arg)))
1010 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_SHARING;
1014 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
1019 /* *************************************************************************
1021 * Specifies debug level, multiple values are ORed together.
1022 * *************************************************************************/
1024 config->debug |= atoi(arg);
1027 /* *************************************************************************
1028 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1029 * *************************************************************************/
1031 case hash_deny_access:
1032 strlcpy(tmp, arg, sizeof(tmp));
1033 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1035 if ((vec_count != 1) && (vec_count != 2))
1037 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1038 "deny-access directive in configuration file.");
1039 string_append(&config->proxy_args,
1040 "<br>\nWARNING: Wrong number of parameters for "
1041 "deny-access directive in configuration file.<br><br>\n");
1045 /* allocate a new node */
1046 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1048 if (cur_acl == NULL)
1050 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1051 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1054 cur_acl->action = ACL_DENY;
1056 if (acl_addr(vec[0], cur_acl->src) < 0)
1058 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1059 "for deny-access directive in configuration file: \"%s\"", vec[0]);
1060 string_append(&config->proxy_args,
1061 "<br>\nWARNING: Invalid source address, port or netmask "
1062 "for deny-access directive in configuration file: \"");
1063 string_append(&config->proxy_args,
1065 string_append(&config->proxy_args,
1072 if (acl_addr(vec[1], cur_acl->dst) < 0)
1074 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1075 "for deny-access directive in configuration file: \"%s\"", vec[1]);
1076 string_append(&config->proxy_args,
1077 "<br>\nWARNING: Invalid destination address, port or netmask "
1078 "for deny-access directive in configuration file: \"");
1079 string_append(&config->proxy_args,
1081 string_append(&config->proxy_args,
1090 cur_acl->wildcard_dst = 1;
1092 #endif /* def HAVE_RFC2553 */
1095 * Add it to the list. Note we reverse the list to get the
1096 * behaviour the user expects. With both the ACL and
1097 * actions file, the last match wins. However, the internal
1098 * implementations are different: The actions file is stored
1099 * in the same order as the file, and scanned completely.
1100 * With the ACL, we reverse the order as we load it, then
1101 * when we scan it we stop as soon as we get a match.
1103 cur_acl->next = config->acl;
1104 config->acl = cur_acl;
1107 #endif /* def FEATURE_ACL */
1109 /* *************************************************************************
1110 * enable-edit-actions 0|1
1111 * *************************************************************************/
1112 #ifdef FEATURE_CGI_EDIT_ACTIONS
1113 case hash_enable_edit_actions:
1114 if ((*arg != '\0') && (0 != atoi(arg)))
1116 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1120 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1123 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1125 /* *************************************************************************
1126 * enable-remote-toggle 0|1
1127 * *************************************************************************/
1128 #ifdef FEATURE_TOGGLE
1129 case hash_enable_remote_toggle:
1130 if ((*arg != '\0') && (0 != atoi(arg)))
1132 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1136 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1139 #endif /* def FEATURE_TOGGLE */
1141 /* *************************************************************************
1142 * enable-remote-http-toggle 0|1
1143 * *************************************************************************/
1144 case hash_enable_remote_http_toggle:
1145 if ((*arg != '\0') && (0 != atoi(arg)))
1147 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1151 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1155 /* *************************************************************************
1156 * enforce-blocks 0|1
1157 * *************************************************************************/
1158 case hash_enforce_blocks:
1159 #ifdef FEATURE_FORCE_LOAD
1160 if ((*arg != '\0') && (0 != atoi(arg)))
1162 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1166 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1169 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1170 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1171 #endif /* def FEATURE_FORCE_LOAD */
1174 /* *************************************************************************
1175 * filterfile file-name
1176 * In confdir by default.
1177 * *************************************************************************/
1178 case hash_filterfile :
1180 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1185 if (i >= MAX_AF_FILES)
1187 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1188 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1191 config->re_filterfile_short[i] = strdup(arg);
1192 config->re_filterfile[i] = make_path(config->confdir, arg);
1196 /* *************************************************************************
1197 * forward url-pattern (.|http-proxy-host[:port])
1198 * *************************************************************************/
1200 strlcpy(tmp, arg, sizeof(tmp));
1201 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1205 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1206 "directive in configuration file.");
1207 string_append(&config->proxy_args,
1208 "<br>\nWARNING: Wrong number of parameters for "
1209 "forward directive in configuration file.");
1213 /* allocate a new node */
1214 cur_fwd = zalloc(sizeof(*cur_fwd));
1215 if (cur_fwd == NULL)
1217 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1218 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1222 cur_fwd->type = SOCKS_NONE;
1224 /* Save the URL pattern */
1225 if (create_url_spec(cur_fwd->url, vec[0]))
1227 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1228 "directive in configuration file.");
1229 string_append(&config->proxy_args,
1230 "<br>\nWARNING: Bad URL specifier for "
1231 "forward directive in configuration file.");
1235 /* Parse the parent HTTP proxy host:port */
1238 if (strcmp(p, ".") != 0)
1240 cur_fwd->forward_port = 8000;
1241 parse_forwarder_address(p, &cur_fwd->forward_host,
1242 &cur_fwd->forward_port);
1246 cur_fwd->next = config->forward;
1247 config->forward = cur_fwd;
1251 /* *************************************************************************
1252 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1253 * *************************************************************************/
1254 case hash_forward_socks4:
1255 strlcpy(tmp, arg, sizeof(tmp));
1256 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1260 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1261 "forward-socks4 directive in configuration file.");
1262 string_append(&config->proxy_args,
1263 "<br>\nWARNING: Wrong number of parameters for "
1264 "forward-socks4 directive in configuration file.");
1268 /* allocate a new node */
1269 cur_fwd = zalloc(sizeof(*cur_fwd));
1270 if (cur_fwd == NULL)
1272 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1273 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1277 cur_fwd->type = SOCKS_4;
1279 /* Save the URL pattern */
1280 if (create_url_spec(cur_fwd->url, vec[0]))
1282 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1283 "directive in configuration file.");
1284 string_append(&config->proxy_args,
1285 "<br>\nWARNING: Bad URL specifier for "
1286 "forward-socks4 directive in configuration file.");
1290 /* Parse the SOCKS proxy host[:port] */
1293 /* XXX: This check looks like a bug. */
1294 if (strcmp(p, ".") != 0)
1296 cur_fwd->gateway_port = 1080;
1297 parse_forwarder_address(p, &cur_fwd->gateway_host,
1298 &cur_fwd->gateway_port);
1301 /* Parse the parent HTTP proxy host[:port] */
1304 if (strcmp(p, ".") != 0)
1306 cur_fwd->forward_port = 8000;
1307 parse_forwarder_address(p, &cur_fwd->forward_host,
1308 &cur_fwd->forward_port);
1312 cur_fwd->next = config->forward;
1313 config->forward = cur_fwd;
1317 /* *************************************************************************
1318 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1319 * *************************************************************************/
1320 case hash_forward_socks4a:
1321 case hash_forward_socks5:
1322 strlcpy(tmp, arg, sizeof(tmp));
1323 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1327 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1328 "forward-socks4a directive in configuration file.");
1329 string_append(&config->proxy_args,
1330 "<br>\nWARNING: Wrong number of parameters for "
1331 "forward-socks4a directive in configuration file.");
1335 /* allocate a new node */
1336 cur_fwd = zalloc(sizeof(*cur_fwd));
1337 if (cur_fwd == NULL)
1339 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1340 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1344 if (directive_hash == hash_forward_socks4a)
1346 cur_fwd->type = SOCKS_4A;
1350 cur_fwd->type = SOCKS_5;
1353 /* Save the URL pattern */
1354 if (create_url_spec(cur_fwd->url, vec[0]))
1356 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1357 "directive in configuration file.");
1358 string_append(&config->proxy_args,
1359 "<br>\nWARNING: Bad URL specifier for "
1360 "forward-socks4a directive in configuration file.");
1364 /* Parse the SOCKS proxy host[:port] */
1367 cur_fwd->gateway_port = 1080;
1368 parse_forwarder_address(p, &cur_fwd->gateway_host,
1369 &cur_fwd->gateway_port);
1371 /* Parse the parent HTTP proxy host[:port] */
1374 if (strcmp(p, ".") != 0)
1376 cur_fwd->forward_port = 8000;
1377 parse_forwarder_address(p, &cur_fwd->forward_host,
1378 &cur_fwd->forward_port);
1382 cur_fwd->next = config->forward;
1383 config->forward = cur_fwd;
1387 /* *************************************************************************
1388 * forwarded-connect-retries n
1389 * *************************************************************************/
1390 case hash_forwarded_connect_retries :
1391 config->forwarded_connect_retries = atoi(arg);
1394 /* *************************************************************************
1395 * hostname hostname-to-show-on-cgi-pages
1396 * *************************************************************************/
1397 case hash_hostname :
1398 freez(config->hostname);
1399 config->hostname = strdup(arg);
1400 if (NULL == config->hostname)
1402 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1406 /* *************************************************************************
1407 * keep-alive-timeout timeout
1408 * *************************************************************************/
1409 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1410 case hash_keep_alive_timeout :
1413 int timeout = atoi(arg);
1416 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1417 config->keep_alive_timeout = timeout;
1421 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1427 /* *************************************************************************
1428 * listen-address [ip][:port]
1429 * *************************************************************************/
1430 case hash_listen_address :
1431 freez(config->haddr);
1432 config->haddr = strdup(arg);
1435 /* *************************************************************************
1436 * logdir directory-name
1437 * *************************************************************************/
1439 freez(config->logdir);
1440 config->logdir = make_path(NULL, arg);
1443 /* *************************************************************************
1444 * logfile log-file-name
1445 * In logdir by default
1446 * *************************************************************************/
1450 logfile = make_path(config->logdir, arg);
1451 if (NULL == logfile)
1453 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1458 /* *************************************************************************
1459 * max-client-connections number
1460 * *************************************************************************/
1461 case hash_max_client_connections :
1464 int max_client_connections = atoi(arg);
1465 if (0 <= max_client_connections)
1467 config->max_client_connections = max_client_connections;
1472 /* *************************************************************************
1473 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1474 * *************************************************************************/
1476 case hash_permit_access:
1477 strlcpy(tmp, arg, sizeof(tmp));
1478 vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1480 if ((vec_count != 1) && (vec_count != 2))
1482 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1483 "permit-access directive in configuration file.");
1484 string_append(&config->proxy_args,
1485 "<br>\nWARNING: Wrong number of parameters for "
1486 "permit-access directive in configuration file.<br><br>\n");
1491 /* allocate a new node */
1492 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1494 if (cur_acl == NULL)
1496 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1497 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1500 cur_acl->action = ACL_PERMIT;
1502 if (acl_addr(vec[0], cur_acl->src) < 0)
1504 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1505 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1506 string_append(&config->proxy_args,
1507 "<br>\nWARNING: Invalid source address, port or netmask for "
1508 "permit-access directive in configuration file: \"");
1509 string_append(&config->proxy_args,
1511 string_append(&config->proxy_args,
1518 if (acl_addr(vec[1], cur_acl->dst) < 0)
1520 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1521 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1522 string_append(&config->proxy_args,
1523 "<br>\nWARNING: Invalid destination address, port or netmask for "
1524 "permit-access directive in configuration file: \"");
1525 string_append(&config->proxy_args,
1527 string_append(&config->proxy_args,
1536 cur_acl->wildcard_dst = 1;
1538 #endif /* def HAVE_RFC2553 */
1541 * Add it to the list. Note we reverse the list to get the
1542 * behaviour the user expects. With both the ACL and
1543 * actions file, the last match wins. However, the internal
1544 * implementations are different: The actions file is stored
1545 * in the same order as the file, and scanned completely.
1546 * With the ACL, we reverse the order as we load it, then
1547 * when we scan it we stop as soon as we get a match.
1549 cur_acl->next = config->acl;
1550 config->acl = cur_acl;
1553 #endif /* def FEATURE_ACL */
1555 /* *************************************************************************
1556 * proxy-info-url url
1557 * *************************************************************************/
1558 case hash_proxy_info_url :
1559 freez(config->proxy_info_url);
1560 config->proxy_info_url = strdup(arg);
1563 /* *************************************************************************
1565 * *************************************************************************/
1566 case hash_single_threaded :
1567 config->multi_threaded = 0;
1570 /* *************************************************************************
1571 * socket-timeout numer_of_seconds
1572 * *************************************************************************/
1573 case hash_socket_timeout :
1576 int socket_timeout = atoi(arg);
1577 if (0 < socket_timeout)
1579 config->socket_timeout = socket_timeout;
1583 log_error(LOG_LEVEL_FATAL,
1584 "Invalid socket-timeout: '%s'", arg);
1589 /* *************************************************************************
1590 * split-large-cgi-forms
1591 * *************************************************************************/
1592 case hash_split_large_cgi_forms :
1593 if ((*arg != '\0') && (0 != atoi(arg)))
1595 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1599 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1603 /* *************************************************************************
1604 * templdir directory-name
1605 * *************************************************************************/
1606 case hash_templdir :
1607 freez(config->templdir);
1608 config->templdir = make_path(NULL, arg);
1611 /* *************************************************************************
1613 * *************************************************************************/
1614 #ifdef FEATURE_TOGGLE
1616 global_toggle_state = atoi(arg);
1618 #endif /* def FEATURE_TOGGLE */
1620 /* *************************************************************************
1621 * trust-info-url url
1622 * *************************************************************************/
1623 #ifdef FEATURE_TRUST
1624 case hash_trust_info_url :
1625 enlist(config->trust_info, arg);
1627 #endif /* def FEATURE_TRUST */
1629 /* *************************************************************************
1630 * trustfile filename
1631 * (In confdir by default.)
1632 * *************************************************************************/
1633 #ifdef FEATURE_TRUST
1634 case hash_trustfile :
1635 freez(config->trustfile);
1636 config->trustfile = make_path(config->confdir, arg);
1638 #endif /* def FEATURE_TRUST */
1640 /* *************************************************************************
1642 * *************************************************************************/
1643 case hash_usermanual :
1645 * XXX: If this isn't the first config directive, the
1646 * show-status page links to the website documentation
1647 * for the directives that were already parsed. Lame.
1649 freez(config->usermanual);
1650 config->usermanual = strdup(arg);
1653 /* *************************************************************************
1654 * Win32 Console options:
1655 * *************************************************************************/
1657 /* *************************************************************************
1659 * *************************************************************************/
1661 case hash_hide_console :
1664 #endif /*def _WIN_CONSOLE*/
1667 /* *************************************************************************
1668 * Win32 GUI options:
1669 * *************************************************************************/
1671 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1672 /* *************************************************************************
1673 * activity-animation (0|1)
1674 * *************************************************************************/
1675 case hash_activity_animation :
1676 g_bShowActivityAnimation = atoi(arg);
1679 /* *************************************************************************
1680 * close-button-minimizes (0|1)
1681 * *************************************************************************/
1682 case hash_close_button_minimizes :
1683 g_bCloseHidesWindow = atoi(arg);
1686 /* *************************************************************************
1687 * log-buffer-size (0|1)
1688 * *************************************************************************/
1689 case hash_log_buffer_size :
1690 g_bLimitBufferSize = atoi(arg);
1693 /* *************************************************************************
1694 * log-font-name fontname
1695 * *************************************************************************/
1696 case hash_log_font_name :
1697 if (strlcpy(g_szFontFaceName, arg,
1698 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1700 log_error(LOG_LEVEL_FATAL,
1701 "log-font-name argument '%s' is longer than %u characters.",
1702 arg, sizeof(g_szFontFaceName)-1);
1706 /* *************************************************************************
1708 * *************************************************************************/
1709 case hash_log_font_size :
1710 g_nFontSize = atoi(arg);
1713 /* *************************************************************************
1714 * log-highlight-messages (0|1)
1715 * *************************************************************************/
1716 case hash_log_highlight_messages :
1717 g_bHighlightMessages = atoi(arg);
1720 /* *************************************************************************
1722 * *************************************************************************/
1723 case hash_log_max_lines :
1724 g_nMaxBufferLines = atoi(arg);
1727 /* *************************************************************************
1728 * log-messages (0|1)
1729 * *************************************************************************/
1730 case hash_log_messages :
1731 g_bLogMessages = atoi(arg);
1734 /* *************************************************************************
1735 * show-on-task-bar (0|1)
1736 * *************************************************************************/
1737 case hash_show_on_task_bar :
1738 g_bShowOnTaskBar = atoi(arg);
1741 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1744 /* *************************************************************************
1745 * Warnings about unsupported features
1746 * *************************************************************************/
1748 case hash_deny_access:
1749 #endif /* ndef FEATURE_ACL */
1750 #ifndef FEATURE_CGI_EDIT_ACTIONS
1751 case hash_enable_edit_actions:
1752 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1753 #ifndef FEATURE_TOGGLE
1754 case hash_enable_remote_toggle:
1755 #endif /* ndef FEATURE_TOGGLE */
1757 case hash_permit_access:
1758 #endif /* ndef FEATURE_ACL */
1759 #ifndef FEATURE_TOGGLE
1761 #endif /* ndef FEATURE_TOGGLE */
1762 #ifndef FEATURE_TRUST
1763 case hash_trustfile :
1764 case hash_trust_info_url :
1765 #endif /* ndef FEATURE_TRUST */
1767 #ifndef _WIN_CONSOLE
1768 case hash_hide_console :
1769 #endif /* ndef _WIN_CONSOLE */
1771 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1772 case hash_activity_animation :
1773 case hash_close_button_minimizes :
1774 case hash_log_buffer_size :
1775 case hash_log_font_name :
1776 case hash_log_font_size :
1777 case hash_log_highlight_messages :
1778 case hash_log_max_lines :
1779 case hash_log_messages :
1780 case hash_show_on_task_bar :
1781 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1782 /* These warnings are annoying - so hide them. -- Jon */
1783 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1786 /* *************************************************************************/
1788 /* *************************************************************************/
1790 * I decided that I liked this better as a warning than an
1791 * error. To change back to an error, just change log level
1792 * to LOG_LEVEL_FATAL.
1794 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1795 "in configuration file (%s).", buf, directive_hash, linenum, configfile);
1796 string_append(&config->proxy_args,
1797 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1800 /* *************************************************************************/
1801 } /* end switch( hash_string(cmd) ) */
1803 /* Save the argument for the show-status page. */
1804 savearg(cmd, arg, config);
1806 } /* end while ( read_config_line(...) ) */
1810 set_debug_level(config->debug);
1812 freez(config->logfile);
1816 if (NULL != logfile)
1818 config->logfile = logfile;
1819 init_error_log(Argv[0], config->logfile);
1827 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1828 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1830 if (config->multi_threaded)
1832 set_keep_alive_timeout(config->keep_alive_timeout);
1837 * While we could use keep-alive without multiple threads
1838 * if we didn't bother with enforcing the connection timeout,
1839 * that might make Tor users sad, even though they shouldn't
1840 * enable the single-threaded option anyway.
1842 * XXX: We could still use Proxy-Connection: keep-alive.
1844 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1845 log_error(LOG_LEVEL_ERROR,
1846 "Config option single-threaded disables connection keep-alive.");
1851 if (NULL == config->proxy_args)
1853 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1856 if (config->actions_file[0])
1858 add_loader(load_action_files, config);
1861 if (config->re_filterfile[0])
1863 add_loader(load_re_filterfiles, config);
1866 #ifdef FEATURE_TRUST
1867 if (config->trustfile)
1869 add_loader(load_trustfile, config);
1871 #endif /* def FEATURE_TRUST */
1873 if ( NULL == config->haddr )
1875 config->haddr = strdup( HADDR_DEFAULT );
1878 if ( NULL != config->haddr )
1880 if ((*config->haddr == '[')
1881 && (NULL != (p = strchr(config->haddr, ']')))
1883 && (0 < (config->hport = atoi(p + 2))))
1886 memmove((void *)config->haddr, config->haddr + 1,
1887 (size_t)(p - config->haddr));
1889 else if (NULL != (p = strchr(config->haddr, ':'))
1890 && (0 < (config->hport = atoi(p + 1))))
1896 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1897 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1899 if (*config->haddr == '\0')
1902 * Only the port specified. We stored it in config->hport
1903 * and don't need its text representation anymore.
1905 freez(config->haddr);
1910 * Want to run all the loaders once now.
1912 * Need to set up a fake csp, so they can get to the config.
1914 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1915 fake_csp->config = config;
1917 if (run_loader(fake_csp))
1920 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1921 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1925 /* FIXME: this is a kludge for win32 */
1926 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1928 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1929 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1930 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1932 #ifdef FEATURE_TRUST
1933 g_trustfile = config->trustfile;
1934 #endif /* def FEATURE_TRUST */
1937 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1938 /* FIXME: end kludge */
1941 config->need_bind = 1;
1943 if (current_configfile)
1945 struct configuration_spec * oldcfg = (struct configuration_spec *)
1946 current_configfile->f;
1948 * Check if config->haddr,hport == oldcfg->haddr,hport
1950 * The following could be written more compactly as a single,
1951 * (unreadably long) if statement.
1953 config->need_bind = 0;
1954 if (config->hport != oldcfg->hport)
1956 config->need_bind = 1;
1958 else if (config->haddr == NULL)
1960 if (oldcfg->haddr != NULL)
1962 config->need_bind = 1;
1965 else if (oldcfg->haddr == NULL)
1967 config->need_bind = 1;
1969 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1971 config->need_bind = 1;
1974 current_configfile->unloader = unload_configfile;
1977 fs->next = files->next;
1980 current_configfile = fs;
1986 /*********************************************************************
1988 * Function : savearg
1990 * Description : Called from `load_config'. It saves each non-empty
1991 * and non-comment line from config into
1992 * config->proxy_args. This is used to create the
1993 * show-proxy-args page. On error, frees
1994 * config->proxy_args and sets it to NULL
1997 * 1 : command = config setting that was found
1998 * 2 : argument = the setting's argument (if any)
1999 * 3 : config = Configuration to save into.
2003 *********************************************************************/
2004 static void savearg(char *command, char *argument, struct configuration_spec * config)
2013 * Add config option name embedded in
2014 * link to its section in the user-manual
2016 buf = strdup("\n<a href=\"");
2017 if (!strncmpic(config->usermanual, "file://", 7) ||
2018 !strncmpic(config->usermanual, "http", 4))
2020 string_append(&buf, config->usermanual);
2024 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
2026 string_append(&buf, CONFIG_HELP_PREFIX);
2027 string_join (&buf, string_toupper(command));
2028 string_append(&buf, "\">");
2029 string_append(&buf, command);
2030 string_append(&buf, "</a> ");
2034 freez(config->proxy_args);
2038 if ( (NULL != argument) && ('\0' != *argument) )
2040 s = html_encode(argument);
2044 freez(config->proxy_args);
2048 if (strncmpic(argument, "http://", 7) == 0)
2050 string_append(&buf, "<a href=\"");
2051 string_append(&buf, s);
2052 string_append(&buf, "\">");
2053 string_join (&buf, s);
2054 string_append(&buf, "</a>");
2058 string_join (&buf, s);
2062 string_append(&buf, "<br>");
2063 string_join(&config->proxy_args, buf);