36
bool imap_client_auth_handle_reply(struct client *client,
37
const struct client_auth_reply *reply)
36
void imap_client_auth_result(struct client *client,
37
enum client_auth_result result,
38
const struct client_auth_reply *reply,
39
struct imap_client *imap_client = (struct imap_client *)client;
41
const char *timestamp, *msg;
43
if (reply->host != NULL) {
45
case CLIENT_AUTH_RESULT_SUCCESS:
46
/* nothing to be done for IMAP */
48
case CLIENT_AUTH_RESULT_REFERRAL_SUCCESS:
49
case CLIENT_AUTH_RESULT_REFERRAL_NOLOGIN:
46
52
[nologin] referral host=.. [port=..] [destuser=..]
50
56
OK [...] Logged in, but you should use this server instead.
51
57
.. [REFERRAL ..] (Reason from auth server)
54
str_append(str, imap_client->cmd_tag);
55
str_append_c(str, ' ');
56
str_append(str, reply->nologin ? "NO " : "OK ");
57
str_printfa(str, "[REFERRAL imap://%s;AUTH=%s@%s",
58
reply->destuser, client->auth_mech_name,
60
if (reply->port != 143)
61
str_printfa(str, ":%u", reply->port);
62
str_append(str, "/] ");
63
if (reply->reason != NULL)
64
str_append(str, reply->reason);
65
else if (reply->nologin)
66
str_append(str, "Try this server instead.");
68
str_append(str, "Logged in, but you should use "
69
"this server instead.");
71
str_append(str, "\r\n");
72
client_send_raw(client, str_c(str));
73
if (!reply->nologin) {
74
client_destroy_success(client, "Login with referral");
77
} else if (!reply->nologin) {
78
/* normal login/failure */
80
} else if (reply->reason != NULL) {
81
client_send_line(client, CLIENT_CMD_REPLY_AUTH_FAIL_REASON,
83
} else if (reply->temp) {
84
timestamp = t_strflocaltime("%Y-%m-%d %H:%M:%S", ioloop_time);
85
msg = t_strdup_printf(AUTH_TEMP_FAILED_MSG" [%s:%s]",
86
my_hostname, timestamp);
87
client_send_line(client,
88
CLIENT_CMD_REPLY_AUTH_FAIL_TEMP, msg);
89
} else if (reply->authz_failure) {
90
client_send_line(client, CLIENT_CMD_REPLY_AUTHZ_FAILED,
91
"Authorization failed");
93
client_send_line(client, CLIENT_CMD_REPLY_AUTH_FAILED,
59
referral = t_str_new(128);
61
memset(&url, 0, sizeof(url));
62
url.userid = reply->destuser;
63
url.auth_type = client->auth_mech_name;
64
url.host_name = reply->host;
65
if (reply->port != 143) {
67
url.port = reply->port;
69
str_append(referral, "REFERRAL ");
70
str_append(referral, imap_url_create(&url));
72
if (result == CLIENT_AUTH_RESULT_REFERRAL_SUCCESS) {
73
client_send_reply_code(client, IMAP_CMD_REPLY_OK,
74
str_c(referral), text);
76
client_send_reply_code(client, IMAP_CMD_REPLY_NO,
77
str_c(referral), text);
80
case CLIENT_AUTH_RESULT_ABORTED:
81
client_send_reply(client, IMAP_CMD_REPLY_BAD, text);
83
case CLIENT_AUTH_RESULT_AUTHFAILED_REASON:
84
client_send_reply_code(client, IMAP_CMD_REPLY_NO,
87
case CLIENT_AUTH_RESULT_AUTHZFAILED:
88
client_send_reply_code(client, IMAP_CMD_REPLY_NO,
89
IMAP_RESP_CODE_AUTHZFAILED, text);
91
case CLIENT_AUTH_RESULT_TEMPFAIL:
92
client_send_reply_code(client, IMAP_CMD_REPLY_NO,
93
IMAP_RESP_CODE_UNAVAILABLE, text);
95
case CLIENT_AUTH_RESULT_SSL_REQUIRED:
96
client_send_reply_code(client, IMAP_CMD_REPLY_NO,
97
IMAP_RESP_CODE_PRIVACYREQUIRED, text);
99
case CLIENT_AUTH_RESULT_AUTHFAILED:
100
client_send_reply_code(client, IMAP_CMD_REPLY_NO,
101
IMAP_RESP_CODE_AUTHFAILED, text);
97
i_assert(reply->nologin);
99
if (!client->destroyed)
100
client_auth_failed(client);