[gcr] gcr: Don't fail preconditions when pkcs11 isn't initialized



commit a6fe45ce4038e0db89f0bf4b0643cdd474e1658f
Author: Stef Walter <stefw gnome org>
Date:   Thu Jul 26 16:43:32 2012 +0200

    gcr: Don't fail preconditions when pkcs11 isn't initialized
    
     * Callers should initialize pkcs11 early, because initialize can
       be a long running call, and should be handled appropriately in
       the user interface.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=680652

 gcr/gcr-library.c |   28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)
---
diff --git a/gcr/gcr-library.c b/gcr/gcr-library.c
index 12b0ff4..a90b23a 100644
--- a/gcr/gcr-library.c
+++ b/gcr/gcr-library.c
@@ -147,11 +147,14 @@ initialize_uris (void)
 	gchar *uri;
 	gchar *debug;
 
-	g_return_if_fail (initialized_modules);
-
 	if (initialized_uris)
 		return;
 
+	if (!initialized_modules) {
+		_gcr_debug ("modules not initialized");
+		return;
+	}
+
 	G_LOCK (uris);
 
 	if (!initialized_uris) {
@@ -326,6 +329,9 @@ gcr_pkcs11_initialize (GCancellable *cancellable,
  * List all the PKCS\#11 modules that are used by the GCR library.
  * Each module is a #GckModule object.
  *
+ * An empty list of modules will be returned if gcr_pkcs11_set_modules(),
+ * or gcr_pkcs11_initialize() has not yet run.
+ *
  * When done with the list, free it with gck_list_unref_free().
  *
  * Returns: (transfer full) (element-type Gck.Module): a newly allocated list
@@ -334,8 +340,9 @@ gcr_pkcs11_initialize (GCancellable *cancellable,
 GList*
 gcr_pkcs11_get_modules (void)
 {
-	g_return_val_if_fail (initialized_modules, NULL);
-	if (!all_modules)
+	if (!initialized_modules)
+		_gcr_debug ("pkcs11 not yet initialized");
+	else if (!all_modules)
 		_gcr_debug ("no modules loaded");
 	return gck_list_ref_copy (all_modules);
 }
@@ -430,6 +437,9 @@ gcr_pkcs11_add_module_from_file (const gchar *module_path, gpointer unused,
  * Selects an appropriate PKCS\#11 slot to store trust assertions. The slot
  * to use is normally configured automatically by the system.
  *
+ * This will only return a valid result after the gcr_pkcs11_initialize()
+ * method has been called.
+ *
  * When done with the #GckSlot, use g_object_unref() to release it.
  *
  * Returns: (transfer full): the #GckSlot to use for trust assertions.
@@ -440,7 +450,8 @@ gcr_pkcs11_get_trust_store_slot (void)
 	GckSlot *slot;
 	GError *error = NULL;
 
-	g_return_val_if_fail (initialized_modules, NULL);
+	if (!initialized_modules)
+		return NULL;
 
 	initialize_uris ();
 	slot = gck_modules_token_for_uri (all_modules, trust_store_uri, &error);
@@ -463,6 +474,9 @@ gcr_pkcs11_get_trust_store_slot (void)
  * List all the PKCS\#11 slots that are used by the GCR library for lookup
  * of trust assertions. Each slot is a #GckSlot object.
  *
+ * This will return an empty list if the gcr_pkcs11_initialize() function has
+ * not yet been called.
+ *
  * When done with the list, free it with gck_list_unref_free().
  *
  * Returns: (transfer full) (element-type Gck.Slot): a list of #GckSlot objects
@@ -475,7 +489,9 @@ gcr_pkcs11_get_trust_lookup_slots (void)
 	GError *error = NULL;
 	gchar **uri;
 
-	g_return_val_if_fail (initialized_modules, NULL);
+	if (!initialized_modules)
+		return NULL;
+
 	initialize_uris ();
 
 	for (uri = trust_lookup_uris; uri && *uri; ++uri) {



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