From: Alan T. DeKok Date: Fri, 25 Aug 2023 14:59:18 +0000 (-0400) Subject: remove test paircmp, and this paircmp_register_by_name X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94758898e0d68fe1b79e063a334785cd15496bca;p=thirdparty%2Ffreeradius-server.git remove test paircmp, and this paircmp_register_by_name --- diff --git a/src/lib/server/paircmp.c b/src/lib/server/paircmp.c index 74c90496e3d..e6ac3e5d7ad 100644 --- a/src/lib/server/paircmp.c +++ b/src/lib/server/paircmp.c @@ -663,56 +663,6 @@ int paircmp_find(fr_dict_attr_t const *da) return false; } -/** Register a function as compare function - * - * @param[in] name the attribute comparison to register. - * @param[in] from the attribute we want to compare with. - * Normally this is the same as attribute. - * If null call the comparison function on - * every attributes in the request if - * first_only is false. - * @param[in] first_only will decide if we loop over the request - * attributes or stop on the first one. - * @param[in] func comparison function. - * @param[in] instance argument to comparison function. - * @return - * - 0 on success - * - <0 on error - */ -int paircmp_register_by_name(char const *name, fr_dict_attr_t const *from, - bool first_only, fr_paircmp_func_t func, void *instance) -{ - fr_dict_attr_flags_t flags; - fr_dict_attr_t const *da; - - memset(&flags, 0, sizeof(flags)); - - da = fr_dict_attr_by_name(NULL, fr_dict_root(fr_dict_internal()), name); - if (da) { - if (paircmp_find(da)) { - fr_strerror_printf_push("Cannot register two comparions for attribute %s", - name); - return -1; - } - } else if (from) { - if (fr_dict_attr_add(fr_dict_unconst(fr_dict_internal()), fr_dict_root(fr_dict_internal()), - name, -1, from->type, &flags) < 0) { - fr_strerror_printf_push("Failed creating attribute '%s'", name); - return -1; - } - - da = fr_dict_attr_by_name(NULL, fr_dict_root(fr_dict_internal()), name); - if (!da) { - fr_strerror_printf("Failed finding attribute '%s'", name); - return -1; - } - - DEBUG("Creating attribute %s", name); - } - - return paircmp_register(da, from, first_only, func, instance); -} - /** Register a function as compare function. * * @param[in] da to register comparison function for. diff --git a/src/lib/server/paircmp.h b/src/lib/server/paircmp.h index 7e14e777666..9c6867f4390 100644 --- a/src/lib/server/paircmp.h +++ b/src/lib/server/paircmp.h @@ -45,9 +45,6 @@ int paircmp_virtual(request_t *request, fr_dict_attr_t const *da, fr_token_t op int paircmp_find(fr_dict_attr_t const *da); -int paircmp_register_by_name(char const *name, fr_dict_attr_t const *from, - bool first_only, fr_paircmp_func_t func, void *instance); - int paircmp_register(fr_dict_attr_t const *attribute, fr_dict_attr_t const *from, bool first_only, fr_paircmp_func_t func, void *instance); diff --git a/src/modules/rlm_test/rlm_test.c b/src/modules/rlm_test/rlm_test.c index f85765d7814..49c7042258b 100644 --- a/src/modules/rlm_test/rlm_test.c +++ b/src/modules/rlm_test/rlm_test.c @@ -193,16 +193,6 @@ fr_dict_attr_autoload_t rlm_test_dict_attr[] = { { NULL } }; -static int rlm_test_cmp(UNUSED void *instance, request_t *request, fr_pair_t const *check) -{ - fr_assert(check->vp_type == FR_TYPE_STRING); - - RINFO("Test-Paircmp called with \"%pV\"", &check->data); - - if (strcmp(check->vp_strvalue, "yes") == 0) return 0; - return 1; -} - /* * Find the named user in this modules database. Create the set * of attribute-value pairs to check and reply with for this user @@ -449,14 +439,6 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) rlm_test_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_test_t); xlat_t *xlat; - if (!cf_section_name2(mctx->inst->conf)) { - if (paircmp_register_by_name("Test-Paircmp", attr_user_name, false, - rlm_test_cmp, inst) < 0) { - PERROR("Failed registering \"Test-Paircmp\""); - return -1; - } - } - /* * Log some messages */ diff --git a/src/tests/keywords/if-paircmp b/src/tests/keywords/if-paircmp index 1a1ede5b405..f393690d95a 100644 --- a/src/tests/keywords/if-paircmp +++ b/src/tests/keywords/if-paircmp @@ -1,20 +1,11 @@ # -# PRE: update if +# PRE: update if paircmp # - -# -# Paircmp -# - -# -# Passing 'yes' causes the test paircmp to return match -# Passing 'no' causes the test paircmp to return a non-match -# -if (!(&Test-Paircmp == 'yes')) { +if (!(&Packet-Src-IP-Address == 127.0.0.1)) { test_fail } -if (&Test-Paircmp == 'no') { +if (&Packet-Src-IP-Address == 127.0.0.2) { test_fail } diff --git a/src/tests/keywords/paircmp b/src/tests/keywords/paircmp index 8c8cef0904d..451f6447f4b 100644 --- a/src/tests/keywords/paircmp +++ b/src/tests/keywords/paircmp @@ -2,26 +2,21 @@ # PRE: if update # update request { - &NAS-Identifier = "yes" + &NAS-IP-Address := 127.0.0.1 } # # test raw values # -if (&Test-Paircmp == 'yes') { - success - -} -else { +if !(&Packet-Src-IP-Address == 127.0.0.1) { test_fail } # # test inter-attribute comparisons # -if (&Test-Paircmp == &NAS-Identifier) { - success -} -else { +if !(&Packet-Src-IP-Address == &NAS-IP-Address) { test_fail } + +success