From 56b9a1e36593618fc26f331e09e56b413d53510b Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Wed, 29 Aug 2018 22:45:00 +0200 Subject: [PATCH] submission: Move relay part of RCPT command to submission-backend-relay.c. --- src/submission/Makefile.am | 1 - src/submission/cmd-rcpt.c | 76 ----------------------- src/submission/submission-backend-relay.c | 65 +++++++++++++++++++ src/submission/submission-backend-relay.h | 2 + src/submission/submission-commands.h | 2 - 5 files changed, 67 insertions(+), 79 deletions(-) delete mode 100644 src/submission/cmd-rcpt.c diff --git a/src/submission/Makefile.am b/src/submission/Makefile.am index 005da97865..e397c18db9 100644 --- a/src/submission/Makefile.am +++ b/src/submission/Makefile.am @@ -34,7 +34,6 @@ submission_DEPENDENCIES = \ $(LIBDOVECOT_DEPS) cmds = \ - cmd-rcpt.c \ cmd-data.c \ cmd-rset.c \ cmd-noop.c \ diff --git a/src/submission/cmd-rcpt.c b/src/submission/cmd-rcpt.c deleted file mode 100644 index fb1d679794..0000000000 --- a/src/submission/cmd-rcpt.c +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ - -#include "submission-common.h" -#include "str.h" -#include "array.h" -#include "smtp-parser.h" -#include "smtp-address.h" -#include "smtp-syntax.h" -#include "smtp-client.h" -#include "smtp-client-connection.h" - -#include "submission-commands.h" - -/* - * RCPT command - */ - -struct cmd_rcpt_context { - struct client *client; - struct smtp_server_cmd_ctx *cmd; - struct smtp_server_cmd_rcpt *data; - - struct smtp_client_command *cmd_proxied; -}; - -static void -cmd_rcpt_replied(struct smtp_server_cmd_ctx *cmd ATTR_UNUSED, - struct cmd_rcpt_context *rcpt_cmd) -{ - if (rcpt_cmd->cmd_proxied != NULL) - smtp_client_command_abort(&rcpt_cmd->cmd_proxied); -} - -static void cmd_rcpt_proxy_cb(const struct smtp_reply *proxy_reply, - struct cmd_rcpt_context *rcpt_cmd) -{ - struct smtp_server_cmd_ctx *cmd = rcpt_cmd->cmd; - struct client *client = rcpt_cmd->client; - struct smtp_reply reply; - - /* finished proxying MAIL command to relay server */ - i_assert(rcpt_cmd != NULL); - rcpt_cmd->cmd_proxied = NULL; - - if (!client_command_handle_proxy_reply(client, proxy_reply, &reply)) - return; - - if ((proxy_reply->status / 100) == 2) { - /* the default 2.0.0 code won't do */ - if (!smtp_reply_has_enhanced_code(proxy_reply)) - reply.enhanced_code = SMTP_REPLY_ENH_CODE(2, 1, 5); - } - - /* forward reply */ - smtp_server_reply_forward(cmd, &reply); -} - -int cmd_rcpt_relay(struct client *client, struct smtp_server_cmd_ctx *cmd, - struct smtp_server_cmd_rcpt *data) -{ - struct cmd_rcpt_context *rcpt_cmd; - - /* queue command (pipeline) */ - rcpt_cmd = p_new(cmd->pool, struct cmd_rcpt_context, 1); - rcpt_cmd->cmd = cmd; - rcpt_cmd->data = data; - rcpt_cmd->client = client; - - smtp_server_command_add_hook(cmd->cmd, SMTP_SERVER_COMMAND_HOOK_REPLIED, - cmd_rcpt_replied, rcpt_cmd); - - rcpt_cmd->cmd_proxied = smtp_client_command_rcpt_submit( - client->proxy_conn, 0, data->path, &data->params, - cmd_rcpt_proxy_cb, rcpt_cmd); - return 0; -} diff --git a/src/submission/submission-backend-relay.c b/src/submission/submission-backend-relay.c index 13613b5cf6..300323ca4f 100644 --- a/src/submission/submission-backend-relay.c +++ b/src/submission/submission-backend-relay.c @@ -316,3 +316,68 @@ int cmd_mail_relay(struct client *client, struct smtp_server_cmd_ctx *cmd, cmd_mail_proxy_cb, mail_cmd); return 0; } + +/* + * RCPT command + */ + +struct cmd_rcpt_context { + struct client *client; + struct smtp_server_cmd_ctx *cmd; + struct smtp_server_cmd_rcpt *data; + + struct smtp_client_command *cmd_proxied; +}; + +static void +cmd_rcpt_replied(struct smtp_server_cmd_ctx *cmd ATTR_UNUSED, + struct cmd_rcpt_context *rcpt_cmd) +{ + if (rcpt_cmd->cmd_proxied != NULL) + smtp_client_command_abort(&rcpt_cmd->cmd_proxied); +} + +static void cmd_rcpt_proxy_cb(const struct smtp_reply *proxy_reply, + struct cmd_rcpt_context *rcpt_cmd) +{ + struct smtp_server_cmd_ctx *cmd = rcpt_cmd->cmd; + struct client *client = rcpt_cmd->client; + struct smtp_reply reply; + + /* finished proxying MAIL command to relay server */ + i_assert(rcpt_cmd != NULL); + rcpt_cmd->cmd_proxied = NULL; + + if (!client_command_handle_proxy_reply(client, proxy_reply, &reply)) + return; + + if ((proxy_reply->status / 100) == 2) { + /* the default 2.0.0 code won't do */ + if (!smtp_reply_has_enhanced_code(proxy_reply)) + reply.enhanced_code = SMTP_REPLY_ENH_CODE(2, 1, 5); + } + + /* forward reply */ + smtp_server_reply_forward(cmd, &reply); +} + +int cmd_rcpt_relay(struct client *client, struct smtp_server_cmd_ctx *cmd, + struct smtp_server_cmd_rcpt *data) +{ + struct cmd_rcpt_context *rcpt_cmd; + + /* queue command (pipeline) */ + rcpt_cmd = p_new(cmd->pool, struct cmd_rcpt_context, 1); + rcpt_cmd->cmd = cmd; + rcpt_cmd->data = data; + rcpt_cmd->client = client; + + smtp_server_command_add_hook(cmd->cmd, SMTP_SERVER_COMMAND_HOOK_REPLIED, + cmd_rcpt_replied, rcpt_cmd); + + rcpt_cmd->cmd_proxied = smtp_client_command_rcpt_submit( + client->proxy_conn, 0, data->path, &data->params, + cmd_rcpt_proxy_cb, rcpt_cmd); + return 0; +} + diff --git a/src/submission/submission-backend-relay.h b/src/submission/submission-backend-relay.h index a6fbd6cbc5..d97497f16d 100644 --- a/src/submission/submission-backend-relay.h +++ b/src/submission/submission-backend-relay.h @@ -5,5 +5,7 @@ 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, + struct smtp_server_cmd_rcpt *data); #endif diff --git a/src/submission/submission-commands.h b/src/submission/submission-commands.h index 81aae8a818..7a9357822c 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_rcpt_relay(struct client *client, struct smtp_server_cmd_ctx *cmd, - struct smtp_server_cmd_rcpt *data); int cmd_rset_relay(struct client *client, struct smtp_server_cmd_ctx *cmd); int cmd_data_relay(struct client *client, struct smtp_server_cmd_ctx *cmd, struct smtp_server_transaction *trans, -- 2.47.3