aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2016-09-28 13:32:04 +0000
committerWerner Koch <[email protected]>2016-09-28 13:32:04 +0000
commit80393661bdfa7ae0288644513575e8a5d708b084 (patch)
treede09d604e266ff97293b31790663f5815696ebe8
parentgpg: Make import filter data object more flexible. (diff)
downloadgnupg-80393661bdfa7ae0288644513575e8a5d708b084.tar.gz
gnupg-80393661bdfa7ae0288644513575e8a5d708b084.zip
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 <[email protected]>
Diffstat (limited to '')
-rw-r--r--g10/import.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/g10/import.c b/g10/import.c
index 25ce74ed9..8d064578b 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.