From: Alan T. DeKok Date: Mon, 4 Nov 2019 22:14:28 +0000 (-0500) Subject: move RADIUS stubtype stuff to libfreeradius-radius X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7ec5f43f035b168b63190c669e9b4a575cf6038;p=thirdparty%2Ffreeradius-server.git move RADIUS stubtype stuff to libfreeradius-radius --- diff --git a/src/lib/util/dict.h b/src/lib/util/dict.h index 80fc52e4f7c..41bd8d2469e 100644 --- a/src/lib/util/dict.h +++ b/src/lib/util/dict.h @@ -200,7 +200,11 @@ typedef enum { * */ typedef struct { - char const *name; //!< name of this protocol + char const *name; //!< name of this protocol + int default_type_size; //!< how many octets are in "type" field + int default_type_length; //!< how many octets are in "length" field + fr_table_num_ordered_t const *subtype_table; //!< for "encrypt=1", etc. + size_t subtype_table_len; //!< length of subtype_table } fr_dict_protocol_t; /* diff --git a/src/lib/util/dict_util.c b/src/lib/util/dict_util.c index 8e74371bb4f..ee92e16963b 100644 --- a/src/lib/util/dict_util.c +++ b/src/lib/util/dict_util.c @@ -62,21 +62,6 @@ fr_table_num_ordered_t const date_precision_table[] = { }; size_t date_precision_table_len = NUM_ELEMENTS(date_precision_table); -static fr_table_num_ordered_t const radius_subtype_table[] = { - { "encrypt=1", FLAG_ENCRYPT_USER_PASSWORD }, - { "encrypt=2", FLAG_ENCRYPT_TUNNEL_PASSWORD }, - { "encrypt=3", FLAG_ENCRYPT_ASCEND_SECRET }, - { "long", FLAG_EXTENDED_ATTR }, - - /* - * And some humanly-readable names - */ - { "encrypt=Ascend-Secret", FLAG_ENCRYPT_ASCEND_SECRET }, - { "encrypt=Tunnel-Password", FLAG_ENCRYPT_TUNNEL_PASSWORD }, - { "encrypt=User-Password", FLAG_ENCRYPT_USER_PASSWORD }, -}; -static size_t radius_subtype_table_len = NUM_ELEMENTS(radius_subtype_table); - static fr_table_num_ordered_t const dhcpv6_subtype_table[] = { { "dns_label", FLAG_ENCODE_DNS_LABEL }, { "encode=dns_label", FLAG_ENCODE_DNS_LABEL }, @@ -545,20 +530,10 @@ int dict_protocol_add(fr_dict_t *dict) } dict->in_protocol_by_num = true; - dict->default_type_size = 1; - dict->default_type_length = 1; - /* * Set the subtype flags and other necessary things. */ switch (dict->root->attr) { - case FR_PROTOCOL_RADIUS: - dict->subtype_table = radius_subtype_table; - dict->subtype_table_len = radius_subtype_table_len; - dict->default_type_size = 1; - dict->default_type_length = 1; - break;; - case FR_PROTOCOL_DHCPV6: dict->subtype_table = dhcpv6_subtype_table; dict->subtype_table_len = dhcpv6_subtype_table_len; @@ -2473,11 +2448,23 @@ static int dict_onload_func(dl_t const *dl, void *symbol, UNUSED void *user_ctx) fr_dict_t *dict = talloc_get_type_abort(dl->uctx, fr_dict_t); fr_dict_protocol_t const *proto = symbol; + /* * Set the protocol-specific callbacks. */ dict->proto = proto; + /* + * @todo - just use dict->proto->foo, once we get the + * rest of the code cleaned up. + */ +#undef COPY +#define COPY(_x) dict->_x = proto->_x + COPY(default_type_size); + COPY(default_type_length); + COPY(subtype_table); + COPY(subtype_table_len); + return 0; } diff --git a/src/protocols/radius/base.c b/src/protocols/radius/base.c index c9978767f87..3fe2423e073 100644 --- a/src/protocols/radius/base.c +++ b/src/protocols/radius/base.c @@ -1123,7 +1123,25 @@ void fr_radius_free(void) fr_dict_autofree(libfreeradius_radius_dict); } +static fr_table_num_ordered_t const subtype_table[] = { + { "encrypt=1", FLAG_ENCRYPT_USER_PASSWORD }, + { "encrypt=2", FLAG_ENCRYPT_TUNNEL_PASSWORD }, + { "encrypt=3", FLAG_ENCRYPT_ASCEND_SECRET }, + { "long", FLAG_EXTENDED_ATTR }, + + /* + * And some humanly-readable names + */ + { "encrypt=Ascend-Secret", FLAG_ENCRYPT_ASCEND_SECRET }, + { "encrypt=Tunnel-Password", FLAG_ENCRYPT_TUNNEL_PASSWORD }, + { "encrypt=User-Password", FLAG_ENCRYPT_USER_PASSWORD }, +}; + extern fr_dict_protocol_t libfreeradius_radius_dict_protocol; fr_dict_protocol_t libfreeradius_radius_dict_protocol = { .name = "radius", + .default_type_size = 1, + .default_type_length = 1, + .subtype_table = subtype_table, + .subtype_table_len = NUM_ELEMENTS(subtype_table), };