Surprised adjuggler.com hasn't been flagged before now
[privoxy.git] / loadcfg.c
1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.99 2009/05/10 10:12:30 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.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.
41  *
42  *    Revision 1.98  2009/04/24 15:29:43  fabiankeil
43  *    Allow to limit the number of of client connections.
44  *
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.
48  *
49  *    Revision 1.96  2009/04/17 11:38:28  fabiankeil
50  *    Add and use parse_forwarder_address() to reduce code duplication.
51  *
52  *    Revision 1.95  2009/04/17 11:34:34  fabiankeil
53  *    Style cosmetics for the IPv6 code.
54  *
55  *    Revision 1.94  2009/04/17 11:27:49  fabiankeil
56  *    Petr Pisar's privoxy-3.0.12-ipv6-3.diff.
57  *
58  *    Revision 1.93  2009/03/18 21:46:26  fabiankeil
59  *    Revert the last commit as there's a better way.
60  *
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.
65  *
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.
70  *
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.
75  *
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.
80  *
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
84  *    directive itself.
85  *
86  *    Revision 1.87  2009/02/15 07:56:13  fabiankeil
87  *    Increase default socket timeout to 300 seconds.
88  *
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.
94  *
95  *    Revision 1.85  2009/01/22 12:06:26  fabiankeil
96  *    Don't keep connections alive when running single-threaded.
97  *
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.
102  *
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.
107  *
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.
112  *
113  *    Revision 1.81  2008/11/13 09:08:42  fabiankeil
114  *    Add new config option: keep-alive-timeout.
115  *
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.
119  *
120  *    Revision 1.79  2008/08/30 12:03:07  fabiankeil
121  *    Remove FEATURE_COOKIE_JAR.
122  *
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.
128  *
129  *    Revision 1.77  2008/05/26 16:13:22  fabiankeil
130  *    Reuse directive_hash and don't hash the same directive twice.
131  *
132  *    Revision 1.76  2008/05/10 09:03:16  fabiankeil
133  *    - Merge three string_append() calls.
134  *    - Remove useless assertion.
135  *
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".
139  *
140  *    Revision 1.74  2008/03/26 18:07:07  fabiankeil
141  *    Add hostname directive. Closes PR#1918189.
142  *
143  *    Revision 1.73  2008/02/16 16:54:51  fabiankeil
144  *    Fix typo.
145  *
146  *    Revision 1.72  2008/02/03 13:46:15  fabiankeil
147  *    Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
148  *
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.
152  *
153  *    Revision 1.70  2007/12/15 14:24:05  fabiankeil
154  *    Plug memory leak if listen-address only specifies the port.
155  *
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.
159  *
160  *    Revision 1.68  2007/10/19 16:32:34  fabiankeil
161  *    Plug memory leak introduced with my last commit.
162  *
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.
166  *
167  *    Revision 1.66  2007/08/05 14:02:09  fabiankeil
168  *    #1763173 from Stefan Huehner: declare unload_configfile() static.
169  *
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".
175  *
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.
180  *      Closes FR#588084.
181  *    - Remove an unnecessary temporary memory allocation.
182  *    - Don't log anything to the console when running as
183  *      daemon and no errors occurred.
184  *
185  *    Revision 1.63  2007/04/09 18:11:36  fabiankeil
186  *    Don't mistake VC++'s _snprintf() for a snprintf() replacement.
187  *
188  *    Revision 1.62  2007/03/17 15:20:05  fabiankeil
189  *    New config option: enforce-blocks.
190  *
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.
194  *
195  *    Revision 1.60  2007/01/27 13:09:16  fabiankeil
196  *    Add new config option "templdir" to
197  *    change the templates directory.
198  *
199  *    Revision 1.59  2006/12/31 17:56:38  fabiankeil
200  *    Added config option accept-intercepted-requests
201  *    and disabled it by default.
202  *
203  *    Revision 1.58  2006/12/31 14:24:29  fabiankeil
204  *    Fix gcc43 compiler warnings.
205  *
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
209  *    in BR #1570678.
210  *
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.
215  *
216  *    Revision 1.55  2006/11/28 15:31:52  fabiankeil
217  *    Fix memory leak in case of config file reloads.
218  *
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.
223  *    Fixes BR 1567373.
224  *
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.
228  *
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.
233  *
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.
239  *
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
243  *    default.
244  *
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)
248  *
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...
251  *
252  *    Revision 1.48.2.6  2006/01/29 23:10:56  david__schmidt
253  *    Multiple filter file support
254  *
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).
258  *
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
263  *
264  *    Revision 1.48.2.3  2003/03/11 11:53:59  oes
265  *    Cosmetic: Renamed cryptic variable
266  *
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
269  *
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)
272  *
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
275  *
276  *    Revision 1.47  2002/05/12 21:36:29  jongfoster
277  *    Correcting function comments
278  *
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
283  *
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
286  *
287  *    Revision 1.44  2002/04/08 20:37:13  swa
288  *    fixed JB spelling
289  *
290  *    Revision 1.43  2002/04/08 20:36:50  swa
291  *    fixed JB spelling
292  *
293  *    Revision 1.42  2002/04/05 15:50:15  oes
294  *    fix for invalid HTML proxy_args
295  *
296  *    Revision 1.41  2002/03/31 17:19:00  jongfoster
297  *    Win32 only: Enabling STRICT to fix a VC++ compile warning.
298  *
299  *    Revision 1.40  2002/03/26 22:29:55  swa
300  *    we have a new homepage!
301  *
302  *    Revision 1.39  2002/03/24 13:25:43  swa
303  *    name change related issues
304  *
305  *    Revision 1.38  2002/03/24 13:05:48  jongfoster
306  *    Renaming re_filterfile to filterfile
307  *
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.
314  *
315  *    Revision 1.36  2002/03/13 00:27:05  jongfoster
316  *    Killing warnings
317  *
318  *    Revision 1.35  2002/03/07 03:52:44  oes
319  *    Set logging to tty for --no-daemon mode
320  *
321  *    Revision 1.34  2002/03/06 23:14:35  jongfoster
322  *    Trivial cosmetic changes to make function comments easier to find.
323  *
324  *    Revision 1.33  2002/03/05 04:52:42  oes
325  *    Deleted non-errlog debugging code
326  *
327  *    Revision 1.32  2002/03/04 18:24:53  oes
328  *    Re-enabled output of unknown config directive hash
329  *
330  *    Revision 1.31  2002/03/03 15:07:20  oes
331  *    Re-enabled automatic config reloading
332  *
333  *    Revision 1.30  2002/01/22 23:31:43  jongfoster
334  *    Replacing strsav() with string_append()
335  *
336  *    Revision 1.29  2002/01/17 21:02:30  jongfoster
337  *    Moving all our URL and URL pattern parsing code to urlmatch.c.
338  *
339  *    Renaming free_url to free_url_spec, since it frees a struct url_spec.
340  *
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)
348  *
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.
353  *
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.
358  *    Add DBG() Macro.
359  *    Add some fatal-error log message for failed malloc().
360  *    Add '-d' if compiled with 'configure --with-debug' to
361  *    enable debug output.
362  *
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.
368  *
369  *    Revision 1.24  2001/10/23 21:40:30  jongfoster
370  *    Added support for enable-edit-actions and enable-remote-toggle config
371  *    file options.
372  *
373  *    Revision 1.23  2001/10/07 15:36:00  oes
374  *    Introduced new config option "buffer-limit"
375  *
376  *    Revision 1.22  2001/09/22 16:36:59  jongfoster
377  *    Removing unused parameter fs from read_config_line()
378  *
379  *    Revision 1.21  2001/09/16 17:10:43  jongfoster
380  *    Moving function savearg() here, since it was the only thing left in
381  *    showargs.c.
382  *
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
388  *
389  *    Revision 1.19  2001/07/15 17:45:16  jongfoster
390  *    Removing some unused #includes
391  *
392  *    Revision 1.18  2001/07/13 14:01:14  oes
393  *     - Removed all #ifdef PCRS
394  *     - Removed vim-settings
395  *
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
405  *
406  *    Revision 1.16  2001/06/09 10:55:28  jongfoster
407  *    Changing BUFSIZ ==> BUFFER_SIZE
408  *
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.
413  *
414  *    Revision 1.14  2001/06/07 14:46:25  joergs
415  *    Missing make_path() added for re_filterfile.
416  *
417  *    Revision 1.13  2001/06/05 22:33:54  jongfoster
418  *
419  *    Fixed minor memory leak.
420  *    Also now uses make_path to prepend the pathnames.
421  *
422  *    Revision 1.12  2001/06/05 20:04:09  jongfoster
423  *    Now uses _snprintf() in place of snprintf() under Win32.
424  *
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
428  *    with redhat values
429  *
430  *    Revision 1.10  2001/06/03 19:11:54  oes
431  *    introduced confdir option
432  *
433  *    Revision 1.9  2001/06/01 20:06:24  jongfoster
434  *    Removed support for "tinygif" option - moved to actions file.
435  *
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".
441  *
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
445  *    are (mostly) done.
446  *
447  *    Also modified interceptor behaviour:
448  *    - We now intercept all URLs beginning with one of the following
449  *      prefixes (and *only* these prefixes):
450  *        * http://i.j.b/
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
463  *      it with an image.)
464  *
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.
471  *
472  *    Revision 1.5  2001/05/25 22:34:30  jongfoster
473  *    Hard tabs->Spaces
474  *
475  *    Revision 1.4  2001/05/22 18:46:04  oes
476  *
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
480  *
481  *    - Enabled filtering WebBugs by providing a pattern
482  *      which kills all 1x1 images
483  *
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 (!).
489  *
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.
495  *
496  *    - Added new feature, which permits blocking remote
497  *      script redirects and firing back a local redirect
498  *      to the browser.
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 :-(
507  *
508  *    - Because a generic redirect template was needed for
509  *      this, tinygif = 3 now uses the same.
510  *
511  *    - Moved GIFs, and other static HTTP response templates
512  *      to project.h
513  *
514  *    - Some minor fixes
515  *
516  *    - Removed some >400 CRs again (Jon, you really worked
517  *      a lot! ;-)
518  *
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
527  *      skipping.
528  *    - Removed tabs from "config"
529  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
530  *    - Bumped up version number.
531  *
532  *    Revision 1.2  2001/05/17 23:01:01  oes
533  *     - Cleaned CRLF's from the sources and related files
534  *
535  *    Revision 1.1.1.1  2001/05/15 13:58:58  oes
536  *    Initial import of version 2.9.3 source tree
537  *
538  *
539  *********************************************************************/
540 \f
541
542 #include "config.h"
543
544 #include <stdio.h>
545 #include <sys/types.h>
546 #include <stdlib.h>
547 #include <string.h>
548 #include <signal.h>
549 #include <fcntl.h>
550 #include <errno.h>
551 #include <ctype.h>
552 #include <assert.h>
553
554 #ifdef _WIN32
555
556 # ifndef STRICT
557 #  define STRICT
558 # endif
559 # include <windows.h>
560
561 # include "win32.h"
562 # ifndef _WIN_CONSOLE
563 #  include "w32log.h"
564 # endif /* ndef _WIN_CONSOLE */
565
566 #else /* ifndef _WIN32 */
567
568 #ifndef __OS2__
569 # include <unistd.h>
570 # include <sys/wait.h>
571 #endif
572 # include <sys/time.h>
573 # include <sys/stat.h>
574 # include <signal.h>
575
576 #endif
577
578 #include "loadcfg.h"
579 #include "list.h"
580 #include "jcc.h"
581 #include "filters.h"
582 #include "loaders.h"
583 #include "miscutil.h"
584 #include "errlog.h"
585 #include "ssplit.h"
586 #include "encode.h"
587 #include "urlmatch.h"
588 #include "cgi.h"
589 #include "gateway.h"
590
591 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
592
593 /*
594  * Fix a problem with Solaris.  There should be no effect on other
595  * platforms.
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".
600  */
601 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
602 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
603
604 #ifdef FEATURE_TOGGLE
605 /* Privoxy is enabled by default. */
606 int global_toggle_state = 1;
607 #endif /* def FEATURE_TOGGLE */
608
609 /* The filename of the configfile */
610 const char *configfile  = NULL;
611
612 /*
613  * CGI functions will later need access to the invocation args,
614  * so we will make argc and argv global.
615  */
616 int Argc = 0;
617 const char **Argv = NULL;
618
619 static struct file_list *current_configfile = NULL;
620
621
622 /*
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).
629  *
630  * Please keep this list sorted alphabetically (but with the Windows
631  * console and GUI specific options last).
632  */
633
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" */
680
681
682 static void savearg(char *command, char *argument, struct configuration_spec * config);
683
684 /*********************************************************************
685  *
686  * Function    :  unload_configfile
687  *
688  * Description :  Free the config structure and all components.
689  *
690  * Parameters  :
691  *          1  :  data: struct configuration_spec to unload
692  *
693  * Returns     :  N/A
694  *
695  *********************************************************************/
696 static void unload_configfile (void * data)
697 {
698    struct configuration_spec * config = (struct configuration_spec *)data;
699    struct forward_spec *cur_fwd = config->forward;
700    int i;
701
702 #ifdef FEATURE_ACL
703    struct access_control_list *cur_acl = config->acl;
704
705    while (cur_acl != NULL)
706    {
707       struct access_control_list * next_acl = cur_acl->next;
708       free(cur_acl);
709       cur_acl = next_acl;
710    }
711    config->acl = NULL;
712 #endif /* def FEATURE_ACL */
713
714    while (cur_fwd != NULL)
715    {
716       struct forward_spec * next_fwd = cur_fwd->next;
717       free_url_spec(cur_fwd->url);
718
719       freez(cur_fwd->gateway_host);
720       freez(cur_fwd->forward_host);
721       free(cur_fwd);
722       cur_fwd = next_fwd;
723    }
724    config->forward = NULL;
725
726    freez(config->confdir);
727    freez(config->logdir);
728    freez(config->templdir);
729    freez(config->hostname);
730
731    freez(config->haddr);
732    freez(config->logfile);
733
734    for (i = 0; i < MAX_AF_FILES; i++)
735    {
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]);
740    }
741
742    freez(config->admin_address);
743    freez(config->proxy_info_url);
744    freez(config->proxy_args);
745    freez(config->usermanual);
746
747 #ifdef FEATURE_TRUST
748    freez(config->trustfile);
749    list_remove_all(config->trust_info);
750 #endif /* def FEATURE_TRUST */
751
752    for (i = 0; i < MAX_AF_FILES; i++)
753    {
754       freez(config->re_filterfile[i]);
755    }
756
757    freez(config);
758 }
759
760
761 #ifdef FEATURE_GRACEFUL_TERMINATION
762 /*********************************************************************
763  *
764  * Function    :  unload_current_config_file
765  *
766  * Description :  Unloads current config file - reset to state at
767  *                beginning of program.
768  *
769  * Parameters  :  None
770  *
771  * Returns     :  N/A
772  *
773  *********************************************************************/
774 void unload_current_config_file(void)
775 {
776    if (current_configfile)
777    {
778       current_configfile->unloader = unload_configfile;
779       current_configfile = NULL;
780    }
781 }
782 #endif
783
784
785 /*********************************************************************
786  *
787  * Function    :  load_config
788  *
789  * Description :  Load the config file and all parameters.
790  *
791  *                XXX: more than thousand lines long
792  *                and thus in serious need of refactoring.
793  *
794  * Parameters  :  None
795  *
796  * Returns     :  The configuration_spec, or NULL on error.
797  *
798  *********************************************************************/
799 struct configuration_spec * load_config(void)
800 {
801    char buf[BUFFER_SIZE];
802    char *p, *q;
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;
808    int i;
809    char *logfile = NULL;
810
811    if (!check_file_changed(current_configfile, configfile, &fs))
812    {
813       /* No need to load */
814       return ((struct configuration_spec *)current_configfile->f);
815    }
816    if (NULL == fs)
817    {
818       log_error(LOG_LEVEL_FATAL,
819          "can't check configuration file '%s':  %E", configfile);
820       return NULL;
821    }
822
823    if (NULL != current_configfile)
824    {
825       log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
826    }
827
828 #ifdef FEATURE_TOGGLE
829    global_toggle_state = 1;
830 #endif /* def FEATURE_TOGGLE */
831
832    fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
833
834    if (NULL == config)
835    {
836       freez(fs->filename);
837       freez(fs);
838       log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
839       return NULL;
840    }
841
842    /*
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".
850     */
851    config->config_file_list = fs;
852
853    /*
854     * Set to defaults
855     */
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;
867 #endif
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;
871
872    configfp = fopen(configfile, "r");
873    if (NULL == configfp)
874    {
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 */
878    }
879
880    while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
881    {
882       char cmd[BUFFER_SIZE];
883       char arg[BUFFER_SIZE];
884       char tmp[BUFFER_SIZE];
885 #ifdef FEATURE_ACL
886       struct access_control_list *cur_acl;
887 #endif /* def FEATURE_ACL */
888       struct forward_spec *cur_fwd;
889       int vec_count;
890       char *vec[3];
891       unsigned long directive_hash;
892
893       strlcpy(tmp, buf, sizeof(tmp));
894
895       /* Copy command (i.e. up to space or tab) into cmd */
896       p = buf;
897       q = cmd;
898       while (*p && (*p != ' ') && (*p != '\t'))
899       {
900          *q++ = *p++;
901       }
902       *q = '\0';
903
904       /* Skip over the whitespace in buf */
905       while (*p && ((*p == ' ') || (*p == '\t')))
906       {
907          p++;
908       }
909
910       /* Copy the argument into arg */
911       strlcpy(arg, p, sizeof(arg));
912
913       /* Should never happen, but check this anyway */
914       if (*cmd == '\0')
915       {
916          continue;
917       }
918
919       /* Make sure the command field is lower case */
920       for (p = cmd; *p; p++)
921       {
922          if (ijb_isupper(*p))
923          {
924             *p = (char)ijb_tolower(*p);
925          }
926       }
927
928       directive_hash = hash_string(cmd);
929       switch (directive_hash)
930       {
931 /* *************************************************************************
932  * actionsfile actions-file-name
933  * In confdir by default
934  * *************************************************************************/
935          case hash_actions_file :
936             i = 0;
937             while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
938             {
939                i++;
940             }
941
942             if (i >= MAX_AF_FILES)
943             {
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).",
946                   MAX_AF_FILES);
947             }
948             config->actions_file_short[i] = strdup(arg);
949             config->actions_file[i] = make_path(config->confdir, arg);
950
951             break;
952 /* *************************************************************************
953  * accept-intercepted-requests
954  * *************************************************************************/
955          case hash_accept_intercepted_requests:
956             if ((*arg != '\0') && (0 != atoi(arg)))
957             {
958                config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
959             }
960             else
961             {
962                config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
963             }
964             break;
965
966 /* *************************************************************************
967  * admin-address email-address
968  * *************************************************************************/
969          case hash_admin_address :
970             freez(config->admin_address);
971             config->admin_address = strdup(arg);
972             break;
973
974 /* *************************************************************************
975  * allow-cgi-request-crunching
976  * *************************************************************************/
977          case hash_allow_cgi_request_crunching:
978             if ((*arg != '\0') && (0 != atoi(arg)))
979             {
980                config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
981             }
982             else
983             {
984                config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
985             }
986             break;
987
988 /* *************************************************************************
989  * buffer-limit n
990  * *************************************************************************/
991          case hash_buffer_limit :
992             config->buffer_limit = (size_t)(1024 * atoi(arg));
993             break;
994
995 /* *************************************************************************
996  * confdir directory-name
997  * *************************************************************************/
998          case hash_confdir :
999             freez(config->confdir);
1000             config->confdir = make_path( NULL, arg);
1001             break;
1002
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)))
1009             {
1010                config->feature_flags |= RUNTIME_FEATURE_CONNECTION_SHARING;
1011             }
1012             else
1013             {
1014                config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
1015             }
1016             break;
1017 #endif
1018
1019 /* *************************************************************************
1020  * debug n
1021  * Specifies debug level, multiple values are ORed together.
1022  * *************************************************************************/
1023          case hash_debug :
1024             config->debug |= atoi(arg);
1025             break;
1026
1027 /* *************************************************************************
1028  * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1029  * *************************************************************************/
1030 #ifdef FEATURE_ACL
1031          case hash_deny_access:
1032             strlcpy(tmp, arg, sizeof(tmp));
1033             vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1034
1035             if ((vec_count != 1) && (vec_count != 2))
1036             {
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");
1042                break;
1043             }
1044
1045             /* allocate a new node */
1046             cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1047
1048             if (cur_acl == NULL)
1049             {
1050                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1051                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1052                break;
1053             }
1054             cur_acl->action = ACL_DENY;
1055
1056             if (acl_addr(vec[0], cur_acl->src) < 0)
1057             {
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,
1064                   vec[0]);
1065                string_append(&config->proxy_args,
1066                   "\"<br><br>\n");
1067                freez(cur_acl);
1068                break;
1069             }
1070             if (vec_count == 2)
1071             {
1072                if (acl_addr(vec[1], cur_acl->dst) < 0)
1073                {
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,
1080                      vec[1]);
1081                   string_append(&config->proxy_args,
1082                      "\"<br><br>\n");
1083                   freez(cur_acl);
1084                   break;
1085                }
1086             }
1087 #ifdef HAVE_RFC2553
1088             else
1089             {
1090                cur_acl->wildcard_dst = 1;
1091             }
1092 #endif /* def HAVE_RFC2553 */
1093
1094             /*
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.
1102              */
1103             cur_acl->next  = config->acl;
1104             config->acl = cur_acl;
1105
1106             break;
1107 #endif /* def FEATURE_ACL */
1108
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)))
1115             {
1116                config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1117             }
1118             else
1119             {
1120                config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1121             }
1122             break;
1123 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1124
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)))
1131             {
1132                config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1133             }
1134             else
1135             {
1136                config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1137             }
1138             break;
1139 #endif /* def FEATURE_TOGGLE */
1140
1141 /* *************************************************************************
1142  * enable-remote-http-toggle 0|1
1143  * *************************************************************************/
1144          case hash_enable_remote_http_toggle:
1145             if ((*arg != '\0') && (0 != atoi(arg)))
1146             {
1147                config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1148             }
1149             else
1150             {
1151                config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1152             }
1153             break;
1154
1155 /* *************************************************************************
1156  * enforce-blocks 0|1
1157  * *************************************************************************/
1158          case hash_enforce_blocks:
1159 #ifdef FEATURE_FORCE_LOAD
1160             if ((*arg != '\0') && (0 != atoi(arg)))
1161             {
1162                config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1163             }
1164             else
1165             {
1166                config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1167             }
1168 #else
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 */
1172             break;
1173
1174 /* *************************************************************************
1175  * filterfile file-name
1176  * In confdir by default.
1177  * *************************************************************************/
1178          case hash_filterfile :
1179             i = 0;
1180             while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1181             {
1182                i++;
1183             }
1184
1185             if (i >= MAX_AF_FILES)
1186             {
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).",
1189                   MAX_AF_FILES);
1190             }
1191             config->re_filterfile_short[i] = strdup(arg);
1192             config->re_filterfile[i] = make_path(config->confdir, arg);
1193
1194             break;
1195
1196 /* *************************************************************************
1197  * forward url-pattern (.|http-proxy-host[:port])
1198  * *************************************************************************/
1199          case hash_forward:
1200             strlcpy(tmp, arg, sizeof(tmp));
1201             vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1202
1203             if (vec_count != 2)
1204             {
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.");
1210                break;
1211             }
1212
1213             /* allocate a new node */
1214             cur_fwd = zalloc(sizeof(*cur_fwd));
1215             if (cur_fwd == NULL)
1216             {
1217                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1218                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1219                break;
1220             }
1221
1222             cur_fwd->type = SOCKS_NONE;
1223
1224             /* Save the URL pattern */
1225             if (create_url_spec(cur_fwd->url, vec[0]))
1226             {
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.");
1232                break;
1233             }
1234
1235             /* Parse the parent HTTP proxy host:port */
1236             p = vec[1];
1237
1238             if (strcmp(p, ".") != 0)
1239             {
1240                cur_fwd->forward_port = 8000;
1241                parse_forwarder_address(p, &cur_fwd->forward_host,
1242                   &cur_fwd->forward_port);
1243             }
1244
1245             /* Add to list. */
1246             cur_fwd->next = config->forward;
1247             config->forward = cur_fwd;
1248
1249             break;
1250
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);
1257
1258             if (vec_count != 3)
1259             {
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.");
1265                break;
1266             }
1267
1268             /* allocate a new node */
1269             cur_fwd = zalloc(sizeof(*cur_fwd));
1270             if (cur_fwd == NULL)
1271             {
1272                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1273                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1274                break;
1275             }
1276
1277             cur_fwd->type = SOCKS_4;
1278
1279             /* Save the URL pattern */
1280             if (create_url_spec(cur_fwd->url, vec[0]))
1281             {
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.");
1287                break;
1288             }
1289
1290             /* Parse the SOCKS proxy host[:port] */
1291             p = vec[1];
1292
1293             /* XXX: This check looks like a bug. */
1294             if (strcmp(p, ".") != 0)
1295             {
1296                cur_fwd->gateway_port = 1080;
1297                parse_forwarder_address(p, &cur_fwd->gateway_host,
1298                   &cur_fwd->gateway_port);
1299             }
1300
1301             /* Parse the parent HTTP proxy host[:port] */
1302             p = vec[2];
1303
1304             if (strcmp(p, ".") != 0)
1305             {
1306                cur_fwd->forward_port = 8000;
1307                parse_forwarder_address(p, &cur_fwd->forward_host,
1308                   &cur_fwd->forward_port);
1309             }
1310
1311             /* Add to list. */
1312             cur_fwd->next = config->forward;
1313             config->forward = cur_fwd;
1314
1315             break;
1316
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);
1324
1325             if (vec_count != 3)
1326             {
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.");
1332                break;
1333             }
1334
1335             /* allocate a new node */
1336             cur_fwd = zalloc(sizeof(*cur_fwd));
1337             if (cur_fwd == NULL)
1338             {
1339                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1340                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1341                break;
1342             }
1343
1344             if (directive_hash == hash_forward_socks4a)
1345             {
1346                cur_fwd->type = SOCKS_4A;
1347             }
1348             else
1349             {
1350                cur_fwd->type = SOCKS_5;
1351             }
1352
1353             /* Save the URL pattern */
1354             if (create_url_spec(cur_fwd->url, vec[0]))
1355             {
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.");
1361                break;
1362             }
1363
1364             /* Parse the SOCKS proxy host[:port] */
1365             p = vec[1];
1366
1367             cur_fwd->gateway_port = 1080;
1368             parse_forwarder_address(p, &cur_fwd->gateway_host,
1369                &cur_fwd->gateway_port);
1370
1371             /* Parse the parent HTTP proxy host[:port] */
1372             p = vec[2];
1373
1374             if (strcmp(p, ".") != 0)
1375             {
1376                cur_fwd->forward_port = 8000;
1377                parse_forwarder_address(p, &cur_fwd->forward_host,
1378                   &cur_fwd->forward_port);
1379             }
1380
1381             /* Add to list. */
1382             cur_fwd->next = config->forward;
1383             config->forward = cur_fwd;
1384
1385             break;
1386
1387 /* *************************************************************************
1388  * forwarded-connect-retries n
1389  * *************************************************************************/
1390          case hash_forwarded_connect_retries :
1391             config->forwarded_connect_retries = atoi(arg);
1392             break;
1393
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)
1401             {
1402                log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1403             }
1404             break;
1405
1406 /* *************************************************************************
1407  * keep-alive-timeout timeout
1408  * *************************************************************************/
1409 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1410          case hash_keep_alive_timeout :
1411             if (*arg != '\0')
1412             {
1413                int timeout = atoi(arg);
1414                if (0 <= timeout)
1415                {
1416                   config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1417                   config->keep_alive_timeout = timeout;
1418                }
1419                else
1420                {
1421                   config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1422                }
1423             }
1424             break;
1425 #endif
1426
1427 /* *************************************************************************
1428  * listen-address [ip][:port]
1429  * *************************************************************************/
1430          case hash_listen_address :
1431             freez(config->haddr);
1432             config->haddr = strdup(arg);
1433             break;
1434
1435 /* *************************************************************************
1436  * logdir directory-name
1437  * *************************************************************************/
1438          case hash_logdir :
1439             freez(config->logdir);
1440             config->logdir = make_path(NULL, arg);
1441             break;
1442
1443 /* *************************************************************************
1444  * logfile log-file-name
1445  * In logdir by default
1446  * *************************************************************************/
1447          case hash_logfile :
1448             if (!no_daemon)
1449             {
1450                logfile = make_path(config->logdir, arg);
1451                if (NULL == logfile)
1452                {
1453                   log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1454                }
1455             }
1456             break;
1457
1458 /* *************************************************************************
1459  * max-client-connections number
1460  * *************************************************************************/
1461          case hash_max_client_connections :
1462             if (*arg != '\0')
1463             {
1464                int max_client_connections = atoi(arg);
1465                if (0 <= max_client_connections)
1466                {
1467                   config->max_client_connections = max_client_connections;
1468                }
1469             }
1470             break;
1471
1472 /* *************************************************************************
1473  * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1474  * *************************************************************************/
1475 #ifdef FEATURE_ACL
1476          case hash_permit_access:
1477             strlcpy(tmp, arg, sizeof(tmp));
1478             vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1479
1480             if ((vec_count != 1) && (vec_count != 2))
1481             {
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");
1487
1488                break;
1489             }
1490
1491             /* allocate a new node */
1492             cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1493
1494             if (cur_acl == NULL)
1495             {
1496                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1497                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1498                break;
1499             }
1500             cur_acl->action = ACL_PERMIT;
1501
1502             if (acl_addr(vec[0], cur_acl->src) < 0)
1503             {
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,
1510                   vec[0]);
1511                string_append(&config->proxy_args,
1512                   "\"<br><br>\n");
1513                freez(cur_acl);
1514                break;
1515             }
1516             if (vec_count == 2)
1517             {
1518                if (acl_addr(vec[1], cur_acl->dst) < 0)
1519                {
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,
1526                      vec[1]);
1527                   string_append(&config->proxy_args,
1528                      "\"<br><br>\n");
1529                   freez(cur_acl);
1530                   break;
1531                }
1532             }
1533 #ifdef HAVE_RFC2553
1534             else
1535             {
1536                cur_acl->wildcard_dst = 1;
1537             }
1538 #endif /* def HAVE_RFC2553 */
1539
1540             /*
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.
1548              */
1549             cur_acl->next  = config->acl;
1550             config->acl = cur_acl;
1551
1552             break;
1553 #endif /* def FEATURE_ACL */
1554
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);
1561             break;
1562
1563 /* *************************************************************************
1564  * single-threaded
1565  * *************************************************************************/
1566          case hash_single_threaded :
1567             config->multi_threaded = 0;
1568             break;
1569
1570 /* *************************************************************************
1571  * socket-timeout numer_of_seconds
1572  * *************************************************************************/
1573          case hash_socket_timeout :
1574             if (*arg != '\0')
1575             {
1576                int socket_timeout = atoi(arg);
1577                if (0 < socket_timeout)
1578                {
1579                   config->socket_timeout = socket_timeout;
1580                }
1581                else
1582                {
1583                   log_error(LOG_LEVEL_FATAL,
1584                      "Invalid socket-timeout: '%s'", arg);
1585                }
1586             }
1587             break;
1588
1589 /* *************************************************************************
1590  * split-large-cgi-forms
1591  * *************************************************************************/
1592          case hash_split_large_cgi_forms :
1593             if ((*arg != '\0') && (0 != atoi(arg)))
1594             {
1595                config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1596             }
1597             else
1598             {
1599                config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1600             }
1601             break;
1602
1603 /* *************************************************************************
1604  * templdir directory-name
1605  * *************************************************************************/
1606          case hash_templdir :
1607             freez(config->templdir);
1608             config->templdir = make_path(NULL, arg);
1609             break;
1610
1611 /* *************************************************************************
1612  * toggle (0|1)
1613  * *************************************************************************/
1614 #ifdef FEATURE_TOGGLE
1615          case hash_toggle :
1616             global_toggle_state = atoi(arg);
1617             break;
1618 #endif /* def FEATURE_TOGGLE */
1619
1620 /* *************************************************************************
1621  * trust-info-url url
1622  * *************************************************************************/
1623 #ifdef FEATURE_TRUST
1624          case hash_trust_info_url :
1625             enlist(config->trust_info, arg);
1626             break;
1627 #endif /* def FEATURE_TRUST */
1628
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);
1637             break;
1638 #endif /* def FEATURE_TRUST */
1639
1640 /* *************************************************************************
1641  * usermanual url
1642  * *************************************************************************/
1643          case hash_usermanual :
1644             /*
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.
1648              */
1649             freez(config->usermanual);
1650             config->usermanual = strdup(arg);
1651             break;
1652
1653 /* *************************************************************************
1654  * Win32 Console options:
1655  * *************************************************************************/
1656
1657 /* *************************************************************************
1658  * hide-console
1659  * *************************************************************************/
1660 #ifdef _WIN_CONSOLE
1661          case hash_hide_console :
1662             hideConsole = 1;
1663             break;
1664 #endif /*def _WIN_CONSOLE*/
1665
1666
1667 /* *************************************************************************
1668  * Win32 GUI options:
1669  * *************************************************************************/
1670
1671 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1672 /* *************************************************************************
1673  * activity-animation (0|1)
1674  * *************************************************************************/
1675          case hash_activity_animation :
1676             g_bShowActivityAnimation = atoi(arg);
1677             break;
1678
1679 /* *************************************************************************
1680  *  close-button-minimizes (0|1)
1681  * *************************************************************************/
1682          case hash_close_button_minimizes :
1683             g_bCloseHidesWindow = atoi(arg);
1684             break;
1685
1686 /* *************************************************************************
1687  * log-buffer-size (0|1)
1688  * *************************************************************************/
1689          case hash_log_buffer_size :
1690             g_bLimitBufferSize = atoi(arg);
1691             break;
1692
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))
1699             {
1700                log_error(LOG_LEVEL_FATAL,
1701                   "log-font-name argument '%s' is longer than %u characters.",
1702                   arg, sizeof(g_szFontFaceName)-1);
1703             }
1704             break;
1705
1706 /* *************************************************************************
1707  * log-font-size n
1708  * *************************************************************************/
1709          case hash_log_font_size :
1710             g_nFontSize = atoi(arg);
1711             break;
1712
1713 /* *************************************************************************
1714  * log-highlight-messages (0|1)
1715  * *************************************************************************/
1716          case hash_log_highlight_messages :
1717             g_bHighlightMessages = atoi(arg);
1718             break;
1719
1720 /* *************************************************************************
1721  * log-max-lines n
1722  * *************************************************************************/
1723          case hash_log_max_lines :
1724             g_nMaxBufferLines = atoi(arg);
1725             break;
1726
1727 /* *************************************************************************
1728  * log-messages (0|1)
1729  * *************************************************************************/
1730          case hash_log_messages :
1731             g_bLogMessages = atoi(arg);
1732             break;
1733
1734 /* *************************************************************************
1735  * show-on-task-bar (0|1)
1736  * *************************************************************************/
1737          case hash_show_on_task_bar :
1738             g_bShowOnTaskBar = atoi(arg);
1739             break;
1740
1741 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1742
1743
1744 /* *************************************************************************
1745  * Warnings about unsupported features
1746  * *************************************************************************/
1747 #ifndef FEATURE_ACL
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 */
1756 #ifndef FEATURE_ACL
1757          case hash_permit_access:
1758 #endif /* ndef FEATURE_ACL */
1759 #ifndef FEATURE_TOGGLE
1760          case hash_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 */
1766
1767 #ifndef _WIN_CONSOLE
1768          case hash_hide_console :
1769 #endif /* ndef _WIN_CONSOLE */
1770
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); */
1784             break;
1785
1786 /* *************************************************************************/
1787          default :
1788 /* *************************************************************************/
1789             /*
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.
1793              */
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>");
1798             break;
1799
1800 /* *************************************************************************/
1801       } /* end switch( hash_string(cmd) ) */
1802
1803       /* Save the argument for the show-status page. */
1804       savearg(cmd, arg, config);
1805
1806    } /* end while ( read_config_line(...) ) */
1807
1808    fclose(configfp);
1809
1810    set_debug_level(config->debug);
1811
1812    freez(config->logfile);
1813
1814    if (!no_daemon)
1815    {
1816       if (NULL != logfile)
1817       {
1818          config->logfile = logfile;
1819          init_error_log(Argv[0], config->logfile);
1820       }
1821       else
1822       {
1823          disable_logging();
1824       }
1825    }
1826
1827 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1828    if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1829    {
1830       if (config->multi_threaded)
1831       {
1832          set_keep_alive_timeout(config->keep_alive_timeout);
1833       }
1834       else
1835       {
1836          /*
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.
1841           *
1842           * XXX: We could still use Proxy-Connection: keep-alive.
1843           */
1844          config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1845          log_error(LOG_LEVEL_ERROR,
1846             "Config option single-threaded disables connection keep-alive.");
1847       }
1848    }
1849 #endif
1850
1851    if (NULL == config->proxy_args)
1852    {
1853       log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1854    }
1855
1856    if (config->actions_file[0])
1857    {
1858       add_loader(load_action_files, config);
1859    }
1860
1861    if (config->re_filterfile[0])
1862    {
1863       add_loader(load_re_filterfiles, config);
1864    }
1865
1866 #ifdef FEATURE_TRUST
1867    if (config->trustfile)
1868    {
1869       add_loader(load_trustfile, config);
1870    }
1871 #endif /* def FEATURE_TRUST */
1872
1873    if ( NULL == config->haddr )
1874    {
1875       config->haddr = strdup( HADDR_DEFAULT );
1876    }
1877
1878    if ( NULL != config->haddr )
1879    {
1880       if ((*config->haddr == '[')
1881          && (NULL != (p = strchr(config->haddr, ']')))
1882          && (p[1] == ':')
1883          && (0 < (config->hport = atoi(p + 2))))
1884       {
1885          *p = '\0';
1886          memmove((void *)config->haddr, config->haddr + 1,
1887             (size_t)(p - config->haddr));
1888       }
1889       else if (NULL != (p = strchr(config->haddr, ':'))
1890          && (0 < (config->hport = atoi(p + 1))))
1891       {
1892          *p = '\0';
1893       }
1894       else
1895       {
1896          log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1897          /* Never get here - LOG_LEVEL_FATAL causes program exit */
1898       }
1899       if (*config->haddr == '\0')
1900       {
1901          /*
1902           * Only the port specified. We stored it in config->hport
1903           * and don't need its text representation anymore.
1904           */
1905          freez(config->haddr);
1906       }
1907    }
1908
1909    /*
1910     * Want to run all the loaders once now.
1911     *
1912     * Need to set up a fake csp, so they can get to the config.
1913     */
1914    fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1915    fake_csp->config = config;
1916
1917    if (run_loader(fake_csp))
1918    {
1919       freez(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 */
1922    }
1923    freez(fake_csp);
1924
1925 /* FIXME: this is a kludge for win32 */
1926 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1927
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 */
1931
1932 #ifdef FEATURE_TRUST
1933    g_trustfile        = config->trustfile;
1934 #endif /* def FEATURE_TRUST */
1935
1936
1937 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1938 /* FIXME: end kludge */
1939
1940
1941    config->need_bind = 1;
1942
1943    if (current_configfile)
1944    {
1945       struct configuration_spec * oldcfg = (struct configuration_spec *)
1946                                            current_configfile->f;
1947       /*
1948        * Check if config->haddr,hport == oldcfg->haddr,hport
1949        *
1950        * The following could be written more compactly as a single,
1951        * (unreadably long) if statement.
1952        */
1953       config->need_bind = 0;
1954       if (config->hport != oldcfg->hport)
1955       {
1956          config->need_bind = 1;
1957       }
1958       else if (config->haddr == NULL)
1959       {
1960          if (oldcfg->haddr != NULL)
1961          {
1962             config->need_bind = 1;
1963          }
1964       }
1965       else if (oldcfg->haddr == NULL)
1966       {
1967          config->need_bind = 1;
1968       }
1969       else if (0 != strcmp(config->haddr, oldcfg->haddr))
1970       {
1971          config->need_bind = 1;
1972       }
1973
1974       current_configfile->unloader = unload_configfile;
1975    }
1976
1977    fs->next = files->next;
1978    files->next = fs;
1979
1980    current_configfile = fs;
1981
1982    return (config);
1983 }
1984
1985
1986 /*********************************************************************
1987  *
1988  * Function    :  savearg
1989  *
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
1995  *
1996  * Parameters  :
1997  *          1  :  command = config setting that was found
1998  *          2  :  argument = the setting's argument (if any)
1999  *          3  :  config = Configuration to save into.
2000  *
2001  * Returns     :  N/A
2002  *
2003  *********************************************************************/
2004 static void savearg(char *command, char *argument, struct configuration_spec * config)
2005 {
2006    char * buf;
2007    char * s;
2008
2009    assert(command);
2010    assert(argument);
2011
2012    /*
2013     * Add config option name embedded in
2014     * link to its section in the user-manual
2015     */
2016    buf = strdup("\n<a href=\"");
2017    if (!strncmpic(config->usermanual, "file://", 7) ||
2018        !strncmpic(config->usermanual, "http", 4))
2019    {
2020       string_append(&buf, config->usermanual);
2021    }
2022    else
2023    {
2024       string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
2025    }
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> ");
2031
2032    if (NULL == buf)
2033    {
2034       freez(config->proxy_args);
2035       return;
2036    }
2037
2038    if ( (NULL != argument) && ('\0' != *argument) )
2039    {
2040       s = html_encode(argument);
2041       if (NULL == s)
2042       {
2043          freez(buf);
2044          freez(config->proxy_args);
2045          return;
2046       }
2047
2048       if (strncmpic(argument, "http://", 7) == 0)
2049       {
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>");
2055       }
2056       else
2057       {
2058          string_join  (&buf, s);
2059       }
2060    }
2061
2062    string_append(&buf, "<br>");
2063    string_join(&config->proxy_args, buf);
2064 }
2065
2066
2067 /*
2068   Local Variables:
2069   tab-width: 3
2070   end:
2071 */