]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Allow "needs_value" to be set for flag parsing so that flag parsing functions don...
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 23 Oct 2024 17:30:48 +0000 (11:30 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 24 Oct 2024 23:07:57 +0000 (17:07 -0600)
src/lib/util/dict.h
src/lib/util/dict_tokenize.c

index b725d2a65de50c2eafcfeb9c94912f0f9b7d7643..4cb1fdb509cc2fd822956f8f7ec3b677af91f1be 100644 (file)
@@ -352,6 +352,7 @@ typedef int (*fr_dict_flag_parse_func_t)(fr_dict_attr_t **da_p, UNUSED char cons
 struct fr_dict_flag_parser_rule_s {
        fr_dict_flag_parse_func_t       func;                           //!< Custom parsing function to convert a flag value string to a C type value.
        void                            *uctx;                          //!< Use context to pass to the custom parsing function.
+       bool                            needs_value;                    //!< This parsing flag must have a value.  Else we error.
 };
 
 /** Protocol specific custom flag definitnion
index ff49c2d15dd193eaf4bfaf65dc1c04f43f61af77..479ee01a75871996048cabc130240d76d086688f 100644 (file)
@@ -374,7 +374,7 @@ static int dict_flag_key(fr_dict_attr_t **da_p, UNUSED char const *value, UNUSED
        return 0;
 }
 
-static int dict_flag_length(fr_dict_attr_t **da_p, UNUSED char const *value, UNUSED fr_dict_flag_parser_rule_t const *rule)
+static int dict_flag_length(fr_dict_attr_t **da_p, char const *value, UNUSED fr_dict_flag_parser_rule_t const *rule)
 {
        fr_dict_attr_t *da = *da_p;
        if (!value) {
@@ -493,7 +493,7 @@ static int dict_flag_secret(fr_dict_attr_t **da_p, UNUSED char const *value, UNU
        return 0;
 }
 
-static int dict_flag_subtype(fr_dict_attr_t **da_p, UNUSED char const *value, UNUSED fr_dict_flag_parser_rule_t const *rule)
+static int dict_flag_subtype(fr_dict_attr_t **da_p, char const *value, UNUSED fr_dict_flag_parser_rule_t const *rule)
 {
        fr_dict_attr_t *da = *da_p;
        fr_type_t subtype;
@@ -566,17 +566,17 @@ static int dict_process_flag_field(dict_tokenize_ctx_t *ctx, char *name, fr_dict
 {
        static fr_dict_flag_parser_t dict_common_flags[] = {
                { L("array"),           { .func = dict_flag_array } },
-               { L("clone"),           { .func = dict_flag_clone } },
-               { L("counter"),         { .func = dict_flag_counter  } },
-               { L("enum"),            { .func = dict_flag_enum } },
+               { L("clone"),           { .func = dict_flag_clone, .needs_value = true } },
+               { L("counter"),         { .func = dict_flag_counter } },
+               { L("enum"),            { .func = dict_flag_enum, .needs_value = true } },
                { L("internal"),        { .func = dict_flag_internal } },
                { L("key"),             { .func = dict_flag_key } },
-               { L("length"),          { .func = dict_flag_length } },
-               { L("offset"),          { .func = dict_flag_offset } },
-               { L("precision"),       { .func = dict_flag_precision } },
-               { L("ref"),             { .func = dict_flag_ref } },
+               { L("length"),          { .func = dict_flag_length, .needs_value = true } },
+               { L("offset"),          { .func = dict_flag_offset, .needs_value = true } },
+               { L("precision"),       { .func = dict_flag_precision, .needs_value = true } },
+               { L("ref"),             { .func = dict_flag_ref, .needs_value = true } },
                { L("secret"),          { .func = dict_flag_secret } },
-               { L("subtype"),         { .func = dict_flag_subtype } },
+               { L("subtype"),         { .func = dict_flag_subtype, .needs_value = true } }
        };
        static size_t dict_common_flags_len = NUM_ELEMENTS(dict_common_flags);
 
@@ -654,6 +654,11 @@ static int dict_process_flag_field(dict_tokenize_ctx_t *ctx, char *name, fr_dict
                        return -1;
                }
 
+               if (parser->needs_value && !value) {
+                       fr_strerror_printf("Flag '%s' requires a value", key);
+                       return -1;
+               }
+
                if (unlikely(parser->func(da_p, value, parser) < 0)) return -1;
        }