1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-08 12:44:23 +01:00

gpg: Prepare to pass additional context to the list functions.

* g10/keylist.c (struct sig_stats): Rename to keylist_context and add
field check_sigs.
(keylist_context_release): New.
(list_all): Set listctx.check_sigs and call release func.
(list_one): Ditto.
(locate_one): Ditto.
(list_keyblock_print): Use .check_sigs field.  Repalce arg opaque by
listctx.
(list_keyblock): Ditto.  Make static.
(list_keyblock_direct): New.
* g10/keygen.c (do_generate_keypair): Replace list_keyblock by
list_keyblock_direct.
--

This is in preparation for the server mode and for a patch to speed up
--list-sigs.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2015-04-06 19:46:25 +02:00
parent f577d5c1a7
commit 67a58118ab
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
3 changed files with 71 additions and 32 deletions

View File

@ -4152,7 +4152,7 @@ do_generate_keypair (struct para_data_s *para,
{ {
tty_printf (_("public and secret key created and signed.\n") ); tty_printf (_("public and secret key created and signed.\n") );
tty_printf ("\n"); tty_printf ("\n");
list_keyblock (pub_root, 0, 1, 1, NULL); list_keyblock_direct (pub_root, 0, 1, 1);
} }

View File

@ -50,17 +50,31 @@ static void list_one (strlist_t names, int secret, int mark_secret);
static void locate_one (ctrl_t ctrl, strlist_t names); static void locate_one (ctrl_t ctrl, strlist_t names);
static void print_card_serialno (const char *serialno); static void print_card_serialno (const char *serialno);
struct sig_stats struct keylist_context
{ {
int inv_sigs; int check_sigs; /* If set signatures shall be verified. */
int no_key; int inv_sigs; /* Counter used if CHECK_SIGS is set. */
int oth_err; int no_key; /* Counter used if CHECK_SIGS is set. */
int oth_err; /* Counter used if CHECK_SIGS is set. */
}; };
static void list_keyblock (kbnode_t keyblock, int secret, int has_secret,
int fpr, struct keylist_context *listctx);
/* The stream used to write attribute packets to. */ /* The stream used to write attribute packets to. */
static estream_t attrib_fp; static estream_t attrib_fp;
/* Release resources from a keylist context. */
static void
keylist_context_release (struct keylist_context *listctx)
{
(void)listctx; /* Nothing to release. */
}
/* List the keys. If list is NULL, all available keys are listed. /* List the keys. If list is NULL, all available keys are listed.
With LOCATE_MODE set the locate algorithm is used to find a With LOCATE_MODE set the locate algorithm is used to find a
key. */ key. */
@ -416,9 +430,13 @@ show_notation (PKT_signature * sig, int indent, int mode, int which)
free_notation (notations); free_notation (notations);
} }
static void static void
print_signature_stats (struct sig_stats *s) print_signature_stats (struct keylist_context *s)
{ {
if (!s->check_sigs)
return; /* Signature checking was not requested. */
if (s->inv_sigs == 1) if (s->inv_sigs == 1)
tty_printf (_("1 bad signature\n")); tty_printf (_("1 bad signature\n"));
else if (s->inv_sigs) else if (s->inv_sigs)
@ -446,9 +464,11 @@ list_all (int secret, int mark_secret)
int rc = 0; int rc = 0;
int any_secret; int any_secret;
const char *lastresname, *resname; const char *lastresname, *resname;
struct sig_stats stats; struct keylist_context listctx;
memset (&stats, 0, sizeof (stats)); memset (&listctx, 0, sizeof (listctx));
if (opt.check_sigs)
listctx.check_sigs = 1;
hd = keydb_new (); hd = keydb_new ();
if (!hd) if (!hd)
@ -499,7 +519,7 @@ list_all (int secret, int mark_secret)
} }
merge_keys_and_selfsig (keyblock); merge_keys_and_selfsig (keyblock);
list_keyblock (keyblock, secret, any_secret, opt.fingerprint, list_keyblock (keyblock, secret, any_secret, opt.fingerprint,
opt.check_sigs ? &stats : NULL); &listctx);
} }
release_kbnode (keyblock); release_kbnode (keyblock);
keyblock = NULL; keyblock = NULL;
@ -513,9 +533,10 @@ list_all (int secret, int mark_secret)
keydb_get_skipped_counter (hd)); keydb_get_skipped_counter (hd));
if (opt.check_sigs && !opt.with_colons) if (opt.check_sigs && !opt.with_colons)
print_signature_stats (&stats); print_signature_stats (&listctx);
leave: leave:
keylist_context_release (&listctx);
release_kbnode (keyblock); release_kbnode (keyblock);
keydb_release (hd); keydb_release (hd);
} }
@ -530,9 +551,11 @@ list_one (strlist_t names, int secret, int mark_secret)
const char *resname; const char *resname;
const char *keyring_str = _("Keyring"); const char *keyring_str = _("Keyring");
int i; int i;
struct sig_stats stats; struct keylist_context listctx;
memset (&stats, 0, sizeof (stats)); memset (&listctx, 0, sizeof (listctx));
if (!secret && opt.check_sigs)
listctx.check_sigs = 1;
/* fixme: using the bynames function has the disadvantage that we /* fixme: using the bynames function has the disadvantage that we
* don't know wether one of the names given was not found. OTOH, * don't know wether one of the names given was not found. OTOH,
@ -561,15 +584,16 @@ list_one (strlist_t names, int secret, int mark_secret)
es_putc ('-', es_stdout); es_putc ('-', es_stdout);
es_putc ('\n', es_stdout); es_putc ('\n', es_stdout);
} }
list_keyblock (keyblock, secret, mark_secret, opt.fingerprint, list_keyblock (keyblock, secret, mark_secret, opt.fingerprint, &listctx);
(!secret && opt.check_sigs)? &stats : NULL);
release_kbnode (keyblock); release_kbnode (keyblock);
} }
while (!getkey_next (ctx, NULL, &keyblock)); while (!getkey_next (ctx, NULL, &keyblock));
getkey_end (ctx); getkey_end (ctx);
if (opt.check_sigs && !opt.with_colons) if (opt.check_sigs && !opt.with_colons)
print_signature_stats (&stats); print_signature_stats (&listctx);
keylist_context_release (&listctx);
} }
@ -580,9 +604,11 @@ locate_one (ctrl_t ctrl, strlist_t names)
strlist_t sl; strlist_t sl;
GETKEY_CTX ctx = NULL; GETKEY_CTX ctx = NULL;
KBNODE keyblock = NULL; KBNODE keyblock = NULL;
struct sig_stats stats; struct keylist_context listctx;
memset (&stats, 0, sizeof (stats)); memset (&listctx, 0, sizeof (listctx));
if (opt.check_sigs)
listctx.check_sigs = 1;
for (sl = names; sl; sl = sl->next) for (sl = names; sl; sl = sl->next)
{ {
@ -596,8 +622,7 @@ locate_one (ctrl_t ctrl, strlist_t names)
{ {
do do
{ {
list_keyblock (keyblock, 0, 0, opt.fingerprint, list_keyblock (keyblock, 0, 0, opt.fingerprint, &listctx);
opt.check_sigs ? &stats : NULL);
release_kbnode (keyblock); release_kbnode (keyblock);
} }
while (ctx && !get_pubkey_next (ctx, NULL, &keyblock)); while (ctx && !get_pubkey_next (ctx, NULL, &keyblock));
@ -607,7 +632,9 @@ locate_one (ctrl_t ctrl, strlist_t names)
} }
if (opt.check_sigs && !opt.with_colons) if (opt.check_sigs && !opt.with_colons)
print_signature_stats (&stats); print_signature_stats (&listctx);
keylist_context_release (&listctx);
} }
@ -869,13 +896,13 @@ list_keyblock_pka (kbnode_t keyblock)
static void static void
list_keyblock_print (KBNODE keyblock, int secret, int fpr, void *opaque) list_keyblock_print (KBNODE keyblock, int secret, int fpr,
struct keylist_context *listctx)
{ {
int rc; int rc;
KBNODE kbctx; KBNODE kbctx;
KBNODE node; KBNODE node;
PKT_public_key *pk; PKT_public_key *pk;
struct sig_stats *stats = opaque;
int skip_sigs = 0; int skip_sigs = 0;
int s2k_char; int s2k_char;
char *hexgrip = NULL; char *hexgrip = NULL;
@ -1103,7 +1130,7 @@ list_keyblock_print (KBNODE keyblock, int secret, int fpr, void *opaque)
int sigrc; int sigrc;
char *sigstr; char *sigstr;
if (stats) if (listctx->check_sigs)
{ {
rc = check_key_signature (keyblock, node, NULL); rc = check_key_signature (keyblock, node, NULL);
switch (gpg_err_code (rc)) switch (gpg_err_code (rc))
@ -1112,15 +1139,15 @@ list_keyblock_print (KBNODE keyblock, int secret, int fpr, void *opaque)
sigrc = '!'; sigrc = '!';
break; break;
case GPG_ERR_BAD_SIGNATURE: case GPG_ERR_BAD_SIGNATURE:
stats->inv_sigs++; listctx->inv_sigs++;
sigrc = '-'; sigrc = '-';
break; break;
case GPG_ERR_NO_PUBKEY: case GPG_ERR_NO_PUBKEY:
case GPG_ERR_UNUSABLE_PUBKEY: case GPG_ERR_UNUSABLE_PUBKEY:
stats->no_key++; listctx->no_key++;
continue; continue;
default: default:
stats->oth_err++; listctx->oth_err++;
sigrc = '%'; sigrc = '%';
break; break;
} }
@ -1641,9 +1668,9 @@ reorder_keyblock (KBNODE keyblock)
do_reorder_keyblock (keyblock, 0); do_reorder_keyblock (keyblock, 0);
} }
void static void
list_keyblock (KBNODE keyblock, int secret, int has_secret, int fpr, list_keyblock (KBNODE keyblock, int secret, int has_secret, int fpr,
void *opaque) struct keylist_context *listctx)
{ {
reorder_keyblock (keyblock); reorder_keyblock (keyblock);
if (opt.print_pka_records) if (opt.print_pka_records)
@ -1651,12 +1678,24 @@ list_keyblock (KBNODE keyblock, int secret, int has_secret, int fpr,
else if (opt.with_colons) else if (opt.with_colons)
list_keyblock_colon (keyblock, secret, has_secret, fpr); list_keyblock_colon (keyblock, secret, has_secret, fpr);
else else
list_keyblock_print (keyblock, secret, fpr, opaque); list_keyblock_print (keyblock, secret, fpr, listctx);
if (secret) if (secret)
es_fflush (es_stdout); es_fflush (es_stdout);
} }
/* Public function used by keygen to list a keyblock. */
void
list_keyblock_direct (kbnode_t keyblock, int secret, int has_secret, int fpr)
{
struct keylist_context listctx;
memset (&listctx, 0, sizeof (listctx));
list_keyblock (keyblock, secret, has_secret, fpr, &listctx);
keylist_context_release (&listctx);
}
/* Print an hex digit in ICAO spelling. */ /* Print an hex digit in ICAO spelling. */
static void static void
print_icao_hexdigit (estream_t fp, int c) print_icao_hexdigit (estream_t fp, int c)

View File

@ -346,8 +346,8 @@ void public_key_list (ctrl_t ctrl, strlist_t list, int locate_mode );
void secret_key_list (ctrl_t ctrl, strlist_t list ); void secret_key_list (ctrl_t ctrl, strlist_t list );
void print_subpackets_colon(PKT_signature *sig); void print_subpackets_colon(PKT_signature *sig);
void reorder_keyblock (KBNODE keyblock); void reorder_keyblock (KBNODE keyblock);
void list_keyblock (kbnode_t keyblock, int secret, int has_secret, void list_keyblock_direct (kbnode_t keyblock, int secret, int has_secret,
int fpr, void *opaque); int fpr);
void print_fingerprint (estream_t fp, PKT_public_key *pk, int mode); void print_fingerprint (estream_t fp, PKT_public_key *pk, int mode);
void print_revokers (estream_t fp, PKT_public_key *pk); void print_revokers (estream_t fp, PKT_public_key *pk);
void show_policy_url(PKT_signature *sig,int indent,int mode); void show_policy_url(PKT_signature *sig,int indent,int mode);