[pan2] Remove dependency on deprecated libgnome-keyring. New libs used: libsecret and gcr (Gtk+ 3).



commit 1cf6b97774af563357240c5571b6f7aee37db72e
Author: Detlef Graef <detlef graef yahoo de>
Date:   Sat Jun 3 16:00:01 2017 +0200

    Remove dependency on deprecated libgnome-keyring. New libs used: libsecret and gcr (Gtk+ 3).

 configure.ac               |    8 ++++++--
 pan/data-impl/data-impl.cc |   36 ++++++++++++++++++++----------------
 pan/data-impl/data-impl.h  |    4 ++--
 pan/data-impl/server.cc    |   21 ++++++---------------
 pan/data/data.h            |    9 ++-------
 pan/gui/pan.cc             |    9 ++++++++-
 pan/gui/server-ui.cc       |    9 ++++++++-
 7 files changed, 52 insertions(+), 44 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index dd93b0b..9442e4b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -61,7 +61,8 @@ GTKSPELL3_REQUIRED=2.0.16
 ENCHANT_REQUIRED=1.6.0
 GNUTLS_REQUIRED=3.0.0
 LIBNOTIFY_REQUIRED=0.4.1
-LIBGKR_REQUIRED=3.2.0
+LIBSECRET_REQUIRED=0.16
+GCR_REQUIRED=3.20
 WEBKIT_REQUIRED=1.8.1
 AC_SUBST(GLIB_REQUIRED)
 AC_SUBST(GLIB_REQUIRED_FOR_DBUS)
@@ -71,6 +72,8 @@ AC_SUBST(GTKSPELL_REQUIRED)
 AC_SUBST(GNUTLS_REQUIRED)
 AC_SUBST(LIBNOTIFY_REQUIRED)
 AC_SUBST(LIBGKR_REQUIRED)
+AC_SUBST(LIBSECRET_REQUIRED)
+AC_SUBST(GCR_REQUIRED)
 AC_SUBST(WEBKIT_REQUIRED)
 
 AC_PROG_CXX
@@ -230,7 +233,8 @@ dnl Check for GNOME Keyring if user-enabled for password storage
 AC_ARG_ENABLE([gkr],
   AS_HELP_STRING([--enable-gkr],[enable GNOME Keyring support (normally: 
no)]),[enable_gkr=$enableval],[enable_gkr=no])
 if test "x$enable_gkr" = "xyes" ; then
-  PKG_CHECK_MODULES([LIBGNOME_KEYRING_1],[gnome-keyring-1 >= 
$LIBGKR_REQUIRED],[HAVE_GKR="yes"],[HAVE_GKR="no"])
+  PKG_CHECK_MODULES([LIBGNOME_KEYRING_1],[libsecret-1 >= $LIBSECRET_REQUIRED gcr-3 >= $GCR_REQUIRED],
+  [HAVE_GKR="yes"],[HAVE_GKR="no"])
   AC_SUBST([LIBGNOME_KEYRING_1_CFLAGS])
   AC_SUBST([LIBGNOME_KEYRING_1_LIBS])
   if test "x$HAVE_GKR" = "xyes"; then
diff --git a/pan/data-impl/data-impl.cc b/pan/data-impl/data-impl.cc
index ee940a3..afd7d7f 100644
--- a/pan/data-impl/data-impl.cc
+++ b/pan/data-impl/data-impl.cc
@@ -34,8 +34,10 @@ extern "C" {
 #include "data-impl.h"
 
 #ifdef HAVE_GKR
-  #include <gnome-keyring-1/gnome-keyring.h>
-  #include <gnome-keyring-1/gnome-keyring-memory.h>
+  #define GCR_API_SUBJECT_TO_CHANGE
+  #include <libsecret/secret.h>
+  #include <gcr/gcr.h>
+  #undef GCR_API_SUBJECT_TO_CHANGE
 #endif
 
 using namespace pan;
@@ -131,17 +133,19 @@ DataImpl :: save_state ()
 }
 
 #ifdef HAVE_GKR
