Add a "special" return value: abort.
[apps/pfixtools.git] / postlicyd / greylist.c
index 108b02b..88ec6c7 100644 (file)
@@ -51,7 +51,7 @@ typedef struct greylist_config_t {
 
 #define GREYLIST_INIT { .lookup_by_host = false,       \
                         .delay = 300,                  \
-                        .retry_window = 2 * 24 * 2600, \
+                        .retry_window = 2 * 24 * 3600, \
                         .client_awl = 5,               \
                         .awl_db = NULL,                \
                         .obj_db = NULL }
@@ -78,8 +78,8 @@ static bool greylist_initialize(greylist_config_t *config,
         if (!tcbdbopen(config->awl_db, path, BDBOWRITER | BDBOCREAT)) {
             tcbdbdel(config->awl_db);
             config->awl_db = NULL;
+            return false;
         }
-        return false;
     }
 
     snprintf(path, sizeof(path), "%s/%sgreylist.db", directory, prefix);
@@ -216,6 +216,7 @@ static bool try_greylist(const greylist_config_t *config,
 
             /* OK.
              */
+            //syslog(LOG_INFO, "client whitelisted");
             return true;
         }
     }
@@ -259,11 +260,13 @@ static bool try_greylist(const greylist_config_t *config,
 
         /* OK
          */
+        //syslog(LOG_INFO, "client whitelisted");
         return true;
     }
 
     /* DUNNO
      */
+    //syslog(LOG_INFO, "client greylisted");
     return false;
 }
 
@@ -346,9 +349,14 @@ static filter_result_t greylist_filter(const filter_t *filter,
                                        const query_t *query)
 {
     const greylist_config_t *config = filter->data;
+    if (query->state != SMTP_RCPT) {
+        syslog(LOG_WARNING, "greylisting only works as smtpd_recipient_restrictions");
+        return HTK_ABORT;
+    }
+
     return try_greylist(config, query->sender, query->client_address,
                         query->client_name, query->recipient) ?
-           HTK_MATCH : HTK_FAIL;
+           HTK_WHITELIST : HTK_GREYLIST;
 }
 
 static int greylist_init(void)
@@ -358,9 +366,10 @@ static int greylist_init(void)
                                           greylist_filter);
     /* Hooks.
      */
+    (void)filter_hook_register(type, "abort");
     (void)filter_hook_register(type, "error");
-    (void)filter_hook_register(type, "fail");
-    (void)filter_hook_register(type, "match");
+    (void)filter_hook_register(type, "greylist");
+    (void)filter_hook_register(type, "whitelist");
 
     /* Parameters.
      */