nm: Replace libgnomekeyring with libsecret
authorLubomir Rintel <lkundrak@v3.sk>
Tue, 29 Mar 2016 17:33:26 +0000 (19:33 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 5 Sep 2016 13:30:54 +0000 (15:30 +0200)
The former is deprecated and the newer API is nicer anyway.

src/frontends/gnome/auth-dialog/Makefile.am
src/frontends/gnome/auth-dialog/main.c
src/frontends/gnome/configure.ac
src/frontends/gnome/debian/control

index 7bbd71d..9c9f7d6 100644 (file)
@@ -3,7 +3,7 @@ nm_libexec_PROGRAMS = nm-strongswan-auth-dialog
 nm_strongswan_auth_dialog_CPPFLAGS = \
        $(GTK_CFLAGS) \
        $(LIBGNOMEUI_CFLAGS) \
-       $(GNOMEKEYRING_CFLAGS) \
+       $(LIBSECRET_CFLAGS) \
        $(NETWORK_MANAGER_CFLAGS) \
        $(NM_UTILS_CFLAGS) \
        -DG_DISABLE_DEPRECATED \
@@ -17,6 +17,5 @@ nm_strongswan_auth_dialog_SOURCES =   \
 nm_strongswan_auth_dialog_LDADD = \
        $(GTK_LIBS) \
        $(LIBGNOMEUI_LIBS) \
-       $(GNOMEKEYRING_LIBS) \
+       $(LIBSECRET_LIBS) \
        $(NM_UTILS_LIBS)
-
index b9fd886..3d5d843 100644 (file)
@@ -22,7 +22,7 @@
 #include <string.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
-#include <gnome-keyring.h>
+#include <libsecret/secret.h>
 #include <libgnomeui/libgnomeui.h>
 #include <nm-vpn-plugin.h>
 #include <nm-setting-vpn.h>
 #define NM_DBUS_SERVICE_STRONGSWAN     "org.freedesktop.NetworkManager.strongswan"
 
 /**
- * lookup a password in the keyring
- */
-static char *lookup_password(char *name, char *service)
-{
-       GList *list;
-       GList *iter;
-       char *pass = NULL;
-
-       if (gnome_keyring_find_network_password_sync(g_get_user_name(), NULL, name,
-                       NULL, service, NULL, 0, &list) != GNOME_KEYRING_RESULT_OK)
-       {
-               return NULL;
-       }
-
-       for (iter = list; iter; iter = iter->next)
-       {
-               GnomeKeyringNetworkPasswordData *data = iter->data;
-
-               if (strcmp(data->object, "password") == 0 && data->password)
-               {
-                       pass = g_strdup(data->password);
-                       break;
-               }
-       }
-       gnome_keyring_network_password_list_free(list);
-       return pass;
-}
-
-/**
  * Wait for quit input
  */
 static void wait_for_quit (void)
@@ -118,7 +89,7 @@ int main (int argc, char *argv[])
        gchar *name = NULL, *uuid = NULL, *service = NULL, *keyring = NULL, *pass;
        GOptionContext *context;
        char *agent, *type;
-       guint32 itemid, minlen = 0;
+       guint32 minlen = 0;
        GtkWidget *dialog;
        GOptionEntry entries[] = {
                { "reprompt", 'r', 0, G_OPTION_ARG_NONE, &retry, "Reprompt for passwords", NULL},
@@ -162,7 +133,12 @@ int main (int argc, char *argv[])
        if (!strcmp(type, "eap") || !strcmp(type, "key") || !strcmp(type, "psk") ||
                !strcmp(type, "smartcard"))
        {
-               pass = lookup_password(name, service);
+               pass = secret_password_lookup_sync(SECRET_SCHEMA_COMPAT_NETWORK, NULL, NULL,
+                                                  "user", g_get_user_name(),
+                                                  "server", name,
+                                                  "protocol", service,
+                                                  NULL);
+
                if ((!pass || retry) && allow_interaction)
                {
                        if (!strcmp(type, "eap"))
@@ -216,12 +192,15 @@ too_short_retry:
                                case GNOME_PASSWORD_DIALOG_REMEMBER_NOTHING:
                                        break;
                                case GNOME_PASSWORD_DIALOG_REMEMBER_SESSION:
-                                       keyring = "session";
+                                       keyring = SECRET_COLLECTION_SESSION;
                                        /* FALL */
                                case GNOME_PASSWORD_DIALOG_REMEMBER_FOREVER:
-                                       if (gnome_keyring_set_network_password_sync(keyring,
-                                                       g_get_user_name(), NULL, name, "password", service, NULL, 0,
-                                                       pass, &itemid) != GNOME_KEYRING_RESULT_OK)
+                                       if (!secret_password_store_sync(SECRET_SCHEMA_COMPAT_NETWORK,
+                                                               keyring, "", pass, NULL, NULL,
+                                                               "user", g_get_user_name(),
+                                                               "server", name,
+                                                               "protocol", service,
+                                                               NULL))
                                        {
                                                g_warning ("storing password in keyring failed");
                                        }
@@ -231,6 +210,7 @@ too_short_retry:
                if (pass)
                {
                        printf("password\n%s\n", pass);
+                       g_free(pass);
                }
        }
        else
index 0aee4a5..f9da6c0 100644 (file)
@@ -45,7 +45,7 @@ AM_GLIB_GNU_GETTEXT
 
 PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.6)
 PKG_CHECK_MODULES(LIBGNOMEUI, libgnomeui-2.0)
-PKG_CHECK_MODULES(GNOMEKEYRING, gnome-keyring-1)
+PKG_CHECK_MODULES(LIBSECRET, libsecret-1)
 PKG_CHECK_EXISTS([libnm-glib],
        [PKG_CHECK_MODULES(NM_UTILS, NetworkManager >= 0.9.0 libnm-util libnm-glib libnm-glib-vpn)],
        [PKG_CHECK_MODULES(NM_UTILS, NetworkManager >= 0.9.0 libnm-util libnm_glib libnm_glib_vpn)]
index d756434..be60bcf 100644 (file)
@@ -9,6 +9,7 @@ Build-Depends: cdbs,
        libnm-glib-dev (>= 0.9),
        libnm-glib-vpn-dev (>= 0.9),
        libgnomeui-dev,
+       libsecret-1-dev,
        automake,
        gnome-common,
 Standards-Version: 3.8.3