From a88831a01858bf0b76cf4d0d612071e94d9e26db Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Tue, 29 Mar 2016 19:33:26 +0200 Subject: [PATCH] nm: Replace libgnomekeyring with libsecret The former is deprecated and the newer API is nicer anyway. --- src/frontends/gnome/auth-dialog/Makefile.am | 5 +- src/frontends/gnome/auth-dialog/main.c | 52 +++++++-------------- src/frontends/gnome/configure.ac | 2 +- src/frontends/gnome/debian/control | 1 + 4 files changed, 20 insertions(+), 40 deletions(-) diff --git a/src/frontends/gnome/auth-dialog/Makefile.am b/src/frontends/gnome/auth-dialog/Makefile.am index 7bbd71d58d..9c9f7d6a0c 100644 --- a/src/frontends/gnome/auth-dialog/Makefile.am +++ b/src/frontends/gnome/auth-dialog/Makefile.am @@ -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) - diff --git a/src/frontends/gnome/auth-dialog/main.c b/src/frontends/gnome/auth-dialog/main.c index b9fd886d57..3d5d843902 100644 --- a/src/frontends/gnome/auth-dialog/main.c +++ b/src/frontends/gnome/auth-dialog/main.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -31,35 +31,6 @@ #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 */ @@ -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 diff --git a/src/frontends/gnome/configure.ac b/src/frontends/gnome/configure.ac index 0aee4a5d5f..f9da6c01cb 100644 --- a/src/frontends/gnome/configure.ac +++ b/src/frontends/gnome/configure.ac @@ -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)] diff --git a/src/frontends/gnome/debian/control b/src/frontends/gnome/debian/control index d756434f67..be60bcf143 100644 --- a/src/frontends/gnome/debian/control +++ b/src/frontends/gnome/debian/control @@ -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 -- 2.47.2