]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lmtp: lmtp-recipient - Put lmtp_local_rcpt() and lmtp_proxy_rcpt() parameters in...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Fri, 28 Dec 2018 22:23:13 +0000 (23:23 +0100)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 17 Jan 2022 11:52:09 +0000 (13:52 +0200)
src/lmtp/lmtp-commands.c
src/lmtp/lmtp-local.c
src/lmtp/lmtp-local.h
src/lmtp/lmtp-proxy.c
src/lmtp/lmtp-proxy.h
src/lmtp/lmtp-recipient.c
src/lmtp/lmtp-recipient.h

index dd8b791e0cbe88487c47e2513a472a04bb3a7837..9bacf28c235d325182cf6cf75f43888ac6e63939 100644 (file)
@@ -8,7 +8,6 @@
 #include "iostream-temp.h"
 #include "master-service.h"
 #include "settings-parser.h"
-#include "lda-settings.h"
 #include "mail-user.h"
 #include "smtp-address.h"
 #include "mail-deliver.h"
@@ -93,6 +92,14 @@ int cmd_rcpt(void *conn_ctx, struct smtp_server_cmd_ctx *cmd,
        struct smtp_server_transaction *trans;
        struct lmtp_recipient *lrcpt;
 
+       i_assert(!smtp_address_isnull(rcpt->path));
+       if (*rcpt->path->localpart == '\0' && rcpt->path->domain == NULL) {
+               smtp_server_recipient_reply(
+                       rcpt, 550, "5.1.1",
+                       "Unacceptable TO: Empty path not allowed");
+               return -1;
+       }
+
        trans = smtp_server_connection_get_transaction(rcpt->conn);
        i_assert(trans != NULL); /* MAIL command is synchronous */
 
@@ -108,46 +115,17 @@ int client_default_cmd_rcpt(struct client *client,
                            struct smtp_server_cmd_ctx *cmd,
                            struct lmtp_recipient *lrcpt)
 {
-       struct smtp_server_recipient *rcpt = lrcpt->rcpt;
-       const char *username, *detail;
-       char delim = '\0';
        int ret;
 
-       i_assert(!smtp_address_isnull(rcpt->path));
-       if (*rcpt->path->localpart == '\0' && rcpt->path->domain == NULL) {
-               smtp_server_recipient_reply(
-                       rcpt, 550, "5.1.1",
-                       "Unacceptable TO: Empty path not allowed");
-               return -1;
-       }
-
-       smtp_address_detail_parse_temp(
-               client->unexpanded_lda_set->recipient_delimiter,
-               rcpt->path, &username, &delim, &detail);
-       i_assert(*username != '\0');
-
-       /* Make user name and detail available in the recipient event. The
-          mail_user event (for local delivery) also adds the user field, but
-          adding it here makes it available to the recipient event in general.
-          Additionally, the auth lookups performed for local and proxy delivery
-          can further override the "user" recipient event when the auth service
-          returns a different user name. In any case, we provide the initial
-          value here.
-        */
-       event_add_str(rcpt->event, "user", username);
-       if (detail[0] != '\0')
-               event_add_str(rcpt->event, "detail", detail);
-
        if (client->lmtp_set->lmtp_proxy) {
                /* proxied? */
-               if ((ret=lmtp_proxy_rcpt(client, cmd, lrcpt,
-                                        username, detail, delim)) != 0)
+               if ((ret = lmtp_proxy_rcpt(client, cmd, lrcpt)) != 0)
                        return (ret < 0 ? -1 : 0);
                /* no */
        }
 
        /* local delivery */
-       return lmtp_local_rcpt(client, cmd, lrcpt, username, detail);
+       return lmtp_local_rcpt(client, cmd, lrcpt);
 }
 
 /*
index c20b619439042840ca8a5dd7afa43b2dc654c00b..d44d91830cc558fee0083ddc26a891732e2b22f1 100644 (file)
@@ -28,8 +28,6 @@
 struct lmtp_local_recipient {
        struct lmtp_recipient *rcpt;
 
-       char *detail;
-
        struct mail_storage_service_user *service_user;
        struct anvil_query *anvil_query;
 
@@ -285,14 +283,13 @@ lmtp_local_rcpt_anvil_cb(const char *reply, void *context)
 
 int lmtp_local_rcpt(struct client *client,
                    struct smtp_server_cmd_ctx *cmd ATTR_UNUSED,
-                   struct lmtp_recipient *lrcpt, const char *username,
-                   const char *detail)
+                   struct lmtp_recipient *lrcpt)
 {
        struct smtp_server_recipient *rcpt = lrcpt->rcpt;
        struct lmtp_local_recipient *llrcpt;
        struct mail_storage_service_input input;
        struct mail_storage_service_user *service_user;
-       const char *error = NULL;
+       const char *error = NULL, *username = lrcpt->username;
        int ret = 0;
 
        i_zero(&input);
@@ -331,7 +328,6 @@ int lmtp_local_rcpt(struct client *client,
 
        llrcpt = p_new(rcpt->pool, struct lmtp_local_recipient, 1);
        llrcpt->rcpt = lrcpt;
-       llrcpt->detail = p_strdup(rcpt->pool, detail);
        llrcpt->service_user = service_user;
 
        lrcpt->type = LMTP_RECIPIENT_TYPE_LOCAL;
@@ -497,13 +493,13 @@ lmtp_local_deliver(struct lmtp_local *local,
        lldctx.smtp_set = smtp_set;
        lldctx.lda_set = lda_set;
 
-       if (*llrcpt->detail == '\0' ||
+       if (*lrcpt->detail == '\0' ||
            !client->lmtp_set->lmtp_save_to_detail_mailbox)
                lldctx.rcpt_default_mailbox = "INBOX";
        else {
                ns = mail_namespace_find_inbox(rcpt_user->namespaces);
                lldctx.rcpt_default_mailbox =
-                       t_strconcat(ns->prefix, llrcpt->detail, NULL);
+                       t_strconcat(ns->prefix, lrcpt->detail, NULL);
        }
 
        ret = client->v.local_deliver(client, lrcpt, cmd, trans, &lldctx);
index 8ef942fcadcdb4dae2461f4a637cacccbb86a0f8..222dd26d64b39780f4041f38e80ccbb57fa8a7a6 100644 (file)
@@ -13,8 +13,7 @@ void lmtp_local_deinit(struct lmtp_local **_local);
 
 int lmtp_local_rcpt(struct client *client,
                    struct smtp_server_cmd_ctx *cmd,
-                   struct lmtp_recipient *lrcpt, const char *username,
-                   const char *detail);
+                   struct lmtp_recipient *lrcpt);
 
 void lmtp_local_add_headers(struct lmtp_local *local,
                            struct smtp_server_transaction *trans,
index be3df7de475b703eb9daab671a893a74ba8eaf30..cb7c6db608ff97ce88be3ce3c1caeec8803b60dd 100644 (file)
@@ -569,9 +569,7 @@ lmtp_proxy_rcpt_login_cb(const struct smtp_reply *proxy_reply, void *context)
 
 int lmtp_proxy_rcpt(struct client *client,
                    struct smtp_server_cmd_ctx *cmd,
-                   struct lmtp_recipient *lrcpt,
-                   const char *username, const char *detail,
-                   char delim)
+                   struct lmtp_recipient *lrcpt)
 {
        struct auth_master_connection *auth_conn;
        struct lmtp_proxy_rcpt_settings set;
@@ -582,7 +580,7 @@ int lmtp_proxy_rcpt(struct client *client,
        struct smtp_address *address = rcpt->path;
        struct auth_user_info info;
        struct mail_storage_service_input input;
-       const char *const *fields, *errstr, *orig_username = username;
+       const char *const *fields, *errstr, *username, *orig_username;
        struct smtp_proxy_data proxy_data;
        struct smtp_address *user;
        string_t *fwfields;
@@ -609,6 +607,7 @@ int lmtp_proxy_rcpt(struct client *client,
        info.forward_fields = lrcpt->forward_fields;
 
        // FIXME: make this async
+       username = orig_username = lrcpt->username;
        auth_pool = pool_alloconly_create("auth lookup", 1024);
        auth_conn = mail_storage_service_get_auth_conn(storage_service);
        ret = auth_master_pass_lookup(auth_conn, username, &info,
@@ -657,11 +656,11 @@ int lmtp_proxy_rcpt(struct client *client,
                        return -1;
                }
                /* Username changed. change the address as well */
-               if (*detail == '\0') {
+               if (*lrcpt->detail == '\0') {
                        address = user;
                } else {
                        address = smtp_address_add_detail_temp(
-                               user, detail, delim);
+                               user, lrcpt->detail, lrcpt->delim);
                }
        } else if (lmtp_proxy_is_ourself(client, &set)) {
                e_error(rcpt->event, "Proxying to <%s> loops to itself",
index 18d27b716dc89d50e874f8232605ff72ab1b99de..78e1f4a4056e5a4350441aff82978c6e1dab9ceb 100644 (file)
@@ -18,8 +18,7 @@ void lmtp_proxy_deinit(struct lmtp_proxy **proxy);
 
 int lmtp_proxy_rcpt(struct client *client,
                    struct smtp_server_cmd_ctx *cmd,
-                   struct lmtp_recipient *rcpt, const char *username,
-                   const char *detail, char delim);
+                   struct lmtp_recipient *rcpt);
 
 void lmtp_proxy_data(struct client *client,
                     struct smtp_server_cmd_ctx *cmd,
index d92fe735405136148e3a887abbd64acca34ac801..aec66334d51e3d17e1b63966778f744206285bc9 100644 (file)
@@ -2,8 +2,11 @@
 
 #include "lmtp-common.h"
 #include "array.h"
+#include "smtp-address.h"
 #include "smtp-server.h"
+#include "lda-settings.h"
 #include "lmtp-recipient.h"
+#include "lmtp-client.h"
 
 struct lmtp_recipient_module_register
 lmtp_recipient_module_register = { 0 };
@@ -14,11 +17,34 @@ lmtp_recipient_create(struct client *client,
                      struct smtp_server_recipient *rcpt)
 {
        struct lmtp_recipient *lrcpt;
+       const char *username, *detail;
+       char delim = '\0';
 
        lrcpt = p_new(rcpt->pool, struct lmtp_recipient, 1);
        lrcpt->rcpt = rcpt;     
        lrcpt->client = client;
 
+       smtp_address_detail_parse_temp(
+               client->unexpanded_lda_set->recipient_delimiter,
+               rcpt->path, &username, &delim, &detail);
+       i_assert(*username != '\0');
+
+       lrcpt->username = p_strdup(rcpt->pool, username);
+       lrcpt->detail = p_strdup(rcpt->pool, detail);
+       lrcpt->delim = delim;
+
+       /* Make user name and detail available in the recipient event. The
+          mail_user event (for local delivery) also adds the user field, but
+          adding it here makes it available to the recipient event in general.
+          Additionally, the auth lookups performed for local and proxy delivery
+          can further override the "user" recipient event when the auth service
+          returns a different user name. In any case, we provide the initial
+          value here.
+        */
+       event_add_str(rcpt->event, "user", lrcpt->username);
+       if (detail[0] != '\0')
+               event_add_str(rcpt->event, "detail", lrcpt->detail);
+
        rcpt->context = lrcpt;
 
        p_array_init(&lrcpt->module_contexts, rcpt->pool, 5);
index 2b4367860f3cf4ee2026e5e9eb1d33368d875494..9863d3e333a6a56b1510aa9232c6c3691fe4ea8a 100644 (file)
@@ -17,6 +17,9 @@ struct lmtp_recipient {
        struct client *client;
        struct smtp_server_recipient *rcpt;
 
+       char *username, *detail;
+       char delim;
+
        enum lmtp_recipient_type type;
        void *backend_context;