[gnome-keyring] secret-store: Set the schema name correctly on loaded items
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring] secret-store: Set the schema name correctly on loaded items
- Date: Fri, 12 Oct 2012 17:47:12 +0000 (UTC)
commit b7648ca3864cf8d952468bae299806b0fcda5442
Author: Stef Walter <stefw gnome org>
Date: Fri Oct 12 17:39:53 2012 +0200
secret-store: Set the schema name correctly on loaded items
* When we loaded items from the keyring we didn't set the schema
correctly.
* This causes any searches for the item that include a schema
in the search parameters to fail.
* Also caused problems storing items, when it was expected that
the item would replace any already stored. This uses a search
internally.
* Fix and add a test for this case, both for encrypted and
plaintext keyring files.
https://bugzilla.gnome.org/show_bug.cgi?id=681727
pkcs11/secret-store/gkm-secret-binary.c | 9 +++++--
pkcs11/secret-store/gkm-secret-textual.c | 15 ++++++++++--
.../tests/files/encrypted-with-schema.keyring | Bin 0 -> 404 bytes
.../tests/files/plain-with-schema.keyring | 23 ++++++++++++++++++++
pkcs11/secret-store/tests/test-secret-binary.c | 21 ++++++++++++++++++
pkcs11/secret-store/tests/test-secret-textual.c | 23 ++++++++++++++++++++
6 files changed, 85 insertions(+), 6 deletions(-)
---
diff --git a/pkcs11/secret-store/gkm-secret-binary.c b/pkcs11/secret-store/gkm-secret-binary.c
index b8dbef7..92ba8ca 100644
--- a/pkcs11/secret-store/gkm-secret-binary.c
+++ b/pkcs11/secret-store/gkm-secret-binary.c
@@ -738,15 +738,18 @@ static void
setup_item_from_info (GkmSecretItem *item, GkmSecretData *data, ItemInfo *info)
{
GkmSecretObject *obj = GKM_SECRET_OBJECT (item);
+ const gchar *schema_name;
GkmSecret *secret;
- const gchar *type;
gkm_secret_object_set_label (obj, info->display_name);
gkm_secret_object_set_created (obj, info->ctime);
gkm_secret_object_set_modified (obj, info->mtime);
- type = gkm_secret_compat_format_item_type (info->type);
- gkm_secret_item_set_schema (item, type);
+ schema_name = g_hash_table_lookup (info->attributes, GKM_SECRET_FIELD_SCHEMA);
+ if (schema_name == NULL)
+ schema_name = gkm_secret_compat_format_item_type (info->type);
+ gkm_secret_item_set_schema (item, schema_name);
+
gkm_secret_item_set_fields (item, info->attributes);
/* Collection is locked */
diff --git a/pkcs11/secret-store/gkm-secret-textual.c b/pkcs11/secret-store/gkm-secret-textual.c
index af7bc37..358c3cc 100644
--- a/pkcs11/secret-store/gkm-secret-textual.c
+++ b/pkcs11/secret-store/gkm-secret-textual.c
@@ -122,7 +122,10 @@ generate_attributes (GKeyFile *file, GkmSecretItem *item)
}
static void
-parse_attributes (GKeyFile *file, GkmSecretItem *item, const gchar **groups)
+parse_attributes (GKeyFile *file,
+ GkmSecretItem *item,
+ const gchar **groups,
+ gint compat_type)
{
GHashTable *attributes;
const gchar *identifier;
@@ -130,6 +133,7 @@ parse_attributes (GKeyFile *file, GkmSecretItem *item, const gchar **groups)
gchar *prefix;
gchar *name, *type;
guint64 number;
+ const gchar *schema_name;
/* Now do the attributes */
@@ -163,6 +167,12 @@ parse_attributes (GKeyFile *file, GkmSecretItem *item, const gchar **groups)
}
gkm_secret_item_set_fields (item, attributes);
+
+ schema_name = g_hash_table_lookup (attributes, GKM_SECRET_FIELD_SCHEMA);
+ if (schema_name == NULL)
+ schema_name = gkm_secret_compat_format_item_type (compat_type);
+ gkm_secret_item_set_schema (item, schema_name);
+
g_hash_table_unref (attributes);
g_free (prefix);
}
@@ -331,7 +341,6 @@ parse_item (GKeyFile *file, GkmSecretItem *item, GkmSecretData *sdata,
g_clear_error (&err);
type = 0;
}
- gkm_secret_item_set_schema (item, gkm_secret_compat_format_item_type (type));
val = g_key_file_get_string (file, identifier, "display-name", NULL);
gkm_secret_object_set_label (obj, val);
@@ -374,7 +383,7 @@ parse_item (GKeyFile *file, GkmSecretItem *item, GkmSecretData *sdata,
gkm_secret_object_set_created (obj, num);
/* Now the other stuff */
- parse_attributes (file, item, groups);
+ parse_attributes (file, item, groups, type);
parse_acl (file, item, groups);
}
diff --git a/pkcs11/secret-store/tests/files/encrypted-with-schema.keyring b/pkcs11/secret-store/tests/files/encrypted-with-schema.keyring
new file mode 100644
index 0000000..63d1a73
Binary files /dev/null and b/pkcs11/secret-store/tests/files/encrypted-with-schema.keyring differ
diff --git a/pkcs11/secret-store/tests/files/plain-with-schema.keyring b/pkcs11/secret-store/tests/files/plain-with-schema.keyring
new file mode 100644
index 0000000..b2d51cd
--- /dev/null
+++ b/pkcs11/secret-store/tests/files/plain-with-schema.keyring
@@ -0,0 +1,23 @@
+[keyring]
+display-name=test
+ctime=0
+mtime=0
+lock-on-idle=false
+lock-after=false
+
+[1]
+item-type=0
+display-name=Secret Test Credentials
+secret=pa$$w0rd
+mtime=1350055423
+ctime=0
+
+[1:attribute0]
+name=rishi-identity
+type=string
+value=rishi-identity
+
+[1:attribute1]
+name=xdg:schema
+type=string
+value=se.lostca.is.rishi.secret
diff --git a/pkcs11/secret-store/tests/test-secret-binary.c b/pkcs11/secret-store/tests/test-secret-binary.c
index f581e3f..a18803c 100644
--- a/pkcs11/secret-store/tests/test-secret-binary.c
+++ b/pkcs11/secret-store/tests/test-secret-binary.c
@@ -225,6 +225,26 @@ test_read_created_on_rhel (Test *test, gconstpointer unused)
g_assert_cmpint (res, ==, GKM_DATA_SUCCESS);
}
+static void
+test_read_with_schema (Test *test,
+ gconstpointer unused)
+{
+ GkmDataResult res;
+ GkmSecret *master;
+ GkmSecretItem *item;
+
+ master = gkm_secret_new_from_password ("test");
+ gkm_secret_data_set_master (test->sdata, master);
+ g_object_unref (master);
+ res = check_read_keyring_file (test, SRCDIR "/files/encrypted-with-schema.keyring");
+ g_assert_cmpint (res, ==, GKM_DATA_SUCCESS);
+
+ item = gkm_secret_collection_get_item (test->collection, "1");
+ g_assert (item != NULL);
+
+ g_assert_cmpstr (gkm_secret_item_get_schema (item), ==, "se.lostca.is.rishi.secret");
+}
+
int
main (int argc, char **argv)
{
@@ -239,6 +259,7 @@ main (int argc, char **argv)
g_test_add ("/secret-store/binary/remove_unavailable", Test, NULL, setup, test_remove_unavailable, teardown);
g_test_add ("/secret-store/binary/created_on_rhel", Test, NULL, setup, test_read_created_on_rhel, teardown);
g_test_add ("/secret-store/binary/created_on_solaris_opencsw", Test, NULL, setup, test_read_created_on_solaris_opencsw, teardown);
+ g_test_add ("/secret-store/binary/read_with_schema", Test, NULL, setup, test_read_with_schema, teardown);
return g_test_run ();
}
diff --git a/pkcs11/secret-store/tests/test-secret-textual.c b/pkcs11/secret-store/tests/test-secret-textual.c
index 4c8a5ae..87bc408 100644
--- a/pkcs11/secret-store/tests/test-secret-textual.c
+++ b/pkcs11/secret-store/tests/test-secret-textual.c
@@ -189,6 +189,28 @@ test_remove_unavailable (Test *test, gconstpointer unused)
g_free (data);
}
+static void
+test_read_with_schema (Test *test,
+ gconstpointer unused)
+{
+ GkmDataResult res;
+ GkmSecretItem *item;
+ gchar *data;
+ gsize n_data;
+
+ if (!g_file_get_contents (SRCDIR "/files/plain-with-schema.keyring", &data, &n_data, NULL))
+ g_assert_not_reached ();
+ res = gkm_secret_textual_read (test->collection, test->sdata, data, n_data);
+ g_assert (res == GKM_DATA_SUCCESS);
+
+ item = gkm_secret_collection_get_item (test->collection, "1");
+ g_assert (item != NULL);
+
+ g_assert_cmpstr (gkm_secret_item_get_schema (item), ==, "se.lostca.is.rishi.secret");
+
+ g_free (data);
+}
+
int
main (int argc, char **argv)
{
@@ -200,6 +222,7 @@ main (int argc, char **argv)
g_test_add ("/secret-store/search/read_bad_number", Test, NULL, setup, test_read_bad_number, teardown);
g_test_add ("/secret-store/search/write", Test, NULL, setup, test_write, teardown);
g_test_add ("/secret-store/search/remove_unavailable", Test, NULL, setup, test_remove_unavailable, teardown);
+ g_test_add ("/secret-store/search/read-with-schema", Test, NULL, setup, test_read_with_schema, teardown);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]