Splitting off bind_port() call into bind_port_helper(), with
[privoxy.git] / loadcfg.c
1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.31 2002/03/03 15:07:20 oes 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 the SourceForge
12  *                IJBSWA team.  http://ijbswa.sourceforge.net
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.31  2002/03/03 15:07:20  oes
39  *    Re-enabled automatic config reloading
40  *
41  *    Revision 1.30  2002/01/22 23:31:43  jongfoster
42  *    Replacing strsav() with string_append()
43  *
44  *    Revision 1.29  2002/01/17 21:02:30  jongfoster
45  *    Moving all our URL and URL pattern parsing code to urlmatch.c.
46  *
47  *    Renaming free_url to free_url_spec, since it frees a struct url_spec.
48  *
49  *    Revision 1.28  2001/12/30 14:07:32  steudten
50  *    - Add signal handling (unix)
51  *    - Add SIGHUP handler (unix)
52  *    - Add creation of pidfile (unix)
53  *    - Add action 'top' in rc file (RH)
54  *    - Add entry 'SIGNALS' to manpage
55  *    - Add exit message to logfile (unix)
56  *
57  *    Revision 1.27  2001/11/07 00:02:13  steudten
58  *    Add line number in error output for lineparsing for
59  *    actionsfile and configfile.
60  *    Special handling for CLF added.
61  *
62  *    Revision 1.26  2001/11/05 21:41:43  steudten
63  *    Add changes to be a real daemon just for unix os.
64  *    (change cwd to /, detach from controlling tty, set
65  *    process group and session leader to the own process.
66  *    Add DBG() Macro.
67  *    Add some fatal-error log message for failed malloc().
68  *    Add '-d' if compiled with 'configure --with-debug' to
69  *    enable debug output.
70  *
71  *    Revision 1.25  2001/10/25 03:40:48  david__schmidt
72  *    Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
73  *    threads to call select() simultaneously.  So, it's time to do a real, live,
74  *    native OS/2 port.  See defines for __EMX__ (the porting layer) vs. __OS2__
75  *    (native). Both versions will work, but using __OS2__ offers multi-threading.
76  *
77  *    Revision 1.24  2001/10/23 21:40:30  jongfoster
78  *    Added support for enable-edit-actions and enable-remote-toggle config
79  *    file options.
80  *
81  *    Revision 1.23  2001/10/07 15:36:00  oes
82  *    Introduced new config option "buffer-limit"
83  *
84  *    Revision 1.22  2001/09/22 16:36:59  jongfoster
85  *    Removing unused parameter fs from read_config_line()
86  *
87  *    Revision 1.21  2001/09/16 17:10:43  jongfoster
88  *    Moving function savearg() here, since it was the only thing left in
89  *    showargs.c.
90  *
91  *    Revision 1.20  2001/07/30 22:08:36  jongfoster
92  *    Tidying up #defines:
93  *    - All feature #defines are now of the form FEATURE_xxx
94  *    - Permanently turned off WIN_GUI_EDIT
95  *    - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
96  *
97  *    Revision 1.19  2001/07/15 17:45:16  jongfoster
98  *    Removing some unused #includes
99  *
100  *    Revision 1.18  2001/07/13 14:01:14  oes
101  *     - Removed all #ifdef PCRS
102  *     - Removed vim-settings
103  *
104  *    Revision 1.17  2001/06/29 13:31:03  oes
105  *    - Improved comments
106  *    - Fixed (actionsfile) and sorted hashes
107  *    - Introduced admin_address and proxy-info-url
108  *      as config parameters
109  *    - Renamed config->proxy_args_invocation (which didn't have
110  *      the invocation but the options!) to config->proxy_args
111  *    - Various adaptions
112  *    - Removed logentry from cancelled commit
113  *
114  *    Revision 1.16  2001/06/09 10:55:28  jongfoster
115  *    Changing BUFSIZ ==> BUFFER_SIZE
116  *
117  *    Revision 1.15  2001/06/07 23:13:40  jongfoster
118  *    Merging ACL and forward files into config file.
119  *    Cosmetic: Sorting config file options alphabetically.
120  *    Cosmetic: Adding brief syntax comments to config file options.
121  *
122  *    Revision 1.14  2001/06/07 14:46:25  joergs
123  *    Missing make_path() added for re_filterfile.
124  *
125  *    Revision 1.13  2001/06/05 22:33:54  jongfoster
126  *
127  *    Fixed minor memory leak.
128  *    Also now uses make_path to prepend the pathnames.
129  *
130  *    Revision 1.12  2001/06/05 20:04:09  jongfoster
131  *    Now uses _snprintf() in place of snprintf() under Win32.
132  *
133  *    Revision 1.11  2001/06/04 18:31:58  swa
134  *    files are now prefixed with either `confdir' or `logdir'.
135  *    `make redhat-dist' replaces both entries confdir and logdir
136  *    with redhat values
137  *
138  *    Revision 1.10  2001/06/03 19:11:54  oes
139  *    introduced confdir option
140  *
141  *    Revision 1.9  2001/06/01 20:06:24  jongfoster
142  *    Removed support for "tinygif" option - moved to actions file.
143  *
144  *    Revision 1.8  2001/05/31 21:27:13  jongfoster
145  *    Removed many options from the config file and into the
146  *    "actions" file: add_forwarded, suppress_vanilla_wafer,
147  *    wafer, add_header, user_agent, referer, from
148  *    Also globally replaced "permission" with "action".
149  *
150  *    Revision 1.7  2001/05/29 09:50:24  jongfoster
151  *    Unified blocklist/imagelist/permissionslist.
152  *    File format is still under discussion, but the internal changes
153  *    are (mostly) done.
154  *
155  *    Also modified interceptor behaviour:
156  *    - We now intercept all URLs beginning with one of the following
157  *      prefixes (and *only* these prefixes):
158  *        * http://i.j.b/
159  *        * http://ijbswa.sf.net/config/
160  *        * http://ijbswa.sourceforge.net/config/
161  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
162  *    - Internal changes so that intercepted and fast redirect pages
163  *      are not replaced with an image.
164  *    - Interceptors now have the option to send a binary page direct
165  *      to the client. (i.e. ijb-send-banner uses this)
166  *    - Implemented show-url-info interceptor.  (Which is why I needed
167  *      the above interceptors changes - a typical URL is
168  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
169  *      The previous mechanism would not have intercepted that, and
170  *      if it had been intercepted then it then it would have replaced
171  *      it with an image.)
172  *
173  *    Revision 1.6  2001/05/26 00:28:36  jongfoster
174  *    Automatic reloading of config file.
175  *    Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
176  *    Most of the global variables have been moved to a new
177  *    struct configuration_spec, accessed through csp->config->globalname
178  *    Most of the globals remaining are used by the Win32 GUI.
179  *
180  *    Revision 1.5  2001/05/25 22:34:30  jongfoster
181  *    Hard tabs->Spaces
182  *
183  *    Revision 1.4  2001/05/22 18:46:04  oes
184  *
185  *    - Enabled filtering banners by size rather than URL
186  *      by adding patterns that replace all standard banner
187  *      sizes with the "Junkbuster" gif to the re_filterfile
188  *
189  *    - Enabled filtering WebBugs by providing a pattern
190  *      which kills all 1x1 images
191  *
192  *    - Added support for PCRE_UNGREEDY behaviour to pcrs,
193  *      which is selected by the (nonstandard and therefore
194  *      capital) letter 'U' in the option string.
195  *      It causes the quantifiers to be ungreedy by default.
196  *      Appending a ? turns back to greedy (!).
197  *
198  *    - Added a new interceptor ijb-send-banner, which
199  *      sends back the "Junkbuster" gif. Without imagelist or
200  *      MSIE detection support, or if tinygif = 1, or the
201  *      URL isn't recognized as an imageurl, a lame HTML
202  *      explanation is sent instead.
203  *
204  *    - Added new feature, which permits blocking remote
205  *      script redirects and firing back a local redirect
206  *      to the browser.
207  *      The feature is conditionally compiled, i.e. it
208  *      can be disabled with --disable-fast-redirects,
209  *      plus it must be activated by a "fast-redirects"
210  *      line in the config file, has its own log level
211  *      and of course wants to be displayed by show-proxy-args
212  *      Note: Boy, all the #ifdefs in 1001 locations and
213  *      all the fumbling with configure.in and acconfig.h
214  *      were *way* more work than the feature itself :-(
215  *
216  *    - Because a generic redirect template was needed for
217  *      this, tinygif = 3 now uses the same.
218  *
219  *    - Moved GIFs, and other static HTTP response templates
220  *      to project.h
221  *
222  *    - Some minor fixes
223  *
224  *    - Removed some >400 CRs again (Jon, you really worked
225  *      a lot! ;-)
226  *
227  *    Revision 1.3  2001/05/20 01:21:20  jongfoster
228  *    Version 2.9.4 checkin.
229  *    - Merged popupfile and cookiefile, and added control over PCRS
230  *      filtering, in new "permissionsfile".
231  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
232  *      file error you now get a message box (in the Win32 GUI) rather
233  *      than the program exiting with no explanation.
234  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
235  *      skipping.
236  *    - Removed tabs from "config"
237  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
238  *    - Bumped up version number.
239  *
240  *    Revision 1.2  2001/05/17 23:01:01  oes
241  *     - Cleaned CRLF's from the sources and related files
242  *
243  *    Revision 1.1.1.1  2001/05/15 13:58:58  oes
244  *    Initial import of version 2.9.3 source tree
245  *
246  *
247  *********************************************************************/
248 \f
249
250 #include "config.h"
251
252 #include <stdio.h>
253 #include <sys/types.h>
254 #include <stdlib.h>
255 #include <string.h>
256 #include <signal.h>
257 #include <fcntl.h>
258 #include <errno.h>
259 #include <ctype.h>
260 #include <assert.h>
261
262 #ifdef _WIN32
263
264 # include <windows.h>
265
266 # include "win32.h"
267 # ifndef _WIN_CONSOLE
268 #  include "w32log.h"
269 # endif /* ndef _WIN_CONSOLE */
270
271 /* VC++ has "_snprintf", not "snprintf" */
272 #define snprintf _snprintf
273
274 #else /* ifndef _WIN32 */
275
276 #ifndef __OS2__
277 # include <unistd.h>
278 # include <sys/wait.h>
279 #endif
280 # include <sys/time.h>
281 # include <sys/stat.h>
282 # include <signal.h>
283
284 #endif
285
286 #include "loadcfg.h"
287 #include "list.h"
288 #include "jcc.h"
289 #include "filters.h"
290 #include "loaders.h"
291 #include "miscutil.h"
292 #include "errlog.h"
293 #include "ssplit.h"
294 #include "encode.h"
295 #include "urlmatch.h"
296
297 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
298
299 /*
300  * Fix a problem with Solaris.  There should be no effect on other
301  * platforms.
302  * Solaris's isspace() is a macro which uses it's argument directly
303  * as an array index.  Therefore we need to make sure that high-bit
304  * characters generate +ve values, and ideally we also want to make
305  * the argument match the declared parameter type of "int".
306  */
307 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
308 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
309
310 #ifdef FEATURE_TOGGLE
311 /* by haroon - indicates if ijb is enabled */
312 int g_bToggleIJB        = 1;   /* JunkBusters is enabled by default. */
313 #endif /* def FEATURE_TOGGLE */
314
315 /* The filename of the configfile */
316 const char *configfile  = NULL;
317
318 /*
319  * CGI functions will later need access to the invocation args,
320  * so we will make argc and argv global.
321  */
322 int Argc = 0;
323 const char **Argv = NULL;
324
325 static struct file_list *current_configfile = NULL;
326
327
328 /*
329  * This takes the "cryptic" hash of each keyword and aliases them to
330  * something a little more readable.  This also makes changing the
331  * hash values easier if they should change or the hash algorthm changes.
332  * Use the included "hash" program to find out what the hash will be
333  * for any string supplied on the command line.  (Or just put it in the
334  * config file and read the number from the error message in the log).
335  *
336  * Please keep this list sorted alphabetically (but with the Windows
337  * console and GUI specific options last).
338  */
339
340 #define hash_actions_file              1196306641ul /* "actionsfile" */
341 #define hash_admin_address             4112573064ul /* "admin-address" */
342 #define hash_buffer_limit              1881726070ul /* "buffer-limit */
343 #define hash_confdir                      1978389ul /* "confdir" */
344 #define hash_debug                          78263ul /* "debug" */
345 #define hash_deny_access               1227333715ul /* "deny-access" */
346 #define hash_enable_edit_actions       2517097536ul /* "enable-edit-actions" */
347 #define hash_enable_remote_toggle      2979744683ul /* "enable-remote-toggle" */
348 #define hash_forward                      2029845ul /* "forward" */
349 #define hash_forward_socks4            3963965521ul /* "forward-socks4" */
350 #define hash_forward_socks4a           2639958518ul /* "forward-socks4a" */
351 #define hash_jarfile                      2046641ul /* "jarfile" */
352 #define hash_listen_address            1255650842ul /* "listen-address" */
353 #define hash_logdir                        422889ul /* "logdir" */
354 #define hash_logfile                      2114766ul /* "logfile" */
355 #define hash_permit_access             3587953268ul /* "permit-access" */
356 #define hash_proxy_info_url            3903079059ul /* "proxy-info-url" */
357 #define hash_re_filterfile             3877522444ul /* "re_filterfile" */
358 #define hash_single_threaded           4250084780ul /* "single-threaded" */
359 #define hash_suppress_blocklists       1948693308ul /* "suppress-blocklists" */
360 #define hash_toggle                        447966ul /* "toggle" */
361 #define hash_trust_info_url             430331967ul /* "trust-info-url" */
362 #define hash_trustfile                   56494766ul /* "trustfile" */
363
364 #define hash_activity_animation        1817904738ul /* "activity-animation" */
365 #define hash_close_button_minimizes    3651284693ul /* "close-button-minimizes" */
366 #define hash_hide_console              2048809870ul /* "hide-console" */
367 #define hash_log_buffer_size           2918070425ul /* "log-buffer-size" */
368 #define hash_log_font_name             2866730124ul /* "log-font-name" */
369 #define hash_log_font_size             2866731014ul /* "log-font-size" */
370 #define hash_log_highlight_messages    4032101240ul /* "log-highlight-messages" */
371 #define hash_log_max_lines             2868344173ul /* "log-max-lines" */
372 #define hash_log_messages              2291744899ul /* "log-messages" */
373 #define hash_show_on_task_bar           215410365ul /* "show-on-task-bar" */
374
375
376 static void savearg(char *command, char *argument, struct configuration_spec * config);
377
378 /*********************************************************************
379  *
380  * Function    :  unload_configfile
381  *
382  * Description :  Free the config structure and all components.
383  *
384  * Parameters  :
385  *          1  :  data: struct configuration_spec to unload
386  *
387  * Returns     :  N/A
388  *
389  *********************************************************************/
390 void unload_configfile (void * data)
391 {
392    struct configuration_spec * config = (struct configuration_spec *)data;
393    struct forward_spec *cur_fwd = config->forward;
394 #ifdef FEATURE_ACL
395    struct access_control_list *cur_acl = config->acl;
396
397    while (cur_acl != NULL)
398    {
399       struct access_control_list * next_acl = cur_acl->next;
400       free(cur_acl);
401       cur_acl = next_acl;
402    }
403    config->acl = NULL;
404 #endif /* def FEATURE_ACL */
405
406    while (cur_fwd != NULL)
407    {
408       struct forward_spec * next_fwd = cur_fwd->next;
409       free_url_spec(cur_fwd->url);
410
411       freez(cur_fwd->gateway_host);
412       freez(cur_fwd->forward_host);
413       free(cur_fwd);
414       cur_fwd = next_fwd;
415    }
416    config->forward = NULL;
417
418 #ifdef FEATURE_COOKIE_JAR
419    if ( NULL != config->jar )
420    {
421       fclose( config->jar );
422       config->jar = NULL;
423    }
424 #endif /* def FEATURE_COOKIE_JAR */
425
426    freez(config->confdir);
427    freez(config->logdir);
428
429    freez(config->haddr);
430    freez(config->logfile);
431
432    freez(config->actions_file);
433    freez(config->admin_address);
434    freez(config->proxy_info_url);
435    freez(config->proxy_args);
436
437 #ifdef FEATURE_COOKIE_JAR
438    freez(config->jarfile);
439 #endif /* def FEATURE_COOKIE_JAR */
440
441    freez(config->re_filterfile);
442
443 }
444
445
446 /*********************************************************************
447  *
448  * Function    :  load_config
449  *
450  * Description :  Load the config file and all parameters.
451  *
452  * Parameters  :
453  *          1  :  csp = Client state (the config member will be
454  *                filled in by this function).
455  *
456  * Returns     :  0 => Ok, everything else is an error.
457  *
458  *********************************************************************/
459 struct configuration_spec * load_config(void)
460 {
461    char buf[BUFFER_SIZE];
462    char *p, *q;
463    FILE *configfp = NULL;
464    struct configuration_spec * config = NULL;
465    struct client_state * fake_csp;
466    struct file_list *fs;
467    unsigned long linenum = 0;
468
469    DBG(1, ("load_config() entered..\n") );
470    if ( !check_file_changed(current_configfile, configfile, &fs))
471    {
472       /* No need to load */
473       return ((struct configuration_spec *)current_configfile->f);
474    }
475    if (!fs)
476    {
477       log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s':  %E",
478                 configfile);
479    }
480
481    log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
482
483 #ifdef FEATURE_TOGGLE
484    g_bToggleIJB      = 1;
485 #endif /* def FEATURE_TOGGLE */
486
487    fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
488
489    if (config==NULL)
490    {
491       freez(fs->filename);
492       freez(fs);
493       log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
494       /* Never get here - LOG_LEVEL_FATAL causes program exit */
495    }
496
497    /*
498     * This is backwards from how it's usually done.
499     * Following the usual pattern, "fs" would be stored in a member
500     * variable in "csp", and then we'd access "config" from "fs->f",
501     * using a cast.  However, "config" is used so often that a
502     * cast each time would be very ugly, and the extra indirection
503     * would waste CPU cycles.  Therefore we store "config" in
504     * "csp->config", and "fs" in "csp->config->config_file_list".
505     */
506    config->config_file_list = fs;
507
508    /*
509     * Set to defaults
510     */
511
512    config->multi_threaded    = 1;
513    config->hport             = HADDR_PORT;
514    config->buffer_limit      = 4096 * 1024;
515    config->proxy_args        = strdup("");
516
517    if ((configfp = fopen(configfile, "r")) == NULL)
518    {
519       log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s':  %E",
520               configfile);
521       /* Never get here - LOG_LEVEL_FATAL causes program exit */
522    }
523
524    while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
525    {
526       char cmd[BUFFER_SIZE];
527       char arg[BUFFER_SIZE];
528       char tmp[BUFFER_SIZE];
529 #ifdef FEATURE_ACL
530       struct access_control_list *cur_acl;
531 #endif /* def FEATURE_ACL */
532       struct forward_spec *cur_fwd;
533       int vec_count;
534       char *vec[3];
535
536       strcpy(tmp, buf);
537
538       /* Copy command (i.e. up to space or tab) into cmd */
539       p = buf;
540       q = cmd;
541       while (*p && (*p != ' ') && (*p != '\t'))
542       {
543          *q++ = *p++;
544       }
545       *q = '\0';
546
547       /* Skip over the whitespace in buf */
548       while (*p && ((*p == ' ') || (*p == '\t')))
549       {
550          p++;
551       }
552
553       /* Copy the argument into arg */
554       strcpy(arg, p);
555
556       /* Should never happen, but check this anyway */
557       if (*cmd == '\0')
558       {
559          continue;
560       }
561
562       /* Make sure the command field is lower case */
563       for (p=cmd; *p; p++)
564       {
565          if (ijb_isupper(*p))
566          {
567             *p = ijb_tolower(*p);
568          }
569       }
570
571       /* Save the argument for show-proxy-args */
572       savearg(cmd, arg, config);
573
574
575       switch( hash_string( cmd ) )
576       {
577 /****************************************************************************
578  * actionsfile actions-file-name
579  * In confdir by default
580  ****************************************************************************/
581          case hash_actions_file :
582             freez(config->actions_file);
583             config->actions_file = make_path(config->confdir, arg);
584             continue;
585
586 /****************************************************************************
587  * admin-address email-address
588  ****************************************************************************/
589          case hash_admin_address :
590             freez(config->admin_address);
591             config->admin_address = strdup(arg);
592             continue;
593
594 /****************************************************************************
595  * buffer-limit n
596  ****************************************************************************/
597          case hash_buffer_limit :
598             config->buffer_limit = (size_t) 1024 * atoi(arg);
599             continue;
600
601 /****************************************************************************
602  * confdir directory-name
603  ****************************************************************************/
604          case hash_confdir :
605             freez(config->confdir);
606             config->confdir = make_path( NULL, arg);
607             continue;
608
609 /****************************************************************************
610  * debug n
611  * Specifies debug level, multiple values are ORed together.
612  ****************************************************************************/
613          case hash_debug :
614             config->debug |= atoi(arg);
615             continue;
616
617 /****************************************************************************
618  * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
619  ****************************************************************************/
620 #ifdef FEATURE_ACL
621          case hash_deny_access:
622             vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
623
624             if ((vec_count != 1) && (vec_count != 2))
625             {
626                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
627                      "deny-access directive in configuration file.");
628                string_append(&config->proxy_args,
629                   "<br>\nWARNING: Wrong number of parameters for "
630                   "deny-access directive in configuration file.<br><br>\n");
631                continue;
632             }
633
634             /* allocate a new node */
635             cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
636
637             if (cur_acl == NULL)
638             {
639                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
640                /* Never get here - LOG_LEVEL_FATAL causes program exit */
641                continue;
642             }
643             cur_acl->action = ACL_DENY;
644
645             if (acl_addr(vec[0], cur_acl->src) < 0)
646             {
647                log_error(LOG_LEVEL_ERROR, "Invalid source IP for deny-access "
648                      "directive in configuration file: \"%s\"", vec[0]);
649                string_append(&config->proxy_args,
650                   "<br>\nWARNING: Invalid source IP for deny-access directive"
651                   " in configuration file: \"");
652                string_append(&config->proxy_args,
653                   vec[0]);
654                string_append(&config->proxy_args,
655                   "\"<br><br>\n");
656                freez(cur_acl);
657                continue;
658             }
659             if (vec_count == 2)
660             {
661                if (acl_addr(vec[1], cur_acl->dst) < 0)
662                {
663                   log_error(LOG_LEVEL_ERROR, "Invalid destination IP for deny-access "
664                         "directive in configuration file: \"%s\"", vec[0]);
665                   string_append(&config->proxy_args,
666                      "<br>\nWARNING: Invalid destination IP for deny-access directive"
667                      " in configuration file: \"");
668                   string_append(&config->proxy_args,
669                      vec[0]);
670                   string_append(&config->proxy_args,
671                      "\"<br><br>\n");
672                   freez(cur_acl);
673                   continue;
674                }
675             }
676
677             /*
678              * Add it to the list.  Note we reverse the list to get the
679              * behaviour the user expects.  With both the ACL and
680              * actions file, the last match wins.  However, the internal
681              * implementations are different:  The actions file is stored
682              * in the same order as the file, and scanned completely.
683              * With the ACL, we reverse the order as we load it, then
684              * when we scan it we stop as soon as we get a match.
685              */
686             cur_acl->next  = config->acl;
687             config->acl = cur_acl;
688
689             continue;
690 #endif /* def FEATURE_ACL */
691
692 /****************************************************************************
693  * enable-edit-actions 0|1
694  ****************************************************************************/
695 #ifdef FEATURE_CGI_EDIT_ACTIONS
696          case hash_enable_edit_actions:
697             if ((*arg != '\0') && (0 != atoi(arg)))
698             {
699                config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
700             }
701             else
702             {
703                config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
704             }
705             continue;
706 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
707
708 /****************************************************************************
709  * enable-remote-toggle 0|1
710  ****************************************************************************/
711 #ifdef FEATURE_CGI_EDIT_ACTIONS
712          case hash_enable_remote_toggle:
713             if ((*arg != '\0') && (0 != atoi(arg)))
714             {
715                config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
716             }
717             else
718             {
719                config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
720             }
721             continue;
722 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
723
724 /****************************************************************************
725  * forward url-pattern (.|http-proxy-host[:port])
726  ****************************************************************************/
727          case hash_forward:
728             vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
729
730             if (vec_count != 2)
731             {
732                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
733                      "directive in configuration file.");
734                string_append(&config->proxy_args,
735                   "<br>\nWARNING: Wrong number of parameters for "
736                   "forward directive in configuration file.");
737                continue;
738             }
739
740             /* allocate a new node */
741             cur_fwd = zalloc(sizeof(*cur_fwd));
742             if (cur_fwd == NULL)
743             {
744                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
745                /* Never get here - LOG_LEVEL_FATAL causes program exit */
746                continue;
747             }
748
749             cur_fwd->type = SOCKS_NONE;
750
751             /* Save the URL pattern */
752             if (create_url_spec(cur_fwd->url, vec[0]))
753             {
754                log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
755                      "directive in configuration file.");
756                string_append(&config->proxy_args,
757                   "<br>\nWARNING: Bad URL specifier for "
758                   "forward directive in configuration file.");
759                continue;
760             }
761
762             /* Parse the parent HTTP proxy host:port */
763             p = vec[1];
764
765             if (strcmp(p, ".") != 0)
766             {
767                cur_fwd->forward_host = strdup(p);
768
769                if ((p = strchr(cur_fwd->forward_host, ':')))
770                {
771                   *p++ = '\0';
772                   cur_fwd->forward_port = atoi(p);
773                }
774
775                if (cur_fwd->forward_port <= 0)
776                {
777                   cur_fwd->forward_port = 8000;
778                }
779             }
780
781             /* Add to list. */
782             cur_fwd->next = config->forward;
783             config->forward = cur_fwd;
784
785             continue;
786
787 /****************************************************************************
788  * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
789  ****************************************************************************/
790          case hash_forward_socks4:
791             vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
792
793             if (vec_count != 3)
794             {
795                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
796                      "forward-socks4 directive in configuration file.");
797                string_append(&config->proxy_args,
798                   "<br>\nWARNING: Wrong number of parameters for "
799                   "forward-socks4 directive in configuration file.");
800                continue;
801             }
802
803             /* allocate a new node */
804             cur_fwd = zalloc(sizeof(*cur_fwd));
805             if (cur_fwd == NULL)
806             {
807                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
808                /* Never get here - LOG_LEVEL_FATAL causes program exit */
809                continue;
810             }
811
812             cur_fwd->type = SOCKS_4;
813
814             /* Save the URL pattern */
815             if (create_url_spec(cur_fwd->url, vec[0]))
816             {
817                log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
818                      "directive in configuration file.");
819                string_append(&config->proxy_args,
820                   "<br>\nWARNING: Bad URL specifier for "
821                   "forward-socks4 directive in configuration file.");
822                continue;
823             }
824
825             /* Parse the SOCKS proxy host[:port] */
826             p = vec[1];
827
828             if (strcmp(p, ".") != 0)
829             {
830                cur_fwd->gateway_host = strdup(p);
831
832                if ((p = strchr(cur_fwd->gateway_host, ':')))
833                {
834                   *p++ = '\0';
835                   cur_fwd->gateway_port = atoi(p);
836                }
837                if (cur_fwd->gateway_port <= 0)
838                {
839                   cur_fwd->gateway_port = 1080;
840                }
841             }
842
843             /* Parse the parent HTTP proxy host[:port] */
844             p = vec[2];
845
846             if (strcmp(p, ".") != 0)
847             {
848                cur_fwd->forward_host = strdup(p);
849
850                if ((p = strchr(cur_fwd->forward_host, ':')))
851                {
852                   *p++ = '\0';
853                   cur_fwd->forward_port = atoi(p);
854                }
855
856                if (cur_fwd->forward_port <= 0)
857                {
858                   cur_fwd->forward_port = 8000;
859                }
860             }
861
862             /* Add to list. */
863             cur_fwd->next = config->forward;
864             config->forward = cur_fwd;
865
866             continue;
867
868 /****************************************************************************
869  * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
870  ****************************************************************************/
871          case hash_forward_socks4a:
872             vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
873
874             if (vec_count != 3)
875             {
876                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
877                      "forward-socks4a directive in configuration file.");
878                string_append(&config->proxy_args,
879                   "<br>\nWARNING: Wrong number of parameters for "
880                   "forward-socks4a directive in configuration file.");
881                continue;
882             }
883
884             /* allocate a new node */
885             cur_fwd = zalloc(sizeof(*cur_fwd));
886             if (cur_fwd == NULL)
887             {
888                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
889                /* Never get here - LOG_LEVEL_FATAL causes program exit */
890                continue;
891             }
892
893             cur_fwd->type = SOCKS_4A;
894
895             /* Save the URL pattern */
896             if (create_url_spec(cur_fwd->url, vec[0]))
897             {
898                log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
899                      "directive in configuration file.");
900                string_append(&config->proxy_args,
901                   "<br>\nWARNING: Bad URL specifier for "
902                   "forward-socks4a directive in configuration file.");
903                continue;
904             }
905
906             /* Parse the SOCKS proxy host[:port] */
907             p = vec[1];
908
909             cur_fwd->gateway_host = strdup(p);
910
911             if ((p = strchr(cur_fwd->gateway_host, ':')))
912             {
913                *p++ = '\0';
914                cur_fwd->gateway_port = atoi(p);
915             }
916             if (cur_fwd->gateway_port <= 0)
917             {
918                cur_fwd->gateway_port = 1080;
919             }
920
921             /* Parse the parent HTTP proxy host[:port] */
922             p = vec[2];
923
924             if (strcmp(p, ".") != 0)
925             {
926                cur_fwd->forward_host = strdup(p);
927
928                if ((p = strchr(cur_fwd->forward_host, ':')))
929                {
930                   *p++ = '\0';
931                   cur_fwd->forward_port = atoi(p);
932                }
933
934                if (cur_fwd->forward_port <= 0)
935                {
936                   cur_fwd->forward_port = 8000;
937                }
938             }
939
940             /* Add to list. */
941             cur_fwd->next = config->forward;
942             config->forward = cur_fwd;
943
944             continue;
945
946 /****************************************************************************
947  * jarfile jar-file-name
948  * In logdir by default
949  ****************************************************************************/
950 #ifdef FEATURE_COOKIE_JAR
951          case hash_jarfile :
952             freez(config->jarfile);
953             config->jarfile = make_path(config->logdir, arg);
954             continue;
955 #endif /* def FEATURE_COOKIE_JAR */
956
957 /****************************************************************************
958  * listen-address [ip][:port]
959  ****************************************************************************/
960          case hash_listen_address :
961             freez(config->haddr);
962             config->haddr = strdup(arg);
963             continue;
964
965 /****************************************************************************
966  * logdir directory-name
967  ****************************************************************************/
968          case hash_logdir :
969             freez(config->logdir);
970             config->logdir = make_path(NULL, arg);
971             continue;
972
973 /****************************************************************************
974  * logfile log-file-name
975  * In logdir by default
976  ****************************************************************************/
977          case hash_logfile :
978             freez(config->logfile);
979             config->logfile = make_path(config->logdir, arg);
980             continue;
981
982 /****************************************************************************
983  * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
984  ****************************************************************************/
985 #ifdef FEATURE_ACL
986          case hash_permit_access:
987             vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
988
989             if ((vec_count != 1) && (vec_count != 2))
990             {
991                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
992                      "permit-access directive in configuration file.");
993                string_append(&config->proxy_args,
994                   "<br>\nWARNING: Wrong number of parameters for "
995                   "permit-access directive in configuration file.<br><br>\n");
996
997                continue;
998             }
999
1000             /* allocate a new node */
1001             cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1002
1003             if (cur_acl == NULL)
1004             {
1005                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1006                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1007                continue;
1008             }
1009             cur_acl->action = ACL_PERMIT;
1010
1011             if (acl_addr(vec[0], cur_acl->src) < 0)
1012             {
1013                log_error(LOG_LEVEL_ERROR, "Invalid source IP for permit-access "
1014                      "directive in configuration file: \"%s\"", vec[0]);
1015                string_append(&config->proxy_args,
1016                   "<br>\nWARNING: Invalid source IP for permit-access directive"
1017                   " in configuration file: \"");
1018                string_append(&config->proxy_args,
1019                   vec[0]);
1020                string_append(&config->proxy_args,
1021                   "\"<br><br>\n");
1022                freez(cur_acl);
1023                continue;
1024             }
1025             if (vec_count == 2)
1026             {
1027                if (acl_addr(vec[1], cur_acl->dst) < 0)
1028                {
1029                   log_error(LOG_LEVEL_ERROR, "Invalid destination IP for "
1030                         "permit-access directive in configuration file: \"%s\"",
1031                         vec[0]);
1032                   string_append(&config->proxy_args,
1033                      "<br>\nWARNING: Invalid destination IP for permit-access directive"
1034                      " in configuration file: \"");
1035                   string_append(&config->proxy_args,
1036                      vec[0]);
1037                   string_append(&config->proxy_args,
1038                      "\"<br><br>\n");
1039                   freez(cur_acl);
1040                   continue;
1041                }
1042             }
1043
1044             /*
1045              * Add it to the list.  Note we reverse the list to get the
1046              * behaviour the user expects.  With both the ACL and
1047              * actions file, the last match wins.  However, the internal
1048              * implementations are different:  The actions file is stored
1049              * in the same order as the file, and scanned completely.
1050              * With the ACL, we reverse the order as we load it, then
1051              * when we scan it we stop as soon as we get a match.
1052              */
1053             cur_acl->next  = config->acl;
1054             config->acl = cur_acl;
1055
1056             continue;
1057 #endif /* def FEATURE_ACL */
1058
1059 /****************************************************************************
1060  * proxy-info-url url
1061  ****************************************************************************/
1062          case hash_proxy_info_url :
1063             freez(config->proxy_info_url);
1064             config->proxy_info_url = strdup(arg);
1065             continue;
1066
1067 /****************************************************************************
1068  * re_filterfile file-name
1069  * In confdir by default.
1070  ****************************************************************************/
1071          case hash_re_filterfile :
1072             freez(config->re_filterfile);
1073             config->re_filterfile = make_path(config->confdir, arg);
1074             continue;
1075
1076 /****************************************************************************
1077  * single-threaded
1078  ****************************************************************************/
1079          case hash_single_threaded :
1080             config->multi_threaded = 0;
1081             continue;
1082
1083 /****************************************************************************
1084  * toggle (0|1)
1085  ****************************************************************************/
1086 #ifdef FEATURE_TOGGLE
1087          case hash_toggle :
1088             g_bToggleIJB = atoi(arg);
1089             continue;
1090 #endif /* def FEATURE_TOGGLE */
1091
1092 /****************************************************************************
1093  * trust-info-url url
1094  ****************************************************************************/
1095 #ifdef FEATURE_TRUST
1096          case hash_trust_info_url :
1097             enlist(config->trust_info, arg);
1098             continue;
1099 #endif /* def FEATURE_TRUST */
1100
1101 /****************************************************************************
1102  * trustfile filename
1103  * (In confdir by default.)
1104  ****************************************************************************/
1105 #ifdef FEATURE_TRUST
1106          case hash_trustfile :
1107             freez(config->trustfile);
1108             config->trustfile = make_path(config->confdir, arg);
1109             continue;
1110 #endif /* def FEATURE_TRUST */
1111
1112
1113 /****************************************************************************
1114  * Win32 Console options:
1115  ****************************************************************************/
1116
1117 /****************************************************************************
1118  * hide-console
1119  ****************************************************************************/
1120 #ifdef _WIN_CONSOLE
1121          case hash_hide_console :
1122             hideConsole = 1;
1123             continue;
1124 #endif /*def _WIN_CONSOLE*/
1125
1126
1127 /****************************************************************************
1128  * Win32 GUI options:
1129  ****************************************************************************/
1130
1131 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1132 /****************************************************************************
1133  * activity-animation (0|1)
1134  ****************************************************************************/
1135          case hash_activity_animation :
1136             g_bShowActivityAnimation = atoi(arg);
1137             continue;
1138
1139 /****************************************************************************
1140  *  close-button-minimizes (0|1)
1141  ****************************************************************************/
1142          case hash_close_button_minimizes :
1143             g_bCloseHidesWindow = atoi(arg);
1144             continue;
1145
1146 /****************************************************************************
1147  * log-buffer-size (0|1)
1148  ****************************************************************************/
1149          case hash_log_buffer_size :
1150             g_bLimitBufferSize = atoi(arg);
1151             continue;
1152
1153 /****************************************************************************
1154  * log-font-name fontnane
1155  ****************************************************************************/
1156          case hash_log_font_name :
1157             strcpy( g_szFontFaceName, arg );
1158             continue;
1159
1160 /****************************************************************************
1161  * log-font-size n
1162  ****************************************************************************/
1163          case hash_log_font_size :
1164             g_nFontSize = atoi(arg);
1165             continue;
1166
1167 /****************************************************************************
1168  * log-highlight-messages (0|1)
1169  ****************************************************************************/
1170          case hash_log_highlight_messages :
1171             g_bHighlightMessages = atoi(arg);
1172             continue;
1173
1174 /****************************************************************************
1175  * log-max-lines n
1176  ****************************************************************************/
1177          case hash_log_max_lines :
1178             g_nMaxBufferLines = atoi(arg);
1179             continue;
1180
1181 /****************************************************************************
1182  * log-messages (0|1)
1183  ****************************************************************************/
1184          case hash_log_messages :
1185             g_bLogMessages = atoi(arg);
1186             continue;
1187
1188 /****************************************************************************
1189  * show-on-task-bar (0|1)
1190  ****************************************************************************/
1191          case hash_show_on_task_bar :
1192             g_bShowOnTaskBar = atoi(arg);
1193             continue;
1194
1195 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1196
1197
1198 /****************************************************************************/
1199 /* Warnings about unsupported features                                      */
1200 /****************************************************************************/
1201 #ifndef FEATURE_ACL
1202          case hash_deny_access:
1203 #endif /* ndef FEATURE_ACL */
1204 #ifndef FEATURE_CGI_EDIT_ACTIONS
1205          case hash_enable_edit_actions:
1206          case hash_enable_remote_toggle:
1207 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1208 #ifndef FEATURE_COOKIE_JAR
1209          case hash_jarfile :
1210 #endif /* ndef FEATURE_COOKIE_JAR */
1211 #ifndef FEATURE_ACL
1212          case hash_permit_access:
1213 #endif /* ndef FEATURE_ACL */
1214 #ifndef FEATURE_TOGGLE
1215          case hash_toggle :
1216 #endif /* ndef FEATURE_TOGGLE */
1217 #ifndef FEATURE_TRUST
1218          case hash_trustfile :
1219          case hash_trust_info_url :
1220 #endif /* ndef FEATURE_TRUST */
1221
1222 #ifndef _WIN_CONSOLE
1223          case hash_hide_console :
1224 #endif /* ndef _WIN_CONSOLE */
1225
1226 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1227          case hash_activity_animation :
1228          case hash_close_button_minimizes :
1229          case hash_log_buffer_size :
1230          case hash_log_font_name :
1231          case hash_log_font_size :
1232          case hash_log_highlight_messages :
1233          case hash_log_max_lines :
1234          case hash_log_messages :
1235          case hash_show_on_task_bar :
1236 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1237             /* These warnings are annoying - so hide them. -- Jon */
1238             /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1239             continue;
1240
1241 /****************************************************************************/
1242          default :
1243 /****************************************************************************/
1244             /*
1245              * I decided that I liked this better as a warning than an
1246              * error.  To change back to an error, just change log level
1247              * to LOG_LEVEL_FATAL.
1248              */
1249             log_error(LOG_LEVEL_ERROR, "Unrecognized directive '%s' (%luul) in line %lu in "
1250                   "configuration file (%s).",  buf, hash_string(cmd), linenum, configfile);
1251             string_append(&config->proxy_args, "<br>\nWARNING: unrecognized directive : ");
1252             string_append(&config->proxy_args, buf);
1253             string_append(&config->proxy_args, "<br><br>\n");
1254             continue;
1255
1256 /****************************************************************************/
1257       } /* end switch( hash_string(cmd) ) */
1258    } /* end while ( read_config_line(...) ) */
1259
1260    fclose(configfp);
1261
1262    if (NULL == config->proxy_args)
1263    {
1264       log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1265    }
1266
1267    init_error_log(Argv[0], config->logfile, config->debug);
1268
1269    if (config->actions_file)
1270    {
1271       add_loader(load_actions_file, config);
1272    }
1273
1274    if (config->re_filterfile)
1275    {
1276       add_loader(load_re_filterfile, config);
1277    }
1278
1279 #ifdef FEATURE_TRUST
1280    if (config->trustfile)
1281    {
1282       add_loader(load_trustfile, config);
1283    }
1284 #endif /* def FEATURE_TRUST */
1285
1286 #ifdef FEATURE_COOKIE_JAR
1287    if ( NULL != config->jarfile )
1288    {
1289       if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1290       {
1291          log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1292          /* Never get here - LOG_LEVEL_FATAL causes program exit */
1293       }
1294       setbuf(config->jar, NULL);
1295    }
1296 #endif /* def FEATURE_COOKIE_JAR */
1297
1298    if ( NULL == config->haddr )
1299    {
1300       config->haddr = strdup( HADDR_DEFAULT );
1301    }
1302
1303    if ( NULL != config->haddr )
1304    {
1305       if ((p = strchr(config->haddr, ':')))
1306       {
1307          *p++ = '\0';
1308          if (*p)
1309          {
1310             config->hport = atoi(p);
1311          }
1312       }
1313
1314       if (config->hport <= 0)
1315       {
1316          *--p = ':';
1317          log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1318          /* Never get here - LOG_LEVEL_FATAL causes program exit */
1319       }
1320       if (*config->haddr == '\0')
1321       {
1322          config->haddr = NULL;
1323       }
1324    }
1325
1326    /*
1327     * Want to run all the loaders once now.
1328     *
1329     * Need to set up a fake csp, so they can get to the config.
1330     */
1331    fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1332    fake_csp->config = config;
1333
1334    if (run_loader(fake_csp))
1335    {
1336       freez(fake_csp);
1337       log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1338       /* Never get here - LOG_LEVEL_FATAL causes program exit */
1339    }
1340    freez(fake_csp);
1341
1342 /* FIXME: this is a kludge for win32 */
1343 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1344
1345    g_actions_file     = config->actions_file;
1346    g_re_filterfile    = config->re_filterfile;
1347
1348 #ifdef FEATURE_TRUST
1349    g_trustfile        = config->trustfile;
1350 #endif /* def FEATURE_TRUST */
1351
1352
1353 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1354 /* FIXME: end kludge */
1355
1356
1357    config->need_bind = 1;
1358
1359    if (current_configfile)
1360    {
1361       struct configuration_spec * oldcfg = (struct configuration_spec *)
1362                                            current_configfile->f;
1363       /*
1364        * Check if config->haddr,hport == oldcfg->haddr,hport
1365        *
1366        * The following could be written more compactly as a single,
1367        * (unreadably long) if statement.
1368        */
1369       config->need_bind = 0;
1370       if (config->hport != oldcfg->hport)
1371       {
1372          config->need_bind = 1;
1373       }
1374       else if (config->haddr == NULL)
1375       {
1376          if (oldcfg->haddr != NULL)
1377          {
1378             config->need_bind = 1;
1379          }
1380       }
1381       else if (oldcfg->haddr == NULL)
1382       {
1383          config->need_bind = 1;
1384       }
1385       else if (0 != strcmp(config->haddr, oldcfg->haddr))
1386       {
1387          config->need_bind = 1;
1388       }
1389
1390       current_configfile->unloader = unload_configfile;
1391    }
1392
1393    fs->next = files->next;
1394    files->next = fs;
1395
1396    current_configfile = fs;
1397
1398    return (config);
1399 }
1400
1401
1402 /*********************************************************************
1403  *
1404  * Function    :  savearg
1405  *
1406  * Description :  Called from `load_config'.  It saves each non-empty
1407  *                and non-comment line from config into
1408  *                config->proxy_args.  This is used to create the
1409  *                show-proxy-args page.  On error, frees
1410  *                config->proxy_args and sets it to NULL
1411  *
1412  * Parameters  :
1413  *          1  :  command = config setting that was found
1414  *          2  :  argument = the setting's argument (if any)
1415  *
1416  * Returns     :  N/A
1417  *
1418  *********************************************************************/
1419 static void savearg(char *command, char *argument, struct configuration_spec * config)
1420 {
1421    char * buf;
1422    char * s;
1423
1424    assert(command);
1425    assert(*command);
1426    assert(argument);
1427
1428    buf = strdup("");
1429
1430    s = html_encode(command);
1431    if (NULL == s)
1432    {
1433       freez(buf);
1434       freez(config->proxy_args);
1435       return;
1436    }
1437    string_append(&buf, "<a href=\"" REDIRECT_URL "option#");
1438    string_append(&buf, s);
1439    string_append(&buf, "\">");
1440    string_join  (&buf, s);
1441    string_append(&buf, "</a> ");
1442
1443    if ( (NULL != argument) && ('\0' != *argument) )
1444    {
1445       s = html_encode(argument);
1446       if (NULL == s)
1447       {
1448          freez(buf);
1449          freez(config->proxy_args);
1450          return;
1451       }
1452
1453       if (strncmpic(argument, "http://", 7) == 0)
1454       {
1455          string_append(&buf, "<a href=\"");
1456          string_append(&buf, s);
1457          string_append(&buf, "\">");
1458          string_join  (&buf, s);
1459          string_append(&buf, "</a>");
1460       }
1461       else
1462       {
1463          string_join  (&buf, s);
1464       }
1465    }
1466
1467    string_append(&buf, "<br>\n");
1468
1469    string_join(&config->proxy_args, buf);
1470 }
1471
1472
1473 /*
1474   Local Variables:
1475   tab-width: 3
1476   end:
1477 */