]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
submission: Move relay part of HELO/EHLO command to submission-backend-relay.c.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 15 Jul 2018 16:54:00 +0000 (18:54 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 12 Feb 2019 13:40:41 +0000 (15:40 +0200)
src/submission/Makefile.am
src/submission/cmd-helo.c [deleted file]
src/submission/submission-backend-relay.c
src/submission/submission-backend-relay.h [new file with mode: 0644]
src/submission/submission-commands.c
src/submission/submission-commands.h

index 69ce63ebed6875330095e6525db0cc2f379ed66a..026320011404bb24a22ae89cb5df7a0691498b9f 100644 (file)
@@ -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 (file)
index 26a8ce9..0000000
+++ /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;
-}
-
index 71f8dc302be764481cc05e005118fdb8bbb61e7d..cf4b2cee668ab3f12971d171ca1f51d6afa4a9f2 100644 (file)
@@ -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 (file)
index 0000000..560ab85
--- /dev/null
@@ -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
index 1e021da5ea214e9b6df72587c7f91e1e6e92cce9..9d1823064da29e590bfb6726f651d7f3122f4a17 100644 (file)
@@ -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;
 }
-
index cd8190662ae22290b6fd3f257ec4f7dfda1e17ce..4d6e4fae0a116fd913d001efb771792c255257de 100644 (file)
@@ -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,