From: oes Date: Tue, 22 May 2001 18:46:04 +0000 (+0000) Subject: - Enabled filtering banners by size rather than URL X-Git-Tag: v_2_9_9~510 X-Git-Url: http://www.privoxy.org/gitweb/installation.html?a=commitdiff_plain;h=1952a87fe55ceeff77c376d61e281df7aee11db7;p=privoxy.git - 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! ;-) --- diff --git a/config.h.in b/config.h.in index 930ca660..b0217675 100644 --- a/config.h.in +++ b/config.h.in @@ -3,7 +3,7 @@ #define _CONFIG_H /********************************************************************* * - * File : $Source: /home/administrator/cvs/ijb/acconfig.h,v $ + * File : $Source: /cvsroot/ijbswa/current/config.h.in,v $ * * Purpose : This file should be the first thing included in every * .c file. (Before even system headers). It contains @@ -37,7 +37,10 @@ * Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Revisions : - * $Log: acconfig.h,v $ + * $Log: config.h.in,v $ + * Revision 1.1 2001/05/15 13:58:49 oes + * Initial revision + * * *********************************************************************/ @@ -108,6 +111,11 @@ */ #undef FORCE_LOAD +/* + * Locally redirect remote script-redirect URLs + */ +#undef FAST_REDIRECTS + /* * Split the show-proxy-args page into a page for each config file. */ diff --git a/configure b/configure index 95567ece..849b8303 100755 --- a/configure +++ b/configure @@ -23,6 +23,8 @@ ac_help="$ac_help --disable-pcrs Don't support arbitrary content modification" ac_help="$ac_help --disable-force Don't allow blockfle to be bypassed" +ac_help="$ac_help + --disable-fast-redirects Don't support fast redirects" ac_help="$ac_help --disable-killpopup Never block popups" ac_help="$ac_help @@ -588,7 +590,7 @@ EOF # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:592: checking for $ac_word" >&5 +echo "configure:594: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -618,7 +620,7 @@ if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:622: checking for $ac_word" >&5 +echo "configure:624: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -669,7 +671,7 @@ fi # Extract the first word of "cl", so it can be a program name with args. set dummy cl; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:673: checking for $ac_word" >&5 +echo "configure:675: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -701,7 +703,7 @@ fi fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:705: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 +echo "configure:707: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. @@ -712,12 +714,12 @@ cross_compiling=$ac_cv_prog_cc_cross cat > conftest.$ac_ext << EOF -#line 716 "configure" +#line 718 "configure" #include "confdefs.h" main(){return(0);} EOF -if { (eval echo configure:721: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:723: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then ac_cv_prog_cc_works=yes # If we can't run a trivial program, we are probably using a cross compiler. if (./conftest; exit) 2>/dev/null; then @@ -743,12 +745,12 @@ if test $ac_cv_prog_cc_works = no; then { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:747: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "configure:749: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:752: checking whether we are using GNU C" >&5 +echo "configure:754: checking whether we are using GNU C" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -757,7 +759,7 @@ else yes; #endif EOF -if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:761: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then +if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:763: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then ac_cv_prog_gcc=yes else ac_cv_prog_gcc=no @@ -776,7 +778,7 @@ ac_test_CFLAGS="${CFLAGS+set}" ac_save_CFLAGS="$CFLAGS" CFLAGS= echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 -echo "configure:780: checking whether ${CC-cc} accepts -g" >&5 +echo "configure:782: checking whether ${CC-cc} accepts -g" >&5 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -808,7 +810,7 @@ else fi echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:812: checking how to run the C preprocessor" >&5 +echo "configure:814: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= @@ -823,13 +825,13 @@ else # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:833: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:835: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -840,13 +842,13 @@ else rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:850: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:852: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -857,13 +859,13 @@ else rm -rf conftest* CPP="${CC-cc} -nologo -E" cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:867: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:869: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -889,19 +891,19 @@ echo "$ac_t""$CPP" 1>&6 echo $ac_n "checking for mingw32 environment""... $ac_c" 1>&6 -echo "configure:893: checking for mingw32 environment" >&5 +echo "configure:895: checking for mingw32 environment" >&5 if eval "test \"`echo '$''{'ac_cv_mingw32'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:907: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_mingw32=yes else @@ -918,12 +920,12 @@ echo "$ac_t""$ac_cv_mingw32" 1>&6 MINGW32= test "$ac_cv_mingw32" = yes && MINGW32=yes echo $ac_n "checking for Cygwin environment""... $ac_c" 1>&6 -echo "configure:922: checking for Cygwin environment" >&5 +echo "configure:924: checking for Cygwin environment" >&5 if eval "test \"`echo '$''{'ac_cv_cygwin'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:940: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_cygwin=yes else @@ -953,7 +955,7 @@ test "$ac_cv_cygwin" = yes && CYGWIN=yes echo $ac_n "checking for executable suffix""... $ac_c" 1>&6 -echo "configure:957: checking for executable suffix" >&5 +echo "configure:959: checking for executable suffix" >&5 if eval "test \"`echo '$''{'ac_cv_exeext'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -963,7 +965,7 @@ else rm -f conftest* echo 'int main () { return 0; }' > conftest.$ac_ext ac_cv_exeext= - if { (eval echo configure:967: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then + if { (eval echo configure:969: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then for file in conftest.*; do case $file in *.c | *.o | *.obj) ;; @@ -984,13 +986,13 @@ echo "$ac_t""${ac_cv_exeext}" 1>&6 ac_exeext=$EXEEXT echo $ac_n "checking for object suffix""... $ac_c" 1>&6 -echo "configure:988: checking for object suffix" >&5 +echo "configure:990: checking for object suffix" >&5 if eval "test \"`echo '$''{'ac_cv_objext'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else rm -f conftest* echo 'int i = 1;' > conftest.$ac_ext -if { (eval echo configure:994: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:996: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then for ac_file in conftest.*; do case $ac_file in *.c) ;; @@ -1010,12 +1012,12 @@ ac_objext=$ac_cv_objext echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 -echo "configure:1014: checking for ANSI C header files" >&5 +echo "configure:1016: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include @@ -1023,7 +1025,7 @@ else #include EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1027: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1029: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -1040,7 +1042,7 @@ rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -1058,7 +1060,7 @@ fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -1079,7 +1081,7 @@ if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext < #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') @@ -1090,7 +1092,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF -if { (eval echo configure:1094: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1096: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then : else @@ -1115,12 +1117,12 @@ fi echo $ac_n "checking for working const""... $ac_c" 1>&6 -echo "configure:1119: checking for working const" >&5 +echo "configure:1121: checking for working const" >&5 if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1175: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_const=yes else @@ -1190,12 +1192,12 @@ EOF fi echo $ac_n "checking for size_t""... $ac_c" 1>&6 -echo "configure:1194: checking for size_t" >&5 +echo "configure:1196: checking for size_t" >&5 if eval "test \"`echo '$''{'ac_cv_type_size_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #if STDC_HEADERS @@ -1226,12 +1228,12 @@ fi for ac_func in strerror bcopy memmove do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1230: checking for $ac_func" >&5 +echo "configure:1232: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1260: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1436,6 +1438,23 @@ EOF fi +# Check whether --enable-fast-redirects or --disable-fast-redirects was given. +if test "${enable_fast_redirects+set}" = set; then + enableval="$enable_fast_redirects" + if test $enableval = yes; then + cat >> confdefs.h <<\EOF +#define FAST_REDIRECTS 1 +EOF + +fi +else + cat >> confdefs.h <<\EOF +#define FAST_REDIRECTS 1 +EOF + +fi + + # Check whether --enable-killpopup or --disable-killpopup was given. if test "${enable_killpopup+set}" = set; then enableval="$enable_killpopup" diff --git a/configure.in b/configure.in index 808b3970..593ef0dd 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. dnl -dnl $Id: configure.in,v 1.1.1.1 2001/05/15 13:58:50 oes Exp $ +dnl $Id: configure.in,v 1.2 2001/05/20 01:21:20 jongfoster Exp $ dnl dnl Written by and Copyright (C) 2001 the SourceForge dnl IJBSWA team. http://ijbswa.sourceforge.net @@ -28,6 +28,19 @@ dnl or write to the Free Software Foundation, Inc., 59 dnl Temple Place - Suite 330, Boston, MA 02111-1307, USA. dnl dnl $Log: configure.in,v $ +dnl Revision 1.2 2001/05/20 01:21:20 jongfoster +dnl Version 2.9.4 checkin. +dnl - Merged popupfile and cookiefile, and added control over PCRS +dnl filtering, in new "permissionsfile". +dnl - Implemented LOG_LEVEL_FATAL, so that if there is a configuration +dnl file error you now get a message box (in the Win32 GUI) rather +dnl than the program exiting with no explanation. +dnl - Made killpopup use the PCRS MIME-type checking and HTTP-header +dnl skipping. +dnl - Removed tabs from "config" +dnl - Moved duplicated url parsing code in "loaders.c" to a new funcition. +dnl - Bumped up version number. +dnl dnl Revision 1.1.1.1 2001/05/15 13:58:50 oes dnl Initial import of version 2.9.3 source tree dnl @@ -180,6 +193,12 @@ AC_ARG_ENABLE(force, AC_DEFINE(FORCE_LOAD) fi],AC_DEFINE(FORCE_LOAD)) +AC_ARG_ENABLE(fast-redirects, +[ --disable-fast-redirects Don't support fast redirects], +[if test $enableval = yes; then + AC_DEFINE(FAST_REDIRECTS) +fi], AC_DEFINE(FAST_REDIRECTS)) + AC_ARG_ENABLE(killpopup, [ --disable-killpopup Never block popups], [if test $enableval = yes; then diff --git a/errlog.c b/errlog.c index f994118b..0aa139af 100644 --- a/errlog.c +++ b/errlog.c @@ -1,4 +1,4 @@ -const char errlog_rcs[] = "$Id: errlog.c,v 1.3 2001/05/20 01:11:40 jongfoster Exp $"; +const char errlog_rcs[] = "$Id: errlog.c,v 1.4 2001/05/21 19:32:54 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/errlog.c,v $ @@ -33,6 +33,9 @@ const char errlog_rcs[] = "$Id: errlog.c,v 1.3 2001/05/20 01:11:40 jongfoster Ex * * Revisions : * $Log: errlog.c,v $ + * Revision 1.4 2001/05/21 19:32:54 jongfoster + * Added another #ifdef _WIN_CONSOLE + * * Revision 1.3 2001/05/20 01:11:40 jongfoster * Added support for LOG_LEVEL_FATAL * Renamed LOG_LEVEL_FRC to LOG_LEVEL_FORCE, @@ -65,23 +68,23 @@ const char errlog_rcs[] = "$Id: errlog.c,v 1.3 2001/05/20 01:11:40 jongfoster Ex #ifdef _WIN32 #include -#ifndef _WIN_CONSOLE +#ifndef _WIN_CONSOLE #include "w32log.h" -#endif /* ndef _WIN_CONSOLE */ +#endif /* ndef _WIN_CONSOLE */ #endif /* def _WIN32 */ #include "errlog.h" #include "project.h" const char errlog_h_rcs[] = ERRLOG_H_VERSION; - - -/* - * LOG_LEVEL_FATAL, LOG_LEVEL_ERROR and LOG_LEVEL_INFO - * cannot be turned off. (There are some exceptional situations - * where we need to get a message to the user). - * - * FIXME: Do we need LOG_LEVEL_INFO here? + + +/* + * LOG_LEVEL_FATAL, LOG_LEVEL_ERROR and LOG_LEVEL_INFO + * cannot be turned off. (There are some exceptional situations + * where we need to get a message to the user). + * + * FIXME: Do we need LOG_LEVEL_INFO here? */ #define LOG_LEVEL_MINIMUM (LOG_LEVEL_FATAL | LOG_LEVEL_ERROR | LOG_LEVEL_INFO) @@ -94,35 +97,35 @@ static char * logfilename = NULL; /* logging detail level. */ static int debug = LOG_LEVEL_MINIMUM; -static void fatal_error(const char * error_message); - - -/********************************************************************* - * - * Function : fatal_error - * - * Description : Displays a fatal error to standard error (or, on - * a WIN32 GUI, to a dialog box), and exits - * JunkBuster with status code 1. - * - * Parameters : - * 1 : error_message = The error message to display. - * - * Returns : Does not return. - * - *********************************************************************/ -static void fatal_error(const char * error_message) -{ -#if defined(_WIN32) && !defined(_WIN_CONSOLE) - MessageBox(NULL, error_message, "Internet JunkBuster Error", - MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST); -#else /* if !defined(_WIN32) || defined(_WIN_CONSOLE) */ - fputs(error_message, stderr); -#endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */ - - exit(1); -} - +static void fatal_error(const char * error_message); + + +/********************************************************************* + * + * Function : fatal_error + * + * Description : Displays a fatal error to standard error (or, on + * a WIN32 GUI, to a dialog box), and exits + * JunkBuster with status code 1. + * + * Parameters : + * 1 : error_message = The error message to display. + * + * Returns : Does not return. + * + *********************************************************************/ +static void fatal_error(const char * error_message) +{ +#if defined(_WIN32) && !defined(_WIN_CONSOLE) + MessageBox(NULL, error_message, "Internet JunkBuster Error", + MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST); +#else /* if !defined(_WIN32) || defined(_WIN_CONSOLE) */ + fputs(error_message, stderr); +#endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */ + + exit(1); +} + /********************************************************************* * @@ -158,7 +161,7 @@ void init_error_log(const char *prog_name, const char *logfname, int debuglevel) if( logfname ) { if( !(fp = fopen(logfname, "a")) ) - { + { log_error(LOG_LEVEL_FATAL, "init_errlog(): can't open logfile: %s", logfname); } @@ -212,12 +215,12 @@ void log_error(int loglevel, char *fmt, ...) switch (loglevel) { - case LOG_LEVEL_ERROR: - outc = sprintf(outbuf, "IJB(%d) Error: ", this_thread); - break; - case LOG_LEVEL_FATAL: - outc = sprintf(outbuf, "IJB(%d) Fatal error: ", this_thread); - break; + case LOG_LEVEL_ERROR: + outc = sprintf(outbuf, "IJB(%d) Error: ", this_thread); + break; + case LOG_LEVEL_FATAL: + outc = sprintf(outbuf, "IJB(%d) Fatal error: ", this_thread); + break; case LOG_LEVEL_GPC: outc = sprintf(outbuf, "IJB(%d) Request: ", this_thread); break; @@ -227,15 +230,24 @@ void log_error(int loglevel, char *fmt, ...) case LOG_LEVEL_HEADER: outc = sprintf(outbuf, "IJB(%d) Header: ", this_thread); break; - case LOG_LEVEL_INFO: - outc = sprintf(outbuf, "IJB(%d) Info: ", this_thread); - break; + case LOG_LEVEL_INFO: + outc = sprintf(outbuf, "IJB(%d) Info: ", this_thread); + break; +#ifdef PCRS case LOG_LEVEL_RE_FILTER: outc = sprintf(outbuf, "IJB(%d) Re-Filter: ", this_thread); break; +#endif /* def PCRS */ +#ifdef FORCE_LOAD case LOG_LEVEL_FORCE: outc = sprintf(outbuf, "IJB(%d) Force: ", this_thread); - break; + break; +#endif /* def FORCE_LOAD */ +#ifdef FAST_REDIRECTS + case LOG_LEVEL_REDIRECTS: + outc = sprintf(outbuf, "IJB(%d) Redirect: ", this_thread); + break; +#endif /* def FAST_REDIRECTS */ default: outc = sprintf(outbuf, "IJB(%d) UNKNOWN LOG TYPE(%d): ", this_thread, loglevel); break; @@ -322,8 +334,8 @@ void log_error(int loglevel, char *fmt, ...) } fputs(outbuf, logfp); /* FIXME RACE HAZARD: should end critical section error_log_use here */ - fatal_error(outbuf); - /* Never get here */ + fatal_error(outbuf); + /* Never get here */ break; } if (outc < BUFSIZ-1) @@ -390,8 +402,8 @@ void log_error(int loglevel, char *fmt, ...) } fputs(outbuf, logfp); /* FIXME RACE HAZARD: should end critical section error_log_use here */ - fatal_error(outbuf); - /* Never get here */ + fatal_error(outbuf); + /* Never get here */ break; } /* switch( p ) */ @@ -436,14 +448,14 @@ void log_error(int loglevel, char *fmt, ...) fputs(outbuf, logfp); - if (loglevel == LOG_LEVEL_FATAL) - { - fatal_error(outbuf); - /* Never get here */ - } - + if (loglevel == LOG_LEVEL_FATAL) + { + fatal_error(outbuf); + /* Never get here */ + } + /* FIXME RACE HAZARD: should end critical section error_log_use here */ - + #if defined(_WIN32) && !defined(_WIN_CONSOLE) /* Write to display */ LogPutString(outbuf); diff --git a/errlog.h b/errlog.h index 82f8bc5e..22c7c810 100644 --- a/errlog.h +++ b/errlog.h @@ -1,6 +1,6 @@ #ifndef _ERRLOG_H #define _ERRLOG_H -#define ERRLOG_H_VERSION "$Id: errlog.h,v 1.1.1.1 2001/05/15 13:58:51 oes Exp $" +#define ERRLOG_H_VERSION "$Id: errlog.h,v 1.2 2001/05/20 01:11:40 jongfoster Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/errlog.h,v $ @@ -35,6 +35,11 @@ * * Revisions : * $Log: errlog.h,v $ + * Revision 1.2 2001/05/20 01:11:40 jongfoster + * Added support for LOG_LEVEL_FATAL + * Renamed LOG_LEVEL_FRC to LOG_LEVEL_FORCE, + * and LOG_LEVEL_REF to LOG_LEVEL_RE_FILTER + * * Revision 1.1.1.1 2001/05/15 13:58:51 oes * Initial import of version 2.9.3 source tree * @@ -53,15 +58,20 @@ extern "C" { #define LOG_LEVEL_IO 0x0004 #define LOG_LEVEL_HEADER 0x0008 #define LOG_LEVEL_LOG 0x0010 -#ifdef PCRS +#ifdef FORCE_LOAD #define LOG_LEVEL_FORCE 0x0020 +#endif /* def FORCE_LOAD */ +#ifdef PCRS #define LOG_LEVEL_RE_FILTER 0x0040 #endif /* def PCRS */ +#ifdef FAST_REDIRECTS +#define LOG_LEVEL_REDIRECTS 0x0080 +#endif /* def FAST_REDIRECTS */ /* Following are always on: */ #define LOG_LEVEL_INFO 0x1000 -#define LOG_LEVEL_ERROR 0x2000 -#define LOG_LEVEL_FATAL 0x4000 /* Exits after writing log */ +#define LOG_LEVEL_ERROR 0x2000 +#define LOG_LEVEL_FATAL 0x4000 /* Exits after writing log */ extern void init_error_log(const char *prog_name, const char *logfname, int debuglevel); extern void log_error(int loglevel, char *fmt, ...); diff --git a/filters.c b/filters.c index f61f4fc1..42f46aff 100644 --- a/filters.c +++ b/filters.c @@ -1,4 +1,4 @@ -const char filters_rcs[] = "$Id: filters.c,v 1.2 2001/05/20 01:21:20 jongfoster Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 1.3 2001/05/20 16:44:47 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.c,v $ @@ -7,9 +7,9 @@ const char filters_rcs[] = "$Id: filters.c,v 1.2 2001/05/20 01:21:20 jongfoster * Functions declared include: * `acl_addr', `add_stats', `block_acl', `block_imageurl', * `block_url', `url_permissions', `domaincmp', `dsplit', - * `filter_popups', `forward_url', + * `filter_popups', `forward_url', 'redirect_url', * `ij_untrusted_url', `intercept_url', `re_process_buffer', - * `show_proxy_args', and `trust_url' + * `show_proxy_args', 'ijb_send_banner', and `trust_url' * * Copyright : Written by and Copyright (C) 2001 the SourceForge * IJBSWA team. http://ijbswa.sourceforge.net @@ -38,6 +38,9 @@ const char filters_rcs[] = "$Id: filters.c,v 1.2 2001/05/20 01:21:20 jongfoster * * Revisions : * $Log: filters.c,v $ + * Revision 1.3 2001/05/20 16:44:47 jongfoster + * Removing last hardcoded JunkBusters.com URLs. + * * Revision 1.2 2001/05/20 01:21:20 jongfoster * Version 2.9.4 checkin. * - Merged popupfile and cookiefile, and added control over PCRS @@ -123,8 +126,8 @@ static const char CBLOCK[] = "was blocked because it matches the following pattern " "in the blockfile: %s\n

