There's no reason for keep_alive_timeout to be signed.
[privoxy.git] / loadcfg.c
1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.100 2009/05/10 10:19:23 fabiankeil Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
5  *
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.
10  *
11  * Copyright   :  Written by and Copyright (C) 2001-2009 the
12  *                Privoxy team. http://www.privoxy.org/
13  *
14  *                Based on the Internet Junkbuster originally written
15  *                by and Copyright (C) 1997 Anonymous Coders and
16  *                Junkbusters Corporation.  http://www.junkbusters.com
17  *
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.
23  *
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.
29  *
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.
35  *
36  * Revisions   :
37  *    $Log: loadcfg.c,v $
38  *    Revision 1.100  2009/05/10 10:19:23  fabiankeil
39  *    Reenable server-side-only keep-alive support, but only share
40  *    outgoing connections if the connection-sharing option is set.
41  *
42  *    Revision 1.99  2009/05/10 10:12:30  fabiankeil
43  *    Initial keep-alive support for the client socket.
44  *    Temporarily disable the server-side-only keep-alive code.
45  *
46  *    Revision 1.98  2009/04/24 15:29:43  fabiankeil
47  *    Allow to limit the number of of client connections.
48  *
49  *    Revision 1.97  2009/04/17 11:45:19  fabiankeil
50  *    Replace HAVE_GETADDRINFO and HAVE_GETNAMEINFO macros
51  *    with HAVE_RFC2553 macro. Original patch by Petr Pisar.
52  *
53  *    Revision 1.96  2009/04/17 11:38:28  fabiankeil
54  *    Add and use parse_forwarder_address() to reduce code duplication.
55  *
56  *    Revision 1.95  2009/04/17 11:34:34  fabiankeil
57  *    Style cosmetics for the IPv6 code.
58  *
59  *    Revision 1.94  2009/04/17 11:27:49  fabiankeil
60  *    Petr Pisar's privoxy-3.0.12-ipv6-3.diff.
61  *
62  *    Revision 1.93  2009/03/18 21:46:26  fabiankeil
63  *    Revert the last commit as there's a better way.
64  *
65  *    Revision 1.92  2009/03/18 20:43:19  fabiankeil
66  *    Don't enable LOG_LEVEL_INFO by default and don't apply the user's
67  *    debug settings until the logfile has been opened (if there is one).
68  *    Patch submitted by Roland in #2624120.
69  *
70  *    Revision 1.91  2009/03/09 17:29:08  fabiankeil
71  *    As of r1.88, the show-status page can use a single line for
72  *    warnings about ignored directives and the names of the ignored
73  *    directives themselves. Reminded by Lee, finally closes #1856559.
74  *
75  *    Revision 1.90  2009/03/07 17:58:02  fabiankeil
76  *    Fix two mingw32-only buffer overflows. Note that triggering
77  *    them requires control over the configuration file in which
78  *    case all bets are off anyway.
79  *
80  *    Revision 1.89  2009/03/01 18:46:33  fabiankeil
81  *    - Help clang understand that we aren't
82  *      dereferencing NULL pointers here.
83  *    - Some style fixes in the modified region.
84  *
85  *    Revision 1.88  2009/02/28 10:57:10  fabiankeil
86  *    Gimme a break or two. Don't let the show-status page
87  *    link to the website documentation for the user-manual
88  *    directive itself.
89  *
90  *    Revision 1.87  2009/02/15 07:56:13  fabiankeil
91  *    Increase default socket timeout to 300 seconds.
92  *
93  *    Revision 1.86  2009/02/08 19:18:57  fabiankeil
94  *    Now that we have the match-all.action file, the other action
95  *    files changed their position in config->actions_file[] back
96  *    to the way it was before standard.action got removed and the
97  *    changes from revision 1.84 have to be reverted.
98  *
99  *    Revision 1.85  2009/01/22 12:06:26  fabiankeil
100  *    Don't keep connections alive when running single-threaded.
101  *
102  *    Revision 1.84  2009/01/14 16:14:36  fabiankeil
103  *    Due to the standard.action file removal, the other action
104  *    files changed their position in config->actions_file[].
105  *    Update mingw32 kludge accordingly.
106  *
107  *    Revision 1.83  2008/12/20 14:53:55  fabiankeil
108  *    Add config option socket-timeout to control the time
109  *    Privoxy waits for data to arrive on a socket. Useful
110  *    in case of stale ssh tunnels or when fuzz-testing.
111  *
112  *    Revision 1.82  2008/11/16 12:43:49  fabiankeil
113  *    Turn keep-alive support into a runtime feature
114  *    that is disabled by setting keep-alive-timeout
115  *    to a negative value.
116  *
117  *    Revision 1.81  2008/11/13 09:08:42  fabiankeil
118  *    Add new config option: keep-alive-timeout.
119  *
120  *    Revision 1.80  2008/08/31 15:59:03  fabiankeil
121  *    There's no reason to let remote toggling support depend
122  *    on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
123  *
124  *    Revision 1.79  2008/08/30 12:03:07  fabiankeil
125  *    Remove FEATURE_COOKIE_JAR.
126  *
127  *    Revision 1.78  2008/08/02 08:23:22  fabiankeil
128  *    If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
129  *    disabled, log a message that blocks will always be enforced
130  *    instead of complaining about an unrecognized directive.
131  *    Reported by Pietro Leone.
132  *
133  *    Revision 1.77  2008/05/26 16:13:22  fabiankeil
134  *    Reuse directive_hash and don't hash the same directive twice.
135  *
136  *    Revision 1.76  2008/05/10 09:03:16  fabiankeil
137  *    - Merge three string_append() calls.
138  *    - Remove useless assertion.
139  *
140  *    Revision 1.75  2008/03/30 14:52:05  fabiankeil
141  *    Rename load_actions_file() and load_re_filterfile()
142  *    as they load multiple files "now".
143  *
144  *    Revision 1.74  2008/03/26 18:07:07  fabiankeil
145  *    Add hostname directive. Closes PR#1918189.
146  *
147  *    Revision 1.73  2008/02/16 16:54:51  fabiankeil
148  *    Fix typo.
149  *
150  *    Revision 1.72  2008/02/03 13:46:15  fabiankeil
151  *    Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
152  *
153  *    Revision 1.71  2007/12/23 15:24:56  fabiankeil
154  *    Reword "unrecognized directive" warning, use better
155  *    mark up and add a <br>. Fixes parts of #1856559.
156  *
157  *    Revision 1.70  2007/12/15 14:24:05  fabiankeil
158  *    Plug memory leak if listen-address only specifies the port.
159  *
160  *    Revision 1.69  2007/10/27 13:02:27  fabiankeil
161  *    Relocate daemon-mode-related log messages to make sure
162  *    they aren't shown again in case of configuration reloads.
163  *
164  *    Revision 1.68  2007/10/19 16:32:34  fabiankeil
165  *    Plug memory leak introduced with my last commit.
166  *
167  *    Revision 1.67  2007/10/14 14:12:41  fabiankeil
168  *    When in daemon mode, close stderr after the configuration file has been
169  *    parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
170  *
171  *    Revision 1.66  2007/08/05 14:02:09  fabiankeil
172  *    #1763173 from Stefan Huehner: declare unload_configfile() static.
173  *
174  *    Revision 1.65  2007/07/21 11:51:36  fabiankeil
175  *    As Hal noticed, checking dispatch_cgi() as the last cruncher
176  *    looks like a bug if CGI requests are blocked unintentionally,
177  *    so don't do it unless the user enabled the new config option
178  *    "allow-cgi-request-crunching".
179  *
180  *    Revision 1.64  2007/05/21 10:44:08  fabiankeil
181  *    - Use strlcpy() instead of strcpy().
182  *    - Stop treating actions files special. Expect a complete file name
183  *      (with or without path) like it's done for the rest of the files.
184  *      Closes FR#588084.
185  *    - Remove an unnecessary temporary memory allocation.
186  *    - Don't log anything to the console when running as
187  *      daemon and no errors occurred.
188  *
189  *    Revision 1.63  2007/04/09 18:11:36  fabiankeil
190  *    Don't mistake VC++'s _snprintf() for a snprintf() replacement.
191  *
192  *    Revision 1.62  2007/03/17 15:20:05  fabiankeil
193  *    New config option: enforce-blocks.
194  *
195  *    Revision 1.61  2007/03/16 16:47:35  fabiankeil
196  *    - Mention other reasons why acl directive loading might have failed.
197  *    - Don't log the acl source if the acl destination is to blame.
198  *
199  *    Revision 1.60  2007/01/27 13:09:16  fabiankeil
200  *    Add new config option "templdir" to
201  *    change the templates directory.
202  *
203  *    Revision 1.59  2006/12/31 17:56:38  fabiankeil
204  *    Added config option accept-intercepted-requests
205  *    and disabled it by default.
206  *
207  *    Revision 1.58  2006/12/31 14:24:29  fabiankeil
208  *    Fix gcc43 compiler warnings.
209  *
210  *    Revision 1.57  2006/12/21 12:57:48  fabiankeil
211  *    Add config option "split-large-forms"
212  *    to work around the browser bug reported
213  *    in BR #1570678.
214  *
215  *    Revision 1.56  2006/12/17 17:04:51  fabiankeil
216  *    Move the <br> in the generated HTML for the config
217  *    options from the beginning of the string to its end.
218  *    Keeps the white space in balance.
219  *
220  *    Revision 1.55  2006/11/28 15:31:52  fabiankeil
221  *    Fix memory leak in case of config file reloads.
222  *
223  *    Revision 1.54  2006/10/21 16:04:22  fabiankeil
224  *    Modified kludge for win32 to make ming32 menu
225  *    "Options/Edit Filters" (sort of) work again.
226  *    Same limitations as for the action files apply.
227  *    Fixes BR 1567373.
228  *
229  *    Revision 1.53  2006/09/06 18:45:03  fabiankeil
230  *    Incorporate modified version of Roland Rosenfeld's patch to
231  *    optionally access the user-manual via Privoxy. Closes patch 679075.
232  *
233  *    Formatting changed to Privoxy style, added call to
234  *    cgi_error_no_template if the requested file doesn't
235  *    exist and modified check whether or not Privoxy itself
236  *    should serve the manual. Should work cross-platform now.
237  *
238  *    Revision 1.52  2006/09/06 10:43:32  fabiankeil
239  *    Added config option enable-remote-http-toggle
240  *    to specify if Privoxy should recognize special
241  *    headers (currently only X-Filter) to change its
242  *    behaviour. Disabled by default.
243  *
244  *    Revision 1.51  2006/09/06 09:23:37  fabiankeil
245  *    Make number of retries in case of forwarded-connect problems
246  *    a config file option (forwarded-connect-retries) and use 0 as
247  *    default.
248  *
249  *    Revision 1.50  2006/07/18 14:48:46  david__schmidt
250  *    Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
251  *    with what was really the latest development (the v_3_0_branch branch)
252  *
253  *    Revision 1.48.2.7  2006/02/02 17:29:16  david__schmidt
254  *    Don't forget to malloc space for the null terminator...
255  *
256  *    Revision 1.48.2.6  2006/01/29 23:10:56  david__schmidt
257  *    Multiple filter file support
258  *
259  *    Revision 1.48.2.5  2003/05/08 15:17:25  oes
260  *    Closed two memory leaks; hopefully the last remaining ones
261  *    (in the main execution paths, anyway).
262  *
263  *    Revision 1.48.2.4  2003/04/11 12:06:14  oes
264  *    Addressed bug #719435
265  *     - Extraneous filterfile directives now logged as errors
266  *     - This and unrecnonised directives now really obvious on status page
267  *
268  *    Revision 1.48.2.3  2003/03/11 11:53:59  oes
269  *    Cosmetic: Renamed cryptic variable
270  *
271  *    Revision 1.48.2.2  2002/11/12 16:28:20  oes
272  *    Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
273  *
274  *    Revision 1.48.2.1  2002/08/21 17:58:05  oes
275  *    Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
276  *
277  *    Revision 1.48  2002/05/14 21:30:38  oes
278  *    savearg now uses own linking code instead of (now special-cased) add_help_link
279  *
280  *    Revision 1.47  2002/05/12 21:36:29  jongfoster
281  *    Correcting function comments
282  *
283  *    Revision 1.46  2002/04/26 12:55:14  oes
284  *     - New option "user-manual", defaults to our site
285  *       via project.h #define
286  *     - savearg now embeds option names in help links
287  *
288  *    Revision 1.45  2002/04/24 02:11:54  oes
289  *    Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
290  *
291  *    Revision 1.44  2002/04/08 20:37:13  swa
292  *    fixed JB spelling
293  *
294  *    Revision 1.43  2002/04/08 20:36:50  swa
295  *    fixed JB spelling
296  *
297  *    Revision 1.42  2002/04/05 15:50:15  oes
298  *    fix for invalid HTML proxy_args
299  *
300  *    Revision 1.41  2002/03/31 17:19:00  jongfoster
301  *    Win32 only: Enabling STRICT to fix a VC++ compile warning.
302  *
303  *    Revision 1.40  2002/03/26 22:29:55  swa
304  *    we have a new homepage!
305  *
306  *    Revision 1.39  2002/03/24 13:25:43  swa
307  *    name change related issues
308  *
309  *    Revision 1.38  2002/03/24 13:05:48  jongfoster
310  *    Renaming re_filterfile to filterfile
311  *
312  *    Revision 1.37  2002/03/16 23:54:06  jongfoster
313  *    Adding graceful termination feature, to help look for memory leaks.
314  *    If you enable this (which, by design, has to be done by hand
315  *    editing config.h) and then go to http://i.j.b/die, then the program
316  *    will exit cleanly after the *next* request.  It should free all the
317  *    memory that was used.
318  *
319  *    Revision 1.36  2002/03/13 00:27:05  jongfoster
320  *    Killing warnings
321  *
322  *    Revision 1.35  2002/03/07 03:52:44  oes
323  *    Set logging to tty for --no-daemon mode
324  *
325  *    Revision 1.34  2002/03/06 23:14:35  jongfoster
326  *    Trivial cosmetic changes to make function comments easier to find.
327  *
328  *    Revision 1.33  2002/03/05 04:52:42  oes
329  *    Deleted non-errlog debugging code
330  *
331  *    Revision 1.32  2002/03/04 18:24:53  oes
332  *    Re-enabled output of unknown config directive hash
333  *
334  *    Revision 1.31  2002/03/03 15:07:20  oes
335  *    Re-enabled automatic config reloading
336  *
337  *    Revision 1.30  2002/01/22 23:31:43  jongfoster
338  *    Replacing strsav() with string_append()
339  *
340  *    Revision 1.29  2002/01/17 21:02:30  jongfoster
341  *    Moving all our URL and URL pattern parsing code to urlmatch.c.
342  *
343  *    Renaming free_url to free_url_spec, since it frees a struct url_spec.
344  *
345  *    Revision 1.28  2001/12/30 14:07:32  steudten
346  *    - Add signal handling (unix)
347  *    - Add SIGHUP handler (unix)
348  *    - Add creation of pidfile (unix)
349  *    - Add action 'top' in rc file (RH)
350  *    - Add entry 'SIGNALS' to manpage
351  *    - Add exit message to logfile (unix)
352  *
353  *    Revision 1.27  2001/11/07 00:02:13  steudten
354  *    Add line number in error output for lineparsing for
355  *    actionsfile and configfile.
356  *    Special handling for CLF added.
357  *
358  *    Revision 1.26  2001/11/05 21:41:43  steudten
359  *    Add changes to be a real daemon just for unix os.
360  *    (change cwd to /, detach from controlling tty, set
361  *    process group and session leader to the own process.
362  *    Add DBG() Macro.
363  *    Add some fatal-error log message for failed malloc().
364  *    Add '-d' if compiled with 'configure --with-debug' to
365  *    enable debug output.
366  *
367  *    Revision 1.25  2001/10/25 03:40:48  david__schmidt
368  *    Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
369  *    threads to call select() simultaneously.  So, it's time to do a real, live,
370  *    native OS/2 port.  See defines for __EMX__ (the porting layer) vs. __OS2__
371  *    (native). Both versions will work, but using __OS2__ offers multi-threading.
372  *
373  *    Revision 1.24  2001/10/23 21:40:30  jongfoster
374  *    Added support for enable-edit-actions and enable-remote-toggle config
375  *    file options.
376  *
377  *    Revision 1.23  2001/10/07 15:36:00  oes
378  *    Introduced new config option "buffer-limit"
379  *
380  *    Revision 1.22  2001/09/22 16:36:59  jongfoster
381  *    Removing unused parameter fs from read_config_line()
382  *
383  *    Revision 1.21  2001/09/16 17:10:43  jongfoster
384  *    Moving function savearg() here, since it was the only thing left in
385  *    showargs.c.
386  *
387  *    Revision 1.20  2001/07/30 22:08:36  jongfoster
388  *    Tidying up #defines:
389  *    - All feature #defines are now of the form FEATURE_xxx
390  *    - Permanently turned off WIN_GUI_EDIT
391  *    - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
392  *
393  *    Revision 1.19  2001/07/15 17:45:16  jongfoster
394  *    Removing some unused #includes
395  *
396  *    Revision 1.18  2001/07/13 14:01:14  oes
397  *     - Removed all #ifdef PCRS
398  *     - Removed vim-settings
399  *
400  *    Revision 1.17  2001/06/29 13:31:03  oes
401  *    - Improved comments
402  *    - Fixed (actionsfile) and sorted hashes
403  *    - Introduced admin_address and proxy-info-url
404  *      as config parameters
405  *    - Renamed config->proxy_args_invocation (which didn't have
406  *      the invocation but the options!) to config->proxy_args
407  *    - Various adaptions
408  *    - Removed logentry from cancelled commit
409  *
410  *    Revision 1.16  2001/06/09 10:55:28  jongfoster
411  *    Changing BUFSIZ ==> BUFFER_SIZE
412  *
413  *    Revision 1.15  2001/06/07 23:13:40  jongfoster
414  *    Merging ACL and forward files into config file.
415  *    Cosmetic: Sorting config file options alphabetically.
416  *    Cosmetic: Adding brief syntax comments to config file options.
417  *
418  *    Revision 1.14  2001/06/07 14:46:25  joergs
419  *    Missing make_path() added for re_filterfile.
420  *
421  *    Revision 1.13  2001/06/05 22:33:54  jongfoster
422  *
423  *    Fixed minor memory leak.
424  *    Also now uses make_path to prepend the pathnames.
425  *
426  *    Revision 1.12  2001/06/05 20:04:09  jongfoster
427  *    Now uses _snprintf() in place of snprintf() under Win32.
428  *
429  *    Revision 1.11  2001/06/04 18:31:58  swa
430  *    files are now prefixed with either `confdir' or `logdir'.
431  *    `make redhat-dist' replaces both entries confdir and logdir
432  *    with redhat values
433  *
434  *    Revision 1.10  2001/06/03 19:11:54  oes
435  *    introduced confdir option
436  *
437  *    Revision 1.9  2001/06/01 20:06:24  jongfoster
438  *    Removed support for "tinygif" option - moved to actions file.
439  *
440  *    Revision 1.8  2001/05/31 21:27:13  jongfoster
441  *    Removed many options from the config file and into the
442  *    "actions" file: add_forwarded, suppress_vanilla_wafer,
443  *    wafer, add_header, user_agent, referer, from
444  *    Also globally replaced "permission" with "action".
445  *
446  *    Revision 1.7  2001/05/29 09:50:24  jongfoster
447  *    Unified blocklist/imagelist/permissionslist.
448  *    File format is still under discussion, but the internal changes
449  *    are (mostly) done.
450  *
451  *    Also modified interceptor behaviour:
452  *    - We now intercept all URLs beginning with one of the following
453  *      prefixes (and *only* these prefixes):
454  *        * http://i.j.b/
455  *        * http://ijbswa.sf.net/config/
456  *        * http://ijbswa.sourceforge.net/config/
457  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
458  *    - Internal changes so that intercepted and fast redirect pages
459  *      are not replaced with an image.
460  *    - Interceptors now have the option to send a binary page direct
461  *      to the client. (i.e. ijb-send-banner uses this)
462  *    - Implemented show-url-info interceptor.  (Which is why I needed
463  *      the above interceptors changes - a typical URL is
464  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
465  *      The previous mechanism would not have intercepted that, and
466  *      if it had been intercepted then it then it would have replaced
467  *      it with an image.)
468  *
469  *    Revision 1.6  2001/05/26 00:28:36  jongfoster
470  *    Automatic reloading of config file.
471  *    Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
472  *    Most of the global variables have been moved to a new
473  *    struct configuration_spec, accessed through csp->config->globalname
474  *    Most of the globals remaining are used by the Win32 GUI.
475  *
476  *    Revision 1.5  2001/05/25 22:34:30  jongfoster
477  *    Hard tabs->Spaces
478  *
479  *    Revision 1.4  2001/05/22 18:46:04  oes
480  *
481  *    - Enabled filtering banners by size rather than URL
482  *      by adding patterns that replace all standard banner
483  *      sizes with the "Junkbuster" gif to the re_filterfile
484  *
485  *    - Enabled filtering WebBugs by providing a pattern
486  *      which kills all 1x1 images
487  *
488  *    - Added support for PCRE_UNGREEDY behaviour to pcrs,
489  *      which is selected by the (nonstandard and therefore
490  *      capital) letter 'U' in the option string.
491  *      It causes the quantifiers to be ungreedy by default.
492  *      Appending a ? turns back to greedy (!).
493  *
494  *    - Added a new interceptor ijb-send-banner, which
495  *      sends back the "Junkbuster" gif. Without imagelist or
496  *      MSIE detection support, or if tinygif = 1, or the
497  *      URL isn't recognized as an imageurl, a lame HTML
498  *      explanation is sent instead.
499  *
500  *    - Added new feature, which permits blocking remote
501  *      script redirects and firing back a local redirect
502  *      to the browser.
503  *      The feature is conditionally compiled, i.e. it
504  *      can be disabled with --disable-fast-redirects,
505  *      plus it must be activated by a "fast-redirects"
506  *      line in the config file, has its own log level
507  *      and of course wants to be displayed by show-proxy-args
508  *      Note: Boy, all the #ifdefs in 1001 locations and
509  *      all the fumbling with configure.in and acconfig.h
510  *      were *way* more work than the feature itself :-(
511  *
512  *    - Because a generic redirect template was needed for
513  *      this, tinygif = 3 now uses the same.
514  *
515  *    - Moved GIFs, and other static HTTP response templates
516  *      to project.h
517  *
518  *    - Some minor fixes
519  *
520  *    - Removed some >400 CRs again (Jon, you really worked
521  *      a lot! ;-)
522  *
523  *    Revision 1.3  2001/05/20 01:21:20  jongfoster
524  *    Version 2.9.4 checkin.
525  *    - Merged popupfile and cookiefile, and added control over PCRS
526  *      filtering, in new "permissionsfile".
527  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
528  *      file error you now get a message box (in the Win32 GUI) rather
529  *      than the program exiting with no explanation.
530  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
531  *      skipping.
532  *    - Removed tabs from "config"
533  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
534  *    - Bumped up version number.
535  *
536  *    Revision 1.2  2001/05/17 23:01:01  oes
537  *     - Cleaned CRLF's from the sources and related files
538  *
539  *    Revision 1.1.1.1  2001/05/15 13:58:58  oes
540  *    Initial import of version 2.9.3 source tree
541  *
542  *
543  *********************************************************************/
544 \f
545
546 #include "config.h"
547
548 #include <stdio.h>
549 #include <sys/types.h>
550 #include <stdlib.h>
551 #include <string.h>
552 #include <signal.h>
553 #include <fcntl.h>
554 #include <errno.h>
555 #include <ctype.h>
556 #include <assert.h>
557
558 #ifdef _WIN32
559
560 # ifndef STRICT
561 #  define STRICT
562 # endif
563 # include <windows.h>
564
565 # include "win32.h"
566 # ifndef _WIN_CONSOLE
567 #  include "w32log.h"
568 # endif /* ndef _WIN_CONSOLE */
569
570 #else /* ifndef _WIN32 */
571
572 #ifndef __OS2__
573 # include <unistd.h>
574 # include <sys/wait.h>
575 #endif
576 # include <sys/time.h>
577 # include <sys/stat.h>
578 # include <signal.h>
579
580 #endif
581
582 #include "loadcfg.h"
583 #include "list.h"
584 #include "jcc.h"
585 #include "filters.h"
586 #include "loaders.h"
587 #include "miscutil.h"
588 #include "errlog.h"
589 #include "ssplit.h"
590 #include "encode.h"
591 #include "urlmatch.h"
592 #include "cgi.h"
593 #include "gateway.h"
594
595 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
596
597 /*
598  * Fix a problem with Solaris.  There should be no effect on other
599  * platforms.
600  * Solaris's isspace() is a macro which uses it's argument directly
601  * as an array index.  Therefore we need to make sure that high-bit
602  * characters generate +ve values, and ideally we also want to make
603  * the argument match the declared parameter type of "int".
604  */
605 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
606 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
607
608 #ifdef FEATURE_TOGGLE
609 /* Privoxy is enabled by default. */
610 int global_toggle_state = 1;
611 #endif /* def FEATURE_TOGGLE */
612
613 /* The filename of the configfile */
614 const char *configfile  = NULL;
615
616 /*
617  * CGI functions will later need access to the invocation args,
618  * so we will make argc and argv global.
619  */
620 int Argc = 0;
621 const char **Argv = NULL;
622
623 static struct file_list *current_configfile = NULL;
624
625
626 /*
627  * This takes the "cryptic" hash of each keyword and aliases them to
628  * something a little more readable.  This also makes changing the
629  * hash values easier if they should change or the hash algorthm changes.
630  * Use the included "hash" program to find out what the hash will be
631  * for any string supplied on the command line.  (Or just put it in the
632  * config file and read the number from the error message in the log).
633  *
634  * Please keep this list sorted alphabetically (but with the Windows
635  * console and GUI specific options last).
636  */
637
638 #define hash_actions_file                1196306641ul /* "actionsfile" */
639 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
640 #define hash_admin_address               4112573064ul /* "admin-address" */
641 #define hash_allow_cgi_request_crunching  258915987ul /* "allow-cgi-request-crunching" */
642 #define hash_buffer_limit                1881726070ul /* "buffer-limit */
643 #define hash_confdir                        1978389ul /* "confdir" */
644 #define hash_connection_sharing          1348841265ul /* "connection-sharing" */
645 #define hash_debug                            78263ul /* "debug" */
646 #define hash_deny_access                 1227333715ul /* "deny-access" */
647 #define hash_enable_edit_actions         2517097536ul /* "enable-edit-actions" */
648 #define hash_enable_remote_toggle        2979744683ul /* "enable-remote-toggle" */
649 #define hash_enable_remote_http_toggle    110543988ul /* "enable-remote-http-toggle" */
650 #define hash_enforce_blocks              1862427469ul /* "enforce-blocks" */
651 #define hash_filterfile                   250887266ul /* "filterfile" */
652 #define hash_forward                        2029845ul /* "forward" */
653 #define hash_forward_socks4              3963965521ul /* "forward-socks4" */
654 #define hash_forward_socks4a             2639958518ul /* "forward-socks4a" */
655 #define hash_forward_socks5              3963965522ul /* "forward-socks5" */
656 #define hash_forwarded_connect_retries    101465292ul /* "forwarded-connect-retries" */
657 #define hash_hostname                      10308071ul /* "hostname" */
658 #define hash_keep_alive_timeout          3878599515ul /* "keep-alive-timeout" */
659 #define hash_listen_address              1255650842ul /* "listen-address" */
660 #define hash_logdir                          422889ul /* "logdir" */
661 #define hash_logfile                        2114766ul /* "logfile" */
662 #define hash_max_client_connections      3595884446ul /* "max-client-connections" */
663 #define hash_permit_access               3587953268ul /* "permit-access" */
664 #define hash_proxy_info_url              3903079059ul /* "proxy-info-url" */
665 #define hash_single_threaded             4250084780ul /* "single-threaded" */
666 #define hash_socket_timeout              1809001761ul /* "socket-timeout" */
667 #define hash_split_large_cgi_forms        671658948ul /* "split-large-cgi-forms" */
668 #define hash_suppress_blocklists         1948693308ul /* "suppress-blocklists" */
669 #define hash_templdir                      11067889ul /* "templdir" */
670 #define hash_toggle                          447966ul /* "toggle" */
671 #define hash_trust_info_url               430331967ul /* "trust-info-url" */
672 #define hash_trustfile                     56494766ul /* "trustfile" */
673 #define hash_usermanual                  1416668518ul /* "user-manual" */
674 #define hash_activity_animation          1817904738ul /* "activity-animation" */
675 #define hash_close_button_minimizes      3651284693ul /* "close-button-minimizes" */
676 #define hash_hide_console                2048809870ul /* "hide-console" */
677 #define hash_log_buffer_size             2918070425ul /* "log-buffer-size" */
678 #define hash_log_font_name               2866730124ul /* "log-font-name" */
679 #define hash_log_font_size               2866731014ul /* "log-font-size" */
680 #define hash_log_highlight_messages      4032101240ul /* "log-highlight-messages" */
681 #define hash_log_max_lines               2868344173ul /* "log-max-lines" */
682 #define hash_log_messages                2291744899ul /* "log-messages" */
683 #define hash_show_on_task_bar             215410365ul /* "show-on-task-bar" */
684
685
686 static void savearg(char *command, char *argument, struct configuration_spec * config);
687
688 /*********************************************************************
689  *
690  * Function    :  unload_configfile
691  *
692  * Description :  Free the config structure and all components.
693  *
694  * Parameters  :
695  *          1  :  data: struct configuration_spec to unload
696  *
697  * Returns     :  N/A
698  *
699  *********************************************************************/
700 static void unload_configfile (void * data)
701 {
702    struct configuration_spec * config = (struct configuration_spec *)data;
703    struct forward_spec *cur_fwd = config->forward;
704    int i;
705
706 #ifdef FEATURE_ACL
707    struct access_control_list *cur_acl = config->acl;
708
709    while (cur_acl != NULL)
710    {
711       struct access_control_list * next_acl = cur_acl->next;
712       free(cur_acl);
713       cur_acl = next_acl;
714    }
715    config->acl = NULL;
716 #endif /* def FEATURE_ACL */
717
718    while (cur_fwd != NULL)
719    {
720       struct forward_spec * next_fwd = cur_fwd->next;
721       free_url_spec(cur_fwd->url);
722
723       freez(cur_fwd->gateway_host);
724       freez(cur_fwd->forward_host);
725       free(cur_fwd);
726       cur_fwd = next_fwd;
727    }
728    config->forward = NULL;
729
730    freez(config->confdir);
731    freez(config->logdir);
732    freez(config->templdir);
733    freez(config->hostname);
734
735    freez(config->haddr);
736    freez(config->logfile);
737
738    for (i = 0; i < MAX_AF_FILES; i++)
739    {
740       freez(config->actions_file_short[i]);
741       freez(config->actions_file[i]);
742       freez(config->re_filterfile_short[i]);
743       freez(config->re_filterfile[i]);
744    }
745
746    freez(config->admin_address);
747    freez(config->proxy_info_url);
748    freez(config->proxy_args);
749    freez(config->usermanual);
750
751 #ifdef FEATURE_TRUST
752    freez(config->trustfile);
753    list_remove_all(config->trust_info);
754 #endif /* def FEATURE_TRUST */
755
756    for (i = 0; i < MAX_AF_FILES; i++)
757    {
758       freez(config->re_filterfile[i]);
759    }
760
761    freez(config);
762 }
763
764
765 #ifdef FEATURE_GRACEFUL_TERMINATION
766 /*********************************************************************
767  *
768  * Function    :  unload_current_config_file
769  *
770  * Description :  Unloads current config file - reset to state at
771  *                beginning of program.
772  *
773  * Parameters  :  None
774  *
775  * Returns     :  N/A
776  *
777  *********************************************************************/
778 void unload_current_config_file(void)
779 {
780    if (current_configfile)
781    {
782       current_configfile->unloader = unload_configfile;
783       current_configfile = NULL;
784    }
785 }
786 #endif
787
788
789 /*********************************************************************
790  *
791  * Function    :  load_config
792  *
793  * Description :  Load the config file and all parameters.
794  *
795  *                XXX: more than thousand lines long
796  *                and thus in serious need of refactoring.
797  *
798  * Parameters  :  None
799  *
800  * Returns     :  The configuration_spec, or NULL on error.
801  *
802  *********************************************************************/
803 struct configuration_spec * load_config(void)
804 {
805    char buf[BUFFER_SIZE];
806    char *p, *q;
807    FILE *configfp = NULL;
808    struct configuration_spec * config = NULL;
809    struct client_state * fake_csp;
810    struct file_list *fs;
811    unsigned long linenum = 0;
812    int i;
813    char *logfile = NULL;
814
815    if (!check_file_changed(current_configfile, configfile, &fs))
816    {
817       /* No need to load */
818       return ((struct configuration_spec *)current_configfile->f);
819    }
820    if (NULL == fs)
821    {
822       log_error(LOG_LEVEL_FATAL,
823          "can't check configuration file '%s':  %E", configfile);
824       return NULL;
825    }
826
827    if (NULL != current_configfile)
828    {
829       log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
830    }
831
832 #ifdef FEATURE_TOGGLE
833    global_toggle_state = 1;
834 #endif /* def FEATURE_TOGGLE */
835
836    fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
837
838    if (NULL == config)
839    {
840       freez(fs->filename);
841       freez(fs);
842       log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
843       return NULL;
844    }
845
846    /*
847     * This is backwards from how it's usually done.
848     * Following the usual pattern, "fs" would be stored in a member
849     * variable in "csp", and then we'd access "config" from "fs->f",
850     * using a cast.  However, "config" is used so often that a
851     * cast each time would be very ugly, and the extra indirection
852     * would waste CPU cycles.  Therefore we store "config" in
853     * "csp->config", and "fs" in "csp->config->config_file_list".
854     */
855    config->config_file_list = fs;
856
857    /*
858     * Set to defaults
859     */
860    config->multi_threaded            = 1;
861    config->buffer_limit              = 4096 * 1024;
862    config->usermanual                = strdup(USER_MANUAL_URL);
863    config->proxy_args                = strdup("");
864    config->forwarded_connect_retries = 0;
865    config->max_client_connections    = 0;
866    config->socket_timeout            = 300; /* XXX: Should be a macro. */
867 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
868    config->keep_alive_timeout        = DEFAULT_KEEP_ALIVE_TIMEOUT;
869    config->feature_flags            &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
870    config->feature_flags            &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
871 #endif
872    config->feature_flags            &= ~RUNTIME_FEATURE_CGI_TOGGLE;
873    config->feature_flags            &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
874    config->feature_flags            &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
875
876    configfp = fopen(configfile, "r");
877    if (NULL == configfp)
878    {
879       log_error(LOG_LEVEL_FATAL,
880          "can't open configuration file '%s':  %E", configfile);
881       /* Never get here - LOG_LEVEL_FATAL causes program exit */
882    }
883
884    while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
885    {
886       char cmd[BUFFER_SIZE];
887       char arg[BUFFER_SIZE];
888       char tmp[BUFFER_SIZE];
889 #ifdef FEATURE_ACL
890       struct access_control_list *cur_acl;
891 #endif /* def FEATURE_ACL */
892       struct forward_spec *cur_fwd;
893       int vec_count;
894       char *vec[3];
895       unsigned long directive_hash;
896
897       strlcpy(tmp, buf, sizeof(tmp));
898
899       /* Copy command (i.e. up to space or tab) into cmd */
900       p = buf;
901       q = cmd;
902       while (*p && (*p != ' ') && (*p != '\t'))
903       {
904          *q++ = *p++;
905       }
906       *q = '\0';
907
908       /* Skip over the whitespace in buf */
909       while (*p && ((*p == ' ') || (*p == '\t')))
910       {
911          p++;
912       }
913
914       /* Copy the argument into arg */
915       strlcpy(arg, p, sizeof(arg));
916
917       /* Should never happen, but check this anyway */
918       if (*cmd == '\0')
919       {
920          continue;
921       }
922
923       /* Make sure the command field is lower case */
924       for (p = cmd; *p; p++)
925       {
926          if (ijb_isupper(*p))
927          {
928             *p = (char)ijb_tolower(*p);
929          }
930       }
931
932       directive_hash = hash_string(cmd);
933       switch (directive_hash)
934       {
935 /* *************************************************************************
936  * actionsfile actions-file-name
937  * In confdir by default
938  * *************************************************************************/
939          case hash_actions_file :
940             i = 0;
941             while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
942             {
943                i++;
944             }
945
946             if (i >= MAX_AF_FILES)
947             {
948                log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
949                   "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
950                   MAX_AF_FILES);
951             }
952             config->actions_file_short[i] = strdup(arg);
953             config->actions_file[i] = make_path(config->confdir, arg);
954
955             break;
956 /* *************************************************************************
957  * accept-intercepted-requests
958  * *************************************************************************/
959          case hash_accept_intercepted_requests:
960             if ((*arg != '\0') && (0 != atoi(arg)))
961             {
962                config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
963             }
964             else
965             {
966                config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
967             }
968             break;
969
970 /* *************************************************************************
971  * admin-address email-address
972  * *************************************************************************/
973          case hash_admin_address :
974             freez(config->admin_address);
975             config->admin_address = strdup(arg);
976             break;
977
978 /* *************************************************************************
979  * allow-cgi-request-crunching
980  * *************************************************************************/
981          case hash_allow_cgi_request_crunching:
982             if ((*arg != '\0') && (0 != atoi(arg)))
983             {
984                config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
985             }
986             else
987             {
988                config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
989             }
990             break;
991
992 /* *************************************************************************
993  * buffer-limit n
994  * *************************************************************************/
995          case hash_buffer_limit :
996             config->buffer_limit = (size_t)(1024 * atoi(arg));
997             break;
998
999 /* *************************************************************************
1000  * confdir directory-name
1001  * *************************************************************************/
1002          case hash_confdir :
1003             freez(config->confdir);
1004             config->confdir = make_path( NULL, arg);
1005             break;
1006
1007 /* *************************************************************************
1008  * connection-sharing (0|1)
1009  * *************************************************************************/
1010 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1011          case hash_connection_sharing :
1012             if ((*arg != '\0') && (0 != atoi(arg)))
1013             {
1014                config->feature_flags |= RUNTIME_FEATURE_CONNECTION_SHARING;
1015             }
1016             else
1017             {
1018                config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
1019             }
1020             break;
1021 #endif
1022
1023 /* *************************************************************************
1024  * debug n
1025  * Specifies debug level, multiple values are ORed together.
1026  * *************************************************************************/
1027          case hash_debug :
1028             config->debug |= atoi(arg);
1029             break;
1030
1031 /* *************************************************************************
1032  * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1033  * *************************************************************************/
1034 #ifdef FEATURE_ACL
1035          case hash_deny_access:
1036             strlcpy(tmp, arg, sizeof(tmp));
1037             vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1038
1039             if ((vec_count != 1) && (vec_count != 2))
1040             {
1041                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1042                      "deny-access directive in configuration file.");
1043                string_append(&config->proxy_args,
1044                   "<br>\nWARNING: Wrong number of parameters for "
1045                   "deny-access directive in configuration file.<br><br>\n");
1046                break;
1047             }
1048
1049             /* allocate a new node */
1050             cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1051
1052             if (cur_acl == NULL)
1053             {
1054                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1055                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1056                break;
1057             }
1058             cur_acl->action = ACL_DENY;
1059
1060             if (acl_addr(vec[0], cur_acl->src) < 0)
1061             {
1062                log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1063                   "for deny-access directive in configuration file: \"%s\"", vec[0]);
1064                string_append(&config->proxy_args,
1065                   "<br>\nWARNING: Invalid source address, port or netmask "
1066                   "for deny-access directive in configuration file: \"");
1067                string_append(&config->proxy_args,
1068                   vec[0]);
1069                string_append(&config->proxy_args,
1070                   "\"<br><br>\n");
1071                freez(cur_acl);
1072                break;
1073             }
1074             if (vec_count == 2)
1075             {
1076                if (acl_addr(vec[1], cur_acl->dst) < 0)
1077                {
1078                   log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1079                      "for deny-access directive in configuration file: \"%s\"", vec[1]);
1080                   string_append(&config->proxy_args,
1081                      "<br>\nWARNING: Invalid destination address, port or netmask "
1082                      "for deny-access directive in configuration file: \"");
1083                   string_append(&config->proxy_args,
1084                      vec[1]);
1085                   string_append(&config->proxy_args,
1086                      "\"<br><br>\n");
1087                   freez(cur_acl);
1088                   break;
1089                }
1090             }
1091 #ifdef HAVE_RFC2553
1092             else
1093             {
1094                cur_acl->wildcard_dst = 1;
1095             }
1096 #endif /* def HAVE_RFC2553 */
1097
1098             /*
1099              * Add it to the list.  Note we reverse the list to get the
1100              * behaviour the user expects.  With both the ACL and
1101              * actions file, the last match wins.  However, the internal
1102              * implementations are different:  The actions file is stored
1103              * in the same order as the file, and scanned completely.
1104              * With the ACL, we reverse the order as we load it, then
1105              * when we scan it we stop as soon as we get a match.
1106              */
1107             cur_acl->next  = config->acl;
1108             config->acl = cur_acl;
1109
1110             break;
1111 #endif /* def FEATURE_ACL */
1112
1113 /* *************************************************************************
1114  * enable-edit-actions 0|1
1115  * *************************************************************************/
1116 #ifdef FEATURE_CGI_EDIT_ACTIONS
1117          case hash_enable_edit_actions:
1118             if ((*arg != '\0') && (0 != atoi(arg)))
1119             {
1120                config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1121             }
1122             else
1123             {
1124                config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1125             }
1126             break;
1127 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1128
1129 /* *************************************************************************
1130  * enable-remote-toggle 0|1
1131  * *************************************************************************/
1132 #ifdef FEATURE_TOGGLE
1133          case hash_enable_remote_toggle:
1134             if ((*arg != '\0') && (0 != atoi(arg)))
1135             {
1136                config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1137             }
1138             else
1139             {
1140                config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1141             }
1142             break;
1143 #endif /* def FEATURE_TOGGLE */
1144
1145 /* *************************************************************************
1146  * enable-remote-http-toggle 0|1
1147  * *************************************************************************/
1148          case hash_enable_remote_http_toggle:
1149             if ((*arg != '\0') && (0 != atoi(arg)))
1150             {
1151                config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1152             }
1153             else
1154             {
1155                config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1156             }
1157             break;
1158
1159 /* *************************************************************************
1160  * enforce-blocks 0|1
1161  * *************************************************************************/
1162          case hash_enforce_blocks:
1163 #ifdef FEATURE_FORCE_LOAD
1164             if ((*arg != '\0') && (0 != atoi(arg)))
1165             {
1166                config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1167             }
1168             else
1169             {
1170                config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1171             }
1172 #else
1173             log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1174                "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1175 #endif /* def FEATURE_FORCE_LOAD */
1176             break;
1177
1178 /* *************************************************************************
1179  * filterfile file-name
1180  * In confdir by default.
1181  * *************************************************************************/
1182          case hash_filterfile :
1183             i = 0;
1184             while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1185             {
1186                i++;
1187             }
1188
1189             if (i >= MAX_AF_FILES)
1190             {
1191                log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1192                   "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1193                   MAX_AF_FILES);
1194             }
1195             config->re_filterfile_short[i] = strdup(arg);
1196             config->re_filterfile[i] = make_path(config->confdir, arg);
1197
1198             break;
1199
1200 /* *************************************************************************
1201  * forward url-pattern (.|http-proxy-host[:port])
1202  * *************************************************************************/
1203          case hash_forward:
1204             strlcpy(tmp, arg, sizeof(tmp));
1205             vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1206
1207             if (vec_count != 2)
1208             {
1209                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1210                      "directive in configuration file.");
1211                string_append(&config->proxy_args,
1212                   "<br>\nWARNING: Wrong number of parameters for "
1213                   "forward directive in configuration file.");
1214                break;
1215             }
1216
1217             /* allocate a new node */
1218             cur_fwd = zalloc(sizeof(*cur_fwd));
1219             if (cur_fwd == NULL)
1220             {
1221                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1222                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1223                break;
1224             }
1225
1226             cur_fwd->type = SOCKS_NONE;
1227
1228             /* Save the URL pattern */
1229             if (create_url_spec(cur_fwd->url, vec[0]))
1230             {
1231                log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1232                      "directive in configuration file.");
1233                string_append(&config->proxy_args,
1234                   "<br>\nWARNING: Bad URL specifier for "
1235                   "forward directive in configuration file.");
1236                break;
1237             }
1238
1239             /* Parse the parent HTTP proxy host:port */
1240             p = vec[1];
1241
1242             if (strcmp(p, ".") != 0)
1243             {
1244                cur_fwd->forward_port = 8000;
1245                parse_forwarder_address(p, &cur_fwd->forward_host,
1246                   &cur_fwd->forward_port);
1247             }
1248
1249             /* Add to list. */
1250             cur_fwd->next = config->forward;
1251             config->forward = cur_fwd;
1252
1253             break;
1254
1255 /* *************************************************************************
1256  * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1257  * *************************************************************************/
1258          case hash_forward_socks4:
1259             strlcpy(tmp, arg, sizeof(tmp));
1260             vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1261
1262             if (vec_count != 3)
1263             {
1264                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1265                      "forward-socks4 directive in configuration file.");
1266                string_append(&config->proxy_args,
1267                   "<br>\nWARNING: Wrong number of parameters for "
1268                   "forward-socks4 directive in configuration file.");
1269                break;
1270             }
1271
1272             /* allocate a new node */
1273             cur_fwd = zalloc(sizeof(*cur_fwd));
1274             if (cur_fwd == NULL)
1275             {
1276                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1277                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1278                break;
1279             }
1280
1281             cur_fwd->type = SOCKS_4;
1282
1283             /* Save the URL pattern */
1284             if (create_url_spec(cur_fwd->url, vec[0]))
1285             {
1286                log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1287                      "directive in configuration file.");
1288                string_append(&config->proxy_args,
1289                   "<br>\nWARNING: Bad URL specifier for "
1290                   "forward-socks4 directive in configuration file.");
1291                break;
1292             }
1293
1294             /* Parse the SOCKS proxy host[:port] */
1295             p = vec[1];
1296
1297             /* XXX: This check looks like a bug. */
1298             if (strcmp(p, ".") != 0)
1299             {
1300                cur_fwd->gateway_port = 1080;
1301                parse_forwarder_address(p, &cur_fwd->gateway_host,
1302                   &cur_fwd->gateway_port);
1303             }
1304
1305             /* Parse the parent HTTP proxy host[:port] */
1306             p = vec[2];
1307
1308             if (strcmp(p, ".") != 0)
1309             {
1310                cur_fwd->forward_port = 8000;
1311                parse_forwarder_address(p, &cur_fwd->forward_host,
1312                   &cur_fwd->forward_port);
1313             }
1314
1315             /* Add to list. */
1316             cur_fwd->next = config->forward;
1317             config->forward = cur_fwd;
1318
1319             break;
1320
1321 /* *************************************************************************
1322  * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1323  * *************************************************************************/
1324          case hash_forward_socks4a:
1325          case hash_forward_socks5:
1326             strlcpy(tmp, arg, sizeof(tmp));
1327             vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1328
1329             if (vec_count != 3)
1330             {
1331                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1332                      "forward-socks4a directive in configuration file.");
1333                string_append(&config->proxy_args,
1334                   "<br>\nWARNING: Wrong number of parameters for "
1335                   "forward-socks4a directive in configuration file.");
1336                break;
1337             }
1338
1339             /* allocate a new node */
1340             cur_fwd = zalloc(sizeof(*cur_fwd));
1341             if (cur_fwd == NULL)
1342             {
1343                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1344                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1345                break;
1346             }
1347
1348             if (directive_hash == hash_forward_socks4a)
1349             {
1350                cur_fwd->type = SOCKS_4A;
1351             }
1352             else
1353             {
1354                cur_fwd->type = SOCKS_5;
1355             }
1356
1357             /* Save the URL pattern */
1358             if (create_url_spec(cur_fwd->url, vec[0]))
1359             {
1360                log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1361                      "directive in configuration file.");
1362                string_append(&config->proxy_args,
1363                   "<br>\nWARNING: Bad URL specifier for "
1364                   "forward-socks4a directive in configuration file.");
1365                break;
1366             }
1367
1368             /* Parse the SOCKS proxy host[:port] */
1369             p = vec[1];
1370
1371             cur_fwd->gateway_port = 1080;
1372             parse_forwarder_address(p, &cur_fwd->gateway_host,
1373                &cur_fwd->gateway_port);
1374
1375             /* Parse the parent HTTP proxy host[:port] */
1376             p = vec[2];
1377
1378             if (strcmp(p, ".") != 0)
1379             {
1380                cur_fwd->forward_port = 8000;
1381                parse_forwarder_address(p, &cur_fwd->forward_host,
1382                   &cur_fwd->forward_port);
1383             }
1384
1385             /* Add to list. */
1386             cur_fwd->next = config->forward;
1387             config->forward = cur_fwd;
1388
1389             break;
1390
1391 /* *************************************************************************
1392  * forwarded-connect-retries n
1393  * *************************************************************************/
1394          case hash_forwarded_connect_retries :
1395             config->forwarded_connect_retries = atoi(arg);
1396             break;
1397
1398 /* *************************************************************************
1399  * hostname hostname-to-show-on-cgi-pages
1400  * *************************************************************************/
1401          case hash_hostname :
1402             freez(config->hostname);
1403             config->hostname = strdup(arg);
1404             if (NULL == config->hostname)
1405             {
1406                log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1407             }
1408             break;
1409
1410 /* *************************************************************************
1411  * keep-alive-timeout timeout
1412  * *************************************************************************/
1413 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1414          case hash_keep_alive_timeout :
1415             if (*arg != '\0')
1416             {
1417                int timeout = atoi(arg);
1418                if (0 <= timeout)
1419                {
1420                   config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1421                   config->keep_alive_timeout = (unsigned int)timeout;
1422                }
1423                else
1424                {
1425                   config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1426                }
1427             }
1428             break;
1429 #endif
1430
1431 /* *************************************************************************
1432  * listen-address [ip][:port]
1433  * *************************************************************************/
1434          case hash_listen_address :
1435             freez(config->haddr);
1436             config->haddr = strdup(arg);
1437             break;
1438
1439 /* *************************************************************************
1440  * logdir directory-name
1441  * *************************************************************************/
1442          case hash_logdir :
1443             freez(config->logdir);
1444             config->logdir = make_path(NULL, arg);
1445             break;
1446
1447 /* *************************************************************************
1448  * logfile log-file-name
1449  * In logdir by default
1450  * *************************************************************************/
1451          case hash_logfile :
1452             if (!no_daemon)
1453             {
1454                logfile = make_path(config->logdir, arg);
1455                if (NULL == logfile)
1456                {
1457                   log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1458                }
1459             }
1460             break;
1461
1462 /* *************************************************************************
1463  * max-client-connections number
1464  * *************************************************************************/
1465          case hash_max_client_connections :
1466             if (*arg != '\0')
1467             {
1468                int max_client_connections = atoi(arg);
1469                if (0 <= max_client_connections)
1470                {
1471                   config->max_client_connections = max_client_connections;
1472                }
1473             }
1474             break;
1475
1476 /* *************************************************************************
1477  * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1478  * *************************************************************************/
1479 #ifdef FEATURE_ACL
1480          case hash_permit_access:
1481             strlcpy(tmp, arg, sizeof(tmp));
1482             vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1483
1484             if ((vec_count != 1) && (vec_count != 2))
1485             {
1486                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1487                      "permit-access directive in configuration file.");
1488                string_append(&config->proxy_args,
1489                   "<br>\nWARNING: Wrong number of parameters for "
1490                   "permit-access directive in configuration file.<br><br>\n");
1491
1492                break;
1493             }
1494
1495             /* allocate a new node */
1496             cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1497
1498             if (cur_acl == NULL)
1499             {
1500                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1501                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1502                break;
1503             }
1504             cur_acl->action = ACL_PERMIT;
1505
1506             if (acl_addr(vec[0], cur_acl->src) < 0)
1507             {
1508                log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1509                   "for permit-access directive in configuration file: \"%s\"", vec[0]);
1510                string_append(&config->proxy_args,
1511                   "<br>\nWARNING: Invalid source address, port or netmask for "
1512                   "permit-access directive in configuration file: \"");
1513                string_append(&config->proxy_args,
1514                   vec[0]);
1515                string_append(&config->proxy_args,
1516                   "\"<br><br>\n");
1517                freez(cur_acl);
1518                break;
1519             }
1520             if (vec_count == 2)
1521             {
1522                if (acl_addr(vec[1], cur_acl->dst) < 0)
1523                {
1524                   log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1525                      "for permit-access directive in configuration file: \"%s\"", vec[1]);
1526                   string_append(&config->proxy_args,
1527                      "<br>\nWARNING: Invalid destination address, port or netmask for "
1528                      "permit-access directive in configuration file: \"");
1529                   string_append(&config->proxy_args,
1530                      vec[1]);
1531                   string_append(&config->proxy_args,
1532                      "\"<br><br>\n");
1533                   freez(cur_acl);
1534                   break;
1535                }
1536             }
1537 #ifdef HAVE_RFC2553
1538             else
1539             {
1540                cur_acl->wildcard_dst = 1;
1541             }
1542 #endif /* def HAVE_RFC2553 */
1543
1544             /*
1545              * Add it to the list.  Note we reverse the list to get the
1546              * behaviour the user expects.  With both the ACL and
1547              * actions file, the last match wins.  However, the internal
1548              * implementations are different:  The actions file is stored
1549              * in the same order as the file, and scanned completely.
1550              * With the ACL, we reverse the order as we load it, then
1551              * when we scan it we stop as soon as we get a match.
1552              */
1553             cur_acl->next  = config->acl;
1554             config->acl = cur_acl;
1555
1556             break;
1557 #endif /* def FEATURE_ACL */
1558
1559 /* *************************************************************************
1560  * proxy-info-url url
1561  * *************************************************************************/
1562          case hash_proxy_info_url :
1563             freez(config->proxy_info_url);
1564             config->proxy_info_url = strdup(arg);
1565             break;
1566
1567 /* *************************************************************************
1568  * single-threaded
1569  * *************************************************************************/
1570          case hash_single_threaded :
1571             config->multi_threaded = 0;
1572             break;
1573
1574 /* *************************************************************************
1575  * socket-timeout numer_of_seconds
1576  * *************************************************************************/
1577          case hash_socket_timeout :
1578             if (*arg != '\0')
1579             {
1580                int socket_timeout = atoi(arg);
1581                if (0 < socket_timeout)
1582                {
1583                   config->socket_timeout = socket_timeout;
1584                }
1585                else
1586                {
1587                   log_error(LOG_LEVEL_FATAL,
1588                      "Invalid socket-timeout: '%s'", arg);
1589                }
1590             }
1591             break;
1592
1593 /* *************************************************************************
1594  * split-large-cgi-forms
1595  * *************************************************************************/
1596          case hash_split_large_cgi_forms :
1597             if ((*arg != '\0') && (0 != atoi(arg)))
1598             {
1599                config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1600             }
1601             else
1602             {
1603                config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1604             }
1605             break;
1606
1607 /* *************************************************************************
1608  * templdir directory-name
1609  * *************************************************************************/
1610          case hash_templdir :
1611             freez(config->templdir);
1612             config->templdir = make_path(NULL, arg);
1613             break;
1614
1615 /* *************************************************************************
1616  * toggle (0|1)
1617  * *************************************************************************/
1618 #ifdef FEATURE_TOGGLE
1619          case hash_toggle :
1620             global_toggle_state = atoi(arg);
1621             break;
1622 #endif /* def FEATURE_TOGGLE */
1623
1624 /* *************************************************************************
1625  * trust-info-url url
1626  * *************************************************************************/
1627 #ifdef FEATURE_TRUST
1628          case hash_trust_info_url :
1629             enlist(config->trust_info, arg);
1630             break;
1631 #endif /* def FEATURE_TRUST */
1632
1633 /* *************************************************************************
1634  * trustfile filename
1635  * (In confdir by default.)
1636  * *************************************************************************/
1637 #ifdef FEATURE_TRUST
1638          case hash_trustfile :
1639             freez(config->trustfile);
1640             config->trustfile = make_path(config->confdir, arg);
1641             break;
1642 #endif /* def FEATURE_TRUST */
1643
1644 /* *************************************************************************
1645  * usermanual url
1646  * *************************************************************************/
1647          case hash_usermanual :
1648             /*
1649              * XXX: If this isn't the first config directive, the
1650              * show-status page links to the website documentation
1651              * for the directives that were already parsed. Lame.
1652              */
1653             freez(config->usermanual);
1654             config->usermanual = strdup(arg);
1655             break;
1656
1657 /* *************************************************************************
1658  * Win32 Console options:
1659  * *************************************************************************/
1660
1661 /* *************************************************************************
1662  * hide-console
1663  * *************************************************************************/
1664 #ifdef _WIN_CONSOLE
1665          case hash_hide_console :
1666             hideConsole = 1;
1667             break;
1668 #endif /*def _WIN_CONSOLE*/
1669
1670
1671 /* *************************************************************************
1672  * Win32 GUI options:
1673  * *************************************************************************/
1674
1675 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1676 /* *************************************************************************
1677  * activity-animation (0|1)
1678  * *************************************************************************/
1679          case hash_activity_animation :
1680             g_bShowActivityAnimation = atoi(arg);
1681             break;
1682
1683 /* *************************************************************************
1684  *  close-button-minimizes (0|1)
1685  * *************************************************************************/
1686          case hash_close_button_minimizes :
1687             g_bCloseHidesWindow = atoi(arg);
1688             break;
1689
1690 /* *************************************************************************
1691  * log-buffer-size (0|1)
1692  * *************************************************************************/
1693          case hash_log_buffer_size :
1694             g_bLimitBufferSize = atoi(arg);
1695             break;
1696
1697 /* *************************************************************************
1698  * log-font-name fontname
1699  * *************************************************************************/
1700          case hash_log_font_name :
1701             if (strlcpy(g_szFontFaceName, arg,
1702                    sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1703             {
1704                log_error(LOG_LEVEL_FATAL,
1705                   "log-font-name argument '%s' is longer than %u characters.",
1706                   arg, sizeof(g_szFontFaceName)-1);
1707             }
1708             break;
1709
1710 /* *************************************************************************
1711  * log-font-size n
1712  * *************************************************************************/
1713          case hash_log_font_size :
1714             g_nFontSize = atoi(arg);
1715             break;
1716
1717 /* *************************************************************************
1718  * log-highlight-messages (0|1)
1719  * *************************************************************************/
1720          case hash_log_highlight_messages :
1721             g_bHighlightMessages = atoi(arg);
1722             break;
1723
1724 /* *************************************************************************
1725  * log-max-lines n
1726  * *************************************************************************/
1727          case hash_log_max_lines :
1728             g_nMaxBufferLines = atoi(arg);
1729             break;
1730
1731 /* *************************************************************************
1732  * log-messages (0|1)
1733  * *************************************************************************/
1734          case hash_log_messages :
1735             g_bLogMessages = atoi(arg);
1736             break;
1737
1738 /* *************************************************************************
1739  * show-on-task-bar (0|1)
1740  * *************************************************************************/
1741          case hash_show_on_task_bar :
1742             g_bShowOnTaskBar = atoi(arg);
1743             break;
1744
1745 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1746
1747
1748 /* *************************************************************************
1749  * Warnings about unsupported features
1750  * *************************************************************************/
1751 #ifndef FEATURE_ACL
1752          case hash_deny_access:
1753 #endif /* ndef FEATURE_ACL */
1754 #ifndef FEATURE_CGI_EDIT_ACTIONS
1755          case hash_enable_edit_actions:
1756 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1757 #ifndef FEATURE_TOGGLE
1758          case hash_enable_remote_toggle:
1759 #endif /* ndef FEATURE_TOGGLE */
1760 #ifndef FEATURE_ACL
1761          case hash_permit_access:
1762 #endif /* ndef FEATURE_ACL */
1763 #ifndef FEATURE_TOGGLE
1764          case hash_toggle :
1765 #endif /* ndef FEATURE_TOGGLE */
1766 #ifndef FEATURE_TRUST
1767          case hash_trustfile :
1768          case hash_trust_info_url :
1769 #endif /* ndef FEATURE_TRUST */
1770
1771 #ifndef _WIN_CONSOLE
1772          case hash_hide_console :
1773 #endif /* ndef _WIN_CONSOLE */
1774
1775 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1776          case hash_activity_animation :
1777          case hash_close_button_minimizes :
1778          case hash_log_buffer_size :
1779          case hash_log_font_name :
1780          case hash_log_font_size :
1781          case hash_log_highlight_messages :
1782          case hash_log_max_lines :
1783          case hash_log_messages :
1784          case hash_show_on_task_bar :
1785 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1786             /* These warnings are annoying - so hide them. -- Jon */
1787             /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1788             break;
1789
1790 /* *************************************************************************/
1791          default :
1792 /* *************************************************************************/
1793             /*
1794              * I decided that I liked this better as a warning than an
1795              * error.  To change back to an error, just change log level
1796              * to LOG_LEVEL_FATAL.
1797              */
1798             log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1799                   "in configuration file (%s).",  buf, directive_hash, linenum, configfile);
1800             string_append(&config->proxy_args,
1801                " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1802             break;
1803
1804 /* *************************************************************************/
1805       } /* end switch( hash_string(cmd) ) */
1806
1807       /* Save the argument for the show-status page. */
1808       savearg(cmd, arg, config);
1809
1810    } /* end while ( read_config_line(...) ) */
1811
1812    fclose(configfp);
1813
1814    set_debug_level(config->debug);
1815
1816    freez(config->logfile);
1817
1818    if (!no_daemon)
1819    {
1820       if (NULL != logfile)
1821       {
1822          config->logfile = logfile;
1823          init_error_log(Argv[0], config->logfile);
1824       }
1825       else
1826       {
1827          disable_logging();
1828       }
1829    }
1830
1831 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1832    if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1833    {
1834       if (config->multi_threaded)
1835       {
1836          set_keep_alive_timeout(config->keep_alive_timeout);
1837       }
1838       else
1839       {
1840          /*
1841           * While we could use keep-alive without multiple threads
1842           * if we didn't bother with enforcing the connection timeout,
1843           * that might make Tor users sad, even though they shouldn't
1844           * enable the single-threaded option anyway.
1845           *
1846           * XXX: We could still use Proxy-Connection: keep-alive.
1847           */
1848          config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1849          log_error(LOG_LEVEL_ERROR,
1850             "Config option single-threaded disables connection keep-alive.");
1851       }
1852    }
1853 #endif
1854
1855    if (NULL == config->proxy_args)
1856    {
1857       log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1858    }
1859
1860    if (config->actions_file[0])
1861    {
1862       add_loader(load_action_files, config);
1863    }
1864
1865    if (config->re_filterfile[0])
1866    {
1867       add_loader(load_re_filterfiles, config);
1868    }
1869
1870 #ifdef FEATURE_TRUST
1871    if (config->trustfile)
1872    {
1873       add_loader(load_trustfile, config);
1874    }
1875 #endif /* def FEATURE_TRUST */
1876
1877    if ( NULL == config->haddr )
1878    {
1879       config->haddr = strdup( HADDR_DEFAULT );
1880    }
1881
1882    if ( NULL != config->haddr )
1883    {
1884       if ((*config->haddr == '[')
1885          && (NULL != (p = strchr(config->haddr, ']')))
1886          && (p[1] == ':')
1887          && (0 < (config->hport = atoi(p + 2))))
1888       {
1889          *p = '\0';
1890          memmove((void *)config->haddr, config->haddr + 1,
1891             (size_t)(p - config->haddr));
1892       }
1893       else if (NULL != (p = strchr(config->haddr, ':'))
1894          && (0 < (config->hport = atoi(p + 1))))
1895       {
1896          *p = '\0';
1897       }
1898       else
1899       {
1900          log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1901          /* Never get here - LOG_LEVEL_FATAL causes program exit */
1902       }
1903       if (*config->haddr == '\0')
1904       {
1905          /*
1906           * Only the port specified. We stored it in config->hport
1907           * and don't need its text representation anymore.
1908           */
1909          freez(config->haddr);
1910       }
1911    }
1912
1913    /*
1914     * Want to run all the loaders once now.
1915     *
1916     * Need to set up a fake csp, so they can get to the config.
1917     */
1918    fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1919    fake_csp->config = config;
1920
1921    if (run_loader(fake_csp))
1922    {
1923       freez(fake_csp);
1924       log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1925       /* Never get here - LOG_LEVEL_FATAL causes program exit */
1926    }
1927    freez(fake_csp);
1928
1929 /* FIXME: this is a kludge for win32 */
1930 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1931
1932    g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1933    g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1934    g_re_filterfile    = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1935
1936 #ifdef FEATURE_TRUST
1937    g_trustfile        = config->trustfile;
1938 #endif /* def FEATURE_TRUST */
1939
1940
1941 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1942 /* FIXME: end kludge */
1943
1944
1945    config->need_bind = 1;
1946
1947    if (current_configfile)
1948    {
1949       struct configuration_spec * oldcfg = (struct configuration_spec *)
1950                                            current_configfile->f;
1951       /*
1952        * Check if config->haddr,hport == oldcfg->haddr,hport
1953        *
1954        * The following could be written more compactly as a single,
1955        * (unreadably long) if statement.
1956        */
1957       config->need_bind = 0;
1958       if (config->hport != oldcfg->hport)
1959       {
1960          config->need_bind = 1;
1961       }
1962       else if (config->haddr == NULL)
1963       {
1964          if (oldcfg->haddr != NULL)
1965          {
1966             config->need_bind = 1;
1967          }
1968       }
1969       else if (oldcfg->haddr == NULL)
1970       {
1971          config->need_bind = 1;
1972       }
1973       else if (0 != strcmp(config->haddr, oldcfg->haddr))
1974       {
1975          config->need_bind = 1;
1976       }
1977
1978       current_configfile->unloader = unload_configfile;
1979    }
1980
1981    fs->next = files->next;
1982    files->next = fs;
1983
1984    current_configfile = fs;
1985
1986    return (config);
1987 }
1988
1989
1990 /*********************************************************************
1991  *
1992  * Function    :  savearg
1993  *
1994  * Description :  Called from `load_config'.  It saves each non-empty
1995  *                and non-comment line from config into
1996  *                config->proxy_args.  This is used to create the
1997  *                show-proxy-args page.  On error, frees
1998  *                config->proxy_args and sets it to NULL
1999  *
2000  * Parameters  :
2001  *          1  :  command = config setting that was found
2002  *          2  :  argument = the setting's argument (if any)
2003  *          3  :  config = Configuration to save into.
2004  *
2005  * Returns     :  N/A
2006  *
2007  *********************************************************************/
2008 static void savearg(char *command, char *argument, struct configuration_spec * config)
2009 {
2010    char * buf;
2011    char * s;
2012
2013    assert(command);
2014    assert(argument);
2015
2016    /*
2017     * Add config option name embedded in
2018     * link to its section in the user-manual
2019     */
2020    buf = strdup("\n<a href=\"");
2021    if (!strncmpic(config->usermanual, "file://", 7) ||
2022        !strncmpic(config->usermanual, "http", 4))
2023    {
2024       string_append(&buf, config->usermanual);
2025    }
2026    else
2027    {
2028       string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
2029    }
2030    string_append(&buf, CONFIG_HELP_PREFIX);
2031    string_join  (&buf, string_toupper(command));
2032    string_append(&buf, "\">");
2033    string_append(&buf, command);
2034    string_append(&buf, "</a> ");
2035
2036    if (NULL == buf)
2037    {
2038       freez(config->proxy_args);
2039       return;
2040    }
2041
2042    if ( (NULL != argument) && ('\0' != *argument) )
2043    {
2044       s = html_encode(argument);
2045       if (NULL == s)
2046       {
2047          freez(buf);
2048          freez(config->proxy_args);
2049          return;
2050       }
2051
2052       if (strncmpic(argument, "http://", 7) == 0)
2053       {
2054          string_append(&buf, "<a href=\"");
2055          string_append(&buf, s);
2056          string_append(&buf, "\">");
2057          string_join  (&buf, s);
2058          string_append(&buf, "</a>");
2059       }
2060       else
2061       {
2062          string_join  (&buf, s);
2063       }
2064    }
2065
2066    string_append(&buf, "<br>");
2067    string_join(&config->proxy_args, buf);
2068 }
2069
2070
2071 /*
2072   Local Variables:
2073   tab-width: 3
2074   end:
2075 */