[evolution-mapi] Kerberos authentication did not work



commit 91b9904b54c7db0b83ee58b77d0d703174f18d85
Author: Milan Crha <mcrha redhat com>
Date:   Fri Jun 29 12:11:21 2012 +0200

    Kerberos authentication did not work

 po/POTFILES.in                                 |    1 +
 src/camel/Makefile.am                          |    2 +
 src/camel/camel-mapi-provider.c                |    4 ++
 src/camel/camel-mapi-sasl-krb.c                |   62 ++++++++++++++++++++++++
 src/camel/camel-mapi-sasl-krb.h                |   59 ++++++++++++++++++++++
 src/camel/camel-mapi-store.c                   |   31 +++++++-----
 src/configuration/e-mail-config-mapi-backend.c |    4 +-
 src/configuration/e-mapi-config-utils.c        |    2 +-
 src/libexchangemapi/e-mapi-connection.c        |    6 +-
 9 files changed, 153 insertions(+), 18 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 85b08dd..d68e58e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,6 +4,7 @@ src/addressbook/e-book-backend-mapi-gal.c
 src/calendar/e-cal-backend-mapi.c
 src/camel/camel-mapi-folder.c
 src/camel/camel-mapi-provider.c
+src/camel/camel-mapi-sasl-krb.c
 src/camel/camel-mapi-store.c
 src/camel/camel-mapi-transport.c
 src/collection/e-mapi-backend.c
diff --git a/src/camel/Makefile.am b/src/camel/Makefile.am
index 6b7ab43..f7bb93a 100644
--- a/src/camel/Makefile.am
+++ b/src/camel/Makefile.am
@@ -18,6 +18,7 @@ libcamelmapi_la_SOURCES = 			\
 	camel-mapi-provider.c			\
 	camel-mapi-folder.c                	\
 	camel-mapi-folder-summary.c		\
+	camel-mapi-sasl-krb.c			\
         camel-mapi-store.c	                \
 	camel-mapi-store-summary.c         	\
 	camel-mapi-transport.c			
@@ -25,6 +26,7 @@ libcamelmapi_la_SOURCES = 			\
 noinst_HEADERS =         			\
 	camel-mapi-folder.h			\
 	camel-mapi-folder-summary.h		\
+	camel-mapi-sasl-krb.h			\
 	camel-mapi-store.h			\
 	camel-mapi-store-summary.h         	\
 	camel-mapi-transport.h
diff --git a/src/camel/camel-mapi-provider.c b/src/camel/camel-mapi-provider.c
index e0a399f..84b2737 100644
--- a/src/camel/camel-mapi-provider.c
+++ b/src/camel/camel-mapi-provider.c
@@ -31,6 +31,7 @@
 
 #include <gmodule.h>
 
+#include "camel-mapi-sasl-krb.h"
 #include "camel-mapi-store.h"
 #include "camel-mapi-transport.h"
 
@@ -114,6 +115,9 @@ camel_provider_module_init(void)
 	bindtextdomain (GETTEXT_PACKAGE, EXCHANGE_MAPI_LOCALEDIR);
 	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
+	/* register MAPIKRB auth type */
+	CAMEL_TYPE_MAPI_SASL_KRB;
+
 	camel_provider_register (&mapi_provider);
 }
 
