From: Alan T. DeKok Date: Sun, 19 Dec 2021 19:14:14 +0000 (-0500) Subject: decode_pair test point should take fr_dict_attr_t const *parent X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0cfd54d634994d1c1b61997711ce55f8a4de14cc;p=thirdparty%2Ffreeradius-server.git decode_pair test point should take fr_dict_attr_t const *parent which lets us start decoding part way through the dictionary, instead of always at the top --- diff --git a/src/bin/unit_test_attribute.c b/src/bin/unit_test_attribute.c index de3f168f1c..aedd9b1935 100644 --- a/src/bin/unit_test_attribute.c +++ b/src/bin/unit_test_attribute.c @@ -1516,7 +1516,7 @@ static size_t command_decode_pair(command_result_t *result, command_file_ctx_t * * point to produce fr_pair_ts. */ while (to_dec < to_dec_end) { - slen = tp->func(cc->tmp_ctx, &head, cc->tmpl_rules.dict_def ? cc->tmpl_rules.dict_def : cc->config->dict, + slen = tp->func(cc->tmp_ctx, &head, fr_dict_root(cc->tmpl_rules.dict_def ? cc->tmpl_rules.dict_def : cc->config->dict), (uint8_t *)to_dec, (to_dec_end - to_dec), decode_ctx); cc->last_ret = slen; if (slen <= 0) { diff --git a/src/lib/eap_aka_sim/base.h b/src/lib/eap_aka_sim/base.h index b48c662804..1928c9b745 100644 --- a/src/lib/eap_aka_sim/base.h +++ b/src/lib/eap_aka_sim/base.h @@ -253,7 +253,7 @@ extern size_t const fr_aka_sim_attr_sizes[FR_TYPE_MAX + 1][2]; /* * decode.c */ -ssize_t fr_aka_sim_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict, +ssize_t fr_aka_sim_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx); int fr_aka_sim_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict, diff --git a/src/lib/eap_aka_sim/decode.c b/src/lib/eap_aka_sim/decode.c index e8cb3acf17..253e926314 100644 --- a/src/lib/eap_aka_sim/decode.c +++ b/src/lib/eap_aka_sim/decode.c @@ -910,7 +910,7 @@ static ssize_t sim_decode_pair_internal(TALLOC_CTX *ctx, fr_pair_list_t *out, fr * * @param[in] ctx to allocate attributes in. * @param[in] out where to insert the attributes. - * @param[in] dict for looking up attributes. + * @param[in] parent for looking up attributes. * @param[in] data data to parse. * @param[in] data_len length of data. For top level attributes packet_ctx must be the length * of the packet (so we can hunt for AT_IV), for Sub-TLVs it should @@ -920,10 +920,10 @@ static ssize_t sim_decode_pair_internal(TALLOC_CTX *ctx, fr_pair_list_t *out, fr * - The number of bytes parsed. * - -1 on error. */ -ssize_t fr_aka_sim_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict, - uint8_t const *data, size_t data_len, void *decode_ctx) +ssize_t fr_aka_sim_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, + uint8_t const *data, size_t data_len, void *decode_ctx) { - return sim_decode_pair_internal(ctx, out, fr_dict_root(dict), data, data_len, decode_ctx); + return sim_decode_pair_internal(ctx, out, parent, data, data_len, decode_ctx); } /** Decode SIM/AKA/AKA' specific packet data @@ -959,6 +959,7 @@ int fr_aka_sim_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dic ssize_t ret; uint8_t const *p = data; uint8_t const *end = p + data_len; + fr_dict_attr_t const *parent; /* * We need at least enough data for the subtype @@ -975,6 +976,7 @@ int fr_aka_sim_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dic return -1; } p += 3; + parent = fr_dict_root(dict); /* * Loop over all the attributes decoding @@ -982,7 +984,7 @@ int fr_aka_sim_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dic * in the SIM/AKA/AKA' dict. */ while (p < end) { - ret = fr_aka_sim_decode_pair(ctx, out, dict, p, end - p, decode_ctx); + ret = fr_aka_sim_decode_pair(ctx, out, parent, p, end - p, decode_ctx); if (ret <= 0) { fr_strerror_const_push("Failed decoding AT"); error: @@ -1001,7 +1003,7 @@ int fr_aka_sim_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dic { fr_pair_t *vp; - vp = fr_pair_afrom_child_num(ctx, fr_dict_root(dict), FR_SUBTYPE); + vp = fr_pair_afrom_child_num(ctx, parent, FR_SUBTYPE); if (!vp) { fr_strerror_const("Failed allocating subtype attribute"); goto error; diff --git a/src/lib/io/pair.h b/src/lib/io/pair.h index f94ec72d1c..a18696d378 100644 --- a/src/lib/io/pair.h +++ b/src/lib/io/pair.h @@ -124,15 +124,15 @@ typedef ssize_t (*fr_pair_encode_t)(fr_dbuff_t *out, fr_dcursor_t *cursor, void * * @param[in] ctx to allocate new pairs in. * @param[in] out to insert new pairs into. - * @param[in] dict to use to lookup attributes. + * @param[in] parent to use for decoding * @param[in] data to decode. * @param[in] data_len The length of the incoming data. - * @param[in] decode_ctx Any decode specific data such as secrets or configurable. + * @param[in] decode_ctx Any decode specific data such as secrets or temporary allocation contexts * @return * - <= 0 on error. May be the offset (as a negative value) where the error occurred. * - > 0 on success. How many bytes were decoded. */ -typedef ssize_t (*fr_pair_decode_t)(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict, +typedef ssize_t (*fr_pair_decode_t)(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx); int fr_pair_decode_value_box_list(TALLOC_CTX *ctx, fr_pair_list_t *out, diff --git a/src/lib/tls/cache.c b/src/lib/tls/cache.c index cc55a33d33..53e89fa717 100644 --- a/src/lib/tls/cache.c +++ b/src/lib/tls/cache.c @@ -193,7 +193,7 @@ static int tls_cache_app_data_get(request_t *request, SSL_SESSION *sess) */ while (fr_dbuff_remaining(&dbuff) > 0) { if (fr_internal_decode_pair_dbuff(request->session_state_ctx, &tmp, - request->dict, &dbuff, NULL) < 0) { + fr_dict_root(request->dict), &dbuff, NULL) < 0) { fr_pair_list_free(&tmp); RPEDEBUG("Failed decoding session-state"); return -1; diff --git a/src/lib/unlang/xlat_pair.c b/src/lib/unlang/xlat_pair.c index e9fb2e0e3e..e61a8018b2 100644 --- a/src/lib/unlang/xlat_pair.c +++ b/src/lib/unlang/xlat_pair.c @@ -30,7 +30,7 @@ RCSID("$Id$") * * @param[in] ctx to allocate new pairs in. * @param[in] out the cursor to update - * @param[in] dict to use to lookup attributes. + * @param[in] parent to use as the root * @param[in] data to decode. * @param[in] data_len The length of the incoming data. * @param[in] decode_ctx Any decode specific data such as secrets or configurable. @@ -39,7 +39,7 @@ RCSID("$Id$") * - <= 0 on error. May be the offset (as a negative value) where the error occurred. * - > 0 on success. How many bytes were decoded. */ -static ssize_t fr_pair_decode_multi(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict, +static ssize_t fr_pair_decode_multi(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx, fr_pair_decode_t decode) { uint8_t const *p, *end; @@ -58,7 +58,7 @@ static ssize_t fr_pair_decode_multi(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dic while (p < end) { ssize_t len; - len = decode(ctx, &tmp, dict, p, end - p, decode_ctx); + len = decode(ctx, &tmp, parent, p, end - p, decode_ctx); if (len <= 0) { fr_pair_list_free(&tmp); return len - (p - data); @@ -94,6 +94,7 @@ int fr_pair_decode_value_box_list(TALLOC_CTX *ctx, fr_pair_list_t *out, int decoded = 0; fr_value_box_t *vb = NULL; fr_pair_t *vp = NULL; + fr_dict_attr_t const *parent = fr_dict_root(request->dict); fr_pair_list_t head; fr_pair_list_init(&head); @@ -109,7 +110,7 @@ int fr_pair_decode_value_box_list(TALLOC_CTX *ctx, fr_pair_list_t *out, continue; } - len = fr_pair_decode_multi(ctx, &head, request->dict, + len = fr_pair_decode_multi(ctx, &head, parent, vb->vb_octets, vb->vb_length, decode_ctx, decode); if (len <= 0) { fr_pair_list_free(&head); @@ -119,7 +120,7 @@ int fr_pair_decode_value_box_list(TALLOC_CTX *ctx, fr_pair_list_t *out, } if (RDEBUG_ENABLED2) { - char const *name = fr_dict_root(request->dict)->name; + char const *name = parent->name; while ((vp = fr_pair_list_next(&head, vp))) { RDEBUG2("decode %s: &%pP", name, vp); diff --git a/src/protocols/dhcpv4/decode.c b/src/protocols/dhcpv4/decode.c index 69a1942773..fbc494a485 100644 --- a/src/protocols/dhcpv4/decode.c +++ b/src/protocols/dhcpv4/decode.c @@ -592,10 +592,10 @@ static ssize_t fr_dhcpv4_decode_proto(TALLOC_CTX *ctx, fr_pair_list_t *out, return data_len; } -static ssize_t decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out, NDEBUG_UNUSED fr_dict_t const *dict, +static ssize_t decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out, NDEBUG_UNUSED fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx) { - fr_assert(dict == dict_dhcpv4); + fr_assert(parent == fr_dict_root(dict_dhcpv4)); return fr_dhcpv4_decode_option(ctx, out, data, data_len, decode_ctx); } diff --git a/src/protocols/dhcpv6/decode.c b/src/protocols/dhcpv6/decode.c index 4ac3f27971..5221b347ef 100644 --- a/src/protocols/dhcpv6/decode.c +++ b/src/protocols/dhcpv6/decode.c @@ -642,10 +642,10 @@ static ssize_t fr_dhcpv6_decode_proto(TALLOC_CTX *ctx, fr_pair_list_t *out, uint } -static ssize_t decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, NDEBUG_UNUSED fr_dict_t const *dict, +static ssize_t decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, NDEBUG_UNUSED fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx) { - fr_assert(dict == dict_dhcpv6); + fr_assert(parent == fr_dict_root(dict_dhcpv6)); return decode_option(ctx, out, fr_dict_root(dict_dhcpv6), data, data_len, decode_ctx); } diff --git a/src/protocols/dns/decode.c b/src/protocols/dns/decode.c index da5c8c9312..80b07a4d97 100644 --- a/src/protocols/dns/decode.c +++ b/src/protocols/dns/decode.c @@ -582,13 +582,13 @@ ssize_t fr_dns_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *packe * * @param[in] ctx context to alloc new attributes in. * @param[in,out] out Where to write the decoded options. - * @param[in] dict to lookup attributes in. + * @param[in] parent to lookup attributes in. * @param[in] data to parse. * @param[in] data_len of data to parse. * @param[in] decode_ctx Unused. */ -static ssize_t decode_rr(TALLOC_CTX *ctx, fr_pair_list_t *out, - UNUSED fr_dict_t const *dict, uint8_t const *data, size_t data_len, void *decode_ctx) +static ssize_t decode_rr(TALLOC_CTX *ctx, fr_pair_list_t *out, UNUSED fr_dict_attr_t const *parent, + uint8_t const *data, size_t data_len, void *decode_ctx) { ssize_t slen; fr_dns_ctx_t *packet_ctx = (fr_dns_ctx_t *) decode_ctx; diff --git a/src/protocols/internal/decode.c b/src/protocols/internal/decode.c index 2e9153fc29..19209054a5 100644 --- a/src/protocols/internal/decode.c +++ b/src/protocols/internal/decode.c @@ -349,13 +349,13 @@ static ssize_t internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dic /** Create a single fr_pair_t and all its nesting * */ -ssize_t fr_internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_t const *dict, +ssize_t fr_internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx) { - return fr_internal_decode_pair_dbuff(ctx, list, dict, &FR_DBUFF_TMP(data, data_len), decode_ctx); + return fr_internal_decode_pair_dbuff(ctx, list, parent, &FR_DBUFF_TMP(data, data_len), decode_ctx); } -ssize_t fr_internal_decode_pair_dbuff(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict, +ssize_t fr_internal_decode_pair_dbuff(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, fr_dbuff_t *dbuff, void *decode_ctx) { fr_pair_list_t tmp; @@ -364,7 +364,7 @@ ssize_t fr_internal_decode_pair_dbuff(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_d fr_pair_list_init(&tmp); - slen = internal_decode_pair(ctx, &tmp, fr_dict_root(dict), &work_dbuff, decode_ctx); + slen = internal_decode_pair(ctx, &tmp, parent, &work_dbuff, decode_ctx); if (slen <= 0) { fr_pair_list_free(&tmp); return slen; diff --git a/src/protocols/internal/internal.h b/src/protocols/internal/internal.h index 2d8e7e9196..5b940a67ad 100644 --- a/src/protocols/internal/internal.h +++ b/src/protocols/internal/internal.h @@ -43,8 +43,8 @@ ssize_t fr_internal_encode_pair(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, void *encode_ctx); -ssize_t fr_internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict, +ssize_t fr_internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx); -ssize_t fr_internal_decode_pair_dbuff(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict, +ssize_t fr_internal_decode_pair_dbuff(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, fr_dbuff_t *dbuff, void *decode_ctx); diff --git a/src/protocols/radius/decode.c b/src/protocols/radius/decode.c index 103d09c172..3aa260dc0a 100644 --- a/src/protocols/radius/decode.c +++ b/src/protocols/radius/decode.c @@ -1878,10 +1878,10 @@ static ssize_t fr_radius_decode_proto(TALLOC_CTX *ctx, fr_pair_list_t *out, test_ctx->secret, talloc_array_length(test_ctx->secret) - 1); } -static ssize_t decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, NDEBUG_UNUSED fr_dict_t const *dict, +static ssize_t decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, NDEBUG_UNUSED fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, fr_radius_ctx_t *packet_ctx) { - fr_assert(dict == dict_radius); + fr_assert(parent == fr_dict_root(dict_radius)); return fr_radius_decode_pair(ctx, out, data, data_len, packet_ctx); }