X-Git-Url: https://the.earth.li/gitweb/?p=onak.git;a=blobdiff_plain;f=keydb.c;h=30a77caf61f912ddf5142aff5669b8d1be2844cc;hp=1a882386bf25933c4ea4ae5fa47853301ce5bd6b;hb=f869498b2b159bd3d363fb2f9d803b99c44de8bc;hpb=a8c0920cce727a12697154a85896f2a3ba47eb75 diff --git a/keydb.c b/keydb.c index 1a88238..30a77ca 100644 --- a/keydb.c +++ b/keydb.c @@ -170,16 +170,18 @@ struct ll *generic_cached_getkeysigs(struct onak_dbctx *dbctx, uint64_t keyid) int generic_update_keys(struct onak_dbctx *dbctx, struct openpgp_publickey **keys, bool sendsync) { - struct openpgp_publickey *curkey = NULL; + struct openpgp_publickey **curkey, *tmp = NULL; struct openpgp_publickey *oldkey = NULL; - struct openpgp_publickey *prev = NULL; struct openpgp_fingerprint fp; int newkeys = 0; bool intrans; - for (curkey = *keys; curkey != NULL; curkey = curkey->next) { + curkey = keys; + while (*curkey != NULL) { + get_fingerprint((*curkey)->publickey, &fp); + intrans = dbctx->starttrans(dbctx); - get_fingerprint(curkey->publickey, &fp); + logthing(LOGTHING_INFO, "Fetching key, result: %d", dbctx->fetch_key_fp(dbctx, &fp, &oldkey, @@ -192,37 +194,34 @@ int generic_update_keys(struct onak_dbctx *dbctx, * one that we send out. */ if (oldkey != NULL) { - merge_keys(oldkey, curkey); - if (curkey->sigs == NULL && - curkey->uids == NULL && - curkey->subkeys == NULL) { - if (prev == NULL) { - *keys = curkey->next; - } else { - prev->next = curkey->next; - curkey->next = NULL; - free_publickey(curkey); - curkey = prev; - } + merge_keys(oldkey, *curkey); + if ((*curkey)->sigs == NULL && + (*curkey)->uids == NULL && + (*curkey)->subkeys == NULL) { + tmp = *curkey; + *curkey = (*curkey)->next; + tmp->next = NULL; + free_publickey(tmp); } else { - prev = curkey; logthing(LOGTHING_INFO, "Merged key; storing updated key."); dbctx->store_key(dbctx, oldkey, intrans, true); + curkey = &(*curkey)->next; } free_publickey(oldkey); oldkey = NULL; } else { logthing(LOGTHING_INFO, "Storing completely new key."); - dbctx->store_key(dbctx, curkey, intrans, false); + dbctx->store_key(dbctx, *curkey, intrans, false); newkeys++; + curkey = &(*curkey)->next; } dbctx->endtrans(dbctx); } - if (sendsync && keys != NULL) { + if (sendsync && keys != NULL && *keys != NULL) { sendkeysync(*keys); }