" #ifdef FORCE_LOAD - "

Go there anyway.

" + "

Go there anyway.

" #endif /* def FORCE_LOAD */ "\n" "\n"; @@ -510,9 +513,9 @@ void re_process_buffer(struct client_state *csp) struct re_filterfile_spec *b; /* Sanity first ;-) */ - if (size <= 0) - { - return; + if (size <= 0) + { + return; } if ( ( NULL == (fl = csp->rlist) ) || ( NULL == (b = fl->f) ) ) @@ -805,6 +808,50 @@ char *intercept_url(struct http_request *http, struct client_state *csp) } +#ifdef FAST_REDIRECTS +/********************************************************************* + * + * Function : redirect_url + * + * Description : Checks for redirection URLs and returns a HTTP redirect + * to the destination URL. + * + * Parameters : + * 1 : http = http_request request, check `basename's of blocklist + * 2 : csp = Current client state (buffers, headers, etc...) + * + * Returns : NULL if URL was clean, HTTP redirect otherwise. + * + *********************************************************************/ +char *redirect_url(struct http_request *http, struct client_state *csp) +{ + char *p, *q; + + p = q = csp->http->path; + log_error(LOG_LEVEL_REDIRECTS, "checking path: %s", p); + + /* find the last URL encoded in the request */ + while (p = strstr(p, "http://")) + { + q = p++; + } + + /* if there was any, generate and return a HTTP redirect */ + if (q != csp->http->path) + { + log_error(LOG_LEVEL_REDIRECTS, "redirecting to: %s", q); + + p = (char *)malloc(strlen(HTTP_REDIRECT_TEMPLATE) + strlen(q)); + sprintf(p, HTTP_REDIRECT_TEMPLATE, q); + return(p); + } + else + { + return(NULL); + } + +} +#endif /* def FAST_REDIRECTS */ /********************************************************************* * @@ -816,7 +863,7 @@ char *intercept_url(struct http_request *http, struct client_state *csp) * 1 : http = http_request request for blocked URLs * 2 : csp = Current client state (buffers, headers, etc...) * - * Returns : permissions bitmask specifiying what this URL can do. + * Returns : permissions bitmask specifiying what this URL can do. * If not on list, will be default_permissions. * *********************************************************************/ @@ -834,9 +881,9 @@ int url_permissions(struct http_request *http, struct client_state *csp) *url = dsplit(http->host); /* if splitting the domain fails, punt */ - if (url->dbuf == NULL) - { - return(default_permissions); + if (url->dbuf == NULL) + { + return(default_permissions); } for (b = b->next; NULL != b; b = b->next) @@ -1200,7 +1247,7 @@ char *show_proxy_args(struct http_request *http, struct client_state *csp) "
\n" "

