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