changeset 19785:6022b536bf25

imap-hibernate: send connect/disconnect events to anvil make doveadm who + mail_max_userip_connections work with hibernated connections.
author manuel <manuel@mausz.at>
date Tue, 16 Feb 2016 18:05:59 +0100
parents 7fbc18735f8d
children deed74084f66
files src/imap-hibernate/imap-client.c src/imap-hibernate/imap-client.h
diffstat 2 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap-hibernate/imap-client.c	Sat Feb 20 23:32:59 2016 +0200
+++ b/src/imap-hibernate/imap-client.c	Tue Feb 16 18:05:59 2016 +0100
@@ -397,12 +397,21 @@
 	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 @@
 		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 @@
 		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,
--- a/src/imap-hibernate/imap-client.h	Sat Feb 20 23:32:59 2016 +0200
+++ b/src/imap-hibernate/imap-client.h	Tue Feb 16 18:05:59 2016 +0100
@@ -22,6 +22,7 @@
 	unsigned int imap_idle_notify_interval;
 	bool idle_cmd;
 	bool have_notify_fd;
+	bool anvil_sent;
 };
 
 struct imap_client *