[dovecot-cvs] dovecot/src/pop3-login client-authenticate.c,1.3,1.4 client.c,1.5,1.6 client.h,1.1,1.2
cras at procontrol.fi
cras at procontrol.fi
Sun Feb 2 12:46:22 EET 2003
- Previous message: [dovecot-cvs] dovecot/src/imap-login client-authenticate.c,1.2,1.3 client.c,1.3,1.4 client.h,1.1,1.2
- Next message: [dovecot-cvs] dovecot/src/login-common auth-common.c,NONE,1.1 auth-common.h,NONE,1.1 Makefile.am,1.1,1.2 client-common.h,1.1,1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/dovecot/src/pop3-login
In directory danu:/tmp/cvs-serv5293/pop3-login
Modified Files:
client-authenticate.c client.c client.h
Log Message:
Moved more auth code to login-common.
Index: client-authenticate.c
===================================================================
RCS file: /home/cvs/dovecot/src/pop3-login/client-authenticate.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- client-authenticate.c 30 Jan 2003 19:52:39 -0000 1.3
+++ client-authenticate.c 2 Feb 2003 10:46:20 -0000 1.4
@@ -11,9 +11,10 @@
#include "auth-connection.h"
#include "../auth/auth-mech-desc.h"
#include "../pop3/capability.h"
+#include "master.h"
+#include "auth-common.h"
#include "client.h"
#include "client-authenticate.h"
-#include "master.h"
static enum auth_mech auth_mechs = 0;
static char *auth_mechs_capability = NULL;
@@ -62,19 +63,19 @@
static void client_auth_abort(struct pop3_client *client, const char *msg)
{
- if (client->auth_request != NULL) {
- auth_abort_request(client->auth_request);
- client->auth_request = NULL;
+ if (client->common.auth_request != NULL) {
+ auth_abort_request(client->common.auth_request);
+ client->common.auth_request = NULL;
}
- client_send_line(client, msg != NULL ? msg :
+ client_send_line(client, msg != NULL ? t_strconcat("-ERR ", msg, NULL) :
"-ERR Authentication failed.");
o_stream_flush(client->output);
/* get back to normal client input */
- if (client->io != NULL)
- io_remove(client->io);
- client->io = client->common.fd == -1 ? NULL :
+ if (client->common.io != NULL)
+ io_remove(client->common.io);
+ client->common.io = client->common.fd == -1 ? NULL :
io_add(client->common.fd, IO_READ, client_input, client);
client_unref(client);
@@ -85,11 +86,12 @@
struct pop3_client *client = (struct pop3_client *) _client;
const char *reason = NULL;
- if (success)
- reason = t_strconcat("Login: ", client->virtual_user, NULL);
- else {
+ if (success) {
+ reason = t_strconcat("Login: ", client->common.virtual_user,
+ NULL);
+ } else {
reason = t_strconcat("Internal login failure: ",
- client->virtual_user, NULL);
+ client->common.virtual_user, NULL);
client_send_line(client, "* BYE Internal login failure.");
}
@@ -116,94 +118,33 @@
t_pop();
}
-static const char *auth_login_get_str(struct auth_login_reply *reply,
- const unsigned char *data, size_t idx)
-{
- size_t stop;
-
- if (idx >= reply->data_size || idx >= reply->reply_idx)
- return NULL;
-
- stop = reply->reply_idx < reply->data_size ?
- reply->reply_idx-1 : reply->data_size;
-
- return t_strndup(data, stop);
-}
-
-static int auth_callback(struct auth_request *request,
- struct auth_login_reply *reply,
- const unsigned char *data, void *context)
-{
- struct pop3_client *client = context;
- const char *user, *realm;
-
- if (reply == NULL) {
- /* failed */
- client->auth_request = NULL;
- client_auth_abort(client, "-ERR Authentication process died.");
- return FALSE;
- }
-
- switch (reply->result) {
- case AUTH_LOGIN_RESULT_CONTINUE:
- client->auth_request = request;
- return TRUE;
-
- case AUTH_LOGIN_RESULT_SUCCESS:
- client->auth_request = NULL;
-
- user = auth_login_get_str(reply, data, reply->username_idx);
- realm = auth_login_get_str(reply, data, reply->realm_idx);
-
- i_free(client->virtual_user);
- client->virtual_user = realm == NULL ?
- i_strdup(user) : i_strconcat(user, "@", realm, NULL);
-
- /* we should be able to log in. if we fail, just
- disconnect the client. */
- client_send_line(client, "+OK Logged in.");
-
- master_request_imap(&client->common, master_callback,
- request->conn->pid, request->id);
-
- /* disable IO until we're back from master */
- if (client->io != NULL) {
- io_remove(client->io);
- client->io = NULL;
- }
- return FALSE;
-
- case AUTH_LOGIN_RESULT_FAILURE:
- /* see if we have error message */
- client->auth_request = NULL;
-
- if (reply->data_size > 0 && data[reply->data_size-1] == '\0') {
- client_auth_abort(client, t_strconcat(
- "-ERR Authentication failed: ",
- (const char *) data, NULL));
- } else {
- /* default error message */
- client_auth_abort(client, NULL);
- }
- return FALSE;
- }
-
- i_unreached();
-}
-
static void login_callback(struct auth_request *request,
struct auth_login_reply *reply,
const unsigned char *data, struct client *_client)
{
struct pop3_client *client = (struct pop3_client *) _client;
+ const char *error;
const void *ptr;
size_t size;
- if (auth_callback(request, reply, data, client)) {
+ switch (auth_callback(request, reply, data, _client,
+ master_callback, &error)) {
+ case -1:
+ /* login failed */
+ client_auth_abort(client, error);
+ break;
+
+ case 0:
ptr = buffer_get_data(client->plain_login, &size);
auth_continue_request(request, ptr, size);
buffer_set_used_size(client->plain_login, 0);
+ break;
+
+ default:
+ /* success, we should be able to log in. if we fail, just
+ disconnect the client. */
+ client_send_line(client, "+OK Logged in.");
}
}
@@ -240,9 +181,9 @@
if (auth_init_request(AUTH_MECH_PLAIN, login_callback,
&client->common, &error)) {
/* don't read any input from client until login is finished */
- if (client->io != NULL) {
- io_remove(client->io);
- client->io = NULL;
+ if (client->common.io != NULL) {
+ io_remove(client->common.io);
+ client->common.io = NULL;
}
return TRUE;
} else {
@@ -259,9 +200,24 @@
struct client *_client)
{
struct pop3_client *client = (struct pop3_client *) _client;
+ const char *error;
- if (auth_callback(request, reply, data, client))
+ switch (auth_callback(request, reply, data, _client,
+ master_callback, &error)) {
+ case -1:
+ /* login failed */
+ client_auth_abort(client, error);
+ break;
+
+ case 0:
client_send_auth_data(client, data, reply->data_size);
+ break;
+
+ default:
+ /* success, we should be able to log in. if we fail, just
+ disconnect the client. */
+ client_send_line(client, "+OK Logged in.");
+ }
}
static void client_auth_input(void *context)
@@ -280,7 +236,7 @@
return;
if (strcmp(line, "*") == 0) {
- client_auth_abort(client, "-ERR Authentication aborted");
+ client_auth_abort(client, "Authentication aborted");
return;
}
@@ -290,11 +246,11 @@
if (base64_decode((const unsigned char *) line, linelen,
NULL, buf) <= 0) {
/* failed */
- client_auth_abort(client, "-ERR Invalid base64 data");
- } else if (client->auth_request == NULL) {
- client_auth_abort(client, "-ERR Don't send unrequested data");
+ client_auth_abort(client, "Invalid base64 data");
+ } else if (client->common.auth_request == NULL) {
+ client_auth_abort(client, "Don't send unrequested data");
} else {
- auth_continue_request(client->auth_request,
+ auth_continue_request(client->common.auth_request,
buffer_get_data(buf, NULL),
buffer_get_used_size(buf));
}
@@ -329,10 +285,10 @@
if (auth_init_request(mech->mech, authenticate_callback,
&client->common, &error)) {
/* following input data will go to authentication */
- if (client->io != NULL)
- io_remove(client->io);
- client->io = io_add(client->common.fd, IO_READ,
- client_auth_input, client);
+ if (client->common.io != NULL)
+ io_remove(client->common.io);
+ client->common.io = io_add(client->common.fd, IO_READ,
+ client_auth_input, client);
} else {
client_send_line(client, t_strconcat(
"-ERR Authentication failed: ", error, NULL));
Index: client.c
===================================================================
RCS file: /home/cvs/dovecot/src/pop3-login/client.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- client.c 2 Feb 2003 10:16:42 -0000 1.5
+++ client.c 2 Feb 2003 10:46:20 -0000 1.6
@@ -75,9 +75,9 @@
/* must be removed before ssl_proxy_new(), since it may
io_add() the same fd. */
- if (client->io != NULL) {
- io_remove(client->io);
- client->io = NULL;
+ if (client->common.io != NULL) {
+ io_remove(client->common.io);
+ client->common.io = NULL;
}
fd_ssl = ssl_proxy_new(client->common.fd);
@@ -96,7 +96,8 @@
client_destroy(client, "TLS handshake failed");
}
- client->io = io_add(client->common.fd, IO_READ, client_input, client);
+ client->common.io =
+ io_add(client->common.fd, IO_READ, client_input, client);
return TRUE;
}
@@ -244,7 +245,7 @@
client->common.ip = *ip;
client->common.fd = fd;
- client->io = io_add(fd, IO_READ, client_input, client);
+ client->common.io = io_add(fd, IO_READ, client_input, client);
client_open_streams(client, fd);
client->plain_login = buffer_create_dynamic(system_pool, 128, 8192);
@@ -268,15 +269,15 @@
i_stream_close(client->input);
o_stream_close(client->output);
- if (client->io != NULL) {
- io_remove(client->io);
- client->io = NULL;
+ if (client->common.io != NULL) {
+ io_remove(client->common.io);
+ client->common.io = NULL;
}
net_disconnect(client->common.fd);
client->common.fd = -1;
- i_free(client->virtual_user);
+ i_free(client->common.virtual_user);
client_unref(client);
}
Index: client.h
===================================================================
RCS file: /home/cvs/dovecot/src/pop3-login/client.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- client.h 28 Jan 2003 21:35:26 -0000 1.1
+++ client.h 2 Feb 2003 10:46:20 -0000 1.2
@@ -11,7 +11,6 @@
time_t created;
int refcount;
- struct io *io;
struct istream *input;
struct ostream *output;
@@ -19,8 +18,6 @@
unsigned int bad_counter;
buffer_t *plain_login;
- struct auth_request *auth_request;
- char *virtual_user;
unsigned int tls:1;
};
- Previous message: [dovecot-cvs] dovecot/src/imap-login client-authenticate.c,1.2,1.3 client.c,1.3,1.4 client.h,1.1,1.2
- Next message: [dovecot-cvs] dovecot/src/login-common auth-common.c,NONE,1.1 auth-common.h,NONE,1.1 Makefile.am,1.1,1.2 client-common.h,1.1,1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the dovecot-cvs
mailing list