aboutsummaryrefslogtreecommitdiffstats
path: root/sm/keydb.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2014-06-02 13:55:00 +0000
committerWerner Koch <[email protected]>2014-06-02 13:55:00 +0000
commit42c043a8ad542c131917879c9b458f234b4bb645 (patch)
tree1847bf9f4161c5fb0f3bd893fdc5a6e87f4336ec /sm/keydb.c
parentgpg: Fix bug parsing a zero length user id. (diff)
downloadgnupg-42c043a8ad542c131917879c9b458f234b4bb645.tar.gz
gnupg-42c043a8ad542c131917879c9b458f234b4bb645.zip
gpgsm: Add a way to save a found state.
* kbx/keybox-defs.h (keybox_found_s): New. (keybox_handle): Factor FOUND out to above. Add saved_found. * kbx/keybox-init.c (keybox_release): Release saved_found. (keybox_push_found_state, keybox_pop_found_state): New. * sm/keydb.c (keydb_handle): Add field saved_found. (keydb_new): Init it. (keydb_push_found_state, keydb_pop_found_state): New.
Diffstat (limited to 'sm/keydb.c')
-rw-r--r--sm/keydb.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/sm/keydb.c b/sm/keydb.c
index 845ebba88..d9eb2e073 100644
--- a/sm/keydb.c
+++ b/sm/keydb.c
@@ -56,6 +56,7 @@ static int used_resources;
struct keydb_handle {
int locked;
int found;
+ int saved_found;
int current;
int is_ephemeral;
int used; /* items in active */
@@ -265,6 +266,7 @@ keydb_new (int secret)
hd = xcalloc (1, sizeof *hd);
hd->found = -1;
+ hd->saved_found = -1;
assert (used_resources <= MAX_KEYDB_RESOURCES);
for (i=j=0; i < used_resources; i++)
@@ -476,6 +478,58 @@ unlock_all (KEYDB_HANDLE hd)
hd->locked = 0;
}
+
+
+/* Push the last found state if any. */
+void
+keydb_push_found_state (KEYDB_HANDLE hd)
+{
+ if (!hd)
+ return;
+
+ if (hd->found < 0 || hd->found >= hd->used)
+ {
+ hd->saved_found = -1;
+ return;
+ }
+
+ switch (hd->active[hd->found].type)
+ {
+ case KEYDB_RESOURCE_TYPE_NONE:
+ break;
+ case KEYDB_RESOURCE_TYPE_KEYBOX:
+ keybox_push_found_state (hd->active[hd->found].u.kr);
+ break;
+ }
+
+ hd->saved_found = hd->found;
+ hd->found = -1;
+}
+
+
+/* Pop the last found state. */
+void
+keydb_pop_found_state (KEYDB_HANDLE hd)
+{
+ if (!hd)
+ return;
+
+ hd->found = hd->saved_found;
+ hd->saved_found = -1;
+ if (hd->found < 0 || hd->found >= hd->used)
+ return;
+
+ switch (hd->active[hd->found].type)
+ {
+ case KEYDB_RESOURCE_TYPE_NONE:
+ break;
+ case KEYDB_RESOURCE_TYPE_KEYBOX:
+ keybox_pop_found_state (hd->active[hd->found].u.kr);
+ break;
+ }
+}
+
+
/*
Return the last found object. Caller must free it. The returned