[evolution-ews/evolution-ews-3-12] Clean up enabling/disabling NTLM and Basic auth types



commit b329d80ab116114eea2df49b26ec9d4887987882
Author: David Woodhouse <David Woodhouse intel com>
Date:   Wed Jul 23 22:49:56 2014 +0100

    Clean up enabling/disabling NTLM and Basic auth types
    
    The use-ntlm property has been deprecated for ages. Use
    soup_session_add_feature_by_type() to enable NTLM instead. And use
    soup_session_disable_feature_by_type() to *disable* Basic auth, if we're
    not supposed to be using it. Otherwise, it gets in the way of our GSSAPI
    hacks.
    
    Leave Basic auth enabled for NTLM though, as it's a useful fallback
    there that people have been using.
    
    (cherry picked from commit b6ff74a490c9ec873224cc7ebd2afdcd35d385e1 and
     subsequent fixes in commit 377da62321797a9492de475aa1e59015bee487d1 and
     commit 2b586f551585e9db47ed6e8787892b5630b1c22e)

 src/server/e-ews-connection-utils.c |   20 +--------------
 src/server/e-ews-connection-utils.h |    5 ----
 src/server/e-ews-connection.c       |   42 +++++++++++++++++++++++--------
 src/server/e-ews-notification.c     |   46 ++++++++++++++++++++++++++--------
 4 files changed, 67 insertions(+), 46 deletions(-)
---
diff --git a/src/server/e-ews-connection-utils.c b/src/server/e-ews-connection-utils.c
index 1d1c91e..5d673b9 100644
--- a/src/server/e-ews-connection-utils.c
+++ b/src/server/e-ews-connection-utils.c
@@ -206,25 +206,7 @@ e_ews_connection_utils_unref_in_thread (gpointer object)
        g_thread_unref (thread);
 }
 
-gboolean
-e_ews_connection_utils_auth_mech_to_use_ntlm (GBinding *binding,
-                                             const GValue *source_value,
-                                             GValue *target_value,
-                                             gpointer user_data)
-{
-       const gchar *auth_mechanism;
-       gboolean use_ntlm;
-
-       /* Use NTLM unless the auth mechanism is "PLAIN" or "GSSAPI". */
-       auth_mechanism = g_value_get_string (source_value);
-       use_ntlm = g_strcmp0 (auth_mechanism, "PLAIN") != 0 &&
-                  g_strcmp0 (auth_mechanism, "GSSAPI") != 0;
-       g_value_set_boolean (target_value, use_ntlm);
-
-       return TRUE;
-}
-
-/* Do not call this directly, use E_EWS_CONNECTION_UTILS_CHECK_ELEMENT macro instead. */
+/* Do not call this directly; use E_EWS_CONNECTION_UTILS_CHECK_ELEMENT macro instead. */
 gboolean
 e_ews_connection_utils_check_element (const gchar *function_name,
                                      const gchar *element_name,
diff --git a/src/server/e-ews-connection-utils.h b/src/server/e-ews-connection-utils.h
index 12479ba..a640e6c 100644
--- a/src/server/e-ews-connection-utils.h
+++ b/src/server/e-ews-connection-utils.h
@@ -32,11 +32,6 @@ void         e_ews_connection_utils_setup_msg_gssapi_auth
                                                         SoupSession *session,
                                                         SoupMessage *message);
 void           e_ews_connection_utils_unref_in_thread  (gpointer object);
-gboolean       e_ews_connection_utils_auth_mech_to_use_ntlm
-                                                       (GBinding *binding,
-                                                        const GValue *source_value,
-                                                        GValue *target_value,
-                                                        gpointer user_data);
 gboolean       e_ews_connection_utils_check_element    (const gchar *function_name,
                                                         const gchar *element_name,
                                                         const gchar *expected_name);
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index bc7ae9d..b52d616 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -1648,6 +1648,35 @@ ews_connection_finalize (GObject *object)
        G_OBJECT_CLASS (e_ews_connection_parent_class)->finalize (object);
 }
 
