From: Alan T. DeKok Date: Tue, 28 Mar 2017 20:01:06 +0000 (-0400) Subject: remove "auto_converted" flag from templates. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57dba7bec0c9ed511dba538ff42b6b3d2d279c15;p=thirdparty%2Ffreeradius-server.git remove "auto_converted" flag from templates. Only the compiler should auto-convert things, and then only if the LHS / RHS match in data type, and in parsing of that data type --- diff --git a/src/include/tmpl.h b/src/include/tmpl.h index 5b29738ab0c..2494ed585fe 100644 --- a/src/include/tmpl.h +++ b/src/include/tmpl.h @@ -174,8 +174,6 @@ typedef struct vp_tmpl_t { size_t len; //!< Length of the raw string used to create the template. FR_TOKEN quote; //!< What type of quoting was around the raw string. - bool auto_converted; //!< Attr-26.9.1 --> Cisco-AVPair - #ifdef HAVE_REGEX bool iflag; //!< regex - case insensitive (if operand is used in regex comparison) bool mflag; //!< regex - multiline flags (controls $ matching) diff --git a/src/main/tmpl.c b/src/main/tmpl.c index 686b4f1a0d4..67b60babbca 100644 --- a/src/main/tmpl.c +++ b/src/main/tmpl.c @@ -715,31 +715,26 @@ ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, vp_tmpl_t **out, char const *nam break; } + /* + * Look up by name, *including* any Attr-1.2.3.4 which was created when + * parsing the configuration files. + */ vpt->tmpl_da = fr_dict_attr_by_name_substr(NULL, &p); if (!vpt->tmpl_da) { char const *q; fr_strerror(); /* Clear out any existing errors */ + /* + * At this point, the OID *must* be unknown, and + * not previously used. + */ slen = fr_dict_unknown_afrom_oid_substr(vpt, &vpt->tmpl_unknown, fr_dict_root(fr_dict_internal), p); /* * Attr-1.2.3.4 is OK. */ if (slen > 0) { - /* - * Check what we just parsed really hasn't been defined - * in the main dictionaries. - * - * If it has, parsing is the same as if the attribute - * name had been used instead of its OID. - */ - vpt->tmpl_da = fr_dict_attr_by_name(NULL, p); - if (vpt->tmpl_da) { - vpt->auto_converted = true; - goto do_num; - } - if (!allow_unknown) { fr_strerror_printf("Unknown attribute"); slen = -(p - name); diff --git a/src/main/unlang_compile.c b/src/main/unlang_compile.c index aaae2d86fbf..97c6c270e08 100644 --- a/src/main/unlang_compile.c +++ b/src/main/unlang_compile.c @@ -722,27 +722,10 @@ static bool pass2_cond_callback(void *ctx, fr_cond_t *c) */ if ((map->lhs->type == TMPL_TYPE_ATTR) && (map->rhs->type == TMPL_TYPE_UNPARSED)) { - /* - * RHS is hex, try to parse it as - * type-specific data. - */ - if (map->lhs->auto_converted && - (map->rhs->name[0] == '0') && (map->rhs->name[1] == 'x') && - (map->rhs->len > 2) && ((map->rhs->len & 0x01) == 0)) { - vpt = map->rhs; - map->rhs = NULL; - - if (!map_cast_from_hex(map, T_BARE_WORD, vpt->name)) { - map->rhs = vpt; - cf_log_err(map->ci, "Cannot parse RHS hex as the data type of the attribute %s", map->lhs->tmpl_da->name); - return -1; - } - talloc_free(vpt); - - } else if ((map->rhs->len > 0) || - (map->op != T_OP_CMP_EQ) || - (map->lhs->tmpl_da->type == PW_TYPE_STRING) || - (map->lhs->tmpl_da->type == PW_TYPE_OCTETS)) { + if ((map->rhs->len > 0) || + (map->op != T_OP_CMP_EQ) || + (map->lhs->tmpl_da->type == PW_TYPE_STRING) || + (map->lhs->tmpl_da->type == PW_TYPE_OCTETS)) { if (tmpl_cast_in_place(map->rhs, map->lhs->tmpl_da->type, map->lhs->tmpl_da) < 0) { cf_log_err(map->ci, "Failed to parse data type %s from string: %s", @@ -1277,27 +1260,11 @@ int unlang_fixup_update(vp_map_t *map, UNUSED void *ctx) * ignore map->rhs. */ if ((map->lhs->type == TMPL_TYPE_ATTR) && (map->rhs->type == TMPL_TYPE_UNPARSED)) { - /* - * Convert it to the correct type. - */ - if (map->lhs->auto_converted && - (map->rhs->name[0] == '0') && (map->rhs->name[1] == 'x') && - (map->rhs->len > 2) && ((map->rhs->len & 0x01) == 0)) { - vp_tmpl_t *vpt = map->rhs; - map->rhs = NULL; - - if (!map_cast_from_hex(map, T_BARE_WORD, vpt->name)) { - map->rhs = vpt; - cf_log_err(map->ci, "Cannot parse RHS hex as the data type of the attribute %s", map->lhs->tmpl_da->name); - return -1; - } - talloc_free(vpt); - /* * It's a literal string, just copy it. * Don't escape anything. */ - } else if (tmpl_cast_in_place(map->rhs, map->lhs->tmpl_da->type, map->lhs->tmpl_da) < 0) { + if (tmpl_cast_in_place(map->rhs, map->lhs->tmpl_da->type, map->lhs->tmpl_da) < 0) { cf_log_err(map->ci, "%s", fr_strerror()); return -1; }