dovecot-2.2: login-common API made more extensible for different...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Feb 13 00:30:07 EET 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/e456e1bce47f
changeset: 14146:e456e1bce47f
user: Timo Sirainen <tss at iki.fi>
date: Mon Feb 13 00:29:55 2012 +0200
description:
login-common API made more extensible for different kinds of protocols.
Patch by Stephan Bosch.
diffstat:
src/imap-login/client-authenticate.c | 98 ++++++++---------
src/imap-login/client-authenticate.h | 6 +-
src/imap-login/client.c | 159 +++++++++++++++++------------
src/imap-login/client.h | 14 ++
src/imap-login/imap-proxy.c | 16 ++-
src/imap-login/imap-proxy.h | 2 +
src/login-common/client-common-auth.c | 181 ++++++++++++++++++++++++---------
src/login-common/client-common.c | 65 ++++++++----
src/login-common/client-common.h | 66 ++++++++----
src/pop3-login/client-authenticate.c | 54 ++++------
src/pop3-login/client-authenticate.h | 6 +-
src/pop3-login/client.c | 74 ++++++++-----
src/pop3-login/client.h | 9 +
src/pop3-login/pop3-proxy.c | 9 +-
src/pop3-login/pop3-proxy.h | 2 +
15 files changed, 471 insertions(+), 290 deletions(-)
diffs (truncated from 1440 to 300 lines):
diff -r 8457e41b634b -r e456e1bce47f src/imap-login/client-authenticate.c
--- a/src/imap-login/client-authenticate.c Sun Feb 12 23:23:25 2012 +0200
+++ b/src/imap-login/client-authenticate.c Mon Feb 13 00:29:55 2012 +0200
@@ -3,14 +3,12 @@
#include "login-common.h"
#include "base64.h"
#include "buffer.h"
-#include "hostpid.h"
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
#include "safe-memset.h"
#include "str.h"
#include "str-sanitize.h"
-#include "time-util.h"
#include "imap-resp-code.h"
#include "imap-parser.h"
#include "auth-client.h"
@@ -33,14 +31,19 @@
}
}
-bool imap_client_auth_handle_reply(struct client *client,
- const struct client_auth_reply *reply)
+void imap_client_auth_result(struct client *client,
+ enum client_auth_result result,
+ const struct client_auth_reply *reply,
+ const char *text)
{
- struct imap_client *imap_client = (struct imap_client *)client;
- string_t *str;
- const char *timestamp, *msg;
+ string_t *referral;
- if (reply->host != NULL) {
+ switch (result) {
+ case CLIENT_AUTH_RESULT_SUCCESS:
+ /* nothing to be done for IMAP */
+ break;
+ case CLIENT_AUTH_RESULT_REFERRAL_SUCCESS:
+ case CLIENT_AUTH_RESULT_REFERRAL_NOLOGIN:
/* IMAP referral
[nologin] referral host=.. [port=..] [destuser=..]
@@ -50,55 +53,46 @@
OK [...] Logged in, but you should use this server instead.
.. [REFERRAL ..] (Reason from auth server)
*/
- str = t_str_new(128);
- str_append(str, imap_client->cmd_tag);
- str_append_c(str, ' ');
- str_append(str, reply->nologin ? "NO " : "OK ");
- str_printfa(str, "[REFERRAL imap://%s;AUTH=%s@%s",
+ referral = t_str_new(128);
+ str_printfa(referral, "REFERRAL imap://%s;AUTH=%s@%s",
reply->destuser, client->auth_mech_name,
reply->host);
if (reply->port != 143)
- str_printfa(str, ":%u", reply->port);
- str_append(str, "/] ");
- if (reply->reason != NULL)
- str_append(str, reply->reason);
- else if (reply->nologin)
- str_append(str, "Try this server instead.");
- else {
- str_append(str, "Logged in, but you should use "
- "this server instead.");
+ str_printfa(referral, ":%u", reply->port);
+ str_append(referral, "/");
+
+ if (result == CLIENT_AUTH_RESULT_REFERRAL_SUCCESS) {
+ client_send_reply_code(client, IMAP_CMD_REPLY_OK,
+ str_c(referral), text);
+ } else {
+ client_send_reply_code(client, IMAP_CMD_REPLY_NO,
+ str_c(referral), text);
}
- str_append(str, "\r\n");
- client_send_raw(client, str_c(str));
- if (!reply->nologin) {
- client_destroy_success(client, "Login with referral");
- return TRUE;
- }
- } else if (!reply->nologin) {
- /* normal login/failure */
- return FALSE;
- } else if (reply->reason != NULL) {
- client_send_line(client, CLIENT_CMD_REPLY_AUTH_FAIL_REASON,
- reply->reason);
- } else if (reply->temp) {
- timestamp = t_strflocaltime("%Y-%m-%d %H:%M:%S", ioloop_time);
- msg = t_strdup_printf(AUTH_TEMP_FAILED_MSG" [%s:%s]",
- my_hostname, timestamp);
- client_send_line(client,
- CLIENT_CMD_REPLY_AUTH_FAIL_TEMP, msg);
- } else if (reply->authz_failure) {
- client_send_line(client, CLIENT_CMD_REPLY_AUTHZ_FAILED,
- "Authorization failed");
- } else {
- client_send_line(client, CLIENT_CMD_REPLY_AUTH_FAILED,
- AUTH_FAILED_MSG);
+ break;
+ case CLIENT_AUTH_RESULT_ABORTED:
+ client_send_reply(client, IMAP_CMD_REPLY_BAD, text);
+ break;
+ case CLIENT_AUTH_RESULT_AUTHFAILED_REASON:
+ client_send_reply_code(client, IMAP_CMD_REPLY_NO,
+ "ALERT", text);
+ break;
+ case CLIENT_AUTH_RESULT_AUTHZFAILED:
+ client_send_reply_code(client, IMAP_CMD_REPLY_NO,
+ IMAP_RESP_CODE_AUTHZFAILED, text);
+ break;
+ case CLIENT_AUTH_RESULT_TEMPFAIL:
+ client_send_reply_code(client, IMAP_CMD_REPLY_NO,
+ IMAP_RESP_CODE_UNAVAILABLE, text);
+ break;
+ case CLIENT_AUTH_RESULT_SSL_REQUIRED:
+ client_send_reply_code(client, IMAP_CMD_REPLY_NO,
+ IMAP_RESP_CODE_PRIVACYREQUIRED, text);
+ break;
+ case CLIENT_AUTH_RESULT_AUTHFAILED:
+ client_send_reply_code(client, IMAP_CMD_REPLY_NO,
+ IMAP_RESP_CODE_AUTHFAILED, text);
+ break;
}
-
- i_assert(reply->nologin);
-
- if (!client->destroyed)
- client_auth_failed(client);
- return TRUE;
}
static int
diff -r 8457e41b634b -r e456e1bce47f src/imap-login/client-authenticate.h
--- a/src/imap-login/client-authenticate.h Sun Feb 12 23:23:25 2012 +0200
+++ b/src/imap-login/client-authenticate.h Mon Feb 13 00:29:55 2012 +0200
@@ -5,8 +5,10 @@
void client_authenticate_get_capabilities(struct client *client, string_t *str);
-bool imap_client_auth_handle_reply(struct client *client,
- const struct client_auth_reply *reply);
+void imap_client_auth_result(struct client *client,
+ enum client_auth_result result,
+ const struct client_auth_reply *reply,
+ const char *text);
int cmd_login(struct imap_client *client, const struct imap_arg *args);
int cmd_authenticate(struct imap_client *imap_client, bool *parsed_r);
diff -r 8457e41b634b -r e456e1bce47f src/imap-login/client.c
--- a/src/imap-login/client.c Sun Feb 12 23:23:25 2012 +0200
+++ b/src/imap-login/client.c Mon Feb 13 00:29:55 2012 +0200
@@ -82,8 +82,8 @@
imap_client->client_ignores_capability_resp_code = TRUE;
client_send_raw(client, t_strconcat(
"* CAPABILITY ", get_capability(client), "\r\n", NULL));
- client_send_line(client, CLIENT_CMD_REPLY_OK,
- "Pre-login capabilities listed, post-login capabilities have more.");
+ client_send_reply(client, IMAP_CMD_REPLY_OK,
+ "Pre-login capabilities listed, post-login capabilities have more.");
return 1;
}
@@ -94,6 +94,16 @@
}
static void
+imap_client_notify_starttls(struct client *client,
+ bool success, const char *text)
+{
+ if (success)
+ client_send_reply(client, IMAP_CMD_REPLY_OK, text);
+ else
+ client_send_reply(client, IMAP_CMD_REPLY_BAD, text);
+}
+
+static void
client_update_info(struct imap_client *client, const struct imap_arg *args)
{
const char *key, *value;
@@ -135,22 +145,22 @@
env = getenv("IMAP_ID_SEND");
client_send_raw(&client->common,
t_strdup_printf("* ID %s\r\n", imap_id_reply_generate(env)));
- client_send_line(&client->common, CLIENT_CMD_REPLY_OK, "ID completed.");
+ client_send_reply(&client->common, IMAP_CMD_REPLY_OK, "ID completed.");
return 1;
}
static int cmd_noop(struct imap_client *client)
{
- client_send_line(&client->common, CLIENT_CMD_REPLY_OK,
- "NOOP completed.");
+ client_send_reply(&client->common, IMAP_CMD_REPLY_OK,
+ "NOOP completed.");
return 1;
}
static int cmd_logout(struct imap_client *client)
{
- client_send_line(&client->common, CLIENT_CMD_REPLY_BYE, "Logging out");
- client_send_line(&client->common, CLIENT_CMD_REPLY_OK,
- "Logout completed.");
+ client_send_reply(&client->common, IMAP_CMD_REPLY_BYE, "Logging out");
+ client_send_reply(&client->common, IMAP_CMD_REPLY_OK,
+ "Logout completed.");
client_destroy(&client->common, "Aborted login");
return 1;
}
@@ -158,8 +168,8 @@
static int cmd_enable(struct imap_client *client)
{
client_send_raw(&client->common, "* ENABLED\r\n");
- client_send_line(&client->common, CLIENT_CMD_REPLY_OK,
- "ENABLE ignored in non-authenticated state.");
+ client_send_reply(&client->common, IMAP_CMD_REPLY_OK,
+ "ENABLE ignored in non-authenticated state.");
return 1;
}
@@ -223,14 +233,14 @@
/* error */
msg = imap_parser_get_error(client->parser, &fatal);
if (fatal) {
- client_send_line(&client->common,
- CLIENT_CMD_REPLY_BYE, msg);
+ client_send_reply(&client->common,
+ IMAP_CMD_REPLY_BYE, msg);
client_destroy(&client->common,
t_strconcat("Disconnected: ", msg, NULL));
return FALSE;
}
- client_send_line(&client->common, CLIENT_CMD_REPLY_BAD, msg);
+ client_send_reply(&client->common, IMAP_CMD_REPLY_BAD, msg);
client->cmd_finished = TRUE;
client->skip_line = TRUE;
return -1;
@@ -309,7 +319,7 @@
client->cmd_finished = TRUE;
if (ret == -2 && strcasecmp(client->cmd_tag, "LOGIN") == 0) {
- client_send_line(&client->common, CLIENT_CMD_REPLY_BAD,
+ client_send_reply(&client->common, IMAP_CMD_REPLY_BAD,
"First parameter in line is IMAP's command tag, "
"not the command name. Add that before the command, "
"like: a login user pass");
@@ -317,13 +327,13 @@
if (*client->cmd_tag == '\0')
client->cmd_tag = "*";
if (++client->common.bad_counter >= CLIENT_MAX_BAD_COMMANDS) {
- client_send_line(&client->common, CLIENT_CMD_REPLY_BYE,
+ client_send_reply(&client->common, IMAP_CMD_REPLY_BYE,
"Too many invalid IMAP commands.");
client_destroy(&client->common,
"Disconnected: Too many invalid commands");
return FALSE;
}
- client_send_line(&client->common, CLIENT_CMD_REPLY_BAD,
+ client_send_reply(&client->common, IMAP_CMD_REPLY_BAD,
"Error in IMAP command received by server.");
}
@@ -343,8 +353,8 @@
if (!auth_client_is_connected(auth_client)) {
/* we're not currently connected to auth process -
don't allow any commands */
- client_send_line(client, CLIENT_CMD_REPLY_STATUS,
- AUTH_SERVER_WAITING_MSG);
+ client_notify_status(client, FALSE,
+ AUTH_SERVER_WAITING_MSG);
if (client->to_auth_waiting != NULL)
timeout_remove(&client->to_auth_waiting);
@@ -386,7 +396,7 @@
imap_parser_unref(&imap_client->parser);
}
-static void imap_client_send_greeting(struct client *client)
+static void imap_client_notify_auth_ready(struct client *client)
{
string_t *greet;
@@ -397,7 +407,6 @@
str_append(greet, "\r\n");
client_send_raw(client, str_c(greet));
- client->greeting_sent = TRUE;
}
static void imap_client_starttls(struct client *client)
@@ -414,50 +423,11 @@
}
static void
-imap_client_send_line(struct client *client, enum client_cmd_reply reply,
- const char *text)
+client_send_reply_raw(struct client *client,
More information about the dovecot-cvs
mailing list