[gnome-initial-setup] account: Make kerberos kinit for enterprise login cancellable



commit 553d0604ad13a250b68eba64b4ae5bb44e4abb67
Author: Stef Walter <stefw redhat com>
Date:   Sun May 26 14:14:33 2013 +0200

    account: Make kerberos kinit for enterprise login cancellable
    
    Migrate to GTask in order to accomplish this.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=701039

 configure.ac                                       |    4 +-
 .../pages/account/gis-account-page.c               |    2 +-
 .../pages/account/um-realm-manager.c               |   60 ++++++++++----------
 .../pages/account/um-realm-manager.h               |    3 +-
 4 files changed, 36 insertions(+), 33 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0fed0d5..41b9a4b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -15,7 +15,7 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [gettext package])
 AM_GLIB_GNU_GETTEXT
 
 NETWORK_MANAGER_REQUIRED_VERSION=0.9.6.4
-GLIB_REQUIRED_VERSION=2.29.4
+GLIB_REQUIRED_VERSION=2.36.0
 GTK_REQUIRED_VERSION=3.7.11
 PANGO_REQUIRED_VERSION=1.32.5
 IBUS_REQUIRED_VERSION=1.4.99
@@ -96,7 +96,7 @@ ISO_CODES=iso-codes
 
 LIBGD_INIT([stack static])
 
-GLIB_VERSION_DEFINES="-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_30 
'-DGLIB_VERSION_MAX_ALLOWED=G_ENCODE_VERSION(2,34)'"
+GLIB_VERSION_DEFINES="-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_36 
'-DGLIB_VERSION_MAX_ALLOWED=G_ENCODE_VERSION(2,36)'"
 
 INITIAL_SETUP_CFLAGS="$INITIAL_SETUP_CFLAGS $GLIB_VERSION_DEFINES"
 
