[gnome-online-accounts/wip/kerberos: 6/6] stuff to squash



commit a1fd7ed45e719b48a1f54d5ba347d4581acc8648
Author: Ray Strode <rstrode redhat com>
Date:   Thu Aug 16 00:40:46 2012 -0400

    stuff to squash

 src/goabackend/goakerberosprovider.c         |   14 ++++--
 src/goaidentity/goaidentity.h                |    1 +
 src/goaidentity/goaidentityservice.c         |   24 ++++++---
 src/goaidentity/goakerberosidentity.c        |   70 ++++++++++++++++---------
 src/goaidentity/goakerberosidentitymanager.c |    9 +++
 5 files changed, 80 insertions(+), 38 deletions(-)
---
diff --git a/src/goabackend/goakerberosprovider.c b/src/goabackend/goakerberosprovider.c
index 9fd8b92..11d0ba7 100644
--- a/src/goabackend/goakerberosprovider.c
+++ b/src/goabackend/goakerberosprovider.c
@@ -29,6 +29,7 @@
 #include "goakerberosprovider.h"
 #include "goaeditablelabel.h"
 #include "goautils.h"
+#include "goaidentity.h"
 
 #include "org.gnome.Identity.h"
 
@@ -101,8 +102,8 @@ typedef struct
 
 static void
 on_identity_signed_in (GoaIdentityServiceManager *manager,
-                       GAsyncResult       *result,
-                       GSimpleAsyncResult *operation_result)
+                       GAsyncResult              *result,
+                       GSimpleAsyncResult        *operation_result)
 {
   gboolean  signed_in;
   GError   *error;
@@ -116,6 +117,8 @@ on_identity_signed_in (GoaIdentityServiceManager *manager,
 
   if (!signed_in)
     {
+      g_warning ("*************  error %s", g_dbus_error_get_remote_error (error));
+      g_dbus_error_strip_remote_error (error);
       g_simple_async_result_take_error (operation_result, error);
       g_simple_async_result_complete_in_idle (operation_result);
       g_object_unref (operation_result);
@@ -142,6 +145,7 @@ on_identity_manager_ensured (GoaKerberosProvider *self,
   manager = goa_identity_service_manager_proxy_new_for_bus_finish (result, &error);
   if (manager == NULL)
     {
+      g_dbus_error_strip_remote_error (error);
       g_simple_async_result_take_error (operation_result, error);
       g_simple_async_result_complete_in_idle (operation_result);
       g_object_unref (operation_result);
@@ -207,6 +211,7 @@ on_object_manager_ensured (GoaKerberosProvider *self,
   manager = goa_identity_service_object_manager_client_new_for_bus_finish (result, &error);
   if (manager == NULL)
     {
+      g_dbus_error_strip_remote_error (error);
       g_simple_async_result_take_error (operation_result, error);
       g_simple_async_result_complete_in_idle (operation_result);
       g_object_unref (operation_result);
@@ -475,7 +480,7 @@ get_ticket_sync (GoaKerberosProvider *self,
     {
       if (credentials == NULL)
         {
-          if (lookup_error == NULL)
+          if (lookup_error != NULL)
               g_propagate_error (error, lookup_error);
           else
               g_set_error (error,
@@ -728,6 +733,8 @@ add_account_cb (GoaManager *manager, GAsyncResult *res, gpointer user_request)
                                        &request->account_object_path,
                                        res,
                                        &request->error);
+  if (request->error != NULL)
+    g_dbus_error_strip_remote_error (request->error);
   g_main_loop_quit (request->loop);
 }
 
@@ -747,7 +754,6 @@ refresh_account (GoaProvider    *provider,
   g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-  error = NULL;
   got_ticket = get_ticket_sync (self,
                                 object,
                                 TRUE /* Allow interaction */,
diff --git a/src/goaidentity/goaidentity.h b/src/goaidentity/goaidentity.h
index 5ede717..acb4af1 100644
--- a/src/goaidentity/goaidentity.h
+++ b/src/goaidentity/goaidentity.h
@@ -56,6 +56,7 @@ typedef enum
   GOA_IDENTITY_ERROR_SAVING_CREDENTIALS,
   GOA_IDENTITY_ERROR_REMOVING_CREDENTIALS,
   GOA_IDENTITY_ERROR_PARSING_IDENTIFIER,
+  GOA_IDENTITY_ERROR_USER_CANCELLED,
 } GoaIdentityError;
 
 typedef enum
diff --git a/src/goaidentity/goaidentityservice.c b/src/goaidentity/goaidentityservice.c
index d3ec342..9520187 100644
--- a/src/goaidentity/goaidentityservice.c
+++ b/src/goaidentity/goaidentityservice.c
@@ -31,6 +31,7 @@
 #include <gcr/gcr.h>
 
 #include "goakerberosprovider.h"
+#include "goaidentityenumtypes.h"
 #include "goaidentityutils.h"
 
 #include "goakerberosidentitymanager.h"
@@ -575,7 +576,7 @@ on_identity_signed_in (GoaIdentityManager *manager,
   if (error != NULL)
     {
       goa_debug ("GoaIdentityService: could not sign in identity: %s",
-               error->message);
+                 error->message);
       g_simple_async_result_take_error (operation_result, error);
     }
   else
@@ -631,6 +632,7 @@ on_account_added (GoaManager         *manager,
 
   self = GOA_IDENTITY_SERVICE (g_async_result_get_source_object (G_ASYNC_RESULT (operation_result)));
   object_path = NULL;
+  object = NULL;
   error = NULL;
 
   if (!goa_manager_call_add_account_finish (manager,
@@ -644,16 +646,16 @@ on_account_added (GoaManager         *manager,
       return;
     }
 
-  if (object_path != NULL)
+  if (object_path != NULL && object_path[0] != '\0')
     {
       goa_debug ("Created account for identity with object path %s", object_path);
+
+      object_manager = goa_client_get_object_manager (self->priv->client);
+      object = GOA_OBJECT (g_dbus_object_manager_get_object (object_manager,
+                                                             object_path));
       g_free (object_path);
     }
 
-  object_manager = goa_client_get_object_manager (self->priv->client);
-  object = GOA_OBJECT (g_dbus_object_manager_get_object (object_manager,
-                                                         object_path));
-
   if (object == NULL)
     g_simple_async_result_set_op_res_gpointer (operation_result, NULL, NULL);
   else
@@ -755,8 +757,8 @@ on_identity_refreshed (GoaIdentityManager *identity_manager,
 
   if (object == NULL)
     add_temporary_account (self, identity);
-
-  ensure_account_credentials (self, object);
+  else
+    ensure_account_credentials (self, object);
 }
 
 typedef struct
@@ -1010,7 +1012,8 @@ on_identity_inquiry (GoaIdentityInquiry *inquiry,
   gcr_system_prompt_open_async (-1,
                                 cancellable,
                                 (GAsyncReadyCallback)
-                                on_system_prompt_open, request);
+                                on_system_prompt_open,
+                                request);
 }
 
 static void
@@ -1535,6 +1538,9 @@ goa_identity_service_class_init (GoaIdentityServiceClass *service_class)
 
   object_class->finalize = goa_identity_service_finalize;
 
+  goa_identity_utils_register_error_domain (GOA_IDENTITY_ERROR, GOA_TYPE_IDENTITY_ERROR);
+  goa_identity_utils_register_error_domain (GOA_IDENTITY_MANAGER_ERROR, GOA_TYPE_IDENTITY_MANAGER_ERROR);
+
   g_type_class_add_private (service_class, sizeof (GoaIdentityServicePrivate));
 }
 
diff --git a/src/goaidentity/goakerberosidentity.c b/src/goaidentity/goakerberosidentity.c
index 81ff5d0..dc3e9aa 100644
--- a/src/goaidentity/goakerberosidentity.c
+++ b/src/goaidentity/goakerberosidentity.c
@@ -988,10 +988,11 @@ on_kerberos_inquiry (krb5_context      kerberos_context,
                            operation->cancellable,
                            operation->inquiry_data);
 
+  if (!goa_identity_inquiry_is_complete (inquiry))
+    g_cancellable_cancel (operation->cancellable);
+
   if (g_cancellable_is_cancelled (operation->cancellable))
     error_code = KRB5_LIBOS_PWDINTR;
-  else if (!goa_identity_inquiry_is_complete (inquiry))
-    error_code = KRB5_LIBOS_PWDINTR;
   else
     error_code = 0;
 
@@ -1048,10 +1049,11 @@ out:
 }
 
 static SignInOperation *
-sign_in_operation_new (GoaKerberosIdentity *identity,
-                       GoaIdentityInquiryFunc inquiry_func,
-                       gpointer inquiry_data,
-                       GDestroyNotify destroy_notify, GCancellable *cancellable)
+sign_in_operation_new (GoaKerberosIdentity    *identity,
+                       GoaIdentityInquiryFunc  inquiry_func,
+                       gpointer                inquiry_data,
+                       GDestroyNotify          destroy_notify,
+                       GCancellable           *cancellable)
 {
   SignInOperation *operation;
 
@@ -1079,14 +1081,15 @@ sign_in_operation_free (SignInOperation *operation)
 }
 
 gboolean
-goa_kerberos_identity_sign_in (GoaKerberosIdentity *self,
-                               const char *principal_name,
-                               gconstpointer initial_password,
-                               GoaIdentitySignInFlags flags,
-                               GoaIdentityInquiryFunc inquiry_func,
-                               gpointer inquiry_data,
-                               GDestroyNotify destroy_notify,
-                               GCancellable *cancellable, GError **error)
+goa_kerberos_identity_sign_in (GoaKerberosIdentity     *self,
+                               const char              *principal_name,
+                               gconstpointer            initial_password,
+                               GoaIdentitySignInFlags   flags,
+                               GoaIdentityInquiryFunc   inquiry_func,
+                               gpointer                 inquiry_data,
+                               GDestroyNotify           destroy_notify,
+                               GCancellable            *cancellable,
+                               GError                 **error)
 {
   SignInOperation *operation;
   krb5_principal principal;
@@ -1098,9 +1101,7 @@ goa_kerberos_identity_sign_in (GoaKerberosIdentity *self,
   gboolean signed_in;
 
   if (g_cancellable_set_error_if_cancelled (cancellable, error))
-    {
-      return FALSE;
-    }
+    return FALSE;
 
   error_code = krb5_get_init_creds_opt_alloc (self->priv->kerberos_context,
                                               &options);
@@ -1111,9 +1112,7 @@ goa_kerberos_identity_sign_in (GoaKerberosIdentity *self,
                                       GOA_IDENTITY_ERROR_ALLOCATING_CREDENTIALS,
                                       error_code, "%k");
       if (destroy_notify)
-        {
-          destroy_notify (inquiry_data);
-        }
+        destroy_notify (inquiry_data);
       return FALSE;
     }
 
@@ -1132,14 +1131,16 @@ goa_kerberos_identity_sign_in (GoaKerberosIdentity *self,
     }
 
   error_code = krb5_parse_name (self->priv->kerberos_context,
-                                principal_name, &principal);
+                                principal_name,
+                                &principal);
 
   if (error_code != 0)
     {
       set_error_from_krb5_error_code (self,
                                       error,
                                       GOA_IDENTITY_ERROR_PARSING_IDENTIFIER,
-                                      error_code, "%k");
+                                      error_code,
+                                      "%k");
       if (destroy_notify)
         destroy_notify (inquiry_data);
       return FALSE;
@@ -1167,12 +1168,27 @@ goa_kerberos_identity_sign_in (GoaKerberosIdentity *self,
                                              start_time,
                                              service_name,
                                              options);
+
+  if (error_code == KRB5_LIBOS_PWDINTR)
+    g_cancellable_cancel (operation->cancellable);
+
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    {
+      if (destroy_notify)
+        destroy_notify (inquiry_data);
+      sign_in_operation_free (operation);
+
+      krb5_free_principal (self->priv->kerberos_context, principal);
+      goto done;
+    }
+
   if (error_code != 0)
     {
       set_error_from_krb5_error_code (self,
                                       error,
                                       GOA_IDENTITY_ERROR_AUTHENTICATION_FAILED,
-                                      error_code, "%k");
+                                      error_code,
+                                      "%k");
       if (destroy_notify)
         destroy_notify (inquiry_data);
       sign_in_operation_free (operation);
@@ -1186,7 +1202,9 @@ goa_kerberos_identity_sign_in (GoaKerberosIdentity *self,
   sign_in_operation_free (operation);
 
   if (!goa_kerberos_identity_update_credentials (self,
-                                                 principal, &new_credentials, error))
+                                                 principal,
+                                                 &new_credentials,
+                                                 error))
     {
       krb5_free_principal (self->priv->kerberos_context, principal);
       goto done;
@@ -1324,7 +1342,9 @@ goa_kerberos_identity_renew (GoaKerberosIdentity *self, GError **error)
     }
 
   if (!goa_kerberos_identity_update_credentials (self,
-                                                 principal, &new_credentials, error))
+                                                 principal,
+                                                 &new_credentials,
+                                                 error))
     {
       krb5_free_principal (self->priv->kerberos_context, principal);
       goto out;
diff --git a/src/goaidentity/goakerberosidentitymanager.c b/src/goaidentity/goakerberosidentitymanager.c
index 607f1de..ed27a9a 100644
--- a/src/goaidentity/goakerberosidentitymanager.c
+++ b/src/goaidentity/goakerberosidentitymanager.c
@@ -823,6 +823,15 @@ sign_in_identity (GoaKerberosIdentityManager *self,
                                       operation->cancellable,
                                       &error))
     {
+      if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        {
+          g_clear_error (&error);
+          g_set_error_literal (&error,
+                               GOA_IDENTITY_ERROR,
+                               GOA_IDENTITY_ERROR_USER_CANCELLED,
+                               _("User cancelled"));
+        }
+
       g_simple_async_result_set_from_error (operation->result, error);
       g_simple_async_result_set_op_res_gpointer (operation->result,
                                                  NULL,



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