- if (keyid < 0x100000000LL) {
- fetch_key(keyid, &publickey, false);
- if (publickey != NULL) {
- keyid = get_keyid(publickey);
- free_publickey(publickey);
- publickey = NULL;
+ for (curkey = *keys; curkey != NULL; curkey = curkey->next) {
+ intrans = dbctx->starttrans(dbctx);
+ get_fingerprint(curkey->publickey, &fp);
+ logthing(LOGTHING_INFO,
+ "Fetching key, result: %d",
+ dbctx->fetch_key_fp(dbctx, &fp, &oldkey,
+ intrans));
+
+ /*
+ * If we already have the key stored in the DB then merge it
+ * with the new one that's been supplied. Otherwise the key
+ * we've just got is the one that goes in the DB and also the
+ * 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;
+ }
+ } else {
+ prev = curkey;
+ logthing(LOGTHING_INFO,
+ "Merged key; storing updated key.");
+ dbctx->store_key(dbctx, oldkey, intrans,
+ true);
+ }
+ free_publickey(oldkey);
+ oldkey = NULL;