size_t len;
RDEBUG4("EXPAND TMPL XLAT PARSED");
- RDEBUG2("EXPAND %s", vpt->name); /* xlat_struct doesn't do this */
+
+ /* No EXPAND <xlat> here as the xlat code does it */
+
if (!buff) {
fr_strerror_const("Missing expansion buffer for XLAT_STRUCT");
return -1;
char *result;
RDEBUG4("EXPAND TMPL XLAT STRUCT");
- RDEBUG2("EXPAND %s", vpt->name); /* xlat_struct doesn't do this */
+ /* No EXPAND xlat here as the xlat code does it */
/* Error in expansion, this is distinct from zero length expansion */
slen = xlat_aeval_compiled(tmp_ctx, &result, request, tmpl_xlat(vpt), escape, escape_ctx);
fr_value_box_bstrndup_shallow(&value, NULL, tmp.vb_strvalue, tmp.vb_length, tmp.tainted);
to_cast = &value;
-
- RDEBUG2(" --> %s", value.vb_strvalue); /* Print post-unescaping */
}
break;
xlat_escape_legacy_t escape, void const *escape_ctx)
{
fr_value_box_list_t result;
+ bool success = false;
TALLOC_CTX *pool = talloc_new(NULL);
+ rlm_rcode_t rcode;
char *str;
XLAT_DEBUG("xlat_eval_sync");
+ *out = NULL;
+
fr_value_box_list_init(&result);
/*
* Use the unlang stack to evaluate
* the async xlat up until the point
* that it needs to yield.
*/
- if (unlang_xlat_push(pool, NULL, &result, request, head, true) < 0) {
+ if (unlang_xlat_push(pool, &success, &result, request, head, true) < 0) {
talloc_free(pool);
- return NULL;
+ return -1;
}
- switch (unlang_interpret_synchronous(unlang_interpret_event_list(request), request)) {
+ rcode = unlang_interpret_synchronous(unlang_interpret_event_list(request), request);
+ switch (rcode) {
default:
break;
case RLM_MODULE_REJECT:
case RLM_MODULE_FAIL:
+ eval_failed:
RPEDEBUG("xlat evaluation failed");
talloc_free(pool);
- return NULL;
+ return -1;
}
+ if (!success) goto eval_failed;
if (!fr_dlist_empty(&result)) {
+ if (escape) {
+ fr_value_box_t *vb = NULL;
+
+ /*
+ * For tainted boxes perform the requested escaping
+ */
+ while ((vb = fr_dlist_next(&result, vb))) {
+ fr_dlist_t entry;
+ size_t len, real_len;
+ char *escaped;
+
+ if (!vb->tainted) continue;
+
+ len = talloc_array_length(str) * 3;
+
+ escaped = talloc_array(pool, char, len);
+ real_len = escape(request, escaped, len, str, UNCONST(void *, escape_ctx));
+
+ entry = vb->entry;
+ fr_value_box_clear_value(vb);
+ fr_value_box_bstrndup(vb, vb, NULL, escaped, real_len, false);
+ vb->entry = entry;
+
+ talloc_free(escaped);
+ }
+ }
+
str = fr_value_box_list_aprint(ctx, &result, NULL, &fr_value_escape_double);
if (!str) {
RPEDEBUG("Failed concatenating xlat result string");
}
talloc_free(pool); /* Memory should be in new ctx */
- if (escape) {
- size_t len;
- char *escaped;
-
- len = talloc_array_length(str) * 3;
-
- escaped = talloc_array(ctx, char, len);
- escape(request, escaped, len, str, UNCONST(void *, escape_ctx));
- talloc_free(str);
- str = escaped;
- }
-
*out = str;
return strlen(str);
ssize_t len;
xlat_exp_t *node;
- RDEBUG2("EXPAND %s", fmt);
RINDENT();
/*
talloc_free(node);
REXDENT();
- RDEBUG2("--> %s", *out);
return len;
}
* - >0 on success which is argc to the corresponding argv
*/
int xlat_aeval_compiled_argv(TALLOC_CTX *ctx, char ***argv, request_t *request,
- xlat_exp_t const *xlat, xlat_escape_legacy_t escape, void const *escape_ctx)
+ xlat_exp_t const *xlat, xlat_escape_legacy_t escape, void const *escape_ctx)
{
int i;
ssize_t slen;