#include <ctype.h>
#include <fcntl.h>
+#include <freeradius-devel/server/main_config.h>
+
bool check_config = false;
static uid_t conf_check_uid = (uid_t)-1;
static gid_t conf_check_gid = (gid_t)-1;
static int cf_file_fill(cf_stack_t *stack);
-#ifdef WITH_XLAT_COND
static const fr_sbuff_term_t if_terminals = FR_SBUFF_TERMS(
L(""),
L("{"),
);
-#endif
static uint8_t const *skip_string(uint8_t const *p, char c)
{
CONF_SECTION *parent = frame->current;
char *buff[4];
tmpl_rules_t t_rules;
-#ifdef WITH_XLAT_COND
xlat_exp_head_t *head = NULL;
fr_sbuff_parse_rules_t p_rules = { };
p_rules.terminals = &if_terminals;
-#endif
/*
* Short names are nicer.
ptr = buff[3];
slen = my_slen;
-#ifdef WITH_XLAT_COND
parse_error:
-#endif
fr_canonicalize_error(cs, &spaces, &text, slen, ptr);
cf_log_err(cs, "Parse error in condition");
return NULL;
}
-#ifdef WITH_XLAT_COND
- my_slen = xlat_tokenize_condition(cs, &head, &FR_SBUFF_IN(buff[3], strlen(buff[3])), &p_rules, &t_rules);
- if (my_slen <= 0) {
- ptr = buff[3];
- slen = my_slen;
- goto parse_error;
+ if (main_config->parse_new_conditions) {
+ my_slen = xlat_tokenize_condition(cs, &head, &FR_SBUFF_IN(buff[3], strlen(buff[3])), &p_rules, &t_rules);
+ if (my_slen <= 0) {
+ ptr = buff[3];
+ slen = my_slen;
+ goto parse_error;
+ }
}
-#endif
}
MEM(cs->name2 = talloc_typed_strdup(cs, buff[2]));
* the condition to the CONF_SECTION.
*/
cf_data_add(cs, cond, NULL, true);
-#ifdef WITH_XLAT_COND
cf_data_add(cs, head, NULL, true);
-#endif
stack->ptr = ptr;
cs->allow_unlang = true;
#include "switch_priv.h"
#include "edit_priv.h"
-
#define UNLANG_IGNORE ((unlang_t *) -1)
static unsigned int unlang_number = 1;
unlang_cond_t *gext;
fr_cond_t *cond;
-#ifdef WITH_XLAT_COND
xlat_exp_head_t *head;
bool is_truthy, value;
xlat_res_rules_t xr_rules = {
.dict_def = unlang_ctx->rules->attr.dict_def,
},
};
-#endif
if (!cf_section_name2(cs)) {
cf_log_err(cs, "'%s' without condition", unlang_ops[ext->type].name);
cond = cf_data_value(cf_data_find(cs, fr_cond_t, NULL));
fr_assert(cond != NULL);
-#ifdef WITH_XLAT_COND
- head = cf_data_value(cf_data_find(cs, xlat_exp_head_t, NULL));
- fr_assert(head != NULL);
-
/*
- * Resolve the xlat first.
+ * Migration support.
*/
- if (xlat_resolve(head, &xr_rules) < 0) {
- cf_log_err(cs, "Failed resolving condition - %s", fr_strerror());
- return NULL;
- }
+ if (main_config->parse_new_conditions) {
+ head = cf_data_value(cf_data_find(cs, xlat_exp_head_t, NULL));
+ fr_assert(head != NULL);
- is_truthy = xlat_is_truthy(head, &value);
-#endif
+ /*
+ * Resolve the xlat first.
+ */
+ if (xlat_resolve(head, &xr_rules) < 0) {
+ cf_log_err(cs, "Failed resolving condition - %s", fr_strerror());
+ return NULL;
+ }
+
+ is_truthy = xlat_is_truthy(head, &value);
+ }
+ /*
+ * We still do some resolving of old-style conditions,
+ * and skipping of sections.
+ */
if (cond->type == COND_TYPE_FALSE) {
cf_log_debug_prefix(cs, "Skipping contents of '%s' as it is always 'false'",
unlang_ops[ext->type].name);
gext = unlang_group_to_cond(g);
gext->cond = cond;
-#ifdef WITH_XLAT_COND
gext->head = head;
gext->is_truthy = is_truthy;
gext->value = value;
-#endif
return c;
}
#include "condition_priv.h"
#include "group_priv.h"
-#ifdef WITH_XLAT_COND
typedef struct {
fr_value_box_list_t out; //!< Head of the result of a nested
///< expansion.
*/
return unlang_group(p_result, request, frame);
}
-#endif
static unlang_action_t unlang_if(rlm_rcode_t *p_result, request_t *request, unlang_stack_frame_t *frame)
{
unlang_group_t *g = unlang_generic_to_group(frame->instruction);
unlang_cond_t *gext = unlang_group_to_cond(g);
-#ifdef WITH_XLAT_COND
unlang_frame_state_cond_t *state = talloc_get_type_abort(frame->state, unlang_frame_state_cond_t);
-#endif
fr_assert(gext->cond != NULL);
-#ifndef WITH_XLAT_COND
- if (!cond_eval(request, *p_result, gext->cond)) {
- RDEBUG2("...");
- return UNLANG_ACTION_EXECUTE_NEXT;
+ /*
+ * Migration support.
+ */
+ if (!main_config->use_new_conditions) {
+ if (!cond_eval(request, *p_result, gext->cond)) {
+ RDEBUG2("...");
+ return UNLANG_ACTION_EXECUTE_NEXT;
+ }
+
+ /*
+ * Tell the main interpreter to skip over the else /
+ * elsif blocks, as this "if" condition was taken.
+ */
+ while (frame->next &&
+ ((frame->next->type == UNLANG_TYPE_ELSE) ||
+ (frame->next->type == UNLANG_TYPE_ELSIF))) {
+ frame->next = frame->next->next;
+ }
+
+ /*
+ * We took the "if". Go recurse into its' children.
+ */
+ return unlang_group(p_result, request, frame);
}
- /*
- * Tell the main interpreter to skip over the else /
- * elsif blocks, as this "if" condition was taken.
- */
- while (frame->next &&
- ((frame->next->type == UNLANG_TYPE_ELSE) ||
- (frame->next->type == UNLANG_TYPE_ELSIF))) {
- frame->next = frame->next->next;
- }
-
- /*
- * We took the "if". Go recurse into its' children.
- */
- return unlang_group(p_result, request, frame);
-#else
-
/*
* If we always run this condition, then don't bother pushing anything onto the stack.
*
request, gext->head, UNLANG_SUB_FRAME) < 0) return UNLANG_ACTION_FAIL;
return UNLANG_ACTION_PUSHED_CHILD;
-#endif
}
void unlang_condition_init(void)
.name = "if",
.interpret = unlang_if,
.debug_braces = true,
-#ifdef WITH_XLAT_COND
.frame_state_size = sizeof(unlang_frame_state_cond_t),
.frame_state_type = "unlang_frame_state_cond_t",
-#endif
});
unlang_register(UNLANG_TYPE_ELSE,
.name = "elseif",
.interpret = unlang_if,
.debug_braces = true,
-#ifdef WITH_XLAT_COND
.frame_state_size = sizeof(unlang_frame_state_cond_t),
.frame_state_type = "unlang_frame_state_cond_t",
-#endif
});
}
#
define KEYWORD_TEST
test.keywords.${1}: $(addprefix $(OUTPUT)/,${1})
+
+#
+# Migration support. Some of the tests don't run under the new
+# conditions, so we don't run them under the new conditions.
+#
+ifeq "$(findstring ${1}, paircmp xlat-string xlat-subst)" ""
+$(OUTPUT)/${1}: NEW_COND=-S parse_new_conditions=yes -S use_new_conditions=yes
+endif
+
endef
$(foreach x,$(FILES),$(eval $(call KEYWORD_TEST,$x)))
# NOTE: Grepping for $< is not safe cross platform, as on Linux it
# expands to the full absolute path, and on macOS it appears to be relative.
$(OUTPUT)/%: $(DIR)/% $(TEST_BIN_DIR)/unit_test_module | $(KEYWORD_RADDB) $(KEYWORD_LIBS) build.raddb rlm_test.la rlm_csv.la rlm_unpack.la
- $(eval CMD:=KEYWORD=$(notdir $@) $(TEST_BIN)/unit_test_module $(UNIT_TEST_KEYWORD_ARGS.$(subst -,_,$(notdir $@))) -D share/dictionary -d src/tests/keywords/ -i "$@.attrs" -f "$@.attrs" -r "$@" -xx)
+ $(eval CMD:=KEYWORD=$(notdir $@) $(TEST_BIN)/unit_test_module $(NEW_COND) $(UNIT_TEST_KEYWORD_ARGS.$(subst -,_,$(notdir $@))) -D share/dictionary -d src/tests/keywords/ -i "$@.attrs" -f "$@.attrs" -r "$@" -xx)
@echo "KEYWORD-TEST $(notdir $@)"
${Q}cp $(if $(wildcard $<.attrs),$<.attrs,$(dir $<)/default-input.attrs) $@.attrs
${Q}if ! $(CMD) > "$@.log" 2>&1 || ! test -f "$@"; then \