Skip to content

Commit

Permalink
*-login: Allow plugins to hook into client allocation and add module-…
Browse files Browse the repository at this point in the history
…specific contexts to client.
  • Loading branch information
sirainen committed Jan 15, 2016
1 parent ad24c03 commit 9132f9d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
15 changes: 15 additions & 0 deletions src/login-common/client-common.h
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/login-common/login-common.h
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/login-common/main.c
Expand Up @@ -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;
Expand Down

0 comments on commit 9132f9d

Please sign in to comment.