[Pkg-gnupg-commit] [gnupg2] 58/292: gpg: Reject import if an import filter removed all user ids.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Mon Nov 21 06:31:26 UTC 2016
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch master
in repository gnupg2.
commit 80393661bdfa7ae0288644513575e8a5d708b084
Author: Werner Koch <wk at gnupg.org>
Date: Wed Sep 28 15:32:04 2016 +0200
gpg: Reject import if an import filter removed all user ids.
* g10/import.c (any_uid_left): New.
(import_one): Check that a UID is left.
Signed-off-by: Werner Koch <wk at gnupg.org>
---
g10/import.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/g10/import.c b/g10/import.c
index 25ce74e..8d06457 100644
--- a/g10/import.c
+++ b/g10/import.c
@@ -115,6 +115,7 @@ static int import_revoke_cert (kbnode_t node, struct import_stats_s *stats);
static int chk_self_sigs (kbnode_t keyblock, u32 *keyid, int *non_self);
static int delete_inv_parts (kbnode_t keyblock,
u32 *keyid, unsigned int options);
+static int any_uid_left (kbnode_t keyblock);
static int merge_blocks (kbnode_t keyblock_orig,
kbnode_t keyblock, u32 *keyid,
int *n_uids, int *n_sigs, int *n_subk );
@@ -1344,6 +1345,7 @@ import_one (ctrl_t ctrl,
size_t an;
char pkstrbuf[PUBKEY_STRING_SIZE];
int merge_keys_done = 0;
+ int any_filter = 0;
/* Get the key and print some info about it. */
node = find_kbnode( keyblock, PKT_PUBLIC_KEY );
@@ -1455,13 +1457,25 @@ import_one (ctrl_t ctrl,
{
apply_keep_uid_filter (keyblock, import_filter.keep_uid);
commit_kbnode (&keyblock);
+ any_filter = 1;
}
if (import_filter.drop_sig)
{
apply_drop_sig_filter (keyblock, import_filter.drop_sig);
commit_kbnode (&keyblock);
+ any_filter = 1;
}
+ /* If we ran any filter we need to check that at least one user id
+ * is left in the keyring. Note that we do not use log_error in
+ * this case. */
+ if (any_filter && !any_uid_left (keyblock))
+ {
+ if (!opt.quiet )
+ log_info ( _("key %s: no valid user IDs\n"), keystr_from_pk (pk));
+ stats->no_user_id++;
+ return 0;
+ }
/* Show the key in the form it is merged or inserted. We skip this
* if "import-export" is also active without --armor or the output
@@ -2743,6 +2757,19 @@ delete_inv_parts (kbnode_t keyblock, u32 *keyid, unsigned int options)
return nvalid;
}
+/* This function returns true if any UID is left in the keyring. */
+static int
+any_uid_left (kbnode_t keyblock)
+{
+ kbnode_t node;
+
+ for (node=keyblock->next; node; node = node->next)
+ if (node->pkt->pkttype == PKT_USER_ID)
+ return 1;
+ return 0;
+}
+
+
/****************
* It may happen that the imported keyblock has duplicated user IDs.
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git
More information about the Pkg-gnupg-commit
mailing list