[gnome-online-accounts/wip/kerberos: 6/7] provider squash



commit 08f4b2d2aedbafbd682e5dff7f63ea91563717e7
Author: Ray Strode <rstrode redhat com>
Date:   Tue Aug 14 13:50:22 2012 -0400

    provider squash

 src/goabackend/goakerberosprovider.c |   51 ++++++++++++++++++++++++++++++++-
 1 files changed, 49 insertions(+), 2 deletions(-)
---
diff --git a/src/goabackend/goakerberosprovider.c b/src/goabackend/goakerberosprovider.c
index f7b8a06..1b8b75b 100644
--- a/src/goabackend/goakerberosprovider.c
+++ b/src/goabackend/goakerberosprovider.c
@@ -364,6 +364,7 @@ on_identity_manager_ensured_for_sign_in (GoaKerberosProvider *self,
 {
   GoaIdentityManager *manager;
   const char         *identity;
+  const char         *password;
   GCancellable       *cancellable;
   GError             *error;
   GVariantBuilder     details;
@@ -385,10 +386,14 @@ on_identity_manager_ensured_for_sign_in (GoaKerberosProvider *self,
   }
 
   cancellable = g_object_get_data (G_OBJECT (operation_result), "cancellable");
+  password = g_object_get_data (G_OBJECT (operation_result), "password");
   identity = g_simple_async_result_get_source_tag (operation_result);
 
   g_variant_builder_init (&details, G_VARIANT_TYPE ("a{ss}"));
 
+  if (password != NULL)
+    g_variant_builder_add (&details, "{ss}", "initial-password", password);
+
   goa_identity_manager_call_sign_in (self->identity_manager,
                                      identity,
                                      g_variant_builder_end (&details),
@@ -401,6 +406,7 @@ on_identity_manager_ensured_for_sign_in (GoaKerberosProvider *self,
 static void
 sign_in_identity (GoaKerberosProvider  *self,
                   const char           *identity,
+                  const char           *password,
                   GCancellable         *cancellable,
                   GAsyncReadyCallback   callback,
                   gpointer              user_data)
@@ -418,6 +424,10 @@ sign_in_identity (GoaKerberosProvider  *self,
   g_object_set_data (G_OBJECT (operation_result),
                      "cancellable",
                      cancellable);
+  g_object_set_data (G_OBJECT (operation_result),
+                     "password",
+                     (gpointer)
+                     password);
 
   ensure_identity_manager (self,
                            cancellable,
@@ -470,6 +480,7 @@ refresh_account (GoaProvider    *provider,
   sign_in_identity (self,
                     identity,
                     NULL,
+                    NULL,
                     (GAsyncReadyCallback)
                     on_account_signed_in,
                     &request);
@@ -584,6 +595,7 @@ start_over:
   sign_in_identity (self,
                     principal,
                     NULL,
+                    NULL,
                     (GAsyncReadyCallback)
                     on_account_signed_in,
                     &request);
@@ -664,13 +676,42 @@ ensure_credentials_sync (GoaProvider         *provider,
                          GError             **error)
 {
   GoaKerberosProvider *self = GOA_KERBEROS_PROVIDER (provider);
+  GVariant            *credentials;
   GoaAccount          *account;
   const char          *identity;
+  const char          *password;
   SignInRequest        request;
+  gboolean             ret;
+
+  ret = FALSE;
 
   account = goa_object_peek_account (object);
   identity = goa_account_get_identity (account);
 
+  credentials = goa_utils_lookup_credentials_sync (provider,
+                                                   object,
+                                                   cancellable,
+                                                   error);
+  if (credentials == NULL)
+    {
+      if (error != NULL && *error == NULL)
+        g_set_error (error,
+                     GOA_ERROR,
+                     GOA_ERROR_NOT_AUTHORIZED,
+                     _("Could not find saved credentials for principal `%s' in keyring"), identity);
+      goto out;
+    }
+
+  if (!g_variant_lookup (credentials, "password", "&s", &password))
+    {
+      g_set_error (error,
+                   GOA_ERROR,
+                   GOA_ERROR_NOT_AUTHORIZED,
+                   _("Did not find password for principal `%s' in credentials"),
+                   identity);
+      goto out;
+    }
+
   memset (&request, 0, sizeof (SignInRequest));
   request.loop = g_main_loop_new (NULL, FALSE);
   request.error = NULL;
@@ -678,6 +719,8 @@ ensure_credentials_sync (GoaProvider         *provider,
   error = NULL;
   sign_in_identity (self,
                     identity,
+                    password,
+
                     NULL,
                     (GAsyncReadyCallback)
                     on_account_signed_in,
@@ -689,12 +732,16 @@ ensure_credentials_sync (GoaProvider         *provider,
   if (request.error != NULL)
     {
       g_propagate_error (error, request.error);
-      return FALSE;
+      goto out;
     }
 
   *out_expires_in = -1;
+  ret = TRUE;
+out:
+  if (credentials != NULL)
+    g_variant_unref (credentials);
 
-  return TRUE;
+  return ret;
 }
 
 static void



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