[dovecot-cvs] dovecot/src/pop3-login Makefile.am, 1.3, 1.4 client-authenticate.c, 1.36, 1.37 client.c, 1.31, 1.32 client.h, 1.13, 1.14 pop3-proxy.c, NONE, 1.1 pop3-proxy.h, NONE, 1.1

cras at dovecot.org cras at dovecot.org
Mon Oct 18 22:21:50 EEST 2004


Update of /var/lib/cvs/dovecot/src/pop3-login
In directory talvi:/tmp/cvs-serv11547/pop3-login

Modified Files:
	Makefile.am client-authenticate.c client.c client.h 
Added Files:
	pop3-proxy.c pop3-proxy.h 
Log Message:
Added IMAP and POP3 proxying support.



Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/pop3-login/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Makefile.am	22 Aug 2003 02:42:13 -0000	1.3
+++ Makefile.am	18 Oct 2004 19:21:48 -0000	1.4
@@ -15,8 +15,10 @@
 
 pop3_login_SOURCES = \
 	client.c \
-	client-authenticate.c
+	client-authenticate.c \
+	pop3-proxy.c
 
 noinst_HEADERS = \
 	client.h \
-	client-authenticate.h
+	client-authenticate.h \
+	pop3-proxy.h

Index: client-authenticate.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/pop3-login/client-authenticate.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- client-authenticate.c	18 Oct 2004 01:13:26 -0000	1.36
+++ client-authenticate.c	18 Oct 2004 19:21:48 -0000	1.37
@@ -15,6 +15,9 @@
 #include "ssl-proxy.h"
 #include "client.h"
 #include "client-authenticate.h"
+#include "pop3-proxy.h"
+
+#include <stdlib.h>
 
 int cmd_capa(struct pop3_client *client, const char *args __attr_unused__)
 {
@@ -77,18 +80,45 @@
 	safe_memset(line, 0, strlen(line));
 }
 
-static int client_handle_success_args(struct pop3_client *client,
-				      const char *const *args)
+static int client_handle_args(struct pop3_client *client,
+			      const char *const *args, int nologin)
 {
-	const char *reason = NULL;
+	const char *reason = NULL, *host = NULL, *destuser = NULL, *pass = NULL;
 	string_t *reply;
-	int nologin = FALSE;
+	unsigned int port = 110;
+	int proxy = FALSE;
 
 	for (; *args != NULL; args++) {
 		if (strcmp(*args, "nologin") == 0)
 			nologin = TRUE;
+		else if (strcmp(*args, "proxy") == 0)
+			proxy = TRUE;
 		else if (strncmp(*args, "reason=", 7) == 0)
 			reason = *args + 7;
+		else if (strncmp(*args, "host=", 5) == 0)
+			host = *args + 5;
+		else if (strncmp(*args, "port=", 5) == 0)
+			port = atoi(*args + 5);
+		else if (strncmp(*args, "destuser=", 9) == 0)
+			destuser = *args + 9;
+		else if (strncmp(*args, "pass=", 5) == 0)
+			pass = *args + 5;
+	}
+
+	if (destuser == NULL)
+		destuser = client->common.virtual_user;
+
+	if (proxy) {
+		/* we want to proxy the connection to another server.
+
+		   proxy host=.. [port=..] [destuser=..] pass=.. */
+		if (pop3_proxy_new(client, host, port, destuser, pass) < 0)
+			client_destroy_internal_failure(client);
+		else {
+			client_destroy(client, t_strconcat(
+				"Proxy: ", client->common.virtual_user, NULL));
+		}
+		return TRUE;
 	}
 
 	if (!nologin)
@@ -122,7 +152,7 @@
 	switch (reply) {
 	case SASL_SERVER_REPLY_SUCCESS:
 		if (args != NULL) {
-			if (client_handle_success_args(client, args))
+			if (client_handle_args(client, args, FALSE))
 				break;
 		}
 
@@ -131,6 +161,11 @@
 			"Login: ", client->common.virtual_user, NULL));
 		break;
 	case SASL_SERVER_REPLY_AUTH_FAILED:
+		if (args != NULL) {
+			if (client_handle_args(client, args, TRUE))
+				break;
+		}
+
 		if (data == NULL)
 			client_send_line(client, "-ERR Authentication failed");
 		else {
@@ -145,12 +180,7 @@
 				    client_input, client);
 		break;
 	case SASL_SERVER_REPLY_MASTER_FAILED:
-		client_send_line(client,
-				 "-ERR [IN-USE] Internal login failure. "
-				 "Refer to server log for more information.");
-		client_destroy(client, t_strconcat("Internal login failure: ",
-						   client->common.virtual_user,
-						   NULL));
+		client_destroy_internal_failure(client);
 		break;
 	case SASL_SERVER_REPLY_CONTINUE:
 		data_len = strlen(data);

Index: client.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/pop3-login/client.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- client.c	18 Oct 2004 01:13:26 -0000	1.31
+++ client.c	18 Oct 2004 19:21:48 -0000	1.32
@@ -366,6 +366,14 @@
 	client_unref(client);
 }
 
+void client_destroy_internal_failure(struct pop3_client *client)
+{
+	client_send_line(client, "-ERR [IN-USE] Internal login failure. "
+			 "Refer to server log for more information.");
+	client_destroy(client, t_strconcat("Internal login failure: ",
+					   client->common.virtual_user, NULL));
+}
+
 void client_ref(struct pop3_client *client)
 {
 	client->refcount++;

Index: client.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/pop3-login/client.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- client.h	17 Oct 2004 23:08:40 -0000	1.13
+++ client.h	18 Oct 2004 19:21:48 -0000	1.14
@@ -30,6 +30,7 @@
 };
 
 void client_destroy(struct pop3_client *client, const char *reason);
+void client_destroy_internal_failure(struct pop3_client *client);
 
 void client_send_line(struct pop3_client *client, const char *line);
 

--- NEW FILE: pop3-proxy.c ---
/* Copyright (C) 2004 Timo Sirainen */

#include "common.h"
#include "ioloop.h"
#include "base64.h"
#include "str.h"
#include "client.h"
#include "login-proxy.h"
#include "pop3-proxy.h"

int pop3_proxy_new(struct pop3_client *client, const char *host,
		   unsigned int port, const char *user, const char *password)
{
	string_t *auth, *str;

	i_assert(user != NULL);

	if (password == NULL) {
		i_error("proxy(%s): password not given",
			client->common.virtual_user);
		return -1;
	}

	auth = t_str_new(128);
	str_append_c(auth, '\0');
	str_append(auth, user);
	str_append_c(auth, '\0');
	str_append(auth, password);

	str = t_str_new(128);
	str_append(str, "AUTH ");
	base64_encode(str_data(auth), str_len(auth), str);
	str_append(str, "\r\n");

	if (login_proxy_new(&client->common, host, port, str_c(str)) < 0)
		return -1;

	if (client->io != NULL) {
		io_remove(client->io);
		client->io = NULL;
	}

	return 0;
}

--- NEW FILE: pop3-proxy.h ---
#ifndef __POP3_PROXY_H
#define __POP3_PROXY_H

int pop3_proxy_new(struct pop3_client *client, const char *host,
		   unsigned int port, const char *user, const char *password);

#endif



More information about the dovecot-cvs mailing list