X-Git-Url: https://the.earth.li/gitweb/?a=blobdiff_plain;f=keydb_stacked.c;h=7e997d99d08cf784bc48e29e7f5d4f67fb502ebc;hb=dfab9e96ee1fa4a10acf9c1cf644d7a4366a5af6;hp=fdbccf34160bf0da8d3074f21e499be82239fc94;hpb=31cda851985140a3b6108fb51f1ef7f7f4aac9cd;p=onak.git
diff --git a/keydb_stacked.c b/keydb_stacked.c
index fdbccf3..7e997d9 100644
--- a/keydb_stacked.c
+++ b/keydb_stacked.c
@@ -13,26 +13,21 @@
* more details.
*
* You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * this program. If not, see .
*/
+#include
+#include
#include
+#include
#include
#include "cleankey.h"
-#include "decodekey.h"
-#include "hash.h"
#include "keydb.h"
-#include "keyid.h"
#include "keystructs.h"
+#include "ll.h"
#include "log.h"
-#include "mem.h"
-#include "merge.h"
#include "onak-conf.h"
-#include "openpgp.h"
-#include "parsekey.h"
-#include "sendsync.h"
struct onak_stacked_dbctx {
struct ll *backends;
@@ -76,7 +71,8 @@ static int stacked_store_key(struct onak_dbctx *dbctx,
publickey, intrans, update);
}
-static int stacked_delete_key(struct onak_dbctx *dbctx, uint64_t keyid,
+static int stacked_delete_key(struct onak_dbctx *dbctx,
+ struct openpgp_fingerprint *fp,
bool intrans)
{
struct onak_stacked_dbctx *privctx =
@@ -85,18 +81,22 @@ static int stacked_delete_key(struct onak_dbctx *dbctx, uint64_t keyid,
(struct onak_dbctx *) privctx->backends->object;
return backend->delete_key(backend,
- keyid, intrans);
+ fp, intrans);
}
static int stacked_update_keys(struct onak_dbctx *dbctx,
- struct openpgp_publickey **keys, bool sendsync)
+ struct openpgp_publickey **keys,
+ struct keyarray *blacklist,
+ bool updateonly,
+ bool sendsync)
{
struct onak_stacked_dbctx *privctx =
(struct onak_stacked_dbctx *) dbctx->priv;
struct onak_dbctx *backend =
(struct onak_dbctx *) privctx->backends->object;
- return backend->update_keys(backend, keys, sendsync);
+ return backend->update_keys(backend, keys, blacklist, updateonly,
+ sendsync);
}
static int stacked_iterate_keys(struct onak_dbctx *dbctx,
@@ -118,7 +118,7 @@ static void store_on_fallback(struct onak_stacked_dbctx *privctx,
(struct onak_dbctx *) privctx->backends->object;
struct openpgp_publickey *curkey;
- cleankeys(publickey);
+ cleankeys(&publickey, config.clean_policies);
/*
* If we walked the stack at all, store the key in the first
* backend if configured to do so. It's not an update as we
@@ -227,19 +227,29 @@ static int stacked_fetch_key_skshash(struct onak_dbctx *dbctx,
return res;
}
+/*
+ * Include the basic keydb routines so we can use them for fall back.
+ * For all of the following we try the top keydb backend and if that doesn't
+ * have answer fall back to the generics, which will do a retrieve from a
+ * backend further down the stack, then a fallback store.
+ */
+#define NEED_KEYID2UID 1
+#define NEED_GETKEYSIGS 1
+#define NEED_UPDATEKEYS 1
+#include "keydb.c"
+
static struct ll *stacked_getkeysigs(struct onak_dbctx *dbctx,
uint64_t keyid, bool *revoked)
{
struct onak_stacked_dbctx *privctx =
(struct onak_stacked_dbctx *) dbctx->priv;
- struct onak_dbctx *backend;
- struct ll *cur;
- struct ll *res = NULL;
+ struct onak_dbctx *backend =
+ (struct onak_dbctx *) privctx->backends->object;
+ struct ll *res;
- for (cur = privctx->backends; cur != NULL && res == NULL;
- cur = cur->next) {
- backend = (struct onak_dbctx *) cur->object;
- res = backend->getkeysigs(backend, keyid, revoked);
+ res = backend->getkeysigs(backend, keyid, revoked);
+ if (res == NULL) {
+ res = generic_getkeysigs(dbctx, keyid, revoked);
}
return res;
@@ -250,14 +260,13 @@ static struct ll *stacked_cached_getkeysigs(struct onak_dbctx *dbctx,
{
struct onak_stacked_dbctx *privctx =
(struct onak_stacked_dbctx *) dbctx->priv;
- struct onak_dbctx *backend;
- struct ll *cur;
- struct ll *res = NULL;
+ struct onak_dbctx *backend =
+ (struct onak_dbctx *) privctx->backends->object;
+ struct ll *res;
- for (cur = privctx->backends; cur != NULL && res == NULL;
- cur = cur->next) {
- backend = (struct onak_dbctx *) cur->object;
- res = backend->cached_getkeysigs(backend, keyid);
+ res = backend->cached_getkeysigs(backend, keyid);
+ if (res == NULL) {
+ res = generic_cached_getkeysigs(dbctx, keyid);
}
return res;
@@ -268,32 +277,13 @@ static char *stacked_keyid2uid(struct onak_dbctx *dbctx,
{
struct onak_stacked_dbctx *privctx =
(struct onak_stacked_dbctx *) dbctx->priv;
- struct onak_dbctx *backend;
- struct ll *cur;
+ struct onak_dbctx *backend =
+ (struct onak_dbctx *) privctx->backends->object;
char *res = NULL;
- for (cur = privctx->backends; cur != NULL && res == NULL;
- cur = cur->next) {
- backend = (struct onak_dbctx *) cur->object;
- res = backend->keyid2uid(backend, keyid);
- }
-
- return res;
-}
-
-static uint64_t stacked_getfullkeyid(struct onak_dbctx *dbctx,
- uint64_t keyid)
-{
- struct onak_stacked_dbctx *privctx =
- (struct onak_stacked_dbctx *) dbctx->priv;
- struct onak_dbctx *backend;
- struct ll *cur;
- uint64_t res = 0;
-
- for (cur = privctx->backends; cur != NULL && res == 0;
- cur = cur->next) {
- backend = (struct onak_dbctx *) cur->object;
- res = backend->getfullkeyid(backend, keyid);
+ res = backend->keyid2uid(backend, keyid);
+ if (!res) {
+ res = generic_keyid2uid(dbctx, keyid);
}
return res;
@@ -389,7 +379,6 @@ struct onak_dbctx *keydb_stacked_init(struct onak_db_config *dbcfg,
dbctx->getkeysigs = stacked_getkeysigs;
dbctx->cached_getkeysigs = stacked_cached_getkeysigs;
dbctx->keyid2uid = stacked_keyid2uid;
- dbctx->getfullkeyid = stacked_getfullkeyid;
dbctx->iterate_keys = stacked_iterate_keys;
}