From 43da0ce639b1cf540198b2f63e790d9127725343 Mon Sep 17 00:00:00 2001 From: jongfoster Date: Sat, 26 May 2001 00:28:36 +0000 Subject: [PATCH] Automatic reloading of config file. Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32). Most of the global variables have been moved to a new struct configuration_spec, accessed through csp->config->globalname Most of the globals remaining are used by the Win32 GUI. --- config.h | 11 +- filters.c | 29 +- jcc.c | 73 +++-- loadcfg.c | 916 +++++++++++++++++++++++++++-------------------------- loadcfg.h | 120 +++---- loaders.c | 107 ++++--- loaders.h | 22 +- parsers.c | 91 ++++-- project.h | 143 ++++++++- showargs.c | 51 +-- showargs.h | 13 +- w32.rc | 5 +- w32log.c | 68 ++-- w32log.h | 28 +- w32res.h | 16 +- 15 files changed, 979 insertions(+), 714 deletions(-) diff --git a/config.h b/config.h index 6f50a535..1e75adbf 100644 --- a/config.h +++ b/config.h @@ -4,7 +4,7 @@ #define _CONFIG_H /********************************************************************* * - * File : $Source: /cvsroot/ijbswa/current/Attic/config.h,v $ + * File : $Source: /cvsroot/ijbswa/current/config.h,v $ * * Purpose : This file should be the first thing included in every * .c file. (Before even system headers). It contains @@ -39,6 +39,10 @@ * * Revisions : * $Log: config.h,v $ + * Revision 1.4 2001/05/25 22:17:28 jongfoster + * Resurrecting these files which are required for the MS Visual C++ + * build only. + * * Revision 1.2 2001/05/20 01:21:20 jongfoster * Version 2.9.4 checkin. * - Merged popupfile and cookiefile, and added control over PCRS @@ -125,6 +129,11 @@ */ #define FORCE_LOAD 1 +/* + * Locally redirect remote script-redirect URLs + */ +#define FAST_REDIRECTS 1 + /* * Split the show-proxy-args page into a page for each config file. */ diff --git a/filters.c b/filters.c index cdcbba39..cab956f7 100644 --- a/filters.c +++ b/filters.c @@ -1,4 +1,4 @@ -const char filters_rcs[] = "$Id: filters.c,v 1.4 2001/05/22 18:46:04 oes Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 1.5 2001/05/25 22:34:30 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.c,v $ @@ -38,6 +38,9 @@ const char filters_rcs[] = "$Id: filters.c,v 1.4 2001/05/22 18:46:04 oes Exp $"; * * Revisions : * $Log: filters.c,v $ + * Revision 1.5 2001/05/25 22:34:30 jongfoster + * Hard tabs->Spaces + * * Revision 1.4 2001/05/22 18:46:04 oes * * - Enabled filtering banners by size rather than URL @@ -717,7 +720,7 @@ char *trust_url(struct http_request *http, struct client_state *csp) /* if splitting the domain fails, punt */ if (url->dbuf == NULL) goto trust_url_not_trusted; - for (tl = trust_list; (t = *tl) ; tl++) + for (tl = csp->config->trust_list; (t = *tl) ; tl++) { if ((t->port == 0) || (t->port == rhttp->port)) { @@ -741,7 +744,7 @@ char *trust_url(struct http_request *http, struct client_state *csp) freez(url->dbuf); freez(url->dvec); - if ((fp = fopen(trustfile, "a"))) + if ((fp = fopen(csp->config->trustfile, "a"))) { h = NULL; @@ -919,7 +922,7 @@ int url_permissions(struct http_request *http, struct client_state *csp) if (((fl = csp->permissions_list) == NULL) || ((b = fl->f) == NULL)) { - return(default_permissions); + return(csp->config->default_permissions); } *url = dsplit(http->host); @@ -927,7 +930,7 @@ int url_permissions(struct http_request *http, struct client_state *csp) /* if splitting the domain fails, punt */ if (url->dbuf == NULL) { - return(default_permissions); + return(csp->config->default_permissions); } for (b = b->next; NULL != b; b = b->next) @@ -954,7 +957,7 @@ int url_permissions(struct http_request *http, struct client_state *csp) freez(url->dbuf); freez(url->dvec); - return(default_permissions); + return(csp->config->default_permissions); } @@ -1298,12 +1301,12 @@ char *show_proxy_args(struct http_request *http, struct client_state *csp) } #endif /* def SPLIT_PROXY_ARGS */ - s = strsav(s, proxy_args->header); - s = strsav(s, proxy_args->invocation); + s = strsav(s, csp->config->proxy_args->header); + s = strsav(s, csp->config->proxy_args->invocation); #ifdef STATISTICS s = add_stats(s); #endif /* def STATISTICS */ - s = strsav(s, proxy_args->gateways); + s = strsav(s, csp->config->proxy_args->gateways); #ifdef SPLIT_PROXY_ARGS s = strsav(s, @@ -1416,7 +1419,7 @@ char *show_proxy_args(struct http_request *http, struct client_state *csp) #endif /* ndef SPLIT_PROXY_ARGS */ - s = strsav(s, proxy_args->trailer); + s = strsav(s, csp->config->proxy_args->trailer); return(s); @@ -1521,13 +1524,13 @@ char *ij_untrusted_url(struct http_request *http, struct client_state *csp) p = strsav(p, "

The following referrers are trusted

