[evolution-data-server] Fix LDAP authentication and process authentication requests on idle



commit 38f4c183321d678435c1371d942672860aa765c4
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jun 29 07:38:35 2011 +0200

    Fix LDAP authentication and process authentication requests on idle

 addressbook/backends/ldap/e-book-backend-ldap.c |   12 ++-
 libedataserver/e-client.c                       |   91 +++++++++-------------
 libedataserverui/e-client-utils.c               |   18 ++++-
 3 files changed, 63 insertions(+), 58 deletions(-)
---
diff --git a/addressbook/backends/ldap/e-book-backend-ldap.c b/addressbook/backends/ldap/e-book-backend-ldap.c
index 8717a7c..37173c4 100644
--- a/addressbook/backends/ldap/e-book-backend-ldap.c
+++ b/addressbook/backends/ldap/e-book-backend-ldap.c
@@ -997,7 +997,7 @@ e_book_backend_ldap_connect (EBookBackendLDAP *bl)
 		} else if (ldap_error == LDAP_UNWILLING_TO_PERFORM) {
 			e_book_backend_notify_auth_required (E_BOOK_BACKEND (bl), TRUE, NULL);
 			g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
-			return EDB_ERROR (AUTHENTICATION_REQUIRED);
+			return EDB_ERROR (SUCCESS);
 		} else {
 			g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
 			g_warning ("Failed to perform root dse query anonymously, (ldap_error 0x%02x)", ldap_error);
@@ -4948,6 +4948,12 @@ e_book_backend_ldap_authenticate_user (EBookBackend *backend,
 		printf ("e_book_backend_ldap_authenticate_user ... \n");
 
 	g_static_rec_mutex_lock (&eds_ldap_handler_lock);
+	if (!auth_method || !*auth_method) {
+		ESource *source = e_book_backend_get_source (backend);
+
+		auth_method = e_source_get_property (source, "auth");
+	}
+
 	if (!bl->priv->is_online) {
 		e_book_backend_notify_readonly (backend, TRUE);
 		e_book_backend_notify_online (backend, FALSE);
@@ -5005,7 +5011,7 @@ e_book_backend_ldap_authenticate_user (EBookBackend *backend,
 				return;
 			}
 		}
-		else if (!strcmp (auth_method, "ldap/simple-binddn")) {
+		else if (!g_strcmp0 (auth_method, "ldap/simple-binddn")) {
 			dn = g_strdup (user);
 		}
 
@@ -5258,7 +5264,7 @@ e_book_backend_ldap_open (EBookBackend	*backend,
 			e_book_backend_notify_auth_required (backend, TRUE, NULL);
 		else
 			e_book_backend_notify_opened (backend, NULL);
-		e_book_backend_respond_opened (backend, book, opid, NULL /* Success */);
+		e_data_book_respond_open (book, opid, NULL /* Success */);
 		return;
 	}
 
diff --git a/libedataserver/e-client.c b/libedataserver/e-client.c
index 676218c..895df4e 100644
--- a/libedataserver/e-client.c
+++ b/libedataserver/e-client.c
@@ -27,7 +27,6 @@
 #include <gio/gio.h>
 
 #include "e-gdbus-marshallers.h"
-#include "e-operation-pool.h"
 
 #include "e-client.h"
 #include "e-client-private.h"
@@ -67,7 +66,6 @@ enum {
 };
 
 static guint signals[LAST_SIGNAL];
-static EOperationPool *ops_pool = NULL;
 
 G_DEFINE_ABSTRACT_TYPE (EClient, e_client, G_TYPE_OBJECT)
 
@@ -168,7 +166,6 @@ e_client_error_create (EClientError code, const gchar *custom_msg)
 }
 
 static void client_set_source (EClient *client, ESource *source);
-static void client_operation_thread (gpointer data, gpointer user_data);
 static void client_handle_authentication (EClient *client, const ECredentials *credentials);
 
 static void
@@ -387,48 +384,6 @@ e_client_class_init (EClientClass *klass)
 		NULL, NULL,
 		g_cclosure_marshal_VOID__VOID,
 		G_TYPE_NONE, 0);
-
-	if (!ops_pool)
-		ops_pool = e_operation_pool_new (2, client_operation_thread, NULL);
-}
-
-typedef enum {
-	E_CLIENT_OP_AUTHENTICATE
-} EClientOp;
-
-typedef struct _EClientOpData {
-	EClient *client;
-	EClientOp op;
-
-	union {
-		ECredentials *credentials;
-	} d;
-} EClientOpData;
-
-static void
-client_operation_thread (gpointer data, gpointer user_data)
-{
-	EClientOpData *op_data = data;
-
-	g_return_if_fail (op_data != NULL);
-
-	switch (op_data->op) {
-	case E_CLIENT_OP_AUTHENTICATE:
-		if (e_client_emit_authenticate (op_data->client, op_data->d.credentials)) {
-			client_handle_authentication (op_data->client, op_data->d.credentials);
-		} else {
-			GError *error;
-
-			error = e_client_error_create (E_CLIENT_ERROR_AUTHENTICATION_REQUIRED, NULL);
-			e_client_emit_opened (op_data->client, error);
-			g_error_free (error);
-		}
-		e_credentials_free (op_data->d.credentials);
-		break;
-	}
-
-	g_object_unref (op_data->client);
-	g_free (op_data);
 }
 
 static void
