From: Florent Bruneau Date: Sat, 4 Oct 2008 13:23:09 +0000 (+0200) Subject: Merge branch 'master' into with-dns-bl X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=1b0d47e10359293dafc8937b8036168d7ec61a6a;hp=a3eac0731ffb3a31b57f9feed0256678f187f2a1;p=apps%2Fpfixtools.git Merge branch 'master' into with-dns-bl --- diff --git a/example/postlicyd.conf b/example/postlicyd.conf index ca17b60..123c66a 100644 --- a/example/postlicyd.conf +++ b/example/postlicyd.conf @@ -126,7 +126,8 @@ spamhaus_and_abuseat { # currently only email OR hostname fields are supported. You MUST choose only # one of these types per strlist, and be carefull that the field you requested # are available in the protocol state you want to use this filter for. -# * hostname fields: helo_name, client_name, reverse_client_name +# * hostname fields: helo_name, client_name, reverse_client_name, sender_domain, +# recipient_domain # * email fields: sender, recipient # No space is allowed in this parameter. # Return value: @@ -207,6 +208,7 @@ greylist { # emitted by postfix. This list with description of each # field is available at: # http://www.postfix.org/SMTPD_POLICY_README.html +# postlicyd also support fields sender_domain and recipient_domain # * OP is an operator. Available operators are: # == field_name is strictly equal to value # =i field_name is case insensitively equal to value diff --git a/postlicyd/match.c b/postlicyd/match.c index b6d108f..1b02cc2 100644 --- a/postlicyd/match.c +++ b/postlicyd/match.c @@ -189,7 +189,9 @@ static inline bool match_condition(const match_condition_t *cond, const query_t CASE(HELO_NAME, helo_name) CASE(QUEUE_ID, queue_id) CASE(SENDER, sender) + CASE(SENDER_DOMAIN, sender_domain) CASE(RECIPIENT, recipient) + CASE(RECIPIENT_DOMAIN, recipient_domain) CASE(RECIPIENT_COUNT, recipient_count) CASE(CLIENT_ADDRESS, client_address) CASE(CLIENT_NAME, client_name) diff --git a/postlicyd/policy_tokens.sh b/postlicyd/policy_tokens.sh index 2b2b07e..f5361c6 100755 --- a/postlicyd/policy_tokens.sh +++ b/postlicyd/policy_tokens.sh @@ -137,6 +137,10 @@ exit 0 ## reverse_client_name ## instance # +# helpers +## sender_domain +## recipient_domain +# # postfix 2.2+ ## sasl_method ## sasl_username diff --git a/postlicyd/query.c b/postlicyd/query.c index 26b590a..327c2b7 100644 --- a/postlicyd/query.c +++ b/postlicyd/query.c @@ -72,8 +72,6 @@ bool query_parse(query_t *query, char *p) #define CASE(up, low) case PTK_##up: query->low = v; v[vlen] = '\0'; break; CASE(HELO_NAME, helo_name); CASE(QUEUE_ID, queue_id); - CASE(SENDER, sender); - CASE(RECIPIENT, recipient); CASE(RECIPIENT_COUNT, recipient_count); CASE(CLIENT_ADDRESS, client_address); CASE(CLIENT_NAME, client_name); @@ -93,6 +91,24 @@ bool query_parse(query_t *query, char *p) CASE(STRESS, stress); #undef CASE + case PTK_SENDER: + query->sender = v; + v[vlen] = '\0'; + query->sender_domain = memchr(query->sender, '@', vlen); + if (query->sender_domain != NULL) { + ++query->sender_domain; + } + break; + + case PTK_RECIPIENT: + query->recipient = v; + v[vlen] = '\0'; + query->recipient_domain = memchr(query->recipient, '@', vlen); + if (query->recipient_domain != NULL) { + ++query->recipient_domain; + } + break; + case PTK_REQUEST: PARSE_CHECK(vtk == PTK_SMTPD_ACCESS_POLICY, "unexpected `request' value: %.*s", vlen, v); diff --git a/postlicyd/query.h b/postlicyd/query.h index f9cd0b6..87ee01e 100644 --- a/postlicyd/query.h +++ b/postlicyd/query.h @@ -69,6 +69,10 @@ typedef struct query_t { const char *reverse_client_name; const char *instance; + /* useful data extracted from previous ones */ + const char *sender_domain; + const char *recipient_domain; + /* postfix 2.2+ */ const char *sasl_method; const char *sasl_username; diff --git a/postlicyd/strlist.c b/postlicyd/strlist.c index 0c8fce3..19fd0b2 100644 --- a/postlicyd/strlist.c +++ b/postlicyd/strlist.c @@ -49,10 +49,11 @@ typedef struct strlist_config_t { int hard_threshold; unsigned is_email :1; + unsigned is_hostname :1; + unsigned match_sender :1; unsigned match_recipient :1; - unsigned is_hostname :1; unsigned match_helo :1; unsigned match_client :1; unsigned match_reverse :1; @@ -276,6 +277,8 @@ static bool strlist_filter_constructor(filter_t *filter) CASE(HELO_NAME, helo, hostname); CASE(CLIENT_NAME, client, hostname); CASE(REVERSE_CLIENT_NAME, reverse, hostname); + CASE(SENDER_DOMAIN, sender, hostname); + CASE(RECIPIENT_DOMAIN, recipient, hostname); CASE(SENDER, sender, email); CASE(RECIPIENT, recipient, email); #undef CASE @@ -352,6 +355,8 @@ static filter_result_t strlist_filter(const filter_t *filter, const query_t *que LOOKUP(helo, helo_name); LOOKUP(client, client_name); LOOKUP(reverse, reverse_client_name); + LOOKUP(recipient, recipient_domain); + LOOKUP(sender, sender_domain); } #undef LOOKUP if (sum >= config->hard_threshold) {