From: Stephan Bosch Date: Sun, 15 Jul 2018 16:54:00 +0000 (+0200) Subject: submission: Move relay part of HELO/EHLO command to submission-backend-relay.c. X-Git-Tag: 2.3.5~255 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=baa1ecb27e31864ddfd1b3572d9a7b7c7208431b;p=thirdparty%2Fdovecot%2Fcore.git submission: Move relay part of HELO/EHLO command to submission-backend-relay.c. --- diff --git a/src/submission/Makefile.am b/src/submission/Makefile.am index 69ce63ebed..0263200114 100644 --- a/src/submission/Makefile.am +++ b/src/submission/Makefile.am @@ -34,7 +34,6 @@ submission_DEPENDENCIES = \ $(LIBDOVECOT_DEPS) cmds = \ - cmd-helo.c \ cmd-mail.c \ cmd-rcpt.c \ cmd-data.c \ @@ -53,6 +52,7 @@ submission_SOURCES = \ noinst_HEADERS = \ submission-common.h \ + submission-backend-relay.h \ submission-commands.h \ submission-client.h \ submission-settings.h diff --git a/src/submission/cmd-helo.c b/src/submission/cmd-helo.c deleted file mode 100644 index 26a8ce9f25..0000000000 --- a/src/submission/cmd-helo.c +++ /dev/null @@ -1,108 +0,0 @@ -/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ - -#include "submission-common.h" -#include "str.h" -#include "ostream.h" -#include "smtp-client.h" -#include "smtp-client-connection.h" - -#include "submission-commands.h" - -/* - * EHLO, HELO commands - */ - -struct cmd_helo_context { - struct client *client; - struct smtp_server_cmd_ctx *cmd; - struct smtp_server_cmd_helo *data; - - struct smtp_client_command *cmd_proxied; -}; - -static void cmd_helo_update_xclient(struct client *client, - struct smtp_server_cmd_helo *data) -{ - struct smtp_proxy_data proxy_data; - - if (!client->set->submission_relay_trusted) - return; - - i_zero(&proxy_data); - proxy_data.helo = data->helo.domain; - proxy_data.proto = (data->helo.old_smtp ? - SMTP_PROXY_PROTOCOL_SMTP : SMTP_PROXY_PROTOCOL_ESMTP); - - (void)smtp_client_connection_send_xclient - (client->proxy_conn, &proxy_data); - client->xclient_sent = TRUE; -} - -static void -cmd_helo_reply(struct smtp_server_cmd_ctx *cmd, struct cmd_helo_context *helo) -{ - struct client *client = helo->client; - - /* proxy an XCLIENT command */ - if (helo->data->changed) - cmd_helo_update_xclient(client, helo->data); - - T_BEGIN { - submission_helo_reply_submit(cmd, helo->data); - } T_END; -} - -static void cmd_helo_proxy_cb(const struct smtp_reply *proxy_reply, - struct cmd_helo_context *helo) -{ - struct smtp_server_cmd_ctx *cmd = helo->cmd; - struct client *client = helo->client; - struct smtp_reply reply; - - if (!client_command_handle_proxy_reply(client, proxy_reply, &reply)) - return; - - if ((proxy_reply->status / 100) == 2) { - cmd_helo_reply(cmd, helo); - } else { - /* RFC 2034, Section 4: - - These codes must appear in all 2xx, 4xx, and 5xx response - lines other than initial greeting and any response to HELO - or EHLO. - */ - reply.enhanced_code = SMTP_REPLY_ENH_CODE_NONE; - smtp_server_reply_forward(cmd, &reply); - } -} - -static void -cmd_helo_start(struct smtp_server_cmd_ctx *cmd ATTR_UNUSED, - struct cmd_helo_context *helo) -{ - struct client *client = helo->client; - - /* proxy an XCLIENT command */ - if (helo->data->changed) - cmd_helo_update_xclient(client, helo->data); -} - -int cmd_helo_relay(struct client *client, struct smtp_server_cmd_ctx *cmd, - struct smtp_server_cmd_helo *data) -{ - struct cmd_helo_context *helo; - - helo = p_new(cmd->pool, struct cmd_helo_context, 1); - helo->client = client; - helo->cmd = cmd; - helo->data = data; - - /* this is not the first HELO/EHLO; just proxy a RSET command */ - smtp_server_command_add_hook( - cmd->cmd, SMTP_SERVER_COMMAND_HOOK_NEXT, - cmd_helo_start, helo); - helo->cmd_proxied = smtp_client_command_rset_submit - (client->proxy_conn, 0, cmd_helo_proxy_cb, helo); - return 0; -} - diff --git a/src/submission/submission-backend-relay.c b/src/submission/submission-backend-relay.c index 71f8dc302b..cf4b2cee66 100644 --- a/src/submission/submission-backend-relay.c +++ b/src/submission/submission-backend-relay.c @@ -1,11 +1,13 @@ /* Copyright (c) 2018 Dovecot authors, see the included COPYING file */ #include "submission-common.h" +#include "str.h" #include "smtp-client.h" #include "smtp-client-connection.h" #include "smtp-client-command.h" #include "submission-commands.h" +#include "submission-backend-relay.h" /* * Common @@ -66,3 +68,101 @@ bool client_command_handle_proxy_reply(struct client *client, } return TRUE; } + +/* + * EHLO, HELO commands + */ + +struct cmd_helo_context { + struct client *client; + struct smtp_server_cmd_ctx *cmd; + struct smtp_server_cmd_helo *data; + + struct smtp_client_command *cmd_proxied; +}; + +static void cmd_helo_update_xclient(struct client *client, + struct smtp_server_cmd_helo *data) +{ + struct smtp_proxy_data proxy_data; + + if (!client->set->submission_relay_trusted) + return; + + i_zero(&proxy_data); + proxy_data.helo = data->helo.domain; + proxy_data.proto = (data->helo.old_smtp ? + SMTP_PROXY_PROTOCOL_SMTP : SMTP_PROXY_PROTOCOL_ESMTP); + + (void)smtp_client_connection_send_xclient + (client->proxy_conn, &proxy_data); + client->xclient_sent = TRUE; +} + +static void +cmd_helo_reply(struct smtp_server_cmd_ctx *cmd, struct cmd_helo_context *helo) +{ + struct client *client = helo->client; + + /* proxy an XCLIENT command */ + if (helo->data->changed) + cmd_helo_update_xclient(client, helo->data); + + T_BEGIN { + submission_helo_reply_submit(cmd, helo->data); + } T_END; +} + +static void cmd_helo_proxy_cb(const struct smtp_reply *proxy_reply, + struct cmd_helo_context *helo) +{ + struct smtp_server_cmd_ctx *cmd = helo->cmd; + struct client *client = helo->client; + struct smtp_reply reply; + + if (!client_command_handle_proxy_reply(client, proxy_reply, &reply)) + return; + + if ((proxy_reply->status / 100) == 2) { + cmd_helo_reply(cmd, helo); + } else { + /* RFC 2034, Section 4: + + These codes must appear in all 2xx, 4xx, and 5xx response + lines other than initial greeting and any response to HELO + or EHLO. + */ + reply.enhanced_code = SMTP_REPLY_ENH_CODE_NONE; + smtp_server_reply_forward(cmd, &reply); + } +} + +static void +cmd_helo_start(struct smtp_server_cmd_ctx *cmd ATTR_UNUSED, + struct cmd_helo_context *helo) +{ + struct client *client = helo->client; + + /* proxy an XCLIENT command */ + if (helo->data->changed) + cmd_helo_update_xclient(client, helo->data); +} + +int cmd_helo_relay(struct client *client, struct smtp_server_cmd_ctx *cmd, + struct smtp_server_cmd_helo *data) +{ + struct cmd_helo_context *helo; + + helo = p_new(cmd->pool, struct cmd_helo_context, 1); + helo->client = client; + helo->cmd = cmd; + helo->data = data; + + /* this is not the first HELO/EHLO; just proxy a RSET command */ + smtp_server_command_add_hook( + cmd->cmd, SMTP_SERVER_COMMAND_HOOK_NEXT, + cmd_helo_start, helo); + helo->cmd_proxied = smtp_client_command_rset_submit + (client->proxy_conn, 0, cmd_helo_proxy_cb, helo); + return 0; +} diff --git a/src/submission/submission-backend-relay.h b/src/submission/submission-backend-relay.h new file mode 100644 index 0000000000..560ab857a3 --- /dev/null +++ b/src/submission/submission-backend-relay.h @@ -0,0 +1,7 @@ +#ifndef SUBMISSION_BACKEND_RELAY_H +#define SUBMISSION_BACKEND_RELAY_H + +int cmd_helo_relay(struct client *client, struct smtp_server_cmd_ctx *cmd, + struct smtp_server_cmd_helo *data); + +#endif diff --git a/src/submission/submission-commands.c b/src/submission/submission-commands.c index 1e021da5ea..9d1823064d 100644 --- a/src/submission/submission-commands.c +++ b/src/submission/submission-commands.c @@ -6,6 +6,7 @@ #include "smtp-client-connection.h" #include "submission-commands.h" +#include "submission-backend-relay.h" /* * EHLO, HELO commands @@ -67,10 +68,6 @@ void submission_helo_reply_submit(struct smtp_server_cmd_ctx *cmd, smtp_server_reply_submit(reply); } -/* - * EHLO, HELO commands - */ - int cmd_helo(void *conn_ctx, struct smtp_server_cmd_ctx *cmd, struct smtp_server_cmd_helo *data) { @@ -85,4 +82,3 @@ int cmd_helo(void *conn_ctx, struct smtp_server_cmd_ctx *cmd, submission_helo_reply_submit(cmd, data); return 1; } - diff --git a/src/submission/submission-commands.h b/src/submission/submission-commands.h index cd8190662a..4d6e4fae0a 100644 --- a/src/submission/submission-commands.h +++ b/src/submission/submission-commands.h @@ -4,8 +4,6 @@ bool client_command_handle_proxy_reply(struct client *client, const struct smtp_reply *reply, struct smtp_reply *reply_r); -int cmd_helo_relay(struct client *client, struct smtp_server_cmd_ctx *cmd, - struct smtp_server_cmd_helo *data); int cmd_mail_relay(struct client *client, struct smtp_server_cmd_ctx *cmd, struct smtp_server_cmd_mail *data); int cmd_rcpt_relay(struct client *client, struct smtp_server_cmd_ctx *cmd,