[gnome-online-accounts/wip/rishi/libsecret-workaround: 7/7] daemon, utils: ...



commit 4bcd65a3d7e6a0e65556a4cd599d0517fba8ab70
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Jul 3 18:18:13 2017 +0200

    daemon, utils: ...

 src/daemon/Makefile.am    |    2 +
 src/daemon/goadaemon.c    |   62 ++++++++++++++++++++++++++++++++++++++------
 src/daemon/goadaemon.h    |    1 +
 src/daemon/main.c         |    8 +++++-
 src/goabackend/goautils.c |   23 ++++++++++------
 src/goabackend/goautils.h |    7 +++-
 6 files changed, 82 insertions(+), 21 deletions(-)
---
diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am
index 5f9a231..b9807bb 100644
--- a/src/daemon/Makefile.am
+++ b/src/daemon/Makefile.am
@@ -34,6 +34,7 @@ goa_daemon_CFLAGS =                                           \
        $(GLIB_CFLAGS)                                          \
        $(GTK_CFLAGS)                                           \
        $(REST_CFLAGS)                                          \
+       $(SECRET_CFLAGS)                                        \
        $(NULL)
 
 goa_daemon_LDADD =                                             \
@@ -42,6 +43,7 @@ goa_daemon_LDADD =                                            \
        $(top_builddir)/src/goabackend/libgoa-backend-1.0.la    \
        $(GTK_LIBS)                                             \
        $(REST_LIBS)                                            \
+       $(SECRET_LIBS)                                          \
        $(NULL)
 
 clean-local :
diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c
index 069b2e8..18b4eef 100644
--- a/src/daemon/goadaemon.c
+++ b/src/daemon/goadaemon.c
@@ -24,6 +24,7 @@
 #include <gio/gio.h>
 #include <glib/gi18n.h>
 #include <rest/rest-proxy.h>
+#include <libsecret/secret.h>
 #include <libsoup/soup.h>
 
 #include "goadaemon.h"
@@ -51,6 +52,9 @@ struct _GoaDaemon
   GQueue *ensure_credentials_queue;
   gboolean ensure_credentials_running;
 
+  SecretService *secret_service;
+  gchar *secret_service_bus_name;
+
   guint config_timeout_id;
   guint credentials_timeout_id;
 };
@@ -58,7 +62,8 @@ struct _GoaDaemon
 enum
 {
   PROP_0,
-  PROP_CONNECTION
+  PROP_CONNECTION,
+  PROP_SECRET_SERVICE_BUS_NAME
 };
 
 static void on_file_monitor_changed (GFileMonitor     *monitor,
@@ -147,9 +152,6 @@ goa_daemon_constructed (GObject *object)
 
   G_OBJECT_CLASS (goa_daemon_parent_class)->constructed (object);
 
-  /* prime the list of accounts */
-  goa_daemon_reload_configuration (self);
-
   /* Export objects */
   g_dbus_object_manager_server_set_connection (self->object_manager, self->connection);
 }
@@ -182,6 +184,8 @@ goa_daemon_finalize (GObject *object)
     }
 
   g_free (self->home_conf_file_path);
+  g_free (self->secret_service_bus_name);
+  g_clear_object (&self->secret_service);
   g_object_unref (self->manager);
   g_object_unref (self->object_manager);
   g_object_unref (self->connection);
@@ -201,6 +205,10 @@ goa_daemon_set_property (GObject *object, guint prop_id, const GValue *value, GP
       self->connection = G_DBUS_CONNECTION (g_value_dup_object (value));
       break;
 
+    case PROP_SECRET_SERVICE_BUS_NAME:
+      self->secret_service_bus_name = g_value_dup_string (value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -390,12 +398,39 @@ goa_daemon_class_init (GoaDaemonClass *klass)
                                                         G_PARAM_CONSTRUCT_ONLY |
                                                         G_PARAM_STATIC_STRINGS |
                                                         G_PARAM_WRITABLE));
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_SECRET_SERVICE_BUS_NAME,
+                                   g_param_spec_string ("secret-service-bus-name",
+                                                        "Secret service bus name",
+                                                        "The D-Bus service name of the secret service",
+                                                        NULL,
+                                                        G_PARAM_CONSTRUCT_ONLY |
+                                                        G_PARAM_STATIC_STRINGS |
+                                                        G_PARAM_WRITABLE));
 }
 
 static gboolean
 goa_daemon_initable_init (GInitable *initable, GCancellable *cancellable, GError **error)
 {
-  return TRUE;
+  GoaDaemon *self = GOA_DAEMON (initable);
+  gboolean ret_val = FALSE;
+
+  self->secret_service = secret_service_open_sync (SECRET_TYPE_SERVICE,
+                                                   self->secret_service_bus_name,
+                                                   SECRET_SERVICE_OPEN_SESSION,
+                                                   cancellable,
+                                                   error);
+  if (self->secret_service == NULL)
+    goto out;
+
+  /* prime the list of accounts */
+  goa_daemon_reload_configuration (self);
+
+  ret_val = TRUE;
+
+ out:
+  return ret_val;
 }
 
 static void
