From edfdc577ffe7408fd6463eb9dba11260d380ab53 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 12 Jun 2017 22:52:56 +0300 Subject: [PATCH] *-login: Add client_vfuncs.input_next_cmd() This allows plugins to hook into all the pre-login commands. For example with imap-login most of the commands could already be hooked into, except for ID and AUTHENTICATE because their parameters reading is handled specially. This allows hooking into them as well. This is actually internal to all the login binaries, so it wouldn't have to be in login-common. However, login-common already has all the code to handle overriding functions nicely and this is a rather useful feature for all the protocols anyway, so it's easier this way and not too ugly. --- src/imap-login/imap-login-client.c | 14 ++++++++++---- src/imap-urlauth/imap-urlauth-login.c | 1 + src/login-common/client-common.h | 1 + src/pop3-login/client.c | 5 ++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/imap-login/imap-login-client.c b/src/imap-login/imap-login-client.c index 3bed536d73..d6a3098e29 100644 --- a/src/imap-login/imap-login-client.c +++ b/src/imap-login/imap-login-client.c @@ -476,10 +476,6 @@ static int client_parse_command(struct imap_client *client, static bool client_handle_input(struct imap_client *client) { - const struct imap_arg *args; - bool parsed; - int ret; - i_assert(!client->common.authenticating); if (client->cmd_finished) { @@ -519,6 +515,15 @@ static bool client_handle_input(struct imap_client *client) if (client->cmd_name == NULL) return FALSE; /* need more data */ } + return client->common.v.input_next_cmd(&client->common); +} + +static bool imap_client_input_next_cmd(struct client *_client) +{ + struct imap_client *client = (struct imap_client *)_client; + const struct imap_arg *args; + bool parsed; + int ret; if (strcasecmp(client->cmd_name, "AUTHENTICATE") == 0) { /* SASL-IR may need more space than input buffer's size, @@ -776,6 +781,7 @@ static struct client_vfuncs imap_client_vfuncs = { imap_proxy_error, imap_proxy_get_state, client_common_send_raw_data, + imap_client_input_next_cmd, }; static const struct login_binary imap_login_binary = { diff --git a/src/imap-urlauth/imap-urlauth-login.c b/src/imap-urlauth/imap-urlauth-login.c index 14eab52d4e..004ac95b4a 100644 --- a/src/imap-urlauth/imap-urlauth-login.c +++ b/src/imap-urlauth/imap-urlauth-login.c @@ -175,6 +175,7 @@ static struct client_vfuncs imap_urlauth_vfuncs = { NULL, NULL, client_common_send_raw_data, + NULL, }; static const struct login_binary imap_urlauth_login_binary = { diff --git a/src/login-common/client-common.h b/src/login-common/client-common.h index d919706b2f..ff5ba0a1df 100644 --- a/src/login-common/client-common.h +++ b/src/login-common/client-common.h @@ -122,6 +122,7 @@ struct client_vfuncs { const char *(*proxy_get_state)(struct client *client); void (*send_raw_data)(struct client *client, const void *data, size_t size); + bool (*input_next_cmd)(struct client *client); }; struct client { diff --git a/src/pop3-login/client.c b/src/pop3-login/client.c index 151da898ff..ae9c2ddb7c 100644 --- a/src/pop3-login/client.c +++ b/src/pop3-login/client.c @@ -22,8 +22,6 @@ /* Disconnect client when it sends too many bad commands */ #define CLIENT_MAX_BAD_COMMANDS 3 -static bool pop3_client_input_next_cmd(struct client *client); - static bool cmd_stls(struct pop3_client *client) { client_cmd_starttls(&client->common); @@ -132,7 +130,7 @@ static void pop3_client_input(struct client *client) commands until the authentication is finished. */ while (!client->output->closed && !client->authenticating && auth_client_is_connected(auth_client)) { - if (!pop3_client_input_next_cmd(client)) + if (!client->v.input_next_cmd(client)) break; } @@ -335,6 +333,7 @@ static struct client_vfuncs pop3_client_vfuncs = { pop3_proxy_error, pop3_proxy_get_state, client_common_send_raw_data, + pop3_client_input_next_cmd, }; static const struct login_binary pop3_login_binary = { -- 2.47.3