Skip to content

Commit

Permalink
lib-smtp: smtp-params - Assume all capabilities are supported when ad…
Browse files Browse the repository at this point in the history
…ding parameter event fields.

The actual capabilities are not really needed, since any assigned field is
relevent for event processing, whether the remote end will accept it or not.

This also fixes an assert failure occuring for proxied connections. Since the
server and client (proxy) connections can have different capabilities and since
the client connection does not have a proper capability list available in the
beginning of the handshake, the event created for a client transaction would
cause an assert failure when parameters were assigned that did not match the
capabilities (none).
  • Loading branch information
stephanbosch authored and sirainen committed Jul 16, 2019
1 parent 2502873 commit c4de810
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 48 deletions.
3 changes: 1 addition & 2 deletions src/lib-lda/mail-deliver.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,7 @@ void mail_deliver_init(struct mail_deliver_context *ctx,
event_add_str(ctx->event, "rcpt_to",
smtp_address_encode(ctx->rcpt_to));
}
smtp_params_rcpt_add_to_event(&ctx->rcpt_params,
SMTP_CAPABILITY__ORCPT, ctx->event);
smtp_params_rcpt_add_to_event(&ctx->rcpt_params, ctx->event);
}

void mail_deliver_deinit(struct mail_deliver_context *ctx)
Expand Down
7 changes: 1 addition & 6 deletions src/lib-smtp/smtp-client-transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,12 @@ static void
smtp_client_transaction_rcpt_update_event(
struct smtp_client_transaction_rcpt *rcpt)
{
struct smtp_client_connection *conn = rcpt->trans->conn;
const char *to = smtp_address_encode(rcpt->rcpt_to);

event_set_append_log_prefix(rcpt->event,
t_strdup_printf("rcpt <%s>: ", to));
event_add_str(rcpt->event, "rcpt_to", to);
smtp_params_rcpt_add_to_event(&rcpt->rcpt_params, conn->caps.standard,
rcpt->event);
smtp_params_rcpt_add_to_event(&rcpt->rcpt_params, rcpt->event);
}

