1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.59 2006/12/31 17:56:38 fabiankeil 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-2007 the SourceForge
12 * Privoxy team. http://www.privoxy.org/
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.59 2006/12/31 17:56:38 fabiankeil
39 * Added config option accept-intercepted-requests
40 * and disabled it by default.
42 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
43 * Fix gcc43 compiler warnings.
45 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
46 * Add config option "split-large-forms"
47 * to work around the browser bug reported
50 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
51 * Move the <br> in the generated HTML for the config
52 * options from the beginning of the string to its end.
53 * Keeps the white space in balance.
55 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
56 * Fix memory leak in case of config file reloads.
58 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
59 * Modified kludge for win32 to make ming32 menu
60 * "Options/Edit Filters" (sort of) work again.
61 * Same limitations as for the action files apply.
64 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
65 * Incorporate modified version of Roland Rosenfeld's patch to
66 * optionally access the user-manual via Privoxy. Closes patch 679075.
68 * Formatting changed to Privoxy style, added call to
69 * cgi_error_no_template if the requested file doesn't
70 * exist and modified check whether or not Privoxy itself
71 * should serve the manual. Should work cross-platform now.
73 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
74 * Added config option enable-remote-http-toggle
75 * to specify if Privoxy should recognize special
76 * headers (currently only X-Filter) to change its
77 * behaviour. Disabled by default.
79 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
80 * Make number of retries in case of forwarded-connect problems
81 * a config file option (forwarded-connect-retries) and use 0 as
84 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
85 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
86 * with what was really the latest development (the v_3_0_branch branch)
88 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
89 * Don't forget to malloc space for the null terminator...
91 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
92 * Multiple filter file support
94 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
95 * Closed two memory leaks; hopefully the last remaining ones
96 * (in the main execution paths, anyway).
98 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
99 * Addressed bug #719435
100 * - Extraneous filterfile directives now logged as errors
101 * - This and unrecnonised directives now really obvious on status page
103 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
104 * Cosmetic: Renamed cryptic variable
106 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
107 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
109 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
110 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
112 * Revision 1.48 2002/05/14 21:30:38 oes
113 * savearg now uses own linking code instead of (now special-cased) add_help_link
115 * Revision 1.47 2002/05/12 21:36:29 jongfoster
116 * Correcting function comments
118 * Revision 1.46 2002/04/26 12:55:14 oes
119 * - New option "user-manual", defaults to our site
120 * via project.h #define
121 * - savearg now embeds option names in help links
123 * Revision 1.45 2002/04/24 02:11:54 oes
124 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
126 * Revision 1.44 2002/04/08 20:37:13 swa
129 * Revision 1.43 2002/04/08 20:36:50 swa
132 * Revision 1.42 2002/04/05 15:50:15 oes
133 * fix for invalid HTML proxy_args
135 * Revision 1.41 2002/03/31 17:19:00 jongfoster
136 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
138 * Revision 1.40 2002/03/26 22:29:55 swa
139 * we have a new homepage!
141 * Revision 1.39 2002/03/24 13:25:43 swa
142 * name change related issues
144 * Revision 1.38 2002/03/24 13:05:48 jongfoster
145 * Renaming re_filterfile to filterfile
147 * Revision 1.37 2002/03/16 23:54:06 jongfoster
148 * Adding graceful termination feature, to help look for memory leaks.
149 * If you enable this (which, by design, has to be done by hand
150 * editing config.h) and then go to http://i.j.b/die, then the program
151 * will exit cleanly after the *next* request. It should free all the
152 * memory that was used.
154 * Revision 1.36 2002/03/13 00:27:05 jongfoster
157 * Revision 1.35 2002/03/07 03:52:44 oes
158 * Set logging to tty for --no-daemon mode
160 * Revision 1.34 2002/03/06 23:14:35 jongfoster
161 * Trivial cosmetic changes to make function comments easier to find.
163 * Revision 1.33 2002/03/05 04:52:42 oes
164 * Deleted non-errlog debugging code
166 * Revision 1.32 2002/03/04 18:24:53 oes
167 * Re-enabled output of unknown config directive hash
169 * Revision 1.31 2002/03/03 15:07:20 oes
170 * Re-enabled automatic config reloading
172 * Revision 1.30 2002/01/22 23:31:43 jongfoster
173 * Replacing strsav() with string_append()
175 * Revision 1.29 2002/01/17 21:02:30 jongfoster
176 * Moving all our URL and URL pattern parsing code to urlmatch.c.
178 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
180 * Revision 1.28 2001/12/30 14:07:32 steudten
181 * - Add signal handling (unix)
182 * - Add SIGHUP handler (unix)
183 * - Add creation of pidfile (unix)
184 * - Add action 'top' in rc file (RH)
185 * - Add entry 'SIGNALS' to manpage
186 * - Add exit message to logfile (unix)
188 * Revision 1.27 2001/11/07 00:02:13 steudten
189 * Add line number in error output for lineparsing for
190 * actionsfile and configfile.
191 * Special handling for CLF added.
193 * Revision 1.26 2001/11/05 21:41:43 steudten
194 * Add changes to be a real daemon just for unix os.
195 * (change cwd to /, detach from controlling tty, set
196 * process group and session leader to the own process.
198 * Add some fatal-error log message for failed malloc().
199 * Add '-d' if compiled with 'configure --with-debug' to
200 * enable debug output.
202 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
203 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
204 * threads to call select() simultaneously. So, it's time to do a real, live,
205 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
206 * (native). Both versions will work, but using __OS2__ offers multi-threading.
208 * Revision 1.24 2001/10/23 21:40:30 jongfoster
209 * Added support for enable-edit-actions and enable-remote-toggle config
212 * Revision 1.23 2001/10/07 15:36:00 oes
213 * Introduced new config option "buffer-limit"
215 * Revision 1.22 2001/09/22 16:36:59 jongfoster
216 * Removing unused parameter fs from read_config_line()
218 * Revision 1.21 2001/09/16 17:10:43 jongfoster
219 * Moving function savearg() here, since it was the only thing left in
222 * Revision 1.20 2001/07/30 22:08:36 jongfoster
223 * Tidying up #defines:
224 * - All feature #defines are now of the form FEATURE_xxx
225 * - Permanently turned off WIN_GUI_EDIT
226 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
228 * Revision 1.19 2001/07/15 17:45:16 jongfoster
229 * Removing some unused #includes
231 * Revision 1.18 2001/07/13 14:01:14 oes
232 * - Removed all #ifdef PCRS
233 * - Removed vim-settings
235 * Revision 1.17 2001/06/29 13:31:03 oes
236 * - Improved comments
237 * - Fixed (actionsfile) and sorted hashes
238 * - Introduced admin_address and proxy-info-url
239 * as config parameters
240 * - Renamed config->proxy_args_invocation (which didn't have
241 * the invocation but the options!) to config->proxy_args
242 * - Various adaptions
243 * - Removed logentry from cancelled commit
245 * Revision 1.16 2001/06/09 10:55:28 jongfoster
246 * Changing BUFSIZ ==> BUFFER_SIZE
248 * Revision 1.15 2001/06/07 23:13:40 jongfoster
249 * Merging ACL and forward files into config file.
250 * Cosmetic: Sorting config file options alphabetically.
251 * Cosmetic: Adding brief syntax comments to config file options.
253 * Revision 1.14 2001/06/07 14:46:25 joergs
254 * Missing make_path() added for re_filterfile.
256 * Revision 1.13 2001/06/05 22:33:54 jongfoster
258 * Fixed minor memory leak.
259 * Also now uses make_path to prepend the pathnames.
261 * Revision 1.12 2001/06/05 20:04:09 jongfoster
262 * Now uses _snprintf() in place of snprintf() under Win32.
264 * Revision 1.11 2001/06/04 18:31:58 swa
265 * files are now prefixed with either `confdir' or `logdir'.
266 * `make redhat-dist' replaces both entries confdir and logdir
269 * Revision 1.10 2001/06/03 19:11:54 oes
270 * introduced confdir option
272 * Revision 1.9 2001/06/01 20:06:24 jongfoster
273 * Removed support for "tinygif" option - moved to actions file.
275 * Revision 1.8 2001/05/31 21:27:13 jongfoster
276 * Removed many options from the config file and into the
277 * "actions" file: add_forwarded, suppress_vanilla_wafer,
278 * wafer, add_header, user_agent, referer, from
279 * Also globally replaced "permission" with "action".
281 * Revision 1.7 2001/05/29 09:50:24 jongfoster
282 * Unified blocklist/imagelist/permissionslist.
283 * File format is still under discussion, but the internal changes
286 * Also modified interceptor behaviour:
287 * - We now intercept all URLs beginning with one of the following
288 * prefixes (and *only* these prefixes):
290 * * http://ijbswa.sf.net/config/
291 * * http://ijbswa.sourceforge.net/config/
292 * - New interceptors "home page" - go to http://i.j.b/ to see it.
293 * - Internal changes so that intercepted and fast redirect pages
294 * are not replaced with an image.
295 * - Interceptors now have the option to send a binary page direct
296 * to the client. (i.e. ijb-send-banner uses this)
297 * - Implemented show-url-info interceptor. (Which is why I needed
298 * the above interceptors changes - a typical URL is
299 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
300 * The previous mechanism would not have intercepted that, and
301 * if it had been intercepted then it then it would have replaced
304 * Revision 1.6 2001/05/26 00:28:36 jongfoster
305 * Automatic reloading of config file.
306 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
307 * Most of the global variables have been moved to a new
308 * struct configuration_spec, accessed through csp->config->globalname
309 * Most of the globals remaining are used by the Win32 GUI.
311 * Revision 1.5 2001/05/25 22:34:30 jongfoster
314 * Revision 1.4 2001/05/22 18:46:04 oes
316 * - Enabled filtering banners by size rather than URL
317 * by adding patterns that replace all standard banner
318 * sizes with the "Junkbuster" gif to the re_filterfile
320 * - Enabled filtering WebBugs by providing a pattern
321 * which kills all 1x1 images
323 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
324 * which is selected by the (nonstandard and therefore
325 * capital) letter 'U' in the option string.
326 * It causes the quantifiers to be ungreedy by default.
327 * Appending a ? turns back to greedy (!).
329 * - Added a new interceptor ijb-send-banner, which
330 * sends back the "Junkbuster" gif. Without imagelist or
331 * MSIE detection support, or if tinygif = 1, or the
332 * URL isn't recognized as an imageurl, a lame HTML
333 * explanation is sent instead.
335 * - Added new feature, which permits blocking remote
336 * script redirects and firing back a local redirect
338 * The feature is conditionally compiled, i.e. it
339 * can be disabled with --disable-fast-redirects,
340 * plus it must be activated by a "fast-redirects"
341 * line in the config file, has its own log level
342 * and of course wants to be displayed by show-proxy-args
343 * Note: Boy, all the #ifdefs in 1001 locations and
344 * all the fumbling with configure.in and acconfig.h
345 * were *way* more work than the feature itself :-(
347 * - Because a generic redirect template was needed for
348 * this, tinygif = 3 now uses the same.
350 * - Moved GIFs, and other static HTTP response templates
355 * - Removed some >400 CRs again (Jon, you really worked
358 * Revision 1.3 2001/05/20 01:21:20 jongfoster
359 * Version 2.9.4 checkin.
360 * - Merged popupfile and cookiefile, and added control over PCRS
361 * filtering, in new "permissionsfile".
362 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
363 * file error you now get a message box (in the Win32 GUI) rather
364 * than the program exiting with no explanation.
365 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
367 * - Removed tabs from "config"
368 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
369 * - Bumped up version number.
371 * Revision 1.2 2001/05/17 23:01:01 oes
372 * - Cleaned CRLF's from the sources and related files
374 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
375 * Initial import of version 2.9.3 source tree
378 *********************************************************************/
384 #include <sys/types.h>
398 # include <windows.h>
401 # ifndef _WIN_CONSOLE
403 # endif /* ndef _WIN_CONSOLE */
405 /* VC++ has "_snprintf", not "snprintf" */
406 #define snprintf _snprintf
408 #else /* ifndef _WIN32 */
412 # include <sys/wait.h>
414 # include <sys/time.h>
415 # include <sys/stat.h>
425 #include "miscutil.h"
429 #include "urlmatch.h"
432 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
435 * Fix a problem with Solaris. There should be no effect on other
437 * Solaris's isspace() is a macro which uses it's argument directly
438 * as an array index. Therefore we need to make sure that high-bit
439 * characters generate +ve values, and ideally we also want to make
440 * the argument match the declared parameter type of "int".
442 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
443 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
445 #ifdef FEATURE_TOGGLE
446 /* Privoxy is enabled by default. */
447 int global_toggle_state = 1;
448 #endif /* def FEATURE_TOGGLE */
450 /* The filename of the configfile */
451 const char *configfile = NULL;
454 * CGI functions will later need access to the invocation args,
455 * so we will make argc and argv global.
458 const char **Argv = NULL;
460 static struct file_list *current_configfile = NULL;
464 * This takes the "cryptic" hash of each keyword and aliases them to
465 * something a little more readable. This also makes changing the
466 * hash values easier if they should change or the hash algorthm changes.
467 * Use the included "hash" program to find out what the hash will be
468 * for any string supplied on the command line. (Or just put it in the
469 * config file and read the number from the error message in the log).
471 * Please keep this list sorted alphabetically (but with the Windows
472 * console and GUI specific options last).
475 #define hash_actions_file 1196306641ul /* "actionsfile" */
476 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
477 #define hash_admin_address 4112573064ul /* "admin-address" */
478 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
479 #define hash_confdir 1978389ul /* "confdir" */
480 #define hash_debug 78263ul /* "debug" */
481 #define hash_deny_access 1227333715ul /* "deny-access" */
482 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
483 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
484 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
485 #define hash_filterfile 250887266ul /* "filterfile" */
486 #define hash_forward 2029845ul /* "forward" */
487 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
488 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
489 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
490 #define hash_jarfile 2046641ul /* "jarfile" */
491 #define hash_listen_address 1255650842ul /* "listen-address" */
492 #define hash_logdir 422889ul /* "logdir" */
493 #define hash_logfile 2114766ul /* "logfile" */
494 #define hash_permit_access 3587953268ul /* "permit-access" */
495 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
496 #define hash_single_threaded 4250084780ul /* "single-threaded" */
497 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
498 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
499 #define hash_templdir 11067889ul /* "templdir" */
500 #define hash_toggle 447966ul /* "toggle" */
501 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
502 #define hash_trustfile 56494766ul /* "trustfile" */
503 #define hash_usermanual 1416668518ul /* "user-manual" */
504 #define hash_activity_animation 1817904738ul /* "activity-animation" */
505 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
506 #define hash_hide_console 2048809870ul /* "hide-console" */
507 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
508 #define hash_log_font_name 2866730124ul /* "log-font-name" */
509 #define hash_log_font_size 2866731014ul /* "log-font-size" */
510 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
511 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
512 #define hash_log_messages 2291744899ul /* "log-messages" */
513 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
516 static void savearg(char *command, char *argument, struct configuration_spec * config);
518 /*********************************************************************
520 * Function : unload_configfile
522 * Description : Free the config structure and all components.
525 * 1 : data: struct configuration_spec to unload
529 *********************************************************************/
530 void unload_configfile (void * data)
532 struct configuration_spec * config = (struct configuration_spec *)data;
533 struct forward_spec *cur_fwd = config->forward;
537 struct access_control_list *cur_acl = config->acl;
539 while (cur_acl != NULL)
541 struct access_control_list * next_acl = cur_acl->next;
546 #endif /* def FEATURE_ACL */
548 while (cur_fwd != NULL)
550 struct forward_spec * next_fwd = cur_fwd->next;
551 free_url_spec(cur_fwd->url);
553 freez(cur_fwd->gateway_host);
554 freez(cur_fwd->forward_host);
558 config->forward = NULL;
560 #ifdef FEATURE_COOKIE_JAR
561 if ( NULL != config->jar )
563 fclose( config->jar );
566 #endif /* def FEATURE_COOKIE_JAR */
568 freez(config->confdir);
569 freez(config->logdir);
570 freez(config->templdir);
572 freez(config->haddr);
573 freez(config->logfile);
575 for (i = 0; i < MAX_AF_FILES; i++)
577 freez(config->actions_file_short[i]);
578 freez(config->actions_file[i]);
579 freez(config->re_filterfile_short[i]);
580 freez(config->re_filterfile[i]);
583 freez(config->admin_address);
584 freez(config->proxy_info_url);
585 freez(config->proxy_args);
586 freez(config->usermanual);
588 #ifdef FEATURE_COOKIE_JAR
589 freez(config->jarfile);
590 #endif /* def FEATURE_COOKIE_JAR */
593 freez(config->trustfile);
594 list_remove_all(config->trust_info);
595 #endif /* def FEATURE_TRUST */
597 for (i = 0; i < MAX_AF_FILES; i++)
599 freez(config->re_filterfile[i]);
606 #ifdef FEATURE_GRACEFUL_TERMINATION
607 /*********************************************************************
609 * Function : unload_current_config_file
611 * Description : Unloads current config file - reset to state at
612 * beginning of program.
618 *********************************************************************/
619 void unload_current_config_file(void)
621 if (current_configfile)
623 current_configfile->unloader = unload_configfile;
624 current_configfile = NULL;
630 /*********************************************************************
632 * Function : load_config
634 * Description : Load the config file and all parameters.
638 * Returns : The configuration_spec, or NULL on error.
640 *********************************************************************/
641 struct configuration_spec * load_config(void)
643 char buf[BUFFER_SIZE];
645 FILE *configfp = NULL;
646 struct configuration_spec * config = NULL;
647 struct client_state * fake_csp;
648 struct file_list *fs;
649 unsigned long linenum = 0;
652 if ( !check_file_changed(current_configfile, configfile, &fs))
654 /* No need to load */
655 return ((struct configuration_spec *)current_configfile->f);
659 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
663 log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
665 #ifdef FEATURE_TOGGLE
666 global_toggle_state = 1;
667 #endif /* def FEATURE_TOGGLE */
669 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
675 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
676 /* Never get here - LOG_LEVEL_FATAL causes program exit */
680 * This is backwards from how it's usually done.
681 * Following the usual pattern, "fs" would be stored in a member
682 * variable in "csp", and then we'd access "config" from "fs->f",
683 * using a cast. However, "config" is used so often that a
684 * cast each time would be very ugly, and the extra indirection
685 * would waste CPU cycles. Therefore we store "config" in
686 * "csp->config", and "fs" in "csp->config->config_file_list".
688 config->config_file_list = fs;
693 config->multi_threaded = 1;
694 config->hport = HADDR_PORT;
695 config->buffer_limit = 4096 * 1024;
696 config->usermanual = strdup(USER_MANUAL_URL);
697 config->proxy_args = strdup("");
698 config->forwarded_connect_retries = 0;
699 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
700 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
701 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
703 if ((configfp = fopen(configfile, "r")) == NULL)
705 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
707 /* Never get here - LOG_LEVEL_FATAL causes program exit */
710 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
712 char cmd[BUFFER_SIZE];
713 char arg[BUFFER_SIZE];
714 char tmp[BUFFER_SIZE];
716 struct access_control_list *cur_acl;
717 #endif /* def FEATURE_ACL */
718 struct forward_spec *cur_fwd;
724 /* Copy command (i.e. up to space or tab) into cmd */
727 while (*p && (*p != ' ') && (*p != '\t'))
733 /* Skip over the whitespace in buf */
734 while (*p && ((*p == ' ') || (*p == '\t')))
739 /* Copy the argument into arg */
742 /* Should never happen, but check this anyway */
748 /* Make sure the command field is lower case */
753 *p = (char)ijb_tolower(*p);
757 /* Save the argument for show-proxy-args */
758 savearg(cmd, arg, config);
761 switch( hash_string( cmd ) )
763 /* *************************************************************************
764 * actionsfile actions-file-name
765 * In confdir by default
766 * *************************************************************************/
767 case hash_actions_file :
769 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
774 if (i >= MAX_AF_FILES)
776 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
777 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
780 config->actions_file_short[i] = strdup(arg);
781 p = malloc(strlen(arg) + sizeof(".action"));
784 log_error(LOG_LEVEL_FATAL, "Out of memory");
787 strcat(p, ".action");
788 config->actions_file[i] = make_path(config->confdir, p);
791 /* *************************************************************************
792 * accept-intercepted-requests
793 * *************************************************************************/
794 case hash_accept_intercepted_requests:
795 if ((*arg != '\0') && (0 != atoi(arg)))
797 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
801 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
805 /* *************************************************************************
806 * admin-address email-address
807 * *************************************************************************/
808 case hash_admin_address :
809 freez(config->admin_address);
810 config->admin_address = strdup(arg);
813 /* *************************************************************************
815 * *************************************************************************/
816 case hash_buffer_limit :
817 config->buffer_limit = (size_t)(1024 * atoi(arg));
820 /* *************************************************************************
821 * confdir directory-name
822 * *************************************************************************/
824 freez(config->confdir);
825 config->confdir = make_path( NULL, arg);
828 /* *************************************************************************
830 * Specifies debug level, multiple values are ORed together.
831 * *************************************************************************/
833 config->debug |= atoi(arg);
836 /* *************************************************************************
837 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
838 * *************************************************************************/
840 case hash_deny_access:
841 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
843 if ((vec_count != 1) && (vec_count != 2))
845 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
846 "deny-access directive in configuration file.");
847 string_append(&config->proxy_args,
848 "<br>\nWARNING: Wrong number of parameters for "
849 "deny-access directive in configuration file.<br><br>\n");
853 /* allocate a new node */
854 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
858 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
859 /* Never get here - LOG_LEVEL_FATAL causes program exit */
862 cur_acl->action = ACL_DENY;
864 if (acl_addr(vec[0], cur_acl->src) < 0)
866 log_error(LOG_LEVEL_ERROR, "Invalid source IP for deny-access "
867 "directive in configuration file: \"%s\"", vec[0]);
868 string_append(&config->proxy_args,
869 "<br>\nWARNING: Invalid source IP for deny-access directive"
870 " in configuration file: \"");
871 string_append(&config->proxy_args,
873 string_append(&config->proxy_args,
880 if (acl_addr(vec[1], cur_acl->dst) < 0)
882 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for deny-access "
883 "directive in configuration file: \"%s\"", vec[0]);
884 string_append(&config->proxy_args,
885 "<br>\nWARNING: Invalid destination IP for deny-access directive"
886 " in configuration file: \"");
887 string_append(&config->proxy_args,
889 string_append(&config->proxy_args,
897 * Add it to the list. Note we reverse the list to get the
898 * behaviour the user expects. With both the ACL and
899 * actions file, the last match wins. However, the internal
900 * implementations are different: The actions file is stored
901 * in the same order as the file, and scanned completely.
902 * With the ACL, we reverse the order as we load it, then
903 * when we scan it we stop as soon as we get a match.
905 cur_acl->next = config->acl;
906 config->acl = cur_acl;
909 #endif /* def FEATURE_ACL */
911 /* *************************************************************************
912 * enable-edit-actions 0|1
913 * *************************************************************************/
914 #ifdef FEATURE_CGI_EDIT_ACTIONS
915 case hash_enable_edit_actions:
916 if ((*arg != '\0') && (0 != atoi(arg)))
918 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
922 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
925 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
927 /* *************************************************************************
928 * enable-remote-toggle 0|1
929 * *************************************************************************/
930 #ifdef FEATURE_CGI_EDIT_ACTIONS
931 case hash_enable_remote_toggle:
932 if ((*arg != '\0') && (0 != atoi(arg)))
934 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
938 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
941 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
943 /* *************************************************************************
944 * enable-remote-http-toggle 0|1
945 * *************************************************************************/
946 case hash_enable_remote_http_toggle:
947 if ((*arg != '\0') && (0 != atoi(arg)))
949 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
953 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
957 /* *************************************************************************
958 * filterfile file-name
959 * In confdir by default.
960 * *************************************************************************/
961 case hash_filterfile :
963 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
968 if (i >= MAX_AF_FILES)
970 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
971 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
974 config->re_filterfile_short[i] = strdup(arg);
975 p = malloc(strlen(arg) + 1);
978 log_error(LOG_LEVEL_FATAL, "Out of memory");
981 config->re_filterfile[i] = make_path(config->confdir, p);
985 /* *************************************************************************
986 * forward url-pattern (.|http-proxy-host[:port])
987 * *************************************************************************/
989 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
993 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
994 "directive in configuration file.");
995 string_append(&config->proxy_args,
996 "<br>\nWARNING: Wrong number of parameters for "
997 "forward directive in configuration file.");
1001 /* allocate a new node */
1002 cur_fwd = zalloc(sizeof(*cur_fwd));
1003 if (cur_fwd == NULL)
1005 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1006 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1010 cur_fwd->type = SOCKS_NONE;
1012 /* Save the URL pattern */
1013 if (create_url_spec(cur_fwd->url, vec[0]))
1015 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1016 "directive in configuration file.");
1017 string_append(&config->proxy_args,
1018 "<br>\nWARNING: Bad URL specifier for "
1019 "forward directive in configuration file.");
1023 /* Parse the parent HTTP proxy host:port */
1026 if (strcmp(p, ".") != 0)
1028 cur_fwd->forward_host = strdup(p);
1030 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1033 cur_fwd->forward_port = atoi(p);
1036 if (cur_fwd->forward_port <= 0)
1038 cur_fwd->forward_port = 8000;
1043 cur_fwd->next = config->forward;
1044 config->forward = cur_fwd;
1048 /* *************************************************************************
1049 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1050 * *************************************************************************/
1051 case hash_forward_socks4:
1052 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1056 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1057 "forward-socks4 directive in configuration file.");
1058 string_append(&config->proxy_args,
1059 "<br>\nWARNING: Wrong number of parameters for "
1060 "forward-socks4 directive in configuration file.");
1064 /* allocate a new node */
1065 cur_fwd = zalloc(sizeof(*cur_fwd));
1066 if (cur_fwd == NULL)
1068 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1069 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1073 cur_fwd->type = SOCKS_4;
1075 /* Save the URL pattern */
1076 if (create_url_spec(cur_fwd->url, vec[0]))
1078 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1079 "directive in configuration file.");
1080 string_append(&config->proxy_args,
1081 "<br>\nWARNING: Bad URL specifier for "
1082 "forward-socks4 directive in configuration file.");
1086 /* Parse the SOCKS proxy host[:port] */
1089 if (strcmp(p, ".") != 0)
1091 cur_fwd->gateway_host = strdup(p);
1093 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1096 cur_fwd->gateway_port = atoi(p);
1098 if (cur_fwd->gateway_port <= 0)
1100 cur_fwd->gateway_port = 1080;
1104 /* Parse the parent HTTP proxy host[:port] */
1107 if (strcmp(p, ".") != 0)
1109 cur_fwd->forward_host = strdup(p);
1111 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1114 cur_fwd->forward_port = atoi(p);
1117 if (cur_fwd->forward_port <= 0)
1119 cur_fwd->forward_port = 8000;
1124 cur_fwd->next = config->forward;
1125 config->forward = cur_fwd;
1129 /* *************************************************************************
1130 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1131 * *************************************************************************/
1132 case hash_forward_socks4a:
1133 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1137 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1138 "forward-socks4a directive in configuration file.");
1139 string_append(&config->proxy_args,
1140 "<br>\nWARNING: Wrong number of parameters for "
1141 "forward-socks4a directive in configuration file.");
1145 /* allocate a new node */
1146 cur_fwd = zalloc(sizeof(*cur_fwd));
1147 if (cur_fwd == NULL)
1149 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1150 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1154 cur_fwd->type = SOCKS_4A;
1156 /* Save the URL pattern */
1157 if (create_url_spec(cur_fwd->url, vec[0]))
1159 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1160 "directive in configuration file.");
1161 string_append(&config->proxy_args,
1162 "<br>\nWARNING: Bad URL specifier for "
1163 "forward-socks4a directive in configuration file.");
1167 /* Parse the SOCKS proxy host[:port] */
1170 cur_fwd->gateway_host = strdup(p);
1172 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1175 cur_fwd->gateway_port = atoi(p);
1177 if (cur_fwd->gateway_port <= 0)
1179 cur_fwd->gateway_port = 1080;
1182 /* Parse the parent HTTP proxy host[:port] */
1185 if (strcmp(p, ".") != 0)
1187 cur_fwd->forward_host = strdup(p);
1189 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1192 cur_fwd->forward_port = atoi(p);
1195 if (cur_fwd->forward_port <= 0)
1197 cur_fwd->forward_port = 8000;
1202 cur_fwd->next = config->forward;
1203 config->forward = cur_fwd;
1207 /* *************************************************************************
1208 * forwarded-connect-retries n
1209 * *************************************************************************/
1210 case hash_forwarded_connect_retries :
1211 config->forwarded_connect_retries = atoi(arg);
1214 /* *************************************************************************
1215 * jarfile jar-file-name
1216 * In logdir by default
1217 * *************************************************************************/
1218 #ifdef FEATURE_COOKIE_JAR
1220 freez(config->jarfile);
1221 config->jarfile = make_path(config->logdir, arg);
1223 #endif /* def FEATURE_COOKIE_JAR */
1225 /* *************************************************************************
1226 * listen-address [ip][:port]
1227 * *************************************************************************/
1228 case hash_listen_address :
1229 freez(config->haddr);
1230 config->haddr = strdup(arg);
1233 /* *************************************************************************
1234 * logdir directory-name
1235 * *************************************************************************/
1237 freez(config->logdir);
1238 config->logdir = make_path(NULL, arg);
1241 /* *************************************************************************
1242 * logfile log-file-name
1243 * In logdir by default
1244 * *************************************************************************/
1246 freez(config->logfile);
1247 config->logfile = no_daemon ? NULL : make_path(config->logdir, arg);
1250 /* *************************************************************************
1251 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1252 * *************************************************************************/
1254 case hash_permit_access:
1255 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1257 if ((vec_count != 1) && (vec_count != 2))
1259 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1260 "permit-access directive in configuration file.");
1261 string_append(&config->proxy_args,
1262 "<br>\nWARNING: Wrong number of parameters for "
1263 "permit-access directive in configuration file.<br><br>\n");
1268 /* allocate a new node */
1269 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1271 if (cur_acl == NULL)
1273 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1274 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1277 cur_acl->action = ACL_PERMIT;
1279 if (acl_addr(vec[0], cur_acl->src) < 0)
1281 log_error(LOG_LEVEL_ERROR, "Invalid source IP for permit-access "
1282 "directive in configuration file: \"%s\"", vec[0]);
1283 string_append(&config->proxy_args,
1284 "<br>\nWARNING: Invalid source IP for permit-access directive"
1285 " in configuration file: \"");
1286 string_append(&config->proxy_args,
1288 string_append(&config->proxy_args,
1295 if (acl_addr(vec[1], cur_acl->dst) < 0)
1297 log_error(LOG_LEVEL_ERROR, "Invalid destination IP for "
1298 "permit-access directive in configuration file: \"%s\"",
1300 string_append(&config->proxy_args,
1301 "<br>\nWARNING: Invalid destination IP for permit-access directive"
1302 " in configuration file: \"");
1303 string_append(&config->proxy_args,
1305 string_append(&config->proxy_args,
1313 * Add it to the list. Note we reverse the list to get the
1314 * behaviour the user expects. With both the ACL and
1315 * actions file, the last match wins. However, the internal
1316 * implementations are different: The actions file is stored
1317 * in the same order as the file, and scanned completely.
1318 * With the ACL, we reverse the order as we load it, then
1319 * when we scan it we stop as soon as we get a match.
1321 cur_acl->next = config->acl;
1322 config->acl = cur_acl;
1325 #endif /* def FEATURE_ACL */
1327 /* *************************************************************************
1328 * proxy-info-url url
1329 * *************************************************************************/
1330 case hash_proxy_info_url :
1331 freez(config->proxy_info_url);
1332 config->proxy_info_url = strdup(arg);
1335 /* *************************************************************************
1337 * *************************************************************************/
1338 case hash_single_threaded :
1339 config->multi_threaded = 0;
1342 /* *************************************************************************
1343 * split-large-cgi-forms
1344 * *************************************************************************/
1345 case hash_split_large_cgi_forms :
1346 if ((*arg != '\0') && (0 != atoi(arg)))
1348 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1352 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1356 /* *************************************************************************
1357 * templdir directory-name
1358 * *************************************************************************/
1359 case hash_templdir :
1360 freez(config->templdir);
1361 config->templdir = make_path(NULL, arg);
1364 /* *************************************************************************
1366 * *************************************************************************/
1367 #ifdef FEATURE_TOGGLE
1369 global_toggle_state = atoi(arg);
1371 #endif /* def FEATURE_TOGGLE */
1373 /* *************************************************************************
1374 * trust-info-url url
1375 * *************************************************************************/
1376 #ifdef FEATURE_TRUST
1377 case hash_trust_info_url :
1378 enlist(config->trust_info, arg);
1380 #endif /* def FEATURE_TRUST */
1382 /* *************************************************************************
1383 * trustfile filename
1384 * (In confdir by default.)
1385 * *************************************************************************/
1386 #ifdef FEATURE_TRUST
1387 case hash_trustfile :
1388 freez(config->trustfile);
1389 config->trustfile = make_path(config->confdir, arg);
1391 #endif /* def FEATURE_TRUST */
1393 /* *************************************************************************
1395 * *************************************************************************/
1396 case hash_usermanual :
1397 freez(config->usermanual);
1398 config->usermanual = strdup(arg);
1401 /* *************************************************************************
1402 * Win32 Console options:
1403 * *************************************************************************/
1405 /* *************************************************************************
1407 * *************************************************************************/
1409 case hash_hide_console :
1412 #endif /*def _WIN_CONSOLE*/
1415 /* *************************************************************************
1416 * Win32 GUI options:
1417 * *************************************************************************/
1419 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1420 /* *************************************************************************
1421 * activity-animation (0|1)
1422 * *************************************************************************/
1423 case hash_activity_animation :
1424 g_bShowActivityAnimation = atoi(arg);
1427 /* *************************************************************************
1428 * close-button-minimizes (0|1)
1429 * *************************************************************************/
1430 case hash_close_button_minimizes :
1431 g_bCloseHidesWindow = atoi(arg);
1434 /* *************************************************************************
1435 * log-buffer-size (0|1)
1436 * *************************************************************************/
1437 case hash_log_buffer_size :
1438 g_bLimitBufferSize = atoi(arg);
1441 /* *************************************************************************
1442 * log-font-name fontnane
1443 * *************************************************************************/
1444 case hash_log_font_name :
1445 strcpy( g_szFontFaceName, arg );
1448 /* *************************************************************************
1450 * *************************************************************************/
1451 case hash_log_font_size :
1452 g_nFontSize = atoi(arg);
1455 /* *************************************************************************
1456 * log-highlight-messages (0|1)
1457 * *************************************************************************/
1458 case hash_log_highlight_messages :
1459 g_bHighlightMessages = atoi(arg);
1462 /* *************************************************************************
1464 * *************************************************************************/
1465 case hash_log_max_lines :
1466 g_nMaxBufferLines = atoi(arg);
1469 /* *************************************************************************
1470 * log-messages (0|1)
1471 * *************************************************************************/
1472 case hash_log_messages :
1473 g_bLogMessages = atoi(arg);
1476 /* *************************************************************************
1477 * show-on-task-bar (0|1)
1478 * *************************************************************************/
1479 case hash_show_on_task_bar :
1480 g_bShowOnTaskBar = atoi(arg);
1483 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1486 /* *************************************************************************
1487 * Warnings about unsupported features
1488 * *************************************************************************/
1490 case hash_deny_access:
1491 #endif /* ndef FEATURE_ACL */
1492 #ifndef FEATURE_CGI_EDIT_ACTIONS
1493 case hash_enable_edit_actions:
1494 case hash_enable_remote_toggle:
1495 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1496 #ifndef FEATURE_COOKIE_JAR
1498 #endif /* ndef FEATURE_COOKIE_JAR */
1500 case hash_permit_access:
1501 #endif /* ndef FEATURE_ACL */
1502 #ifndef FEATURE_TOGGLE
1504 #endif /* ndef FEATURE_TOGGLE */
1505 #ifndef FEATURE_TRUST
1506 case hash_trustfile :
1507 case hash_trust_info_url :
1508 #endif /* ndef FEATURE_TRUST */
1510 #ifndef _WIN_CONSOLE
1511 case hash_hide_console :
1512 #endif /* ndef _WIN_CONSOLE */
1514 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1515 case hash_activity_animation :
1516 case hash_close_button_minimizes :
1517 case hash_log_buffer_size :
1518 case hash_log_font_name :
1519 case hash_log_font_size :
1520 case hash_log_highlight_messages :
1521 case hash_log_max_lines :
1522 case hash_log_messages :
1523 case hash_show_on_task_bar :
1524 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1525 /* These warnings are annoying - so hide them. -- Jon */
1526 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1529 /* *************************************************************************/
1531 /* *************************************************************************/
1533 * I decided that I liked this better as a warning than an
1534 * error. To change back to an error, just change log level
1535 * to LOG_LEVEL_FATAL.
1537 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1538 "in configuration file (%s).", buf, hash_string(cmd), linenum, configfile);
1539 string_append(&config->proxy_args,
1540 " <b><font color=\"red\">WARNING: unrecognized directive, ignored</font></b>");
1543 /* *************************************************************************/
1544 } /* end switch( hash_string(cmd) ) */
1545 } /* end while ( read_config_line(...) ) */
1549 if (NULL == config->proxy_args)
1551 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1554 init_error_log(Argv[0], config->logfile, config->debug);
1556 if (config->actions_file[0])
1558 add_loader(load_actions_file, config);
1561 if (config->re_filterfile)
1563 add_loader(load_re_filterfile, config);
1566 #ifdef FEATURE_TRUST
1567 if (config->trustfile)
1569 add_loader(load_trustfile, config);
1571 #endif /* def FEATURE_TRUST */
1573 #ifdef FEATURE_COOKIE_JAR
1574 if ( NULL != config->jarfile )
1576 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1578 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1579 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1581 setbuf(config->jar, NULL);
1583 #endif /* def FEATURE_COOKIE_JAR */
1585 if ( NULL == config->haddr )
1587 config->haddr = strdup( HADDR_DEFAULT );
1590 if ( NULL != config->haddr )
1592 if (NULL != (p = strchr(config->haddr, ':')))
1597 config->hport = atoi(p);
1601 if (config->hport <= 0)
1604 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1605 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1607 if (*config->haddr == '\0')
1609 config->haddr = NULL;
1614 * Want to run all the loaders once now.
1616 * Need to set up a fake csp, so they can get to the config.
1618 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1619 fake_csp->config = config;
1621 if (run_loader(fake_csp))
1624 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1625 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1629 /* FIXME: this is a kludge for win32 */
1630 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1632 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1633 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1634 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1636 #ifdef FEATURE_TRUST
1637 g_trustfile = config->trustfile;
1638 #endif /* def FEATURE_TRUST */
1641 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1642 /* FIXME: end kludge */
1645 config->need_bind = 1;
1647 if (current_configfile)
1649 struct configuration_spec * oldcfg = (struct configuration_spec *)
1650 current_configfile->f;
1652 * Check if config->haddr,hport == oldcfg->haddr,hport
1654 * The following could be written more compactly as a single,
1655 * (unreadably long) if statement.
1657 config->need_bind = 0;
1658 if (config->hport != oldcfg->hport)
1660 config->need_bind = 1;
1662 else if (config->haddr == NULL)
1664 if (oldcfg->haddr != NULL)
1666 config->need_bind = 1;
1669 else if (oldcfg->haddr == NULL)
1671 config->need_bind = 1;
1673 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1675 config->need_bind = 1;
1678 current_configfile->unloader = unload_configfile;
1681 fs->next = files->next;
1684 current_configfile = fs;
1690 /*********************************************************************
1692 * Function : savearg
1694 * Description : Called from `load_config'. It saves each non-empty
1695 * and non-comment line from config into
1696 * config->proxy_args. This is used to create the
1697 * show-proxy-args page. On error, frees
1698 * config->proxy_args and sets it to NULL
1701 * 1 : command = config setting that was found
1702 * 2 : argument = the setting's argument (if any)
1703 * 3 : config = Configuration to save into.
1707 *********************************************************************/
1708 static void savearg(char *command, char *argument, struct configuration_spec * config)
1718 * Add config option name embedded in
1719 * link to it's section in the user-manual
1721 buf = strdup("\n<a href=\"");
1722 if (!strncmpic(config->usermanual, "file://", 7) ||
1723 !strncmpic(config->usermanual, "http", 4))
1725 string_append(&buf, config->usermanual);
1729 string_append(&buf, "http://");
1730 string_append(&buf, CGI_SITE_2_HOST);
1731 string_append(&buf, "/user-manual/");
1733 string_append(&buf, CONFIG_HELP_PREFIX);
1734 string_join (&buf, string_toupper(command));
1735 string_append(&buf, "\">");
1736 string_append(&buf, command);
1737 string_append(&buf, "</a> ");
1741 freez(config->proxy_args);
1745 if ( (NULL != argument) && ('\0' != *argument) )
1747 s = html_encode(argument);
1751 freez(config->proxy_args);
1755 if (strncmpic(argument, "http://", 7) == 0)
1757 string_append(&buf, "<a href=\"");
1758 string_append(&buf, s);
1759 string_append(&buf, "\">");
1760 string_join (&buf, s);
1761 string_append(&buf, "</a>");
1765 string_join (&buf, s);
1769 string_append(&buf, "<br>");
1770 string_join(&config->proxy_args, buf);