summaryrefslogtreecommitdiffstats
path: root/g10/revoke.c
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@g10code.com>2015-11-20 13:00:19 +0100
committerNeal H. Walfield <neal@g10code.com>2015-11-20 13:00:19 +0100
commit178af9c3f56d385fe28a9e5e8bde0ab34c0b260e (patch)
tree30293f90562f99a05f6957970e8e04ed511c2183 /g10/revoke.c
parentgpg: Refactor print_seckey_info. (diff)
downloadgnupg2-178af9c3f56d385fe28a9e5e8bde0ab34c0b260e.tar.xz
gnupg2-178af9c3f56d385fe28a9e5e8bde0ab34c0b260e.zip
gpg: Fail if the search description passed to --gen-revoke is ambiguous.
* g10/revoke.c (gen_revoke): Error out if the search description is ambiguous. -- Signed-off-by: Neal H. Walfield <neal@g10code.com>
Diffstat (limited to 'g10/revoke.c')
-rw-r--r--g10/revoke.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/g10/revoke.c b/g10/revoke.c
index 0ed2604ed..8599d17af 100644
--- a/g10/revoke.c
+++ b/g10/revoke.c
@@ -630,6 +630,47 @@ gen_revoke (const char *uname)
goto leave;
}
+ rc = keydb_search (kdbhd, &desc, 1, NULL);
+ if (gpg_err_code (rc) == GPG_ERR_NOT_FOUND)
+ /* Not ambiguous. */
+ {
+ }
+ else if (rc == 0)
+ /* Ambiguous. */
+ {
+ char *info;
+
+ log_error (_("'%s' matches multiple secret keys:\n"), uname);
+
+ info = format_seckey_info (keyblock->pkt->pkt.public_key);
+ log_error (" %s\n", info);
+ xfree (info);
+ release_kbnode (keyblock);
+
+ rc = keydb_get_keyblock (kdbhd, &keyblock);
+ while (! rc)
+ {
+ info = format_seckey_info (keyblock->pkt->pkt.public_key);
+ log_error (" %s\n", info);
+ xfree (info);
+ release_kbnode (keyblock);
+ keyblock = NULL;
+
+ rc = keydb_search (kdbhd, &desc, 1, NULL);
+ if (! rc)
+ rc = keydb_get_keyblock (kdbhd, &keyblock);
+ }
+
+ rc = GPG_ERR_AMBIGUOUS_NAME;
+
+ goto leave;
+ }
+ else
+ {
+ log_error (_("error searching the keyring: %s\n"), gpg_strerror (rc));
+ goto leave;
+ }
+
/* Get the keyid from the keyblock. */
node = find_kbnode (keyblock, PKT_PUBLIC_KEY);
if (!node)