1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.17 2001/06/29 13:31:03 oes Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
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.
11 * Copyright : Written by and Copyright (C) 2001 the SourceForge
12 * IJBSWA team. http://ijbswa.sourceforge.net
14 * Based on the Internet Junkbuster originally written
15 * by and Copyright (C) 1997 Anonymous Coders and
16 * Junkbusters Corporation. http://www.junkbusters.com
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.
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.
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.
38 * Revision 1.17 2001/06/29 13:31:03 oes
40 * - Fixed (actionsfile) and sorted hashes
41 * - Introduced admin_address and proxy-info-url
42 * as config parameters
43 * - Renamed config->proxy_args_invocation (which didn't have
44 * the invocation but the options!) to config->proxy_args
46 * - Removed logentry from cancelled commit
48 * Revision 1.16 2001/06/09 10:55:28 jongfoster
49 * Changing BUFSIZ ==> BUFFER_SIZE
51 * Revision 1.15 2001/06/07 23:13:40 jongfoster
52 * Merging ACL and forward files into config file.
53 * Cosmetic: Sorting config file options alphabetically.
54 * Cosmetic: Adding brief syntax comments to config file options.
56 * Revision 1.14 2001/06/07 14:46:25 joergs
57 * Missing make_path() added for re_filterfile.
59 * Revision 1.13 2001/06/05 22:33:54 jongfoster
61 * Fixed minor memory leak.
62 * Also now uses make_path to prepend the pathnames.
64 * Revision 1.12 2001/06/05 20:04:09 jongfoster
65 * Now uses _snprintf() in place of snprintf() under Win32.
67 * Revision 1.11 2001/06/04 18:31:58 swa
68 * files are now prefixed with either `confdir' or `logdir'.
69 * `make redhat-dist' replaces both entries confdir and logdir
72 * Revision 1.10 2001/06/03 19:11:54 oes
73 * introduced confdir option
75 * Revision 1.9 2001/06/01 20:06:24 jongfoster
76 * Removed support for "tinygif" option - moved to actions file.
78 * Revision 1.8 2001/05/31 21:27:13 jongfoster
79 * Removed many options from the config file and into the
80 * "actions" file: add_forwarded, suppress_vanilla_wafer,
81 * wafer, add_header, user_agent, referer, from
82 * Also globally replaced "permission" with "action".
84 * Revision 1.7 2001/05/29 09:50:24 jongfoster
85 * Unified blocklist/imagelist/permissionslist.
86 * File format is still under discussion, but the internal changes
89 * Also modified interceptor behaviour:
90 * - We now intercept all URLs beginning with one of the following
91 * prefixes (and *only* these prefixes):
93 * * http://ijbswa.sf.net/config/
94 * * http://ijbswa.sourceforge.net/config/
95 * - New interceptors "home page" - go to http://i.j.b/ to see it.
96 * - Internal changes so that intercepted and fast redirect pages
97 * are not replaced with an image.
98 * - Interceptors now have the option to send a binary page direct
99 * to the client. (i.e. ijb-send-banner uses this)
100 * - Implemented show-url-info interceptor. (Which is why I needed
101 * the above interceptors changes - a typical URL is
102 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
103 * The previous mechanism would not have intercepted that, and
104 * if it had been intercepted then it then it would have replaced
107 * Revision 1.6 2001/05/26 00:28:36 jongfoster
108 * Automatic reloading of config file.
109 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
110 * Most of the global variables have been moved to a new
111 * struct configuration_spec, accessed through csp->config->globalname
112 * Most of the globals remaining are used by the Win32 GUI.
114 * Revision 1.5 2001/05/25 22:34:30 jongfoster
117 * Revision 1.4 2001/05/22 18:46:04 oes
119 * - Enabled filtering banners by size rather than URL
120 * by adding patterns that replace all standard banner
121 * sizes with the "Junkbuster" gif to the re_filterfile
123 * - Enabled filtering WebBugs by providing a pattern
124 * which kills all 1x1 images
126 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
127 * which is selected by the (nonstandard and therefore
128 * capital) letter 'U' in the option string.
129 * It causes the quantifiers to be ungreedy by default.
130 * Appending a ? turns back to greedy (!).
132 * - Added a new interceptor ijb-send-banner, which
133 * sends back the "Junkbuster" gif. Without imagelist or
134 * MSIE detection support, or if tinygif = 1, or the
135 * URL isn't recognized as an imageurl, a lame HTML
136 * explanation is sent instead.
138 * - Added new feature, which permits blocking remote
139 * script redirects and firing back a local redirect
141 * The feature is conditionally compiled, i.e. it
142 * can be disabled with --disable-fast-redirects,
143 * plus it must be activated by a "fast-redirects"
144 * line in the config file, has its own log level
145 * and of course wants to be displayed by show-proxy-args
146 * Note: Boy, all the #ifdefs in 1001 locations and
147 * all the fumbling with configure.in and acconfig.h
148 * were *way* more work than the feature itself :-(
150 * - Because a generic redirect template was needed for
151 * this, tinygif = 3 now uses the same.
153 * - Moved GIFs, and other static HTTP response templates
158 * - Removed some >400 CRs again (Jon, you really worked
161 * Revision 1.3 2001/05/20 01:21:20 jongfoster
162 * Version 2.9.4 checkin.
163 * - Merged popupfile and cookiefile, and added control over PCRS
164 * filtering, in new "permissionsfile".
165 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
166 * file error you now get a message box (in the Win32 GUI) rather
167 * than the program exiting with no explanation.
168 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
170 * - Removed tabs from "config"
171 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
172 * - Bumped up version number.
174 * Revision 1.2 2001/05/17 23:01:01 oes
175 * - Cleaned CRLF's from the sources and related files
177 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
178 * Initial import of version 2.9.3 source tree
181 *********************************************************************/
187 #include <sys/types.h>
197 # include <sys/timeb.h>
198 # include <windows.h>
200 # include <process.h>
203 # endif /* def TOGGLE */
206 # ifndef _WIN_CONSOLE
208 # endif /* ndef _WIN_CONSOLE */
210 /* VC++ has "_snprintf", not "snprintf" */
211 #define snprintf _snprintf
213 #else /* ifndef _WIN32 */
216 # include <sys/time.h>
217 # include <sys/wait.h>
218 # include <sys/stat.h>
228 #include "showargs.h"
230 #include "killpopup.h"
231 #include "miscutil.h"
233 #include "jbsockets.h"
237 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
240 * Fix a problem with Solaris. There should be no effect on other
242 * Solaris's isspace() is a macro which uses it's argument directly
243 * as an array index. Therefore we need to make sure that high-bit
244 * characters generate +ve values, and ideally we also want to make
245 * the argument match the declared parameter type of "int".
247 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
248 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
251 /* by haroon - indicates if ijb is enabled */
252 int g_bToggleIJB = 1; /* JunkBusters is enabled by default. */
255 /* The filename of the configfile */
256 const char *configfile = NULL;
259 * CGI functions will later need access to the invocation args,
260 * so we will make argc and argv global.
263 const char **Argv = NULL;
265 static struct file_list *current_configfile = NULL;
269 * This takes the "cryptic" hash of each keyword and aliases them to
270 * something a little more readable. This also makes changing the
271 * hash values easier if they should change or the hash algorthm changes.
272 * Use the included "hash" program to find out what the hash will be
273 * for any string supplied on the command line. (Or just put it in the
274 * config file and read the number from the error message in the log).
276 * Please keep this list sorted alphabetically (but with the Windows
277 * console and GUI specific options last).
280 #define hash_actions_file 1196306641ul /* "actionsfile" */
281 #define hash_admin_address 4112573064ul /* "admin-address" */
282 #define hash_confdir 1978389ul /* "confdir" */
283 #define hash_debug 78263ul /* "debug" */
284 #define hash_deny_access 1227333715ul /* "deny-access" */
285 #define hash_forward 2029845ul /* "forward" */
286 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
287 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
288 #define hash_jarfile 2046641ul /* "jarfile" */
289 #define hash_listen_address 1255650842ul /* "listen-address" */
290 #define hash_logdir 422889ul /* "logdir" */
291 #define hash_logfile 2114766ul /* "logfile" */
292 #define hash_permit_access 3587953268ul /* "permit-access" */
293 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
294 #define hash_re_filterfile 3877522444ul /* "re_filterfile" */
295 #define hash_single_threaded 4250084780ul /* "single-threaded" */
296 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
297 #define hash_toggle 447966ul /* "toggle" */
298 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
299 #define hash_trustfile 56494766ul /* "trustfile" */
301 #define hash_activity_animation 1817904738ul /* "activity-animation" */
302 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
303 #define hash_hide_console 2048809870ul /* "hide-console" */
304 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
305 #define hash_log_font_name 2866730124ul /* "log-font-name" */
306 #define hash_log_font_size 2866731014ul /* "log-font-size" */
307 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
308 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
309 #define hash_log_messages 2291744899ul /* "log-messages" */
310 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
314 /*********************************************************************
316 * Function : unload_configfile
318 * Description : Free the config structure and all components.
321 * 1 : data: struct configuration_spec to unload
325 *********************************************************************/
326 void unload_configfile (void * data)
328 struct configuration_spec * config = (struct configuration_spec *)data;
329 struct forward_spec *cur_fwd = config->forward;
331 struct access_control_list *cur_acl = config->acl;
333 while (cur_acl != NULL)
335 struct access_control_list * next_acl = cur_acl->next;
340 #endif /* def ACL_FILES */
342 while (cur_fwd != NULL)
344 struct forward_spec * next_fwd = cur_fwd->next;
345 free_url(cur_fwd->url);
347 freez(cur_fwd->gateway_host);
348 freez(cur_fwd->forward_host);
352 config->forward = NULL;
355 if ( NULL != config->jar )
357 fclose( config->jar );
360 #endif /* def JAR_FILES */
362 freez((char *)config->confdir);
363 freez((char *)config->logdir);
365 freez((char *)config->haddr);
366 freez((char *)config->logfile);
368 freez((char *)config->actions_file);
369 freez((char *)config->admin_address);
370 freez((char *)config->proxy_info_url);
371 freez((char *)config->proxy_args);
374 freez((char *)config->jarfile);
375 #endif /* def JAR_FILES */
377 #ifndef SPLIT_PROXY_ARGS
378 freez((char *)config->suppress_message);
379 #endif /* ndef SPLIT_PROXY_ARGS */
381 freez((char *)config->re_filterfile);
386 /*********************************************************************
388 * Function : load_config
390 * Description : Load the config file and all parameters.
393 * 1 : csp = Client state (the config member will be
394 * filled in by this function).
396 * Returns : 0 => Ok, everything else is an error.
398 *********************************************************************/
399 struct configuration_spec * load_config(void)
401 char buf[BUFFER_SIZE];
403 FILE *configfp = NULL;
404 struct configuration_spec * config = NULL;
405 struct client_state * fake_csp;
406 struct file_list *fs;
408 if (!check_file_changed(current_configfile, configfile, &fs))
410 /* No need to load */
411 return ((struct configuration_spec *)current_configfile->f);
415 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
419 log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
425 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
431 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
432 /* Never get here - LOG_LEVEL_FATAL causes program exit */
436 * This is backwards from how it's usually done.
437 * Following the usual pattern, "fs" would be stored in a member
438 * variable in "csp", and then we'd access "config" from "fs->f",
439 * using a cast. However, "config" is used so often that a
440 * cast each time would be very ugly, and the extra indirection
441 * would waste CPU cycles. Therefore we store "config" in
442 * "csp->config", and "fs" in "csp->config->config_file_list".
444 config->config_file_list = fs;
450 config->multi_threaded = 1;
451 config->hport = HADDR_PORT;
453 if ((configfp = fopen(configfile, "r")) == NULL)
455 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
457 /* Never get here - LOG_LEVEL_FATAL causes program exit */
460 while (read_config_line(buf, sizeof(buf), configfp, fs) != NULL)
462 char cmd[BUFFER_SIZE];
463 char arg[BUFFER_SIZE];
464 char tmp[BUFFER_SIZE];
466 struct access_control_list *cur_acl;
467 #endif /* def ACL_FILES */
468 struct forward_spec *cur_fwd;
474 /* Copy command (i.e. up to space or tab) into cmd */
477 while (*p && (*p != ' ') && (*p != '\t'))
483 /* Skip over the whitespace in buf */
484 while (*p && ((*p == ' ') || (*p == '\t')))
489 /* Copy the argument into arg */
492 /* Should never happen, but check this anyway */
498 /* Make sure the command field is lower case */
503 *p = ijb_tolower(*p);
507 /* Save the argument for show-proxy-args */
508 savearg(cmd, arg, config);
511 switch( hash_string( cmd ) )
513 /****************************************************************************
514 * actionsfile actions-file-name
515 * In confdir by default
516 ****************************************************************************/
517 case hash_actions_file :
518 freez((char *)config->actions_file);
519 config->actions_file = make_path(config->confdir, arg);
522 /****************************************************************************
523 * admin-address email-address
524 ****************************************************************************/
525 case hash_admin_address :
526 freez((char *)config->admin_address);
527 config->admin_address = strdup(arg);
530 /****************************************************************************
531 * confdir directory-name
532 ****************************************************************************/
534 freez((char *)config->confdir);
535 config->confdir = strdup(arg);
538 /****************************************************************************
540 * Specifies debug level, multiple values are ORed together.
541 ****************************************************************************/
543 config->debug |= atoi(arg);
546 /****************************************************************************
547 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
548 ****************************************************************************/
550 case hash_deny_access:
551 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
553 if ((vec_count != 1) && (vec_count != 2))
555 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
556 "deny-access directive in configuration file.");
557 config->proxy_args = strsav( config->proxy_args,
558 "<br>\nWARNING: Wrong number of parameters for "
559 "deny-access directive in configuration file.<br><br>\n");
563 /* allocate a new node */
564 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
568 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
569 /* Never get here - LOG_LEVEL_FATAL causes program exit */
572 cur_acl->action = ACL_DENY;
574 if (acl_addr(vec[0], cur_acl->src) < 0)
576 log_error(LOG_LEVEL_ERROR, "Invalid source IP for deny-access "
577 "directive in configuration file: \"%s\"", vec[0]);
578 config->proxy_args = strsav( config->proxy_args,
579 "<br>\nWARNING: Invalid source IP for deny-access directive"
580 " in configuration file: \"");
581 config->proxy_args = strsav( config->proxy_args,
583 config->proxy_args = strsav( config->proxy_args,
590 if (acl_addr(vec[1], cur_acl->dst) < 0)
592 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for deny-access "
593 "directive in configuration file: \"%s\"", vec[0]);
594 config->proxy_args = strsav( config->proxy_args,
595 "<br>\nWARNING: Invalid destination IP for deny-access directive"
596 " in configuration file: \"");
597 config->proxy_args = strsav( config->proxy_args,
599 config->proxy_args = strsav( config->proxy_args,
607 * Add it to the list. Note we reverse the list to get the
608 * behaviour the user expects. With both the ACL and
609 * actions file, the last match wins. However, the internal
610 * implementations are different: The actions file is stored
611 * in the same order as the file, and scanned completely.
612 * With the ACL, we reverse the order as we load it, then
613 * when we scan it we stop as soon as we get a match.
615 cur_acl->next = config->acl;
616 config->acl = cur_acl;
619 #endif /* def ACL_FILES */
621 /****************************************************************************
622 * forward url-pattern (.|http-proxy-host[:port])
623 ****************************************************************************/
625 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
629 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
630 "directive in configuration file.");
631 config->proxy_args = strsav( config->proxy_args,
632 "<br>\nWARNING: Wrong number of parameters for "
633 "forward directive in configuration file.");
637 /* allocate a new node */
638 cur_fwd = zalloc(sizeof(*cur_fwd));
641 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
642 /* Never get here - LOG_LEVEL_FATAL causes program exit */
646 cur_fwd->type = SOCKS_NONE;
648 /* Save the URL pattern */
649 if (create_url_spec(cur_fwd->url, vec[0]))
651 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
652 "directive in configuration file.");
653 config->proxy_args = strsav( config->proxy_args,
654 "<br>\nWARNING: Bad URL specifier for "
655 "forward directive in configuration file.");
659 /* Parse the parent HTTP proxy host:port */
662 if (strcmp(p, ".") != 0)
664 cur_fwd->forward_host = strdup(p);
666 if ((p = strchr(cur_fwd->forward_host, ':')))
669 cur_fwd->forward_port = atoi(p);
672 if (cur_fwd->forward_port <= 0)
674 cur_fwd->forward_port = 8000;
679 cur_fwd->next = config->forward;
680 config->forward = cur_fwd;
684 /****************************************************************************
685 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
686 ****************************************************************************/
687 case hash_forward_socks4:
688 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
692 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
693 "forward-socks4 directive in configuration file.");
694 config->proxy_args = strsav( config->proxy_args,
695 "<br>\nWARNING: Wrong number of parameters for "
696 "forward-socks4 directive in configuration file.");
700 /* allocate a new node */
701 cur_fwd = zalloc(sizeof(*cur_fwd));
704 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
705 /* Never get here - LOG_LEVEL_FATAL causes program exit */
709 cur_fwd->type = SOCKS_4;
711 /* Save the URL pattern */
712 if (create_url_spec(cur_fwd->url, vec[0]))
714 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
715 "directive in configuration file.");
716 config->proxy_args = strsav( config->proxy_args,
717 "<br>\nWARNING: Bad URL specifier for "
718 "forward-socks4 directive in configuration file.");
722 /* Parse the SOCKS proxy host[:port] */
725 if (strcmp(p, ".") != 0)
727 cur_fwd->gateway_host = strdup(p);
729 if ((p = strchr(cur_fwd->gateway_host, ':')))
732 cur_fwd->gateway_port = atoi(p);
734 if (cur_fwd->gateway_port <= 0)
736 cur_fwd->gateway_port = 1080;
740 /* Parse the parent HTTP proxy host[:port] */
743 if (strcmp(p, ".") != 0)
745 cur_fwd->forward_host = strdup(p);
747 if ((p = strchr(cur_fwd->forward_host, ':')))
750 cur_fwd->forward_port = atoi(p);
753 if (cur_fwd->forward_port <= 0)
755 cur_fwd->forward_port = 8000;
760 cur_fwd->next = config->forward;
761 config->forward = cur_fwd;
765 /****************************************************************************
766 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
767 ****************************************************************************/
768 case hash_forward_socks4a:
769 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
773 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
774 "forward-socks4a directive in configuration file.");
775 config->proxy_args = strsav( config->proxy_args,
776 "<br>\nWARNING: Wrong number of parameters for "
777 "forward-socks4a directive in configuration file.");
781 /* allocate a new node */
782 cur_fwd = zalloc(sizeof(*cur_fwd));
785 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
786 /* Never get here - LOG_LEVEL_FATAL causes program exit */
790 cur_fwd->type = SOCKS_4A;
792 /* Save the URL pattern */
793 if (create_url_spec(cur_fwd->url, vec[0]))
795 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
796 "directive in configuration file.");
797 config->proxy_args = strsav( config->proxy_args,
798 "<br>\nWARNING: Bad URL specifier for "
799 "forward-socks4a directive in configuration file.");
803 /* Parse the SOCKS proxy host[:port] */
806 cur_fwd->gateway_host = strdup(p);
808 if ((p = strchr(cur_fwd->gateway_host, ':')))
811 cur_fwd->gateway_port = atoi(p);
813 if (cur_fwd->gateway_port <= 0)
815 cur_fwd->gateway_port = 1080;
818 /* Parse the parent HTTP proxy host[:port] */
821 if (strcmp(p, ".") != 0)
823 cur_fwd->forward_host = strdup(p);
825 if ((p = strchr(cur_fwd->forward_host, ':')))
828 cur_fwd->forward_port = atoi(p);
831 if (cur_fwd->forward_port <= 0)
833 cur_fwd->forward_port = 8000;
838 cur_fwd->next = config->forward;
839 config->forward = cur_fwd;
843 /****************************************************************************
844 * jarfile jar-file-name
845 * In logdir by default
846 ****************************************************************************/
849 freez((char *)config->jarfile);
850 config->jarfile = make_path(config->logdir, arg);
852 #endif /* def JAR_FILES */
854 /****************************************************************************
855 * listen-address [ip][:port]
856 ****************************************************************************/
857 case hash_listen_address :
858 freez((char *)config->haddr);
859 config->haddr = strdup(arg);
862 /****************************************************************************
863 * logdir directory-name
864 ****************************************************************************/
866 freez((char *)config->logdir);
867 config->logdir = strdup(arg);
870 /****************************************************************************
871 * logfile log-file-name
872 * In logdir by default
873 ****************************************************************************/
875 freez((char *)config->logfile);
876 config->logfile = make_path(config->logdir, arg);
879 /****************************************************************************
880 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
881 ****************************************************************************/
883 case hash_permit_access:
884 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
886 if ((vec_count != 1) && (vec_count != 2))
888 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
889 "permit-access directive in configuration file.");
890 config->proxy_args = strsav( config->proxy_args,
891 "<br>\nWARNING: Wrong number of parameters for "
892 "permit-access directive in configuration file.<br><br>\n");
897 /* allocate a new node */
898 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
902 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
903 /* Never get here - LOG_LEVEL_FATAL causes program exit */
906 cur_acl->action = ACL_PERMIT;
908 if (acl_addr(vec[0], cur_acl->src) < 0)
910 log_error(LOG_LEVEL_ERROR, "Invalid source IP for permit-access "
911 "directive in configuration file: \"%s\"", vec[0]);
912 config->proxy_args = strsav( config->proxy_args,
913 "<br>\nWARNING: Invalid source IP for permit-access directive"
914 " in configuration file: \"");
915 config->proxy_args = strsav( config->proxy_args,
917 config->proxy_args = strsav( config->proxy_args,
924 if (acl_addr(vec[1], cur_acl->dst) < 0)
926 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for "
927 "permit-access directive in configuration file: \"%s\"",
929 config->proxy_args = strsav( config->proxy_args,
930 "<br>\nWARNING: Invalid destination IP for permit-access directive"
931 " in configuration file: \"");
932 config->proxy_args = strsav( config->proxy_args,
934 config->proxy_args = strsav( config->proxy_args,
942 * Add it to the list. Note we reverse the list to get the
943 * behaviour the user expects. With both the ACL and
944 * actions file, the last match wins. However, the internal
945 * implementations are different: The actions file is stored
946 * in the same order as the file, and scanned completely.
947 * With the ACL, we reverse the order as we load it, then
948 * when we scan it we stop as soon as we get a match.
950 cur_acl->next = config->acl;
951 config->acl = cur_acl;
954 #endif /* def ACL_FILES */
956 /****************************************************************************
958 ****************************************************************************/
959 case hash_proxy_info_url :
960 freez((char *)config->proxy_info_url);
961 config->proxy_info_url = strdup(arg);
964 /****************************************************************************
965 * re_filterfile file-name
966 * In confdir by default.
967 ****************************************************************************/
968 case hash_re_filterfile :
969 freez((char *)config->re_filterfile);
970 config->re_filterfile = make_path(config->confdir, arg);
973 /****************************************************************************
975 ****************************************************************************/
976 case hash_single_threaded :
977 config->multi_threaded = 0;
980 /****************************************************************************
981 * FIXME: Document this FIXME2: Shouldn't we throw this out? --oes
982 ****************************************************************************/
983 #ifndef SPLIT_PROXY_ARGS
984 case hash_suppress_blocklists :
987 config->suppress_message = strdup(arg);
991 /* There will be NO reference in proxy-args. */
992 config->suppress_message = NULL;
995 config->suppress_blocklists = 1;
997 #endif /* ndef SPLIT_PROXY_ARGS */
999 /****************************************************************************
1001 ****************************************************************************/
1004 g_bToggleIJB = atoi(arg);
1006 #endif /* def TOGGLE */
1008 /****************************************************************************
1009 * trust-info-url url
1010 ****************************************************************************/
1012 case hash_trust_info_url :
1013 enlist(config->trust_info, arg);
1015 #endif /* def TRUST_FILES */
1017 /****************************************************************************
1018 * trustfile filename
1019 * (In confdir by default.)
1020 ****************************************************************************/
1022 case hash_trustfile :
1023 freez((char *)config->trustfile);
1024 config->trustfile = make_path(config->confdir, arg);
1026 #endif /* def TRUST_FILES */
1029 /****************************************************************************
1030 * Win32 Console options:
1031 ****************************************************************************/
1033 /****************************************************************************
1035 ****************************************************************************/
1037 case hash_hide_console :
1040 #endif /*def _WIN_CONSOLE*/
1043 /****************************************************************************
1044 * Win32 GUI options:
1045 ****************************************************************************/
1047 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1048 /****************************************************************************
1049 * activity-animation (0|1)
1050 ****************************************************************************/
1051 case hash_activity_animation :
1052 g_bShowActivityAnimation = atoi(arg);
1055 /****************************************************************************
1056 * close-button-minimizes (0|1)
1057 ****************************************************************************/
1058 case hash_close_button_minimizes :
1059 g_bCloseHidesWindow = atoi(arg);
1062 /****************************************************************************
1063 * log-buffer-size (0|1)
1064 ****************************************************************************/
1065 case hash_log_buffer_size :
1066 g_bLimitBufferSize = atoi(arg);
1069 /****************************************************************************
1070 * log-font-name fontnane
1071 ****************************************************************************/
1072 case hash_log_font_name :
1073 strcpy( g_szFontFaceName, arg );
1076 /****************************************************************************
1078 ****************************************************************************/
1079 case hash_log_font_size :
1080 g_nFontSize = atoi(arg);
1083 /****************************************************************************
1084 * log-highlight-messages (0|1)
1085 ****************************************************************************/
1086 case hash_log_highlight_messages :
1087 g_bHighlightMessages = atoi(arg);
1090 /****************************************************************************
1092 ****************************************************************************/
1093 case hash_log_max_lines :
1094 g_nMaxBufferLines = atoi(arg);
1097 /****************************************************************************
1098 * log-messages (0|1)
1099 ****************************************************************************/
1100 case hash_log_messages :
1101 g_bLogMessages = atoi(arg);
1104 /****************************************************************************
1105 * show-on-task-bar (0|1)
1106 ****************************************************************************/
1107 case hash_show_on_task_bar :
1108 g_bShowOnTaskBar = atoi(arg);
1111 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1114 /****************************************************************************/
1115 /* Warnings about unsupported features */
1116 /****************************************************************************/
1118 case hash_deny_access:
1119 #endif /* ndef ACL_FILES */
1122 #endif /* ndef JAR_FILES */
1124 case hash_permit_access:
1125 #endif /* ndef ACL_FILES */
1126 #ifdef SPLIT_PROXY_ARGS
1127 case hash_suppress_blocklists :
1128 #endif /* def SPLIT_PROXY_ARGS */
1131 #endif /* ndef TOGGLE */
1133 case hash_trustfile :
1134 case hash_trust_info_url :
1135 #endif /* ndef TRUST_FILES */
1137 #ifndef _WIN_CONSOLE
1138 case hash_hide_console :
1139 #endif /* ndef _WIN_CONSOLE */
1141 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1142 case hash_activity_animation :
1143 case hash_close_button_minimizes :
1144 case hash_log_buffer_size :
1145 case hash_log_font_name :
1146 case hash_log_font_size :
1147 case hash_log_highlight_messages :
1148 case hash_log_max_lines :
1149 case hash_log_messages :
1150 case hash_show_on_task_bar :
1151 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1152 /* These warnings are annoying - so hide them. -- Jon */
1153 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1156 /****************************************************************************/
1158 /****************************************************************************/
1160 * I decided that I liked this better as a warning than an
1161 * error. To change back to an error, just change log level
1162 * to LOG_LEVEL_FATAL.
1164 log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%luul) in "
1165 "configuration file: \"%s\"", hash_string( cmd ), buf);
1166 config->proxy_args = strsav( config->proxy_args, "<br>\nWARNING: unrecognized directive : ");
1167 config->proxy_args = strsav( config->proxy_args, buf);
1168 config->proxy_args = strsav( config->proxy_args, "<br><br>\n");
1171 /****************************************************************************/
1172 } /* end switch( hash_string(cmd) ) */
1173 } /* end while ( read_config_line(...) ) */
1177 init_error_log(Argv[0], config->logfile, config->debug);
1179 if (config->actions_file)
1181 add_loader(load_actions_file, config);
1184 if (config->re_filterfile)
1186 add_loader(load_re_filterfile, config);
1190 if (config->trustfile)
1192 add_loader(load_trustfile, config);
1197 if ( NULL != config->jarfile )
1199 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1201 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1202 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1204 setbuf(config->jar, NULL);
1206 #endif /* def JAR_FILES */
1208 if ( NULL == config->haddr )
1210 config->haddr = strdup( HADDR_DEFAULT );
1213 if ( NULL != config->haddr )
1215 if ((p = strchr(config->haddr, ':')))
1220 config->hport = atoi(p);
1224 if (config->hport <= 0)
1227 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1228 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1230 if (*config->haddr == '\0')
1232 config->haddr = NULL;
1237 * Want to run all the loaders once now.
1239 * Need to set up a fake csp, so they can get to the config.
1241 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1242 fake_csp->config = config;
1244 if (run_loader(fake_csp))
1247 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1248 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1252 #ifndef SPLIT_PROXY_ARGS
1253 if (!suppress_blocklists)
1255 fs->proxy_args = strsav(fs->proxy_args, "</pre>");
1257 #endif /* ndef SPLIT_PROXY_ARGS */
1259 /* FIXME: this is a kludge for win32 */
1260 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1262 g_actions_file = config->actions_file;
1263 g_re_filterfile = config->re_filterfile;
1266 g_trustfile = config->trustfile;
1270 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1271 /* FIXME: end kludge */
1274 config->need_bind = 1;
1276 if (current_configfile)
1278 struct configuration_spec * oldcfg = (struct configuration_spec *)
1279 current_configfile->f;
1281 * Check if config->haddr,hport == oldcfg->haddr,hport
1283 * The following could be written more compactly as a single,
1284 * (unreadably long) if statement.
1286 config->need_bind = 0;
1287 if (config->hport != oldcfg->hport)
1289 config->need_bind = 1;
1291 else if (config->haddr == NULL)
1293 if (oldcfg->haddr != NULL)
1295 config->need_bind = 1;
1298 else if (oldcfg->haddr == NULL)
1300 config->need_bind = 1;
1302 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1304 config->need_bind = 1;
1307 current_configfile->unloader = unload_configfile;
1310 fs->next = files->next;
1313 current_configfile = fs;