From 5ee46c69de39413529d791016e539a4a4647cc20 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Thu, 14 Feb 2019 00:17:20 +0100 Subject: [PATCH] lmtp: Replace i_error() with e_error(). --- src/lmtp/lmtp-client.c | 2 +- src/lmtp/lmtp-commands.c | 2 +- src/lmtp/lmtp-local.c | 26 +++++++++++++++----------- src/lmtp/lmtp-proxy.c | 37 ++++++++++++++++++++++++------------- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/lmtp/lmtp-client.c b/src/lmtp/lmtp-client.c index b00ab3afad..a52a25c785 100644 --- a/src/lmtp/lmtp-client.c +++ b/src/lmtp/lmtp-client.c @@ -362,7 +362,7 @@ static bool client_connection_is_trusted(void *context) net = t_strsplit_spaces(client->lmtp_set->login_trusted_networks, ", "); for (; *net != NULL; net++) { if (net_parse_range(*net, &net_ip, &bits) < 0) { - i_error("login_trusted_networks: " + e_error(client->event, "login_trusted_networks: " "Invalid network '%s'", *net); break; } diff --git a/src/lmtp/lmtp-commands.c b/src/lmtp/lmtp-commands.c index c61db396e0..f45bffd93b 100644 --- a/src/lmtp/lmtp-commands.c +++ b/src/lmtp/lmtp-commands.c @@ -163,7 +163,7 @@ int cmd_data_continue(void *conn_ctx, struct smtp_server_cmd_ctx *cmd, data = i_stream_get_data(data_input, &size); if (o_stream_send(state->mail_data_output, data, size) != (ssize_t)size) { - i_error("write(%s) failed: %s", + e_error(client->event, "write(%s) failed: %s", o_stream_get_name(state->mail_data_output), o_stream_get_error(state->mail_data_output)); smtp_server_reply(cmd, 451, "4.3.0", diff --git a/src/lmtp/lmtp-local.c b/src/lmtp/lmtp-local.c index 62e40fc5ac..302a188af5 100644 --- a/src/lmtp/lmtp-local.c +++ b/src/lmtp/lmtp-local.c @@ -195,7 +195,7 @@ lmtp_local_rcpt_check_quota(struct lmtp_local_recipient *llrcpt) &user, &error); if (ret < 0) { - i_error("Failed to initialize user %s: %s", + e_error(rcpt->event, "Failed to initialize user %s: %s", smtp_address_encode(address), error); ret = -1; } else { @@ -208,7 +208,8 @@ lmtp_local_rcpt_check_quota(struct lmtp_local_recipient *llrcpt) if (mail_error == MAIL_ERROR_NOQUOTA) { lmtp_local_rcpt_reply_overquota(llrcpt, cmd, error); } else { - i_error("mailbox_get_status(%s, STATUS_CHECK_OVER_QUOTA) " + e_error(rcpt->event, + "mailbox_get_status(%s, STATUS_CHECK_OVER_QUOTA) " "failed: %s", mailbox_get_vname(box), mailbox_get_last_internal_error(box, NULL)); @@ -277,7 +278,7 @@ lmtp_local_rcpt_anvil_cb(const char *reply, void *context) if (reply == NULL) { /* lookup failed */ } else if (str_to_uint(reply, ¶llel_count) < 0) { - i_error("Invalid reply from anvil: %s", reply); + e_error(rcpt->event, "Invalid reply from anvil: %s", reply); } if (parallel_count >= client->lmtp_set->lmtp_user_concurrency_limit) { @@ -339,7 +340,8 @@ int lmtp_local_rcpt(struct client *client, struct smtp_server_cmd_ctx *cmd, ret = mail_storage_service_lookup(storage_service, &input, &service_user, &error); if (ret < 0) { - i_error("Failed to lookup user %s: %s", username, error); + e_error(rcpt->event, "Failed to lookup user %s: %s", + username, error); smtp_server_reply(cmd, 451, "4.3.0", "<%s> Temporary internal error", smtp_address_encode(address)); @@ -493,7 +495,7 @@ lmtp_local_deliver(struct lmtp_local *local, i_set_failure_prefix("lmtp(%s, %s): ", my_pid, username); if (mail_storage_service_next(storage_service, service_user, &rcpt_user, &error) < 0) { - i_error("Failed to initialize user: %s", error); + e_error(rcpt->event, "Failed to initialize user: %s", error); smtp_server_reply_index(cmd, rcpt_idx, 451, "4.3.0", "<%s> Temporary internal error", smtp_address_encode(rcpt_to)); @@ -516,7 +518,7 @@ lmtp_local_deliver(struct lmtp_local *local, &error); } if (ret <= 0) { - i_error("Failed to expand settings: %s", error); + e_error(rcpt->event, "Failed to expand settings: %s", error); smtp_server_reply_index(cmd, rcpt_idx, 451, "4.3.0", "<%s> Temporary internal error", smtp_address_encode(rcpt_to)); @@ -527,7 +529,7 @@ lmtp_local_deliver(struct lmtp_local *local, if (var_expand_with_funcs(str, rcpt_user->set->mail_log_prefix, var_table, mail_user_var_expand_func_table, rcpt_user, &error) <= 0) { - i_error("Failed to expand mail_log_prefix=%s: %s", + e_error(rcpt->event, "Failed to expand mail_log_prefix=%s: %s", rcpt_user->set->mail_log_prefix, error); smtp_server_reply_index(cmd, rcpt_idx, 451, "4.3.0", "<%s> Temporary internal error", @@ -634,7 +636,7 @@ int lmtp_local_default_deliver(struct client *client, ret = -1; } else { /* This shouldn't happen */ - i_error("BUG: Saving failed to unknown storage"); + e_error(rcpt->event, "BUG: Saving failed to unknown storage"); smtp_server_reply_index(cmd, rcpt_idx, 451, "4.3.0", "<%s> Temporary internal error", smtp_address_encode(rcpt_to)); @@ -716,7 +718,7 @@ lmtp_local_open_raw_mail(struct lmtp_local *local, if (raw_mailbox_alloc_stream(client->raw_mail_user, input, (time_t)-1, smtp_address_encode(trans->mail_from), &box) < 0) { - i_error("Can't open delivery mail as raw: %s", + e_error(client->event, "Can't open delivery mail as raw: %s", mailbox_get_last_internal_error(box, &error)); mailbox_free(&box); lmtp_local_rcpt_fail_all(local, cmd, @@ -781,7 +783,9 @@ void lmtp_local_data(struct client *client, /* enable core dumping again. we need to chdir also to root-owned directory to get core dumps. */ restrict_access_allow_coredumps(TRUE); - if (chdir(base_dir) < 0) - i_error("chdir(%s) failed: %m", base_dir); + if (chdir(base_dir) < 0) { + e_error(client->event, + "chdir(%s) failed: %m", base_dir); + } } } diff --git a/src/lmtp/lmtp-proxy.c b/src/lmtp/lmtp-proxy.c index c990f5b7b7..6392667ebe 100644 --- a/src/lmtp/lmtp-proxy.c +++ b/src/lmtp/lmtp-proxy.c @@ -320,9 +320,11 @@ lmtp_proxy_handle_reply(struct smtp_server_cmd_ctx *cmd, */ static bool -lmtp_proxy_rcpt_parse_fields(struct lmtp_proxy_rcpt_settings *set, +lmtp_proxy_rcpt_parse_fields(struct lmtp_recipient *lrcpt, + struct lmtp_proxy_rcpt_settings *set, const char *const *args, const char **address) { + struct smtp_server_recipient *rcpt = lrcpt->rcpt; const char *p, *key, *value; bool proxying = FALSE, port_set = FALSE; @@ -342,23 +344,27 @@ lmtp_proxy_rcpt_parse_fields(struct lmtp_proxy_rcpt_settings *set, set->host = value; else if (strcmp(key, "hostip") == 0) { if (net_addr2ip(value, &set->hostip) < 0) { - i_error("proxy: Invalid hostip %s", value); + e_error(rcpt->event, + "proxy: Invalid hostip %s", value); return FALSE; } } else if (strcmp(key, "source_ip") == 0) { if (net_addr2ip(value, &set->source_ip) < 0) { - i_error("proxy: Invalid source_ip %s", value); + e_error(rcpt->event, + "proxy: Invalid source_ip %s", value); return FALSE; } } else if (strcmp(key, "port") == 0) { if (net_str2port(value, &set->port) < 0) { - i_error("proxy: Invalid port number %s", value); + e_error(rcpt->event, + "proxy: Invalid port number %s", value); return FALSE; } port_set = TRUE; } else if (strcmp(key, "proxy_timeout") == 0) { if (str_to_uint(value, &set->timeout_msecs) < 0) { - i_error("proxy: Invalid proxy_timeout value %s", value); + e_error(rcpt->event,"proxy: " + "Invalid proxy_timeout value %s", value); return FALSE; } set->timeout_msecs *= 1000; @@ -374,7 +380,8 @@ lmtp_proxy_rcpt_parse_fields(struct lmtp_proxy_rcpt_settings *set, if (!port_set) set->port = 25; } else { - i_error("proxy: Unknown protocol %s", value); + e_error(rcpt->event, + "proxy: Unknown protocol %s", value); return FALSE; } } else if (strcmp(key, "ssl") == 0) { @@ -395,7 +402,7 @@ lmtp_proxy_rcpt_parse_fields(struct lmtp_proxy_rcpt_settings *set, } } if (proxying && set->host == NULL) { - i_error("proxy: host not given"); + e_error(rcpt->event, "proxy: host not given"); return FALSE; } return proxying; @@ -514,7 +521,7 @@ int lmtp_proxy_rcpt(struct client *client, set.protocol = SMTP_PROTOCOL_LMTP; set.timeout_msecs = LMTP_PROXY_DEFAULT_TIMEOUT_MSECS; - if (!lmtp_proxy_rcpt_parse_fields(&set, fields, &username)) { + if (!lmtp_proxy_rcpt_parse_fields(lrcpt, &set, fields, &username)) { /* not proxying this user */ pool_unref(&auth_pool); return 0; @@ -527,7 +534,8 @@ int lmtp_proxy_rcpt(struct client *client, if (smtp_address_parse_username(pool_datastack_create(), username, &user, &errstr) < 0) { - i_error("%s: Username `%s' returned by passdb lookup is not a valid SMTP address", + e_error(rcpt->event, "%s: " + "Username `%s' returned by passdb lookup is not a valid SMTP address", orig_username, username); smtp_server_reply(cmd, 550, "5.3.5", "<%s> " "Internal user lookup failure", @@ -542,7 +550,8 @@ int lmtp_proxy_rcpt(struct client *client, address = smtp_address_add_detail_temp(user, detail, delim); } } else if (lmtp_proxy_is_ourself(client, &set)) { - i_error("Proxying to <%s> loops to itself", username); + e_error(rcpt->event, "Proxying to <%s> loops to itself", + username); smtp_server_reply(cmd, 554, "5.4.6", "<%s> Proxying loops to itself", smtp_address_encode(address)); @@ -552,7 +561,8 @@ int lmtp_proxy_rcpt(struct client *client, smtp_server_connection_get_proxy_data(cmd->conn, &proxy_data); if (proxy_data.ttl_plus_1 == 1) { - i_error("Proxying to <%s> appears to be looping (TTL=0)", + e_error(rcpt->event, + "Proxying to <%s> appears to be looping (TTL=0)", username); smtp_server_reply(cmd, 554, "5.4.6", "<%s> Proxying appears to be looping (TTL=0)", @@ -642,7 +652,7 @@ lmtp_proxy_data_cb(const struct smtp_reply *proxy_reply, while for us this is just an info event */ i_info("%s", str_c(msg)); } else { - i_error("%s", str_c(msg)); + e_error(rcpt->event, "%s", str_c(msg)); } if (!lmtp_proxy_handle_reply(cmd, proxy_reply, &reply)) @@ -676,7 +686,8 @@ void lmtp_proxy_data(struct client *client, proxy->data_input = data_input; i_stream_ref(proxy->data_input); if (i_stream_get_size(proxy->data_input, TRUE, &size) < 0) { - i_error("i_stream_get_size(data_input) failed: %s", + e_error(client->event, + "i_stream_get_size(data_input) failed: %s", i_stream_get_error(proxy->data_input)); size = (uoff_t)-1; }