From 8ac61bc708194f01e64c3c12127def1ec149687c Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Wed, 30 Jan 2008 17:21:28 +0000 Subject: [PATCH] 2008-01-29 Marcus Brinkmann * keylist.c (list_internal_keys): New variable lastcert. Use it to suppress duplicates which immediately follow each other. --- sm/ChangeLog | 5 +++++ sm/keylist.c | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/sm/ChangeLog b/sm/ChangeLog index 3f7374a4f..dcbbff3cf 100644 --- a/sm/ChangeLog +++ b/sm/ChangeLog @@ -1,3 +1,8 @@ +2008-01-29 Marcus Brinkmann + + * keylist.c (list_internal_keys): New variable lastcert. Use it + to suppress duplicates which immediately follow each other. + 2008-01-27 Werner Koch * import.c (popen_protect_tool): Set bit 7 in the flags for diff --git a/sm/keylist.c b/sm/keylist.c index 0f5313eb2..e9ca9b809 100644 --- a/sm/keylist.c +++ b/sm/keylist.c @@ -1171,6 +1171,7 @@ list_internal_keys (ctrl_t ctrl, strlist_t names, estream_t fp, strlist_t sl; int ndesc; ksba_cert_t cert = NULL; + ksba_cert_t lastcert = NULL; gpg_error_t rc = 0; const char *lastresname, *resname; int have_secret; @@ -1228,6 +1229,7 @@ list_internal_keys (ctrl_t ctrl, strlist_t names, estream_t fp, currently we stop at the first match. To do this we need an extra flag to enable this feature so */ + /* Suppress duplicates at least when they follow each other. */ lastresname = NULL; while (!(rc = keydb_search (hd, desc, ndesc))) { @@ -1248,7 +1250,15 @@ list_internal_keys (ctrl_t ctrl, strlist_t names, estream_t fp, log_error ("keydb_get_cert failed: %s\n", gpg_strerror (rc)); goto leave; } - + /* Skip duplicated certificates, at least if they follow each + others. This works best if a single key is searched for and + expected. FIXME: Non-sequential duplicates remain. */ + if (gpgsm_certs_identical_p (cert, lastcert)) + { + ksba_cert_release (cert); + continue; + } + resname = keydb_get_resource_name (hd); if (lastresname != resname ) @@ -1301,7 +1311,9 @@ list_internal_keys (ctrl_t ctrl, strlist_t names, estream_t fp, es_putc ('\n', fp); } } - ksba_cert_release (cert); + + ksba_cert_release (lastcert); + lastcert = cert; cert = NULL; } if (gpg_err_code (rc) == GPG_ERR_EOF || rc == -1 ) @@ -1311,6 +1323,7 @@ list_internal_keys (ctrl_t ctrl, strlist_t names, estream_t fp, leave: ksba_cert_release (cert); + ksba_cert_release (lastcert); xfree (desc); keydb_release (hd); return rc;