diff --git a/src/camel/camel-mapi-sasl-krb.c b/src/camel/camel-mapi-sasl-krb.c
new file mode 100644
index 0000000..3f744a3
--- /dev/null
+++ b/src/camel/camel-mapi-sasl-krb.c
@@ -0,0 +1,62 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
+#include <glib/gi18n-lib.h>
+
+#include "camel-mapi-sasl-krb.h"
+
+static CamelServiceAuthType mapi_sasl_krb_auth_type = {
+	N_("Kerberos"),
+
+	N_("This option will connect to the server using kerberos key."),
+
+	"MAPIKRB",
+	FALSE
+};
+
+G_DEFINE_TYPE (CamelMapiSaslKrb, camel_mapi_sasl_krb, CAMEL_TYPE_SASL)
+
+static GByteArray *
+mapi_sasl_krb_challenge_sync (CamelSasl *sasl,
+                              GByteArray *token,
+                              GCancellable *cancellable,
+                              GError **error)
+{
+	camel_sasl_set_authenticated (sasl, TRUE);
+
+	return NULL;
+}
+
+static void
+camel_mapi_sasl_krb_class_init (CamelMapiSaslKrbClass *class)
+{
+	CamelSaslClass *sasl_class;
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->auth_type = &mapi_sasl_krb_auth_type;
+	sasl_class->challenge_sync = mapi_sasl_krb_challenge_sync;
+}
+
+static void
+camel_mapi_sasl_krb_init (CamelMapiSaslKrb *mapi_sasl_krb)
+{
+}
diff --git a/src/camel/camel-mapi-sasl-krb.h b/src/camel/camel-mapi-sasl-krb.h
new file mode 100644
index 0000000..9438592
--- /dev/null
+++ b/src/camel/camel-mapi-sasl-krb.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef CAMEL_MAPI_SASL_KRB_H
+#define CAMEL_MAPI_SASL_KRB_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_MAPI_SASL_KRB \
+	(camel_mapi_sasl_krb_get_type ())
+#define CAMEL_MAPI_SASL_KRB(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MAPI_SASL_KRB, CamelMapiSaslKrb))
+#define CAMEL_MAPI_SASL_KRB_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MAPI_SASL_KRB, CamelMapiSaslKrbClass))
+#define CAMEL_IS_MAPI_SASL_KRB(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MAPI_SASL_KRB))
+#define CAMEL_IS_MAPI_SASL_KRB_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MAPI_SASL_KRB))
+#define CAMEL_MAPI_SASL_KRB_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MAPI_SASL_KRB, CamelMapiSaslKrbClass))
+
+G_BEGIN_DECLS
+
+typedef struct _CamelMapiSaslKrb CamelMapiSaslKrb;
+typedef struct _CamelMapiSaslKrbClass CamelMapiSaslKrbClass;
+
+struct _CamelMapiSaslKrb {
+	CamelSasl parent;
+};
+
+struct _CamelMapiSaslKrbClass {
+	CamelSaslClass parent_class;
+};
+
+GType camel_mapi_sasl_krb_get_type (void);
+
+G_END_DECLS
+
+#endif /* CAMEL_MAPI_SASL_KRB_H */
diff --git a/src/camel/camel-mapi-store.c b/src/camel/camel-mapi-store.c
index a2a504f..5d1a4f5 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -42,6 +42,7 @@
 
 #include "camel-mapi-store.h"
 #include "camel-mapi-folder.h"
+#include "camel-mapi-sasl-krb.h"
 #include "camel-mapi-settings.h"
 #include "camel-mapi-store-summary.h"
 #include "camel-mapi-folder-summary.h"
@@ -1952,6 +1953,9 @@ camel_mapi_store_class_init (CamelMapiStoreClass *class)
 	CamelServiceClass *service_class;
 	CamelStoreClass *store_class;
 
+	/* register MAPIKRB auth type */
+	CAMEL_TYPE_MAPI_SASL_KRB;
+
 	g_type_class_add_private (class, sizeof (CamelMapiStorePrivate));
 
 	object_class = G_OBJECT_CLASS (class);
