changeset 9753:fc025d93b274 HEAD

*-login: Moved common code to sasl_server_get_advertised_mechs().
author Timo Sirainen <tss@iki.fi>
date Sun, 09 Aug 2009 16:20:31 -0400
parents e616c3d00c2c
children b9ad5b841f7e
files src/imap-login/client-authenticate.c src/login-common/sasl-server.c src/login-common/sasl-server.h src/pop3-login/client-authenticate.c
diffstat 4 files changed, 38 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 	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);
--- 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)
 {
--- 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 @@
 				    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,
--- 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 @@
 		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.");