mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-17 15:44:34 +02:00
g10: Simplify code: remove field struct getkey_ctx_s.keyblock.
* g10/getkey.c (struct getkey_ctx_s): Remove field keyblock. (finish_lookup): Add parameter keyblock. Update caller to pass this. (lookup): Add new local variable keyblock. Use this instead of ctx->keyblock for referencing the keyblock. -- Signed-off-by: Neal H. Walfield <neal@g10code.com>.
This commit is contained in:
parent
7d5999f096
commit
3798f73c07
25
g10/getkey.c
25
g10/getkey.c
@ -1,6 +1,7 @@
|
|||||||
/* getkey.c - Get a key from the database
|
/* getkey.c - Get a key from the database
|
||||||
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
|
||||||
* 2007, 2008, 2010 Free Software Foundation, Inc.
|
* 2007, 2008, 2010 Free Software Foundation, Inc.
|
||||||
|
* Copyright (C) 2015 g10 Code GmbH
|
||||||
*
|
*
|
||||||
* This file is part of GnuPG.
|
* This file is part of GnuPG.
|
||||||
*
|
*
|
||||||
@ -50,7 +51,6 @@ struct getkey_ctx_s
|
|||||||
{
|
{
|
||||||
int exact;
|
int exact;
|
||||||
int want_secret; /* The caller requested only secret keys. */
|
int want_secret; /* The caller requested only secret keys. */
|
||||||
KBNODE keyblock;
|
|
||||||
KBPOS kbpos;
|
KBPOS kbpos;
|
||||||
KBNODE found_key; /* Pointer into some keyblock. */
|
KBNODE found_key; /* Pointer into some keyblock. */
|
||||||
strlist_t extra_list; /* Will be freed when releasing the context. */
|
strlist_t extra_list; /* Will be freed when releasing the context. */
|
||||||
@ -2339,9 +2339,8 @@ merge_selfsigs (KBNODE keyblock)
|
|||||||
* is the key we actually found by looking at the keyid or a fingerprint and
|
* is the key we actually found by looking at the keyid or a fingerprint and
|
||||||
* may either point to the primary or one of the subkeys. */
|
* may either point to the primary or one of the subkeys. */
|
||||||
static int
|
static int
|
||||||
finish_lookup (GETKEY_CTX ctx)
|
finish_lookup (GETKEY_CTX ctx, KBNODE keyblock)
|
||||||
{
|
{
|
||||||
KBNODE keyblock = ctx->keyblock;
|
|
||||||
KBNODE k;
|
KBNODE k;
|
||||||
KBNODE foundk = NULL;
|
KBNODE foundk = NULL;
|
||||||
PKT_user_id *foundu = NULL;
|
PKT_user_id *foundu = NULL;
|
||||||
@ -2568,6 +2567,7 @@ lookup (getkey_ctx_t ctx, kbnode_t *ret_keyblock, int want_secret)
|
|||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
int no_suitable_key = 0;
|
int no_suitable_key = 0;
|
||||||
|
KBNODE keyblock = NULL;
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
@ -2590,7 +2590,7 @@ lookup (getkey_ctx_t ctx, kbnode_t *ret_keyblock, int want_secret)
|
|||||||
if (ctx->nitems && ctx->items->mode == KEYDB_SEARCH_MODE_FIRST)
|
if (ctx->nitems && ctx->items->mode == KEYDB_SEARCH_MODE_FIRST)
|
||||||
ctx->items->mode = KEYDB_SEARCH_MODE_NEXT;
|
ctx->items->mode = KEYDB_SEARCH_MODE_NEXT;
|
||||||
|
|
||||||
rc = keydb_get_keyblock (ctx->kr_handle, &ctx->keyblock);
|
rc = keydb_get_keyblock (ctx->kr_handle, &keyblock);
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
log_error ("keydb_get_keyblock failed: %s\n", gpg_strerror (rc));
|
log_error ("keydb_get_keyblock failed: %s\n", gpg_strerror (rc));
|
||||||
@ -2598,14 +2598,14 @@ lookup (getkey_ctx_t ctx, kbnode_t *ret_keyblock, int want_secret)
|
|||||||
goto skip;
|
goto skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (want_secret && agent_probe_any_secret_key (NULL, ctx->keyblock))
|
if (want_secret && agent_probe_any_secret_key (NULL, keyblock))
|
||||||
goto skip; /* No secret key available. */
|
goto skip; /* No secret key available. */
|
||||||
|
|
||||||
/* Warning: node flag bits 0 and 1 should be preserved by
|
/* Warning: node flag bits 0 and 1 should be preserved by
|
||||||
* merge_selfsigs. For secret keys, premerge transferred the
|
* merge_selfsigs. For secret keys, premerge transferred the
|
||||||
* keys to the keyblock. */
|
* keys to the keyblock. */
|
||||||
merge_selfsigs (ctx->keyblock);
|
merge_selfsigs (keyblock);
|
||||||
if (finish_lookup (ctx))
|
if (finish_lookup (ctx, keyblock))
|
||||||
{
|
{
|
||||||
no_suitable_key = 0;
|
no_suitable_key = 0;
|
||||||
goto found;
|
goto found;
|
||||||
@ -2615,8 +2615,8 @@ lookup (getkey_ctx_t ctx, kbnode_t *ret_keyblock, int want_secret)
|
|||||||
|
|
||||||
skip:
|
skip:
|
||||||
/* Release resources and continue search. */
|
/* Release resources and continue search. */
|
||||||
release_kbnode (ctx->keyblock);
|
release_kbnode (keyblock);
|
||||||
ctx->keyblock = NULL;
|
keyblock = NULL;
|
||||||
/* We need to disable the caching so that for an exact key
|
/* We need to disable the caching so that for an exact key
|
||||||
search we won't get the result back from the cache and thus
|
search we won't get the result back from the cache and thus
|
||||||
end up in an endless loop. Disabling the cache here at this
|
end up in an endless loop. Disabling the cache here at this
|
||||||
@ -2632,8 +2632,8 @@ found:
|
|||||||
|
|
||||||
if (!rc)
|
if (!rc)
|
||||||
{
|
{
|
||||||
*ret_keyblock = ctx->keyblock; /* Return the keyblock. */
|
*ret_keyblock = keyblock; /* Return the keyblock. */
|
||||||
ctx->keyblock = NULL;
|
keyblock = NULL;
|
||||||
}
|
}
|
||||||
else if ((gpg_err_code (rc) == GPG_ERR_NOT_FOUND
|
else if ((gpg_err_code (rc) == GPG_ERR_NOT_FOUND
|
||||||
|| gpg_err_code (rc) == GPG_ERR_LEGACY_KEY) && no_suitable_key)
|
|| gpg_err_code (rc) == GPG_ERR_LEGACY_KEY) && no_suitable_key)
|
||||||
@ -2641,8 +2641,7 @@ found:
|
|||||||
else if (gpg_err_code (rc) == GPG_ERR_NOT_FOUND)
|
else if (gpg_err_code (rc) == GPG_ERR_NOT_FOUND)
|
||||||
rc = want_secret? GPG_ERR_NO_SECKEY : GPG_ERR_NO_PUBKEY;
|
rc = want_secret? GPG_ERR_NO_SECKEY : GPG_ERR_NO_PUBKEY;
|
||||||
|
|
||||||
release_kbnode (ctx->keyblock);
|
release_kbnode (keyblock);
|
||||||
ctx->keyblock = NULL;
|
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user