commit a18ba0730061fee6a8e9b12d858bda8e5858c6fe
parent 4b14947042934228088a3eadbaa90f9394d807f9
Author: Christian Grothoff <christian@grothoff.org>
Date: Tue, 15 Apr 2025 16:05:42 +0200
fail if unknown measure is specified, fix escaping in KYC script
Diffstat:
3 files changed, 125 insertions(+), 112 deletions(-)
diff --git a/src/kyclogic/kyclogic_api.c b/src/kyclogic/kyclogic_api.c
@@ -548,6 +548,52 @@ check_measure (const struct TALER_KYCLOGIC_Measure *measure)
}
+/**
+ * Find measure @a measure_name in @a lrs.
+ * If measure is not found in @a lrs, fall back to
+ * default measures.
+ *
+ * @param lrs rule set to search, can be NULL to only search default measures
+ * @param measure_name name of measure to find
+ * @return NULL if not found, otherwise the measure
+ */
+static const struct TALER_KYCLOGIC_Measure *
+find_measure (
+ const struct TALER_KYCLOGIC_LegitimizationRuleSet *lrs,
+ const char *measure_name)
+{
+ if (NULL != lrs)
+ {
+ for (unsigned int i = 0; i<lrs->num_custom_measures; i++)
+ {
+ const struct TALER_KYCLOGIC_Measure *cm
+ = &lrs->custom_measures[i];
+
+ if (0 == strcasecmp (measure_name,
+ cm->measure_name))
+ return cm;
+ }
+ }
+ if (lrs != &default_rules)
+ {
+ /* Try measures from default rules */
+ for (unsigned int i = 0; i<default_rules.num_custom_measures; i++)
+ {
+ const struct TALER_KYCLOGIC_Measure *cm
+ = &default_rules.custom_measures[i];
+
+ if (0 == strcasecmp (measure_name,
+ cm->measure_name))
+ return cm;
+ }
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Measure `%s' not found\n",
+ measure_name);
+ return NULL;
+}
+
+
struct TALER_KYCLOGIC_LegitimizationRuleSet *
TALER_KYCLOGIC_rules_parse (const json_t *jlrs)
{
@@ -616,6 +662,73 @@ TALER_KYCLOGIC_rules_parse (const json_t *jlrs)
GNUNET_break (0);
goto cleanup;
}
+
+ if (0 != lrs->num_custom_measures)
+ {
+ lrs->custom_measures
+ = GNUNET_new_array (lrs->num_custom_measures,
+ struct TALER_KYCLOGIC_Measure);
+
+ {
+ const json_t *jmeasure;
+ const char *measure_name;
+ unsigned int off = 0;
+
+ json_object_foreach ((json_t *) jcustom_measures,
+ measure_name,
+ jmeasure)
+ {
+ const char *check_name;
+ const char *prog_name;
+ const json_t *context = NULL;
+ bool voluntary = false;
+ struct TALER_KYCLOGIC_Measure *measure
+ = &lrs->custom_measures[off++];
+ struct GNUNET_JSON_Specification ispec[] = {
+ GNUNET_JSON_spec_string ("check_name",
+ &check_name),
+ GNUNET_JSON_spec_string ("prog_name",
+ &prog_name),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_object_const ("context",
+ &context),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_bool ("voluntary",
+ &voluntary),
+ NULL),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (jmeasure,
+ ispec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ goto cleanup;
+ }
+ measure->measure_name
+ = GNUNET_strdup (measure_name);
+ measure->check_name
+ = GNUNET_strdup (check_name);
+ measure->prog_name
+ = GNUNET_strdup (prog_name);
+ measure->voluntary
+ = voluntary;
+ if (NULL != context)
+ measure->context
+ = json_incref ((json_t*) context);
+ if (! check_measure (measure))
+ {
+ GNUNET_break_op (0);
+ goto cleanup;
+ }
+ }
+ }
+ }
+
+
lrs->jlrs
= json_incref ((json_t *) jlrs);
lrs->kyc_rules
@@ -707,76 +820,22 @@ TALER_KYCLOGIC_rules_parse (const json_t *jlrs)
{
rule->verboten = true;
}
+ if (NULL ==
+ find_measure (lrs,
+ str))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Measure `%s' specified in rule set unknown\n",
+ str);
+ GNUNET_break_op (0);
+ goto cleanup;
+ }
rule->next_measures[j]
= GNUNET_strdup (str);
}
}
}
}
- if (0 != lrs->num_custom_measures)
- {
- lrs->custom_measures
- = GNUNET_new_array (lrs->num_custom_measures,
- struct TALER_KYCLOGIC_Measure);
-
- {
- const json_t *jmeasure;
- const char *measure_name;
- unsigned int off = 0;
-
- json_object_foreach ((json_t *) jcustom_measures,
- measure_name,
- jmeasure)
- {
- const char *check_name;
- const char *prog_name;
- const json_t *context = NULL;
- bool voluntary = false;
- struct TALER_KYCLOGIC_Measure *measure
- = &lrs->custom_measures[off++];
- struct GNUNET_JSON_Specification ispec[] = {
- GNUNET_JSON_spec_string ("check_name",
- &check_name),
- GNUNET_JSON_spec_string ("prog_name",
- &prog_name),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_object_const ("context",
- &context),
- NULL),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_bool ("voluntary",
- &voluntary),
- NULL),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (jmeasure,
- ispec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- goto cleanup;
- }
- measure->measure_name
- = GNUNET_strdup (measure_name);
- measure->check_name
- = GNUNET_strdup (check_name);
- measure->prog_name
- = GNUNET_strdup (prog_name);
- measure->voluntary
- = voluntary;
- if (NULL != context)
- measure->context
- = json_incref ((json_t*) context);
- if (! check_measure (measure))
- {
- GNUNET_break_op (0);
- goto cleanup;
- }
- }
- }
- }
return lrs;
cleanup:
TALER_KYCLOGIC_rules_free (lrs);
@@ -993,52 +1052,6 @@ TALER_KYCLOGIC_rules_to_limits (const json_t *jrules)
}
-/**
- * Find measure @a measure_name in @a lrs.
- * If measure is not found in @a lrs, fall back to
- * default measures.
- *
- * @param lrs rule set to search, can be NULL to only search default measures
- * @param measure_name name of measure to find
- * @return NULL if not found, otherwise the measure
- */
-static const struct TALER_KYCLOGIC_Measure *
-find_measure (
- const struct TALER_KYCLOGIC_LegitimizationRuleSet *lrs,
- const char *measure_name)
-{
- if (NULL != lrs)
- {
- for (unsigned int i = 0; i<lrs->num_custom_measures; i++)
- {
- const struct TALER_KYCLOGIC_Measure *cm
- = &lrs->custom_measures[i];
-
- if (0 == strcasecmp (measure_name,
- cm->measure_name))
- return cm;
- }
- }
- if (lrs != &default_rules)
- {
- /* Try measures from default rules */
- for (unsigned int i = 0; i<default_rules.num_custom_measures; i++)
- {
- const struct TALER_KYCLOGIC_Measure *cm
- = &default_rules.custom_measures[i];
-
- if (0 == strcasecmp (measure_name,
- cm->measure_name))
- return cm;
- }
- }
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Measure `%s' not found\n",
- measure_name);
- return NULL;
-}
-
-
const struct TALER_KYCLOGIC_Measure *
TALER_KYCLOGIC_rule_get_instant_measure (
const struct TALER_KYCLOGIC_KycRule *r)
diff --git a/src/kyclogic/taler-exchange-helper-measure-tops-3rdparty-check b/src/kyclogic/taler-exchange-helper-measure-tops-3rdparty-check
@@ -126,7 +126,7 @@ in
echo "Selected VQF form ${FORM}." 1>&2
# Force user to fill in $FORM
- NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] |= if (.rule_name=="deposit-limit-zero" or .measures[0] == "form-vqf-902.11") then .measures=["form-${FORM}"] else . end)')
+ NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] |= if (.rule_name=="deposit-limit-zero" or .measures[0] == "form-vqf-902.11") then .measures=["form-'${FORM}'"] else . end)')
INVESTIGATE="false"
;;
esac
diff --git a/src/kyclogic/taler-exchange-helper-measure-tops-kyx-check b/src/kyclogic/taler-exchange-helper-measure-tops-kyx-check
@@ -138,7 +138,7 @@ in
# Proceed to FORM.
echo "Selected VQF form ${FORM}." 1>&2
# Force user to fill in $FORM
- NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] |= if (.measures[0]=="kyx") then .measures=["form-${FORM}"] else . end)')
+ NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] |= if (.measures[0]=="kyx") then .measures=["form-'${FORM}'"] else . end)')
INVESTIGATE="false"
;;
esac