From: Alan T. DeKok Date: Tue, 11 May 2021 19:21:00 +0000 (-0400) Subject: add "load-dictionary" command, and remove unused "test-dictionary" X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5f5fc5048811875e29ba4339c7083faa4e72c890;p=thirdparty%2Ffreeradius-server.git add "load-dictionary" command, and remove unused "test-dictionary" which now appends definitions to the current dictionary --- diff --git a/src/bin/unit_test_attribute.c b/src/bin/unit_test_attribute.c index 4259ade001a..733c53b2ab3 100644 --- a/src/bin/unit_test_attribute.c +++ b/src/bin/unit_test_attribute.c @@ -1837,6 +1837,39 @@ static size_t command_exit(command_result_t *result, UNUSED command_file_ctx_t * RETURN_EXIT(atoi(in)); } +static size_t command_load_dictionary(command_result_t *result, command_file_ctx_t *cc, + UNUSED char *data, UNUSED size_t data_used, char *in, UNUSED size_t inlen) +{ + char *name, *tmp = NULL; + char const *dir; + char *q; + int ret; + + fr_dict_global_ctx_set(cc->config->dict_gctx); + + if (in[0] == '\0') { + fr_strerror_const("Missing dictionary name"); + RETURN_PARSE_ERROR(0); + } + + q = strchr(in, ' '); + if (q) { + name = tmp = talloc_bstrndup(NULL, in, q - in); + q++; + dir = q; + } else { + name = in; + dir = cc->path; + } + + ret = fr_dict_read(UNCONST(fr_dict_t *, cc->tmpl_rules.dict_def), dir, name); + talloc_free(tmp); + if (ret < 0) RETURN_COMMAND_ERROR(); + + RETURN_OK(0); +} + + /** Compare the data buffer to an expected value * */ @@ -2067,18 +2100,6 @@ static size_t command_touch(command_result_t *result, UNUSED command_file_ctx_t RETURN_OK(0); } -static size_t command_test_dictionary(command_result_t *result, command_file_ctx_t *cc, - UNUSED char *data, UNUSED size_t data_used, char *in, UNUSED size_t inlen) -{ - int ret; - - fr_dict_global_ctx_set(cc->test_gctx); - ret = dictionary_load_common(result, cc, in, "."); - fr_dict_global_ctx_set(cc->config->dict_gctx); - - return ret; -} - /** Callback for a tmpl rule parser * */ @@ -2464,6 +2485,11 @@ static fr_table_ptr_sorted_t commands[] = { .usage = "exit[ ]", .description = "Exit with the specified error number. If no is provided, process will exit with 0" }}, + { L("load-dictionary "),&(command_entry_t){ + .func = command_load_dictionary, + .usage = "load-dictionary []", + .description = "Load an additional dictionary from the same directory as the input file. Optionally you can specify a full path via ", + }}, { L("match"), &(command_entry_t){ .func = command_match, .usage = "match ", @@ -2514,11 +2540,6 @@ static fr_table_ptr_sorted_t commands[] = { .usage = "returned", .description = "Print the returned value to the data buffer" }}, - { L("test-dictionary "),&(command_entry_t){ - .func = command_test_dictionary, - .usage = "test-dictionary []", - .description = "Switch the active dictionary. Root is set to the path containing the current test file (override with cd ). is relative to the root.", - }}, { L("tmpl-rules "), &(command_entry_t){ .func = command_tmpl_rules,