2 * cleankey.c - Routines to look for common key problems and clean them up.
4 * Copyright 2004 Jonathan McDowell <noodles@earth.li>
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "keystructs.h"
31 * dedupuids - Merge duplicate uids on a key.
32 * @key: The key to de-dup uids on.
34 * This function attempts to merge duplicate IDs on a key. It returns 0
35 * if the key is unchanged, otherwise the number of dups merged.
37 int dedupuids(struct openpgp_publickey *key)
39 struct openpgp_signedpacket_list *curuid = NULL;
40 struct openpgp_signedpacket_list *dup = NULL;
41 struct openpgp_signedpacket_list *tmp = NULL;
44 log_assert(key != NULL);
46 while (curuid != NULL) {
47 dup = find_signed_packet(curuid->next, curuid->packet);
49 logthing(LOGTHING_INFO, "Found duplicate uid: %.*s",
50 curuid->packet->length,
51 curuid->packet->data);
53 merge_packet_sigs(curuid, dup);
55 * Remove the duplicate uid.
58 while (tmp != NULL && tmp->next != dup) {
61 log_assert(tmp != NULL);
62 tmp->next = dup->next;
64 free_signedpacket_list(dup);
66 dup = find_signed_packet(curuid->next, curuid->packet);
68 curuid = curuid->next;
75 * cleankeys - Apply all available cleaning options on a list of keys.
76 * @keys: The list of keys to clean.
78 * Applies all the cleaning options we can (eg duplicate key ids) to a
79 * list of keys. Returns 0 if no changes were made, otherwise the number
82 int cleankeys(struct openpgp_publickey *keys)
86 while (keys != NULL) {
87 if (dedupuids(keys) > 0) {