]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
*-login: Add client_vfuncs.input_next_cmd()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 12 Jun 2017 19:52:56 +0000 (22:52 +0300)
committerGitLab <gitlab@git.dovecot.net>
Tue, 13 Jun 2017 21:23:16 +0000 (00:23 +0300)
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
src/imap-urlauth/imap-urlauth-login.c
src/login-common/client-common.h
src/pop3-login/client.c

index 3bed536d739f930f15915e96297fb0dfd4cfbb35..d6a3098e2962a9d92157cb37690917a6171efea5 100644 (file)
@@ -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 = {
index 14eab52d4eba873377f8b86b74a3eca1a0c401bc..004ac95b4af66ef4ea6c0081ada467af1a754b32 100644 (file)
@@ -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 = {
index d919706b2f8786dfc25c2d892863a0811899e20e..ff5ba0a1dfddad8c853e21cb316ceafea738b42a 100644 (file)
@@ -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 {
index 151da898ff2e7180eb36e604a559c6cf1be70313..ae9c2ddb7c471b5bed648c25bd5c93a5ce536d3a 100644 (file)
@@ -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 = {