mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-21 14:47:03 +01:00
* getkey.c (get_seckey_byname2): Significantly simplify this function by
using key_byname to do the heavy lifting. Note that this also fixes an old problem when the first key on the secret keyring has an unusable stub primary, but is still chosen.
This commit is contained in:
parent
7d74743c0e
commit
0c67c75cbe
@ -1,5 +1,10 @@
|
|||||||
2004-04-25 David Shaw <dshaw@jabberwocky.com>
|
2004-04-25 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
|
* getkey.c (get_seckey_byname2): Significantly simplify this
|
||||||
|
function by using key_byname to do the heavy lifting. Note that
|
||||||
|
this also fixes an old problem when the first key on the secret
|
||||||
|
keyring has an unusable stub primary, but is still chosen.
|
||||||
|
|
||||||
* getkey.c (key_byname): If namelist is NULL, return the first key
|
* getkey.c (key_byname): If namelist is NULL, return the first key
|
||||||
in the keyring.
|
in the keyring.
|
||||||
|
|
||||||
|
45
g10/getkey.c
45
g10/getkey.c
@ -1055,44 +1055,25 @@ get_keyblock_byfprint( KBNODE *ret_keyblock, const byte *fprint,
|
|||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
get_seckey_byname2( GETKEY_CTX *retctx,
|
get_seckey_byname2( GETKEY_CTX *retctx,
|
||||||
PKT_secret_key *sk, const char *name, int unprotect,
|
PKT_secret_key *sk, const char *name, int unprotect,
|
||||||
KBNODE *retblock )
|
KBNODE *retblock )
|
||||||
{
|
{
|
||||||
STRLIST namelist = NULL;
|
STRLIST namelist = NULL;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if( !name && opt.def_secret_key && *opt.def_secret_key ) {
|
if( !name && opt.def_secret_key && *opt.def_secret_key )
|
||||||
add_to_strlist( &namelist, opt.def_secret_key );
|
add_to_strlist( &namelist, opt.def_secret_key );
|
||||||
rc = key_byname( retctx, namelist, NULL, sk, 1, 1, retblock, NULL );
|
else if(name)
|
||||||
}
|
add_to_strlist( &namelist, name );
|
||||||
else if( !name ) { /* use the first one as default key */
|
|
||||||
struct getkey_ctx_s ctx;
|
|
||||||
KBNODE kb = NULL;
|
|
||||||
|
|
||||||
assert (!retctx ); /* do we need this at all */
|
rc = key_byname( retctx, namelist, NULL, sk, 1, 1, retblock, NULL );
|
||||||
assert (!retblock);
|
|
||||||
memset( &ctx, 0, sizeof ctx );
|
|
||||||
ctx.not_allocated = 1;
|
|
||||||
ctx.kr_handle = keydb_new (1);
|
|
||||||
ctx.nitems = 1;
|
|
||||||
ctx.items[0].mode = KEYDB_SEARCH_MODE_FIRST;
|
|
||||||
rc = lookup( &ctx, &kb, 1 );
|
|
||||||
if (!rc && sk )
|
|
||||||
sk_from_block ( &ctx, sk, kb );
|
|
||||||
release_kbnode ( kb );
|
|
||||||
get_seckey_end( &ctx );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
add_to_strlist( &namelist, name );
|
|
||||||
rc = key_byname( retctx, namelist, NULL, sk, 1, 1, retblock, NULL );
|
|
||||||
}
|
|
||||||
|
|
||||||
free_strlist( namelist );
|
free_strlist( namelist );
|
||||||
|
|
||||||
if( !rc && unprotect )
|
if( !rc && unprotect )
|
||||||
rc = check_secret_key( sk, 0 );
|
rc = check_secret_key( sk, 0 );
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user