summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dbase.c31
-rw-r--r--test/README32
-rwxr-xr-xtest/create_mails.sh56
-rwxr-xr-xtest/run_test.sh55
-rw-r--r--test/test-config40
5 files changed, 213 insertions, 1 deletions
diff --git a/src/dbase.c b/src/dbase.c
index 563de25..356e1c9 100644
--- a/src/dbase.c
+++ b/src/dbase.c
@@ -174,6 +174,7 @@ Domain *DBNewDomain(RE_Expression name)
dom->no_user=0;
dom->no_block=0;
dom->no_allow=0;
+ dom->no_allow_to=0;
dom->user=NULL;
dom->block=NULL;
@@ -276,15 +277,23 @@ int DBBlockMessage(const POP3Message *msg)
reason=DSReset(reason);
if (IsTrustedDomain(msg->from_domain))
+ {
+ KBSDEBUG(("**** ALLOWED - trusted domain '%s'\n",msg->from_domain));
return FALSE;
+ }
if (IsTrustedUser(msg->from_uname,msg->from_domain))
+ {
+ KBSDEBUG(("**** ALLOWED - trusted user '%s@%s'\n",
+ msg->from_uname,msg->from_domain));
return FALSE;
+ }
if (ConfigInt(CONFIG_BLOCKHTML) &&
(strncmp(msg->content_type,html,strlen(html))==0 ||
strcmp(msg->content_type,"UNKNOWN")==0))
{
+ KBSDEBUG(("**** BLOCKED - content_type '%s'\n",msg->content_type));
DSAddCP(reason,"HTML message or unknown content type");
return TRUE;
}
@@ -301,12 +310,17 @@ int DBBlockMessage(const POP3Message *msg)
else
DSAddCP(reason,"blacklisted");
+ KBSDEBUG(("**** BLOCKED - blacklisted '%s'\n",msg->from_domain));
+
return TRUE;
}
}
if (!(dom=GetDomain(msg->from_domain)))
+ {
+ KBSDEBUG(("**** ALLOWED - no domain for '%s'\n",msg->from_domain));
return FALSE;
+ }
ds=DSInit();
@@ -319,6 +333,7 @@ int DBBlockMessage(const POP3Message *msg)
{
if (RESearch(dom->allow[f],ds->text))
{
+ KBSDEBUG(("**** ALLOWED - allowed subject '%s'\n",ds->text));
DSFree(ds);
return FALSE;
}
@@ -343,6 +358,8 @@ int DBBlockMessage(const POP3Message *msg)
else
DSAddCP(reason,"disallowed to address");
+ KBSDEBUG(("**** BLOCKED - bad to address '%s'\n",msg->to));
+
DSFree(ds);
return TRUE;
}
@@ -368,6 +385,10 @@ int DBBlockMessage(const POP3Message *msg)
}
else
DSAddCP(reason,"disallowed name");
+
+ KBSDEBUG(("**** BLOCKED - bad from username '%s'\n",
+ msg->from_uname));
+
return TRUE;
}
}
@@ -384,10 +405,18 @@ int DBBlockMessage(const POP3Message *msg)
else
DSAddCP(reason,"disallowed subject");
DSFree(ds);
+
+ KBSDEBUG(("**** BLOCKED - bad subject '%s'\n",ds->text));
+
return TRUE;
}
}
+ if (dom->def_block)
+ KBSDEBUG(("**** BLOCKED - default block\n"));
+ else
+ KBSDEBUG(("**** ALLOWED - default no block\n"));
+
DSAddCP(reason,"default block");
DSFree(ds);
return dom->def_block;
@@ -483,7 +512,7 @@ void DBDump(void)
while(d)
{
KBSDEBUG(("DOMAIN '%s' default:%s\n",
- d->name,d->def_block ? "block":"allow"));
+ REGetExpression(d->name),d->def_block ? "block":"allow"));
for(f=0;f<d->no_user;f++)
KBSDEBUG((" user[%d]='%s'\n",
diff --git a/test/README b/test/README
new file mode 100644
index 0000000..595c31f
--- /dev/null
+++ b/test/README
@@ -0,0 +1,32 @@
+
+Pre-requisites
+--------------
+
+* SMTP server
+* POP3 server
+* bash (required for TCP redirects)
+
+
+create_mails.sh
+---------------
+
+This creates the test emails on the local system. Edit to set the test
+username.
+
+
+run_test.sh
+-----------
+
+Runs the simple confidence tests.
+
+
+test-config
+-----------
+
+The test configuration. Edit to set the test username and password.
+
+
+Notes
+-----
+
+These tests are *really* basic.
diff --git a/test/create_mails.sh b/test/create_mails.sh
new file mode 100755
index 0000000..15da45c
--- /dev/null
+++ b/test/create_mails.sh
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+# Set this to the local user who will recieve the test emails.
+# It's recommended that this user is a simple non-login user
+# specifically for email testing.
+#
+UNAME=kbstest
+
+# Check the environment
+#
+if [ ! -x ../src/kbs ] ; then
+ echo kbs not built!
+ exit
+fi
+
+if [ "`netstat -a | egrep LISTEN | egrep smtp`" = "" ] ; then
+ echo No SMTP server
+ exit
+fi
+
+function email()
+{
+ cat << ENDMAIL > /dev/tcp/localhost/25
+HELO localhost
+MAIL FROM: $1
+RCPT TO: $UNAME
+DATA
+To: $2
+Subject: $3
+Content-Type: $4
+
+Test $5
+
+.
+QUIT
+ENDMAIL
+
+ echo Created email from $1 to $2
+}
+
+# Send the test emails
+#
+email "trusted@google.com" "uname@hostname" "" "text/plain" 1
+email "bad_user@microsoft.com" "uname@hostname" "good" "text/plain" 2
+email "trusted@google.com" "uname@hostname" "good" "text/plain" 3
+email "trusted@google.com" "uname@hostname" "bad" "text/plain" 4
+email "good_user@freebsd.org" "uname@hostname" "bad" "text/plain" 5
+email "good_user@freebsd.org" "uname@hostname" "bad" "text/html" 6
+email "good_user@google.com" "uname@hostname" "good" "text/plain" 7
+email "bad_user@google.com" "uname@hostname" "good" "text/html" 8
+email "bad_user@google.com" "uname@hostname" "bad" "text/plain" 9
+email "bad_user@google.com" "uname@hostname" "bad" "text/html" 10
+email "bad_user@google.com" "uname@hostname" "b_a_d" "text/plain" 11
+email "bad_user_uname@google.com" "baduname@hostname" "good" "text/plain" 12
+email "bad_user_hname@google.com" "uname@badhostname" "good" "text/plain" 13
+email "bad_user2@google.com" "uname@hostname" "good" "text/plain" 14
diff --git a/test/run_test.sh b/test/run_test.sh
new file mode 100755
index 0000000..de78860
--- /dev/null
+++ b/test/run_test.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+# Check the environment
+#
+if [ ! -x ../src/kbs ] ; then
+ echo kbs not built!
+ exit
+fi
+
+rm -f log
+
+../src/kbs test-config
+
+OK=1
+
+function fail()
+{
+ echo "BAD: " $*
+ OK=0
+}
+
+function good()
+{
+ echo GOOD: $*
+}
+
+if [ "`wc -l log | awk '{print $1}'`" != 8 ] ; then
+ fail Incorrect number of lines in log file - expected 8
+else
+ good Correct number of lines in log file - expected 8
+fi
+
+for i in trusted@ freebsd.org good_user ; do
+ if [ "`egrep $i log`" != "" ] ; then
+ fail Item $i incorrectly deleted
+ else
+ good Item $i correctly not deleted
+ fi
+done
+
+for i in bad_user@ microsoft.com bad_user2@ bad_user_uname@ bad_user_hname@ ; do
+ if [ "`egrep $i log`" == "" ] ; then
+ fail Item $i incorrectly not deleted
+ else
+ good Item $i correctly deleted
+ fi
+done
+
+if [ $OK == 1 ] ; then
+ echo '**** TEST OK'
+else
+ echo '**** TEST FAILED'
+fi
+
+rm -f log
diff --git a/test/test-config b/test/test-config
new file mode 100644
index 0000000..84fc6cc
--- /dev/null
+++ b/test/test-config
@@ -0,0 +1,40 @@
+set hostname localhost
+
+# These need setting correctly for the user defined in create_mails.sh
+#
+set username kbstest
+set password kbstest
+
+set casesense off
+set verbose off
+set showmatch on
+set dejunk on
+set testmode off
+set blockhtml on
+set log log
+
+trusted_users
+{
+ trusted@google.com
+}
+
+trusted_domains
+{
+ freebsd.org
+}
+
+blacklist
+{
+ microsoft.com
+}
+
+domain "."
+{
+ default allow
+
+ block_user bad_user2
+
+ allow_to "^UNAME\@HOSTNAME$"
+
+ block_subject "^bad$"
+}