From: Nick Porter Date: Fri, 27 Jan 2023 08:54:45 +0000 (+0000) Subject: Add skip_list option to pair_append_by_tmpl_parent X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=655fcdfa665fda65e20b972458a057b533ffafe9;p=thirdparty%2Ffreeradius-server.git Add skip_list option to pair_append_by_tmpl_parent With all attr tmpls having a list as the first ar, need to be able to skip that when building into temporary lists rather than into request->pair_root --- diff --git a/src/lib/server/tmpl.h b/src/lib/server/tmpl.h index 136b37db41a..035415cb827 100644 --- a/src/lib/server/tmpl.h +++ b/src/lib/server/tmpl.h @@ -1304,7 +1304,7 @@ int tmpl_find_vp(fr_pair_t **out, request_t *request, tmpl_t const *vpt) CC_HI int tmpl_find_or_add_vp(fr_pair_t **out, request_t *request, tmpl_t const *vpt) CC_HINT(nonnull); int pair_append_by_tmpl_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, - tmpl_t const *vpt) CC_HINT(nonnull(1,3,4)); + tmpl_t const *vpt, bool skip_list) CC_HINT(nonnull(1,3,4)); int tmpl_extents_find(TALLOC_CTX *ctx, fr_dlist_head_t *leaf, fr_dlist_head_t *interior, diff --git a/src/lib/server/tmpl_eval.c b/src/lib/server/tmpl_eval.c index f88f6f32613..5456b593832 100644 --- a/src/lib/server/tmpl_eval.c +++ b/src/lib/server/tmpl_eval.c @@ -989,11 +989,12 @@ int tmpl_find_or_add_vp(fr_pair_t **out, request_t *request, tmpl_t const *vpt) * @param[out] out Leaf pair we allocated. * @param[in] list to insert into. * @param[in] vpt tmpl representing the attribute to add. + * @param[in] skip_list skip list attr ref at the head of the tmpl. * @return * - 0 on success. * - -1 on failure. */ -int pair_append_by_tmpl_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, tmpl_t const *vpt) +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) { fr_pair_t *vp = NULL; TALLOC_CTX *pair_ctx = ctx; @@ -1008,6 +1009,8 @@ int pair_append_by_tmpl_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t leaf = tmpl_attr_list_tail(ar_list); ar = tmpl_attr_list_head(ar_list); + if (!ar) goto error; + if (skip_list && tmpl_attr_is_list_attr(ar)) ar = tmpl_attr_list_next(ar_list, ar); /* * Walk down the tmpl ar stack looking for candidate parent diff --git a/src/listen/ldap_sync/proto_ldap_sync_ldap.c b/src/listen/ldap_sync/proto_ldap_sync_ldap.c index e54a743ecf7..00dda1ecc49 100644 --- a/src/listen/ldap_sync/proto_ldap_sync_ldap.c +++ b/src/listen/ldap_sync/proto_ldap_sync_ldap.c @@ -478,7 +478,7 @@ int ldap_sync_entry_send(sync_state_t *sync, uint8_t const uuid[SYNC_UUID_LENGTH for (i = 0; i < count; i++) { if (values[i]->bv_len == 0) continue; - if (pair_append_by_tmpl_parent(sync_packet_ctx, &vp, pairs, map->lhs) < 0) break; + if (pair_append_by_tmpl_parent(sync_packet_ctx, &vp, pairs, map->lhs, true) < 0) break; if (fr_value_box_from_str(vp, &vp->data, vp->da->type, NULL, values[i]->bv_val, values[i]->bv_len, NULL, true) < 0) { fr_pair_remove(pairs, vp);