1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-03-11 22:52:47 +01:00

* getkey.c (key_byname): If namelist is NULL, return the first key in the

keyring.
This commit is contained in:
David Shaw 2004-04-26 00:36:01 +00:00
parent 732f049817
commit 7d74743c0e
2 changed files with 46 additions and 29 deletions

View File

@ -1,3 +1,8 @@
2004-04-25 David Shaw <dshaw@jabberwocky.com>
* getkey.c (key_byname): If namelist is NULL, return the first key
in the keyring.
2004-04-22 David Shaw <dshaw@jabberwocky.com> 2004-04-22 David Shaw <dshaw@jabberwocky.com>
* keygen.c (make_backsig): If DO_BACKSIGS is not defined, do not * keygen.c (make_backsig): If DO_BACKSIGS is not defined, do not

View File

@ -779,11 +779,12 @@ skip_unusable(void *dummy,u32 *keyid,PKT_user_id *uid)
/**************** /****************
* Try to get the pubkey by the userid. This function looks for the * Try to get the pubkey by the userid. This function looks for the
* first pubkey certificate which has the given name in a user_id. * first pubkey certificate which has the given name in a user_id. if
* if pk/sk has the pubkey algo set, the function will only return * pk/sk has the pubkey algo set, the function will only return a
* a pubkey with that algo. * pubkey with that algo. If namelist is NULL, the first key is
* The caller should provide storage for either the pk or the sk. * returned. The caller should provide storage for either the pk or
* If ret_kb is not NULL the function will return the keyblock there. * the sk. If ret_kb is not NULL the function will return the
* keyblock there.
*/ */
static int static int
@ -806,18 +807,31 @@ key_byname( GETKEY_CTX *retctx, STRLIST namelist,
if (ret_kdbhd) if (ret_kdbhd)
*ret_kdbhd = NULL; *ret_kdbhd = NULL;
if(!namelist)
{
ctx = m_alloc_clear (sizeof *ctx);
ctx->nitems = 1;
ctx->items[0].mode=KEYDB_SEARCH_MODE_FIRST;
if(!include_unusable)
ctx->items[0].skipfnc=skip_unusable;
}
else
{
/* build the search context */ /* build the search context */
for(n=0, r=namelist; r; r = r->next ) for(n=0, r=namelist; r; r = r->next )
n++; n++;
ctx = m_alloc_clear (sizeof *ctx + (n-1)*sizeof ctx->items ); ctx = m_alloc_clear (sizeof *ctx + (n-1)*sizeof ctx->items );
ctx->nitems = n; ctx->nitems = n;
for(n=0, r=namelist; r; r = r->next, n++ ) { for(n=0, r=namelist; r; r = r->next, n++ )
{
classify_user_id (r->d, &ctx->items[n]); classify_user_id (r->d, &ctx->items[n]);
if (ctx->items[n].exact) if (ctx->items[n].exact)
ctx->exact = 1; ctx->exact = 1;
if (!ctx->items[n].mode) { if (!ctx->items[n].mode)
{
m_free (ctx); m_free (ctx);
return G10ERR_INV_USER_ID; return G10ERR_INV_USER_ID;
} }
@ -829,6 +843,7 @@ key_byname( GETKEY_CTX *retctx, STRLIST namelist,
&& ctx->items[n].mode!=KEYDB_SEARCH_MODE_FPR) && ctx->items[n].mode!=KEYDB_SEARCH_MODE_FPR)
ctx->items[n].skipfnc=skip_unusable; ctx->items[n].skipfnc=skip_unusable;
} }
}
ctx->kr_handle = keydb_new (secmode); ctx->kr_handle = keydb_new (secmode);
if ( !ret_kb ) if ( !ret_kb )
@ -909,7 +924,6 @@ get_pubkey_next( GETKEY_CTX ctx, PKT_public_key *pk, KBNODE *ret_keyblock )
return rc; return rc;
} }
void void
get_pubkey_end( GETKEY_CTX ctx ) get_pubkey_end( GETKEY_CTX ctx )
{ {
@ -922,8 +936,6 @@ get_pubkey_end( GETKEY_CTX ctx )
} }
/**************** /****************
* Search for a key with the given fingerprint. * Search for a key with the given fingerprint.
* FIXME: * FIXME: