[gnome-online-accounts] Remove the credentials from the keyring when an account is removed
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts] Remove the credentials from the keyring when an account is removed
- Date: Fri, 23 Mar 2012 11:08:33 +0000 (UTC)
commit 4f85170591f1230e06414e8e3c3210289cb79ac3
Author: Debarshi Ray <debarshir gnome org>
Date: Thu Mar 22 07:24:23 2012 +0100
Remove the credentials from the keyring when an account is removed
A new convenience method goa_provider_delete_credentials_sync has been
added.
Fixes: https://bugzilla.gnome.org/654168
src/daemon/goadaemon.c | 40 ++++++++++++++++++++++++-
src/goabackend/goaprovider.c | 67 ++++++++++++++++++++++++++++++++++++++++++
src/goabackend/goaprovider.h | 4 ++
3 files changed, 110 insertions(+), 1 deletions(-)
---
diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c
index 201d922..ccdf35d 100644
--- a/src/daemon/goadaemon.c
+++ b/src/daemon/goadaemon.c
@@ -1,6 +1,6 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
- * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2011, 2012 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -939,13 +939,17 @@ on_account_handle_remove (GoaAccount *account,
gpointer user_data)
{
GoaDaemon *daemon = GOA_DAEMON (user_data);
+ GoaProvider *provider;
GKeyFile *key_file;
+ const gchar *provider_type;
gchar *path;
gchar *group;
gchar *data;
gsize length;
GError *error;
+ provider = NULL;
+ provider_type = NULL;
path = NULL;
group = NULL;
key_file = NULL;
@@ -1001,11 +1005,45 @@ on_account_handle_remove (GoaAccount *account,
goto out;
}
+ provider_type = goa_account_get_provider_type (account);
+ if (provider_type == NULL)
+ {
+ error = NULL;
+ g_set_error_literal (&error,
+ GOA_ERROR,
+ GOA_ERROR_FAILED, /* TODO: more specific */
+ _("ProviderType property is not set for account"));
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ goto out;
+ }
+
+ provider = goa_provider_get_for_provider_type (provider_type);
+ if (provider == NULL)
+ {
+ error = NULL;
+ g_set_error (&error,
+ GOA_ERROR,
+ GOA_ERROR_FAILED, /* TODO: more specific */
+ _("Failed to find a provider for: %s"),
+ provider_type);
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ goto out;
+ }
+
+ error = NULL;
+ if (!goa_provider_delete_credentials_sync (provider, account, NULL, &error))
+ {
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ goto out;
+ }
+
goa_daemon_reload_configuration (daemon);
goa_account_complete_remove (account, invocation);
out:
+ if (provider != NULL)
+ g_object_unref (provider);
g_free (data);
if (key_file != NULL)
g_key_file_free (key_file);
diff --git a/src/goabackend/goaprovider.c b/src/goabackend/goaprovider.c
index 0df49c0..a88cbd7 100644
--- a/src/goabackend/goaprovider.c
+++ b/src/goabackend/goaprovider.c
@@ -853,6 +853,73 @@ goa_provider_lookup_credentials_sync (GoaProvider *provider,
/* ---------------------------------------------------------------------------------------------------- */
/**
+ * goa_provider_delete_credentials_sync:
+ * @provider: A #GoaProvider.
+ * @object: The #GoaAccount to delete credentials for.
+ * @cancellable: (allow-none): A #GCancellable or %NULL.
+ * @error: Return location for error or %NULL.
+ *
+ * Deletes the credentials in the keyring for @object previously stored
+ * with goa_provider_store_credentials_sync().
+ *
+ * The calling thread is blocked while waiting for a reply.
+ *
+ * This is a convenience method (not virtual) that subclasses can use.
+ *
+ * Returns: %TRUE if the credentials was successfully deleted, %FALSE
+ * if @error is set.
+ */
+gboolean
+goa_provider_delete_credentials_sync (GoaProvider *provider,
+ GoaAccount *object,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret;
+ gchar *password_key;
+ GnomeKeyringResult result;
+ const gchar *identity;
+
+ g_return_val_if_fail (GOA_IS_PROVIDER (provider), FALSE);
+ g_return_val_if_fail (GOA_IS_ACCOUNT (object), FALSE);
+ g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ /* TODO: use GCancellable */
+ ret = FALSE;
+
+ password_key = NULL;
+
+ identity = goa_account_get_id (object);
+
+ password_key = g_strdup_printf ("%s:gen%d:%s",
+ goa_provider_get_provider_type (GOA_PROVIDER (provider)),
+ goa_provider_get_credentials_generation (GOA_PROVIDER (provider)),
+ identity);
+
+ result = gnome_keyring_delete_password_sync (&keyring_password_schema,
+ "goa-identity", password_key,
+ NULL);
+ if (result != GNOME_KEYRING_RESULT_OK)
+ {
+ g_set_error (error,
+ GOA_ERROR,
+ GOA_ERROR_FAILED, /* TODO: more specific */
+ _("Failed to delete credentials from the keyring: %s"),
+ gnome_keyring_result_to_message (result));
+ goto out;
+ }
+
+ ret = TRUE;
+
+ out:
+ g_free (password_key);
+ return ret;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+/**
* SECTION:goautil
* @title: Utilities
* @short_description: Various utility routines
diff --git a/src/goabackend/goaprovider.h b/src/goabackend/goaprovider.h
index df9e302..0a97e09 100644
--- a/src/goabackend/goaprovider.h
+++ b/src/goabackend/goaprovider.h
@@ -147,6 +147,10 @@ GVariant *goa_provider_lookup_credentials_sync (GoaProvider *provid
GoaObject *object,
GCancellable *cancellable,
GError **error);
+gboolean goa_provider_delete_credentials_sync (GoaProvider *provider,
+ GoaAccount *account,
+ GCancellable *cancellable,
+ GError **error);
void goa_provider_ensure_credentials (GoaProvider *provider,
GoaObject *object,
GCancellable *cancellable,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]