mirror of
https://bitbucket.org/jsuto/piler.git
synced 2025-06-12 23:17:02 +02:00
added body option for the rules check
This commit is contained in:
@ -105,6 +105,7 @@ struct rule {
|
||||
regex_t from;
|
||||
regex_t to;
|
||||
regex_t subject;
|
||||
regex_t body;
|
||||
regex_t attachment_name;
|
||||
regex_t attachment_type;
|
||||
#endif
|
||||
@ -119,7 +120,7 @@ struct rule {
|
||||
|
||||
int days;
|
||||
|
||||
char emptyfrom, emptyto, emptysubject, emptyaname, emptyatype;
|
||||
char emptyfrom, emptyto, emptysubject, emptybody, emptyaname, emptyatype;
|
||||
|
||||
char *rulestr;
|
||||
char compiled;
|
||||
|
38
src/rules.c
38
src/rules.c
@ -12,20 +12,21 @@
|
||||
|
||||
void load_rules(struct session_data *sdata, struct __data *data, struct node *xhash[], char *table){
|
||||
char s[SMALLBUFSIZE];
|
||||
char domain[SMALLBUFSIZE], from[SMALLBUFSIZE], to[SMALLBUFSIZE], subject[SMALLBUFSIZE], _size[SMALLBUFSIZE], attachment_name[SMALLBUFSIZE], attachment_type[SMALLBUFSIZE], _attachment_size[SMALLBUFSIZE];
|
||||
char domain[SMALLBUFSIZE], from[SMALLBUFSIZE], to[SMALLBUFSIZE], subject[SMALLBUFSIZE], body[SMALLBUFSIZE], _size[SMALLBUFSIZE], attachment_name[SMALLBUFSIZE], attachment_type[SMALLBUFSIZE], _attachment_size[SMALLBUFSIZE];
|
||||
int size=0, attachment_size=0, spam=0, days=0;
|
||||
|
||||
memset(domain, 0, sizeof(domain));
|
||||
memset(from, 0, sizeof(from));
|
||||
memset(to, 0, sizeof(to));
|
||||
memset(subject, 0, sizeof(subject));
|
||||
memset(body, 0, sizeof(body));
|
||||
memset(_size, 0, sizeof(_size));
|
||||
memset(attachment_name, 0, sizeof(attachment_name));
|
||||
memset(attachment_type, 0, sizeof(attachment_type));
|
||||
memset(_attachment_size, 0, sizeof(_attachment_size));
|
||||
|
||||
|
||||
snprintf(s, sizeof(s)-1, "SELECT `domain`, `from`, `to`, `subject`, `_size`, `size`, `attachment_name`, `attachment_type`, `_attachment_size`, `attachment_size`, `spam`, `days` FROM `%s`", table);
|
||||
snprintf(s, sizeof(s)-1, "SELECT `domain`, `from`, `to`, `subject`, `body`, `_size`, `size`, `attachment_name`, `attachment_type`, `_attachment_size`, `attachment_size`, `spam`, `days` FROM `%s`", table);
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), s) == ERR) return;
|
||||
|
||||
@ -42,6 +43,7 @@ void load_rules(struct session_data *sdata, struct __data *data, struct node *xh
|
||||
data->sql[data->pos] = &from[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(from)-2; data->pos++;
|
||||
data->sql[data->pos] = &to[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(to)-2; data->pos++;
|
||||
data->sql[data->pos] = &subject[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(subject)-2; data->pos++;
|
||||
data->sql[data->pos] = &body[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(body)-2; data->pos++;
|
||||
data->sql[data->pos] = &_size[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(_size)-2; data->pos++;
|
||||
data->sql[data->pos] = (char *)&size; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(size); data->pos++;
|
||||
data->sql[data->pos] = &attachment_name[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(attachment_name)-2; data->pos++;
|
||||
@ -56,12 +58,13 @@ void load_rules(struct session_data *sdata, struct __data *data, struct node *xh
|
||||
p_store_results(sdata, data->stmt_generic, data);
|
||||
|
||||
while(p_fetch_results(data->stmt_generic) == OK){
|
||||
append_rule(xhash, domain, from, to, subject, _size, size, attachment_name, attachment_type, _attachment_size, attachment_size, spam, days, data);
|
||||
append_rule(xhash, domain, from, to, subject, body, _size, size, attachment_name, attachment_type, _attachment_size, attachment_size, spam, days, data);
|
||||
|
||||
memset(domain, 0, sizeof(domain));
|
||||
memset(from, 0, sizeof(from));
|
||||
memset(to, 0, sizeof(to));
|
||||
memset(subject, 0, sizeof(subject));
|
||||
memset(body, 0, sizeof(body));
|
||||
memset(_size, 0, sizeof(_size));
|
||||
memset(attachment_name, 0, sizeof(attachment_name));
|
||||
memset(attachment_type, 0, sizeof(attachment_type));
|
||||
@ -78,7 +81,7 @@ ENDE:
|
||||
}
|
||||
|
||||
|
||||
int append_rule(struct node *xhash[], char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_name, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data){
|
||||
int append_rule(struct node *xhash[], char *domain, char *from, char *to, char *subject, char *body, char *_size, int size, char *attachment_name, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data){
|
||||
struct node *q, *Q=NULL, *node;
|
||||
struct rule *rule;
|
||||
int rc=0;
|
||||
@ -88,11 +91,11 @@ int append_rule(struct node *xhash[], char *domain, char *from, char *to, char *
|
||||
memset(node, 0, sizeof(struct node));
|
||||
node->r = NULL;
|
||||
|
||||
rule = create_rule_item(domain, from, to, subject, _size, size, attachment_name, attachment_type, _attachment_size, attachment_size, spam, days, data);
|
||||
rule = create_rule_item(domain, from, to, subject, body, _size, size, attachment_name, attachment_type, _attachment_size, attachment_size, spam, days, data);
|
||||
|
||||
if(rule == NULL){
|
||||
free(node);
|
||||
syslog(LOG_INFO, "could not load rule=%s/%s/%s/%s/%s,%d", domain, from, to, subject, _size, size);
|
||||
syslog(LOG_INFO, "could not load rule=%s/%s/%s/%s/%s/%s,%d", domain, from, to, subject, body, _size, size);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -116,7 +119,7 @@ int append_rule(struct node *xhash[], char *domain, char *from, char *to, char *
|
||||
}
|
||||
|
||||
|
||||
struct rule *create_rule_item(char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_name, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data){
|
||||
struct rule *create_rule_item(char *domain, char *from, char *to, char *subject, char *body, char *_size, int size, char *attachment_name, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data){
|
||||
struct rule *h=NULL;
|
||||
char empty = '\0';
|
||||
int len;
|
||||
@ -151,6 +154,9 @@ struct rule *create_rule_item(char *domain, char *from, char *to, char *subject,
|
||||
if(!subject || strlen(subject) < 1){ subject = ∅ h->emptysubject = 1; }
|
||||
if(regcomp(&(h->subject), subject, REG_ICASE | REG_EXTENDED)) h->compiled = 0;
|
||||
|
||||
if(!body || strlen(body) < 1){ body = ∅ h->emptybody = 1; }
|
||||
if(regcomp(&(h->body), body, REG_ICASE | REG_EXTENDED)) h->compiled = 0;
|
||||
|
||||
h->spam = spam;
|
||||
h->days = days;
|
||||
|
||||
@ -171,12 +177,12 @@ struct rule *create_rule_item(char *domain, char *from, char *to, char *subject,
|
||||
if(!_attachment_size) _attachment_size = ∅
|
||||
snprintf(h->_attachment_size, 3, "%s", _attachment_size);
|
||||
|
||||
len = strlen(domain)+8 + strlen(from)+6 + strlen(to)+4 + strlen(subject)+9 + strlen(_size)+6 + strlen(attachment_name)+10 + strlen(attachment_type)+10 + strlen(_attachment_size)+10 + 9 + 15 + 15;
|
||||
len = strlen(domain)+8 + strlen(from)+6 + strlen(to)+4 + strlen(subject)+9 + strlen(body)+6 + strlen(_size)+6 + strlen(attachment_name)+10 + strlen(attachment_type)+10 + strlen(_attachment_size)+10 + 9 + 15 + 15;
|
||||
h->rulestr = malloc(len);
|
||||
|
||||
|
||||
|
||||
if(h->rulestr) snprintf(h->rulestr, len-1, "domain=%s,from=%s,to=%s,subject=%s,size%s%d,att.name=%s,att.type=%s,att.size%s%d,spam=%d", domain, from, to, subject, _size, size, attachment_name, attachment_type, _attachment_size, attachment_size, spam);
|
||||
if(h->rulestr) snprintf(h->rulestr, len-1, "domain=%s,from=%s,to=%s,subject=%s,body=%s,size%s%d,att.name=%s,att.type=%s,att.size%s%d,spam=%d", domain, from, to, subject, body, _size, size, attachment_name, attachment_type, _attachment_size, attachment_size, spam);
|
||||
else h->compiled = 0;
|
||||
|
||||
h->r = NULL;
|
||||
@ -220,6 +226,12 @@ char *check_againt_ruleset(struct node *xhash[], struct _state *state, int size,
|
||||
ismatch += RULE_UNDEF;
|
||||
}
|
||||
else if(regexec(&(p->subject), state->b_subject, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
||||
|
||||
if(p->emptybody == 1){
|
||||
ismatch += RULE_UNDEF;
|
||||
}
|
||||
else if(regexec(&(p->body), state->b_body, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
||||
|
||||
}
|
||||
|
||||
if(ismatch > 0){
|
||||
@ -278,6 +290,12 @@ unsigned long query_retain_period(struct __data *data, struct _state *state, int
|
||||
ismatch += RULE_UNDEF;
|
||||
}
|
||||
else if(regexec(&(p->subject), state->b_subject, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
||||
|
||||
if(p->emptybody == 1){
|
||||
ismatch += RULE_UNDEF;
|
||||
}
|
||||
else if(regexec(&(p->body), state->b_body, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
||||
|
||||
}
|
||||
|
||||
if(ismatch > 0){
|
||||
@ -373,6 +391,8 @@ void clearrules(struct node *xhash[]){
|
||||
|
||||
regfree(&(rule->from));
|
||||
regfree(&(rule->to));
|
||||
regfree(&(rule->subject));
|
||||
regfree(&(rule->body));
|
||||
regfree(&(rule->attachment_name));
|
||||
regfree(&(rule->attachment_type));
|
||||
|
||||
|
@ -8,8 +8,8 @@
|
||||
#include "defs.h"
|
||||
|
||||
void load_rules(struct session_data *sdata, struct __data *data, struct node *xhash[], char *table);
|
||||
int append_rule(struct node *xhash[], char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_name, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data);
|
||||
struct rule *create_rule_item(char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_name, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data);
|
||||
int append_rule(struct node *xhash[], char *domain, char *from, char *to, char *subject, char *body, char *_size, int size, char *attachment_name, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data);
|
||||
struct rule *create_rule_item(char *domain, char *from, char *to, char *subject, char *body, char *_size, int size, char *attachment_name, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data);
|
||||
char *check_againt_ruleset(struct node *xhash[], struct _state *state, int size, int spam);
|
||||
unsigned long query_retain_period(struct __data *data, struct _state *state, int size, int spam, struct __config *cfg);
|
||||
int check_size_rule(int message_size, int size, char *_size);
|
||||
|
Reference in New Issue
Block a user