-GnomeKeyringResult
+gboolean
 DataImpl :: password_encrypt (const PasswordData& pw)
 {
 //  g_return_val_if_fail (pw, GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON);
+GError *error_c = NULL;
 
   return (
-    gnome_keyring_store_password_sync (
-      GNOME_KEYRING_NETWORK_PASSWORD,
-      GNOME_KEYRING_DEFAULT,
+    secret_password_store_sync (
+      SECRET_SCHEMA_COMPAT_NETWORK,
+      SECRET_COLLECTION_DEFAULT,
       _("Pan Newsreader's server passwords"),
       pw.pw,
+      NULL, &error_c,
       "user", pw.user.str,
       "server", pw.server.c_str(),
       NULL)
@@ -149,31 +153,31 @@ DataImpl :: password_encrypt (const PasswordData& pw)
 
 }
 
-// TODO use gnome_keyring_memory_new etc
-GnomeKeyringResult
+gchar*
 DataImpl :: password_decrypt (PasswordData& pw) const
 {
-
+  GError *error_c = NULL;
   gchar* pwd = NULL;
 
-  GnomeKeyringResult ret =
-    gnome_keyring_find_password_sync (
-    GNOME_KEYRING_NETWORK_PASSWORD,
-    &pwd,
+  pwd =
+    secret_password_lookup_sync (
+    SECRET_SCHEMA_COMPAT_NETWORK,
+    NULL,
+    &error_c,
     "user", pw.user.str,
     "server", pw.server.c_str(),
     NULL);
 
   if (pwd)
   {
-    pw.pw = gnome_keyring_memory_strdup(pwd);
-    gnome_keyring_free_password(pwd);
+    pw.pw = gcr_secure_memory_strdup(pwd);
+    secret_password_free(pwd);
   }
   else
   {
     pw.pw = const_cast<gchar*>("");
   }
 
-  return (pw.pw ? GNOME_KEYRING_RESULT_OK : GNOME_KEYRING_RESULT_DENIED) ;
+  return pwd;
 }
 #endif
diff --git a/pan/data-impl/data-impl.h b/pan/data-impl/data-impl.h
index d539bc2..18eb010 100644
--- a/pan/data-impl/data-impl.h
+++ b/pan/data-impl/data-impl.h
@@ -106,8 +106,8 @@ namespace pan
 
     public:
 #ifdef HAVE_GKR
-      GnomeKeyringResult password_encrypt (const PasswordData&);
-      GnomeKeyringResult password_decrypt (PasswordData&) const;
+      gboolean password_encrypt (const PasswordData&);
+      gchar* password_decrypt (PasswordData&) const;
 #endif
     private:
 
diff --git a/pan/data-impl/server.cc b/pan/data-impl/server.cc
index 4c013e6..d45a4c0 100644
--- a/pan/data-impl/server.cc
+++ b/pan/data-impl/server.cc
@@ -255,24 +255,15 @@ DataImpl :: get_server_auth (const Quark   & server,
       PasswordData pw;
       pw.server = s->host;
       pw.user = s->username;
-      switch (password_decrypt(pw))
-      {
-        case GNOME_KEYRING_RESULT_NO_MATCH:
-          Log::add_info_va(_("There seems to be no password set for server %s."), s->host.c_str());
-          break;
-
-        case GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON:
-          Log::add_urgent_va (_("GNOME Keyring denied access to the passwords."), s->host.c_str());
-          break;
 
-        case GNOME_KEYRING_RESULT_OK:
-//          setme_password.assign(pw.pw.str, pw.pw.len);
+      if (password_decrypt(pw) == NULL)
+      {
+                 Log::add_urgent_va (_("Got no password from libsecret API-Call 
secret_password_lookup_sync() for server %s."), s->host.c_str());
+      }
+      else
+      {
           setme_password = pw.pw;
           s->gkr_pw = pw.pw;
-          break;
-
-        default:
-          break;
       }
     }
 #endif
diff --git a/pan/data/data.h b/pan/data/data.h
index 7c771a3..52018e3 100644
--- a/pan/data/data.h
+++ b/pan/data/data.h
@@ -39,11 +39,6 @@
 #include <pan/gui/prefs.h>
 #include <pan/gui/progress-view.h>
 
-#ifdef HAVE_GKR
-  #include <gnome-keyring-1/gnome-keyring.h>
-  #include <gnome-keyring-1/gnome-keyring-memory.h>
-#endif
-
 namespace pan
 {
   class FilterInfo;
@@ -229,8 +224,8 @@ namespace pan
 
     public:
 #ifdef HAVE_GKR
-      virtual GnomeKeyringResult password_encrypt (const PasswordData&) = 0;
-      virtual GnomeKeyringResult password_decrypt (PasswordData&) const = 0;
+      virtual gboolean password_encrypt (const PasswordData&) = 0;
+      virtual gchar* password_decrypt (PasswordData&) const = 0;
 #endif
       /** Gets a quark to the provided hostname */
       virtual bool find_server_by_hn (const std::string& server, Quark& setme) const = 0;
diff --git a/pan/gui/pan.cc b/pan/gui/pan.cc
index b7c4490..2b5ccb4 100644
--- a/pan/gui/pan.cc
+++ b/pan/gui/pan.cc
@@ -48,6 +48,13 @@ extern "C" {
   #include <pan/tasks/socket-impl-openssl.h>
 #endif
 
+#ifdef HAVE_GKR
+  #define GCR_API_SUBJECT_TO_CHANGE
+  #include <libsecret/secret.h>
+  #include <gcr/gcr.h>
+  #undef GCR_API_SUBJECT_TO_CHANGE
+#endif
+
 #include <config.h>
 #include <pan/general/debug.h>
 #include <pan/general/log.h>
@@ -1142,7 +1149,7 @@ main (int argc, char *argv[])
       Data::Server* s(data.find_server(*it));
       if (s && s->gkr_pw)
       {
-        gnome_keyring_memory_free(s->gkr_pw);
+        gcr_secure_memory_free(s->gkr_pw);
       }
     }
   }
diff --git a/pan/gui/server-ui.cc b/pan/gui/server-ui.cc
index 0895c61..255e8bc 100644
--- a/pan/gui/server-ui.cc
+++ b/pan/gui/server-ui.cc
@@ -43,6 +43,13 @@ extern "C" {
   #include <gnutls/gnutls.h>
 #endif
 
+#ifdef HAVE_GKR
+  #define GCR_API_SUBJECT_TO_CHANGE
+  #include <libsecret/secret.h>
+  #include <gcr/gcr.h>
+  #undef GCR_API_SUBJECT_TO_CHANGE
+#endif
+
 using namespace pan;
 
 /************
@@ -224,7 +231,7 @@ namespace
       const int max_conn (gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(d->connection_limit_spin)));
       StringView user (pan_entry_get_text (d->auth_username_entry));
 #ifdef HAVE_GKR
-      gchar* pass = gnome_keyring_memory_strdup(gtk_entry_get_text(GTK_ENTRY(d->auth_password_entry)));
+      gchar* pass = gcr_secure_memory_strdup(gtk_entry_get_text(GTK_ENTRY(d->auth_password_entry)));
 #else
       gchar* pass = (gchar*)gtk_entry_get_text(GTK_ENTRY(d->auth_password_entry));
 #endif


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