[evolution-mapi/gnome-3-2] Bug #664016 - Password prompt for Notes, Tasks, etc. on login



commit af66c968d98377cef6d3173386cbe98684fd90a6
Author: Milan Crha <mcrha redhat com>
Date:   Mon Nov 14 19:57:12 2011 +0100

    Bug #664016 - Password prompt for Notes, Tasks, etc. on login

 .../exchange-mapi-account-listener.c               |    3 +
 src/addressbook/e-book-backend-mapi.c              |    5 +-
 src/calendar/e-cal-backend-mapi.c                  |    7 ++-
 src/camel/camel-mapi-store.c                       |    9 +++-
 src/libexchangemapi/exchange-mapi-connection.c     |   66 ++++++++++++++++++++
 5 files changed, 86 insertions(+), 4 deletions(-)
---
diff --git a/src/account-setup-eplugin/exchange-mapi-account-listener.c b/src/account-setup-eplugin/exchange-mapi-account-listener.c
index c3a3b10..b7547b6 100644
--- a/src/account-setup-eplugin/exchange-mapi-account-listener.c
+++ b/src/account-setup-eplugin/exchange-mapi-account-listener.c
@@ -350,6 +350,9 @@ add_cal_esource (EAccount *account, GSList *folders, ExchangeMAPIFolderType fold
 		e_source_set_property (source, "acl-owner-name", account->id->name);
 		e_source_set_property (source, "acl-owner-email", account->id->address);
 
+		if (folder_type != MAPI_FOLDER_TYPE_APPOINTMENT)
+			e_source_set_property (source, "alarm", "never");
+
 		if (is_new_source)
 			e_source_group_add_source (group, source, -1);
 
diff --git a/src/addressbook/e-book-backend-mapi.c b/src/addressbook/e-book-backend-mapi.c
index a2ae71a..17f0681 100644
--- a/src/addressbook/e-book-backend-mapi.c
+++ b/src/addressbook/e-book-backend-mapi.c
@@ -1956,13 +1956,16 @@ mapi_error_to_edb_error (GError **perror, const GError *mapi_error, EDataBookSta
 	if (!perror)
 		return;
 
-	if (code == E_DATA_BOOK_STATUS_OTHER_ERROR && mapi_error) {
+	if (code == E_DATA_BOOK_STATUS_OTHER_ERROR && mapi_error && mapi_error->domain == E_MAPI_ERROR) {
 		/* Change error to more accurate only with OTHER_ERROR */
 		switch (mapi_error->code) {
 		case MAPI_E_PASSWORD_CHANGE_REQUIRED:
 		case MAPI_E_PASSWORD_EXPIRED:
 			code = E_DATA_BOOK_STATUS_AUTHENTICATION_REQUIRED;
 			break;
+		case MAPI_E_NETWORK_ERROR:
+			code = E_DATA_BOOK_STATUS_REPOSITORY_OFFLINE;
+			break;
 		default:
 			break;
 		}
diff --git a/src/calendar/e-cal-backend-mapi.c b/src/calendar/e-cal-backend-mapi.c
index 790b096..1ebba8a 100644
--- a/src/calendar/e-cal-backend-mapi.c
+++ b/src/calendar/e-cal-backend-mapi.c
@@ -111,13 +111,16 @@ mapi_error_to_edc_error (GError **perror, const GError *mapi_error, EDataCalCall
 	if (!perror)
 		return;
 
-	if (code == OtherError && mapi_error) {
+	if (code == OtherError && mapi_error && mapi_error->domain == E_MAPI_ERROR) {
 		/* Change error to more accurate only with OtherError */
 		switch (mapi_error->code) {
 		case MAPI_E_PASSWORD_CHANGE_REQUIRED:
 		case MAPI_E_PASSWORD_EXPIRED:
 			code = AuthenticationRequired;
 			break;
+		case MAPI_E_NETWORK_ERROR:
+			code = RepositoryOffline;
+			break;
 		default:
 			break;
 		}
@@ -1250,7 +1253,7 @@ ecbm_connect_user (ECalBackend *backend, GCancellable *cancellable, const gchar
 	if (priv->conn && exchange_mapi_connection_connected (priv->conn)) {
 		/* Success */;
 	} else {
-		mapi_error_to_edc_error (perror, mapi_error, AuthenticationFailed, NULL);
+		mapi_error_to_edc_error (perror, mapi_error, g_error_matches (mapi_error, E_MAPI_ERROR, MAPI_E_NETWORK_ERROR) ? OtherError : AuthenticationFailed, NULL);
 		if (mapi_error)
 			g_error_free (mapi_error);
 		g_static_mutex_unlock (&auth_mutex);
diff --git a/src/camel/camel-mapi-store.c b/src/camel/camel-mapi-store.c
index ee54af1..ceb4adc 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -1724,7 +1724,14 @@ mapi_auth_loop (CamelService *service, GError **error)
 
 		store->priv->conn = exchange_mapi_connection_new (profile, url->passwd, &mapi_error);
 		if (!store->priv->conn || !exchange_mapi_connection_connected (store->priv->conn)) {
-			if (mapi_error) {
+			if (g_error_matches (mapi_error, E_MAPI_ERROR, MAPI_E_NETWORK_ERROR)) {
+				g_set_error_literal (
+					error, CAMEL_SERVICE_ERROR,
+					CAMEL_SERVICE_ERROR_UNAVAILABLE,
+					mapi_error->message);
+				g_error_free (mapi_error);
+				return FALSE;
+			} else if (mapi_error) {
 				errbuf = g_strdup_printf (_("Unable to authenticate to Exchange MAPI server: %s"), mapi_error->message);
 				g_error_free (mapi_error);
 			} else {
diff --git a/src/libexchangemapi/exchange-mapi-connection.c b/src/libexchangemapi/exchange-mapi-connection.c
index 1071b8d..d317f95 100644
--- a/src/libexchangemapi/exchange-mapi-connection.c
+++ b/src/libexchangemapi/exchange-mapi-connection.c
@@ -33,6 +33,8 @@
 #include <libedataserver/e-data-server-util.h>
 #include <libedataserver/e-flag.h>
 
+#include <tevent.h>
+
 #include "exchange-mapi-connection.h"
 #include "exchange-mapi-folder.h"
 #include "exchange-mapi-utils.h"
@@ -3650,6 +3652,67 @@ exchange_mapi_connection_events_monitor (ExchangeMapiConnection *conn, struct ma
 
 /* profile related functions - begin */
 
+extern const struct ndr_interface_table ndr_table_exchange_ds_rfr; /* from openchange's ndr_exchange.h */
+
+static enum MAPISTATUS
+test_server_availability (struct mapi_context *mapi_ctx,
+			  const gchar *profname,
+			  const gchar *password)
+{
+	enum MAPISTATUS	ms = MAPI_E_LOGON_FAILED;
+	TALLOC_CTX *mem_ctx;
+	struct mapi_profile *profile;
+	gchar *binding_str;
+	struct dcerpc_pipe *pipe;
+	struct tevent_context	*ev;
+	NTSTATUS status;
+
+	mem_ctx = talloc_new (mapi_ctx->mem_ctx);
+	profile = talloc_zero (mem_ctx, struct mapi_profile);
+	if (!profile) {
+		talloc_free (mem_ctx);
+		return MAPI_E_NOT_ENOUGH_RESOURCES;
+	}
+
+	ms = OpenProfile (mapi_ctx, profile, profname, password);
+	if (ms != MAPI_E_SUCCESS)
+		goto cleanup;
+
+	ms = LoadProfile (mapi_ctx, profile);
+	if (ms != MAPI_E_SUCCESS)
+		goto cleanup;
+
+	binding_str = talloc_asprintf (mem_ctx, "ncacn_ip_tcp:%s[", profile->server);
+
+	/* If seal option is enabled in the profile */
+	if (profile->seal == true) {
+		binding_str = talloc_strdup_append (binding_str, "seal,");
+	}
+
+	/* If localaddress parameter is available in the profile */
+	if (profile->localaddr) {
+		binding_str = talloc_asprintf_append (binding_str, "localaddress=%s,", profile->localaddr);
+	}
+
+	binding_str = talloc_strdup_append (binding_str, "]");
+	ev = tevent_context_init (mem_ctx);
+
+	status = dcerpc_pipe_connect (mem_ctx, &pipe, binding_str, &ndr_table_exchange_ds_rfr, profile->credentials, ev, mapi_ctx->lp_ctx); 
+
+	if (!NT_STATUS_IS_OK (status))
+		exchange_mapi_debug_print ("%s: Failed to connect to remote server: %s %s\n", G_STRFUNC, binding_str, nt_errstr (status));
+
+	if (NT_STATUS_EQUAL (status, NT_STATUS_OBJECT_NAME_NOT_FOUND))
+		ms = MAPI_E_NETWORK_ERROR;
+
+	talloc_free (binding_str);
+
+ cleanup:
+	talloc_free (mem_ctx);
+
+	return ms;
+}
+
 struct tcp_data
 {
 	const gchar *profname;
@@ -3840,6 +3903,9 @@ mapi_profile_load (const gchar *profname, const gchar *password, GError **perror
 	if (ms == MAPI_E_NOT_FOUND && try_create_profile (profname, password))
 		ms = MapiLogonEx (mapi_ctx, &session, profname, password);
 
+	if (ms == MAPI_E_LOGON_FAILED)
+		ms = test_server_availability (mapi_ctx, profname, password);
+
 	if (ms != MAPI_E_SUCCESS) {
 		make_mapi_error (perror, "MapiLogonEx", ms);
 		goto cleanup;



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