diff options
author | Werner Koch <wk@gnupg.org> | 2015-05-08 15:51:11 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2015-05-08 15:51:11 +0200 |
commit | 3c439c0447f8a7468a61bbdc4c9a101ef2451dcb (patch) | |
tree | f7c1e9085cf66dc7a0db3e82dababdc22054a2e4 | |
parent | gpg: Minor code merging in keyedit. (diff) | |
download | gnupg2-3c439c0447f8a7468a61bbdc4c9a101ef2451dcb.tar.xz gnupg2-3c439c0447f8a7468a61bbdc4c9a101ef2451dcb.zip |
gpg: Add push/pop found state feature to keydb.
* g10/keydb.c (keydb_handle): Add field saved_found.
(keydb_new): Init new field.
(keydb_push_found_state, keydb_pop_found_state): New.
* g10/keyring.c (kyring_handle): Add field saved_found.
(keyring_push_found_state, keyring_pop_found_state): New.
--
We have the same feature in gpgsm. It is very useful to check for an
unambiguous user id with a follow up update of the keyblock.
Signed-off-by: Werner Koch <wk@gnupg.org>
-rw-r--r-- | g10/keydb.c | 65 | ||||
-rw-r--r-- | g10/keydb.h | 2 | ||||
-rw-r--r-- | g10/keyring.c | 24 | ||||
-rw-r--r-- | g10/keyring.h | 2 |
4 files changed, 88 insertions, 5 deletions
diff --git a/g10/keydb.c b/g10/keydb.c index 040ca65c2..2d1e07cf3 100644 --- a/g10/keydb.c +++ b/g10/keydb.c @@ -1,7 +1,6 @@ /* keydb.c - key database dispatcher - * Copyright (C) 2001, 2002, 2003, 2004, 2005, - * 2008, 2009, 2011, 2013 Free Software Foundation, Inc. - * Coyrright (C) 2013 Werner Koch + * Copyright (C) 2001-2013 Free Software Foundation, Inc. + * Coyrright (C) 2001-2015 Werner Koch * * This file is part of GnuPG. * @@ -67,6 +66,7 @@ struct keydb_handle { int locked; int found; + int saved_found; unsigned long skipped_long_blobs; int no_caching; int current; @@ -542,6 +542,7 @@ keydb_new (void) hd = xmalloc_clear (sizeof *hd); hd->found = -1; + hd->saved_found = -1; assert (used_resources <= MAX_KEYDB_RESOURCES); for (i=j=0; i < used_resources; i++) @@ -741,6 +742,64 @@ unlock_all (KEYDB_HANDLE hd) } + +/* 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_KEYRING: + keyring_push_found_state (hd->active[hd->found].u.kr); + break; + case KEYDB_RESOURCE_TYPE_KEYBOX: + keybox_push_found_state (hd->active[hd->found].u.kb); + 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_KEYRING: + keyring_pop_found_state (hd->active[hd->found].u.kr); + break; + case KEYDB_RESOURCE_TYPE_KEYBOX: + keybox_pop_found_state (hd->active[hd->found].u.kb); + break; + } +} + + + static gpg_error_t parse_keyblock_image (iobuf_t iobuf, int pk_no, int uid_no, const u32 *sigstatus, kbnode_t *r_keyblock) diff --git a/g10/keydb.h b/g10/keydb.h index 11a10e984..0e3816f1d 100644 --- a/g10/keydb.h +++ b/g10/keydb.h @@ -136,6 +136,8 @@ gpg_error_t keydb_add_resource (const char *url, unsigned int flags); KEYDB_HANDLE keydb_new (void); void keydb_release (KEYDB_HANDLE hd); void keydb_disable_caching (KEYDB_HANDLE hd); +void keydb_push_found_state (KEYDB_HANDLE hd); +void keydb_pop_found_state (KEYDB_HANDLE hd); const char *keydb_get_resource_name (KEYDB_HANDLE hd); gpg_error_t keydb_get_keyblock (KEYDB_HANDLE hd, KBNODE *ret_kb); gpg_error_t keydb_update_keyblock (KEYDB_HANDLE hd, kbnode_t kb); diff --git a/g10/keyring.c b/g10/keyring.c index ee76e8a33..a5178ace4 100644 --- a/g10/keyring.c +++ b/g10/keyring.c @@ -1,5 +1,6 @@ /* keyring.c - keyring file handling - * Copyright (C) 2001, 2004, 2009, 2010 Free Software Foundation, Inc. + * Copyright (C) 1998-2010 Free Software Foundation, Inc. + * Copyright (C) 1997-2015 Werner Koch * * This file is part of GnuPG. * @@ -83,7 +84,7 @@ struct keyring_handle size_t pk_no; size_t uid_no; unsigned int n_packets; /*used for delete and update*/ - } found; + } found, saved_found; struct { char *name; char *pattern; @@ -279,6 +280,25 @@ keyring_release (KEYRING_HANDLE hd) } +/* Save the current found state in HD for later retrieval by + keybox_pop_found_state. Only one state may be saved. */ +void +keyring_push_found_state (KEYRING_HANDLE hd) +{ + hd->saved_found = hd->found; + hd->found.kr = NULL; +} + + +/* Restore the saved found state in HD. */ +void +keyring_pop_found_state (KEYRING_HANDLE hd) +{ + hd->found = hd->saved_found; + hd->saved_found.kr = NULL; +} + + const char * keyring_get_resource_name (KEYRING_HANDLE hd) { diff --git a/g10/keyring.h b/g10/keyring.h index f83c2cb18..1469b7040 100644 --- a/g10/keyring.h +++ b/g10/keyring.h @@ -29,6 +29,8 @@ int keyring_is_writable (void *token); KEYRING_HANDLE keyring_new (void *token); void keyring_release (KEYRING_HANDLE hd); +void keyring_push_found_state (KEYRING_HANDLE hd); +void keyring_pop_found_state (KEYRING_HANDLE hd); const char *keyring_get_resource_name (KEYRING_HANDLE hd); int keyring_lock (KEYRING_HANDLE hd, int yes); int keyring_get_keyblock (KEYRING_HANDLE hd, KBNODE *ret_kb); |