static struct smtp_client_transaction_rcpt *
Expand Down Expand Up @@ -828,7 +826,6 @@ static void
smtp_client_transaction_mail_cb(const struct smtp_reply *reply,
struct smtp_client_transaction *trans)
{
struct smtp_client_connection *conn = trans->conn;
struct smtp_client_transaction_mail *mail = trans->mail_head;
bool success = smtp_reply_is_success(reply);

Expand Down Expand Up @@ -880,7 +877,6 @@ smtp_client_transaction_mail_cb(const struct smtp_reply *reply,
event_add_str(trans->event, "mail_from",
smtp_address_encode(mail->mail_from));
smtp_params_mail_add_to_event(&mail->mail_params,
conn->caps.standard,
trans->event);
}

Expand Down Expand Up @@ -945,7 +941,6 @@ void smtp_client_transaction_start(
event_add_str(trans->event, "mail_from",
smtp_address_encode(mail->mail_from));
smtp_params_mail_add_to_event(&mail->mail_params,
conn->caps.standard,
trans->event);

struct event_passthrough *e =
Expand Down
39 changes: 7 additions & 32 deletions src/lib-smtp/smtp-params.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,9 @@ smtp_params_mail_get_extra(const struct smtp_params_mail *params,

static void
smtp_params_mail_add_auth_to_event(const struct smtp_params_mail *params,
enum smtp_capability caps,
struct event *event)
{
/* AUTH: RFC 4954 */
if ((caps & SMTP_CAPABILITY_AUTH) == 0)
return;
if (params->auth == NULL)
return;

Expand All @@ -671,7 +668,6 @@ smtp_params_mail_add_auth_to_event(const struct smtp_params_mail *params,

static void
smtp_params_mail_add_body_to_event(const struct smtp_params_mail *params,
enum smtp_capability caps,
struct event *event)
{
/* BODY: RFC 6152 */
Expand All @@ -682,12 +678,9 @@ smtp_params_mail_add_body_to_event(const struct smtp_params_mail *params,
event_add_str(event, "mail_param_body", "7BIT");
break;
case SMTP_PARAM_MAIL_BODY_TYPE_8BITMIME:
i_assert((caps & SMTP_CAPABILITY_8BITMIME) != 0);
event_add_str(event, "mail_param_body", "8BITMIME");
break;
case SMTP_PARAM_MAIL_BODY_TYPE_BINARYMIME:
i_assert((caps & SMTP_CAPABILITY_BINARYMIME) != 0 &&
(caps & SMTP_CAPABILITY_CHUNKING) != 0);
event_add_str(event, "mail_param_body", "BINARYMIME");
break;
case SMTP_PARAM_MAIL_BODY_TYPE_EXTENSION:
Expand All @@ -700,12 +693,9 @@ smtp_params_mail_add_body_to_event(const struct smtp_params_mail *params,

static void
smtp_params_mail_add_envid_to_event(const struct smtp_params_mail *params,
enum smtp_capability caps,
struct event *event)
{
/* ENVID: RFC 3461, Section 4.4 */
if ((caps & SMTP_CAPABILITY_DSN) == 0)
return;
if (params->envid == NULL)
return;

Expand All @@ -714,12 +704,9 @@ smtp_params_mail_add_envid_to_event(const struct smtp_params_mail *params,

static void
smtp_params_mail_add_ret_to_event(const struct smtp_params_mail *params,
enum smtp_capability caps,
struct event *event)
{
/* RET: RFC 3461, Section 4.3 */
if ((caps & SMTP_CAPABILITY_DSN) == 0)
return;
switch (params->ret) {
case SMTP_PARAM_MAIL_RET_UNSPECIFIED:
break;
Expand All @@ -736,27 +723,23 @@ smtp_params_mail_add_ret_to_event(const struct smtp_params_mail *params,

static void
smtp_params_mail_add_size_to_event(const struct smtp_params_mail *params,
enum smtp_capability caps,
struct event *event)
{
/* SIZE: RFC 1870 */
if ((caps & SMTP_CAPABILITY_SIZE) == 0)
return;
if (params->size == 0)
return;

event_add_int(event, "mail_param_size", params->size);
}

void smtp_params_mail_add_to_event(const struct smtp_params_mail *params,
enum smtp_capability caps,
struct event *event)
{
smtp_params_mail_add_auth_to_event(params, caps, event);
smtp_params_mail_add_body_to_event(params, caps, event);
smtp_params_mail_add_envid_to_event(params, caps, event);
smtp_params_mail_add_ret_to_event(params, caps, event);
smtp_params_mail_add_size_to_event(params, caps, event);
smtp_params_mail_add_auth_to_event(params, event);
smtp_params_mail_add_body_to_event(params, event);
smtp_params_mail_add_envid_to_event(params, event);
smtp_params_mail_add_ret_to_event(params, event);
smtp_params_mail_add_size_to_event(params, event);
}

/*
Expand Down Expand Up @@ -1257,12 +1240,9 @@ bool smtp_params_rcpt_equals(const struct smtp_params_rcpt *params1,

static void
smtp_params_rcpt_add_notify_to_event(const struct smtp_params_rcpt *params,
enum smtp_capability caps,
struct event *event)
{
/* NOTIFY: RFC 3461, Section 4.1 */
if ((caps & SMTP_CAPABILITY_DSN) == 0)
return;
if (params->notify == SMTP_PARAM_RCPT_NOTIFY_UNSPECIFIED)
return;
if ((params->notify & SMTP_PARAM_RCPT_NOTIFY_NEVER) != 0) {
Expand All @@ -1289,15 +1269,11 @@ smtp_params_rcpt_add_notify_to_event(const struct smtp_params_rcpt *params,

static void
smtp_params_rcpt_add_orcpt_to_event(const struct smtp_params_rcpt *params,
enum smtp_capability caps,
struct event *event)
{
/* ORCPT: RFC 3461, Section 4.2 */
if (params->orcpt.addr_type == NULL)
return;
if ((caps & SMTP_CAPABILITY_DSN) == 0 &&
(caps & SMTP_CAPABILITY__ORCPT) == 0)
return;

event_add_str(event, "rcpt_param_orcpt_type",
params->orcpt.addr_type);
Expand All @@ -1312,9 +1288,8 @@ smtp_params_rcpt_add_orcpt_to_event(const struct smtp_params_rcpt *params,
}

void smtp_params_rcpt_add_to_event(const struct smtp_params_rcpt *params,
enum smtp_capability caps,
struct event *event)
{
smtp_params_rcpt_add_notify_to_event(params, caps, event);
smtp_params_rcpt_add_orcpt_to_event(params, caps, event);
smtp_params_rcpt_add_notify_to_event(params, event);
smtp_params_rcpt_add_orcpt_to_event(params, event);
}
2 changes: 0 additions & 2 deletions src/lib-smtp/smtp-params.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ smtp_params_mail_get_extra(const struct smtp_params_mail *params,
/* events */

void smtp_params_mail_add_to_event(const struct smtp_params_mail *params,
enum smtp_capability caps,
struct event *event);

/*
Expand Down Expand Up @@ -171,7 +170,6 @@ bool smtp_params_rcpt_equals(const struct smtp_params_rcpt *params1,
/* events */

void smtp_params_rcpt_add_to_event(const struct smtp_params_rcpt *params,
enum smtp_capability caps,
struct event *event);

#endif
4 changes: 1 addition & 3 deletions src/lib-smtp/smtp-server-recipient.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
static void
smtp_server_recipient_update_event(struct smtp_server_recipient_private *prcpt)
{
struct smtp_server_connection *conn = prcpt->rcpt.conn;
struct event *event = prcpt->rcpt.event;
const char *path = smtp_address_encode(prcpt->rcpt.path);

event_add_str(event, "rcpt_to", path);
smtp_params_rcpt_add_to_event(&prcpt->rcpt.params,
conn->set.capabilities, event);
smtp_params_rcpt_add_to_event(&prcpt->rcpt.params, event);
event_set_append_log_prefix(event,
t_strdup_printf("rcpt %s: ", path));
}
Expand Down
4 changes: 1 addition & 3 deletions src/lib-smtp/smtp-server-transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
static void
smtp_server_transaction_update_event(struct smtp_server_transaction *trans)
{
struct smtp_server_connection *conn = trans->conn;
struct event *event = trans->event;

event_add_str(event, "transaction_id", trans->id);
event_add_str(event, "mail_from",
smtp_address_encode(trans->mail_from));
smtp_params_mail_add_to_event(&trans->params, conn->set.capabilities,
event);
smtp_params_mail_add_to_event(&trans->params, event);
event_set_append_log_prefix(event,
t_strdup_printf("trans %s: ", trans->id));
}
Expand Down

0 comments on commit c4de810

Please sign in to comment.