[network-manager-applet/nma-0-9-8] applet: Migrate from libgnome-keyring to libsecret



commit 3139c01b50b09fb8aa552913b0722925b5ddebd3
Author: Dan Winship <danw gnome org>
Date:   Wed Aug 22 10:08:36 2012 -0400

    applet: Migrate from libgnome-keyring to libsecret
    
    The optional migration tool still uses libgnome-keyring.
    
    Based on a patch from Stef Walter.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=679849

 configure.ac                        |   23 ++--
 src/Makefile.am                     |    8 +-
 src/applet-agent.c                  |  285 ++++++++++++++---------------------
 src/applet-device-gsm.c             |   72 +++++----
 src/connection-editor/Makefile.am   |    1 -
 src/gconf-helpers/Makefile.am       |    9 +-
 src/gconf-helpers/tests/Makefile.am |    5 +-
 src/libnm-gtk/Makefile.am           |    2 -
 src/mobile-helpers.c                |   95 +++++-------
 src/mobile-helpers.h                |    5 +
 src/utils/tests/Makefile.am         |    6 +-
 11 files changed, 216 insertions(+), 295 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d54bbf0..bf3bbb1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -124,23 +124,26 @@ AC_ARG_ENABLE([migration],
               fi])
 AC_MSG_RESULT([$enable_migration])
 if test "$enable_migration" = "yes"; then
-       PKG_CHECK_MODULES(GCONF, [gconf-2.0], :,
+       PKG_CHECK_MODULES(MIGRATION, [gconf-2.0 gnome-keyring-1], :,
                          [AC_MSG_ERROR([
-Could not find GConf devel files, which are needed for
-nm-applet-migration-tool. You can configure with --disable-migration
-if you want to build without the code to migrate GConf settings from
-older (< 0.9) nm-applet releases.])])
+Could not find devel files needed for nm-applet-migration-tool:
 
-       AC_SUBST(GCONF_CFLAGS)
-       AC_SUBST(GCONF_LIBS)
+$MIGRATION_PKG_ERRORS
+
+You can configure with --disable-migration if you want to build
+without the code to migrate GConf settings from older (< 0.9)
+nm-applet releases.])])
+
+       AC_SUBST(MIGRATION_CFLAGS)
+       AC_SUBST(MIGRATION_LIBS)
 
        AC_DEFINE(BUILD_MIGRATION_TOOL, 1, [Define when building nm-applet-migration-tool])
 fi
 AM_CONDITIONAL(BUILD_MIGRATION_TOOL, test "$enable_migration" = "yes")
 
-PKG_CHECK_MODULES(GNOME_KEYRING, [gnome-keyring-1])
-AC_SUBST(GNOME_KEYRING_CFLAGS)
-AC_SUBST(GNOME_KEYRING_LIBS)
+PKG_CHECK_MODULES(LIBSECRET, [libsecret-unstable])
+AC_SUBST(LIBSECRET_CFLAGS)
+AC_SUBST(LIBSECRET_LIBS)
 
 # Check for libnotify >= 0.7
 PKG_CHECK_MODULES(LIBNOTIFY_07, [libnotify >= 0.7], [have_libnotify_07=yes],[have_libnotify_07=no])
diff --git a/src/Makefile.am b/src/Makefile.am
index 05eaaf0..eecd788 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,7 +5,7 @@ bin_PROGRAMS = nm-applet
 nm_applet_CPPFLAGS = \
        $(GTK_CFLAGS) \
        $(NMA_CFLAGS) \
-       $(GNOME_KEYRING_CFLAGS) \
+       $(LIBSECRET_CFLAGS) \
        $(NOTIFY_CFLAGS) \
        -DICONDIR=\""$(datadir)/icons"\"                                                \
        -DUIDIR=\""$(uidir)"\"                                                  \
@@ -65,7 +65,7 @@ nm_applet_LDADD = \
        -lm \
        $(GTK_LIBS) \
        $(NMA_LIBS) \
-       $(GNOME_KEYRING_LIBS) \
+       $(LIBSECRET_LIBS) \
        $(NOTIFY_LIBS) \
        ${top_builddir}/src/marshallers/libmarshallers.la \
        ${top_builddir}/src/utils/libutils.la \
@@ -88,7 +88,7 @@ endif
 
 nm_applet_migration_tool_CPPFLAGS = \
        $(nm_applet_CPPFLAGS) \
-       $(GCONF_CFLAGS) \
+       $(MIGRATION_CFLAGS) \
        -I${top_srcdir}/src/gconf-helpers
 
 nm_applet_migration_tool_SOURCES = \
@@ -96,7 +96,7 @@ nm_applet_migration_tool_SOURCES = \
 
 nm_applet_migration_tool_LDADD = \
        $(nm_applet_LDADD) \
-       $(GCONF_LIBS) \
+       $(MIGRATION_LIBS) \
        ${top_builddir}/src/gconf-helpers/libgconf-helpers.la
 
 
diff --git a/src/applet-agent.c b/src/applet-agent.c
index ae7e680..48bd02f 100644
--- a/src/applet-agent.c
+++ b/src/applet-agent.c
@@ -25,7 +25,6 @@
 
 #include <glib/gi18n.h>
 #include <string.h>
