2 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.16 2001/06/09 10:55:28 jongfoster Exp $";
3 /*********************************************************************
5 * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
7 * Purpose : Loads settings from the configuration file into
8 * global variables. This file contains both the
9 * routine to load the configuration and the global
10 * variables it writes to.
12 * Copyright : Written by and Copyright (C) 2001 the SourceForge
13 * IJBSWA team. http://ijbswa.sourceforge.net
15 * Based on the Internet Junkbuster originally written
16 * by and Copyright (C) 1997 Anonymous Coders and
17 * Junkbusters Corporation. http://www.junkbusters.com
19 * This program is free software; you can redistribute it
20 * and/or modify it under the terms of the GNU General
21 * Public License as published by the Free Software
22 * Foundation; either version 2 of the License, or (at
23 * your option) any later version.
25 * This program is distributed in the hope that it will
26 * be useful, but WITHOUT ANY WARRANTY; without even the
27 * implied warranty of MERCHANTABILITY or FITNESS FOR A
28 * PARTICULAR PURPOSE. See the GNU General Public
29 * License for more details.
31 * The GNU General Public License should be included with
32 * this file. If not, you can view it at
33 * http://www.gnu.org/copyleft/gpl.html
34 * or write to the Free Software Foundation, Inc., 59
35 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
39 * Revision 1.16 2001/06/09 10:55:28 jongfoster
40 * Changing BUFSIZ ==> BUFFER_SIZE
42 * Revision 1.15 2001/06/07 23:13:40 jongfoster
43 * Merging ACL and forward files into config file.
44 * Cosmetic: Sorting config file options alphabetically.
45 * Cosmetic: Adding brief syntax comments to config file options.
47 * Revision 1.14 2001/06/07 14:46:25 joergs
48 * Missing make_path() added for re_filterfile.
50 * Revision 1.13 2001/06/05 22:33:54 jongfoster
52 * Fixed minor memory leak.
53 * Also now uses make_path to prepend the pathnames.
55 * Revision 1.12 2001/06/05 20:04:09 jongfoster
56 * Now uses _snprintf() in place of snprintf() under Win32.
58 * Revision 1.11 2001/06/04 18:31:58 swa
59 * files are now prefixed with either `confdir' or `logdir'.
60 * `make redhat-dist' replaces both entries confdir and logdir
63 * Revision 1.10 2001/06/03 19:11:54 oes
64 * introduced confdir option
66 * Revision 1.9 2001/06/01 20:06:24 jongfoster
67 * Removed support for "tinygif" option - moved to actions file.
69 * Revision 1.8 2001/05/31 21:27:13 jongfoster
70 * Removed many options from the config file and into the
71 * "actions" file: add_forwarded, suppress_vanilla_wafer,
72 * wafer, add_header, user_agent, referer, from
73 * Also globally replaced "permission" with "action".
75 * Revision 1.7 2001/05/29 09:50:24 jongfoster
76 * Unified blocklist/imagelist/permissionslist.
77 * File format is still under discussion, but the internal changes
80 * Also modified interceptor behaviour:
81 * - We now intercept all URLs beginning with one of the following
82 * prefixes (and *only* these prefixes):
84 * * http://ijbswa.sf.net/config/
85 * * http://ijbswa.sourceforge.net/config/
86 * - New interceptors "home page" - go to http://i.j.b/ to see it.
87 * - Internal changes so that intercepted and fast redirect pages
88 * are not replaced with an image.
89 * - Interceptors now have the option to send a binary page direct
90 * to the client. (i.e. ijb-send-banner uses this)
91 * - Implemented show-url-info interceptor. (Which is why I needed
92 * the above interceptors changes - a typical URL is
93 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
94 * The previous mechanism would not have intercepted that, and
95 * if it had been intercepted then it then it would have replaced
98 * Revision 1.6 2001/05/26 00:28:36 jongfoster
99 * Automatic reloading of config file.
100 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
101 * Most of the global variables have been moved to a new
102 * struct configuration_spec, accessed through csp->config->globalname
103 * Most of the globals remaining are used by the Win32 GUI.
105 * Revision 1.5 2001/05/25 22:34:30 jongfoster
108 * Revision 1.4 2001/05/22 18:46:04 oes
110 * - Enabled filtering banners by size rather than URL
111 * by adding patterns that replace all standard banner
112 * sizes with the "Junkbuster" gif to the re_filterfile
114 * - Enabled filtering WebBugs by providing a pattern
115 * which kills all 1x1 images
117 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
118 * which is selected by the (nonstandard and therefore
119 * capital) letter 'U' in the option string.
120 * It causes the quantifiers to be ungreedy by default.
121 * Appending a ? turns back to greedy (!).
123 * - Added a new interceptor ijb-send-banner, which
124 * sends back the "Junkbuster" gif. Without imagelist or
125 * MSIE detection support, or if tinygif = 1, or the
126 * URL isn't recognized as an imageurl, a lame HTML
127 * explanation is sent instead.
129 * - Added new feature, which permits blocking remote
130 * script redirects and firing back a local redirect
132 * The feature is conditionally compiled, i.e. it
133 * can be disabled with --disable-fast-redirects,
134 * plus it must be activated by a "fast-redirects"
135 * line in the config file, has its own log level
136 * and of course wants to be displayed by show-proxy-args
137 * Note: Boy, all the #ifdefs in 1001 locations and
138 * all the fumbling with configure.in and acconfig.h
139 * were *way* more work than the feature itself :-(
141 * - Because a generic redirect template was needed for
142 * this, tinygif = 3 now uses the same.
144 * - Moved GIFs, and other static HTTP response templates
149 * - Removed some >400 CRs again (Jon, you really worked
152 * Revision 1.3 2001/05/20 01:21:20 jongfoster
153 * Version 2.9.4 checkin.
154 * - Merged popupfile and cookiefile, and added control over PCRS
155 * filtering, in new "permissionsfile".
156 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
157 * file error you now get a message box (in the Win32 GUI) rather
158 * than the program exiting with no explanation.
159 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
161 * - Removed tabs from "config"
162 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
163 * - Bumped up version number.
165 * Revision 1.2 2001/05/17 23:01:01 oes
166 * - Cleaned CRLF's from the sources and related files
168 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
169 * Initial import of version 2.9.3 source tree
172 *********************************************************************/
178 #include <sys/types.h>
188 # include <sys/timeb.h>
189 # include <windows.h>
191 # include <process.h>
194 # endif /* def TOGGLE */
197 # ifndef _WIN_CONSOLE
199 # endif /* ndef _WIN_CONSOLE */
201 /* VC++ has "_snprintf", not "snprintf" */
202 #define snprintf _snprintf
204 #else /* ifndef _WIN32 */
207 # include <sys/time.h>
208 # include <sys/wait.h>
209 # include <sys/stat.h>
219 #include "showargs.h"
221 #include "killpopup.h"
222 #include "miscutil.h"
224 #include "jbsockets.h"
228 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
231 * Fix a problem with Solaris. There should be no effect on other
233 * Solaris's isspace() is a macro which uses it's argument directly
234 * as an array index. Therefore we need to make sure that high-bit
235 * characters generate +ve values, and ideally we also want to make
236 * the argument match the declared parameter type of "int".
238 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
239 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
242 /* by haroon - indicates if ijb is enabled */
243 int g_bToggleIJB = 1; /* JunkBusters is enabled by default. */
246 /* The filename of the configfile */
247 const char *configfile = NULL;
250 * CGI functions will later need access to the invocation args,
251 * so we will make argc and argv global.
254 const char **Argv = NULL;
256 static struct file_list *current_configfile = NULL;
260 * This takes the "cryptic" hash of each keyword and aliases them to
261 * something a little more readable. This also makes changing the
262 * hash values easier if they should change or the hash algorthm changes.
263 * Use the included "hash" program to find out what the hash will be
264 * for any string supplied on the command line. (Or just put it in the
265 * config file and read the number from the error message in the log).
267 * Please keep this list sorted alphabetically (but with the Windows
268 * console and GUI specific options last).
271 #define hash_actions_file 1196306641ul /* "actionsfile" */
272 #define hash_admin_address 4112573064ul /* "admin-address" */
273 #define hash_confdir 1978389ul /* "confdir" */
274 #define hash_debug 78263ul /* "debug" */
275 #define hash_deny_access 1227333715ul /* "deny-access" */
276 #define hash_forward 2029845ul /* "forward" */
277 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
278 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
279 #define hash_jarfile 2046641ul /* "jarfile" */
280 #define hash_listen_address 1255650842ul /* "listen-address" */
281 #define hash_logdir 422889ul /* "logdir" */
282 #define hash_logfile 2114766ul /* "logfile" */
283 #define hash_permit_access 3587953268ul /* "permit-access" */
284 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
285 #define hash_re_filterfile 3877522444ul /* "re_filterfile" */
286 #define hash_single_threaded 4250084780ul /* "single-threaded" */
287 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
288 #define hash_toggle 447966ul /* "toggle" */
289 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
290 #define hash_trustfile 56494766ul /* "trustfile" */
292 #define hash_activity_animation 1817904738ul /* "activity-animation" */
293 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
294 #define hash_hide_console 2048809870ul /* "hide-console" */
295 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
296 #define hash_log_font_name 2866730124ul /* "log-font-name" */
297 #define hash_log_font_size 2866731014ul /* "log-font-size" */
298 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
299 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
300 #define hash_log_messages 2291744899ul /* "log-messages" */
301 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
305 /*********************************************************************
307 * Function : unload_configfile
309 * Description : Free the config structure and all components.
312 * 1 : data: struct configuration_spec to unload
316 *********************************************************************/
317 void unload_configfile (void * data)
319 struct configuration_spec * config = (struct configuration_spec *)data;
320 struct forward_spec *cur_fwd = config->forward;
322 struct access_control_list *cur_acl = config->acl;
324 while (cur_acl != NULL)
326 struct access_control_list * next_acl = cur_acl->next;
331 #endif /* def ACL_FILES */
333 while (cur_fwd != NULL)
335 struct forward_spec * next_fwd = cur_fwd->next;
336 free_url(cur_fwd->url);
338 freez(cur_fwd->gateway_host);
339 freez(cur_fwd->forward_host);
343 config->forward = NULL;
346 if ( NULL != config->jar )
348 fclose( config->jar );
351 #endif /* def JAR_FILES */
353 freez((char *)config->confdir);
354 freez((char *)config->logdir);
356 freez((char *)config->haddr);
357 freez((char *)config->logfile);
359 freez((char *)config->actions_file);
360 freez((char *)config->admin_address);
361 freez((char *)config->proxy_info_url);
362 freez((char *)config->proxy_args);
365 freez((char *)config->jarfile);
366 #endif /* def JAR_FILES */
368 #ifndef SPLIT_PROXY_ARGS
369 freez((char *)config->suppress_message);
370 #endif /* ndef SPLIT_PROXY_ARGS */
373 freez((char *)config->re_filterfile);
374 #endif /* def PCRS */
379 /*********************************************************************
381 * Function : load_config
383 * Description : Load the config file and all parameters.
386 * 1 : csp = Client state (the config member will be
387 * filled in by this function).
389 * Returns : 0 => Ok, everything else is an error.
391 *********************************************************************/
392 struct configuration_spec * load_config(void)
394 char buf[BUFFER_SIZE];
396 FILE *configfp = NULL;
397 struct configuration_spec * config = NULL;
398 struct client_state * fake_csp;
399 struct file_list *fs;
401 if (!check_file_changed(current_configfile, configfile, &fs))
403 /* No need to load */
404 return ((struct configuration_spec *)current_configfile->f);
408 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
412 log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
418 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
424 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
425 /* Never get here - LOG_LEVEL_FATAL causes program exit */
429 * This is backwards from how it's usually done.
430 * Following the usual pattern, "fs" would be stored in a member
431 * variable in "csp", and then we'd access "config" from "fs->f",
432 * using a cast. However, "config" is used so often that a
433 * cast each time would be very ugly, and the extra indirection
434 * would waste CPU cycles. Therefore we store "config" in
435 * "csp->config", and "fs" in "csp->config->config_file_list".
437 config->config_file_list = fs;
443 config->multi_threaded = 1;
444 config->hport = HADDR_PORT;
446 if ((configfp = fopen(configfile, "r")) == NULL)
448 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
450 /* Never get here - LOG_LEVEL_FATAL causes program exit */
453 while (read_config_line(buf, sizeof(buf), configfp, fs) != NULL)
455 char cmd[BUFFER_SIZE];
456 char arg[BUFFER_SIZE];
457 char tmp[BUFFER_SIZE];
459 struct access_control_list *cur_acl;
460 #endif /* def ACL_FILES */
461 struct forward_spec *cur_fwd;
467 /* Copy command (i.e. up to space or tab) into cmd */
470 while (*p && (*p != ' ') && (*p != '\t'))
476 /* Skip over the whitespace in buf */
477 while (*p && ((*p == ' ') || (*p == '\t')))
482 /* Copy the argument into arg */
485 /* Should never happen, but check this anyway */
491 /* Make sure the command field is lower case */
496 *p = ijb_tolower(*p);
500 /* Save the argument for show-proxy-args */
501 savearg(cmd, arg, config);
504 switch( hash_string( cmd ) )
506 /****************************************************************************
507 * actionsfile actions-file-name
508 * In confdir by default
509 ****************************************************************************/
510 case hash_actions_file :
511 freez((char *)config->actions_file);
512 config->actions_file = make_path(config->confdir, arg);
515 /****************************************************************************
516 * admin-address email-address
517 ****************************************************************************/
518 case hash_admin_address :
519 freez((char *)config->admin_address);
520 config->admin_address = strdup(arg);
523 /****************************************************************************
524 * confdir directory-name
525 ****************************************************************************/
527 freez((char *)config->confdir);
528 config->confdir = strdup(arg);
531 /****************************************************************************
533 * Specifies debug level, multiple values are ORed together.
534 ****************************************************************************/
536 config->debug |= atoi(arg);
539 /****************************************************************************
540 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
541 ****************************************************************************/
543 case hash_deny_access:
544 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
546 if ((vec_count != 1) && (vec_count != 2))
548 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
549 "deny-access directive in configuration file.");
550 config->proxy_args = strsav( config->proxy_args,
551 "<br>\nWARNING: Wrong number of parameters for "
552 "deny-access directive in configuration file.<br><br>\n");
556 /* allocate a new node */
557 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
561 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
562 /* Never get here - LOG_LEVEL_FATAL causes program exit */
565 cur_acl->action = ACL_DENY;
567 if (acl_addr(vec[0], cur_acl->src) < 0)
569 log_error(LOG_LEVEL_ERROR, "Invalid source IP for deny-access "
570 "directive in configuration file: \"%s\"", vec[0]);
571 config->proxy_args = strsav( config->proxy_args,
572 "<br>\nWARNING: Invalid source IP for deny-access directive"
573 " in configuration file: \"");
574 config->proxy_args = strsav( config->proxy_args,
576 config->proxy_args = strsav( config->proxy_args,
583 if (acl_addr(vec[1], cur_acl->dst) < 0)
585 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for deny-access "
586 "directive in configuration file: \"%s\"", vec[0]);
587 config->proxy_args = strsav( config->proxy_args,
588 "<br>\nWARNING: Invalid destination IP for deny-access directive"
589 " in configuration file: \"");
590 config->proxy_args = strsav( config->proxy_args,
592 config->proxy_args = strsav( config->proxy_args,
600 * Add it to the list. Note we reverse the list to get the
601 * behaviour the user expects. With both the ACL and
602 * actions file, the last match wins. However, the internal
603 * implementations are different: The actions file is stored
604 * in the same order as the file, and scanned completely.
605 * With the ACL, we reverse the order as we load it, then
606 * when we scan it we stop as soon as we get a match.
608 cur_acl->next = config->acl;
609 config->acl = cur_acl;
612 #endif /* def ACL_FILES */
614 /****************************************************************************
615 * forward url-pattern (.|http-proxy-host[:port])
616 ****************************************************************************/
618 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
622 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
623 "directive in configuration file.");
624 config->proxy_args = strsav( config->proxy_args,
625 "<br>\nWARNING: Wrong number of parameters for "
626 "forward directive in configuration file.");
630 /* allocate a new node */
631 cur_fwd = zalloc(sizeof(*cur_fwd));
634 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
635 /* Never get here - LOG_LEVEL_FATAL causes program exit */
639 cur_fwd->type = SOCKS_NONE;
641 /* Save the URL pattern */
642 if (create_url_spec(cur_fwd->url, vec[0]))
644 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
645 "directive in configuration file.");
646 config->proxy_args = strsav( config->proxy_args,
647 "<br>\nWARNING: Bad URL specifier for "
648 "forward directive in configuration file.");
652 /* Parse the parent HTTP proxy host:port */
655 if (strcmp(p, ".") != 0)
657 cur_fwd->forward_host = strdup(p);
659 if ((p = strchr(cur_fwd->forward_host, ':')))
662 cur_fwd->forward_port = atoi(p);
665 if (cur_fwd->forward_port <= 0)
667 cur_fwd->forward_port = 8000;
672 cur_fwd->next = config->forward;
673 config->forward = cur_fwd;
677 /****************************************************************************
678 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
679 ****************************************************************************/
680 case hash_forward_socks4:
681 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
685 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
686 "forward-socks4 directive in configuration file.");
687 config->proxy_args = strsav( config->proxy_args,
688 "<br>\nWARNING: Wrong number of parameters for "
689 "forward-socks4 directive in configuration file.");
693 /* allocate a new node */
694 cur_fwd = zalloc(sizeof(*cur_fwd));
697 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
698 /* Never get here - LOG_LEVEL_FATAL causes program exit */
702 cur_fwd->type = SOCKS_4;
704 /* Save the URL pattern */
705 if (create_url_spec(cur_fwd->url, vec[0]))
707 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
708 "directive in configuration file.");
709 config->proxy_args = strsav( config->proxy_args,
710 "<br>\nWARNING: Bad URL specifier for "
711 "forward-socks4 directive in configuration file.");
715 /* Parse the SOCKS proxy host[:port] */
718 if (strcmp(p, ".") != 0)
720 cur_fwd->gateway_host = strdup(p);
722 if ((p = strchr(cur_fwd->gateway_host, ':')))
725 cur_fwd->gateway_port = atoi(p);
727 if (cur_fwd->gateway_port <= 0)
729 cur_fwd->gateway_port = 1080;
733 /* Parse the parent HTTP proxy host[:port] */
736 if (strcmp(p, ".") != 0)
738 cur_fwd->forward_host = strdup(p);
740 if ((p = strchr(cur_fwd->forward_host, ':')))
743 cur_fwd->forward_port = atoi(p);
746 if (cur_fwd->forward_port <= 0)
748 cur_fwd->forward_port = 8000;
753 cur_fwd->next = config->forward;
754 config->forward = cur_fwd;
758 /****************************************************************************
759 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
760 ****************************************************************************/
761 case hash_forward_socks4a:
762 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
766 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
767 "forward-socks4a directive in configuration file.");
768 config->proxy_args = strsav( config->proxy_args,
769 "<br>\nWARNING: Wrong number of parameters for "
770 "forward-socks4a directive in configuration file.");
774 /* allocate a new node */
775 cur_fwd = zalloc(sizeof(*cur_fwd));
778 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
779 /* Never get here - LOG_LEVEL_FATAL causes program exit */
783 cur_fwd->type = SOCKS_4A;
785 /* Save the URL pattern */
786 if (create_url_spec(cur_fwd->url, vec[0]))
788 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
789 "directive in configuration file.");
790 config->proxy_args = strsav( config->proxy_args,
791 "<br>\nWARNING: Bad URL specifier for "
792 "forward-socks4a directive in configuration file.");
796 /* Parse the SOCKS proxy host[:port] */
799 cur_fwd->gateway_host = strdup(p);
801 if ((p = strchr(cur_fwd->gateway_host, ':')))
804 cur_fwd->gateway_port = atoi(p);
806 if (cur_fwd->gateway_port <= 0)
808 cur_fwd->gateway_port = 1080;
811 /* Parse the parent HTTP proxy host[:port] */
814 if (strcmp(p, ".") != 0)
816 cur_fwd->forward_host = strdup(p);
818 if ((p = strchr(cur_fwd->forward_host, ':')))
821 cur_fwd->forward_port = atoi(p);
824 if (cur_fwd->forward_port <= 0)
826 cur_fwd->forward_port = 8000;
831 cur_fwd->next = config->forward;
832 config->forward = cur_fwd;
836 /****************************************************************************
837 * jarfile jar-file-name
838 * In logdir by default
839 ****************************************************************************/
842 freez((char *)config->jarfile);
843 config->jarfile = make_path(config->logdir, arg);
845 #endif /* def JAR_FILES */
847 /****************************************************************************
848 * listen-address [ip][:port]
849 ****************************************************************************/
850 case hash_listen_address :
851 freez((char *)config->haddr);
852 config->haddr = strdup(arg);
855 /****************************************************************************
856 * logdir directory-name
857 ****************************************************************************/
859 freez((char *)config->logdir);
860 config->logdir = strdup(arg);
863 /****************************************************************************
864 * logfile log-file-name
865 * In logdir by default
866 ****************************************************************************/
868 freez((char *)config->logfile);
869 config->logfile = make_path(config->logdir, arg);
872 /****************************************************************************
873 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
874 ****************************************************************************/
876 case hash_permit_access:
877 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
879 if ((vec_count != 1) && (vec_count != 2))
881 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
882 "permit-access directive in configuration file.");
883 config->proxy_args = strsav( config->proxy_args,
884 "<br>\nWARNING: Wrong number of parameters for "
885 "permit-access directive in configuration file.<br><br>\n");
890 /* allocate a new node */
891 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
895 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
896 /* Never get here - LOG_LEVEL_FATAL causes program exit */
899 cur_acl->action = ACL_PERMIT;
901 if (acl_addr(vec[0], cur_acl->src) < 0)
903 log_error(LOG_LEVEL_ERROR, "Invalid source IP for permit-access "
904 "directive in configuration file: \"%s\"", vec[0]);
905 config->proxy_args = strsav( config->proxy_args,
906 "<br>\nWARNING: Invalid source IP for permit-access directive"
907 " in configuration file: \"");
908 config->proxy_args = strsav( config->proxy_args,
910 config->proxy_args = strsav( config->proxy_args,
917 if (acl_addr(vec[1], cur_acl->dst) < 0)
919 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for "
920 "permit-access directive in configuration file: \"%s\"",
922 config->proxy_args = strsav( config->proxy_args,
923 "<br>\nWARNING: Invalid destination IP for permit-access directive"
924 " in configuration file: \"");
925 config->proxy_args = strsav( config->proxy_args,
927 config->proxy_args = strsav( config->proxy_args,
935 * Add it to the list. Note we reverse the list to get the
936 * behaviour the user expects. With both the ACL and
937 * actions file, the last match wins. However, the internal
938 * implementations are different: The actions file is stored
939 * in the same order as the file, and scanned completely.
940 * With the ACL, we reverse the order as we load it, then
941 * when we scan it we stop as soon as we get a match.
943 cur_acl->next = config->acl;
944 config->acl = cur_acl;
947 #endif /* def ACL_FILES */
949 /****************************************************************************
951 ****************************************************************************/
952 case hash_proxy_info_url :
953 freez((char *)config->proxy_info_url);
954 config->proxy_info_url = strdup(arg);
957 /****************************************************************************
958 * re_filterfile file-name
959 * In confdir by default.
960 ****************************************************************************/
962 case hash_re_filterfile :
963 freez((char *)config->re_filterfile);
964 config->re_filterfile = make_path(config->confdir, arg);
966 #endif /* def PCRS */
968 /****************************************************************************
970 ****************************************************************************/
971 case hash_single_threaded :
972 config->multi_threaded = 0;
975 /****************************************************************************
976 * FIXME: Document this FIXME2: Shouldn't we throw this out? --oes
977 ****************************************************************************/
978 #ifndef SPLIT_PROXY_ARGS
979 case hash_suppress_blocklists :
982 config->suppress_message = strdup(arg);
986 /* There will be NO reference in proxy-args. */
987 config->suppress_message = NULL;
990 config->suppress_blocklists = 1;
992 #endif /* ndef SPLIT_PROXY_ARGS */
994 /****************************************************************************
996 ****************************************************************************/
999 g_bToggleIJB = atoi(arg);
1001 #endif /* def TOGGLE */
1003 /****************************************************************************
1004 * trust-info-url url
1005 ****************************************************************************/
1007 case hash_trust_info_url :
1008 enlist(config->trust_info, arg);
1010 #endif /* def TRUST_FILES */
1012 /****************************************************************************
1013 * trustfile filename
1014 * (In confdir by default.)
1015 ****************************************************************************/
1017 case hash_trustfile :
1018 freez((char *)config->trustfile);
1019 config->trustfile = make_path(config->confdir, arg);
1021 #endif /* def TRUST_FILES */
1024 /****************************************************************************
1025 * Win32 Console options:
1026 ****************************************************************************/
1028 /****************************************************************************
1030 ****************************************************************************/
1032 case hash_hide_console :
1035 #endif /*def _WIN_CONSOLE*/
1038 /****************************************************************************
1039 * Win32 GUI options:
1040 ****************************************************************************/
1042 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1043 /****************************************************************************
1044 * activity-animation (0|1)
1045 ****************************************************************************/
1046 case hash_activity_animation :
1047 g_bShowActivityAnimation = atoi(arg);
1050 /****************************************************************************
1051 * close-button-minimizes (0|1)
1052 ****************************************************************************/
1053 case hash_close_button_minimizes :
1054 g_bCloseHidesWindow = atoi(arg);
1057 /****************************************************************************
1058 * log-buffer-size (0|1)
1059 ****************************************************************************/
1060 case hash_log_buffer_size :
1061 g_bLimitBufferSize = atoi(arg);
1064 /****************************************************************************
1065 * log-font-name fontnane
1066 ****************************************************************************/
1067 case hash_log_font_name :
1068 strcpy( g_szFontFaceName, arg );
1071 /****************************************************************************
1073 ****************************************************************************/
1074 case hash_log_font_size :
1075 g_nFontSize = atoi(arg);
1078 /****************************************************************************
1079 * log-highlight-messages (0|1)
1080 ****************************************************************************/
1081 case hash_log_highlight_messages :
1082 g_bHighlightMessages = atoi(arg);
1085 /****************************************************************************
1087 ****************************************************************************/
1088 case hash_log_max_lines :
1089 g_nMaxBufferLines = atoi(arg);
1092 /****************************************************************************
1093 * log-messages (0|1)
1094 ****************************************************************************/
1095 case hash_log_messages :
1096 g_bLogMessages = atoi(arg);
1099 /****************************************************************************
1100 * show-on-task-bar (0|1)
1101 ****************************************************************************/
1102 case hash_show_on_task_bar :
1103 g_bShowOnTaskBar = atoi(arg);
1106 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1109 /****************************************************************************/
1110 /* Warnings about unsupported features */
1111 /****************************************************************************/
1113 case hash_deny_access:
1114 #endif /* ndef ACL_FILES */
1117 #endif /* ndef JAR_FILES */
1119 case hash_permit_access:
1120 #endif /* ndef ACL_FILES */
1122 case hash_re_filterfile :
1123 #endif /* ndef PCRS */
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);
1183 if (config->re_filterfile)
1185 add_loader(load_re_filterfile, config);
1187 #endif /* def PCRS */
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;
1264 g_re_filterfile = config->re_filterfile;
1267 g_trustfile = config->trustfile;
1271 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1272 /* FIXME: end kludge */
1275 config->need_bind = 1;
1277 if (current_configfile)
1279 struct configuration_spec * oldcfg = (struct configuration_spec *)
1280 current_configfile->f;
1282 * Check if config->haddr,hport == oldcfg->haddr,hport
1284 * The following could be written more compactly as a single,
1285 * (unreadably long) if statement.
1287 config->need_bind = 0;
1288 if (config->hport != oldcfg->hport)
1290 config->need_bind = 1;
1292 else if (config->haddr == NULL)
1294 if (oldcfg->haddr != NULL)
1296 config->need_bind = 1;
1299 else if (oldcfg->haddr == NULL)
1301 config->need_bind = 1;
1303 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1305 config->need_bind = 1;
1308 current_configfile->unloader = unload_configfile;
1311 fs->next = files->next;
1314 current_configfile = fs;