From: Alan T. DeKok Date: Fri, 14 Jul 2023 13:01:51 +0000 (-0400) Subject: mdd migration flag for nested pairs, and test it X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a74e3568885dc9ba6e75b368c284f4cdeea1221b;p=thirdparty%2Ffreeradius-server.git mdd migration flag for nested pairs, and test it --- diff --git a/src/bin/unit_test_attribute.c b/src/bin/unit_test_attribute.c index 45f2ddb71f2..5f3906f855d 100644 --- a/src/bin/unit_test_attribute.c +++ b/src/bin/unit_test_attribute.c @@ -2453,6 +2453,49 @@ static size_t command_max_buffer_size(command_result_t *result, command_file_ctx RETURN_OK(snprintf(data, COMMAND_OUTPUT_MAX, "%ld", size)); } +/** Set or clear migration flags. + * + */ +static size_t command_migrate(command_result_t *result, UNUSED command_file_ctx_t *cc, + UNUSED char *data, UNUSED size_t data_used, char *in, UNUSED size_t inlen) +{ + char *p; + bool *out; + + fr_skip_whitespace(in); + p = in; + + if (strncmp(p, "pair_legacy_nested", sizeof("pair_legacy_nested") - 1) == 0) { + p += sizeof("pair_legacy_nested") - 1; + out = &fr_pair_legacy_nested; + + } else { + fr_strerror_const("Unknown migration flag"); + RETURN_PARSE_ERROR(0); + } + + fr_skip_whitespace(p); + if (*p != '=') { + fr_strerror_const("Missing '=' after flag"); + RETURN_PARSE_ERROR(0); + } + p++; + + fr_skip_whitespace(p); + if ((strcmp(p, "yes") == 0) || (strcmp(p, "true") == 0) || (strcmp(p, "1") == 0)) { + *out = true; + + } else if ((strcmp(p, "no") == 0) || (strcmp(p, "false") == 0) || (strcmp(p, "0") == 0)) { + *out = false; + + } else { + fr_strerror_const("Invalid value for flag"); + RETURN_PARSE_ERROR(0); + } + + RETURN_OK(0); +} + /** Skip the test file if we're missing a particular feature * */ @@ -3165,6 +3208,11 @@ static fr_table_ptr_sorted_t commands[] = { .usage = "max-buffer-size[ ]", .description = "Limit the maximum temporary buffer space available for any command which uses it" }}, + { L("migrate "), &(command_entry_t){ + .func = command_migrate, + .usage = "migrate =", + .description = "Set migration flag" + }}, { L("need-feature "), &(command_entry_t){ .func = command_need_feature, .usage = "need-feature ", diff --git a/src/tests/unit/file_nested.txt b/src/tests/unit/file_nested.txt new file mode 100644 index 00000000000..ee8b92c261b --- /dev/null +++ b/src/tests/unit/file_nested.txt @@ -0,0 +1,38 @@ +# +# Tests for parsing files ala radclient or "users" +# +# This is the same as "file.txt", but with the migration flag set. +# +# $Id$ +# + +proto-dictionary radius +migrate pair_legacy_nested = yes + +# +# Fully specified paths. +# +read_file files/cisco_avpair.txt +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" } } + +# +# 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" } } + + +# +# 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", AVPair += "2", AVPair += "3", AVPair += "4" } } + +count +match 10