From: Alan T. DeKok Date: Wed, 12 Jul 2023 18:05:34 +0000 (-0400) Subject: update for tested VPs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be1312e4d648d83eeb406e83aa7c74de509aa676;p=thirdparty%2Ffreeradius-server.git update for tested VPs if we set the nested flag "true" and edit the tests, they should all now pass. --- diff --git a/src/lib/util/pair_legacy.c b/src/lib/util/pair_legacy.c index 9057c468145..04b025ee91a 100644 --- a/src/lib/util/pair_legacy.c +++ b/src/lib/util/pair_legacy.c @@ -81,7 +81,7 @@ static ssize_t fr_pair_list_afrom_substr(TALLOC_CTX *ctx, fr_dict_attr_t const * { fr_pair_t *vp = NULL; fr_pair_t *my_relative_vp; - char const *p, *next; + char const *p, *next, *op_p; fr_token_t quote, last_token = T_INVALID; fr_dict_attr_t const *internal = NULL; fr_pair_list_t *my_list = list; @@ -200,6 +200,7 @@ static ssize_t fr_pair_list_afrom_substr(TALLOC_CTX *ctx, fr_dict_attr_t const * p = next; fr_skip_whitespace(p); + op_p = p; /* * There must be an operator here. @@ -213,11 +214,22 @@ static ssize_t fr_pair_list_afrom_substr(TALLOC_CTX *ctx, fr_dict_attr_t const * fr_skip_whitespace(p); - if (!nested || parent_vp) { + if (!nested || parent_vp || (*relative_vp && ((*relative_vp)->da == da->parent))) { vp = fr_pair_afrom_da(my_ctx, da); if (!vp) goto error; fr_pair_append(my_list, vp); + } else if (*relative_vp) { + + if (op != T_OP_ADD_EQ) { + fr_strerror_const("Relative attributes can only use '+=' for the operator"); + p = op_p; + goto error; + } + + vp = fr_pair_afrom_da_depth_nested(my_ctx, my_list, da, (*relative_vp)->da->depth); + if (!vp) goto error; + } else if (op != T_OP_ADD_EQ) { fr_assert(op != T_OP_PREPEND); diff --git a/src/tests/unit/file.txt b/src/tests/unit/file.txt index 4031e76e510..35a81da1aa5 100644 --- a/src/tests/unit/file.txt +++ b/src/tests/unit/file.txt @@ -14,17 +14,36 @@ proto-dictionary radius read_file files/cisco_avpair.txt match User-Name = "bob", User-Password = "hello", Vendor-Specific.Cisco.AVPair = "1", Vendor-Specific.Cisco.AVPair += "2", Vendor-Specific.Cisco.AVPair += "3", Vendor-Specific.Cisco.AVPair += "4" +# nested +#match User-Name = "bob", User-Password = "hello", Vendor-Specific = { Cisco = { AVPair = "1", AVPair += "2", AVPair += "3", AVPair += "4" } } + # # Relative attributes, all on the same line. # read_file files/cisco_relative.txt match User-Name = "bob", User-Password = "hello", Vendor-Specific.Cisco = { AVPair = "1", AVPair += "2", AVPair += "3", AVPair += "4" } +# nested +#match User-Name = "bob", User-Password = "hello", Vendor-Specific = { Cisco = { AVPair = "1", AVPair += "2", AVPair += "3", AVPair += "4" } } + # # Relative attributes, each on a different line # read_file files/cisco_multiline_relative.txt match User-Name = "bob", User-Password = "hello", Vendor-Specific.Cisco = { AVPair = "1", AVPair += "2", AVPair += "3", AVPair += "4" } +# nested +#match User-Name = "bob", User-Password = "hello", Vendor-Specific = { Cisco = { AVPair = "1", AVPair += "2", AVPair += "3", AVPair += "4" } } + + +# +# Multiple Cisco AVPAir, all on one line +# +read_file files/cisco_single_line.txt +match User-Name = "bob", User-Password = "hello", Vendor-Specific.Cisco.AVPair = "1", Vendor-Specific.Cisco.AVPair += "2", Vendor-Specific.Cisco.AVPair += "3", Vendor-Specific.Cisco.AVPair += "4" + +# nested +#match User-Name = "bob", User-Password = "hello", Vendor-Specific = { Cisco = { AVPair = "1", AVPair += "2", AVPair += "3", AVPair += "4" } } + count -match 7 +match 9