-#include <gnome-keyring.h>
 #include <dbus/dbus-glib.h>
 #include <nm-setting-connection.h>
 #include <nm-setting-8021x.h>
@@ -35,6 +34,9 @@
 #include <nm-setting-wired.h>
 #include <nm-setting-pppoe.h>
 
+#define SECRET_API_SUBJECT_TO_CHANGE
+#include <libsecret/secret.h>
+
 #include "applet-agent.h"
 #include "utils.h"
 #include "nma-marshal.h"
@@ -43,6 +45,17 @@
 #define KEYRING_SN_TAG "setting-name"
 #define KEYRING_SK_TAG "setting-key"
 
+static const SecretSchema network_manager_secret_schema = {
+       "org.freedesktop.NetworkManager.Connection",
+       SECRET_SCHEMA_DONT_MATCH_NAME,
+       {
+               { KEYRING_UUID_TAG, SECRET_SCHEMA_ATTRIBUTE_STRING },
+               { KEYRING_SN_TAG, SECRET_SCHEMA_ATTRIBUTE_STRING },
+               { KEYRING_SK_TAG, SECRET_SCHEMA_ATTRIBUTE_STRING },
+               { NULL, 0 },
+       }
+};
+
 G_DEFINE_TYPE (AppletAgent, applet_agent, NM_TYPE_SECRET_AGENT);
 
 #define APPLET_AGENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), APPLET_TYPE_AGENT, 
AppletAgentPrivate))
@@ -80,8 +93,8 @@ typedef struct {
        NMSecretAgentDeleteSecretsFunc delete_callback;
        gpointer callback_data;
 
-       GSList *keyring_calls;
-       gboolean canceled;
+       GCancellable *cancellable;
+       gint keyring_calls;
 } Request;
 
 static Request *
@@ -112,17 +125,18 @@ request_new (NMSecretAgent *agent,
        r->save_callback = save_callback;
        r->delete_callback = delete_callback;
        r->callback_data = callback_data;
+       r->cancellable = g_cancellable_new ();
        return r;
 }
 
 static void
 request_free (Request *r)
 {
-       if (r->canceled == FALSE)
+       if (!g_cancellable_is_cancelled (r->cancellable))
                g_hash_table_remove (APPLET_AGENT_GET_PRIVATE (r->agent)->requests, GUINT_TO_POINTER (r->id));
 
        /* By the time the request is freed, all keyring calls should be completed */
-       g_warn_if_fail (r->keyring_calls == NULL);
+       g_warn_if_fail (r->keyring_calls == 0);
 
        g_object_unref (r->connection);
        g_free (r->path);
@@ -132,38 +146,6 @@ request_free (Request *r)
        g_slice_free (Request, r);
 }
 
-
-/*************************************************************/
-
-/* The keyring doesn't pass the call ID to the callback for the
- * operation which the call ID represents, so we have to track
- * it with a small structure.  Ugh.
- */
-
-typedef struct {
-       Request *r;
-       gpointer keyring_id;
-} KeyringCall;
-
-static inline KeyringCall *
-keyring_call_new (Request *r)
-{
-       KeyringCall *call;
-
-       call = g_malloc0 (sizeof (KeyringCall));
-       call->r = r;
-       return call;
-}
-
-static inline void
-keyring_call_free (gpointer data)
-{
-       KeyringCall *call = data;
-
-       memset (call, 0, sizeof (*call));
-       g_free (call);
-}
-
 /*******************************************************/
 
 static void
@@ -189,7 +171,7 @@ get_secrets_cb (AppletAgent *self,
                secrets = NULL;
        }
 
