Skip to content

Commit

Permalink
Check RHS of update sections in pass2, for xlat syntax
Browse files Browse the repository at this point in the history
so:

	update reply {
		Filter-Id := "%{foo: bar}"
	}

Will now get:

	./raddb/sites-enabled/default[231]: Failed parsing expanded string %{foo: bar}
        ./raddb/sites-enabled/default[231]:                                  ^ Unknown module
  • Loading branch information
alandekok committed Mar 21, 2014
1 parent 679df44 commit 2304f1d
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions src/main/modcall.c
Expand Up @@ -2613,6 +2613,51 @@ static bool pass2_callback(UNUSED void *ctx, fr_cond_t *c)

return true;
}


/*
* Compile the RHS of update sections to xlat_exp_t
*/
static bool modcall_pass2_update(modgroup *g)
{
value_pair_map_t *map;

for (map = g->map; map != NULL; map = map->next) {
ssize_t slen;
char *fmt;
char const *error;
xlat_exp_t *head;

if (map->src->type != VPT_TYPE_XLAT) continue;

rad_assert(map->src->vpd == NULL);

fmt = talloc_strdup(map->src, map->src->name);
slen = xlat_tokenize(map->src, fmt, &head, &error);
talloc_free(fmt);

if (slen < 0) {
size_t offset;
char *spbuf;

offset = -slen;

spbuf = malloc(offset + 1);
memset(spbuf, ' ', offset);
spbuf[offset] = '\0';

cf_log_err(map->ci, "Failed parsing expanded string %s",
map->src->name);
cf_log_err(map->ci, " %.*s^ %s",
(int) offset, spbuf, error);
free(spbuf);
return false;
}
talloc_free(head);
}

return true;
}
#endif

/*
Expand All @@ -2629,13 +2674,20 @@ bool modcall_pass2(modcallable *mc)
rad_assert(0 == 1);
break;

case MOD_SINGLE:
#ifdef WITH_UNLANG
case MOD_UPDATE: /* @todo: pre-parse xlat's */
case MOD_UPDATE:
g = mod_callabletogroup(this);
if (!modcall_pass2_update(g)) {
return false;
}
break;

case MOD_XLAT: /* @todo: pre-parse xlat's */
case MOD_BREAK:
case MOD_REFERENCE:
#endif

case MOD_SINGLE:
break; /* do nothing */

#ifdef WITH_UNLANG
Expand Down

0 comments on commit 2304f1d

Please sign in to comment.