\n" "The " BANNER " Proxy - \n" - "" HOME_PAGE_URL "\n" + "" HOME_PAGE_URL "\n" "" "\n"); return(s); @@ -1258,7 +1305,7 @@ char *show_proxy_args(struct http_request *http, struct client_state *csp) s = strsav(s, "\n"); } #endif /* def USE_IMAGE_LIST */ - + #ifdef PCRS if (csp->rlist) { @@ -1332,6 +1379,28 @@ char *show_proxy_args(struct http_request *http, struct client_state *csp) } +/********************************************************************* + * + * Function : ijb_send_banner + * + * Description : This "crunch"es "http:/any.thing/ijb-send-banner and + * thus triggers sending the image in jcc.c:chat. + * For the unlikely case, that the imagefile/MSIE + * mechanism is not used, or tinygif = 0, a page + * describing the reson of the interception is generated. + * + * Parameters : + * 1 : http = http_request request for crunched URL + * 2 : csp = Current client state (buffers, headers, etc...) + * + * Returns : A string that contains why this was intercepted. + * + *********************************************************************/ +char *ijb_send_banner(struct http_request *http, struct client_state *csp) +{ + return(strdup(CNOBANNER)); +} + #ifdef TRUST_FILES /********************************************************************* * diff --git a/filters.h b/filters.h index a510ddf4..70643883 100644 --- a/filters.h +++ b/filters.h @@ -1,6 +1,6 @@ #ifndef _FILTERS_H #define _FILTERS_H -#define FILTERS_H_VERSION "$Id: filters.h,v 1.1.1.1 2001/05/15 13:58:52 oes Exp $" +#define FILTERS_H_VERSION "$Id: filters.h,v 1.2 2001/05/20 01:21:20 jongfoster Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.h,v $ @@ -40,12 +40,25 @@ * * Revisions : * $Log: filters.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:58:52 oes * Initial import of version 2.9.3 source tree * * *********************************************************************/ - + #include "project.h" @@ -63,6 +76,7 @@ extern char *block_url(struct http_request *http, struct client_state *csp); extern char *trust_url(struct http_request *http, struct client_state *csp); #endif /* def TRUST_FILES */ extern char *intercept_url(struct http_request *http, struct client_state *csp); +extern char *redirect_url(struct http_request *http, struct client_state *csp); #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) extern int block_imageurl(struct http_request *http, struct client_state *csp); @@ -79,6 +93,7 @@ extern struct url_spec dsplit(char *domain); extern int domaincmp(struct url_spec *pattern, struct url_spec *fqdn); extern char *show_proxy_args(struct http_request *http, struct client_state *csp); +extern char *ijb_send_banner(struct http_request *http, struct client_state *csp); #ifdef TRUST_FILES extern char *ij_untrusted_url(struct http_request *http, struct client_state *csp); diff --git a/jcc.c b/jcc.c index ee27d19d..9b3b9ee8 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.3 2001/05/20 01:21:20 jongfoster Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.4 2001/05/21 19:34:01 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -33,6 +33,9 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.3 2001/05/20 01:21:20 jongfoster Exp $"; * * Revisions : * $Log: jcc.c,v $ + * Revision 1.4 2001/05/21 19:34:01 jongfoster + * Made failure to bind() a fatal error. + * * Revision 1.3 2001/05/20 01:21:20 jongfoster * Version 2.9.4 checkin. * - Merged popupfile and cookiefile, and added control over PCRS @@ -135,90 +138,6 @@ static void serve(struct client_state *csp); static int32 server_thread(void *data); #endif /* def __BEOS__ */ - -#define BODY "\n" - -static const char CFAIL[] = - "HTTP/1.0 503 Connect failed\n" - "Content-Type: text/html\n\n" - "\n" - "\n" - "Internet Junkbuster: Connect failed\n" - "\n" - BODY - "

