]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move RADIUS stubtype stuff to libfreeradius-radius
authorAlan T. DeKok <aland@freeradius.org>
Mon, 4 Nov 2019 22:14:28 +0000 (17:14 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 4 Nov 2019 22:14:28 +0000 (17:14 -0500)
src/lib/util/dict.h
src/lib/util/dict_util.c
src/protocols/radius/base.c

index 80fc52e4f7c77b1cda17d0b26ab6b59c37acb6f5..41bd8d2469eb70748bc7cefb562bba31c5ec0fbb 100644 (file)
@@ -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;
 
 /*
index 8e74371bb4fa0321942ce8ba1070cd24ff2b30a1..ee92e16963bf230209cb46b0b1f898d53cc37dbd 100644 (file)
@@ -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;
 }
 
index c9978767f87585cdea7e85c844a4d96b481e99b8..3fe2423e07382dc3713684924dd4a0c84fbd221d 100644 (file)
@@ -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),
 };