2 * keydb_db4.c - Routines to store and fetch keys in a DB4 database.
4 * Copyright 2002-2008 Jonathan McDowell <noodles@earth.li>
20 #include "charfuncs.h"
24 #include "decodekey.h"
25 #include "keystructs.h"
28 #include "onak-conf.h"
32 #define DB4_UPGRADE_FILE "db_upgrade.lck"
35 * dbenv - our database environment.
37 static DB_ENV *dbenv = NULL;
40 * numdb - The number of database files we have.
42 static int numdbs = 16;
45 * dbconn - our connections to the key database files.
47 static DB **dbconns = NULL;
50 * worddb - our connection to the word database.
52 static DB *worddb = NULL;
55 * id32db - our connection to the 32bit ID database.
57 static DB *id32db = NULL;
60 * txn - our current transaction id.
62 static DB_TXN *txn = NULL;
64 DB *keydb(uint64_t keyid)
70 return(dbconns[keytrun % numdbs]);
74 * db4_errfunc - Direct DB errors to logfile
76 * Basic function to take errors from the DB library and output them to
77 * the logfile rather than stderr.
79 #if (DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR < 3)
80 static void db4_errfunc(const char *errpfx, const char *errmsg)
82 static void db4_errfunc(const DB_ENV *edbenv, const char *errpfx,
87 logthing(LOGTHING_DEBUG, "db4 error: %s:%s", errpfx, errmsg);
89 logthing(LOGTHING_DEBUG, "db4 error: %s", errmsg);
96 * starttrans - Start a transaction.
98 * Start a transaction. Intended to be used if we're about to perform many
99 * operations on the database to help speed it all up, or if we want
100 * something to only succeed if all relevant operations are successful.
102 static bool db4_starttrans(void)
106 log_assert(dbenv != NULL);
107 log_assert(txn == NULL);
109 ret = dbenv->txn_begin(dbenv,
110 NULL, /* No parent transaction */
114 logthing(LOGTHING_CRITICAL,
115 "Error starting transaction: %s",
124 * endtrans - End a transaction.
126 * Ends a transaction.
128 static void db4_endtrans(void)
132 log_assert(dbenv != NULL);
133 log_assert(txn != NULL);
135 ret = txn->commit(txn,
138 logthing(LOGTHING_CRITICAL,
139 "Error ending transaction: %s",
149 * cleanupdb - De-initialize the key database.
151 * This function should be called upon program exit to allow the DB to
152 * cleanup after itself.
154 static void db4_cleanupdb(void)
159 dbenv->txn_checkpoint(dbenv, 0, 0, 0);
160 if (id32db != NULL) {
161 id32db->close(id32db, 0);
164 if (worddb != NULL) {
165 worddb->close(worddb, 0);
168 for (i = 0; i < numdbs; i++) {
169 if (dbconns[i] != NULL) {
170 dbconns[i]->close(dbconns[i], 0);
176 dbenv->close(dbenv, 0);
182 * db4_upgradedb - Upgrade a DB4 database
184 * Called if we discover we need to upgrade our DB4 database; ie if
185 * we're running with a newer version of db4 than the database was
188 static int db4_upgradedb(int numdb)
197 snprintf(buf, sizeof(buf) - 1, "%s/%s", config.db_dir,
199 lockfile_fd = open(buf, O_RDWR | O_CREAT | O_EXCL, 0600);
200 if (lockfile_fd < 0) {
201 if (errno == EEXIST) {
202 while (stat(buf, &statbuf) == 0) ;
205 logthing(LOGTHING_CRITICAL, "Couldn't open database "
206 "update lock file: %s", strerror(errno));
210 snprintf(buf, sizeof(buf) - 1, "%d", getpid());
211 write(lockfile_fd, buf, strlen(buf));
214 logthing(LOGTHING_NOTICE, "Upgrading DB4 database");
215 ret = db_env_create(&dbenv, 0);
216 dbenv->set_errcall(dbenv, &db4_errfunc);
217 dbenv->remove(dbenv, config.db_dir, 0);
219 for (i = 0; i < numdb; i++) {
220 ret = db_create(&curdb, NULL, 0);
222 snprintf(buf, sizeof(buf) - 1, "%s/keydb.%d.db",
224 logthing(LOGTHING_DEBUG, "Upgrading %s", buf);
225 ret = curdb->upgrade(curdb, buf, 0);
226 curdb->close(curdb, 0);
228 logthing(LOGTHING_ERROR, "Error upgrading DB %s : %s",
234 ret = db_create(&curdb, NULL, 0);
236 snprintf(buf, sizeof(buf) - 1, "%s/worddb", config.db_dir);
237 logthing(LOGTHING_DEBUG, "Upgrading %s", buf);
238 ret = curdb->upgrade(curdb, buf, 0);
239 curdb->close(curdb, 0);
241 logthing(LOGTHING_ERROR, "Error upgrading DB %s : %s",
246 ret = db_create(&curdb, NULL, 0);
248 snprintf(buf, sizeof(buf) - 1, "%s/id32db", config.db_dir);
249 logthing(LOGTHING_DEBUG, "Upgrading %s", buf);
250 ret = curdb->upgrade(curdb, buf, 0);
251 curdb->close(curdb, 0);
253 logthing(LOGTHING_ERROR, "Error upgrading DB %s : %s",
258 snprintf(buf, sizeof(buf) - 1, "%s/%s", config.db_dir,
266 * initdb - Initialize the key database.
268 * This function should be called before any of the other functions in
269 * this file are called in order to allow the DB to be initialized ready
272 static void db4_initdb(bool readonly)
281 snprintf(buf, sizeof(buf) - 1, "%s/%s", config.db_dir,
283 ret = stat(buf, &statbuf);
284 while ((ret == 0) || (errno != ENOENT)) {
286 logthing(LOGTHING_CRITICAL, "Couldn't stat upgrade "
287 "lock file: %s (%d)", strerror(errno), ret);
290 logthing(LOGTHING_DEBUG, "DB4 upgrade in progress; waiting.");
292 ret = stat(buf, &statbuf);
296 snprintf(buf, sizeof(buf) - 1, "%s/num_keydb", config.db_dir);
297 numdb = fopen(buf, "r");
299 if (fgets(buf, sizeof(buf), numdb) != NULL) {
303 } else if (!readonly) {
304 logthing(LOGTHING_ERROR, "Couldn't open num_keydb: %s",
306 numdb = fopen(buf, "w");
308 fprintf(numdb, "%d", numdbs);
311 logthing(LOGTHING_ERROR,
312 "Couldn't write num_keydb: %s",
317 dbconns = malloc(sizeof (DB *) * numdbs);
318 if (dbconns == NULL) {
319 logthing(LOGTHING_CRITICAL,
320 "Couldn't allocate memory for dbconns");
325 ret = db_env_create(&dbenv, 0);
327 logthing(LOGTHING_CRITICAL,
328 "db_env_create: %s", db_strerror(ret));
333 * Enable deadlock detection so that we don't block indefinitely on
334 * anything. What we really want is simple 2 state locks, but I'm not
335 * sure how to make the standard DB functions do that yet.
338 dbenv->set_errcall(dbenv, &db4_errfunc);
339 ret = dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT);
341 logthing(LOGTHING_CRITICAL,
342 "db_env_create: %s", db_strerror(ret));
347 ret = dbenv->open(dbenv, config.db_dir,
348 DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_LOCK |
352 #ifdef DB_VERSION_MISMATCH
353 if (ret == DB_VERSION_MISMATCH) {
354 dbenv->close(dbenv, 0);
356 ret = db4_upgradedb(numdbs);
358 ret = db_env_create(&dbenv, 0);
361 dbenv->set_errcall(dbenv, &db4_errfunc);
362 dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT);
363 ret = dbenv->open(dbenv, config.db_dir,
364 DB_INIT_LOG | DB_INIT_MPOOL |
365 DB_INIT_LOCK | DB_INIT_TXN |
366 DB_CREATE | DB_RECOVER,
370 dbenv->txn_checkpoint(dbenv,
379 logthing(LOGTHING_CRITICAL,
380 "Error opening db environment: %s (%s)",
383 dbenv->close(dbenv, 0);
391 for (i = 0; !ret && i < numdbs; i++) {
392 ret = db_create(&dbconns[i], dbenv, 0);
394 logthing(LOGTHING_CRITICAL,
395 "db_create: %s", db_strerror(ret));
399 snprintf(buf, 1023, "keydb.%d.db", i);
404 ret = dbconns[i]->open(dbconns[i],
412 logthing(LOGTHING_CRITICAL,
413 "Error opening key database:"
424 ret = db_create(&worddb, dbenv, 0);
426 logthing(LOGTHING_CRITICAL, "db_create: %s",
432 ret = worddb->set_flags(worddb, DB_DUP);
436 ret = worddb->open(worddb, txn, "worddb", "worddb", DB_BTREE,
440 logthing(LOGTHING_CRITICAL,
441 "Error opening word database: %s (%s)",
448 ret = db_create(&id32db, dbenv, 0);
450 logthing(LOGTHING_CRITICAL, "db_create: %s",
456 ret = id32db->set_flags(id32db, DB_DUP);
460 ret = id32db->open(id32db, txn, "id32db", "id32db", DB_HASH,
464 logthing(LOGTHING_CRITICAL,
465 "Error opening id32 database: %s (%s)",
477 logthing(LOGTHING_CRITICAL,
478 "Error opening database; exiting");
486 * getfullkeyid - Maps a 32bit key id to a 64bit one.
487 * @keyid: The 32bit keyid.
489 * This function maps a 32bit key id to the full 64bit one. It returns the
490 * full keyid. If the key isn't found a keyid of 0 is returned.
492 static uint64_t db4_getfullkeyid(uint64_t keyid)
496 uint32_t shortkeyid = 0;
499 if (keyid < 0x100000000LL) {
500 ret = id32db->cursor(id32db,
505 shortkeyid = keyid & 0xFFFFFFFF;
507 memset(&key, 0, sizeof(key));
508 memset(&data, 0, sizeof(data));
509 key.data = &shortkeyid;
510 key.size = sizeof(shortkeyid);
511 data.flags = DB_DBT_MALLOC;
513 ret = cursor->c_get(cursor,
519 keyid = *(uint64_t *) data.data;
521 if (data.data != NULL) {
527 ret = cursor->c_close(cursor);
535 * fetch_key - Given a keyid fetch the key from storage.
536 * @keyid: The keyid to fetch.
537 * @publickey: A pointer to a structure to return the key in.
538 * @intrans: If we're already in a transaction.
540 * We use the hex representation of the keyid as the filename to fetch the
541 * key from. The key is stored in the file as a binary OpenPGP stream of
542 * packets, so we can just use read_openpgp_stream() to read the packets
543 * in and then parse_keys() to parse the packets into a publickey
546 static int db4_fetch_key(uint64_t keyid, struct openpgp_publickey **publickey,
549 struct openpgp_packet_list *packets = NULL;
553 struct buffer_ctx fetchbuf;
555 if (keyid < 0x100000000LL) {
556 keyid = db4_getfullkeyid(keyid);
559 memset(&key, 0, sizeof(key));
560 memset(&data, 0, sizeof(data));
565 key.size = sizeof(keyid);
572 ret = keydb(keyid)->get(keydb(keyid),
579 fetchbuf.buffer = data.data;
581 fetchbuf.size = data.size;
582 read_openpgp_stream(buffer_fetchchar, &fetchbuf,
584 parse_keys(packets, publickey);
585 free_packet_list(packets);
588 } else if (ret != DB_NOTFOUND) {
589 logthing(LOGTHING_ERROR,
590 "Problem retrieving key: %s",
601 int worddb_cmp(const void *d1, const void *d2)
603 return memcmp(d1, d2, 12);
607 * fetch_key_text - Trys to find the keys that contain the supplied text.
608 * @search: The text to search for.
609 * @publickey: A pointer to a structure to return the key in.
611 * This function searches for the supplied text and returns the keys that
614 static int db4_fetch_key_text(const char *search,
615 struct openpgp_publickey **publickey)
623 char *searchtext = NULL;
624 struct ll *wordlist = NULL;
625 struct ll *curword = NULL;
626 struct keyarray keylist = { NULL, 0, 0 };
627 struct keyarray newkeylist = { NULL, 0, 0 };
631 searchtext = strdup(search);
632 wordlist = makewordlist(wordlist, searchtext);
634 for (curword = wordlist; curword != NULL; curword = curword->next) {
637 ret = worddb->cursor(worddb,
642 memset(&key, 0, sizeof(key));
643 memset(&data, 0, sizeof(data));
644 key.data = curword->object;
645 key.size = strlen(curword->object);
646 data.flags = DB_DBT_MALLOC;
647 ret = cursor->c_get(cursor,
651 while (ret == 0 && strncmp(key.data, curword->object,
653 ((char *) curword->object)[key.size] == 0) {
655 for (i = 4; i < 12; i++) {
657 keyid += ((unsigned char *)
662 * Only add the keys containing this word if this is
663 * our first pass (ie we have no existing key list),
664 * or the key contained a previous word.
666 if (firstpass || array_find(&keylist, keyid)) {
667 array_add(&newkeylist, keyid);
673 ret = cursor->c_get(cursor,
678 array_free(&keylist);
679 keylist = newkeylist;
680 newkeylist.keys = NULL;
681 newkeylist.count = newkeylist.size = 0;
682 if (data.data != NULL) {
686 ret = cursor->c_close(cursor);
691 llfree(wordlist, NULL);
695 for (i = 0; i < keylist.count; i++) {
696 numkeys += db4_fetch_key(keylist.keys[i],
700 array_free(&keylist);
710 * delete_key - Given a keyid delete the key from storage.
711 * @keyid: The keyid to delete.
712 * @intrans: If we're already in a transaction.
714 * This function deletes a public key from whatever storage mechanism we
715 * are using. Returns 0 if the key existed.
717 static int db4_delete_key(uint64_t keyid, bool intrans)
719 struct openpgp_publickey *publickey = NULL;
722 uint32_t shortkeyid = 0;
723 uint64_t *subkeyids = NULL;
727 char *primary = NULL;
728 unsigned char worddb_data[12];
729 struct ll *wordlist = NULL;
730 struct ll *curword = NULL;
731 bool deadlock = false;
737 db4_fetch_key(keyid, &publickey, true);
740 * Walk through the uids removing the words from the worddb.
742 if (publickey != NULL) {
743 uids = keyuids(publickey, &primary);
746 for (i = 0; ret == 0 && uids[i] != NULL; i++) {
747 wordlist = makewordlist(wordlist, uids[i]);
750 ret = worddb->cursor(worddb,
755 for (curword = wordlist; curword != NULL && !deadlock;
756 curword = curword->next) {
757 memset(&key, 0, sizeof(key));
758 memset(&data, 0, sizeof(data));
759 key.data = curword->object;
760 key.size = strlen(key.data);
761 data.data = worddb_data;
762 data.size = sizeof(worddb_data);
765 * Our data is the key creation time followed by the
768 worddb_data[ 0] = publickey->publickey->data[1];
769 worddb_data[ 1] = publickey->publickey->data[2];
770 worddb_data[ 2] = publickey->publickey->data[3];
771 worddb_data[ 3] = publickey->publickey->data[4];
772 worddb_data[ 4] = (keyid >> 56) & 0xFF;
773 worddb_data[ 5] = (keyid >> 48) & 0xFF;
774 worddb_data[ 6] = (keyid >> 40) & 0xFF;
775 worddb_data[ 7] = (keyid >> 32) & 0xFF;
776 worddb_data[ 8] = (keyid >> 24) & 0xFF;
777 worddb_data[ 9] = (keyid >> 16) & 0xFF;
778 worddb_data[10] = (keyid >> 8) & 0xFF;
779 worddb_data[11] = keyid & 0xFF;
781 ret = cursor->c_get(cursor,
787 ret = cursor->c_del(cursor, 0);
789 logthing(LOGTHING_ERROR,
790 "Problem deleting word: %s",
796 logthing(LOGTHING_ERROR,
797 "Problem deleting word: %s",
799 if (ret == DB_LOCK_DEADLOCK) {
804 ret = cursor->c_close(cursor);
808 * Free our UID and word lists.
810 llfree(wordlist, NULL);
811 for (i = 0; uids[i] != NULL; i++) {
817 free_publickey(publickey);
822 ret = id32db->cursor(id32db,
827 shortkeyid = keyid & 0xFFFFFFFF;
829 memset(&key, 0, sizeof(key));
830 memset(&data, 0, sizeof(data));
831 key.data = &shortkeyid;
832 key.size = sizeof(shortkeyid);
834 data.size = sizeof(keyid);
836 ret = cursor->c_get(cursor,
842 ret = cursor->c_del(cursor, 0);
844 logthing(LOGTHING_ERROR,
845 "Problem deleting short keyid: %s",
851 logthing(LOGTHING_ERROR,
852 "Problem deleting short keyid: %s",
854 if (ret == DB_LOCK_DEADLOCK) {
859 subkeyids = keysubkeys(publickey);
861 while (subkeyids != NULL && subkeyids[i] != 0) {
862 shortkeyid = subkeyids[i++] & 0xFFFFFFFF;
864 memset(&key, 0, sizeof(key));
865 memset(&data, 0, sizeof(data));
866 key.data = &shortkeyid;
867 key.size = sizeof(shortkeyid);
869 data.size = sizeof(keyid);
871 ret = cursor->c_get(cursor,
877 ret = cursor->c_del(cursor, 0);
879 logthing(LOGTHING_ERROR,
880 "Problem deleting short"
887 logthing(LOGTHING_ERROR,
888 "Problem deleting short keyid: %s",
890 if (ret == DB_LOCK_DEADLOCK) {
895 if (subkeyids != NULL) {
900 ret = cursor->c_close(cursor);
906 key.size = sizeof(keyid);
908 keydb(keyid)->del(keydb(keyid),
918 return deadlock ? (-1) : (ret == DB_NOTFOUND);
922 * store_key - Takes a key and stores it.
923 * @publickey: A pointer to the public key to store.
924 * @intrans: If we're already in a transaction.
925 * @update: If true the key exists and should be updated.
927 * Again we just use the hex representation of the keyid as the filename
928 * to store the key to. We flatten the public key to a list of OpenPGP
929 * packets and then use write_openpgp_stream() to write the stream out to
930 * the file. If update is true then we delete the old key first, otherwise
931 * we trust that it doesn't exist.
933 static int db4_store_key(struct openpgp_publickey *publickey, bool intrans,
936 struct openpgp_packet_list *packets = NULL;
937 struct openpgp_packet_list *list_end = NULL;
938 struct openpgp_publickey *next = NULL;
941 struct buffer_ctx storebuf;
945 uint32_t shortkeyid = 0;
946 uint64_t *subkeyids = NULL;
948 char *primary = NULL;
949 unsigned char worddb_data[12];
950 struct ll *wordlist = NULL;
951 struct ll *curword = NULL;
952 bool deadlock = false;
954 keyid = get_keyid(publickey);
961 * Delete the key if we already have it.
963 * TODO: Can we optimize this perhaps? Possibly when other data is
964 * involved as well? I suspect this is easiest and doesn't make a lot
965 * of difference though - the largest chunk of data is the keydata and
966 * it definitely needs updated.
969 deadlock = (db4_delete_key(keyid, true) == -1);
973 * Convert the key to a flat set of binary data.
976 next = publickey->next;
977 publickey->next = NULL;
978 flatten_publickey(publickey, &packets, &list_end);
979 publickey->next = next;
982 storebuf.size = 8192;
983 storebuf.buffer = malloc(8192);
985 write_openpgp_stream(buffer_putchar, &storebuf, packets);
988 * Now we have the key data store it in the DB; the keyid is
991 memset(&key, 0, sizeof(key));
992 memset(&data, 0, sizeof(data));
994 key.size = sizeof(keyid);
995 data.size = storebuf.offset;
996 data.data = storebuf.buffer;
998 ret = keydb(keyid)->put(keydb(keyid),
1004 logthing(LOGTHING_ERROR,
1005 "Problem storing key: %s",
1007 if (ret == DB_LOCK_DEADLOCK) {
1012 free(storebuf.buffer);
1013 storebuf.buffer = NULL;
1015 storebuf.offset = 0;
1017 free_packet_list(packets);
1022 * Walk through our uids storing the words into the db with the keyid.
1025 uids = keyuids(publickey, &primary);
1028 for (i = 0; ret == 0 && uids[i] != NULL; i++) {
1029 wordlist = makewordlist(wordlist, uids[i]);
1032 for (curword = wordlist; curword != NULL && !deadlock;
1033 curword = curword->next) {
1034 memset(&key, 0, sizeof(key));
1035 memset(&data, 0, sizeof(data));
1036 key.data = curword->object;
1037 key.size = strlen(key.data);
1038 data.data = worddb_data;
1039 data.size = sizeof(worddb_data);
1042 * Our data is the key creation time followed by the
1045 worddb_data[ 0] = publickey->publickey->data[1];
1046 worddb_data[ 1] = publickey->publickey->data[2];
1047 worddb_data[ 2] = publickey->publickey->data[3];
1048 worddb_data[ 3] = publickey->publickey->data[4];
1049 worddb_data[ 4] = (keyid >> 56) & 0xFF;
1050 worddb_data[ 5] = (keyid >> 48) & 0xFF;
1051 worddb_data[ 6] = (keyid >> 40) & 0xFF;
1052 worddb_data[ 7] = (keyid >> 32) & 0xFF;
1053 worddb_data[ 8] = (keyid >> 24) & 0xFF;
1054 worddb_data[ 9] = (keyid >> 16) & 0xFF;
1055 worddb_data[10] = (keyid >> 8) & 0xFF;
1056 worddb_data[11] = keyid & 0xFF;
1057 ret = worddb->put(worddb,
1063 logthing(LOGTHING_ERROR,
1064 "Problem storing word: %s",
1066 if (ret == DB_LOCK_DEADLOCK) {
1073 * Free our UID and word lists.
1075 llfree(wordlist, NULL);
1076 for (i = 0; uids[i] != NULL; i++) {
1085 * Write the truncated 32 bit keyid so we can lookup the full id for
1089 shortkeyid = keyid & 0xFFFFFFFF;
1091 memset(&key, 0, sizeof(key));
1092 memset(&data, 0, sizeof(data));
1093 key.data = &shortkeyid;
1094 key.size = sizeof(shortkeyid);
1096 data.size = sizeof(keyid);
1098 ret = id32db->put(id32db,
1104 logthing(LOGTHING_ERROR,
1105 "Problem storing short keyid: %s",
1107 if (ret == DB_LOCK_DEADLOCK) {
1114 subkeyids = keysubkeys(publickey);
1116 while (subkeyids != NULL && subkeyids[i] != 0) {
1117 shortkeyid = subkeyids[i++] & 0xFFFFFFFF;
1119 memset(&key, 0, sizeof(key));
1120 memset(&data, 0, sizeof(data));
1121 key.data = &shortkeyid;
1122 key.size = sizeof(shortkeyid);
1124 data.size = sizeof(keyid);
1126 ret = id32db->put(id32db,
1132 logthing(LOGTHING_ERROR,
1133 "Problem storing short keyid: %s",
1135 if (ret == DB_LOCK_DEADLOCK) {
1140 if (subkeyids != NULL) {
1150 return deadlock ? -1 : 0 ;
1154 * iterate_keys - call a function once for each key in the db.
1155 * @iterfunc: The function to call.
1156 * @ctx: A context pointer
1158 * Calls iterfunc once for each key in the database. ctx is passed
1159 * unaltered to iterfunc. This function is intended to aid database dumps
1160 * and statistic calculations.
1162 * Returns the number of keys we iterated over.
1164 static int db4_iterate_keys(void (*iterfunc)(void *ctx,
1165 struct openpgp_publickey *key), void *ctx)
1172 struct buffer_ctx fetchbuf;
1173 struct openpgp_packet_list *packets = NULL;
1174 struct openpgp_publickey *key = NULL;
1176 for (i = 0; i < numdbs; i++) {
1177 ret = dbconns[i]->cursor(dbconns[i],
1182 memset(&dbkey, 0, sizeof(dbkey));
1183 memset(&data, 0, sizeof(data));
1184 ret = cursor->c_get(cursor, &dbkey, &data, DB_NEXT);
1186 fetchbuf.buffer = data.data;
1187 fetchbuf.offset = 0;
1188 fetchbuf.size = data.size;
1189 read_openpgp_stream(buffer_fetchchar, &fetchbuf,
1191 parse_keys(packets, &key);
1195 free_publickey(key);
1197 free_packet_list(packets);
1200 memset(&dbkey, 0, sizeof(dbkey));
1201 memset(&data, 0, sizeof(data));
1202 ret = cursor->c_get(cursor, &dbkey, &data,
1206 if (ret != DB_NOTFOUND) {
1207 logthing(LOGTHING_ERROR,
1208 "Problem reading key: %s",
1212 ret = cursor->c_close(cursor);
1220 * Include the basic keydb routines.
1222 #define NEED_GETKEYSIGS 1
1223 #define NEED_KEYID2UID 1
1224 #define NEED_UPDATEKEYS 1
1227 struct dbfuncs keydb_db4_funcs = {
1228 .initdb = db4_initdb,
1229 .cleanupdb = db4_cleanupdb,
1230 .starttrans = db4_starttrans,
1231 .endtrans = db4_endtrans,
1232 .fetch_key = db4_fetch_key,
1233 .fetch_key_text = db4_fetch_key_text,
1234 .store_key = db4_store_key,
1235 .update_keys = generic_update_keys,
1236 .delete_key = db4_delete_key,
1237 .getkeysigs = generic_getkeysigs,
1238 .cached_getkeysigs = generic_cached_getkeysigs,
1239 .keyid2uid = generic_keyid2uid,
1240 .getfullkeyid = db4_getfullkeyid,
1241 .iterate_keys = db4_iterate_keys,