@@ -405,13 +440,22 @@ goa_daemon_initable_iface_init (GInitableIface *iface)
 }
 
 GoaDaemon *
-goa_daemon_new (GDBusConnection *connection, GCancellable *cancellable, GError **error)
+goa_daemon_new (GDBusConnection   *connection,
+                const gchar       *secret_service_bus_name,
+                GCancellable      *cancellable,
+                GError           **error)
 {
   g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
+  g_return_val_if_fail (secret_service_bus_name != NULL && secret_service_bus_name[0] != '\0', NULL);
   g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-  return GOA_DAEMON (g_initable_new (GOA_TYPE_DAEMON, cancellable, error, "connection", connection, NULL));
+  return GOA_DAEMON (g_initable_new (GOA_TYPE_DAEMON,
+                                     cancellable,
+                                     error,
+                                     "connection", connection,
+                                     "secret-service-bus-name", secret_service_bus_name,
+                                     NULL));
 }
 
 
@@ -597,7 +641,7 @@ add_config_file (GoaDaemon     *self,
                   needs_update = g_key_file_remove_group (key_file, groups[n], NULL);
 
                   error = NULL;
-                  if (!goa_utils_delete_credentials_for_id_sync (provider, id, NULL, &error))
+                  if (!goa_utils_delete_credentials_for_id_sync (self->secret_service, provider, id, NULL, 
&error))
                     {
                       g_warning ("Unable to clean-up stale keyring entries: %s", error->message);
                       g_error_free (error);
@@ -1478,7 +1522,7 @@ on_account_handle_remove (GoaAccount            *account,
     }
 
   error = NULL;
-  if (!goa_utils_delete_credentials_for_account_sync (provider, account, NULL, &error))
+  if (!goa_utils_delete_credentials_for_account_sync (self->secret_service, provider, account, NULL, &error))
     {
       g_dbus_method_invocation_take_error (invocation, error);
       goto out;
diff --git a/src/daemon/goadaemon.h b/src/daemon/goadaemon.h
index 88e737c..87b84d2 100644
--- a/src/daemon/goadaemon.h
+++ b/src/daemon/goadaemon.h
@@ -27,6 +27,7 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (GoaDaemon, goa_daemon, GOA, DAEMON, GObject);
 
 GoaDaemon          *goa_daemon_new                (GDBusConnection   *connection,
+                                                   const gchar       *secret_service_bus_name,
                                                    GCancellable      *cancellable,
                                                    GError           **error);
 
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 22d114b..3794f54 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -39,6 +39,8 @@ static GOptionEntry opt_entries[] =
   {NULL }
 };
 static GoaDaemon *the_daemon = NULL;
+static const gchar *SECRET_SERVICE_BUS_NAME = "org.freedesktop.secrets";
+static const gchar *secret_service_bus_name = NULL;
 
 static void
 on_bus_acquired (GDBusConnection *connection,
@@ -53,7 +55,7 @@ on_bus_acquired (GDBusConnection *connection,
   g_debug ("Connected to the session bus");
 
   error = NULL;
-  the_daemon = goa_daemon_new (connection, NULL, &error);
+  the_daemon = goa_daemon_new (connection, secret_service_bus_name, NULL, &error);
   if (error != NULL)
     {
       g_warning ("Unable to initialize GoaDaemon: %s (%s, %d)",
@@ -121,6 +123,10 @@ main (int    argc,
       goto out;
     }
 
+  secret_service_bus_name = g_getenv ("SECRET_SERVICE_BUS_NAME");
+  if (secret_service_bus_name == NULL)
+    secret_service_bus_name = SECRET_SERVICE_BUS_NAME;
+
   g_message ("goa-daemon version %s starting", PACKAGE_VERSION);
 
   loop = g_main_loop_new (NULL, FALSE);
diff --git a/src/goabackend/goautils.c b/src/goabackend/goautils.c
index f384d0c..97fc677 100644
--- a/src/goabackend/goautils.c
+++ b/src/goabackend/goautils.c
@@ -19,7 +19,6 @@
 #include "config.h"
 
 #include <glib/gi18n-lib.h>
-#include <libsecret/secret.h>
 
 #ifdef GOA_TELEPATHY_ENABLED
 #include <telepathy-glib/telepathy-glib.h>
@@ -337,24 +336,27 @@ goa_utils_set_dialog_title (GoaProvider *provider, GtkDialog *dialog, gboolean a
 }
 
 gboolean
-goa_utils_delete_credentials_for_account_sync (GoaProvider   *provider,
+goa_utils_delete_credentials_for_account_sync (SecretService *secret_service,
+                                               GoaProvider   *provider,
                                                GoaAccount    *object,
                                                GCancellable  *cancellable,
                                                GError       **error)
 {
   const gchar *id;
 
+  g_return_val_if_fail (SECRET_IS_SERVICE (secret_service), FALSE);
   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);
 
   id = goa_account_get_id (object);
-  return goa_utils_delete_credentials_for_id_sync (provider, id, cancellable, error);
+  return goa_utils_delete_credentials_for_id_sync (secret_service, provider, id, cancellable, error);
 }
 
 gboolean
-goa_utils_delete_credentials_for_id_sync (GoaProvider   *provider,
+goa_utils_delete_credentials_for_id_sync (SecretService *secret_service,
+                                          GoaProvider   *provider,
                                           const gchar   *id,
                                           GCancellable  *cancellable,
                                           GError       **error)
@@ -362,7 +364,9 @@ goa_utils_delete_credentials_for_id_sync (GoaProvider   *provider,
   gboolean ret = FALSE;
   gchar *password_key = NULL;
   GError *sec_error = NULL;
+  GHashTable *attributes = NULL;
 
+  g_return_val_if_fail (SECRET_IS_SERVICE (secret_service), FALSE);
   g_return_val_if_fail (GOA_IS_PROVIDER (provider), FALSE);
   g_return_val_if_fail (id != NULL && id[0] != '\0', FALSE);
   g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
@@ -373,11 +377,11 @@ goa_utils_delete_credentials_for_id_sync (GoaProvider   *provider,
                                   goa_provider_get_credentials_generation (provider),
                                   id);
 
-  secret_password_clear_sync (&secret_password_schema,
-                              cancellable,
-                              &sec_error,
-                              "goa-identity", password_key,
-                              NULL);
+  attributes = secret_attributes_build (&secret_password_schema, "goa-identity", password_key, NULL);
+  if (attributes == NULL)
+    goto out;
+
+  secret_service_clear_sync (secret_service, &secret_password_schema, attributes, cancellable, &sec_error);
   if (sec_error != NULL)
     {
       g_warning ("secret_password_clear_sync() failed: %s", sec_error->message);
@@ -393,6 +397,7 @@ goa_utils_delete_credentials_for_id_sync (GoaProvider   *provider,
   ret = TRUE;
 
  out:
+  g_clear_pointer (&attributes, (GDestroyNotify) g_hash_table_unref);
   g_free (password_key);
   return ret;
 }
diff --git a/src/goabackend/goautils.h b/src/goabackend/goautils.h
index 757318d..080e751 100644
--- a/src/goabackend/goautils.h
+++ b/src/goabackend/goautils.h
@@ -26,6 +26,7 @@
 #include <gio/gio.h>
 #include <glib.h>
 #include <gtk/gtk.h>
+#include <libsecret/secret.h>
 #include <libsoup/soup.h>
 
 #include "goaprovider.h"
@@ -62,12 +63,14 @@ gchar           *goa_utils_data_input_stream_read_line (GDataInputStream  *strea
 
 void             goa_utils_set_dialog_title (GoaProvider *provider, GtkDialog *dialog, gboolean add_account);
 
-gboolean         goa_utils_delete_credentials_for_account_sync (GoaProvider    *provider,
+gboolean         goa_utils_delete_credentials_for_account_sync (SecretService  *secret_service,
+                                                                GoaProvider    *provider,
                                                                 GoaAccount     *account,
                                                                 GCancellable   *cancellable,
                                                                 GError        **error);
 
-gboolean         goa_utils_delete_credentials_for_id_sync (GoaProvider    *provider,
+gboolean         goa_utils_delete_credentials_for_id_sync (SecretService  *secret_service,
+                                                           GoaProvider    *provider,
                                                            const gchar    *id,
                                                            GCancellable   *cancellable,
                                                            GError        **error);


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