]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap-login: Log Pre-login ID parameters as the imap_id_received event
authorKarl Fleischmann <karl.fleischmann@open-xchange.com>
Wed, 1 Mar 2023 13:40:24 +0000 (14:40 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 31 Mar 2023 05:54:46 +0000 (05:54 +0000)
Drop the manual filtering of the 'imap_id_log' fields in favor of using
a named event and respective log string.

src/imap-login/imap-login-client.h
src/imap-login/imap-login-cmd-id.c
src/imap-login/imap-login-settings.c
src/imap-login/imap-login-settings.h

index 6259ec5d8d14b4ef3cfe5a8b29cb6d3e31d452f8..6a17be565196202e8d0df2af4c67260bf7bfeee0 100644 (file)
@@ -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;
 };
 
index e2d050d6a94786ace4ce797115eecbdb05576d9f..a36f8533cb049f840bc57d43604f464798e51c25 100644 (file)
@@ -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");
index bd6b1641c00030b1e6853b9c1fa738d2dffb4e8c..a24c9eb26f827b69f1779d495f80e57eb665e823 100644 (file)
@@ -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,
 };
index 51ce1a8d8b1ed612b1fa472c7ded03ce65ed052e..cb4f2d8c2753a7e972e58817f3294bd67c59b046 100644 (file)
@@ -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;
 };