1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.2 2001/05/17 23:01:01 oes 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.2 2001/05/17 23:01:01 oes
39 * - Cleaned CRLF's from the sources and related files
41 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
42 * Initial import of version 2.9.3 source tree
45 *********************************************************************/
51 #include <sys/types.h>
61 # include <sys/timeb.h>
67 # endif /* def TOGGLE */
72 # endif /* ndef _WIN_CONSOLE */
74 #else /* ifndef _WIN32 */
77 # include <sys/time.h>
78 # include <sys/wait.h>
79 # include <sys/stat.h>
90 #include "killpopup.h"
93 #include "jbsockets.h"
96 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
99 * Fix a problem with Solaris. There should be no effect on other
101 * Solaris's isspace() is a macro which uses it's argument directly
102 * as an array index. Therefore we need to make sure that high-bit
103 * characters generate +ve values, and ideally we also want to make
104 * the argument match the declared parameter type of "int".
106 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
107 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
109 static const char VANILLA_WAFER[] =
110 "NOTICE=TO_WHOM_IT_MAY_CONCERN_"
111 "Do_not_send_me_any_copyrighted_information_other_than_the_"
112 "document_that_I_am_requesting_or_any_of_its_necessary_components._"
113 "In_particular_do_not_send_me_any_cookies_that_"
114 "are_subject_to_a_claim_of_copyright_by_anybody._"
115 "Take_notice_that_I_refuse_to_be_bound_by_any_license_condition_"
116 "(copyright_or_otherwise)_applying_to_any_cookie._";
119 /* by haroon - indicates if ijb is enabled */
120 int g_bToggleIJB = 1; /* JunkBusters is enabled by default. */
124 int multi_threaded = 1;
126 #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
128 const char *tinygifurl = NULL;
129 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
131 const char *logfile = NULL;
133 const char *configfile = NULL;
135 const char *blockfile = NULL;
136 const char *permissions_file = NULL;
137 const char *forwardfile = NULL;
140 const char *aclfile = NULL;
141 #endif /* def ACL_FILES */
143 #ifdef USE_IMAGE_LIST
144 const char *imagefile = NULL;
145 #endif /* def USE_IMAGE_LIST */
148 * Permissions to use for URLs not in the permissions list.
\r
150 int default_permissions = PERMIT_RE_FILTER;
\r
153 const char *re_filterfile = NULL;
154 #endif /* def PCRS */
157 const char *trustfile = NULL;
158 #endif /* def TRUST_FILES */
161 const char *jarfile = NULL;
163 #endif /* def JAR_FILES */
165 const char *referrer = NULL;
166 const char *uagent = NULL;
167 const char *from = NULL;
169 #ifndef SPLIT_PROXY_ARGS
170 const char *suppress_message = NULL;
171 #endif /* ndef SPLIT_PROXY_ARGS */
173 int suppress_vanilla_wafer = 0;
174 int add_forwarded = 0;
176 struct list wafer_list[1];
177 struct list xtra_list[1];
180 struct list trust_info[1];
181 struct url_spec *trust_list[64];
182 #endif /* def TRUST_FILES */
185 * Port and IP to bind to.
186 * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000
188 const char *haddr = NULL;
191 #ifndef SPLIT_PROXY_ARGS
192 int suppress_blocklists = 0; /* suppress listing sblock and simage */
193 #endif /* ndef SPLIT_PROXY_ARGS */
195 struct proxy_args proxy_args[1];
198 int config_changed = 0;
202 * The load_config function is now going to call `init_proxy_args',
203 * so it will need argc and argv. Since load_config will also be
204 * a signal handler, we need to have these globally available.
207 const char **Argv = NULL;
211 * This takes the "cryptic" hash of each keyword and aliases them to
212 * something a little more readable. This also makes changing the
213 * hash values easier if they should change or the hash algorthm changes.
214 * Use the included "hash" program to find out what the hash will be
215 * for any string supplied on the command line. (Or just put it in the
\r
216 * config file and read the number from the error message in the log).
219 #define hash_trustfile 56494766ul
220 #define hash_trust_info_url 449869467ul
221 #define hash_debug 78263ul
222 #define hash_tinygif 2227702ul
223 #define hash_add_forwarded_header 3191044770ul
224 #define hash_single_threaded 4250084780ul
225 #define hash_suppress_vanilla_wafer 3121233547ul
226 #define hash_wafer 89669ul
227 #define hash_add_header 237434619ul
228 #define hash_permissions_file 3825730796lu /* "permissionsfile" */
\r
229 #define hash_logfile 2114766ul
230 #define hash_blockfile 48845391ul
231 #define hash_imagefile 51447891ul
232 #define hash_jarfile 2046641ul
233 #define hash_listen_address 1255650842ul
234 #define hash_forwardfile 1268669141ul
235 #define hash_aclfile 1908516ul
236 #define hash_re_filterfile 3877522444ul
237 #define hash_user_agent 283326691ul
238 #define hash_referrer 10883969ul
239 #define hash_referer 2176719ul
240 #define hash_from 16264ul
241 #define hash_hide_console 2048809870ul
242 #define hash_include_stats 2174146548ul
243 #define hash_suppress_blocklists 1948693308ul
244 #define hash_toggle 447966ul
246 #define hash_activity_animation 1817904738ul
247 #define hash_log_messages 2291744899ul
248 #define hash_log_highlight_messages 4032101240ul
249 #define hash_log_buffer_size 2918070425ul
250 #define hash_log_max_lines 2868344173ul
251 #define hash_log_font_name 2866730124ul
252 #define hash_log_font_size 2866731014ul
253 #define hash_show_on_task_bar 215410365ul
254 #define hash_close_button_minimizes 3651284693ul
257 /*********************************************************************
259 * Function : load_config
261 * Description : Load the config file and all parameters.
264 * 1 : signum : this can be the signal SIGHUP or 0 (if from main).
265 * In any case, we just ignore this and reload the config file.
267 * Returns : configret : 0 => Ok, everything else is an error.
268 * Note: we use configret since a signal handler cannot
269 * return a value, and this function does double duty.
270 * Ie. Is is called from main and from signal( SIGHUP );
\r
272 *********************************************************************/
273 void load_config( int signum )
277 FILE *configfp = NULL;
279 configret = 0; /* FIXME: This is obsolete, always 0. */
282 log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
284 init_proxy_args(Argc, Argv);
287 /* (Waste of memory [not quite a "leak"] here. The
288 * last blockfile/permissions file/... etc will not be
289 * unloaded until we load a new one. If the
290 * block/... feature has been disabled in
291 * the new config file, then we're wasting some
292 * memory we could otherwise reclaim.
295 /* Disable all loaders. */
296 remove_all_loaders();
299 * Reset to as close to startup state as we can.
300 * But leave changing the logfile until after we're done loading.
309 #endif /* def JAR_FILES */
312 multi_threaded = 1;
\r
314 default_permissions = PERMIT_RE_FILTER;
316 #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
318 freez((char *)tinygifurl);
319 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
321 suppress_vanilla_wafer = 0;
327 #endif /*def _WIN_CONSOLE*/
336 #endif /* def STATISTICS */
338 #ifndef SPLIT_PROXY_ARGS
339 suppress_blocklists = 0;
340 #endif /* ndef SPLIT_PROXY_ARGS */
343 freez((char *)haddr);
344 freez((char *)uagent);
345 freez((char *)referrer);
346 freez((char *)logfile);
349 freez((char *)blockfile);
350 freez((char *)permissions_file);
351 freez((char *)forwardfile);
354 freez((char *)aclfile);
355 #endif /* def ACL_FILES */
357 #ifdef USE_IMAGE_LIST
358 freez((char *)imagefile);
359 #endif /* def USE_IMAGE_LIST */
362 freez((char *)jarfile);
363 #endif /* def JAR_FILES */
365 #ifndef SPLIT_PROXY_ARGS
366 freez((char *)suppress_message);
367 #endif /* ndef SPLIT_PROXY_ARGS */
370 freez((char *)trustfile);
371 #endif /* def TRUST_FILES */
374 freez((char *)re_filterfile);
375 #endif /* def PCRS */
377 if (NULL != configfile)
379 if ((configfp = fopen(configfile, "r")) == NULL)
381 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
383 /* Never get here - LOG_LEVEL_FATAL causes program exit */
\r
387 if (NULL != configfp)
389 memset (buf, 'j', sizeof(buf));
390 while (read_config_line(buf, sizeof(buf), configfp, NULL) != NULL)
398 /* Copy command (i.e. up to space or tab) into cmd */
401 while (*p && (*p != ' ') && (*p != '\t'))
407 /* Skip over the whitespace in buf */
408 while (*p && ((*p == ' ') || (*p == '\t')))
413 /* Copy the argument into arg */
416 /* Should never happen, but check this anyway */
422 /* Make sure the command field is lower case */
427 *p = ijb_tolower(*p);
431 /* Save the argument for show-proxy-args */
435 switch( hash_string( cmd ) )
438 case hash_trustfile :
439 freez((char *)trustfile);
440 trustfile = strdup(arg);
443 case hash_trust_info_url :
444 enlist(trust_info, arg);
446 #endif /* def TRUST_FILES */
452 #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
454 freez((char *)tinygifurl);
459 while((*p >= '0') && (*p <= '9'))
463 while((*p == ' ') || (*p == '\t'))
469 q = malloc(strlen(p) + 5);
473 strcat(q, "\r\n\r\n");
478 if ((tinygif != 1) &&
480 ((tinygif != 3) || (tinygifurl==NULL)) )
482 log_error(LOG_LEVEL_ERROR, "tinygif setting invalid.");
485 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
487 case hash_add_forwarded_header :
491 case hash_single_threaded :
495 case hash_suppress_vanilla_wafer :
496 suppress_vanilla_wafer = 1;
500 enlist(wafer_list, arg);
503 case hash_add_header :
504 enlist(xtra_list, arg);
507 case hash_permissions_file :
508 freez((char *)permissions_file);
509 permissions_file = strdup(arg);
513 freez((char *)logfile);
514 logfile = strdup(arg);
517 case hash_blockfile :
518 freez((char *)blockfile);
519 blockfile = strdup(arg);
522 #ifdef USE_IMAGE_LIST
523 case hash_imagefile :
524 freez((char *)imagefile);
525 imagefile = strdup(arg);
527 #endif /* def USE_IMAGE_LIST */
531 freez((char *)jarfile);
532 jarfile = strdup(arg);
534 #endif /* def JAR_FILES */
536 case hash_listen_address :
537 freez((char *)haddr);
541 case hash_forwardfile :
542 freez((char *)forwardfile);
543 forwardfile = strdup(arg);
548 freez((char *)aclfile);
549 aclfile = strdup(arg);
551 #endif /* def ACL_FILES */
554 case hash_re_filterfile :
555 freez((char *)re_filterfile);
556 re_filterfile = strdup(arg);
558 #endif /* def PCRS */
560 case hash_user_agent :
561 freez((char *)uagent);
562 uagent = strdup(arg);
566 * Offer choice of correct spelling according to dictionary,
567 * or the misspelling used in the HTTP spec.
571 freez((char *)referrer);
572 referrer = strdup(arg);
581 case hash_hide_console :
584 #endif /*def _WIN_CONSOLE*/
586 #ifndef SPLIT_PROXY_ARGS
587 case hash_suppress_blocklists :
590 suppress_message = strdup(arg);
594 /* There will be NO reference in proxy-args. */
595 suppress_message = NULL;
598 suppress_blocklists = 1;
600 #endif /* ndef SPLIT_PROXY_ARGS */
604 g_bToggleIJB = atoi(arg);
606 #endif /* def TOGGLE */
608 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
609 case hash_activity_animation :
610 g_bShowActivityAnimation = atoi(arg);
613 case hash_log_messages :
614 g_bLogMessages = atoi(arg);
617 case hash_log_highlight_messages :
618 g_bHighlightMessages = atoi(arg);
621 case hash_log_buffer_size :
622 g_bLimitBufferSize = atoi(arg);
625 case hash_log_max_lines :
626 g_nMaxBufferLines = atoi(arg);
629 case hash_log_font_name :
630 strcpy( g_szFontFaceName, arg );
633 case hash_log_font_size :
634 g_nFontSize = atoi(arg);
637 case hash_show_on_task_bar :
638 g_bShowOnTaskBar = atoi(arg);
641 case hash_close_button_minimizes :
642 g_bCloseHidesWindow = atoi(arg);
644 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
646 /* Warnings about unsupported features */
649 case hash_trustfile :
650 case hash_trust_info_url :
651 #endif /* ndef TRUST_FILES */
652 #ifndef USE_IMAGE_LIST
653 case hash_imagefile :
654 #endif /* ndef USE_IMAGE_LIST */
656 case hash_re_filterfile :
657 #endif /* ndef PCRS */
660 #endif /* ndef TOGGLE */
661 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
662 case hash_activity_animation :
663 case hash_log_messages :
664 case hash_log_highlight_messages :
665 case hash_log_buffer_size :
666 case hash_log_max_lines :
667 case hash_log_font_name :
668 case hash_log_font_size :
669 case hash_show_on_task_bar :
670 case hash_close_button_minimizes :
671 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
673 case hash_hide_console :
674 #endif /* ndef _WIN_CONSOLE */
675 #if !defined(DETECT_MSIE_IMAGES) && !defined(USE_IMAGE_LIST)
677 #endif /* !defined(DETECT_MSIE_IMAGES) && !defined(USE_IMAGE_LIST) */
680 #endif /* ndef JAR_FILES */
683 #endif /* ndef ACL_FILES */
685 #ifdef SPLIT_PROXY_ARGS
686 case hash_suppress_blocklists :
687 #endif /* def SPLIT_PROXY_ARGS */
688 log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd);
693 * I decided that I liked this better as a warning than an
\r
694 * error. To change back to an error, just change log level
\r
695 * to LOG_LEVEL_FATAL.
\r
697 log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%lulu) in "
698 "configuration file: \"%s\"", hash_string( cmd ), buf);
699 p = malloc( BUFSIZ );
702 sprintf( p, "<br>\nWARNING: unrecognized directive : %s<br><br>\n", buf );
703 proxy_args->invocation = strsav( proxy_args->invocation, p );
712 init_error_log(Argv[0], logfile, debug);
714 if (permissions_file)
716 add_loader(load_permissions_file);
721 add_loader(load_blockfile);
724 #ifdef USE_IMAGE_LIST
727 add_loader(load_imagefile);
729 #endif /* def USE_IMAGE_LIST */
734 add_loader(load_trustfile);
736 #endif /* def TRUST_FILES */
740 add_loader(load_forwardfile);
746 add_loader(load_aclfile);
748 #endif /* def ACL_FILES */
753 add_loader(load_re_filterfile);
755 #endif /* def PCRS */
758 if ( NULL != jarfile )
760 if ( NULL == (jar = fopen(jarfile, "a")) )
762 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", jarfile);
763 /* Never get here - LOG_LEVEL_FATAL causes program exit */
767 #endif /* def JAR_FILES */
771 haddr = strdup( HADDR_DEFAULT );
776 if ((p = strchr(haddr, ':')))
788 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", haddr);
789 /* Never get here - LOG_LEVEL_FATAL causes program exit */
\r
797 if (run_loader(NULL))
799 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
\r
800 /* Never get here - LOG_LEVEL_FATAL causes program exit */
\r
805 * If we're logging cookies in a cookie jar, and the user has not
806 * supplied any wafers, and the user has not told us to suppress the
807 * vanilla wafer, then send the vanilla wafer.
809 if ((jarfile != NULL)
810 && (wafer_list->next == NULL)
811 && (suppress_vanilla_wafer == 0))
813 enlist(wafer_list, VANILLA_WAFER);
815 #endif /* def JAR_FILES */