From: Karl Fleischmann Date: Wed, 1 Mar 2023 13:40:24 +0000 (+0100) Subject: imap-login: Log Pre-login ID parameters as the imap_id_received event X-Git-Tag: 2.4.0~2833 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df54614802cce1d8b3ba9ecfc3cddb38f947dc5a;p=thirdparty%2Fdovecot%2Fcore.git imap-login: Log Pre-login ID parameters as the imap_id_received event Drop the manual filtering of the 'imap_id_log' fields in favor of using a named event and respective log string. --- diff --git a/src/imap-login/imap-login-client.h b/src/imap-login/imap-login-client.h index 6259ec5d8d..6a17be5651 100644 --- a/src/imap-login/imap-login-client.h +++ b/src/imap-login/imap-login-client.h @@ -46,8 +46,7 @@ struct imap_client_cmd_id { enum imap_client_id_state state; char key[IMAP_ID_KEY_MAX_LEN+1]; - - char **log_keys; + struct event *params_event; string_t *log_reply; }; diff --git a/src/imap-login/imap-login-cmd-id.c b/src/imap-login/imap-login-cmd-id.c index e2d050d6a9..a36f8533cb 100644 --- a/src/imap-login/imap-login-cmd-id.c +++ b/src/imap-login/imap-login-cmd-id.c @@ -131,6 +131,7 @@ client_try_update_info(struct imap_client *client, } static void cmd_id_handle_keyvalue(struct imap_client *client, + struct imap_id_log_entry *log_entry, const char *key, const char *value) { bool client_id_str; @@ -157,13 +158,11 @@ static void cmd_id_handle_keyvalue(struct imap_client *client, imap_append_quoted(client->common.client_id, value); } - if (client->cmd_id->log_reply != NULL && - (client->cmd_id->log_keys == NULL || - str_array_icase_find((void *)client->cmd_id->log_keys, key))) - imap_id_log_reply_append(client->cmd_id->log_reply, key, value); + imap_id_add_log_entry(log_entry, key, value); } static int cmd_id_handle_args(struct imap_client *client, + struct imap_id_log_entry *log_entry, const struct imap_arg *arg) { struct imap_client_cmd_id *id = client->cmd_id; @@ -175,20 +174,8 @@ static int cmd_id_handle_args(struct imap_client *client, return 1; if (arg->type != IMAP_ARG_LIST) return -1; - if (client->set->imap_id_log[0] == '\0') { - /* no ID logging */ - } else if (client->id_logged) { - /* already logged the ID reply */ - } else { + if (!client->id_logged) id->log_reply = str_new(default_pool, 64); - if (strcmp(client->set->imap_id_log, "*") == 0) { - /* log all keys */ - } else { - /* log only specified keys */ - id->log_keys = p_strsplit_spaces(default_pool, - client->set->imap_id_log, " "); - } - } id->state = IMAP_CLIENT_ID_STATE_KEY; break; case IMAP_CLIENT_ID_STATE_KEY: @@ -201,7 +188,10 @@ static int cmd_id_handle_args(struct imap_client *client, case IMAP_CLIENT_ID_STATE_VALUE: if (!imap_arg_get_nstring(arg, &value)) return -1; - cmd_id_handle_keyvalue(client, id->key, value); + if (!client->id_logged && id->log_reply != NULL) { + log_entry->reply = id->log_reply; + cmd_id_handle_keyvalue(client, log_entry, id->key, value); + } id->state = IMAP_CLIENT_ID_STATE_KEY; break; } @@ -210,13 +200,14 @@ static int cmd_id_handle_args(struct imap_client *client, static void cmd_id_finish(struct imap_client *client) { - /* finished handling the parameters */ if (!client->id_logged) { client->id_logged = TRUE; - if (client->cmd_id->log_reply != NULL) { - e_info(client->common.event, "ID sent: %s", - str_c(client->cmd_id->log_reply)); + if (client->cmd_id->log_reply != NULL && + str_len(client->cmd_id->log_reply) > 0) { + e_debug(client->cmd_id->params_event, + "Pre-login ID sent: %s", + str_c(client->cmd_id->log_reply)); } } @@ -233,9 +224,8 @@ void cmd_id_free(struct imap_client *client) { struct imap_client_cmd_id *id = client->cmd_id; + event_unref(&id->params_event); str_free(&id->log_reply); - if (id->log_keys != NULL) - p_strsplit_free(default_pool, id->log_keys); imap_parser_unref(&id->parser); i_free_and_null(client->cmd_id); @@ -265,10 +255,17 @@ int cmd_id(struct imap_client *client) parser_flags = IMAP_PARSE_FLAG_INSIDE_LIST; } + if (id->params_event == NULL) { + id->params_event = event_create(client->common.event); + event_set_name(id->params_event, "imap_id_received"); + } + struct imap_id_log_entry log_entry = { + .event = id->params_event, + }; while ((ret = imap_parser_read_args(id->parser, 1, parser_flags, &args)) > 0) { i_assert(ret == 1); - if ((ret = cmd_id_handle_args(client, args)) < 0) { + if ((ret = cmd_id_handle_args(client, &log_entry, args)) < 0) { client_send_reply(&client->common, IMAP_CMD_REPLY_BAD, "Invalid ID parameters"); diff --git a/src/imap-login/imap-login-settings.c b/src/imap-login/imap-login-settings.c index bd6b1641c0..a24c9eb26f 100644 --- a/src/imap-login/imap-login-settings.c +++ b/src/imap-login/imap-login-settings.c @@ -82,7 +82,6 @@ struct service_settings imap_login_service_settings = { static const struct setting_define imap_login_setting_defines[] = { DEF(STR, imap_capability), DEF(STR, imap_id_send), - DEF(STR, imap_id_log), DEF(BOOL, imap_literal_minus), DEF(BOOL, imap_id_retain), @@ -92,7 +91,6 @@ static const struct setting_define imap_login_setting_defines[] = { static const struct imap_login_settings imap_login_default_settings = { .imap_capability = "", .imap_id_send = "name *", - .imap_id_log = "", .imap_literal_minus = FALSE, .imap_id_retain = FALSE, }; diff --git a/src/imap-login/imap-login-settings.h b/src/imap-login/imap-login-settings.h index 51ce1a8d8b..cb4f2d8c27 100644 --- a/src/imap-login/imap-login-settings.h +++ b/src/imap-login/imap-login-settings.h @@ -4,7 +4,6 @@ struct imap_login_settings { const char *imap_capability; const char *imap_id_send; - const char *imap_id_log; bool imap_literal_minus; bool imap_id_retain; };