[gnome-initial-setup] Rework keyring handling again
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup] Rework keyring handling again
- Date: Wed, 5 Mar 2014 15:06:25 +0000 (UTC)
commit df1c5b356a692f90f1c6e1159b9440f18cb57204
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Mar 4 08:21:47 2014 -0500
Rework keyring handling again
This version just uses gnome-keyring-daemon directly to create
the login keyring, and updates the password when needed. We use
the new --unlock option of gnome-keyring-daemon to avoid the
complicated rendezvous protocol required for --login / --start.
configure.ac | 1 -
gnome-initial-setup/Makefile.am | 3 +-
gnome-initial-setup/gis-keyring.c | 161 +++++------
gnome-initial-setup/gis-keyring.h | 4 +-
gnome-initial-setup/gis-prompt.c | 313 --------------------
gnome-initial-setup/gis-prompt.h | 51 ----
gnome-initial-setup/gnome-initial-setup.c | 2 +-
.../pages/password/gis-password-page.c | 11 +
8 files changed, 93 insertions(+), 453 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 6fa9659..f888739 100644
--- a/configure.ac
+++ b/configure.ac
@@ -43,7 +43,6 @@ PKG_CHECK_MODULES(INITIAL_SETUP,
rest-0.7
json-glib-1.0
libsecret-1
- gcr-3
pwquality)
PKG_CHECK_MODULES(CHEESE,
diff --git a/gnome-initial-setup/Makefile.am b/gnome-initial-setup/Makefile.am
index acb80a2..6f7b47b 100644
--- a/gnome-initial-setup/Makefile.am
+++ b/gnome-initial-setup/Makefile.am
@@ -28,8 +28,7 @@ gnome_initial_setup_SOURCES = \
gis-assistant.c gis-assistant.h \
gis-page.c gis-page.h \
gis-driver.c gis-driver.h \
- gis-keyring.c gis-keyring.h \
- gis-prompt.c gis-prompt.h
+ gis-keyring.c gis-keyring.h
gnome_initial_setup_LDADD = \
pages/language/libgislanguage.la \
diff --git a/gnome-initial-setup/gis-keyring.c b/gnome-initial-setup/gis-keyring.c
index a7de651..136bc21 100644
--- a/gnome-initial-setup/gis-keyring.c
+++ b/gnome-initial-setup/gis-keyring.c
@@ -21,14 +21,13 @@
#include "config.h"
+#include <string.h>
+
#include <gio/gio.h>
#include "gis-keyring.h"
#include <libsecret/secret.h>
-#include <gcr/gcr.h>
-
-#include "gis-prompt.h"
/* We never want to see a keyring dialog, but we need to make
* sure a keyring is present.
@@ -38,90 +37,84 @@
* exist yet.
*/
-#define GCR_DBUS_PROMPTER_SYSTEM_BUS_NAME "org.gnome.keyring.SystemPrompter"
-
-static void
-on_bus_acquired (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
-{
- GcrSystemPrompter *prompter;
-
- prompter = gcr_system_prompter_new (GCR_SYSTEM_PROMPTER_SINGLE, GIS_TYPE_PROMPT);
- gcr_system_prompter_register (prompter, connection);
-}
-
-static void
-created_collection (GObject *source,
- GAsyncResult *result,
- gpointer user_data)
-{
- SecretCollection *collection;
- GError *error = NULL;
-
- collection = secret_collection_create_finish (result, &error);
- if (collection)
- {
- g_debug ("Created keyring '%s', %s\n",
- secret_collection_get_label (collection),
- secret_collection_get_locked (collection) ? "locked" : "unlocked");
- g_object_unref (collection);
- }
- else
- {
- g_warning ("Failed to create keyring: %s\n", error->message);
- g_error_free (error);
- }
-}
-
-static void
-got_alias (GObject *source,
- GAsyncResult *result,
- gpointer user_data)
-{
- SecretCollection *collection;
-
- collection = secret_collection_for_alias_finish (result, NULL);
- if (collection)
- {
- g_debug ("Found default keyring '%s', %s\n",
- secret_collection_get_label (collection),
- secret_collection_get_locked (collection) ? "locked" : "unlocked");
- g_object_unref (collection);
- }
- else
- {
- secret_collection_create (NULL, "login", SECRET_COLLECTION_DEFAULT, 0, NULL, created_collection, NULL);
- }
-}
-
-static void
-on_name_acquired (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
-{
- g_debug ("Got " GCR_DBUS_PROMPTER_SYSTEM_BUS_NAME "\n");
-
- secret_collection_for_alias (NULL, SECRET_COLLECTION_DEFAULT, SECRET_COLLECTION_NONE, NULL, got_alias,
NULL);
-}
-
-static void
-on_name_lost (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+void
+gis_ensure_login_keyring (const gchar *pwd)
{
- g_debug ("Lost " GCR_DBUS_PROMPTER_SYSTEM_BUS_NAME "\n");
+ GSubprocess *subprocess = NULL;
+ GSubprocessLauncher *launcher = NULL;
+ GError *error = NULL;
+
+ g_debug ("launching gnome-keyring-daemon --login");
+ launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE
| G_SUBPROCESS_FLAGS_STDERR_SILENCE);
+ subprocess = g_subprocess_launcher_spawn (launcher, &error, "gnome-keyring-daemon", "--unlock", NULL);
+ if (subprocess == NULL) {
+ g_warning ("Failed to spawn gnome-keyring-daemon --unlock: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ if (!g_subprocess_communicate_utf8 (subprocess, "gis", NULL, NULL, NULL, &error)) {
+ g_warning ("Failed to communicate with gnome-keyring-daemon: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+out:
+ if (subprocess)
+ g_object_unref (subprocess);
+ if (launcher)
+ g_object_unref (launcher);
}
void
-gis_ensure_keyring (void)
+gis_update_login_keyring_password (const gchar *old_, const gchar *new_)
{
- g_bus_own_name (G_BUS_TYPE_SESSION,
- GCR_DBUS_PROMPTER_SYSTEM_BUS_NAME,
- G_BUS_NAME_OWNER_FLAGS_REPLACE,
- on_bus_acquired,
- on_name_acquired,
- on_name_lost,
- NULL, NULL);
+ GDBusConnection *bus = NULL;
+ SecretService *service = NULL;
+ SecretValue *old_secret = NULL;
+ SecretValue *new_secret = NULL;
+ gchar *path = NULL;
+ GError *error = NULL;
+
+ service = secret_service_get_sync (0, NULL, &error);
+ if (service == NULL) {
+ g_warning ("Failed to get secret service: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (bus == NULL) {
+ g_warning ("Failed to get session bus: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ old_secret = secret_value_new (old_, strlen (old_), "text/plain");
+ new_secret = secret_value_new (new_, strlen (new_), "text/plain");
+
+ g_dbus_connection_call (bus,
+ "org.gnome.keyring",
+ "/org/gnome/keyring",
+ "org.gnome.keyring.InternalUnsupportedGuiltRiddenInterface",
+ "ChangeWithMasterPassword",
+ g_variant_new ("o@(oayays)@(oayays)",
+ "/org/freedesktop/secrets/collection/login",
+ secret_service_encode_dbus_secret (service, old_secret),
+ secret_service_encode_dbus_secret (service, new_secret)),
+ NULL,
+ 0,
+ G_MAXINT,
+ NULL, NULL, NULL);
+
+out:
+
+ if (service)
+ g_object_unref (service);
+ if (bus)
+ g_object_unref (bus);
+ if (old_secret)
+ secret_value_unref (old_secret);
+ if (new_secret)
+ secret_value_unref (new_secret);
}
-
diff --git a/gnome-initial-setup/gis-keyring.h b/gnome-initial-setup/gis-keyring.h
index 607417f..a33b76b 100644
--- a/gnome-initial-setup/gis-keyring.h
+++ b/gnome-initial-setup/gis-keyring.h
@@ -27,7 +27,9 @@
G_BEGIN_DECLS
-void gis_ensure_keyring (void);
+void gis_ensure_login_keyring (const gchar *pwd);
+void gis_update_login_keyring_password (const gchar *old_,
+ const gchar *new_);
G_END_DECLS
diff --git a/gnome-initial-setup/gnome-initial-setup.c b/gnome-initial-setup/gnome-initial-setup.c
index c73a621..a8f961d 100644
--- a/gnome-initial-setup/gnome-initial-setup.c
+++ b/gnome-initial-setup/gnome-initial-setup.c
@@ -219,7 +219,7 @@ main (int argc, char *argv[])
}
#endif
- gis_ensure_keyring ();
+ gis_ensure_login_keyring ("gis");
driver = gis_driver_new (get_mode ());
g_signal_connect (driver, "rebuild-pages", G_CALLBACK (rebuild_pages_cb), NULL);
diff --git a/gnome-initial-setup/pages/password/gis-password-page.c
b/gnome-initial-setup/pages/password/gis-password-page.c
index 76cb72f..8b683d1 100644
--- a/gnome-initial-setup/pages/password/gis-password-page.c
+++ b/gnome-initial-setup/pages/password/gis-password-page.c
@@ -28,6 +28,9 @@
#include "gis-password-page.h"
#include "gis-account-page-local.h"
#include "gis-account-page-enterprise.h"
+
+#include "gis-keyring.h"
+
#include "pw-utils.h"
#include <glib/gi18n.h>
@@ -76,6 +79,7 @@ gis_password_page_save_data (GisPage *gis_page)
GisPasswordPagePrivate *priv = gis_password_page_get_instance_private (page);
ActUser *act_user;
const gchar *password;
+ const gchar *old_password;
if (gis_page->driver == NULL)
return;
@@ -85,6 +89,11 @@ gis_password_page_save_data (GisPage *gis_page)
if (act_user == NULL) /* enterprise account */
return;
+ if (password)
+ old_password = password;
+ else
+ old_password = "gis";
+
password = gtk_entry_get_text (GTK_ENTRY (priv->password_entry));
if (strlen (password) == 0)
@@ -93,6 +102,8 @@ gis_password_page_save_data (GisPage *gis_page)
act_user_set_password (act_user, password, "");
gis_driver_set_user_permissions (gis_page->driver, act_user, password);
+
+ gis_update_login_keyring_password (old_password, password);
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]