From e744ba667be26cb92ce831f3b9898a34d8200228 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 16 Feb 2016 18:05:59 +0100 Subject: [PATCH] imap-hibernate: send connect/disconnect events to anvil make doveadm who + mail_max_userip_connections work with hibernated connections. --- src/imap-hibernate/imap-client.c | 23 +++++++++++++++++++++++ src/imap-hibernate/imap-client.h | 1 + 2 files changed, 24 insertions(+) diff --git a/src/imap-hibernate/imap-client.c b/src/imap-hibernate/imap-client.c index f14080a2a5..5c7209e17b 100644 --- a/src/imap-hibernate/imap-client.c +++ b/src/imap-hibernate/imap-client.c @@ -397,12 +397,21 @@ static void imap_client_io_deactivate_user(struct imap_client *client ATTR_UNUSE i_set_failure_prefix("imap-hibernate: "); } +static const char *imap_client_get_anvil_userip_ident(struct imap_client_state *state) +{ + if (state->remote_ip.family == 0) + return NULL; + return t_strconcat(net_ip2addr(&state->remote_ip), "/", + str_tabescape(state->username), NULL); +} + struct imap_client * imap_client_create(int fd, const struct imap_client_state *state) { struct imap_client *client; pool_t pool = pool_alloconly_create("imap client", 256); void *statebuf; + const char *ident; i_assert(state->username != NULL); i_assert(state->mail_log_prefix != NULL); @@ -434,6 +443,13 @@ imap_client_create(int fd, const struct imap_client_state *state) client->log_prefix = p_strdup(pool, str_c(str)); } T_END; + ident = imap_client_get_anvil_userip_ident(&client->state); + if (ident != NULL) { + master_service_anvil_send(master_service, t_strconcat( + "CONNECT\t", my_pid, "\timap/", ident, "\n", NULL)); + client->state.anvil_sent = TRUE; + } + p_array_init(&client->notifys, pool, 2); DLLIST_PREPEND(&imap_clients, client); return client; @@ -468,6 +484,13 @@ void imap_client_destroy(struct imap_client **_client, const char *reason) i_info("%s %s", reason, client->state.stats); } + if (client->state.anvil_sent) { + master_service_anvil_send(master_service, t_strconcat( + "DISCONNECT\t", my_pid, "\timap/", + imap_client_get_anvil_userip_ident(&client->state), + "\n", NULL)); + } + if (client->ioloop_ctx != NULL) { io_loop_context_remove_callbacks(client->ioloop_ctx, imap_client_io_activate_user, diff --git a/src/imap-hibernate/imap-client.h b/src/imap-hibernate/imap-client.h index 131b404733..a57c974db9 100644 --- a/src/imap-hibernate/imap-client.h +++ b/src/imap-hibernate/imap-client.h @@ -22,6 +22,7 @@ struct imap_client_state { unsigned int imap_idle_notify_interval; bool idle_cmd; bool have_notify_fd; + bool anvil_sent; }; struct imap_client *