]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Pass dictionary into condition tokenizer
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 8 Dec 2018 22:47:56 +0000 (17:47 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 10 Dec 2018 16:20:40 +0000 (11:20 -0500)
src/bin/unit_test_attribute.c
src/lib/server/cf_file.c
src/lib/server/cond_tokenize.c
src/lib/server/parser.h
src/tests/unit/condition.txt

index b08689a233353b9549a1d1c47d0a2fdf4ce0f127..b69fc1cf3377fc051c027e986edcb6ac5029209d 100644 (file)
@@ -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;
                }
 
index d6e881885fec80dfc849dd0f47e89e8179426f1b..9b650fd1190e4c2b580e8a7bd7f4a2ccaa58821c 100644 (file)
@@ -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:
index cf5e13aad8bc1008b6558b6f708b351e691c83fc..b04ff7dc4c4ae39000aea7f89198dc1cf8dab56c 100644 (file)
@@ -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);
 }
 
 /*
index ce1a979969fe3853a108057867a6bb8d6a7d9687..07cc13bc90d1f38cefc3ccdaedc3e5bf5cf222ec 100644 (file)
@@ -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);
index 6474f94db2074b25f6fd7e2293ca8ae7170c07a0..eba329c5d2cb545a698b1e6621044d6b706f19a1 100644 (file)
@@ -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\