]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Deprecate and no-op the incidences module
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 15 May 2025 22:56:47 +0000 (16:56 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 15 May 2025 22:56:47 +0000 (16:56 -0600)
The few almost useful incidences left were workarounds for the old
cache implementation.

src/Makefile.am
src/algorithm.c
src/config/incidences.c
src/file.h
src/incidence.c [deleted file]
src/incidence.h [deleted file]
src/log.c
src/log.h
src/main.c
src/object/manifest.c
test/mock.c

index 548584a4f3f991737822d4701657c7953b2a4719..f67795784332234b6de501083a169ce1c7657a9e 100644 (file)
@@ -31,7 +31,6 @@ fort_SOURCES += ext.h ext.c
 fort_SOURCES += file.h file.c
 fort_SOURCES += hash.h hash.c
 fort_SOURCES += http.h http.c
-fort_SOURCES += incidence.h incidence.c
 fort_SOURCES += init.h init.c
 fort_SOURCES += json_handler.h json_handler.c
 fort_SOURCES += json_util.c json_util.h
index cf400c60df0e927350e6939799a407eb05effd18..d402d02be4e89fc2e5b99a07a2d0f4f7e5d3dbfd 100644 (file)
@@ -109,18 +109,11 @@ validate_cms_hash_algorithm(AlgorithmIdentifier_t *id, char const *what)
         * some implementations encode parameters as a NULL element
         * while others omit them entirely.  The correct encoding is to omit the
         * parameters field;
-        *
-        * We will treat NULL object parameters as one type of error, and any
-        * other type of present parameters as a different error. The former
-        * will be silenceable, because many people are breaking the rule.
         */
        if (id->parameters != NULL) {
                error = is_asn1_null_object(id->parameters)
-                   ? incidence(INID_HASHALG_HAS_PARAMS,
-                       "The hash algorithm of the '%s' has a NULL object as parameters",
-                       what)
-                   : pr_val_err("The hash algorithm of the '%s' has parameters",
-                       what);
+                   ? pr_val_err("The hash algorithm of the '%s' has a NULL object as parameters", what)
+                   : pr_val_err("The hash algorithm of the '%s' has parameters", what);
        }
 
        return error;
index 7d20fe07e357cc3021a5bccd047904c8e130484d..ae0d3ee7176744cf80f8a62cf19f2a3d5d2f2214 100644 (file)
@@ -1,18 +1,19 @@
 #include "config/incidences.h"
 
-#include "incidence.h"
+#include "log.h"
 
 static void
 incidences_print(struct option_field const *field, void *_value)
 {
-       incidence_print();
+       /* Empty */
 }
 
 static int
 incidences_parse_json(struct option_field const *opt, json_t *json,
     void *_result)
 {
-       return incidence_update(json);
+       pr_op_warn("Incidences are deprecated; please delete them from your configuration.");
+       return 0;
 }
 
 const struct global_type gt_incidences = {
index e96012dc5f0a135fbfab415d3fbe180fb1700147..013779b22dd41ed765602349dd215f143bd1221d 100644 (file)
@@ -44,7 +44,7 @@ struct cache_sequence {
        char *prefix;
        unsigned long next_id;
        size_t pathlen;
-       bool free_prefix; // XXX seems to be always false
+       bool free_prefix;
 };
 
 void cseq_init(struct cache_sequence *, char *, unsigned long, bool);
diff --git a/src/incidence.c b/src/incidence.c
deleted file mode 100644 (file)
index b9a35b2..0000000
+++ /dev/null
@@ -1,177 +0,0 @@
-#include "incidence.h"
-
-#include <assert.h>
-
-#include "json_util.h"
-#include "log.h"
-#include "types/array.h"
-
-struct incidence {
-       const enum incidence_id id;
-       char const *const name;
-       char const *const description;
-       const enum incidence_action default_action;
-       enum incidence_action action;
-};
-
-static struct incidence incidences[__INID_MAX] = {
-       {
-               INID_HASHALG_HAS_PARAMS,
-               "incid-hashalg-has-params",
-               "Signed Object's hash algorithm has NULL object as parameters",
-               INAC_IGNORE,
-       },
-       {
-               INID_OBJ_NOT_DER,
-               "incid-obj-not-der-encoded",
-               "Object isn't DER encoded",
-               INAC_IGNORE,
-       },
-       {
-               INID_MFT_FILE_NOT_FOUND,
-               "incid-file-at-mft-not-found",
-               "File listed at manifest doesn't exist",
-               INAC_ERROR,
-       },
-       {
-               INID_MFT_FILE_HASH_NOT_MATCH,
-               "incid-file-at-mft-hash-not-match",
-               "File hash listed at manifest doesn't match the actual file hash",
-               INAC_ERROR,
-       },
-       {
-               INID_MFT_STALE,
-               "incid-mft-stale",
-               "The current time is after the nextUpdate field at the manifest",
-               INAC_ERROR,
-       },
-};
-
-static int
-name2id(char const *name, enum incidence_id *id)
-{
-       array_index i;
-
-       for (i = 0; i < __INID_MAX; i++) {
-               if (strcmp(name, incidences[i].name) == 0) {
-                       *id = i;
-                       return 0;
-               }
-       }
-
-       return pr_op_err("Unknown incidence name: %s", name);
-}
-
-static char const *
-action2str(enum incidence_action action)
-{
-       switch (action) {
-       case INAC_IGNORE:
-               return "ignore";
-       case INAC_WARN:
-               return "warn";
-       case INAC_ERROR:
-               return "error";
-       }
-
-       return "unknown";
-}
-
-static int
-init_action(json_t *json)
-{
-       enum incidence_id id;
-       char const *name;
-       char const *action_str;
-       enum incidence_action action;
-       int error;
-
-       id = __INID_MAX;
-       error = json_get_str(json, "name", &name);
-       if (error < 0)
-               return error;
-       if (error > 0)
-               return pr_op_err("Incidence is missing the 'name' tag.");
-       error = name2id(name, &id);
-       if (error)
-               return error;
-       error = json_get_str(json, "action", &action_str);
-       if (error < 0)
-               return error;
-       if (error > 0)
-               return pr_op_err("Incidence '%s' is missing the 'action' tag.",
-                   name);
-
-       if (strcmp("ignore", action_str) == 0)
-               action = INAC_IGNORE;
-       else if (strcmp("warn", action_str) == 0)
-               action = INAC_WARN;
-       else if (strcmp("error", action_str) == 0)
-               action = INAC_ERROR;
-       else
-               return pr_op_err("Unknown incidence action: '%s'", action_str);
-
-       incidences[id].action = action;
-       return 0;
-}
-
-/**
- * Concurrent inits are allowed.
- */
-int
-incidence_init(void)
-{
-       array_index i;
-
-       /* Make sure the programmer didn't desync the id enum and the array. */
-       assert(__INID_MAX == ARRAY_LEN(incidences));
-       for (i = 0; i < __INID_MAX; i++) {
-               assert(i == incidences[i].id);
-               /* Also init. */
-               incidences[i].action = incidences[i].default_action;
-       }
-
-       return 0;
-}
-
-/**
- * Concurrent calls to this function are allowed.
- */
-int
-incidence_update(json_t *json)
-{
-       array_index i;
-       json_t *child;
-       int error;
-
-       if (!json_is_array(json))
-               return pr_op_err("The incidences JSON element is supposed to be an array.");
-
-       json_array_foreach(json, i, child) {
-               error = init_action(child);
-               if (error)
-                       return error;
-       }
-
-       return 0;
-}
-
-void
-incidence_print(void)
-{
-       array_index i;
-
-       pr_op_info("Custom incidences:");
-
-       for (i = 0; i < __INID_MAX; i++) {
-               pr_op_info("  %s (%s): %s", incidences[i].name,
-                   incidences[i].description,
-                   action2str(incidences[i].action));
-       }
-}
-
-enum incidence_action
-incidence_get_action(enum incidence_id id)
-{
-       return incidences[id].action;
-}
diff --git a/src/incidence.h b/src/incidence.h
deleted file mode 100644 (file)
index f0170ae..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-#ifndef SRC_INCIDENCE_INCIDENCE_H_
-#define SRC_INCIDENCE_INCIDENCE_H_
-
-#include <jansson.h>
-
-/*
- * Note: If you need to add, modify or delete an element from this enum,
- * remember that you also need to add it to the incidences array. That's all.
- */
-enum incidence_id {
-       INID_HASHALG_HAS_PARAMS,
-       INID_OBJ_NOT_DER,
-       INID_MFT_FILE_NOT_FOUND, // XXX deprecate and no-op
-       INID_MFT_FILE_HASH_NOT_MATCH, // XXX deprecate and no-op
-       INID_MFT_STALE,
-       // XXX Document elimination of INID_CRL_STALE
-
-       __INID_MAX,
-};
-
-enum incidence_action {
-       /**
-        * Do not print error message, continue validation as if nothing
-        * happened.
-        */
-       INAC_IGNORE,
-       /**
-        * Print error message in warning log level, continue validation as if
-        * nothing happened.
-        */
-       INAC_WARN,
-       /**
-        * Print error message in error log level, fail validation of the
-        * offending object (and all of its children).
-        */
-       INAC_ERROR,
-};
-
-int incidence_init(void); /* incidence_destroy() is not needed. */
-int incidence_update(json_t *);
-
-void incidence_print(void);
-enum incidence_action incidence_get_action(enum incidence_id);
-
-#endif /* SRC_INCIDENCE_INCIDENCE_H_ */
index 8a8f02dd0eec7c920aeaa81bff36515f49a0afcf..9c3c86794096d05da78fd9a261e5485ff0b65e74 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -569,27 +569,3 @@ pr_crit(const char *format, ...)
        print_stack_trace(NULL);
        exit(-1);
 }
-
-/**
- * Prints the [format, ...] error message using the configured logging severity
- * of the @id incidence.
- */
-int
-incidence(enum incidence_id id, const char *format, ...)
-{
-       enum incidence_action action;
-
-       action = incidence_get_action(id);
-       switch (action) {
-       case INAC_IGNORE:
-               return 0;
-       case INAC_WARN:
-               PR_SIMPLE(LOG_WARNING, val_config);
-               return 0;
-       case INAC_ERROR:
-               PR_SIMPLE(LOG_ERR, val_config);
-               return EINVAL;
-       }
-
-       pr_crit("Unknown incidence action: %u", action);
-}
index 453899d2a29fb05fc94f027e4ad6f22a1b9fdabf..d6fa4340630fec44bd43dc7e1680655db0eb4556 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -4,8 +4,6 @@
 #include <stdbool.h>
 #include <stdio.h>
 
-#include "incidence.h"
-
 #define PR_COLOR_DBG   "\x1B[36m"      /* Cyan */
 #define PR_COLOR_INF   "\x1B[37m"      /* White */
 #define PR_COLOR_WRN   "\x1B[33m"      /* Yellow */
@@ -105,8 +103,6 @@ __dead void enomem_panic(void);
 /* Programming errors */
 __dead void pr_crit(const char *, ...) CHECK_FORMAT(1, 2);
 
-int incidence(enum incidence_id, const char *, ...) CHECK_FORMAT(2, 3);
-
 /*
  * Quick and dirty debugging messages.
  *
index 11b0bb19aa356b52e8a8a3baa996c240fc385bf8..d81751cca25977530d4547a08f38b14676b9c203 100644 (file)
@@ -132,9 +132,6 @@ main(int argc, char **argv)
        register_signal_handlers();
 
        error = thvar_init();
-       if (error)
-               goto revert_rsync;
-       error = incidence_init();
        if (error)
                goto revert_rsync;
        error = nid_init();
index 87fe274fa02ee4a7df907f9c7071f6015f9ab14c..1eb9bbadf67b4702f04779dde2d33f3c342dba31 100644 (file)
@@ -94,8 +94,7 @@ validate_dates(GeneralizedTime_t *this, GeneralizedTime_t *next,
                    TM_ARGS(thisUpdate));
        }
        if (tm_cmp(&now, &nextUpdate) > 0) {
-               return incidence(INID_MFT_STALE,
-                   "Manifest is stale. (nextUpdate: " TM_FMT ")",
+               return pr_val_err("Manifest is stale. (nextUpdate: " TM_FMT ")",
                    TM_ARGS(nextUpdate));
        }
 
index bc881cba002bb2255fde354512133fbac61b3d38..47c3c8a90fad25df0a1fbe72e49db39420adbedf 100644 (file)
@@ -4,7 +4,6 @@
 #include <arpa/inet.h>
 #include <time.h>
 #include "config.h"
-#include "incidence.h"
 #include "log.h"
 #include "thread_var.h"
 
@@ -64,13 +63,6 @@ MOCK_INT_PRINT(pr_val_warn, PR_COLOR_WRN, 0)
 MOCK_INT_PRINT(pr_val_err, PR_COLOR_ERR, EINVAL)
 MOCK_INT_PRINT(val_crypto_err, PR_COLOR_ERR, EINVAL)
 
-int
-incidence(enum incidence_id id, const char *format, ...)
-{
-       MOCK_PRINT(PR_COLOR_ERR);
-       return EINVAL;
-}
-
 void
 enomem_panic(void)
 {