Do compile time checks of literal map values
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 28 Nov 2013 13:25:48 +0000 (13:25 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 28 Nov 2013 13:31:30 +0000 (13:31 +0000)
src/lib/valuepair.c
src/main/map.c

index bb90e91..4b39979 100644 (file)
@@ -1419,8 +1419,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value)
                 *      attribute.
                 */
                if ((dval = dict_valbyname(vp->da->attr, vp->da->vendor, value)) == NULL) {
-                       fr_strerror_printf("Unknown value %s for attribute %s",
-                                  value, vp->da->name);
+                       fr_strerror_printf("Unknown value '%s' for attribute '%s'", value, vp->da->name);
                        return false;
                }
                vp->vp_integer = dval->value;
index 2acada5..72404a3 100644 (file)
@@ -340,7 +340,6 @@ value_pair_map_t *radius_cp2map(TALLOC_CTX *ctx, CONF_PAIR *cp,
        if (type == T_BARE_WORD) {
                if (*value == '&') {
                        map->src = radius_attr2tmpl(map, value + 1, src_request_def, src_list_def);
-
                } else {
                        if (!isdigit((int) *value) &&
                            ((strchr(value, ':') != NULL) ||
@@ -438,6 +437,26 @@ 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;
        }