" - BANNER - "

" - "TCP connection to '%s' failed: %s.\n
" - "\n" - "\n"; - -static const char CNXDOM[] = - "HTTP/1.0 404 Non-existent domain\n" - "Content-Type: text/html\n\n" - "\n" - "\n" - "Internet Junkbuster: Non-existent domain\n" - "\n" - BODY - "

" - BANNER - "

" - "No such domain: %s\n" - "\n" - "\n"; - -static const char CSUCCEED[] = - "HTTP/1.0 200 Connection established\n" - "Proxy-Agent: IJ/" VERSION "\n\n"; - -static const char CHEADER[] = - "HTTP/1.0 400 Invalid header received from browser\n\n"; - -static const char SHEADER[] = - "HTTP/1.0 502 Invalid header received from server\n\n"; - -#if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) - -/* - * Hint: You can encode your own GIFs like that: - * perl -e 'while (read STDIN, $c, 1) { printf("\\%.3o,", unpack("C", $c)); }' - */ - -static const char BLANKGIF[] = - "HTTP/1.0 200 OK\r\n" - "Pragma: no-cache\r\n" - "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n" - "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n" - "Content-type: image/gif\r\n\r\n" - "GIF89a\001\000\001\000\200\000\000\377\377\377\000\000" - "\000!\371\004\001\000\000\000\000,\000\000\000\000\001" - "\000\001\000\000\002\002D\001\000;"; - -static const char JBGIF[] = - "HTTP/1.0 200 OK\r\n" - "Pragma: no-cache\r\n" - "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n" - "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n" - "Content-type: image/gif\r\n\r\n" - "GIF89aD\000\013\000\360\000\000\000\000\000\377\377\377!" - "\371\004\001\000\000\001\000,\000\000\000\000D\000\013\000" - "\000\002a\214\217\251\313\355\277\000\200G&K\025\316hC\037" - "\200\234\230Y\2309\235S\230\266\206\372J\253<\3131\253\271" - "\270\215\342\254\013\203\371\202\264\334P\207\332\020o\266" - "N\215I\332=\211\312\3513\266:\026AK)\364\370\365aobr\305" - "\372\003S\275\274k2\354\254z\347?\335\274x\306^9\374\276" - "\037Q\000\000;"; - -static const char FWGIF[] = - "HTTP/1.0 302 Blocked Advert\r\n" - "Pragma: no-cache\r\n" - "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n" - "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n" - "Location: "; - -#endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */ - #ifdef _WIN32 #define sleep(N) Sleep(((N) * 1000)) #endif @@ -247,36 +166,35 @@ static const char FWGIF[] = *********************************************************************/ static void chat(struct client_state *csp) { -/* This next line is a little ugly, but it simplifies the if statement below. */ -/* Basically if TOGGLE, then we want the if to test "csp->toggled_on", else we don't */ -#ifdef TOGGLE -# define IS_TOGGLED_ON csp->toggled_on && -#else /* ifndef TOGGLE */ -# define IS_TOGGLED_ON -#endif /* ndef TOGGLE */ - -/* This next line is a little ugly, but it simplifies the if statement below. */ -/* Basically if TRUST_FILES, then we want the if to call "trust_url", else we don't */ -#ifdef TRUST_FILES -# define IS_TRUSTED_URL (p = trust_url(http, csp)) || -#else /* ifndef TRUST_FILES */ -# define IS_TRUSTED_URL -#endif /* ndef TRUST_FILES */ - - +/* This next line is a little ugly, but it simplifies the if statement below. */ +/* Basically if TOGGLE, then we want the if to test "csp->toggled_on", else we don't */ +#ifdef TOGGLE +# define IS_TOGGLED_ON csp->toggled_on && +#else /* ifndef TOGGLE */ +# define IS_TOGGLED_ON +#endif /* ndef TOGGLE */ + +/* This next line is a little ugly, but it simplifies the if statement below. */ +/* Basically if TRUST_FILES, then we want the if to call "trust_url", else we don't */ +#ifdef TRUST_FILES +# define IS_TRUSTED_URL (p = trust_url(http, csp)) || +#else /* ifndef TRUST_FILES */ +# define IS_TRUSTED_URL +#endif /* ndef TRUST_FILES */ + char buf[BUFSIZ], *hdr, *p, *req; char *err = NULL; char *eno; fd_set rfds; int n, maxfd, server_body, ms_iis5_hack = 0; const struct gateway *gw; - struct http_request *http; -#ifdef KILLPOPUPS - int block_popups; /* bool, 1==will block popups */ - int block_popups_now = 0; /* bool, 1==currently blocking popups */ -#endif /* def KILLPOPUPS */ + struct http_request *http; +#ifdef KILLPOPUPS + int block_popups; /* bool, 1==will block popups */ + int block_popups_now = 0; /* bool, 1==currently blocking popups */ +#endif /* def KILLPOPUPS */ #ifdef PCRS - int pcrs_filter; /* bool, 1==will filter through pcrs */ + int pcrs_filter; /* bool, 1==will filter through pcrs */ int filtering = 0; /* bool, 1==currently filtering through pcrs */ #endif /* def PCRS */ @@ -341,7 +259,7 @@ static void chat(struct client_state *csp) if ((gw = forward_url(http, csp)) == NULL) { log_error(LOG_LEVEL_FATAL, "gateway spec is NULL!?!? This can't happen!"); - /* Never get here - LOG_LEVEL_FATAL causes program exit */ + /* Never get here - LOG_LEVEL_FATAL causes program exit */ } /* build the http request to send to the server @@ -389,31 +307,31 @@ static void chat(struct client_state *csp) freez(p); } } - + /* decide what we're to do with cookies */ - -#ifdef TOGGLE - if (!csp->toggled_on) - { - /* Most compatible set of permissions */ - csp->permissions = PERMIT_COOKIE_SET | PERMIT_COOKIE_READ | PERMIT_POPUPS; - } - else - { - csp->permissions = url_permissions(http, csp); - } -#else /* ifndef TOGGLE */ - csp->permissions = url_permissions(http, csp); -#endif /* ndef TOGGLE */ - -#ifdef KILLPOPUPS - block_popups = ((csp->permissions & PERMIT_POPUPS) == 0); -#endif /* def KILLPOPUPS */ -#ifdef PCRS - pcrs_filter = (csp->rlist != NULL) && /* There are expressions to be used */ + +#ifdef TOGGLE + if (!csp->toggled_on) + { + /* Most compatible set of permissions */ + csp->permissions = PERMIT_COOKIE_SET | PERMIT_COOKIE_READ | PERMIT_POPUPS; + } + else + { + csp->permissions = url_permissions(http, csp); + } +#else /* ifndef TOGGLE */ + csp->permissions = url_permissions(http, csp); +#endif /* ndef TOGGLE */ + +#ifdef KILLPOPUPS + block_popups = ((csp->permissions & PERMIT_POPUPS) == 0); +#endif /* def KILLPOPUPS */ +#ifdef PCRS + pcrs_filter = (csp->rlist != NULL) && /* There are expressions to be used */ ((csp->permissions & PERMIT_RE_FILTER) != 0); -#endif /* def PCRS */ - +#endif /* def PCRS */ + /* grab the rest of the client's headers */ @@ -443,15 +361,8 @@ static void chat(struct client_state *csp) destroy_list(csp->headers); - - /* - * by haroon - most of credit to srt19170 - * if toggled_on flag is true then IJB is enabled, do the usual - * otherwise avoid crunching - */ - /* Check the request against all rules, unless - * we're disabled or in force mode. + * we're toggled off or in force mode. */ if (IS_TOGGLED_ON @@ -460,7 +371,11 @@ static void chat(struct client_state *csp) #endif /* def FORCE_LOAD */ ( (p = intercept_url(http, csp)) || IS_TRUSTED_URL - (p = block_url(http, csp)) )) + (p = block_url(http, csp)) +#ifdef FAST_REDIRECTS + || (fast_redirects && (p = redirect_url(http, csp))) +#endif /* def FAST_REDIRECTS */ + )) { #ifdef STATISTICS csp->rejected = 1; @@ -469,31 +384,33 @@ static void chat(struct client_state *csp) log_error(LOG_LEVEL_GPC, "%s%s crunch!", http->hostport, http->path); #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) - /* now use block_imageurl */ + /* Block as image? */ if ( (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")) + { + write_socket(csp->cfd, JBGIF, sizeof(JBGIF)-1); + } if (tinygif == 1) { write_socket(csp->cfd, BLANKGIF, sizeof(BLANKGIF)-1); } else if ((tinygif == 3) && (tinygifurl)) { - write_socket(csp->cfd, FWGIF, sizeof(FWGIF)-1); - write_socket(csp->cfd, tinygifurl, strlen(tinygifurl)); - } - else - { - write_socket(csp->cfd, JBGIF, sizeof(JBGIF)-1); + p = (char *)malloc(strlen(HTTP_REDIRECT_TEMPLATE) + strlen(tinygifurl)); + sprintf(p, HTTP_REDIRECT_TEMPLATE, tinygifurl); + write_socket(csp->cfd, p, strlen(p)); } } else #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */ + /* Block as HTML */ { - /* Send HTML "blocked" message */ + /* Send HTML "blocked" message, interception, or redirection result */ write_socket(csp->cfd, p, strlen(p)); } @@ -797,24 +714,24 @@ static void chat(struct client_state *csp) * the client (along with anything else that * may be in the buffer) */ - -#ifdef KILLPOPUPS - /* Start blocking popups if appropriate. */ - - if (csp->is_text && /* It's a text / * MIME-Type */ - !http->ssl && /* We talk plaintext */ - block_popups) - { - block_popups_now = 1; - } - -#endif /* def KILLPOPUPS */ - + +#ifdef KILLPOPUPS + /* Start blocking popups if appropriate. */ + + if (csp->is_text && /* It's a text / * MIME-Type */ + !http->ssl && /* We talk plaintext */ + block_popups) + { + block_popups_now = 1; + } + +#endif /* def KILLPOPUPS */ + #ifdef PCRS /* Start re_filtering this if appropriate. */ - + if (csp->is_text && /* It's a text / * MIME-Type */ - !http->ssl && /* We talk plaintext */ + !http->ssl && /* We talk plaintext */ pcrs_filter) /* Policy allows */ { filtering = 1; @@ -1056,7 +973,7 @@ static void listen_loop(void) "- There may be another junkbuster or some other " "proxy running on port %d", (NULL != haddr) ? haddr : "INADDR_ANY", hport, hport - ); + ); /* shouldn't get here */ return; } @@ -1136,7 +1053,7 @@ static void listen_loop(void) if (run_loader(csp)) { - log_error(LOG_LEVEL_FATAL, "a loader failed - must exit"); + log_error(LOG_LEVEL_FATAL, "a loader failed - must exit"); /* Never get here - LOG_LEVEL_FATAL causes program exit */ } diff --git a/loadcfg.c b/loadcfg.c index 185241be..e85f47e1 100644 --- a/loadcfg.c +++ b/loadcfg.c @@ -1,4 +1,4 @@ -const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.2 2001/05/17 23:01:01 oes Exp $"; +const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.3 2001/05/20 01:21:20 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $ @@ -35,6 +35,19 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.2 2001/05/17 23:01:01 oes Exp $"; * * Revisions : * $Log: loadcfg.c,v $ + * Revision 1.3 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.2 2001/05/17 23:01:01 oes * - Cleaned CRLF's from the sources and related files * @@ -143,16 +156,20 @@ const char *aclfile = NULL; #ifdef USE_IMAGE_LIST const char *imagefile = NULL; #endif /* def USE_IMAGE_LIST */ - -/* - * Permissions to use for URLs not in the permissions list. + +/* + * Permissions to use for URLs not in the permissions list. */ -int default_permissions = PERMIT_RE_FILTER; +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 */ @@ -212,7 +229,7 @@ const char **Argv = NULL; * something a little more readable. This also makes changing the * hash values easier if they should change or the hash algorthm changes. * Use the included "hash" program to find out what the hash will be - * for any string supplied on the command line. (Or just put it in the + * for any string supplied on the command line. (Or just put it in the * config file and read the number from the error message in the log). */ @@ -225,7 +242,7 @@ const char **Argv = NULL; #define hash_suppress_vanilla_wafer 3121233547ul #define hash_wafer 89669ul #define hash_add_header 237434619ul -#define hash_permissions_file 3825730796lu /* "permissionsfile" */ +#define hash_permissions_file 3825730796lu /* "permissionsfile" */ #define hash_logfile 2114766ul #define hash_blockfile 48845391ul #define hash_imagefile 51447891ul @@ -238,6 +255,7 @@ const char **Argv = NULL; #define hash_referrer 10883969ul #define hash_referer 2176719ul #define hash_from 16264ul +#define hash_fast_redirects 464873764lu #define hash_hide_console 2048809870ul #define hash_include_stats 2174146548ul #define hash_suppress_blocklists 1948693308ul @@ -267,7 +285,7 @@ const char **Argv = NULL; * 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 ); + * Ie. Is is called from main and from signal( SIGHUP ); * *********************************************************************/ void load_config( int signum ) @@ -309,8 +327,8 @@ void load_config( int signum ) #endif /* def JAR_FILES */ debug = 0; - multi_threaded = 1; - + multi_threaded = 1; + default_permissions = PERMIT_RE_FILTER; #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) @@ -374,13 +392,17 @@ void load_config( int signum ) freez((char *)re_filterfile); #endif /* def PCRS */ +#ifdef FAST_REDIRECTS + fast_redirects = 0; +#endif /* def FAST_REDIRECTS */ + if (NULL != configfile) { 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 */ + /* Never get here - LOG_LEVEL_FATAL causes program exit */ } } @@ -577,6 +599,12 @@ void load_config( int signum ) from = strdup(arg); continue; +#ifdef FAST_REDIRECTS + case hash_fast_redirects : + fast_redirects = 1; + continue; +#endif /* def FAST_REDIRECTS */ + #ifdef _WIN_CONSOLE case hash_hide_console : hideConsole = 1; @@ -689,11 +717,11 @@ void load_config( int signum ) 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. - */ + /* + * 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 ); @@ -786,7 +814,7 @@ void load_config( int signum ) { *--p = ':'; log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", haddr); - /* Never get here - LOG_LEVEL_FATAL causes program exit */ + /* Never get here - LOG_LEVEL_FATAL causes program exit */ } if (*haddr == '\0') { @@ -796,8 +824,8 @@ void load_config( int signum ) if (run_loader(NULL)) { - log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting."); - /* Never get here - LOG_LEVEL_FATAL causes program exit */ + log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting."); + /* Never get here - LOG_LEVEL_FATAL causes program exit */ } #ifdef JAR_FILES diff --git a/loadcfg.h b/loadcfg.h index 58ed1bbb..4c9e9924 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.2 2001/05/17 23:01:01 oes Exp $" +#define LOADCFG_H_VERSION "$Id: loadcfg.h,v 1.3 2001/05/20 01:21:20 jongfoster Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loadcfg.h,v $ @@ -37,6 +37,19 @@ * * Revisions : * $Log: loadcfg.h,v $ + * Revision 1.3 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.2 2001/05/17 23:01:01 oes * - Cleaned CRLF's from the sources and related files * @@ -96,7 +109,11 @@ extern const char *trustfile; extern const char *re_filterfile; #endif /* def PCRS */ -extern int default_permissions; +#ifdef FAST_REDIRECTS +extern int fast_redirects; +#endif /* def FAST_REDIRECTS */ + +extern int default_permissions; #ifdef JAR_FILES extern const char *jarfile; diff --git a/parsers.c b/parsers.c index ad686b3b..4f51e0bf 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.2 2001/05/17 23:02:36 oes Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.3 2001/05/20 01:21:20 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -41,6 +41,19 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.2 2001/05/17 23:02:36 oes Exp $"; * * Revisions : * $Log: parsers.c,v $ + * Revision 1.3 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.2 2001/05/17 23:02:36 oes * - Made referrer option accept 'L' as a substitute for 'ยง' * @@ -114,8 +127,9 @@ const struct parsers client_patterns[] = { const struct interceptors intercept_patterns[] = { { "show-proxy-args", 14, show_proxy_args }, + { "ijb-send-banner", 14, ijb_send_banner }, #ifdef TRUST_FILES - { "ij-untrusted-url", 14, ij_untrusted_url }, + { "ij-untrusted-url", 15, ij_untrusted_url }, #endif /* def TRUST_FILES */ { NULL, 0, NULL } }; diff --git a/pcrs.c b/pcrs.c index cd0c94a8..edb1ebfc 100644 --- a/pcrs.c +++ b/pcrs.c @@ -1,18 +1,17 @@ -const char pcrs_rcs[] = "$Id: pcrs.c,v 1.1 2001/05/13 21:57:07 administrator Exp $"; +const char pcrs_rcs[] = "$Id: pcrs.c,v 1.1.1.1 2001/05/15 13:59:02 oes Exp $"; /********************************************************************* * - * File : $Source: /home/administrator/cvs/ijb/pcrs.c,v $ + * File : $Source: /cvsroot/ijbswa/current/pcrs.c,v $ * - * Purpose : This is the pre-pre-alpha realease of libpcrs. It is only - * published at this (ugly) stage of development, because it is + * Purpose : This is the alpha release of libpcrs. It is only published + * at this early stage of development, because it is * needed for a new feature in JunkBuster. * - * Apart from the code being quite a mess, no inconsistencies, - * memory leaks or functional bugs **should** be present. - * - * While you ROTFL at the code, you could just as well mail me - * (andreas@oesterhelt.org) with advice for improvement. + * While no inconsistencies, memory leaks or functional bugs + * are known at this time, there *could* be plenty ;-). Also, + * Many pcre-specific options are not yet supported, and + * error handling needs improvement. * * pcrs is a supplement to the brilliant pcre library by Philip * Hazel (ph10@cam.ac.uk) and adds Perl-style substitution. That @@ -21,10 +20,32 @@ const char pcrs_rcs[] = "$Id: pcrs.c,v 1.1 2001/05/13 21:57:07 administrator Exp * Currently, there's no documentation besides comments and the * source itself ;-) * - * Copyright : Written and copyright by andreas@oesterhelt.org + * Copyright : Written and Copyright (C) 2000 by Andreas Oesterhelt + * + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public + * License for more details. + * + * The GNU General Public License should be included with + * this file. If not, you can view it at + * http://www.gnu.org/copyleft/gpl.html + * or write to the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Revisions : * $Log: pcrs.c,v $ + * Revision 1.1.1.1 2001/05/15 13:59:02 oes + * Initial import of version 2.9.3 source tree + * * *********************************************************************/ @@ -121,6 +142,7 @@ int pcrs_compile_perl_options(char *optstring, int *globalflag) case 'o': break; case 's': rc |= PCRE_DOTALL; break; case 'x': rc |= PCRE_EXTENDED; break; + case 'U': rc |= PCRE_UNGREEDY; break; default: break; } } diff --git a/project.h b/project.h index 7371d659..28511c91 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.2 2001/05/17 23:01:01 oes Exp $" +#define PROJECT_H_VERSION "$Id: project.h,v 1.3 2001/05/20 01:21:20 jongfoster Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/project.h,v $ @@ -36,6 +36,19 @@ * * Revisions : * $Log: project.h,v $ + * Revision 1.3 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.2 2001/05/17 23:01:01 oes * - Cleaned CRLF's from the sources and related files * @@ -118,7 +131,6 @@ struct http_request int ssl; }; - struct gateway { /* generic attributes */ @@ -188,8 +200,8 @@ struct list struct client_state { - int permissions; - + int permissions; + int cfd; int sfd; @@ -242,17 +254,17 @@ struct client_state /* files associated with this client */ struct file_list *blist; /* blockfile */ struct file_list *flist; /* forwardfile */ - struct file_list *permissions_list; - + struct file_list *permissions_list; -#ifdef ACL_FILES + +#ifdef ACL_FILES struct file_list *alist; /* aclfile */ #endif /* def ACL_FILES */ #ifdef USE_IMAGE_LIST struct file_list *ilist; /* imagefile */ #endif /* def USE_IMAGE_LIST */ - + #ifdef PCRS struct file_list *rlist; /* Perl re_filterfile */ #endif /* def PCRS */ @@ -260,7 +272,7 @@ struct client_state #ifdef TRUST_FILES struct file_list *tlist; /* trustfile */ #endif /* def TRUST_FILES */ - + struct client_state *next; }; @@ -349,20 +361,20 @@ struct block_spec int reject; struct block_spec *next; }; - - -#define PERMIT_COOKIE_SET 0x0001 -#define PERMIT_COOKIE_READ 0x0002 -#define PERMIT_RE_FILTER 0x0004 -#define PERMIT_POPUPS 0x0008 - -struct permissions_spec -{ - struct url_spec url[1]; - int permissions; - struct permissions_spec * next; -}; - + + +#define PERMIT_COOKIE_SET 0x0001 +#define PERMIT_COOKIE_READ 0x0002 +#define PERMIT_RE_FILTER 0x0004 +#define PERMIT_POPUPS 0x0008 + +struct permissions_spec +{ + struct url_spec url[1]; + int permissions; + struct permissions_spec * next; +}; + struct forward_spec { struct url_spec url[1]; @@ -380,7 +392,7 @@ struct re_filterfile_spec pcrs_job *joblist; }; #endif /* def PCRS */ - + #ifdef ACL_FILES #define ACL_PERMIT 1 /* accept connection request */ @@ -410,20 +422,113 @@ struct access_control_list #define BANNER "Internet JUNKBUSTER" #ifdef FORCE_LOAD -/* - * FIXME: Unfortunately, IE lowercases the domain name. JunkBuster does - * a case-sensitive compare. JunkBuster should be modified to do a - * case-insensitive compatison. As a temporary workaround, I've lowercased - * the FORCE_PREFIX. - * - * #define FORCE_PREFIX "IJB-FORCE-LOAD-" - */ -#define FORCE_PREFIX "ijb-force-load-" +#define FORCE_PREFIX "/IJB-FORCE-LOAD" #endif /* def FORCE_LOAD */ #define HOME_PAGE_URL "http://ijbswa.sourceforge.net/" #define REDIRECT_URL HOME_PAGE_URL "redirect.php?v=" VERSION "&to=" +static const char CFAIL[] = + "HTTP/1.0 503 Connect failed\n" + "Content-Type: text/html\n\n" + "\n" + "\n" + "Internet Junkbuster: Connect failed\n" + "\n" + BODY + "

