1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.22 2001/09/22 16:36:59 jongfoster Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
6 * Purpose : Loads settings from the configuration file into
7 * global variables. This file contains both the
8 * routine to load the configuration and the global
9 * variables it writes to.
11 * Copyright : Written by and Copyright (C) 2001 the SourceForge
12 * IJBSWA team. http://ijbswa.sourceforge.net
14 * Based on the Internet Junkbuster originally written
15 * by and Copyright (C) 1997 Anonymous Coders and
16 * Junkbusters Corporation. http://www.junkbusters.com
18 * This program is free software; you can redistribute it
19 * and/or modify it under the terms of the GNU General
20 * Public License as published by the Free Software
21 * Foundation; either version 2 of the License, or (at
22 * your option) any later version.
24 * This program is distributed in the hope that it will
25 * be useful, but WITHOUT ANY WARRANTY; without even the
26 * implied warranty of MERCHANTABILITY or FITNESS FOR A
27 * PARTICULAR PURPOSE. See the GNU General Public
28 * License for more details.
30 * The GNU General Public License should be included with
31 * this file. If not, you can view it at
32 * http://www.gnu.org/copyleft/gpl.html
33 * or write to the Free Software Foundation, Inc., 59
34 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 * Revision 1.22 2001/09/22 16:36:59 jongfoster
39 * Removing unused parameter fs from read_config_line()
41 * Revision 1.21 2001/09/16 17:10:43 jongfoster
42 * Moving function savearg() here, since it was the only thing left in
45 * Revision 1.20 2001/07/30 22:08:36 jongfoster
46 * Tidying up #defines:
47 * - All feature #defines are now of the form FEATURE_xxx
48 * - Permanently turned off WIN_GUI_EDIT
49 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
51 * Revision 1.19 2001/07/15 17:45:16 jongfoster
52 * Removing some unused #includes
54 * Revision 1.18 2001/07/13 14:01:14 oes
55 * - Removed all #ifdef PCRS
56 * - Removed vim-settings
58 * Revision 1.17 2001/06/29 13:31:03 oes
60 * - Fixed (actionsfile) and sorted hashes
61 * - Introduced admin_address and proxy-info-url
62 * as config parameters
63 * - Renamed config->proxy_args_invocation (which didn't have
64 * the invocation but the options!) to config->proxy_args
66 * - Removed logentry from cancelled commit
68 * Revision 1.16 2001/06/09 10:55:28 jongfoster
69 * Changing BUFSIZ ==> BUFFER_SIZE
71 * Revision 1.15 2001/06/07 23:13:40 jongfoster
72 * Merging ACL and forward files into config file.
73 * Cosmetic: Sorting config file options alphabetically.
74 * Cosmetic: Adding brief syntax comments to config file options.
76 * Revision 1.14 2001/06/07 14:46:25 joergs
77 * Missing make_path() added for re_filterfile.
79 * Revision 1.13 2001/06/05 22:33:54 jongfoster
81 * Fixed minor memory leak.
82 * Also now uses make_path to prepend the pathnames.
84 * Revision 1.12 2001/06/05 20:04:09 jongfoster
85 * Now uses _snprintf() in place of snprintf() under Win32.
87 * Revision 1.11 2001/06/04 18:31:58 swa
88 * files are now prefixed with either `confdir' or `logdir'.
89 * `make redhat-dist' replaces both entries confdir and logdir
92 * Revision 1.10 2001/06/03 19:11:54 oes
93 * introduced confdir option
95 * Revision 1.9 2001/06/01 20:06:24 jongfoster
96 * Removed support for "tinygif" option - moved to actions file.
98 * Revision 1.8 2001/05/31 21:27:13 jongfoster
99 * Removed many options from the config file and into the
100 * "actions" file: add_forwarded, suppress_vanilla_wafer,
101 * wafer, add_header, user_agent, referer, from
102 * Also globally replaced "permission" with "action".
104 * Revision 1.7 2001/05/29 09:50:24 jongfoster
105 * Unified blocklist/imagelist/permissionslist.
106 * File format is still under discussion, but the internal changes
109 * Also modified interceptor behaviour:
110 * - We now intercept all URLs beginning with one of the following
111 * prefixes (and *only* these prefixes):
113 * * http://ijbswa.sf.net/config/
114 * * http://ijbswa.sourceforge.net/config/
115 * - New interceptors "home page" - go to http://i.j.b/ to see it.
116 * - Internal changes so that intercepted and fast redirect pages
117 * are not replaced with an image.
118 * - Interceptors now have the option to send a binary page direct
119 * to the client. (i.e. ijb-send-banner uses this)
120 * - Implemented show-url-info interceptor. (Which is why I needed
121 * the above interceptors changes - a typical URL is
122 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
123 * The previous mechanism would not have intercepted that, and
124 * if it had been intercepted then it then it would have replaced
127 * Revision 1.6 2001/05/26 00:28:36 jongfoster
128 * Automatic reloading of config file.
129 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
130 * Most of the global variables have been moved to a new
131 * struct configuration_spec, accessed through csp->config->globalname
132 * Most of the globals remaining are used by the Win32 GUI.
134 * Revision 1.5 2001/05/25 22:34:30 jongfoster
137 * Revision 1.4 2001/05/22 18:46:04 oes
139 * - Enabled filtering banners by size rather than URL
140 * by adding patterns that replace all standard banner
141 * sizes with the "Junkbuster" gif to the re_filterfile
143 * - Enabled filtering WebBugs by providing a pattern
144 * which kills all 1x1 images
146 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
147 * which is selected by the (nonstandard and therefore
148 * capital) letter 'U' in the option string.
149 * It causes the quantifiers to be ungreedy by default.
150 * Appending a ? turns back to greedy (!).
152 * - Added a new interceptor ijb-send-banner, which
153 * sends back the "Junkbuster" gif. Without imagelist or
154 * MSIE detection support, or if tinygif = 1, or the
155 * URL isn't recognized as an imageurl, a lame HTML
156 * explanation is sent instead.
158 * - Added new feature, which permits blocking remote
159 * script redirects and firing back a local redirect
161 * The feature is conditionally compiled, i.e. it
162 * can be disabled with --disable-fast-redirects,
163 * plus it must be activated by a "fast-redirects"
164 * line in the config file, has its own log level
165 * and of course wants to be displayed by show-proxy-args
166 * Note: Boy, all the #ifdefs in 1001 locations and
167 * all the fumbling with configure.in and acconfig.h
168 * were *way* more work than the feature itself :-(
170 * - Because a generic redirect template was needed for
171 * this, tinygif = 3 now uses the same.
173 * - Moved GIFs, and other static HTTP response templates
178 * - Removed some >400 CRs again (Jon, you really worked
181 * Revision 1.3 2001/05/20 01:21:20 jongfoster
182 * Version 2.9.4 checkin.
183 * - Merged popupfile and cookiefile, and added control over PCRS
184 * filtering, in new "permissionsfile".
185 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
186 * file error you now get a message box (in the Win32 GUI) rather
187 * than the program exiting with no explanation.
188 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
190 * - Removed tabs from "config"
191 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
192 * - Bumped up version number.
194 * Revision 1.2 2001/05/17 23:01:01 oes
195 * - Cleaned CRLF's from the sources and related files
197 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
198 * Initial import of version 2.9.3 source tree
201 *********************************************************************/
207 #include <sys/types.h>
217 # include <windows.h>
220 # ifndef _WIN_CONSOLE
222 # endif /* ndef _WIN_CONSOLE */
224 /* VC++ has "_snprintf", not "snprintf" */
225 #define snprintf _snprintf
227 #else /* ifndef _WIN32 */
230 # include <sys/time.h>
231 # include <sys/wait.h>
232 # include <sys/stat.h>
242 #include "miscutil.h"
247 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
250 * Fix a problem with Solaris. There should be no effect on other
252 * Solaris's isspace() is a macro which uses it's argument directly
253 * as an array index. Therefore we need to make sure that high-bit
254 * characters generate +ve values, and ideally we also want to make
255 * the argument match the declared parameter type of "int".
257 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
258 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
260 #ifdef FEATURE_TOGGLE
261 /* by haroon - indicates if ijb is enabled */
262 int g_bToggleIJB = 1; /* JunkBusters is enabled by default. */
263 #endif /* def FEATURE_TOGGLE */
265 /* The filename of the configfile */
266 const char *configfile = NULL;
269 * CGI functions will later need access to the invocation args,
270 * so we will make argc and argv global.
273 const char **Argv = NULL;
275 static struct file_list *current_configfile = NULL;
279 * This takes the "cryptic" hash of each keyword and aliases them to
280 * something a little more readable. This also makes changing the
281 * hash values easier if they should change or the hash algorthm changes.
282 * Use the included "hash" program to find out what the hash will be
283 * for any string supplied on the command line. (Or just put it in the
284 * config file and read the number from the error message in the log).
286 * Please keep this list sorted alphabetically (but with the Windows
287 * console and GUI specific options last).
290 #define hash_actions_file 1196306641ul /* "actionsfile" */
291 #define hash_admin_address 4112573064ul /* "admin-address" */
292 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
293 #define hash_confdir 1978389ul /* "confdir" */
294 #define hash_debug 78263ul /* "debug" */
295 #define hash_deny_access 1227333715ul /* "deny-access" */
296 #define hash_forward 2029845ul /* "forward" */
297 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
298 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
299 #define hash_jarfile 2046641ul /* "jarfile" */
300 #define hash_listen_address 1255650842ul /* "listen-address" */
301 #define hash_logdir 422889ul /* "logdir" */
302 #define hash_logfile 2114766ul /* "logfile" */
303 #define hash_permit_access 3587953268ul /* "permit-access" */
304 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
305 #define hash_re_filterfile 3877522444ul /* "re_filterfile" */
306 #define hash_single_threaded 4250084780ul /* "single-threaded" */
307 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
308 #define hash_toggle 447966ul /* "toggle" */
309 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
310 #define hash_trustfile 56494766ul /* "trustfile" */
312 #define hash_activity_animation 1817904738ul /* "activity-animation" */
313 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
314 #define hash_hide_console 2048809870ul /* "hide-console" */
315 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
316 #define hash_log_font_name 2866730124ul /* "log-font-name" */
317 #define hash_log_font_size 2866731014ul /* "log-font-size" */
318 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
319 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
320 #define hash_log_messages 2291744899ul /* "log-messages" */
321 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
324 static void savearg(char *c, char *o, struct configuration_spec * config);
327 /*********************************************************************
329 * Function : unload_configfile
331 * Description : Free the config structure and all components.
334 * 1 : data: struct configuration_spec to unload
338 *********************************************************************/
339 void unload_configfile (void * data)
341 struct configuration_spec * config = (struct configuration_spec *)data;
342 struct forward_spec *cur_fwd = config->forward;
344 struct access_control_list *cur_acl = config->acl;
346 while (cur_acl != NULL)
348 struct access_control_list * next_acl = cur_acl->next;
353 #endif /* def FEATURE_ACL */
355 while (cur_fwd != NULL)
357 struct forward_spec * next_fwd = cur_fwd->next;
358 free_url(cur_fwd->url);
360 freez(cur_fwd->gateway_host);
361 freez(cur_fwd->forward_host);
365 config->forward = NULL;
367 #ifdef FEATURE_COOKIE_JAR
368 if ( NULL != config->jar )
370 fclose( config->jar );
373 #endif /* def FEATURE_COOKIE_JAR */
375 freez((char *)config->confdir);
376 freez((char *)config->logdir);
378 freez((char *)config->haddr);
379 freez((char *)config->logfile);
381 freez((char *)config->actions_file);
382 freez((char *)config->admin_address);
383 freez((char *)config->proxy_info_url);
384 freez((char *)config->proxy_args);
386 #ifdef FEATURE_COOKIE_JAR
387 freez((char *)config->jarfile);
388 #endif /* def FEATURE_COOKIE_JAR */
390 freez((char *)config->re_filterfile);
395 /*********************************************************************
397 * Function : load_config
399 * Description : Load the config file and all parameters.
402 * 1 : csp = Client state (the config member will be
403 * filled in by this function).
405 * Returns : 0 => Ok, everything else is an error.
407 *********************************************************************/
408 struct configuration_spec * load_config(void)
410 char buf[BUFFER_SIZE];
412 FILE *configfp = NULL;
413 struct configuration_spec * config = NULL;
414 struct client_state * fake_csp;
415 struct file_list *fs;
417 if (!check_file_changed(current_configfile, configfile, &fs))
419 /* No need to load */
420 return ((struct configuration_spec *)current_configfile->f);
424 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
428 log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
430 #ifdef FEATURE_TOGGLE
432 #endif /* def FEATURE_TOGGLE */
434 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
440 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
441 /* Never get here - LOG_LEVEL_FATAL causes program exit */
445 * This is backwards from how it's usually done.
446 * Following the usual pattern, "fs" would be stored in a member
447 * variable in "csp", and then we'd access "config" from "fs->f",
448 * using a cast. However, "config" is used so often that a
449 * cast each time would be very ugly, and the extra indirection
450 * would waste CPU cycles. Therefore we store "config" in
451 * "csp->config", and "fs" in "csp->config->config_file_list".
453 config->config_file_list = fs;
459 config->multi_threaded = 1;
460 config->hport = HADDR_PORT;
461 config->buffer_limit = 4096 * 1024;
463 if ((configfp = fopen(configfile, "r")) == NULL)
465 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
467 /* Never get here - LOG_LEVEL_FATAL causes program exit */
470 while (read_config_line(buf, sizeof(buf), configfp) != NULL)
472 char cmd[BUFFER_SIZE];
473 char arg[BUFFER_SIZE];
474 char tmp[BUFFER_SIZE];
476 struct access_control_list *cur_acl;
477 #endif /* def FEATURE_ACL */
478 struct forward_spec *cur_fwd;
484 /* Copy command (i.e. up to space or tab) into cmd */
487 while (*p && (*p != ' ') && (*p != '\t'))
493 /* Skip over the whitespace in buf */
494 while (*p && ((*p == ' ') || (*p == '\t')))
499 /* Copy the argument into arg */
502 /* Should never happen, but check this anyway */
508 /* Make sure the command field is lower case */
513 *p = ijb_tolower(*p);
517 /* Save the argument for show-proxy-args */
518 savearg(cmd, arg, config);
521 switch( hash_string( cmd ) )
523 /****************************************************************************
524 * actionsfile actions-file-name
525 * In confdir by default
526 ****************************************************************************/
527 case hash_actions_file :
528 freez((char *)config->actions_file);
529 config->actions_file = make_path(config->confdir, arg);
532 /****************************************************************************
533 * admin-address email-address
534 ****************************************************************************/
535 case hash_admin_address :
536 freez((char *)config->admin_address);
537 config->admin_address = strdup(arg);
540 /****************************************************************************
542 ****************************************************************************/
543 case hash_buffer_limit :
544 config->buffer_limit = (size_t) 1024 * atoi(arg);
547 /****************************************************************************
548 * confdir directory-name
549 ****************************************************************************/
551 freez((char *)config->confdir);
552 config->confdir = strdup(arg);
555 /****************************************************************************
557 * Specifies debug level, multiple values are ORed together.
558 ****************************************************************************/
560 config->debug |= atoi(arg);
563 /****************************************************************************
564 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
565 ****************************************************************************/
567 case hash_deny_access:
568 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
570 if ((vec_count != 1) && (vec_count != 2))
572 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
573 "deny-access directive in configuration file.");
574 config->proxy_args = strsav( config->proxy_args,
575 "<br>\nWARNING: Wrong number of parameters for "
576 "deny-access directive in configuration file.<br><br>\n");
580 /* allocate a new node */
581 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
585 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
586 /* Never get here - LOG_LEVEL_FATAL causes program exit */
589 cur_acl->action = ACL_DENY;
591 if (acl_addr(vec[0], cur_acl->src) < 0)
593 log_error(LOG_LEVEL_ERROR, "Invalid source IP for deny-access "
594 "directive in configuration file: \"%s\"", vec[0]);
595 config->proxy_args = strsav( config->proxy_args,
596 "<br>\nWARNING: Invalid source IP for deny-access directive"
597 " in configuration file: \"");
598 config->proxy_args = strsav( config->proxy_args,
600 config->proxy_args = strsav( config->proxy_args,
607 if (acl_addr(vec[1], cur_acl->dst) < 0)
609 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for deny-access "
610 "directive in configuration file: \"%s\"", vec[0]);
611 config->proxy_args = strsav( config->proxy_args,
612 "<br>\nWARNING: Invalid destination IP for deny-access directive"
613 " in configuration file: \"");
614 config->proxy_args = strsav( config->proxy_args,
616 config->proxy_args = strsav( config->proxy_args,
624 * Add it to the list. Note we reverse the list to get the
625 * behaviour the user expects. With both the ACL and
626 * actions file, the last match wins. However, the internal
627 * implementations are different: The actions file is stored
628 * in the same order as the file, and scanned completely.
629 * With the ACL, we reverse the order as we load it, then
630 * when we scan it we stop as soon as we get a match.
632 cur_acl->next = config->acl;
633 config->acl = cur_acl;
636 #endif /* def FEATURE_ACL */
638 /****************************************************************************
639 * forward url-pattern (.|http-proxy-host[:port])
640 ****************************************************************************/
642 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
646 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
647 "directive in configuration file.");
648 config->proxy_args = strsav( config->proxy_args,
649 "<br>\nWARNING: Wrong number of parameters for "
650 "forward directive in configuration file.");
654 /* allocate a new node */
655 cur_fwd = zalloc(sizeof(*cur_fwd));
658 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
659 /* Never get here - LOG_LEVEL_FATAL causes program exit */
663 cur_fwd->type = SOCKS_NONE;
665 /* Save the URL pattern */
666 if (create_url_spec(cur_fwd->url, vec[0]))
668 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
669 "directive in configuration file.");
670 config->proxy_args = strsav( config->proxy_args,
671 "<br>\nWARNING: Bad URL specifier for "
672 "forward directive in configuration file.");
676 /* Parse the parent HTTP proxy host:port */
679 if (strcmp(p, ".") != 0)
681 cur_fwd->forward_host = strdup(p);
683 if ((p = strchr(cur_fwd->forward_host, ':')))
686 cur_fwd->forward_port = atoi(p);
689 if (cur_fwd->forward_port <= 0)
691 cur_fwd->forward_port = 8000;
696 cur_fwd->next = config->forward;
697 config->forward = cur_fwd;
701 /****************************************************************************
702 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
703 ****************************************************************************/
704 case hash_forward_socks4:
705 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
709 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
710 "forward-socks4 directive in configuration file.");
711 config->proxy_args = strsav( config->proxy_args,
712 "<br>\nWARNING: Wrong number of parameters for "
713 "forward-socks4 directive in configuration file.");
717 /* allocate a new node */
718 cur_fwd = zalloc(sizeof(*cur_fwd));
721 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
722 /* Never get here - LOG_LEVEL_FATAL causes program exit */
726 cur_fwd->type = SOCKS_4;
728 /* Save the URL pattern */
729 if (create_url_spec(cur_fwd->url, vec[0]))
731 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
732 "directive in configuration file.");
733 config->proxy_args = strsav( config->proxy_args,
734 "<br>\nWARNING: Bad URL specifier for "
735 "forward-socks4 directive in configuration file.");
739 /* Parse the SOCKS proxy host[:port] */
742 if (strcmp(p, ".") != 0)
744 cur_fwd->gateway_host = strdup(p);
746 if ((p = strchr(cur_fwd->gateway_host, ':')))
749 cur_fwd->gateway_port = atoi(p);
751 if (cur_fwd->gateway_port <= 0)
753 cur_fwd->gateway_port = 1080;
757 /* Parse the parent HTTP proxy host[:port] */
760 if (strcmp(p, ".") != 0)
762 cur_fwd->forward_host = strdup(p);
764 if ((p = strchr(cur_fwd->forward_host, ':')))
767 cur_fwd->forward_port = atoi(p);
770 if (cur_fwd->forward_port <= 0)
772 cur_fwd->forward_port = 8000;
777 cur_fwd->next = config->forward;
778 config->forward = cur_fwd;
782 /****************************************************************************
783 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
784 ****************************************************************************/
785 case hash_forward_socks4a:
786 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
790 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
791 "forward-socks4a directive in configuration file.");
792 config->proxy_args = strsav( config->proxy_args,
793 "<br>\nWARNING: Wrong number of parameters for "
794 "forward-socks4a directive in configuration file.");
798 /* allocate a new node */
799 cur_fwd = zalloc(sizeof(*cur_fwd));
802 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
803 /* Never get here - LOG_LEVEL_FATAL causes program exit */
807 cur_fwd->type = SOCKS_4A;
809 /* Save the URL pattern */
810 if (create_url_spec(cur_fwd->url, vec[0]))
812 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
813 "directive in configuration file.");
814 config->proxy_args = strsav( config->proxy_args,
815 "<br>\nWARNING: Bad URL specifier for "
816 "forward-socks4a directive in configuration file.");
820 /* Parse the SOCKS proxy host[:port] */
823 cur_fwd->gateway_host = strdup(p);
825 if ((p = strchr(cur_fwd->gateway_host, ':')))
828 cur_fwd->gateway_port = atoi(p);
830 if (cur_fwd->gateway_port <= 0)
832 cur_fwd->gateway_port = 1080;
835 /* Parse the parent HTTP proxy host[:port] */
838 if (strcmp(p, ".") != 0)
840 cur_fwd->forward_host = strdup(p);
842 if ((p = strchr(cur_fwd->forward_host, ':')))
845 cur_fwd->forward_port = atoi(p);
848 if (cur_fwd->forward_port <= 0)
850 cur_fwd->forward_port = 8000;
855 cur_fwd->next = config->forward;
856 config->forward = cur_fwd;
860 /****************************************************************************
861 * jarfile jar-file-name
862 * In logdir by default
863 ****************************************************************************/
864 #ifdef FEATURE_COOKIE_JAR
866 freez((char *)config->jarfile);
867 config->jarfile = make_path(config->logdir, arg);
869 #endif /* def FEATURE_COOKIE_JAR */
871 /****************************************************************************
872 * listen-address [ip][:port]
873 ****************************************************************************/
874 case hash_listen_address :
875 freez((char *)config->haddr);
876 config->haddr = strdup(arg);
879 /****************************************************************************
880 * logdir directory-name
881 ****************************************************************************/
883 freez((char *)config->logdir);
884 config->logdir = strdup(arg);
887 /****************************************************************************
888 * logfile log-file-name
889 * In logdir by default
890 ****************************************************************************/
892 freez((char *)config->logfile);
893 config->logfile = make_path(config->logdir, arg);
896 /****************************************************************************
897 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
898 ****************************************************************************/
900 case hash_permit_access:
901 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
903 if ((vec_count != 1) && (vec_count != 2))
905 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
906 "permit-access directive in configuration file.");
907 config->proxy_args = strsav( config->proxy_args,
908 "<br>\nWARNING: Wrong number of parameters for "
909 "permit-access directive in configuration file.<br><br>\n");
914 /* allocate a new node */
915 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
919 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
920 /* Never get here - LOG_LEVEL_FATAL causes program exit */
923 cur_acl->action = ACL_PERMIT;
925 if (acl_addr(vec[0], cur_acl->src) < 0)
927 log_error(LOG_LEVEL_ERROR, "Invalid source IP for permit-access "
928 "directive in configuration file: \"%s\"", vec[0]);
929 config->proxy_args = strsav( config->proxy_args,
930 "<br>\nWARNING: Invalid source IP for permit-access directive"
931 " in configuration file: \"");
932 config->proxy_args = strsav( config->proxy_args,
934 config->proxy_args = strsav( config->proxy_args,
941 if (acl_addr(vec[1], cur_acl->dst) < 0)
943 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for "
944 "permit-access directive in configuration file: \"%s\"",
946 config->proxy_args = strsav( config->proxy_args,
947 "<br>\nWARNING: Invalid destination IP for permit-access directive"
948 " in configuration file: \"");
949 config->proxy_args = strsav( config->proxy_args,
951 config->proxy_args = strsav( config->proxy_args,
959 * Add it to the list. Note we reverse the list to get the
960 * behaviour the user expects. With both the ACL and
961 * actions file, the last match wins. However, the internal
962 * implementations are different: The actions file is stored
963 * in the same order as the file, and scanned completely.
964 * With the ACL, we reverse the order as we load it, then
965 * when we scan it we stop as soon as we get a match.
967 cur_acl->next = config->acl;
968 config->acl = cur_acl;
971 #endif /* def FEATURE_ACL */
973 /****************************************************************************
975 ****************************************************************************/
976 case hash_proxy_info_url :
977 freez((char *)config->proxy_info_url);
978 config->proxy_info_url = strdup(arg);
981 /****************************************************************************
982 * re_filterfile file-name
983 * In confdir by default.
984 ****************************************************************************/
985 case hash_re_filterfile :
986 freez((char *)config->re_filterfile);
987 config->re_filterfile = make_path(config->confdir, arg);
990 /****************************************************************************
992 ****************************************************************************/
993 case hash_single_threaded :
994 config->multi_threaded = 0;
997 /****************************************************************************
999 ****************************************************************************/
1000 #ifdef FEATURE_TOGGLE
1002 g_bToggleIJB = atoi(arg);
1004 #endif /* def FEATURE_TOGGLE */
1006 /****************************************************************************
1007 * trust-info-url url
1008 ****************************************************************************/
1009 #ifdef FEATURE_TRUST
1010 case hash_trust_info_url :
1011 enlist(config->trust_info, arg);
1013 #endif /* def FEATURE_TRUST */
1015 /****************************************************************************
1016 * trustfile filename
1017 * (In confdir by default.)
1018 ****************************************************************************/
1019 #ifdef FEATURE_TRUST
1020 case hash_trustfile :
1021 freez((char *)config->trustfile);
1022 config->trustfile = make_path(config->confdir, arg);
1024 #endif /* def FEATURE_TRUST */
1027 /****************************************************************************
1028 * Win32 Console options:
1029 ****************************************************************************/
1031 /****************************************************************************
1033 ****************************************************************************/
1035 case hash_hide_console :
1038 #endif /*def _WIN_CONSOLE*/
1041 /****************************************************************************
1042 * Win32 GUI options:
1043 ****************************************************************************/
1045 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1046 /****************************************************************************
1047 * activity-animation (0|1)
1048 ****************************************************************************/
1049 case hash_activity_animation :
1050 g_bShowActivityAnimation = atoi(arg);
1053 /****************************************************************************
1054 * close-button-minimizes (0|1)
1055 ****************************************************************************/
1056 case hash_close_button_minimizes :
1057 g_bCloseHidesWindow = atoi(arg);
1060 /****************************************************************************
1061 * log-buffer-size (0|1)
1062 ****************************************************************************/
1063 case hash_log_buffer_size :
1064 g_bLimitBufferSize = atoi(arg);
1067 /****************************************************************************
1068 * log-font-name fontnane
1069 ****************************************************************************/
1070 case hash_log_font_name :
1071 strcpy( g_szFontFaceName, arg );
1074 /****************************************************************************
1076 ****************************************************************************/
1077 case hash_log_font_size :
1078 g_nFontSize = atoi(arg);
1081 /****************************************************************************
1082 * log-highlight-messages (0|1)
1083 ****************************************************************************/
1084 case hash_log_highlight_messages :
1085 g_bHighlightMessages = atoi(arg);
1088 /****************************************************************************
1090 ****************************************************************************/
1091 case hash_log_max_lines :
1092 g_nMaxBufferLines = atoi(arg);
1095 /****************************************************************************
1096 * log-messages (0|1)
1097 ****************************************************************************/
1098 case hash_log_messages :
1099 g_bLogMessages = atoi(arg);
1102 /****************************************************************************
1103 * show-on-task-bar (0|1)
1104 ****************************************************************************/
1105 case hash_show_on_task_bar :
1106 g_bShowOnTaskBar = atoi(arg);
1109 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1112 /****************************************************************************/
1113 /* Warnings about unsupported features */
1114 /****************************************************************************/
1116 case hash_deny_access:
1117 #endif /* ndef FEATURE_ACL */
1118 #ifndef FEATURE_COOKIE_JAR
1120 #endif /* ndef FEATURE_COOKIE_JAR */
1122 case hash_permit_access:
1123 #endif /* ndef FEATURE_ACL */
1124 #ifndef FEATURE_TOGGLE
1126 #endif /* ndef FEATURE_TOGGLE */
1127 #ifndef FEATURE_TRUST
1128 case hash_trustfile :
1129 case hash_trust_info_url :
1130 #endif /* ndef FEATURE_TRUST */
1132 #ifndef _WIN_CONSOLE
1133 case hash_hide_console :
1134 #endif /* ndef _WIN_CONSOLE */
1136 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1137 case hash_activity_animation :
1138 case hash_close_button_minimizes :
1139 case hash_log_buffer_size :
1140 case hash_log_font_name :
1141 case hash_log_font_size :
1142 case hash_log_highlight_messages :
1143 case hash_log_max_lines :
1144 case hash_log_messages :
1145 case hash_show_on_task_bar :
1146 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1147 /* These warnings are annoying - so hide them. -- Jon */
1148 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1151 /****************************************************************************/
1153 /****************************************************************************/
1155 * I decided that I liked this better as a warning than an
1156 * error. To change back to an error, just change log level
1157 * to LOG_LEVEL_FATAL.
1159 log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%luul) in "
1160 "configuration file: \"%s\"", hash_string( cmd ), buf);
1161 config->proxy_args = strsav( config->proxy_args, "<br>\nWARNING: unrecognized directive : ");
1162 config->proxy_args = strsav( config->proxy_args, buf);
1163 config->proxy_args = strsav( config->proxy_args, "<br><br>\n");
1166 /****************************************************************************/
1167 } /* end switch( hash_string(cmd) ) */
1168 } /* end while ( read_config_line(...) ) */
1172 init_error_log(Argv[0], config->logfile, config->debug);
1174 if (config->actions_file)
1176 add_loader(load_actions_file, config);
1179 if (config->re_filterfile)
1181 add_loader(load_re_filterfile, config);
1184 #ifdef FEATURE_TRUST
1185 if (config->trustfile)
1187 add_loader(load_trustfile, config);
1189 #endif /* def FEATURE_TRUST */
1191 #ifdef FEATURE_COOKIE_JAR
1192 if ( NULL != config->jarfile )
1194 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1196 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1197 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1199 setbuf(config->jar, NULL);
1201 #endif /* def FEATURE_COOKIE_JAR */
1203 if ( NULL == config->haddr )
1205 config->haddr = strdup( HADDR_DEFAULT );
1208 if ( NULL != config->haddr )
1210 if ((p = strchr(config->haddr, ':')))
1215 config->hport = atoi(p);
1219 if (config->hport <= 0)
1222 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1223 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1225 if (*config->haddr == '\0')
1227 config->haddr = NULL;
1232 * Want to run all the loaders once now.
1234 * Need to set up a fake csp, so they can get to the config.
1236 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1237 fake_csp->config = config;
1239 if (run_loader(fake_csp))
1242 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1243 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1247 /* FIXME: this is a kludge for win32 */
1248 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1250 g_actions_file = config->actions_file;
1251 g_re_filterfile = config->re_filterfile;
1253 #ifdef FEATURE_TRUST
1254 g_trustfile = config->trustfile;
1255 #endif /* def FEATURE_TRUST */
1258 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1259 /* FIXME: end kludge */
1262 config->need_bind = 1;
1264 if (current_configfile)
1266 struct configuration_spec * oldcfg = (struct configuration_spec *)
1267 current_configfile->f;
1269 * Check if config->haddr,hport == oldcfg->haddr,hport
1271 * The following could be written more compactly as a single,
1272 * (unreadably long) if statement.
1274 config->need_bind = 0;
1275 if (config->hport != oldcfg->hport)
1277 config->need_bind = 1;
1279 else if (config->haddr == NULL)
1281 if (oldcfg->haddr != NULL)
1283 config->need_bind = 1;
1286 else if (oldcfg->haddr == NULL)
1288 config->need_bind = 1;
1290 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1292 config->need_bind = 1;
1295 current_configfile->unloader = unload_configfile;
1298 fs->next = files->next;
1301 current_configfile = fs;
1307 /*********************************************************************
1309 * Function : savearg
1311 * Description : Called from `load_config'. It saves each non-empty
1312 * and non-comment line from config into a list. This
1313 * list is used to create the show-proxy-args page.
1316 * 1 : c = config setting that was found
1317 * 2 : o = the setting's argument (if any)
1321 *********************************************************************/
1322 static void savearg(char *c, char *o, struct configuration_spec * config)
1324 char buf[BUFFER_SIZE];
1328 if ( ( NULL != c ) && ( '\0' != *c ) )
1330 if ((c = html_encode(c)))
1332 sprintf(buf, "<a href=\"" REDIRECT_URL "option#%s\">%s</a> ", c, c);
1336 if ( ( NULL != o ) && ( '\0' != *o ) )
1338 if ((o = html_encode(o)))
1340 if (strncmpic(o, "http://", 7) == 0)
1342 strcat(buf, "<a href=\"");
1346 strcat(buf, "</a>");
1356 strcat(buf, "<br>\n");
1358 config->proxy_args = strsav(config->proxy_args, buf);