From: Alan T. DeKok Date: Thu, 17 Sep 2020 15:21:01 +0000 (-0400) Subject: clean up and rename RADIUS flags X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca02a9ff7eb8d3044c24febc9d069ebf645fc376;p=thirdparty%2Ffreeradius-server.git clean up and rename RADIUS flags --- diff --git a/src/modules/proto_radius/proto_radius.c b/src/modules/proto_radius/proto_radius.c index 3aedaeb2f4a..df1b2bf3590 100644 --- a/src/modules/proto_radius/proto_radius.c +++ b/src/modules/proto_radius/proto_radius.c @@ -349,7 +349,7 @@ static int mod_decode(void const *instance, REQUEST *request, uint8_t *const dat for (vp = fr_cursor_init(&cursor, &request->packet->vps); vp != NULL; vp = fr_cursor_next(&cursor)) { - if (vp->da->flags.subtype != FLAG_ENCRYPT_NONE) { + if (!flag_encrypted(&vp->da->flags)) { switch (vp->da->type) { default: break; diff --git a/src/modules/proto_tacacs/proto_tacacs.c b/src/modules/proto_tacacs/proto_tacacs.c index f85a896d8a2..ad16e56769f 100644 --- a/src/modules/proto_tacacs/proto_tacacs.c +++ b/src/modules/proto_tacacs/proto_tacacs.c @@ -319,7 +319,7 @@ static int mod_decode(void const *instance, REQUEST *request, uint8_t *const dat for (vp = fr_cursor_init(&cursor, &request->packet->vps); vp != NULL; vp = fr_cursor_next(&cursor)) { - if (vp->da->flags.subtype != FLAG_ENCRYPT_NONE) { + if (!vp->da->flags.subtype) { switch (vp->da->type) { default: break; diff --git a/src/protocols/radius/base.c b/src/protocols/radius/base.c index 77447565890..036c83eeabe 100644 --- a/src/protocols/radius/base.c +++ b/src/protocols/radius/base.c @@ -1135,7 +1135,7 @@ static fr_table_num_ordered_t const subtype_table[] = { { L("encrypt=1"), FLAG_ENCRYPT_USER_PASSWORD }, { L("encrypt=2"), FLAG_ENCRYPT_TUNNEL_PASSWORD }, { L("encrypt=3"), FLAG_ENCRYPT_ASCEND_SECRET }, - { L("long"), FLAG_EXTENDED_ATTR }, + { L("long"), FLAG_LONG_EXTENDED_ATTR }, /* * And some humanly-readable names @@ -1148,11 +1148,6 @@ static fr_table_num_ordered_t const subtype_table[] = { static bool attr_valid(UNUSED fr_dict_t *dict, fr_dict_attr_t const *parent, UNUSED char const *name, UNUSED int attr, fr_type_t type, fr_dict_attr_flags_t *flags) { - if ((parent->type == FR_TYPE_STRUCT) && (type == FR_TYPE_EXTENDED)) { - fr_strerror_printf("Attributes of type 'extended' cannot be used inside of a 'struct'"); - return false; - } - /* * "extra" signifies that subtype is being used by the * dictionaries itself. @@ -1174,18 +1169,13 @@ static bool attr_valid(UNUSED fr_dict_t *dict, fr_dict_attr_t const *parent, } if (parent->type == FR_TYPE_STRUCT) { - if (flags->subtype == FLAG_EXTENDED_ATTR) { + if (type == FR_TYPE_EXTENDED) { fr_strerror_printf("Attributes of type 'extended' cannot be used inside of a 'struct'"); return false; } - if (flag_encrypted(flags)) { - fr_strerror_printf("Attributes inside of a 'struct' MUST NOT be encrypted."); - return false; - } - - if (flag_has_tag(flags)) { - fr_strerror_printf("Tagged attributes cannot be used inside of a 'struct'"); + if (flags->subtype) { + fr_strerror_printf("Attributes inside of a 'struct' MUST NOT have flags set"); return false; } @@ -1202,7 +1192,7 @@ static bool attr_valid(UNUSED fr_dict_t *dict, fr_dict_attr_t const *parent, return false; } - if ((flags->subtype == FLAG_EXTENDED_ATTR) && (type != FR_TYPE_EXTENDED)) { + if (flag_long_extended(flags) && (type != FR_TYPE_EXTENDED)) { fr_strerror_printf("The 'long' flag can only be used for attributes of type 'extended'"); return false; } @@ -1236,7 +1226,7 @@ static bool attr_valid(UNUSED fr_dict_t *dict, fr_dict_attr_t const *parent, switch (type) { case FR_TYPE_EXTENDED: - if (flags->subtype == FLAG_EXTENDED_ATTR) break; + if (flag_long_extended(flags)) break; FALL_THROUGH; default: diff --git a/src/protocols/radius/decode.c b/src/protocols/radius/decode.c index 34047799987..4ffabeef267 100644 --- a/src/protocols/radius/decode.c +++ b/src/protocols/radius/decode.c @@ -1029,7 +1029,7 @@ ssize_t fr_radius_decode_pair_value(TALLOC_CTX *ctx, fr_cursor_t *cursor, fr_dic FR_PROTO_TRACE("Parent %s len %zu ... %zu", parent->name, attr_len, packet_len); data_len = attr_len; - extra = flag_extended(&parent->flags); + extra = flag_long_extended(&parent->flags); /* * Silently ignore zero-length attributes. diff --git a/src/protocols/radius/encode.c b/src/protocols/radius/encode.c index 4633b56ca3b..84d1a31f945 100644 --- a/src/protocols/radius/encode.c +++ b/src/protocols/radius/encode.c @@ -823,7 +823,7 @@ static ssize_t encode_extended_hdr(fr_dbuff_t *dbuff, VP_VERIFY(vp); FR_PROTO_STACK_PRINT(da_stack, depth); - extra = flag_extended(&da_stack->da[0]->flags); + extra = flag_long_extended(&da_stack->da[0]->flags); /* * @fixme: check depth of stack diff --git a/src/protocols/radius/radius.h b/src/protocols/radius/radius.h index a85b1d10767..6d63a328b65 100644 --- a/src/protocols/radius/radius.h +++ b/src/protocols/radius/radius.h @@ -84,8 +84,8 @@ typedef enum { * Order of the flags is important for the flag_foo() checks. */ enum { - FLAG_ENCRYPT_NONE = 0, //!< Don't encrypt the attribute. - FLAG_EXTENDED_ATTR, //!< the attribute is a long extended attribute + FLAG_NONE = 0, //!< No extra flags + FLAG_LONG_EXTENDED_ATTR, //!< the attribute is a long extended attribute FLAG_CONCAT, //!< the attribute is concatenated FLAG_ENCRYPT_USER_PASSWORD, //!< Encrypt attribute RFC 2865 style. @@ -97,7 +97,7 @@ enum { #define flag_has_tag(_flags) ((_flags)->has_tag) #define flag_concat(_flags) (!(_flags)->extra && (_flags)->subtype == FLAG_CONCAT) #define flag_encrypted(_flags) (!(_flags)->extra && (_flags)->subtype >= FLAG_ENCRYPT_USER_PASSWORD) -#define flag_extended(_flags) (!(_flags)->extra && (_flags)->subtype == FLAG_EXTENDED_ATTR) +#define flag_long_extended(_flags) (!(_flags)->extra && (_flags)->subtype == FLAG_LONG_EXTENDED_ATTR) #define flag_tunnel_password(_flags) (!(_flags)->extra && (_flags)->subtype == FLAG_ENCRYPT_TUNNEL_PASSWORD) /*