The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
edit.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: 76288b0b40b292fe3878cf4c0d3c777930a41605 $
19 *
20 * @brief fr_pair_t editing
21 *
22 * @ingroup AVP
23 *
24 * @copyright 2021 Network RADIUS SAS (legal@networkradius.com)
25 */
26RCSID("$Id: 76288b0b40b292fe3878cf4c0d3c777930a41605 $")
27
28#include <freeradius-devel/server/base.h>
29#include <freeradius-devel/server/tmpl_dcursor.h>
30#include <freeradius-devel/util/edit.h>
31#include <freeradius-devel/util/calc.h>
32#include <freeradius-devel/unlang/tmpl.h>
33#include <freeradius-devel/unlang/edit.h>
34#include <freeradius-devel/unlang/transaction.h>
35#include <freeradius-devel/unlang/unlang_priv.h>
36#include "edit_priv.h"
37
38#undef XDEBUG
39#if 1
40#define XDEBUG(...)
41#else
42#define XDEBUG DEBUG2
43#endif
44
45#define RDEBUG_ASSIGN(_name, _op, _box) do { \
46 RDEBUG2(((_box)->type == FR_TYPE_STRING) ? "%s %s \"%pV\"" : "%s %s %pV", _name, fr_tokens[_op], _box); \
47} while (0)
48
49typedef struct {
50 fr_value_box_list_t result; //!< result of expansion
51 tmpl_t const *vpt; //!< expanded tmpl
52 tmpl_t *to_free; //!< tmpl to free.
53 bool create; //!< whether we need to create the VP
54 fr_pair_t *vp; //!< VP referenced by tmpl.
55 fr_pair_t *vp_parent; //!< parent of the current VP
56 fr_pair_list_t pair_list; //!< for structural attributes
58
59typedef struct edit_map_s edit_map_t;
60
62
64
65struct edit_map_s {
66 fr_edit_list_t *el; //!< edit list
67
68 TALLOC_CTX *ctx;
71
72 map_list_t const *map_list;
73 map_t const *map; //!< the map to evaluate
74
76
77 edit_result_t lhs; //!< LHS child entries
78 edit_result_t rhs; //!< RHS child entries
79
80 unlang_edit_expand_t func; //!< for process state
81 unlang_edit_expand_t check_lhs; //!< for special cases
82 unlang_edit_expand_t expanded_lhs; //!< for special cases
83};
84
85/** State of an edit block
86 *
87 */
89 fr_edit_list_t *el; //!< edit list
90 bool *success; //!< whether or not the edit succeeded
91 bool ours;
92
94
95 edit_map_t *current; //!< what we're currently doing.
97};
98
99#define MAP_INFO cf_filename(map->ci), cf_lineno(map->ci)
100
101static fr_pair_t *edit_list_pair_build(fr_pair_t *parent, fr_dcursor_t *cursor, fr_dict_attr_t const *da, void *uctx);
102
103/*
104 * Convert a value-box list to a LHS attribute #tmpl_t
105 */
106static int tmpl_attr_from_result(TALLOC_CTX *ctx, map_t const *map, edit_result_t *out, request_t *request)
107{
108 ssize_t slen;
109 fr_value_box_t *box = fr_value_box_list_head(&out->result);
110
111 if (!box) {
112 RWDEBUG("%s %s ... - Assignment failed - No value on right-hand side", map->lhs->name, fr_tokens[map->op]);
113 return -1;
114 }
115
116 /*
117 * Mash all of the results together.
118 */
119 if (fr_value_box_list_concat_in_place(box, box, &out->result, FR_TYPE_STRING, FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
120 RWDEBUG("Failed converting result to string");
121 return -1;
122 }
123
124 /*
125 * Parse the LHS as an attribute reference. It can't be
126 * anything else.
127 */
128 slen = tmpl_afrom_attr_str(ctx, NULL, &out->to_free, box->vb_strvalue,
129 &(tmpl_rules_t){
130 .attr = {
131 .dict_def = request->local_dict,
132 .list_def = request_attr_request,
133 }
134 });
135 if (slen <= 0) {
136 RPEDEBUG("Expansion result \"%s\" is not an attribute reference", box->vb_strvalue);
137 return -1;
138 }
139
140 out->vpt = out->to_free;
141 fr_value_box_list_talloc_free(&out->result);
142
143 return 0;
144}
145
146
147/*
148 * Expand a tmpl.
149 */
150static int tmpl_to_values(TALLOC_CTX *ctx, edit_result_t *out, request_t *request, tmpl_t const *vpt)
151{
152 fr_assert(out->vpt == NULL);
153 fr_assert(out->to_free == NULL);
154
155 switch (vpt->type) {
156 case TMPL_TYPE_DATA:
157 return 0;
158
159 case TMPL_TYPE_ATTR:
160 out->vpt = vpt;
161 return 0;
162
163 case TMPL_TYPE_EXEC:
164 if (unlang_tmpl_push(ctx, &out->result, request, vpt, NULL) < 0) return -1;
165 return 1;
166
167 case TMPL_TYPE_XLAT:
168 if (unlang_xlat_push(ctx, NULL, &out->result, request, tmpl_xlat(vpt), false) < 0) return -1;
169 return 1;
170
171 default:
172 /*
173 * The other tmpl types MUST have already been
174 * converted to the "realized" types.
175 */
177 fr_assert(0);
178 break;
179 }
180
181 return -1;
182}
183
184static void edit_debug_attr_list(request_t *request, fr_pair_list_t const *list, map_t const *map);
185
186static void edit_debug_attr_vp(request_t *request, fr_pair_t *vp, map_t const *map)
187{
188 fr_assert(vp != NULL);
189
190 if (map) {
191 switch (vp->vp_type) {
193 RDEBUG2("%s = {", map->lhs->name);
194 RINDENT();
195 edit_debug_attr_list(request, &vp->vp_group, map_list_head(&map->child));
196 REXDENT();
197 RDEBUG2("}");
198 break;
199
200 default:
201 RDEBUG_ASSIGN(map->lhs->name, vp->op, &vp->data);
202 break;
203 }
204 } else {
205 switch (vp->vp_type) {
207 RDEBUG2("%s = {", vp->da->name);
208 RINDENT();
209 edit_debug_attr_list(request, &vp->vp_group, NULL);
210 REXDENT();
211 RDEBUG2("}");
212 break;
213
214 default:
215 RDEBUG_ASSIGN(vp->da->name, vp->op, &vp->data);
216 break;
217 }
218 }
219}
220
221static void edit_debug_attr_list(request_t *request, fr_pair_list_t const *list, map_t const *map)
222{
223 fr_pair_t *vp;
224 map_t const *child = NULL;
225
226 if (map) child = map_list_head(&map->child);
227
228 for (vp = fr_pair_list_next(list, NULL);
229 vp != NULL;
230 vp = fr_pair_list_next(list, vp)) {
231 edit_debug_attr_vp(request, vp, child);
232 if (map) child = map_list_next(&map->child, child);
233 }
234}
235
236static int edit_create_lhs_vp(request_t *request, TALLOC_CTX *ctx, edit_map_t *current)
237{
238 int err;
239 fr_pair_t *vp;
240 tmpl_dcursor_ctx_t lhs_cc;
241 fr_dcursor_t lhs_cursor;
242
243 fr_assert(current->lhs.create);
244
245 /*
246 * Now that we have the RHS values, go create the LHS vp. We delay creating it until
247 * now, because the RHS might just be nothing. In which case we don't want to create the
248 * LHS, and then discover that we need to delete it.
249 */
251 vp = tmpl_dcursor_build_init(&err, ctx, &lhs_cc, &lhs_cursor, request, current->lhs.vpt, edit_list_pair_build, current);
252 tmpl_dcursor_clear(&lhs_cc);
253 if (!vp) {
254 RWDEBUG("Failed creating attribute %s", current->lhs.vpt->name);
255 return -1;
256 }
257
258 current->lhs.vp = vp;
259
260 return 0;
261}
262
263/* Apply the edits to a structural attribute..
264 *
265 * Figure out what edits to do, and then do them.
266 */
268{
269 fr_pair_t *vp;
270 fr_pair_list_t *children;
271 int rcode;
272 map_t const *map = current->map;
274 fr_dcursor_t cursor;
275
276 XDEBUG("apply_edits_to_list %s", map->lhs->name);
277
278 /*
279 * RHS is a sublist, go apply that.
280 */
281 if (!map->rhs) {
282 children = &current->rhs.pair_list;
283 goto apply_list;
284 }
285
286 /*
287 * For RHS of data, it should be a string which contains the pairs to use.
288 */
289 if (!current->rhs.vpt) {
290 fr_value_box_t *box;
291 fr_dict_attr_t const *da;
292 fr_pair_parse_t root, relative;
293
294 if (tmpl_is_data(map->rhs)) {
295 box = tmpl_value(map->rhs);
296
297 if (box->type != FR_TYPE_STRING) {
298 REDEBUG("Invalid data type for assignment to list");
299 return -1;
300 }
301
302 } else {
303 box = fr_value_box_list_head(&current->rhs.result);
304
305 /*
306 * Can't concatenate empty results.
307 */
308 if (!box) {
309 RWDEBUG("%s %s ... - Assignment failed to having no value on right-hand side", map->lhs->name, fr_tokens[map->op]);
310 return -1;
311 }
312
313 /*
314 * Mash all of the results together.
315 */
316 if (fr_value_box_list_concat_in_place(box, box, &current->rhs.result, FR_TYPE_STRING, FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
317 RWDEBUG("Failed converting result to string");
318 return -1;
319 }
320 }
321
322 children = &current->rhs.pair_list;
323
324 /*
325 * For exec, etc., parse the pair list from a string, in the context of the
326 * parent VP. Because we're going to be moving them to the parent VP at some
327 * point. The ones which aren't moved will get deleted in this function.
328 */
329 da = tmpl_attr_tail_da(current->lhs.vpt);
330 if (fr_type_is_group(da->type)) da = fr_dict_root(request->proto_dict);
331
332 root = (fr_pair_parse_t) {
333 .ctx = current->ctx,
334 .da = da,
335 .list = children,
336 .allow_compare = true,
337 .tainted = box->tainted,
338 };
339 relative = (fr_pair_parse_t) { };
340
341 if (fr_pair_list_afrom_substr(&root, &relative, &FR_SBUFF_IN(box->vb_strvalue, box->vb_length)) < 0) {
342 RPEDEBUG("Failed parsing string '%pV' as attribute list", box);
343 return -1;
344 }
345
346 goto apply_list;
347 }
348
349 fr_assert(current->rhs.vpt);
350 fr_assert(tmpl_is_attr(current->rhs.vpt));
351
352 /*
353 * Doing no modifications to a list is a NOOP.
354 */
355 vp = tmpl_dcursor_init(NULL, request, &cc, &cursor, request, current->rhs.vpt);
356 if (!vp) {
358 return 0;
359 }
360
361 /*
362 * Remove an attribute from a list. The tmpl_dcursor and tmpl_parser ensures that the RHS
363 * references are done in the context of the LHS attribute.
364 */
365 if (map->op == T_OP_SUB_EQ) {
366 fr_pair_t *next;
367
368 /*
369 * Loop over matching attributes, and delete them.
370 */
371 RDEBUG2("%s %s %s", current->lhs.vpt->name, fr_tokens[T_OP_SUB_EQ], current->rhs.vpt->name);
372
373 for ( ; vp != NULL; vp = next) {
374 fr_pair_list_t *list;
375
376 next = fr_dcursor_next(&cursor);
377
378 list = fr_pair_parent_list(vp);
379 fr_assert(list != NULL);
380
381 /*
382 * @todo - if this attribute is structural, then remove all children which aren't
383 * immutable. For now, this is good enough.
384 */
385 if (fr_pair_immutable(vp)) {
386 RWDEBUG("Not removing immutable %pP", vp);
387 continue;
388 }
389
390 if (vp->vp_edit) {
391 RWDEBUG("Attribute cannot be removed, as it is being used in a 'foreach' loop - %pP", vp);
392 continue;
393 }
394
395 if (fr_edit_list_pair_delete(current->el, list, vp) < 0) {
396 RPEDEBUG("Failed deleting attribute");
398 return -1;
399 }
400 }
401
403 return 0;
404 }
405
406 /*
407 * Check the RHS thing we're copying.
408 */
409 if (fr_type_is_structural(vp->vp_type)) {
411
412 if (tmpl_attr_tail_num(current->rhs.vpt) == NUM_ALL) {
413 REDEBUG("%s[%d] Wildcard for structural attribute %s is not yet implemented.", MAP_INFO, current->rhs.vpt->name);
414 return -1;
415 }
416
417 children = &vp->vp_group;
418 goto apply_list;
419 }
420
421 /*
422 * Copy the attributes from the cursor to a temporary pair list.
423 */
424 fr_pair_list_init(&current->rhs.pair_list);
425 while (vp) {
426 fr_pair_t *copy;
427
428 copy = fr_pair_copy(request, vp);
429 if (!copy) {
430 fr_pair_list_free(&current->rhs.pair_list);
432 return -1;
433 }
434 fr_pair_append(&current->rhs.pair_list, copy);
435
436 vp = fr_dcursor_next(&cursor);
437 }
439
440 children = &current->rhs.pair_list;
441
442 /*
443 * Apply structural thingies!
444 */
445apply_list:
446 fr_assert(children != NULL);
447
448 /*
449 * If we have to create the LHS, then do so now.
450 */
451 if (current->lhs.create && (edit_create_lhs_vp(request, state, current) < 0)) {
452 return -1;
453 }
454
455 fr_assert(current->lhs.vp != NULL);
456
457#ifdef STATIC_ANALYZER
458 if (!current->lhs.vp) return -1;
459#endif
460
461 /*
462 * Print the children before we do the modifications.
463 */
464 if (!current->parent) {
465 RDEBUG2("%s %s {", current->lhs.vpt->name, fr_tokens[map->op]);
466 if (fr_debug_lvl >= L_DBG_LVL_2) {
467 RINDENT();
468 edit_debug_attr_list(request, children, map);
469 REXDENT();
470 }
471 RDEBUG2("}");
472 }
473
474 fr_pair_list_foreach(children, child) {
475 if (!fr_dict_attr_can_contain(current->lhs.vp->da, child->da)) {
476 RDEBUG("Cannot perform assignment: Attribute \"%s\" is not a child of parent \"%s\"",
477 child->da->name, current->lhs.vp->da->name);
478 rcode = -1;
479 goto done;
480 }
481 }
482
483 if (map->op != T_OP_EQ) {
484 fr_assert(current->el != NULL);
485
486 rcode = fr_edit_list_apply_list_assignment(current->el, current->lhs.vp, map->op, children,
487 (children != &current->rhs.pair_list));
488 if (rcode < 0) RPEDEBUG("Failed performing list '%s' operation", fr_tokens[map->op]);
489
490 } else {
491#if 0
492 /*
493 * The RHS list _should_ be a copy of the LHS list. But for some cases it's not. We
494 * should spend time tracking this down, but not today.
495 *
496 * For now, brute-force copy isn't wrong.
497 */
498 if (children == &current->rhs.pair_list) {
499 fr_pair_list_append(&current->lhs.vp->vp_group, children);
500 } else
501#endif
502 (void) fr_pair_list_copy(current->lhs.vp, &current->lhs.vp->vp_group, children);
503
504 PAIR_VERIFY(current->lhs.vp);
505 rcode = 0;
506 }
507
508 /*
509 * If the child list wasn't copied, then we just created it, and we need to free it.
510 */
511done:
512 if (children == &current->rhs.pair_list) fr_pair_list_free(children);
513 return rcode;
514}
515
516static bool pair_is_editable(request_t *request, fr_pair_t *vp)
517{
518 if (vp->vp_edit) {
519 RWDEBUG("Attribute cannot be removed, as it is being used in a 'foreach' loop - %s", vp->da->name);
520 return false;
521 }
522
523 if (!fr_type_is_structural(vp->vp_type)) return true;
524
525 fr_pair_list_foreach(&vp->vp_group, child) {
526 if (!pair_is_editable(request, child)) return false;
527 }
528
529 return true;
530}
531
532static int edit_delete_lhs(request_t *request, edit_map_t *current, bool delete)
533{
535 fr_dcursor_t cursor;
536
537 /*
538 * These are magic.
539 */
540 if (delete) {
541 fr_dict_attr_t const *da = tmpl_attr_tail_da(current->lhs.vpt);
542
543 if (fr_type_is_structural(da->type) &&
544 ((da == request_attr_request) ||
545 (da == request_attr_reply) ||
546 (da == request_attr_control) ||
547 (da == request_attr_state))) {
548 delete = false;
549 }
550 }
551
552 while (true) {
553 int err;
555
556 /*
557 * Reinitialize the cursor for every VP. This is because fr_dcursor_remove() does not
558 * work with tmpl_dcursors, as the tmpl_dcursor code does not set the "remove" callback.
559 * And the tmpl is NUM_UNSPEC, which means "the first one", whereas for T_OP_SET_EQ, we
560 * really mean "delete all except the first one".
561 *
562 * Once that's implemented, we also need to update the edit list API to
563 * allow for "please delete children"?
564 */
565 vp = tmpl_dcursor_init(&err, current->ctx, &cc, &cursor, request, current->lhs.vpt);
566 if (!vp) break;
567
569 fr_assert(parent != NULL);
570
571 if (!pair_is_editable(request, vp)) {
573 return -1;
574 }
575
576 if (!delete) {
577 if (fr_type_is_structural(vp->vp_type)) {
578
579 if (fr_edit_list_free_pair_children(current->el, vp) < 0) return -1;
580 } else {
581 /*
582 * No need to save value, as fr_edit_list_apply_pair_assignment() will do
583 * that for us.
584 */
585 }
586
587 current->lhs.vp = vp;
589 return 0;
590 }
591
592 /*
593 * Delete all of them. We'll create one later for the SET operation.
594 */
595 if (fr_edit_list_pair_delete(current->el, &parent->vp_group, vp) < 0) {
596 RPWDEBUG("Failed deleting attribute");
597 return -1;
598 }
600 }
601
602 return 0;
603}
604
605/*
606 * Apply the edits to a leaf attribute. First we figure out where the results come from:
607 *
608 * single value-box (e.g. tmpl_is_data(vpt)
609 * rhs value-box result list (we create a dcursor)
610 * RHS attribute reference (we create a nested dcursor to get the values from the pair list)
611 *
612 * Then we figure out what to do with those values.
613 *
614 * if it needs to be created, then create it and just mash the results in place
615 * otherwise apply the edits (+=, etc.) to an existing attribute.
616 *
617 * @todo - move to using dcursors for all of the values. The dcursor should exist in current->rhs. It
618 * should be used even for TMPL_DATA and single value-boxes. Once that's done, it becomes easier to use
619 * dcursors for xlats, too.
620 */
622{
623 fr_value_box_t *box = NULL;
625 fr_dcursor_t cursor;
626 fr_dcursor_t pair_cursor;
627 bool single = false, pair = false;
628 map_t const *map = current->map;
629
630 XDEBUG("apply_edits_to_leaf %s", map->lhs->name);
631
632 if (!tmpl_is_attr(current->lhs.vpt)) {
633 REDEBUG("%s[%d] The left side of an assignment must be an attribute reference", MAP_INFO);
634 return -1;
635 }
636
637 /*
638 * &Foo := { a, b, c }
639 *
640 * There should be values in RHS result, all of value boxes.
641 */
642 if (!map->rhs) {
643 fr_assert(current->rhs.vpt == NULL);
644 goto rhs_list;
645
646 }
647
648 if (!current->rhs.vpt) {
649 /*
650 * There's no RHS tmpl, so the result must be in in the parent RHS tmpl as data, OR in
651 * the RHS result list.
652 */
653 if (tmpl_is_data(map->rhs)) {
654 box = tmpl_value(map->rhs);
655 single = true;
656
657 } else if ((map->rhs->quote == T_SINGLE_QUOTED_STRING) || (map->rhs->quote == T_DOUBLE_QUOTED_STRING)) {
658 /*
659 * The caller asked for a string, so instead of returning a list, return a string.
660 *
661 * If there's no output, then it's an empty string.
662 *
663 * We have to check this here, because the quote is part of the tmpl, and we call
664 * xlat_push(), which doesn't know about the quote.
665 *
666 * @todo - we should really push the quote into the xlat, too.
667 */
668 box = fr_value_box_list_head(&current->rhs.result);
669
670 if (!box) {
671 MEM(box = fr_value_box_alloc(state, FR_TYPE_STRING, NULL));
672 fr_value_box_strdup(box, box, NULL, "", false);
673 fr_value_box_list_insert_tail(&current->rhs.result, box);
674
675 } else if (fr_value_box_list_concat_in_place(box, box, &current->rhs.result, FR_TYPE_STRING,
676 FR_VALUE_BOX_LIST_FREE_BOX, true, 8192) < 0) {
677 RWDEBUG("Failed converting result to string");
678 return -1;
679 }
680 box = fr_value_box_list_head(&current->rhs.result);
681 single = true;
682
683 } else {
684 rhs_list:
685 if (fr_value_box_list_num_elements(&current->rhs.result) == 1) {
686 box = fr_value_box_list_head(&current->rhs.result);
687 single = true;
688 } else {
689 box = fr_dcursor_init(&cursor, fr_value_box_list_dlist_head(&current->rhs.result));
690 }
691 }
692 } else {
693 fr_pair_t *vp;
694 int err;
695
696 /*
697 * We have a temporary tmpl on the RHS. It MUST be an attribute, because everything else
698 * was expanded to a value-box list.
699 */
700 fr_assert(tmpl_is_attr(current->rhs.vpt));
701
702 /*
703 * Get a cursor over the RHS pairs.
704 */
705 vp = tmpl_dcursor_init(&err, request, &cc, &pair_cursor, request, current->rhs.vpt);
706 if (!vp) {
708
709 if (map->op != T_OP_SET) return 0;
710
711 /*
712 * No RHS pairs means we can finally delete all of the LHS.
713 */
714 return edit_delete_lhs(request, current, true);
715 }
716
717 box = fr_pair_dcursor_nested_init(&cursor, &pair_cursor); // the list is unused
718 pair = true;
719 }
720
721 if (!box) {
722 if (map->op != T_OP_SET) {
723 RWDEBUG("%s %s ... - Assignment failed - No value on right-hand side", map->lhs->name, fr_tokens[map->op]);
724 return -1;
725 }
726
727 /*
728 * Set is "delete, then add".
729 */
730 RDEBUG2("%s :=", current->lhs.vpt->name);
731 goto done;
732 }
733
734 /*
735 * The parent is a structural type. The RHS is a temporary list or attribute, which we can just
736 * add to the parents pair list. The parent will then take care of merging that pair list into
737 * the appropriate place.
738 */
739 if (current->temporary_pair_list) {
740 fr_pair_list_t *list = &current->parent->rhs.pair_list;
741 fr_pair_t *vp;
742
743 if (!current->parent->lhs.vp) {
744 if (edit_create_lhs_vp(request, request, current->parent) < 0) return -1;
745 }
746
747 while (box) {
748 /*
749 * Create (or find) all intermediate attributes. The LHS map might have multiple
750 * attribute names in it.
751 *
752 * @todo - audit other uses of tmpl_attr_tail_da() and fr_pair_afrom_da() in this file.
753 */
754 if (pair_append_by_tmpl_parent(current->parent->lhs.vp, &vp, list, current->lhs.vpt, true) < 0) {
755 RWDEBUG("Failed creating attribute %s", current->lhs.vpt->name);
756 return -1;
757 }
758
759 vp->op = map->op;
760 if (fr_value_box_cast(vp, &vp->data, vp->vp_type, vp->da, box) < 0) return -1;
761
762 if (single) break;
763
764 box = fr_dcursor_next(&cursor);
765 }
766
767 goto done;
768 }
769
770 /*
771 * If we're supposed to create the LHS, then go do that.
772 */
773 if (current->lhs.create) {
774 fr_dict_attr_t const *da = tmpl_attr_tail_da(current->lhs.vpt);
775 fr_pair_t *vp;
776
777 /*
778 * Something went wrong creating the value, it's a failure. Note that we fail _all_
779 * subsequent assignments, too.
780 */
781 if (fr_type_is_null(box->type)) goto fail;
782
783 if (edit_create_lhs_vp(request, state, current) < 0) goto fail;
784
785 fr_assert(current->lhs.vp_parent != NULL);
786 fr_assert(fr_type_is_structural(current->lhs.vp_parent->vp_type));
787
788 vp = current->lhs.vp;
789
790 /*
791 * There's always at least one LHS vp created. So we apply that first.
792 */
793 RDEBUG_ASSIGN(current->lhs.vpt->name, map->op, box);
794
795 /*
796 * The VP has already been inserted into the edit list, so we don't need to edit it's
797 * value, we can just mash it in place.
798 */
799 if (fr_value_box_cast(vp, &vp->data, vp->vp_type, vp->da, box) < 0) goto fail;
800 vp->op = T_OP_EQ;
801 if (vp->da->flags.unsafe) fr_value_box_mark_unsafe(&vp->data);
802
803 if (single) goto done;
804
805 /*
806 * Now that the attribute has been created, go apply the rest of the values to the attribute.
807 */
808 if (!((map->op == T_OP_EQ) || (map->op == T_OP_SET))) {
809 box = fr_dcursor_next(&cursor);
810 if (!box) goto done;
811
812 goto apply_op;
813 }
814
815 if (current->lhs.vp->da->flags.local) {
816 if (fr_dcursor_next_peek(&cursor)) RWDEBUG("Ignoring extra values for local variable");
817 goto done;
818 }
819
820 /*
821 * Loop over the remaining items, adding the VPs we've just created.
822 */
823 while ((box = fr_dcursor_next(&cursor)) != NULL) {
824 RDEBUG_ASSIGN(current->lhs.vpt->name, map->op, box);
825
826 MEM(vp = fr_pair_afrom_da(current->lhs.vp_parent, da));
827 if (fr_value_box_cast(vp, &vp->data, vp->vp_type, vp->da, box) < 0) goto fail;
828 if (vp->da->flags.unsafe) fr_value_box_mark_unsafe(&vp->data);
829
830 if (fr_edit_list_insert_pair_tail(state->el, &current->lhs.vp_parent->vp_group, vp) < 0) goto fail;
831 vp->op = T_OP_EQ;
832 }
833
834 goto done;
835 }
836
837 /*
838 * If we're not creating a temporary list, we must be editing an existing attribute on the LHS.
839 *
840 * We have two remaining cases. One is the attribute was just created with "=" or ":=", so we
841 * can just mash its value. The second is that the attribute already exists, and we're editing
842 * it's value using something like "+=".
843 */
844 fr_assert(current->lhs.vp != NULL);
845
846#ifdef STATIC_ANALYZER
847 if (!current->lhs.vp) return -1;
848#endif
849
850apply_op:
851 /*
852 * All other operators are "modify in place", of the existing current->lhs.vp
853 */
854 while (box) {
855 RDEBUG_ASSIGN(current->lhs.vpt->name, map->op, box);
856 if (current->lhs.vp->da->flags.unsafe) fr_value_box_mark_unsafe(box);
857
858 /*
859 * The apply function also takes care of doing data type upcasting and conversion. So we don't
860 * have to check for compatibility of the data types on the LHS and RHS.
861 */
863 current->lhs.vp,
864 map->op,
865 box) < 0) {
866 fail:
867 RPEDEBUG("Assigning value to %s failed", map->lhs->name);
868 if (pair) tmpl_dcursor_clear(&cc);
869 return -1;
870 }
871
872 if (single) break;
873
874 box = fr_dcursor_next(&cursor);
875 }
876
877done:
878 if (pair) tmpl_dcursor_clear(&cc);
879 fr_value_box_list_talloc_free(&current->rhs.result);
880
881 return 0;
882}
883
884
885/** Simple pair building callback for use with tmpl_dcursors
886 *
887 * Which always appends the new pair to the tail of the list
888 * since it is only called when no matching pairs were found when
889 * walking the list.
890 *
891 * Note that this function is called for all intermediate nodes which are built!
892 *
893 *
894 *
895 * @param[in] parent to allocate new pair within.
896 * @param[in,out] cursor to append new pair to.
897 * @param[in] da of new pair.
898 * @param[in] uctx unused.
899 * @return
900 * - newly allocated #fr_pair_t.
901 * - NULL on error.
902 */
904{
905 fr_pair_t *vp;
906 edit_map_t *current = uctx;
907
909 if (!vp) return NULL;
910
911 current->lhs.vp_parent = parent;
912 current->lhs.vp = vp;
913
914 if (fr_edit_list_insert_pair_tail(current->el, &parent->vp_group, vp) < 0) {
916 return NULL;
917 }
918
919 /*
920 * Tell the cursor that we appended a pair. This
921 * function only gets called when we've ran off of the
922 * end of the list, and can't find the thing we're
923 * looking for. So it's safe at set the current one
924 * here.
925 *
926 * @todo - mainly only because we don't allow creating
927 * foo[4] when there's <3 matching entries. i.e. the
928 * "arrays" here are really lists, so we can't create
929 * "holes" in the list.
930 */
931 fr_dcursor_set_current(cursor, vp);
932
933 return vp;
934}
935
936#define DECLARE(_x) static int _x(request_t *request, unlang_frame_state_edit_t *state, edit_map_t *current)
937
944
945/*
946 * Clean up the current state, and go to the next map.
947 */
949{
950 TALLOC_FREE(current->lhs.to_free);
951 TALLOC_FREE(current->rhs.to_free);
952 fr_pair_list_free(&current->rhs.pair_list);
953 current->lhs.vp = NULL;
954 current->lhs.vp_parent = NULL;
955 current->lhs.vpt = NULL;
956 current->rhs.vpt = NULL;
957
958 current->map = map_list_next(current->map_list, current->map);
959 current->func = expand_lhs;
960
961 /*
962 * Don't touch the other callbacks.
963 */
964
965 return 0;
966}
967
968/*
969 * Validate the RHS of an expansion.
970 */
972{
973 map_t const *map = current->map;
974
975 XDEBUG("%s map %s %s ...", __FUNCTION__, map->lhs->name, fr_tokens[map->op]);
976
977 /*
978 * := is "remove all matching, and then add". So if even if we don't add anything, we still remove things.
979 *
980 * If we deleted the attribute when processing the LHS, then you couldn't reference an attribute
981 * in it's own assignment:
982 *
983 * &foo := %tolower(foo)
984 *
985 * so we have to delay the deletion until the RHS has been fully expanded. But we don't always
986 * delete everything. e.g. if the map is:
987 *
988 * &foo[1] := %tolower(foo[1])
989 *
990 * The we just apply the assignment to the LHS, over-writing it's value.
991 */
992 if ((map->op == T_OP_SET) &&
993 ((tmpl_attr_tail_num(current->lhs.vpt) == NUM_UNSPEC) || (tmpl_attr_tail_num(current->lhs.vpt) > 0) ||
994 !current->map->rhs)) {
995 if (edit_delete_lhs(request, current,
996 (tmpl_attr_tail_num(current->lhs.vpt) == NUM_UNSPEC) || !current->map->rhs) < 0) return -1;
997 }
998
999 /*
1000 * @todo - Realize the RHS box value. By moving the code in apply_edits_to_leaf() to a common function,
1001 * and getting the box dcursor here.
1002 *
1003 * Then, get a cursor for the LHS vp, and loop over it, applying the edits in the operator, using
1004 * the comparisons in the RHS box.
1005 *
1006 * This lets us use array indexes (or more complex things) on the LHS, and means that we don't
1007 * have to realize the VPs and use horrible hacks.
1008 */
1009 if (current->parent && (current->parent->map->op == T_OP_SUB_EQ)) {
1010 fr_assert(current->temporary_pair_list);
1011 fr_assert(tmpl_is_attr(current->lhs.vpt)); /* can only apply edits to real attributes */
1012 fr_assert(map->rhs); /* can only filter on leaf attributes */
1013
1014#if 0
1015 {
1016 // dcursor_init over current->lhs.vpt, using children of current->parent.lhs_vp
1017 //
1018 // and then use the dcursor from the apply_edits_to_leaf() to get value-boxes
1019 rcode = fr_value_box_cmp_op(map->op, &vp->data, box);
1020 if (rcode < 0) return -1;
1021
1022 if (!rcode) continue;
1023
1024 if (fr_edit_list_pair_delete(el, list, vp) < 0) return -1;
1025 }
1026
1027 return next_map(request, state, current);
1028#endif
1029 }
1030
1031 if (fr_type_is_leaf(tmpl_attr_tail_da(current->lhs.vpt)->type)) {
1032 if (apply_edits_to_leaf(request, state, current) < 0) return -1;
1033 } else {
1034 if (apply_edits_to_list(request, state, current) < 0) return -1;
1035 }
1036
1037 return next_map(request, state, current);
1038}
1039
1040/*
1041 * The RHS map is a sublist. Go expand that by creating a child expansion context, and returning to the
1042 * main loop.
1043 */
1045{
1046 map_t const *map = current->map;
1047 edit_map_t *child;
1048
1049 XDEBUG("%s map %s %s ...", __FUNCTION__, map->lhs->name, fr_tokens[map->op]);
1050
1051 /*
1052 * If there's no RHS tmpl, then the RHS is a child list.
1053 */
1054 fr_assert(!map->rhs);
1055
1056 /*
1057 * Fast path: child is empty, we don't need to do anything.
1058 */
1059 if (fr_dlist_empty(&map->child.head)) {
1060 if (fr_type_is_leaf(tmpl_attr_tail_da(current->lhs.vpt)->type) && (map->op != T_OP_SET)) {
1061 REDEBUG("%s[%d] Cannot assign a list to the '%s' data type", MAP_INFO, fr_type_to_str(tmpl_attr_tail_da(current->lhs.vpt)->type));
1062 return -1;
1063 }
1064
1065 return check_rhs(request, state, current);
1066 }
1067
1068 /*
1069 * Allocate a new child structure if necessary.
1070 */
1071 child = current->child;
1072 if (!child) {
1073 MEM(child = talloc_zero(state, edit_map_t));
1074 current->child = child;
1075 child->parent = current;
1076 }
1077
1078 /*
1079 * Initialize the child structure. There's no edit list here, as we're
1080 * creating a temporary pair list. Any edits to this list aren't
1081 * tracked, as it only exists in current->parent->rhs.pair_list.
1082 *
1083 * The parent edit_state_t will take care of applying any edits to the
1084 * parent vp. Any child pairs which aren't used will be freed.
1085 */
1086 child->el = NULL;
1087 child->map_list = &map->child;
1088 child->map = map_list_head(child->map_list);
1089 child->func = expand_lhs;
1090
1091 if (fr_type_is_leaf(tmpl_attr_tail_da(current->lhs.vpt)->type)) {
1092 child->ctx = child;
1093 child->check_lhs = check_lhs_value;
1095 } else {
1096 child->ctx = current->lhs.vp ? (TALLOC_CTX *) current->lhs.vp : (TALLOC_CTX *) child;
1097 child->check_lhs = check_lhs_nested;
1099 child->temporary_pair_list = true;
1100 }
1101
1102 memset(&child->lhs, 0, sizeof(child->lhs));
1103 memset(&child->rhs, 0, sizeof(child->rhs));
1104
1106 fr_value_box_list_init(&child->lhs.result);
1107 fr_value_box_list_init(&child->rhs.result);
1108
1109 /*
1110 * Continue back with the RHS when we're done processing the
1111 * child. The go process the child.
1112 */
1113 current->func = check_rhs;
1114 state->current = child;
1115 RINDENT();
1116 return 0;
1117}
1118
1119
1120/*
1121 * Expand the RHS of an assignment operation.
1122 */
1124{
1125 int rcode;
1126 map_t const *map = current->map;
1127
1128 if (!map->rhs) return expand_rhs_list(request, state, current);
1129
1130 XDEBUG("%s map %s %s %s", __FUNCTION__, map->lhs->name, fr_tokens[map->op], map->rhs->name);
1131
1132 /*
1133 * Turn the RHS into a tmpl_t. This can involve just referencing an existing
1134 * tmpl in map->rhs, or expanding an xlat to get an attribute name.
1135 */
1136 rcode = tmpl_to_values(state, &current->rhs, request, map->rhs);
1137 if (rcode < 0) return -1;
1138
1139 if (rcode == 1) {
1140 current->func = check_rhs;
1141 return 1;
1142 }
1143
1144 return check_rhs(request, state, current);
1145}
1146
1147/*
1148 * The LHS is a value, and the parent is a leaf. There is no RHS.
1149 *
1150 * Do some validations, and move the value-boxes to the parents result list.
1151 */
1153{
1154 map_t const *map = current->map;
1155 fr_value_box_t *box;
1156 fr_pair_t *vp;
1157 tmpl_t const *vpt;
1159 fr_dcursor_t cursor;
1160
1161 fr_assert(current->parent);
1162
1163 XDEBUG("%s map %s", __FUNCTION__, map->lhs->name);
1164
1165 if (tmpl_is_data(map->lhs)) {
1166 vpt = map->lhs;
1167
1168 data:
1169 MEM(box = fr_value_box_alloc_null(state));
1170 if (fr_value_box_copy(box, box, tmpl_value(vpt)) < 0) return -1;
1171
1172 fr_value_box_list_insert_tail(&current->parent->rhs.result, box);
1173
1174 return next_map(request, state, current);
1175 }
1176
1177 if (!current->lhs.vpt) {
1178 vpt = map->lhs;
1179
1180 /*
1181 *
1182 */
1183 if (tmpl_is_xlat(vpt)) return next_map(request,state, current);
1184
1185 attr:
1187
1188 /*
1189 * Loop over the attributes, copying their value-boxes to the parent list.
1190 */
1191 vp = tmpl_dcursor_init(NULL, request, &cc, &cursor, request, vpt);
1192 while (vp) {
1193 MEM(box = fr_value_box_alloc_null(state));
1194 if (fr_value_box_copy(box, box, &vp->data) < 0) return -1;
1195
1196 fr_value_box_list_insert_tail(&current->parent->rhs.result, box);
1197
1198 vp = fr_dcursor_next(&cursor);
1199 }
1200 tmpl_dcursor_clear(&cc);
1201
1202 return next_map(request, state, current);
1203 }
1204
1205 vpt = current->lhs.vpt;
1206
1207 if (tmpl_is_data(vpt)) goto data;
1208
1209 goto attr;
1210}
1211
1212/*
1213 * We've expanded the LHS (xlat or exec) into a value-box list. The result gets moved to the parent
1214 * result list.
1215 *
1216 * There's no RHS, so once the LHS has been expanded, we jump immediately to the next entry.
1217 */
1219{
1220 fr_dict_attr_t const *da;
1222 fr_value_box_t *box = fr_value_box_list_head(&current->lhs.result);
1223 fr_value_box_t *dst;
1224 fr_sbuff_unescape_rules_t *erules = NULL;
1225
1226 fr_assert(current->parent);
1227
1228 if (!box) {
1229 RWDEBUG("Failed expanding result");
1230 return -1;
1231 }
1232
1233 fr_assert(tmpl_is_attr(current->parent->lhs.vpt));
1234
1235 /*
1236 * There's only one value-box, just use it as-is. We let the parent handler complain about being
1237 * able to parse (or not) the value.
1238 */
1239 if (!fr_value_box_list_next(&current->lhs.result, box)) goto done;
1240
1241 /*
1242 * Figure out how to parse the string.
1243 */
1244 da = tmpl_attr_tail_da(current->parent->lhs.vpt);
1245 if (fr_type_is_structural(da->type)) {
1246 fr_assert(da->type == FR_TYPE_GROUP);
1247
1249
1250 } else if (fr_type_is_variable_size(da->type)) {
1251 type = da->type;
1252
1253 } else {
1255 }
1256
1257 /*
1258 * Mash all of the results together.
1259 */
1260 if (fr_value_box_list_concat_in_place(box, box, &current->lhs.result, type, FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
1261 RWDEBUG("Failed converting result to '%s' - no memory", fr_type_to_str(type));
1262 return -1;
1263 }
1264
1265 /*
1266 * Strings, etc. get assigned to the parent. Fixed-size things ger parsed according to their values / enums.
1267 */
1268 if (!fr_type_is_fixed_size(da->type)) {
1269 done:
1270 fr_value_box_list_move(&current->parent->rhs.result, &current->lhs.result);
1271 return next_map(request, state, current);
1272 }
1273
1274 /*
1275 * Try to re-parse the box as the destination data type.
1276 */
1277 MEM(dst = fr_value_box_alloc(state, type, da));
1278
1279 erules = fr_value_unescape_by_quote[current->map->lhs->quote];
1280
1281 if (fr_value_box_from_str(dst, dst, da->type, da, box->vb_strvalue, box->vb_length, erules) < 0) {
1282 RWDEBUG("Failed converting result to '%s' - %s", fr_type_to_str(type), fr_strerror());
1283 return -1;
1284 }
1286
1287 fr_value_box_list_talloc_free(&current->lhs.result);
1288 fr_value_box_list_insert_tail(&current->parent->rhs.result, dst);
1289 return next_map(request, state, current);
1290}
1291
1292/*
1293 * Check the LHS of an assignment, for
1294 *
1295 * foo = { bar = baz } LHS bar
1296 *
1297 * There are more limitations here on the attr / op / value format then for the top-level check_lhs().
1298 */
1300{
1301 map_t const *map = current->map;
1302
1303 fr_assert(current->parent != NULL);
1304
1305 XDEBUG("%s map %s", __FUNCTION__, map->lhs->name);
1306
1307 /*
1308 * Don't create the leaf. The apply_edits_to_leaf() function will create them after the RHS has
1309 * been expanded.
1310 */
1311 if (fr_type_is_leaf(tmpl_attr_tail_da(current->lhs.vpt)->type)) {
1312 return expand_rhs(request, state, current);
1313 }
1314
1315 /*
1316 * We have a parent, so we know that attribute exist. Which means that we don't need to call a
1317 * cursor function to create this VP.
1318 */
1319
1320 /*
1321 * We create this VP in the "current" context, so that it's freed on
1322 * error. If we create it in the LHS VP context, then we have to
1323 * manually free rhs.pair_list on any error. Creating it in the
1324 * "current" context means we have to reparent it when we move it to the
1325 * parent list, but fr_edit_list_apply_list_assignment() does that
1326 * anyways.
1327 */
1328 MEM(current->lhs.vp = fr_pair_afrom_da(current->ctx, tmpl_attr_tail_da(current->lhs.vpt)));
1329 fr_pair_append(&current->parent->rhs.pair_list, current->lhs.vp);
1330 current->lhs.vp->op = map->op;
1331
1332 return expand_rhs(request, state, current);
1333}
1334
1335/*
1336 * The LHS tmpl is now an attribute reference. Do some sanity checks on tmpl_attr_tail_num(), operators, etc.
1337 * Once that's done, go expand the RHS.
1338 */
1340{
1341 map_t const *map = current->map;
1342 int err;
1343 fr_pair_t *vp;
1345 fr_dcursor_t cursor;
1346
1347 current->lhs.create = false;
1348 current->lhs.vp = NULL;
1349
1350 XDEBUG("%s map %s %s ...", __FUNCTION__, map->lhs->name, fr_tokens[map->op]);
1351
1352 /*
1353 * Create the attribute, including any necessary parents.
1354 */
1355 if ((map->op == T_OP_EQ) ||
1356 (fr_type_is_leaf(tmpl_attr_tail_da(current->lhs.vpt)->type) && fr_comparison_op[map->op])) {
1357 if (tmpl_attr_tail_num(current->lhs.vpt) == NUM_UNSPEC) {
1358 current->lhs.create = true;
1359
1360 /*
1361 * Don't go to expand_rhs(), as we have to see if the attribute exists.
1362 */
1363 }
1364
1365 } else if (map->op == T_OP_SET) {
1366 if (tmpl_attr_tail_num(current->lhs.vpt) == NUM_UNSPEC) {
1367 current->lhs.create = true;
1368 return expand_rhs(request, state, current);
1369 }
1370
1371 /*
1372 * Else we're doing something like:
1373 *
1374 * &foo[1] := bar
1375 *
1376 * the attribute has to exist, and we modify its value as a leaf.
1377 *
1378 * If the RHS is a list, we can set the children for a LHS structural type.
1379 * But if the LHS is a leaf, then we can't do:
1380 *
1381 * &foo[3] := { a, b, c}
1382 *
1383 * because foo[3] is a single leaf value, not a list.
1384 */
1385 if (!map->rhs && fr_type_is_leaf(tmpl_attr_tail_da(current->lhs.vpt)->type) &&
1386 (map_list_num_elements(&map->child) > 0)) {
1387 RWDEBUG("Cannot set one entry to multiple values for %s", current->lhs.vpt->name);
1388 return -1;
1389 }
1390
1391 } else if (map->op == T_OP_ADD_EQ) {
1392 /*
1393 * For "+=", if there's no existing attribute, create one, and rewrite the operator we
1394 * apply to ":=". Which also means moving the operator be in edit_map_t, and then updating the
1395 * "apply" functions above to use that for the operations, but map->op for printing.
1396 *
1397 * This allows "foo += 4" to set "foo := 4" when the attribute doesn't exist. It also allows us
1398 * to do list appending to an empty list. But likely only for strings, octets, and numbers.
1399 * Nothing much else makes sense.
1400 */
1401
1402 switch (tmpl_attr_tail_da(current->lhs.vpt)->type) {
1403 case FR_TYPE_NUMERIC:
1404 case FR_TYPE_OCTETS:
1405 case FR_TYPE_STRING:
1406 case FR_TYPE_STRUCTURAL:
1407 current->lhs.create = true;
1408 break;
1409
1410 default:
1411 break;
1412 }
1413 }
1414
1415 /*
1416 * Find the VP. If the operation is "=" or ":=", then it's OK for the VP to not exist.
1417 *
1418 * @todo - put the cursor into the LHS, and then set lhs.vp == NULL
1419 * use the cursor in apply_edits_to_leaf()
1420 */
1422 vp = tmpl_dcursor_init(&err, current->ctx, &cc, &cursor, request, current->lhs.vpt);
1423 tmpl_dcursor_clear(&cc);
1424 if (!vp) {
1425 if (!current->lhs.create) {
1426 RWDEBUG("Failed finding %s", current->lhs.vpt->name);
1427 return -1;
1428 }
1429
1430 /*
1431 * Else we need to create it.
1432 */
1433 return expand_rhs(request, state, current);
1434
1435 } else if (current->lhs.create) {
1436 /*
1437 * &foo[1] := bar
1438 * &foo = bar
1439 */
1440 current->lhs.create = false;
1441
1442 if (map->rhs && fr_type_is_structural(vp->vp_type) && tmpl_is_exec(map->rhs)) {
1443 int rcode;
1444
1445 current->lhs.vp = vp;
1446 current->lhs.vp_parent = fr_pair_parent(vp);
1447
1448 rcode = tmpl_to_values(state, &current->rhs, request, map->rhs);
1449 if (rcode < 0) return -1;
1450
1451 if (rcode == 1) {
1452 current->func = check_rhs;
1453 return 1;
1454 }
1455
1456 return expand_rhs(request, state, current);
1457 }
1458
1459 /*
1460 * We found it, but the attribute already exists. This
1461 * is a NOOP, where we ignore this assignment.
1462 */
1463 if (map->op == T_OP_EQ) {
1464 return next_map(request, state, current);
1465 }
1466
1467 /*
1468 * &foo[1] exists, don't bother deleting it. Just over-write its value.
1469 */
1470 fr_assert((map->op == T_OP_SET) || (map->op == T_OP_ADD_EQ) || fr_comparison_op[map->op]);
1471// fr_assert((map->op == T_OP_ADD_EQ) || tmpl_attr_tail_num(map->lhs) != NUM_UNSPEC);
1472
1473 // &control := ...
1474 }
1475
1476 /*
1477 * We forbid operations on immutable leaf attributes.
1478 *
1479 * If a list contains an immutable attribute, then we can still operate on the list, but instead
1480 * we look at each VP we're operating on.
1481 */
1482 if (fr_type_is_leaf(vp->vp_type) && vp->vp_immutable) {
1483 RWDEBUG("Cannot modify immutable value for %s", current->lhs.vpt->name);
1484 return -1;
1485 }
1486
1487 /*
1488 * We found an existing attribute, with a modification operator.
1489 */
1490 current->lhs.vp = vp;
1491 current->lhs.vp_parent = fr_pair_parent(current->lhs.vp);
1492 return expand_rhs(request, state, current);
1493}
1494
1495/*
1496 * We've expanding the LHS into a string. Now convert it to an attribute.
1497 *
1498 * foo := bar LHS foo
1499 * foo = { bar = baz } LHS bar
1500 */
1502{
1503 REXDENT();
1504
1505 if (tmpl_attr_from_result(state, current->map, &current->lhs, request) < 0) return -1;
1506
1507 return current->check_lhs(request, state, current);
1508}
1509
1510/*
1511 * Take the LHS of a map, and figure out what it is. Data and attributes are immediately processed.
1512 * xlats and execs are expanded, and then their expansion is checked.
1513 *
1514 * This function is called for all variants of the LHS:
1515 *
1516 * foo := bar LHS foo
1517 * foo = { bar = baz } LHS bar
1518 * foo = { 1, 2, 3, 4 } LHS 1, 2, etc.
1519 *
1520 */
1522{
1523 int rcode;
1524 map_t const *map = current->map;
1525
1526 XDEBUG("%s map %s %s ...", __FUNCTION__, map->lhs->name, fr_tokens[map->op]);
1527
1528 fr_assert(fr_value_box_list_empty(&current->lhs.result)); /* Should have been consumed */
1529 fr_assert(fr_value_box_list_empty(&current->rhs.result)); /* Should have been consumed */
1530
1531 rcode = tmpl_to_values(state, &current->lhs, request, map->lhs);
1532 if (rcode < 0) return -1;
1533
1534 if (rcode == 1) {
1535 current->func = current->expanded_lhs;
1536 return 1;
1537 }
1538
1539 return current->check_lhs(request, state, current);
1540}
1541
1542/** Apply a map (recursively) to a request.
1543 *
1544 * @param[out] p_result The rcode indicating what the result
1545 * of the operation was.
1546 * @param[in] request The current request.
1547 * @param[in] frame Current stack frame.
1548 * @return
1549 * - UNLANG_ACTION_CALCULATE_RESULT changes were applied.
1550 * - UNLANG_ACTION_PUSHED_CHILD async execution of an expansion is required.
1551 */
1553{
1554 unlang_frame_state_edit_t *state = talloc_get_type_abort(frame->state, unlang_frame_state_edit_t);
1555
1556 /*
1557 * Keep running the "expand map" function until done.
1558 */
1559 while (state->current) {
1560 while (state->current->map) {
1561 int rcode;
1562
1563 if (!state->current->map->rhs) {
1564 XDEBUG("MAP %s ...", state->current->map->lhs->name);
1565 } else {
1566 XDEBUG("MAP %s ... %s", state->current->map->lhs->name, state->current->map->rhs->name);
1567 }
1568
1569 rcode = state->current->func(request, state, state->current);
1570 if (rcode < 0) {
1571 RINDENT_RESTORE(request, state);
1572
1573 /*
1574 * Expansions, etc. failures are SOFT failures, which undo the edit
1575 * operations, but otherwise do not affect the interpreter.
1576 *
1577 * However, if the caller asked for the actual result, return that, too.
1578 */
1579 if (state->success) *state->success = false;
1580
1581 if (state->ours) fr_edit_list_abort(state->el);
1582 TALLOC_FREE(frame->state);
1583 repeatable_clear(frame);
1584 *p_result = RLM_MODULE_FAIL;
1585
1587 }
1588
1589 if (rcode == 1) {
1590 repeatable_set(frame);
1592 }
1593 }
1594
1595 /*
1596 * Stop if there's no parent to process.
1597 */
1598 if (!state->current->parent) break;
1599
1600 state->current = state->current->parent;
1601 REXDENT(); /* "push child" has called RINDENT */
1602 }
1603
1604 /*
1605 * Freeing the edit list will automatically commit the edits. i.e. trash the undo list, and
1606 * leave the edited pairs in place.
1607 */
1608
1609 RINDENT_RESTORE(request, state);
1610
1611 *p_result = RLM_MODULE_NOOP;
1612 if (state->success) *state->success = true;
1614}
1615
1616static void edit_state_init_internal(request_t *request, unlang_frame_state_edit_t *state, fr_edit_list_t *el, map_list_t const *map_list)
1617{
1618 edit_map_t *current = &state->first;
1619
1620 state->current = current;
1621 fr_value_box_list_init(&current->lhs.result);
1622 fr_value_box_list_init(&current->rhs.result);
1623
1624 /*
1625 * The edit list creates a local pool which should
1626 * generally be large enough for most edits.
1627 */
1628 if (!el) {
1629 MEM(state->el = fr_edit_list_alloc(state, map_list_num_elements(map_list), NULL));
1630 state->ours = true;
1631 } else {
1632 state->el = el;
1633 state->ours = false;
1634 }
1635
1636 current->ctx = state;
1637 current->el = state->el;
1638 current->map_list = map_list;
1639 current->map = map_list_head(current->map_list);
1640 fr_pair_list_init(&current->rhs.pair_list);
1641 current->func = expand_lhs;
1642 current->check_lhs = check_lhs;
1643 current->expanded_lhs = expanded_lhs_attribute;
1644
1645 /*
1646 * Save current indentation for the error path.
1647 */
1648 RINDENT_SAVE(state, request);
1649}
1650
1651/** Execute an update block
1652 *
1653 * Update blocks execute in two phases, first there's an evaluation phase where
1654 * each input map is evaluated, outputting one or more modification maps. The modification
1655 * maps detail a change that should be made to a list in the current request.
1656 * The request is not modified during this phase.
1657 *
1658 * The second phase applies those modification maps to the current request.
1659 * This re-enables the atomic functionality of update blocks provided in v2.x.x.
1660 * If one map fails in the evaluation phase, no more maps are processed, and the current
1661 * result is discarded.
1662 */
1664{
1666 unlang_frame_state_edit_t *state = talloc_get_type_abort(frame->state, unlang_frame_state_edit_t);
1668
1669 edit_state_init_internal(request, state, el, &edit->maps);
1670
1671 /*
1672 * Call process_edit to do all of the work.
1673 */
1674 frame_repeat(frame, process_edit);
1675 return process_edit(p_result, request, frame);
1676}
1677
1678
1679/** Push a map onto the stack for edit evaluation
1680 *
1681 * If the "success" variable returns "false", the caller should call fr_edit_list_abort().
1682 *
1683 * If the "success" variable returns "true", the caller can free the edit list (or rely on talloc to do that)
1684 * and the transaction will be finalized.
1685 *
1686 * @param[in] request The current request.
1687 * @param[out] success Whether or not the edit succeeded
1688 * @param[in] el Edit list which can be used to apply multiple edits
1689 * @param[in] map_list The map list to process
1690 */
1691int unlang_edit_push(request_t *request, bool *success, fr_edit_list_t *el, map_list_t const *map_list)
1692{
1693 unlang_stack_t *stack = request->stack;
1694 unlang_stack_frame_t *frame;
1696
1697 unlang_edit_t *edit;
1698
1699 static unlang_t edit_instruction = {
1701 .name = "edit",
1702 .debug_name = "edit",
1703 .actions = {
1704 .actions = {
1705 [RLM_MODULE_REJECT] = 0,
1706 [RLM_MODULE_FAIL] = 0,
1707 [RLM_MODULE_OK] = 0,
1708 [RLM_MODULE_HANDLED] = 0,
1709 [RLM_MODULE_INVALID] = 0,
1710 [RLM_MODULE_DISALLOW] = 0,
1711 [RLM_MODULE_NOTFOUND] = 0,
1712 [RLM_MODULE_NOOP] = 0,
1713 [RLM_MODULE_UPDATED] = 0
1714 },
1715 .retry = RETRY_INIT,
1716 },
1717 };
1718
1719 MEM(edit = talloc(stack, unlang_edit_t));
1720 *edit = (unlang_edit_t) {
1721 .self = edit_instruction,
1722 };
1723 map_list_init(&edit->maps);
1724
1725 /*
1726 * Push a new edit frame onto the stack
1727 */
1729 RLM_MODULE_NOT_SET, UNLANG_NEXT_STOP, false) < 0) return -1;
1730
1731 frame = &stack->frame[stack->depth];
1732 state = talloc_get_type_abort(frame->state, unlang_frame_state_edit_t);
1733
1734 edit_state_init_internal(request, state, el, map_list);
1735 state->success = success;
1736
1737 return 0;
1738}
1739
1741{
1743 &(unlang_op_t){
1744 .name = "edit",
1745 .interpret = unlang_edit_state_init,
1746 .frame_state_size = sizeof(unlang_frame_state_edit_t),
1747 .frame_state_type = "unlang_frame_state_edit_t",
1748 });
1749}
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_PUSHED_CHILD
unlang_t pushed a new child onto the stack, execute it instead of continuing.
Definition action.h:39
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
Definition action.h:37
#define RCSID(id)
Definition build.h:485
#define UNUSED
Definition build.h:317
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
Definition dcursor.h:288
static void * fr_dcursor_next_peek(fr_dcursor_t *cursor)
Return the next iterator item without advancing the cursor.
Definition dcursor.h:303
#define fr_dcursor_init(_cursor, _head)
Initialise a cursor.
Definition dcursor.h:732
static void * fr_dcursor_set_current(fr_dcursor_t *cursor, void *item)
Set the cursor to a specified item.
Definition dcursor.h:353
#define MEM(x)
Definition debug.h:36
static fr_slen_t err
Definition dict.h:833
bool fr_dict_attr_can_contain(fr_dict_attr_t const *parent, fr_dict_attr_t const *child)
See if a structural da is allowed to contain another da.
Definition dict_util.c:4877
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
Definition dict_util.c:2402
static bool fr_dlist_empty(fr_dlist_head_t const *list_head)
Check whether a list has any items.
Definition dlist.h:501
map_list_t maps
Head of the map list.
Definition edit_priv.h:33
static unlang_t * unlang_edit_to_generic(unlang_edit_t const *p)
Definition edit_priv.h:45
static unlang_edit_t * unlang_generic_to_edit(unlang_t const *p)
Cast a generic structure to the edit extension.
Definition edit_priv.h:39
unlang_t self
Definition edit_priv.h:32
int unlang_interpret_push(request_t *request, unlang_t const *instruction, rlm_rcode_t default_rcode, bool do_next_sibling, bool top_frame)
Push a new frame onto the stack.
Definition interpret.c:159
#define REXDENT()
Exdent (unindent) R* messages by one level.
Definition log.h:443
#define RWDEBUG(fmt,...)
Definition log.h:361
#define RINDENT_SAVE(_x, _request)
Save indentation for later restoral.
Definition log.h:388
#define RINDENT_RESTORE(_request, _x)
Definition log.h:392
#define RPEDEBUG(fmt,...)
Definition log.h:376
#define RPWDEBUG(fmt,...)
Definition log.h:366
#define RINDENT()
Indent R* messages by one level.
Definition log.h:430
void unlang_register(int type, unlang_op_t *op)
Register an operation with the interpreter.
Definition base.c:63
talloc_free(reap)
int fr_debug_lvl
Definition log.c:40
@ L_DBG_LVL_2
2nd highest priority debug messages (-xx | -X).
Definition log.h:71
static char * stack[MAX_STACK]
Definition radmin.c:158
fr_type_t
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_OCTETS
Raw octets.
@ FR_TYPE_GROUP
A grouping of other attributes.
long int ssize_t
int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from)
Duplicate a list of pairs.
Definition pair.c:2321
fr_pair_list_t * fr_pair_parent_list(fr_pair_t const *vp)
Return a pointer to the parent pair list.
Definition pair.c:929
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
Definition pair.c:1347
fr_pair_t * fr_pair_parent(fr_pair_t const *vp)
Return a pointer to the parent pair.
Definition pair.c:944
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
Definition pair.c:285
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:46
bool fr_pair_immutable(fr_pair_t const *vp)
Definition pair.c:2282
fr_pair_t * fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp)
Copy a single valuepair.
Definition pair.c:491
fr_value_box_t * fr_pair_dcursor_nested_init(fr_dcursor_t *cursor, fr_dcursor_t *parent)
Initialises a special dcursor over another cursor which returns fr_pair_t, but we return fr_value_box...
Definition pair.c:1300
fr_slen_t fr_pair_list_afrom_substr(fr_pair_parse_t const *root, fr_pair_parse_t *relative, fr_sbuff_t *in)
Parse a fr_pair_list_t from a substring.
struct fr_pair_parse_s fr_pair_parse_t
TALLOC_CTX * ctx
Definition pair_legacy.h:43
#define fr_assert(_expr)
Definition rad_assert.h:38
static rc_request_t * current
static bool done
Definition radclient.c:81
#define REDEBUG(fmt,...)
Definition radclient.h:52
#define RDEBUG2(fmt,...)
Definition radclient.h:54
#define RDEBUG(fmt,...)
Definition radclient.h:53
char const * name
Test name (as specified in the request).
Definition radclient.h:101
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
@ RLM_MODULE_INVALID
The module considers the request invalid.
Definition rcode.h:45
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:43
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:42
@ RLM_MODULE_DISALLOW
Reject the request (user is locked out).
Definition rcode.h:46
@ RLM_MODULE_REJECT
Immediately reject the request.
Definition rcode.h:41
@ RLM_MODULE_NOTFOUND
User not found.
Definition rcode.h:47
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition rcode.h:49
@ RLM_MODULE_NOT_SET
Error resolving rcode (should not be returned by modules).
Definition rcode.h:51
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition rcode.h:48
@ RLM_MODULE_HANDLED
The module handled the request, so stop.
Definition rcode.h:44
fr_dict_attr_t const * request_attr_request
Definition request.c:43
fr_dict_attr_t const * request_attr_control
Definition request.c:45
fr_dict_attr_t const * request_attr_state
Definition request.c:46
fr_dict_attr_t const * request_attr_reply
Definition request.c:44
#define FR_SBUFF_IN(_start, _len_or_end)
Set of parsing rules for *unescape_until functions.
static int16_t tmpl_attr_tail_num(tmpl_t const *vpt)
Return the last attribute reference's attribute number.
Definition tmpl.h:885
#define tmpl_is_xlat(vpt)
Definition tmpl.h:210
#define tmpl_value(_tmpl)
Definition tmpl.h:937
#define tmpl_is_attr(vpt)
Definition tmpl.h:208
#define NUM_ALL
Definition tmpl.h:391
#define tmpl_is_exec(vpt)
Definition tmpl.h:211
#define tmpl_xlat(_tmpl)
Definition tmpl.h:930
ssize_t tmpl_afrom_attr_str(TALLOC_CTX *ctx, tmpl_attr_error_t *err, tmpl_t **out, char const *name, tmpl_rules_t const *rules))
Parse a string into a TMPL_TYPE_ATTR_* type tmpl_t.
@ TMPL_TYPE_ATTR
Reference to one or more attributes.
Definition tmpl.h:142
@ TMPL_TYPE_XLAT
Pre-parsed xlat expansion.
Definition tmpl.h:146
@ TMPL_TYPE_EXEC
Callout to an external script or program.
Definition tmpl.h:150
@ TMPL_TYPE_DATA
Value in native boxed format.
Definition tmpl.h:138
#define tmpl_is_data(vpt)
Definition tmpl.h:206
void tmpl_debug(tmpl_t const *vpt)
static fr_slen_t vpt
Definition tmpl.h:1269
#define NUM_UNSPEC
Definition tmpl.h:390
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
Definition tmpl.h:801
int pair_append_by_tmpl_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, tmpl_t const *vpt, bool skip_list))
Allocate and insert a leaf vp from a tmpl_t, building the parent vps if needed.
Definition tmpl_eval.c:964
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:332
fr_aka_sim_id_type_t type
fr_pair_t * vp
Value pair map.
Definition map.h:77
fr_token_t op
The operator that controls insertion of the dst attribute.
Definition map.h:82
tmpl_t * lhs
Typically describes the attribute to add, modify or compare.
Definition map.h:78
map_list_t child
parent map, for nested ones
Definition map.h:89
tmpl_t * rhs
Typically describes a literal value or a src attribute to copy or compare.
Definition map.h:79
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
Definition pair.h:69
int unlang_tmpl_push(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *tmpl, unlang_tmpl_args_t *args)
Push a tmpl onto the stack for evaluation.
Definition tmpl.c:261
void tmpl_dcursor_clear(tmpl_dcursor_ctx_t *cc)
Clear any temporary state allocations.
#define tmpl_dcursor_build_init(_err, _ctx, _cc, _cursor, _request, _vpt, _build, _uctx)
#define tmpl_dcursor_init(_err, _ctx, _cc, _cursor, _request, _vpt)
Maintains state between cursor calls.
goto success
Definition tmpl_eval.c:1443
char const * fr_tokens[T_TOKEN_LAST]
Definition token.c:77
const bool fr_comparison_op[T_TOKEN_LAST]
Definition token.c:197
@ T_OP_SUB_EQ
Definition token.h:70
@ T_SINGLE_QUOTED_STRING
Definition token.h:122
@ T_OP_EQ
Definition token.h:83
@ T_OP_SET
Definition token.h:84
@ T_OP_ADD_EQ
Definition token.h:69
@ T_DOUBLE_QUOTED_STRING
Definition token.h:121
fr_edit_list_t * unlang_interpret_edit_list(request_t *request)
static fr_event_list_t * el
TALLOC_CTX * ctx
Definition edit.c:68
fr_pair_t * vp_parent
parent of the current VP
Definition edit.c:55
int(* unlang_edit_expand_t)(request_t *request, unlang_frame_state_edit_t *state, edit_map_t *current)
Definition edit.c:63
static int check_rhs(request_t *request, unlang_frame_state_edit_t *state, edit_map_t *current)
Definition edit.c:971
static unlang_action_t unlang_edit_state_init(rlm_rcode_t *p_result, request_t *request, unlang_stack_frame_t *frame)
Execute an update block.
Definition edit.c:1663
tmpl_t const * vpt
expanded tmpl
Definition edit.c:51
edit_map_t * parent
Definition edit.c:69
struct unlang_frame_state_edit_s unlang_frame_state_edit_t
Definition edit.c:61
static int expand_rhs_list(request_t *request, unlang_frame_state_edit_t *state, edit_map_t *current)
Definition edit.c:1044
static void edit_state_init_internal(request_t *request, unlang_frame_state_edit_t *state, fr_edit_list_t *el, map_list_t const *map_list)
Definition edit.c:1616
static void edit_debug_attr_vp(request_t *request, fr_pair_t *vp, map_t const *map)
Definition edit.c:186
static unlang_action_t process_edit(rlm_rcode_t *p_result, request_t *request, unlang_stack_frame_t *frame)
Apply a map (recursively) to a request.
Definition edit.c:1552
map_list_t const * map_list
Definition edit.c:72
fr_pair_list_t pair_list
for structural attributes
Definition edit.c:56
void unlang_edit_init(void)
Definition edit.c:1740
static int expand_lhs(request_t *request, unlang_frame_state_edit_t *state, edit_map_t *current)
Definition edit.c:1521
unlang_edit_expand_t func
for process state
Definition edit.c:80
static int next_map(UNUSED request_t *request, UNUSED unlang_frame_state_edit_t *state, edit_map_t *current)
Definition edit.c:948
tmpl_t * to_free
tmpl to free.
Definition edit.c:52
static int check_lhs(request_t *request, unlang_frame_state_edit_t *state, edit_map_t *current)
Definition edit.c:1339
int unlang_edit_push(request_t *request, bool *success, fr_edit_list_t *el, map_list_t const *map_list)
Push a map onto the stack for edit evaluation.
Definition edit.c:1691
#define XDEBUG(...)
fr_pair_t editing
Definition edit.c:40
static int check_lhs_value(request_t *request, unlang_frame_state_edit_t *state, edit_map_t *current)
Definition edit.c:1152
#define RDEBUG_ASSIGN(_name, _op, _box)
Definition edit.c:45
static int check_lhs_nested(request_t *request, unlang_frame_state_edit_t *state, edit_map_t *current)
Definition edit.c:1299
static int expand_rhs(request_t *request, unlang_frame_state_edit_t *state, edit_map_t *current)
Definition edit.c:1123
#define MAP_INFO
Definition edit.c:99
static int expanded_lhs_value(request_t *request, unlang_frame_state_edit_t *state, edit_map_t *current)
Definition edit.c:1218
static int apply_edits_to_list(request_t *request, unlang_frame_state_edit_t *state, edit_map_t *current)
Definition edit.c:267
static int edit_delete_lhs(request_t *request, edit_map_t *current, bool delete)
Definition edit.c:532
map_t const * map
the map to evaluate
Definition edit.c:73
static fr_pair_t * edit_list_pair_build(fr_pair_t *parent, fr_dcursor_t *cursor, fr_dict_attr_t const *da, void *uctx)
Simple pair building callback for use with tmpl_dcursors.
Definition edit.c:903
bool temporary_pair_list
Definition edit.c:75
fr_edit_list_t * el
edit list
Definition edit.c:66
fr_edit_list_t * el
edit list
Definition edit.c:89
static bool pair_is_editable(request_t *request, fr_pair_t *vp)
Definition edit.c:516
static int tmpl_attr_from_result(TALLOC_CTX *ctx, map_t const *map, edit_result_t *out, request_t *request)
Definition edit.c:106
static void edit_debug_attr_list(request_t *request, fr_pair_list_t const *list, map_t const *map)
Definition edit.c:221
bool create
whether we need to create the VP
Definition edit.c:53
fr_value_box_list_t result
result of expansion
Definition edit.c:50
unlang_edit_expand_t check_lhs
for special cases
Definition edit.c:81
static int tmpl_to_values(TALLOC_CTX *ctx, edit_result_t *out, request_t *request, tmpl_t const *vpt)
Definition edit.c:150
static int edit_create_lhs_vp(request_t *request, TALLOC_CTX *ctx, edit_map_t *current)
Definition edit.c:236
static int expanded_lhs_attribute(request_t *request, unlang_frame_state_edit_t *state, edit_map_t *current)
Definition edit.c:1501
edit_map_t * child
Definition edit.c:70
bool * success
whether or not the edit succeeded
Definition edit.c:90
unlang_edit_expand_t expanded_lhs
for special cases
Definition edit.c:82
edit_map_t * current
what we're currently doing.
Definition edit.c:95
static int apply_edits_to_leaf(request_t *request, unlang_frame_state_edit_t *state, edit_map_t *current)
Definition edit.c:621
#define DECLARE(_x)
Definition edit.c:936
edit_result_t rhs
RHS child entries.
Definition edit.c:78
edit_result_t lhs
LHS child entries.
Definition edit.c:77
fr_pair_t * vp
VP referenced by tmpl.
Definition edit.c:54
State of an edit block.
Definition edit.c:88
int unlang_xlat_push(TALLOC_CTX *ctx, bool *p_success, fr_value_box_list_t *out, request_t *request, xlat_exp_head_t const *xlat, bool top_frame)
Push a pre-compiled xlat onto the stack for evaluation.
Definition xlat.c:282
static void repeatable_clear(unlang_stack_frame_t *frame)
void * state
Stack frame specialisations.
#define UNLANG_NEXT_STOP
Definition unlang_priv.h:92
@ UNLANG_TYPE_EDIT
edit VPs in place. After 20 years!
Definition unlang_priv.h:76
static void frame_repeat(unlang_stack_frame_t *frame, unlang_process_t process)
Mark the current stack frame up for repeat, and set a new process function.
unlang_t const * instruction
The unlang node we're evaluating.
static void repeatable_set(unlang_stack_frame_t *frame)
unlang_type_t type
The specialisation of this node.
An unlang operation.
A node in a graph of unlang_op_t (s) that we execute.
Our interpreter stack, as distinct from the C stack.
An unlang stack associated with a request.
int fr_edit_list_apply_list_assignment(fr_edit_list_t *el, fr_pair_t *dst, fr_token_t op, fr_pair_list_t *src, bool copy)
Apply operators to lists.
Definition edit.c:1491
int fr_edit_list_pair_delete(fr_edit_list_t *el, fr_pair_list_t *list, fr_pair_t *vp)
Delete a VP.
Definition edit.c:598
void fr_edit_list_abort(fr_edit_list_t *el)
Abort the entries in an edit list.
Definition edit.c:193
int fr_edit_list_free_pair_children(fr_edit_list_t *el, fr_pair_t *vp)
Free children of a structural pair.
Definition edit.c:713
int fr_edit_list_apply_pair_assignment(fr_edit_list_t *el, fr_pair_t *vp, fr_token_t op, fr_value_box_t const *in)
Apply operators to pairs.
Definition edit.c:980
fr_edit_list_t * fr_edit_list_alloc(TALLOC_CTX *ctx, int hint, fr_edit_list_t *parent)
Allocate an edit list.
Definition edit.c:794
Track a series of edits.
Definition edit.c:101
#define fr_edit_list_insert_pair_tail(_el, _list, _vp)
Definition edit.h:51
#define PAIR_VERIFY(_x)
Definition pair.h:191
fr_pair_t * fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item))
Get the next item in a valuepair list after a specific entry.
Definition pair_inline.c:69
#define fr_pair_list_foreach(_list_head, _iter)
Iterate over the contents of a fr_pair_list_t.
Definition pair.h:261
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src)
Appends a list of fr_pair_t from a temporary list to a destination list.
static fr_slen_t parent
Definition pair.h:845
#define RETRY_INIT
Definition retry.h:39
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:553
void fr_strerror_clear(void)
Clears all pending messages from the talloc pools.
Definition strerror.c:576
#define fr_type_is_group(_x)
Definition types.h:355
#define fr_type_is_variable_size(_x)
Definition types.h:367
#define fr_type_is_structural(_x)
Definition types.h:371
#define fr_type_is_fixed_size(_x)
Definition types.h:366
#define FR_TYPE_STRUCTURAL
Definition types.h:296
#define fr_type_is_null(_x)
Definition types.h:326
#define fr_type_is_leaf(_x)
Definition types.h:372
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
Definition types.h:433
#define FR_TYPE_NUMERIC
Definition types.h:286
void fr_value_box_mark_unsafe(fr_value_box_t *vb)
Mark a value-box as "unsafe".
Definition value.c:6484
int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, fr_value_box_t const *src)
Convert one type of fr_value_box_t to another.
Definition value.c:3574
int fr_value_box_copy(TALLOC_CTX *ctx, fr_value_box_t *dst, const fr_value_box_t *src)
Copy value data verbatim duplicating any buffers.
Definition value.c:3963
int fr_value_box_cmp_op(fr_token_t op, fr_value_box_t const *a, fr_value_box_t const *b)
Compare two attributes using an operator.
Definition value.c:975
ssize_t fr_value_box_from_str(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, char const *in, size_t inlen, fr_sbuff_unescape_rules_t const *erules)
Definition value.c:5450
int fr_value_box_strdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted)
Copy a nul terminated string to a fr_value_box_t.
Definition value.c:4161
void fr_value_box_safety_copy_changed(fr_value_box_t *out, fr_value_box_t const *in)
Copy the safety values from one box to another.
Definition value.c:6527
fr_sbuff_unescape_rules_t * fr_value_unescape_by_quote[T_TOKEN_LAST]
Definition value.c:335
int fr_value_box_list_concat_in_place(TALLOC_CTX *ctx, fr_value_box_t *out, fr_value_box_list_t *list, fr_type_t type, fr_value_box_list_action_t proc_action, bool flatten, size_t max_size)
Concatenate a list of value boxes.
Definition value.c:5934
@ FR_VALUE_BOX_LIST_FREE
Definition value.h:232
@ FR_VALUE_BOX_LIST_FREE_BOX
Free each processed box.
Definition value.h:229
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
Definition value.h:632
static fr_slen_t data
Definition value.h:1274
#define fr_value_box_alloc_null(_ctx)
Allocate a value box for later use with a value assignment function.
Definition value.h:643
static size_t char ** out
Definition value.h:1012