aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--antispam-plugin.c11
-rw-r--r--antispam-plugin.h7
-rw-r--r--crm114-exec.c13
-rw-r--r--dspam-exec.c13
-rw-r--r--mailtrain.c13
-rw-r--r--signature-log.c13
-rw-r--r--spool2dir.c13
7 files changed, 51 insertions, 32 deletions
diff --git a/antispam-plugin.c b/antispam-plugin.c
index 8a6fb65..b94481b 100644
--- a/antispam-plugin.c
+++ b/antispam-plugin.c
@@ -330,20 +330,27 @@ void PLUGIN_FUNCTION(init)(void)
tmp = get_setting("BACKEND");
if (tmp) {
void *lib;
+
if (*tmp != '/')
tmp = t_strconcat(BACKENDDIR, tmp, ".so", NULL);
+
lib = dlopen(tmp, RTLD_NOW | RTLD_LOCAL);
if (!lib) {
debug("backend failed to load: %s\n", strerror(errno));
exit(3);
}
+
backend = dlsym(lib, "antispam_backend");
if (!backend) {
debug("invalid backend!\n");
exit(5);
}
- }
- else {
+
+ if (backend->api_version != BACKEND_API_VERSION) {
+ debug("backend API version mismatch");
+ exit(7);
+ }
+ } else {
debug("no backend selected!\n");
exit(2);
}
diff --git a/antispam-plugin.h b/antispam-plugin.h
index 4b95f63..2caf5a3 100644
--- a/antispam-plugin.h
+++ b/antispam-plugin.h
@@ -29,7 +29,14 @@ enum classification {
CLASS_SPAM,
};
+/* Update whenever the struct below needs to change */
+#define API_CODE 1
+#define BACKEND_API_VERSION ((DOVECOT_VERSION << 8) | API_CODE)
+
struct backend {
+ /* Set to BACKEND_API_VERSION */
+ unsigned int api_version;
+
void (*init)(pool_t pool);
void (*exit)(void);
/*
diff --git a/crm114-exec.c b/crm114-exec.c
index f4245dd..3947dbc 100644
--- a/crm114-exec.c
+++ b/crm114-exec.c
@@ -203,10 +203,11 @@ static void backend_exit(void)
}
struct backend antispam_backend = {
- .init = backend_init,
- .exit = backend_exit,
- .handle_mail = backend_handle_mail,
- .start = backend_start,
- .rollback = backend_rollback,
- .commit = backend_commit,
+ .api_version = BACKEND_API_VERSION,
+ .init = backend_init,
+ .exit = backend_exit,
+ .handle_mail = backend_handle_mail,
+ .start = backend_start,
+ .rollback = backend_rollback,
+ .commit = backend_commit,
};
diff --git a/dspam-exec.c b/dspam-exec.c
index ed706d7..4be4af4 100644
--- a/dspam-exec.c
+++ b/dspam-exec.c
@@ -268,10 +268,11 @@ static void backend_exit(void)
}
struct backend antispam_backend = {
- .init = backend_init,
- .exit = backend_exit,
- .handle_mail = backend_handle_mail,
- .start = backend_start,
- .rollback = backend_rollback,
- .commit = backend_commit,
+ .api_version = BACKEND_API_VERSION,
+ .init = backend_init,
+ .exit = backend_exit,
+ .handle_mail = backend_handle_mail,
+ .start = backend_start,
+ .rollback = backend_rollback,
+ .commit = backend_commit,
};
diff --git a/mailtrain.c b/mailtrain.c
index 276eb4a..e1c7bab 100644
--- a/mailtrain.c
+++ b/mailtrain.c
@@ -354,10 +354,11 @@ static void backend_exit(void)
}
struct backend antispam_backend = {
- .init = backend_init,
- .exit = backend_exit,
- .handle_mail = backend_handle_mail,
- .start = backend_start,
- .rollback = backend_rollback,
- .commit = backend_commit,
+ .api_version = BACKEND_API_VERSION,
+ .init = backend_init,
+ .exit = backend_exit,
+ .handle_mail = backend_handle_mail,
+ .start = backend_start,
+ .rollback = backend_rollback,
+ .commit = backend_commit,
};
diff --git a/signature-log.c b/signature-log.c
index 1cfc956..d0ab332 100644
--- a/signature-log.c
+++ b/signature-log.c
@@ -161,10 +161,11 @@ static void backend_exit(void)
}
struct backend antispam_backend = {
- .init = backend_init,
- .exit = backend_exit,
- .handle_mail = backend_handle_mail,
- .start = backend_start,
- .rollback = backend_rollback,
- .commit = backend_commit,
+ .api_version = BACKEND_API_VERSION,
+ .init = backend_init,
+ .exit = backend_exit,
+ .handle_mail = backend_handle_mail,
+ .start = backend_start,
+ .rollback = backend_rollback,
+ .commit = backend_commit,
};
diff --git a/spool2dir.c b/spool2dir.c
index 2c4b547..26fcd3e 100644
--- a/spool2dir.c
+++ b/spool2dir.c
@@ -259,10 +259,11 @@ static void backend_exit(void)
}
struct backend antispam_backend = {
- .init = backend_init,
- .exit = backend_exit,
- .handle_mail = backend_handle_mail,
- .start = backend_start,
- .rollback = backend_rollback,
- .commit = backend_commit,
+ .api_version = BACKEND_API_VERSION,
+ .init = backend_init,
+ .exit = backend_exit,
+ .handle_mail = backend_handle_mail,
+ .start = backend_start,
+ .rollback = backend_rollback,
+ .commit = backend_commit,
};