diff options
author | Ian C <ianc@noddybox.co.uk> | 2003-12-09 01:25:08 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2003-12-09 01:25:08 +0000 |
commit | b0feacc0fe2d006ac4536f5069c9373beffe2cf5 (patch) | |
tree | a8f78032fe66f9be35383c27851bd65189b693f9 /src | |
parent | 1c161a8cbe16aa59cc8bf4d60d5fa64fdcbc6aa5 (diff) |
Added blacklist command; fixed a few dodgy frees (oops)
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 51 | ||||
-rw-r--r-- | src/dbase.c | 26 | ||||
-rw-r--r-- | src/dbase.h | 5 | ||||
-rw-r--r-- | src/kbsrc | 39 |
4 files changed, 106 insertions, 15 deletions
diff --git a/src/config.c b/src/config.c index 268198d..4e369f7 100644 --- a/src/config.c +++ b/src/config.c @@ -54,6 +54,7 @@ typedef enum { TOK_AllowSubject, TOK_BlockSubject, TOK_SubjectMacro, + TOK_Blacklist, TOK_VarHostname, TOK_VarPort, TOK_VarUsername, @@ -122,6 +123,7 @@ static const Command cmd_table[]= {"allow_subject", TOK_AllowSubject}, {"block_subject", TOK_BlockSubject}, {"subject_macro", TOK_SubjectMacro}, + {"blacklist", TOK_Blacklist}, /* Variables */ @@ -524,6 +526,50 @@ static int DoSubjectMacro(FILE *fp) } +static int DoBlacklist(FILE *fp) +{ + DString ds; + Token tok; + + ds=DSInit(); + + tok=GetToken(fp,&ds); + + if (tok!=TOK_OpenBracket) + { + DSAddCP(error,"Missing opening bracket in blacklist"); + DSFree(ds); + return FALSE; + } + + while((tok=GetToken(fp,&ds))!=TOK_CloseBracket) + { + RE_Expression re; + + if (tok==TOK_EOF) + { + DSAddCP(error,"Missing close bracket in blacklist"); + DSFree(ds); + return FALSE; + } + + if (!(re=RECompile(ds->text))) + { + DSAddCP(error,"Bad regular expression: "); + DSAddDS(error,ds); + DSFree(ds); + return FALSE; + } + + DBBlacklist(re); + } + + DSFree(ds); + + return TRUE; +} + + /* ---------------------------------------- PRVIVATE FUNCTIONS */ static int Getc(FILE *fp) @@ -695,6 +741,11 @@ static int Parse(FILE *fp) ok=FALSE; break; + case TOK_Blacklist: + if (!DoBlacklist(fp)) + ok=FALSE; + break; + case TOK_Expression: DSAddCP(error,"Unknown command in config file: "); DSAddDS(error,txt); diff --git a/src/dbase.c b/src/dbase.c index 43fe0b5..98a7629 100644 --- a/src/dbase.c +++ b/src/dbase.c @@ -62,9 +62,11 @@ static Domain *tail; static int no_trusted_users=0; static int no_trusted_domains=0; +static int no_blacklist=0; static char **trusted_user=NULL; static char **trusted_domain=NULL; +static RE_Expression **blacklist=NULL; static const char *reason; @@ -220,6 +222,14 @@ void DBTrustedDomain(const char *domain) } +void DBBlacklist(RE_Expression re) +{ + no_blacklist++; + blacklist=Realloc(blacklist,sizeof(RE_Expression)*no_blacklist); + blacklist[no_blacklist-1]=re; +} + + int DBBlockMessage(const POP3Message *msg) { static const char *html="text/html"; @@ -243,6 +253,15 @@ int DBBlockMessage(const POP3Message *msg) return TRUE; } + for(f=0;f<no_blacklist;f++) + { + if (RESearch(blacklist[f],msg->from_domain)) + { + reason="blacklisted"; + return TRUE; + } + } + if (!(dom=GetDomain(msg->from_domain))) return FALSE; @@ -316,6 +335,11 @@ void DBClose(void) free(trusted_user); + for(f=0;f<no_blacklist;f++) + REFree(blacklist[f]); + + free(blacklist); + d=head; while(d) @@ -337,7 +361,7 @@ void DBClose(void) free(t->block); for(f=0;f<t->no_allow;f++) - free(t->allow[f]); + REFree(t->allow[f]); free(t->allow); diff --git a/src/dbase.h b/src/dbase.h index c7a98ee..7ee7164 100644 --- a/src/dbase.h +++ b/src/dbase.h @@ -80,6 +80,11 @@ void DBTrustedUser(const char *username); void DBTrustedDomain(const char *domain); +/* Adds a blacklisted domain +*/ +void DBBlacklist(RE_Expression re); + + /* Returns TRUE if message is to be blocked */ int DBBlockMessage(const POP3Message *msg); @@ -24,31 +24,41 @@ trusted_domains { my-place-of-work.com freebsd.org + kernel.org } +# Blacklist specific domains +# +blacklist +{ + ^wretched-hive-of-scum-and-villainy\.com$ + ^jumbo-whatsits\.com$ + ^microsoft\.com$ +} + + +# Set up a few subject macros +# +subject_macro "i" "[il1!]" +subject_macro "e" "[e3]" +subject_macro "s" "[s5z]" + + # Domain based rules # # Remember that the domain is defined in the form of a regular expression! # # Anyone who doesn't know me, has to include the string ansi-c to -# get through from a .net address. +# get through from a .com address. # -domain "\.net$" +domain "\.com$" { default block allow_subject ".*ansi-c.*" } -# 'Blacklist' a specific domain -# -domain "^wretched-hive-of-scum-and-villainy\.com$" -{ - default block -} - - # Or alternatively apply general rules to all untrusted messages # domain "." @@ -66,7 +76,7 @@ domain "." # to check the delete logs once in a while. # # And to avoid insulting anyone, there are some obvious words missing - # from this example list... If you're old enough, add them yourself. + # from this example list... If you're old enough, add them yourself... # # And finally remember a few variants - spelling isn't what it once was # amongst spammers... @@ -78,14 +88,15 @@ domain "." block_subject ".* ?mortgage ?.*" block_subject ".* ?credit card ?.*" block_subject ".* ?miracle pill ?.*" - block_subject ".* ?teenage girl ?.*" + block_subject ".* ?schoolgirl ?.*" block_subject ".* ?video tape ?.*" block_subject ".* ?sexy? ?.*" block_subject ".* ?naked ?.*" block_subject ".* ?nigeria ?.*" # Why would anyone sane want to use my username in a subject? - # I know who I am! + # I know who I am! Note it's capitilised so nothing bizarre gets + # done by the subject macros. # - block_subject "emailname@my-isp.co.uk" + block_subject "EMAILNAME@MY-ISP.CO.UK" } |