From e0088298ef140eed031bbdbc0cbc5feebf8e2976 Mon Sep 17 00:00:00 2001 From: Bruce Guenter Date: Sun, 12 Nov 2006 20:42:40 +0000 Subject: [PATCH] Added a version number to the plugin ABI to prevent semantic mismatches. --- NEWS | 4 ++-- backend-echo.c | 1 + backend-qmail.c | 1 + mailfront.h | 6 ++++++ modules.c | 9 +++++++++ plugin-add-received.c | 1 + plugin-check-fqdn.c | 1 + plugin-clamav.c | 1 + plugin-counters.c | 1 + plugin-cvm-validate.c | 1 + plugin-mailrules.c | 1 + plugin-patterns.c | 1 + plugin-qmail-validate.c | 1 + plugin-reject.c | 1 + plugin-relayclient.c | 1 + plugin-require-auth.c | 1 + plugin.c | 1 + protocol-qmqp.c | 1 + protocol-qmtp.c | 1 + protocol-smtp.c | 1 + 20 files changed, 34 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index d40b3fb..e88cbe3 100644 --- a/NEWS +++ b/NEWS @@ -3,8 +3,8 @@ Changes in version 1.10 - Added a ClamAV virus scanner plugin. -- Modified the plugin API to add a flags word and to (optionally) save - messages to a temporary file (needed by the ClamAV plugin). +- Modified the plugin API to add a version code, a flags word, and to + (optionally) save messages to a temporary file. Development of this version has been sponsored by FutureQuest, Inc. ossi@FutureQuest.net http://www.FutureQuest.net/ diff --git a/backend-echo.c b/backend-echo.c index e530018..81d55b3 100644 --- a/backend-echo.c +++ b/backend-echo.c @@ -85,6 +85,7 @@ static const response* message_end(int fd) } struct plugin backend = { + .version = PLUGIN_VERSION, .reset = reset, .sender = sender, .recipient = recipient, diff --git a/backend-qmail.c b/backend-qmail.c index 391f018..d659464 100644 --- a/backend-qmail.c +++ b/backend-qmail.c @@ -204,6 +204,7 @@ static const response* message_end(int fd) } struct plugin backend = { + .version = PLUGIN_VERSION, .reset = reset, .sender = do_sender, .recipient = do_recipient, diff --git a/mailfront.h b/mailfront.h index 0d8f031..5e463ab 100644 --- a/mailfront.h +++ b/mailfront.h @@ -9,8 +9,11 @@ #define FLAG_NEED_FILE (1<<0) +#define PLUGIN_VERSION 2 + struct plugin { + unsigned version; struct plugin* next; const char* name; unsigned flags; @@ -24,8 +27,11 @@ struct plugin const response* (*message_end)(int fd); }; +#define PROTOCOL_VERSION 2 + struct protocol { + unsigned version; const char* name; int (*respond_line)(unsigned number, int final, const char* msg, unsigned long len); diff --git a/modules.c b/modules.c index 1b6fefb..e259bec 100644 --- a/modules.c +++ b/modules.c @@ -6,6 +6,9 @@ #include "conf_modules.c" static response resp_load = { 451, 0 }; +static RESPONSE(backend_version,451,"4.3.0 Backend ABI version mismatch"); +static RESPONSE(plugin_version,451,"4.3.0 Plugin ABI version mismatch"); +static RESPONSE(protocol_version,451,"4.3.0 Protocol ABI version mismatch"); struct plugin* plugin_list = 0; struct plugin* plugin_tail = 0; @@ -97,6 +100,8 @@ static const response* load_plugin(const char* name) if ((plugin = find_builtin_plugin(name)) == 0) { if ((plugin = load_object("plugin", name)) == 0) return &resp_load; + if (plugin->version != PLUGIN_VERSION) + return &resp_plugin_version; if ((plugin->name = strdup(name)) == 0) return &resp_oom; } @@ -140,8 +145,12 @@ const response* load_modules(const char* protocol_name, module_path = conf_modules; if ((session.protocol = load_object("protocol", protocol_name)) == 0) return &resp_load; + if (session.protocol->version != PROTOCOL_VERSION) + return &resp_protocol_version; if ((session.backend = load_object("backend", backend_name)) == 0) return &resp_load; + if (session.backend->version != PLUGIN_VERSION) + return &resp_backend_version; module_flags |= session.backend->flags; while (*plugins != 0) if ((r = load_plugins(*plugins++)) != 0) diff --git a/plugin-add-received.c b/plugin-add-received.c index a727b91..6a38966 100644 --- a/plugin-add-received.c +++ b/plugin-add-received.c @@ -144,6 +144,7 @@ static const response* data_start(int fd) } struct plugin plugin = { + .version = PLUGIN_VERSION, .init = init, .data_start = data_start, }; diff --git a/plugin-check-fqdn.c b/plugin-check-fqdn.c index 3f09c2d..f84c25e 100644 --- a/plugin-check-fqdn.c +++ b/plugin-check-fqdn.c @@ -17,6 +17,7 @@ static const response* either(str* s) } struct plugin plugin = { + .version = PLUGIN_VERSION, .sender = either, .recipient = either, }; diff --git a/plugin-clamav.c b/plugin-clamav.c index 0020462..8ada986 100644 --- a/plugin-clamav.c +++ b/plugin-clamav.c @@ -102,6 +102,7 @@ static const response* message_end(int fd) } struct plugin plugin = { + .version = PLUGIN_VERSION, .flags = FLAG_NEED_FILE, .message_end = message_end, }; diff --git a/plugin-counters.c b/plugin-counters.c index 633f780..eec3f5a 100644 --- a/plugin-counters.c +++ b/plugin-counters.c @@ -126,6 +126,7 @@ static const response* block(const char* bytes, unsigned long len) } struct plugin plugin = { + .version = PLUGIN_VERSION, .init = init, .reset = reset, .sender = sender, diff --git a/plugin-cvm-validate.c b/plugin-cvm-validate.c index 8bb178b..764efc1 100644 --- a/plugin-cvm-validate.c +++ b/plugin-cvm-validate.c @@ -53,6 +53,7 @@ static const response* validate_recipient(str* recipient) } struct plugin plugin = { + .version = PLUGIN_VERSION, .init = validate_init, .recipient = validate_recipient, }; diff --git a/plugin-mailrules.c b/plugin-mailrules.c index b3c0435..f214cad 100644 --- a/plugin-mailrules.c +++ b/plugin-mailrules.c @@ -426,6 +426,7 @@ static const response* validate_recipient(str* recipient) } struct plugin plugin = { + .version = PLUGIN_VERSION, .init = init, .reset = reset, .sender = validate_sender, diff --git a/plugin-patterns.c b/plugin-patterns.c index 368e94f..a2d1b8d 100644 --- a/plugin-patterns.c +++ b/plugin-patterns.c @@ -149,6 +149,7 @@ static const response* check(const char* bytes, unsigned long len) } struct plugin plugin = { + .version = PLUGIN_VERSION, .data_start = init, .data_block = check, }; diff --git a/plugin-qmail-validate.c b/plugin-qmail-validate.c index 241dbfb..e94a351 100644 --- a/plugin-qmail-validate.c +++ b/plugin-qmail-validate.c @@ -87,6 +87,7 @@ static const response* validate_recipient(str* recipient) } struct plugin plugin = { + .version = PLUGIN_VERSION, .init = validate_init, .sender = validate_sender, .recipient = validate_recipient, diff --git a/plugin-reject.c b/plugin-reject.c index bde563e..d269b37 100644 --- a/plugin-reject.c +++ b/plugin-reject.c @@ -24,5 +24,6 @@ static const response* sender(str* s) } struct plugin plugin = { + .version = PLUGIN_VERSION, .sender = sender, }; diff --git a/plugin-relayclient.c b/plugin-relayclient.c index c9f7fb1..ccec5d1 100644 --- a/plugin-relayclient.c +++ b/plugin-relayclient.c @@ -16,5 +16,6 @@ static const response* do_recipient(str* recipient) } struct plugin plugin = { + .version = PLUGIN_VERSION, .recipient = do_recipient, }; diff --git a/plugin-require-auth.c b/plugin-require-auth.c index f97e700..4f2fc5e 100644 --- a/plugin-require-auth.c +++ b/plugin-require-auth.c @@ -12,5 +12,6 @@ static const response* sender(str* s) } struct plugin plugin = { + .version = PLUGIN_VERSION, .sender = sender, }; diff --git a/plugin.c b/plugin.c index f9b0805..05ded4b 100644 --- a/plugin.c +++ b/plugin.c @@ -40,6 +40,7 @@ static const response* message_end(int fd) } struct plugin plugin = { + .version = PLUGIN_VERSION, .flags = 0, .init = init, .helo = helo, diff --git a/protocol-qmqp.c b/protocol-qmqp.c index 7d019a4..03f0f71 100644 --- a/protocol-qmqp.c +++ b/protocol-qmqp.c @@ -103,6 +103,7 @@ static int mainloop(void) } struct protocol protocol = { + .version = PROTOCOL_VERSION, .name = "QMQP", .respond_line = qmtp_respond_line, .mainloop = mainloop, diff --git a/protocol-qmtp.c b/protocol-qmtp.c index 511ef2d..f59bfee 100644 --- a/protocol-qmtp.c +++ b/protocol-qmtp.c @@ -108,6 +108,7 @@ static int mainloop(void) } struct protocol protocol = { + .version = PROTOCOL_VERSION, .name = "QMTP", .respond_line = qmtp_respond_line, .mainloop = mainloop, diff --git a/protocol-smtp.c b/protocol-smtp.c index ec2b2ff..eaa9b89 100644 --- a/protocol-smtp.c +++ b/protocol-smtp.c @@ -407,6 +407,7 @@ static int smtp_respond_line(unsigned num, int final, } struct protocol protocol = { + .version = PROTOCOL_VERSION, .name = "SMTP", .respond_line = smtp_respond_line, .init = init,