[gnome-keyring] [gkm] Always pass around session when finding stuff.



commit dd1f7ff8cf719c0b58624a7cdf9326d3231bf02f
Author: Stef Walter <stef memberwebs com>
Date:   Sun Jun 13 01:50:03 2010 +0000

    [gkm] Always pass around session when finding stuff.
    
     * This is because attributes can vary depending on session
       and we need the session to determine their value.

 pkcs11/gkm/gkm-certificate.c                |    6 ++--
 pkcs11/gkm/gkm-certificate.h                |    1 +
 pkcs11/gkm/gkm-credential.c                 |    4 +-
 pkcs11/gkm/gkm-manager.c                    |   33 ++++++++++++++++----------
 pkcs11/gkm/gkm-manager.h                    |    5 ++++
 pkcs11/gkm/gkm-session.c                    |    4 +-
 pkcs11/roots-store/gkm-roots-certificate.c  |    2 +-
 pkcs11/secret-store/gkm-secret-collection.c |   13 ++++++----
 pkcs11/secret-store/gkm-secret-collection.h |    3 +-
 pkcs11/secret-store/gkm-secret-item.c       |    6 ++--
 pkcs11/secret-store/gkm-secret-search.c     |    8 +++---
 11 files changed, 51 insertions(+), 34 deletions(-)
