]> the.earth.li Git - onak.git/blobdiff - keydb.c
Add test for blacklisting functionality
[onak.git] / keydb.c
diff --git a/keydb.c b/keydb.c
index 30a77caf61f912ddf5142aff5669b8d1be2844cc..f6b9682f2d4b4ade0db0494fbf4c4b312a80171e 100644 (file)
--- a/keydb.c
+++ b/keydb.c
@@ -159,6 +159,8 @@ struct ll *generic_cached_getkeysigs(struct onak_dbctx *dbctx, uint64_t keyid)
 /**
  *     update_keys - Takes a list of public keys and updates them in the DB.
  *     @keys: The keys to update in the DB.
+ *     @blacklist: A keyarray of key fingerprints not to accept.
+ *     @updateonly: Only update existing keys, don't add new ones.
  *     @sendsync: Should we send a sync mail to our peers.
  *
  *     Takes a list of keys and adds them to the database, merging them with
@@ -168,24 +170,38 @@ struct ll *generic_cached_getkeysigs(struct onak_dbctx *dbctx, uint64_t keyid)
  *     the DB). Returns the number of entirely new keys added.
  */
 int generic_update_keys(struct onak_dbctx *dbctx,
-               struct openpgp_publickey **keys, bool sendsync)
+               struct openpgp_publickey **keys,
+               struct keyarray *blacklist,
+               bool updateonly,
+               bool sendsync)
 {
        struct openpgp_publickey **curkey, *tmp = NULL;
        struct openpgp_publickey *oldkey = NULL;
        struct openpgp_fingerprint fp;
-       int newkeys = 0;
+       int newkeys = 0, ret;
        bool intrans;
 
        curkey = keys;
        while (*curkey != NULL) {
                get_fingerprint((*curkey)->publickey, &fp);
+               if (blacklist && array_find(blacklist, &fp)) {
+                       logthing(LOGTHING_INFO, "Ignoring blacklisted key.");
+                       tmp = *curkey;
+                       *curkey = (*curkey)->next;
+                       tmp->next = NULL;
+                       free_publickey(tmp);
+                       continue;
+               }
 
                intrans = dbctx->starttrans(dbctx);
 
-               logthing(LOGTHING_INFO,
-                       "Fetching key, result: %d",
-                       dbctx->fetch_key_fp(dbctx, &fp, &oldkey,
-                                       intrans));
+               ret = dbctx->fetch_key_fp(dbctx, &fp, &oldkey, intrans);
+               if (ret == 0 && updateonly) {
+                       logthing(LOGTHING_INFO,
+                               "Skipping new key as update only set.");
+                       curkey = &(*curkey)->next;
+                       goto next;
+               }
 
                /*
                 * If we already have the key stored in the DB then merge it
@@ -218,6 +234,7 @@ int generic_update_keys(struct onak_dbctx *dbctx,
                        newkeys++;
                        curkey = &(*curkey)->next;
                }
+next:
                dbctx->endtrans(dbctx);
        }