" + BANNER + "

" + "TCP connection to '%s' failed: %s.\n
" + "\n" + "\n"; + +static const char CNXDOM[] = + "HTTP/1.0 404 Non-existent domain\n" + "Content-Type: text/html\n\n" + "\n" + "\n" + "Internet Junkbuster: Non-existent domain\n" + "\n" + BODY + "

" + BANNER + "

" + "No such domain: %s\n" + "\n" + "\n"; + +static const char CNOBANNER[] = + "HTTP/1.0 200 No Banner\n" + "Content-Type: text/html\n\n" + "\n" + "\n" + "Internet Junkbuster: No Banner\n" + "\n" + BODY + "

" + BANNER + "

" + "You asked for a banner that this proxy can't produce because either configuration does not permit.\n
" + "or the URL didn't end with .gif\n" + "\n" + "\n"; + +static const char CSUCCEED[] = + "HTTP/1.0 200 Connection established\n" + "Proxy-Agent: IJ/" VERSION "\n\n"; + +static const char CHEADER[] = + "HTTP/1.0 400 Invalid header received from browser\n\n"; + +static const char SHEADER[] = + "HTTP/1.0 502 Invalid header received from server\n\n"; + +#if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) + +/* + * Hint: You can encode your own GIFs like that: + * perl -e 'while (read STDIN, $c, 1) { printf("\\%.3o,", unpack("C", $c)); }' + */ + +static const char BLANKGIF[] = + "HTTP/1.0 200 OK\r\n" + "Pragma: no-cache\r\n" + "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n" + "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n" + "Content-type: image/gif\r\n\r\n" + "GIF89a\001\000\001\000\200\000\000\377\377\377\000\000" + "\000!\371\004\001\000\000\000\000,\000\000\000\000\001" + "\000\001\000\000\002\002D\001\000;"; + +static const char JBGIF[] = + "HTTP/1.0 200 OK\r\n" + "Pragma: no-cache\r\n" + "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n" + "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n" + "Content-type: image/gif\r\n\r\n" + "GIF89aD\000\013\000\360\000\000\000\000\000\377\377\377!" + "\371\004\001\000\000\001\000,\000\000\000\000D\000\013\000" + "\000\002a\214\217\251\313\355\277\000\200G&K\025\316hC\037" + "\200\234\230Y\2309\235S\230\266\206\372J\253<\3131\253\271" + "\270\215\342\254\013\203\371\202\264\334P\207\332\020o\266" + "N\215I\332=\211\312\3513\266:\026AK)\364\370\365aobr\305" + "\372\003S\275\274k2\354\254z\347?\335\274x\306^9\374\276" + "\037Q\000\000;"; + +#endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */ + +#if defined(FAST_REDIRECTS) || defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) + +static const char HTTP_REDIRECT_TEMPLATE[] = + "HTTP/1.0 302 Local Redirect from Junkbuster\r\n" + "Pragma: no-cache\r\n" + "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n" + "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n" + "Location: %s\r\n"; + +#endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */ + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/re_filterfile b/re_filterfile index 16c073bf..6e40a899 100644 --- a/re_filterfile +++ b/re_filterfile @@ -5,6 +5,10 @@ # Note that you are free to choose the delimter as you # see fit. # +# Note: in addidion to the Perl-options egimosx, U is supported +# and turns the default to ungreedy matching. Add ? to quantifiers +# to switch back to greedy. +# # Kill OnUnload popups. Yummy. # check it out on http://www.zdnet.com/zdsubs/yahoo/tree/yfs.html @@ -42,6 +46,28 @@ s/status='.*?';*//ig # JavaScript: s/window\.open\(/who_wants_this_to.open(/ig # HTML : s/target="?_blank"?/target_who/g +# Kill banners by size: +# (Sizes from http://www.iab.net/iab_banner_standards/bannersizes.html) +# +s|]*?(width=['"]?468\D)[^>]*(height=['"]?60\D).*?>||ig +s|]*?(width=['"]?234\D)[^>]*(height=['"]?60\D).*?>||ig +s|]*?(width=['"]?88\D)[^>]*(height=['"]?31\D).*?>||ig +s|]*?(width=['"]?120\D)[^>]*(height=['"]?90\D).*?>||ig +s|]*?(width=['"]?120\D)[^>]*(height=['"]?60\D).*?>||ig +s|]*?(width=['"]?160\D)[^>]*(height=['"]?600\D).*?>||ig +s|]*?(width=['"]?120\D)[^>]*(height=['"]?600\D).*?>||ig +s|]*?(width=['"]?125\D)[^>]*(height=['"]?125\D).*?>||ig +s|]*?(width=['"]?120\D)[^>]*(height=['"]?240\D).*?>||ig +s|]*?(width=['"]?180\D)[^>]*(height=['"]?150\D).*?>||ig +s|]*?(width=['"]?300\D)[^>]*(height=['"]?250\D).*?>||ig +s|]*?(width=['"]?250\D)[^>]*(height=['"]?250\D).*?>||ig +s|]*?(width=['"]?240\D)[^>]*(height=['"]?400\D).*?>||ig +s|]*?(width=['"]?336\D)[^>]*(height=['"]?280\D).*?>||ig + +# Squish WebBugs: +# +s/]*?(width|height) *= *['"]?1\D[^>]*?(width|height) *= *['"]?1\D.*?>//ig + # Fun stuff: # s/microsoft(?!.com)/MicroSuck<\/b>/ig