1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.25 2001/10/25 03:40:48 david__schmidt 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.25 2001/10/25 03:40:48 david__schmidt
39 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
40 * threads to call select() simultaneously. So, it's time to do a real, live,
41 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
42 * (native). Both versions will work, but using __OS2__ offers multi-threading.
44 * Revision 1.24 2001/10/23 21:40:30 jongfoster
45 * Added support for enable-edit-actions and enable-remote-toggle config
48 * Revision 1.23 2001/10/07 15:36:00 oes
49 * Introduced new config option "buffer-limit"
51 * Revision 1.22 2001/09/22 16:36:59 jongfoster
52 * Removing unused parameter fs from read_config_line()
54 * Revision 1.21 2001/09/16 17:10:43 jongfoster
55 * Moving function savearg() here, since it was the only thing left in
58 * Revision 1.20 2001/07/30 22:08:36 jongfoster
59 * Tidying up #defines:
60 * - All feature #defines are now of the form FEATURE_xxx
61 * - Permanently turned off WIN_GUI_EDIT
62 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
64 * Revision 1.19 2001/07/15 17:45:16 jongfoster
65 * Removing some unused #includes
67 * Revision 1.18 2001/07/13 14:01:14 oes
68 * - Removed all #ifdef PCRS
69 * - Removed vim-settings
71 * Revision 1.17 2001/06/29 13:31:03 oes
73 * - Fixed (actionsfile) and sorted hashes
74 * - Introduced admin_address and proxy-info-url
75 * as config parameters
76 * - Renamed config->proxy_args_invocation (which didn't have
77 * the invocation but the options!) to config->proxy_args
79 * - Removed logentry from cancelled commit
81 * Revision 1.16 2001/06/09 10:55:28 jongfoster
82 * Changing BUFSIZ ==> BUFFER_SIZE
84 * Revision 1.15 2001/06/07 23:13:40 jongfoster
85 * Merging ACL and forward files into config file.
86 * Cosmetic: Sorting config file options alphabetically.
87 * Cosmetic: Adding brief syntax comments to config file options.
89 * Revision 1.14 2001/06/07 14:46:25 joergs
90 * Missing make_path() added for re_filterfile.
92 * Revision 1.13 2001/06/05 22:33:54 jongfoster
94 * Fixed minor memory leak.
95 * Also now uses make_path to prepend the pathnames.
97 * Revision 1.12 2001/06/05 20:04:09 jongfoster
98 * Now uses _snprintf() in place of snprintf() under Win32.
100 * Revision 1.11 2001/06/04 18:31:58 swa
101 * files are now prefixed with either `confdir' or `logdir'.
102 * `make redhat-dist' replaces both entries confdir and logdir
105 * Revision 1.10 2001/06/03 19:11:54 oes
106 * introduced confdir option
108 * Revision 1.9 2001/06/01 20:06:24 jongfoster
109 * Removed support for "tinygif" option - moved to actions file.
111 * Revision 1.8 2001/05/31 21:27:13 jongfoster
112 * Removed many options from the config file and into the
113 * "actions" file: add_forwarded, suppress_vanilla_wafer,
114 * wafer, add_header, user_agent, referer, from
115 * Also globally replaced "permission" with "action".
117 * Revision 1.7 2001/05/29 09:50:24 jongfoster
118 * Unified blocklist/imagelist/permissionslist.
119 * File format is still under discussion, but the internal changes
122 * Also modified interceptor behaviour:
123 * - We now intercept all URLs beginning with one of the following
124 * prefixes (and *only* these prefixes):
126 * * http://ijbswa.sf.net/config/
127 * * http://ijbswa.sourceforge.net/config/
128 * - New interceptors "home page" - go to http://i.j.b/ to see it.
129 * - Internal changes so that intercepted and fast redirect pages
130 * are not replaced with an image.
131 * - Interceptors now have the option to send a binary page direct
132 * to the client. (i.e. ijb-send-banner uses this)
133 * - Implemented show-url-info interceptor. (Which is why I needed
134 * the above interceptors changes - a typical URL is
135 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
136 * The previous mechanism would not have intercepted that, and
137 * if it had been intercepted then it then it would have replaced
140 * Revision 1.6 2001/05/26 00:28:36 jongfoster
141 * Automatic reloading of config file.
142 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
143 * Most of the global variables have been moved to a new
144 * struct configuration_spec, accessed through csp->config->globalname
145 * Most of the globals remaining are used by the Win32 GUI.
147 * Revision 1.5 2001/05/25 22:34:30 jongfoster
150 * Revision 1.4 2001/05/22 18:46:04 oes
152 * - Enabled filtering banners by size rather than URL
153 * by adding patterns that replace all standard banner
154 * sizes with the "Junkbuster" gif to the re_filterfile
156 * - Enabled filtering WebBugs by providing a pattern
157 * which kills all 1x1 images
159 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
160 * which is selected by the (nonstandard and therefore
161 * capital) letter 'U' in the option string.
162 * It causes the quantifiers to be ungreedy by default.
163 * Appending a ? turns back to greedy (!).
165 * - Added a new interceptor ijb-send-banner, which
166 * sends back the "Junkbuster" gif. Without imagelist or
167 * MSIE detection support, or if tinygif = 1, or the
168 * URL isn't recognized as an imageurl, a lame HTML
169 * explanation is sent instead.
171 * - Added new feature, which permits blocking remote
172 * script redirects and firing back a local redirect
174 * The feature is conditionally compiled, i.e. it
175 * can be disabled with --disable-fast-redirects,
176 * plus it must be activated by a "fast-redirects"
177 * line in the config file, has its own log level
178 * and of course wants to be displayed by show-proxy-args
179 * Note: Boy, all the #ifdefs in 1001 locations and
180 * all the fumbling with configure.in and acconfig.h
181 * were *way* more work than the feature itself :-(
183 * - Because a generic redirect template was needed for
184 * this, tinygif = 3 now uses the same.
186 * - Moved GIFs, and other static HTTP response templates
191 * - Removed some >400 CRs again (Jon, you really worked
194 * Revision 1.3 2001/05/20 01:21:20 jongfoster
195 * Version 2.9.4 checkin.
196 * - Merged popupfile and cookiefile, and added control over PCRS
197 * filtering, in new "permissionsfile".
198 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
199 * file error you now get a message box (in the Win32 GUI) rather
200 * than the program exiting with no explanation.
201 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
203 * - Removed tabs from "config"
204 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
205 * - Bumped up version number.
207 * Revision 1.2 2001/05/17 23:01:01 oes
208 * - Cleaned CRLF's from the sources and related files
210 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
211 * Initial import of version 2.9.3 source tree
214 *********************************************************************/
220 #include <sys/types.h>
230 # include <windows.h>
233 # ifndef _WIN_CONSOLE
235 # endif /* ndef _WIN_CONSOLE */
237 /* VC++ has "_snprintf", not "snprintf" */
238 #define snprintf _snprintf
240 #else /* ifndef _WIN32 */
244 # include <sys/wait.h>
246 # include <sys/time.h>
247 # include <sys/stat.h>
257 #include "miscutil.h"
262 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
265 * Fix a problem with Solaris. There should be no effect on other
267 * Solaris's isspace() is a macro which uses it's argument directly
268 * as an array index. Therefore we need to make sure that high-bit
269 * characters generate +ve values, and ideally we also want to make
270 * the argument match the declared parameter type of "int".
272 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
273 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
275 #ifdef FEATURE_TOGGLE
276 /* by haroon - indicates if ijb is enabled */
277 int g_bToggleIJB = 1; /* JunkBusters is enabled by default. */
278 #endif /* def FEATURE_TOGGLE */
280 /* The filename of the configfile */
281 const char *configfile = NULL;
284 * CGI functions will later need access to the invocation args,
285 * so we will make argc and argv global.
288 const char **Argv = NULL;
290 static struct file_list *current_configfile = NULL;
294 * This takes the "cryptic" hash of each keyword and aliases them to
295 * something a little more readable. This also makes changing the
296 * hash values easier if they should change or the hash algorthm changes.
297 * Use the included "hash" program to find out what the hash will be
298 * for any string supplied on the command line. (Or just put it in the
299 * config file and read the number from the error message in the log).
301 * Please keep this list sorted alphabetically (but with the Windows
302 * console and GUI specific options last).
305 #define hash_actions_file 1196306641ul /* "actionsfile" */
306 #define hash_admin_address 4112573064ul /* "admin-address" */
307 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
308 #define hash_confdir 1978389ul /* "confdir" */
309 #define hash_debug 78263ul /* "debug" */
310 #define hash_deny_access 1227333715ul /* "deny-access" */
311 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
312 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
313 #define hash_forward 2029845ul /* "forward" */
314 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
315 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
316 #define hash_jarfile 2046641ul /* "jarfile" */
317 #define hash_listen_address 1255650842ul /* "listen-address" */
318 #define hash_logdir 422889ul /* "logdir" */
319 #define hash_logfile 2114766ul /* "logfile" */
320 #define hash_permit_access 3587953268ul /* "permit-access" */
321 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
322 #define hash_re_filterfile 3877522444ul /* "re_filterfile" */
323 #define hash_single_threaded 4250084780ul /* "single-threaded" */
324 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
325 #define hash_toggle 447966ul /* "toggle" */
326 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
327 #define hash_trustfile 56494766ul /* "trustfile" */
329 #define hash_activity_animation 1817904738ul /* "activity-animation" */
330 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
331 #define hash_hide_console 2048809870ul /* "hide-console" */
332 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
333 #define hash_log_font_name 2866730124ul /* "log-font-name" */
334 #define hash_log_font_size 2866731014ul /* "log-font-size" */
335 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
336 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
337 #define hash_log_messages 2291744899ul /* "log-messages" */
338 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
341 static void savearg(char *c, char *o, struct configuration_spec * config);
344 /*********************************************************************
346 * Function : unload_configfile
348 * Description : Free the config structure and all components.
351 * 1 : data: struct configuration_spec to unload
355 *********************************************************************/
356 void unload_configfile (void * data)
358 struct configuration_spec * config = (struct configuration_spec *)data;
359 struct forward_spec *cur_fwd = config->forward;
361 struct access_control_list *cur_acl = config->acl;
363 while (cur_acl != NULL)
365 struct access_control_list * next_acl = cur_acl->next;
370 #endif /* def FEATURE_ACL */
372 while (cur_fwd != NULL)
374 struct forward_spec * next_fwd = cur_fwd->next;
375 free_url(cur_fwd->url);
377 freez(cur_fwd->gateway_host);
378 freez(cur_fwd->forward_host);
382 config->forward = NULL;
384 #ifdef FEATURE_COOKIE_JAR
385 if ( NULL != config->jar )
387 fclose( config->jar );
390 #endif /* def FEATURE_COOKIE_JAR */
392 freez(config->confdir);
393 freez(config->logdir);
395 freez(config->haddr);
396 freez(config->logfile);
398 freez(config->actions_file);
399 freez(config->admin_address);
400 freez(config->proxy_info_url);
401 freez(config->proxy_args);
403 #ifdef FEATURE_COOKIE_JAR
404 freez(config->jarfile);
405 #endif /* def FEATURE_COOKIE_JAR */
407 freez(config->re_filterfile);
412 /*********************************************************************
414 * Function : load_config
416 * Description : Load the config file and all parameters.
419 * 1 : csp = Client state (the config member will be
420 * filled in by this function).
422 * Returns : 0 => Ok, everything else is an error.
424 *********************************************************************/
425 struct configuration_spec * load_config(void)
427 char buf[BUFFER_SIZE];
429 FILE *configfp = NULL;
430 struct configuration_spec * config = NULL;
431 struct client_state * fake_csp;
432 struct file_list *fs;
434 DBG(1, ("load_config() entered..\n") );
435 if (!check_file_changed(current_configfile, configfile, &fs))
437 /* No need to load */
438 return ((struct configuration_spec *)current_configfile->f);
442 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
447 log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
450 #ifdef FEATURE_TOGGLE
452 #endif /* def FEATURE_TOGGLE */
454 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
460 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
461 /* Never get here - LOG_LEVEL_FATAL causes program exit */
465 * This is backwards from how it's usually done.
466 * Following the usual pattern, "fs" would be stored in a member
467 * variable in "csp", and then we'd access "config" from "fs->f",
468 * using a cast. However, "config" is used so often that a
469 * cast each time would be very ugly, and the extra indirection
470 * would waste CPU cycles. Therefore we store "config" in
471 * "csp->config", and "fs" in "csp->config->config_file_list".
473 config->config_file_list = fs;
479 config->multi_threaded = 1;
480 config->hport = HADDR_PORT;
481 config->buffer_limit = 4096 * 1024;
483 if ((configfp = fopen(configfile, "r")) == NULL)
485 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
487 /* Never get here - LOG_LEVEL_FATAL causes program exit */
490 while (read_config_line(buf, sizeof(buf), configfp) != NULL)
492 char cmd[BUFFER_SIZE];
493 char arg[BUFFER_SIZE];
494 char tmp[BUFFER_SIZE];
496 struct access_control_list *cur_acl;
497 #endif /* def FEATURE_ACL */
498 struct forward_spec *cur_fwd;
504 /* Copy command (i.e. up to space or tab) into cmd */
507 while (*p && (*p != ' ') && (*p != '\t'))
513 /* Skip over the whitespace in buf */
514 while (*p && ((*p == ' ') || (*p == '\t')))
519 /* Copy the argument into arg */
522 /* Should never happen, but check this anyway */
528 /* Make sure the command field is lower case */
533 *p = ijb_tolower(*p);
537 /* Save the argument for show-proxy-args */
538 savearg(cmd, arg, config);
541 switch( hash_string( cmd ) )
543 /****************************************************************************
544 * actionsfile actions-file-name
545 * In confdir by default
546 ****************************************************************************/
547 case hash_actions_file :
548 freez(config->actions_file);
549 config->actions_file = make_path(config->confdir, arg);
552 /****************************************************************************
553 * admin-address email-address
554 ****************************************************************************/
555 case hash_admin_address :
556 freez(config->admin_address);
557 config->admin_address = strdup(arg);
560 /****************************************************************************
562 ****************************************************************************/
563 case hash_buffer_limit :
564 config->buffer_limit = (size_t) 1024 * atoi(arg);
567 /****************************************************************************
568 * confdir directory-name
569 ****************************************************************************/
571 freez(config->confdir);
572 config->confdir = strdup(arg);
575 /****************************************************************************
577 * Specifies debug level, multiple values are ORed together.
578 ****************************************************************************/
580 config->debug |= atoi(arg);
583 /****************************************************************************
584 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
585 ****************************************************************************/
587 case hash_deny_access:
588 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
590 if ((vec_count != 1) && (vec_count != 2))
592 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
593 "deny-access directive in configuration file.");
594 config->proxy_args = strsav( config->proxy_args,
595 "<br>\nWARNING: Wrong number of parameters for "
596 "deny-access directive in configuration file.<br><br>\n");
600 /* allocate a new node */
601 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
605 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
606 /* Never get here - LOG_LEVEL_FATAL causes program exit */
609 cur_acl->action = ACL_DENY;
611 if (acl_addr(vec[0], cur_acl->src) < 0)
613 log_error(LOG_LEVEL_ERROR, "Invalid source IP for deny-access "
614 "directive in configuration file: \"%s\"", vec[0]);
615 config->proxy_args = strsav( config->proxy_args,
616 "<br>\nWARNING: Invalid source IP for deny-access directive"
617 " in configuration file: \"");
618 config->proxy_args = strsav( config->proxy_args,
620 config->proxy_args = strsav( config->proxy_args,
627 if (acl_addr(vec[1], cur_acl->dst) < 0)
629 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for deny-access "
630 "directive in configuration file: \"%s\"", vec[0]);
631 config->proxy_args = strsav( config->proxy_args,
632 "<br>\nWARNING: Invalid destination IP for deny-access directive"
633 " in configuration file: \"");
634 config->proxy_args = strsav( config->proxy_args,
636 config->proxy_args = strsav( config->proxy_args,
644 * Add it to the list. Note we reverse the list to get the
645 * behaviour the user expects. With both the ACL and
646 * actions file, the last match wins. However, the internal
647 * implementations are different: The actions file is stored
648 * in the same order as the file, and scanned completely.
649 * With the ACL, we reverse the order as we load it, then
650 * when we scan it we stop as soon as we get a match.
652 cur_acl->next = config->acl;
653 config->acl = cur_acl;
656 #endif /* def FEATURE_ACL */
658 /****************************************************************************
659 * enable-edit-actions 0|1
660 ****************************************************************************/
661 #ifdef FEATURE_CGI_EDIT_ACTIONS
662 case hash_enable_edit_actions:
663 if ((*arg != '\0') && (0 != atoi(arg)))
665 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
669 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
672 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
674 /****************************************************************************
675 * enable-remote-toggle 0|1
676 ****************************************************************************/
677 #ifdef FEATURE_CGI_EDIT_ACTIONS
678 case hash_enable_remote_toggle:
679 if ((*arg != '\0') && (0 != atoi(arg)))
681 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
685 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
688 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
690 /****************************************************************************
691 * forward url-pattern (.|http-proxy-host[:port])
692 ****************************************************************************/
694 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
698 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
699 "directive in configuration file.");
700 config->proxy_args = strsav( config->proxy_args,
701 "<br>\nWARNING: Wrong number of parameters for "
702 "forward directive in configuration file.");
706 /* allocate a new node */
707 cur_fwd = zalloc(sizeof(*cur_fwd));
710 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
711 /* Never get here - LOG_LEVEL_FATAL causes program exit */
715 cur_fwd->type = SOCKS_NONE;
717 /* Save the URL pattern */
718 if (create_url_spec(cur_fwd->url, vec[0]))
720 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
721 "directive in configuration file.");
722 config->proxy_args = strsav( config->proxy_args,
723 "<br>\nWARNING: Bad URL specifier for "
724 "forward directive in configuration file.");
728 /* Parse the parent HTTP proxy host:port */
731 if (strcmp(p, ".") != 0)
733 cur_fwd->forward_host = strdup(p);
735 if ((p = strchr(cur_fwd->forward_host, ':')))
738 cur_fwd->forward_port = atoi(p);
741 if (cur_fwd->forward_port <= 0)
743 cur_fwd->forward_port = 8000;
748 cur_fwd->next = config->forward;
749 config->forward = cur_fwd;
753 /****************************************************************************
754 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
755 ****************************************************************************/
756 case hash_forward_socks4:
757 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
761 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
762 "forward-socks4 directive in configuration file.");
763 config->proxy_args = strsav( config->proxy_args,
764 "<br>\nWARNING: Wrong number of parameters for "
765 "forward-socks4 directive in configuration file.");
769 /* allocate a new node */
770 cur_fwd = zalloc(sizeof(*cur_fwd));
773 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
774 /* Never get here - LOG_LEVEL_FATAL causes program exit */
778 cur_fwd->type = SOCKS_4;
780 /* Save the URL pattern */
781 if (create_url_spec(cur_fwd->url, vec[0]))
783 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
784 "directive in configuration file.");
785 config->proxy_args = strsav( config->proxy_args,
786 "<br>\nWARNING: Bad URL specifier for "
787 "forward-socks4 directive in configuration file.");
791 /* Parse the SOCKS proxy host[:port] */
794 if (strcmp(p, ".") != 0)
796 cur_fwd->gateway_host = strdup(p);
798 if ((p = strchr(cur_fwd->gateway_host, ':')))
801 cur_fwd->gateway_port = atoi(p);
803 if (cur_fwd->gateway_port <= 0)
805 cur_fwd->gateway_port = 1080;
809 /* Parse the parent HTTP proxy host[:port] */
812 if (strcmp(p, ".") != 0)
814 cur_fwd->forward_host = strdup(p);
816 if ((p = strchr(cur_fwd->forward_host, ':')))
819 cur_fwd->forward_port = atoi(p);
822 if (cur_fwd->forward_port <= 0)
824 cur_fwd->forward_port = 8000;
829 cur_fwd->next = config->forward;
830 config->forward = cur_fwd;
834 /****************************************************************************
835 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
836 ****************************************************************************/
837 case hash_forward_socks4a:
838 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
842 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
843 "forward-socks4a directive in configuration file.");
844 config->proxy_args = strsav( config->proxy_args,
845 "<br>\nWARNING: Wrong number of parameters for "
846 "forward-socks4a directive in configuration file.");
850 /* allocate a new node */
851 cur_fwd = zalloc(sizeof(*cur_fwd));
854 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
855 /* Never get here - LOG_LEVEL_FATAL causes program exit */
859 cur_fwd->type = SOCKS_4A;
861 /* Save the URL pattern */
862 if (create_url_spec(cur_fwd->url, vec[0]))
864 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
865 "directive in configuration file.");
866 config->proxy_args = strsav( config->proxy_args,
867 "<br>\nWARNING: Bad URL specifier for "
868 "forward-socks4a directive in configuration file.");
872 /* Parse the SOCKS proxy host[:port] */
875 cur_fwd->gateway_host = strdup(p);
877 if ((p = strchr(cur_fwd->gateway_host, ':')))
880 cur_fwd->gateway_port = atoi(p);
882 if (cur_fwd->gateway_port <= 0)
884 cur_fwd->gateway_port = 1080;
887 /* Parse the parent HTTP proxy host[:port] */
890 if (strcmp(p, ".") != 0)
892 cur_fwd->forward_host = strdup(p);
894 if ((p = strchr(cur_fwd->forward_host, ':')))
897 cur_fwd->forward_port = atoi(p);
900 if (cur_fwd->forward_port <= 0)
902 cur_fwd->forward_port = 8000;
907 cur_fwd->next = config->forward;
908 config->forward = cur_fwd;
912 /****************************************************************************
913 * jarfile jar-file-name
914 * In logdir by default
915 ****************************************************************************/
916 #ifdef FEATURE_COOKIE_JAR
918 freez(config->jarfile);
919 config->jarfile = make_path(config->logdir, arg);
921 #endif /* def FEATURE_COOKIE_JAR */
923 /****************************************************************************
924 * listen-address [ip][:port]
925 ****************************************************************************/
926 case hash_listen_address :
927 freez(config->haddr);
928 config->haddr = strdup(arg);
931 /****************************************************************************
932 * logdir directory-name
933 ****************************************************************************/
935 freez(config->logdir);
936 config->logdir = make_path(NULL, arg);
939 /****************************************************************************
940 * logfile log-file-name
941 * In logdir by default
942 ****************************************************************************/
944 freez(config->logfile);
945 config->logfile = make_path(config->logdir, arg);
948 /****************************************************************************
949 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
950 ****************************************************************************/
952 case hash_permit_access:
953 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
955 if ((vec_count != 1) && (vec_count != 2))
957 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
958 "permit-access directive in configuration file.");
959 config->proxy_args = strsav( config->proxy_args,
960 "<br>\nWARNING: Wrong number of parameters for "
961 "permit-access directive in configuration file.<br><br>\n");
966 /* allocate a new node */
967 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
971 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
972 /* Never get here - LOG_LEVEL_FATAL causes program exit */
975 cur_acl->action = ACL_PERMIT;
977 if (acl_addr(vec[0], cur_acl->src) < 0)
979 log_error(LOG_LEVEL_ERROR, "Invalid source IP for permit-access "
980 "directive in configuration file: \"%s\"", vec[0]);
981 config->proxy_args = strsav( config->proxy_args,
982 "<br>\nWARNING: Invalid source IP for permit-access directive"
983 " in configuration file: \"");
984 config->proxy_args = strsav( config->proxy_args,
986 config->proxy_args = strsav( config->proxy_args,
993 if (acl_addr(vec[1], cur_acl->dst) < 0)
995 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for "
996 "permit-access directive in configuration file: \"%s\"",
998 config->proxy_args = strsav( config->proxy_args,
999 "<br>\nWARNING: Invalid destination IP for permit-access directive"
1000 " in configuration file: \"");
1001 config->proxy_args = strsav( config->proxy_args,
1003 config->proxy_args = strsav( config->proxy_args,
1011 * Add it to the list. Note we reverse the list to get the
1012 * behaviour the user expects. With both the ACL and
1013 * actions file, the last match wins. However, the internal
1014 * implementations are different: The actions file is stored
1015 * in the same order as the file, and scanned completely.
1016 * With the ACL, we reverse the order as we load it, then
1017 * when we scan it we stop as soon as we get a match.
1019 cur_acl->next = config->acl;
1020 config->acl = cur_acl;
1023 #endif /* def FEATURE_ACL */
1025 /****************************************************************************
1026 * proxy-info-url url
1027 ****************************************************************************/
1028 case hash_proxy_info_url :
1029 freez(config->proxy_info_url);
1030 config->proxy_info_url = strdup(arg);
1033 /****************************************************************************
1034 * re_filterfile file-name
1035 * In confdir by default.
1036 ****************************************************************************/
1037 case hash_re_filterfile :
1038 freez(config->re_filterfile);
1039 config->re_filterfile = make_path(config->confdir, arg);
1042 /****************************************************************************
1044 ****************************************************************************/
1045 case hash_single_threaded :
1046 config->multi_threaded = 0;
1049 /****************************************************************************
1051 ****************************************************************************/
1052 #ifdef FEATURE_TOGGLE
1054 g_bToggleIJB = atoi(arg);
1056 #endif /* def FEATURE_TOGGLE */
1058 /****************************************************************************
1059 * trust-info-url url
1060 ****************************************************************************/
1061 #ifdef FEATURE_TRUST
1062 case hash_trust_info_url :
1063 enlist(config->trust_info, arg);
1065 #endif /* def FEATURE_TRUST */
1067 /****************************************************************************
1068 * trustfile filename
1069 * (In confdir by default.)
1070 ****************************************************************************/
1071 #ifdef FEATURE_TRUST
1072 case hash_trustfile :
1073 freez(config->trustfile);
1074 config->trustfile = make_path(config->confdir, arg);
1076 #endif /* def FEATURE_TRUST */
1079 /****************************************************************************
1080 * Win32 Console options:
1081 ****************************************************************************/
1083 /****************************************************************************
1085 ****************************************************************************/
1087 case hash_hide_console :
1090 #endif /*def _WIN_CONSOLE*/
1093 /****************************************************************************
1094 * Win32 GUI options:
1095 ****************************************************************************/
1097 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1098 /****************************************************************************
1099 * activity-animation (0|1)
1100 ****************************************************************************/
1101 case hash_activity_animation :
1102 g_bShowActivityAnimation = atoi(arg);
1105 /****************************************************************************
1106 * close-button-minimizes (0|1)
1107 ****************************************************************************/
1108 case hash_close_button_minimizes :
1109 g_bCloseHidesWindow = atoi(arg);
1112 /****************************************************************************
1113 * log-buffer-size (0|1)
1114 ****************************************************************************/
1115 case hash_log_buffer_size :
1116 g_bLimitBufferSize = atoi(arg);
1119 /****************************************************************************
1120 * log-font-name fontnane
1121 ****************************************************************************/
1122 case hash_log_font_name :
1123 strcpy( g_szFontFaceName, arg );
1126 /****************************************************************************
1128 ****************************************************************************/
1129 case hash_log_font_size :
1130 g_nFontSize = atoi(arg);
1133 /****************************************************************************
1134 * log-highlight-messages (0|1)
1135 ****************************************************************************/
1136 case hash_log_highlight_messages :
1137 g_bHighlightMessages = atoi(arg);
1140 /****************************************************************************
1142 ****************************************************************************/
1143 case hash_log_max_lines :
1144 g_nMaxBufferLines = atoi(arg);
1147 /****************************************************************************
1148 * log-messages (0|1)
1149 ****************************************************************************/
1150 case hash_log_messages :
1151 g_bLogMessages = atoi(arg);
1154 /****************************************************************************
1155 * show-on-task-bar (0|1)
1156 ****************************************************************************/
1157 case hash_show_on_task_bar :
1158 g_bShowOnTaskBar = atoi(arg);
1161 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1164 /****************************************************************************/
1165 /* Warnings about unsupported features */
1166 /****************************************************************************/
1168 case hash_deny_access:
1169 #endif /* ndef FEATURE_ACL */
1170 #ifndef FEATURE_CGI_EDIT_ACTIONS
1171 case hash_enable_edit_actions:
1172 case hash_enable_remote_toggle:
1173 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1174 #ifndef FEATURE_COOKIE_JAR
1176 #endif /* ndef FEATURE_COOKIE_JAR */
1178 case hash_permit_access:
1179 #endif /* ndef FEATURE_ACL */
1180 #ifndef FEATURE_TOGGLE
1182 #endif /* ndef FEATURE_TOGGLE */
1183 #ifndef FEATURE_TRUST
1184 case hash_trustfile :
1185 case hash_trust_info_url :
1186 #endif /* ndef FEATURE_TRUST */
1188 #ifndef _WIN_CONSOLE
1189 case hash_hide_console :
1190 #endif /* ndef _WIN_CONSOLE */
1192 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1193 case hash_activity_animation :
1194 case hash_close_button_minimizes :
1195 case hash_log_buffer_size :
1196 case hash_log_font_name :
1197 case hash_log_font_size :
1198 case hash_log_highlight_messages :
1199 case hash_log_max_lines :
1200 case hash_log_messages :
1201 case hash_show_on_task_bar :
1202 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1203 /* These warnings are annoying - so hide them. -- Jon */
1204 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1207 /****************************************************************************/
1209 /****************************************************************************/
1211 * I decided that I liked this better as a warning than an
1212 * error. To change back to an error, just change log level
1213 * to LOG_LEVEL_FATAL.
1215 log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%luul) in "
1216 "configuration file: \"%s\"", hash_string( cmd ), buf);
1217 config->proxy_args = strsav( config->proxy_args, "<br>\nWARNING: unrecognized directive : ");
1218 config->proxy_args = strsav( config->proxy_args, buf);
1219 config->proxy_args = strsav( config->proxy_args, "<br><br>\n");
1222 /****************************************************************************/
1223 } /* end switch( hash_string(cmd) ) */
1224 } /* end while ( read_config_line(...) ) */
1228 init_error_log(Argv[0], config->logfile, config->debug);
1230 if (config->actions_file)
1232 add_loader(load_actions_file, config);
1235 if (config->re_filterfile)
1237 add_loader(load_re_filterfile, config);
1240 #ifdef FEATURE_TRUST
1241 if (config->trustfile)
1243 add_loader(load_trustfile, config);
1245 #endif /* def FEATURE_TRUST */
1247 #ifdef FEATURE_COOKIE_JAR
1248 if ( NULL != config->jarfile )
1250 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1252 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1253 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1255 setbuf(config->jar, NULL);
1257 #endif /* def FEATURE_COOKIE_JAR */
1259 if ( NULL == config->haddr )
1261 config->haddr = strdup( HADDR_DEFAULT );
1264 if ( NULL != config->haddr )
1266 if ((p = strchr(config->haddr, ':')))
1271 config->hport = atoi(p);
1275 if (config->hport <= 0)
1278 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1279 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1281 if (*config->haddr == '\0')
1283 config->haddr = NULL;
1288 * Want to run all the loaders once now.
1290 * Need to set up a fake csp, so they can get to the config.
1292 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1293 fake_csp->config = config;
1295 if (run_loader(fake_csp))
1298 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1299 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1303 /* FIXME: this is a kludge for win32 */
1304 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1306 g_actions_file = config->actions_file;
1307 g_re_filterfile = config->re_filterfile;
1309 #ifdef FEATURE_TRUST
1310 g_trustfile = config->trustfile;
1311 #endif /* def FEATURE_TRUST */
1314 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1315 /* FIXME: end kludge */
1318 config->need_bind = 1;
1320 if (current_configfile)
1322 struct configuration_spec * oldcfg = (struct configuration_spec *)
1323 current_configfile->f;
1325 * Check if config->haddr,hport == oldcfg->haddr,hport
1327 * The following could be written more compactly as a single,
1328 * (unreadably long) if statement.
1330 config->need_bind = 0;
1331 if (config->hport != oldcfg->hport)
1333 config->need_bind = 1;
1335 else if (config->haddr == NULL)
1337 if (oldcfg->haddr != NULL)
1339 config->need_bind = 1;
1342 else if (oldcfg->haddr == NULL)
1344 config->need_bind = 1;
1346 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1348 config->need_bind = 1;
1351 current_configfile->unloader = unload_configfile;
1354 fs->next = files->next;
1357 current_configfile = fs;
1363 /*********************************************************************
1365 * Function : savearg
1367 * Description : Called from `load_config'. It saves each non-empty
1368 * and non-comment line from config into a list. This
1369 * list is used to create the show-proxy-args page.
1372 * 1 : c = config setting that was found
1373 * 2 : o = the setting's argument (if any)
1377 *********************************************************************/
1378 static void savearg(char *c, char *o, struct configuration_spec * config)
1380 char buf[BUFFER_SIZE];
1384 if ( ( NULL != c ) && ( '\0' != *c ) )
1386 if ((c = html_encode(c)))
1388 sprintf(buf, "<a href=\"" REDIRECT_URL "option#%s\">%s</a> ", c, c);
1392 if ( ( NULL != o ) && ( '\0' != *o ) )
1394 if ((o = html_encode(o)))
1396 if (strncmpic(o, "http://", 7) == 0)
1398 strcat(buf, "<a href=\"");
1402 strcat(buf, "</a>");
1412 strcat(buf, "<br>\n");
1414 config->proxy_args = strsav(config->proxy_args, buf);