Merge branch 'master' into with-dns-bl
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 4 Oct 2008 13:23:09 +0000 (15:23 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 4 Oct 2008 13:23:09 +0000 (15:23 +0200)
example/postlicyd.conf
postlicyd/match.c
postlicyd/policy_tokens.sh
postlicyd/query.c
postlicyd/query.h
postlicyd/strlist.c

index ca17b60..123c66a 100644 (file)
@@ -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
index b6d108f..1b02cc2 100644 (file)
@@ -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)
index 2b2b07e..f5361c6 100755 (executable)
@@ -137,6 +137,10 @@ exit 0
 ## reverse_client_name
 ## instance
 #
+# helpers
+## sender_domain
+## recipient_domain
+#
 # postfix 2.2+
 ## sasl_method
 ## sasl_username
index 26b590a..327c2b7 100644 (file)
@@ -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);
index f9cd0b6..87ee01e 100644 (file)
@@ -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;
index 0c8fce3..19fd0b2 100644 (file)
@@ -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) {