[pan2] Build libsecret & gcr with gtk3 only, gnome-keyring with gtk2
- From: Petr Kovář <pmkovar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2] Build libsecret & gcr with gtk3 only, gnome-keyring with gtk2
- Date: Sun, 18 Jun 2017 19:16:44 +0000 (UTC)
commit 8f5e9f0fedc2694b1ea7d78353ce4392b303d327
Author: Petr Kovar <pknbe volny cz>
Date: Mon Jun 5 23:50:08 2017 +0200
Build libsecret & gcr with gtk3 only, gnome-keyring with gtk2
configure.ac | 17 +++++++++-----
pan/data-impl/data-impl.cc | 54 +++++++++++++++++++++++++++++++++++++++++++-
pan/data-impl/data-impl.h | 5 ++++
pan/data-impl/server.cc | 38 ++++++++++++++++++++++++++++++-
pan/data/data.h | 12 +++++++++
pan/gui/pan.cc | 6 +++++
pan/gui/server-ui.cc | 6 +++++
7 files changed, 130 insertions(+), 8 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9442e4b..ada5f49 100644
--- a/configure.ac
+++ b/configure.ac
@@ -61,6 +61,7 @@ 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
@@ -229,16 +230,20 @@ if test "x$enable_libnotify" = "xyes" ; then
fi
fi
-dnl Check for GNOME Keyring if user-enabled for password storage
+dnl Check for libsecret (GTK+ 3 only) or 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])
+ AS_HELP_STRING([--enable-gkr],[enable GNOME Keyring or libsecret support (normally:
no)]),[enable_gkr=$enableval],[enable_gkr=no])
if test "x$enable_gkr" = "xyes" ; then
- PKG_CHECK_MODULES([LIBGNOME_KEYRING_1],[libsecret-1 >= $LIBSECRET_REQUIRED gcr-3 >= $GCR_REQUIRED],
- [HAVE_GKR="yes"],[HAVE_GKR="no"])
+ if test "x$want_gtk3" = "xyes" ; then
+ PKG_CHECK_MODULES([LIBGNOME_KEYRING_1],[libsecret-1 >= $LIBSECRET_REQUIRED gcr-3 >= $GCR_REQUIRED],
+ [HAVE_GKR="yes"],[HAVE_GKR="no"])
+ else
+ PKG_CHECK_MODULES([LIBGNOME_KEYRING_1],[gnome-keyring-1 >=
$LIBGKR_REQUIRED],[HAVE_GKR="yes"],[HAVE_GKR="no"])
+ fi
AC_SUBST([LIBGNOME_KEYRING_1_CFLAGS])
AC_SUBST([LIBGNOME_KEYRING_1_LIBS])
if test "x$HAVE_GKR" = "xyes"; then
- AC_DEFINE([HAVE_GKR],[1],[GNOME Keyring support for password storage])
+ AC_DEFINE([HAVE_GKR],[1],[GNOME Keyring or libsecret support for password storage])
fi
fi
@@ -345,7 +350,7 @@ Configuration:
With WebKitGTK+: ${want_webkit}
With GnuTLS: ${gnutls_msg}
With libnotify: ${enable_libnotify}
- With GNOME Keyring: ${enable_gkr}
+ With password storage: ${enable_gkr}
With yelp-tools: ${want_yelp_tools}
With user manual: ${enable_manual}
"
diff --git a/pan/data-impl/data-impl.cc b/pan/data-impl/data-impl.cc
index afd7d7f..74748ea 100644
--- a/pan/data-impl/data-impl.cc
+++ b/pan/data-impl/data-impl.cc
@@ -34,10 +34,15 @@ extern "C" {
#include "data-impl.h"
#ifdef HAVE_GKR
+#if GTK_CHECK_VERSION(3,0,0)
#define GCR_API_SUBJECT_TO_CHANGE
#include <libsecret/secret.h>
#include <gcr/gcr.h>
#undef GCR_API_SUBJECT_TO_CHANGE
+#else
+ #include <gnome-keyring-1/gnome-keyring.h>
+ #include <gnome-keyring-1/gnome-keyring-memory.h>
+#endif /* GTK_CHECK_VERSION(3,0,0) */
#endif
using namespace pan;
@@ -133,10 +138,10 @@ DataImpl :: save_state ()
}
#ifdef HAVE_GKR
+#if GTK_CHECK_VERSION(3,0,0)
gboolean
DataImpl :: password_encrypt (const PasswordData& pw)
{
-// g_return_val_if_fail (pw, GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON);
GError *error_c = NULL;
return (
@@ -180,4 +185,51 @@ DataImpl :: password_decrypt (PasswordData& pw) const
return pwd;
}
+#else
+GnomeKeyringResult
+DataImpl :: password_encrypt (const PasswordData& pw)
+{
+// g_return_val_if_fail (pw, GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON);
+
+ return (
+ gnome_keyring_store_password_sync (
+ GNOME_KEYRING_NETWORK_PASSWORD,
+ GNOME_KEYRING_DEFAULT,
+ _("Pan Newsreader's server passwords"),
+ pw.pw,
+ "user", pw.user.str,
+ "server", pw.server.c_str(),
+ NULL)
+ );
+
+}
+
+// TODO use gnome_keyring_memory_new etc
+GnomeKeyringResult
+DataImpl :: password_decrypt (PasswordData& pw) const
+{
+
+ gchar* pwd = NULL;
+
+ GnomeKeyringResult ret =
+ gnome_keyring_find_password_sync (
+ GNOME_KEYRING_NETWORK_PASSWORD,
+ &pwd,
+ "user", pw.user.str,
+ "server", pw.server.c_str(),
+ NULL);
+
+ if (pwd)
+ {
+ pw.pw = gnome_keyring_memory_strdup(pwd);
+ gnome_keyring_free_password(pwd);
+ }
+ else
+ {
+ pw.pw = const_cast<gchar*>("");
+ }
+
+ return (pw.pw ? GNOME_KEYRING_RESULT_OK : GNOME_KEYRING_RESULT_DENIED) ;
+}
+#endif /* GTK_CHECK_VERSION(3,0,0) */
#endif
diff --git a/pan/data-impl/data-impl.h b/pan/data-impl/data-impl.h
index 18eb010..4c0974a 100644
--- a/pan/data-impl/data-impl.h
+++ b/pan/data-impl/data-impl.h
@@ -106,8 +106,13 @@ namespace pan
public:
#ifdef HAVE_GKR
+#if GTK_CHECK_VERSION(3,0,0)
gboolean password_encrypt (const PasswordData&);
gchar* password_decrypt (PasswordData&) const;
+#else
+ GnomeKeyringResult password_encrypt (const PasswordData&);
+ GnomeKeyringResult password_decrypt (PasswordData&) const;
+#endif /* GTK_CHECK_VERSION(3,0,0) */
#endif
private:
diff --git a/pan/data-impl/server.cc b/pan/data-impl/server.cc
index d45a4c0..602262d 100644
--- a/pan/data-impl/server.cc
+++ b/pan/data-impl/server.cc
@@ -242,6 +242,7 @@ DataImpl :: get_server_auth (const Quark & server,
#ifndef HAVE_GKR
setme_password = g_strdup(s->password.c_str());
#else
+#if GTK_CHECK_VERSION(3,0,0)
if (!use_gkr)
{
setme_password = g_strdup(s->password.c_str());
@@ -258,7 +259,7 @@ DataImpl :: get_server_auth (const Quark & server,
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());
+ Log::add_urgent_va (_("Received no password from libsecret for server %s."), s->host.c_str());
}
else
{
@@ -266,6 +267,41 @@ DataImpl :: get_server_auth (const Quark & server,
s->gkr_pw = pw.pw;
}
}
+#else
+ if (!use_gkr)
+ {
+ setme_password = g_strdup(s->password.c_str());
+ }
+ else if (s->gkr_pw)
+ {
+ setme_password = s->gkr_pw;
+ }
+ else
+ {
+ 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);
+ setme_password = pw.pw;
+ s->gkr_pw = pw.pw;
+ break;
+
+ default:
+ break;
+ }
+ }
+#endif /* GTK_CHECK_VERSION(3,0,0) */
#endif
}
diff --git a/pan/data/data.h b/pan/data/data.h
index 52018e3..f914b69 100644
--- a/pan/data/data.h
+++ b/pan/data/data.h
@@ -39,6 +39,13 @@
#include <pan/gui/prefs.h>
#include <pan/gui/progress-view.h>
+#ifdef HAVE_GKR
+#if !GTK_CHECK_VERSION(3,0,0)
+ #include <gnome-keyring-1/gnome-keyring.h>
+ #include <gnome-keyring-1/gnome-keyring-memory.h>
+#endif /* !GTK_CHECK_VERSION(3,0,0) */
+#endif
+
namespace pan
{
class FilterInfo;
@@ -224,8 +231,13 @@ namespace pan
public:
#ifdef HAVE_GKR
+#if GTK_CHECK_VERSION(3,0,0)
virtual gboolean password_encrypt (const PasswordData&) = 0;
virtual gchar* password_decrypt (PasswordData&) const = 0;
+#else
+ virtual GnomeKeyringResult password_encrypt (const PasswordData&) = 0;
+ virtual GnomeKeyringResult password_decrypt (PasswordData&) const = 0;
+#endif /* GTK_CHECK_VERSION(3,0,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 2b5ccb4..4083675 100644
--- a/pan/gui/pan.cc
+++ b/pan/gui/pan.cc
@@ -49,10 +49,12 @@ extern "C" {
#endif
#ifdef HAVE_GKR
+#if GTK_CHECK_VERSION(3,0,0)
#define GCR_API_SUBJECT_TO_CHANGE
#include <libsecret/secret.h>
#include <gcr/gcr.h>
#undef GCR_API_SUBJECT_TO_CHANGE
+#endif /* GTK_CHECK_VERSION(3,0,0) */
#endif
#include <config.h>
@@ -1149,7 +1151,11 @@ main (int argc, char *argv[])
Data::Server* s(data.find_server(*it));
if (s && s->gkr_pw)
{
+#if GTK_CHECK_VERSION(3,0,0)
gcr_secure_memory_free(s->gkr_pw);
+#else
+ gnome_keyring_memory_free(s->gkr_pw);
+#endif /* GTK_CHECK_VERSION(3,0,0) */
}
}
}
diff --git a/pan/gui/server-ui.cc b/pan/gui/server-ui.cc
index 255e8bc..d6f3e69 100644
--- a/pan/gui/server-ui.cc
+++ b/pan/gui/server-ui.cc
@@ -44,10 +44,12 @@ extern "C" {
#endif
#ifdef HAVE_GKR
+#if GTK_CHECK_VERSION(3,0,0)
#define GCR_API_SUBJECT_TO_CHANGE
#include <libsecret/secret.h>
#include <gcr/gcr.h>
#undef GCR_API_SUBJECT_TO_CHANGE
+#endif /* GTK_CHECK_VERSION(3,0,0) */
#endif
using namespace pan;
@@ -231,8 +233,12 @@ 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
+#if GTK_CHECK_VERSION(3,0,0)
gchar* pass = gcr_secure_memory_strdup(gtk_entry_get_text(GTK_ENTRY(d->auth_password_entry)));
#else
+ gchar* pass = gnome_keyring_memory_strdup(gtk_entry_get_text(GTK_ENTRY(d->auth_password_entry)));
+#endif /* GTK_CHECK_VERSION(3,0,0) */
+#else
gchar* pass = (gchar*)gtk_entry_get_text(GTK_ENTRY(d->auth_password_entry));
#endif
int age (31);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]