1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.20 2001/07/30 22:08:36 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.20 2001/07/30 22:08:36 jongfoster
39 * Tidying up #defines:
40 * - All feature #defines are now of the form FEATURE_xxx
41 * - Permanently turned off WIN_GUI_EDIT
42 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
44 * Revision 1.19 2001/07/15 17:45:16 jongfoster
45 * Removing some unused #includes
47 * Revision 1.18 2001/07/13 14:01:14 oes
48 * - Removed all #ifdef PCRS
49 * - Removed vim-settings
51 * Revision 1.17 2001/06/29 13:31:03 oes
53 * - Fixed (actionsfile) and sorted hashes
54 * - Introduced admin_address and proxy-info-url
55 * as config parameters
56 * - Renamed config->proxy_args_invocation (which didn't have
57 * the invocation but the options!) to config->proxy_args
59 * - Removed logentry from cancelled commit
61 * Revision 1.16 2001/06/09 10:55:28 jongfoster
62 * Changing BUFSIZ ==> BUFFER_SIZE
64 * Revision 1.15 2001/06/07 23:13:40 jongfoster
65 * Merging ACL and forward files into config file.
66 * Cosmetic: Sorting config file options alphabetically.
67 * Cosmetic: Adding brief syntax comments to config file options.
69 * Revision 1.14 2001/06/07 14:46:25 joergs
70 * Missing make_path() added for re_filterfile.
72 * Revision 1.13 2001/06/05 22:33:54 jongfoster
74 * Fixed minor memory leak.
75 * Also now uses make_path to prepend the pathnames.
77 * Revision 1.12 2001/06/05 20:04:09 jongfoster
78 * Now uses _snprintf() in place of snprintf() under Win32.
80 * Revision 1.11 2001/06/04 18:31:58 swa
81 * files are now prefixed with either `confdir' or `logdir'.
82 * `make redhat-dist' replaces both entries confdir and logdir
85 * Revision 1.10 2001/06/03 19:11:54 oes
86 * introduced confdir option
88 * Revision 1.9 2001/06/01 20:06:24 jongfoster
89 * Removed support for "tinygif" option - moved to actions file.
91 * Revision 1.8 2001/05/31 21:27:13 jongfoster
92 * Removed many options from the config file and into the
93 * "actions" file: add_forwarded, suppress_vanilla_wafer,
94 * wafer, add_header, user_agent, referer, from
95 * Also globally replaced "permission" with "action".
97 * Revision 1.7 2001/05/29 09:50:24 jongfoster
98 * Unified blocklist/imagelist/permissionslist.
99 * File format is still under discussion, but the internal changes
102 * Also modified interceptor behaviour:
103 * - We now intercept all URLs beginning with one of the following
104 * prefixes (and *only* these prefixes):
106 * * http://ijbswa.sf.net/config/
107 * * http://ijbswa.sourceforge.net/config/
108 * - New interceptors "home page" - go to http://i.j.b/ to see it.
109 * - Internal changes so that intercepted and fast redirect pages
110 * are not replaced with an image.
111 * - Interceptors now have the option to send a binary page direct
112 * to the client. (i.e. ijb-send-banner uses this)
113 * - Implemented show-url-info interceptor. (Which is why I needed
114 * the above interceptors changes - a typical URL is
115 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
116 * The previous mechanism would not have intercepted that, and
117 * if it had been intercepted then it then it would have replaced
120 * Revision 1.6 2001/05/26 00:28:36 jongfoster
121 * Automatic reloading of config file.
122 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
123 * Most of the global variables have been moved to a new
124 * struct configuration_spec, accessed through csp->config->globalname
125 * Most of the globals remaining are used by the Win32 GUI.
127 * Revision 1.5 2001/05/25 22:34:30 jongfoster
130 * Revision 1.4 2001/05/22 18:46:04 oes
132 * - Enabled filtering banners by size rather than URL
133 * by adding patterns that replace all standard banner
134 * sizes with the "Junkbuster" gif to the re_filterfile
136 * - Enabled filtering WebBugs by providing a pattern
137 * which kills all 1x1 images
139 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
140 * which is selected by the (nonstandard and therefore
141 * capital) letter 'U' in the option string.
142 * It causes the quantifiers to be ungreedy by default.
143 * Appending a ? turns back to greedy (!).
145 * - Added a new interceptor ijb-send-banner, which
146 * sends back the "Junkbuster" gif. Without imagelist or
147 * MSIE detection support, or if tinygif = 1, or the
148 * URL isn't recognized as an imageurl, a lame HTML
149 * explanation is sent instead.
151 * - Added new feature, which permits blocking remote
152 * script redirects and firing back a local redirect
154 * The feature is conditionally compiled, i.e. it
155 * can be disabled with --disable-fast-redirects,
156 * plus it must be activated by a "fast-redirects"
157 * line in the config file, has its own log level
158 * and of course wants to be displayed by show-proxy-args
159 * Note: Boy, all the #ifdefs in 1001 locations and
160 * all the fumbling with configure.in and acconfig.h
161 * were *way* more work than the feature itself :-(
163 * - Because a generic redirect template was needed for
164 * this, tinygif = 3 now uses the same.
166 * - Moved GIFs, and other static HTTP response templates
171 * - Removed some >400 CRs again (Jon, you really worked
174 * Revision 1.3 2001/05/20 01:21:20 jongfoster
175 * Version 2.9.4 checkin.
176 * - Merged popupfile and cookiefile, and added control over PCRS
177 * filtering, in new "permissionsfile".
178 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
179 * file error you now get a message box (in the Win32 GUI) rather
180 * than the program exiting with no explanation.
181 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
183 * - Removed tabs from "config"
184 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
185 * - Bumped up version number.
187 * Revision 1.2 2001/05/17 23:01:01 oes
188 * - Cleaned CRLF's from the sources and related files
190 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
191 * Initial import of version 2.9.3 source tree
194 *********************************************************************/
200 #include <sys/types.h>
210 # include <windows.h>
213 # ifndef _WIN_CONSOLE
215 # endif /* ndef _WIN_CONSOLE */
217 /* VC++ has "_snprintf", not "snprintf" */
218 #define snprintf _snprintf
220 #else /* ifndef _WIN32 */
223 # include <sys/time.h>
224 # include <sys/wait.h>
225 # include <sys/stat.h>
235 #include "miscutil.h"
240 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
243 * Fix a problem with Solaris. There should be no effect on other
245 * Solaris's isspace() is a macro which uses it's argument directly
246 * as an array index. Therefore we need to make sure that high-bit
247 * characters generate +ve values, and ideally we also want to make
248 * the argument match the declared parameter type of "int".
250 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
251 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
253 #ifdef FEATURE_TOGGLE
254 /* by haroon - indicates if ijb is enabled */
255 int g_bToggleIJB = 1; /* JunkBusters is enabled by default. */
256 #endif /* def FEATURE_TOGGLE */
258 /* The filename of the configfile */
259 const char *configfile = NULL;
262 * CGI functions will later need access to the invocation args,
263 * so we will make argc and argv global.
266 const char **Argv = NULL;
268 static struct file_list *current_configfile = NULL;
272 * This takes the "cryptic" hash of each keyword and aliases them to
273 * something a little more readable. This also makes changing the
274 * hash values easier if they should change or the hash algorthm changes.
275 * Use the included "hash" program to find out what the hash will be
276 * for any string supplied on the command line. (Or just put it in the
277 * config file and read the number from the error message in the log).
279 * Please keep this list sorted alphabetically (but with the Windows
280 * console and GUI specific options last).
283 #define hash_actions_file 1196306641ul /* "actionsfile" */
284 #define hash_admin_address 4112573064ul /* "admin-address" */
285 #define hash_confdir 1978389ul /* "confdir" */
286 #define hash_debug 78263ul /* "debug" */
287 #define hash_deny_access 1227333715ul /* "deny-access" */
288 #define hash_forward 2029845ul /* "forward" */
289 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
290 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
291 #define hash_jarfile 2046641ul /* "jarfile" */
292 #define hash_listen_address 1255650842ul /* "listen-address" */
293 #define hash_logdir 422889ul /* "logdir" */
294 #define hash_logfile 2114766ul /* "logfile" */
295 #define hash_permit_access 3587953268ul /* "permit-access" */
296 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
297 #define hash_re_filterfile 3877522444ul /* "re_filterfile" */
298 #define hash_single_threaded 4250084780ul /* "single-threaded" */
299 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
300 #define hash_toggle 447966ul /* "toggle" */
301 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
302 #define hash_trustfile 56494766ul /* "trustfile" */
304 #define hash_activity_animation 1817904738ul /* "activity-animation" */
305 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
306 #define hash_hide_console 2048809870ul /* "hide-console" */
307 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
308 #define hash_log_font_name 2866730124ul /* "log-font-name" */
309 #define hash_log_font_size 2866731014ul /* "log-font-size" */
310 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
311 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
312 #define hash_log_messages 2291744899ul /* "log-messages" */
313 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
316 static void savearg(char *c, char *o, struct configuration_spec * config);
319 /*********************************************************************
321 * Function : unload_configfile
323 * Description : Free the config structure and all components.
326 * 1 : data: struct configuration_spec to unload
330 *********************************************************************/
331 void unload_configfile (void * data)
333 struct configuration_spec * config = (struct configuration_spec *)data;
334 struct forward_spec *cur_fwd = config->forward;
336 struct access_control_list *cur_acl = config->acl;
338 while (cur_acl != NULL)
340 struct access_control_list * next_acl = cur_acl->next;
345 #endif /* def FEATURE_ACL */
347 while (cur_fwd != NULL)
349 struct forward_spec * next_fwd = cur_fwd->next;
350 free_url(cur_fwd->url);
352 freez(cur_fwd->gateway_host);
353 freez(cur_fwd->forward_host);
357 config->forward = NULL;
359 #ifdef FEATURE_COOKIE_JAR
360 if ( NULL != config->jar )
362 fclose( config->jar );
365 #endif /* def FEATURE_COOKIE_JAR */
367 freez((char *)config->confdir);
368 freez((char *)config->logdir);
370 freez((char *)config->haddr);
371 freez((char *)config->logfile);
373 freez((char *)config->actions_file);
374 freez((char *)config->admin_address);
375 freez((char *)config->proxy_info_url);
376 freez((char *)config->proxy_args);
378 #ifdef FEATURE_COOKIE_JAR
379 freez((char *)config->jarfile);
380 #endif /* def FEATURE_COOKIE_JAR */
382 freez((char *)config->re_filterfile);
387 /*********************************************************************
389 * Function : load_config
391 * Description : Load the config file and all parameters.
394 * 1 : csp = Client state (the config member will be
395 * filled in by this function).
397 * Returns : 0 => Ok, everything else is an error.
399 *********************************************************************/
400 struct configuration_spec * load_config(void)
402 char buf[BUFFER_SIZE];
404 FILE *configfp = NULL;
405 struct configuration_spec * config = NULL;
406 struct client_state * fake_csp;
407 struct file_list *fs;
409 if (!check_file_changed(current_configfile, configfile, &fs))
411 /* No need to load */
412 return ((struct configuration_spec *)current_configfile->f);
416 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
420 log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
422 #ifdef FEATURE_TOGGLE
424 #endif /* def FEATURE_TOGGLE */
426 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
432 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
433 /* Never get here - LOG_LEVEL_FATAL causes program exit */
437 * This is backwards from how it's usually done.
438 * Following the usual pattern, "fs" would be stored in a member
439 * variable in "csp", and then we'd access "config" from "fs->f",
440 * using a cast. However, "config" is used so often that a
441 * cast each time would be very ugly, and the extra indirection
442 * would waste CPU cycles. Therefore we store "config" in
443 * "csp->config", and "fs" in "csp->config->config_file_list".
445 config->config_file_list = fs;
451 config->multi_threaded = 1;
452 config->hport = HADDR_PORT;
454 if ((configfp = fopen(configfile, "r")) == NULL)
456 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
458 /* Never get here - LOG_LEVEL_FATAL causes program exit */
461 while (read_config_line(buf, sizeof(buf), configfp, fs) != NULL)
463 char cmd[BUFFER_SIZE];
464 char arg[BUFFER_SIZE];
465 char tmp[BUFFER_SIZE];
467 struct access_control_list *cur_acl;
468 #endif /* def FEATURE_ACL */
469 struct forward_spec *cur_fwd;
475 /* Copy command (i.e. up to space or tab) into cmd */
478 while (*p && (*p != ' ') && (*p != '\t'))
484 /* Skip over the whitespace in buf */
485 while (*p && ((*p == ' ') || (*p == '\t')))
490 /* Copy the argument into arg */
493 /* Should never happen, but check this anyway */
499 /* Make sure the command field is lower case */
504 *p = ijb_tolower(*p);
508 /* Save the argument for show-proxy-args */
509 savearg(cmd, arg, config);
512 switch( hash_string( cmd ) )
514 /****************************************************************************
515 * actionsfile actions-file-name
516 * In confdir by default
517 ****************************************************************************/
518 case hash_actions_file :
519 freez((char *)config->actions_file);
520 config->actions_file = make_path(config->confdir, arg);
523 /****************************************************************************
524 * admin-address email-address
525 ****************************************************************************/
526 case hash_admin_address :
527 freez((char *)config->admin_address);
528 config->admin_address = strdup(arg);
531 /****************************************************************************
532 * confdir directory-name
533 ****************************************************************************/
535 freez((char *)config->confdir);
536 config->confdir = strdup(arg);
539 /****************************************************************************
541 * Specifies debug level, multiple values are ORed together.
542 ****************************************************************************/
544 config->debug |= atoi(arg);
547 /****************************************************************************
548 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
549 ****************************************************************************/
551 case hash_deny_access:
552 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
554 if ((vec_count != 1) && (vec_count != 2))
556 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
557 "deny-access directive in configuration file.");
558 config->proxy_args = strsav( config->proxy_args,
559 "<br>\nWARNING: Wrong number of parameters for "
560 "deny-access directive in configuration file.<br><br>\n");
564 /* allocate a new node */
565 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
569 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
570 /* Never get here - LOG_LEVEL_FATAL causes program exit */
573 cur_acl->action = ACL_DENY;
575 if (acl_addr(vec[0], cur_acl->src) < 0)
577 log_error(LOG_LEVEL_ERROR, "Invalid source IP for deny-access "
578 "directive in configuration file: \"%s\"", vec[0]);
579 config->proxy_args = strsav( config->proxy_args,
580 "<br>\nWARNING: Invalid source IP for deny-access directive"
581 " in configuration file: \"");
582 config->proxy_args = strsav( config->proxy_args,
584 config->proxy_args = strsav( config->proxy_args,
591 if (acl_addr(vec[1], cur_acl->dst) < 0)
593 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for deny-access "
594 "directive in configuration file: \"%s\"", vec[0]);
595 config->proxy_args = strsav( config->proxy_args,
596 "<br>\nWARNING: Invalid destination 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,
608 * Add it to the list. Note we reverse the list to get the
609 * behaviour the user expects. With both the ACL and
610 * actions file, the last match wins. However, the internal
611 * implementations are different: The actions file is stored
612 * in the same order as the file, and scanned completely.
613 * With the ACL, we reverse the order as we load it, then
614 * when we scan it we stop as soon as we get a match.
616 cur_acl->next = config->acl;
617 config->acl = cur_acl;
620 #endif /* def FEATURE_ACL */
622 /****************************************************************************
623 * forward url-pattern (.|http-proxy-host[:port])
624 ****************************************************************************/
626 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
630 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
631 "directive in configuration file.");
632 config->proxy_args = strsav( config->proxy_args,
633 "<br>\nWARNING: Wrong number of parameters for "
634 "forward directive in configuration file.");
638 /* allocate a new node */
639 cur_fwd = zalloc(sizeof(*cur_fwd));
642 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
643 /* Never get here - LOG_LEVEL_FATAL causes program exit */
647 cur_fwd->type = SOCKS_NONE;
649 /* Save the URL pattern */
650 if (create_url_spec(cur_fwd->url, vec[0]))
652 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
653 "directive in configuration file.");
654 config->proxy_args = strsav( config->proxy_args,
655 "<br>\nWARNING: Bad URL specifier for "
656 "forward directive in configuration file.");
660 /* Parse the parent HTTP proxy host:port */
663 if (strcmp(p, ".") != 0)
665 cur_fwd->forward_host = strdup(p);
667 if ((p = strchr(cur_fwd->forward_host, ':')))
670 cur_fwd->forward_port = atoi(p);
673 if (cur_fwd->forward_port <= 0)
675 cur_fwd->forward_port = 8000;
680 cur_fwd->next = config->forward;
681 config->forward = cur_fwd;
685 /****************************************************************************
686 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
687 ****************************************************************************/
688 case hash_forward_socks4:
689 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
693 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
694 "forward-socks4 directive in configuration file.");
695 config->proxy_args = strsav( config->proxy_args,
696 "<br>\nWARNING: Wrong number of parameters for "
697 "forward-socks4 directive in configuration file.");
701 /* allocate a new node */
702 cur_fwd = zalloc(sizeof(*cur_fwd));
705 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
706 /* Never get here - LOG_LEVEL_FATAL causes program exit */
710 cur_fwd->type = SOCKS_4;
712 /* Save the URL pattern */
713 if (create_url_spec(cur_fwd->url, vec[0]))
715 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
716 "directive in configuration file.");
717 config->proxy_args = strsav( config->proxy_args,
718 "<br>\nWARNING: Bad URL specifier for "
719 "forward-socks4 directive in configuration file.");
723 /* Parse the SOCKS proxy host[:port] */
726 if (strcmp(p, ".") != 0)
728 cur_fwd->gateway_host = strdup(p);
730 if ((p = strchr(cur_fwd->gateway_host, ':')))
733 cur_fwd->gateway_port = atoi(p);
735 if (cur_fwd->gateway_port <= 0)
737 cur_fwd->gateway_port = 1080;
741 /* Parse the parent HTTP proxy host[:port] */
744 if (strcmp(p, ".") != 0)
746 cur_fwd->forward_host = strdup(p);
748 if ((p = strchr(cur_fwd->forward_host, ':')))
751 cur_fwd->forward_port = atoi(p);
754 if (cur_fwd->forward_port <= 0)
756 cur_fwd->forward_port = 8000;
761 cur_fwd->next = config->forward;
762 config->forward = cur_fwd;
766 /****************************************************************************
767 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
768 ****************************************************************************/
769 case hash_forward_socks4a:
770 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
774 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
775 "forward-socks4a directive in configuration file.");
776 config->proxy_args = strsav( config->proxy_args,
777 "<br>\nWARNING: Wrong number of parameters for "
778 "forward-socks4a directive in configuration file.");
782 /* allocate a new node */
783 cur_fwd = zalloc(sizeof(*cur_fwd));
786 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
787 /* Never get here - LOG_LEVEL_FATAL causes program exit */
791 cur_fwd->type = SOCKS_4A;
793 /* Save the URL pattern */
794 if (create_url_spec(cur_fwd->url, vec[0]))
796 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
797 "directive in configuration file.");
798 config->proxy_args = strsav( config->proxy_args,
799 "<br>\nWARNING: Bad URL specifier for "
800 "forward-socks4a directive in configuration file.");
804 /* Parse the SOCKS proxy host[:port] */
807 cur_fwd->gateway_host = strdup(p);
809 if ((p = strchr(cur_fwd->gateway_host, ':')))
812 cur_fwd->gateway_port = atoi(p);
814 if (cur_fwd->gateway_port <= 0)
816 cur_fwd->gateway_port = 1080;
819 /* Parse the parent HTTP proxy host[:port] */
822 if (strcmp(p, ".") != 0)
824 cur_fwd->forward_host = strdup(p);
826 if ((p = strchr(cur_fwd->forward_host, ':')))
829 cur_fwd->forward_port = atoi(p);
832 if (cur_fwd->forward_port <= 0)
834 cur_fwd->forward_port = 8000;
839 cur_fwd->next = config->forward;
840 config->forward = cur_fwd;
844 /****************************************************************************
845 * jarfile jar-file-name
846 * In logdir by default
847 ****************************************************************************/
848 #ifdef FEATURE_COOKIE_JAR
850 freez((char *)config->jarfile);
851 config->jarfile = make_path(config->logdir, arg);
853 #endif /* def FEATURE_COOKIE_JAR */
855 /****************************************************************************
856 * listen-address [ip][:port]
857 ****************************************************************************/
858 case hash_listen_address :
859 freez((char *)config->haddr);
860 config->haddr = strdup(arg);
863 /****************************************************************************
864 * logdir directory-name
865 ****************************************************************************/
867 freez((char *)config->logdir);
868 config->logdir = strdup(arg);
871 /****************************************************************************
872 * logfile log-file-name
873 * In logdir by default
874 ****************************************************************************/
876 freez((char *)config->logfile);
877 config->logfile = make_path(config->logdir, arg);
880 /****************************************************************************
881 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
882 ****************************************************************************/
884 case hash_permit_access:
885 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
887 if ((vec_count != 1) && (vec_count != 2))
889 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
890 "permit-access directive in configuration file.");
891 config->proxy_args = strsav( config->proxy_args,
892 "<br>\nWARNING: Wrong number of parameters for "
893 "permit-access directive in configuration file.<br><br>\n");
898 /* allocate a new node */
899 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
903 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
904 /* Never get here - LOG_LEVEL_FATAL causes program exit */
907 cur_acl->action = ACL_PERMIT;
909 if (acl_addr(vec[0], cur_acl->src) < 0)
911 log_error(LOG_LEVEL_ERROR, "Invalid source IP for permit-access "
912 "directive in configuration file: \"%s\"", vec[0]);
913 config->proxy_args = strsav( config->proxy_args,
914 "<br>\nWARNING: Invalid source IP for permit-access directive"
915 " in configuration file: \"");
916 config->proxy_args = strsav( config->proxy_args,
918 config->proxy_args = strsav( config->proxy_args,
925 if (acl_addr(vec[1], cur_acl->dst) < 0)
927 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for "
928 "permit-access directive in configuration file: \"%s\"",
930 config->proxy_args = strsav( config->proxy_args,
931 "<br>\nWARNING: Invalid destination IP for permit-access directive"
932 " in configuration file: \"");
933 config->proxy_args = strsav( config->proxy_args,
935 config->proxy_args = strsav( config->proxy_args,
943 * Add it to the list. Note we reverse the list to get the
944 * behaviour the user expects. With both the ACL and
945 * actions file, the last match wins. However, the internal
946 * implementations are different: The actions file is stored
947 * in the same order as the file, and scanned completely.
948 * With the ACL, we reverse the order as we load it, then
949 * when we scan it we stop as soon as we get a match.
951 cur_acl->next = config->acl;
952 config->acl = cur_acl;
955 #endif /* def FEATURE_ACL */
957 /****************************************************************************
959 ****************************************************************************/
960 case hash_proxy_info_url :
961 freez((char *)config->proxy_info_url);
962 config->proxy_info_url = strdup(arg);
965 /****************************************************************************
966 * re_filterfile file-name
967 * In confdir by default.
968 ****************************************************************************/
969 case hash_re_filterfile :
970 freez((char *)config->re_filterfile);
971 config->re_filterfile = make_path(config->confdir, arg);
974 /****************************************************************************
976 ****************************************************************************/
977 case hash_single_threaded :
978 config->multi_threaded = 0;
981 /****************************************************************************
983 ****************************************************************************/
984 #ifdef FEATURE_TOGGLE
986 g_bToggleIJB = atoi(arg);
988 #endif /* def FEATURE_TOGGLE */
990 /****************************************************************************
992 ****************************************************************************/
994 case hash_trust_info_url :
995 enlist(config->trust_info, arg);
997 #endif /* def FEATURE_TRUST */
999 /****************************************************************************
1000 * trustfile filename
1001 * (In confdir by default.)
1002 ****************************************************************************/
1003 #ifdef FEATURE_TRUST
1004 case hash_trustfile :
1005 freez((char *)config->trustfile);
1006 config->trustfile = make_path(config->confdir, arg);
1008 #endif /* def FEATURE_TRUST */
1011 /****************************************************************************
1012 * Win32 Console options:
1013 ****************************************************************************/
1015 /****************************************************************************
1017 ****************************************************************************/
1019 case hash_hide_console :
1022 #endif /*def _WIN_CONSOLE*/
1025 /****************************************************************************
1026 * Win32 GUI options:
1027 ****************************************************************************/
1029 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1030 /****************************************************************************
1031 * activity-animation (0|1)
1032 ****************************************************************************/
1033 case hash_activity_animation :
1034 g_bShowActivityAnimation = atoi(arg);
1037 /****************************************************************************
1038 * close-button-minimizes (0|1)
1039 ****************************************************************************/
1040 case hash_close_button_minimizes :
1041 g_bCloseHidesWindow = atoi(arg);
1044 /****************************************************************************
1045 * log-buffer-size (0|1)
1046 ****************************************************************************/
1047 case hash_log_buffer_size :
1048 g_bLimitBufferSize = atoi(arg);
1051 /****************************************************************************
1052 * log-font-name fontnane
1053 ****************************************************************************/
1054 case hash_log_font_name :
1055 strcpy( g_szFontFaceName, arg );
1058 /****************************************************************************
1060 ****************************************************************************/
1061 case hash_log_font_size :
1062 g_nFontSize = atoi(arg);
1065 /****************************************************************************
1066 * log-highlight-messages (0|1)
1067 ****************************************************************************/
1068 case hash_log_highlight_messages :
1069 g_bHighlightMessages = atoi(arg);
1072 /****************************************************************************
1074 ****************************************************************************/
1075 case hash_log_max_lines :
1076 g_nMaxBufferLines = atoi(arg);
1079 /****************************************************************************
1080 * log-messages (0|1)
1081 ****************************************************************************/
1082 case hash_log_messages :
1083 g_bLogMessages = atoi(arg);
1086 /****************************************************************************
1087 * show-on-task-bar (0|1)
1088 ****************************************************************************/
1089 case hash_show_on_task_bar :
1090 g_bShowOnTaskBar = atoi(arg);
1093 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1096 /****************************************************************************/
1097 /* Warnings about unsupported features */
1098 /****************************************************************************/
1100 case hash_deny_access:
1101 #endif /* ndef FEATURE_ACL */
1102 #ifndef FEATURE_COOKIE_JAR
1104 #endif /* ndef FEATURE_COOKIE_JAR */
1106 case hash_permit_access:
1107 #endif /* ndef FEATURE_ACL */
1108 #ifndef FEATURE_TOGGLE
1110 #endif /* ndef FEATURE_TOGGLE */
1111 #ifndef FEATURE_TRUST
1112 case hash_trustfile :
1113 case hash_trust_info_url :
1114 #endif /* ndef FEATURE_TRUST */
1116 #ifndef _WIN_CONSOLE
1117 case hash_hide_console :
1118 #endif /* ndef _WIN_CONSOLE */
1120 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1121 case hash_activity_animation :
1122 case hash_close_button_minimizes :
1123 case hash_log_buffer_size :
1124 case hash_log_font_name :
1125 case hash_log_font_size :
1126 case hash_log_highlight_messages :
1127 case hash_log_max_lines :
1128 case hash_log_messages :
1129 case hash_show_on_task_bar :
1130 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1131 /* These warnings are annoying - so hide them. -- Jon */
1132 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1135 /****************************************************************************/
1137 /****************************************************************************/
1139 * I decided that I liked this better as a warning than an
1140 * error. To change back to an error, just change log level
1141 * to LOG_LEVEL_FATAL.
1143 log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%luul) in "
1144 "configuration file: \"%s\"", hash_string( cmd ), buf);
1145 config->proxy_args = strsav( config->proxy_args, "<br>\nWARNING: unrecognized directive : ");
1146 config->proxy_args = strsav( config->proxy_args, buf);
1147 config->proxy_args = strsav( config->proxy_args, "<br><br>\n");
1150 /****************************************************************************/
1151 } /* end switch( hash_string(cmd) ) */
1152 } /* end while ( read_config_line(...) ) */
1156 init_error_log(Argv[0], config->logfile, config->debug);
1158 if (config->actions_file)
1160 add_loader(load_actions_file, config);
1163 if (config->re_filterfile)
1165 add_loader(load_re_filterfile, config);
1168 #ifdef FEATURE_TRUST
1169 if (config->trustfile)
1171 add_loader(load_trustfile, config);
1173 #endif /* def FEATURE_TRUST */
1175 #ifdef FEATURE_COOKIE_JAR
1176 if ( NULL != config->jarfile )
1178 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1180 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1181 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1183 setbuf(config->jar, NULL);
1185 #endif /* def FEATURE_COOKIE_JAR */
1187 if ( NULL == config->haddr )
1189 config->haddr = strdup( HADDR_DEFAULT );
1192 if ( NULL != config->haddr )
1194 if ((p = strchr(config->haddr, ':')))
1199 config->hport = atoi(p);
1203 if (config->hport <= 0)
1206 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1207 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1209 if (*config->haddr == '\0')
1211 config->haddr = NULL;
1216 * Want to run all the loaders once now.
1218 * Need to set up a fake csp, so they can get to the config.
1220 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1221 fake_csp->config = config;
1223 if (run_loader(fake_csp))
1226 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1227 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1231 /* FIXME: this is a kludge for win32 */
1232 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1234 g_actions_file = config->actions_file;
1235 g_re_filterfile = config->re_filterfile;
1237 #ifdef FEATURE_TRUST
1238 g_trustfile = config->trustfile;
1239 #endif /* def FEATURE_TRUST */
1242 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1243 /* FIXME: end kludge */
1246 config->need_bind = 1;
1248 if (current_configfile)
1250 struct configuration_spec * oldcfg = (struct configuration_spec *)
1251 current_configfile->f;
1253 * Check if config->haddr,hport == oldcfg->haddr,hport
1255 * The following could be written more compactly as a single,
1256 * (unreadably long) if statement.
1258 config->need_bind = 0;
1259 if (config->hport != oldcfg->hport)
1261 config->need_bind = 1;
1263 else if (config->haddr == NULL)
1265 if (oldcfg->haddr != NULL)
1267 config->need_bind = 1;
1270 else if (oldcfg->haddr == NULL)
1272 config->need_bind = 1;
1274 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1276 config->need_bind = 1;
1279 current_configfile->unloader = unload_configfile;
1282 fs->next = files->next;
1285 current_configfile = fs;
1291 /*********************************************************************
1293 * Function : savearg
1295 * Description : Called from `load_config'. It saves each non-empty
1296 * and non-comment line from config into a list. This
1297 * list is used to create the show-proxy-args page.
1300 * 1 : c = config setting that was found
1301 * 2 : o = the setting's argument (if any)
1305 *********************************************************************/
1306 static void savearg(char *c, char *o, struct configuration_spec * config)
1308 char buf[BUFFER_SIZE];
1312 if ( ( NULL != c ) && ( '\0' != *c ) )
1314 if ((c = html_encode(c)))
1316 sprintf(buf, "<a href=\"" REDIRECT_URL "option#%s\">%s</a> ", c, c);
1320 if ( ( NULL != o ) && ( '\0' != *o ) )
1322 if ((o = html_encode(o)))
1324 if (strncmpic(o, "http://", 7) == 0)
1326 strcat(buf, "<a href=\"");
1330 strcat(buf, "</a>");
1340 strcat(buf, "<br>\n");
1342 config->proxy_args = strsav(config->proxy_args, buf);