From: Alan T. DeKok Date: Fri, 19 Jun 2015 16:01:49 +0000 (-0400) Subject: Move virtual re-write to pass2 callback X-Git-Tag: release_3_0_9~116 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=647dd797ed21713bef6f756ebdadd9b2a0cdf3ca;p=thirdparty%2Ffreeradius-server.git Move virtual re-write to pass2 callback So that the main parser has the correct data --- diff --git a/src/main/modcall.c b/src/main/modcall.c index 3e5a824cc27..2f77906a1ca 100644 --- a/src/main/modcall.c +++ b/src/main/modcall.c @@ -3126,6 +3126,7 @@ static bool pass2_fixup_undefined(CONF_ITEM const *ci, vp_tmpl_t *vpt) static bool pass2_callback(UNUSED void *ctx, fr_cond_t *c) { vp_map_t *map; + vp_tmpl_t *vpt; if (c->type == COND_TYPE_EXISTS) { if (c->data.vpt->type == TMPL_TYPE_XLAT) { @@ -3250,7 +3251,6 @@ check_paircmp: (strncmp(map->lhs->name, "Foreach-Variable-", 17) == 0)) { char *fmt; ssize_t slen; - vp_tmpl_t *vpt; fmt = talloc_asprintf(map->lhs, "%%{%s}", map->lhs->name); slen = tmpl_afrom_str(map, &vpt, fmt, talloc_array_length(fmt) - 1, @@ -3283,6 +3283,23 @@ check_paircmp: rad_assert(map->lhs->type != TMPL_TYPE_REGEX); #endif + /* + * Convert &Packet-Type to "%{Packet-Type}", because + * these attributes don't really exist. The code to + * find an attribute reference doesn't work, but the + * xlat code does. + */ + vpt = c->data.map->lhs; + if ((vpt->type == TMPL_TYPE_ATTR) && vpt->tmpl_da->flags.virtual) { + if (!c->cast) c->cast = vpt->tmpl_da; + vpt->tmpl_xlat = xlat_from_tmpl_attr(vpt, vpt); + vpt->type = TMPL_TYPE_XLAT_STRUCT; + } + + /* + * @todo v3.1: do the same thing for the RHS... + */ + /* * Only attributes can have a paircompare registered, and * they can only be with the current REQUEST, and only diff --git a/src/main/parser.c b/src/main/parser.c index a94a0dd1627..67329b2339f 100644 --- a/src/main/parser.c +++ b/src/main/parser.c @@ -1006,24 +1006,6 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *st } else { vp_tmpl_t *vpt; - /* - * Convert &Packet-Type to "%{Packet-Type}", because - * these attributes don't really exist. The code to - * find an attribute reference doesn't work, but the - * xlat code does. - */ - vpt = c->data.map->lhs; - if ((vpt->type == TMPL_TYPE_ATTR) && vpt->tmpl_da->flags.virtual) { - vpt->tmpl_xlat = xlat_from_tmpl_attr(vpt, vpt); - vpt->type = TMPL_TYPE_XLAT_STRUCT; - } - - vpt = c->data.map->rhs; - if ((vpt->type == TMPL_TYPE_ATTR) && vpt->tmpl_da->flags.virtual) { - vpt->tmpl_xlat = xlat_from_tmpl_attr(vpt, vpt); - vpt->type = TMPL_TYPE_XLAT_STRUCT; - } - /* * Two attributes? They must be of the same type */