gnome-keyring r1237 - in trunk: . daemon/pk
- From: nnielsen svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-keyring r1237 - in trunk: . daemon/pk
- Date: Mon, 11 Aug 2008 02:47:15 +0000 (UTC)
Author: nnielsen
Date: Mon Aug 11 02:47:15 2008
New Revision: 1237
URL: http://svn.gnome.org/viewvc/gnome-keyring?rev=1237&view=rev
Log:
* daemon/pk/gkr-pk-index.c:
* daemon/pk/gkr-pk-index.h:
* daemon/pk/gkr-pk-object-storage.c: Only load properly imported keys
in main object storage. Remove keys properly when deleted.
Modified:
trunk/ChangeLog
trunk/daemon/pk/gkr-pk-index.c
trunk/daemon/pk/gkr-pk-index.h
trunk/daemon/pk/gkr-pk-object-storage.c
Modified: trunk/daemon/pk/gkr-pk-index.c
==============================================================================
--- trunk/daemon/pk/gkr-pk-index.c (original)
+++ trunk/daemon/pk/gkr-pk-index.c Mon Aug 11 02:47:15 2008
@@ -864,6 +864,20 @@
}
gboolean
+gkr_pk_index_add (GkrPkIndex *index, gkrconstid digest)
+{
+ GkrKeyringItem *item;
+
+ if (!index)
+ index = gkr_pk_index_default ();
+
+ g_return_val_if_fail (GKR_IS_PK_INDEX (index), FALSE);
+
+ item = find_item_for_digest (index, digest, TRUE);
+ return item ? TRUE : FALSE;
+}
+
+gboolean
gkr_pk_index_delete (GkrPkIndex *index, gkrconstid digest)
{
GkrKeyringItem *item;
Modified: trunk/daemon/pk/gkr-pk-index.h
==============================================================================
--- trunk/daemon/pk/gkr-pk-index.h (original)
+++ trunk/daemon/pk/gkr-pk-index.h Mon Aug 11 02:47:15 2008
@@ -114,6 +114,8 @@
gboolean gkr_pk_index_copy (GkrPkIndex *old_index, GkrPkIndex *new_index,
gkrconstid digest);
+gboolean gkr_pk_index_add (GkrPkIndex *index, gkrconstid digest);
+
gboolean gkr_pk_index_delete (GkrPkIndex *index, gkrconstid digest);
gboolean gkr_pk_index_have (GkrPkIndex *index, gkrconstid digest);
Modified: trunk/daemon/pk/gkr-pk-object-storage.c
==============================================================================
--- trunk/daemon/pk/gkr-pk-object-storage.c (original)
+++ trunk/daemon/pk/gkr-pk-object-storage.c Mon Aug 11 02:47:15 2008
@@ -50,7 +50,6 @@
struct _GkrPkObjectStoragePrivate {
GHashTable *specific_load_requests;
- GHashTable *denied_import_requests;
GkrLocationWatch *watch;
};
@@ -62,7 +61,7 @@
typedef struct {
GkrPkObjectStorage *storage; /* The object storage to parse into */
GQuark location; /* The location being parsed */
- GHashTable *checks; /* The set of objects that existed before parse */
+ GkrPkChecks *checks; /* The set of objects that existed before parse */
} ParseContext;
@@ -104,7 +103,6 @@
{
ParseContext *ctx = (ParseContext*)user_data;
GkrPkObjectStoragePrivate *pv = GKR_PK_OBJECT_STORAGE_GET_PRIVATE (ctx->storage);
- gboolean ret;
g_return_val_if_fail (loc == ctx->location, FALSE);
@@ -112,30 +110,39 @@
* If the user isn't specifically requesting this object, then we don't
* necessarily prompt for a password.
*/
- if (!g_hash_table_lookup (pv->specific_load_requests, digest)) {
-
- /* If the user specifically denied this earlier, then don't prompt */
- if (g_hash_table_lookup (pv->denied_import_requests, digest)) {
- *password = NULL;
- return FALSE;
- }
- }
-
- /* TODO: Work out how imports work, add to denied import requests if necessary */
-
- ret = gkr_pk_storage_get_load_password (GKR_PK_STORAGE (ctx->storage), loc, digest,
- type, label, state, password);
+ if (!g_hash_table_lookup (pv->specific_load_requests, digest))
+ return FALSE;
- return ret;
+ return gkr_pk_storage_get_load_password (GKR_PK_STORAGE (ctx->storage), loc, digest,
+ type, label, state, password);
}
static GkrPkObject*
prepare_object (GkrPkObjectStorage *storage, GQuark location,
gkrconstid digest, GQuark type)
{
+ GkrPkObjectStoragePrivate *pv = GKR_PK_OBJECT_STORAGE_GET_PRIVATE (storage);
GkrPkManager *manager;
GkrPkObject *object;
+ GkrPkIndex *index;
GType gtype;
+
+ /* We don't know the type, not much else we can do */
+ if (!type)
+ return NULL;
+
+ /*
+ * The object must be in our index for us to load or otherwise
+ * process it. See gkr_pk_object_storage_store() for getting
+ * stuff into index.
+ */
+
+ index = gkr_pk_storage_index (GKR_PK_STORAGE (storage), location);
+ if (!gkr_pk_index_have (index, digest)) {
+ g_message ("object at %s is not imported properly, ignoring.",
+ gkr_location_to_string (location));
+ return NULL;
+ }
manager = gkr_pk_manager_for_token ();
object = gkr_pk_manager_find_by_digest (manager, digest);
@@ -143,18 +150,23 @@
/* The object already exists just reference it */
if (object) {
gkr_pk_storage_add_object (GKR_PK_STORAGE (storage), object);
- return object;
- }
-
- gtype = gkr_pk_object_get_object_type (type);
- g_return_val_if_fail (gtype != 0, NULL);
+
+ /* Create a new object here */
+ } else {
+ gtype = gkr_pk_object_get_object_type (type);
+ g_return_val_if_fail (gtype != 0, NULL);
- object = g_object_new (gtype, "manager", manager, "location", location,
- "digest", digest, NULL);
- gkr_pk_storage_add_object (GKR_PK_STORAGE (storage), object);
+ object = g_object_new (gtype, "manager", manager, "location", location,
+ "digest", digest, NULL);
+ gkr_pk_storage_add_object (GKR_PK_STORAGE (storage), object);
- /* Object was reffed */
- g_object_unref (object);
+ /* Object was reffed */
+ g_object_unref (object);
+ }
+
+ /* Make note of having seen this object in load requests */
+ g_hash_table_remove (pv->specific_load_requests, digest);
+
return object;
}
@@ -162,72 +174,54 @@
parser_parsed_partial (GkrPkixParser *parser, GQuark location, gkrid digest,
GQuark type, ParseContext *ctx)
{
- GkrPkObjectStoragePrivate *pv = GKR_PK_OBJECT_STORAGE_GET_PRIVATE (ctx->storage);
- GkrPkObject *object;
-
- /* TODO: What do we do if we don't know the type? */
- if (!type)
- return FALSE;
-
- object = prepare_object (ctx->storage, location, digest, type);
- g_return_val_if_fail (object != NULL, FALSE);
+ GkrPkObject *object = prepare_object (ctx->storage, location, digest, type);
+ if (object == NULL)
+ return FALSE;
- /* Make note of having seen this object in load requests */
- g_hash_table_remove (pv->specific_load_requests, digest);
-
/* Make note of having seen this one */
gkr_pk_storage_checks_mark (ctx->checks, object);
-
- return TRUE;
+ return TRUE;
}
static gboolean
parser_parsed_sexp (GkrPkixParser *parser, GQuark location, gkrid digest,
GQuark type, gcry_sexp_t sexp, ParseContext *ctx)
{
- GkrPkObjectStoragePrivate *pv = GKR_PK_OBJECT_STORAGE_GET_PRIVATE (ctx->storage);
GkrPkObject *object;
-
+
g_return_val_if_fail (type != 0, FALSE);
object = prepare_object (ctx->storage, location, digest, type);
- g_return_val_if_fail (object != NULL, FALSE);
-
- /* Make note of having seen this object in load requests */
- g_hash_table_remove (pv->specific_load_requests, digest);
-
- /* Make note of having seen this one */
- g_hash_table_remove (ctx->checks, object);
-
+ if (object == NULL)
+ return FALSE;
+
+ /* Setup the sexp, probably a key, on this object */
+ g_object_set (object, "gcrypt-sexp", sexp, NULL);
+
/* Make note of having seen this one */
gkr_pk_storage_checks_mark (ctx->checks, object);
-
- /* TODO: Work how imports work */
- return TRUE;
+
+ return TRUE;
}
static gboolean
parser_parsed_asn1 (GkrPkixParser *parser, GQuark location, gkrconstid digest,
GQuark type, ASN1_TYPE asn1, ParseContext *ctx)
{
- GkrPkObjectStoragePrivate *pv = GKR_PK_OBJECT_STORAGE_GET_PRIVATE (ctx->storage);
GkrPkObject *object;
g_return_val_if_fail (type != 0, FALSE);
object = prepare_object (ctx->storage, location, digest, type);
- g_return_val_if_fail (object != NULL, FALSE);
-
- /* Make note of having seen this object in load requests */
- g_hash_table_remove (pv->specific_load_requests, digest);
-
- /* Make note of having seen this one */
- g_hash_table_remove (ctx->checks, object);
+ if (object == NULL)
+ return FALSE;
/* Setup the asn1, probably a certificate on this object */
g_object_set (object, "asn1-tree", asn1, NULL);
- /* TODO: Work out how imports work */
+ /* Make note of having seen this one */
+ gkr_pk_storage_checks_mark (ctx->checks, object);
+
return TRUE;
}
@@ -244,7 +238,7 @@
ctx.storage = storage;
ctx.checks = gkr_pk_storage_checks_prepare (GKR_PK_STORAGE (storage), loc);
- /* TODO: Try and use a shared parser? */
+ /* Create a parser object */
parser = gkr_pkix_parser_new (FALSE);
g_signal_connect (parser, "parsed-asn1", G_CALLBACK (parser_parsed_asn1), &ctx);
g_signal_connect (parser, "parsed-sexp", G_CALLBACK (parser_parsed_sexp), &ctx);
@@ -288,7 +282,6 @@
GkrPkObjectStoragePrivate *pv = GKR_PK_OBJECT_STORAGE_GET_PRIVATE (storage);
pv->specific_load_requests = g_hash_table_new_full (gkr_id_hash, gkr_id_equals, gkr_id_free, NULL);
- pv->denied_import_requests = g_hash_table_new_full (gkr_id_hash, gkr_id_equals, gkr_id_free, NULL);
/* The main key and certificate storage */
pv->watch = gkr_location_watch_new (NULL, 0, RELATIVE_DIRECTORY, "*", "*.keystore");
@@ -413,6 +406,7 @@
/* The object now has a (possibly new) location, and possibly new digest */
g_object_set (obj, "location", loc, "storage", stor, "digest", digest, NULL);
gkr_pk_storage_add_object (stor, obj);
+ gkr_pk_index_add (gkr_pk_storage_index (stor, loc), digest);
}
gkr_id_free (digest);
@@ -428,6 +422,7 @@
g_return_val_if_fail (!err || !*err, FALSE);
g_return_val_if_fail (GKR_IS_PK_OBJECT_STORAGE (storage), FALSE);
+ g_return_val_if_fail (GKR_IS_PK_OBJECT (obj), FALSE);
g_return_val_if_fail (obj->storage == storage, FALSE);
g_return_val_if_fail (obj->location, FALSE);
@@ -447,6 +442,12 @@
/* Delete the object itself */
if (!gkr_location_delete_file (obj->location, err))
return FALSE;
+
+ /* Remove it from our indexes */
+ gkr_pk_index_delete (gkr_pk_storage_index (storage, obj->location), obj->digest);
+
+ /* And remove it from our list */
+ gkr_pk_storage_del_object (storage, obj);
return TRUE;
}
@@ -458,7 +459,6 @@
GkrPkObjectStoragePrivate *pv = GKR_PK_OBJECT_STORAGE_GET_PRIVATE (obj);
g_hash_table_remove_all (pv->specific_load_requests);
- g_hash_table_remove_all (pv->denied_import_requests);
if (pv->watch) {
g_signal_handlers_disconnect_by_func (pv->watch, location_load, storage);
@@ -476,7 +476,6 @@
GkrPkObjectStoragePrivate *pv = GKR_PK_OBJECT_STORAGE_GET_PRIVATE (obj);
g_hash_table_destroy (pv->specific_load_requests);
- g_hash_table_destroy (pv->denied_import_requests);
g_assert (pv->watch == NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]