2 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.15 2001/06/07 23:13:40 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.15 2001/06/07 23:13:40 jongfoster
40 * Merging ACL and forward files into config file.
41 * Cosmetic: Sorting config file options alphabetically.
42 * Cosmetic: Adding brief syntax comments to config file options.
44 * Revision 1.14 2001/06/07 14:46:25 joergs
45 * Missing make_path() added for re_filterfile.
47 * Revision 1.13 2001/06/05 22:33:54 jongfoster
49 * Fixed minor memory leak.
50 * Also now uses make_path to prepend the pathnames.
52 * Revision 1.12 2001/06/05 20:04:09 jongfoster
53 * Now uses _snprintf() in place of snprintf() under Win32.
55 * Revision 1.11 2001/06/04 18:31:58 swa
56 * files are now prefixed with either `confdir' or `logdir'.
57 * `make redhat-dist' replaces both entries confdir and logdir
60 * Revision 1.10 2001/06/03 19:11:54 oes
61 * introduced confdir option
63 * Revision 1.10 2001/06/03 11:03:48 oes
70 * adapted to new enlist_unique arg format
74 * introduced confdir option
76 * filters.c filtrers.h
78 * extracted-CGI relevant stuff
86 * support for new cgi mechansim
90 * functions for new list type: "map"
91 * extended enlist_unique
98 * deleted const struct interceptors
106 * added struct http_response
107 * changes struct interceptors to struct cgi_dispatcher
108 * moved HTML stuff to cgi.h
117 * Revision 1.9 2001/06/01 20:06:24 jongfoster
118 * Removed support for "tinygif" option - moved to actions file.
120 * Revision 1.8 2001/05/31 21:27:13 jongfoster
121 * Removed many options from the config file and into the
122 * "actions" file: add_forwarded, suppress_vanilla_wafer,
123 * wafer, add_header, user_agent, referer, from
124 * Also globally replaced "permission" with "action".
126 * Revision 1.7 2001/05/29 09:50:24 jongfoster
127 * Unified blocklist/imagelist/permissionslist.
128 * File format is still under discussion, but the internal changes
131 * Also modified interceptor behaviour:
132 * - We now intercept all URLs beginning with one of the following
133 * prefixes (and *only* these prefixes):
135 * * http://ijbswa.sf.net/config/
136 * * http://ijbswa.sourceforge.net/config/
137 * - New interceptors "home page" - go to http://i.j.b/ to see it.
138 * - Internal changes so that intercepted and fast redirect pages
139 * are not replaced with an image.
140 * - Interceptors now have the option to send a binary page direct
141 * to the client. (i.e. ijb-send-banner uses this)
142 * - Implemented show-url-info interceptor. (Which is why I needed
143 * the above interceptors changes - a typical URL is
144 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
145 * The previous mechanism would not have intercepted that, and
146 * if it had been intercepted then it then it would have replaced
149 * Revision 1.6 2001/05/26 00:28:36 jongfoster
150 * Automatic reloading of config file.
151 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
152 * Most of the global variables have been moved to a new
153 * struct configuration_spec, accessed through csp->config->globalname
154 * Most of the globals remaining are used by the Win32 GUI.
156 * Revision 1.5 2001/05/25 22:34:30 jongfoster
159 * Revision 1.4 2001/05/22 18:46:04 oes
161 * - Enabled filtering banners by size rather than URL
162 * by adding patterns that replace all standard banner
163 * sizes with the "Junkbuster" gif to the re_filterfile
165 * - Enabled filtering WebBugs by providing a pattern
166 * which kills all 1x1 images
168 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
169 * which is selected by the (nonstandard and therefore
170 * capital) letter 'U' in the option string.
171 * It causes the quantifiers to be ungreedy by default.
172 * Appending a ? turns back to greedy (!).
174 * - Added a new interceptor ijb-send-banner, which
175 * sends back the "Junkbuster" gif. Without imagelist or
176 * MSIE detection support, or if tinygif = 1, or the
177 * URL isn't recognized as an imageurl, a lame HTML
178 * explanation is sent instead.
180 * - Added new feature, which permits blocking remote
181 * script redirects and firing back a local redirect
183 * The feature is conditionally compiled, i.e. it
184 * can be disabled with --disable-fast-redirects,
185 * plus it must be activated by a "fast-redirects"
186 * line in the config file, has its own log level
187 * and of course wants to be displayed by show-proxy-args
188 * Note: Boy, all the #ifdefs in 1001 locations and
189 * all the fumbling with configure.in and acconfig.h
190 * were *way* more work than the feature itself :-(
192 * - Because a generic redirect template was needed for
193 * this, tinygif = 3 now uses the same.
195 * - Moved GIFs, and other static HTTP response templates
200 * - Removed some >400 CRs again (Jon, you really worked
203 * Revision 1.3 2001/05/20 01:21:20 jongfoster
204 * Version 2.9.4 checkin.
205 * - Merged popupfile and cookiefile, and added control over PCRS
206 * filtering, in new "permissionsfile".
207 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
208 * file error you now get a message box (in the Win32 GUI) rather
209 * than the program exiting with no explanation.
210 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
212 * - Removed tabs from "config"
213 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
214 * - Bumped up version number.
216 * Revision 1.2 2001/05/17 23:01:01 oes
217 * - Cleaned CRLF's from the sources and related files
219 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
220 * Initial import of version 2.9.3 source tree
223 *********************************************************************/
229 #include <sys/types.h>
239 # include <sys/timeb.h>
240 # include <windows.h>
242 # include <process.h>
245 # endif /* def TOGGLE */
248 # ifndef _WIN_CONSOLE
250 # endif /* ndef _WIN_CONSOLE */
252 /* VC++ has "_snprintf", not "snprintf" */
253 #define snprintf _snprintf
255 #else /* ifndef _WIN32 */
258 # include <sys/time.h>
259 # include <sys/wait.h>
260 # include <sys/stat.h>
270 #include "showargs.h"
272 #include "killpopup.h"
273 #include "miscutil.h"
275 #include "jbsockets.h"
279 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
282 * Fix a problem with Solaris. There should be no effect on other
284 * Solaris's isspace() is a macro which uses it's argument directly
285 * as an array index. Therefore we need to make sure that high-bit
286 * characters generate +ve values, and ideally we also want to make
287 * the argument match the declared parameter type of "int".
289 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
290 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
293 /* by haroon - indicates if ijb is enabled */
294 int g_bToggleIJB = 1; /* JunkBusters is enabled by default. */
297 /* The filename of the configfile */
298 const char *configfile = NULL;
301 * The load_config function is now going to call `init_proxy_args',
302 * so it will need argc and argv. So we need to have these
303 * globally available.
306 const char **Argv = NULL;
308 static struct file_list *current_configfile = NULL;
312 * This takes the "cryptic" hash of each keyword and aliases them to
313 * something a little more readable. This also makes changing the
314 * hash values easier if they should change or the hash algorthm changes.
315 * Use the included "hash" program to find out what the hash will be
316 * for any string supplied on the command line. (Or just put it in the
317 * config file and read the number from the error message in the log).
319 * Please keep this list sorted alphabetically (but with the Windows
320 * console and GUI specific options last).
323 #define hash_actions_file 3825730796ul /* FIXME "permissionsfile" */
324 #define hash_confdir 1978389ul /* "confdir" */
325 #define hash_debug 78263ul /* "debug" */
326 #define hash_deny_access 1227333715ul /* "deny-access" */
327 #define hash_forward 2029845ul /* "forward" */
328 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
329 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
330 #define hash_jarfile 2046641ul /* "jarfile" */
331 #define hash_listen_address 1255650842ul /* "listen-address" */
332 #define hash_logdir 422889ul /* "logdir" */
333 #define hash_logfile 2114766ul /* "logfile" */
334 #define hash_permit_access 3587953268ul /* "permit-access" */
335 #define hash_re_filterfile 3877522444ul /* "re_filterfile" */
336 #define hash_single_threaded 4250084780ul /* "single-threaded" */
337 #define hash_suppress_blocklists 1948693308ul /* ??? */
338 #define hash_toggle 447966ul /* "toggle" */
339 #define hash_trust_info_url 449869467ul /* ??? */
340 #define hash_trustfile 56494766ul /* "trustfile" */
342 #define hash_hide_console 2048809870ul /* "hide-console" */
344 #define hash_activity_animation 1817904738ul /* "activity-animation" */
345 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
346 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
347 #define hash_log_font_name 2866730124ul /* "log-font-name" */
348 #define hash_log_font_size 2866731014ul /* "log-font-size" */
349 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
350 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
351 #define hash_log_messages 2291744899ul /* "log-messages" */
352 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
355 /*********************************************************************
357 * Function : unload_configfile
359 * Description : Free the config structure and all components.
362 * 1 : data: struct configuration_spec to unload
366 *********************************************************************/
367 void unload_configfile (void * data)
369 struct configuration_spec * config = (struct configuration_spec *)data;
370 struct forward_spec *cur_fwd = config->forward;
372 struct access_control_list *cur_acl = config->acl;
374 while (cur_acl != NULL)
376 struct access_control_list * next_acl = cur_acl->next;
381 #endif /* def ACL_FILES */
383 while (cur_fwd != NULL)
385 struct forward_spec * next_fwd = cur_fwd->next;
386 free_url(cur_fwd->url);
388 freez(cur_fwd->gateway_host);
389 freez(cur_fwd->forward_host);
393 config->forward = NULL;
396 if ( NULL != config->jar )
398 fclose( config->jar );
401 #endif /* def JAR_FILES */
403 freez((char *)config->confdir);
404 freez((char *)config->logdir);
406 freez((char *)config->haddr);
407 freez((char *)config->logfile);
409 freez((char *)config->actions_file);
412 freez((char *)config->jarfile);
413 #endif /* def JAR_FILES */
415 #ifndef SPLIT_PROXY_ARGS
416 freez((char *)config->suppress_message);
417 #endif /* ndef SPLIT_PROXY_ARGS */
420 freez((char *)config->re_filterfile);
421 #endif /* def PCRS */
426 /*********************************************************************
428 * Function : load_config
430 * Description : Load the config file and all parameters.
433 * 1 : csp = Client state (the config member will be
434 * filled in by this function).
436 * Returns : 0 => Ok, everything else is an error.
438 *********************************************************************/
439 struct configuration_spec * load_config(void)
441 char buf[BUFFER_SIZE];
443 FILE *configfp = NULL;
444 struct configuration_spec * config = NULL;
445 struct client_state * fake_csp;
446 struct file_list *fs;
448 if (!check_file_changed(current_configfile, configfile, &fs))
450 /* No need to load */
451 return ((struct configuration_spec *)current_configfile->f);
455 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
459 log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
465 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
471 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
472 /* Never get here - LOG_LEVEL_FATAL causes program exit */
476 * This is backwards from how it's usually done.
477 * Following the usual pattern, "fs" would be stored in a member
478 * variable in "csp", and then we'd access "config" from "fs->f",
479 * using a cast. However, "config" is used so often that a
480 * cast each time would be very ugly, and the extra indirection
481 * would waste CPU cycles. Therefore we store "config" in
482 * "csp->config", and "fs" in "csp->config->config_file_list".
484 config->config_file_list = fs;
486 init_proxy_args(Argc, Argv, config);
492 config->multi_threaded = 1;
493 config->hport = HADDR_PORT;
495 if ((configfp = fopen(configfile, "r")) == NULL)
497 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
499 /* Never get here - LOG_LEVEL_FATAL causes program exit */
502 while (read_config_line(buf, sizeof(buf), configfp, fs) != NULL)
504 char cmd[BUFFER_SIZE];
505 char arg[BUFFER_SIZE];
506 char tmp[BUFFER_SIZE];
508 struct access_control_list *cur_acl;
509 #endif /* def ACL_FILES */
510 struct forward_spec *cur_fwd;
516 /* Copy command (i.e. up to space or tab) into cmd */
519 while (*p && (*p != ' ') && (*p != '\t'))
525 /* Skip over the whitespace in buf */
526 while (*p && ((*p == ' ') || (*p == '\t')))
531 /* Copy the argument into arg */
534 /* Should never happen, but check this anyway */
540 /* Make sure the command field is lower case */
545 *p = ijb_tolower(*p);
549 /* Save the argument for show-proxy-args */
550 savearg(cmd, arg, config);
553 switch( hash_string( cmd ) )
555 /****************************************************************************
556 * permissionsfile actions-file-name
557 * In confdir by default
558 ****************************************************************************/
559 case hash_actions_file :
560 freez((char *)config->actions_file);
561 config->actions_file = make_path(config->confdir, arg);
564 /****************************************************************************
565 * confdir directory-name
566 ****************************************************************************/
568 freez((char *)config->confdir);
569 config->confdir = strdup(arg);
572 /****************************************************************************
574 * Specifies debug level, multiple values are ORed together.
575 ****************************************************************************/
577 config->debug |= atoi(arg);
580 /****************************************************************************
581 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
582 ****************************************************************************/
584 case hash_deny_access:
585 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
587 if ((vec_count != 1) && (vec_count != 2))
589 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
590 "deny-access directive in configuration file.");
591 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
592 "<br>\nWARNING: Wrong number of parameters for "
593 "deny-access directive in configuration file.<br><br>\n");
597 /* allocate a new node */
598 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
602 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
603 /* Never get here - LOG_LEVEL_FATAL causes program exit */
606 cur_acl->action = ACL_DENY;
608 if (acl_addr(vec[0], cur_acl->src) < 0)
610 log_error(LOG_LEVEL_ERROR, "Invalid source IP for deny-access "
611 "directive in configuration file: \"%s\"", vec[0]);
612 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
613 "<br>\nWARNING: Invalid source IP for deny-access directive"
614 " in configuration file: \"");
615 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
617 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
624 if (acl_addr(vec[1], cur_acl->dst) < 0)
626 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for deny-access "
627 "directive in configuration file: \"%s\"", vec[0]);
628 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
629 "<br>\nWARNING: Invalid destination IP for deny-access directive"
630 " in configuration file: \"");
631 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
633 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
641 * Add it to the list. Note we reverse the list to get the
642 * behaviour the user expects. With both the ACL and
643 * actions file, the last match wins. However, the internal
644 * implementations are different: The actions file is stored
645 * in the same order as the file, and scanned completely.
646 * With the ACL, we reverse the order as we load it, then
647 * when we scan it we stop as soon as we get a match.
649 cur_acl->next = config->acl;
650 config->acl = cur_acl;
653 #endif /* def ACL_FILES */
655 /****************************************************************************
656 * forward url-pattern (.|http-proxy-host[:port])
657 ****************************************************************************/
659 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
663 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
664 "directive in configuration file.");
665 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
666 "<br>\nWARNING: Wrong number of parameters for "
667 "forward directive in configuration file.");
671 /* allocate a new node */
672 cur_fwd = zalloc(sizeof(*cur_fwd));
675 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
676 /* Never get here - LOG_LEVEL_FATAL causes program exit */
680 cur_fwd->type = SOCKS_NONE;
682 /* Save the URL pattern */
683 if (create_url_spec(cur_fwd->url, vec[0]))
685 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
686 "directive in configuration file.");
687 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
688 "<br>\nWARNING: Bad URL specifier for "
689 "forward directive in configuration file.");
693 /* Parse the parent HTTP proxy host:port */
696 if (strcmp(p, ".") != 0)
698 cur_fwd->forward_host = strdup(p);
700 if ((p = strchr(cur_fwd->forward_host, ':')))
703 cur_fwd->forward_port = atoi(p);
706 if (cur_fwd->forward_port <= 0)
708 cur_fwd->forward_port = 8000;
713 cur_fwd->next = config->forward;
714 config->forward = cur_fwd;
718 /****************************************************************************
719 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
720 ****************************************************************************/
721 case hash_forward_socks4:
722 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
726 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
727 "forward-socks4 directive in configuration file.");
728 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
729 "<br>\nWARNING: Wrong number of parameters for "
730 "forward-socks4 directive in configuration file.");
734 /* allocate a new node */
735 cur_fwd = zalloc(sizeof(*cur_fwd));
738 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
739 /* Never get here - LOG_LEVEL_FATAL causes program exit */
743 cur_fwd->type = SOCKS_4;
745 /* Save the URL pattern */
746 if (create_url_spec(cur_fwd->url, vec[0]))
748 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
749 "directive in configuration file.");
750 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
751 "<br>\nWARNING: Bad URL specifier for "
752 "forward-socks4 directive in configuration file.");
756 /* Parse the SOCKS proxy host[:port] */
759 if (strcmp(p, ".") != 0)
761 cur_fwd->gateway_host = strdup(p);
763 if ((p = strchr(cur_fwd->gateway_host, ':')))
766 cur_fwd->gateway_port = atoi(p);
768 if (cur_fwd->gateway_port <= 0)
770 cur_fwd->gateway_port = 1080;
774 /* Parse the parent HTTP proxy host[:port] */
777 if (strcmp(p, ".") != 0)
779 cur_fwd->forward_host = strdup(p);
781 if ((p = strchr(cur_fwd->forward_host, ':')))
784 cur_fwd->forward_port = atoi(p);
787 if (cur_fwd->forward_port <= 0)
789 cur_fwd->forward_port = 8000;
794 cur_fwd->next = config->forward;
795 config->forward = cur_fwd;
799 /****************************************************************************
800 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
801 ****************************************************************************/
802 case hash_forward_socks4a:
803 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
807 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
808 "forward-socks4a directive in configuration file.");
809 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
810 "<br>\nWARNING: Wrong number of parameters for "
811 "forward-socks4a directive in configuration file.");
815 /* allocate a new node */
816 cur_fwd = zalloc(sizeof(*cur_fwd));
819 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
820 /* Never get here - LOG_LEVEL_FATAL causes program exit */
824 cur_fwd->type = SOCKS_4A;
826 /* Save the URL pattern */
827 if (create_url_spec(cur_fwd->url, vec[0]))
829 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
830 "directive in configuration file.");
831 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
832 "<br>\nWARNING: Bad URL specifier for "
833 "forward-socks4a directive in configuration file.");
837 /* Parse the SOCKS proxy host[:port] */
840 cur_fwd->gateway_host = strdup(p);
842 if ((p = strchr(cur_fwd->gateway_host, ':')))
845 cur_fwd->gateway_port = atoi(p);
847 if (cur_fwd->gateway_port <= 0)
849 cur_fwd->gateway_port = 1080;
852 /* Parse the parent HTTP proxy host[:port] */
855 if (strcmp(p, ".") != 0)
857 cur_fwd->forward_host = strdup(p);
859 if ((p = strchr(cur_fwd->forward_host, ':')))
862 cur_fwd->forward_port = atoi(p);
865 if (cur_fwd->forward_port <= 0)
867 cur_fwd->forward_port = 8000;
872 cur_fwd->next = config->forward;
873 config->forward = cur_fwd;
877 /****************************************************************************
878 * jarfile jar-file-name
879 * In logdir by default
880 ****************************************************************************/
883 freez((char *)config->jarfile);
884 config->jarfile = make_path(config->logdir, arg);
886 #endif /* def JAR_FILES */
888 /****************************************************************************
889 * listen-address [ip][:port]
890 ****************************************************************************/
891 case hash_listen_address :
892 freez((char *)config->haddr);
893 config->haddr = strdup(arg);
896 /****************************************************************************
897 * logdir directory-name
898 ****************************************************************************/
900 freez((char *)config->logdir);
901 config->logdir = strdup(arg);
904 /****************************************************************************
905 * logfile log-file-name
906 * In logdir by default
907 ****************************************************************************/
909 freez((char *)config->logfile);
910 config->logfile = make_path(config->logdir, arg);
913 /****************************************************************************
914 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
915 ****************************************************************************/
917 case hash_permit_access:
918 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
920 if ((vec_count != 1) && (vec_count != 2))
922 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
923 "permit-access directive in configuration file.");
924 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
925 "<br>\nWARNING: Wrong number of parameters for "
926 "permit-access directive in configuration file.<br><br>\n");
931 /* allocate a new node */
932 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
936 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
937 /* Never get here - LOG_LEVEL_FATAL causes program exit */
940 cur_acl->action = ACL_PERMIT;
942 if (acl_addr(vec[0], cur_acl->src) < 0)
944 log_error(LOG_LEVEL_ERROR, "Invalid source IP for permit-access "
945 "directive in configuration file: \"%s\"", vec[0]);
946 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
947 "<br>\nWARNING: Invalid source IP for permit-access directive"
948 " in configuration file: \"");
949 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
951 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
958 if (acl_addr(vec[1], cur_acl->dst) < 0)
960 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for "
961 "permit-access directive in configuration file: \"%s\"",
963 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
964 "<br>\nWARNING: Invalid destination IP for permit-access directive"
965 " in configuration file: \"");
966 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
968 config->proxy_args_invocation = strsav( config->proxy_args_invocation,
976 * Add it to the list. Note we reverse the list to get the
977 * behaviour the user expects. With both the ACL and
978 * actions file, the last match wins. However, the internal
979 * implementations are different: The actions file is stored
980 * in the same order as the file, and scanned completely.
981 * With the ACL, we reverse the order as we load it, then
982 * when we scan it we stop as soon as we get a match.
984 cur_acl->next = config->acl;
985 config->acl = cur_acl;
988 #endif /* def ACL_FILES */
990 /****************************************************************************
991 * re_filterfile file-name
992 * In confdir by default.
993 ****************************************************************************/
995 case hash_re_filterfile :
996 freez((char *)config->re_filterfile);
997 config->re_filterfile = make_path(config->confdir, arg);
999 #endif /* def PCRS */
1001 /****************************************************************************
1003 ****************************************************************************/
1004 case hash_single_threaded :
1005 config->multi_threaded = 0;
1008 /****************************************************************************
1009 * FIXME: Document this
1010 ****************************************************************************/
1011 #ifndef SPLIT_PROXY_ARGS
1012 case hash_suppress_blocklists :
1015 config->suppress_message = strdup(arg);
1019 /* There will be NO reference in proxy-args. */
1020 config->suppress_message = NULL;
1023 config->suppress_blocklists = 1;
1025 #endif /* ndef SPLIT_PROXY_ARGS */
1027 /****************************************************************************
1029 ****************************************************************************/
1032 g_bToggleIJB = atoi(arg);
1034 #endif /* def TOGGLE */
1036 /****************************************************************************
1037 * FIXME: Please document this!
1038 ****************************************************************************/
1040 case hash_trust_info_url :
1041 enlist(config->trust_info, arg);
1043 #endif /* def TRUST_FILES */
1045 /****************************************************************************
1046 * trustfile filename
1047 * (In confdir by default.)
1048 ****************************************************************************/
1050 case hash_trustfile :
1051 freez((char *)config->trustfile);
1052 config->trustfile = make_path(config->confdir, arg);
1054 #endif /* def TRUST_FILES */
1057 /****************************************************************************
1058 * Win32 Console options:
1059 ****************************************************************************/
1061 /****************************************************************************
1063 ****************************************************************************/
1065 case hash_hide_console :
1068 #endif /*def _WIN_CONSOLE*/
1071 /****************************************************************************
1072 * Win32 GUI options:
1073 ****************************************************************************/
1075 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1076 /****************************************************************************
1077 * activity-animation (0|1)
1078 ****************************************************************************/
1079 case hash_activity_animation :
1080 g_bShowActivityAnimation = atoi(arg);
1083 /****************************************************************************
1084 * close-button-minimizes (0|1)
1085 ****************************************************************************/
1086 case hash_close_button_minimizes :
1087 g_bCloseHidesWindow = atoi(arg);
1090 /****************************************************************************
1091 * log-buffer-size (0|1)
1092 ****************************************************************************/
1093 case hash_log_buffer_size :
1094 g_bLimitBufferSize = atoi(arg);
1097 /****************************************************************************
1098 * log-font-name fontnane
1099 ****************************************************************************/
1100 case hash_log_font_name :
1101 strcpy( g_szFontFaceName, arg );
1104 /****************************************************************************
1106 ****************************************************************************/
1107 case hash_log_font_size :
1108 g_nFontSize = atoi(arg);
1111 /****************************************************************************
1112 * log-highlight-messages (0|1)
1113 ****************************************************************************/
1114 case hash_log_highlight_messages :
1115 g_bHighlightMessages = atoi(arg);
1118 /****************************************************************************
1120 ****************************************************************************/
1121 case hash_log_max_lines :
1122 g_nMaxBufferLines = atoi(arg);
1125 /****************************************************************************
1126 * log-messages (0|1)
1127 ****************************************************************************/
1128 case hash_log_messages :
1129 g_bLogMessages = atoi(arg);
1132 /****************************************************************************
1133 * show-on-task-bar (0|1)
1134 ****************************************************************************/
1135 case hash_show_on_task_bar :
1136 g_bShowOnTaskBar = atoi(arg);
1139 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1142 /****************************************************************************/
1143 /* Warnings about unsupported features */
1144 /****************************************************************************/
1146 case hash_deny_access:
1147 #endif /* ndef ACL_FILES */
1150 #endif /* ndef JAR_FILES */
1152 case hash_permit_access:
1153 #endif /* ndef ACL_FILES */
1155 case hash_re_filterfile :
1156 #endif /* ndef PCRS */
1157 #ifdef SPLIT_PROXY_ARGS
1158 case hash_suppress_blocklists :
1159 #endif /* def SPLIT_PROXY_ARGS */
1162 #endif /* ndef TOGGLE */
1164 case hash_trustfile :
1165 case hash_trust_info_url :
1166 #endif /* ndef TRUST_FILES */
1168 #ifndef _WIN_CONSOLE
1169 case hash_hide_console :
1170 #endif /* ndef _WIN_CONSOLE */
1172 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1173 case hash_activity_animation :
1174 case hash_close_button_minimizes :
1175 case hash_log_buffer_size :
1176 case hash_log_font_name :
1177 case hash_log_font_size :
1178 case hash_log_highlight_messages :
1179 case hash_log_max_lines :
1180 case hash_log_messages :
1181 case hash_show_on_task_bar :
1182 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1183 /* These warnings are annoying - so hide them. -- Jon */
1184 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1187 /****************************************************************************/
1189 /****************************************************************************/
1191 * I decided that I liked this better as a warning than an
1192 * error. To change back to an error, just change log level
1193 * to LOG_LEVEL_FATAL.
1195 log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%luul) in "
1196 "configuration file: \"%s\"", hash_string( cmd ), buf);
1197 config->proxy_args_invocation = strsav( config->proxy_args_invocation, "<br>\nWARNING: unrecognized directive : ");
1198 config->proxy_args_invocation = strsav( config->proxy_args_invocation, buf);
1199 config->proxy_args_invocation = strsav( config->proxy_args_invocation, "<br><br>\n");
1202 /****************************************************************************/
1203 } /* end switch( hash_string(cmd) ) */
1204 } /* end while ( read_config_line(...) ) */
1208 init_error_log(Argv[0], config->logfile, config->debug);
1210 if (config->actions_file)
1212 add_loader(load_actions_file, config);
1216 if (config->re_filterfile)
1218 add_loader(load_re_filterfile, config);
1220 #endif /* def PCRS */
1223 if (config->trustfile)
1225 add_loader(load_trustfile, config);
1230 if ( NULL != config->jarfile )
1232 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1234 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1235 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1237 setbuf(config->jar, NULL);
1239 #endif /* def JAR_FILES */
1241 if ( NULL == config->haddr )
1243 config->haddr = strdup( HADDR_DEFAULT );
1246 if ( NULL != config->haddr )
1248 if ((p = strchr(config->haddr, ':')))
1253 config->hport = atoi(p);
1257 if (config->hport <= 0)
1260 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1261 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1263 if (*config->haddr == '\0')
1265 config->haddr = NULL;
1270 * Want to run all the loaders once now.
1272 * Need to set up a fake csp, so they can get to the config.
1274 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1275 fake_csp->config = config;
1277 if (run_loader(fake_csp))
1280 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1281 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1285 #ifndef SPLIT_PROXY_ARGS
1286 if (!suppress_blocklists)
1288 fs->proxy_args = strsav(fs->proxy_args, "</pre>");
1290 #endif /* ndef SPLIT_PROXY_ARGS */
1292 /* FIXME: this is a kludge for win32 */
1293 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1295 g_actions_file = config->actions_file;
1297 g_re_filterfile = config->re_filterfile;
1300 g_trustfile = config->trustfile;
1304 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1305 /* FIXME: end kludge */
1308 config->need_bind = 1;
1310 if (current_configfile)
1312 struct configuration_spec * oldcfg = (struct configuration_spec *)
1313 current_configfile->f;
1315 * Check if config->haddr,hport == oldcfg->haddr,hport
1317 * The following could be written more compactly as a single,
1318 * (unreadably long) if statement.
1320 config->need_bind = 0;
1321 if (config->hport != oldcfg->hport)
1323 config->need_bind = 1;
1325 else if (config->haddr == NULL)
1327 if (oldcfg->haddr != NULL)
1329 config->need_bind = 1;
1332 else if (oldcfg->haddr == NULL)
1334 config->need_bind = 1;
1336 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1338 config->need_bind = 1;
1341 current_configfile->unloader = unload_configfile;
1344 fs->next = files->next;
1347 current_configfile = fs;