]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
*-login: Allow plugins to hook into client allocation and add module-specific context...
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 15 Jan 2016 16:03:11 +0000 (18:03 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 15 Jan 2016 16:31:52 +0000 (18:31 +0200)
src/login-common/client-common.c
src/login-common/client-common.h
src/login-common/login-common.h
src/login-common/main.c

index 15aa54593667965386713861c7b69db774f1fd71..1e5f1fba6d2c5057bdf6b52973a6b74c6e17f471 100644 (file)
@@ -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))
index 769b33a5cd686ec59950fd31f82e595009be1e4b..18b885b1c585fa3d0712759e02a34b30e11a2802 100644 (file)
@@ -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,
index de405b895808099e28566c2cca884a912c9f3a29..7dca9c58321d8d32feb650f234e60bbeb3b8363c 100644 (file)
@@ -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;
index a3a4289884280db0125688839edc94197951c49c..1ae0396c0550dd4f6337c439e53de552f504cb61 100644 (file)
@@ -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;