]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
submission: submission-client - Add client.event and use it as mail_*user's parent...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Thu, 27 Dec 2018 21:09:50 +0000 (22:09 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 3 Oct 2022 10:34:30 +0000 (10:34 +0000)
src/submission/main.c
src/submission/submission-client.c
src/submission/submission-client.h
src/submission/submission-common.h

index 0556280a8c2f1ae0fc63b9c6001d89b8e600ed44..d4551a0b3205c0146376c3cb184a345ee34b124c 100644 (file)
@@ -47,6 +47,10 @@ static struct login_server *login_server = NULL;
 submission_client_created_func_t *hook_client_created = NULL;
 bool submission_debug = FALSE;
 
+struct event_category event_category_submission = {
+       .name = "submission",
+};
+
 submission_client_created_func_t *
 submission_client_created_hook_set(submission_client_created_func_t *new_hook)
 {
@@ -145,23 +149,47 @@ client_create_from_input(const struct mail_storage_service_input *input,
                         int fd_in, int fd_out, const buffer_t *input_buf,
                         const char **error_r)
 {
+       struct mail_storage_service_input service_input;
        struct mail_storage_service_user *user;
        struct mail_user *mail_user;
        struct submission_settings *set;
        bool no_greeting = HAS_ALL_BITS(login_flags,
                                        LOGIN_REQUEST_FLAG_IMPLICIT);
+       struct event *event;
        const char *errstr;
        const char *helo = NULL;
        struct smtp_proxy_data proxy_data;
        const unsigned char *data;
        size_t data_len;
 
-       if (mail_storage_service_lookup_next(storage_service, input,
+       event = event_create(NULL);
+       event_add_category(event, &event_category_submission);
+       event_add_fields(event, (const struct event_add_field []){
+               { .key = "user", .value = input->username },
+               { .key = NULL }
+       });
+       if (input->local_ip.family != 0)
+               event_add_str(event, "local_ip", net_ip2addr(&input->local_ip));
+       if (input->local_port != 0)
+               event_add_int(event, "local_port", input->local_port);
+       if (input->remote_ip.family != 0)
+               event_add_str(event, "remote_ip", net_ip2addr(&input->remote_ip));
+       if (input->remote_port != 0)
+               event_add_int(event, "remote_port", input->remote_port);
+
+       service_input = *input;
+       service_input.event_parent = event;
+       if (mail_storage_service_lookup_next(storage_service, &service_input,
                                             &user, &mail_user, error_r) <= 0) {
                send_error(fd_out, my_hostname,
                        "4.7.0", MAIL_ERRSTR_CRITICAL_MSG);
+               event_unref(&event);
                return -1;
        }
+       /* Add the session only after creating the user, because
+          input->session_id may be NULL */
+       event_add_str(event, "session", mail_user->session_id);
+
        restrict_access_allow_coredumps(TRUE);
 
        set = mail_storage_service_user_get_set(user)[1];
@@ -176,6 +204,7 @@ client_create_from_input(const struct mail_storage_service_input *input,
                        "4.3.5", MAIL_ERRSTR_CRITICAL_MSG);
                mail_user_deinit(&mail_user);
                mail_storage_service_user_unref(&user);
+               event_unref(&event);
                return -1;
        }
 
@@ -187,6 +216,7 @@ client_create_from_input(const struct mail_storage_service_input *input,
                        "4.3.5", MAIL_ERRSTR_CRITICAL_MSG);
                mail_user_deinit(&mail_user);
                mail_storage_service_user_unref(&user);
+               event_unref(&event);
                return -1;
        }
 
@@ -209,9 +239,10 @@ client_create_from_input(const struct mail_storage_service_input *input,
                 */
        }
 
-       (void)client_create(fd_in, fd_out, mail_user,
+       (void)client_create(fd_in, fd_out, event, mail_user,
                            user, set, helo, &proxy_data, data, data_len,
                            no_greeting);
+       event_unref(&event);
        return 0;
 }
 
index c8e56b0fcc5fb550b6bdb78856fb10f6dc05a6e0..5c9a2b69b45fa6b656f59713b6167ae1eccd573d 100644 (file)
@@ -175,7 +175,8 @@ static void client_init_urlauth(struct client *client)
 }
 
 struct client *
-client_create(int fd_in, int fd_out, struct mail_user *user,
+client_create(int fd_in, int fd_out, struct event *event,
+             struct mail_user *user,
              struct mail_storage_service_user *service_user,
              const struct submission_settings *set, const char *helo,
              const struct smtp_proxy_data *proxy_data,
@@ -197,6 +198,8 @@ client_create(int fd_in, int fd_out, struct mail_user *user,
        client = p_new(pool, struct client, 1);
        client->pool = pool;
        client->v = submission_client_vfuncs;
+       client->event = event;
+       event_ref(client->event);
        client->user = user;
        client->service_user = service_user;
        client->set = set;
@@ -326,6 +329,7 @@ client_default_destroy(struct client *client)
 
        client_state_reset(client);
 
+       event_unref(&client->event);
        pool_unref(&client->pool);
 
        master_service_client_connection_destroyed(master_service);
index 805ea42d2a9cbbabcce23270a00ec3c3f3f8ea41..681495b77ab5c39ec11b1a0db03945a0c0472c34 100644 (file)
@@ -82,6 +82,7 @@ struct client {
        pool_t pool;
 
        struct submission_client_vfuncs v;
+       struct event *event;
 
        const struct setting_parser_info *user_set_info;
        const struct submission_settings *set;
@@ -135,7 +136,8 @@ extern struct client *submission_clients;
 extern unsigned int submission_client_count;
 
 struct client *
-client_create(int fd_in, int fd_out, struct mail_user *user,
+client_create(int fd_in, int fd_out, struct event *event,
+             struct mail_user *user,
              struct mail_storage_service_user *service_user,
              const struct submission_settings *set, const char *helo,
              const struct smtp_proxy_data *proxy_data,
index 093d503481bc62753bc2eada9d787a4e9370ceea..17fb2376f5bde52335931481eae3d0a4b726ef92 100644 (file)
@@ -30,6 +30,7 @@ typedef void submission_client_created_func_t(struct client **client);
 
 extern submission_client_created_func_t *hook_client_created;
 extern bool submission_debug;
+extern struct event_category event_category_submission;
 
 extern struct smtp_server *smtp_server;
 extern struct smtp_client *smtp_client;