Unified blocklist/imagelist/permissionslist.
[privoxy.git] / loadcfg.c
1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.6 2001/05/26 00:28:36 jongfoster 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.6  2001/05/26 00:28:36  jongfoster
39  *    Automatic reloading of config file.
40  *    Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
41  *    Most of the global variables have been moved to a new
42  *    struct configuration_spec, accessed through csp->config->globalname
43  *    Most of the globals remaining are used by the Win32 GUI.
44  *
45  *    Revision 1.5  2001/05/25 22:34:30  jongfoster
46  *    Hard tabs->Spaces
47  *
48  *    Revision 1.4  2001/05/22 18:46:04  oes
49  *
50  *    - Enabled filtering banners by size rather than URL
51  *      by adding patterns that replace all standard banner
52  *      sizes with the "Junkbuster" gif to the re_filterfile
53  *
54  *    - Enabled filtering WebBugs by providing a pattern
55  *      which kills all 1x1 images
56  *
57  *    - Added support for PCRE_UNGREEDY behaviour to pcrs,
58  *      which is selected by the (nonstandard and therefore
59  *      capital) letter 'U' in the option string.
60  *      It causes the quantifiers to be ungreedy by default.
61  *      Appending a ? turns back to greedy (!).
62  *
63  *    - Added a new interceptor ijb-send-banner, which
64  *      sends back the "Junkbuster" gif. Without imagelist or
65  *      MSIE detection support, or if tinygif = 1, or the
66  *      URL isn't recognized as an imageurl, a lame HTML
67  *      explanation is sent instead.
68  *
69  *    - Added new feature, which permits blocking remote
70  *      script redirects and firing back a local redirect
71  *      to the browser.
72  *      The feature is conditionally compiled, i.e. it
73  *      can be disabled with --disable-fast-redirects,
74  *      plus it must be activated by a "fast-redirects"
75  *      line in the config file, has its own log level
76  *      and of course wants to be displayed by show-proxy-args
77  *      Note: Boy, all the #ifdefs in 1001 locations and
78  *      all the fumbling with configure.in and acconfig.h
79  *      were *way* more work than the feature itself :-(
80  *
81  *    - Because a generic redirect template was needed for
82  *      this, tinygif = 3 now uses the same.
83  *
84  *    - Moved GIFs, and other static HTTP response templates
85  *      to project.h
86  *
87  *    - Some minor fixes
88  *
89  *    - Removed some >400 CRs again (Jon, you really worked
90  *      a lot! ;-)
91  *
92  *    Revision 1.3  2001/05/20 01:21:20  jongfoster
93  *    Version 2.9.4 checkin.
94  *    - Merged popupfile and cookiefile, and added control over PCRS
95  *      filtering, in new "permissionsfile".
96  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
97  *      file error you now get a message box (in the Win32 GUI) rather
98  *      than the program exiting with no explanation.
99  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
100  *      skipping.
101  *    - Removed tabs from "config"
102  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
103  *    - Bumped up version number.
104  *
105  *    Revision 1.2  2001/05/17 23:01:01  oes
106  *     - Cleaned CRLF's from the sources and related files
107  *
108  *    Revision 1.1.1.1  2001/05/15 13:58:58  oes
109  *    Initial import of version 2.9.3 source tree
110  *
111  *
112  *********************************************************************/
113 \f
114
115 #include "config.h"
116
117 #include <stdio.h>
118 #include <sys/types.h>
119 #include <stdlib.h>
120 #include <string.h>
121 #include <signal.h>
122 #include <fcntl.h>
123 #include <errno.h>
124 #include <ctype.h>
125
126 #ifdef _WIN32
127
128 # include <sys/timeb.h>
129 # include <windows.h>
130 # include <io.h>
131 # include <process.h>
132 # ifdef TOGGLE
133 #  include <time.h>
134 # endif /* def TOGGLE */
135
136 # include "win32.h"
137 # ifndef _WIN_CONSOLE
138 #  include "w32log.h"
139 # endif /* ndef _WIN_CONSOLE */
140
141 #else /* ifndef _WIN32 */
142
143 # include <unistd.h>
144 # include <sys/time.h>
145 # include <sys/wait.h>
146 # include <sys/stat.h>
147 # include <signal.h>
148
149 #endif
150
151 #include "loadcfg.h"
152 #include "jcc.h"
153 #include "filters.h"
154 #include "loaders.h"
155 #include "showargs.h"
156 #include "parsers.h"
157 #include "killpopup.h"
158 #include "miscutil.h"
159 #include "errlog.h"
160 #include "jbsockets.h"
161 #include "gateway.h"
162
163 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
164
165 /*
166  * Fix a problem with Solaris.  There should be no effect on other
167  * platforms.
168  * Solaris's isspace() is a macro which uses it's argument directly
169  * as an array index.  Therefore we need to make sure that high-bit
170  * characters generate +ve values, and ideally we also want to make
171  * the argument match the declared parameter type of "int".
172  */
173 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
174 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
175
176 static const char VANILLA_WAFER[] =
177    "NOTICE=TO_WHOM_IT_MAY_CONCERN_"
178    "Do_not_send_me_any_copyrighted_information_other_than_the_"
179    "document_that_I_am_requesting_or_any_of_its_necessary_components._"
180    "In_particular_do_not_send_me_any_cookies_that_"
181    "are_subject_to_a_claim_of_copyright_by_anybody._"
182    "Take_notice_that_I_refuse_to_be_bound_by_any_license_condition_"
183    "(copyright_or_otherwise)_applying_to_any_cookie._";
184
185 #ifdef TOGGLE
186 /* by haroon - indicates if ijb is enabled */
187 int g_bToggleIJB        = 1;   /* JunkBusters is enabled by default. */
188 #endif
189
190 /* The filename of the configfile */
191 const char *configfile  = NULL;
192
193 /*
194  * The load_config function is now going to call `init_proxy_args',
195  * so it will need argc and argv.  So we need to have these
196  * globally available.
197  */
198 int Argc = 0;
199 const char **Argv = NULL;
200
201 static struct file_list *current_configfile = NULL;
202
203
204 /*
205  * This takes the "cryptic" hash of each keyword and aliases them to
206  * something a little more readable.  This also makes changing the
207  * hash values easier if they should change or the hash algorthm changes.
208  * Use the included "hash" program to find out what the hash will be
209  * for any string supplied on the command line.  (Or just put it in the
210  * config file and read the number from the error message in the log).
211  */
212
213 #define hash_trustfile                 56494766ul
214 #define hash_trust_info_url            449869467ul
215 #define hash_debug                     78263ul
216 #define hash_tinygif                   2227702ul
217 #define hash_add_forwarded_header      3191044770ul
218 #define hash_single_threaded           4250084780ul
219 #define hash_suppress_vanilla_wafer    3121233547ul
220 #define hash_wafer                     89669ul
221 #define hash_add_header                237434619ul
222 #define hash_permissions_file          3825730796lu /* "permissionsfile" */
223 #define hash_logfile                   2114766ul
224 #define hash_blockfile                 48845391ul
225 #define hash_imagefile                 51447891ul
226 #define hash_jarfile                   2046641ul
227 #define hash_listen_address            1255650842ul
228 #define hash_forwardfile               1268669141ul
229 #define hash_aclfile                   1908516ul
230 #define hash_re_filterfile             3877522444ul
231 #define hash_user_agent                283326691ul
232 #define hash_referrer                  10883969ul
233 #define hash_referer                   2176719ul
234 #define hash_from                      16264ul
235 #define hash_fast_redirects            464873764lu
236 #define hash_hide_console              2048809870ul
237 #define hash_include_stats             2174146548ul
238 #define hash_suppress_blocklists       1948693308ul
239 #define hash_toggle                    447966ul
240
241 #define hash_activity_animation        1817904738ul
242 #define hash_log_messages              2291744899ul
243 #define hash_log_highlight_messages    4032101240ul
244 #define hash_log_buffer_size           2918070425ul
245 #define hash_log_max_lines             2868344173ul
246 #define hash_log_font_name             2866730124ul
247 #define hash_log_font_size             2866731014ul
248 #define hash_show_on_task_bar          215410365ul
249 #define hash_close_button_minimizes    3651284693ul
250
251
252
253 /*********************************************************************
254  *
255  * Function    :  unload_configfile
256  *
257  * Description :  Free the config structure and all components.
258  *
259  * Parameters  :
260  *          1  :  data: struct configuration_spec to unload
261  *
262  * Returns     :  N/A
263  *
264  *********************************************************************/
265 void unload_configfile (void * data)
266 {
267    struct configuration_spec * config = (struct configuration_spec *)data;
268
269 #ifdef JAR_FILES
270    if ( NULL != config->jar )
271    {
272       fclose( config->jar );
273       config->jar = NULL;
274    }
275 #endif /* def JAR_FILES */
276 #ifdef IMAGE_BLOCKING
277    freez((char *)config->tinygifurl);
278 #endif /* def IMAGE_BLOCKING */
279
280    freez((char *)config->from);
281    freez((char *)config->haddr);
282    freez((char *)config->uagent);
283    freez((char *)config->referrer);
284    freez((char *)config->logfile);
285
286    freez((char *)config->permissions_file);
287    freez((char *)config->forwardfile);
288
289 #ifdef ACL_FILES
290    freez((char *)config->aclfile);
291 #endif /* def ACL_FILES */
292
293 #ifdef JAR_FILES
294    freez((char *)config->jarfile);
295 #endif /* def JAR_FILES */
296
297 #ifndef SPLIT_PROXY_ARGS
298    freez((char *)config->suppress_message);
299 #endif /* ndef SPLIT_PROXY_ARGS */
300
301 #ifdef PCRS
302    freez((char *)config->re_filterfile);
303 #endif /* def PCRS */
304
305 }
306
307
308 /*********************************************************************
309  *
310  * Function    :  load_config
311  *
312  * Description :  Load the config file and all parameters.
313  *
314  * Parameters  :
315  *          1  :  csp = Client state (the config member will be 
316  *                filled in by this function).
317  *
318  * Returns     :  0 => Ok, everything else is an error.
319  *
320  *********************************************************************/
321 struct configuration_spec * load_config(void)
322 {
323    char buf[BUFSIZ];
324    char *p, *q;
325    FILE *configfp = NULL;
326    struct configuration_spec * config = NULL;
327    int suppress_vanilla_wafer;
328    struct client_state * fake_csp;
329
330    struct file_list *fs;
331
332    if (!check_file_changed(current_configfile, configfile, &fs))
333    {
334       /* No need to load */
335       return ((struct configuration_spec *)current_configfile->f);
336    }
337    if (!fs)
338    {
339       log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s':  %E",
340                 configfile);
341    }
342
343    log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
344
345 #ifdef TOGGLE
346    g_bToggleIJB      = 1;
347 #endif
348
349    fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
350
351    if (config==NULL)
352    {
353       freez(fs->filename);
354       freez(fs);
355       log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
356       /* Never get here - LOG_LEVEL_FATAL causes program exit */
357    }
358
359    /*
360     * This is backwards from how it's usually done.
361     * Following the usual pattern, "fs" would be stored in a member 
362     * variable in "csp", and then we'd access "config" from "fs->f",
363     * using a cast.  However, "config" is used so often that a 
364     * cast each time would be very ugly, and the extra indirection
365     * would waste CPU cycles.  Therefore we store "config" in
366     * "csp->config", and "fs" in "csp->config->config_file_list".
367     */
368    config->config_file_list = fs;
369
370    init_proxy_args(Argc, Argv, config);
371
372    /*
373     * Set to defaults
374     */
375
376    config->multi_threaded    = 1;
377    config->default_permissions = PERMIT_RE_FILTER | PERMIT_FAST_REDIRECTS;
378    config->hport             = HADDR_PORT;
379
380    if ((configfp = fopen(configfile, "r")) == NULL)
381    {
382       log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s':  %E",
383               configfile);
384       /* Never get here - LOG_LEVEL_FATAL causes program exit */
385    }
386
387    while (read_config_line(buf, sizeof(buf), configfp, fs) != NULL)
388    {
389       char cmd[BUFSIZ];
390       char arg[BUFSIZ];
391       char tmp[BUFSIZ];
392
393       strcpy(tmp, buf);
394
395       /* Copy command (i.e. up to space or tab) into cmd */
396       p = buf;
397       q = cmd;
398       while (*p && (*p != ' ') && (*p != '\t'))
399       {
400          *q++ = *p++;
401       }
402       *q = '\0';
403
404       /* Skip over the whitespace in buf */
405       while (*p && ((*p == ' ') || (*p == '\t')))
406       {
407          p++;
408       }
409
410       /* Copy the argument into arg */
411       strcpy(arg, p);
412
413       /* Should never happen, but check this anyway */
414       if (*cmd == '\0')
415       {
416          continue;
417       }
418
419       /* Make sure the command field is lower case */
420       for (p=cmd; *p; p++)
421       {
422          if (ijb_isupper(*p))
423          {
424             *p = ijb_tolower(*p);
425          }
426       }
427
428       /* Save the argument for show-proxy-args */
429       savearg(cmd, arg, config);
430
431
432       switch( hash_string( cmd ) )
433       {
434 #ifdef TRUST_FILES
435          case hash_trustfile :
436             freez((char *)config->trustfile);
437             config->trustfile = strdup(arg);
438             continue;
439
440          case hash_trust_info_url :
441             enlist(config->trust_info, arg);
442             continue;
443 #endif /* def TRUST_FILES */
444
445          case hash_debug :
446             config->debug |= atoi(arg);
447             continue;
448
449 #ifdef IMAGE_BLOCKING
450          case hash_tinygif :
451             freez((char *)config->tinygifurl);
452             config->tinygif = atoi(arg);
453             if(3 == config->tinygif)
454             {
455                p = arg;
456                while((*p >= '0') && (*p <= '9'))
457                {
458                   p++;
459                }
460                while((*p == ' ') || (*p == '\t'))
461                {
462                   p++;
463                }
464                if (*p)
465                {
466                   q = malloc(strlen(p) + 5);
467                   if (q)
468                   {
469                      strcpy(q, p);
470                      strcat(q, "\r\n\r\n");
471                      config->tinygifurl = q;
472                   }
473                }
474             }
475             if ((config->tinygif != 1) && 
476                 (config->tinygif != 2) && 
477                 ((config->tinygif != 3) || (config->tinygifurl==NULL)) )
478             {
479                log_error(LOG_LEVEL_ERROR, "tinygif setting invalid.");
480             }
481             continue;
482 #endif /* def IMAGE_BLOCKING */
483
484          case hash_add_forwarded_header :
485             config->add_forwarded = 1;
486             continue;
487
488          case hash_single_threaded :
489             config->multi_threaded = 0;
490             continue;
491
492          case hash_suppress_vanilla_wafer :
493             suppress_vanilla_wafer = 1;
494             continue;
495
496          case hash_wafer :
497             enlist(config->wafer_list, arg);
498             continue;
499
500          case hash_add_header :
501             enlist(config->xtra_list, arg);
502             continue;
503
504          case hash_permissions_file :
505             freez((char *)config->permissions_file);
506             config->permissions_file = strdup(arg);
507             continue;
508
509          case hash_logfile :
510             freez((char *)config->logfile);
511             config->logfile = strdup(arg);
512             continue;
513
514 #ifdef JAR_FILES
515          case hash_jarfile :
516             freez((char *)config->jarfile);
517             config->jarfile = strdup(arg);
518             continue;
519 #endif /* def JAR_FILES */
520
521          case hash_listen_address :
522             freez((char *)config->haddr);
523             config->haddr = strdup(arg);
524             continue;
525
526          case hash_forwardfile :
527             freez((char *)config->forwardfile);
528             config->forwardfile = strdup(arg);
529             continue;
530
531 #ifdef ACL_FILES
532          case hash_aclfile :
533             freez((char *)config->aclfile);
534             config->aclfile = strdup(arg);
535             continue;
536 #endif /* def ACL_FILES */
537
538 #ifdef PCRS
539          case hash_re_filterfile :
540             freez((char *)config->re_filterfile);
541             config->re_filterfile = strdup(arg);
542             continue;
543 #endif /* def PCRS */
544
545          case hash_user_agent :
546             freez((char *)config->uagent);
547             config->uagent = strdup(arg);
548             continue;
549
550             /*
551              * Offer choice of correct spelling according to dictionary,
552              * or the misspelling used in the HTTP spec.
553              */
554          case hash_referrer :
555          case hash_referer :
556             freez((char *)config->referrer);
557             config->referrer = strdup(arg);
558             continue;
559
560          case hash_from :
561             freez((char *)config->from);
562             config->from = strdup(arg);
563             continue;
564 #ifdef _WIN_CONSOLE
565          case hash_hide_console :
566             hideConsole = 1;
567             continue;
568 #endif /*def _WIN_CONSOLE*/
569
570 #ifndef SPLIT_PROXY_ARGS
571          case hash_suppress_blocklists :
572             if (arg[0] != '\0')
573             {
574                config->suppress_message = strdup(arg);
575             }
576             else
577             {
578                /* There will be NO reference in proxy-args. */
579                config->suppress_message = NULL;
580             }
581
582             config->suppress_blocklists = 1;
583             continue;
584 #endif /* ndef SPLIT_PROXY_ARGS */
585
586 #ifdef TOGGLE
587          case hash_toggle :
588             g_bToggleIJB = atoi(arg);
589             continue;
590 #endif /* def TOGGLE */
591
592 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
593          case hash_activity_animation :
594             g_bShowActivityAnimation = atoi(arg);
595             continue;
596
597          case hash_log_messages :
598             g_bLogMessages = atoi(arg);
599             continue;
600
601          case hash_log_highlight_messages :
602             g_bHighlightMessages = atoi(arg);
603             continue;
604
605          case hash_log_buffer_size :
606             g_bLimitBufferSize = atoi(arg);
607             continue;
608
609          case hash_log_max_lines :
610             g_nMaxBufferLines = atoi(arg);
611             continue;
612
613          case hash_log_font_name :
614             strcpy( g_szFontFaceName, arg );
615             continue;
616
617          case hash_log_font_size :
618             g_nFontSize = atoi(arg);
619             continue;
620
621          case hash_show_on_task_bar :
622             g_bShowOnTaskBar = atoi(arg);
623             continue;
624
625          case hash_close_button_minimizes :
626             g_bCloseHidesWindow = atoi(arg);
627             continue;
628 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
629
630          /* Warnings about unsupported features */
631
632          case hash_blockfile :
633          case hash_imagefile :
634          case hash_fast_redirects :
635 #ifndef PCRS
636          case hash_re_filterfile :
637 #endif /* ndef PCRS */
638 #ifndef TOGGLE
639          case hash_toggle :
640 #endif /* ndef TOGGLE */
641 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
642          case hash_activity_animation :
643          case hash_log_messages :
644          case hash_log_highlight_messages :
645          case hash_log_buffer_size :
646          case hash_log_max_lines :
647          case hash_log_font_name :
648          case hash_log_font_size :
649          case hash_show_on_task_bar :
650          case hash_close_button_minimizes :
651 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
652 #ifndef _WIN_CONSOLE
653          case hash_hide_console :
654 #endif /* ndef _WIN_CONSOLE */
655 #ifndef IMAGE_BLOCKING
656          case hash_tinygif :
657 #endif /* def IMAGE_BLOCKING */
658 #ifndef JAR_FILES
659          case hash_jarfile :
660 #endif /* ndef JAR_FILES */
661 #ifndef ACL_FILES
662          case hash_aclfile :
663 #endif /* ndef ACL_FILES */
664 #ifdef SPLIT_PROXY_ARGS
665          case hash_suppress_blocklists :
666 #endif /* def SPLIT_PROXY_ARGS */
667             log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd);
668             continue;
669
670          default :
671             /*
672              * I decided that I liked this better as a warning than an
673              * error.  To change back to an error, just change log level
674              * to LOG_LEVEL_FATAL.
675              */
676             log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%lulu) in "
677                   "configuration file: \"%s\"", hash_string( cmd ), buf);
678             p = malloc( BUFSIZ );
679             if (p != NULL)
680             {
681                sprintf( p, "<br>\nWARNING: unrecognized directive : %s<br><br>\n", buf );
682                config->proxy_args_invocation = strsav( config->proxy_args_invocation, p );
683                freez( p );
684             }
685             continue;
686       } /* end switch( hash_string(cmd) ) */
687    } /* end while ( read_config_line(...) ) */
688
689    fclose(configfp);
690
691    init_error_log(Argv[0], config->logfile, config->debug);
692
693    if (config->permissions_file)
694    {
695       add_loader(load_permissions_file, config);
696    }
697
698    if (config->forwardfile)
699    {
700       add_loader(load_forwardfile, config);
701    }
702
703 #ifdef ACL_FILES
704    if (config->aclfile)
705    {
706       add_loader(load_aclfile, config);
707    }
708 #endif /* def ACL_FILES */
709
710 #ifdef PCRS
711    if (config->re_filterfile)
712    {
713       add_loader(load_re_filterfile, config);
714    }
715 #endif /* def PCRS */
716
717 #ifdef TRUST_FILES
718    if (config->trustfile)
719    {
720       add_loader(load_trustfile, config);
721    }
722 #endif
723
724 #ifdef JAR_FILES
725    if ( NULL != config->jarfile )
726    {
727       if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
728       {
729          log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
730          /* Never get here - LOG_LEVEL_FATAL causes program exit */
731       }
732       setbuf(config->jar, NULL);
733    }
734 #endif /* def JAR_FILES */
735
736    if ( NULL == config->haddr )
737    {
738       config->haddr = strdup( HADDR_DEFAULT );
739    }
740
741    if ( NULL != config->haddr )
742    {
743       if ((p = strchr(config->haddr, ':')))
744       {
745          *p++ = '\0';
746          if (*p)
747          {
748             config->hport = atoi(p);
749          }
750       }
751
752       if (config->hport <= 0)
753       {
754          *--p = ':';
755          log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
756          /* Never get here - LOG_LEVEL_FATAL causes program exit */
757       }
758       if (*config->haddr == '\0')
759       {
760          config->haddr = NULL;
761       }
762    }
763
764    /*
765     * Want to run all the loaders once now.
766     *
767     * Need to set up a fake csp, so they can get to the config.
768     */
769    fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
770    fake_csp->config = config;
771
772    if (run_loader(fake_csp))
773    {
774       freez(fake_csp);
775       log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
776       /* Never get here - LOG_LEVEL_FATAL causes program exit */
777    }
778    freez(fake_csp);
779
780 #ifdef JAR_FILES
781    /*
782     * If we're logging cookies in a cookie jar, and the user has not
783     * supplied any wafers, and the user has not told us to suppress the
784     * vanilla wafer, then send the vanilla wafer.
785     */
786    if ((config->jarfile != NULL)
787        && (config->wafer_list->next == NULL)
788        && (suppress_vanilla_wafer == 0))
789    {
790       enlist(config->wafer_list, VANILLA_WAFER);
791    }
792 #endif /* def JAR_FILES */
793
794    end_proxy_args(config);
795
796 #ifndef SPLIT_PROXY_ARGS
797    if (!suppress_blocklists)
798    {
799       fs->proxy_args = strsav(fs->proxy_args, "</pre>");
800    }
801 #endif /* ndef SPLIT_PROXY_ARGS */
802
803 /* FIXME: this is a kludge for win32 */
804 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
805
806    g_permissions_file = config->permissions_file;
807    g_forwardfile      = config->forwardfile;
808 #ifdef ACL_FILES
809    g_aclfile          = config->aclfile;
810 #endif /* def ACL_FILES */
811 #ifdef PCRS
812    g_re_filterfile    = config->re_filterfile;
813 #endif
814 #ifdef TRUST_FILES
815    g_trustfile        = config->trustfile;
816 #endif
817    
818
819 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
820 /* FIXME: end kludge */
821
822
823    config->need_bind = 1;
824
825    if (current_configfile)
826    {
827       struct configuration_spec * oldcfg = (struct configuration_spec *)
828                                            current_configfile->f;
829       /*
830        * Check if config->haddr,hport == oldcfg->haddr,hport
831        *
832        * The following could be written more compactly as a single,
833        * (unreadably long) if statement.
834        */
835       config->need_bind = 0;
836       if (config->hport != oldcfg->hport)
837       {
838          config->need_bind = 1;
839       }
840       else if (config->haddr == NULL)
841       {
842          if (oldcfg->haddr != NULL)
843          {
844             config->need_bind = 1;
845          }
846       }
847       else if (oldcfg->haddr == NULL)
848       {
849          config->need_bind = 1;
850       }
851       else if (0 != strcmp(config->haddr, oldcfg->haddr))
852       {
853          config->need_bind = 1;
854       }
855
856       current_configfile->unloader = unload_configfile;
857    }
858
859    fs->next = files->next;
860    files->next = fs;
861
862    current_configfile = fs;
863
864    return (config);
865 }
866
867
868 /*
869   Local Variables:
870   tab-width: 3
871   end:
872 */