changeset 19572:8bb95d42e5ea

*-login: Allow plugins to hook into client allocation and add module-specific contexts to client.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 15 Jan 2016 18:03:11 +0200
parents a6cd5382373f
children d7bce1945b52
files src/login-common/client-common.c src/login-common/client-common.h src/login-common/login-common.h src/login-common/main.c
diffstat 4 files changed, 39 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/login-common/client-common.c	Fri Jan 15 17:17:05 2016 +0200
+++ b/src/login-common/client-common.c	Fri Jan 15 18:03:11 2016 +0200
@@ -1,6 +1,7 @@
 /* Copyright (c) 2002-2016 Dovecot authors, see the included COPYING file */
 
 #include "login-common.h"
+#include "array.h"
 #include "hostpid.h"
 #include "llist.h"
 #include "istream.h"
@@ -28,6 +29,21 @@
 static struct client *last_client = NULL;
 static unsigned int clients_count = 0;
 
+static void empty_login_client_allocated_hook(struct client *client ATTR_UNUSED)
+{
+}
+static login_client_allocated_func_t *hook_client_allocated =
+	empty_login_client_allocated_hook;
+
+login_client_allocated_func_t *
+login_client_allocated_hook_set(login_client_allocated_func_t *new_hook)
+{
+	login_client_allocated_func_t *old_hook = hook_client_allocated;
+
+	hook_client_allocated = new_hook;
+	return old_hook;
+}
+
 static void client_idle_disconnect_timeout(struct client *client)
 {
 	const char *user_reason, *destroy_reason;
@@ -124,6 +140,7 @@
 	client->pool = pool;
 	client->set = set;
 	client->ssl_set = ssl_set;
+	p_array_init(&client->module_contexts, client->pool, 5);
 
 	client->fd = fd;
 	client->tls = ssl;
@@ -153,6 +170,7 @@
 			    client_idle_disconnect_timeout, client);
 	client_open_streams(client);
 
+	hook_client_allocated(client);
 	client->v.create(client, other_sets);
 
 	if (auth_client_is_connected(auth_client))
--- a/src/login-common/client-common.h	Fri Jan 15 17:17:05 2016 +0200
+++ b/src/login-common/client-common.h	Fri Jan 15 18:03:11 2016 +0200
@@ -147,6 +147,9 @@
 	unsigned int auth_attempts, auth_successes;
 	pid_t mail_pid;
 
+	/* Module-specific contexts. */
+	ARRAY(union login_client_module_context *) module_contexts;
+
 	char *virtual_user, *virtual_user_orig, *virtual_auth_user;
 	unsigned int destroyed:1;
 	unsigned int input_blocked:1;
@@ -172,8 +175,20 @@
 	/* ... */
 };
 
+union login_client_module_context {
+	struct client_vfuncs super;
+	struct login_module_register *reg;
+};
+
 extern struct client *clients;
 
+typedef void login_client_allocated_func_t(struct client *client);
+
+/* Sets the client allocation hook and returns the previous hook,
+   which the new hook should call. */
+login_client_allocated_func_t *
+login_client_allocated_hook_set(login_client_allocated_func_t *new_hook);
+
 struct client *
 client_create(int fd, bool ssl, pool_t pool,
 	      const struct master_service_connection *conn,
--- a/src/login-common/login-common.h	Fri Jan 15 17:17:05 2016 +0200
+++ b/src/login-common/login-common.h	Fri Jan 15 18:03:11 2016 +0200
@@ -38,6 +38,11 @@
 	bool sasl_support_final_reply;
 };
 
+struct login_module_register {
+	unsigned int id;
+};
+extern struct login_module_register login_module_register;
+
 extern const struct login_binary *login_binary;
 extern struct auth_client *auth_client;
 extern struct master_auth *master_auth;
--- a/src/login-common/main.c	Fri Jan 15 17:17:05 2016 +0200
+++ b/src/login-common/main.c	Fri Jan 15 18:03:11 2016 +0200
@@ -40,6 +40,7 @@
 struct anvil_client *anvil;
 const char *login_rawlog_dir = NULL;
 unsigned int initial_service_count;
+struct login_module_register login_module_register;
 
 const struct login_settings *global_login_settings;
 const struct master_service_ssl_settings *global_ssl_settings;