* Copyright 2002-2004 Project Purple
*/
-#include <assert.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <ctype.h>
{
int i = 0;
- dbenv->txn_checkpoint(dbenv, 0, 0, 0);
- id32db->close(id32db, 0);
- id32db = NULL;
- worddb->close(worddb, 0);
- worddb = NULL;
- for (i = 0; i < numdbs; i++) {
- dbconns[i]->close(dbconns[i], 0);
- dbconns[i] = NULL;
+ if (dbenv != NULL) {
+ dbenv->txn_checkpoint(dbenv, 0, 0, 0);
+ if (id32db != NULL) {
+ id32db->close(id32db, 0);
+ id32db = NULL;
+ }
+ if (worddb != NULL) {
+ worddb->close(worddb, 0);
+ worddb = NULL;
+ }
+ for (i = 0; i < numdbs; i++) {
+ if (dbconns[i] != NULL) {
+ dbconns[i]->close(dbconns[i], 0);
+ dbconns[i] = NULL;
+ }
+ }
+ dbenv->close(dbenv, 0);
+ dbenv = NULL;
}
- dbenv->close(dbenv, 0);
- dbenv = NULL;
}
/**
{
int ret;
- assert(dbenv != NULL);
- assert(txn == NULL);
+ log_assert(dbenv != NULL);
+ log_assert(txn == NULL);
ret = dbenv->txn_begin(dbenv,
NULL, /* No parent transaction */
{
int ret;
- assert(dbenv != NULL);
- assert(txn != NULL);
+ log_assert(dbenv != NULL);
+ log_assert(txn != NULL);
ret = txn->commit(txn,
0);
uids = NULL;
}
- if (!intrans) {
- endtrans();
- }
-
/*
* Write the truncated 32 bit keyid so we can lookup the full id for
* queries.
}
}
+ if (!intrans) {
+ endtrans();
+ }
+
return deadlock ? -1 : 0 ;
}
return 0;
}
+/**
+ * iterate_keys - call a function once for each key in the db.
+ * @iterfunc: The function to call.
+ * @ctx: A context pointer
+ *
+ * Calls iterfunc once for each key in the database. ctx is passed
+ * unaltered to iterfunc. This function is intended to aid database dumps
+ * and statistic calculations.
+ *
+ * Returns the number of keys we iterated over.
+ */
+int iterate_keys(void (*iterfunc)(void *ctx, struct openpgp_publickey *key),
+ void *ctx)
+{
+ DBT dbkey, data;
+ DBC *cursor = NULL;
+ int ret = 0;
+ int i = 0;
+ int numkeys = 0;
+ struct buffer_ctx fetchbuf;
+ struct openpgp_packet_list *packets = NULL;
+ struct openpgp_publickey *key = NULL;
+
+ for (i = 0; i < numdbs; i++) {
+ ret = dbconns[i]->cursor(dbconns[i],
+ NULL,
+ &cursor,
+ 0); /* flags */
+
+ memset(&dbkey, 0, sizeof(dbkey));
+ memset(&data, 0, sizeof(data));
+ ret = cursor->c_get(cursor, &dbkey, &data, DB_NEXT);
+ while (ret == 0) {
+ fetchbuf.buffer = data.data;
+ fetchbuf.offset = 0;
+ fetchbuf.size = data.size;
+ read_openpgp_stream(buffer_fetchchar, &fetchbuf,
+ &packets, 0);
+ parse_keys(packets, &key);
+
+ iterfunc(ctx, key);
+
+ free_publickey(key);
+ key = NULL;
+ free_packet_list(packets);
+ packets = NULL;
+
+ memset(&dbkey, 0, sizeof(dbkey));
+ memset(&data, 0, sizeof(data));
+ ret = cursor->c_get(cursor, &dbkey, &data,
+ DB_NEXT);
+ numkeys++;
+ }
+ if (ret != DB_NOTFOUND) {
+ logthing(LOGTHING_ERROR,
+ "Problem reading key: %s",
+ db_strerror(ret));
+ }
+
+ ret = cursor->c_close(cursor);
+ cursor = NULL;
+ }
+
+ return numkeys;
+}
+
/**
* getfullkeyid - Maps a 32bit key id to a 64bit one.
* @keyid: The 32bit keyid.
*/
#define NEED_GETKEYSIGS 1
#define NEED_KEYID2UID 1
+#define NEED_UPDATEKEYS 1
#include "keydb.c"