1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.18 2001/07/13 14:01:14 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.18 2001/07/13 14:01:14 oes
39 * - Removed all #ifdef PCRS
40 * - Removed vim-settings
42 * Revision 1.17 2001/06/29 13:31:03 oes
44 * - Fixed (actionsfile) and sorted hashes
45 * - Introduced admin_address and proxy-info-url
46 * as config parameters
47 * - Renamed config->proxy_args_invocation (which didn't have
48 * the invocation but the options!) to config->proxy_args
50 * - Removed logentry from cancelled commit
52 * Revision 1.16 2001/06/09 10:55:28 jongfoster
53 * Changing BUFSIZ ==> BUFFER_SIZE
55 * Revision 1.15 2001/06/07 23:13:40 jongfoster
56 * Merging ACL and forward files into config file.
57 * Cosmetic: Sorting config file options alphabetically.
58 * Cosmetic: Adding brief syntax comments to config file options.
60 * Revision 1.14 2001/06/07 14:46:25 joergs
61 * Missing make_path() added for re_filterfile.
63 * Revision 1.13 2001/06/05 22:33:54 jongfoster
65 * Fixed minor memory leak.
66 * Also now uses make_path to prepend the pathnames.
68 * Revision 1.12 2001/06/05 20:04:09 jongfoster
69 * Now uses _snprintf() in place of snprintf() under Win32.
71 * Revision 1.11 2001/06/04 18:31:58 swa
72 * files are now prefixed with either `confdir' or `logdir'.
73 * `make redhat-dist' replaces both entries confdir and logdir
76 * Revision 1.10 2001/06/03 19:11:54 oes
77 * introduced confdir option
79 * Revision 1.9 2001/06/01 20:06:24 jongfoster
80 * Removed support for "tinygif" option - moved to actions file.
82 * Revision 1.8 2001/05/31 21:27:13 jongfoster
83 * Removed many options from the config file and into the
84 * "actions" file: add_forwarded, suppress_vanilla_wafer,
85 * wafer, add_header, user_agent, referer, from
86 * Also globally replaced "permission" with "action".
88 * Revision 1.7 2001/05/29 09:50:24 jongfoster
89 * Unified blocklist/imagelist/permissionslist.
90 * File format is still under discussion, but the internal changes
93 * Also modified interceptor behaviour:
94 * - We now intercept all URLs beginning with one of the following
95 * prefixes (and *only* these prefixes):
97 * * http://ijbswa.sf.net/config/
98 * * http://ijbswa.sourceforge.net/config/
99 * - New interceptors "home page" - go to http://i.j.b/ to see it.
100 * - Internal changes so that intercepted and fast redirect pages
101 * are not replaced with an image.
102 * - Interceptors now have the option to send a binary page direct
103 * to the client. (i.e. ijb-send-banner uses this)
104 * - Implemented show-url-info interceptor. (Which is why I needed
105 * the above interceptors changes - a typical URL is
106 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
107 * The previous mechanism would not have intercepted that, and
108 * if it had been intercepted then it then it would have replaced
111 * Revision 1.6 2001/05/26 00:28:36 jongfoster
112 * Automatic reloading of config file.
113 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
114 * Most of the global variables have been moved to a new
115 * struct configuration_spec, accessed through csp->config->globalname
116 * Most of the globals remaining are used by the Win32 GUI.
118 * Revision 1.5 2001/05/25 22:34:30 jongfoster
121 * Revision 1.4 2001/05/22 18:46:04 oes
123 * - Enabled filtering banners by size rather than URL
124 * by adding patterns that replace all standard banner
125 * sizes with the "Junkbuster" gif to the re_filterfile
127 * - Enabled filtering WebBugs by providing a pattern
128 * which kills all 1x1 images
130 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
131 * which is selected by the (nonstandard and therefore
132 * capital) letter 'U' in the option string.
133 * It causes the quantifiers to be ungreedy by default.
134 * Appending a ? turns back to greedy (!).
136 * - Added a new interceptor ijb-send-banner, which
137 * sends back the "Junkbuster" gif. Without imagelist or
138 * MSIE detection support, or if tinygif = 1, or the
139 * URL isn't recognized as an imageurl, a lame HTML
140 * explanation is sent instead.
142 * - Added new feature, which permits blocking remote
143 * script redirects and firing back a local redirect
145 * The feature is conditionally compiled, i.e. it
146 * can be disabled with --disable-fast-redirects,
147 * plus it must be activated by a "fast-redirects"
148 * line in the config file, has its own log level
149 * and of course wants to be displayed by show-proxy-args
150 * Note: Boy, all the #ifdefs in 1001 locations and
151 * all the fumbling with configure.in and acconfig.h
152 * were *way* more work than the feature itself :-(
154 * - Because a generic redirect template was needed for
155 * this, tinygif = 3 now uses the same.
157 * - Moved GIFs, and other static HTTP response templates
162 * - Removed some >400 CRs again (Jon, you really worked
165 * Revision 1.3 2001/05/20 01:21:20 jongfoster
166 * Version 2.9.4 checkin.
167 * - Merged popupfile and cookiefile, and added control over PCRS
168 * filtering, in new "permissionsfile".
169 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
170 * file error you now get a message box (in the Win32 GUI) rather
171 * than the program exiting with no explanation.
172 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
174 * - Removed tabs from "config"
175 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
176 * - Bumped up version number.
178 * Revision 1.2 2001/05/17 23:01:01 oes
179 * - Cleaned CRLF's from the sources and related files
181 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
182 * Initial import of version 2.9.3 source tree
185 *********************************************************************/
191 #include <sys/types.h>
201 # include <windows.h>
204 # ifndef _WIN_CONSOLE
206 # endif /* ndef _WIN_CONSOLE */
208 /* VC++ has "_snprintf", not "snprintf" */
209 #define snprintf _snprintf
211 #else /* ifndef _WIN32 */
214 # include <sys/time.h>
215 # include <sys/wait.h>
216 # include <sys/stat.h>
226 #include "showargs.h"
228 #include "killpopup.h"
229 #include "miscutil.h"
231 #include "jbsockets.h"
235 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
238 * Fix a problem with Solaris. There should be no effect on other
240 * Solaris's isspace() is a macro which uses it's argument directly
241 * as an array index. Therefore we need to make sure that high-bit
242 * characters generate +ve values, and ideally we also want to make
243 * the argument match the declared parameter type of "int".
245 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
246 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
249 /* by haroon - indicates if ijb is enabled */
250 int g_bToggleIJB = 1; /* JunkBusters is enabled by default. */
253 /* The filename of the configfile */
254 const char *configfile = NULL;
257 * CGI functions will later need access to the invocation args,
258 * so we will make argc and argv global.
261 const char **Argv = NULL;
263 static struct file_list *current_configfile = NULL;
267 * This takes the "cryptic" hash of each keyword and aliases them to
268 * something a little more readable. This also makes changing the
269 * hash values easier if they should change or the hash algorthm changes.
270 * Use the included "hash" program to find out what the hash will be
271 * for any string supplied on the command line. (Or just put it in the
272 * config file and read the number from the error message in the log).
274 * Please keep this list sorted alphabetically (but with the Windows
275 * console and GUI specific options last).
278 #define hash_actions_file 1196306641ul /* "actionsfile" */
279 #define hash_admin_address 4112573064ul /* "admin-address" */
280 #define hash_confdir 1978389ul /* "confdir" */
281 #define hash_debug 78263ul /* "debug" */
282 #define hash_deny_access 1227333715ul /* "deny-access" */
283 #define hash_forward 2029845ul /* "forward" */
284 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
285 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
286 #define hash_jarfile 2046641ul /* "jarfile" */
287 #define hash_listen_address 1255650842ul /* "listen-address" */
288 #define hash_logdir 422889ul /* "logdir" */
289 #define hash_logfile 2114766ul /* "logfile" */
290 #define hash_permit_access 3587953268ul /* "permit-access" */
291 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
292 #define hash_re_filterfile 3877522444ul /* "re_filterfile" */
293 #define hash_single_threaded 4250084780ul /* "single-threaded" */
294 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
295 #define hash_toggle 447966ul /* "toggle" */
296 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
297 #define hash_trustfile 56494766ul /* "trustfile" */
299 #define hash_activity_animation 1817904738ul /* "activity-animation" */
300 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
301 #define hash_hide_console 2048809870ul /* "hide-console" */
302 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
303 #define hash_log_font_name 2866730124ul /* "log-font-name" */
304 #define hash_log_font_size 2866731014ul /* "log-font-size" */
305 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
306 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
307 #define hash_log_messages 2291744899ul /* "log-messages" */
308 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
312 /*********************************************************************
314 * Function : unload_configfile
316 * Description : Free the config structure and all components.
319 * 1 : data: struct configuration_spec to unload
323 *********************************************************************/
324 void unload_configfile (void * data)
326 struct configuration_spec * config = (struct configuration_spec *)data;
327 struct forward_spec *cur_fwd = config->forward;
329 struct access_control_list *cur_acl = config->acl;
331 while (cur_acl != NULL)
333 struct access_control_list * next_acl = cur_acl->next;
338 #endif /* def ACL_FILES */
340 while (cur_fwd != NULL)
342 struct forward_spec * next_fwd = cur_fwd->next;
343 free_url(cur_fwd->url);
345 freez(cur_fwd->gateway_host);
346 freez(cur_fwd->forward_host);
350 config->forward = NULL;
353 if ( NULL != config->jar )
355 fclose( config->jar );
358 #endif /* def JAR_FILES */
360 freez((char *)config->confdir);
361 freez((char *)config->logdir);
363 freez((char *)config->haddr);
364 freez((char *)config->logfile);
366 freez((char *)config->actions_file);
367 freez((char *)config->admin_address);
368 freez((char *)config->proxy_info_url);
369 freez((char *)config->proxy_args);
372 freez((char *)config->jarfile);
373 #endif /* def JAR_FILES */
375 #ifndef SPLIT_PROXY_ARGS
376 freez((char *)config->suppress_message);
377 #endif /* ndef SPLIT_PROXY_ARGS */
379 freez((char *)config->re_filterfile);
384 /*********************************************************************
386 * Function : load_config
388 * Description : Load the config file and all parameters.
391 * 1 : csp = Client state (the config member will be
392 * filled in by this function).
394 * Returns : 0 => Ok, everything else is an error.
396 *********************************************************************/
397 struct configuration_spec * load_config(void)
399 char buf[BUFFER_SIZE];
401 FILE *configfp = NULL;
402 struct configuration_spec * config = NULL;
403 struct client_state * fake_csp;
404 struct file_list *fs;
406 if (!check_file_changed(current_configfile, configfile, &fs))
408 /* No need to load */
409 return ((struct configuration_spec *)current_configfile->f);
413 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
417 log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
423 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
429 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
430 /* Never get here - LOG_LEVEL_FATAL causes program exit */
434 * This is backwards from how it's usually done.
435 * Following the usual pattern, "fs" would be stored in a member
436 * variable in "csp", and then we'd access "config" from "fs->f",
437 * using a cast. However, "config" is used so often that a
438 * cast each time would be very ugly, and the extra indirection
439 * would waste CPU cycles. Therefore we store "config" in
440 * "csp->config", and "fs" in "csp->config->config_file_list".
442 config->config_file_list = fs;
448 config->multi_threaded = 1;
449 config->hport = HADDR_PORT;
451 if ((configfp = fopen(configfile, "r")) == NULL)
453 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
455 /* Never get here - LOG_LEVEL_FATAL causes program exit */
458 while (read_config_line(buf, sizeof(buf), configfp, fs) != NULL)
460 char cmd[BUFFER_SIZE];
461 char arg[BUFFER_SIZE];
462 char tmp[BUFFER_SIZE];
464 struct access_control_list *cur_acl;
465 #endif /* def ACL_FILES */
466 struct forward_spec *cur_fwd;
472 /* Copy command (i.e. up to space or tab) into cmd */
475 while (*p && (*p != ' ') && (*p != '\t'))
481 /* Skip over the whitespace in buf */
482 while (*p && ((*p == ' ') || (*p == '\t')))
487 /* Copy the argument into arg */
490 /* Should never happen, but check this anyway */
496 /* Make sure the command field is lower case */
501 *p = ijb_tolower(*p);
505 /* Save the argument for show-proxy-args */
506 savearg(cmd, arg, config);
509 switch( hash_string( cmd ) )
511 /****************************************************************************
512 * actionsfile actions-file-name
513 * In confdir by default
514 ****************************************************************************/
515 case hash_actions_file :
516 freez((char *)config->actions_file);
517 config->actions_file = make_path(config->confdir, arg);
520 /****************************************************************************
521 * admin-address email-address
522 ****************************************************************************/
523 case hash_admin_address :
524 freez((char *)config->admin_address);
525 config->admin_address = strdup(arg);
528 /****************************************************************************
529 * confdir directory-name
530 ****************************************************************************/
532 freez((char *)config->confdir);
533 config->confdir = strdup(arg);
536 /****************************************************************************
538 * Specifies debug level, multiple values are ORed together.
539 ****************************************************************************/
541 config->debug |= atoi(arg);
544 /****************************************************************************
545 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
546 ****************************************************************************/
548 case hash_deny_access:
549 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
551 if ((vec_count != 1) && (vec_count != 2))
553 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
554 "deny-access directive in configuration file.");
555 config->proxy_args = strsav( config->proxy_args,
556 "<br>\nWARNING: Wrong number of parameters for "
557 "deny-access directive in configuration file.<br><br>\n");
561 /* allocate a new node */
562 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
566 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
567 /* Never get here - LOG_LEVEL_FATAL causes program exit */
570 cur_acl->action = ACL_DENY;
572 if (acl_addr(vec[0], cur_acl->src) < 0)
574 log_error(LOG_LEVEL_ERROR, "Invalid source IP for deny-access "
575 "directive in configuration file: \"%s\"", vec[0]);
576 config->proxy_args = strsav( config->proxy_args,
577 "<br>\nWARNING: Invalid source IP for deny-access directive"
578 " in configuration file: \"");
579 config->proxy_args = strsav( config->proxy_args,
581 config->proxy_args = strsav( config->proxy_args,
588 if (acl_addr(vec[1], cur_acl->dst) < 0)
590 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for deny-access "
591 "directive in configuration file: \"%s\"", vec[0]);
592 config->proxy_args = strsav( config->proxy_args,
593 "<br>\nWARNING: Invalid destination IP for deny-access directive"
594 " in configuration file: \"");
595 config->proxy_args = strsav( config->proxy_args,
597 config->proxy_args = strsav( config->proxy_args,
605 * Add it to the list. Note we reverse the list to get the
606 * behaviour the user expects. With both the ACL and
607 * actions file, the last match wins. However, the internal
608 * implementations are different: The actions file is stored
609 * in the same order as the file, and scanned completely.
610 * With the ACL, we reverse the order as we load it, then
611 * when we scan it we stop as soon as we get a match.
613 cur_acl->next = config->acl;
614 config->acl = cur_acl;
617 #endif /* def ACL_FILES */
619 /****************************************************************************
620 * forward url-pattern (.|http-proxy-host[:port])
621 ****************************************************************************/
623 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
627 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
628 "directive in configuration file.");
629 config->proxy_args = strsav( config->proxy_args,
630 "<br>\nWARNING: Wrong number of parameters for "
631 "forward directive in configuration file.");
635 /* allocate a new node */
636 cur_fwd = zalloc(sizeof(*cur_fwd));
639 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
640 /* Never get here - LOG_LEVEL_FATAL causes program exit */
644 cur_fwd->type = SOCKS_NONE;
646 /* Save the URL pattern */
647 if (create_url_spec(cur_fwd->url, vec[0]))
649 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
650 "directive in configuration file.");
651 config->proxy_args = strsav( config->proxy_args,
652 "<br>\nWARNING: Bad URL specifier for "
653 "forward directive in configuration file.");
657 /* Parse the parent HTTP proxy host:port */
660 if (strcmp(p, ".") != 0)
662 cur_fwd->forward_host = strdup(p);
664 if ((p = strchr(cur_fwd->forward_host, ':')))
667 cur_fwd->forward_port = atoi(p);
670 if (cur_fwd->forward_port <= 0)
672 cur_fwd->forward_port = 8000;
677 cur_fwd->next = config->forward;
678 config->forward = cur_fwd;
682 /****************************************************************************
683 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
684 ****************************************************************************/
685 case hash_forward_socks4:
686 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
690 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
691 "forward-socks4 directive in configuration file.");
692 config->proxy_args = strsav( config->proxy_args,
693 "<br>\nWARNING: Wrong number of parameters for "
694 "forward-socks4 directive in configuration file.");
698 /* allocate a new node */
699 cur_fwd = zalloc(sizeof(*cur_fwd));
702 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
703 /* Never get here - LOG_LEVEL_FATAL causes program exit */
707 cur_fwd->type = SOCKS_4;
709 /* Save the URL pattern */
710 if (create_url_spec(cur_fwd->url, vec[0]))
712 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
713 "directive in configuration file.");
714 config->proxy_args = strsav( config->proxy_args,
715 "<br>\nWARNING: Bad URL specifier for "
716 "forward-socks4 directive in configuration file.");
720 /* Parse the SOCKS proxy host[:port] */
723 if (strcmp(p, ".") != 0)
725 cur_fwd->gateway_host = strdup(p);
727 if ((p = strchr(cur_fwd->gateway_host, ':')))
730 cur_fwd->gateway_port = atoi(p);
732 if (cur_fwd->gateway_port <= 0)
734 cur_fwd->gateway_port = 1080;
738 /* Parse the parent HTTP proxy host[:port] */
741 if (strcmp(p, ".") != 0)
743 cur_fwd->forward_host = strdup(p);
745 if ((p = strchr(cur_fwd->forward_host, ':')))
748 cur_fwd->forward_port = atoi(p);
751 if (cur_fwd->forward_port <= 0)
753 cur_fwd->forward_port = 8000;
758 cur_fwd->next = config->forward;
759 config->forward = cur_fwd;
763 /****************************************************************************
764 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
765 ****************************************************************************/
766 case hash_forward_socks4a:
767 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
771 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
772 "forward-socks4a directive in configuration file.");
773 config->proxy_args = strsav( config->proxy_args,
774 "<br>\nWARNING: Wrong number of parameters for "
775 "forward-socks4a directive in configuration file.");
779 /* allocate a new node */
780 cur_fwd = zalloc(sizeof(*cur_fwd));
783 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
784 /* Never get here - LOG_LEVEL_FATAL causes program exit */
788 cur_fwd->type = SOCKS_4A;
790 /* Save the URL pattern */
791 if (create_url_spec(cur_fwd->url, vec[0]))
793 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
794 "directive in configuration file.");
795 config->proxy_args = strsav( config->proxy_args,
796 "<br>\nWARNING: Bad URL specifier for "
797 "forward-socks4a directive in configuration file.");
801 /* Parse the SOCKS proxy host[:port] */
804 cur_fwd->gateway_host = strdup(p);
806 if ((p = strchr(cur_fwd->gateway_host, ':')))
809 cur_fwd->gateway_port = atoi(p);
811 if (cur_fwd->gateway_port <= 0)
813 cur_fwd->gateway_port = 1080;
816 /* Parse the parent HTTP proxy host[:port] */
819 if (strcmp(p, ".") != 0)
821 cur_fwd->forward_host = strdup(p);
823 if ((p = strchr(cur_fwd->forward_host, ':')))
826 cur_fwd->forward_port = atoi(p);
829 if (cur_fwd->forward_port <= 0)
831 cur_fwd->forward_port = 8000;
836 cur_fwd->next = config->forward;
837 config->forward = cur_fwd;
841 /****************************************************************************
842 * jarfile jar-file-name
843 * In logdir by default
844 ****************************************************************************/
847 freez((char *)config->jarfile);
848 config->jarfile = make_path(config->logdir, arg);
850 #endif /* def JAR_FILES */
852 /****************************************************************************
853 * listen-address [ip][:port]
854 ****************************************************************************/
855 case hash_listen_address :
856 freez((char *)config->haddr);
857 config->haddr = strdup(arg);
860 /****************************************************************************
861 * logdir directory-name
862 ****************************************************************************/
864 freez((char *)config->logdir);
865 config->logdir = strdup(arg);
868 /****************************************************************************
869 * logfile log-file-name
870 * In logdir by default
871 ****************************************************************************/
873 freez((char *)config->logfile);
874 config->logfile = make_path(config->logdir, arg);
877 /****************************************************************************
878 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
879 ****************************************************************************/
881 case hash_permit_access:
882 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
884 if ((vec_count != 1) && (vec_count != 2))
886 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
887 "permit-access directive in configuration file.");
888 config->proxy_args = strsav( config->proxy_args,
889 "<br>\nWARNING: Wrong number of parameters for "
890 "permit-access directive in configuration file.<br><br>\n");
895 /* allocate a new node */
896 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
900 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
901 /* Never get here - LOG_LEVEL_FATAL causes program exit */
904 cur_acl->action = ACL_PERMIT;
906 if (acl_addr(vec[0], cur_acl->src) < 0)
908 log_error(LOG_LEVEL_ERROR, "Invalid source IP for permit-access "
909 "directive in configuration file: \"%s\"", vec[0]);
910 config->proxy_args = strsav( config->proxy_args,
911 "<br>\nWARNING: Invalid source IP for permit-access directive"
912 " in configuration file: \"");
913 config->proxy_args = strsav( config->proxy_args,
915 config->proxy_args = strsav( config->proxy_args,
922 if (acl_addr(vec[1], cur_acl->dst) < 0)
924 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for "
925 "permit-access directive in configuration file: \"%s\"",
927 config->proxy_args = strsav( config->proxy_args,
928 "<br>\nWARNING: Invalid destination IP for permit-access directive"
929 " in configuration file: \"");
930 config->proxy_args = strsav( config->proxy_args,
932 config->proxy_args = strsav( config->proxy_args,
940 * Add it to the list. Note we reverse the list to get the
941 * behaviour the user expects. With both the ACL and
942 * actions file, the last match wins. However, the internal
943 * implementations are different: The actions file is stored
944 * in the same order as the file, and scanned completely.
945 * With the ACL, we reverse the order as we load it, then
946 * when we scan it we stop as soon as we get a match.
948 cur_acl->next = config->acl;
949 config->acl = cur_acl;
952 #endif /* def ACL_FILES */
954 /****************************************************************************
956 ****************************************************************************/
957 case hash_proxy_info_url :
958 freez((char *)config->proxy_info_url);
959 config->proxy_info_url = strdup(arg);
962 /****************************************************************************
963 * re_filterfile file-name
964 * In confdir by default.
965 ****************************************************************************/
966 case hash_re_filterfile :
967 freez((char *)config->re_filterfile);
968 config->re_filterfile = make_path(config->confdir, arg);
971 /****************************************************************************
973 ****************************************************************************/
974 case hash_single_threaded :
975 config->multi_threaded = 0;
978 /****************************************************************************
979 * FIXME: Document this FIXME2: Shouldn't we throw this out? --oes
980 ****************************************************************************/
981 #ifndef SPLIT_PROXY_ARGS
982 case hash_suppress_blocklists :
985 config->suppress_message = strdup(arg);
989 /* There will be NO reference in proxy-args. */
990 config->suppress_message = NULL;
993 config->suppress_blocklists = 1;
995 #endif /* ndef SPLIT_PROXY_ARGS */
997 /****************************************************************************
999 ****************************************************************************/
1002 g_bToggleIJB = atoi(arg);
1004 #endif /* def TOGGLE */
1006 /****************************************************************************
1007 * trust-info-url url
1008 ****************************************************************************/
1010 case hash_trust_info_url :
1011 enlist(config->trust_info, arg);
1013 #endif /* def TRUST_FILES */
1015 /****************************************************************************
1016 * trustfile filename
1017 * (In confdir by default.)
1018 ****************************************************************************/
1020 case hash_trustfile :
1021 freez((char *)config->trustfile);
1022 config->trustfile = make_path(config->confdir, arg);
1024 #endif /* def TRUST_FILES */
1027 /****************************************************************************
1028 * Win32 Console options:
1029 ****************************************************************************/
1031 /****************************************************************************
1033 ****************************************************************************/
1035 case hash_hide_console :
1038 #endif /*def _WIN_CONSOLE*/
1041 /****************************************************************************
1042 * Win32 GUI options:
1043 ****************************************************************************/
1045 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1046 /****************************************************************************
1047 * activity-animation (0|1)
1048 ****************************************************************************/
1049 case hash_activity_animation :
1050 g_bShowActivityAnimation = atoi(arg);
1053 /****************************************************************************
1054 * close-button-minimizes (0|1)
1055 ****************************************************************************/
1056 case hash_close_button_minimizes :
1057 g_bCloseHidesWindow = atoi(arg);
1060 /****************************************************************************
1061 * log-buffer-size (0|1)
1062 ****************************************************************************/
1063 case hash_log_buffer_size :
1064 g_bLimitBufferSize = atoi(arg);
1067 /****************************************************************************
1068 * log-font-name fontnane
1069 ****************************************************************************/
1070 case hash_log_font_name :
1071 strcpy( g_szFontFaceName, arg );
1074 /****************************************************************************
1076 ****************************************************************************/
1077 case hash_log_font_size :
1078 g_nFontSize = atoi(arg);
1081 /****************************************************************************
1082 * log-highlight-messages (0|1)
1083 ****************************************************************************/
1084 case hash_log_highlight_messages :
1085 g_bHighlightMessages = atoi(arg);
1088 /****************************************************************************
1090 ****************************************************************************/
1091 case hash_log_max_lines :
1092 g_nMaxBufferLines = atoi(arg);
1095 /****************************************************************************
1096 * log-messages (0|1)
1097 ****************************************************************************/
1098 case hash_log_messages :
1099 g_bLogMessages = atoi(arg);
1102 /****************************************************************************
1103 * show-on-task-bar (0|1)
1104 ****************************************************************************/
1105 case hash_show_on_task_bar :
1106 g_bShowOnTaskBar = atoi(arg);
1109 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1112 /****************************************************************************/
1113 /* Warnings about unsupported features */
1114 /****************************************************************************/
1116 case hash_deny_access:
1117 #endif /* ndef ACL_FILES */
1120 #endif /* ndef JAR_FILES */
1122 case hash_permit_access:
1123 #endif /* ndef ACL_FILES */
1124 #ifdef SPLIT_PROXY_ARGS
1125 case hash_suppress_blocklists :
1126 #endif /* def SPLIT_PROXY_ARGS */
1129 #endif /* ndef TOGGLE */
1131 case hash_trustfile :
1132 case hash_trust_info_url :
1133 #endif /* ndef TRUST_FILES */
1135 #ifndef _WIN_CONSOLE
1136 case hash_hide_console :
1137 #endif /* ndef _WIN_CONSOLE */
1139 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1140 case hash_activity_animation :
1141 case hash_close_button_minimizes :
1142 case hash_log_buffer_size :
1143 case hash_log_font_name :
1144 case hash_log_font_size :
1145 case hash_log_highlight_messages :
1146 case hash_log_max_lines :
1147 case hash_log_messages :
1148 case hash_show_on_task_bar :
1149 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1150 /* These warnings are annoying - so hide them. -- Jon */
1151 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1154 /****************************************************************************/
1156 /****************************************************************************/
1158 * I decided that I liked this better as a warning than an
1159 * error. To change back to an error, just change log level
1160 * to LOG_LEVEL_FATAL.
1162 log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%luul) in "
1163 "configuration file: \"%s\"", hash_string( cmd ), buf);
1164 config->proxy_args = strsav( config->proxy_args, "<br>\nWARNING: unrecognized directive : ");
1165 config->proxy_args = strsav( config->proxy_args, buf);
1166 config->proxy_args = strsav( config->proxy_args, "<br><br>\n");
1169 /****************************************************************************/
1170 } /* end switch( hash_string(cmd) ) */
1171 } /* end while ( read_config_line(...) ) */
1175 init_error_log(Argv[0], config->logfile, config->debug);
1177 if (config->actions_file)
1179 add_loader(load_actions_file, config);
1182 if (config->re_filterfile)
1184 add_loader(load_re_filterfile, config);
1188 if (config->trustfile)
1190 add_loader(load_trustfile, config);
1195 if ( NULL != config->jarfile )
1197 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1199 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1200 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1202 setbuf(config->jar, NULL);
1204 #endif /* def JAR_FILES */
1206 if ( NULL == config->haddr )
1208 config->haddr = strdup( HADDR_DEFAULT );
1211 if ( NULL != config->haddr )
1213 if ((p = strchr(config->haddr, ':')))
1218 config->hport = atoi(p);
1222 if (config->hport <= 0)
1225 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1226 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1228 if (*config->haddr == '\0')
1230 config->haddr = NULL;
1235 * Want to run all the loaders once now.
1237 * Need to set up a fake csp, so they can get to the config.
1239 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1240 fake_csp->config = config;
1242 if (run_loader(fake_csp))
1245 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1246 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1250 #ifndef SPLIT_PROXY_ARGS
1251 if (!suppress_blocklists)
1253 fs->proxy_args = strsav(fs->proxy_args, "</pre>");
1255 #endif /* ndef SPLIT_PROXY_ARGS */
1257 /* FIXME: this is a kludge for win32 */
1258 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1260 g_actions_file = config->actions_file;
1261 g_re_filterfile = config->re_filterfile;
1264 g_trustfile = config->trustfile;
1268 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1269 /* FIXME: end kludge */
1272 config->need_bind = 1;
1274 if (current_configfile)
1276 struct configuration_spec * oldcfg = (struct configuration_spec *)
1277 current_configfile->f;
1279 * Check if config->haddr,hport == oldcfg->haddr,hport
1281 * The following could be written more compactly as a single,
1282 * (unreadably long) if statement.
1284 config->need_bind = 0;
1285 if (config->hport != oldcfg->hport)
1287 config->need_bind = 1;
1289 else if (config->haddr == NULL)
1291 if (oldcfg->haddr != NULL)
1293 config->need_bind = 1;
1296 else if (oldcfg->haddr == NULL)
1298 config->need_bind = 1;
1300 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1302 config->need_bind = 1;
1305 current_configfile->unloader = unload_configfile;
1308 fs->next = files->next;
1311 current_configfile = fs;