jesred-1.2pl1/004075500136020002117000000000000665244543600134465ustar00elknerivs00002740000002jesred-1.2pl1/main.c010044400136020002117000000116420656514766300145410ustar00elknerivs00002740000002/* * $Id: main.c,v 1.3 1998/08/15 00:00:50 elkner Exp $ * * Author: Squirm derived http://www.senet.com.au/squirm/ * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * * 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. * * http://www.gnu.org/copyleft/gpl.html or ./gpl.html * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include #include #include #include #include #include #include #ifdef LOCAL_REGEX #include "regex.h" #else #include #endif #include "main.h" #include "ip_list.h" #include "pattern_list.h" #include "config.h" #include "util.h" #include "log.h" #include "version.h" #include "rewrite.h" static void Usage (void); static void GetOptions(int argc, char *argv[]); int echo_mode = 0; int sig_hup = 0; int interactive = 0; int allow_siblings = 0; #ifdef DEBUG int debug_mode = 0; #endif FILE *fd_redirect = NULL; FILE *fd_rewrite = NULL; int main(int argc, char **argv) { char *f_allow = NULL; char *f_rules = NULL; char *f_rewrite = NULL; char *f_redirect = NULL; int first_run = 1; char buff[BUFSIZE]; char redirect_url[BUFSIZE]; char *url, *src_addr, *ident, *method; int finished = 0; int buff_status = 0; ip_acl *ip_list = NULL; pattern_item *pattern_list = NULL; /* go into interactive mode if we're run as root */ if((int)getuid() == 0) { interactive = 1; fprintf(stderr, "%s running as UID 0: writing logs to stderr\n",APPNAME); } signal(SIGHUP, HUPhandler); signal(SIGKILL, KILLhandler); GetOptions(argc, argv); /* main program loop, executed forever more unless terminated by a kill signal or EOF on stdin */ while(! finished) { int val; sig_hup = 0; log(INFO, "Freeing up old linked lists\n"); ip_acl_destroy(&ip_list); plist_destroy(&pattern_list); closeLogs(); read_config(&f_allow, &f_rules, &f_redirect, &f_rewrite); if (! interactive) openLogs(&f_redirect, &f_rewrite); read_allow(&f_allow, &ip_list); read_rules(&f_rules, &pattern_list); if(echo_mode) log(ERROR, "Invalid condition - continuing in ECHO mode\n"); log(INFO, "%s (PID %d) started\n", APPNAME, (int)getpid()); while((!sig_hup) && (fgets(buff, BUFSIZE, stdin) != NULL)){ if(echo_mode) { puts(""); fflush(stdout); continue; } /* separate the four fields from the single input line of stdin */ buff_status = parse_buff(buff, &url, &src_addr, &ident, &method, ip_list, pattern_list); /* error during parsing the passed line from squid - no rewrite */ if(buff_status) { puts(""); fflush(stdout); continue; } /* check echo_mode again (sighup)*/ if(echo_mode) { puts(""); fflush(stdout); log(ERROR, "Invalid condition - continuing in ECHO mode\n"); continue; } /* find a rule for rewriting the URL */ val = pattern_compare(url, redirect_url, pattern_list); if( val < 1 ) { /* no rule found = 0, or ABORT rule -N */ puts(""); fflush(stdout); continue; } else { /* redirect_url contains the replacement URL */ if ( redirect_url[0] == '\0' ) { /* regex[i] abort, i.e. empty replacement URL */ puts(""); fflush(stdout); } else { printf("%s %s %s %s\n", redirect_url, src_addr, ident, method); fflush(stdout); log(MATCH, "%s %s %s %d\n", src_addr, url, redirect_url, val); } } } if(! sig_hup) finished = 1; } /* end while(1) */ ip_acl_destroy(&ip_list); plist_destroy(&pattern_list); closeLogs(); safe_free(f_rewrite); safe_free(f_redirect); return 0; } static void GetOptions(int argc, char *argv[]) { extern char *optarg; extern int optind; int c; while ((c = getopt(argc, argv, "hv")) != -1) { switch (c) { case 'h' : Usage(); break; case 'v' : printf("%s %s (C) by %s (%s)\n%s\n", APPNAME, VERSION, AUTHOR, AUTHOR_EMAIL, APPURL); exit(0); default: Usage(); break; } } } static void Usage(void) { fprintf(stderr, "Usage: %s [-h] [-v]\n\n" " -h print this and exit\n" " -v show version and exit\n", APPNAME); exit(1); } jesred-1.2pl1/config.c010044400136020002117000000113600652767347100150560ustar00elknerivs00002740000002/* * $Id: config.c,v 1.1 1998/05/17 23:48:09 elkner Exp $ * * Author: Jens Elkner elkner@ivs.cs.uni-magdeburg.de * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * * 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. * * http://www.gnu.org/copyleft/gpl.html or ./gpl.html * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include #include #include #include #include #include #include #ifdef LOCAL_REGEX #include "regex.h" #else #include #endif #include "log.h" #include "path.h" #include "main.h" #include "ip_list.h" #include "pattern_list.h" #include "config.h" #include "util.h" char *CleanLine(const char *); const char *const w_space = " \t\n\r"; void read_allow(char **file, ip_acl **list) { FILE *fd; char *token = NULL; char buff[BUFSIZE]; struct in_addr addr; fd = fopen(*file, "r"); if(fd == NULL) { token = strerror(errno); log(ERROR, "unable to open local addresses file %s: %s\n", *file ? *file : "", token); echo_mode = 1; return; } log(INFO, "Loading IP List from %s\n",*file); while( !echo_mode && (fgets(buff, BUFSIZE, fd) != NULL) ) { token = CleanLine(buff); if ( token == NULL ) continue; addToIPACL(list, token); } fclose(fd); safe_free(*file); } void read_config(char **allow, char **rules, char **redirect, char **rewrite) { FILE *fd; char *token, *token2; char buff[BUFSIZE]; echo_mode = 0; allow_siblings = 0; strcpy(buff,DEFAULT_PATH); strcat(buff,"/"); strcat(buff,"jesred.conf"); if ( (fd=fopen(buff,"r")) == NULL) { token = strerror(errno); fprintf(stderr,"Can't open config file %s for reading: %s\n" "Using echo mode!!!\n", buff, token); echo_mode++; return; } /* just to be sure */ safe_free(*allow); safe_free(*rules); safe_free(*redirect); safe_free(*rewrite); while (fgets(buff, BUFSIZE, fd) != NULL) { token = CleanLine(buff); if ( token == NULL ) continue; token2 = strchr(token,'='); if (token2) { *token2 = '\0'; token = CleanLine(token); if (! token) continue; token2++; token2 = CleanLine(token2); if (! token2) continue; if ( ! strcasecmp(token,"allow") ) *allow = strdup(token2); else if ( ! strcasecmp(token,"rules")) *rules = strdup(token2); else if (! strcasecmp(token,"redirect_log")) *redirect = strdup(token2); else if (! strcasecmp(token,"rewrite_log")) *rewrite = strdup(token2); #ifdef DEBUG else if ( (! strcasecmp(token,"debug")) && (! strcasecmp(token2,"true")) ) debug_mode++; #endif else if (! strcasecmp(token,"siblings")) { if (! strcasecmp(token2,"true")) allow_siblings++; } else fprintf(stderr, "Unknown keyword or value \"%s = %s\" - ignored\n", token ? token : "", token2 ? token2 : ""); } } fclose(fd); } /* attention - it changes the original string */ char * CleanLine(const char *line) { char *token = NULL; int i; token = (char *) line; if (token[strlen(line)-1] == '\n') token[strlen(line)-1] = '\0'; /* skip leading and trailing white space of the line */ token += strspn(line, w_space); if ( *token == '#' ) { return (NULL); } for(i= strlen(token) -1 ; i >= 0; i--) { if (token[i] != ' ') break; else token[i] = '\0'; } if ( *token == '\0' ) { return (NULL); } return (token); } /* load the squirm.patterns into linked list */ void read_rules(char **file, pattern_item **plist) { char buff[BUFSIZE]; FILE *fd; char *token = NULL; if ( ! *file || (fd = fopen(*file, "rt")) == NULL ) { echo_mode = 1; token = strerror(errno); log(ERROR, "unable to open redirect patterns file %s: %s\n", *file ? *file : "", token); return; } log(INFO, "Reading Patterns from config %s\n", *file); while(!echo_mode && (fgets(buff, BUFSIZE, fd) != NULL)) { /* skip blank lines and comments */ token = CleanLine(buff); if ( ! token) continue; add_to_patterns(token, plist); } fclose(fd); safe_free(*file); } #include "pattern_list.h" #include "config.h" #include "util.h" char *CleanLine(const char *); const char *const w_space = " \t\n\r"; void read_allow(char **file, ip_acl **list) { FILE *fd; char *token = NULL; char buff[BUFSIZE]; struct in_addr addr; jesred-1.2pl1/config.h010044400136020002117000000022010652760042300150400ustar00elknerivs00002740000002/* * $Id: config.h,v 1.1 1998/05/17 15:24:03 elkner Exp $ * * Author: Jens Elkner elkner@ivs.cs.uni-magdeburg.de * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * * 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. * * http://www.gnu.org/copyleft/gpl.html or ./gpl.html * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef CONF_H #define CONF_H void read_allow(char **, ip_acl **); void read_rules(char **,pattern_item **); void read_config(char **, char **, char **, char **); #endif jesred-1.2pl1/etc/004075500136020002117000000000000652767034400142205ustar00elknerivs00002740000002jesred-1.2pl1/etc/jesred.conf010064400136020002117000000013360656520576200163430ustar00elknerivs00002740000002# file with IP addresses, for which URL rewriting is [not] allowed allow = /local/squid/etc/redirect.acl # file with rules for URL rewriting rules = /local/squid/etc/redirect.rules # log file for general, error and debug messages (empty value or commenting # this out disables logging) redirect_log = /local/squid/logs/redirect.log # log file for URL rewrites (empty value or commenting this out disables # logging of URL rewrites) # Log file format: Timestamp Client/Ident URL RURL NO rewrite_log = /local/squid/logs/rewrite.log # Debug mode: if set to yes and DEBUG option was compiled in, this enables # debug logging to redirect_log #debug = true # Allow ICP_QUERY request to be rewritten, if a rule applies #siblings = true jesred-1.2pl1/etc/redirect.rules010064400136020002117000000107120656520400400170570ustar00elknerivs00002740000002# Example: redirector rules # since jesred uses exactly the same pattern functions as squirm 1.0 betaB, # you can also find detailed information about this file on: # http://www.senet.com.au/squirm/#squirm_patterns ############################################################################# # Since jesred uses a linear list of redirect rules, the order of the rules # # in this file is important!!! # ############################################################################# # TAG: abort string # # If jesred enconters the specified string at the end # of the passed URL, it immediately returns and echo's back a newline (i.e. # no rewrite) - so this speeds up the lookup process a lot! # such rules are referred as ABORT rules # rule 1 - 7 abort .html abort .jpg abort .html abort .shtml abort .java abort .jar abort .htm # TAG: regex RE [RURL [ACCEL]] # TAG: regexi RE [RURL [ACCEL]] # # ACCEL is honored only, if you compiled jesred with the switch -DUSE_ACCEL # # regex ... indicates, that the following RE is case-sensitive # regexi ... indicates, that the following RE is case-insensitive # RE ... is the regular expression, which has to match the passed URL to get # rewritten with the following RURL (it is only limited by the # implementation of the used regex functions - so see the man page # for the regex functions you compiled jesred with, to get detailed # information on supported RE's) # RURL ... if RE matches the passed URL, jesred returns RURL # ACCEL ... a string, which # starts with a '^' if the string after the '^' is NOT completely # the same as the passed URL starts with # OR (except when case-insensitive) no egexc with # RE and the passed URL (relative expensive) will # be called, since the RE wouldn't match the # pased URL - i.e. no match # ends with a '$' if the passed URL does NOT end exactly with the # string before the '$' (expcept case-insensitive) # OR , no egexc with with RE and the passed URL # will be called - i.e. no match # is plain text if accelerator string does not occur in the URL, # no regexc with RE and the passed URL will be # called - i.e. no match # #------------------------------------------------------------------------------ # If RURL and ACCEL are omitted, all URLs which match RE, are NOT rewritten. # So the following two rules prevent jesred from rewriting matched URLs, but # with the 2nd rule jesred does NOT need to store the RURL (thus consuming # less memory) and does NOT need to do all the pattern replacements (faster)... # # regex ^http://(.*)/ads/minizoff(.*) http://\1/ads/minizoff\2 # # NO_REDIRECT rule # regex ^http://(.*)/ads/minizoff(.*) #------------------------------------------------------------------------------ # # I recommend to use the "accelerators" '^' and '$' in REs whereever it is # possible, since this speeds up the pattern matching a lot! #------------------------------------------------------------------------------ # rule 8 - 9 regex ^http://199.78.52.10/~web_ani/.*\.gif http://141.44.30.2/images/dot.gif ^http://199.78.52.10/~web_ani/ abort .gif # rule 10 - 17 regexi ^http://ad.doubleclick.net/ad/.* http://141.44.30.2/images/dot.gif ^http://ad.doubleclick.net/ad/ regex ^http://ad.preferences.com/image.* http://141.44.30.2/images/dot.gif ^http://ad.preferences.com/image regex ^http://ads[0-9][0-9].focalink.com/SmartBanner/nph-graphic.* http://141.44.30.2/images/dot.gif regex ^http://adserver.developer.com/cgi-bin/accipiter/adserver.exe.* http://141.44.30.2/images/dot.gif http://adserver.developer.com/cgi-bin/accipiter/adserver.exe regex ^http://tracker.clicktrade.com/Tracker.* http://141.44.30.2/images/dot.gif http://tracker.clicktrade.com/Tracker regex ^http://adforce.imgis.com/?adserv.* http://141.44.30.2/images/dot.gif ^http://adforce.imgis.com/?adserv regex ^http://195.90.252.40/banner.* http://141.44.30.2/images/dot.gif ^http://195.90.252.40/banner regex ^http://www.artuframe.com/partners/affiliates/banners.* http://141.44.30.2/images/dot.gif ^http://www.artuframe.com/partners/affiliates/banners # NOTE: actually '.' in RE is any character, so if you want to be sure, # escape the special meaning with a prefixed '\' ;-) # We use the IP address in the rewritten URL to get the local image cached ;-) # BTW: You might have a look at our latest redirect.rules file for our # parent proxy cache via # http://www.cs.uni-magdeburg.de/proxy/filter.shtml ######################################################jesred-1.2pl1/etc/redirect.acl010064400136020002117000000023500652767421000164730ustar00elknerivs00002740000002# Example: IP access pattern file # the following CDIR notation is allowed ONLY: # a.b.c.d/m with a, b, c, d ... {0..255} and m ... {0..32} # and is referred as IP access pattern. # # you can prefix any IP access pattern with a '!`, which explicitly says, # "Do not rewrite the passed URL from this client" ############################################################################# # Since jesred uses a linear list of ip access patterns, the order of the # # ip access patterns in this file is important!!! # ############################################################################# # jesred uses a linear IP Access pattern list. As long as no match is found, # it compares the clients IP address with the next pattern, listed below. # If the end of the list is reached and no match was found, jesred echo's # back a "\n", which indicates no URL replacement to squid. # If the client IP address matches an entry below, rewrite rules # are applied immediately (i.e. no further checks for other IP access # pattern matches will be done). # # These are my children caches which have their own redirectors running !141.44.251.15/32 !149.203.102.1/32 # rewrite all URLs from 141.44.0.0/16 149.203.0.0/16 193.175.28.0/24 jesred-1.2pl1/Makefile010064400136020002117000000052730655624732600151130ustar00elknerivs00002740000002# Your preferred Compiler # HINT: If you want to run the program on an UltraSPARC driven machine, # I recommend to use Sun C-Compiler >= 4.0 or gcc >= 2.8.0 with # optimization level >= 4 for best performance. CC=cc INCLUDE = -I. LDFLAGS = # Compiler Options AC_CFLAGS = -xO5 -mr -s -xcrossfile #-g -xsb # SUN cc >= 4.0 #AC_CFLAGS = -O3 -s # SGI cc, AIX cc #AC_CFLAGS = -O5 -s # GNU cc # extra Libraries ( we need this for inet_addr(char *) only ) XTRA_LIBS = -lnsl # Solaris 2.x #XTRA_LIBS = # AIX 4.2, Linux 2.x.x, IRIX 5.x, 6.x # if you want to have the option, to enable debug message logging, # uncomment the following line, but beware: This DECREASES THE PERFORMANCE # of the program a lot !!! # DEBUG = -DDEBUG # If you don't have regex support on your OS standard librar{y|ies} # or you do not want to use it, get gnu regex 0.12 or higher, # compile it as described in its INSTALL (you do not need to install it!), # uncomment the lines below (XOBJS, DEFS) and substitute regex-0.12 with the # directory, where GNU regex.h and regex.o are located. # Hint: At least on Solaris >= 2.5 you get best performance, when you # use the regex stuff from stdlibc. If you really need the GNU stuff, # compile it with highest optimization (default is no optimization!), # which gives you about 20% speed up ... GNU regex is available via: # ftp://ftp.tu-chemnitz.de/pub/gnu/regex-0.12.tar.gz (GNU mirror) or # ftp://prep.ai.mit.edu/pub/gnu/regex-0.12.tar.gz # XOBJS = regex-0.12/regex.o # DEFS = -DLOCAL_REGEX -Iregex-0.12 # If you want to use ACCEL patterns (compatibility to squirm 1.0Beta), # add -DUSE_ACCEL to DEFS. # # Since in my tests it didn't gave me much performance improvement, I don't # use them but prefer a more readable redirect.rules files (and so a little # bit smaller jesred wrt. memory usage). So why to compile it in, when # I don't want to use ACCEL ;-) # If jesred is compiled without -DUSE_ACCEL the ACCEL strings in the # redirect rules are ignored, if there are some. # # DEFS = -DUSE_ACCEL # That's it - no further changes should be necessary ;-) # =========================================================================== OBJS = \ main.o \ ip_list.o \ util.o \ log.o \ config.o \ rewrite.o \ pattern_list.o CFILES = $(patsubst %.o,%.c,$(OBJS)) PROGS = jesred CFLAGS = $(AC_CFLAGS) $(INCLUDE) LIBS = -L. $(XTRA_LIBS) .SUFFIXES: .o .c.o: ${CC} ${CFLAGS} ${DEFS} ${DEBUG} -c $< all: $(PROGS) $(OBJS): Makefile jesred: $(OBJS) Makefile $< $(CC) -o $@ $(LDFLAGS) $(OBJS) $(XOBJS) $(LIBS) depend: makedepend $(CFLAGS) $(DEFS) $(CFILES) .DONE: query query: -sbquery nosuchthing clean: -rm -rf $(OBJS) *pure_* core $(PROGS) jesred-1.2pl1/README010044400136020002117000000056010652764310500143150ustar00elknerivs00002740000002Jesred 1.0, Copyright (C) 1998 Jens Elkner (elkner@ivs.cs.uni-magdeburg.de) http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ 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. http://www.gnu.org/copyleft/gpl.html or ./gpl.html You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ------------------ Jesred is a Squid redirector program. ------------------- It is derived from Chris Foote's and Wayne Piekarski's squirm 1.0 betaB (see http://www.senet.com.au/squirm/) and uses some slightly modified routines (IP ACL stuff) from squid (see http://squid.nlanr.net). For more information about Squid redirectors see http://squid.nlanr.net/Squid/FAQ/FAQ-14.html Main improvements wrt. squirm 1.0 betaB: ========================================= - uses a configuration file (jesred.conf) - strict usage of subnet/mask notation and squid's ip acl lists to determine, whether to rewrite the passed URL for a specific client/sibling or not (probably a big plus for Class A and B networks) - optionally allows to rewrite URL's for siblings as well - optionally logging of common and error messages to a file - optionally logging of URL rewrites to a separate file - avoids persistent opening/closing of the log file[s] - supports reconfiguration via 'kill -HUP pid' and re-reads the complete configuration file, and that's why it is able to change the following on the fly, i.e. no need to restart squid: - change the used log file[s] (useful for log file rotation - just rewrite jesred.conf and send a HUP signal to jesred processes) - enable/disable logging - enable/disable debug mode if compiled with DEBUG option - enable/disable URL rewriting of ICP_QUERY (sibling) requests ****************************************** - finally: * ABOUT TWICE AS FAST as squirm 1.0betaB * ****************************************** (even with ICP_QUERY URL rewriting it was still twice as fast as squirm - remember: squirm allows to rewrite GET requests only! I tested with the extract of the first 100.000 entries from our parent cache's access.log file and our class B subnet - i.e. 141.44.0.0/16 ) Main drawback wrt. squirm 1.0 betaB: ===================================== - it uses about 256 KB more than squirm on solaris 2.6 (but anyway, it is still less than perl 5.004 ;-)) jesred-1.2pl1/main.h010044400136020002117000000023730652760061300145320ustar00elknerivs00002740000002/* * $Id: main.h,v 1.1 1998/05/17 15:26:03 elkner Exp $ * * Author: Squirm derived http://www.senet.com.au/squirm/ * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * * 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. * * http://www.gnu.org/copyleft/gpl.html or ./gpl.html * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef MAIN_H #define MAIN_H #define BUFSIZE 4096 extern int echo_mode; /* for strange compilers */ #ifdef DEBUG extern int debug_mode; #endif extern int allow_siblings; extern int sig_hup; extern int interactive; extern FILE *fd_rewrite; extern FILE *fd_redirect; #endif /* MAIN_H */ jesred-1.2pl1/log.c010044400136020002117000000053600652760050600143620ustar00elknerivs00002740000002/* * $Id: log.c,v 1.1 1998/05/17 15:24:54 elkner Exp $ * * Author: Jens Elkner elkner@ivs.cs.uni-magdeburg.de * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * * 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. * * http://www.gnu.org/copyleft/gpl.html or ./gpl.html * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include #include #include #include #include "main.h" #include "util.h" #include "log.h" FILE *openFile(char *); void openLogs(char **redirect, char **rewrite) { if ( *rewrite ) { fd_rewrite = openFile(*rewrite); safe_free(*rewrite); } else fd_rewrite = NULL; if ( *redirect ) { fd_redirect = openFile(*redirect); safe_free(*redirect); } else fd_redirect = NULL; } FILE * openFile(char *file) { FILE *fd; if ((fd = fopen(file, "a+")) == NULL) { fprintf(stderr,"Warning: Can't open file %s for writing! \n" "Skipping all related messages!\n",file); } return fd; } void log(log_code c, char *format, ...) { FILE *fd; char msg[BUFSIZE]; va_list args; struct timeval current_time; va_start(args, format); if(vsprintf(msg, format, args) > (BUFSIZE - 1)) { /* string is longer than the maximum buffer we specified, so just return */ return; } va_end(args); if(interactive) { gettimeofday(¤t_time, NULL); fprintf(stderr, "%d.%03d %s", (int) current_time.tv_sec, (int) current_time.tv_usec / 1000, msg); fflush(stderr); return; } if (c == MATCH ) { if ( ! fd_rewrite) return; fd = fd_rewrite; } else if ( c == ERROR || c == INFO ) { if (! fd_redirect) return; fd = fd_redirect; } #ifdef DEBUG else if ( c == DEBG ) { if (! fd_redirect ) return; fd = fd_redirect; } #endif else return; gettimeofday(¤t_time, NULL); fprintf(fd, "%d.%03d %s", (int) current_time.tv_sec, (int) current_time.tv_usec / 1000, msg); fflush(fd); /* should we really do that all the time ??? */ } void closeLogs(void) { if ( fd_rewrite) fclose(fd_rewrite); if ( fd_redirect) fclose(fd_redirect); } jesred-1.2pl1/ip_list.h010044400136020002117000000114000652767345500152560ustar00elknerivs00002740000002/* * $Id: ip_list.h,v 1.1 1998/05/17 23:47:57 elkner Exp $ * * Author: Harvest/Squid derived http://squid.nlanr.net/Squid/ * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * * 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. * * http://www.gnu.org/copyleft/gpl.html or ./gpl.html * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ /* * Copyright (c) 1994, 1995. All rights reserved. * * The Harvest software was developed by the Internet Research Task * Force Research Group on Resource Discovery (IRTF-RD): * * Mic Bowman of Transarc Corporation. * Peter Danzig of the University of Southern California. * Darren R. Hardy of the University of Colorado at Boulder. * Udi Manber of the University of Arizona. * Michael F. Schwartz of the University of Colorado at Boulder. * Duane Wessels of the University of Colorado at Boulder. * * This copyright notice applies to software in the Harvest * ``src/'' directory only. Users should consult the individual * copyright notices in the ``components/'' subdirectories for * copyright information about other software bundled with the * Harvest source code distribution. * * TERMS OF USE * * The Harvest software may be used and re-distributed without * charge, provided that the software origin and research team are * cited in any use of the system. Most commonly this is * accomplished by including a link to the Harvest Home Page * (http://harvest.cs.colorado.edu/) from the query page of any * Broker you deploy, as well as in the query result pages. These * links are generated automatically by the standard Broker * software distribution. * * The Harvest software is provided ``as is'', without express or * implied warranty, and with no support nor obligation to assist * in its use, correction, modification or enhancement. We assume * no liability with respect to the infringement of copyrights, * trade secrets, or any patents, and are not responsible for * consequential damages. Proper use of the Harvest software is * entirely the responsibility of the user. * * DERIVATIVE WORKS * * Users may make derivative works from the Harvest software, subject * to the following constraints: * * - You must include the above copyright notice and these * accompanying paragraphs in all forms of derivative works, * and any documentation and other materials related to such * distribution and use acknowledge that the software was * developed at the above institutions. * * - You must notify IRTF-RD regarding your distribution of * the derivative work. * * - You must clearly notify users that your are distributing * a modified version and not the original Harvest software. * * - Any derivative product is also subject to these copyright * and use restrictions. * * Note that the Harvest software is NOT in the public domain. We * retain copyright, as specified above. * * HISTORY OF FREE SOFTWARE STATUS * * Originally we required sites to license the software in cases * where they were going to build commercial products/services * around Harvest. In June 1995 we changed this policy. We now * allow people to use the core Harvest software (the code found in * the Harvest ``src/'' directory) for free. We made this change * in the interest of encouraging the widest possible deployment of * the technology. The Harvest software is really a reference * implementation of a set of protocols and formats, some of which * we intend to standardize. We encourage commercial * re-implementations of code complying to this set of standards. */ #ifndef IPLIST_H #define IPLIST_H typedef enum { IP_ALLOW, IP_DENY } ip_access_type; typedef struct _ip_acl { struct in_addr addr; struct in_addr mask; ip_access_type access; struct _ip_acl *next; } ip_acl; extern void ip_acl_destroy(ip_acl **); extern void addToIPACL(ip_acl **, const char *); extern ip_access_type ip_access_check(struct in_addr, const ip_acl *); #endif an 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 hojesred-1.2pl1/ip_list.c010044400136020002117000000151330665244505300152460ustar00elknerivs00002740000002/* * $Id: ip_list.c,v 1.2 1999/01/23 22:16:11 elkner Exp $ * * Author: Harvest/Squid derived http://squid.nlanr.net/Squid/ * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * * 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. * * http://www.gnu.org/copyleft/gpl.html or ./gpl.html * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ /* * Copyright (c) 1994, 1995. All rights reserved. * * The Harvest software was developed by the Internet Research Task * Force Research Group on Resource Discovery (IRTF-RD): * * Mic Bowman of Transarc Corporation. * Peter Danzig of the University of Southern California. * Darren R. Hardy of the University of Colorado at Boulder. * Udi Manber of the University of Arizona. * Michael F. Schwartz of the University of Colorado at Boulder. * Duane Wessels of the University of Colorado at Boulder. * * This copyright notice applies to software in the Harvest * ``src/'' directory only. Users should consult the individual * copyright notices in the ``components/'' subdirectories for * copyright information about other software bundled with the * Harvest source code distribution. * * TERMS OF USE * * The Harvest software may be used and re-distributed without * charge, provided that the software origin and research team are * cited in any use of the system. Most commonly this is * accomplished by including a link to the Harvest Home Page * (http://harvest.cs.colorado.edu/) from the query page of any * Broker you deploy, as well as in the query result pages. These * links are generated automatically by the standard Broker * software distribution. * * The Harvest software is provided ``as is'', without express or * implied warranty, and with no support nor obligation to assist * in its use, correction, modification or enhancement. We assume * no liability with respect to the infringement of copyrights, * trade secrets, or any patents, and are not responsible for * consequential damages. Proper use of the Harvest software is * entirely the responsibility of the user. * * DERIVATIVE WORKS * * Users may make derivative works from the Harvest software, subject * to the following constraints: * * - You must include the above copyright notice and these * accompanying paragraphs in all forms of derivative works, * and any documentation and other materials related to such * distribution and use acknowledge that the software was * developed at the above institutions. * * - You must notify IRTF-RD regarding your distribution of * the derivative work. * * - You must clearly notify users that your are distributing * a modified version and not the original Harvest software. * * - Any derivative product is also subject to these copyright * and use restrictions. * * Note that the Harvest software is NOT in the public domain. We * retain copyright, as specified above. * * HISTORY OF FREE SOFTWARE STATUS * * Originally we required sites to license the software in cases * where they were going to build commercial products/services * around Harvest. In June 1995 we changed this policy. We now * allow people to use the core Harvest software (the code found in * the Harvest ``src/'' directory) for free. We made this change * in the interest of encouraging the widest possible deployment of * the technology. The Harvest software is really a reference * implementation of a set of protocols and formats, some of which * we intend to standardize. We encourage commercial * re-implementations of code complying to this set of standards. */ #ifdef __FreeBSD__ # include # include #endif /* __FreeBSD__ */ #include #include #include "ip_list.h" #include "util.h" #include "log.h" static int ip_acl_match(struct in_addr c, const ip_acl *a); static int ip_acl_match(struct in_addr c, const ip_acl *a) { static struct in_addr h; h.s_addr = c.s_addr & a->mask.s_addr; if (h.s_addr == a->addr.s_addr) return 1; else return 0; } ip_access_type ip_access_check(struct in_addr address, const ip_acl *list) { const ip_acl *p = NULL; /* address ... network byte-order IP addr */ #ifdef DEBUG if (!list) { log(DEBG, "ACL: denied %s\n", inet_ntoa(address)); return IP_DENY; } for (p = list; p; p = p->next) { if (ip_acl_match(address, p)) { log(DEBG, "ACL: %s %s\n", p->access==IP_DENY ? "denied" : "allowed", inet_ntoa(address)); return p->access; } } log(DEBG, "ACL: denied %s\n", inet_ntoa(address)); return IP_DENY; #else if (!list) return IP_DENY; for (p = list; p; p = p->next) { if (ip_acl_match(address, p)) return p->access; } return IP_DENY; #endif } void addToIPACL(ip_acl **list, const char *ip_str) { ip_acl *p, *q; int a1, a2, a3, a4, m1; struct in_addr lmask; int inv = 0; int c; if (!ip_str) { return; } if (! (*list)) { /* empty list */ *list = xcalloc(1, sizeof(ip_acl)); (*list)->next = NULL; q = *list; } else { /* find end of list */ p = *list; while (p->next) p = p->next; q = xcalloc(1, sizeof(ip_acl)); q->next = NULL; p->next = q; } /* decode ip address */ if (*ip_str == '!') { ip_str++; inv++; } a1 = a2 = a3 = a4 = 0; c = sscanf(ip_str, "%d.%d.%d.%d/%d", &a1, &a2, &a3, &a4, &m1); if (m1 < 0 || m1 > 32) { log(ERROR, "addToIPACL: Ignoring invalid IP acl line '%s'\n", ip_str); return; } q->access = inv ? IP_DENY : IP_ALLOW; q->addr.s_addr = htonl(a1 * 0x1000000 + a2 * 0x10000 + a3 * 0x100 + a4); lmask.s_addr = m1 ? htonl(0xfffffffful << (32 - m1)) : 0; q->mask.s_addr = lmask.s_addr; } void ip_acl_destroy(ip_acl **a) { ip_acl *b; ip_acl *n; for (b = *a; b; b = n) { n = b->next; safe_free(b); } *a = NULL; } jesred-1.2pl1/log.h010044400136020002117000000022560652760052400143700ustar00elknerivs00002740000002/* * $Id: log.h,v 1.1 1998/05/17 15:25:08 elkner Exp $ * * Author: Jens Elkner elkner@ivs.cs.uni-magdeburg.de * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * * 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. * * http://www.gnu.org/copyleft/gpl.html or ./gpl.html * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef LOG_H #define LOG_H typedef enum { MATCH, ERROR, DEBG, INFO } log_code; extern void log(log_code c, char *format, ...); extern void closeLogs(void); extern void openLogs(char **, char **); #endif jesred-1.2pl1/INSTALL010064400136020002117000000055100655625170400144710ustar00elknerivs00002740000002JESRED INSTALLATION: COMMON: For best performance on Solaris 2.x I recommend to compile everything with __Sun's C compiler >= 4.0__ or GNU c compiler >= 2.8.0 and a optimization level >= 4 . At least on Solaris >= 2.5 you should use the regex functions from the OS' std libc instead of GNU regex-0.12!!! 0) if you do NOT want to use the regex functions of your OS standard libraries, get GNU regex-0.12 or higher and compile it as described in its INSTALL file (we only need regex.h and regex.o, so u do not need to install it!) WARNING: Per default it compiles with debug option and no optimization. So edit its Makefile, to get better code (i.e. more performance). GNU regex is available via: ftp://ftp.tu-chemnitz.de/pub/gnu/regex-0.12.tar.gz (GNU mirror) or ftp://prep.ai.mit.edu/pub/gnu/regex-0.12.tar.gz 1) edit the Makefile and insert the appropriate values for: - your compiler ( CC ) - compiler options like optimization level etc. ( AC_FLAGS ) - extra libraries like -lnsl or -lxnet etc. ( XTRA_LIBS ) - enable debug option, if you want enable/disable debugging during jesred runs ( DEBUG ) - if you use GNU regex, uncomment XOBJS and DEFS and sustitute regex-0.12 with the path, where your GNU regex.[ho] resides - if you want to use redirect rules with ACCEL option, add -DUSE_ACCEL to DEFS. 2) edit path.h and set the DEFAULT_PATH to the directory, where jesred will find its configuration file jesred.conf 3) make 4) copy jesred to an appropriate directory 5) create the jesred configuration file DEFAULT_PATH/jesred.conf (an example with explanations is located in ./etc) and the rewrite.allow and rewrite.rule file or whichever file names you set in jesred.conf If you forget it and start/reconfigure squid, jesred prints out a warning messages to stderr an continues to work in echo_mode. You can still copy the configuration file to the appropriate location and send a HUP signal to ALL redirector processes to read in the new one ;-) NOTE: in all configuration files, all leading and trailing white spaces of a line are ignored. 2nd, a line which starts with a '#' is ignored completely! 6) optional: Verify/Test of jesred a) create a redirect file (e.g. from your squid native access.log file with head -100000 access.log | awk -p '{ print $7 " " $3"/-" " " $8 " " $6}' \ >/var/tmp/testurls ) b) enable the log files in jesred.conf c) jesred < /var/tmp/testurls >/dev/null d) check out the log files (see jesred.conf) 7) modify in squid.conf the redirect_program tag (e.g. redirect_program /local/squid/bin/jesred ) 8) check out, if redirect_children in squid_conf meets your needs 9) reconfigure squid (e.g. squid -k reconfigure) 10) check out the log files, if you have enabled them in jesred.conf jesred-1.2pl1/util.h010044400136020002117000000111460652760076100145650ustar00elknerivs00002740000002/* * $Id: util.h,v 1.1 1998/05/17 15:27:45 elkner Exp $ * * Author: Harvest/Squid derived http://squid.nlanr.net/Squid/ * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * * 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. * * http://www.gnu.org/copyleft/gpl.html or ./gpl.html * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ /* * Copyright (c) 1994, 1995. All rights reserved. * * The Harvest software was developed by the Internet Research Task * Force Research Group on Resource Discovery (IRTF-RD): * * Mic Bowman of Transarc Corporation. * Peter Danzig of the University of Southern California. * Darren R. Hardy of the University of Colorado at Boulder. * Udi Manber of the University of Arizona. * Michael F. Schwartz of the University of Colorado at Boulder. * Duane Wessels of the University of Colorado at Boulder. * * This copyright notice applies to software in the Harvest * ``src/'' directory only. Users should consult the individual * copyright notices in the ``components/'' subdirectories for * copyright information about other software bundled with the * Harvest source code distribution. * * TERMS OF USE * * The Harvest software may be used and re-distributed without * charge, provided that the software origin and research team are * cited in any use of the system. Most commonly this is * accomplished by including a link to the Harvest Home Page * (http://harvest.cs.colorado.edu/) from the query page of any * Broker you deploy, as well as in the query result pages. These * links are generated automatically by the standard Broker * software distribution. * * The Harvest software is provided ``as is'', without express or * implied warranty, and with no support nor obligation to assist * in its use, correction, modification or enhancement. We assume * no liability with respect to the infringement of copyrights, * trade secrets, or any patents, and are not responsible for * consequential damages. Proper use of the Harvest software is * entirely the responsibility of the user. * * DERIVATIVE WORKS * * Users may make derivative works from the Harvest software, subject * to the following constraints: * * - You must include the above copyright notice and these * accompanying paragraphs in all forms of derivative works, * and any documentation and other materials related to such * distribution and use acknowledge that the software was * developed at the above institutions. * * - You must notify IRTF-RD regarding your distribution of * the derivative work. * * - You must clearly notify users that your are distributing * a modified version and not the original Harvest software. * * - Any derivative product is also subject to these copyright * and use restrictions. * * Note that the Harvest software is NOT in the public domain. We * retain copyright, as specified above. * * HISTORY OF FREE SOFTWARE STATUS * * Originally we required sites to license the software in cases * where they were going to build commercial products/services * around Harvest. In June 1995 we changed this policy. We now * allow people to use the core Harvest software (the code found in * the Harvest ``src/'' directory) for free. We made this change * in the interest of encouraging the widest possible deployment of * the technology. The Harvest software is really a reference * implementation of a set of protocols and formats, some of which * we intend to standardize. We encourage commercial * re-implementations of code complying to this set of standards. */ #ifndef UTIL_H #define UTIL_H #define safe_free(x) if (x) { free(x); x = NULL; } extern void HUPhandler(int); extern void KILLhandler(int); extern void *xcalloc(size_t, size_t); extern char *savestr(const char *); extern void delstr(char *); #endif jesred-1.2pl1/path.h010044400136020002117000000003150655621126100145330ustar00elknerivs00002740000002/* * $Id: path.h,v 1.1 1998/07/24 23:03:13 elkner Exp $ */ #ifndef PATH_H #define PATH_H /* change this to the path, which contains your jesred.conf */ #define DEFAULT_PATH "/local/squid/etc" #endif jesred-1.2pl1/util.c010044400136020002117000000127040652760074100145570ustar00elknerivs00002740000002/* * $Id: util.c,v 1.1 1998/05/17 15:27:29 elkner Exp $ * * Author: Harvest/Squid derived http://squid.nlanr.net/Squid/ * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * * 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. * * http://www.gnu.org/copyleft/gpl.html or ./gpl.html * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ /* * Copyright (c) 1994, 1995. All rights reserved. * * The Harvest software was developed by the Internet Research Task * Force Research Group on Resource Discovery (IRTF-RD): * * Mic Bowman of Transarc Corporation. * Peter Danzig of the University of Southern California. * Darren R. Hardy of the University of Colorado at Boulder. * Udi Manber of the University of Arizona. * Michael F. Schwartz of the University of Colorado at Boulder. * Duane Wessels of the University of Colorado at Boulder. * * This copyright notice applies to software in the Harvest * ``src/'' directory only. Users should consult the individual * copyright notices in the ``components/'' subdirectories for * copyright information about other software bundled with the * Harvest source code distribution. * * TERMS OF USE * * The Harvest software may be used and re-distributed without * charge, provided that the software origin and research team are * cited in any use of the system. Most commonly this is * accomplished by including a link to the Harvest Home Page * (http://harvest.cs.colorado.edu/) from the query page of any * Broker you deploy, as well as in the query result pages. These * links are generated automatically by the standard Broker * software distribution. * * The Harvest software is provided ``as is'', without express or * implied warranty, and with no support nor obligation to assist * in its use, correction, modification or enhancement. We assume * no liability with respect to the infringement of copyrights, * trade secrets, or any patents, and are not responsible for * consequential damages. Proper use of the Harvest software is * entirely the responsibility of the user. * * DERIVATIVE WORKS * * Users may make derivative works from the Harvest software, subject * to the following constraints: * * - You must include the above copyright notice and these * accompanying paragraphs in all forms of derivative works, * and any documentation and other materials related to such * distribution and use acknowledge that the software was * developed at the above institutions. * * - You must notify IRTF-RD regarding your distribution of * the derivative work. * * - You must clearly notify users that your are distributing * a modified version and not the original Harvest software. * * - Any derivative product is also subject to these copyright * and use restrictions. * * Note that the Harvest software is NOT in the public domain. We * retain copyright, as specified above. * * HISTORY OF FREE SOFTWARE STATUS * * Originally we required sites to license the software in cases * where they were going to build commercial products/services * around Harvest. In June 1995 we changed this policy. We now * allow people to use the core Harvest software (the code found in * the Harvest ``src/'' directory) for free. We made this change * in the interest of encouraging the widest possible deployment of * the technology. The Harvest software is really a reference * implementation of a set of protocols and formats, some of which * we intend to standardize. We encourage commercial * re-implementations of code complying to this set of standards. */ #include #include #include #include #include "util.h" #include "log.h" #include "main.h" void HUPhandler(int kill) { sig_hup = 1; log(ERROR, "HUP received. Reconfiguring....\n"); signal(SIGHUP, HUPhandler); } void KILLhandler(int kill) { sig_hup = 1; log(ERROR, "KILL received. Shutting down....\n"); closeLogs(); exit(1); } /* * xcalloc() - same as calloc(3). Used for portability. * Never returns NULL; fatal on error. */ void * xcalloc(size_t n, size_t sz) { static void *p; if (n < 1) n = 1; if (sz < 1) sz = 1; if ((p = calloc(n, sz)) == NULL) { perror("xcalloc"); } return (p); } char * savestr(const char *str) { char *save; save = (char *)malloc(strlen(str) + 1); if ( save == NULL ) { perror("Problems allocating memory for a string:"); log(ERROR,"Problems allocating memory for \"%s\"",str); } else { strcpy(save, str); } return save; } void delstr(char *str) { safe_free(str); } jesred-1.2pl1/rewrite.h010044400136020002117000000024120655624700300152630ustar00elknerivs00002740000002/* * $Id: rewrite.h,v 1.2 1998/07/25 03:16:19 elkner Exp $ * * Author: Squirm derived http://www.senet.com.au/squirm/ * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * * 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. * * http://www.gnu.org/copyleft/gpl.html or ./gpl.html * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Thanks to Chris Foote, chris@senet.com.au - except parse_buff * not much to change here (i.e. don't like to go deeper into the pattern stuff) * ;-) * */ #ifndef REWRITE_H #define REWRITE_H extern int parse_buff(char *, char **, char **, char **, char **, ip_acl *, pattern_item *); #endif jesred-1.2pl1/version.h010044400136020002117000000010230656517705000152700ustar00elknerivs00002740000002/* $Id: version.h,v 1.2 1998/08/15 03:19:03 elkner Exp $ * * Author: Jens Elkner elkner@ivs.cs.uni-magdeburg.de * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * */ #ifndef VERSION_H #define VERSION_H #define APPNAME "JESRED" #define VERSION "1.2" #define AUTHOR "Jens Elkner" #define AUTHOR_EMAIL "elkner@ivs.cs.uni-magdeburg.de" #define AUTHOR_URL "http://ivs.cs.uni-magdeburg.de/~elkner/" #define APPURL "http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/" #endif /* VERSION_H */ jesred-1.2pl1/rewrite.c010044400136020002117000000241360656514771300152740ustar00elknerivs00002740000002/* * $Id: rewrite.c,v 1.3 1998/08/15 00:01:14 elkner Exp $ * * Author: Squirm derived http://www.senet.com.au/squirm/ * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * * 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. * * http://www.gnu.org/copyleft/gpl.html or ./gpl.html * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Thanks to Chris Foote, chris@senet.com.au - except parse_buff * not much to change here (i.e. don't like to go deeper into the pattern stuff) * ;-) * */ #include #include #include #include #include #include #include #ifdef LOCAL_REGEX #include "regex.h" #else #include #endif #include "log.h" #include "ip_list.h" #include "pattern_list.h" #include "rewrite.h" #include "main.h" /* load the stdin for the redirector into an IN_BUFF structure Sets in_buff.url to "" if the fields can't be converted */ int replace_string(pattern_item *, char *, char *); #ifdef USE_ACCEL static int match_accel(char *, char *, int, int); #endif int parse_buff(char *buff, char **url, char **src_addr, char **ident, char **method, ip_acl *ip, pattern_item *p) { int c, i; struct in_addr address; char *token, *new_token; char *end[4]; c = 0; token = strchr(buff,' '); if ( token ) { /* URL */ c++; *token = '\0'; end[0] = token; *url = buff; new_token = strchr(++token,' '); if (new_token) { /* Address */ c++; *new_token = '\0'; end[1] = new_token; *src_addr = token; token = strchr(++new_token,' '); if (token) { /* Ident */ c++; *token = '\0'; end[2] = token; *ident = new_token; new_token = strchr(++token,'\n'); if (new_token) { c++; *new_token = '\0'; end[3] = new_token; *method = token; } } } } if(c != 4) { for(i = 0; i < c; i++) { if ( end[i] ) *end[i] = ' '; } log(ERROR, "incorrect input (%d): %s", c, buff); return 1; } #ifdef DEBUG log(DEBG, "Request: %s %s %s %s\n", *url, *src_addr, *ident, *method); #endif /* all methods must be GET or ICP_QUERY */ c = 0; if (allow_siblings && (! strcmp(*method, "ICP_QUERY")) ) c--; if( strcmp(*method, "GET") ) c++; if ( c ) { #ifdef DEBUG for(c = 0; c < 4; c++) { if ( end[c] ) *end[c] = ' '; } log(DEBG, "method not \"GET\" %s\n", buff); #endif return 1; } /* URL with less than 7 char is invalid */ if(strlen(*url) <= 7) { log(ERROR, "strlen url to short (%d)\n", strlen(*url)); return 1; } /* check that the IP source address supplied is valid */ token = strchr(*src_addr,'/'); if ( token ) *token = '\0'; /* for inet_addr we have to link with libnsl on Solaris: i.e. on 2.6 448K r-x + 40K rwx, but since it is a shared lib, it is already loaded, when squid runs - so not much waste of memory ;-) */ if ( (address.s_addr = inet_addr(*src_addr)) == -1 ) { log(ERROR, "client IP address not valid %s\n", *src_addr ? *src_addr : ""); if ( token ) *token = '/'; return 1; } if ( token ) *token = '/'; /* make sure the IP source address matches that of the ones in our list */ if( ip_access_check(address, ip) == IP_DENY ) { #ifdef DEBUG log(DEBG, "client IP address %s not matched\n", *src_addr); #endif return 1; } return 0; } /* returns replacement URL for a match in newurl < 0 if abort pattern match, 0 if no match found, > 1 pattern match if match, the number of the matching rule will be returned */ int pattern_compare(char *url,char *newurl, pattern_item *phead) { pattern_item *curr; int pos; int len; int i; int matched; int pattern_no = 0; curr = NULL; for(curr = phead; curr != NULL; curr = curr->next) { pattern_no++; matched = 1; /* assume a match until a character isn't the same */ if(curr->type == ABORT) { len = strlen(curr->pattern); pos = strlen(url) - len; /* this is dangerous */ for(i = 0; i <= len; i++) { if (url[pos] != curr->pattern[i]) { matched = 0; break; } pos++; } if(matched) { #ifdef DEBUG log(DEBG, "abort pattern matched: %s (rule %d)\n", url, pattern_no); #endif return (0 - pattern_no); /* URL matches abort file extension */ } } else { /* check for accelerator string */ #ifdef USE_ACCEL if(curr->has_accel) { /* check to see if the accelerator string matches, then bother doing a regexec() on it */ if(match_accel(url, curr->accel, curr->accel_type, curr->case_sensitive)) { #ifdef DEBUG log(DEBG, "URL %s matches accelerator %s (rule %d)\n", url, curr->accel, pattern_no); #endif /* Now we must test for normal or extended */ if (curr->type == EXTENDED) { if ( replace_string(curr, url, newurl) == 1 ) return pattern_no; } else /* Type == NORMAL */ { if(regexec(&curr->cpattern, url, 0, 0, 0) == 0){ strcpy(newurl,curr->replacement); return pattern_no; } } } /* end match_accel loop */ } else { /* we haven't got an accelerator string, so we use regex instead */ /* Now we must test for normal or extended */ #endif if (curr->type == EXTENDED) { if ( replace_string(curr, url, newurl) == 1) return pattern_no; } else /* Type == NORMAL */ { if(regexec(&curr->cpattern, url, 0, 0, 0) == 0) { strcpy(newurl,curr->replacement); return pattern_no; } } #ifdef USE_ACCEL } #endif } } return 0; } int replace_string (pattern_item *curr, char *url, char *buffer) { char *replacement_string = NULL; regmatch_t match_data[10]; int parenthesis; char *in_ptr; char *out_ptr; int replay_num; int count; /* Perform the regex call */ if (regexec (&curr->cpattern, url, 10, &match_data[0], 0) != 0) return 0; /* Ok, setup the traversal pointers */ in_ptr = curr->replacement; out_ptr = buffer; /* Count the number of replays in the pattern */ parenthesis = count_parenthesis (curr->pattern); if (parenthesis < 0) { /* Invalid return value - don't log because we already have done it */ return 0; } /* Traverse the url string now */ while (*in_ptr != '\0') { if (isdigit (*in_ptr)) { /* We have a number, how many chars are there before us? */ switch (in_ptr - curr->replacement) { case 0: /* This is the first char Since there is no backslash before hand, this is not a pattern match, so loop around */ { *out_ptr = *in_ptr; out_ptr++; in_ptr++; continue; } case 1: /* Only one char back to check, so see if it's a backslash */ if (*(in_ptr - 1) != '\\') { *out_ptr = *in_ptr; out_ptr++; in_ptr++; continue; } break; default: /* Two or more chars back to check, so see if the previous is a backslash, and also the one before. Two backslashes mean that we should not replace anything! */ if ( (*(in_ptr - 1) != '\\') || ((*(in_ptr - 1) == '\\') && (*(in_ptr - 2) == '\\')) ) { *out_ptr = *in_ptr; out_ptr++; in_ptr++; continue; } } /* Ok, if we reach this point, then we have found something to replace. It also means that the last time we went through here, we copied in a backslash char, so we should backtrack one on the output string before continuing */ out_ptr--; /* We need to convert the current in_ptr into a number for array lookups */ replay_num = (*in_ptr) - '0'; /* Now copy in the chars from the replay string */ for (count = match_data[replay_num].rm_so; count < match_data[replay_num].rm_eo; count++) { /* Copy in the chars */ *out_ptr = url[count]; out_ptr++; } /* Increment the in pointer */ in_ptr++; } else { *out_ptr = *in_ptr; out_ptr++; in_ptr++; } /* Increment the in pointer and loop around */ /* in_ptr++; */ } /* Terminate the string */ *out_ptr = '\0'; /* return to the caller (buffer contains the new url) */ return 1; } #ifdef USE_ACCEL static int match_accel(char *url, char *accel, int accel_type, int case_sensitive) { /* return 1 if url contains accel */ int i, offset; static char l_accel[BUFSIZE]; int accel_len; int url_len; if(accel_type == ACCEL_NORMAL) { if(case_sensitive) { if(strstr(url, accel)) return 1; else return 0; } else { /* convert to lower case */ for(i = 0; url[i] != '\0'; i++) l_accel[i] = tolower(url[i]); l_accel[i] = '\0'; if(strstr(l_accel, accel)) return 1; else return 0; } } if(accel_type == ACCEL_START) { accel_len = strlen(accel); url_len = strlen(url); if(url_len < accel_len) return 0; if(case_sensitive) { for(i = 0; i < accel_len; i++) { if(accel[i] != url[i]) return 0; } } else { for(i = 0; i < accel_len; i++) { if(accel[i] != tolower(url[i])) return 0; } } return 1; } if(accel_type == ACCEL_END) { accel_len = strlen(accel); url_len = strlen(url); offset = url_len - accel_len; if(offset < 0) return 0; if(case_sensitive) { for(i = 0; i < accel_len; i++) { if(accel[i] != url[i+offset]) return 0; } } else { for(i = 0; i < accel_len; i++) { if(accel[i] != tolower(url[i+offset])) return 0; } } return 1; } /* we shouldn't reach this section! */ return 0; } #endif http://www.senet.com.au/squirm/ * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * * 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 thajesred-1.2pl1/pattern_list.c010044400136020002117000000163460655624171500163240ustar00elknerivs00002740000002/* * $Id: pattern_list.c,v 1.2 1998/07/25 02:32:45 elkner Exp $ * * Author: Squirm derived http://www.senet.com.au/squirm/ * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * * 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. * * http://www.gnu.org/copyleft/gpl.html or ./gpl.html * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Thanks to Chris Foote, chris@senet.com.au - not much to change here ;-) * */ #include #include #ifdef LOCAL_REGEX #include "regex.h" #else #include #endif #include "main.h" #include "log.h" #include "util.h" #include "pattern_list.h" void add_to_plist(pattern_item, pattern_item **); #ifdef USE_ACCEL char * get_accel(char *, int *, int); #endif void add_to_patterns(char *pattern, pattern_item **plist) { char first[BUFSIZE]; char second[BUFSIZE]; char type[BUFSIZE]; #ifdef USE_ACCEL char accel[BUFSIZE]; #endif regex_t compiled; pattern_item rpattern; int abort_type = 0; int parenthesis; int stored; /* The regex_flags that we use are: REG_EXTENDED REG_NOSUB REG_ICASE; */ int regex_flags = REG_NOSUB; rpattern.type = NORMAL; rpattern.case_sensitive = 1; #ifdef USE_ACCEL stored = sscanf(pattern, "%s %s %s %s", type, first, second, accel); #else stored = sscanf(pattern, "%s %s %s", type, first, second); #endif if((stored < 2) || (stored > 4)) { log(ERROR, "unable to get a pair of patterns in add_to_patterns() " "for [%s]\n", pattern); echo_mode = 1; return; } if(stored == 2) strcpy(second, ""); if(strcmp(type, "abort") == 0) { rpattern.type = ABORT; abort_type = 1; } if(strcmp(type, "regexi") == 0) { regex_flags |= REG_ICASE; rpattern.case_sensitive = 0; } if(!abort_type) { parenthesis = count_parenthesis (first); if (parenthesis < 0) { /* The function returned an invalid result, indicating an invalid string */ log (ERROR, "count_parenthesis() returned " "left count did not match right count for line: [%s]\n", pattern); echo_mode = 1; return; } else if (parenthesis > 0) { regex_flags |= REG_EXTENDED; rpattern.type = EXTENDED; regex_flags ^= REG_NOSUB; } } if(regcomp(&compiled, first, regex_flags)) { log(ERROR, "Invalid regex [%s] in pattern file\n", first); echo_mode = 1; return; } rpattern.cpattern = compiled; rpattern.pattern = (char *)malloc(sizeof(char) * (strlen(first) +1)); if(rpattern.pattern == NULL) { log(ERROR, "unable to allocate memory in add_to_patterns()\n"); echo_mode = 1; return; } strcpy(rpattern.pattern, first); rpattern.replacement = (char *)malloc(sizeof(char) * (strlen(second) +1)); if(rpattern.replacement == NULL) { log(ERROR, "unable to allocate memory in add_to_patterns()\n"); echo_mode = 1; return; } strcpy(rpattern.replacement, second); #ifdef USE_ACCEL /* use accelerator string if it exists */ if(stored == 4) { rpattern.has_accel = 1; rpattern.accel = get_accel(accel, &rpattern.accel_type, rpattern.case_sensitive); if(rpattern.accel == NULL) { log(ERROR, "unable to allocate memory from get_accel()\n"); echo_mode = 1; return; } } else { rpattern.has_accel = 0; rpattern.accel = NULL; } #endif add_to_plist(rpattern, plist); } #ifdef USE_ACCEL char * get_accel(char *accel, int *accel_type, int case_sensitive) { /* returns the stripped accelerator string or NULL if memory can't be allocated converts the accel string to lower case if(case_sensitive) */ /* accel_type is assigned one of the values: #define ACCEL_NORMAL 1 #define ACCEL_START 2 #define ACCEL_END 3 */ int len, i; char *new_accel = NULL; *accel_type = 0; len = strlen(accel); if(accel[0] == '^') *accel_type = ACCEL_START; if(accel[len - 1] == '$') *accel_type = ACCEL_END; if(! *accel_type) *accel_type = ACCEL_NORMAL; /* copy the strings */ new_accel = (char *)malloc(sizeof(char) * strlen(accel)); strcpy(new_accel,accel); if(*accel_type == ACCEL_START || *accel_type == ACCEL_END) { if(new_accel == NULL) return NULL; if(*accel_type == ACCEL_START) { if(case_sensitive) for(i = 0; i < len; i++) new_accel[i] = accel[i+1]; else for(i = 0; i < len; i++) new_accel[i] = tolower(accel[i+1]); } if(*accel_type == ACCEL_END) { if(case_sensitive) for(i = 0; i < len - 1; i++) new_accel[i] = accel[i]; else for(i = 0; i < len - 1; i++) new_accel[i] = tolower(accel[i]); new_accel[i] = '\0'; } } else { if(!case_sensitive) { for(i = 0; i < len; i++) new_accel[i] = tolower(accel[i]); new_accel[i] = '\0'; } } return new_accel; } #endif void add_to_plist(pattern_item pattern, pattern_item **plist) { pattern_item *curr; pattern_item *new; curr = NULL; new = NULL; if (! (*plist)) { /* empty list */ *plist = xcalloc(1, sizeof(pattern_item)); new = *plist; } else { /* find end of list */ curr = *plist; while(curr->next) curr = curr->next; new = xcalloc(1, sizeof(pattern_item)); curr->next = new; } if(! new) { log(ERROR, "unable to allocate memory in add_to_plist()\n"); /* exit(3); */ echo_mode = 1; return; } new->pattern = pattern.pattern; new->replacement = pattern.replacement; new->type = pattern.type; #ifdef USE_ACCEL new->has_accel = pattern.has_accel; new->accel = pattern.accel; new->accel_type = pattern.accel_type; #endif new->case_sensitive = pattern.case_sensitive; /* not sure whether we need to copy each item in the struct */ new->cpattern = pattern.cpattern; new->next = NULL; } int count_parenthesis (char *pattern) { int lcount = 0; int rcount = 0; int i; /* Traverse string looking for ( and ) */ for (i = 0; i < strlen (pattern); i++) { /* We have found a left ( */ if (pattern [i] == '(') { /* Do not count if there is a backslash */ if ((i != 0) && (pattern [i-1] == '\\')) continue; else lcount++; } if (pattern [i] == ')') { if ((i != 0) && (pattern [i-1] == '\\')) continue; else rcount++; } } /* Check that left == right */ if (lcount != rcount) return (-1); return (lcount); } void plist_destroy(pattern_item **a) { pattern_item *b; pattern_item *n; for (b = *a; b; b = n) { n = b->next; safe_free(b->pattern); safe_free(b->replacement); #ifdef USE_ACCEL if (b->accel) safe_free(b->accel); #endif regfree(&(b->cpattern)); safe_free(b); } *a = NULL; } jesred-1.2pl1/ChangeLog010064400136020002117000000025430665244533700152210ustar00elknerivs00002740000002Changes to jesred 1.2pl1 (Jan 23, 1999) from jesred 1.2: - respects to the FreeBSD community (added required includes to ip_list.c) Changes to jesred 1.2 (Aug 15, 1998) from jesred 1.1: - IF a URL is rewritten, now the number of the appropriate rule is append to the rewrite.log file. So it is easier to analyze the log file and to check out the frequency of pattern matches for each rewrite rule (to keep the log file small, there is as usual no log entry for any matched ABORT or NO_REDIRECT rule) - added rule number comments to redirect.rules example Changes to jesred 1.1 (Jul 25, 1998) from jesred 1.0: - Added shortcut for URLs, which should not be rewritten (just omit RURL and ACCEL in the redirect rule) such rules are referred as NO_REDIRECT rules - fixed memory leak (on SIGHUP jesred 1.0 did not free allocated memory for compiled regex patterns) - fixed ACCEL bug for NORMAL Accelerators (i.e. ACCEL without a ^ and $) to compare the ACCEL with the [lower cased] URL instead of the [lower cased] URL with itself ;-) - support of ACCEL is now optional (i.e. one has to compile with option -DUSE_ACCEL, to use it - otherwise ACCEL strings are ignored) - enabled GetOptions function for printing version information and help via optional switches -v/-h - Added some comments in the etc/redirect.rules example the frequency of pattern matches for each rewrite rule (to keep the log file small, there is as usual no log entry for any matched ABORT or NO_REDIjesred-1.2pl1/pattern_list.h010044400136020002117000000031340655624560400163210ustar00elknerivs00002740000002/* * $Id: pattern_list.h,v 1.3 1998/07/25 03:05:40 elkner Exp $ * * Author: Squirm derived http://www.senet.com.au/squirm/ * Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/ * * 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. * * http://www.gnu.org/copyleft/gpl.html or ./gpl.html * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Thanks to Chris Foote, chris@senet.com.au - not much to change here ;-) * */ #ifndef PATTERN_H #define PATTERN_H #define NORMAL 1 #define EXTENDED 2 #define ABORT 3 #ifdef USE_ACCEL #define ACCEL_NORMAL 1 #define ACCEL_START 2 #define ACCEL_END 3 #endif typedef struct _pattern_item { char *pattern; char *replacement; int case_sensitive; int type; #ifdef USE_ACCEL int has_accel; int accel_type; char *accel; #endif regex_t cpattern; struct _pattern_item *next; } pattern_item; extern void add_to_patterns(char *, pattern_item **); extern void plist_destroy(pattern_item **); #endif jesred-1.2pl1/gpl.html010044400136020002117000000503250652513024700151040ustar00elknerivs00002740000002 GNU General Public License - GNU Project - Free Software Foundation (FSF)

GNU General Public License

 [image of a Philosophical Gnu] (jpeg 7k) (jpeg 141k) no gifs due to patent problems


Table of Contents


GNU GENERAL PUBLIC LICENSE

Version 2, June 1991

Copyright (C) 1989, 1991 Free Software Foundation, Inc.  
59 Temple Place - Suite 330, Boston, MA  02111-1307, USA

Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Preamble

The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too.

When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.

To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.

For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.

We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.

Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.

Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.

The precise terms and conditions for copying, distribution and modification follow.

TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".

Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.

1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.

You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.

2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:

  • a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.

  • b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.

  • c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.

Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.

In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.

3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:

  • a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,

  • b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,

  • c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.

If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.

4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.

5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.

6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.

7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.

If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.

It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.

This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.

8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.

9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.

Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.

10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.

NO WARRANTY

11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

END OF TERMS AND CONDITIONS

How to Apply These Terms to Your New Programs

If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.

To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.

one line to give the program's name and an idea of what it does.
Copyright (C) 19yy  name of author

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.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this when it starts in an interactive mode:

Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
type `show w'.  This is free software, and you are welcome
to redistribute it under certain conditions; type `show c' 
for details.

The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program.

You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names:

Yoyodyne, Inc., hereby disclaims all copyright
interest in the program `Gnomovision'
(which makes passes at compilers) written 
by James Hacker.

signature of Ty Coon, 1 April 1989
Ty Coon, President of Vice

This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License.


Return to GNU's home page.

FSF & GNU inquiries & questions to gnu@gnu.org. Other ways to contact the FSF.

Comments on these web pages to webmasters@www.gnu.org, send other questions to gnu@gnu.org.

Copyright notice above.
Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA

Updated: 16 Feb 1998 tower


ng access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.

4. You may not copy, mo