rule check fix

This commit is contained in:
SJ 2014-05-12 01:05:44 +02:00
parent e2afcc34bf
commit f763ed5f4d
4 changed files with 40 additions and 21 deletions

View File

@ -14,7 +14,7 @@
#define VERSION "0.1.25-rc2" #define VERSION "0.1.25-rc2"
#define BUILD 871 #define BUILD 872
#define HOSTID "mailarchiver" #define HOSTID "mailarchiver"
@ -127,8 +127,10 @@
#define WRITE_TO_STDOUT 0 #define WRITE_TO_STDOUT 0
#define WRITE_TO_BUFFER 1 #define WRITE_TO_BUFFER 1
#define S_STATUS_UNDEF "undef"
#define S_STATUS_STORED "stored" #define S_STATUS_STORED "stored"
#define S_STATUS_DUPLICATE "duplicate" #define S_STATUS_DUPLICATE "duplicate"
#define S_STATUS_DISCARDED "discarded"
#define S_STATUS_ERROR "error" #define S_STATUS_ERROR "error"
#endif /* _CONFIG_H */ #endif /* _CONFIG_H */

View File

@ -58,6 +58,10 @@
#define MAXCHILDREN 64 #define MAXCHILDREN 64
#define RULE_UNDEF 0
#define RULE_MATCH 1
#define RULE_NO_MATCH -100
typedef void signal_func (int); typedef void signal_func (int);

View File

