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
15 #include "keystructs.h"
21 * dedupuids - Merge duplicate uids on a key.
22 * @key: The key to de-dup uids on.
24 * This function attempts to merge duplicate IDs on a key. It returns 0
25 * if the key is unchanged, otherwise the number of dups merged.
27 int dedupuids(struct openpgp_publickey *key)
29 struct openpgp_signedpacket_list *curuid = NULL;
30 struct openpgp_signedpacket_list *dup = NULL;
31 struct openpgp_signedpacket_list *tmp = NULL;
36 while (curuid != NULL) {
37 dup = find_signed_packet(curuid->next, curuid->packet);
39 logthing(LOGTHING_INFO, "Found duplicate uid: %.*s",
40 curuid->packet->length,
41 curuid->packet->data);
43 merge_packet_sigs(curuid, dup);
45 * Remove the duplicate uid.
48 while (tmp != NULL && tmp->next != dup) {
52 tmp->next = dup->next;
54 free_signedpacket_list(dup);
56 dup = find_signed_packet(curuid->next, curuid->packet);
58 curuid = curuid->next;
65 * cleankeys - Apply all available cleaning options on a list of keys.
66 * @keys: The list of keys to clean.
68 * Applies all the cleaning options we can (eg duplicate key ids) to a
69 * list of keys. Returns 0 if no changes were made, otherwise the number
72 int cleankeys(struct openpgp_publickey *keys)
76 while (keys != NULL) {
77 if (dedupuids(keys) > 0) {