From 25b418355f07ed01965aed68c25c3ce65168d5d4 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Sun, 14 Sep 2014 12:18:29 +0200 Subject: Port to libsecret --- auth-dialog/Makefile.am | 4 +-- auth-dialog/main.c | 68 +++++++++++++++++++++++++-------------- auth-dialog/vpn-password-dialog.c | 1 - configure.ac | 6 ++-- 4 files changed, 48 insertions(+), 31 deletions(-) diff --git a/auth-dialog/Makefile.am b/auth-dialog/Makefile.am index fe45a82..97046af 100644 --- a/auth-dialog/Makefile.am +++ b/auth-dialog/Makefile.am @@ -6,7 +6,7 @@ nm_iodine_auth_dialog_CPPFLAGS = \ $(NM_CFLAGS) \ $(GTHREAD_CFLAGS) \ $(GTK_CFLAGS) \ - $(GNOMEKEYRING_CFLAGS) \ + $(LIBSECRET_CFLAGS) \ -DICONDIR=\""$(datadir)/pixmaps"\" \ -DBINDIR=\""$(bindir)"\" \ -DG_DISABLE_DEPRECATED \ @@ -24,7 +24,7 @@ nm_iodine_auth_dialog_SOURCES = \ nm_iodine_auth_dialog_LDADD = \ $(GTK_LIBS) \ $(NM_LIBS) \ - $(GNOMEKEYRING_LIBS) + $(LIBSECRET_LIBS) CLEANFILES = *~ diff --git a/auth-dialog/main.c b/auth-dialog/main.c index 03586e4..4321c64 100644 --- a/auth-dialog/main.c +++ b/auth-dialog/main.c @@ -16,7 +16,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright © 2012 Guido Günther + * Copyright © 2012,2014 Guido Günther * * Heavily based on network-manager-pptp by Dan Williams */ @@ -31,8 +31,8 @@ #include #include -#include -#include +#define SECRET_API_SUBJECT_TO_CHANGE +#include #include #include @@ -47,6 +47,19 @@ #define UI_KEYFILE_GROUP "VPN Plugin UI" + +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 }, + } +}; + + static void keyfile_add_entry_info (GKeyFile *keyfile, const gchar *key, @@ -78,29 +91,34 @@ keyfile_print_stdout (GKeyFile *keyfile) 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; } @@ -128,14 +146,14 @@ get_secrets (const char *vpn_uuid, if (!(pw_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) && !(pw_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) { if (in_pw) - pw = gnome_keyring_memory_strdup (in_pw); + pw = g_strdup (in_pw); else pw = keyring_lookup_secret (vpn_uuid, NM_IODINE_KEY_PASSWORD); } /* Don't ask if the passwords is unused */ if (pw_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED) { - gnome_keyring_memory_free (pw); + g_free (pw); return TRUE; } @@ -197,7 +215,7 @@ get_secrets (const char *vpn_uuid, new_password = vpn_password_dialog_get_password (dialog); if (new_password) { - *out_pw = gnome_keyring_memory_strdup (new_password); + *out_pw = g_strdup (new_password); success = TRUE; } } diff --git a/auth-dialog/vpn-password-dialog.c b/auth-dialog/vpn-password-dialog.c index 6b5cb34..c19d686 100644 --- a/auth-dialog/vpn-password-dialog.c +++ b/auth-dialog/vpn-password-dialog.c @@ -23,7 +23,6 @@ */ #include -#include #include #include diff --git a/configure.ac b/configure.ac index cc9e348..86470a2 100644 --- a/configure.ac +++ b/configure.ac @@ -67,9 +67,9 @@ if test x"$with_gnome" != xno; then AC_SUBST(GTK_CFLAGS) AC_SUBST(GTK_LIBS) - PKG_CHECK_MODULES(GNOMEKEYRING, gnome-keyring-1) - AC_SUBST(GNOMEKEYRING_CFLAGS) - AC_SUBST(GNOMEKEYRING_LIBS) + PKG_CHECK_MODULES(LIBSECRET, libsecret-1) + AC_SUBST(LIBSECRET_CFLAGS) + AC_SUBST(LIBSECRET_LIBS) fi PKG_CHECK_MODULES(NM, -- cgit v1.2.3