kbx: Change skipfnc's prototype so that we can provide all information.

* kbx/keybox-search-desc.h (struct keydb_search_desc.skipfnc): Change
third parameter to be the index of the user id packet in the keyblock
rather than the packet itself.  Update users.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>.

The keybox code doesn't work directly with keyblocks.  As such, the
matched user packet is not readily available to pass to
DESC[n].SKIPFNC.  But, we do know the index of the user id packet that
matched.  Thus, pass that instead.  If the skip function needs the
user id packet, it can use the key id to look up the key block and
find the appropriate packet.
This commit is contained in:
Neal H. Walfield 2015-09-14 11:27:43 +02:00
parent 83e17ab1b4
commit 9acbeac236
4 changed files with 31 additions and 14 deletions

View File

@ -543,10 +543,11 @@ get_seckey (PKT_public_key *pk, u32 *keyid)
static int
skip_unusable (void *dummy, u32 * keyid, PKT_user_id * uid)
skip_unusable (void *dummy, u32 * keyid, int uid_no)
{
int unusable = 0;
KBNODE keyblock;
PKT_public_key *pk;
(void) dummy;
@ -557,28 +558,38 @@ skip_unusable (void *dummy, u32 * keyid, PKT_user_id * uid)
goto leave;
}
pk = keyblock->pkt->pkt.public_key;
/* Is the user ID in question revoked/expired? */
if (uid)
if (uid_no)
{
KBNODE node;
int uids_seen = 0;
for (node = keyblock; node; node = node->next)
{
if (node->pkt->pkttype == PKT_USER_ID)
{
if (cmp_user_ids (uid, node->pkt->pkt.user_id) == 0
&& (node->pkt->pkt.user_id->is_revoked
|| node->pkt->pkt.user_id->is_expired))
{
unusable = 1;
break;
}
PKT_user_id *user_id = node->pkt->pkt.user_id;
uids_seen ++;
if (uids_seen != uid_no)
continue;
if (user_id->is_revoked || user_id->is_expired)
unusable = 1;
break;
}
}
/* If UID_NO is non-zero, then the keyblock better have at least
that many UIDs. */
assert (uids_seen == uid_no);
}
if (!unusable)
unusable = pk_is_disabled (keyblock->pkt->pkt.public_key);
unusable = pk_is_disabled (pk);
leave:
release_kbnode (keyblock);

View File

@ -1148,7 +1148,7 @@ keyring_search (KEYRING_HANDLE hd, KEYDB_SEARCH_DESC *desc,
for (n=any_skip?0:ndesc; n < ndesc; n++)
{
if (desc[n].skipfnc
&& desc[n].skipfnc (desc[n].skipfncvalue, aki, uid))
&& desc[n].skipfnc (desc[n].skipfncvalue, aki, uid_no))
break;
}
if (n == ndesc)

View File

@ -57,7 +57,13 @@ typedef struct gpg_pkt_user_id_s *gpg_pkt_user_id_t;
struct keydb_search_desc
{
KeydbSearchMode mode;
int (*skipfnc)(void *, u32 *, gpg_pkt_user_id_t);
/* Callback used to filter results. The first parameter is
SKIPFUNCVALUE. The second is the keyid. The third is the
1-based index of the UID packet that matched the search criteria
(or 0, if none).
Return non-zero if the result should be skipped. */
int (*skipfnc)(void *, u32 *, int);
void *skipfncvalue;
const unsigned char *sn;
int snlen; /* -1 := sn is a hex string */

View File

@ -1010,8 +1010,8 @@ keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc,
if (desc[n].skipfnc
&& blob_get_first_keyid (blob, kid)
&& desc[n].skipfnc (desc[n].skipfncvalue, kid, NULL))
break;
&& desc[n].skipfnc (desc[n].skipfncvalue, kid, uid_no))
break;
}
if (n == ndesc)
break; /* got it */