]> the.earth.li Git - onak.git/commitdiff
Use a set of policy flags to indicate what key cleaning to perform
authorJonathan McDowell <noodles@earth.li>
Tue, 9 Apr 2019 18:53:54 +0000 (19:53 +0100)
committerJonathan McDowell <noodles@earth.li>
Tue, 9 Apr 2019 18:53:54 +0000 (19:53 +0100)
To decouple cleankeys.c from the keyserver config, and prepare for an
extension of the policies available, use a set of flags to indicate what
key cleaning to perform.

add.c
cleankey.c
cleankey.h
keydb_stacked.c
lookup.c
onak-conf.c
onak-conf.h
onak.c
stripkey.c

diff --git a/add.c b/add.c
index 48dccf09cde79bb7165eee81fd949ae167dc01b8..c3a54a7295601947fc46b8277dbaa4731e324901 100644 (file)
--- a/add.c
+++ b/add.c
@@ -88,7 +88,7 @@ int main(int argc, char *argv[])
                        catchsignals();
                        dbctx = config.dbinit(config.backend, false);
                        
-                       count = cleankeys(keys);
+                       count = cleankeys(&keys, config.clean_policies);
                        logthing(LOGTHING_INFO, "%d keys cleaned.",
                                        count);
 
index afe5a06a82b7cb2aacf53c18e4d06cfebc03f7e0..3ef76f9167679b61316f03f817fd81816ac7437c 100644 (file)
@@ -181,26 +181,33 @@ int clean_key_sighashes(struct openpgp_publickey *key)
 
 /**
  *     cleankeys - Apply all available cleaning options on a list of keys.
- *     @keys: The list of keys to clean.
+ *     @policies: The cleaning policies to apply.
  *
- *     Applies all the cleaning options we can (eg duplicate key ids) to a
- *     list of keys. Returns 0 if no changes were made, otherwise the number
- *     of keys cleaned.
+ *     Applies the requested cleaning policies to a list of keys. These are
+ *     specified from the ONAK_CLEAN_* set of flags, or ONAK_CLEAN_ALL to
+ *     apply all available cleaning options. Returns 0 if no changes were
+ *     made, otherwise the number of keys cleaned. Note that some options
+ *     may result in keys being removed entirely from the list.
  */
-int cleankeys(struct openpgp_publickey *keys)
+int cleankeys(struct openpgp_publickey **keys, uint64_t policies)
 {
+       struct openpgp_publickey *curkey;
        int changed = 0, count;
 
-       while (keys != NULL) {
-               count = dedupuids(keys);
-               count += dedupsubkeys(keys);
-               if (config.check_sighash) {
-                       count += clean_key_sighashes(keys);
+       if (keys == NULL)
+               return 0;
+
+       curkey = *keys;
+       while (curkey != NULL) {
+               count = dedupuids(curkey);
+               count += dedupsubkeys(curkey);
+               if (policies & ONAK_CLEAN_CHECK_SIGHASH) {
+                       count += clean_key_sighashes(curkey);
                }
                if (count > 0) {
                        changed++;
                }
-               keys = keys->next;
+               curkey = curkey->next;
        }
 
        return changed;
index 454dd4cd6c13ade22bc97a0c36c258e99a78d585..073ef666000af646d7d145296a51fda94f367fda 100644 (file)
 
 #include "keystructs.h"
 
+#define ONAK_CLEAN_CHECK_SIGHASH       (1 << 0)
+#define ONAK_CLEAN_ALL                 (uint64_t) -1
+
 /**
  *     cleankeys - Apply all available cleaning options on a list of keys.
  *     @publickey: The list of keys to clean.
+ *     @policies: The cleaning policies to apply.
  *
- *     Applies all the cleaning options we can (eg duplicate key ids) to a
- *     list of keys. Returns 0 if no changes were made, otherwise the number
- *     of keys cleaned.
+ *     Applies the requested cleaning policies to a list of keys. These are
+ *     specified from the ONAK_CLEAN_* set of flags, or ONAK_CLEAN_ALL to
+ *     apply all available cleaning options. Returns 0 if no changes were
+ *     made, otherwise the number of keys cleaned. Note that some options
+ *     may result in keys being removed entirely from the list.
  */
-int cleankeys(struct openpgp_publickey *keys);
+int cleankeys(struct openpgp_publickey **keys, uint64_t policies);
 
 #endif
index 06ee7098bb08f6d58a90f90e69e878296a9eb77f..59c988da9172f0cd862df64a251fde0fc03541a0 100644 (file)
@@ -113,7 +113,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
index fda1686234f06160dfd7af7be1819c441fcf2bc2..c9f94a9e8579c51c187659cecb08f36a742a86a3 100644 (file)
--- a/lookup.c
+++ b/lookup.c
@@ -239,7 +239,7 @@ int main(int argc, char *argv[])
                                        result,
                                        search);
                                puts("<pre>");
-                               cleankeys(publickey);
+                               cleankeys(&publickey, config.clean_policies);
                                flatten_publickey(publickey,
                                                        &packets,
                                                        &list_end);
index e4f0bc75312f1b5f4c65cbfbbf1ab27c7868f25d..e6b645c48057bf4bf10fb4143ebcd82f87a1dc14 100644 (file)
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <strings.h>
 
+#include "cleankey.h"
 #include "ll.h"
 #include "log.h"
 #include "onak-conf.h"
@@ -52,7 +53,7 @@ struct onak_config config = {
 
        .dbinit = DBINIT,
 
-       .check_sighash = true,
+       .clean_policies = ONAK_CLEAN_CHECK_SIGHASH,
 
        .bin_dir = NULL,
        .mail_dir = NULL,
@@ -169,8 +170,14 @@ static bool parseoldconfigline(char *line)
        } else if (!strncmp("sock_dir ", line, 9)) {
                config.sock_dir = strdup(&line[9]);
        } else if (!strncmp("check_sighash ", line, 9)) {
-               config.check_sighash = parsebool(&line[9],
-                                       config.check_sighash);
+               if (parsebool(&line[9], config.clean_policies &
+                                       ONAK_CLEAN_CHECK_SIGHASH)) {
+                       config.clean_policies |=
+                               ONAK_CLEAN_CHECK_SIGHASH;
+               } else {
+                       config.clean_policies &=
+                               ~ONAK_CLEAN_CHECK_SIGHASH;
+               }
        } else {
                return false;
        }
@@ -273,8 +280,14 @@ static bool parseconfigline(char *line)
                                strdup(value));
                /* [verification] section */
                } else if (MATCH("verification", "check_sighash")) {
-                       config.check_sighash = parsebool(value,
-                                       config.check_sighash);
+                       if (parsebool(value, config.clean_policies &
+                                       ONAK_CLEAN_CHECK_SIGHASH)) {
+                               config.clean_policies |=
+                                       ONAK_CLEAN_CHECK_SIGHASH;
+                       } else {
+                               config.clean_policies &=
+                                       ~ONAK_CLEAN_CHECK_SIGHASH;
+                       }
                } else {
                        return false;
                }
