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



commit a577ac5c4aa74d0d5f2d54aa872ab8e0e126a375
Author: Milan Crha <mcrha redhat com>
Date:   Mon Nov 14 19:56:00 2011 +0100

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

 .../e-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                       |    6 ++
 src/libexchangemapi/e-mapi-connection.c            |   70 ++++++++++++++++++++
 5 files changed, 88 insertions(+), 3 deletions(-)
---
diff --git a/src/account-setup-eplugin/e-mapi-account-listener.c b/src/account-setup-eplugin/e-mapi-account-listener.c
index a577e5d..09324a8 100644
--- a/src/account-setup-eplugin/e-mapi-account-listener.c
+++ b/src/account-setup-eplugin/e-mapi-account-listener.c
@@ -350,6 +350,9 @@ add_cal_esource (EAccount *account, GSList *folders, EMapiFolderType folder_type
 		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 0faff1b..cdc3901 100644
--- a/src/addressbook/e-book-backend-mapi.c
+++ b/src/addressbook/e-book-backend-mapi.c
@@ -1982,13 +1982,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 2ead0a7..505fbed 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;
 		}
@@ -1302,7 +1305,7 @@ ecbm_connect_user (ECalBackend *backend, GCancellable *cancellable, const gchar
 	if (priv->conn && e_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 30c3435..53267f7 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -1802,6 +1802,12 @@ mapi_authenticate_sync (CamelService *service,
 	} else if (g_error_matches (mapi_error, E_MAPI_ERROR, MAPI_E_LOGON_FAILED)) {
 		g_clear_error (&mapi_error);
 		result = CAMEL_AUTHENTICATION_REJECTED;
+	} else 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);
+		result = CAMEL_AUTHENTICATION_ERROR;
 	} else {
 		/* mapi_error should be set */
 		g_return_val_if_fail (
diff --git a/src/libexchangemapi/e-mapi-connection.c b/src/libexchangemapi/e-mapi-connection.c
index e1f89a4..a02692f 100644
--- a/src/libexchangemapi/e-mapi-connection.c
+++ b/src/libexchangemapi/e-mapi-connection.c
@@ -33,6 +33,8 @@
 #include <libedataserver/e-data-server-util.h>
 #include <libedataserver/e-flag.h>
 
+#include <tevent.h>
+
 #include "e-mapi-connection.h"
 #include "e-mapi-folder.h"
 #include "e-mapi-utils.h"
@@ -5167,6 +5169,71 @@ e_mapi_connection_events_monitor (EMapiConnection *conn, struct mapi_notify_cont
 
 /* 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,
+			  GCancellable *cancellable,
+			  GError **perror)
+{
+	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))
+		e_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;
+		g_set_error (perror, E_MAPI_ERROR, ms, _("Server '%s' is not reachable"), profile->server);
+	}
+
+	talloc_free (binding_str);
+
+ cleanup:
+	talloc_free (mem_ctx);
+
+	return ms;
+}
+
 struct tcp_data
 {
 	struct mapi_context *mapi_ctx;
@@ -5296,6 +5363,9 @@ mapi_profile_load (struct mapi_context *mapi_ctx, const gchar *profname, const g
 	if (ms == MAPI_E_NOT_FOUND && try_create_profile (mapi_ctx, profname, password, cancellable, perror))
 		ms = MapiLogonEx (mapi_ctx, &session, profname, password);
 
+	if (ms == MAPI_E_LOGON_FAILED)
+		ms = test_server_availability (mapi_ctx, profname, password, cancellable, perror);
+
 	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]