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
8 * $Id: cleankey.c,v 1.1 2004/05/31 14:16:49 noodles Exp $
17 #include "keystructs.h"
23 * dedupuids - Merge duplicate uids on a key.
24 * @key: The key to de-dup uids on.
26 * This function attempts to merge duplicate IDs on a key. It returns 0
27 * if the key is unchanged, otherwise the number of dups merged.
29 int dedupuids(struct openpgp_publickey *key)
31 struct openpgp_signedpacket_list *curuid = NULL;
32 struct openpgp_signedpacket_list *dup = NULL;
33 struct openpgp_signedpacket_list *tmp = NULL;
38 while (curuid != NULL) {
39 dup = find_signed_packet(curuid->next, curuid->packet);
41 logthing(LOGTHING_INFO, "Found duplicate uid: %.*s",
42 curuid->packet->length,
43 curuid->packet->data);
45 merge_packet_sigs(curuid, dup);
47 * Remove the duplicate uid.
50 while (tmp != NULL && tmp->next != dup) {
54 tmp->next = dup->next;
56 free_signedpacket_list(dup);
58 dup = find_signed_packet(curuid->next, curuid->packet);
60 curuid = curuid->next;
67 * cleankeys - Apply all available cleaning options on a list of keys.
68 * @keys: The list of keys to clean.
70 * Applies all the cleaning options we can (eg duplicate key ids) to a
71 * list of keys. Returns 0 if no changes were made, otherwise the number
74 int cleankeys(struct openpgp_publickey *keys)
78 while (keys != NULL) {
79 if (dedupuids(keys) > 0) {