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.
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);
{ 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
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
*/
#
-# 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
}
# 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