@ -185,6 +185,7 @@ char *check_againt_ruleset(struct node *xhash[], struct _state *state, int size,
size_t nmatch=0; size_t nmatch=0;
struct rule *p; struct rule *p;
struct node *q; struct node *q;
int ismatch;
q = xhash[0]; q = xhash[0];
@ -194,14 +195,18 @@ char *check_againt_ruleset(struct node *xhash[], struct _state *state, int size,
p = q->str; p = q->str;
if(p){ if(p){
ismatch = 0;
ismatch += check_spam_rule(spam, p->spam);
ismatch += check_size_rule(size, p->size, p->_size);
ismatch += check_attachment_rule(state, p);
if( if(
p->compiled == 1 && p->compiled == 1 &&
regexec(&(p->from), state->b_from, nmatch, NULL, 0) == 0 && regexec(&(p->from), state->b_from, nmatch, NULL, 0) == 0 &&
regexec(&(p->to), state->b_to, nmatch, NULL, 0) == 0 && regexec(&(p->to), state->b_to, nmatch, NULL, 0) == 0 &&
regexec(&(p->subject), state->b_subject, nmatch, NULL, 0) == 0 && regexec(&(p->subject), state->b_subject, nmatch, NULL, 0) == 0 &&
check_size_rule(size, p->size, p->_size) == 1 && ismatch > 0
check_attachment_rule(state, p) == 1 &&
check_spam_rule(spam, p->spam) == 1
){ ){
return p->rulestr; return p->rulestr;
} }
@ -220,6 +225,7 @@ unsigned long query_retain_period(struct __data *data, struct _state *state, int
size_t nmatch=0; size_t nmatch=0;
struct rule *p; struct rule *p;
struct node *q; struct node *q;
int ismatch;
q = data->retention_rules[0]; q = data->retention_rules[0];
@ -228,6 +234,12 @@ unsigned long query_retain_period(struct __data *data, struct _state *state, int
if(q->str){ if(q->str){
p = q->str; p = q->str;
ismatch = 0;
ismatch += check_spam_rule(spam, p->spam);
ismatch += check_size_rule(size, p->size, p->_size);
ismatch += check_attachment_rule(state, p);
if(p->domainlen > 2){ if(p->domainlen > 2){
if(strcasestr(state->b_to_domain, p->domain) || strcasestr(state->b_from_domain, p->domain)){ if(strcasestr(state->b_to_domain, p->domain) || strcasestr(state->b_from_domain, p->domain)){
state->retention = p->days; state->retention = p->days;
@ -239,9 +251,7 @@ unsigned long query_retain_period(struct __data *data, struct _state *state, int
regexec(&(p->from), state->b_from, nmatch, NULL, 0) == 0 && regexec(&(p->from), state->b_from, nmatch, NULL, 0) == 0 &&
regexec(&(p->to), state->b_to, nmatch, NULL, 0) == 0 && regexec(&(p->to), state->b_to, nmatch, NULL, 0) == 0 &&
regexec(&(p->subject), state->b_subject, nmatch, NULL, 0) == 0 && regexec(&(p->subject), state->b_subject, nmatch, NULL, 0) == 0 &&
check_size_rule(size, p->size, p->_size) == 1 && ismatch > 0
check_attachment_rule(state, p) == 1 &&
check_spam_rule(spam, p->spam) == 1
){ ){
state->retention = p->days; state->retention = p->days;
return p->days * 86400; return p->days * 86400;
@ -260,21 +270,21 @@ unsigned long query_retain_period(struct __data *data, struct _state *state, int
int check_size_rule(int message_size, int size, char *_size){ int check_size_rule(int message_size, int size, char *_size){
if(size <= 0) return 1; if(size <= 0) return RULE_UNDEF;
if(strcmp(_size, ">") == 0 && message_size > size) return 1; if(strcmp(_size, ">") == 0 && message_size > size) return RULE_MATCH;
if(strcmp(_size, "<") == 0 && message_size < size) return 1; if(strcmp(_size, "<") == 0 && message_size < size) return RULE_MATCH;
if(strcmp(_size, "=") == 0 && message_size == size) return 1; if(strcmp(_size, "=") == 0 && message_size == size) return RULE_MATCH;
if( (strcmp(_size, "<>") == 0 || strcmp(_size, "!=") == 0) && message_size != size) return 1; if( (strcmp(_size, "<>") == 0 || strcmp(_size, "!=") == 0) && message_size != size) return RULE_MATCH;
return 0; return RULE_NO_MATCH;
} }
int check_spam_rule(int is_spam, int spam){ int check_spam_rule(int is_spam, int spam){
if(spam == -1) return 1; if(spam == -1) return RULE_UNDEF;
if(is_spam == spam) return 1; if(is_spam == spam) return RULE_MATCH;
return 0; return RULE_NO_MATCH;
} }
@ -282,7 +292,7 @@ int check_attachment_rule(struct _state *state, struct rule *rule){
int i; int i;
size_t nmatch=0; size_t nmatch=0;
if(state->n_attachments == 0) return 1; if(state->n_attachments == 0) return RULE_UNDEF;
for(i=1; i<=state->n_attachments; i++){ for(i=1; i<=state->n_attachments; i++){
if( if(
@ -290,11 +300,11 @@ int check_attachment_rule(struct _state *state, struct rule *rule){
regexec(&(rule->attachment_type), state->attachments[i].type, nmatch, NULL, 0) == 0 && regexec(&(rule->attachment_type), state->attachments[i].type, nmatch, NULL, 0) == 0 &&
check_size_rule(state->attachments[i].size, rule->attachment_size, rule->_attachment_size) == 1 check_size_rule(state->attachments[i].size, rule->attachment_size, rule->_attachment_size) == 1
){ ){
return 1; return RULE_MATCH;
} }
} }
return 0; return RULE_NO_MATCH;
} }

View File

@ -200,6 +200,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
extractEmail(sdata.rcptto[i], rcpttoemail); extractEmail(sdata.rcptto[i], rcpttoemail);
inj = ERR; inj = ERR;
status = S_STATUS_UNDEF;
if(db_conn == 1){ if(db_conn == 1){
@ -228,12 +229,16 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
counters.c_ignore++; counters.c_ignore++;
remove_stripped_attachments(&sstate); remove_stripped_attachments(&sstate);
status = S_STATUS_DISCARDED;
} }
else { else {
inj = process_message(&sdata, &sstate, data, cfg); inj = process_message(&sdata, &sstate, data, cfg);
unlink(sstate.message_id_hash); unlink(sstate.message_id_hash);
counters.c_size += sdata.tot_len; counters.c_size += sdata.tot_len;
counters.c_stored_size = sdata.stored_len; counters.c_stored_size = sdata.stored_len;
status = S_STATUS_STORED;
} }
} }
@ -246,8 +251,6 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
snprintf(sdata.acceptbuf, SMALLBUFSIZE-1, "250 Ok %s <%s>\r\n", sdata.ttmpfile, rcpttoemail); snprintf(sdata.acceptbuf, SMALLBUFSIZE-1, "250 Ok %s <%s>\r\n", sdata.ttmpfile, rcpttoemail);
status = S_STATUS_STORED;
if(inj == ERR){ if(inj == ERR){
snprintf(sdata.acceptbuf, SMALLBUFSIZE-1, "451 %s <%s>\r\n", sdata.ttmpfile, rcpttoemail); snprintf(sdata.acceptbuf, SMALLBUFSIZE-1, "451 %s <%s>\r\n", sdata.ttmpfile, rcpttoemail);
status = S_STATUS_ERROR; status = S_STATUS_ERROR;