From 6ade11d2bbca91801f224456c8ffa7129ad2d37d Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Fri, 28 Dec 2018 23:23:13 +0100 Subject: [PATCH] lmtp: lmtp-recipient - Put lmtp_local_rcpt() and lmtp_proxy_rcpt() parameters in struct lmtp_recipient. --- src/lmtp/lmtp-commands.c | 42 ++++++++++----------------------------- src/lmtp/lmtp-local.c | 12 ++++------- src/lmtp/lmtp-local.h | 3 +-- src/lmtp/lmtp-proxy.c | 11 +++++----- src/lmtp/lmtp-proxy.h | 3 +-- src/lmtp/lmtp-recipient.c | 26 ++++++++++++++++++++++++ src/lmtp/lmtp-recipient.h | 3 +++ 7 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/lmtp/lmtp-commands.c b/src/lmtp/lmtp-commands.c index dd8b791e0c..9bacf28c23 100644 --- a/src/lmtp/lmtp-commands.c +++ b/src/lmtp/lmtp-commands.c @@ -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); } /* diff --git a/src/lmtp/lmtp-local.c b/src/lmtp/lmtp-local.c index c20b619439..d44d91830c 100644 --- a/src/lmtp/lmtp-local.c +++ b/src/lmtp/lmtp-local.c @@ -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); diff --git a/src/lmtp/lmtp-local.h b/src/lmtp/lmtp-local.h index 8ef942fcad..222dd26d64 100644 --- a/src/lmtp/lmtp-local.h +++ b/src/lmtp/lmtp-local.h @@ -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, diff --git a/src/lmtp/lmtp-proxy.c b/src/lmtp/lmtp-proxy.c index be3df7de47..cb7c6db608 100644 --- a/src/lmtp/lmtp-proxy.c +++ b/src/lmtp/lmtp-proxy.c @@ -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", diff --git a/src/lmtp/lmtp-proxy.h b/src/lmtp/lmtp-proxy.h index 18d27b716d..78e1f4a405 100644 --- a/src/lmtp/lmtp-proxy.h +++ b/src/lmtp/lmtp-proxy.h @@ -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, diff --git a/src/lmtp/lmtp-recipient.c b/src/lmtp/lmtp-recipient.c index d92fe73540..aec66334d5 100644 --- a/src/lmtp/lmtp-recipient.c +++ b/src/lmtp/lmtp-recipient.c @@ -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); diff --git a/src/lmtp/lmtp-recipient.h b/src/lmtp/lmtp-recipient.h index 2b4367860f..9863d3e333 100644 --- a/src/lmtp/lmtp-recipient.h +++ b/src/lmtp/lmtp-recipient.h @@ -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; -- 2.47.3