1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.24 2001/10/23 21:40:30 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.24 2001/10/23 21:40:30 jongfoster
39 * Added support for enable-edit-actions and enable-remote-toggle config
42 * Revision 1.23 2001/10/07 15:36:00 oes
43 * Introduced new config option "buffer-limit"
45 * Revision 1.22 2001/09/22 16:36:59 jongfoster
46 * Removing unused parameter fs from read_config_line()
48 * Revision 1.21 2001/09/16 17:10:43 jongfoster
49 * Moving function savearg() here, since it was the only thing left in
52 * Revision 1.20 2001/07/30 22:08:36 jongfoster
53 * Tidying up #defines:
54 * - All feature #defines are now of the form FEATURE_xxx
55 * - Permanently turned off WIN_GUI_EDIT
56 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
58 * Revision 1.19 2001/07/15 17:45:16 jongfoster
59 * Removing some unused #includes
61 * Revision 1.18 2001/07/13 14:01:14 oes
62 * - Removed all #ifdef PCRS
63 * - Removed vim-settings
65 * Revision 1.17 2001/06/29 13:31:03 oes
67 * - Fixed (actionsfile) and sorted hashes
68 * - Introduced admin_address and proxy-info-url
69 * as config parameters
70 * - Renamed config->proxy_args_invocation (which didn't have
71 * the invocation but the options!) to config->proxy_args
73 * - Removed logentry from cancelled commit
75 * Revision 1.16 2001/06/09 10:55:28 jongfoster
76 * Changing BUFSIZ ==> BUFFER_SIZE
78 * Revision 1.15 2001/06/07 23:13:40 jongfoster
79 * Merging ACL and forward files into config file.
80 * Cosmetic: Sorting config file options alphabetically.
81 * Cosmetic: Adding brief syntax comments to config file options.
83 * Revision 1.14 2001/06/07 14:46:25 joergs
84 * Missing make_path() added for re_filterfile.
86 * Revision 1.13 2001/06/05 22:33:54 jongfoster
88 * Fixed minor memory leak.
89 * Also now uses make_path to prepend the pathnames.
91 * Revision 1.12 2001/06/05 20:04:09 jongfoster
92 * Now uses _snprintf() in place of snprintf() under Win32.
94 * Revision 1.11 2001/06/04 18:31:58 swa
95 * files are now prefixed with either `confdir' or `logdir'.
96 * `make redhat-dist' replaces both entries confdir and logdir
99 * Revision 1.10 2001/06/03 19:11:54 oes
100 * introduced confdir option
102 * Revision 1.9 2001/06/01 20:06:24 jongfoster
103 * Removed support for "tinygif" option - moved to actions file.
105 * Revision 1.8 2001/05/31 21:27:13 jongfoster
106 * Removed many options from the config file and into the
107 * "actions" file: add_forwarded, suppress_vanilla_wafer,
108 * wafer, add_header, user_agent, referer, from
109 * Also globally replaced "permission" with "action".
111 * Revision 1.7 2001/05/29 09:50:24 jongfoster
112 * Unified blocklist/imagelist/permissionslist.
113 * File format is still under discussion, but the internal changes
116 * Also modified interceptor behaviour:
117 * - We now intercept all URLs beginning with one of the following
118 * prefixes (and *only* these prefixes):
120 * * http://ijbswa.sf.net/config/
121 * * http://ijbswa.sourceforge.net/config/
122 * - New interceptors "home page" - go to http://i.j.b/ to see it.
123 * - Internal changes so that intercepted and fast redirect pages
124 * are not replaced with an image.
125 * - Interceptors now have the option to send a binary page direct
126 * to the client. (i.e. ijb-send-banner uses this)
127 * - Implemented show-url-info interceptor. (Which is why I needed
128 * the above interceptors changes - a typical URL is
129 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
130 * The previous mechanism would not have intercepted that, and
131 * if it had been intercepted then it then it would have replaced
134 * Revision 1.6 2001/05/26 00:28:36 jongfoster
135 * Automatic reloading of config file.
136 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
137 * Most of the global variables have been moved to a new
138 * struct configuration_spec, accessed through csp->config->globalname
139 * Most of the globals remaining are used by the Win32 GUI.
141 * Revision 1.5 2001/05/25 22:34:30 jongfoster
144 * Revision 1.4 2001/05/22 18:46:04 oes
146 * - Enabled filtering banners by size rather than URL
147 * by adding patterns that replace all standard banner
148 * sizes with the "Junkbuster" gif to the re_filterfile
150 * - Enabled filtering WebBugs by providing a pattern
151 * which kills all 1x1 images
153 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
154 * which is selected by the (nonstandard and therefore
155 * capital) letter 'U' in the option string.
156 * It causes the quantifiers to be ungreedy by default.
157 * Appending a ? turns back to greedy (!).
159 * - Added a new interceptor ijb-send-banner, which
160 * sends back the "Junkbuster" gif. Without imagelist or
161 * MSIE detection support, or if tinygif = 1, or the
162 * URL isn't recognized as an imageurl, a lame HTML
163 * explanation is sent instead.
165 * - Added new feature, which permits blocking remote
166 * script redirects and firing back a local redirect
168 * The feature is conditionally compiled, i.e. it
169 * can be disabled with --disable-fast-redirects,
170 * plus it must be activated by a "fast-redirects"
171 * line in the config file, has its own log level
172 * and of course wants to be displayed by show-proxy-args
173 * Note: Boy, all the #ifdefs in 1001 locations and
174 * all the fumbling with configure.in and acconfig.h
175 * were *way* more work than the feature itself :-(
177 * - Because a generic redirect template was needed for
178 * this, tinygif = 3 now uses the same.
180 * - Moved GIFs, and other static HTTP response templates
185 * - Removed some >400 CRs again (Jon, you really worked
188 * Revision 1.3 2001/05/20 01:21:20 jongfoster
189 * Version 2.9.4 checkin.
190 * - Merged popupfile and cookiefile, and added control over PCRS
191 * filtering, in new "permissionsfile".
192 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
193 * file error you now get a message box (in the Win32 GUI) rather
194 * than the program exiting with no explanation.
195 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
197 * - Removed tabs from "config"
198 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
199 * - Bumped up version number.
201 * Revision 1.2 2001/05/17 23:01:01 oes
202 * - Cleaned CRLF's from the sources and related files
204 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
205 * Initial import of version 2.9.3 source tree
208 *********************************************************************/
214 #include <sys/types.h>
224 # include <windows.h>
227 # ifndef _WIN_CONSOLE
229 # endif /* ndef _WIN_CONSOLE */
231 /* VC++ has "_snprintf", not "snprintf" */
232 #define snprintf _snprintf
234 #else /* ifndef _WIN32 */
238 # include <sys/wait.h>
240 # include <sys/time.h>
241 # include <sys/stat.h>
251 #include "miscutil.h"
256 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
259 * Fix a problem with Solaris. There should be no effect on other
261 * Solaris's isspace() is a macro which uses it's argument directly
262 * as an array index. Therefore we need to make sure that high-bit
263 * characters generate +ve values, and ideally we also want to make
264 * the argument match the declared parameter type of "int".
266 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
267 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
269 #ifdef FEATURE_TOGGLE
270 /* by haroon - indicates if ijb is enabled */
271 int g_bToggleIJB = 1; /* JunkBusters is enabled by default. */
272 #endif /* def FEATURE_TOGGLE */
274 /* The filename of the configfile */
275 const char *configfile = NULL;
278 * CGI functions will later need access to the invocation args,
279 * so we will make argc and argv global.
282 const char **Argv = NULL;
284 static struct file_list *current_configfile = NULL;
288 * This takes the "cryptic" hash of each keyword and aliases them to
289 * something a little more readable. This also makes changing the
290 * hash values easier if they should change or the hash algorthm changes.
291 * Use the included "hash" program to find out what the hash will be
292 * for any string supplied on the command line. (Or just put it in the
293 * config file and read the number from the error message in the log).
295 * Please keep this list sorted alphabetically (but with the Windows
296 * console and GUI specific options last).
299 #define hash_actions_file 1196306641ul /* "actionsfile" */
300 #define hash_admin_address 4112573064ul /* "admin-address" */
301 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
302 #define hash_confdir 1978389ul /* "confdir" */
303 #define hash_debug 78263ul /* "debug" */
304 #define hash_deny_access 1227333715ul /* "deny-access" */
305 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
306 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
307 #define hash_forward 2029845ul /* "forward" */
308 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
309 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
310 #define hash_jarfile 2046641ul /* "jarfile" */
311 #define hash_listen_address 1255650842ul /* "listen-address" */
312 #define hash_logdir 422889ul /* "logdir" */
313 #define hash_logfile 2114766ul /* "logfile" */
314 #define hash_permit_access 3587953268ul /* "permit-access" */
315 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
316 #define hash_re_filterfile 3877522444ul /* "re_filterfile" */
317 #define hash_single_threaded 4250084780ul /* "single-threaded" */
318 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
319 #define hash_toggle 447966ul /* "toggle" */
320 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
321 #define hash_trustfile 56494766ul /* "trustfile" */
323 #define hash_activity_animation 1817904738ul /* "activity-animation" */
324 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
325 #define hash_hide_console 2048809870ul /* "hide-console" */
326 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
327 #define hash_log_font_name 2866730124ul /* "log-font-name" */
328 #define hash_log_font_size 2866731014ul /* "log-font-size" */
329 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
330 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
331 #define hash_log_messages 2291744899ul /* "log-messages" */
332 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
335 static void savearg(char *c, char *o, struct configuration_spec * config);
338 /*********************************************************************
340 * Function : unload_configfile
342 * Description : Free the config structure and all components.
345 * 1 : data: struct configuration_spec to unload
349 *********************************************************************/
350 void unload_configfile (void * data)
352 struct configuration_spec * config = (struct configuration_spec *)data;
353 struct forward_spec *cur_fwd = config->forward;
355 struct access_control_list *cur_acl = config->acl;
357 while (cur_acl != NULL)
359 struct access_control_list * next_acl = cur_acl->next;
364 #endif /* def FEATURE_ACL */
366 while (cur_fwd != NULL)
368 struct forward_spec * next_fwd = cur_fwd->next;
369 free_url(cur_fwd->url);
371 freez(cur_fwd->gateway_host);
372 freez(cur_fwd->forward_host);
376 config->forward = NULL;
378 #ifdef FEATURE_COOKIE_JAR
379 if ( NULL != config->jar )
381 fclose( config->jar );
384 #endif /* def FEATURE_COOKIE_JAR */
386 freez(config->confdir);
387 freez(config->logdir);
389 freez(config->haddr);
390 freez(config->logfile);
392 freez(config->actions_file);
393 freez(config->admin_address);
394 freez(config->proxy_info_url);
395 freez(config->proxy_args);
397 #ifdef FEATURE_COOKIE_JAR
398 freez(config->jarfile);
399 #endif /* def FEATURE_COOKIE_JAR */
401 freez(config->re_filterfile);
406 /*********************************************************************
408 * Function : load_config
410 * Description : Load the config file and all parameters.
413 * 1 : csp = Client state (the config member will be
414 * filled in by this function).
416 * Returns : 0 => Ok, everything else is an error.
418 *********************************************************************/
419 struct configuration_spec * load_config(void)
421 char buf[BUFFER_SIZE];
423 FILE *configfp = NULL;
424 struct configuration_spec * config = NULL;
425 struct client_state * fake_csp;
426 struct file_list *fs;
428 if (!check_file_changed(current_configfile, configfile, &fs))
430 /* No need to load */
431 return ((struct configuration_spec *)current_configfile->f);
435 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
439 log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
441 #ifdef FEATURE_TOGGLE
443 #endif /* def FEATURE_TOGGLE */
445 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
451 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
452 /* Never get here - LOG_LEVEL_FATAL causes program exit */
456 * This is backwards from how it's usually done.
457 * Following the usual pattern, "fs" would be stored in a member
458 * variable in "csp", and then we'd access "config" from "fs->f",
459 * using a cast. However, "config" is used so often that a
460 * cast each time would be very ugly, and the extra indirection
461 * would waste CPU cycles. Therefore we store "config" in
462 * "csp->config", and "fs" in "csp->config->config_file_list".
464 config->config_file_list = fs;
470 config->multi_threaded = 1;
471 config->hport = HADDR_PORT;
472 config->buffer_limit = 4096 * 1024;
474 if ((configfp = fopen(configfile, "r")) == NULL)
476 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
478 /* Never get here - LOG_LEVEL_FATAL causes program exit */
481 while (read_config_line(buf, sizeof(buf), configfp) != NULL)
483 char cmd[BUFFER_SIZE];
484 char arg[BUFFER_SIZE];
485 char tmp[BUFFER_SIZE];
487 struct access_control_list *cur_acl;
488 #endif /* def FEATURE_ACL */
489 struct forward_spec *cur_fwd;
495 /* Copy command (i.e. up to space or tab) into cmd */
498 while (*p && (*p != ' ') && (*p != '\t'))
504 /* Skip over the whitespace in buf */
505 while (*p && ((*p == ' ') || (*p == '\t')))
510 /* Copy the argument into arg */
513 /* Should never happen, but check this anyway */
519 /* Make sure the command field is lower case */
524 *p = ijb_tolower(*p);
528 /* Save the argument for show-proxy-args */
529 savearg(cmd, arg, config);
532 switch( hash_string( cmd ) )
534 /****************************************************************************
535 * actionsfile actions-file-name
536 * In confdir by default
537 ****************************************************************************/
538 case hash_actions_file :
539 freez(config->actions_file);
540 config->actions_file = make_path(config->confdir, arg);
543 /****************************************************************************
544 * admin-address email-address
545 ****************************************************************************/
546 case hash_admin_address :
547 freez(config->admin_address);
548 config->admin_address = strdup(arg);
551 /****************************************************************************
553 ****************************************************************************/
554 case hash_buffer_limit :
555 config->buffer_limit = (size_t) 1024 * atoi(arg);
558 /****************************************************************************
559 * confdir directory-name
560 ****************************************************************************/
562 freez(config->confdir);
563 config->confdir = strdup(arg);
566 /****************************************************************************
568 * Specifies debug level, multiple values are ORed together.
569 ****************************************************************************/
571 config->debug |= atoi(arg);
574 /****************************************************************************
575 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
576 ****************************************************************************/
578 case hash_deny_access:
579 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
581 if ((vec_count != 1) && (vec_count != 2))
583 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
584 "deny-access directive in configuration file.");
585 config->proxy_args = strsav( config->proxy_args,
586 "<br>\nWARNING: Wrong number of parameters for "
587 "deny-access directive in configuration file.<br><br>\n");
591 /* allocate a new node */
592 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
596 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
597 /* Never get here - LOG_LEVEL_FATAL causes program exit */
600 cur_acl->action = ACL_DENY;
602 if (acl_addr(vec[0], cur_acl->src) < 0)
604 log_error(LOG_LEVEL_ERROR, "Invalid source IP for deny-access "
605 "directive in configuration file: \"%s\"", vec[0]);
606 config->proxy_args = strsav( config->proxy_args,
607 "<br>\nWARNING: Invalid source IP for deny-access directive"
608 " in configuration file: \"");
609 config->proxy_args = strsav( config->proxy_args,
611 config->proxy_args = strsav( config->proxy_args,
618 if (acl_addr(vec[1], cur_acl->dst) < 0)
620 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for deny-access "
621 "directive in configuration file: \"%s\"", vec[0]);
622 config->proxy_args = strsav( config->proxy_args,
623 "<br>\nWARNING: Invalid destination IP for deny-access directive"
624 " in configuration file: \"");
625 config->proxy_args = strsav( config->proxy_args,
627 config->proxy_args = strsav( config->proxy_args,
635 * Add it to the list. Note we reverse the list to get the
636 * behaviour the user expects. With both the ACL and
637 * actions file, the last match wins. However, the internal
638 * implementations are different: The actions file is stored
639 * in the same order as the file, and scanned completely.
640 * With the ACL, we reverse the order as we load it, then
641 * when we scan it we stop as soon as we get a match.
643 cur_acl->next = config->acl;
644 config->acl = cur_acl;
647 #endif /* def FEATURE_ACL */
649 /****************************************************************************
650 * enable-edit-actions 0|1
651 ****************************************************************************/
652 #ifdef FEATURE_CGI_EDIT_ACTIONS
653 case hash_enable_edit_actions:
654 if ((*arg != '\0') && (0 != atoi(arg)))
656 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
660 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
663 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
665 /****************************************************************************
666 * enable-remote-toggle 0|1
667 ****************************************************************************/
668 #ifdef FEATURE_CGI_EDIT_ACTIONS
669 case hash_enable_remote_toggle:
670 if ((*arg != '\0') && (0 != atoi(arg)))
672 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
676 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
679 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
681 /****************************************************************************
682 * forward url-pattern (.|http-proxy-host[:port])
683 ****************************************************************************/
685 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
689 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
690 "directive in configuration file.");
691 config->proxy_args = strsav( config->proxy_args,
692 "<br>\nWARNING: Wrong number of parameters for "
693 "forward directive in configuration file.");
697 /* allocate a new node */
698 cur_fwd = zalloc(sizeof(*cur_fwd));
701 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
702 /* Never get here - LOG_LEVEL_FATAL causes program exit */
706 cur_fwd->type = SOCKS_NONE;
708 /* Save the URL pattern */
709 if (create_url_spec(cur_fwd->url, vec[0]))
711 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
712 "directive in configuration file.");
713 config->proxy_args = strsav( config->proxy_args,
714 "<br>\nWARNING: Bad URL specifier for "
715 "forward directive in configuration file.");
719 /* Parse the parent HTTP proxy host:port */
722 if (strcmp(p, ".") != 0)
724 cur_fwd->forward_host = strdup(p);
726 if ((p = strchr(cur_fwd->forward_host, ':')))
729 cur_fwd->forward_port = atoi(p);
732 if (cur_fwd->forward_port <= 0)
734 cur_fwd->forward_port = 8000;
739 cur_fwd->next = config->forward;
740 config->forward = cur_fwd;
744 /****************************************************************************
745 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
746 ****************************************************************************/
747 case hash_forward_socks4:
748 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
752 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
753 "forward-socks4 directive in configuration file.");
754 config->proxy_args = strsav( config->proxy_args,
755 "<br>\nWARNING: Wrong number of parameters for "
756 "forward-socks4 directive in configuration file.");
760 /* allocate a new node */
761 cur_fwd = zalloc(sizeof(*cur_fwd));
764 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
765 /* Never get here - LOG_LEVEL_FATAL causes program exit */
769 cur_fwd->type = SOCKS_4;
771 /* Save the URL pattern */
772 if (create_url_spec(cur_fwd->url, vec[0]))
774 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
775 "directive in configuration file.");
776 config->proxy_args = strsav( config->proxy_args,
777 "<br>\nWARNING: Bad URL specifier for "
778 "forward-socks4 directive in configuration file.");
782 /* Parse the SOCKS proxy host[:port] */
785 if (strcmp(p, ".") != 0)
787 cur_fwd->gateway_host = strdup(p);
789 if ((p = strchr(cur_fwd->gateway_host, ':')))
792 cur_fwd->gateway_port = atoi(p);
794 if (cur_fwd->gateway_port <= 0)
796 cur_fwd->gateway_port = 1080;
800 /* Parse the parent HTTP proxy host[:port] */
803 if (strcmp(p, ".") != 0)
805 cur_fwd->forward_host = strdup(p);
807 if ((p = strchr(cur_fwd->forward_host, ':')))
810 cur_fwd->forward_port = atoi(p);
813 if (cur_fwd->forward_port <= 0)
815 cur_fwd->forward_port = 8000;
820 cur_fwd->next = config->forward;
821 config->forward = cur_fwd;
825 /****************************************************************************
826 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
827 ****************************************************************************/
828 case hash_forward_socks4a:
829 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
833 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
834 "forward-socks4a directive in configuration file.");
835 config->proxy_args = strsav( config->proxy_args,
836 "<br>\nWARNING: Wrong number of parameters for "
837 "forward-socks4a directive in configuration file.");
841 /* allocate a new node */
842 cur_fwd = zalloc(sizeof(*cur_fwd));
845 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
846 /* Never get here - LOG_LEVEL_FATAL causes program exit */
850 cur_fwd->type = SOCKS_4A;
852 /* Save the URL pattern */
853 if (create_url_spec(cur_fwd->url, vec[0]))
855 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
856 "directive in configuration file.");
857 config->proxy_args = strsav( config->proxy_args,
858 "<br>\nWARNING: Bad URL specifier for "
859 "forward-socks4a directive in configuration file.");
863 /* Parse the SOCKS proxy host[:port] */
866 cur_fwd->gateway_host = strdup(p);
868 if ((p = strchr(cur_fwd->gateway_host, ':')))
871 cur_fwd->gateway_port = atoi(p);
873 if (cur_fwd->gateway_port <= 0)
875 cur_fwd->gateway_port = 1080;
878 /* Parse the parent HTTP proxy host[:port] */
881 if (strcmp(p, ".") != 0)
883 cur_fwd->forward_host = strdup(p);
885 if ((p = strchr(cur_fwd->forward_host, ':')))
888 cur_fwd->forward_port = atoi(p);
891 if (cur_fwd->forward_port <= 0)
893 cur_fwd->forward_port = 8000;
898 cur_fwd->next = config->forward;
899 config->forward = cur_fwd;
903 /****************************************************************************
904 * jarfile jar-file-name
905 * In logdir by default
906 ****************************************************************************/
907 #ifdef FEATURE_COOKIE_JAR
909 freez(config->jarfile);
910 config->jarfile = make_path(config->logdir, arg);
912 #endif /* def FEATURE_COOKIE_JAR */
914 /****************************************************************************
915 * listen-address [ip][:port]
916 ****************************************************************************/
917 case hash_listen_address :
918 freez(config->haddr);
919 config->haddr = strdup(arg);
922 /****************************************************************************
923 * logdir directory-name
924 ****************************************************************************/
926 freez(config->logdir);
927 config->logdir = strdup(arg);
930 /****************************************************************************
931 * logfile log-file-name
932 * In logdir by default
933 ****************************************************************************/
935 freez(config->logfile);
936 config->logfile = make_path(config->logdir, arg);
939 /****************************************************************************
940 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
941 ****************************************************************************/
943 case hash_permit_access:
944 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
946 if ((vec_count != 1) && (vec_count != 2))
948 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
949 "permit-access directive in configuration file.");
950 config->proxy_args = strsav( config->proxy_args,
951 "<br>\nWARNING: Wrong number of parameters for "
952 "permit-access directive in configuration file.<br><br>\n");
957 /* allocate a new node */
958 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
962 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
963 /* Never get here - LOG_LEVEL_FATAL causes program exit */
966 cur_acl->action = ACL_PERMIT;
968 if (acl_addr(vec[0], cur_acl->src) < 0)
970 log_error(LOG_LEVEL_ERROR, "Invalid source IP for permit-access "
971 "directive in configuration file: \"%s\"", vec[0]);
972 config->proxy_args = strsav( config->proxy_args,
973 "<br>\nWARNING: Invalid source IP for permit-access directive"
974 " in configuration file: \"");
975 config->proxy_args = strsav( config->proxy_args,
977 config->proxy_args = strsav( config->proxy_args,
984 if (acl_addr(vec[1], cur_acl->dst) < 0)
986 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for "
987 "permit-access directive in configuration file: \"%s\"",
989 config->proxy_args = strsav( config->proxy_args,
990 "<br>\nWARNING: Invalid destination IP for permit-access directive"
991 " in configuration file: \"");
992 config->proxy_args = strsav( config->proxy_args,
994 config->proxy_args = strsav( config->proxy_args,
1002 * Add it to the list. Note we reverse the list to get the
1003 * behaviour the user expects. With both the ACL and
1004 * actions file, the last match wins. However, the internal
1005 * implementations are different: The actions file is stored
1006 * in the same order as the file, and scanned completely.
1007 * With the ACL, we reverse the order as we load it, then
1008 * when we scan it we stop as soon as we get a match.
1010 cur_acl->next = config->acl;
1011 config->acl = cur_acl;
1014 #endif /* def FEATURE_ACL */
1016 /****************************************************************************
1017 * proxy-info-url url
1018 ****************************************************************************/
1019 case hash_proxy_info_url :
1020 freez(config->proxy_info_url);
1021 config->proxy_info_url = strdup(arg);
1024 /****************************************************************************
1025 * re_filterfile file-name
1026 * In confdir by default.
1027 ****************************************************************************/
1028 case hash_re_filterfile :
1029 freez(config->re_filterfile);
1030 config->re_filterfile = make_path(config->confdir, arg);
1033 /****************************************************************************
1035 ****************************************************************************/
1036 case hash_single_threaded :
1037 config->multi_threaded = 0;
1040 /****************************************************************************
1042 ****************************************************************************/
1043 #ifdef FEATURE_TOGGLE
1045 g_bToggleIJB = atoi(arg);
1047 #endif /* def FEATURE_TOGGLE */
1049 /****************************************************************************
1050 * trust-info-url url
1051 ****************************************************************************/
1052 #ifdef FEATURE_TRUST
1053 case hash_trust_info_url :
1054 enlist(config->trust_info, arg);
1056 #endif /* def FEATURE_TRUST */
1058 /****************************************************************************
1059 * trustfile filename
1060 * (In confdir by default.)
1061 ****************************************************************************/
1062 #ifdef FEATURE_TRUST
1063 case hash_trustfile :
1064 freez(config->trustfile);
1065 config->trustfile = make_path(config->confdir, arg);
1067 #endif /* def FEATURE_TRUST */
1070 /****************************************************************************
1071 * Win32 Console options:
1072 ****************************************************************************/
1074 /****************************************************************************
1076 ****************************************************************************/
1078 case hash_hide_console :
1081 #endif /*def _WIN_CONSOLE*/
1084 /****************************************************************************
1085 * Win32 GUI options:
1086 ****************************************************************************/
1088 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1089 /****************************************************************************
1090 * activity-animation (0|1)
1091 ****************************************************************************/
1092 case hash_activity_animation :
1093 g_bShowActivityAnimation = atoi(arg);
1096 /****************************************************************************
1097 * close-button-minimizes (0|1)
1098 ****************************************************************************/
1099 case hash_close_button_minimizes :
1100 g_bCloseHidesWindow = atoi(arg);
1103 /****************************************************************************
1104 * log-buffer-size (0|1)
1105 ****************************************************************************/
1106 case hash_log_buffer_size :
1107 g_bLimitBufferSize = atoi(arg);
1110 /****************************************************************************
1111 * log-font-name fontnane
1112 ****************************************************************************/
1113 case hash_log_font_name :
1114 strcpy( g_szFontFaceName, arg );
1117 /****************************************************************************
1119 ****************************************************************************/
1120 case hash_log_font_size :
1121 g_nFontSize = atoi(arg);
1124 /****************************************************************************
1125 * log-highlight-messages (0|1)
1126 ****************************************************************************/
1127 case hash_log_highlight_messages :
1128 g_bHighlightMessages = atoi(arg);
1131 /****************************************************************************
1133 ****************************************************************************/
1134 case hash_log_max_lines :
1135 g_nMaxBufferLines = atoi(arg);
1138 /****************************************************************************
1139 * log-messages (0|1)
1140 ****************************************************************************/
1141 case hash_log_messages :
1142 g_bLogMessages = atoi(arg);
1145 /****************************************************************************
1146 * show-on-task-bar (0|1)
1147 ****************************************************************************/
1148 case hash_show_on_task_bar :
1149 g_bShowOnTaskBar = atoi(arg);
1152 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1155 /****************************************************************************/
1156 /* Warnings about unsupported features */
1157 /****************************************************************************/
1159 case hash_deny_access:
1160 #endif /* ndef FEATURE_ACL */
1161 #ifndef FEATURE_CGI_EDIT_ACTIONS
1162 case hash_enable_edit_actions:
1163 case hash_enable_remote_toggle:
1164 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1165 #ifndef FEATURE_COOKIE_JAR
1167 #endif /* ndef FEATURE_COOKIE_JAR */
1169 case hash_permit_access:
1170 #endif /* ndef FEATURE_ACL */
1171 #ifndef FEATURE_TOGGLE
1173 #endif /* ndef FEATURE_TOGGLE */
1174 #ifndef FEATURE_TRUST
1175 case hash_trustfile :
1176 case hash_trust_info_url :
1177 #endif /* ndef FEATURE_TRUST */
1179 #ifndef _WIN_CONSOLE
1180 case hash_hide_console :
1181 #endif /* ndef _WIN_CONSOLE */
1183 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1184 case hash_activity_animation :
1185 case hash_close_button_minimizes :
1186 case hash_log_buffer_size :
1187 case hash_log_font_name :
1188 case hash_log_font_size :
1189 case hash_log_highlight_messages :
1190 case hash_log_max_lines :
1191 case hash_log_messages :
1192 case hash_show_on_task_bar :
1193 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1194 /* These warnings are annoying - so hide them. -- Jon */
1195 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1198 /****************************************************************************/
1200 /****************************************************************************/
1202 * I decided that I liked this better as a warning than an
1203 * error. To change back to an error, just change log level
1204 * to LOG_LEVEL_FATAL.
1206 log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%luul) in "
1207 "configuration file: \"%s\"", hash_string( cmd ), buf);
1208 config->proxy_args = strsav( config->proxy_args, "<br>\nWARNING: unrecognized directive : ");
1209 config->proxy_args = strsav( config->proxy_args, buf);
1210 config->proxy_args = strsav( config->proxy_args, "<br><br>\n");
1213 /****************************************************************************/
1214 } /* end switch( hash_string(cmd) ) */
1215 } /* end while ( read_config_line(...) ) */
1219 init_error_log(Argv[0], config->logfile, config->debug);
1221 if (config->actions_file)
1223 add_loader(load_actions_file, config);
1226 if (config->re_filterfile)
1228 add_loader(load_re_filterfile, config);
1231 #ifdef FEATURE_TRUST
1232 if (config->trustfile)
1234 add_loader(load_trustfile, config);
1236 #endif /* def FEATURE_TRUST */
1238 #ifdef FEATURE_COOKIE_JAR
1239 if ( NULL != config->jarfile )
1241 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1243 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1244 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1246 setbuf(config->jar, NULL);
1248 #endif /* def FEATURE_COOKIE_JAR */
1250 if ( NULL == config->haddr )
1252 config->haddr = strdup( HADDR_DEFAULT );
1255 if ( NULL != config->haddr )
1257 if ((p = strchr(config->haddr, ':')))
1262 config->hport = atoi(p);
1266 if (config->hport <= 0)
1269 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1270 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1272 if (*config->haddr == '\0')
1274 config->haddr = NULL;
1279 * Want to run all the loaders once now.
1281 * Need to set up a fake csp, so they can get to the config.
1283 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1284 fake_csp->config = config;
1286 if (run_loader(fake_csp))
1289 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1290 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1294 /* FIXME: this is a kludge for win32 */
1295 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1297 g_actions_file = config->actions_file;
1298 g_re_filterfile = config->re_filterfile;
1300 #ifdef FEATURE_TRUST
1301 g_trustfile = config->trustfile;
1302 #endif /* def FEATURE_TRUST */
1305 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1306 /* FIXME: end kludge */
1309 config->need_bind = 1;
1311 if (current_configfile)
1313 struct configuration_spec * oldcfg = (struct configuration_spec *)
1314 current_configfile->f;
1316 * Check if config->haddr,hport == oldcfg->haddr,hport
1318 * The following could be written more compactly as a single,
1319 * (unreadably long) if statement.
1321 config->need_bind = 0;
1322 if (config->hport != oldcfg->hport)
1324 config->need_bind = 1;
1326 else if (config->haddr == NULL)
1328 if (oldcfg->haddr != NULL)
1330 config->need_bind = 1;
1333 else if (oldcfg->haddr == NULL)
1335 config->need_bind = 1;
1337 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1339 config->need_bind = 1;
1342 current_configfile->unloader = unload_configfile;
1345 fs->next = files->next;
1348 current_configfile = fs;
1354 /*********************************************************************
1356 * Function : savearg
1358 * Description : Called from `load_config'. It saves each non-empty
1359 * and non-comment line from config into a list. This
1360 * list is used to create the show-proxy-args page.
1363 * 1 : c = config setting that was found
1364 * 2 : o = the setting's argument (if any)
1368 *********************************************************************/
1369 static void savearg(char *c, char *o, struct configuration_spec * config)
1371 char buf[BUFFER_SIZE];
1375 if ( ( NULL != c ) && ( '\0' != *c ) )
1377 if ((c = html_encode(c)))
1379 sprintf(buf, "<a href=\"" REDIRECT_URL "option#%s\">%s</a> ", c, c);
1383 if ( ( NULL != o ) && ( '\0' != *o ) )
1385 if ((o = html_encode(o)))
1387 if (strncmpic(o, "http://", 7) == 0)
1389 strcat(buf, "<a href=\"");
1393 strcat(buf, "</a>");
1403 strcat(buf, "<br>\n");
1405 config->proxy_args = strsav(config->proxy_args, buf);