]> 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)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Fri, 16 Jun 2017 13:08:22 +0000 (16:08 +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 16999f2bb814711adb2b73bdc218132226308be0..d2673bfe97e39aeee075b768e50e54b7522b5ab8 100644 (file)
@@ -464,10 +464,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) {
@@ -507,6 +503,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,
@@ -762,6 +767,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 947c53542950f96beb3f68a5551780d89a52f9a1..439ed89dedfb91efd8f41cb1bedbdcf43676d56e 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 8e74d45aa1ce7e4593572c8b800f1420a2e722cc..c8142ab52d9dfc41f70773d539629dae6096f724 100644 (file)
@@ -105,6 +105,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 = {