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