]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move more normalisation to cond_normalise()
authorAlan T. DeKok <aland@freeradius.org>
Thu, 7 Jan 2021 17:49:06 +0000 (12:49 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 7 Jan 2021 20:50:11 +0000 (15:50 -0500)
src/lib/server/cond_tokenize.c

index e4a58ecb4cf0890b029e31388f064bbd3eabefa3..0ce6cf393d8905c289973871789536f1e22bcfc9 100644 (file)
@@ -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;
        }
 
+       /*
+        *      <ipaddr>"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;
                }
-
-               /*
-                *      <ipaddr>"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));
-               }
        }
 
        /*