@@ -2081,6 +2085,7 @@ mapi_connect_sync (CamelService *service,
 	CamelMapiStore *store = CAMEL_MAPI_STORE (service);
 	CamelServiceConnectionStatus status;
 	CamelSession *session;
+	EMapiProfileData empd = { 0 };
 	uint64_t current_size = -1, receive_quota = -1, send_quota = -1;
 	gchar *name;
 
@@ -2104,7 +2109,9 @@ mapi_connect_sync (CamelService *service,
 	name = camel_service_get_name (service, TRUE);
 	camel_operation_push_message (cancellable, _("Connecting to '%s'"), name);
 
-	if (!camel_session_authenticate_sync (session, service, NULL, cancellable, error)) {
+	e_mapi_util_profiledata_from_settings (&empd, CAMEL_MAPI_SETTINGS (camel_service_get_settings (service)));
+
+	if (!camel_session_authenticate_sync (session, service, empd.krb_sso ? "MAPIKRB" : NULL, cancellable, error)) {
 		camel_operation_pop_message (cancellable);
 		camel_service_disconnect_sync (service, TRUE, cancellable, NULL);
 		g_free (name);
@@ -2534,20 +2541,20 @@ mapi_authenticate_sync (CamelService *service,
 	profile = camel_mapi_settings_get_profile (mapi_settings);
 
 	if (empd.krb_sso) {
-		if (e_mapi_util_trigger_krb_auth (&empd, error))
-			return CAMEL_AUTHENTICATION_ACCEPTED;
-		else
+		if (!e_mapi_util_trigger_krb_auth (&empd, error))
 			return CAMEL_AUTHENTICATION_ERROR;
-	}
 
-	password = camel_service_get_password (service);
+		password = NULL;
+	} else {
+		password = camel_service_get_password (service);
 
-	if (password == NULL) {
-		g_set_error_literal (
-			error, CAMEL_SERVICE_ERROR,
-			CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
-			_("Authentication password not available"));
-		return CAMEL_AUTHENTICATION_ERROR;
+		if (password == NULL) {
+			g_set_error_literal (
+				error, CAMEL_SERVICE_ERROR,
+				CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
+				_("Authentication password not available"));
+			return CAMEL_AUTHENTICATION_ERROR;
+		}
 	}
 
 	password_str = g_string_new (password);
diff --git a/src/configuration/e-mail-config-mapi-backend.c b/src/configuration/e-mail-config-mapi-backend.c
index 8954a50..cca84df 100644
--- a/src/configuration/e-mail-config-mapi-backend.c
+++ b/src/configuration/e-mail-config-mapi-backend.c
@@ -298,7 +298,7 @@ mail_config_mapi_authenticator_try_password_sync (ESourceAuthenticator *auth,
 	EMailConfigMapiAuthenticator *mapi_authenticator = (EMailConfigMapiAuthenticator *) auth;
 	EMailConfigServicePage *page;
 	ESourceRegistry *registry;
-	EMapiProfileData empd;
+	EMapiProfileData empd = { 0 };
 	GError *mapi_error = NULL;
 
 	empd.username = mapi_authenticator->username;
@@ -415,7 +415,7 @@ validate_credentials_thread (GObject *button,
 
 	if (mapi_authenticator->krb_sso) {
 		GError *error = NULL;
-		EMapiProfileData empd;
+		EMapiProfileData empd = { 0 };
 
 		empd.username = mapi_authenticator->username;
 		empd.domain = mapi_authenticator->domain;
diff --git a/src/configuration/e-mapi-config-utils.c b/src/configuration/e-mapi-config-utils.c
index 66a471e..ac2afb6 100644
--- a/src/configuration/e-mapi-config-utils.c
+++ b/src/configuration/e-mapi-config-utils.c
@@ -265,7 +265,7 @@ mapi_config_utils_authenticator_try_password_sync (ESourceAuthenticator *auth,
 						   GError **error)
 {
 	EMapiConfigUtilsAuthenticator *authenticator = (EMapiConfigUtilsAuthenticator *) auth;
-	EMapiProfileData empd;
+	EMapiProfileData empd = { 0 };
 	CamelNetworkSettings *network_settings;
 	GError *mapi_error = NULL;
 
diff --git a/src/libexchangemapi/e-mapi-connection.c b/src/libexchangemapi/e-mapi-connection.c
index 134a4bc..0da0030 100644
--- a/src/libexchangemapi/e-mapi-connection.c
+++ b/src/libexchangemapi/e-mapi-connection.c
@@ -6726,7 +6726,7 @@ mapi_profile_create (struct mapi_context *mapi_ctx,
 	}
 
 	/*We need all the params before proceeding.*/
-	e_return_val_mapi_error_if_fail (COMPLETE_PROFILEDATA (empd) && empd->password && empd->password->len,
+	e_return_val_mapi_error_if_fail (COMPLETE_PROFILEDATA (empd) && (empd->krb_sso || (empd->password && empd->password->len)),
 					 MAPI_E_INVALID_PARAMETER, FALSE);
 
 	if (use_locking)
@@ -6742,7 +6742,7 @@ mapi_profile_create (struct mapi_context *mapi_ctx,
 	/* don't bother to check error - it would be valid if we got an error */
 
 	ms = CreateProfile (mapi_ctx, profname, empd->username,
-			    empd->password->str, OC_PROFILE_NOPASSWORD);
+			    empd->krb_sso ? NULL : empd->password->str, OC_PROFILE_NOPASSWORD);
 	if (ms != MAPI_E_SUCCESS) {
 		make_mapi_error (perror, "CreateProfile", ms);
 		goto cleanup;
@@ -6774,7 +6774,7 @@ mapi_profile_create (struct mapi_context *mapi_ctx,
 
 	/* Login now */
 	e_mapi_debug_print("Logging into the server... ");
-	ms = MapiLogonProvider (mapi_ctx, &session, profname, empd->password->str,
+	ms = MapiLogonProvider (mapi_ctx, &session, profname, empd->krb_sso ? NULL : empd->password->str,
 				PROVIDER_ID_NSPI);
 	if (ms != MAPI_E_SUCCESS) {
 		make_mapi_error (perror, "MapiLogonProvider", ms);



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