X-Git-Url: http://the.earth.li/gitweb/?a=blobdiff_plain;f=keydb.c;h=ac70640e26df6bfedcfd7f506a09e30155a75abf;hb=c04c1c60469823c01268187ec49102d1ff540806;hp=0039057093898bc067f5c3149ae9a0ec352559a9;hpb=6fcdf43b866c8199065bdf5bfc05942ed79bde16;p=onak.git diff --git a/keydb.c b/keydb.c index 0039057..ac70640 100644 --- a/keydb.c +++ b/keydb.c @@ -1,9 +1,20 @@ /* * keydb.c - Routines for DB access that just use store/fetch. * - * Jonathan McDowell + * Copyright 2002-2004 Jonathan McDowell * - * Copyright 2002-2004 Project Purple + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /** @@ -23,6 +34,7 @@ #include "keystructs.h" #include "mem.h" #include "merge.h" +#include "openpgp.h" #include "parsekey.h" #include "sendsync.h" @@ -38,11 +50,11 @@ char *generic_keyid2uid(uint64_t keyid) char buf[1024]; buf[0]=0; - if (config.dbbackend->fetch_key(keyid, &publickey, false) && + if (config.dbbackend->fetch_key_id(keyid, &publickey, false) && publickey != NULL) { curuid = publickey->uids; while (curuid != NULL && buf[0] == 0) { - if (curuid->packet->tag == 13) { + if (curuid->packet->tag == OPENPGP_PACKET_UID) { snprintf(buf, 1023, "%.*s", (int) curuid->packet->length, curuid->packet->data); @@ -76,7 +88,7 @@ struct ll *generic_getkeysigs(uint64_t keyid, bool *revoked) struct openpgp_signedpacket_list *uids = NULL; struct openpgp_publickey *publickey = NULL; - config.dbbackend->fetch_key(keyid, &publickey, false); + config.dbbackend->fetch_key_id(keyid, &publickey, false); if (publickey != NULL) { for (uids = publickey->uids; uids != NULL; uids = uids->next) { @@ -105,16 +117,24 @@ struct ll *generic_cached_getkeysigs(uint64_t keyid) struct stats_key *key = NULL; struct stats_key *signedkey = NULL; struct ll *cursig = NULL; + struct ll *sigs = NULL; bool revoked = false; if (keyid == 0) { return NULL; } - key = createandaddtohash(keyid); + key = findinhash(keyid); - if (key->gotsigs == false) { - key->sigs = config.dbbackend->getkeysigs(key->keyid, &revoked); + if (key == NULL || key->gotsigs == false) { + sigs = config.dbbackend->getkeysigs(keyid, &revoked); + if (sigs == NULL) { + return NULL; + } + if (key == NULL) { + key = createandaddtohash(keyid); + } + key->sigs = sigs; key->revoked = revoked; for (cursig = key->sigs; cursig != NULL; cursig = cursig->next) { @@ -140,9 +160,9 @@ uint64_t generic_getfullkeyid(uint64_t keyid) struct openpgp_publickey *publickey = NULL; if (keyid < 0x100000000LL) { - config.dbbackend->fetch_key(keyid, &publickey, false); + config.dbbackend->fetch_key_id(keyid, &publickey, false); if (publickey != NULL) { - keyid = get_keyid(publickey); + get_keyid(publickey, &keyid); free_publickey(publickey); publickey = NULL; } else { @@ -173,13 +193,15 @@ int generic_update_keys(struct openpgp_publickey **keys, bool sendsync) struct openpgp_publickey *prev = NULL; int newkeys = 0; bool intrans; + uint64_t keyid; for (curkey = *keys; curkey != NULL; curkey = curkey->next) { intrans = config.dbbackend->starttrans(); + get_keyid(curkey, &keyid); logthing(LOGTHING_INFO, - "Fetching key 0x%llX, result: %d", - get_keyid(curkey), - config.dbbackend->fetch_key(get_keyid(curkey), &oldkey, + "Fetching key 0x%" PRIX64 ", result: %d", + keyid, + config.dbbackend->fetch_key_id(keyid, &oldkey, intrans)); /* @@ -227,3 +249,30 @@ int generic_update_keys(struct openpgp_publickey **keys, bool sendsync) return newkeys; } #endif /* NEED_UPDATEKEYS */ + +#ifdef NEED_GET_FP +static int generic_fetch_key_fp(uint8_t *fp, size_t fpsize, + struct openpgp_publickey **publickey, bool intrans) +{ + uint64_t keyid; + int i; + + if (fpsize > MAX_FINGERPRINT_LEN) { + return 0; + } + + /* + * We assume if the backend is using this function it's not storing + * anything bigger than the 64 bit key ID and just truncate the + * fingerprint to get that value. This doesn't work for v3 keys, + * but there's no way to map from v3 fingerprint to v3 key ID so + * if the backend can't do it we're going to fail anyway. + */ + keyid = 0; + for (i = (fpsize - 8); i < fpsize; i++) { + keyid = (keyid << 8) + fp[i]; + } + + return config.dbbackend->fetch_key_id(keyid, publickey, intrans); +} +#endif