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