2 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.14 2001/06/07 14:46:25 joergs 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.14 2001/06/07 14:46:25 joergs
40 * Missing make_path() added for re_filterfile.
42 * Revision 1.13 2001/06/05 22:33:54 jongfoster
44 * Fixed minor memory leak.
45 * Also now uses make_path to prepend the pathnames.
47 * Revision 1.12 2001/06/05 20:04:09 jongfoster
48 * Now uses _snprintf() in place of snprintf() under Win32.
50 * Revision 1.11 2001/06/04 18:31:58 swa
51 * files are now prefixed with either `confdir' or `logdir'.
52 * `make redhat-dist' replaces both entries confdir and logdir
55 * Revision 1.10 2001/06/03 19:11:54 oes
56 * introduced confdir option
58 * Revision 1.10 2001/06/03 11:03:48 oes
65 * adapted to new enlist_unique arg format
69 * introduced confdir option
71 * filters.c filtrers.h
73 * extracted-CGI relevant stuff
81 * support for new cgi mechansim
85 * functions for new list type: "map"
86 * extended enlist_unique
93 * deleted const struct interceptors
101 * added struct http_response
102 * changes struct interceptors to struct cgi_dispatcher
103 * moved HTML stuff to cgi.h
112 * Revision 1.9 2001/06/01 20:06:24 jongfoster
113 * Removed support for "tinygif" option - moved to actions file.
115 * Revision 1.8 2001/05/31 21:27:13 jongfoster
116 * Removed many options from the config file and into the
117 * "actions" file: add_forwarded, suppress_vanilla_wafer,
118 * wafer, add_header, user_agent, referer, from
119 * Also globally replaced "permission" with "action".
121 * Revision 1.7 2001/05/29 09:50:24 jongfoster
122 * Unified blocklist/imagelist/permissionslist.
123 * File format is still under discussion, but the internal changes
126 * Also modified interceptor behaviour:
127 * - We now intercept all URLs beginning with one of the following
128 * prefixes (and *only* these prefixes):
130 * * http://ijbswa.sf.net/config/
131 * * http://ijbswa.sourceforge.net/config/
132 * - New interceptors "home page" - go to http://i.j.b/ to see it.
133 * - Internal changes so that intercepted and fast redirect pages
134 * are not replaced with an image.
135 * - Interceptors now have the option to send a binary page direct
136 * to the client. (i.e. ijb-send-banner uses this)
137 * - Implemented show-url-info interceptor. (Which is why I needed
138 * the above interceptors changes - a typical URL is
139 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
140 * The previous mechanism would not have intercepted that, and
141 * if it had been intercepted then it then it would have replaced
144 * Revision 1.6 2001/05/26 00:28:36 jongfoster
145 * Automatic reloading of config file.
146 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
147 * Most of the global variables have been moved to a new
148 * struct configuration_spec, accessed through csp->config->globalname
149 * Most of the globals remaining are used by the Win32 GUI.
151 * Revision 1.5 2001/05/25 22:34:30 jongfoster
154 * Revision 1.4 2001/05/22 18:46:04 oes
156 * - Enabled filtering banners by size rather than URL
157 * by adding patterns that replace all standard banner
158 * sizes with the "Junkbuster" gif to the re_filterfile
160 * - Enabled filtering WebBugs by providing a pattern
161 * which kills all 1x1 images
163 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
164 * which is selected by the (nonstandard and therefore
165 * capital) letter 'U' in the option string.
166 * It causes the quantifiers to be ungreedy by default.
167 * Appending a ? turns back to greedy (!).
169 * - Added a new interceptor ijb-send-banner, which
170 * sends back the "Junkbuster" gif. Without imagelist or
171 * MSIE detection support, or if tinygif = 1, or the
172 * URL isn't recognized as an imageurl, a lame HTML
173 * explanation is sent instead.
175 * - Added new feature, which permits blocking remote
176 * script redirects and firing back a local redirect
178 * The feature is conditionally compiled, i.e. it
179 * can be disabled with --disable-fast-redirects,
180 * plus it must be activated by a "fast-redirects"
181 * line in the config file, has its own log level
182 * and of course wants to be displayed by show-proxy-args
183 * Note: Boy, all the #ifdefs in 1001 locations and
184 * all the fumbling with configure.in and acconfig.h
185 * were *way* more work than the feature itself :-(
187 * - Because a generic redirect template was needed for
188 * this, tinygif = 3 now uses the same.
190 * - Moved GIFs, and other static HTTP response templates
195 * - Removed some >400 CRs again (Jon, you really worked
198 * Revision 1.3 2001/05/20 01:21:20 jongfoster
199 * Version 2.9.4 checkin.
200 * - Merged popupfile and cookiefile, and added control over PCRS
201 * filtering, in new "permissionsfile".
202 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
203 * file error you now get a message box (in the Win32 GUI) rather
204 * than the program exiting with no explanation.
205 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
207 * - Removed tabs from "config"
208 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
209 * - Bumped up version number.
211 * Revision 1.2 2001/05/17 23:01:01 oes
212 * - Cleaned CRLF's from the sources and related files
214 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
215 * Initial import of version 2.9.3 source tree
218 *********************************************************************/
224 #include <sys/types.h>
234 # include <sys/timeb.h>
235 # include <windows.h>
237 # include <process.h>
240 # endif /* def TOGGLE */
243 # ifndef _WIN_CONSOLE
245 # endif /* ndef _WIN_CONSOLE */
247 /* VC++ has "_snprintf", not "snprintf" */
248 #define snprintf _snprintf
250 #else /* ifndef _WIN32 */
253 # include <sys/time.h>
254 # include <sys/wait.h>
255 # include <sys/stat.h>
265 #include "showargs.h"
267 #include "killpopup.h"
268 #include "miscutil.h"
270 #include "jbsockets.h"
274 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
277 * Fix a problem with Solaris. There should be no effect on other
279 * Solaris's isspace() is a macro which uses it's argument directly
280 * as an array index. Therefore we need to make sure that high-bit
281 * characters generate +ve values, and ideally we also want to make
282 * the argument match the declared parameter type of "int".
284 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
285 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
288 /* by haroon - indicates if ijb is enabled */
289 int g_bToggleIJB = 1; /* JunkBusters is enabled by default. */
292 /* The filename of the configfile */
293 const char *configfile = NULL;
296 * The load_config function is now going to call `init_proxy_args',
297 * so it will need argc and argv. So we need to have these
298 * globally available.
301 const char **Argv = NULL;
303 static struct file_list *current_configfile = NULL;
307 * This takes the "cryptic" hash of each keyword and aliases them to
308 * something a little more readable. This also makes changing the
309 * hash values easier if they should change or the hash algorthm changes.
310 * Use the included "hash" program to find out what the hash will be
311 * for any string supplied on the command line. (Or just put it in the
312 * config file and read the number from the error message in the log).
314 * Please keep this list sorted alphabetically (but with the Windows
315 * console and GUI specific options last).
318 #define hash_actions_file 3825730796ul /* FIXME "permissionsfile" */
319 #define hash_confdir 1978389ul /* "confdir" */
320 #define hash_debug 78263ul /* "debug" */
321 #define hash_deny_access 1227333715ul /* "deny-access" */
322 #define hash_forward 2029845ul /* "forward" */
323 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
324 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
325 #define hash_jarfile 2046641ul /* "jarfile" */
326 #define hash_listen_address 1255650842ul /* "listen-address" */
327 #define hash_logdir 422889ul /* "logdir" */
328 #define hash_logfile 2114766ul /* "logfile" */
329 #define hash_permit_access 3587953268ul /* "permit-access" */
330 #define hash_re_filterfile 3877522444ul /* "re_filterfile" */
331 #define hash_single_threaded 4250084780ul /* "single-threaded" */
332 #define hash_suppress_blocklists 1948693308ul /* ??? */
333 #define hash_toggle 447966ul /* "toggle" */
334 #define hash_trust_info_url 449869467ul /* ??? */
335 #define hash_trustfile 56494766ul /* "trustfile" */
337 #define hash_hide_console 2048809870ul /* "hide-console" */
339 #define hash_activity_animation 1817904738ul /* "activity-animation" */
340 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
341 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
342 #define hash_log_font_name 2866730124ul /* "log-font-name" */
343 #define hash_log_font_size 2866731014ul /* "log-font-size" */
344 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
345 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
346 #define hash_log_messages 2291744899ul /* "log-messages" */
347 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
350 /*********************************************************************
352 * Function : unload_configfile
354 * Description : Free the config structure and all components.
357 * 1 : data: struct configuration_spec to unload
361 *********************************************************************/
362 void unload_configfile (void * data)
364 struct configuration_spec * config = (struct configuration_spec *)data;
365 struct forward_spec *cur_fwd = config->forward;
367 struct access_control_list *cur_acl = config->acl;
369 while (cur_acl != NULL)
371 struct access_control_list * next_acl = cur_acl->next;
376 #endif /* def ACL_FILES */
378 while (cur_fwd != NULL)
380 struct forward_spec * next_fwd = cur_fwd->next;
381 free_url(cur_fwd->url);
383 freez(cur_fwd->gateway_host);
384 freez(cur_fwd->forward_host);
388 config->forward = NULL;
391 if ( NULL != config->jar )
393 fclose( config->jar );
396 #endif /* def JAR_FILES */
398 freez((char *)config->confdir);
399 freez((char *)config->logdir);
401 freez((char *)config->haddr);
402 freez((char *)config->logfile);
404 freez((char *)config->actions_file);
407 freez((char *)config->jarfile);
408 #endif /* def JAR_FILES */
410 #ifndef SPLIT_PROXY_ARGS
411 freez((char *)config->suppress_message);
412 #endif /* ndef SPLIT_PROXY_ARGS */
415 freez((char *)config->re_filterfile);
416 #endif /* def PCRS */
421 /*********************************************************************
423 * Function : load_config
425 * Description : Load the config file and all parameters.
428 * 1 : csp = Client state (the config member will be
429 * filled in by this function).
431 * Returns : 0 => Ok, everything else is an error.
433 *********************************************************************/
434 struct configuration_spec * load_config(void)
438 FILE *configfp = NULL;
439 struct configuration_spec * config = NULL;
440 struct client_state * fake_csp;
441 struct file_list *fs;
443 if (!check_file_changed(current_configfile, configfile, &fs))
445 /* No need to load */
446 return ((struct configuration_spec *)current_configfile->f);
450 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
454 log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
460 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
466 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
467 /* Never get here - LOG_LEVEL_FATAL causes program exit */
471 * This is backwards from how it's usually done.
472 * Following the usual pattern, "fs" would be stored in a member
473 * variable in "csp", and then we'd access "config" from "fs->f",
474 * using a cast. However, "config" is used so often that a
475 * cast each time would be very ugly, and the extra indirection
476 * would waste CPU cycles. Therefore we store "config" in
477 * "csp->config", and "fs" in "csp->config->config_file_list".
479 config->config_file_list = fs;
481 init_proxy_args(Argc, Argv, config);
487 config->multi_threaded = 1;
488 config->hport = HADDR_PORT;
490 if ((configfp = fopen(configfile, "r")) == NULL)
492 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
494 /* Never get here - LOG_LEVEL_FATAL causes program exit */
497 while (read_config_line(buf, sizeof(buf), configfp, fs) != NULL)
503 struct access_control_list *cur_acl;
504 #endif /* def ACL_FILES */
505 struct forward_spec *cur_fwd;
511 /* Copy command (i.e. up to space or tab) into cmd */
514 while (*p && (*p != ' ') && (*p != '\t'))
520 /* Skip over the whitespace in buf */
521 while (*p && ((*p == ' ') || (*p == '\t')))
526 /* Copy the argument into arg */
529 /* Should never happen, but check this anyway */
535 /* Make sure the command field is lower case */
540 *p = ijb_tolower(*p);
544 /* Save the argument for show-proxy-args */
545 savearg(cmd, arg, config);
548 switch( hash_string( cmd ) )
550 /****************************************************************************
551 * permissionsfile actions-file-name
552 * In confdir by default
553 ****************************************************************************/
554 case hash_actions_file :
555 freez((char *)config->actions_file);
556 config->actions_file = make_path(config->confdir, arg);
559 /****************************************************************************
560 * confdir directory-name
561 ****************************************************************************/
563 freez((char *)config->confdir);
564 config->confdir = strdup(arg);
567 /****************************************************************************
569 * Specifies debug level, multiple values are ORed together.
570 ****************************************************************************/
572 config->debug |= atoi(arg);
575 /****************************************************************************
576 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
577 ****************************************************************************/
579 case hash_deny_access:
580 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
582 if ((vec_count != 1) && (vec_count != 2))
584 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
585 "deny-access directive in configuration file.");
586 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
587 "<br>\nWARNING: Wrong number of parameters for "
588 "deny-access directive in configuration file.<br><br>\n");
592 /* allocate a new node */
593 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
597 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
598 /* Never get here - LOG_LEVEL_FATAL causes program exit */
601 cur_acl->action = ACL_DENY;
603 if (acl_addr(vec[0], cur_acl->src) < 0)
605 log_error(LOG_LEVEL_ERROR, "Invalid source IP for deny-access "
606 "directive in configuration file: \"%s\"", vec[0]);
607 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
608 "<br>\nWARNING: Invalid source IP for deny-access directive"
609 " in configuration file: \"");
610 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
612 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
619 if (acl_addr(vec[1], cur_acl->dst) < 0)
621 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for deny-access "
622 "directive in configuration file: \"%s\"", vec[0]);
623 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
624 "<br>\nWARNING: Invalid destination IP for deny-access directive"
625 " in configuration file: \"");
626 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
628 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
636 * Add it to the list. Note we reverse the list to get the
637 * behaviour the user expects. With both the ACL and
638 * actions file, the last match wins. However, the internal
639 * implementations are different: The actions file is stored
640 * in the same order as the file, and scanned completely.
641 * With the ACL, we reverse the order as we load it, then
642 * when we scan it we stop as soon as we get a match.
644 cur_acl->next = config->acl;
645 config->acl = cur_acl;
648 #endif /* def ACL_FILES */
650 /****************************************************************************
651 * forward url-pattern (.|http-proxy-host[:port])
652 ****************************************************************************/
654 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
658 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
659 "directive in configuration file.");
660 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
661 "<br>\nWARNING: Wrong number of parameters for "
662 "forward directive in configuration file.");
666 /* allocate a new node */
667 cur_fwd = zalloc(sizeof(*cur_fwd));
670 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
671 /* Never get here - LOG_LEVEL_FATAL causes program exit */
675 cur_fwd->type = SOCKS_NONE;
677 /* Save the URL pattern */
678 if (create_url_spec(cur_fwd->url, vec[0]))
680 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
681 "directive in configuration file.");
682 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
683 "<br>\nWARNING: Bad URL specifier for "
684 "forward directive in configuration file.");
688 /* Parse the parent HTTP proxy host:port */
691 if (strcmp(p, ".") != 0)
693 cur_fwd->forward_host = strdup(p);
695 if ((p = strchr(cur_fwd->forward_host, ':')))
698 cur_fwd->forward_port = atoi(p);
701 if (cur_fwd->forward_port <= 0)
703 cur_fwd->forward_port = 8000;
708 cur_fwd->next = config->forward;
709 config->forward = cur_fwd;
713 /****************************************************************************
714 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
715 ****************************************************************************/
716 case hash_forward_socks4:
717 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
721 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
722 "forward-socks4 directive in configuration file.");
723 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
724 "<br>\nWARNING: Wrong number of parameters for "
725 "forward-socks4 directive in configuration file.");
729 /* allocate a new node */
730 cur_fwd = zalloc(sizeof(*cur_fwd));
733 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
734 /* Never get here - LOG_LEVEL_FATAL causes program exit */
738 cur_fwd->type = SOCKS_4;
740 /* Save the URL pattern */
741 if (create_url_spec(cur_fwd->url, vec[0]))
743 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
744 "directive in configuration file.");
745 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
746 "<br>\nWARNING: Bad URL specifier for "
747 "forward-socks4 directive in configuration file.");
751 /* Parse the SOCKS proxy host[:port] */
754 if (strcmp(p, ".") != 0)
756 cur_fwd->gateway_host = strdup(p);
758 if ((p = strchr(cur_fwd->gateway_host, ':')))
761 cur_fwd->gateway_port = atoi(p);
763 if (cur_fwd->gateway_port <= 0)
765 cur_fwd->gateway_port = 1080;
769 /* Parse the parent HTTP proxy host[:port] */
772 if (strcmp(p, ".") != 0)
774 cur_fwd->forward_host = strdup(p);
776 if ((p = strchr(cur_fwd->forward_host, ':')))
779 cur_fwd->forward_port = atoi(p);
782 if (cur_fwd->forward_port <= 0)
784 cur_fwd->forward_port = 8000;
789 cur_fwd->next = config->forward;
790 config->forward = cur_fwd;
794 /****************************************************************************
795 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
796 ****************************************************************************/
797 case hash_forward_socks4a:
798 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
802 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
803 "forward-socks4a directive in configuration file.");
804 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
805 "<br>\nWARNING: Wrong number of parameters for "
806 "forward-socks4a directive in configuration file.");
810 /* allocate a new node */
811 cur_fwd = zalloc(sizeof(*cur_fwd));
814 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
815 /* Never get here - LOG_LEVEL_FATAL causes program exit */
819 cur_fwd->type = SOCKS_4A;
821 /* Save the URL pattern */
822 if (create_url_spec(cur_fwd->url, vec[0]))
824 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
825 "directive in configuration file.");
826 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
827 "<br>\nWARNING: Bad URL specifier for "
828 "forward-socks4a directive in configuration file.");
832 /* Parse the SOCKS proxy host[:port] */
835 cur_fwd->gateway_host = strdup(p);
837 if ((p = strchr(cur_fwd->gateway_host, ':')))
840 cur_fwd->gateway_port = atoi(p);
842 if (cur_fwd->gateway_port <= 0)
844 cur_fwd->gateway_port = 1080;
847 /* Parse the parent HTTP proxy host[:port] */
850 if (strcmp(p, ".") != 0)
852 cur_fwd->forward_host = strdup(p);
854 if ((p = strchr(cur_fwd->forward_host, ':')))
857 cur_fwd->forward_port = atoi(p);
860 if (cur_fwd->forward_port <= 0)
862 cur_fwd->forward_port = 8000;
867 cur_fwd->next = config->forward;
868 config->forward = cur_fwd;
872 /****************************************************************************
873 * jarfile jar-file-name
874 * In logdir by default
875 ****************************************************************************/
878 freez((char *)config->jarfile);
879 config->jarfile = make_path(config->logdir, arg);
881 #endif /* def JAR_FILES */
883 /****************************************************************************
884 * listen-address [ip][:port]
885 ****************************************************************************/
886 case hash_listen_address :
887 freez((char *)config->haddr);
888 config->haddr = strdup(arg);
891 /****************************************************************************
892 * logdir directory-name
893 ****************************************************************************/
895 freez((char *)config->logdir);
896 config->logdir = strdup(arg);
899 /****************************************************************************
900 * logfile log-file-name
901 * In logdir by default
902 ****************************************************************************/
904 freez((char *)config->logfile);
905 config->logfile = make_path(config->logdir, arg);
908 /****************************************************************************
909 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
910 ****************************************************************************/
912 case hash_permit_access:
913 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
915 if ((vec_count != 1) && (vec_count != 2))
917 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
918 "permit-access directive in configuration file.");
919 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
920 "<br>\nWARNING: Wrong number of parameters for "
921 "permit-access directive in configuration file.<br><br>\n");
926 /* allocate a new node */
927 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
931 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
932 /* Never get here - LOG_LEVEL_FATAL causes program exit */
935 cur_acl->action = ACL_PERMIT;
937 if (acl_addr(vec[0], cur_acl->src) < 0)
939 log_error(LOG_LEVEL_ERROR, "Invalid source IP for permit-access "
940 "directive in configuration file: \"%s\"", vec[0]);
941 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
942 "<br>\nWARNING: Invalid source IP for permit-access directive"
943 " in configuration file: \"");
944 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
946 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
953 if (acl_addr(vec[1], cur_acl->dst) < 0)
955 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for "
956 "permit-access directive in configuration file: \"%s\"",
958 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
959 "<br>\nWARNING: Invalid destination IP for permit-access directive"
960 " in configuration file: \"");
961 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
963 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
971 * Add it to the list. Note we reverse the list to get the
972 * behaviour the user expects. With both the ACL and
973 * actions file, the last match wins. However, the internal
974 * implementations are different: The actions file is stored
975 * in the same order as the file, and scanned completely.
976 * With the ACL, we reverse the order as we load it, then
977 * when we scan it we stop as soon as we get a match.
979 cur_acl->next = config->acl;
980 config->acl = cur_acl;
983 #endif /* def ACL_FILES */
985 /****************************************************************************
986 * re_filterfile file-name
987 * In confdir by default.
988 ****************************************************************************/
990 case hash_re_filterfile :
991 freez((char *)config->re_filterfile);
992 config->re_filterfile = make_path(config->confdir, arg);
994 #endif /* def PCRS */
996 /****************************************************************************
998 ****************************************************************************/
999 case hash_single_threaded :
1000 config->multi_threaded = 0;
1003 /****************************************************************************
1004 * FIXME: Document this
1005 ****************************************************************************/
1006 #ifndef SPLIT_PROXY_ARGS
1007 case hash_suppress_blocklists :
1010 config->suppress_message = strdup(arg);
1014 /* There will be NO reference in proxy-args. */
1015 config->suppress_message = NULL;
1018 config->suppress_blocklists = 1;
1020 #endif /* ndef SPLIT_PROXY_ARGS */
1022 /****************************************************************************
1024 ****************************************************************************/
1027 g_bToggleIJB = atoi(arg);
1029 #endif /* def TOGGLE */
1031 /****************************************************************************
1032 * FIXME: Please document this!
1033 ****************************************************************************/
1035 case hash_trust_info_url :
1036 enlist(config->trust_info, arg);
1038 #endif /* def TRUST_FILES */
1040 /****************************************************************************
1041 * trustfile filename
1042 * (In confdir by default.)
1043 ****************************************************************************/
1045 case hash_trustfile :
1046 freez((char *)config->trustfile);
1047 config->trustfile = make_path(config->confdir, arg);
1049 #endif /* def TRUST_FILES */
1052 /****************************************************************************
1053 * Win32 Console options:
1054 ****************************************************************************/
1056 /****************************************************************************
1058 ****************************************************************************/
1060 case hash_hide_console :
1063 #endif /*def _WIN_CONSOLE*/
1066 /****************************************************************************
1067 * Win32 GUI options:
1068 ****************************************************************************/
1070 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1071 /****************************************************************************
1072 * activity-animation (0|1)
1073 ****************************************************************************/
1074 case hash_activity_animation :
1075 g_bShowActivityAnimation = atoi(arg);
1078 /****************************************************************************
1079 * close-button-minimizes (0|1)
1080 ****************************************************************************/
1081 case hash_close_button_minimizes :
1082 g_bCloseHidesWindow = atoi(arg);
1085 /****************************************************************************
1086 * log-buffer-size (0|1)
1087 ****************************************************************************/
1088 case hash_log_buffer_size :
1089 g_bLimitBufferSize = atoi(arg);
1092 /****************************************************************************
1093 * log-font-name fontnane
1094 ****************************************************************************/
1095 case hash_log_font_name :
1096 strcpy( g_szFontFaceName, arg );
1099 /****************************************************************************
1101 ****************************************************************************/
1102 case hash_log_font_size :
1103 g_nFontSize = atoi(arg);
1106 /****************************************************************************
1107 * log-highlight-messages (0|1)
1108 ****************************************************************************/
1109 case hash_log_highlight_messages :
1110 g_bHighlightMessages = atoi(arg);
1113 /****************************************************************************
1115 ****************************************************************************/
1116 case hash_log_max_lines :
1117 g_nMaxBufferLines = atoi(arg);
1120 /****************************************************************************
1121 * log-messages (0|1)
1122 ****************************************************************************/
1123 case hash_log_messages :
1124 g_bLogMessages = atoi(arg);
1127 /****************************************************************************
1128 * show-on-task-bar (0|1)
1129 ****************************************************************************/
1130 case hash_show_on_task_bar :
1131 g_bShowOnTaskBar = atoi(arg);
1134 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1137 /****************************************************************************/
1138 /* Warnings about unsupported features */
1139 /****************************************************************************/
1141 case hash_deny_access:
1142 #endif /* ndef ACL_FILES */
1145 #endif /* ndef JAR_FILES */
1147 case hash_permit_access:
1148 #endif /* ndef ACL_FILES */
1150 case hash_re_filterfile :
1151 #endif /* ndef PCRS */
1152 #ifdef SPLIT_PROXY_ARGS
1153 case hash_suppress_blocklists :
1154 #endif /* def SPLIT_PROXY_ARGS */
1157 #endif /* ndef TOGGLE */
1159 case hash_trustfile :
1160 case hash_trust_info_url :
1161 #endif /* ndef TRUST_FILES */
1163 #ifndef _WIN_CONSOLE
1164 case hash_hide_console :
1165 #endif /* ndef _WIN_CONSOLE */
1167 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1168 case hash_activity_animation :
1169 case hash_close_button_minimizes :
1170 case hash_log_buffer_size :
1171 case hash_log_font_name :
1172 case hash_log_font_size :
1173 case hash_log_highlight_messages :
1174 case hash_log_max_lines :
1175 case hash_log_messages :
1176 case hash_show_on_task_bar :
1177 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1178 /* These warnings are annoying - so hide them. -- Jon */
1179 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1182 /****************************************************************************/
1184 /****************************************************************************/
1186 * I decided that I liked this better as a warning than an
1187 * error. To change back to an error, just change log level
1188 * to LOG_LEVEL_FATAL.
1190 log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%luul) in "
1191 "configuration file: \"%s\"", hash_string( cmd ), buf);
1192 config->proxy_args_invocation = strsav( config->proxy_args_invocation, "<br>\nWARNING: unrecognized directive : ");
1193 config->proxy_args_invocation = strsav( config->proxy_args_invocation, buf);
1194 config->proxy_args_invocation = strsav( config->proxy_args_invocation, "<br><br>\n");
1197 /****************************************************************************/
1198 } /* end switch( hash_string(cmd) ) */
1199 } /* end while ( read_config_line(...) ) */
1203 init_error_log(Argv[0], config->logfile, config->debug);
1205 if (config->actions_file)
1207 add_loader(load_actions_file, config);
1211 if (config->re_filterfile)
1213 add_loader(load_re_filterfile, config);
1215 #endif /* def PCRS */
1218 if (config->trustfile)
1220 add_loader(load_trustfile, config);
1225 if ( NULL != config->jarfile )
1227 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1229 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1230 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1232 setbuf(config->jar, NULL);
1234 #endif /* def JAR_FILES */
1236 if ( NULL == config->haddr )
1238 config->haddr = strdup( HADDR_DEFAULT );
1241 if ( NULL != config->haddr )
1243 if ((p = strchr(config->haddr, ':')))
1248 config->hport = atoi(p);
1252 if (config->hport <= 0)
1255 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1256 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1258 if (*config->haddr == '\0')
1260 config->haddr = NULL;
1265 * Want to run all the loaders once now.
1267 * Need to set up a fake csp, so they can get to the config.
1269 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1270 fake_csp->config = config;
1272 if (run_loader(fake_csp))
1275 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1276 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1280 #ifndef SPLIT_PROXY_ARGS
1281 if (!suppress_blocklists)
1283 fs->proxy_args = strsav(fs->proxy_args, "</pre>");
1285 #endif /* ndef SPLIT_PROXY_ARGS */
1287 /* FIXME: this is a kludge for win32 */
1288 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1290 g_actions_file = config->actions_file;
1292 g_re_filterfile = config->re_filterfile;
1295 g_trustfile = config->trustfile;
1299 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1300 /* FIXME: end kludge */
1303 config->need_bind = 1;
1305 if (current_configfile)
1307 struct configuration_spec * oldcfg = (struct configuration_spec *)
1308 current_configfile->f;
1310 * Check if config->haddr,hport == oldcfg->haddr,hport
1312 * The following could be written more compactly as a single,
1313 * (unreadably long) if statement.
1315 config->need_bind = 0;
1316 if (config->hport != oldcfg->hport)
1318 config->need_bind = 1;
1320 else if (config->haddr == NULL)
1322 if (oldcfg->haddr != NULL)
1324 config->need_bind = 1;
1327 else if (oldcfg->haddr == NULL)
1329 config->need_bind = 1;
1331 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1333 config->need_bind = 1;
1336 current_configfile->unloader = unload_configfile;
1339 fs->next = files->next;
1342 current_configfile = fs;