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