[gnome-keyring] Use the XDG directories for storing keys
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring] Use the XDG directories for storing keys
- Date: Fri, 17 Aug 2012 08:28:09 +0000 (UTC)
commit 747b37bbd8fb82830524c8603f6fcf1ceae605dc
Author: Stef Walter <stefw gnome org>
Date: Sat Aug 11 07:18:59 2012 +0200
Use the XDG directories for storing keys
* If the new XDG directory doesn't exist, and the old
~/.gnome2/keyrings does exist, then continue to use that
* Otherwise create the new directory in g_get_user_data_dir() as
appropriate.
https://bugzilla.gnome.org/show_bug.cgi?id=613644
daemon/dbus/gkd-secret-service.c | 30 +++++++++++++++++++++---
pkcs11/gkm/gkm-util.c | 37 +++++++++++++++++++++++++++++++
pkcs11/gkm/gkm-util.h | 2 +
pkcs11/gnome2-store/gkm-gnome2-module.c | 7 +++++-
pkcs11/secret-store/gkm-secret-module.c | 11 +++++----
5 files changed, 77 insertions(+), 10 deletions(-)
---
diff --git a/daemon/dbus/gkd-secret-service.c b/daemon/dbus/gkd-secret-service.c
index 5efd66e..6319f5c 100644
--- a/daemon/dbus/gkd-secret-service.c
+++ b/daemon/dbus/gkd-secret-service.c
@@ -61,6 +61,7 @@ struct _GkdSecretService {
GkdSecretObjects *objects;
GHashTable *aliases;
GckSession *internal_session;
+ gchar *alias_directory;
};
typedef struct _ServiceClient {
@@ -82,9 +83,30 @@ G_DEFINE_TYPE (GkdSecretService, gkd_secret_service, G_TYPE_OBJECT);
*/
static gchar*
-default_path (void)
+default_path (GkdSecretService *self)
{
- return g_build_filename (g_get_home_dir (), ".gnome2", "keyrings", "default", NULL);
+ gchar *old_directory;
+ gchar *new_directory;
+
+ if (self->alias_directory == NULL) {
+ new_directory = g_build_filename (g_get_user_data_dir (), "keyrings", NULL);
+ old_directory = g_build_filename (g_get_home_dir (), ".gnome2", "keyrings", NULL);
+
+ if (!g_file_test (new_directory, G_FILE_TEST_IS_DIR) &&
+ g_file_test (old_directory, G_FILE_TEST_IS_DIR)) {
+ self->alias_directory = old_directory;
+ old_directory = NULL;
+ } else {
+ self->alias_directory = new_directory;
+ new_directory = NULL;
+ }
+
+ g_free (old_directory);
+ g_free (new_directory);
+ g_debug ("keyring alias directory: %s", self->alias_directory);
+ }
+
+ return g_build_filename (self->alias_directory, "default", NULL);
}
static void
@@ -100,7 +122,7 @@ update_default (GkdSecretService *self, gboolean force)
return;
}
- path = default_path ();
+ path = default_path (self);
if (g_file_get_contents (path, &contents, NULL, NULL)) {
g_strstrip (contents);
if (!contents[0]) {
@@ -124,7 +146,7 @@ store_default (GkdSecretService *self)
if (!identifier)
return;
- path = default_path ();
+ path = default_path (self);
if (!g_file_set_contents (path, identifier, -1, &error))
g_message ("couldn't store default keyring: %s", egg_error_message (error));
g_free (path);
diff --git a/pkcs11/gkm/gkm-util.c b/pkcs11/gkm/gkm-util.c
index 32fb722..0106d56 100644
--- a/pkcs11/gkm/gkm-util.c
+++ b/pkcs11/gkm/gkm-util.c
@@ -60,7 +60,10 @@
#include <glib.h>
#include <glib-object.h>
+#include <glib/gstdio.h>
+#include <errno.h>
+#include <fcntl.h>
#include <stdio.h>
#include <string.h>
@@ -135,3 +138,37 @@ gkm_util_dispose_unref (gpointer object)
g_object_run_dispose (G_OBJECT (object));
g_object_unref (object);
}
+
+gchar *
+gkm_util_locate_keyrings_directory (void)
+{
+ gchar *old_directory;
+ gchar *new_directory;
+ gchar *directory;
+
+ old_directory = g_build_filename (g_get_home_dir (), ".gnome2", "keyrings", NULL);
+ new_directory = g_build_filename (g_get_user_data_dir (), "keyrings", NULL);
+
+ /*
+ * If the new XDG directory doesn't exist, and the old one does,
+ * use the old one, otherwise create/use the new XDG location.
+ */
+
+ if (!g_file_test (new_directory, G_FILE_TEST_IS_DIR) &&
+ g_file_test (old_directory, G_FILE_TEST_IS_DIR)) {
+ directory = old_directory;
+ old_directory = NULL;
+
+ g_message ("using old keyring directory: %s", directory);
+ } else {
+ directory = new_directory;
+ new_directory = NULL;
+
+ if (g_mkdir_with_parents (directory, S_IRWXU) < 0)
+ g_warning ("unable to create keyring dir: %s", directory);
+ }
+
+ g_free (old_directory);
+ g_free (new_directory);
+ return directory;
+}
diff --git a/pkcs11/gkm/gkm-util.h b/pkcs11/gkm/gkm-util.h
index c9af5a7..06cd33a 100644
--- a/pkcs11/gkm/gkm-util.h
+++ b/pkcs11/gkm/gkm-util.h
@@ -64,4 +64,6 @@ CK_ULONG gkm_util_next_handle (void);
void gkm_util_dispose_unref (gpointer object);
+gchar * gkm_util_locate_keyrings_directory (void);
+
#endif /* GKM_UTIL_H_ */
diff --git a/pkcs11/gnome2-store/gkm-gnome2-module.c b/pkcs11/gnome2-store/gkm-gnome2-module.c
index a63e6af..4c51796 100644
--- a/pkcs11/gnome2-store/gkm-gnome2-module.c
+++ b/pkcs11/gnome2-store/gkm-gnome2-module.c
@@ -29,6 +29,8 @@
#include "gkm/gkm-certificate.h"
#include "gkm/gkm-data-asn1.h"
+#define DEBUG_FLAG GKM_DEBUG_STORAGE
+#include "gkm/gkm-debug.h"
#include "gkm/gkm-manager.h"
#include "gkm/gkm-secret.h"
#include "gkm/gkm-transaction.h"
@@ -264,10 +266,13 @@ static GObject*
gkm_gnome2_module_constructor (GType type, guint n_props, GObjectConstructParam *props)
{
GkmGnome2Module *self = GKM_GNOME2_MODULE (G_OBJECT_CLASS (gkm_gnome2_module_parent_class)->constructor(type, n_props, props));
+
g_return_val_if_fail (self, NULL);
if (!self->directory)
- self->directory = g_build_filename (g_get_home_dir (), ".gnome2", "keyrings", NULL);
+ self->directory = gkm_util_locate_keyrings_directory ();
+ gkm_debug ("gnome2 module directory: %s", self->directory);
+
self->storage = gkm_gnome2_storage_new (GKM_MODULE (self), self->directory);
return G_OBJECT (self);
diff --git a/pkcs11/secret-store/gkm-secret-module.c b/pkcs11/secret-store/gkm-secret-module.c
index cb22b0a..42d93f7 100644
--- a/pkcs11/secret-store/gkm-secret-module.c
+++ b/pkcs11/secret-store/gkm-secret-module.c
@@ -28,8 +28,11 @@
#include "gkm-secret-store.h"
#include "gkm/gkm-credential.h"
+#define DEBUG_FLAG GKM_DEBUG_STORAGE
+#include "gkm/gkm-debug.h"
#include "gkm/gkm-file-tracker.h"
#include "gkm/gkm-transaction.h"
+#include "gkm/gkm-util.h"
#include <glib/gstdio.h>
@@ -391,11 +394,9 @@ gkm_secret_module_constructor (GType type, guint n_props, GObjectConstructParam
g_return_val_if_fail (self, NULL);
- if (!self->directory) {
- self->directory = g_build_filename (g_get_home_dir (), ".gnome2", "keyrings", NULL);
- if (g_mkdir_with_parents (self->directory, S_IRWXU) < 0)
- g_warning ("unable to create keyring dir: %s", self->directory);
- }
+ if (!self->directory)
+ self->directory = gkm_util_locate_keyrings_directory ();
+ gkm_debug ("secret store directory: %s", self->directory);
self->tracker = gkm_file_tracker_new (self->directory, "*.keyring", NULL);
g_signal_connect (self->tracker, "file-added", G_CALLBACK (on_file_load), self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]