diff options
author | Werner Koch <[email protected]> | 2014-06-02 13:55:00 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2014-06-02 13:55:00 +0000 |
commit | 42c043a8ad542c131917879c9b458f234b4bb645 (patch) | |
tree | 1847bf9f4161c5fb0f3bd893fdc5a6e87f4336ec /sm | |
parent | gpg: Fix bug parsing a zero length user id. (diff) | |
download | gnupg-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')
-rw-r--r-- | sm/keydb.c | 54 | ||||
-rw-r--r-- | sm/keydb.h | 2 |
2 files changed, 56 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 diff --git a/sm/keydb.h b/sm/keydb.h index 6e432f893..aec31c399 100644 --- a/sm/keydb.h +++ b/sm/keydb.h @@ -43,6 +43,8 @@ gpg_error_t keydb_get_flags (KEYDB_HANDLE hd, int which, int idx, unsigned int *value); gpg_error_t keydb_set_flags (KEYDB_HANDLE hd, int which, int idx, unsigned int value); +void keydb_push_found_state (KEYDB_HANDLE hd); +void keydb_pop_found_state (KEYDB_HANDLE hd); int keydb_get_cert (KEYDB_HANDLE hd, ksba_cert_t *r_cert); int keydb_insert_cert (KEYDB_HANDLE hd, ksba_cert_t cert); int keydb_update_cert (KEYDB_HANDLE hd, ksba_cert_t cert); |