summaryrefslogtreecommitdiff
path: root/pkcs11
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2012-08-11 07:18:59 +0200
committerStef Walter <stefw@gnome.org>2012-08-17 10:27:15 +0200
commit747b37bbd8fb82830524c8603f6fcf1ceae605dc (patch)
tree008369d57e4c69f8ec41b42805f7ae6a749805e4 /pkcs11
parent6700ef0a6aa8a43a4ba2b43b30a85206407d1264 (diff)
downloadgnome-keyring-747b37bbd8fb82830524c8603f6fcf1ceae605dc.tar.gz
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
Diffstat (limited to 'pkcs11')
-rw-r--r--pkcs11/gkm/gkm-util.c37
-rw-r--r--pkcs11/gkm/gkm-util.h2
-rw-r--r--pkcs11/gnome2-store/gkm-gnome2-module.c7
-rw-r--r--pkcs11/secret-store/gkm-secret-module.c11
4 files changed, 51 insertions, 6 deletions
diff --git a/pkcs11/gkm/gkm-util.c b/pkcs11/gkm/gkm-util.c
index 32fb722e..0106d562 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 c9af5a78..06cd33af 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 a63e6aff..4c517963 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 cb22b0a4..42d93f7a 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);