[gcr/mjog/gcr-lib-uri-handling: 4/4] Update gcr_pkcs11_get_trust_{store|lookup}_slot URI checks



commit 29debbadd17d88c4d31b907015a147fff7b90820
Author: Michael Gratton <mike vee net>
Date:   Tue Dec 25 13:36:29 2018 +1030

    Update gcr_pkcs11_get_trust_{store|lookup}_slot URI checks
    
    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.

 gcr/gcr-library.c | 18 +++++++++++++++---
 1 file 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));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]