@@ -448,7 +461,8 @@ void writeconfig(const char *configfile)
        fprintf(conffile, "\n");
 
        fprintf(conffile, "[verification]\n");
-       WRITE_BOOL(config.check_sighash, "check_sighash");
+       WRITE_BOOL(config.clean_policies & ONAK_CLEAN_CHECK_SIGHASH,
+                       "check_sighash");
        fprintf(conffile, "\n");
 
        fprintf(conffile, "[mail]\n");
index 6d7500aab096fc08fb86c02b2fdbe193d97c543d..3e02b7a0226769bacc240e47db3972a7e42d7aca 100644 (file)
@@ -21,6 +21,7 @@
 #define __ONAK_CONF_H_
 
 #include <stdbool.h>
+#include <stdint.h>
 
 #include "ll.h"
 
@@ -88,8 +89,8 @@ struct onak_config {
        /** Pointer to the initialisation function for our loaded DB backend */
        struct onak_dbctx *(*dbinit)(struct onak_db_config *, bool);
 
-       /** Should we verify signature hashes match? */
-       bool check_sighash;
+       /** What policies should we use for cleaning keys? */
+       uint64_t clean_policies;
 
        /*
         * Options used by the email handling script.
diff --git a/onak.c b/onak.c
index 89c2ec7ba04e5f779ef87c56863b1dd3d919b622..085a876c54c9dac6ceb1d4f22bbb8ec2fcff8f91 100644 (file)
--- a/onak.c
+++ b/onak.c
@@ -233,7 +233,7 @@ int main(int argc, char *argv[])
                        logthing(LOGTHING_INFO, "Finished reading %d keys.",
                                        result);
 
-                       result = cleankeys(keys);
+                       result = cleankeys(&keys, config.clean_policies);
                        logthing(LOGTHING_INFO, "%d keys cleaned.",
                                        result);
 
@@ -288,7 +288,8 @@ int main(int argc, char *argv[])
                                        result);
 
                        if (keys != NULL) {
-                               result = cleankeys(keys);
+                               result = cleankeys(&keys,
+                                               config.clean_policies);
                                logthing(LOGTHING_INFO, "%d keys cleaned.",
                                                result);
 
@@ -436,7 +437,7 @@ int main(int argc, char *argv[])
                        dbctx->starttrans(dbctx);
                        if (dbctx->fetch_key_id(dbctx, keyid, &keys, true)) {
                                dbctx->delete_key(dbctx, keyid, true);
-                               cleankeys(keys);
+                               cleankeys(&keys, config.clean_policies);
                                dbctx->store_key(dbctx, keys, true, false);
                        } else {
                                puts("Key not found");
index f845f346c8549cadb51978607e3240ce5e449854..5579236cdedb143faf0deeed22d2a5e8289d8d9b 100644 (file)
@@ -49,7 +49,7 @@ int main(int argc, char** argv) {
   parse_keys( packets, &keys );
   free_packet_list(packets);
   packets = NULL;
-  cleankeys( keys );
+  cleankeys(&keys, ONAK_CLEAN_ALL);
   /* Iterate over the keys... */
   for( key = keys; key; key = key->next ) {
     uint64_t keyid;