summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile94
-rw-r--r--src/dbase.c75
-rw-r--r--src/dbase.h5
-rw-r--r--src/debug.c77
-rw-r--r--src/debug.h63
-rw-r--r--src/kbs.c6
-rw-r--r--src/pop3.c1
-rw-r--r--src/rexp.c2
-rw-r--r--src/util.c13
-rw-r--r--src/util.h7
10 files changed, 293 insertions, 50 deletions
diff --git a/src/Makefile b/src/Makefile
index 15b4775..508cd54 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -18,11 +18,16 @@
#
# -------------------------------------------------------------------------
#
-# $Id: Makefile,v 1.7 2004-01-26 02:01:49 ianc Exp $
+# $Id: Makefile,v 1.8 2004-06-05 01:09:58 ianc Exp $
#
-# CFLAGS assumes that gcc is being used - simply comment out if required
-CFLAGS = -g -Wall -Werror
+# Uncomment for debug output
+#
+# DEBUG = -DKBS_DEBUG
+
+# CFLAGS assumes that gcc is being used - simply change as required
+#
+CFLAGS = -g -Wall -Werror $(DEBUG)
TARGET = kbs
@@ -32,6 +37,7 @@ SOURCE = kbs.c \
rexp.c \
dbase.c \
dstring.c \
+ debug.c \
util.c
OBJECTS = kbs.o \
@@ -40,6 +46,7 @@ OBJECTS = kbs.o \
rexp.o \
dbase.o \
dstring.o \
+ debug.o \
util.o
$(TARGET): $(OBJECTS)
@@ -50,56 +57,61 @@ clean:
depend:
make clean
- makedepend -- $(CFLAGS) -- $(SOURCE)
+ makedepend -- $(CFLAGS) $(DEBUG) -- $(SOURCE)
if test -e Makefile ; then rm -f Makefile.bak ; fi
# DO NOT DELETE THIS LINE -- make depend depends on it
kbs.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h
-kbs.o: /usr/include/sys/_types.h /usr/include/machine/_types.h
-kbs.o: /usr/include/limits.h /usr/include/sys/limits.h
-kbs.o: /usr/include/machine/_limits.h /usr/include/sys/syslimits.h
-kbs.o: /usr/include/stdio.h /usr/include/string.h /usr/include/strings.h
-kbs.o: /usr/include/stdarg.h /usr/include/time.h /usr/include/sys/timespec.h
+kbs.o: /usr/include/machine/ansi.h /usr/include/limits.h
+kbs.o: /usr/include/sys/_posix.h /usr/include/machine/limits.h
+kbs.o: /usr/include/sys/syslimits.h /usr/include/stdio.h
+kbs.o: /usr/include/string.h /usr/include/stdarg.h /usr/include/time.h
kbs.o: /usr/include/errno.h global.h config.h pop3.h msg.h dbase.h rexp.h
-kbs.o: dstring.h util.h
+kbs.o: dstring.h debug.h util.h
pop3.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h
-pop3.o: /usr/include/sys/_types.h /usr/include/machine/_types.h
-pop3.o: /usr/include/string.h /usr/include/strings.h /usr/include/stdio.h
-pop3.o: /usr/include/stdarg.h /usr/include/ctype.h /usr/include/runetype.h
-pop3.o: /usr/include/unistd.h /usr/include/sys/types.h
-pop3.o: /usr/include/machine/endian.h /usr/include/sys/select.h
-pop3.o: /usr/include/sys/_sigset.h /usr/include/sys/_timeval.h
-pop3.o: /usr/include/sys/timespec.h /usr/include/sys/unistd.h
-pop3.o: /usr/include/sys/socket.h /usr/include/sys/_iovec.h
-pop3.o: /usr/include/machine/param.h /usr/include/netinet/in.h
+pop3.o: /usr/include/machine/ansi.h /usr/include/string.h
+pop3.o: /usr/include/stdio.h /usr/include/stdarg.h /usr/include/ctype.h
+pop3.o: /usr/include/runetype.h /usr/include/unistd.h
+pop3.o: /usr/include/sys/types.h /usr/include/sys/inttypes.h
+pop3.o: /usr/include/machine/types.h /usr/include/machine/endian.h
+pop3.o: /usr/include/sys/unistd.h /usr/include/sys/_posix.h
+pop3.o: /usr/include/sys/select.h /usr/include/sys/event.h
+pop3.o: /usr/include/sys/queue.h /usr/include/sys/socket.h
+pop3.o: /usr/include/machine/param.h /usr/include/sys/time.h
+pop3.o: /usr/include/time.h /usr/include/netinet/in.h
pop3.o: /usr/include/netinet6/in6.h /usr/include/netinet/tcp.h
pop3.o: /usr/include/netdb.h global.h pop3.h msg.h dstring.h util.h
config.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h
-config.o: /usr/include/sys/_types.h /usr/include/machine/_types.h
-config.o: /usr/include/string.h /usr/include/strings.h /usr/include/stdio.h
-config.o: /usr/include/errno.h /usr/include/ctype.h /usr/include/runetype.h
-config.o: global.h config.h dstring.h dbase.h msg.h rexp.h util.h
+config.o: /usr/include/machine/ansi.h /usr/include/string.h
+config.o: /usr/include/stdio.h /usr/include/errno.h /usr/include/ctype.h
+config.o: /usr/include/runetype.h global.h config.h dstring.h dbase.h msg.h
+config.o: rexp.h util.h
rexp.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h
-rexp.o: /usr/include/sys/_types.h /usr/include/machine/_types.h
+rexp.o: /usr/include/machine/ansi.h /usr/include/unistd.h
+rexp.o: /usr/include/sys/types.h /usr/include/sys/inttypes.h
+rexp.o: /usr/include/machine/types.h /usr/include/machine/endian.h
+rexp.o: /usr/include/sys/unistd.h /usr/include/sys/_posix.h
rexp.o: /usr/include/regex.h global.h rexp.h config.h util.h
dbase.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h
-dbase.o: /usr/include/sys/_types.h /usr/include/machine/_types.h
-dbase.o: /usr/include/string.h /usr/include/strings.h /usr/include/stdio.h
-dbase.o: /usr/include/ctype.h /usr/include/runetype.h global.h dbase.h msg.h
-dbase.o: rexp.h dstring.h config.h util.h
+dbase.o: /usr/include/machine/ansi.h /usr/include/string.h
+dbase.o: /usr/include/strings.h /usr/include/stdio.h /usr/include/ctype.h
+dbase.o: /usr/include/runetype.h global.h dbase.h msg.h rexp.h dstring.h
+dbase.o: config.h debug.h util.h
dstring.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h
-dstring.o: /usr/include/sys/_types.h /usr/include/machine/_types.h
-dstring.o: /usr/include/string.h /usr/include/strings.h /usr/include/stdio.h
-dstring.o: /usr/include/stdarg.h /usr/include/ctype.h /usr/include/runetype.h
-dstring.o: /usr/include/sys/types.h /usr/include/machine/endian.h
-dstring.o: /usr/include/sys/select.h /usr/include/sys/_sigset.h
-dstring.o: /usr/include/sys/_timeval.h /usr/include/sys/timespec.h
-dstring.o: /usr/include/sys/socket.h /usr/include/sys/_iovec.h
-dstring.o: /usr/include/machine/param.h /usr/include/netinet/in.h
-dstring.o: /usr/include/netinet6/in6.h /usr/include/netinet/tcp.h
-dstring.o: /usr/include/netdb.h global.h dstring.h util.h
+dstring.o: /usr/include/machine/ansi.h /usr/include/string.h
+dstring.o: /usr/include/stdio.h /usr/include/stdarg.h /usr/include/ctype.h
+dstring.o: /usr/include/runetype.h /usr/include/sys/types.h
+dstring.o: /usr/include/sys/inttypes.h /usr/include/machine/types.h
+dstring.o: /usr/include/machine/endian.h /usr/include/sys/select.h
+dstring.o: /usr/include/sys/event.h /usr/include/sys/queue.h
+dstring.o: /usr/include/sys/socket.h /usr/include/machine/param.h
+dstring.o: /usr/include/netinet/in.h /usr/include/netinet6/in6.h
+dstring.o: /usr/include/netinet/tcp.h /usr/include/netdb.h global.h dstring.h
+dstring.o: util.h
+debug.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h
+debug.o: /usr/include/machine/ansi.h /usr/include/stdio.h
+debug.o: /usr/include/stdarg.h global.h debug.h
util.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h
-util.o: /usr/include/sys/_types.h /usr/include/machine/_types.h
-util.o: /usr/include/string.h /usr/include/strings.h /usr/include/stdio.h
-util.o: global.h util.h
+util.o: /usr/include/machine/ansi.h /usr/include/string.h
+util.o: /usr/include/stdio.h global.h util.h
diff --git a/src/dbase.c b/src/dbase.c
index e1caa04..563de25 100644
--- a/src/dbase.c
+++ b/src/dbase.c
@@ -35,6 +35,7 @@ static const char id[]="$Id$";
#include "dbase.h"
#include "dstring.h"
#include "config.h"
+#include "debug.h"
#include "util.h"
static const char header_id[]=KBS_DBASE_H;
@@ -77,17 +78,27 @@ static DString reason=NULL;
/* ---------------------------------------- PRVIVATE FUNCTIONS
*/
-static int IsTrustedUser(const char *username)
+static int IsTrustedUser(const char *username, const char *domain)
{
+ char *p;
int f;
+ int res=FALSE;
- for(f=0;f<no_trusted_users;f++)
+ p=CopyStr(username);
+ p=CatStr(p,"@");
+ p=CatStr(p,domain);
+
+ for(f=0;f<no_trusted_users && !res;f++)
{
- if (strcasecmp(username,trusted_user[f])==0)
- return TRUE;
+ if (strcasecmp(p,trusted_user[f])==0)
+ {
+ res=TRUE;
+ }
}
- return FALSE;
+ free(p);
+
+ return res;
}
@@ -252,6 +263,14 @@ int DBBlockMessage(const POP3Message *msg)
int f;
int show;
+ KBSDEBUG(("msg.id=%d\n",msg->id));
+ KBSDEBUG(("msg.to='%s'\n",msg->to));
+ KBSDEBUG(("msg.from='%s'\n",msg->from));
+ KBSDEBUG(("msg.from_uname='%s'\n",msg->from_uname));
+ KBSDEBUG(("msg.from_domain='%s'\n",msg->from_domain));
+ KBSDEBUG(("msg.subject='%s'\n",msg->subject));
+ KBSDEBUG(("msg.content_type='%s'\n",msg->content_type));
+
show=ConfigInt(CONFIG_SHOWMATCH);
reason=DSReset(reason);
@@ -259,7 +278,7 @@ int DBBlockMessage(const POP3Message *msg)
if (IsTrustedDomain(msg->from_domain))
return FALSE;
- if (IsTrustedUser(msg->from_uname))
+ if (IsTrustedUser(msg->from_uname,msg->from_domain))
return FALSE;
if (ConfigInt(CONFIG_BLOCKHTML) &&
@@ -428,7 +447,7 @@ void DBClose(void)
free(t->allow);
- for(f=0;f<t->no_allow;f++)
+ for(f=0;f<t->no_allow_to;f++)
REFree(t->allow_to[f]);
free(t->allow_to);
@@ -445,4 +464,46 @@ void DBClose(void)
}
+void DBDump(void)
+{
+ Domain *d;
+ int f;
+
+ for(f=0;f<no_trusted_domains;f++)
+ KBSDEBUG(("trusted_domain[%d]='%s'\n",f,trusted_domain[f]));
+
+ for(f=0;f<no_trusted_users;f++)
+ KBSDEBUG(("trusted_user[%d]='%s'\n",f,trusted_user[f]));
+
+ for(f=0;f<no_blacklist;f++)
+ KBSDEBUG(("blacklist[%d]='%s'\n",f,blacklist[f]));
+
+ d=head;
+
+ while(d)
+ {
+ KBSDEBUG(("DOMAIN '%s' default:%s\n",
+ d->name,d->def_block ? "block":"allow"));
+
+ for(f=0;f<d->no_user;f++)
+ KBSDEBUG((" user[%d]='%s'\n",
+ f,d->user[f]));
+
+ for(f=0;f<d->no_block;f++)
+ KBSDEBUG((" block[%d]='%s'\n",
+ f,REGetExpression(d->block[f])));
+
+ for(f=0;f<d->no_allow;f++)
+ KBSDEBUG((" allow[%d]='%s'\n",
+ f,REGetExpression(d->allow[f])));
+
+ for(f=0;f<d->no_allow_to;f++)
+ KBSDEBUG((" allow_to[%d]='%s'\n",
+ f,REGetExpression(d->allow_to[f])));
+
+ d=d->next;
+ }
+}
+
+
/* END OF FILE */
diff --git a/src/dbase.h b/src/dbase.h
index 1b3dfa6..4a82f9a 100644
--- a/src/dbase.h
+++ b/src/dbase.h
@@ -106,6 +106,11 @@ const char *DBBlockReason(void);
void DBClose(void);
+/* Dump the database if debugging is enabled
+*/
+void DBDump(void);
+
+
#endif
/* END OF FILE */
diff --git a/src/debug.c b/src/debug.c
new file mode 100644
index 0000000..5c0b84a
--- /dev/null
+++ b/src/debug.c
@@ -0,0 +1,77 @@
+/*
+
+ kbs - Simple, easily fooled, POP3 spam filter
+
+ Copyright (C) 2003 Ian Cowburn (ianc@noddybox.demon.co.uk)
+
+ 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
+
+ -------------------------------------------------------------------------
+
+ Debug interface
+
+*/
+static const char id[]="$Id$";
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "global.h"
+#include "debug.h"
+
+static const char header_id[]=KBS_DEBUG_H;
+
+#define DEBUG_FILE "kbs_debug.out"
+
+#define USE_STDERR
+
+
+/* ---------------------------------------- GLOBALS
+*/
+int ext_kbsdebug_line=__LINE__;
+const char *ext_kbsdebug_file=__FILE__;
+
+
+/* ---------------------------------------- STATICS
+*/
+static FILE *fp=NULL;
+
+
+/* ---------------------------------------- INTERFACES
+*/
+
+void KbsDebug(const char *fmt, ...)
+{
+ va_list va;
+
+#ifndef USE_STDERR
+ if (!fp)
+ if ((fp=fopen(DEBUG_FILE,"w")))
+ setbuf(fp,NULL);
+
+ if (!fp)
+ return;
+#else
+ fp=stdout;
+#endif
+
+ fprintf(fp,"%s(%d):",ext_kbsdebug_file,ext_kbsdebug_line);
+ va_start(va,fmt);
+ vfprintf(fp,fmt,va);
+ va_end(va);
+}
+
+/* END OF FILE */
diff --git a/src/debug.h b/src/debug.h
new file mode 100644
index 0000000..1f3498a
--- /dev/null
+++ b/src/debug.h
@@ -0,0 +1,63 @@
+/*
+
+ kbs - Simple, easily fooled, POP3 spam filter
+
+ Copyright (C) 2003 Ian Cowburn (ianc@noddybox.demon.co.uk)
+
+ 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
+
+ -------------------------------------------------------------------------
+
+ $Id$
+
+ Debug interface
+
+*/
+
+#ifndef KBS_DEBUG_H
+#define KBS_DEBUG_H "$Id$"
+
+/* ---------------------------------------- INTERFACES
+*/
+
+/* Note that the KBSDEBUG macro is actually used like:
+
+ KBSDEBUG(("string=%s\n",str));
+*/
+#ifdef KBS_DEBUG
+
+#define KBSDEBUG(x) do \
+ { \
+ extern int ext_kbsdebug_line; \
+ extern const char *ext_kbsdebug_file; \
+ ext_kbsdebug_line=__LINE__; \
+ ext_kbsdebug_file=__FILE__; \
+ KbsDebug x; \
+ } while(0)
+
+#else
+
+#define KBSDEBUG(x) do {} while(0)
+
+#endif
+
+
+/* Don't use - use KBSDEBUG() instead
+*/
+void KbsDebug(const char *fmt, ...);
+
+#endif
+
+/* END OF FILE */
diff --git a/src/kbs.c b/src/kbs.c
index 8cdf8be..ef6ab1e 100644
--- a/src/kbs.c
+++ b/src/kbs.c
@@ -36,6 +36,7 @@ static const char id[]="$Id$";
#include "pop3.h"
#include "dbase.h"
#include "dstring.h"
+#include "debug.h"
#include "util.h"
static const char header_id[]=KBS_GLOBAL_H;
@@ -125,6 +126,8 @@ int main(int argc, char *argv[])
fp=NULL;
}
+ DBDump();
+
if ((msg=POP3GetList()))
{
int tot=0;
@@ -189,6 +192,7 @@ static void Log(FILE *fp, const char *fmt,...)
char buff[128];
time_t t;
struct tm *ts;
+ va_list va;
if (!fp)
return;
@@ -200,10 +204,8 @@ static void Log(FILE *fp, const char *fmt,...)
"%Y-%m-%d %H:%M:%S: ",
ts);
-
fprintf(fp,"%s",buff);
- va_list va;
va_start(va,fmt);
vfprintf(fp,fmt,va);
diff --git a/src/pop3.c b/src/pop3.c
index bfd9e6c..5d87e9a 100644
--- a/src/pop3.c
+++ b/src/pop3.c
@@ -35,6 +35,7 @@ static const char id[]="$Id$";
#include <sys/types.h>
#include <sys/select.h>
#include <sys/socket.h>
+#include <sys/time.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
diff --git a/src/rexp.c b/src/rexp.c
index effa882..6deeda7 100644
--- a/src/rexp.c
+++ b/src/rexp.c
@@ -26,6 +26,8 @@
static const char id[]="$Id$";
#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
#include <regex.h>
#include "global.h"
diff --git a/src/util.c b/src/util.c
index 62dd79c..4db37f5 100644
--- a/src/util.c
+++ b/src/util.c
@@ -48,6 +48,19 @@ char *CopyStr(const char *p)
}
+char *CatStr(char *orig, const char *p)
+{
+ char *new;
+
+ new=Malloc(strlen(orig)+strlen(p)+1);
+ strcpy(new,orig);
+ strcat(new,p);
+ free(orig);
+
+ return new;
+}
+
+
void *F_Malloc(const char *file, int line, size_t len)
{
void *new;
diff --git a/src/util.h b/src/util.h
index c754307..88db7ee 100644
--- a/src/util.h
+++ b/src/util.h
@@ -43,6 +43,13 @@
char *CopyStr(const char *p);
+/* Concatante a string.
+ NOTE: orig must have been allocated with Malloc() or Realloc(), and will
+ have been free()ed when this returns.
+*/
+char *CatStr(char *orig, const char *p);
+
+
/* Malloc wrapper. Just use free() to free.
*/
void *F_Malloc(const char *file, int line, size_t len);