diff options
author | Werner Koch <wk@gnupg.org> | 2014-06-02 15:55:00 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2014-06-02 15:55:00 +0200 |
commit | 42c043a8ad542c131917879c9b458f234b4bb645 (patch) | |
tree | 1847bf9f4161c5fb0f3bd893fdc5a6e87f4336ec /kbx | |
parent | gpg: Fix bug parsing a zero length user id. (diff) | |
download | gnupg2-42c043a8ad542c131917879c9b458f234b4bb645.tar.xz gnupg2-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 'kbx')
-rw-r--r-- | kbx/keybox-defs.h | 17 | ||||
-rw-r--r-- | kbx/keybox-init.c | 30 | ||||
-rw-r--r-- | kbx/keybox.h | 2 |
3 files changed, 42 insertions, 7 deletions
diff --git a/kbx/keybox-defs.h b/kbx/keybox-defs.h index f79c093fd..7bbcf83cf 100644 --- a/kbx/keybox-defs.h +++ b/kbx/keybox-defs.h @@ -85,6 +85,14 @@ struct keybox_name }; +struct keybox_found_s +{ + KEYBOXBLOB blob; + off_t offset; + size_t pk_no; + size_t uid_no; + unsigned int n_packets; /*used for delete and update*/ +}; struct keybox_handle { CONST_KB_NAME kb; @@ -93,13 +101,8 @@ struct keybox_handle { int eof; int error; int ephemeral; - struct { - KEYBOXBLOB blob; - off_t offset; - size_t pk_no; - size_t uid_no; - unsigned int n_packets; /*used for delete and update*/ - } found; + struct keybox_found_s found; + struct keybox_found_s saved_found; struct { char *name; char *pattern; diff --git a/kbx/keybox-init.c b/kbx/keybox-init.c index d3299412a..8ae3ec315 100644 --- a/kbx/keybox-init.c +++ b/kbx/keybox-init.c @@ -148,6 +148,7 @@ keybox_release (KEYBOX_HANDLE hd) hd->kb->handle_table[idx] = NULL; } _keybox_release_blob (hd->found.blob); + _keybox_release_blob (hd->saved_found.blob); if (hd->fp) { fclose (hd->fp); @@ -159,6 +160,35 @@ keybox_release (KEYBOX_HANDLE hd) } +/* Save the current found state in HD for later retrieval by + keybox_restore_found_state. Only one state may be saved. */ +void +keybox_push_found_state (KEYBOX_HANDLE hd) +{ + if (hd->saved_found.blob) + { + _keybox_release_blob (hd->saved_found.blob); + hd->saved_found.blob = NULL; + } + hd->saved_found = hd->found; + hd->found.blob = NULL; +} + + +/* Restore the saved found state in HD. */ +void +keybox_pop_found_state (KEYBOX_HANDLE hd) +{ + if (hd->found.blob) + { + _keybox_release_blob (hd->found.blob); + hd->found.blob = NULL; + } + hd->found = hd->saved_found; + hd->saved_found.blob = NULL; +} + + const char * keybox_get_resource_name (KEYBOX_HANDLE hd) { diff --git a/kbx/keybox.h b/kbx/keybox.h index 4c447a577..96c6db549 100644 --- a/kbx/keybox.h +++ b/kbx/keybox.h @@ -64,6 +64,8 @@ int keybox_is_writable (void *token); KEYBOX_HANDLE keybox_new (void *token, int secret); void keybox_release (KEYBOX_HANDLE hd); +void keybox_push_found_state (KEYBOX_HANDLE hd); +void keybox_pop_found_state (KEYBOX_HANDLE hd); const char *keybox_get_resource_name (KEYBOX_HANDLE hd); int keybox_set_ephemeral (KEYBOX_HANDLE hd, int yes); |