@@ -860,28 +815,56 @@ client_handle_authentication (EClient *client, const ECredentials *credentials)
 	return klass->handle_authentication (client, credentials);
 }
 
-/* Processes authentication request in a new thread. Usual steps are:
+struct EClientAuthData {
+	EClient *client;
+	ECredentials *credentials;
+};
+
+static gboolean
+client_process_authentication_idle_cb (gpointer user_data)
+{
+	struct EClientAuthData *auth_data = user_data;
+
+	g_return_val_if_fail (auth_data != NULL, FALSE);
+
+	if (e_client_emit_authenticate (auth_data->client, auth_data->credentials)) {
+		client_handle_authentication (auth_data->client, auth_data->credentials);
+	} else {
+		GError *error;
+
+		error = e_client_error_create (E_CLIENT_ERROR_AUTHENTICATION_REQUIRED, NULL);
+		e_client_emit_opened (auth_data->client, error);
+		g_error_free (error);
+	}
+
+	e_credentials_free (auth_data->credentials);
+	g_object_unref (auth_data->client);
+	g_free (auth_data);
+
+	return FALSE;
+}
+
+/* Processes authentication request in idle callback. Usual steps are:
    a) backend sends an auth-required signal
    b) EClient implementation calls this function
-   c) a new thread is run which emits authenticate signal by e_client_emit_authenticate ()
+   c) a new idle callback is run which emits authenticate signal by e_client_emit_authenticate ()
    d) if anyone responds (returns true), the EClient::handle_authentication
-      is called from the same extra thread with new credentials
+      is called from the same idle callback with new credentials
    e) EClient implementation passes results to backend in the EClient::handle_authentication
 */
 void
 e_client_process_authentication (EClient *client, const ECredentials *credentials)
 {
-	EClientOpData *op_data;
+	struct EClientAuthData *auth_data;
 
 	g_return_if_fail (client != NULL);
 	g_return_if_fail (E_IS_CLIENT (client));
 
-	op_data = g_new0 (EClientOpData, 1);
-	op_data->client = g_object_ref (client);
-	op_data->op = E_CLIENT_OP_AUTHENTICATE;
-	op_data->d.credentials = credentials ? e_credentials_new_clone (credentials) : e_credentials_new ();
+	auth_data = g_new0 (struct EClientAuthData, 1);
+	auth_data->client = g_object_ref (client);
+	auth_data->credentials = credentials ? e_credentials_new_clone (credentials) : e_credentials_new ();
 
-	e_operation_pool_push (ops_pool, op_data);
+	g_idle_add (client_process_authentication_idle_cb, auth_data);
 }
 
 gboolean
diff --git a/libedataserverui/e-client-utils.c b/libedataserverui/e-client-utils.c
index 36ccb9e..6df1d22 100644
--- a/libedataserverui/e-client-utils.c
+++ b/libedataserverui/e-client-utils.c
@@ -737,7 +737,23 @@ e_client_utils_authenticate_handler (EClient *client, ECredentials *credentials,
 	g_return_val_if_fail (source != NULL, FALSE);
 
 	if (!e_credentials_has_key (credentials, E_CREDENTIALS_KEY_USERNAME)) {
-		e_credentials_set (credentials, E_CREDENTIALS_KEY_USERNAME, e_source_get_property (source, "username"));
+		const gchar *username;
+
+		username = e_source_get_property (source, "username");
+		if (!username) {
+			const gchar *auth;
+
+			auth = e_source_get_property (source, "auth");
+			if (g_strcmp0 (auth, "ldap/simple-binddn") == 0)
+				username = e_source_get_property (source, "binddn");
+			else
+				username = e_source_get_property (source, "email_addr");
+
+			if (!username)
+				username = "";
+		}
+
+		e_credentials_set (credentials, E_CREDENTIALS_KEY_USERNAME, username);
 
 		/* no username set on the source - deny authentication request until
 		   username will be also enterable with e-passwords */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]