[gnome-initial-setup/shell/4765: 95/362] Rework keyring handling again
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup/shell/4765: 95/362] Rework keyring handling again
- Date: Thu, 19 Mar 2015 01:29:03 +0000 (UTC)
commit f1ad95e0306441542fc0f68d8ded67c6d1c0de45
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.
Conflicts:
configure.ac
gnome-initial-setup/gnome-initial-setup.c
gnome-initial-setup/pages/password/gis-password-page.c
[endlessm/eos-shell#2901]
configure.ac | 4 +-
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/account/gis-account-page.c | 10 +-
8 files changed, 91 insertions(+), 457 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index bd14034..a18b192 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,7 +40,6 @@ PKG_CHECK_MODULES(INITIAL_SETUP,
polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION
accountsservice
gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION
- gnome-keyring-1
gstreamer-1.0
fontconfig
geoclue-2.0
@@ -54,8 +53,7 @@ PKG_CHECK_MODULES(INITIAL_SETUP,
pango >= $PANGO_REQUIRED_VERSION
pwquality
egg-list-box-uninstalled
- libsecret-1
- gcr-3)
+ libsecret-1)
PKG_CHECK_MODULES(COPY_WORKER, gio-2.0 gnome-keyring-1)
diff --git a/gnome-initial-setup/Makefile.am b/gnome-initial-setup/Makefile.am
index d2504a2..571b1e0 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 04677bb..9b706b2 100644
--- a/gnome-initial-setup/gnome-initial-setup.c
+++ b/gnome-initial-setup/gnome-initial-setup.c
@@ -272,7 +272,7 @@ main (int argc, char *argv[])
#endif
g_type_ensure (EGG_TYPE_LIST_BOX);
- 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/account/gis-account-page.c
b/gnome-initial-setup/pages/account/gis-account-page.c
index 51025e4..9d728b3 100644
--- a/gnome-initial-setup/pages/account/gis-account-page.c
+++ b/gnome-initial-setup/pages/account/gis-account-page.c
@@ -31,7 +31,6 @@
#include <glib/gi18n.h>
#include <gio/gio.h>
-#include <gnome-keyring.h>
#include <act/act-user-manager.h>
@@ -467,7 +466,9 @@ local_create_user (GisAccountPage *page)
{
GisAccountPagePrivate *priv = gis_account_page_get_instance_private (page);
const gchar *username;
+ const gchar *old_username;
const gchar *password;
+ const gchar *old_password;
const gchar *fullname;
const gchar *language;
gboolean autologin_active;
@@ -491,13 +492,16 @@ local_create_user (GisAccountPage *page)
return;
}
+ gis_driver_get_user_permissions (GIS_PAGE (page)->driver, &old_username, &old_password);
+ if (!old_password)
+ old_password = "gis";
+
act_user_set_user_name (priv->act_user, username);
act_user_set_account_type (priv->act_user, priv->account_type);
if (strlen (password) == 0) {
act_user_set_password_mode (priv->act_user, ACT_USER_PASSWORD_MODE_NONE);
} else {
act_user_set_password (priv->act_user, password, "");
- gnome_keyring_create_sync ("login", password);
save_user_password (password);
}
@@ -510,6 +514,8 @@ local_create_user (GisAccountPage *page)
priv->act_user,
password);
+ gis_update_login_keyring_password (old_password, password);
+
if (autologin_active) {
lock_settings = g_settings_new ("org.gnome.desktop.screensaver");
g_settings_set_boolean (lock_settings, "lock-enabled", FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]