]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add test for literal values
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 4 Dec 2013 11:49:04 +0000 (11:49 +0000)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 4 Dec 2013 13:43:32 +0000 (08:43 -0500)
Only do RHS literal validation in updates and rlm_cache

src/main/map.c
src/main/modcall.c
src/modules/rlm_cache/rlm_cache.c
src/tests/keywords/update-error-3 [new file with mode: 0644]

index 72404a318ce1876b67d35aa232602a5a0d8b4a86..a35cacf2a1942a19f30b0a7c417215323853b493 100644 (file)
@@ -437,26 +437,6 @@ value_pair_map_t *radius_cp2map(TALLOC_CTX *ctx, CONF_PAIR *cp,
                        }
                break;
 
-               case VPT_TYPE_LITERAL:
-               /*
-                *      If LHS is an attribute, and RHS is a literal, we can
-                *      check that the format is correct.
-                */
-               if (map->dst->type == VPT_TYPE_ATTR) {
-                       VALUE_PAIR *vp;
-                       bool ret;
-
-                       MEM(vp = pairalloc(NULL, map->dst->da));
-                       vp->op = map->op;
-
-                       ret = pairparsevalue(vp, map->src->name);
-                       talloc_free(vp);
-                       if (!ret) {
-                               cf_log_err(ci, "%s", fr_strerror());
-                               return NULL;
-                       }
-               }
-
                default:
                        break;
        }
index df0781f57c97910db5f2d5bfb2b1f932ad554b5d..710edc2b8449be7d3f2acef851f38dfd4b6d5c90 100644 (file)
@@ -1503,21 +1503,44 @@ static modcallable *do_compile_modupdate(modcallable *parent, UNUSED rlm_compone
        int rcode;
        modgroup *g;
        modcallable *csingle;
-       value_pair_map_t *map;
+       value_pair_map_t *map, *head = NULL;
 
        /*
         *      This looks at cs->name2 to determine which list to update
         */
-       rcode = radius_attrmap(cs, &map, PAIR_LIST_REQUEST, PAIR_LIST_REQUEST, 128);
+       rcode = radius_attrmap(cs, &head, PAIR_LIST_REQUEST, PAIR_LIST_REQUEST, 128);
        if (rcode < 0) return NULL; /* message already printed */
 
-       if (!map) {
+       if (!head) {
                cf_log_err_cs(cs, "'update' sections cannot be empty");
                return NULL;
        }
 
+       for (map = head; map != NULL; map = map->next) {
+               if ((map->dst->type == VPT_TYPE_ATTR) && (map->src->type == VPT_TYPE_LITERAL)) {
+                       /*
+                        *      If LHS is an attribute, and RHS is a literal, we can
+                        *      check that the format is correct.
+                        */
+                       VALUE_PAIR *vp;
+                       bool ret;
+
+                       MEM(vp = pairalloc(cs, map->dst->da));
+                       vp->op = map->op;
+
+                       ret = pairparsevalue(vp, map->src->name);
+                       talloc_free(vp);
+                       if (!ret) {
+                               talloc_free(head);
+                               cf_log_err(map->ci, "%s", fr_strerror());
+                               return NULL;
+                       }
+               }
+       }
+
        g = rad_malloc(sizeof(*g)); /* never fails */
        memset(g, 0, sizeof(*g));
+
        csingle = mod_grouptocallable(g);
 
        csingle->parent = parent;
@@ -1537,7 +1560,7 @@ static modcallable *do_compile_modupdate(modcallable *parent, UNUSED rlm_compone
        g->grouptype = GROUPTYPE_SIMPLE;
        g->children = NULL;
        g->cs = cs;
-       g->map = map;
+       g->map = head;
 
        return csingle;
 }
index a855deb10df1e300f711edcd5d4525262fb95660..20d72db2a9b4eb6b5a39e6bc2652c1a17005ff93 100644 (file)
@@ -593,6 +593,25 @@ static int cache_verify(rlm_cache_t *inst, value_pair_map_t **head)
                 *      cache entries.
                 */
                case VPT_TYPE_LITERAL:
+                       /*
+                        *      @fixme: This should be moved into a common function
+                        *      with the check in do_compile_modupdate.
+                        */
+                       if (map->dst->type == VPT_TYPE_ATTR) {
+                               VALUE_PAIR *vp;
+                               bool ret;
+
+                               MEM(vp = pairalloc(NULL, map->dst->da));
+                               vp->op = map->op;
+
+                               ret = pairparsevalue(vp, map->src->name);
+                               talloc_free(vp);
+                               if (!ret) {
+                                       cf_log_err(map->ci, "%s", fr_strerror());
+                                       return -1;
+                               }
+                       }
+
                case VPT_TYPE_XLAT:
                case VPT_TYPE_ATTR:
                        switch (map->op) {
diff --git a/src/tests/keywords/update-error-3 b/src/tests/keywords/update-error-3
new file mode 100644 (file)
index 0000000..ffab73a
--- /dev/null
@@ -0,0 +1,10 @@
+#
+# PRE: update-error
+#
+#  It's an error to assign literal values which are not
+#  part of the set of enumerated values for an attribute
+#
+update {
+       Service-Type := 'hello' # ERROR
+       reply:Filter-Id := "filter"
+}