diff options
author | Stefan Walter <stefw@src.gnome.org> | 2009-01-30 21:45:06 +0000 |
---|---|---|
committer | Stefan Walter <stefw@src.gnome.org> | 2009-01-30 21:45:06 +0000 |
commit | 752e7aea07d1742dd2253debfe68e4fda71a6703 (patch) | |
tree | 84357c99e1be5801d674ef2e89ef3acc01b0e4ab /daemon | |
parent | c888e90c70dfb0620e57d5505d13f73c3199451b (diff) |
Don't assert when trying to lock a keyring without a password. Fixes bug
* daemon/keyrings/gkr-keyring.c:
* daemon/keyrings/tests/unit-test-keyring-file.c: Don't assert when
trying to lock a keyring without a password. Fixes bug #569253
svn path=/trunk/; revision=1486
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/keyrings/gkr-keyring.c | 10 | ||||
-rw-r--r-- | daemon/keyrings/tests/unit-test-keyring-file.c | 60 |
2 files changed, 66 insertions, 4 deletions
diff --git a/daemon/keyrings/gkr-keyring.c b/daemon/keyrings/gkr-keyring.c index 515ecc7e..8e111795 100644 --- a/daemon/keyrings/gkr-keyring.c +++ b/daemon/keyrings/gkr-keyring.c @@ -501,10 +501,12 @@ gkr_keyring_lock (GkrKeyring *keyring) if (!keyring->location) return TRUE; - g_assert (keyring->password != NULL); + /* Password will be null for textual keyrings */ + if (keyring->password != NULL) { + egg_secure_strfree (keyring->password); + keyring->password = NULL; + } - egg_secure_strfree (keyring->password); - keyring->password = NULL; if (!gkr_keyring_update_from_disk (keyring)) { /* Failed to re-read, remove the keyring */ g_warning ("Couldn't re-read keyring %s\n", keyring->keyring_name); @@ -520,7 +522,7 @@ gkr_keyring_unlock (GkrKeyring *keyring, const gchar *password) if (!keyring->locked) return TRUE; - g_assert (keyring->password == NULL); + g_return_val_if_fail (keyring->password == NULL, FALSE); keyring->password = egg_secure_strdup (password); if (!gkr_keyring_update_from_disk (keyring)) { diff --git a/daemon/keyrings/tests/unit-test-keyring-file.c b/daemon/keyrings/tests/unit-test-keyring-file.c index 1bc64ba4..8d1557c8 100644 --- a/daemon/keyrings/tests/unit-test-keyring-file.c +++ b/daemon/keyrings/tests/unit-test-keyring-file.c @@ -25,6 +25,8 @@ #include "run-auto-test.h" +#include "common/gkr-location.h" + #include "egg/egg-secure-memory.h" #include "keyrings/gkr-keyring.h" @@ -46,6 +48,23 @@ * * Tests be run in the order specified here. */ + +static GQuark +location_for_test_data (const gchar *filename) +{ + GQuark quark; + gchar *dir; + gchar *path; + + dir = g_get_current_dir (); + g_assert (dir); + + path = g_build_filename (dir, "test-data", filename, NULL); + quark = gkr_location_from_path (path); + g_free (path); + + return quark; +} static void validate_keyring_contents (GkrKeyring *keyring, CuTest *cu) @@ -173,3 +192,44 @@ void unit_test_keyring_parse_plain (CuTest *cu) validate_keyring_contents (keyring, cu); } + +void unit_test_keyring_double_lock_encrypted (CuTest *cu) +{ + GkrKeyring *encrypted; + gboolean ret; + + encrypted = gkr_keyring_new ("encrypted", location_for_test_data ("encrypted.keyring")); + encrypted->password = egg_secure_strdup ("my-keyring-password"); + ret = gkr_keyring_update_from_disk (encrypted); + CuAssert (cu, "couldn't parse generated textual data", ret == TRUE); + + /* Lock it */ + gkr_keyring_lock (encrypted); + CuAssert (cu, "locked", encrypted->locked); + + /* Should succeed */ + gkr_keyring_lock (encrypted); + CuAssert (cu, "locked", encrypted->locked); + + g_object_unref (encrypted); +} + +void unit_test_keyring_double_lock_plain (CuTest *cu) +{ + GkrKeyring *keyring; + gboolean ret; + + keyring = gkr_keyring_new ("plain", location_for_test_data ("plain.keyring")); + ret = gkr_keyring_update_from_disk (keyring); + CuAssert (cu, "couldn't parse generated textual data", ret == TRUE); + + /* Lock it, shouldn't actually work, no way to lock */ + gkr_keyring_lock (keyring); + CuAssert (cu, "locked", !keyring->locked); + + /* Shouldn't crash */ + gkr_keyring_lock (keyring); + CuAssert (cu, "locked", !keyring->locked); + + g_object_unref (keyring); +} |