2 * cleankey.c - Routines to look for common key problems and clean them up.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2004 Project Purple
14 #include "keystructs.h"
20 * dedupuids - Merge duplicate uids on a key.
21 * @key: The key to de-dup uids on.
23 * This function attempts to merge duplicate IDs on a key. It returns 0
24 * if the key is unchanged, otherwise the number of dups merged.
26 int dedupuids(struct openpgp_publickey *key)
28 struct openpgp_signedpacket_list *curuid = NULL;
29 struct openpgp_signedpacket_list *dup = NULL;
30 struct openpgp_signedpacket_list *tmp = NULL;
33 log_assert(key != NULL);
35 while (curuid != NULL) {
36 dup = find_signed_packet(curuid->next, curuid->packet);
38 logthing(LOGTHING_INFO, "Found duplicate uid: %.*s",
39 curuid->packet->length,
40 curuid->packet->data);
42 merge_packet_sigs(curuid, dup);
44 * Remove the duplicate uid.
47 while (tmp != NULL && tmp->next != dup) {
50 log_assert(tmp != NULL);
51 tmp->next = dup->next;
53 free_signedpacket_list(dup);
55 dup = find_signed_packet(curuid->next, curuid->packet);
57 curuid = curuid->next;
64 * cleankeys - Apply all available cleaning options on a list of keys.
65 * @keys: The list of keys to clean.
67 * Applies all the cleaning options we can (eg duplicate key ids) to a
68 * list of keys. Returns 0 if no changes were made, otherwise the number
71 int cleankeys(struct openpgp_publickey *keys)
75 while (keys != NULL) {
76 if (dedupuids(keys) > 0) {