1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.1 2001/05/13 21:57:06 administrator Exp $";
2 /*********************************************************************
4 * File : $Source: /home/administrator/cvs/ijb/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.
39 *********************************************************************/
45 #include <sys/types.h>
55 # include <sys/timeb.h>
61 # endif /* def TOGGLE */
66 # endif /* ndef _WIN_CONSOLE */
68 #else /* ifndef _WIN32 */
71 # include <sys/time.h>
72 # include <sys/wait.h>
73 # include <sys/stat.h>
84 #include "killpopup.h"
87 #include "jbsockets.h"
90 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
93 * Fix a problem with Solaris. There should be no effect on other
95 * Solaris's isspace() is a macro which uses it's argument directly
96 * as an array index. Therefore we need to make sure that high-bit
97 * characters generate +ve values, and ideally we also want to make
98 * the argument match the declared parameter type of "int".
100 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
101 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
103 static const char VANILLA_WAFER[] =
104 "NOTICE=TO_WHOM_IT_MAY_CONCERN_"
105 "Do_not_send_me_any_copyrighted_information_other_than_the_"
106 "document_that_I_am_requesting_or_any_of_its_necessary_components._"
107 "In_particular_do_not_send_me_any_cookies_that_"
108 "are_subject_to_a_claim_of_copyright_by_anybody._"
109 "Take_notice_that_I_refuse_to_be_bound_by_any_license_condition_"
110 "(copyright_or_otherwise)_applying_to_any_cookie._";
113 /* by haroon - indicates if ijb is enabled */
114 int g_bToggleIJB = 1; /* JunkBusters is enabled by default. */
118 int multi_threaded = 1;
120 #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
122 const char *tinygifurl = NULL;
\r
123 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
125 const char *logfile = NULL;
127 const char *configfile = NULL;
129 const char *blockfile = NULL;
130 const char *cookiefile = NULL;
131 const char *forwardfile = NULL;
134 const char *aclfile = NULL;
135 #endif /* def ACL_FILES */
137 #ifdef USE_IMAGE_LIST
138 const char *imagefile = NULL;
139 #endif /* def USE_IMAGE_LIST */
142 const char *popupfile = NULL;
143 int kill_all_popups = 0; /* Not recommended really ... */
144 #endif /* def KILLPOPUPS */
147 const char *re_filterfile = NULL;
148 int re_filter_all = 0;
149 #endif /* def PCRS */
152 const char *trustfile = NULL;
153 #endif /* def TRUST_FILES */
156 const char *jarfile = NULL;
158 #endif /* def JAR_FILES */
160 const char *referrer = NULL;
161 const char *uagent = NULL;
162 const char *from = NULL;
164 #ifndef SPLIT_PROXY_ARGS
165 const char *suppress_message = NULL;
166 #endif /* ndef SPLIT_PROXY_ARGS */
168 int suppress_vanilla_wafer = 0;
169 int add_forwarded = 0;
171 struct list wafer_list[1];
172 struct list xtra_list[1];
175 struct list trust_info[1];
176 struct url_spec *trust_list[64];
177 #endif /* def TRUST_FILES */
180 * Port and IP to bind to.
181 * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000
183 const char *haddr = NULL;
186 #ifndef SPLIT_PROXY_ARGS
187 int suppress_blocklists = 0; /* suppress listing sblock and simage */
188 #endif /* ndef SPLIT_PROXY_ARGS */
190 struct proxy_args proxy_args[1];
193 int config_changed = 0;
197 * The load_config function is now going to call `init_proxy_args',
198 * so it will need argc and argv. Since load_config will also be
199 * a signal handler, we need to have these globally available.
202 const char **Argv = NULL;
206 * This takes the "cryptic" hash of each keyword and aliases them to
207 * something a little more readable. This also makes changing the
208 * hash values easier if they should change or the hash algorthm changes.
209 * Use the included "hash" program to find out what the hash will be
210 * for any string supplied on the command line.
213 #define hash_trustfile 56494766ul
214 #define hash_trust_info_url 449869467ul
215 #define hash_debug 78263ul
216 #define hash_tinygif 2227702ul
217 #define hash_add_forwarded_header 3191044770ul
218 #define hash_single_threaded 4250084780ul
219 #define hash_suppress_vanilla_wafer 3121233547ul
220 #define hash_wafer 89669ul
221 #define hash_add_header 237434619ul
222 #define hash_cookiefile 247469766ul
223 #define hash_logfile 2114766ul
224 #define hash_blockfile 48845391ul
225 #define hash_imagefile 51447891ul
226 #define hash_jarfile 2046641ul
227 #define hash_listen_address 1255650842ul
228 #define hash_forwardfile 1268669141ul
229 #define hash_aclfile 1908516ul
230 #define hash_popupfile 54623516ul
231 #define hash_kill_all_popups 2311539906ul
232 #define hash_re_filterfile 3877522444ul
233 #define hash_re_filter_all 3877521376ul
234 #define hash_user_agent 283326691ul
235 #define hash_referrer 10883969ul
236 #define hash_referer 2176719ul
237 #define hash_from 16264ul
238 #define hash_hide_console 2048809870ul
239 #define hash_include_stats 2174146548ul
240 #define hash_suppress_blocklists 1948693308ul
241 #define hash_toggle 447966ul
243 #define hash_activity_animation 1817904738ul
244 #define hash_log_messages 2291744899ul
245 #define hash_log_highlight_messages 4032101240ul
246 #define hash_log_buffer_size 2918070425ul
247 #define hash_log_max_lines 2868344173ul
248 #define hash_log_font_name 2866730124ul
249 #define hash_log_font_size 2866731014ul
250 #define hash_show_on_task_bar 215410365ul
251 #define hash_close_button_minimizes 3651284693ul
254 /*********************************************************************
256 * Function : load_config
258 * Description : Load the config file and all parameters.
261 * 1 : signum : this can be the signal SIGHUP or 0 (if from main).
262 * In any case, we just ignore this and reload the config file.
264 * Returns : configret : 0 => Ok, everything else is an error.
265 * Note: we use configret since a signal handler cannot
266 * return a value, and this function does double duty.
267 * Ie. Is is called from main and from signal( SIGHUP );
269 *********************************************************************/
270 void load_config( int signum )
274 FILE *configfp = NULL;
279 log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
281 init_proxy_args(Argc, Argv);
284 /* (Waste of memory [not quite a "leak"] here. The
285 * last blockfile/popupfile/... etc will not be
286 * unloaded until we load a new one. If the
287 * block/popup/... feature has been disabled in
288 * the new config file, then we're wasting some
289 * memory we could otherwise reclaim.
292 /* Disable all loaders. */
293 remove_all_loaders();
296 * Reset to as close to startup state as we can.
297 * But leave changing the logfile until after we're done loading.
306 #endif /* def JAR_FILES */
311 #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
313 freez((char *)tinygifurl);
314 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
316 suppress_vanilla_wafer = 0;
322 #endif /*def _WIN_CONSOLE*/
326 #endif /* def PCRS */
330 #endif /* def KILLPOPUPS */
339 #endif /* def STATISTICS */
341 #ifndef SPLIT_PROXY_ARGS
342 suppress_blocklists = 0;
343 #endif /* ndef SPLIT_PROXY_ARGS */
346 freez((char *)haddr);
347 freez((char *)uagent);
348 freez((char *)referrer);
349 freez((char *)logfile);
352 freez((char *)blockfile);
353 freez((char *)cookiefile);
354 freez((char *)forwardfile);
357 freez((char *)aclfile);
358 #endif /* def ACL_FILES */
360 #ifdef USE_IMAGE_LIST
361 freez((char *)imagefile);
362 #endif /* def USE_IMAGE_LIST */
365 freez((char *)jarfile);
366 #endif /* def JAR_FILES */
369 freez((char *)popupfile);
370 #endif /* def KILLPOPUPS */
372 #ifndef SPLIT_PROXY_ARGS
373 freez((char *)suppress_message);
374 #endif /* ndef SPLIT_PROXY_ARGS */
377 freez((char *)trustfile);
378 #endif /* def TRUST_FILES */
381 freez((char *)re_filterfile);
382 #endif /* def PCRS */
384 if (NULL != configfile)
386 if ((configfp = fopen(configfile, "r")) == NULL)
388 log_error(LOG_LEVEL_ERROR, "can't open configuration file '%s': %E",
395 if (NULL != configfp)
397 memset (buf, 'j', sizeof(buf));
398 while (read_config_line(buf, sizeof(buf), configfp, NULL) != NULL)
406 /* Copy command (i.e. up to space or tab) into cmd */
409 while (*p && (*p != ' ') && (*p != '\t'))
415 /* Skip over the whitespace in buf */
416 while (*p && ((*p == ' ') || (*p == '\t')))
421 /* Copy the argument into arg */
424 /* Should never happen, but check this anyway */
430 /* Make sure the command field is lower case */
435 *p = ijb_tolower(*p);
439 /* Save the argument for show-proxy-args */
443 switch( hash_string( cmd ) )
446 case hash_trustfile :
\r
447 freez((char *)trustfile);
448 trustfile = strdup(arg);
451 case hash_trust_info_url :
452 enlist(trust_info, arg);
454 #endif /* def TRUST_FILES */
460 #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
461 case hash_tinygif :
\r
462 freez((char *)tinygifurl);
467 while((*p >= '0') && (*p <= '9'))
\r
471 while((*p == ' ') || (*p == '\t'))
\r
477 q = malloc(strlen(p) + 5);
\r
481 strcat(q, "\r\n\r\n");
\r
486 if ((tinygif != 1) &&
\r
488 ((tinygif != 3) || (tinygifurl==NULL)) )
\r
490 log_error(LOG_LEVEL_ERROR, "tinygif setting invalid.");
\r
493 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
495 case hash_add_forwarded_header :
499 case hash_single_threaded :
503 case hash_suppress_vanilla_wafer :
504 suppress_vanilla_wafer = 1;
508 enlist(wafer_list, arg);
511 case hash_add_header :
512 enlist(xtra_list, arg);
515 case hash_cookiefile :
\r
516 freez((char *)cookiefile);
517 cookiefile = strdup(arg);
520 case hash_logfile :
\r
521 freez((char *)logfile);
522 logfile = strdup(arg);
525 case hash_blockfile :
\r
526 freez((char *)blockfile);
527 blockfile = strdup(arg);
530 #ifdef USE_IMAGE_LIST
531 case hash_imagefile :
\r
532 freez((char *)imagefile);
533 imagefile = strdup(arg);
535 #endif /* def USE_IMAGE_LIST */
538 case hash_jarfile :
\r
539 freez((char *)jarfile);
540 jarfile = strdup(arg);
542 #endif /* def JAR_FILES */
544 case hash_listen_address :
\r
545 freez((char *)haddr);
549 case hash_forwardfile :
\r
550 freez((char *)forwardfile);
551 forwardfile = strdup(arg);
555 case hash_aclfile :
\r
556 freez((char *)aclfile);
557 aclfile = strdup(arg);
559 #endif /* def ACL_FILES */
562 case hash_popupfile :
\r
563 freez((char *)popupfile);
564 popupfile = strdup(arg);
567 case hash_kill_all_popups :
570 #endif /* def KILLPOPUPS */
573 case hash_re_filterfile :
\r
574 freez((char *)re_filterfile);
575 re_filterfile = strdup(arg);
578 case hash_re_filter_all :
580 log_error(LOG_LEVEL_REF, "re_filter policy is %s.",
581 re_filter_all ? "RADICAL" : "SEMI-SMART");
583 #endif /* def PCRS */
585 case hash_user_agent :
\r
586 freez((char *)uagent);
587 uagent = strdup(arg);
591 * Offer choice of correct spelling according to dictionary,
592 * or the misspelling used in the HTTP spec.
595 case hash_referer :
\r
596 freez((char *)referrer);
597 referrer = strdup(arg);
606 case hash_hide_console :
609 #endif /*def _WIN_CONSOLE*/
611 #ifndef SPLIT_PROXY_ARGS
612 case hash_suppress_blocklists :
615 suppress_message = strdup(arg);
619 /* There will be NO reference in proxy-args. */
620 suppress_message = NULL;
623 suppress_blocklists = 1;
625 #endif /* ndef SPLIT_PROXY_ARGS */
629 g_bToggleIJB = atoi(arg);
631 #endif /* def TOGGLE */
633 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
634 case hash_activity_animation :
635 g_bShowActivityAnimation = atoi(arg);
638 case hash_log_messages :
639 g_bLogMessages = atoi(arg);
642 case hash_log_highlight_messages :
643 g_bHighlightMessages = atoi(arg);
646 case hash_log_buffer_size :
647 g_bLimitBufferSize = atoi(arg);
650 case hash_log_max_lines :
651 g_nMaxBufferLines = atoi(arg);
654 case hash_log_font_name :
655 strcpy( g_szFontFaceName, arg );
658 case hash_log_font_size :
659 g_nFontSize = atoi(arg);
662 case hash_show_on_task_bar :
663 g_bShowOnTaskBar = atoi(arg);
666 case hash_close_button_minimizes :
667 g_bCloseHidesWindow = atoi(arg);
669 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
671 /* Warnings about unsupported features */
674 case hash_trustfile :
675 case hash_trust_info_url :
676 #endif /* ndef TRUST_FILES */
677 #ifndef USE_IMAGE_LIST
678 case hash_imagefile :
679 #endif /* ndef USE_IMAGE_LIST */
681 case hash_re_filterfile :
682 case hash_re_filter_all :
683 #endif /* ndef PCRS */
686 #endif /* ndef TOGGLE */
687 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
688 case hash_activity_animation :
689 case hash_log_messages :
690 case hash_log_highlight_messages :
691 case hash_log_buffer_size :
692 case hash_log_max_lines :
693 case hash_log_font_name :
694 case hash_log_font_size :
695 case hash_show_on_task_bar :
696 case hash_close_button_minimizes :
697 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
699 case hash_hide_console :
700 #endif /* ndef _WIN_CONSOLE */
701 #if !defined(DETECT_MSIE_IMAGES) && !defined(USE_IMAGE_LIST)
703 #endif /* !defined(DETECT_MSIE_IMAGES) && !defined(USE_IMAGE_LIST) */
705 case hash_popupfile :
706 case hash_kill_all_popups :
707 #endif /* ndef KILLPOPUPS */
710 #endif /* ndef JAR_FILES */
713 #endif /* ndef ACL_FILES */
715 #ifdef SPLIT_PROXY_ARGS
716 case hash_suppress_blocklists :
717 #endif /* def SPLIT_PROXY_ARGS */
718 log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd);
722 log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%lulu) in "
723 "configuration file: \"%s\"", hash_string( cmd ), buf);
724 p = malloc( BUFSIZ );
727 sprintf( p, "<br>\nWARNING: unrecognized directive : %s<br><br>\n", buf );
728 proxy_args->invocation = strsav( proxy_args->invocation, p );
732 * I decided that I liked this better as a warning than an
746 init_error_log(Argv[0], logfile, debug);
750 add_loader(load_cookiefile);
755 add_loader(load_blockfile);
758 #ifdef USE_IMAGE_LIST
761 add_loader(load_imagefile);
763 #endif /* def USE_IMAGE_LIST */
768 add_loader(load_trustfile);
770 #endif /* def TRUST_FILES */
774 add_loader(load_forwardfile);
780 add_loader(load_aclfile);
782 #endif /* def ACL_FILES */
787 add_loader(load_popupfile);
789 #endif /* def KILLPOPUPS */
794 add_loader(load_re_filterfile);
796 #endif /* def PCRS */
799 if ( NULL != jarfile )
801 if ( NULL == (jar = fopen(jarfile, "a")) )
803 log_error(LOG_LEVEL_ERROR, "can't open jarfile '%s': %E", jarfile);
809 #endif /* def JAR_FILES */
813 haddr = strdup( HADDR_DEFAULT );
818 if ((p = strchr(haddr, ':')))
830 log_error(LOG_LEVEL_ERROR, "invalid bind port spec %s", haddr);
840 if (run_loader(NULL))
848 * If we're logging cookies in a cookie jar, and the user has not
849 * supplied any wafers, and the user has not told us to suppress the
850 * vanilla wafer, then send the vanilla wafer.
852 if ((jarfile != NULL)
853 && (wafer_list->next == NULL)
854 && (suppress_vanilla_wafer == 0))
856 enlist(wafer_list, VANILLA_WAFER);
858 #endif /* def JAR_FILES */