[evolution-data-server] Bug #605125 - Crash while trying to access ldap address book



commit dc3d17d5b1f1f759b6bba102cf6d65470e45722c
Author: Milan Crha <mcrha redhat com>
Date:   Mon Dec 21 21:44:20 2009 +0100

    Bug #605125 - Crash while trying to access ldap address book

 addressbook/backends/ldap/e-book-backend-ldap.c |   26 +++++++++++++++++-----
 1 files changed, 20 insertions(+), 6 deletions(-)
---
diff --git a/addressbook/backends/ldap/e-book-backend-ldap.c b/addressbook/backends/ldap/e-book-backend-ldap.c
index a3d1af6..0c57d4f 100644
--- a/addressbook/backends/ldap/e-book-backend-ldap.c
+++ b/addressbook/backends/ldap/e-book-backend-ldap.c
@@ -980,7 +980,6 @@ e_book_backend_ldap_connect (EBookBackendLDAP *bl)
 			return (GNOME_Evolution_Addressbook_AuthenticationFailed);
 		}
 
-		g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
 		if (ldap_error == LDAP_INSUFFICIENT_ACCESS)
 			ldap_error = LDAP_SUCCESS;
 		else
@@ -998,7 +997,9 @@ e_book_backend_ldap_connect (EBookBackendLDAP *bl)
 		if (ldap_error == LDAP_SUCCESS
 		    || ldap_error == LDAP_PARTIAL_RESULTS
 		    || LDAP_NAME_ERROR (ldap_error)) {
+			e_book_backend_set_is_loaded (E_BOOK_BACKEND (bl), TRUE);
 			blpriv->connected = TRUE;
+			g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
 
 			/* check to see if evolutionPerson is supported, if we can (me
 			   might not be able to if we can't authenticate.  if we
@@ -1006,8 +1007,6 @@ e_book_backend_ldap_connect (EBookBackendLDAP *bl)
 			if (!bl->priv->evolutionPersonChecked)
 				check_schema_support (bl);
 
-			e_book_backend_set_is_loaded (E_BOOK_BACKEND (bl), TRUE);
-
 			if (enable_debug) {
 				printf ("e_book_backend_ldap_connect ... success \n");
 				g_get_current_time (&end);
@@ -1019,9 +1018,12 @@ e_book_backend_ldap_connect (EBookBackendLDAP *bl)
 			return GNOME_Evolution_Addressbook_Success;
 		} else if (ldap_error == LDAP_UNWILLING_TO_PERFORM) {
 			e_book_backend_notify_auth_required (E_BOOK_BACKEND (bl));
+			g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
 			return GNOME_Evolution_Addressbook_AuthenticationRequired;
-		} else
+		} 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);
+		}
 	}
 	else {
 		g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
@@ -4797,15 +4799,25 @@ e_book_backend_ldap_authenticate_user (EBookBackend *backend,
 	if (enable_debug)
 		printf ("e_book_backend_ldap_authenticate_user ... \n");
 
+	g_static_rec_mutex_lock (&eds_ldap_handler_lock);
 	if (bl->priv->mode == GNOME_Evolution_Addressbook_MODE_LOCAL) {
 		e_book_backend_notify_writable (backend, FALSE);
 		e_book_backend_notify_connection_status (backend, FALSE);
 		e_data_book_respond_authenticate_user (book,
 						       opid,
 						       GNOME_Evolution_Addressbook_Success);
+		g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
 		return;
 	}
 
+	if (bl->priv->connected) {
+		/* other client connected meanwhile, report success and return */
+		e_data_book_respond_authenticate_user (book, opid, GNOME_Evolution_Addressbook_Success);
+		g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
+		return;
+	}
+	g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
+
 	if (!g_ascii_strncasecmp (auth_method, LDAP_SIMPLE_PREFIX, strlen (LDAP_SIMPLE_PREFIX))) {
 
 		if (bl->priv->ldap && !strcmp (auth_method, "ldap/simple-email")) {
@@ -5148,7 +5160,9 @@ e_book_backend_ldap_load_source (EBookBackend             *backend,
 		if (enable_debug)
 			printf ("e_book_backend_ldap_load_source ... skipping anonymous bind, because auth required\n");
 
-		e_book_backend_notify_auth_required (E_BOOK_BACKEND (bl));
+		if (!e_book_backend_is_loaded (backend))
+			e_book_backend_notify_auth_required (backend);
+		e_book_backend_set_is_loaded (backend, TRUE);
 		return GNOME_Evolution_Addressbook_Success;
 	}
 
@@ -5160,7 +5174,7 @@ e_book_backend_ldap_load_source (EBookBackend             *backend,
 		return result;
 	}
 
-	if (auth_required) {
+	if (auth_required && !e_book_backend_is_loaded (backend)) {
 		e_book_backend_notify_auth_required (E_BOOK_BACKEND (bl));
 		return result;
 	}



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