]> the.earth.li Git - onak.git/blobdiff - keydb/keydb_keyring.c
0.6.3 release
[onak.git] / keydb / keydb_keyring.c
index 9550434c612d5b027f3cf4a369b001d696d8e9fe..328aa737e796d7809d02560d27942f4c02cae78d 100644 (file)
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "build-config.h"
 #include "charfuncs.h"
 #include "keyarray.h"
 #include "keydb.h"
@@ -57,7 +58,7 @@ struct onak_keyring_dbctx {
  *
  *     This is just a no-op for keyring file access.
  */
-static bool keyring_starttrans(struct onak_dbctx *dbctx)
+static bool keyring_starttrans(__unused struct onak_dbctx *dbctx)
 {
        return true;
 }
@@ -67,7 +68,7 @@ static bool keyring_starttrans(struct onak_dbctx *dbctx)
  *
  *     This is just a no-op for keyring file access.
  */
-static void keyring_endtrans(struct onak_dbctx *dbctx)
+static void keyring_endtrans(__unused struct onak_dbctx *dbctx)
 {
        return;
 }
@@ -75,7 +76,7 @@ static void keyring_endtrans(struct onak_dbctx *dbctx)
 /**
  * keyring_fetch_key - fetch a key given its index
  */
-static int keyring_fetch_key(struct onak_keyring_dbctx *privctx,
+static int keyring_fetch_key_idx(struct onak_keyring_dbctx *privctx,
                unsigned int index,
                struct openpgp_publickey **publickey)
 {
@@ -97,10 +98,14 @@ static int keyring_fetch_key(struct onak_keyring_dbctx *privctx,
        return 1;
 }
 
-static int keyring_fetch_key_fp(struct onak_dbctx *dbctx,
+/*
+ * We only index the primary fingerprint of the key, so will only return one
+ * key at most from this function.
+ */
+static int keyring_fetch_key(struct onak_dbctx *dbctx,
                        struct openpgp_fingerprint *fingerprint,
                        struct openpgp_publickey **publickey,
-                       bool intrans)
+                       __unused bool intrans)
 {
        struct onak_keyring_dbctx *privctx =
                (struct onak_keyring_dbctx *) dbctx->priv;
@@ -112,7 +117,7 @@ static int keyring_fetch_key_fp(struct onak_dbctx *dbctx,
        }
 
        if (i < privctx->count) {
-               return keyring_fetch_key(privctx, i, publickey);
+               return keyring_fetch_key_idx(privctx, i, publickey);
        }
 
        return 0;
@@ -127,7 +132,7 @@ static int keyring_fetch_key_fp(struct onak_dbctx *dbctx,
 static int keyring_fetch_key_id(struct onak_dbctx *dbctx,
                uint64_t keyid,
                struct openpgp_publickey **publickey,
-               bool intrans)
+               __unused bool intrans)
 {
        struct onak_keyring_dbctx *privctx =
                (struct onak_keyring_dbctx *) dbctx->priv;
@@ -136,7 +141,7 @@ static int keyring_fetch_key_id(struct onak_dbctx *dbctx,
        count = 0;
        for (i = 0; i < privctx->count; i++) {
                if (fingerprint2keyid(&privctx->keys[i].fp) == keyid) {
-                       if (keyring_fetch_key(privctx, i, publickey))
+                       if (keyring_fetch_key_idx(privctx, i, publickey))
                                count++;
                }
        }
@@ -152,9 +157,10 @@ static int keyring_fetch_key_id(struct onak_dbctx *dbctx,
  *
  *     We don't support storing keys into a keyring file.
  */
-static int keyring_store_key(struct onak_dbctx *dbctx,
-               struct openpgp_publickey *publickey, bool intrans,
-               bool update)
+static int keyring_store_key(__unused struct onak_dbctx *dbctx,
+               __unused struct openpgp_publickey *publickey,
+               __unused bool intrans,
+               __unused bool update)
 {
        return 0;
 }
@@ -166,8 +172,8 @@ static int keyring_store_key(struct onak_dbctx *dbctx,
  *
  *     We don't support removing keys from a keyring file.
  */
-static int keyring_delete_key(struct onak_dbctx *dbctx,
-               struct openpgp_fingerprint *fp, bool intrans)
+static int keyring_delete_key(__unused struct onak_dbctx *dbctx,
+               __unused struct openpgp_fingerprint *fp, __unused bool intrans)
 {
        return 1;
 }
@@ -182,9 +188,9 @@ static int keyring_delete_key(struct onak_dbctx *dbctx,
  *
  *     TODO: Write for flat file access. Some sort of grep?
  */
-static int keyring_fetch_key_text(struct onak_dbctx *dbctx,
-               const char *search,
-               struct openpgp_publickey **publickey)
+static int keyring_fetch_key_text(__unused struct onak_dbctx *dbctx,
+               __unused const char *search,
+               __unused struct openpgp_publickey **publickey)
 {
        return 0;
 }
@@ -211,7 +217,7 @@ static int keyring_iterate_keys(struct onak_dbctx *dbctx,
 
        count = 0;
        for (i = 0; i < privctx->count; i++) {
-               if (keyring_fetch_key(privctx, i, &key)) {
+               if (keyring_fetch_key_idx(privctx, i, &key)) {
                        iterfunc(ctx, key);
                        free_publickey(key);
                        key = NULL;
@@ -221,11 +227,11 @@ static int keyring_iterate_keys(struct onak_dbctx *dbctx,
        return count;
 }
 
-static int keyring_update_keys(struct onak_dbctx *dbctx,
-               struct openpgp_publickey **keys,
-               struct keyarray *blacklist,
-               bool updateonly,
-               bool sendsync)
+static int keyring_update_keys(__unused struct onak_dbctx *dbctx,
+               __unused struct openpgp_publickey **keys,
+               __unused struct keyarray *blacklist,
+               __unused bool updateonly,
+               __unused bool sendsync)
 {
        return 0;
 }
@@ -327,7 +333,8 @@ static int keyring_parse_keys(struct onak_keyring_dbctx *privctx)
                                 * We need to fetch the key to calculate the
                                 * fingerprint.
                                 */
-                               keyring_fetch_key(privctx, privctx->count - 1,
+                               keyring_fetch_key_idx(privctx,
+                                               privctx->count - 1,
                                                &key);
                                get_fingerprint(key->publickey,
                                        &privctx->keys[privctx->count - 1].fp);
@@ -366,7 +373,7 @@ static void keyring_cleanupdb(struct onak_dbctx *dbctx)
        if (dbctx != NULL) {
                free(dbctx);
        }
-};
+}
 
 /**
  *     initdb - Initialize the key database.
@@ -374,7 +381,7 @@ static void keyring_cleanupdb(struct onak_dbctx *dbctx)
  *     This is just a no-op for flat file access.
  */
 struct onak_dbctx *keydb_keyring_init(struct onak_db_config *dbcfg,
-               bool readonly)
+               __unused bool readonly)
 {
        struct onak_keyring_dbctx *privctx;
        struct onak_dbctx *dbctx;
@@ -440,8 +447,10 @@ struct onak_dbctx *keydb_keyring_init(struct onak_db_config *dbcfg,
        dbctx->cleanupdb                = keyring_cleanupdb;
        dbctx->starttrans               = keyring_starttrans;
        dbctx->endtrans                 = keyring_endtrans;
+       dbctx->fetch_key                = keyring_fetch_key;
+       /* We don't index by subkey fingerprint, so fallback to fetch_key */
+       dbctx->fetch_key_fp             = keyring_fetch_key;
        dbctx->fetch_key_id             = keyring_fetch_key_id;
-       dbctx->fetch_key_fp             = keyring_fetch_key_fp;
        dbctx->fetch_key_text           = keyring_fetch_key_text;
        dbctx->store_key                = keyring_store_key;
        dbctx->update_keys              = keyring_update_keys;