[network-manager-openswan] auth-dialog: port to libsecret



commit e44a7fa3a8971b006690ba1b4a3b6ff9c3968d57
Author: Dan Winship <danw gnome org>
Date:   Wed Feb 27 14:26:15 2013 +0100

    auth-dialog: port to libsecret
    
    https://bugzilla.gnome.org/show_bug.cgi?id=694307

 auth-dialog/Makefile.am |    4 +-
 auth-dialog/main.c      |   72 ++++++++++++++++++++++++++++-------------------
 configure.ac            |    6 ++--
 3 files changed, 48 insertions(+), 34 deletions(-)
---
diff --git a/auth-dialog/Makefile.am b/auth-dialog/Makefile.am
index ab2321b..7a36e59 100644
--- a/auth-dialog/Makefile.am
+++ b/auth-dialog/Makefile.am
@@ -7,7 +7,7 @@ nm_openswan_auth_dialog_CPPFLAGS = \
        $(NM_CFLAGS) \
        $(GTK_CFLAGS) \
        $(NMGTK_CFLAGS) \
-       $(GNOMEKEYRING_CFLAGS) \
+       $(LIBSECRET_CFLAGS) \
        -DICONDIR=\""$(datadir)/pixmaps"\" \
        -DBINDIR=\""$(bindir)"\" \
        -DG_DISABLE_DEPRECATED \
@@ -21,7 +21,7 @@ nm_openswan_auth_dialog_LDADD = \
        $(NM_LIBS) \
        $(GTK_LIBS) \
        $(NMGTK_LIBS) \
-       $(GNOMEKEYRING_LIBS)
+       $(LIBSECRET_LIBS)
 
 CLEANFILES = *~
 
diff --git a/auth-dialog/main.c b/auth-dialog/main.c
index f569e7b..24dd666 100644
--- a/auth-dialog/main.c
+++ b/auth-dialog/main.c
@@ -29,8 +29,9 @@
 #include <string.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
-#include <gnome-keyring.h>
-#include <gnome-keyring-memory.h>
+
+#define SECRET_API_SUBJECT_TO_CHANGE
+#include <libsecret/secret.h>
 
 #include <nm-setting-vpn.h>
 #include <nm-setting-connection.h>
@@ -43,34 +44,47 @@
 #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 },
+       }
+};
+
 #define UI_KEYFILE_GROUP "VPN Plugin UI"
 
 static char *
 keyring_lookup_secret (const char *uuid, const char *secret_name)
 {
-       GList *found_list = NULL;
-       GnomeKeyringResult ret;
-       GnomeKeyringFound *found;
+       GHashTable *attrs;
+       GList *list;
        char *secret = NULL;
 
-       ret = gnome_keyring_find_itemsv_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
-                                             &found_list,
-                                             KEYRING_UUID_TAG,
-                                             GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
-                                             uuid,
-                                             KEYRING_SN_TAG,
-                                             GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
-                                             NM_SETTING_VPN_SETTING_NAME,
-                                             KEYRING_SK_TAG,
-                                             GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
-                                             secret_name,
-                                             NULL);
-       if (ret == GNOME_KEYRING_RESULT_OK && found_list) {
-               found = g_list_nth_data (found_list, 0);
-               secret = gnome_keyring_memory_strdup (found->secret);
+       attrs = secret_attributes_build (&network_manager_secret_schema,
+                                        KEYRING_UUID_TAG, uuid,
+                                        KEYRING_SN_TAG, NM_SETTING_VPN_SETTING_NAME,
+                                        KEYRING_SK_TAG, secret_name,
+                                        NULL);
+
+       list = secret_service_search_sync (NULL, &network_manager_secret_schema, attrs,
+                                          SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK | 
SECRET_SEARCH_LOAD_SECRETS,
+                                          NULL, NULL);
+       if (list && list->data) {
+               SecretItem *item = list->data;
+               SecretValue *value = secret_item_get_secret (item);
+
+               if (value) {
+                       secret = g_strdup (secret_value_get (value, NULL));
+                       secret_value_unref (value);
+               }
        }
 
-       gnome_keyring_found_list_free (found_list);
+       g_list_free_full (list, g_object_unref);
+       g_hash_table_unref (attrs);
        return secret;
 }
 
@@ -130,7 +144,7 @@ get_secrets (const char *vpn_uuid,
        if (   !(upw_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED)
            && !(upw_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
                if (in_upw)
-                       upw = gnome_keyring_memory_strdup (in_upw);
+                       upw = g_strdup (in_upw);
                else
                        upw = keyring_lookup_secret (vpn_uuid, NM_OPENSWAN_XAUTH_PASSWORD);
 
@@ -142,7 +156,7 @@ get_secrets (const char *vpn_uuid,
        if (   !(gpw_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED)
            && !(gpw_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
                if (in_gpw)
-                       gpw = gnome_keyring_memory_strdup (in_gpw);
+                       gpw = g_strdup (in_gpw);
                else
                        gpw = keyring_lookup_secret (vpn_uuid, NM_OPENSWAN_PSK_VALUE);
 
@@ -241,8 +255,8 @@ get_secrets (const char *vpn_uuid,
        /* Show the dialog */
        success = nma_vpn_password_dialog_run_and_block (dialog);
        if (success) {
-               *out_upw = gnome_keyring_memory_strdup (nma_vpn_password_dialog_get_password (dialog));
-               *out_gpw = gnome_keyring_memory_strdup (nma_vpn_password_dialog_get_password_secondary 
(dialog));
+               *out_upw = g_strdup (nma_vpn_password_dialog_get_password (dialog));
+               *out_gpw = g_strdup (nma_vpn_password_dialog_get_password_secondary (dialog));
        }
 
        gtk_widget_hide (GTK_WIDGET (dialog));
@@ -251,8 +265,8 @@ get_secrets (const char *vpn_uuid,
  out:
        g_free (prompt);
 
-       gnome_keyring_memory_free (upw);
-       gnome_keyring_memory_free (gpw);
+       g_free (upw);
+       g_free (gpw);
 
        return success;
 }
@@ -380,8 +394,8 @@ main (int argc, char *argv[])
                        printf ("%s\n%s\n", NM_OPENSWAN_PSK_VALUE, group_password);
                printf ("\n\n");
 
-               gnome_keyring_memory_free (password);
-               gnome_keyring_memory_free (group_password);
+               g_free (password);
+               g_free (group_password);
 
                /* for good measure, flush stdout since Kansas is going Bye-Bye */
                fflush (stdout);
diff --git a/configure.ac b/configure.ac
index ccf2046..12c7172 100644
--- a/configure.ac
+++ b/configure.ac
@@ -84,9 +84,9 @@ if test x"$with_gnome" != xno; then
        AC_SUBST(NMGTK_CFLAGS)
        AC_SUBST(NMGTK_LIBS)
 
-       PKG_CHECK_MODULES(GNOMEKEYRING, gnome-keyring-1)
-       AC_SUBST(GNOMEKEYRING_CFLAGS)
-       AC_SUBST(GNOMEKEYRING_LIBS)
+       PKG_CHECK_MODULES(LIBSECRET, libsecret-unstable)
+       AC_SUBST(LIBSECRET_CFLAGS)
+       AC_SUBST(LIBSECRET_LIBS)
 fi
 
 dnl


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