summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Gratton <mike@vee.net>2018-12-25 13:36:29 +1030
committerMichael Gratton <mike@vee.net>2019-01-10 10:37:46 +0000
commit29debbadd17d88c4d31b907015a147fff7b90820 (patch)
tree8aa95601fe8dc8407356f03f71fb81a4884f038a
parent4b97d86eef2cc5b72ca2031cf88b8834d4420b68 (diff)
downloadgcr-mjog/gcr-lib-uri-handling.tar.gz
Update gcr_pkcs11_get_trust_{store|lookup}_slot URI checksmjog/gcr-lib-uri-handling
No store/lookup URIs may be present, even after initialising them, if no appropriate stores are found. Check this is the case before attempting to use them, and clarify in both debug output and the gtkdocs about what is happening in such cases. This makes the underlying problem in #10 a bit more obvious when debugging.
-rw-r--r--gcr/gcr-library.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/gcr/gcr-library.c b/gcr/gcr-library.c
index 7275c63..7b896fb 100644
--- a/gcr/gcr-library.c
+++ b/gcr/gcr-library.c
@@ -486,7 +486,9 @@ gcr_pkcs11_add_module_from_file (const gchar *module_path, gpointer unused,
*
* When done with the #GckSlot, use g_object_unref() to release it.
*
- * Returns: (transfer full): the #GckSlot to use for trust assertions.
+ * Returns: (transfer full) (nullable): the #GckSlot to use for trust
+ * assertions, or null if not initialized or no appropriate
+ * trust store could be found.
*/
GckSlot *
gcr_pkcs11_get_trust_store_slot (void)
@@ -498,6 +500,11 @@ gcr_pkcs11_get_trust_store_slot (void)
return NULL;
initialize_uris ();
+ if (!trust_store_uri) {
+ g_warning ("no slot available for storing assertions");
+ return NULL;
+ }
+
slot = gck_modules_token_for_uri (all_modules, trust_store_uri, &error);
if (!slot) {
if (error) {
@@ -523,8 +530,9 @@ gcr_pkcs11_get_trust_store_slot (void)
*
* When done with the list, free it with gck_list_unref_free().
*
- * Returns: (transfer full) (element-type Gck.Slot): a list of #GckSlot objects
- * to use for lookup of trust.
+ * Returns: (transfer full) (element-type Gck.Slot): a list of #GckSlot
+ * objects to use for lookup of trust, or the empty list if not
+ * initialized or no appropriate trust stores could be found.
*/
GList*
gcr_pkcs11_get_trust_lookup_slots (void)
@@ -537,6 +545,10 @@ gcr_pkcs11_get_trust_lookup_slots (void)
return NULL;
initialize_uris ();
+ if (!trust_lookup_uris) {
+ g_warning ("no slots available for assertion lookup");
+ return NULL;
+ }
for (uri = trust_lookup_uris; uri && *uri; ++uri) {
results = g_list_concat (results, gck_modules_tokens_for_uri (all_modules, *uri, &error));