---
diff --git a/pkcs11/gkm/gkm-certificate.c b/pkcs11/gkm/gkm-certificate.c
index 28dfad8..5c5b9d0 100644
--- a/pkcs11/gkm/gkm-certificate.c
+++ b/pkcs11/gkm/gkm-certificate.c
@@ -313,7 +313,7 @@ gkm_certificate_real_get_attribute (GkmObject *base, GkmSession *session, CK_ATT
 		return gkm_attribute_set_bool (attr, FALSE);
 
 	case CKA_CERTIFICATE_CATEGORY:
-		if (!gkm_certificate_calc_category (self, &category))
+		if (!gkm_certificate_calc_category (self, session, &category))
 			return CKR_FUNCTION_FAILED;
 		return gkm_attribute_set_ulong (attr, category);
 
@@ -624,7 +624,7 @@ gkm_certificate_serializable (GkmSerializableIface *iface)
  */
 
 gboolean
-gkm_certificate_calc_category (GkmCertificate *self, CK_ULONG* category)
+gkm_certificate_calc_category (GkmCertificate *self, GkmSession *session, CK_ULONG* category)
 {
 	const guchar *extension;
 	GkmManager *manager;
@@ -639,7 +639,7 @@ gkm_certificate_calc_category (GkmCertificate *self, CK_ULONG* category)
 	/* First see if we have a private key for this certificate */
 	manager = gkm_object_get_manager (GKM_OBJECT (self));
 	if (manager != NULL) {
-		object = gkm_manager_find_related (manager, CKO_PRIVATE_KEY, GKM_OBJECT (self));
+		object = gkm_manager_find_related (manager, session, CKO_PRIVATE_KEY, GKM_OBJECT (self));
 		if (object != NULL) {
 			*category = 1; /* token user */
 			return TRUE;
diff --git a/pkcs11/gkm/gkm-certificate.h b/pkcs11/gkm/gkm-certificate.h
index 0269be1..bb73e4c 100644
--- a/pkcs11/gkm/gkm-certificate.h
+++ b/pkcs11/gkm/gkm-certificate.h
@@ -53,6 +53,7 @@ GType                      gkm_certificate_get_type               (void);
 GkmFactory*                gkm_certificate_get_factory            (void);
 
 gboolean                   gkm_certificate_calc_category          (GkmCertificate *self,
+                                                                   GkmSession *session,
                                                                    CK_ULONG* category);
 
 GkmCertificateKey*         gkm_certificate_get_public_key         (GkmCertificate *self);
diff --git a/pkcs11/gkm/gkm-credential.c b/pkcs11/gkm/gkm-credential.c
index 25281f6..eec474c 100644
--- a/pkcs11/gkm/gkm-credential.c
+++ b/pkcs11/gkm/gkm-credential.c
@@ -492,7 +492,7 @@ gkm_credential_for_each (GkmSession *session, GkmObject *object,
 
 	/* Find any on the session */
 	results = gkm_manager_find_by_attributes (gkm_session_get_manager (session),
-	                                          attrs, G_N_ELEMENTS (attrs));
+	                                          session, attrs, G_N_ELEMENTS (attrs));
 
 	for (l = results; l; l = g_list_next (l)) {
 		g_object_ref (l->data);
@@ -509,7 +509,7 @@ gkm_credential_for_each (GkmSession *session, GkmObject *object,
 
 	/* Find any in the token */
 	results = gkm_manager_find_by_attributes (gkm_module_get_manager (gkm_session_get_module (session)),
-	                                          attrs, G_N_ELEMENTS (attrs));
+	                                          session, attrs, G_N_ELEMENTS (attrs));
 
 	for (l = results; l; l = g_list_next (l)) {
 		g_object_ref (l->data);
diff --git a/pkcs11/gkm/gkm-manager.c b/pkcs11/gkm/gkm-manager.c
index d1769e7..b35e3c3 100644
--- a/pkcs11/gkm/gkm-manager.c
+++ b/pkcs11/gkm/gkm-manager.c
@@ -68,6 +68,7 @@ typedef struct _Finder {
 	gpointer results;
 	CK_ATTRIBUTE_PTR attrs;
 	CK_ULONG n_attrs;
+	GkmSession *session;
 } Finder;
 
 G_DEFINE_TYPE(GkmManager, gkm_manager, G_TYPE_OBJECT);
@@ -488,7 +489,7 @@ find_each_object (gpointer unused, gpointer object, gpointer user_data)
 			if (!index_contains (index, object, attr))
 				return;
 		} else {
-			if (!gkm_object_match (object, NULL, attr))
+			if (!gkm_object_match (object, finder->session, attr))
 				return;
 		}
 	}
@@ -878,9 +879,10 @@ gkm_manager_find_one_by_string_property (GkmManager *self, const gchar *property
 }
 
 GkmObject*
-gkm_manager_find_one_by_attributes (GkmManager *self, CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs)
+gkm_manager_find_one_by_attributes (GkmManager *self, GkmSession *session,
+                                    CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs)
 {
-	Finder finder;
+	Finder finder = { 0, };
 
 	g_return_val_if_fail (GKM_IS_MANAGER (self), NULL);
 	g_return_val_if_fail (attrs || !n_attrs, NULL);
@@ -890,6 +892,7 @@ gkm_manager_find_one_by_attributes (GkmManager *self, CK_ATTRIBUTE_PTR attrs, CK
 	finder.manager = self;
 	finder.attrs = attrs;
 	finder.n_attrs = n_attrs;
+	finder.session = session;
 
 	find_for_attributes (&finder);
 
@@ -897,9 +900,10 @@ gkm_manager_find_one_by_attributes (GkmManager *self, CK_ATTRIBUTE_PTR attrs, CK
 }
 
 GList*
-gkm_manager_find_by_attributes (GkmManager *self, CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs)
+gkm_manager_find_by_attributes (GkmManager *self, GkmSession *session,
+                                CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs)
 {
-	Finder finder;
+	Finder finder = { 0, };
 
 	g_return_val_if_fail (GKM_IS_MANAGER (self), NULL);
 	g_return_val_if_fail (attrs || !n_attrs, NULL);
@@ -909,6 +913,7 @@ gkm_manager_find_by_attributes (GkmManager *self, CK_ATTRIBUTE_PTR attrs, CK_ULO
 	finder.manager = self;
 	finder.attrs = attrs;
 	finder.n_attrs = n_attrs;
+	finder.session = session;
 
 	find_for_attributes (&finder);
 
@@ -916,7 +921,7 @@ gkm_manager_find_by_attributes (GkmManager *self, CK_ATTRIBUTE_PTR attrs, CK_ULO
 }
 
 GList*
-gkm_manager_find_by_class (GkmManager *self, CK_OBJECT_CLASS klass)
+gkm_manager_find_by_class (GkmManager *self, GkmSession *session, CK_OBJECT_CLASS klass)
 {
 	CK_ATTRIBUTE attr;
 
@@ -926,11 +931,12 @@ gkm_manager_find_by_class (GkmManager *self, CK_OBJECT_CLASS klass)
 	attr.ulValueLen = sizeof (klass);
 	attr.pValue = &klass;
 
-	return gkm_manager_find_by_attributes (self, &attr, 1);
+	return gkm_manager_find_by_attributes (self, session, &attr, 1);
 }
 
 GkmObject*
-gkm_manager_find_related (GkmManager *self, CK_OBJECT_CLASS klass, GkmObject *related_to)
+gkm_manager_find_related (GkmManager *self, GkmSession *session,
+                          CK_OBJECT_CLASS klass, GkmObject *related_to)
 {
 	CK_ATTRIBUTE attrs[2];
 	GkmObject *object;
@@ -952,18 +958,18 @@ gkm_manager_find_related (GkmManager *self, CK_OBJECT_CLASS klass, GkmObject *re
 	attrs[1].pValue = &klass;
 	attrs[1].ulValueLen = sizeof (klass);
 
-	object = gkm_manager_find_one_by_attributes (self, attrs, 2);
+	object = gkm_manager_find_one_by_attributes (self, session, attrs, 2);
 	g_free (id);
 
 	return object;
 }
 
 CK_RV
-gkm_manager_find_handles (GkmManager *self, gboolean also_private,
-                          CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs,
-                          GArray *found)
+gkm_manager_find_handles (GkmManager *self, GkmSession *session,
+                          gboolean also_private, CK_ATTRIBUTE_PTR attrs,
+                          CK_ULONG n_attrs, GArray *found)
 {
-	Finder finder;
+	Finder finder = { 0, };
 
 	g_return_val_if_fail (GKM_IS_MANAGER (self), CKR_GENERAL_ERROR);
 	g_return_val_if_fail (attrs || !n_attrs, CKR_GENERAL_ERROR);
@@ -973,6 +979,7 @@ gkm_manager_find_handles (GkmManager *self, gboolean also_private,
 	finder.manager = self;
 	finder.attrs = attrs;
 	finder.n_attrs = n_attrs;
+	finder.session = session;
 
 	find_for_attributes (&finder);
 
diff --git a/pkcs11/gkm/gkm-manager.h b/pkcs11/gkm/gkm-manager.h
index 5f07611..7f4cb43 100644
--- a/pkcs11/gkm/gkm-manager.h
+++ b/pkcs11/gkm/gkm-manager.h
@@ -117,21 +117,26 @@ GkmObject*              gkm_manager_find_one_by_string_property (GkmManager *sel
                                                                  const gchar *value);
 
 GList*                  gkm_manager_find_by_attributes          (GkmManager *self,
+                                                                 GkmSession *session,
                                                                  CK_ATTRIBUTE_PTR template,
                                                                  CK_ULONG n_attrs);
 
 GList*                  gkm_manager_find_by_class               (GkmManager *self,
+                                                                 GkmSession *session,
                                                                  CK_OBJECT_CLASS klass);
 
 GkmObject*              gkm_manager_find_one_by_attributes      (GkmManager *self,
+                                                                 GkmSession *session,
                                                                  CK_ATTRIBUTE_PTR template,
                                                                  CK_ULONG n_attrs);
 
 GkmObject*              gkm_manager_find_related                (GkmManager *self,
+                                                                 GkmSession *session,
                                                                  CK_OBJECT_CLASS klass,
                                                                  GkmObject *related_to);
 
 CK_RV                   gkm_manager_find_handles                (GkmManager *self,
+                                                                 GkmSession *session,
                                                                  gboolean include_private,
                                                                  CK_ATTRIBUTE_PTR template,
                                                                  CK_ULONG count,
diff --git a/pkcs11/gkm/gkm-session.c b/pkcs11/gkm/gkm-session.c
index 474c1b2..854ca98 100644
--- a/pkcs11/gkm/gkm-session.c
+++ b/pkcs11/gkm/gkm-session.c
@@ -1142,11 +1142,11 @@ gkm_session_C_FindObjectsInit (GkmSession* self, CK_ATTRIBUTE_PTR template,
 		rv = gkm_module_refresh_token (self->pv->module);
 		if (rv == CKR_OK)
 			rv = gkm_manager_find_handles (gkm_module_get_manager (self->pv->module),
-			                               also_private, template, count, found);
+			                               self, also_private, template, count, found);
 	}
 
 	if (rv == CKR_OK && (all || !token)) {
-		rv = gkm_manager_find_handles (self->pv->manager, also_private,
+		rv = gkm_manager_find_handles (self->pv->manager, self, also_private,
 		                               template, count, found);
 	}
 
diff --git a/pkcs11/roots-store/gkm-roots-certificate.c b/pkcs11/roots-store/gkm-roots-certificate.c
index fcb3f96..8499ec4 100644
--- a/pkcs11/roots-store/gkm-roots-certificate.c
+++ b/pkcs11/roots-store/gkm-roots-certificate.c
@@ -67,7 +67,7 @@ gkm_roots_certificate_get_attribute (GkmObject *base, GkmSession *session, CK_AT
 		return gkm_attribute_set_bool (attr, TRUE);
 
 	case CKA_CERTIFICATE_CATEGORY:
-		if (!gkm_certificate_calc_category (GKM_CERTIFICATE (self), &category))
+		if (!gkm_certificate_calc_category (GKM_CERTIFICATE (self), session, &category))
 			return CKR_FUNCTION_FAILED;
 		/* Unknown category, is CA by default in this slot */
 		if (category == 0)
diff --git a/pkcs11/secret-store/gkm-secret-collection.c b/pkcs11/secret-store/gkm-secret-collection.c
index 970da45..4b6cb69 100644
--- a/pkcs11/secret-store/gkm-secret-collection.c
+++ b/pkcs11/secret-store/gkm-secret-collection.c
@@ -278,12 +278,15 @@ factory_create_collection (GkmSession *session, GkmTransaction *transaction,
 
 		/* Try to find the collection with that identifier */
 		if (!gkm_attributes_find_boolean (attrs, n_attrs, CKA_TOKEN, &is_token))
-			collection = gkm_secret_collection_find (attr, gkm_module_get_manager (module),
+			collection = gkm_secret_collection_find (session, attr,
+			                                         gkm_module_get_manager (module),
 			                                         gkm_session_get_manager (session), NULL);
 		else if (is_token)
-			collection = gkm_secret_collection_find (attr, gkm_module_get_manager (module), NULL);
+			collection = gkm_secret_collection_find (session, attr,
+			                                         gkm_module_get_manager (module), NULL);
 		else
-			collection = gkm_secret_collection_find (attr, gkm_session_get_manager (session), NULL);
+			collection = gkm_secret_collection_find (session, attr,
+			                                         gkm_session_get_manager (session), NULL);
 
 		/* Already have one with this identifier? Just return that */
 		if (collection != NULL) {
@@ -717,7 +720,7 @@ gkm_secret_collection_has_item (GkmSecretCollection *self, GkmSecretItem *item)
 }
 
 GkmSecretCollection*
-gkm_secret_collection_find (CK_ATTRIBUTE_PTR attr, ...)
+gkm_secret_collection_find (GkmSession *session, CK_ATTRIBUTE_PTR attr, ...)
 {
 	CK_OBJECT_CLASS klass = CKO_G_COLLECTION;
 	GkmSecretCollection *result = NULL;
@@ -737,7 +740,7 @@ gkm_secret_collection_find (CK_ATTRIBUTE_PTR attr, ...)
 
 	va_start (va, attr);
 	while (!result && (manager = va_arg (va, GkmManager*)) != NULL) {
-		objects = gkm_manager_find_by_attributes (manager, attrs, 2);
+		objects = gkm_manager_find_by_attributes (manager, session, attrs, 2);
 		if (objects && GKM_IS_SECRET_COLLECTION (objects->data))
 			result = objects->data;
 		g_list_free (objects);
diff --git a/pkcs11/secret-store/gkm-secret-collection.h b/pkcs11/secret-store/gkm-secret-collection.h
index 983d637..b1e3afb 100644
--- a/pkcs11/secret-store/gkm-secret-collection.h
+++ b/pkcs11/secret-store/gkm-secret-collection.h
@@ -46,7 +46,8 @@ GType                gkm_secret_collection_get_type        (void);
 
 GkmFactory*          gkm_secret_collection_get_factory     (void) G_GNUC_CONST;
 
-GkmSecretCollection* gkm_secret_collection_find            (CK_ATTRIBUTE_PTR attr,
+GkmSecretCollection* gkm_secret_collection_find            (GkmSession *session,
+                                                            CK_ATTRIBUTE_PTR attr,
                                                             ...) G_GNUC_NULL_TERMINATED;
 
 GkmDataResult        gkm_secret_collection_load            (GkmSecretCollection *self);
diff --git a/pkcs11/secret-store/gkm-secret-item.c b/pkcs11/secret-store/gkm-secret-item.c
index 0311ade..d03c4a8 100644
--- a/pkcs11/secret-store/gkm-secret-item.c
+++ b/pkcs11/secret-store/gkm-secret-item.c
@@ -157,11 +157,11 @@ factory_create_item (GkmSession *session, GkmTransaction *transaction,
 
 	gkm_attribute_consume (attr);
 	if (!gkm_attributes_find_boolean (attrs, n_attrs, CKA_TOKEN, &is_token))
-		collection = gkm_secret_collection_find (attr, m_manager, s_manager, NULL);
+		collection = gkm_secret_collection_find (session, attr, m_manager, s_manager, NULL);
 	else if (is_token)
-		collection = gkm_secret_collection_find (attr, m_manager, NULL);
+		collection = gkm_secret_collection_find (session, attr, m_manager, NULL);
 	else
-		collection = gkm_secret_collection_find (attr, s_manager, NULL);
+		collection = gkm_secret_collection_find (session, attr, s_manager, NULL);
 
 	if (!collection) {
 		gkm_transaction_fail (transaction, CKR_TEMPLATE_INCONSISTENT);
diff --git a/pkcs11/secret-store/gkm-secret-search.c b/pkcs11/secret-store/gkm-secret-search.c
index 00754cb..fd86056 100644
--- a/pkcs11/secret-store/gkm-secret-search.c
+++ b/pkcs11/secret-store/gkm-secret-search.c
@@ -166,14 +166,14 @@ on_manager_gone_away (gpointer user_data, GObject *where_the_object_was)
 }
 
 static void
-populate_search_from_manager (GkmSecretSearch *self, GkmManager *manager)
+populate_search_from_manager (GkmSecretSearch *self, GkmSession *session, GkmManager *manager)
 {
 	GList *objects, *o;
 
 	self->managers = g_list_append (self->managers, manager);
 
 	/* Add in all the objects */
-	objects = gkm_manager_find_by_class (manager, CKO_SECRET_KEY);
+	objects = gkm_manager_find_by_class (manager, session, CKO_SECRET_KEY);
 	for (o = objects; o; o = g_list_next (o))
 		on_manager_added_object (manager, o->data, self);
 	g_list_free (objects);
@@ -242,8 +242,8 @@ factory_create_search (GkmSession *session, GkmTransaction *transaction,
 	/* Load any new items or collections */
 	gkm_module_refresh_token (module);
 
-	populate_search_from_manager (search, s_manager);
-	populate_search_from_manager (search, m_manager);
+	populate_search_from_manager (search, session, s_manager);
+	populate_search_from_manager (search, session, m_manager);
 
 	gkm_session_complete_object_creation (session, transaction, GKM_OBJECT (search),
 	                                      TRUE, attrs, n_attrs);



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