From 9132f9df4e12ed5293c70957813aa3736444a13c Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 15 Jan 2016 18:03:11 +0200 Subject: [PATCH] *-login: Allow plugins to hook into client allocation and add module-specific contexts to client. --- src/login-common/client-common.c | 18 ++++++++++++++++++ src/login-common/client-common.h | 15 +++++++++++++++ src/login-common/login-common.h | 5 +++++ src/login-common/main.c | 1 + 4 files changed, 39 insertions(+) diff --git a/src/login-common/client-common.c b/src/login-common/client-common.c index 15aa545936..1e5f1fba6d 100644 --- a/src/login-common/client-common.c +++ b/src/login-common/client-common.c @@ -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 @@ struct client *clients = NULL; 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_create(int fd, bool ssl, pool_t pool, 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_create(int fd, bool ssl, pool_t pool, 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)) diff --git a/src/login-common/client-common.h b/src/login-common/client-common.h index 769b33a5cd..18b885b1c5 100644 --- a/src/login-common/client-common.h +++ b/src/login-common/client-common.h @@ -147,6 +147,9 @@ struct client { 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 @@ struct client { /* ... */ }; +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, diff --git a/src/login-common/login-common.h b/src/login-common/login-common.h index de405b8958..7dca9c5832 100644 --- a/src/login-common/login-common.h +++ b/src/login-common/login-common.h @@ -38,6 +38,11 @@ struct login_binary { 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; diff --git a/src/login-common/main.c b/src/login-common/main.c index a3a4289884..1ae0396c05 100644 --- a/src/login-common/main.c +++ b/src/login-common/main.c @@ -40,6 +40,7 @@ bool closing_down, login_debug; 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;