From: Alan T. DeKok Date: Thu, 7 Jan 2021 17:49:06 +0000 (-0500) Subject: move more normalisation to cond_normalise() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9dbe58f1e16d62b3146c8bf6d53f8350c484268;p=thirdparty%2Ffreeradius-server.git move more normalisation to cond_normalise() --- diff --git a/src/lib/server/cond_tokenize.c b/src/lib/server/cond_tokenize.c index e4a58ecb4cf..0ce6cf393d8 100644 --- a/src/lib/server/cond_tokenize.c +++ b/src/lib/server/cond_tokenize.c @@ -689,6 +689,60 @@ static int cond_normalise(TALLOC_CTX *ctx, fr_token_t lhs_type, fr_cond_t **c_ou goto check_short_circuit; } + /* + * "foo" CMP &Attribute-Name The cast may + * not be necessary, and we can re-write it so + * that the attribute reference is on the LHS. + * + * @todo - this rewrite isn't strictly necessary, and + * should likely be removed once the conditional + * evaluator is smarter. + */ + if ((c->type == COND_TYPE_MAP) && c->cast && + tmpl_is_attr(c->data.map->rhs) && + (c->cast->type == tmpl_da(c->data.map->rhs)->type) && + !tmpl_is_attr(c->data.map->lhs)) { + tmpl_t *tmp; + + tmp = c->data.map->rhs; + c->data.map->rhs = c->data.map->lhs; + c->data.map->lhs = tmp; + + c->cast = NULL; + + switch (c->data.map->op) { + case T_OP_CMP_EQ: + case T_OP_NE: + /* do nothing */ + break; + + case T_OP_LE: + c->data.map->op = T_OP_GE; + break; + + case T_OP_LT: + c->data.map->op = T_OP_GT; + break; + + case T_OP_GE: + c->data.map->op = T_OP_LE; + break; + + case T_OP_GT: + c->data.map->op = T_OP_LT; + break; + + default: + fr_strerror_const("Internal sanity check failed 1"); + return -1; + } + + /* + * This must have been parsed into TMPL_TYPE_DATA. + */ + fr_assert(!tmpl_is_unresolved(c->data.map->rhs)); + } + /* * Normalise the equality checks. * @@ -825,55 +879,6 @@ static int cond_normalise(TALLOC_CTX *ctx, fr_token_t lhs_type, fr_cond_t **c_ou TALLOC_FREE(c->data.map); goto check_true; } - - /* - * "foo" CMP &Attribute-Name The cast may - * not be necessary, and we can re-write it so - * that the attribute reference is on the LHS. - */ - if (c->cast && - tmpl_is_attr(c->data.map->rhs) && - (c->cast->type == tmpl_da(c->data.map->rhs)->type) && - !tmpl_is_attr(c->data.map->lhs)) { - tmpl_t *tmp; - - tmp = c->data.map->rhs; - c->data.map->rhs = c->data.map->lhs; - c->data.map->lhs = tmp; - - c->cast = NULL; - - switch (c->data.map->op) { - case T_OP_CMP_EQ: - /* do nothing */ - break; - - case T_OP_LE: - c->data.map->op = T_OP_GE; - break; - - case T_OP_LT: - c->data.map->op = T_OP_GT; - break; - - case T_OP_GE: - c->data.map->op = T_OP_LE; - break; - - case T_OP_GT: - c->data.map->op = T_OP_LT; - break; - - default: - fr_strerror_const("Internal sanity check failed 1"); - return -1; - } - - /* - * This must have been parsed into TMPL_TYPE_DATA. - */ - fr_assert(!tmpl_is_unresolved(c->data.map->rhs)); - } } /*