]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
pop3-login: client-authenticate - Send redirect reply upon referral nologin auth...
authorStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 1 Nov 2021 01:33:50 +0000 (02:33 +0100)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 17 Jan 2022 11:52:10 +0000 (13:52 +0200)
src/pop3-login/client-authenticate.c

index 118f65a9f450f354196df4c5f3e186f7b1f1b310..b4ead6857787ad985dd9130036763709a1f66a0e 100644 (file)
 #include "safe-memset.h"
 #include "str.h"
 #include "str-sanitize.h"
+#include "uri-util.h"
 #include "auth-client.h"
 #include "pop3-capability.h"
+#include "pop3-protocol.h"
 #include "client.h"
 #include "client-authenticate.h"
 #include "pop3-proxy.h"
@@ -47,15 +49,41 @@ bool cmd_capa(struct pop3_client *client, const char *args ATTR_UNUSED)
        return TRUE;
 }
 
+static void
+pop3_client_send_referral(struct client *client,
+                         const struct client_auth_reply *reply)
+{
+       string_t *line = t_str_new(128);
+
+       str_append(line, "-ERR [REFERRAL/");
+
+       struct uri_host host = {
+               .name = reply->proxy.host,
+               .ip = reply->proxy.host_ip,
+       };
+       if (reply->proxy.username != NULL)
+               uri_append_userinfo(line, reply->proxy.username);
+       uri_append_host(line, &host);
+       if (reply->proxy.port != POP3_DEFAULT_PORT)
+               uri_append_port(line, reply->proxy.port);
+
+       str_append(line, "] Referral\r\n");
+
+       client_send_raw_data(client, str_data(line), str_len(line));
+}
+
 void pop3_client_auth_result(struct client *client,
                             enum client_auth_result result,
-                            const struct client_auth_reply *reply ATTR_UNUSED,
+                            const struct client_auth_reply *reply,
                             const char *text)
 {
        switch (result) {
        case CLIENT_AUTH_RESULT_SUCCESS:
                /* nothing to be done for POP3 */
                break;
+       case CLIENT_AUTH_RESULT_REFERRAL_NOLOGIN:
+               pop3_client_send_referral(client, reply);
+               break;
        case CLIENT_AUTH_RESULT_TEMPFAIL:
                client_send_reply(client, POP3_CMD_REPLY_TEMPFAIL, text);
                break;