Start of type checks on RHS of conditions
authorAlan T. DeKok <aland@freeradius.org>
Mon, 13 May 2013 12:58:11 +0000 (08:58 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 13 May 2013 12:58:11 +0000 (08:58 -0400)
src/main/parser.c
src/tests/condition.txt

index d6bd0df..7c9ab8e 100644 (file)
@@ -279,6 +279,7 @@ static ssize_t condition_tokenize_cast(char const *start, DICT_ATTR const **pda,
  */
 #define return_P(_x) *error = _x;goto return_p
 #define return_0(_x) *error = _x;goto return_0
+#define return_rhs(_x) *error = _x;goto return_rhs
 #define return_SLEN goto return_slen
 
 
@@ -613,6 +614,16 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, char const *start, int brace,
 
                        } else {
                                /*
+                                *      Two attributes?  They must be of the same type
+                                */
+                               if ((c->data.map->src->type == VPT_TYPE_ATTR) &&
+                                   (c->data.map->dst->type == VPT_TYPE_ATTR) &&
+                                   (c->data.map->dst->da->type != c->data.map->src->da->type)) {
+                               same_type:
+                                       return_0("Attribute comparisons must be of the same attribute type");
+                               }
+
+                               /*
                                 *      Without a cast, we can't compare "foo" to User-Name,
                                 *      it has to be done the other way around.
                                 */
@@ -627,17 +638,6 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, char const *start, int brace,
                                }
 
                                /*
-                                *      Two attributes?  They must be of the same type
-                                */
-                               if ((c->data.map->src->type == VPT_TYPE_ATTR) &&
-                                   (c->data.map->dst->type == VPT_TYPE_ATTR) &&
-                                   (c->data.map->dst->da->type != c->data.map->src->da->type)) {
-                               same_type:
-                                       *error = "Attribute comparisons must be of the same attribute type";
-                                       goto return_0;
-                               }
-
-                               /*
                                 *      Invalid: User-Name == bob
                                 *      Valid:   User-Name == "bob"
                                 */
@@ -645,7 +645,22 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, char const *start, int brace,
                                    (c->data.map->src->type != VPT_TYPE_ATTR) &&
                                    (c->data.map->dst->da->type == PW_TYPE_STRING) &&
                                    (rhs_type == T_BARE_WORD)) {
-                                       *error = "Must have string as value for attribute";
+                                       return_rhs("Must have string as value for attribute");
+                               }
+
+                               /*
+                                *      Quotes around non-string
+                                *      attributes mean that it's
+                                *      either xlat, or an exec.
+                                */
+                               if ((c->data.map->dst->type == VPT_TYPE_ATTR) &&
+                                   (c->data.map->src->type != VPT_TYPE_ATTR) &&
+                                   (c->data.map->dst->da->type != PW_TYPE_STRING) &&
+                                   (c->data.map->dst->da->type != PW_TYPE_OCTETS) &&
+                                   (c->data.map->dst->da->type != PW_TYPE_DATE) &&
+                                   (rhs_type == T_SINGLE_QUOTED_STRING)) {
+                                       *error = "Value must be an unquoted string";
+                               return_rhs:
                                        if (lhs) talloc_free(lhs);
                                        if (rhs) talloc_free(rhs);
                                        talloc_free(c);
index 762d571..494ea89 100644 (file)
@@ -211,4 +211,16 @@ data &User-Name == 'bob'
 condition User-Name == bob
 data ERROR offset 13 Must have string as value for attribute
 
+# Integer (etc.) types must be "bare"
+condition Session-Timeout == 10
+data &Session-Timeout == 10
 
+condition Session-Timeout == '10'
+data ERROR offset 19 Value must be an unquoted string
+
+# Except for dates, which can be humanly readable!
+condition Event-Timestamp == "January 1, 2012"
+data &Event-Timestamp == "January 1, 2012"
+
+condition Event-Timestamp == 'January 1, 2012'
+data &Event-Timestamp == 'January 1, 2012'