]> the.earth.li Git - onak.git/blobdiff - keydb/keydb_fs.c
0.6.3 release
[onak.git] / keydb / keydb_fs.c
index f8d55dc8233dd80a2b92e6878abee3719dc67cd0..921c97834da28f292d72cfcc1128ffb2f3c7e840 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "charfuncs.h"
 #include "decodekey.h"
+#include "key-store.h"
 #include "keydb.h"
 #include "keyid.h"
 #include "keystructs.h"
@@ -258,8 +259,9 @@ static int fs_fetch_key_id(struct onak_dbctx *dbctx,
              bool intrans)
 {
        static char buffer[PATH_MAX];
-       int ret = 0, fd;
+       int ret = 0;
        struct openpgp_packet_list *packets = NULL;
+       onak_status_t res;
 
        if (!intrans)
                fs_starttrans(dbctx);
@@ -268,20 +270,20 @@ static int fs_fetch_key_id(struct onak_dbctx *dbctx,
                keyid = fs_getfullkeyid(dbctx, keyid);
 
        keypath(buffer, sizeof(buffer), keyid, dbctx->config->location);
-       fd = open(buffer, O_RDONLY);
-       if (fd == -1 && errno == ENOENT) {
+       res = onak_read_openpgp_file(buffer,
+                                       &packets);
+       if (res == ONAK_E_NOT_FOUND) {
                subkeypath(buffer, sizeof(buffer), keyid,
                        dbctx->config->location);
-               fd = open(buffer, O_RDONLY);
+               res = onak_read_openpgp_file(buffer,
+                                       &packets);
        }
 
-       if (fd != -1) {
+       if (res == ONAK_E_OK) {
                /* File is present, load it in... */
-               read_openpgp_stream(file_fetchchar, &fd, &packets, 0);
                parse_keys(packets, publickey);
                free_packet_list(packets);
                packets = NULL;
-               close(fd);
                ret = 1;
        }
 
@@ -593,16 +595,16 @@ static int fs_fetch_key_skshash(struct onak_dbctx *dbctx,
              struct openpgp_publickey **publickey)
 {
        static char buffer[PATH_MAX];
-       int ret = 0, fd;
+       int ret = 0;
        struct openpgp_packet_list *packets = NULL;
+       onak_status_t res;
 
        skshashpath(buffer, sizeof(buffer), hash, dbctx->config->location);
-       if ((fd = open(buffer, O_RDONLY)) != -1) {
-               read_openpgp_stream(file_fetchchar, &fd, &packets, 0);
+       res = onak_read_openpgp_file(buffer, &packets);
+       if (res == ONAK_E_OK) {
                parse_keys(packets, publickey);
                free_packet_list(packets);
                packets = NULL;
-               close(fd);
                ret = 1;
        }
 
@@ -620,9 +622,10 @@ static int fs_fetch_key_skshash(struct onak_dbctx *dbctx,
  *
  *     Returns the number of keys we iterated over.
  */
-static int fs_iterate_keys(struct onak_dbctx *dbctx,
-               void (*iterfunc)(void *ctx,
-               struct openpgp_publickey *key), void *ctx)
+static int fs_iterate_keys(__unused struct onak_dbctx *dbctx,
+               __unused void (*iterfunc)(void *ctx,
+                       struct openpgp_publickey *key),
+               __unused void *ctx)
 {
        return 0;
 }
@@ -633,6 +636,7 @@ static int fs_iterate_keys(struct onak_dbctx *dbctx,
 #define NEED_KEYID2UID 1
 #define NEED_GETKEYSIGS 1
 #define NEED_UPDATEKEYS 1
+#define NEED_GET 1
 #define NEED_GET_FP 1
 #include "keydb.c"
 
@@ -709,8 +713,9 @@ struct onak_dbctx *keydb_fs_init(struct onak_db_config *dbcfg, bool readonly)
        dbctx->cleanupdb                = fs_cleanupdb;
        dbctx->starttrans               = fs_starttrans;
        dbctx->endtrans                 = fs_endtrans;
-       dbctx->fetch_key_id             = fs_fetch_key_id;
+       dbctx->fetch_key                = generic_fetch_key;
        dbctx->fetch_key_fp             = generic_fetch_key_fp;
+       dbctx->fetch_key_id             = fs_fetch_key_id;
        dbctx->fetch_key_text           = fs_fetch_key_text;
        dbctx->fetch_key_skshash        = fs_fetch_key_skshash;
        dbctx->store_key                = fs_store_key;