dovecot-2.0: *-login: Moved common code to sasl_server_get_adver...

dovecot at dovecot.org dovecot at dovecot.org
Sun Aug 9 23:49:50 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/fc025d93b274
changeset: 9753:fc025d93b274
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Aug 09 16:20:31 2009 -0400
description:
*-login: Moved common code to sasl_server_get_advertised_mechs().

diffstat:

4 files changed, 38 insertions(+), 25 deletions(-)
src/imap-login/client-authenticate.c |   17 ++++-------------
src/login-common/sasl-server.c       |   28 ++++++++++++++++++++++++++++
src/login-common/sasl-server.h       |    3 +++
src/pop3-login/client-authenticate.c |   15 +++------------

diffs (105 lines):

diff -r e616c3d00c2c -r fc025d93b274 src/imap-login/client-authenticate.c
--- a/src/imap-login/client-authenticate.c	Sun Aug 09 15:03:40 2009 -0400
+++ b/src/imap-login/client-authenticate.c	Sun Aug 09 16:20:31 2009 -0400
@@ -29,20 +29,11 @@ const char *client_authenticate_get_capa
 	string_t *str;
 
 	str = t_str_new(128);
-	mech = auth_client_get_available_mechs(auth_client, &count);
+	mech = sasl_server_get_advertised_mechs(&client->common, &count);
 	for (i = 0; i < count; i++) {
-		/* a) transport is secured
-		   b) auth mechanism isn't plaintext
-		   c) we allow insecure authentication
-		*/
-		if ((mech[i].flags & MECH_SEC_PRIVATE) == 0 &&
-		    (client->common.secured ||
-		     !client->common.set->disable_plaintext_auth ||
-		     (mech[i].flags & MECH_SEC_PLAINTEXT) == 0)) {
-			str_append_c(str, ' ');
-			str_append(str, "AUTH=");
-			str_append(str, mech[i].name);
-		}
+		str_append_c(str, ' ');
+		str_append(str, "AUTH=");
+		str_append(str, mech[i].name);
 	}
 
 	return str_c(str);
diff -r e616c3d00c2c -r fc025d93b274 src/login-common/sasl-server.c
--- a/src/login-common/sasl-server.c	Sun Aug 09 15:03:40 2009 -0400
+++ b/src/login-common/sasl-server.c	Sun Aug 09 16:20:31 2009 -0400
@@ -21,6 +21,34 @@
 	"Maximum number of connections from user+IP exceeded " \
 	"(mail_max_userip_connections)"
 
+const struct auth_mech_desc *
+sasl_server_get_advertised_mechs(struct client *client, unsigned int *count_r)
+{
+	const struct auth_mech_desc *mech;
+	struct auth_mech_desc *ret_mech;
+	unsigned int i, j, count;
+
+	mech = auth_client_get_available_mechs(auth_client, &count);
+	if (count == 0) {
+		*count_r = 0;
+		return NULL;
+	}
+
+	ret_mech = t_new(struct auth_mech_desc, count);
+	for (i = j = 0; i < count; i++) {
+		/* a) transport is secured
+		   b) auth mechanism isn't plaintext
+		   c) we allow insecure authentication
+		*/
+		if ((mech[i].flags & MECH_SEC_PRIVATE) == 0 &&
+		    (client->secured || !client->set->disable_plaintext_auth ||
+		     (mech[i].flags & MECH_SEC_PLAINTEXT) == 0))
+			ret_mech[j++] = mech[i];
+	}
+	*count_r = j;
+	return ret_mech;
+}
+
 static enum auth_request_flags
 client_get_auth_flags(struct client *client)
 {
diff -r e616c3d00c2c -r fc025d93b274 src/login-common/sasl-server.h
--- a/src/login-common/sasl-server.h	Sun Aug 09 15:03:40 2009 -0400
+++ b/src/login-common/sasl-server.h	Sun Aug 09 16:20:31 2009 -0400
@@ -15,6 +15,9 @@ typedef void sasl_server_callback_t(stru
 				    enum sasl_server_reply reply,
 				    const char *data, const char *const *args);
 
+const struct auth_mech_desc *
+sasl_server_get_advertised_mechs(struct client *client, unsigned int *count_r);
+
 void sasl_server_auth_begin(struct client *client,
 			    const char *service, const char *mech_name,
 			    const char *initial_resp_base64,
diff -r e616c3d00c2c -r fc025d93b274 src/pop3-login/client-authenticate.c
--- a/src/pop3-login/client-authenticate.c	Sun Aug 09 15:03:40 2009 -0400
+++ b/src/pop3-login/client-authenticate.c	Sun Aug 09 16:20:31 2009 -0400
@@ -41,19 +41,10 @@ bool cmd_capa(struct pop3_client *client
 		str_append(str, "USER\r\n");
 
 	str_append(str, "SASL");
-	mech = auth_client_get_available_mechs(auth_client, &count);
+	mech = sasl_server_get_advertised_mechs(&client->common, &count);
 	for (i = 0; i < count; i++) {
-		/* a) transport is secured
-		   b) auth mechanism isn't plaintext
-		   c) we allow insecure authentication
-		*/
-		if ((mech[i].flags & MECH_SEC_PRIVATE) == 0 &&
-		    (client->common.secured ||
-		     !client->common.set->disable_plaintext_auth ||
-		     (mech[i].flags & MECH_SEC_PLAINTEXT) == 0)) {
-			str_append_c(str, ' ');
-			str_append(str, mech[i].name);
-		}
+		str_append_c(str, ' ');
+		str_append(str, mech[i].name);
 	}
 	str_append(str, "\r\n.");
 


More information about the dovecot-cvs mailing list