From: Arran Cudbard-Bell Date: Sat, 8 Dec 2018 22:47:56 +0000 (-0500) Subject: Pass dictionary into condition tokenizer X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cfb118973a8752fc8a68f8fd242ae7182dc78a34;p=thirdparty%2Ffreeradius-server.git Pass dictionary into condition tokenizer --- diff --git a/src/bin/unit_test_attribute.c b/src/bin/unit_test_attribute.c index b08689a2333..b69fc1cf337 100644 --- a/src/bin/unit_test_attribute.c +++ b/src/bin/unit_test_attribute.c @@ -526,13 +526,13 @@ static int encode_rfc(char *buffer, uint8_t *output, size_t outlen) return length + sublen; } -static void parse_condition(char const *input, char *output, size_t outlen) +static void parse_condition(fr_dict_t const *dict, char const *input, char *output, size_t outlen) { ssize_t dec_len; char const *error = NULL; fr_cond_t *cond; - dec_len = fr_cond_tokenize(NULL, NULL, input, &cond, &error, FR_COND_ONE_PASS); + dec_len = fr_cond_tokenize(NULL, &cond, &error, dict, NULL, input, FR_COND_ONE_PASS); if (dec_len <= 0) { snprintf(output, outlen, "ERROR offset %d %s", (int) -dec_len, error); return; @@ -1024,7 +1024,7 @@ do { \ p += 14; } - if (fr_pair_list_afrom_str(packet, proto_dict, p, &head) != T_EOL) { + if (fr_pair_list_afrom_str(packet, proto_dict ? proto_dict : dict, p, &head) != T_EOL) { strerror_concat(output, sizeof(output)); talloc_free(packet); @@ -1092,7 +1092,7 @@ do { \ if (strcmp(test_type, "attribute") == 0) { p += 10; - if (fr_pair_list_afrom_str(NULL, proto_dict, p, &head) != T_EOL) { + if (fr_pair_list_afrom_str(NULL, proto_dict ? proto_dict : dict, p, &head) != T_EOL) { strerror_concat(output, sizeof(output)); continue; } @@ -1131,7 +1131,7 @@ do { \ if (strcmp(test_type, "condition") == 0) { p += 10; - parse_condition(p, output, sizeof(output)); + parse_condition(proto_dict ? proto_dict : dict, p, output, sizeof(output)); continue; } diff --git a/src/lib/server/cf_file.c b/src/lib/server/cf_file.c index d6e881885fe..9b650fd1190 100644 --- a/src/lib/server/cf_file.c +++ b/src/lib/server/cf_file.c @@ -1149,8 +1149,8 @@ static int cf_section_read(char const *filename, int *lineno, FILE *fp, /* * Skip (...) to find the { */ - slen = fr_cond_tokenize(this, cf_section_to_item(this), ptr, &cond, - &error, FR_COND_TWO_PASS); + slen = fr_cond_tokenize(this, &cond, &error, + NULL, cf_section_to_item(this), ptr, FR_COND_TWO_PASS); memcpy(&p, &ptr, sizeof(p)); if (slen < 0) { @@ -1208,8 +1208,8 @@ static int cf_section_read(char const *filename, int *lineno, FILE *fp, css->item.filename = filename; css->item.lineno = *lineno; - slen = fr_cond_tokenize(css, cf_section_to_item(css), ptr, &cond, - &error, FR_COND_TWO_PASS); + slen = fr_cond_tokenize(css, &cond, &error, + NULL, cf_section_to_item(css), ptr, FR_COND_TWO_PASS); *p = '{'; /* put it back */ cond_error: diff --git a/src/lib/server/cond_tokenize.c b/src/lib/server/cond_tokenize.c index cf5e13aad8b..b04ff7dc4c4 100644 --- a/src/lib/server/cond_tokenize.c +++ b/src/lib/server/cond_tokenize.c @@ -441,19 +441,20 @@ static bool cond_type_check(fr_cond_t *c, fr_type_t lhs_type) /** Tokenize a conditional check * * @param[in] ctx for talloc + * @param[out] pcond pointer to the returned condition structure + * @param[out] error the parse error (if any) * @param[in] ci for CONF_ITEM * @param[in] start the start of the string to process. Should be "(..." * @param[in] brace look for a closing brace - * @param[out] pcond pointer to the returned condition structure - * @param[out] error the parse error (if any) * @param[in] flags do one/two pass * @param[in] rules for attribute parsing * @return * - Length of the string skipped. * - < 0 (the offset to the offending error) on error. */ -static ssize_t cond_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *start, bool brace, - fr_cond_t **pcond, char const **error, int flags, vp_tmpl_rules_t const *rules) +static ssize_t cond_tokenize(TALLOC_CTX *ctx, fr_cond_t **pcond, char const **error, + CONF_ITEM *ci, char const *start, bool brace, + int flags, vp_tmpl_rules_t const *rules) { ssize_t slen, tlen; char const *p = start; @@ -511,7 +512,7 @@ static ssize_t cond_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *start, */ c->type = COND_TYPE_CHILD; c->ci = ci; - slen = cond_tokenize(c, ci, p, true, &c->data.child, error, flags, rules); + slen = cond_tokenize(c, &c->data.child, error, ci, p, true, flags, rules); if (slen <= 0) return_SLEN; if (!c->data.child) { @@ -1282,7 +1283,7 @@ static ssize_t cond_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *start, /* * May still be looking for a closing brace. */ - slen = cond_tokenize(c, ci, p, brace, &c->next, error, flags, rules); + slen = cond_tokenize(c, &c->next, error, ci, p, brace, flags, rules); if (slen <= 0) { return_slen: if (lhs) talloc_free(lhs); @@ -1727,24 +1728,27 @@ done: /** Tokenize a conditional check * - * @param[in] ctx for talloc - * @param[in] ci for CONF_ITEM - * @param[in] start the start of the string to process. Should be "(..." - * @param[out] head the parsed condition structure - * @param[out] error the parse error (if any) - * @param[in] flags do one/two pass - * @return + * @param[in] ctx for talloc + * @param[out] head the parsed condition structure + * @param[out] error the parse error (if any) + * @param[in] dict dictionary to resolve attributes in. + * @param[in] ci for CONF_ITEM + * @param[in] start the start of the string to process. Should be "(..." + * @param[in] flags do one/two pass + * @return * - Length of the string skipped. * - < 0 (the offset to the offending error) on error. */ -ssize_t fr_cond_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *start, - fr_cond_t **head, char const **error, int flags) +ssize_t fr_cond_tokenize(TALLOC_CTX *ctx, + fr_cond_t **head, char const **error, + fr_dict_t const *dict, + CONF_ITEM *ci, char const *start, int flags) { - vp_tmpl_rules_t parse_rules; - - memset(&parse_rules, 0, sizeof(parse_rules)); + vp_tmpl_rules_t parse_rules = { + .dict_def = dict + }; - return cond_tokenize(ctx, ci, start, false, head, error, flags, &parse_rules); + return cond_tokenize(ctx, head, error, ci, start, false, flags, &parse_rules); } /* diff --git a/src/lib/server/parser.h b/src/lib/server/parser.h index ce1a979969f..07cc13bc90d 100644 --- a/src/lib/server/parser.h +++ b/src/lib/server/parser.h @@ -99,7 +99,9 @@ struct fr_cond_t { #define FR_COND_ONE_PASS (0) #define FR_COND_TWO_PASS (1) -ssize_t fr_cond_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *start, fr_cond_t **head, char const **error, int flag); +ssize_t fr_cond_tokenize(TALLOC_CTX *ctx, fr_cond_t **head, char const **error, + fr_dict_t const *dict, + CONF_ITEM *ci, char const *start, int flag); size_t cond_snprint(char *buffer, size_t bufsize, fr_cond_t const *c); bool fr_cond_walk(fr_cond_t *head, bool (*callback)(fr_cond_t *cond, void *uctx), void *uctx); diff --git a/src/tests/unit/condition.txt b/src/tests/unit/condition.txt index 6474f94db20..eba329c5d2c 100644 --- a/src/tests/unit/condition.txt +++ b/src/tests/unit/condition.txt @@ -9,7 +9,7 @@ # A bunch of errors, in the order that the error strings # appear in parser.c # - +load-dictionary radius # All IP address literals should be parsed as prefixes condition ("foo\