From d665228eb2739e604a9058df1ef605a898c6d4f9 Mon Sep 17 00:00:00 2001 From: Bruce Guenter Date: Sun, 3 Jul 2011 14:05:21 -0600 Subject: [PATCH] Pass sender/recip parameters into plugins (unused) --- NEWS | 3 +++ backend-echo.c | 6 ++++-- backend-qmail.c | 6 ++++-- builtins.c | 12 ++++++++---- mailfront.c | 22 ++++++++++++++++------ mailfront.h | 8 ++++---- plugin-api.html | 21 +++++++++++++-------- plugin-check-fqdn.c | 6 ++++-- plugin-counters.c | 6 ++++-- plugin-cvm-validate.c | 3 ++- plugin-lua.c | 12 ++++++++---- plugin-mailrules.c | 6 ++++-- plugin-qmail-validate.c | 6 ++++-- plugin-template.c | 4 ++-- protocol-qmqp.c | 4 ++-- protocol-qmtp.c | 4 ++-- protocol-smtp.c | 8 +++----- 17 files changed, 87 insertions(+), 50 deletions(-) diff --git a/NEWS b/NEWS index 11e621e..4ff2e54 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,9 @@ Changes in version 2.00 - Capabilities reported by the SMTP EHLO response can be added by plugins. + - Plugins are passed any SMTP parameters given with the sender and + recipient commands. + Plugins compiled for previous versions of mailfront will not work without recompiling. diff --git a/backend-echo.c b/backend-echo.c index c91c58d..39461c2 100644 --- a/backend-echo.c +++ b/backend-echo.c @@ -15,22 +15,24 @@ static const response* reset(void) return 0; } -static const response* sender(str* s) +static const response* sender(str* s, str* params) { str_copys(&tmp, "Sender='"); str_cat(&tmp, s); str_cats(&tmp, "'."); resp.message = tmp.s; return &resp; + (void)params; } -static const response* recipient(str* r) +static const response* recipient(str* r, str* params) { str_copys(&tmp, "Recipient='"); str_cat(&tmp, r); str_cats(&tmp, "'."); resp.message = tmp.s; return &resp; + (void)params; } static const response* data_block(const char* bytes, unsigned long len) diff --git a/backend-qmail.c b/backend-qmail.c index 8f51352..daacc1f 100644 --- a/backend-qmail.c +++ b/backend-qmail.c @@ -40,20 +40,22 @@ static const response* reset(void) return 0; } -static const response* do_sender(str* sender) +static const response* do_sender(str* sender, str* params) { if (!str_catc(&buffer, 'F') || !str_cat(&buffer, sender) || !str_catc(&buffer, 0)) return &resp_oom; return 0; + (void)params; } -static const response* do_recipient(str* recipient) +static const response* do_recipient(str* recipient, str* params) { if (!str_catc(&buffer, 'T') || !str_cat(&buffer, recipient) || !str_catc(&buffer, 0)) return &resp_oom; return 0; + (void)params; } static const response *start_qq(int msgfd, int envfd) diff --git a/builtins.c b/builtins.c index 085ae3e..27093fe 100644 --- a/builtins.c +++ b/builtins.c @@ -6,13 +6,14 @@ static RESPONSE(ok, 250, 0); static RESPONSE(mustauth, 530, "5.7.1 You must authenticate first."); static response resp; -static const response* accept(str* s) +static const response* accept(str* s, str* params) { return &resp_accept; (void)s; + (void)params; } -static const response* reject(str* s) +static const response* reject(str* s, str* params) { const char* sr; if ((sr = session_getenv("SMTPREJECT")) != 0 @@ -30,9 +31,10 @@ static const response* reject(str* s) } return 0; (void)s; + (void)params; } -static const response* relayclient_recip(str* recipient) +static const response* relayclient_recip(str* recipient, str* params) { const char* relayclient = session_getenv("RELAYCLIENT"); if (relayclient != 0) { @@ -42,15 +44,17 @@ static const response* relayclient_recip(str* recipient) else if (session_getnum("authenticated", 0)) return &resp_ok; return 0; + (void)params; } -static const response* require_auth(str* s) +static const response* require_auth(str* s, str* params) { if (!session_getnum("authenticated", 0) && session_getenv("RELAYCLIENT") == 0) return &resp_mustauth; return 0; (void)s; + (void)params; } struct plugin builtin_plugins[] = { diff --git a/mailfront.c b/mailfront.c index 6d843a1..9d7ef9b 100644 --- a/mailfront.c +++ b/mailfront.c @@ -23,6 +23,8 @@ extern void report_io_bytes(void); static str tmp_prefix; +static str no_params; + #define MODULE_CALL(NAME,PARAMS,SHORT,RESET) do{ \ struct plugin* plugin; \ const response* tmp; \ @@ -80,29 +82,37 @@ const response* handle_reset(void) return resp; } -const response* handle_sender(str* sender) +const response* handle_sender(str* sender, str* params) { const response* resp = 0; const response* tmpresp = 0; - MODULE_CALL(sender, (sender), 1, 0); + if (params == 0) { + no_params.len = 0; + params = &no_params; + } + MODULE_CALL(sender, (sender, params), 1, 0); if (resp == 0) return &resp_no_sender; if (session.backend->sender != 0) - if (!response_ok(tmpresp = session.backend->sender(sender))) + if (!response_ok(tmpresp = session.backend->sender(sender, params))) return tmpresp; if (resp == 0 || resp->message == 0) resp = tmpresp; return resp; } -const response* handle_recipient(str* recip) +const response* handle_recipient(str* recip, str* params) { const response* resp = 0; const response* hresp = 0; - MODULE_CALL(recipient, (recip), 1, 0); + if (params == 0) { + no_params.len = 0; + params = &no_params; + } + MODULE_CALL(recipient, (recip, params), 1, 0); if (resp == 0) return &resp_no_rcpt; if (session.backend->recipient != 0) - if (!response_ok(hresp = session.backend->recipient(recip))) + if (!response_ok(hresp = session.backend->recipient(recip, params))) return hresp; if (resp == 0 || resp->message == 0) resp = hresp; return resp; diff --git a/mailfront.h b/mailfront.h index 9926604..c0259c9 100644 --- a/mailfront.h +++ b/mailfront.h @@ -19,8 +19,8 @@ struct plugin const response* (*init)(void); const response* (*helo)(str* hostname, str* capabilities); const response* (*reset)(void); - const response* (*sender)(str*); - const response* (*recipient)(str*); + const response* (*sender)(str* address, str* params); + const response* (*recipient)(str* address, str* params); const response* (*data_start)(int fd); const response* (*data_block)(const char* bytes, unsigned long len); const response* (*message_end)(int fd); @@ -45,8 +45,8 @@ extern const char* getprotoenv(const char*); extern const char UNKNOWN[]; extern const response* handle_helo(str* host, str* capabilities); extern const response* handle_reset(void); -extern const response* handle_sender(str* sender); -extern const response* handle_recipient(str* recip); +extern const response* handle_sender(str* sender, str* params); +extern const response* handle_recipient(str* recip, str* params); extern const response* handle_data_start(void); extern void handle_data_bytes(const char* bytes, unsigned len); extern const response* handle_message_end(void); diff --git a/plugin-api.html b/plugin-api.html index 63ae4e5..3d6755c 100644 --- a/plugin-api.html +++ b/plugin-api.html @@ -103,6 +103,11 @@

Hook Functions

str documentation module for functions to use in manipulating these objects.

+

Sender and recipient SMTP parameters are passed as a str* +containing a NUL delimited list of KEYWORD=VALUE pairs. If the +parameter keyword was not followed by a value in the SMTP conversation, +the =VALUE portion will not be present in the string. +

Be aware that the sender and recipient hooks may be called before the message data is handled (as with the SMTP protocol) or after (as with the QMQP and QMTP protocol). In either case, the @@ -128,15 +133,15 @@

Hook Functions

The capabilities variable contains a list of SMTP EHLO response capabilities, each followed by a newline. -
const response* sender(str* address)
This hook is -called after a sender email address is transmitted by the client, and is -called exactly once per message. This chain short-circuits on non-error -response.
+
const response* sender(str* address, str* params)
+
This hook is called after a sender email address is transmitted by +the client, and is called exactly once per message. This chain +short-circuits on non-error response.
-
const response* recipient(str* address)
This hook -is called after a sender email address is transmitted by the client, and -may be called zero or more times per message. This chain short-circuits -on non-error responses.
+
const response* recipient(str* address, str* params)
+
This hook is called after a sender email address is transmitted by +the client, and may be called zero or more times per message. This +chain short-circuits on non-error responses.
const response* data_start(int fd)
This hook is called when the sender starts transmitting the message data. Note that diff --git a/plugin-check-fqdn.c b/plugin-check-fqdn.c index 2d3dc7a..efe2fde 100644 --- a/plugin-check-fqdn.c +++ b/plugin-check-fqdn.c @@ -68,7 +68,7 @@ static const response* check_domains(const str* s, const char* domains) } } -static const response* sender(str* s) +static const response* sender(str* s, str* params) { const response* r; const char* domains; @@ -80,13 +80,15 @@ static const response* sender(str* s) if ((domains = session_getenv("SENDER_DOMAINS")) != 0) return check_domains(s, domains); return 0; + (void)params; } -static const response* recipient(str* s) +static const response* recipient(str* s, str* params) { if (s->len == 0) return &resp_notemptyrcpt; return check_fqdn(s); + (void)params; } struct plugin plugin = { diff --git a/plugin-counters.c b/plugin-counters.c index 60c30c4..f841a33 100644 --- a/plugin-counters.c +++ b/plugin-counters.c @@ -51,7 +51,7 @@ static const response* reset(void) return 0; } -static const response* sender(str* r) +static const response* sender(str* r, str* params) { /* This MUST be done as a sender match to make sure SMTP "MAIL FROM" * commands with a SIZE parameter can be rejected properly. */ @@ -59,9 +59,10 @@ static const response* sender(str* r) minenv("maxrcpts", "MAXRCPTS"); (void)r; return 0; + (void)params; } -static const response* recipient(str* r) +static const response* recipient(str* r, str* params) { unsigned long maxrcpts = minenv("maxrcpts", "MAXRCPTS"); minenv("maxdatabytes", "DATABYTES"); @@ -70,6 +71,7 @@ static const response* recipient(str* r) return &resp_manyrcpt; return 0; (void)r; + (void)params; } static const response* start(int fd) diff --git a/plugin-cvm-validate.c b/plugin-cvm-validate.c index e974646..58bd63c 100644 --- a/plugin-cvm-validate.c +++ b/plugin-cvm-validate.c @@ -38,7 +38,7 @@ static const response* validate_init(void) return 0; } -static const response* validate_recipient(str* recipient) +static const response* validate_recipient(str* recipient, str* params) { struct cvm_credential creds[3]; unsigned i; @@ -70,6 +70,7 @@ static const response* validate_recipient(str* recipient) str_free(&creds[1].value); str_free(&creds[2].value); return r; + (void)params; } struct plugin plugin = { diff --git a/plugin-lua.c b/plugin-lua.c index c9f58e5..e4e4787 100644 --- a/plugin-lua.c +++ b/plugin-lua.c @@ -235,22 +235,26 @@ static const response* helo(str* hostname, str* capabilities) return 0; } -static const response* sender(str* address) +static const response* sender(str* address, str* params) { if (setup("sender")) { lua_pushlstring(L, address->s, address->len); - return callit(1); + lua_pushlstring(L, params->s, params->len); + return callit(2); } return 0; + (void)params; } -static const response* recipient(str* address) +static const response* recipient(str* address, str* params) { if (setup("recipient")) { lua_pushlstring(L, address->s, address->len); - return callit(1); + lua_pushlstring(L, params->s, params->len); + return callit(2); } return 0; + (void)params; } static const response* data_start(int fd) diff --git a/plugin-mailrules.c b/plugin-mailrules.c index a1a5fb9..30e9cde 100644 --- a/plugin-mailrules.c +++ b/plugin-mailrules.c @@ -393,7 +393,7 @@ static void copy_addr(const str* addr, static str saved_sender; static str sender_domain; -static const response* validate_sender(str* sender) +static const response* validate_sender(str* sender, str* params) { struct rule* rule; const response* r; @@ -407,12 +407,13 @@ static const response* validate_sender(str* sender) return r; } return 0; + (void)params; } static str laddr; static str rdomain; -static const response* validate_recipient(str* recipient) +static const response* validate_recipient(str* recipient, str* params) { struct rule* rule; const response* r; @@ -428,6 +429,7 @@ static const response* validate_recipient(str* recipient) return r; } return 0; + (void)params; } struct plugin plugin = { diff --git a/plugin-qmail-validate.c b/plugin-qmail-validate.c index e94a351..99dfdb3 100644 --- a/plugin-qmail-validate.c +++ b/plugin-qmail-validate.c @@ -42,7 +42,7 @@ static const response* validate_init(void) return 0; } -static const response* validate_sender(str* sender) +static const response* validate_sender(str* sender, str* params) { int at; str_copy(&tmp, sender); @@ -54,9 +54,10 @@ static const response* validate_sender(str* sender) if (dict_get(&bmf, &tmp)) return &resp_badmailfrom; } return 0; + (void)params; } -static const response* validate_recipient(str* recipient) +static const response* validate_recipient(str* recipient, str* params) { int at; @@ -84,6 +85,7 @@ static const response* validate_recipient(str* recipient) } } return 0; + (void)params; } struct plugin plugin = { diff --git a/plugin-template.c b/plugin-template.c index 779d614..f27da09 100644 --- a/plugin-template.c +++ b/plugin-template.c @@ -27,7 +27,7 @@ static const response* reset(void) /* The sender function is called exactly once per message. The parameter * is the sender email addres, and may be modified. */ -static const response* sender(str* address) +static const response* sender(str* address, str* params) { return 0; } @@ -35,7 +35,7 @@ static const response* sender(str* address) /* The recipient function is called one or more times per message, once * for each recipient. The parameter is the recipient email address, * and may be modified. */ -static const response* recipient(str* address) +static const response* recipient(str* address, str* params) { return 0; } diff --git a/protocol-qmqp.c b/protocol-qmqp.c index 03f0f71..2aa7731 100644 --- a/protocol-qmqp.c +++ b/protocol-qmqp.c @@ -63,7 +63,7 @@ static void get_sender(ibuf* in) } msg3("sender <", line.s, ">"); if (response_ok(resp)) - resp = handle_sender(&line); + resp = handle_sender(&line, 0); } static void get_recips(ibuf* in) @@ -77,7 +77,7 @@ static void get_recips(ibuf* in) } msg3("recipient <", line.s, ">"); if (response_ok(resp)) - resp = handle_recipient(&line); + resp = handle_recipient(&line, 0); } die("EOF before end of recipient list"); } diff --git a/protocol-qmtp.c b/protocol-qmtp.c index 40d1d1e..c8300e5 100644 --- a/protocol-qmtp.c +++ b/protocol-qmtp.c @@ -58,7 +58,7 @@ static void get_sender(ibuf* in) } msg3("sender <", line.s, ">"); if (response_ok(resp)) - resp = handle_sender(&line); + resp = handle_sender(&line, 0); } static void get_recips(ibuf* in) @@ -83,7 +83,7 @@ static void get_recips(ibuf* in) str_copyb(&tmp, line.s+j, len); msg3("recipient <", tmp.s, ">"); if (response_ok(resp)) - resp = handle_recipient(&tmp); + resp = handle_recipient(&tmp, 0); i = j + len; } } diff --git a/protocol-smtp.c b/protocol-smtp.c index a206adc..0ca7439 100644 --- a/protocol-smtp.c +++ b/protocol-smtp.c @@ -97,9 +97,7 @@ static const char* find_param(const char* name) { const long len = strlen(name); striter i; - for (striter_start(&i, ¶ms, 0); - striter_valid(&i); - striter_advance(&i)) { + striter_loop(&i, ¶ms, 0) { if (strncasecmp(i.startptr, name, len) == 0) { if (i.startptr[len] == '0') return i.startptr + len; @@ -169,7 +167,7 @@ static int MAIL(void) msg2("MAIL ", arg.s); do_reset(); parse_addr_arg(); - if ((resp = handle_sender(&addr)) == 0) + if ((resp = handle_sender(&addr, ¶ms)) == 0) resp = &resp_mail_ok; if (number_ok(resp)) { /* Look up the size limit after handling the sender, @@ -191,7 +189,7 @@ static int RCPT(void) msg2("RCPT ", arg.s); if (!saw_mail) return respond(&resp_no_mail); parse_addr_arg(); - if ((resp = handle_recipient(&addr)) == 0) + if ((resp = handle_recipient(&addr, ¶ms)) == 0) resp = &resp_rcpt_ok; if (number_ok(resp)) saw_rcpt = 1; return respond(resp);