diff --git a/gnome-initial-setup/pages/account/gis-account-page.c 
b/gnome-initial-setup/pages/account/gis-account-page.c
index 662652f..a8b40d5 100644
--- a/gnome-initial-setup/pages/account/gis-account-page.c
+++ b/gnome-initial-setup/pages/account/gis-account-page.c
@@ -647,7 +647,7 @@ on_realm_login (GObject *source,
   GError *error = NULL;
   GBytes *creds = NULL;
 
-  um_realm_login_finish (result, &creds, &error);
+  um_realm_login_finish (realm, result, &creds, &error);
 
   /*
    * User login is valid, but cannot authenticate right now (eg: user needs
diff --git a/gnome-initial-setup/pages/account/um-realm-manager.c 
b/gnome-initial-setup/pages/account/um-realm-manager.c
index 4329b1b..0b0fe15 100644
--- a/gnome-initial-setup/pages/account/um-realm-manager.c
+++ b/gnome-initial-setup/pages/account/um-realm-manager.c
@@ -763,11 +763,12 @@ login_perform_kinit (krb5_context k5,
 }
 
 static void
-kinit_thread_func (GSimpleAsyncResult *async,
-                   GObject *object,
+kinit_thread_func (GTask *task,
+                   gpointer source_object,
+                   gpointer task_data,
                    GCancellable *cancellable)
 {
-        LoginClosure *login = g_simple_async_result_get_op_res_gpointer (async);
+        LoginClosure *login = task_data;
         krb5_context k5 = NULL;
         krb5_error_code code;
         GError *error = NULL;
@@ -807,32 +808,33 @@ kinit_thread_func (GSimpleAsyncResult *async,
                                 g_error_free (error);
                         }
                 }
+                g_task_return_boolean (task, TRUE);
                 break;
 
         case KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN:
         case KRB5KDC_ERR_POLICY:
-                g_simple_async_result_set_error (async, UM_REALM_ERROR, UM_REALM_ERROR_BAD_LOGIN,
-                                                 _("Cannot log in as %s at the %s domain"),
-                                                 login->user, login->domain);
+                g_task_return_new_error (task, UM_REALM_ERROR, UM_REALM_ERROR_BAD_LOGIN,
+                                         _("Cannot log in as %s at the %s domain"),
+                                         login->user, login->domain);
                 break;
         case KRB5KDC_ERR_PREAUTH_FAILED:
         case KRB5KRB_AP_ERR_BAD_INTEGRITY:
-                g_simple_async_result_set_error (async, UM_REALM_ERROR, UM_REALM_ERROR_BAD_PASSWORD,
-                                                 _("Invalid password, please try again"));
+                g_task_return_new_error (task, UM_REALM_ERROR, UM_REALM_ERROR_BAD_PASSWORD,
+                                         _("Invalid password, please try again"));
                 break;
         case KRB5_PREAUTH_FAILED:
         case KRB5KDC_ERR_KEY_EXP:
         case KRB5KDC_ERR_CLIENT_REVOKED:
         case KRB5KDC_ERR_ETYPE_NOSUPP:
         case KRB5_PROG_ETYPE_NOSUPP:
-                g_simple_async_result_set_error (async, UM_REALM_ERROR, UM_REALM_ERROR_CANNOT_AUTH,
-                                                 _("Cannot log in as %s at the %s domain"),
-                                                 login->user, login->domain);
+                g_task_return_new_error (task, UM_REALM_ERROR, UM_REALM_ERROR_CANNOT_AUTH,
+                                         _("Cannot log in as %s at the %s domain"),
+                                         login->user, login->domain);
                 break;
         default:
-                g_simple_async_result_set_error (async, UM_REALM_ERROR, UM_REALM_ERROR_GENERIC,
-                                                 _("Couldn't connect to the %s domain: %s"),
-                                                 login->domain, krb5_get_error_message (k5, code));
+                g_task_return_new_error (task, UM_REALM_ERROR, UM_REALM_ERROR_GENERIC,
+                                         _("Couldn't connect to the %s domain: %s"),
+                                         login->domain, krb5_get_error_message (k5, code));
                 break;
         }
 
@@ -854,7 +856,7 @@ um_realm_login (UmRealmObject *realm,
                 GAsyncReadyCallback callback,
                 gpointer user_data)
 {
-        GSimpleAsyncResult *async;
+        GTask *task;
         LoginClosure *login;
         UmRealmKerberos *kerberos;
 
@@ -866,40 +868,40 @@ um_realm_login (UmRealmObject *realm,
         kerberos = um_realm_object_get_kerberos (realm);
         g_return_if_fail (kerberos != NULL);
 
-        async = g_simple_async_result_new (NULL, callback, user_data,
-                                           um_realm_login);
+        task = g_task_new (realm, cancellable, callback, user_data);
         login = g_slice_new0 (LoginClosure);
         login->domain = g_strdup (um_realm_kerberos_get_domain_name (kerberos));
         login->realm = g_strdup (um_realm_kerberos_get_realm_name (kerberos));
         login->user = g_strdup (user);
         login->password = g_strdup (password);
-        g_simple_async_result_set_op_res_gpointer (async, login, login_closure_free);
+        g_task_set_task_data (task, login, login_closure_free);
 
-        g_simple_async_result_set_handle_cancellation (async, TRUE);
-        g_simple_async_result_run_in_thread (async, kinit_thread_func,
-                                             G_PRIORITY_DEFAULT, cancellable);
+        g_task_set_check_cancellable (task, TRUE);
+        g_task_set_return_on_cancel (task, TRUE);
 
-        g_object_unref (async);
+        g_task_run_in_thread (task, kinit_thread_func);
+
+        g_object_unref (task);
         g_object_unref (kerberos);
 }
 
 gboolean
-um_realm_login_finish (GAsyncResult *result,
+um_realm_login_finish (UmRealmObject *realm,
+                       GAsyncResult *result,
                        GBytes **credentials,
                        GError **error)
 {
-        GSimpleAsyncResult *async;
+        GTask *task;
         LoginClosure *login;
 
-        g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL,
-                              um_realm_login), FALSE);
+        g_return_val_if_fail (g_task_is_valid (result, realm), FALSE);
         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-        async = G_SIMPLE_ASYNC_RESULT (result);
-        if (g_simple_async_result_propagate_error (async, error))
+        task = G_TASK (result);
+        if (!g_task_propagate_boolean (task, error))
                 return FALSE;
 
-        login = g_simple_async_result_get_op_res_gpointer (async);
+        login = g_task_get_task_data (task);
         if (credentials) {
                 if (login->credentials)
                         *credentials = g_bytes_ref (login->credentials);
diff --git a/gnome-initial-setup/pages/account/um-realm-manager.h 
b/gnome-initial-setup/pages/account/um-realm-manager.h
index 0c09152..6b7a47a 100644
--- a/gnome-initial-setup/pages/account/um-realm-manager.h
+++ b/gnome-initial-setup/pages/account/um-realm-manager.h
@@ -71,7 +71,8 @@ void             um_realm_login                   (UmRealmObject *realm,
                                                    GAsyncReadyCallback callback,
                                                    gpointer user_data);
 
-gboolean         um_realm_login_finish            (GAsyncResult *result,
+gboolean         um_realm_login_finish            (UmRealmObject *realm,
+                                                   GAsyncResult *result,
                                                    GBytes **credentials,
                                                    GError **error);
 


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