]> the.earth.li Git - onak.git/blobdiff - keydb/keydb_db4.c
0.6.3 release
[onak.git] / keydb / keydb_db4.c
index 1f306e267f60e9851c0dd65b0874517ba7afcb39..35fcdd1cd1913817197b5ebf0bc8a74e582e342c 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <db.h>
 
+#include "build-config.h"
 #include "charfuncs.h"
 #include "keyarray.h"
 #include "keydb.h"
@@ -92,7 +93,7 @@ DB *keydb_fp(struct onak_db4_dbctx *privctx, struct openpgp_fingerprint *fp)
 #if (DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR < 3)
 static void db4_errfunc(const char *errpfx, const char *errmsg)
 #else
-static void db4_errfunc(const DB_ENV *edbenv, const char *errpfx,
+static void db4_errfunc(__unused const DB_ENV *edbenv, const char *errpfx,
                const char *errmsg)
 #endif
 {
@@ -295,10 +296,11 @@ static int db4_upgradedb(struct onak_dbctx *dbctx)
 /**
  *     fetch_key_fp - Given a fingerprint fetch the key from storage.
  */
-static int db4_fetch_key_fp(struct onak_dbctx *dbctx,
+static int db4_fetch_key_int(struct onak_dbctx *dbctx,
                struct openpgp_fingerprint *fingerprint,
                struct openpgp_publickey **publickey,
-               bool intrans)
+               bool intrans,
+               bool dosubkey)
 {
        struct onak_db4_dbctx *privctx = (struct onak_db4_dbctx *) dbctx->priv;
        struct openpgp_packet_list *packets = NULL;
@@ -328,7 +330,7 @@ static int db4_fetch_key_fp(struct onak_dbctx *dbctx,
                        &data,
                        0); /* flags*/
 
-       if (ret == DB_NOTFOUND) {
+       if (ret == DB_NOTFOUND && dosubkey) {
                /* If we didn't find the key ID see if it's a subkey ID */
                memset(&key, 0, sizeof(key));
                memset(&data, 0, sizeof(data));
@@ -386,6 +388,22 @@ static int db4_fetch_key_fp(struct onak_dbctx *dbctx,
        return (numkeys);
 }
 
+static int db4_fetch_key(struct onak_dbctx *dbctx,
+               struct openpgp_fingerprint *fingerprint,
+               struct openpgp_publickey **publickey,
+               bool intrans)
+{
+       return db4_fetch_key_int(dbctx, fingerprint, publickey, intrans, false);
+}
+
+static int db4_fetch_key_fp(struct onak_dbctx *dbctx,
+               struct openpgp_fingerprint *fingerprint,
+               struct openpgp_publickey **publickey,
+               bool intrans)
+{
+       return db4_fetch_key_int(dbctx, fingerprint, publickey, intrans, true);
+}
+
 /**
  *     fetch_key_id - Given a keyid fetch the key from storage.
  *     @keyid: The keyid to fetch.
@@ -1744,8 +1762,9 @@ struct onak_dbctx *keydb_db4_init(struct onak_db_config *dbcfg, bool readonly)
        dbctx->cleanupdb                = db4_cleanupdb;
        dbctx->starttrans               = db4_starttrans;
        dbctx->endtrans                 = db4_endtrans;
-       dbctx->fetch_key_id             = db4_fetch_key_id;
+       dbctx->fetch_key                = db4_fetch_key;
        dbctx->fetch_key_fp             = db4_fetch_key_fp;
+       dbctx->fetch_key_id             = db4_fetch_key_id;
        dbctx->fetch_key_text           = db4_fetch_key_text;
        dbctx->fetch_key_skshash        = db4_fetch_key_skshash;
        dbctx->store_key                = db4_store_key;