+static GObject *
+ews_connection_constructor (GType gtype, guint n_properties,
+                           GObjectConstructParam *properties)
+{
+       GObject *obj = G_OBJECT_CLASS (e_ews_connection_parent_class)->
+               constructor (gtype, n_properties, properties);
+       EEwsConnection *cnc = E_EWS_CONNECTION (obj);
+       CamelEwsSettings *ews_settings = e_ews_connection_ref_settings (cnc);
+       gchar *auth_mech = NULL;
+
+       g_object_get (G_OBJECT (ews_settings), "auth-mechanism", &auth_mech,
+                     NULL);
+
+       /* We need to disable Basic auth to avoid it getting in the way of
+        * our GSSAPI hacks. But leave it enabled in the case where NTLM is
+        * enabled, which is the default configuration. It's a useful fallback
+        * which people may be relying on. */
+       if (g_strcmp0 (auth_mech, "GSSAPI") == 0)
+               soup_session_remove_feature_by_type (cnc->priv->soup_session,
+                                                    SOUP_TYPE_AUTH_BASIC);
+       else if (g_strcmp0 (auth_mech, "PLAIN") != 0) /* NTLM */
+               soup_session_add_feature_by_type (cnc->priv->soup_session,
+                                                 SOUP_TYPE_AUTH_NTLM);
+       g_free (auth_mech);
+       g_object_unref(ews_settings);
+
+       return obj;
+}
+
 static ESourceAuthenticationResult
 ews_connection_try_password_sync (ESourceAuthenticator *authenticator,
                                   const GString *password,
@@ -1706,6 +1735,7 @@ e_ews_connection_class_init (EEwsConnectionClass *class)
        g_type_class_add_private (class, sizeof (EEwsConnectionPrivate));
 
        object_class = G_OBJECT_CLASS (class);
+       object_class->constructor = ews_connection_constructor;
        object_class->set_property = ews_connection_set_property;
        object_class->get_property = ews_connection_get_property;
        object_class->dispose = ews_connection_dispose;
@@ -1844,9 +1874,7 @@ e_ews_connection_init (EEwsConnection *cnc)
        cnc->priv->soup_thread = g_thread_new (NULL, e_ews_soup_thread, cnc);
 
        cnc->priv->soup_session = soup_session_async_new_with_options (
-               SOUP_SESSION_USE_NTLM, TRUE,
-               SOUP_SESSION_ASYNC_CONTEXT,
-               cnc->priv->soup_context,
+               SOUP_SESSION_ASYNC_CONTEXT, cnc->priv->soup_context,
                NULL);
 
        /* Do not use G_BINDING_SYNC_CREATE because the property_lock is
@@ -2233,14 +2261,6 @@ e_ews_connection_new_full (const gchar *uri,
                cnc->priv->impersonate_user = NULL;
        }
 
-       g_object_bind_property_full (
-               settings, "auth-mechanism",
-               cnc->priv->soup_session, "use-ntlm",
-               G_BINDING_SYNC_CREATE,
-               e_ews_connection_utils_auth_mech_to_use_ntlm,
-               NULL,
-               NULL, (GDestroyNotify) NULL);
-
        g_object_bind_property (
                settings, "timeout",
                cnc->priv->soup_session, "timeout",
diff --git a/src/server/e-ews-notification.c b/src/server/e-ews-notification.c
index 2198978..9721576 100644
--- a/src/server/e-ews-notification.c
+++ b/src/server/e-ews-notification.c
@@ -123,14 +123,6 @@ e_ews_notification_new (EEwsConnection *connection)
 
        ews_settings = e_ews_connection_ref_settings (connection);
 
-       g_object_bind_property_full (
-               ews_settings, "auth-mechanism",
-               notification->priv->soup_session, "use-ntlm",
-               G_BINDING_SYNC_CREATE,
-               e_ews_connection_utils_auth_mech_to_use_ntlm,
-               NULL,
-               NULL, (GDestroyNotify) NULL);
-
        g_object_unref (ews_settings);
 
        return notification;
@@ -226,6 +218,39 @@ ews_notification_dispose (GObject *object)
        G_OBJECT_CLASS (e_ews_notification_parent_class)->dispose (object);
 }
 
+static GObject *
+ews_notification_constructor (GType gtype, guint n_properties,
+                             GObjectConstructParam *properties)
+{
+       GObject *obj = G_OBJECT_CLASS (e_ews_notification_parent_class)->
+               constructor (gtype, n_properties, properties);
+       EEwsNotificationPrivate *priv;
+       CamelEwsSettings *ews_settings;
+       gchar *auth_mech = NULL;
+
+       priv = E_EWS_NOTIFICATION_GET_PRIVATE (obj);
+
+       ews_settings = e_ews_connection_ref_settings (priv->connection);
+
+       g_object_get (G_OBJECT (ews_settings), "auth-mechanism", &auth_mech,
+                     NULL);
+
+       /* We need to disable Basic auth to avoid it getting in the way of
+        * our GSSAPI hacks. But leave it enabled in the case where NTLM is
+        * enabled, which is the default configuration. It's a useful fallback
+        * which people may be relying on. */
+       if (g_strcmp0 (auth_mech, "GSSAPI") == 0)
+               soup_session_remove_feature_by_type (priv->soup_session,
+                                                    SOUP_TYPE_AUTH_BASIC);
+       else if (g_strcmp0 (auth_mech, "PLAIN") != 0) /* NTLM */
+               soup_session_add_feature_by_type (priv->soup_session,
+                                                 SOUP_TYPE_AUTH_NTLM);
+       g_free (auth_mech);
+       g_object_unref(ews_settings);
+
+       return obj;
+}
+
 static void
 e_ews_notification_class_init (EEwsNotificationClass *class)
 {
@@ -234,6 +259,7 @@ e_ews_notification_class_init (EEwsNotificationClass *class)
        g_type_class_add_private (class, sizeof (EEwsNotificationPrivate));
 
        object_class = G_OBJECT_CLASS (class);
+       object_class->constructor = ews_notification_constructor;
        object_class->set_property = ews_notification_set_property;
        object_class->get_property = ews_notification_get_property;
        object_class->dispose = ews_notification_dispose;
@@ -258,9 +284,7 @@ e_ews_notification_init (EEwsNotification *notification)
 
        notification->priv = E_EWS_NOTIFICATION_GET_PRIVATE (notification);
 
-       notification->priv->soup_session = soup_session_sync_new_with_options (
-               SOUP_SESSION_USE_NTLM, TRUE,
-               NULL);
+       notification->priv->soup_session = soup_session_sync_new ();
 
        soup_session_add_feature_by_type (notification->priv->soup_session,
                                          SOUP_TYPE_COOKIE_JAR);


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