-       if (r->canceled == FALSE) {
+       if (!g_cancellable_is_cancelled (r->cancellable)) {
                /* Save updated secrets as long as user-interaction was allowed; otherwise
                 * we'd be saving secrets we just pulled out of the keyring which is somewhat
                 * redundant.
@@ -319,38 +301,41 @@ destroy_gvalue (gpointer data)
 }
 
 static void
-keyring_find_secrets_cb (GnomeKeyringResult result,
-                         GList *list,
+keyring_find_secrets_cb (GObject *source,
+                         GAsyncResult *result,
                          gpointer user_data)
 {
-       KeyringCall *call = user_data;
-       Request *r = call->r;
+       Request *r = user_data;
        GError *error = NULL;
+       GError *search_error = NULL;
        const char *connection_id = NULL;
        GHashTable *secrets = NULL, *settings = NULL;
+       GList *list = NULL;
        GList *iter;
        gboolean hint_found = FALSE, ask = FALSE;
 
-       r->keyring_calls = g_slist_remove (r->keyring_calls, call);
-       if (r->canceled) {
+       r->keyring_calls--;
+       if (g_cancellable_is_cancelled (r->cancellable)) {
                /* Callback already called by NM or dispose */
                request_free (r);
                return;
        }
 
+       list = secret_service_search_finish (NULL, result, &search_error);
        connection_id = nm_connection_get_id (r->connection);
 
-       if (result == GNOME_KEYRING_RESULT_CANCELLED) {
+       if (g_error_matches (search_error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
                error = g_error_new_literal (NM_SECRET_AGENT_ERROR,
                                             NM_SECRET_AGENT_ERROR_USER_CANCELED,
                                             "The secrets request was canceled by the user");
+               g_error_free (search_error);
                goto done;
-       } else if (   result != GNOME_KEYRING_RESULT_OK
-                  && result != GNOME_KEYRING_RESULT_NO_MATCH) {
+       } else if (search_error) {
                error = g_error_new (NM_SECRET_AGENT_ERROR,
                                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
-                                    "%s.%d - failed to read secrets from keyring (result %d)",
-                                    __FILE__, __LINE__, result);
+                                    "%s.%d - failed to read secrets from keyring (%s)",
+                                    __FILE__, __LINE__, error->message);
+               g_error_free (search_error);
                goto done;
        }
 
@@ -365,26 +350,27 @@ keyring_find_secrets_cb (GnomeKeyringResult result,
 
        /* Extract the secrets from the list of matching keyring items */
        for (iter = list; iter != NULL; iter = g_list_next (iter)) {
-               GnomeKeyringFound *found = iter->data;
-               GnomeKeyringAttribute *attr;
-               const char *key_name = NULL;
-               int i;
-
-               for (i = 0; i < found->attributes->len; i++) {
-                       attr = &(gnome_keyring_attribute_list_index (found->attributes, i));
-                       if (   (strcmp (attr->name, KEYRING_SK_TAG) == 0)
-                           && (attr->type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING)) {
-
-                               key_name = attr->value.string;
-                               g_hash_table_insert (secrets, g_strdup (key_name), string_to_gvalue 
(found->secret));
-
-                               /* See if this property matches a given hint */
-                               if (r->hints && r->hints[0]) {
-                                       if (!g_strcmp0 (r->hints[0], key_name) || !g_strcmp0 (r->hints[1], 
key_name))
-                                               hint_found = TRUE;
-                               }
-                               break;
+               SecretItem *item = iter->data;
+               SecretValue *secret;
+               const char *key_name;
+               GHashTable *attributes;
+
+               secret = secret_item_get_secret (item);
+               if (secret) {
+                       attributes = secret_item_get_attributes (item);
+                       key_name = g_hash_table_lookup (attributes, KEYRING_SK_TAG);
+                       g_hash_table_insert (secrets, g_strdup (key_name),
+                                            string_to_gvalue (secret_value_get (secret, NULL)));
+
+                       /* See if this property matches a given hint */
+                       if (r->hints && r->hints[0]) {
+                               if (!g_strcmp0 (r->hints[0], key_name) || !g_strcmp0 (r->hints[1], key_name))
+                                       hint_found = TRUE;
                        }
+
+                       g_hash_table_unref (attributes);
+                       secret_value_unref (secret);
+                       break;
                }
        }
 
@@ -409,6 +395,7 @@ keyring_find_secrets_cb (GnomeKeyringResult result,
        g_hash_table_insert (settings, g_strdup (r->setting_name), secrets);
 
 done:
+       g_list_free_full (list, g_object_unref);
        if (ask) {
                GHashTableIter hash_iter;
                const char *setting_name;
@@ -453,7 +440,7 @@ get_secrets (NMSecretAgent *agent,
        NMSettingConnection *s_con;
        NMSetting *setting;
        const char *uuid, *ctype;
-       KeyringCall *call;
+       GHashTable *attrs;
 
        setting = nm_connection_get_setting_by_name (connection, setting_name);
        if (!setting) {
@@ -505,19 +492,17 @@ get_secrets (NMSecretAgent *agent,
        /* For everything else we scrape the keyring for secrets first, and ask
         * later if required.
         */
-       call = keyring_call_new (r);
-       call->keyring_id = gnome_keyring_find_itemsv (GNOME_KEYRING_ITEM_GENERIC_SECRET,
-                                                     keyring_find_secrets_cb,
-                                                     call,
-                                                     keyring_call_free,
-                                                     KEYRING_UUID_TAG,
-                                                     GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
-                                                     uuid,
-                                                     KEYRING_SN_TAG,
-                                                     GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
-                                                     setting_name,
-                                                     NULL);
-       r->keyring_calls = g_slist_append (r->keyring_calls, call);
+       attrs = secret_attributes_build (&network_manager_secret_schema,
+                                        KEYRING_UUID_TAG, uuid,
+                                        KEYRING_SN_TAG, setting_name,
+                                        NULL);
+
+       secret_service_search (NULL, &network_manager_secret_schema, attrs,
+                              SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK | SECRET_SEARCH_LOAD_SECRETS,
+                              r->cancellable, keyring_find_secrets_cb, r);
+
+       r->keyring_calls++;
+       g_hash_table_unref (attrs);
 }
 
 /*******************************************************/
@@ -545,16 +530,8 @@ cancel_get_secrets (NMSecretAgent *agent,
                /* Cancel any matching GetSecrets call */
                if (   g_strcmp0 (r->path, connection_path) == 0
                    && g_strcmp0 (r->setting_name, setting_name) == 0) {
-                       GSList *kiter;
-
-                       r->canceled = TRUE;
-
                        /* cancel outstanding keyring operations */
-                       for (kiter = r->keyring_calls; kiter; kiter = g_slist_next (kiter)) {
-                               KeyringCall *call = kiter->data;
-
-                               gnome_keyring_cancel_request (call->keyring_id);
-                       }
+                       g_cancellable_cancel (r->cancellable);
 
                        r->get_callback (NM_SECRET_AGENT (r->agent), r->connection, NULL, error, 
r->callback_data);
                        g_hash_table_remove (priv->requests, GUINT_TO_POINTER (r->id));
@@ -568,36 +545,35 @@ cancel_get_secrets (NMSecretAgent *agent,
 /*******************************************************/
 
 static void
-save_request_try_complete (Request *r, KeyringCall *call)
+save_request_try_complete (Request *r)
 {
        /* Only call the SaveSecrets callback and free the request when all the
         * secrets have been saved to the keyring.
         */
-       if (call)
-               r->keyring_calls = g_slist_remove (r->keyring_calls, call);
-
-       if (g_slist_length (r->keyring_calls) == 0) {
-               if (r->canceled == FALSE)
+       if (r->keyring_calls == 0) {
+               if (!g_cancellable_is_cancelled (r->cancellable))
                        r->save_callback (NM_SECRET_AGENT (r->agent), r->connection, NULL, r->callback_data);
                request_free (r);
        }
 }
 
 static void
-save_secret_cb (GnomeKeyringResult result, guint val, gpointer user_data)
+save_secret_cb (GObject *source,
+                GAsyncResult *result,
+                gpointer user_data)
 {
-       KeyringCall *call = user_data;
-
-       save_request_try_complete (call->r, call);
+       secret_password_store_finish (result, NULL);
+       save_request_try_complete (user_data);
 }
 
-static GnomeKeyringAttributeList *
+
+
+static GHashTable *
 _create_keyring_add_attr_list (NMConnection *connection,
                                const char *setting_name,
                                const char *setting_key,
                                char **out_display_name)
 {
-       GnomeKeyringAttributeList *attrs = NULL;
        const char *connection_id, *connection_uuid;
 
        g_return_val_if_fail (connection != NULL, NULL);
@@ -616,17 +592,11 @@ _create_keyring_add_attr_list (NMConnection *connection,
                                                     setting_key);
        }
 
-       attrs = gnome_keyring_attribute_list_new ();
-       gnome_keyring_attribute_list_append_string (attrs,
-                                                   KEYRING_UUID_TAG,
-                                                   connection_uuid);
-       gnome_keyring_attribute_list_append_string (attrs,
-                                                   KEYRING_SN_TAG,
-                                                   setting_name);
-       gnome_keyring_attribute_list_append_string (attrs,
-                                                   KEYRING_SK_TAG,
-                                                   setting_key);
-       return attrs;
+       return secret_attributes_build (&network_manager_secret_schema,
+                                       KEYRING_UUID_TAG, connection_uuid,
+                                       KEYRING_SN_TAG, setting_name,
+                                       KEYRING_SK_TAG, setting_key,
+                                       NULL);
 }
 
 static void
@@ -636,8 +606,7 @@ save_one_secret (Request *r,
                  const char *secret,
                  const char *display_name)
 {
-       GnomeKeyringAttributeList *attrs;
-       KeyringCall *call;
+       GHashTable *attrs;
        char *alt_display_name = NULL;
        const char *setting_name;
        NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE;
@@ -656,19 +625,13 @@ save_one_secret (Request *r,
                                               key,
                                               display_name ? NULL : &alt_display_name);
        g_assert (attrs);
-       call = keyring_call_new (r);
-       call->keyring_id = gnome_keyring_item_create (NULL,
-                                                     GNOME_KEYRING_ITEM_GENERIC_SECRET,
-                                                     display_name ? display_name : alt_display_name,
-                                                     attrs,
-                                                     secret,
-                                                     TRUE,
-                                                     save_secret_cb,
-                                                     call,
-                                                     keyring_call_free);
-       r->keyring_calls = g_slist_append (r->keyring_calls, call);
-
-       gnome_keyring_attribute_list_free (attrs);
+
+       secret_password_storev (&network_manager_secret_schema, attrs, NULL,
+                               display_name ? display_name : alt_display_name, secret,
+                               r->cancellable, save_secret_cb, r);
+       r->keyring_calls++;
+
+       g_hash_table_unref (attrs);
        g_free (alt_display_name);
 }
 
@@ -742,7 +705,7 @@ save_delete_cb (NMSecretAgent *agent,
         * try to complete the request here.  If there were secrets to save the
         * request will get completed when those keyring calls return.
         */
-       save_request_try_complete (r, NULL);
+       save_request_try_complete (r);
 }
 
 static void
@@ -765,37 +728,28 @@ save_secrets (NMSecretAgent *agent,
 /*******************************************************/
 
 static void
-keyring_delete_cb (GnomeKeyringResult result, gpointer user_data)
-{
-       /* Ignored */
-}
-
-static void
-delete_find_items_cb (GnomeKeyringResult result, GList *list, gpointer user_data)
+delete_find_items_cb (GObject *source,
+                      GAsyncResult *result,
+                      gpointer user_data)
 {
-       KeyringCall *call = user_data;
-       Request *r = call->r;
-       GList *iter;
+       Request *r = user_data;
+       GError *secret_error = NULL;
        GError *error = NULL;
 
-       r->keyring_calls = g_slist_remove (r->keyring_calls, call);
-       if (r->canceled) {
+       r->keyring_calls--;
+       if (g_cancellable_is_cancelled (r->cancellable)) {
                /* Callback already called by NM or dispose */
                request_free (r);
                return;
        }
 
-       if ((result == GNOME_KEYRING_RESULT_OK) || (result == GNOME_KEYRING_RESULT_NO_MATCH)) {
-               for (iter = list; iter != NULL; iter = g_list_next (iter)) {
-                       GnomeKeyringFound *found = (GnomeKeyringFound *) iter->data;
-
-                       gnome_keyring_item_delete (found->keyring, found->item_id, keyring_delete_cb, NULL, 
NULL);
-               }
-       } else {
+       secret_password_clear_finish (result, &secret_error);
+       if (secret_error != NULL) {
                error = g_error_new (NM_SECRET_AGENT_ERROR,
                                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
-                                    "The request could not be completed.  Keyring result: %d",
-                                    result);
+                                    "The request could not be completed (%s)",
+                                    secret_error->message);
+               g_error_free (secret_error);
        }
 
        r->delete_callback (r->agent, r->connection, error, r->callback_data);
@@ -813,7 +767,6 @@ delete_secrets (NMSecretAgent *agent,
        Request *r;
        NMSettingConnection *s_con;
        const char *uuid;
-       KeyringCall *call;
 
        r = request_new (agent, connection, connection_path, NULL, NULL, FALSE, NULL, NULL, callback, 
callback_data);
        g_hash_table_insert (priv->requests, GUINT_TO_POINTER (r->id), r);
@@ -823,16 +776,11 @@ delete_secrets (NMSecretAgent *agent,
        uuid = nm_setting_connection_get_uuid (s_con);
        g_assert (uuid);
 
-       call = keyring_call_new (r);
-       call->keyring_id = gnome_keyring_find_itemsv (GNOME_KEYRING_ITEM_GENERIC_SECRET,
-                                                     delete_find_items_cb,
-                                                     call,
-                                                     keyring_call_free,
-                                                     KEYRING_UUID_TAG,
-                                                     GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
-                                                     uuid,
-                                                     NULL);
-       r->keyring_calls = g_slist_append (r->keyring_calls, call);
+       secret_password_clear (&network_manager_secret_schema, r->cancellable,
+                              delete_find_items_cb, r,
+                              KEYRING_UUID_TAG, uuid,
+                              NULL);
+       r->keyring_calls++;
 }
 
 void
@@ -881,20 +829,11 @@ dispose (GObject *object)
        if (!priv->disposed) {
                GHashTableIter iter;
                Request *r;
-               GSList *kiter;
 
                /* Mark any outstanding requests as canceled */
                g_hash_table_iter_init (&iter, priv->requests);
-               while (g_hash_table_iter_next (&iter, NULL, (gpointer) &r)) {
-                       r->canceled = TRUE;
-
-                       /* cancel the request's outstanding keyring operations */
-                       for (kiter = r->keyring_calls; kiter; kiter = g_slist_next (kiter)) {
-                               KeyringCall *call = kiter->data;
-
-                               gnome_keyring_cancel_request (call->keyring_id);
-                       }
-               }
+               while (g_hash_table_iter_next (&iter, NULL, (gpointer) &r))
+                       g_cancellable_cancel (r->cancellable);
 
                g_hash_table_destroy (priv->requests);
                priv->disposed = TRUE;
diff --git a/src/applet-device-gsm.c b/src/applet-device-gsm.c
index 4ffebcd..2ab8edb 100644
--- a/src/applet-device-gsm.c
+++ b/src/applet-device-gsm.c
@@ -29,6 +29,9 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
+#define SECRET_API_SUBJECT_TO_CHANGE
+#include <libsecret/secret.h>
+
 #include <nm-device.h>
 #include <nm-setting-connection.h>
 #include <nm-setting-gsm.h>
@@ -37,7 +40,6 @@
 #include <nm-device-modem.h>
 #include <nm-utils.h>
 #include <nm-secret-agent.h>
-#include <gnome-keyring.h>
 
 #include "applet.h"
 #include "applet-device-gsm.h"
@@ -95,7 +97,7 @@ typedef struct {
 
        /* Unlock dialog stuff */
        GtkWidget *dialog;
-       gpointer keyring_id;
+       GCancellable *cancellable;
 } GsmDeviceInfo;
 
 static void unlock_dialog_destroy (GsmDeviceInfo *info);
@@ -628,9 +630,6 @@ gsm_device_info_free (gpointer data)
        if (info->bus)
                dbus_g_connection_unref (info->bus);
 
-       if (info->keyring_id)
-               gnome_keyring_cancel_request (info->keyring_id);
-
        if (info->mobile_providers_database)
                g_object_unref (info->mobile_providers_database);
 
@@ -794,17 +793,25 @@ keyring_unlock_pin_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user
 }
 
 static void
-keyring_pin_check_cb (GnomeKeyringResult result, GList *list, gpointer user_data)
+keyring_pin_check_cb (GObject *source,
+                      GAsyncResult *result,
+                      gpointer user_data)
 {
        GsmDeviceInfo *info = user_data;
        GList *iter;
-       const char *pin = NULL;
+       GList *list;
+       SecretItem *item;
+       GError *error = NULL;
+       SecretValue *pin = NULL;
+       GHashTable *attributes;
+       const gchar *simid;
 
-       info->keyring_id = NULL;
+       list = secret_service_search_finish (NULL, result, &error);
 
-       if (result != GNOME_KEYRING_RESULT_OK) {
+       if (error != NULL) {
                /* No saved PIN, just ask the user */
                unlock_dialog_new (info->device, info);
+               g_error_free (error);
                return;
        }
 
@@ -815,28 +822,25 @@ keyring_pin_check_cb (GnomeKeyringResult result, GList *list, gpointer user_data
        for (iter = list;
             info->simid && (pin == NULL) && iter;
             iter = g_list_next (iter)) {
-               GnomeKeyringFound *found = iter->data;
-               int i;
+               item = iter->data;
 
                /* Look for a matching "simid" attribute */
-               for (i = 0; (pin == NULL) && i < found->attributes->len; i++) {
-                       GnomeKeyringAttribute attr = gnome_keyring_attribute_list_index (found->attributes, 
i);
-
-                       if (   g_strcmp0 (attr.name, "simid") == 0
-                           && attr.type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING
-                           && g_strcmp0 (attr.value.string, info->simid) == 0) {
-                               pin = found->secret;
-                               break;
-                       }
-               }
+               attributes = secret_item_get_attributes (item);
+               simid = g_hash_table_lookup (attributes, "simid");
+               if (g_strcmp0 (simid, info->simid))
+                       pin = secret_item_get_secret (item);
+               else
+                       pin = NULL;
+               g_hash_table_unref (attributes);
+
+               if (pin != NULL)
+                       break;
        }
 
        if (pin == NULL) {
                /* Fall back to the first result's PIN */
-               pin = ((GnomeKeyringFound *) list->data)->secret;
+               pin = secret_item_get_secret (list->data);
                if (pin == NULL) {
-                       /* Should never get here */
-                       g_warn_if_fail (pin != NULL);
                        unlock_dialog_new (info->device, info);
                        return;
                }
@@ -846,12 +850,14 @@ keyring_pin_check_cb (GnomeKeyringResult result, GList *list, gpointer user_data
        if (!dbus_g_proxy_begin_call_with_timeout (info->card_proxy, "SendPin",
                                                   keyring_unlock_pin_reply, info, NULL,
                                                   15000,  /* 15 seconds */
-                                                  G_TYPE_STRING, pin,
+                                                  G_TYPE_STRING, secret_value_get (pin, NULL),
                                                   G_TYPE_INVALID)) {
                g_warning ("Failed to auto-unlock devid:%s simid:%s",
                           info->devid ? info->devid : "(unknown)",
                           info->simid ? info->simid : "(unknown)");
        }
+
+       secret_value_unref (pin);
 }
 
 static void
@@ -860,6 +866,7 @@ simid_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
        GsmDeviceInfo *info = user_data;
        GError *error = NULL;
        GValue value = { 0 };
+       GHashTable *attrs;
 
        if (dbus_g_proxy_end_call (proxy, call, &error,
                                   G_TYPE_VALUE, &value,
@@ -876,15 +883,11 @@ simid_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
        if (info->unlock_required) {
                /* If we have a device ID ask the keyring for any saved SIM-PIN codes */
                if (info->devid && (g_strcmp0 (info->unlock_required, "sim-pin") == 0)) {
-                       g_warn_if_fail (info->keyring_id == NULL);
-                       info->keyring_id = gnome_keyring_find_itemsv (GNOME_KEYRING_ITEM_GENERIC_SECRET,
-                                                                     keyring_pin_check_cb,
-                                                                     info,
-                                                                     NULL,
-                                                                     "devid",
-                                                                     GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
-                                                                     info->devid,
-                                                                     NULL);
+                       attrs = secret_attributes_build (&mobile_secret_schema, "devid", info->devid, NULL);
+                       secret_service_search (NULL, &mobile_secret_schema, attrs,
+                                              SECRET_SEARCH_UNLOCK | SECRET_SEARCH_LOAD_SECRETS,
+                                              info->cancellable, keyring_pin_check_cb, info);
+                       g_hash_table_unref (attrs);
                } else {
                        /* Couldn't get a device ID, but unlock required; present dialog */
                        unlock_dialog_new (info->device, info);
@@ -1126,6 +1129,7 @@ gsm_device_added (NMDevice *device, NMApplet *applet)
        info->applet = applet;
        info->device = device;
        info->bus = bus;
+       info->cancellable = g_cancellable_new ();
 
        info->props_proxy = dbus_g_proxy_new_for_name (info->bus,
                                                       "org.freedesktop.ModemManager",
diff --git a/src/connection-editor/Makefile.am b/src/connection-editor/Makefile.am
index 773a559..4cc9005 100644
--- a/src/connection-editor/Makefile.am
+++ b/src/connection-editor/Makefile.am
@@ -3,7 +3,6 @@ bin_PROGRAMS = nm-connection-editor
 nm_connection_editor_CPPFLAGS = \
        $(GTK_CFLAGS) \
        $(NMA_CFLAGS) \
-       $(GNOME_KEYRING_CFLAGS) \
        -DICONDIR=\""$(datadir)/icons"\" \
        -DUIDIR=\""$(uidir)"\" \
        -DBINDIR=\""$(bindir)"\" \
diff --git a/src/gconf-helpers/Makefile.am b/src/gconf-helpers/Makefile.am
index c4c52c3..3740f18 100644
--- a/src/gconf-helpers/Makefile.am
+++ b/src/gconf-helpers/Makefile.am
@@ -16,15 +16,13 @@ libgconf_helpers_la_CPPFLAGS = \
        -I$(top_srcdir)/src/utils \
        $(GTK_CFLAGS) \
        $(NMA_CFLAGS) \
-       $(GCONF_CFLAGS) \
-       $(GNOME_KEYRING_CFLAGS) \
+       $(MIGRATION_CFLAGS) \
        $(DISABLE_DEPRECATED)
 
 libgconf_helpers_la_LIBADD = \
        $(GTK_LIBS) \
        $(NMA_LIBS) \
-       $(GCONF_LIBS) \
-       $(GNOME_KEYRING_LIBS)
+       $(MIGRATION_LIBS)
 
 #########################
 # Test library
@@ -36,8 +34,7 @@ libgconf_helpers_test_la_CPPFLAGS = \
        -I$(top_srcdir)/src/utils \
        $(GTK_CFLAGS) \
        $(NMA_CFLAGS) \
-       $(GCONF_CFLAGS) \
-       $(GNOME_KEYRING_CFLAGS) \
+       $(MIGRATION_CFLAGS) \
        $(DISABLE_DEPRECATED)
 
 # no keyring or gconf libs since we'll override them
diff --git a/src/gconf-helpers/tests/Makefile.am b/src/gconf-helpers/tests/Makefile.am
index 882af31..f8e3d64 100644
--- a/src/gconf-helpers/tests/Makefile.am
+++ b/src/gconf-helpers/tests/Makefile.am
@@ -14,14 +14,13 @@ test_upgrade_CPPFLAGS = \
        -DTESTDIR=\"$(srcdir)\" \
        $(GTK_CFLAGS) \
        $(NMA_CFLAGS) \
-       $(GCONF_CFLAGS) \
-       $(GNOME_KEYRING_CFLAGS)
+       $(MIGRATION_CFLAGS)
 
 test_upgrade_LDADD = \
        ${builddir}/../libgconf-helpers-test.la \
        $(GTK_CFLAGS) \
        $(NMA_LIBS) \
-       $(GNOME_KEYRING_LIBS)
+       $(MIGRATION_LIBS)
 
 check-local: test-upgrade
        $(abs_builddir)/test-upgrade
diff --git a/src/libnm-gtk/Makefile.am b/src/libnm-gtk/Makefile.am
index dbc7477..0896694 100644
--- a/src/libnm-gtk/Makefile.am
+++ b/src/libnm-gtk/Makefile.am
@@ -25,7 +25,6 @@ libnm_gtk_la_CFLAGS = \
        $(GTK_CFLAGS) \
        $(NMA_CFLAGS) \
        $(DBUS_CFLAGS) \
-       $(GNOME_KEYRING_CFLAGS) \
        $(GUDEV_CFLAGS) \
        -DICONDIR=\""$(datadir)/icons"\" \
        -DUIDIR=\""$(uidir)"\" \
@@ -44,7 +43,6 @@ libnm_gtk_la_CFLAGS = \
 libnm_gtk_la_LIBADD = \
        $(GTK_LIBS) \
        $(NMA_LIBS) \
-       $(GNOME_KEYRING_LIBS) \
        $(GUDEV_LIBS) \
        $(top_builddir)/src/marshallers/libmarshallers.la \
        $(top_builddir)/src/wireless-security/libwireless-security.la
diff --git a/src/mobile-helpers.c b/src/mobile-helpers.c
index dcb437e..4c1db5f 100644
--- a/src/mobile-helpers.c
+++ b/src/mobile-helpers.c
@@ -23,7 +23,9 @@
 #include <ctype.h>
 #include <glib/gi18n.h>
 #include <nm-utils.h>
-#include <gnome-keyring.h>
+
+#define SECRET_API_SUBJECT_TO_CHANGE
+#include <libsecret/secret.h>
 
 #include "utils.h"
 #include "mobile-helpers.h"
@@ -277,11 +279,31 @@ mobile_helper_wizard (NMDeviceModemCapabilities capabilities,
 
 /********************************************************************/
 
+const SecretSchema mobile_secret_schema = {
+       "org.freedesktop.NetworkManager.Mobile",
+       SECRET_SCHEMA_DONT_MATCH_NAME,
+       {
+               { "devid", SECRET_SCHEMA_ATTRIBUTE_STRING },
+               { "simid", SECRET_SCHEMA_ATTRIBUTE_STRING },
+               { NULL, 0 },
+       }
+};
+
 static void
-save_pin_cb (GnomeKeyringResult result, guint32 val, gpointer user_data)
+save_pin_cb (GObject *source,
+             GAsyncResult *result,
+             gpointer user_data)
 {
-       if (result != GNOME_KEYRING_RESULT_OK)
-               g_warning ("%s: result %d", (const char *) user_data, result);
+       GError *error = NULL;
+       gchar *error_msg = user_data;
+
+       secret_password_store_finish (result, &error);
+       if (error != NULL) {
+               g_warning ("%s: %s", error_msg, error->message);
+               g_error_free (error);
+       }
+
+       g_free (error_msg);
 }
 
 void
@@ -289,75 +311,32 @@ mobile_helper_save_pin_in_keyring (const char *devid,
                                    const char *simid,
                                    const char *pin)
 {
-       GnomeKeyringAttributeList *attributes;
-       GnomeKeyringAttribute attr;
-       const char *name;
+       char *name;
        char *error_msg;
 
        name = g_strdup_printf (_("PIN code for SIM card '%s' on '%s'"),
                                simid ? simid : "unknown",
                                devid);
 
-       attributes = gnome_keyring_attribute_list_new ();
-       attr.name = g_strdup ("devid");
-       attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
-       attr.value.string = g_strdup (devid);
-       g_array_append_val (attributes, attr);
-
-       if (simid) {
-               attr.name = g_strdup ("simid");
-               attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
-               attr.value.string = g_strdup (simid);
-               g_array_append_val (attributes, attr);
-       }
-
        error_msg = g_strdup_printf ("Saving PIN code in keyring for devid:%s simid:%s failed",
                                     devid, simid ? simid : "(unknown)");
 
-       gnome_keyring_item_create (NULL,
-                                  GNOME_KEYRING_ITEM_GENERIC_SECRET,
-                                  name,
-                                  attributes,
-                                  pin,
-                                  TRUE,
-                                  save_pin_cb,
-                                  error_msg,
-                                  (GDestroyNotify) g_free);
-
-       gnome_keyring_attribute_list_free (attributes);
-}
-
-static void
-delete_pin_cb (GnomeKeyringResult result, gpointer user_data)
-{
-       /* nothing to do */
-}
-
-static void
-delete_pins_find_cb (GnomeKeyringResult result, GList *list, gpointer user_data)
-{
-       GList *iter;
-
-       if (result == GNOME_KEYRING_RESULT_OK) {
-               for (iter = list; iter; iter = g_list_next (iter)) {
-                       GnomeKeyringFound *found = iter->data;
+       secret_password_store (&mobile_secret_schema,
+                              NULL, name, pin,
+                              NULL, save_pin_cb, error_msg,
+                              "devid", devid,
+                              simid ? "simid" : NULL, simid,
+                              NULL);
 
-                       gnome_keyring_item_delete (found->keyring, found->item_id, delete_pin_cb, NULL, NULL);
-               }
-       }
+       g_free (name);
 }
 
 void
 mobile_helper_delete_pin_in_keyring (const char *devid)
 {
-       gnome_keyring_find_itemsv (GNOME_KEYRING_ITEM_GENERIC_SECRET,
-                                  delete_pins_find_cb,
-                                  NULL,
-                                  NULL,
-                                  "devid",
-                                  GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
-                                  devid,
-                                  NULL);
+       secret_password_clear (&mobile_secret_schema, NULL, NULL, NULL,
+                              "devid", devid,
+                              NULL);
 }
 
 /********************************************************************/
diff --git a/src/mobile-helpers.h b/src/mobile-helpers.h
index d1057c6..ce20135 100644
--- a/src/mobile-helpers.h
+++ b/src/mobile-helpers.h
@@ -24,6 +24,9 @@
 #define APPLET_MOBILE_HELPERS_H
 
 #include <gtk/gtk.h>
+#define SECRET_API_SUBJECT_TO_CHANGE
+#include <libsecret/secret.h>
+
 #include "applet.h"
 #include "nm-mobile-wizard.h"
 #include "nm-mobile-providers.h"
@@ -71,6 +74,8 @@ gboolean   mobile_helper_wizard (NMDeviceModemCapabilities capabilities,
 
 /********************************************************************/
 
+extern const SecretSchema mobile_secret_schema;
+
 void mobile_helper_save_pin_in_keyring   (const char *devid,
                                           const char *simid,
                                           const char *pin);
diff --git a/src/utils/tests/Makefile.am b/src/utils/tests/Makefile.am
index 47bcd8d..6534f70 100644
--- a/src/utils/tests/Makefile.am
+++ b/src/utils/tests/Makefile.am
@@ -6,14 +6,12 @@ test_utils_SOURCES = test-utils.c
 
 test_utils_CPPFLAGS = \
        $(GTK_CFLAGS) \
-       $(NMA_CFLAGS) \
-       $(GNOME_KEYRING_CFLAGS)
+       $(NMA_CFLAGS)
 
 test_utils_LDADD = \
        ${top_builddir}/src/utils/libutils.la \
        $(GTK_LIBS) \
-       $(NMA_LIBS) \
-       $(GNOME_KEYRING_LIBS)
+       $(NMA_LIBS)
 
 check-local: test-utils
        $(abs_builddir)/test-utils


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