\n"); - for (tl = trust_list; (t = *tl) ; tl++) + for (tl = csp->config->trust_list; (t = *tl) ; tl++) { sprintf(buf, "%s
\n", t->spec); p = strsav(p, buf); } - if (trust_info->next) + if (csp->config->trust_info->next) { struct list *l; @@ -1541,7 +1544,7 @@ char *ij_untrusted_url(struct http_request *http, struct client_state *csp) p = strsav(p, buf); - for (l = trust_info->next; l ; l = l->next) + for (l = csp->config->trust_info->next; l ; l = l->next) { sprintf(buf, "
  • %s
    \n", diff --git a/jcc.c b/jcc.c index 1376c34e..38ac12d9 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.7 2001/05/25 22:34:30 jongfoster Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.8 2001/05/25 22:43:18 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -33,6 +33,9 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.7 2001/05/25 22:34:30 jongfoster Exp $"; * * Revisions : * $Log: jcc.c,v $ + * Revision 1.8 2001/05/25 22:43:18 jongfoster + * Fixing minor memory leak and buffer overflow. + * * Revision 1.7 2001/05/25 22:34:30 jongfoster * Hard tabs->Spaces * @@ -428,7 +431,7 @@ static void chat(struct client_state *csp) IS_TRUSTED_URL (p = block_url(http, csp)) #ifdef FAST_REDIRECTS - || (fast_redirects && (p = redirect_url(http, csp))) + || (csp->config->fast_redirects && (p = redirect_url(http, csp))) #endif /* def FAST_REDIRECTS */ )) { @@ -440,25 +443,26 @@ static void chat(struct client_state *csp) #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) /* Block as image? */ - if ( (tinygif > 0) && block_imageurl(http, csp) ) + if ( (csp->config->tinygif > 0) && block_imageurl(http, csp) ) { /* Send "blocked" image */ log_error(LOG_LEVEL_GPC, "%s%s image crunch!", http->hostport, http->path); - if ((tinygif == 2) || strstr(http->path, "ijb-send-banner")) + if ((csp->config->tinygif == 2) || strstr(http->path, "ijb-send-banner")) { write_socket(csp->cfd, JBGIF, sizeof(JBGIF)-1); } - else if (tinygif == 1) + else if (csp->config->tinygif == 1) { write_socket(csp->cfd, BLANKGIF, sizeof(BLANKGIF)-1); } - else if ((tinygif == 3) && (tinygifurl)) + else if ((csp->config->tinygif == 3) && (csp->config->tinygifurl)) { freez(p); - p = (char *)malloc(sizeof(HTTP_REDIRECT_TEMPLATE) + strlen(tinygifurl)); - sprintf(p, HTTP_REDIRECT_TEMPLATE, tinygifurl); + p = (char *)malloc(sizeof(HTTP_REDIRECT_TEMPLATE) + + strlen(csp->config->tinygifurl)); + sprintf(p, HTTP_REDIRECT_TEMPLATE, csp->config->tinygifurl); write_socket(csp->cfd, p, strlen(p)); } else @@ -970,22 +974,8 @@ int main(int argc, const char *argv[]) configfile = argv[1]; } - remove_all_loaders(); - memset( proxy_args, 0, sizeof( proxy_args ) ); files->next = NULL; - load_config( 0 ); - - /* - * Since load_config acts as a signal handler too, it returns - * its status in configret. Check it for an error in loading. - */ - if ( 0 != configret ) - { - /* load config failed! Exit with error. */ - return( 1 ); - } - #ifdef _WIN32 InitWin32(); #endif @@ -994,7 +984,6 @@ int main(int argc, const char *argv[]) #ifndef _WIN32 signal(SIGPIPE, SIG_IGN); signal(SIGCHLD, SIG_IGN); - signal(SIGHUP, load_config); #else /* ifdef _WIN32 */ # ifdef _WIN_CONSOLE @@ -1030,24 +1019,29 @@ static void listen_loop(void) { struct client_state *csp = NULL; int bfd; + struct configuration_spec * config; + + config = load_config(); log_error(LOG_LEVEL_CONNECT, "bind (%s, %d)", - haddr ? haddr : "INADDR_ANY", hport); + config->haddr ? config->haddr : "INADDR_ANY", config->hport); - bfd = bind_port(haddr, hport); - config_changed = 0; + bfd = bind_port(config->haddr, config->hport); if (bfd < 0) { log_error(LOG_LEVEL_FATAL, "can't bind %s:%d: %E " "- There may be another junkbuster or some other " "proxy running on port %d", - (NULL != haddr) ? haddr : "INADDR_ANY", hport, hport + (NULL != config->haddr) ? config->haddr : "INADDR_ANY", + config->hport, config->hport ); /* shouldn't get here */ return; } + config->need_bind = 0; + while (FOREVER) { @@ -1070,7 +1064,9 @@ static void listen_loop(void) csp->active = 1; csp->sfd = -1; - if ( config_changed ) + csp->config = config = load_config(); + + if ( config->need_bind ) { /* * Since we were listening to the "old port", we will not see @@ -1084,13 +1080,26 @@ static void listen_loop(void) * request. This should not be a so common of an operation * that this will hurt people's feelings. */ + close_socket(bfd); log_error(LOG_LEVEL_CONNECT, "bind (%s, %d)", - haddr ? haddr : "INADDR_ANY", hport); - bfd = bind_port(haddr, hport); + config->haddr ? config->haddr : "INADDR_ANY", config->hport); + bfd = bind_port(config->haddr, config->hport); + + if (bfd < 0) + { + log_error(LOG_LEVEL_FATAL, "can't bind %s:%d: %E " + "- There may be another junkbuster or some other " + "proxy running on port %d", + (NULL != config->haddr) ? config->haddr : "INADDR_ANY", + config->hport, config->hport + ); + /* shouldn't get here */ + return; + } - config_changed = 0; + config->need_bind = 0; } log_error(LOG_LEVEL_CONNECT, "accept connection ... "); @@ -1127,7 +1136,7 @@ static void listen_loop(void) /* Never get here - LOG_LEVEL_FATAL causes program exit */ } - if (multi_threaded) + if (config->multi_threaded) { int child_id; diff --git a/loadcfg.c b/loadcfg.c index ae33439e..82bd9163 100644 --- a/loadcfg.c +++ b/loadcfg.c @@ -1,4 +1,4 @@ -const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.4 2001/05/22 18:46:04 oes Exp $"; +const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.5 2001/05/25 22:34:30 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $ @@ -35,6 +35,9 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.4 2001/05/22 18:46:04 oes Exp $"; * * Revisions : * $Log: loadcfg.c,v $ + * Revision 1.5 2001/05/25 22:34:30 jongfoster + * Hard tabs->Spaces + * * Revision 1.4 2001/05/22 18:46:04 oes * * - Enabled filtering banners by size rather than URL @@ -177,96 +180,19 @@ static const char VANILLA_WAFER[] = int g_bToggleIJB = 1; /* JunkBusters is enabled by default. */ #endif -int debug = 0; -int multi_threaded = 1; - -#if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) -int tinygif = 0; -const char *tinygifurl = NULL; -#endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */ - -const char *logfile = NULL; - +/* The filename of the configfile */ const char *configfile = NULL; -const char *blockfile = NULL; -const char *permissions_file = NULL; -const char *forwardfile = NULL; - -#ifdef ACL_FILES -const char *aclfile = NULL; -#endif /* def ACL_FILES */ - -#ifdef USE_IMAGE_LIST -const char *imagefile = NULL; -#endif /* def USE_IMAGE_LIST */ - -/* - * Permissions to use for URLs not in the permissions list. - */ -int default_permissions = PERMIT_RE_FILTER; - -#ifdef PCRS -const char *re_filterfile = NULL; -#endif /* def PCRS */ - -#ifdef FAST_REDIRECTS -int fast_redirects = 0; -#endif /* def FAST_REDIRECTS */ - -#ifdef TRUST_FILES -const char *trustfile = NULL; -#endif /* def TRUST_FILES */ - -#ifdef JAR_FILES -const char *jarfile = NULL; -FILE *jar = NULL; -#endif /* def JAR_FILES */ - -const char *referrer = NULL; -const char *uagent = NULL; -const char *from = NULL; - -#ifndef SPLIT_PROXY_ARGS -const char *suppress_message = NULL; -#endif /* ndef SPLIT_PROXY_ARGS */ - -int suppress_vanilla_wafer = 0; -int add_forwarded = 0; - -struct list wafer_list[1]; -struct list xtra_list[1]; - -#ifdef TRUST_FILES -struct list trust_info[1]; -struct url_spec *trust_list[64]; -#endif /* def TRUST_FILES */ - -/* - * Port and IP to bind to. - * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000 - */ -const char *haddr = NULL; -int hport = 0; - -#ifndef SPLIT_PROXY_ARGS -int suppress_blocklists = 0; /* suppress listing sblock and simage */ -#endif /* ndef SPLIT_PROXY_ARGS */ - -struct proxy_args proxy_args[1]; - -int configret = 0; -int config_changed = 0; - - /* * The load_config function is now going to call `init_proxy_args', - * so it will need argc and argv. Since load_config will also be - * a signal handler, we need to have these globally available. + * so it will need argc and argv. So we need to have these + * globally available. */ int Argc = 0; const char **Argv = NULL; +static struct file_list *current_configfile = NULL; + /* * This takes the "cryptic" hash of each keyword and aliases them to @@ -316,561 +242,572 @@ const char **Argv = NULL; #define hash_close_button_minimizes 3651284693ul + /********************************************************************* * - * Function : load_config + * Function : unload_configfile * - * Description : Load the config file and all parameters. + * Description : Free the config structure and all components. * * Parameters : - * 1 : signum : this can be the signal SIGHUP or 0 (if from main). - * In any case, we just ignore this and reload the config file. + * 1 : data: struct configuration_spec to unload * - * Returns : configret : 0 => Ok, everything else is an error. - * Note: we use configret since a signal handler cannot - * return a value, and this function does double duty. - * Ie. Is is called from main and from signal( SIGHUP ); + * Returns : N/A * *********************************************************************/ -void load_config( int signum ) +void unload_configfile (void * data) { - char buf[BUFSIZ]; - char *p, *q; - FILE *configfp = NULL; - - configret = 0; /* FIXME: This is obsolete, always 0. */ - config_changed = 1; - - log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile); - - init_proxy_args(Argc, Argv); - - - /* (Waste of memory [not quite a "leak"] here. The - * last blockfile/permissions file/... etc will not be - * unloaded until we load a new one. If the - * block/... feature has been disabled in - * the new config file, then we're wasting some - * memory we could otherwise reclaim. - */ - - /* Disable all loaders. */ - remove_all_loaders(); - - /* - * Reset to as close to startup state as we can. - * But leave changing the logfile until after we're done loading. - */ + struct configuration_spec * config = (struct configuration_spec *)data; #ifdef JAR_FILES - if ( NULL != jar ) + if ( NULL != config->jar ) { - fclose( jar ); - jar = NULL; + fclose( config->jar ); + config->jar = NULL; } #endif /* def JAR_FILES */ - - debug = 0; - multi_threaded = 1; - - default_permissions = PERMIT_RE_FILTER; - #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) - tinygif = 0; - freez((char *)tinygifurl); + freez((char *)config->tinygifurl); #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */ - suppress_vanilla_wafer = 0; - add_forwarded = 0; - hport = HADDR_PORT; + freez((char *)config->from); + freez((char *)config->haddr); + freez((char *)config->uagent); + freez((char *)config->referrer); + freez((char *)config->logfile); -#ifdef _WIN_CONSOLE - hideConsole = 0; -#endif /*def _WIN_CONSOLE*/ - -#ifdef TOGGLE - g_bToggleIJB = 1; -#endif - -#ifdef STATISTICS - urls_read = 0; - urls_rejected = 0; -#endif /* def STATISTICS */ - -#ifndef SPLIT_PROXY_ARGS - suppress_blocklists = 0; -#endif /* ndef SPLIT_PROXY_ARGS */ - - freez((char *)from); - freez((char *)haddr); - freez((char *)uagent); - freez((char *)referrer); - freez((char *)logfile); - - - freez((char *)blockfile); - freez((char *)permissions_file); - freez((char *)forwardfile); + freez((char *)config->blockfile); + freez((char *)config->permissions_file); + freez((char *)config->forwardfile); #ifdef ACL_FILES - freez((char *)aclfile); + freez((char *)config->aclfile); #endif /* def ACL_FILES */ #ifdef USE_IMAGE_LIST - freez((char *)imagefile); + freez((char *)config->imagefile); #endif /* def USE_IMAGE_LIST */ #ifdef JAR_FILES - freez((char *)jarfile); + freez((char *)config->jarfile); #endif /* def JAR_FILES */ #ifndef SPLIT_PROXY_ARGS - freez((char *)suppress_message); + freez((char *)config->suppress_message); #endif /* ndef SPLIT_PROXY_ARGS */ -#ifdef TRUST_FILES - freez((char *)trustfile); -#endif /* def TRUST_FILES */ - #ifdef PCRS - freez((char *)re_filterfile); + freez((char *)config->re_filterfile); #endif /* def PCRS */ -#ifdef FAST_REDIRECTS - fast_redirects = 0; -#endif /* def FAST_REDIRECTS */ +} + + +/********************************************************************* + * + * Function : load_config + * + * Description : Load the config file and all parameters. + * + * Parameters : + * 1 : csp = Client state (the config member will be + * filled in by this function). + * + * Returns : 0 => Ok, everything else is an error. + * + *********************************************************************/ +struct configuration_spec * load_config(void) +{ + char buf[BUFSIZ]; + char *p, *q; + FILE *configfp = NULL; + struct configuration_spec * config = NULL; + int suppress_vanilla_wafer; + struct client_state * fake_csp; + + struct file_list *fs; - if (NULL != configfile) + if (!check_file_changed(current_configfile, configfile, &fs)) { - if ((configfp = fopen(configfile, "r")) == NULL) - { - log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E", - configfile); - /* Never get here - LOG_LEVEL_FATAL causes program exit */ - } + /* No need to load */ + return ((struct configuration_spec *)current_configfile->f); + } + if (!fs) + { + log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E", + configfile); + } + + log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile); + +#ifdef TOGGLE + g_bToggleIJB = 1; +#endif + + fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config)); + + if (config==NULL) + { + freez(fs->filename); + freez(fs); + log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration"); + /* Never get here - LOG_LEVEL_FATAL causes program exit */ + } + + /* + * This is backwards from how it's usually done. + * Following the usual pattern, "fs" would be stored in a member + * variable in "csp", and then we'd access "config" from "fs->f", + * using a cast. However, "config" is used so often that a + * cast each time would be very ugly, and the extra indirection + * would waste CPU cycles. Therefore we store "config" in + * "csp->config", and "fs" in "csp->config->config_file_list". + */ + config->config_file_list = fs; + + init_proxy_args(Argc, Argv, config); + + /* + * Set to defaults + */ + + config->multi_threaded = 1; + config->default_permissions = PERMIT_RE_FILTER; + config->hport = HADDR_PORT; + + if ((configfp = fopen(configfile, "r")) == NULL) + { + log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E", + configfile); + /* Never get here - LOG_LEVEL_FATAL causes program exit */ } - if (NULL != configfp) + while (read_config_line(buf, sizeof(buf), configfp, fs) != NULL) { - memset (buf, 'j', sizeof(buf)); - while (read_config_line(buf, sizeof(buf), configfp, NULL) != NULL) - { - char cmd[BUFSIZ]; - char arg[BUFSIZ]; - char tmp[BUFSIZ]; + char cmd[BUFSIZ]; + char arg[BUFSIZ]; + char tmp[BUFSIZ]; - strcpy(tmp, buf); + strcpy(tmp, buf); - /* Copy command (i.e. up to space or tab) into cmd */ - p = buf; - q = cmd; - while (*p && (*p != ' ') && (*p != '\t')) - { - *q++ = *p++; - } - *q = '\0'; + /* Copy command (i.e. up to space or tab) into cmd */ + p = buf; + q = cmd; + while (*p && (*p != ' ') && (*p != '\t')) + { + *q++ = *p++; + } + *q = '\0'; - /* Skip over the whitespace in buf */ - while (*p && ((*p == ' ') || (*p == '\t'))) - { - p++; - } + /* Skip over the whitespace in buf */ + while (*p && ((*p == ' ') || (*p == '\t'))) + { + p++; + } - /* Copy the argument into arg */ - strcpy(arg, p); + /* Copy the argument into arg */ + strcpy(arg, p); - /* Should never happen, but check this anyway */ - if (*cmd == '\0') - { - continue; - } + /* Should never happen, but check this anyway */ + if (*cmd == '\0') + { + continue; + } - /* Make sure the command field is lower case */ - for (p=cmd; *p; p++) + /* Make sure the command field is lower case */ + for (p=cmd; *p; p++) + { + if (ijb_isupper(*p)) { - if (ijb_isupper(*p)) - { - *p = ijb_tolower(*p); - } + *p = ijb_tolower(*p); } + } - /* Save the argument for show-proxy-args */ - savearg(cmd, arg); + /* Save the argument for show-proxy-args */ + savearg(cmd, arg, config); - switch( hash_string( cmd ) ) - { + switch( hash_string( cmd ) ) + { #ifdef TRUST_FILES - case hash_trustfile : - freez((char *)trustfile); - trustfile = strdup(arg); - continue; + case hash_trustfile : + freez((char *)config->trustfile); + config->trustfile = strdup(arg); + continue; - case hash_trust_info_url : - enlist(trust_info, arg); - continue; + case hash_trust_info_url : + enlist(config->trust_info, arg); + continue; #endif /* def TRUST_FILES */ - case hash_debug : - debug |= atoi(arg); - continue; + case hash_debug : + config->debug |= atoi(arg); + continue; #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) - case hash_tinygif : - freez((char *)tinygifurl); - tinygif = atoi(arg); - if(3 == tinygif) + case hash_tinygif : + freez((char *)config->tinygifurl); + config->tinygif = atoi(arg); + if(3 == config->tinygif) + { + p = arg; + while((*p >= '0') && (*p <= '9')) { - p = arg; - while((*p >= '0') && (*p <= '9')) - { - p++; - } - while((*p == ' ') || (*p == '\t')) - { - p++; - } - if (*p) - { - q = malloc(strlen(p) + 5); - if (q) - { - strcpy(q, p); - strcat(q, "\r\n\r\n"); - tinygifurl = q; - } - } + p++; } - if ((tinygif != 1) && - (tinygif != 2) && - ((tinygif != 3) || (tinygifurl==NULL)) ) + while((*p == ' ') || (*p == '\t')) { - log_error(LOG_LEVEL_ERROR, "tinygif setting invalid."); + p++; } - continue; + if (*p) + { + q = malloc(strlen(p) + 5); + if (q) + { + strcpy(q, p); + strcat(q, "\r\n\r\n"); + config->tinygifurl = q; + } + } + } + if ((config->tinygif != 1) && + (config->tinygif != 2) && + ((config->tinygif != 3) || (config->tinygifurl==NULL)) ) + { + log_error(LOG_LEVEL_ERROR, "tinygif setting invalid."); + } + continue; #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */ - case hash_add_forwarded_header : - add_forwarded = 1; - continue; + case hash_add_forwarded_header : + config->add_forwarded = 1; + continue; - case hash_single_threaded : - multi_threaded = 0; - continue; + case hash_single_threaded : + config->multi_threaded = 0; + continue; - case hash_suppress_vanilla_wafer : - suppress_vanilla_wafer = 1; - continue; + case hash_suppress_vanilla_wafer : + suppress_vanilla_wafer = 1; + continue; - case hash_wafer : - enlist(wafer_list, arg); - continue; + case hash_wafer : + enlist(config->wafer_list, arg); + continue; - case hash_add_header : - enlist(xtra_list, arg); - continue; + case hash_add_header : + enlist(config->xtra_list, arg); + continue; - case hash_permissions_file : - freez((char *)permissions_file); - permissions_file = strdup(arg); - continue; + case hash_permissions_file : + freez((char *)config->permissions_file); + config->permissions_file = strdup(arg); + continue; - case hash_logfile : - freez((char *)logfile); - logfile = strdup(arg); - continue; + case hash_logfile : + freez((char *)config->logfile); + config->logfile = strdup(arg); + continue; - case hash_blockfile : - freez((char *)blockfile); - blockfile = strdup(arg); - continue; + case hash_blockfile : + freez((char *)config->blockfile); + config->blockfile = strdup(arg); + continue; #ifdef USE_IMAGE_LIST - case hash_imagefile : - freez((char *)imagefile); - imagefile = strdup(arg); - continue; + case hash_imagefile : + freez((char *)config->imagefile); + config->imagefile = strdup(arg); + continue; #endif /* def USE_IMAGE_LIST */ #ifdef JAR_FILES - case hash_jarfile : - freez((char *)jarfile); - jarfile = strdup(arg); - continue; + case hash_jarfile : + freez((char *)config->jarfile); + config->jarfile = strdup(arg); + continue; #endif /* def JAR_FILES */ - case hash_listen_address : - freez((char *)haddr); - haddr = strdup(arg); - continue; + case hash_listen_address : + freez((char *)config->haddr); + config->haddr = strdup(arg); + continue; - case hash_forwardfile : - freez((char *)forwardfile); - forwardfile = strdup(arg); - continue; + case hash_forwardfile : + freez((char *)config->forwardfile); + config->forwardfile = strdup(arg); + continue; #ifdef ACL_FILES - case hash_aclfile : - freez((char *)aclfile); - aclfile = strdup(arg); - continue; + case hash_aclfile : + freez((char *)config->aclfile); + config->aclfile = strdup(arg); + continue; #endif /* def ACL_FILES */ #ifdef PCRS - case hash_re_filterfile : - freez((char *)re_filterfile); - re_filterfile = strdup(arg); - continue; + case hash_re_filterfile : + freez((char *)config->re_filterfile); + config->re_filterfile = strdup(arg); + continue; #endif /* def PCRS */ - case hash_user_agent : - freez((char *)uagent); - uagent = strdup(arg); - continue; + case hash_user_agent : + freez((char *)config->uagent); + config->uagent = strdup(arg); + continue; - /* - * Offer choice of correct spelling according to dictionary, - * or the misspelling used in the HTTP spec. - */ - case hash_referrer : - case hash_referer : - freez((char *)referrer); - referrer = strdup(arg); - continue; + /* + * Offer choice of correct spelling according to dictionary, + * or the misspelling used in the HTTP spec. + */ + case hash_referrer : + case hash_referer : + freez((char *)config->referrer); + config->referrer = strdup(arg); + continue; - case hash_from : - freez((char *)from); - from = strdup(arg); - continue; + case hash_from : + freez((char *)config->from); + config->from = strdup(arg); + continue; #ifdef FAST_REDIRECTS - case hash_fast_redirects : - fast_redirects = 1; + case hash_fast_redirects : + config->fast_redirects = 1; continue; #endif /* def FAST_REDIRECTS */ #ifdef _WIN_CONSOLE - case hash_hide_console : - hideConsole = 1; - continue; + case hash_hide_console : + hideConsole = 1; + continue; #endif /*def _WIN_CONSOLE*/ #ifndef SPLIT_PROXY_ARGS - case hash_suppress_blocklists : - if (arg[0] != '\0') - { - suppress_message = strdup(arg); - } - else - { - /* There will be NO reference in proxy-args. */ - suppress_message = NULL; - } + case hash_suppress_blocklists : + if (arg[0] != '\0') + { + config->suppress_message = strdup(arg); + } + else + { + /* There will be NO reference in proxy-args. */ + config->suppress_message = NULL; + } - suppress_blocklists = 1; - continue; + config->suppress_blocklists = 1; + continue; #endif /* ndef SPLIT_PROXY_ARGS */ #ifdef TOGGLE - case hash_toggle : - g_bToggleIJB = atoi(arg); - continue; + case hash_toggle : + g_bToggleIJB = atoi(arg); + continue; #endif /* def TOGGLE */ #if defined(_WIN32) && ! defined(_WIN_CONSOLE) - case hash_activity_animation : - g_bShowActivityAnimation = atoi(arg); - continue; + case hash_activity_animation : + g_bShowActivityAnimation = atoi(arg); + continue; - case hash_log_messages : - g_bLogMessages = atoi(arg); - continue; + case hash_log_messages : + g_bLogMessages = atoi(arg); + continue; - case hash_log_highlight_messages : - g_bHighlightMessages = atoi(arg); - continue; + case hash_log_highlight_messages : + g_bHighlightMessages = atoi(arg); + continue; - case hash_log_buffer_size : - g_bLimitBufferSize = atoi(arg); - continue; + case hash_log_buffer_size : + g_bLimitBufferSize = atoi(arg); + continue; - case hash_log_max_lines : - g_nMaxBufferLines = atoi(arg); - continue; + case hash_log_max_lines : + g_nMaxBufferLines = atoi(arg); + continue; - case hash_log_font_name : - strcpy( g_szFontFaceName, arg ); - continue; + case hash_log_font_name : + strcpy( g_szFontFaceName, arg ); + continue; - case hash_log_font_size : - g_nFontSize = atoi(arg); - continue; + case hash_log_font_size : + g_nFontSize = atoi(arg); + continue; - case hash_show_on_task_bar : - g_bShowOnTaskBar = atoi(arg); - continue; + case hash_show_on_task_bar : + g_bShowOnTaskBar = atoi(arg); + continue; - case hash_close_button_minimizes : - g_bCloseHidesWindow = atoi(arg); - continue; + case hash_close_button_minimizes : + g_bCloseHidesWindow = atoi(arg); + continue; #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */ - /* Warnings about unsupported features */ + /* Warnings about unsupported features */ -#ifndef TRUST_FILES - case hash_trustfile : - case hash_trust_info_url : -#endif /* ndef TRUST_FILES */ #ifndef USE_IMAGE_LIST - case hash_imagefile : + case hash_imagefile : #endif /* ndef USE_IMAGE_LIST */ #ifndef PCRS - case hash_re_filterfile : + case hash_re_filterfile : #endif /* ndef PCRS */ #ifndef TOGGLE - case hash_toggle : + case hash_toggle : #endif /* ndef TOGGLE */ #if defined(_WIN_CONSOLE) || ! defined(_WIN32) - case hash_activity_animation : - case hash_log_messages : - case hash_log_highlight_messages : - case hash_log_buffer_size : - case hash_log_max_lines : - case hash_log_font_name : - case hash_log_font_size : - case hash_show_on_task_bar : - case hash_close_button_minimizes : + case hash_activity_animation : + case hash_log_messages : + case hash_log_highlight_messages : + case hash_log_buffer_size : + case hash_log_max_lines : + case hash_log_font_name : + case hash_log_font_size : + case hash_show_on_task_bar : + case hash_close_button_minimizes : #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */ #ifndef _WIN_CONSOLE - case hash_hide_console : + case hash_hide_console : #endif /* ndef _WIN_CONSOLE */ #if !defined(DETECT_MSIE_IMAGES) && !defined(USE_IMAGE_LIST) - case hash_tinygif : + case hash_tinygif : #endif /* !defined(DETECT_MSIE_IMAGES) && !defined(USE_IMAGE_LIST) */ #ifndef JAR_FILES - case hash_jarfile : + case hash_jarfile : #endif /* ndef JAR_FILES */ #ifndef ACL_FILES - case hash_aclfile : + case hash_aclfile : #endif /* ndef ACL_FILES */ - +#ifndef FAST_REDIRECTS + case hash_fast_redirects : +#endif /* ndef FAST_REDIRECTS */ #ifdef SPLIT_PROXY_ARGS - case hash_suppress_blocklists : + case hash_suppress_blocklists : #endif /* def SPLIT_PROXY_ARGS */ - log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); - continue; + log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); + continue; - default : - /* - * I decided that I liked this better as a warning than an - * error. To change back to an error, just change log level - * to LOG_LEVEL_FATAL. - */ - log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%lulu) in " - "configuration file: \"%s\"", hash_string( cmd ), buf); - p = malloc( BUFSIZ ); - if (p != NULL) - { - sprintf( p, "
    \nWARNING: unrecognized directive : %s

    \n", buf ); - proxy_args->invocation = strsav( proxy_args->invocation, p ); - freez( p ); - } - continue; - } - } - fclose(configfp); - } + default : + /* + * I decided that I liked this better as a warning than an + * error. To change back to an error, just change log level + * to LOG_LEVEL_FATAL. + */ + log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%lulu) in " + "configuration file: \"%s\"", hash_string( cmd ), buf); + p = malloc( BUFSIZ ); + if (p != NULL) + { + sprintf( p, "
    \nWARNING: unrecognized directive : %s

    \n", buf ); + config->proxy_args->invocation = strsav( config->proxy_args->invocation, p ); + freez( p ); + } + continue; + } /* end switch( hash_string(cmd) ) */ + } /* end while ( read_config_line(...) ) */ + + fclose(configfp); - init_error_log(Argv[0], logfile, debug); + init_error_log(Argv[0], config->logfile, config->debug); - if (permissions_file) + if (config->permissions_file) { - add_loader(load_permissions_file); + add_loader(load_permissions_file, config); } - if (blockfile) + if (config->blockfile) { - add_loader(load_blockfile); + add_loader(load_blockfile, config); } #ifdef USE_IMAGE_LIST - if (imagefile) + if (config->imagefile) { - add_loader(load_imagefile); + add_loader(load_imagefile, config); } #endif /* def USE_IMAGE_LIST */ -#ifdef TRUST_FILES - if (trustfile) - { - add_loader(load_trustfile); - } -#endif /* def TRUST_FILES */ - - if (forwardfile) + if (config->forwardfile) { - add_loader(load_forwardfile); + add_loader(load_forwardfile, config); } #ifdef ACL_FILES - if (aclfile) + if (config->aclfile) { - add_loader(load_aclfile); + add_loader(load_aclfile, config); } #endif /* def ACL_FILES */ #ifdef PCRS - if (re_filterfile) + if (config->re_filterfile) { - add_loader(load_re_filterfile); + add_loader(load_re_filterfile, config); } #endif /* def PCRS */ + +#ifdef TRUST_FILES + if (config->trustfile) + { + add_loader(load_trustfile, config); + } +#endif #ifdef JAR_FILES - if ( NULL != jarfile ) + if ( NULL != config->jarfile ) { - if ( NULL == (jar = fopen(jarfile, "a")) ) + if ( NULL == (config->jar = fopen(config->jarfile, "a")) ) { - log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", jarfile); + log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile); /* Never get here - LOG_LEVEL_FATAL causes program exit */ } - setbuf(jar, NULL); + setbuf(config->jar, NULL); } #endif /* def JAR_FILES */ - if ( NULL == haddr ) + if ( NULL == config->haddr ) { - haddr = strdup( HADDR_DEFAULT ); + config->haddr = strdup( HADDR_DEFAULT ); } - if ( NULL != haddr ) + if ( NULL != config->haddr ) { - if ((p = strchr(haddr, ':'))) + if ((p = strchr(config->haddr, ':'))) { *p++ = '\0'; if (*p) { - hport = atoi(p); + config->hport = atoi(p); } } - if (hport <= 0) + if (config->hport <= 0) { *--p = ':'; - log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", haddr); + log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr); /* Never get here - LOG_LEVEL_FATAL causes program exit */ } - if (*haddr == '\0') + if (*config->haddr == '\0') { - haddr = NULL; + config->haddr = NULL; } } - if (run_loader(NULL)) + /* + * Want to run all the loaders once now. + * + * Need to set up a fake csp, so they can get to the config. + */ + fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp)); + fake_csp->config = config; + + if (run_loader(fake_csp)) { + freez(fake_csp); log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting."); /* Never get here - LOG_LEVEL_FATAL causes program exit */ } + freez(fake_csp); #ifdef JAR_FILES /* @@ -878,16 +815,89 @@ void load_config( int signum ) * supplied any wafers, and the user has not told us to suppress the * vanilla wafer, then send the vanilla wafer. */ - if ((jarfile != NULL) - && (wafer_list->next == NULL) + if ((config->jarfile != NULL) + && (config->wafer_list->next == NULL) && (suppress_vanilla_wafer == 0)) { - enlist(wafer_list, VANILLA_WAFER); + enlist(config->wafer_list, VANILLA_WAFER); } #endif /* def JAR_FILES */ - end_proxy_args(); + end_proxy_args(config); + +#ifndef SPLIT_PROXY_ARGS + if (!suppress_blocklists) + { + fs->proxy_args = strsav(fs->proxy_args, ""); + } +#endif /* ndef SPLIT_PROXY_ARGS */ + +/* FIXME: this is a kludge for win32 */ +#if defined(_WIN32) && !defined (_WIN_CONSOLE) + + g_blockfile = config->blockfile; + g_permissions_file = config->permissions_file; + g_forwardfile = config->forwardfile; +#ifdef ACL_FILES + g_aclfile = config->aclfile; +#endif /* def ACL_FILES */ +#ifdef USE_IMAGE_LIST + g_imagefile = config->imagefile; +#endif /* def USE_IMAGE_LIST */ +#ifdef PCRS + g_re_filterfile = config->re_filterfile; +#endif +#ifdef TRUST_FILES + g_trustfile = config->trustfile; +#endif + + +#endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */ +/* FIXME: end kludge */ + + + config->need_bind = 1; + + if (current_configfile) + { + struct configuration_spec * oldcfg = (struct configuration_spec *) + current_configfile->f; + /* + * Check if config->haddr,hport == oldcfg->haddr,hport + * + * The following could be written more compactly as a single, + * (unreadably long) if statement. + */ + config->need_bind = 0; + if (config->hport != oldcfg->hport) + { + config->need_bind = 1; + } + else if (config->haddr == NULL) + { + if (oldcfg->haddr != NULL) + { + config->need_bind = 1; + } + } + else if (oldcfg->haddr == NULL) + { + config->need_bind = 1; + } + else if (0 != strcmp(config->haddr, oldcfg->haddr)) + { + config->need_bind = 1; + } + + current_configfile->unloader = unload_configfile; + } + + fs->next = files->next; + files->next = fs; + + current_configfile = fs; + return (config); } diff --git a/loadcfg.h b/loadcfg.h index 4c9e9924..ea13f483 100644 --- a/loadcfg.h +++ b/loadcfg.h @@ -1,6 +1,6 @@ #ifndef _LOADCFG_H #define _LOADCFG_H -#define LOADCFG_H_VERSION "$Id: loadcfg.h,v 1.3 2001/05/20 01:21:20 jongfoster Exp $" +#define LOADCFG_H_VERSION "$Id: loadcfg.h,v 1.4 2001/05/22 18:46:04 oes Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loadcfg.h,v $ @@ -37,6 +37,50 @@ * * Revisions : * $Log: loadcfg.h,v $ + * Revision 1.4 2001/05/22 18:46:04 oes + * + * - Enabled filtering banners by size rather than URL + * by adding patterns that replace all standard banner + * sizes with the "Junkbuster" gif to the re_filterfile + * + * - Enabled filtering WebBugs by providing a pattern + * which kills all 1x1 images + * + * - Added support for PCRE_UNGREEDY behaviour to pcrs, + * which is selected by the (nonstandard and therefore + * capital) letter 'U' in the option string. + * It causes the quantifiers to be ungreedy by default. + * Appending a ? turns back to greedy (!). + * + * - Added a new interceptor ijb-send-banner, which + * sends back the "Junkbuster" gif. Without imagelist or + * MSIE detection support, or if tinygif = 1, or the + * URL isn't recognized as an imageurl, a lame HTML + * explanation is sent instead. + * + * - Added new feature, which permits blocking remote + * script redirects and firing back a local redirect + * to the browser. + * The feature is conditionally compiled, i.e. it + * can be disabled with --disable-fast-redirects, + * plus it must be activated by a "fast-redirects" + * line in the config file, has its own log level + * and of course wants to be displayed by show-proxy-args + * Note: Boy, all the #ifdefs in 1001 locations and + * all the fumbling with configure.in and acconfig.h + * were *way* more work than the feature itself :-( + * + * - Because a generic redirect template was needed for + * this, tinygif = 3 now uses the same. + * + * - Moved GIFs, and other static HTTP response templates + * to project.h + * + * - Some minor fixes + * + * - Removed some >400 CRs again (Jon, you really worked + * a lot! ;-) + * * Revision 1.3 2001/05/20 01:21:20 jongfoster * Version 2.9.4 checkin. * - Merged popupfile and cookiefile, and added control over PCRS @@ -77,80 +121,8 @@ extern "C" { extern int g_bToggleIJB; #endif -extern int debug; -extern int multi_threaded; - -#if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) -extern int tinygif; -extern const char *tinygifurl; -#endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */ - -extern const char *logfile; - extern const char *configfile; -#ifdef ACL_FILES -extern const char *aclfile; -#endif /* def ACL_FILES */ - -extern const char *blockfile; -extern const char *permissions_file; -extern const char *forwardfile; - -#ifdef USE_IMAGE_LIST -extern const char *imagefile; -#endif /* def USE_IMAGE_LIST */ - -#ifdef TRUST_FILES -extern const char *trustfile; -#endif /* def TRUST_FILES */ - -#ifdef PCRS -extern const char *re_filterfile; -#endif /* def PCRS */ - -#ifdef FAST_REDIRECTS -extern int fast_redirects; -#endif /* def FAST_REDIRECTS */ - -extern int default_permissions; - -#ifdef JAR_FILES -extern const char *jarfile; -extern FILE *jar; -#endif /* def JAR_FILES */ - -extern const char *referrer; -extern const char *uagent; -extern const char *from; - -#ifndef SPLIT_PROXY_ARGS -extern const char *suppress_message; -#endif /* ndef SPLIT_PROXY_ARGS */ - -extern int suppress_vanilla_wafer; -extern int add_forwarded; - -extern struct list wafer_list[]; -extern struct list xtra_list[]; - -#ifdef TRUST_FILES -extern struct list trust_info[]; -extern struct url_spec *trust_list[]; -#endif /* def TRUST_FILES */ - -extern const char *haddr; -extern int hport; - -#ifndef SPLIT_PROXY_ARGS -extern int suppress_blocklists; /* suppress listing sblock and simage */ -#endif /* ndef SPLIT_PROXY_ARGS */ - -extern struct proxy_args proxy_args[1]; - -extern int configret; /* FIXME: This is obsolete, always 0. */ -extern int config_changed; - /* The load_config function is now going to call: * init_proxy_args, so it will need argc and argv. @@ -161,7 +133,7 @@ extern int Argc; extern const char **Argv; -extern void load_config( int ); +extern struct configuration_spec * load_config(void); /* Revision control strings from this header and associated .c file */ diff --git a/loaders.c b/loaders.c index 8a24af2f..3f481d8a 100644 --- a/loaders.c +++ b/loaders.c @@ -1,4 +1,4 @@ -const char loaders_rcs[] = "$Id: loaders.c,v 1.5 2001/05/23 10:39:05 oes Exp $"; +const char loaders_rcs[] = "$Id: loaders.c,v 1.6 2001/05/23 12:27:33 oes Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loaders.c,v $ @@ -35,6 +35,10 @@ const char loaders_rcs[] = "$Id: loaders.c,v 1.5 2001/05/23 10:39:05 oes Exp $"; * * Revisions : * $Log: loaders.c,v $ + * Revision 1.6 2001/05/23 12:27:33 oes + * + * Fixed ugly indentation of my last changes + * * Revision 1.5 2001/05/23 10:39:05 oes * - Added support for escaping the comment character * in config files by a backslash @@ -111,10 +115,6 @@ const char loaders_h_rcs[] = LOADERS_H_VERSION; #define ijb_isspace(__X) isspace((int)(unsigned char)(__X)) -#define NLOADERS 8 -static int (*loaders[NLOADERS])(struct client_state *); - - /* * Currently active files. * These are also entered in the main linked list of files. @@ -184,6 +184,13 @@ void sweep(void) { /* mark this client's files as active */ + /* + * Always have a configuration file. + * (Also note the slightly non-standard extra + * indirection here.) + */ + ncsp->config->config_file_list->active = 1; + if (ncsp->blist) /* block files */ { ncsp->blist->active = 1; @@ -653,9 +660,9 @@ static void unload_re_filterfile(void *f) * On error: 1 and sets newfl == NULL * *********************************************************************/ -static int check_file_changed(const struct file_list * current, - const char * filename, - struct file_list ** newfl) +int check_file_changed(const struct file_list * current, + const char * filename, + struct file_list ** newfl) { struct file_list *fs; struct stat statbuf[1]; @@ -865,7 +872,7 @@ int load_aclfile(struct client_state *csp) struct access_control_list *a, *bl; struct file_list *fs; - if (!check_file_changed(current_aclfile, aclfile, &fs)) + if (!check_file_changed(current_aclfile, csp->config->aclfile, &fs)) { /* No need to load */ if (csp) @@ -887,7 +894,7 @@ int load_aclfile(struct client_state *csp) goto load_aclfile_error; } - fp = fopen(aclfile, "r"); + fp = fopen(csp->config->aclfile, "r"); if (fp == NULL) { @@ -974,7 +981,8 @@ int load_aclfile(struct client_state *csp) return(0); load_aclfile_error: - log_error(LOG_LEVEL_ERROR, "can't load access control list %s: %E", aclfile); + log_error(LOG_LEVEL_ERROR, "can't load access control list %s: %E", + csp->config->aclfile); return(-1); } @@ -1002,7 +1010,7 @@ int load_blockfile(struct client_state *csp) int reject; struct file_list *fs; - if (!check_file_changed(current_blockfile, blockfile, &fs)) + if (!check_file_changed(current_blockfile, csp->config->blockfile, &fs)) { /* No need to load */ if (csp) @@ -1022,7 +1030,7 @@ int load_blockfile(struct client_state *csp) goto load_blockfile_error; } - if ((fp = fopen(blockfile, "r")) == NULL) + if ((fp = fopen(csp->config->blockfile, "r")) == NULL) { goto load_blockfile_error; } @@ -1096,7 +1104,7 @@ int load_blockfile(struct client_state *csp) return(0); load_blockfile_error: - log_error(LOG_LEVEL_ERROR, "can't load blockfile '%s': %E", blockfile); + log_error(LOG_LEVEL_ERROR, "can't load blockfile '%s': %E", csp->config->blockfile); return(-1); } @@ -1124,7 +1132,7 @@ int load_imagefile(struct client_state *csp) int reject; struct file_list *fs; - if (!check_file_changed(current_imagefile, imagefile, &fs)) + if (!check_file_changed(current_imagefile, csp->config->imagefile, &fs)) { /* No need to load */ if (csp) @@ -1144,7 +1152,7 @@ int load_imagefile(struct client_state *csp) goto load_imagefile_error; } - if ((fp = fopen(imagefile, "r")) == NULL) + if ((fp = fopen(csp->config->imagefile, "r")) == NULL) { goto load_imagefile_error; } @@ -1218,7 +1226,7 @@ int load_imagefile(struct client_state *csp) return(0); load_imagefile_error: - log_error(LOG_LEVEL_ERROR, "can't load imagefile '%s': %E", imagefile); + log_error(LOG_LEVEL_ERROR, "can't load imagefile '%s': %E", csp->config->imagefile); return(-1); } @@ -1248,7 +1256,7 @@ int load_permissions_file(struct client_state *csp) struct file_list *fs; int i; - if (!check_file_changed(current_permissions_file, permissions_file, &fs)) + if (!check_file_changed(current_permissions_file, csp->config->permissions_file, &fs)) { /* No need to load */ if (csp) @@ -1268,7 +1276,7 @@ int load_permissions_file(struct client_state *csp) goto load_permissions_error; } - if ((fp = fopen(permissions_file, "r")) == NULL) + if ((fp = fopen(csp->config->permissions_file, "r")) == NULL) { goto load_permissions_error; } @@ -1279,7 +1287,7 @@ int load_permissions_file(struct client_state *csp) * * Reset it to default first. */ - default_permissions = PERMIT_RE_FILTER; + csp->config->default_permissions = PERMIT_RE_FILTER; while (read_config_line(buf, sizeof(buf), fp, fs) != NULL) { @@ -1362,7 +1370,7 @@ int load_permissions_file(struct client_state *csp) /* a lines containing only "special" chars sets default */ if (*buf == '\0') { - default_permissions = permissions; + csp->config->default_permissions = permissions; continue; } @@ -1416,7 +1424,8 @@ int load_permissions_file(struct client_state *csp) return(0); load_permissions_error: - log_error(LOG_LEVEL_ERROR, "can't load permissions file '%s': %E", permissions_file); + log_error(LOG_LEVEL_ERROR, "can't load permissions file '%s': %E", + csp->config->permissions_file); return(-1); } @@ -1446,7 +1455,7 @@ int load_trustfile(struct client_state *csp) int reject, trusted; struct file_list *fs; - if (!check_file_changed(current_trustfile, trustfile, &fs)) + if (!check_file_changed(current_trustfile, csp->config->trustfile, &fs)) { /* No need to load */ if (csp) @@ -1466,12 +1475,12 @@ int load_trustfile(struct client_state *csp) goto load_trustfile_error; } - if ((fp = fopen(trustfile, "r")) == NULL) + if ((fp = fopen(csp->config->trustfile, "r")) == NULL) { goto load_trustfile_error; } - tl = trust_list; + tl = csp->config->trust_list; while (read_config_line(buf, sizeof(buf), fp, fs) != NULL) { @@ -1559,7 +1568,8 @@ int load_trustfile(struct client_state *csp) return(0); load_trustfile_error: - log_error(LOG_LEVEL_ERROR, "can't load trustfile '%s': %E", trustfile); + log_error(LOG_LEVEL_ERROR, "can't load trustfile '%s': %E", + csp->config->trustfile); return(-1); } @@ -1590,7 +1600,7 @@ int load_forwardfile(struct client_state *csp) const struct gateway *gw; struct url_spec url[1]; - if (!check_file_changed(current_forwardfile, forwardfile, &fs)) + if (!check_file_changed(current_forwardfile, csp->config->forwardfile, &fs)) { /* No need to load */ if (csp) @@ -1611,7 +1621,7 @@ int load_forwardfile(struct client_state *csp) goto load_forwardfile_error; } - if ((fp = fopen(forwardfile, "r")) == NULL) + if ((fp = fopen(csp->config->forwardfile, "r")) == NULL) { goto load_forwardfile_error; } @@ -1828,7 +1838,8 @@ int load_forwardfile(struct client_state *csp) return(0); load_forwardfile_error: - log_error(LOG_LEVEL_ERROR, "can't load forwardfile '%s': %E", forwardfile); + log_error(LOG_LEVEL_ERROR, "can't load forwardfile '%s': %E", + csp->config->forwardfile); return(-1); } @@ -1860,7 +1871,7 @@ int load_re_filterfile(struct client_state *csp) int error; pcrs_job *dummy; - if (!check_file_changed(current_re_filterfile, re_filterfile, &fs)) + if (!check_file_changed(current_re_filterfile, csp->config->re_filterfile, &fs)) { /* No need to load */ if (csp) @@ -1881,7 +1892,7 @@ int load_re_filterfile(struct client_state *csp) } /* Open the file or fail */ - if ((fp = fopen(re_filterfile, "r")) == NULL) + if ((fp = fopen(csp->config->re_filterfile, "r")) == NULL) { goto load_re_filterfile_error; } @@ -1933,7 +1944,8 @@ int load_re_filterfile(struct client_state *csp) return( 0 ); load_re_filterfile_error: - log_error(LOG_LEVEL_ERROR, "can't load re_filterfile '%s': %E", re_filterfile); + log_error(LOG_LEVEL_ERROR, "can't load re_filterfile '%s': %E", + csp->config->re_filterfile); return(-1); } @@ -1950,19 +1962,21 @@ load_re_filterfile_error: * Parameters : * 1 : loader = pointer to a function that can parse and load * the appropriate config file. + * 2 : config = The configuration_spec to add the loader to. * * Returns : N/A * *********************************************************************/ -void add_loader(int (*loader)(struct client_state *)) +void add_loader(int (*loader)(struct client_state *), + struct configuration_spec * config) { int i; for (i=0; i < NLOADERS; i++) { - if (loaders[i] == NULL) + if (config->loaders[i] == NULL) { - loaders[i] = loader; + config->loaders[i] = loader; break; } } @@ -1981,6 +1995,8 @@ void add_loader(int (*loader)(struct client_state *)) * * Parameters : * 1 : csp = Current client state (buffers, headers, etc...) + * Must be non-null. Reads: "csp->config" + * Writes: various data members. * * Returns : 0 => Ok, everything else is an error. * @@ -1992,34 +2008,17 @@ int run_loader(struct client_state *csp) for (i=0; i < NLOADERS; i++) { - if (loaders[i] == NULL) + if (csp->config->loaders[i] == NULL) { break; } - ret |= (loaders[i])(csp); + ret |= (csp->config->loaders[i])(csp); } return(ret); } -/********************************************************************* - * - * Function : remove_all_loaders - * - * Description : Remove all loaders from the list. - * - * Parameters : N/A - * - * Returns : N/A - * - *********************************************************************/ -void remove_all_loaders(void) -{ - memset( loaders, 0, sizeof( loaders ) ); -} - - /* Local Variables: tab-width: 3 diff --git a/loaders.h b/loaders.h index 35e9ecbc..3947dd90 100644 --- a/loaders.h +++ b/loaders.h @@ -1,6 +1,6 @@ #ifndef _LOADERS_H #define _LOADERS_H -#define LOADERS_H_VERSION "$Id: loaders.h,v 1.1.1.1 2001/05/15 13:59:00 oes Exp $" +#define LOADERS_H_VERSION "$Id: loaders.h,v 1.2 2001/05/20 01:21:20 jongfoster Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loaders.h,v $ @@ -37,6 +37,19 @@ * * Revisions : * $Log: loaders.h,v $ + * Revision 1.2 2001/05/20 01:21:20 jongfoster + * Version 2.9.4 checkin. + * - Merged popupfile and cookiefile, and added control over PCRS + * filtering, in new "permissionsfile". + * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration + * file error you now get a message box (in the Win32 GUI) rather + * than the program exiting with no explanation. + * - Made killpopup use the PCRS MIME-type checking and HTTP-header + * skipping. + * - Removed tabs from "config" + * - Moved duplicated url parsing code in "loaders.c" to a new funcition. + * - Bumped up version number. + * * Revision 1.1.1.1 2001/05/15 13:59:00 oes * Initial import of version 2.9.3 source tree * @@ -52,6 +65,9 @@ extern "C" { extern void sweep(void); extern char *read_config_line(char *buf, int buflen, FILE *fp, struct file_list *fs); +extern int check_file_changed(const struct file_list * current, + const char * filename, + struct file_list ** newfl); extern int load_blockfile(struct client_state *csp); extern int load_permissions_file(struct client_state *csp); @@ -73,9 +89,9 @@ extern int load_trustfile(struct client_state *csp); extern int load_re_filterfile(struct client_state *csp); #endif /* def PCRS */ -extern void add_loader(int (*loader)(struct client_state *)); +extern void add_loader(int (*loader)(struct client_state *), + struct configuration_spec * config); extern int run_loader(struct client_state *csp); -extern void remove_all_loaders(void); #ifdef PCRS extern int load_re_filterfile(struct client_state *csp); diff --git a/parsers.c b/parsers.c index 4f51e0bf..6d655b5d 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.3 2001/05/20 01:21:20 jongfoster Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.4 2001/05/22 18:46:04 oes Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -41,6 +41,50 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.3 2001/05/20 01:21:20 jongfoster * * Revisions : * $Log: parsers.c,v $ + * Revision 1.4 2001/05/22 18:46:04 oes + * + * - Enabled filtering banners by size rather than URL + * by adding patterns that replace all standard banner + * sizes with the "Junkbuster" gif to the re_filterfile + * + * - Enabled filtering WebBugs by providing a pattern + * which kills all 1x1 images + * + * - Added support for PCRE_UNGREEDY behaviour to pcrs, + * which is selected by the (nonstandard and therefore + * capital) letter 'U' in the option string. + * It causes the quantifiers to be ungreedy by default. + * Appending a ? turns back to greedy (!). + * + * - Added a new interceptor ijb-send-banner, which + * sends back the "Junkbuster" gif. Without imagelist or + * MSIE detection support, or if tinygif = 1, or the + * URL isn't recognized as an imageurl, a lame HTML + * explanation is sent instead. + * + * - Added new feature, which permits blocking remote + * script redirects and firing back a local redirect + * to the browser. + * The feature is conditionally compiled, i.e. it + * can be disabled with --disable-fast-redirects, + * plus it must be activated by a "fast-redirects" + * line in the config file, has its own log level + * and of course wants to be displayed by show-proxy-args + * Note: Boy, all the #ifdefs in 1001 locations and + * all the fumbling with configure.in and acconfig.h + * were *way* more work than the feature itself :-( + * + * - Because a generic redirect template was needed for + * this, tinygif = 3 now uses the same. + * + * - Moved GIFs, and other static HTTP response templates + * to project.h + * + * - Some minor fixes + * + * - Removed some >400 CRs again (Jon, you really worked + * a lot! ;-) + * * Revision 1.3 2001/05/20 01:21:20 jongfoster * Version 2.9.4 checkin. * - Merged popupfile and cookiefile, and added control over PCRS @@ -782,18 +826,18 @@ char *client_referrer(const struct parsers *v, char *s, struct client_state *csp csp->referrer = strdup(s); - if (referrer == NULL) + if (csp->config->referrer == NULL) { log_error(LOG_LEVEL_HEADER, "crunch!"); return(NULL); } - if (*referrer == '.') + if (*csp->config->referrer == '.') { return(strdup(s)); } - if (*referrer == '@') + if (*csp->config->referrer == '@') { if (csp->permissions & PERMIT_COOKIE_READ) { @@ -811,7 +855,7 @@ char *client_referrer(const struct parsers *v, char *s, struct client_state *csp * to fool stupid checks for in-site links */ - if (*referrer == '§' || *referrer == 'L') + if (*csp->config->referrer == '§' || *csp->config->referrer == 'L') { if (csp->permissions & PERMIT_COOKIE_READ) { @@ -831,7 +875,7 @@ char *client_referrer(const struct parsers *v, char *s, struct client_state *csp log_error(LOG_LEVEL_HEADER, "modified"); s = strsav( NULL, "Referer: " ); - s = strsav( s, referrer ); + s = strsav( s, csp->config->referrer ); return(s); } @@ -865,18 +909,18 @@ char *client_uagent(const struct parsers *v, char *s, struct client_state *csp) } #endif /* def DETECT_MSIE_IMAGES */ - if (uagent == NULL) + if (csp->config->uagent == NULL) { log_error(LOG_LEVEL_HEADER, "default"); return(strdup(DEFAULT_USER_AGENT)); } - if (*uagent == '.') + if (*csp->config->uagent == '.') { return(strdup(s)); } - if (*uagent == '@') + if (*csp->config->uagent == '@') { if (csp->permissions & PERMIT_COOKIE_READ) { @@ -892,7 +936,7 @@ char *client_uagent(const struct parsers *v, char *s, struct client_state *csp) log_error(LOG_LEVEL_HEADER, "modified"); s = strsav( NULL, "User-Agent: " ); - s = strsav( s, uagent ); + s = strsav( s, csp->config->uagent ); return(s); } @@ -914,18 +958,18 @@ char *client_uagent(const struct parsers *v, char *s, struct client_state *csp) *********************************************************************/ char *client_ua(const struct parsers *v, char *s, struct client_state *csp) { - if (uagent == NULL) + if (csp->config->uagent == NULL) { log_error(LOG_LEVEL_HEADER, "crunch!"); return(NULL); } - if (*uagent == '.') + if (*csp->config->uagent == '.') { return(strdup(s)); } - if (*uagent == '@') + if (*csp->config->uagent == '@') { if (csp->permissions & PERMIT_COOKIE_READ) { @@ -963,13 +1007,13 @@ char *client_ua(const struct parsers *v, char *s, struct client_state *csp) char *client_from(const struct parsers *v, char *s, struct client_state *csp) { /* if not set, zap it */ - if (from == NULL) + if (csp->config->from == NULL) { log_error(LOG_LEVEL_HEADER, "crunch!"); return(NULL); } - if (*from == '.') + if (*csp->config->from == '.') { return(strdup(s)); } @@ -977,7 +1021,7 @@ char *client_from(const struct parsers *v, char *s, struct client_state *csp) log_error(LOG_LEVEL_HEADER, " modified"); s = strsav( NULL, "From: " ); - s = strsav( s, from ); + s = strsav( s, csp->config->from ); return(s); } @@ -1036,7 +1080,7 @@ char *client_send_cookie(const struct parsers *v, char *s, struct client_state * *********************************************************************/ char *client_x_forwarded(const struct parsers *v, char *s, struct client_state *csp) { - if (add_forwarded) + if (csp->config->add_forwarded) { csp->x_forwarded = strdup(s); } @@ -1121,7 +1165,7 @@ void client_cookie_adder(struct client_state *csp) tmp = strsav(tmp, l->str); } - for (l = wafer_list->next; l ; l = l->next) + for (l = csp->config->wafer_list->next; l ; l = l->next) { if (tmp) { @@ -1166,7 +1210,7 @@ void client_xtra_adder(struct client_state *csp) { struct list *l; - for (l = xtra_list->next; l ; l = l->next) + for (l = csp->config->xtra_list->next; l ; l = l->next) { log_error(LOG_LEVEL_HEADER, "addh: %s", l->str); enlist(csp->headers, l->str); @@ -1191,7 +1235,10 @@ void client_x_forwarded_adder(struct client_state *csp) { char *p = NULL; - if (add_forwarded == 0) return; + if (csp->config->add_forwarded == 0) + { + return; + } if (csp->x_forwarded) { @@ -1230,9 +1277,9 @@ void client_x_forwarded_adder(struct client_state *csp) char *server_set_cookie(const struct parsers *v, char *s, struct client_state *csp) { #ifdef JAR_FILES - if (jar) + if (csp->config->jar) { - fprintf(jar, "%s\t%s\n", csp->http->host, (s + v->len + 1)); + fprintf(csp->config->jar, "%s\t%s\n", csp->http->host, (s + v->len + 1)); } #endif /* def JAR_FILES */ diff --git a/project.h b/project.h index 28511c91..df218bdf 100644 --- a/project.h +++ b/project.h @@ -1,6 +1,6 @@ #ifndef _PROJECT_H #define _PROJECT_H -#define PROJECT_H_VERSION "$Id: project.h,v 1.3 2001/05/20 01:21:20 jongfoster Exp $" +#define PROJECT_H_VERSION "$Id: project.h,v 1.4 2001/05/22 18:46:04 oes Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/project.h,v $ @@ -36,6 +36,50 @@ * * Revisions : * $Log: project.h,v $ + * Revision 1.4 2001/05/22 18:46:04 oes + * + * - Enabled filtering banners by size rather than URL + * by adding patterns that replace all standard banner + * sizes with the "Junkbuster" gif to the re_filterfile + * + * - Enabled filtering WebBugs by providing a pattern + * which kills all 1x1 images + * + * - Added support for PCRE_UNGREEDY behaviour to pcrs, + * which is selected by the (nonstandard and therefore + * capital) letter 'U' in the option string. + * It causes the quantifiers to be ungreedy by default. + * Appending a ? turns back to greedy (!). + * + * - Added a new interceptor ijb-send-banner, which + * sends back the "Junkbuster" gif. Without imagelist or + * MSIE detection support, or if tinygif = 1, or the + * URL isn't recognized as an imageurl, a lame HTML + * explanation is sent instead. + * + * - Added new feature, which permits blocking remote + * script redirects and firing back a local redirect + * to the browser. + * The feature is conditionally compiled, i.e. it + * can be disabled with --disable-fast-redirects, + * plus it must be activated by a "fast-redirects" + * line in the config file, has its own log level + * and of course wants to be displayed by show-proxy-args + * Note: Boy, all the #ifdefs in 1001 locations and + * all the fumbling with configure.in and acconfig.h + * were *way* more work than the feature itself :-( + * + * - Because a generic redirect template was needed for + * this, tinygif = 3 now uses the same. + * + * - Moved GIFs, and other static HTTP response templates + * to project.h + * + * - Some minor fixes + * + * - Removed some >400 CRs again (Jon, you really worked + * a lot! ;-) + * * Revision 1.3 2001/05/20 01:21:20 jongfoster * Version 2.9.4 checkin. * - Merged popupfile and cookiefile, and added control over PCRS @@ -118,6 +162,9 @@ extern "C" { /* Need this for struct gateway */ struct client_state; +/* Need this for struct client_state */ +struct configuration_spec; + struct http_request { @@ -200,6 +247,8 @@ struct list struct client_state { + struct configuration_spec * config; + int permissions; int cfd; @@ -415,6 +464,98 @@ struct access_control_list }; #endif /* def ACL_FILES */ +/* Maximum number of loaders (permissions, block, forward, acl...) */ +#define NLOADERS 8 + +/* + * Data loaded from the configuration file. + * + * (Anomaly: toggle is still handled through a global, not this structure) + */ +struct configuration_spec +{ + int debug; + int multi_threaded; + +#if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) + int tinygif; + const char *tinygifurl; +#endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */ + + const char *logfile; + + const char *blockfile; + const char *permissions_file; + const char *forwardfile; + +#ifdef ACL_FILES + const char *aclfile; +#endif /* def ACL_FILES */ + +#ifdef USE_IMAGE_LIST + const char *imagefile; +#endif /* def USE_IMAGE_LIST */ + +#ifdef PCRS + const char *re_filterfile; +#endif /* def PCRS */ + + /* + * Permissions to use for URLs not in the permissions list. + */ + int default_permissions; + +#ifdef JAR_FILES + const char * jarfile; + FILE * jar; +#endif /* def JAR_FILES */ + + const char *referrer; + const char *uagent; + const char *from; + + int add_forwarded; + + struct list wafer_list[1]; + struct list xtra_list[1]; + + /* + * Port and IP to bind to. + * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000 + */ + const char *haddr; + int hport; + +#ifndef SPLIT_PROXY_ARGS + const char *suppress_message; +#endif /* ndef SPLIT_PROXY_ARGS */ + +#ifndef SPLIT_PROXY_ARGS + /* suppress listing sblock and simage */ + int suppress_blocklists; +#endif /* ndef SPLIT_PROXY_ARGS */ + +#ifdef FAST_REDIRECTS + int fast_redirects; +#endif /* def FAST_REDIRECTS */ + +#ifdef TRUST_FILES + const char * trustfile; + + struct list trust_info[1]; + struct url_spec *trust_list[64]; +#endif /* def TRUST_FILES */ + + struct proxy_args proxy_args[1]; + + struct file_list *config_file_list; + + int (*loaders[NLOADERS])(struct client_state *); + + int need_bind; /* bool, nonzero if we need to bind() to the new port */ +}; + + #define SZ(X) (sizeof(X) / sizeof(*X)) #define WHITEBG "\n" diff --git a/showargs.c b/showargs.c index 7bbac02a..3889b8c6 100644 --- a/showargs.c +++ b/showargs.c @@ -1,4 +1,4 @@ -const char showargs_rcs[] = "$Id: showargs.c,v 1.5 2001/05/22 18:54:49 oes Exp $"; +const char showargs_rcs[] = "$Id: showargs.c,v 1.6 2001/05/25 22:32:56 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/showargs.c,v $ @@ -33,6 +33,9 @@ const char showargs_rcs[] = "$Id: showargs.c,v 1.5 2001/05/22 18:54:49 oes Exp $ * * Revisions : * $Log: showargs.c,v $ + * Revision 1.6 2001/05/25 22:32:56 jongfoster + * CRLF->LF + * * Revision 1.5 2001/05/22 18:54:49 oes * * - Enabled filtering banners by size rather than URL @@ -111,6 +114,7 @@ const char showargs_rcs[] = "$Id: showargs.c,v 1.5 2001/05/22 18:54:49 oes Exp $ #include #include +#include "project.h" #include "showargs.h" #include "jcc.h" #include "encode.h" @@ -197,7 +201,7 @@ char *strsav(char *old, const char *text_to_append) * Returns : N/A * *********************************************************************/ -void savearg(char *c, char *o) +void savearg(char *c, char *o, struct configuration_spec * config) { char buf[BUFSIZ]; @@ -233,7 +237,7 @@ void savearg(char *c, char *o) strcat(buf, "
    \n"); - proxy_args->invocation = strsav(proxy_args->invocation, buf); + config->proxy_args->invocation = strsav(config->proxy_args->invocation, buf); } @@ -251,18 +255,20 @@ void savearg(char *c, char *o) * Returns : N/A * *********************************************************************/ -void init_proxy_args(int argc, const char *argv[]) +void init_proxy_args(int argc, const char *argv[], struct configuration_spec * config) { const struct gateway *g; + char * b; int i; - freez(proxy_args->header); - freez(proxy_args->invocation); - freez(proxy_args->gateways); - freez(proxy_args->trailer); + freez(config->proxy_args->header); + freez(config->proxy_args->invocation); + freez(config->proxy_args->gateways); + freez(config->proxy_args->trailer); - proxy_args->header = strsav(proxy_args->header, + b = NULL; + b = strsav(b, "HTTP/1.0 200 OK\n" "Server: IJ/" VERSION "\n" "Content-type: text/html\n\n" @@ -282,35 +288,38 @@ void init_proxy_args(int argc, const char *argv[]) "

    \n" ); - proxy_args->header = strsav(proxy_args->header, + b = strsav(b, "

    The program was invoked as follows

    \n"); for (i=0; i < argc; i++) { - proxy_args->header = strsav(proxy_args->header, argv[i]); - proxy_args->header = strsav(proxy_args->header, " "); + b = strsav(b, argv[i]); + b = strsav(b, " "); } - proxy_args->header = strsav(proxy_args->header, "
    \n"); + b = strsav(b, "
    \n"); + config->proxy_args->header = b; - proxy_args->invocation = strsav( - proxy_args->invocation, + config->proxy_args->invocation = strsav( + config->proxy_args->invocation, "
    \n" "and the following options were set in the configuration file" "

    \n" ); + b = NULL; - proxy_args->gateways = strsav(proxy_args->gateways, + b = strsav(b, "

    It supports the following gateway protocols:

    \n"); for (g = gateways; g->name; g++) { - proxy_args->gateways = strsav(proxy_args->gateways, g->name); - proxy_args->gateways = strsav(proxy_args->gateways, " "); + b = strsav(b, g->name); + b = strsav(b, " "); } - proxy_args->gateways = strsav(proxy_args->gateways, "
    \n"); + b = strsav(b, "
    \n"); + config->proxy_args->gateways = b; } @@ -325,7 +334,7 @@ void init_proxy_args(int argc, const char *argv[]) * Returns : N/A * *********************************************************************/ -void end_proxy_args(void) +void end_proxy_args(struct configuration_spec * config) { char *b = NULL; char buf[BUFSIZ]; @@ -525,7 +534,7 @@ void end_proxy_args(void) "\n" ); - proxy_args->trailer = b; + config->proxy_args->trailer = b; } diff --git a/showargs.h b/showargs.h index 82b511c5..ec5a0016 100644 --- a/showargs.h +++ b/showargs.h @@ -1,9 +1,9 @@ #ifndef _SHOWARGS_H #define _SHOWARGS_H -#define SHOWARGS_H_VERSION "$Id: showargs.h,v 1.1 2001/05/13 21:57:07 administrator Exp $" +#define SHOWARGS_H_VERSION "$Id: showargs.h,v 1.1.1.1 2001/05/15 13:59:03 oes Exp $" /********************************************************************* * - * File : $Source: /home/administrator/cvs/ijb/showargs.h,v $ + * File : $Source: /cvsroot/ijbswa/current/showargs.h,v $ * * Purpose : Contains various utility routines needed to * generate the show-proxy-args page. @@ -35,6 +35,9 @@ * * Revisions : * $Log: showargs.h,v $ + * Revision 1.1.1.1 2001/05/15 13:59:03 oes + * Initial import of version 2.9.3 source tree + * * *********************************************************************/ @@ -44,10 +47,10 @@ extern "C" { #endif extern char *strsav(char *old, const char *text_to_append); -extern void savearg(char *c, char *o); +extern void savearg(char *c, char *o, struct configuration_spec * config); -extern void init_proxy_args(int argc, const char *argv[]); -extern void end_proxy_args(void); +extern void init_proxy_args(int argc, const char *argv[], struct configuration_spec * config); +extern void end_proxy_args(struct configuration_spec * config); /* Revision control strings from this header and associated .c file */ extern const char showargs_rcs[]; diff --git a/w32.rc b/w32.rc index 2bf24ef5..30798d00 100644 --- a/w32.rc +++ b/w32.rc @@ -31,6 +31,9 @@ * * Revisions : * $Log: w32.rc,v $ + * Revision 1.3 2001/05/25 22:33:40 jongfoster + * CRLF->LF + * * Revision 1.2 2001/05/20 01:21:20 jongfoster * Version 2.9.4 checkin. * - Merged popupfile and cookiefile, and added control over PCRS @@ -132,7 +135,6 @@ BEGIN #ifdef TOGGLE MENUITEM "&Enable", ID_TOGGLE_IJB, CHECKED #endif - MENUITEM "&Reload config", ID_RELOAD_CONFIG MENUITEM "Show &JunkBuster Window", ID_SHOWWINDOW END END @@ -160,7 +162,6 @@ BEGIN BEGIN #ifdef TOGGLE MENUITEM "&Enable", ID_TOGGLE_IJB, CHECKED - MENUITEM "&Reload config", ID_RELOAD_CONFIG MENUITEM SEPARATOR #endif MENUITEM "&Junkbuster...", ID_TOOLS_EDITJUNKBUSTER diff --git a/w32log.c b/w32log.c index 15a33838..8cf2ba03 100644 --- a/w32log.c +++ b/w32log.c @@ -1,4 +1,4 @@ -const char w32log_rcs[] = "$Id: w32log.c,v 1.3 2001/05/20 15:07:54 jongfoster Exp $"; +const char w32log_rcs[] = "$Id: w32log.c,v 1.4 2001/05/22 18:56:28 oes Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/w32log.c,v $ @@ -32,6 +32,9 @@ const char w32log_rcs[] = "$Id: w32log.c,v 1.3 2001/05/20 15:07:54 jongfoster Ex * * Revisions : * $Log: w32log.c,v $ + * Revision 1.4 2001/05/22 18:56:28 oes + * CRLF -> LF + * * Revision 1.3 2001/05/20 15:07:54 jongfoster * File is now ignored if _WIN_CONSOLE is defined. * @@ -147,6 +150,27 @@ char g_szFontFaceName[255] = DEFAULT_LOG_FONT_NAME; int g_nFontSize = DEFAULT_LOG_FONT_SIZE; +/* FIXME: this is a kludge */ + +const char * g_blockfile = NULL; +const char * g_permissions_file = NULL; +const char * g_forwardfile = NULL; +#ifdef ACL_FILES +const char * g_aclfile = NULL; +#endif /* def ACL_FILES */ +#ifdef USE_IMAGE_LIST +const char * g_imagefile = NULL; +#endif /* def USE_IMAGE_LIST */ +#ifdef PCRS +const char * g_re_filterfile = NULL; +#endif +#ifdef TRUST_FILES +const char * g_trustfile = NULL; +#endif /* def TRUST_FILES */ + +/* FIXME: end kludge */ + + #ifdef REGEX /* Regular expression for detected URLs */ #define RE_URL "http:[^ \n\r]*" @@ -1041,57 +1065,43 @@ void OnLogCommand(int nCommand) break; #endif - case ID_RELOAD_CONFIG: - configret = 0; - load_config( 1 ); - - if ( configret ) - { - log_error(LOG_LEVEL_ERROR, "load_config encountered a problem! You should probably restart IJB."); - } - else - { - log_error(LOG_LEVEL_INFO, "Configuration has been reloaded."); - } - break; - case ID_TOOLS_EDITJUNKBUSTER: EditFile(configfile); break; case ID_TOOLS_EDITBLOCKERS: - EditFile(blockfile); + EditFile(g_blockfile); break; case ID_TOOLS_EDITPERMISSIONS: - EditFile(permissions_file); + EditFile(g_permissions_file); break; case ID_TOOLS_EDITFORWARD: - EditFile(forwardfile); + EditFile(g_forwardfile); break; #ifdef ACL_FILES case ID_TOOLS_EDITACLS: - EditFile(aclfile); + EditFile(g_aclfile); break; #endif /* def ACL_FILES */ #ifdef USE_IMAGE_LIST case ID_TOOLS_EDITIMAGE: - EditFile(imagefile); + EditFile(g_imagefile); break; #endif /* def USE_IMAGE_LIST */ #ifdef PCRS case ID_TOOLS_EDITPERLRE: - EditFile(re_filterfile); + EditFile(g_re_filterfile); break; #endif #ifdef TRUST_FILES case ID_TOOLS_EDITTRUST: - EditFile(trustfile); + EditFile(g_trustfile); break; #endif /* def TRUST_FILES */ @@ -1143,20 +1153,20 @@ void OnLogCommand(int nCommand) void OnLogInitMenu(HMENU hmenu) { /* Only enable editors if there is a file to edit */ - EnableMenuItem(hmenu, ID_TOOLS_EDITPERMISSIONS, MF_BYCOMMAND | (permissions_file ? MF_ENABLED : MF_GRAYED)); - EnableMenuItem(hmenu, ID_TOOLS_EDITBLOCKERS, MF_BYCOMMAND | (blockfile ? MF_ENABLED : MF_GRAYED)); - EnableMenuItem(hmenu, ID_TOOLS_EDITFORWARD, MF_BYCOMMAND | (forwardfile ? MF_ENABLED : MF_GRAYED)); + EnableMenuItem(hmenu, ID_TOOLS_EDITPERMISSIONS, MF_BYCOMMAND | (g_permissions_file ? MF_ENABLED : MF_GRAYED)); + EnableMenuItem(hmenu, ID_TOOLS_EDITBLOCKERS, MF_BYCOMMAND | (g_blockfile ? MF_ENABLED : MF_GRAYED)); + EnableMenuItem(hmenu, ID_TOOLS_EDITFORWARD, MF_BYCOMMAND | (g_forwardfile ? MF_ENABLED : MF_GRAYED)); #ifdef ACL_FILES - EnableMenuItem(hmenu, ID_TOOLS_EDITACLS, MF_BYCOMMAND | (aclfile ? MF_ENABLED : MF_GRAYED)); + EnableMenuItem(hmenu, ID_TOOLS_EDITACLS, MF_BYCOMMAND | (g_aclfile ? MF_ENABLED : MF_GRAYED)); #endif /* def ACL_FILES */ #ifdef USE_IMAGE_LIST - EnableMenuItem(hmenu, ID_TOOLS_EDITIMAGE, MF_BYCOMMAND | (imagefile ? MF_ENABLED : MF_GRAYED)); + EnableMenuItem(hmenu, ID_TOOLS_EDITIMAGE, MF_BYCOMMAND | (g_imagefile ? MF_ENABLED : MF_GRAYED)); #endif /* def USE_IMAGE_LIST */ #ifdef PCRS - EnableMenuItem(hmenu, ID_TOOLS_EDITPERLRE, MF_BYCOMMAND | (re_filterfile ? MF_ENABLED : MF_GRAYED)); + EnableMenuItem(hmenu, ID_TOOLS_EDITPERLRE, MF_BYCOMMAND | (g_re_filterfile ? MF_ENABLED : MF_GRAYED)); #endif #ifdef TRUST_FILES - EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (trustfile ? MF_ENABLED : MF_GRAYED)); + EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED)); #endif /* def TRUST_FILES */ /* Check/uncheck options */ diff --git a/w32log.h b/w32log.h index 85b43754..75da1c59 100644 --- a/w32log.h +++ b/w32log.h @@ -1,9 +1,9 @@ #ifndef _W32LOG_H #define _W32LOG_H -#define W32LOG_H_VERSION "$Id: w32log.h,v 1.1 2001/05/13 21:57:07 administrator Exp $" +#define W32LOG_H_VERSION "$Id: w32log.h,v 1.1.1.1 2001/05/15 13:59:07 oes Exp $" /********************************************************************* * - * File : $Source: /home/administrator/cvs/ijb/w32log.h,v $ + * File : $Source: /cvsroot/ijbswa/current/w32log.h,v $ * * Purpose : Functions for creating and destroying the log window, * ouputting strings, processing messages and so on. @@ -34,6 +34,9 @@ * * Revisions : * $Log: w32log.h,v $ + * Revision 1.1.1.1 2001/05/15 13:59:07 oes + * Initial import of version 2.9.3 source tree + * * *********************************************************************/ @@ -72,6 +75,27 @@ extern char g_szFontFaceName[255]; extern int g_nFontSize; +/* FIXME: this is a kludge */ + +extern const char * g_blockfile; +extern const char * g_permissions_file; +extern const char * g_forwardfile; +#ifdef ACL_FILES +extern const char * g_aclfile; +#endif /* def ACL_FILES */ +#ifdef USE_IMAGE_LIST +extern const char * g_imagefile; +#endif /* def USE_IMAGE_LIST */ +#ifdef PCRS +extern const char * g_re_filterfile; +#endif +#ifdef TRUST_FILES +extern const char * g_trustfile; +#endif /* def TRUST_FILES */ + +/* FIXME: end kludge */ + + extern int LogPutString(const char *pszText); extern BOOL InitLogWindow(void); extern void TermLogWindow(void); diff --git a/w32res.h b/w32res.h index 002872e5..c052373f 100644 --- a/w32res.h +++ b/w32res.h @@ -1,6 +1,6 @@ #ifndef _W32RES_H #define _W32RES_H -#define W32RES_H_VERSION "$Id: w32res.h,v 1.1.1.1 2001/05/15 13:59:08 oes Exp $" +#define W32RES_H_VERSION "$Id: w32res.h,v 1.2 2001/05/20 01:21:20 jongfoster Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/w32res.h,v $ @@ -34,6 +34,19 @@ * * Revisions : * $Log: w32res.h,v $ + * Revision 1.2 2001/05/20 01:21:20 jongfoster + * Version 2.9.4 checkin. + * - Merged popupfile and cookiefile, and added control over PCRS + * filtering, in new "permissionsfile". + * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration + * file error you now get a message box (in the Win32 GUI) rather + * than the program exiting with no explanation. + * - Made killpopup use the PCRS MIME-type checking and HTTP-header + * skipping. + * - Removed tabs from "config" + * - Moved duplicated url parsing code in "loaders.c" to a new funcition. + * - Bumped up version number. + * * Revision 1.1.1.1 2001/05/15 13:59:08 oes * Initial import of version 2.9.3 source tree * @@ -86,7 +99,6 @@ #ifdef TOGGLE #define ID_TOGGLE_IJB 4012 #endif -#define ID_RELOAD_CONFIG 4013 /* Break these out so they are easier to extend, but keep consecutive */ #define ID_TOOLS_EDITJUNKBUSTER 5000 -- 2.39.2