]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix for if ("%{Tmp-Integer-0}" =~ /"%{Tmp-Integer-0}"/
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 5 Nov 2014 22:36:29 +0000 (17:36 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 6 Nov 2014 02:08:35 +0000 (21:08 -0500)
and other minor issues

src/main/evaluate.c
src/modules/rlm_example/rlm_example.c

index 9f773e37cfe89aa0f84827f6b62ea412d5a1f2e0..29ce8723f1427acdf1811263825a470d3b7598fe 100644 (file)
@@ -440,7 +440,7 @@ static int cond_normalise_values(REQUEST *request, fr_cond_t const *c,
        value_pair_map_t const *map = c->data.map;
 
        DICT_ATTR const *cast = NULL;
-       PW_TYPE cast_type = PW_TYPE_STRING;
+       PW_TYPE cast_type = PW_TYPE_INVALID;
 
        int rcode;
 
@@ -462,9 +462,7 @@ static int cond_normalise_values(REQUEST *request, fr_cond_t const *c,
         */
 #define CAST(_s) \
 do {\
-       if (!cast && lhs && rhs && (lhs_type == PW_TYPE_STRING) && (rhs_type == PW_TYPE_STRING) &&\
-           all_digits(lhs->strvalue) && all_digits(rhs->strvalue)) cast_type = PW_TYPE_INTEGER64;\
-       if ((cast_type != _s ## _type) && (_s ## _type != PW_TYPE_INVALID)) {\
+       if ((cast_type != PW_TYPE_INVALID) && (_s ## _type != PW_TYPE_INVALID) && (cast_type != _s ## _type)) {\
                ssize_t r;\
                EVAL_DEBUG("CASTING " #_s " FROM %s TO %s",\
                           fr_int2str(dict_attr_types, _s ## _type, "<INVALID>"),\
@@ -482,6 +480,17 @@ do {\
        }\
 } while (0)
 
+#define CHECK_INT_CAST(_l, _r) \
+do {\
+       if ((cast_type == PW_TYPE_INVALID) &&\
+           _l && (_l ## _type == PW_TYPE_STRING) &&\
+           _r && (_r ## _type == PW_TYPE_STRING) &&\
+           all_digits(lhs->strvalue) && all_digits(rhs->strvalue)) {\
+               cast_type = PW_TYPE_INTEGER64;\
+               EVAL_DEBUG("OPERANDS ARE NUMBER STRINGS, SETTING CAST TO integer64");\
+       }\
+} while (0)
+
        /*
         *      Regular expressions need both operands to be strings
         */
@@ -533,6 +542,7 @@ do {\
                        rhs = &vp->data;
                        rhs_len = vp->length;
 
+                       CHECK_INT_CAST(lhs, rhs);
                        CAST(lhs);
                        CAST(rhs);
 
@@ -549,6 +559,7 @@ do {\
                rhs = &map->rhs->tmpl_data_value;
                rhs_len = map->rhs->tmpl_data_length;
 
+               CHECK_INT_CAST(lhs, rhs);
                CAST(lhs);
                CAST(rhs);
 
@@ -577,6 +588,7 @@ do {\
                rhs_type = PW_TYPE_STRING;
                rhs = &data;
 
+               CHECK_INT_CAST(lhs, rhs);
                CAST(lhs);
                CAST(rhs);
 
index c0c78c02dbf0472a163b6e262dee0f138c516cd3..ac866d46af1ca9c065c5127de5937cee4378d37c 100644 (file)
@@ -89,7 +89,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
        }
 
        if (dict_addattr("Example-Paircmp", -1, 0, PW_TYPE_STRING, flags) < 0) {
-               ERROR("Failed creating paircmp attribute", fr_strerror());
+               ERROR("Failed creating paircmp attribute: %s", fr_strerror());
 
                return -1;
        }