]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move to using new function syntax
authorAlan T. DeKok <aland@freeradius.org>
Mon, 27 Nov 2023 15:50:17 +0000 (10:50 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 27 Nov 2023 16:06:12 +0000 (11:06 -0500)
and regularize the names.

doc/antora/modules/raddb/nav.adoc
doc/antora/modules/raddb/pages/mods-available/dict.adoc [new file with mode: 0644]
raddb/mods-available/dict [new file with mode: 0644]
src/modules/rlm_dict/rlm_dict.c
src/tests/modules/dict/map.unlang

index 0aab4be4ee931d4460bb56b494a14bdd9b4d4408..9cc199a2b6bcba25c2b5496d96236daa4f371ae1 100644 (file)
@@ -28,6 +28,7 @@
 *** xref:mods-available/detail.log.adoc[Detail Module (Log Sample)]
 *** xref:mods-available/dhcp_sqlippool.adoc[DHCP SQL-IP-Pool Module]
 *** xref:mods-available/dhcpv4.adoc[DHCPv4 Module]
+*** xref:mods-available/dict.adoc[Dict Module]
 *** xref:mods-available/digest.adoc[Digest Module]
 *** xref:mods-available/eap.adoc[EAP Module]
 *** xref:mods-available/eap_inner.adoc[EAP/Inner Module]
diff --git a/doc/antora/modules/raddb/pages/mods-available/dict.adoc b/doc/antora/modules/raddb/pages/mods-available/dict.adoc
new file mode 100644 (file)
index 0000000..915af55
--- /dev/null
@@ -0,0 +1,91 @@
+
+
+
+
+= Dict Module
+
+The `dict` module registers expansions which query the dictionaries.
+
+
+## Expansions
+
+The following expansions allow querying the dictionaries.
+
+### %dict.attr(_<string>_)
+
+Takes an attribute name, and returns the canonicalized name of the attribute.
+
+If the attribute does not exist, nothing is returned.
+
+.Return: _string_
+
+### %dict.attr.by.num(_<uint32>_)
+
+Takes an attribute number, and returns the canonicalized name of the attribute.
+
+If the attribute does not exist, nothing is returned.
+
+This function is useful only for "top level" attributes such as `link:https://freeradius.org/rfc/rfc2865.html#User-Name[User-Name]`.
+Where the attribute is nested, use `%dict.attr.by.oid()` instead.
+
+.Return: _string_
+
+### %dict.attr.by.oid(_<string>_)
+
+Takes a full OID reference (e.g. `26.9.1`), and returns the name of
+the attribute.
+
+If the attribute does not exist, nothing is returned.
+
+.Return: _string_
+
+### %dict.attr.num(_<string>_)
+
+Takes an attribute name, and returns the number of the attribute.
+
+If the attribute does not exist, nothing is returned.
+
+Note that only the _final_ attribute number is returned.  For example, the OID
+for `Vendor-Specific.Cisco.AVPair` is `26.9.1`.  This function will return
+`1`, and not the full OID.
+
+.Return: _uint32_
+
+### %dict.attr.type(_<string>_)
+
+Takes an attribute name, and returns the data type of the attribute.
+
+If the attribute does not exist, nothing is returned.
+
+.Return: _string_
+
+### %dict.vendor(_<string>_)
+
+Takes an vendor name, and returns the canonicalized name of the vendor.
+
+If the vendor does not exist, nothing is returned.
+
+.Return: _string_
+
+### %dict.vendor.by.num(_<uint32>_)
+
+Takes an vendor number, and returns the canonicalized name of the vendor.
+
+If the vendor does not exist, nothing is returned.
+
+.Return: _string_
+
+
+
+## Configuration Settings
+
+This module takes no configuration.
+
+
+
+== Default Configuration
+
+```
+dict {
+}
+```
diff --git a/raddb/mods-available/dict b/raddb/mods-available/dict
new file mode 100644 (file)
index 0000000..bc19695
--- /dev/null
@@ -0,0 +1,89 @@
+#  -*- text -*-
+#
+#
+#  $Id$
+
+#######################################################################
+#
+#  = Dict Module
+#
+#  The `dict` module registers expansions which query the dictionaries.
+
+#
+#  ## Expansions
+#
+#  The following expansions allow querying the dictionaries.
+#
+#  ### %dict.attr(_<string>_)
+#
+#  Takes an attribute name, and returns the canonicalized name of the attribute.
+#
+#  If the attribute does not exist, nothing is returned.
+#
+#  .Return: _string_
+#
+#  ### %dict.attr.by.num(_<uint32>_)
+#
+#  Takes an attribute number, and returns the canonicalized name of the attribute.
+#
+#  If the attribute does not exist, nothing is returned.
+#
+#  This function is useful only for "top level" attributes such as `User-Name`.
+#  Where the attribute is nested, use `%dict.attr.by.oid()` instead.
+#
+#  .Return: _string_
+#
+#  ### %dict.attr.by.oid(_<string>_)
+#
+#  Takes a full OID reference (e.g. `26.9.1`), and returns the name of
+#  the attribute.
+#
+#  If the attribute does not exist, nothing is returned.
+#
+#  .Return: _string_
+#
+#  ### %dict.attr.num(_<string>_)
+#
+#  Takes an attribute name, and returns the number of the attribute.
+#
+#  If the attribute does not exist, nothing is returned.
+#
+#  Note that only the _final_ attribute number is returned.  For example, the OID
+#  for `Vendor-Specific.Cisco.AVPair` is `26.9.1`.  This function will return
+#  `1`, and not the full OID.
+#
+#  .Return: _uint32_
+#
+#  ### %dict.attr.type(_<string>_)
+#
+#  Takes an attribute name, and returns the data type of the attribute.
+#
+#  If the attribute does not exist, nothing is returned.
+#
+#  .Return: _string_
+#
+#  ### %dict.vendor(_<string>_)
+#
+#  Takes an vendor name, and returns the canonicalized name of the vendor.
+#
+#  If the vendor does not exist, nothing is returned.
+#
+#  .Return: _string_
+#
+#  ### %dict.vendor.by.num(_<uint32>_)
+#
+#  Takes an vendor number, and returns the canonicalized name of the vendor.
+#
+#  If the vendor does not exist, nothing is returned.
+#
+#  .Return: _string_
+#
+
+#
+#  ## Configuration Settings
+#
+#  This module takes no configuration.
+#
+dict {
+
+}
index 9f6ba3946d21d9db16405f2592bd4bde4993f1e6..9cff7d611774aa298b52ae97d27109b00a9964ce 100644 (file)
@@ -216,6 +216,27 @@ static xlat_action_t xlat_attr_num(TALLOC_CTX *ctx, fr_dcursor_t *out,
        return XLAT_ACTION_DONE;
 }
 
+/** Return the data type of an attribute reference
+ *
+ * @ingroup xlat_functions
+ */
+static xlat_action_t xlat_attr_type(TALLOC_CTX *ctx, fr_dcursor_t *out,
+                                  UNUSED xlat_ctx_t const *xctx,
+                                  request_t *request, fr_value_box_list_t *in)
+{
+       fr_pair_t       *vp;
+       fr_value_box_t  *attr = fr_value_box_list_head(in);
+       fr_value_box_t  *vb;
+
+       if ((xlat_fmt_get_vp(&vp, request, attr->vb_strvalue) < 0) || !vp) return XLAT_ACTION_FAIL;
+
+       MEM(vb = fr_value_box_alloc_null(ctx));
+
+       fr_value_box_strdup(vb, vb, vp->da, fr_type_to_str(vp->vp_type), false);
+       fr_dcursor_append(out, vb);
+       return XLAT_ACTION_DONE;
+}
+
 #define XLAT_REGISTER(_name, _func, _type, _args) \
 if (unlikely(!(xlat = xlat_func_register(NULL, _name, _func, _type)))) return -1; \
 xlat_func_args_set(xlat, _args)
@@ -224,24 +245,24 @@ static int mod_load(void)
 {
        xlat_t  *xlat;
 
-       XLAT_REGISTER("attr_by_num", xlat_dict_attr_by_num, FR_TYPE_STRING, xlat_dict_attr_by_num_args);
-       XLAT_REGISTER("attr_by_oid", xlat_dict_attr_by_oid, FR_TYPE_STRING, xlat_dict_attr_by_oid_args);
-       XLAT_REGISTER("vendor", xlat_vendor, FR_TYPE_STRING, xlat_vendor_args);
-       XLAT_REGISTER("vendor_num", xlat_vendor_num, FR_TYPE_UINT32, xlat_vendor_num_args);
-       XLAT_REGISTER("attr", xlat_attr, FR_TYPE_STRING, xlat_attr_args);
-       XLAT_REGISTER("attr_num", xlat_attr_num, FR_TYPE_UINT32, xlat_attr_num_args);
-
+       XLAT_REGISTER("dict.attr.by.num", xlat_dict_attr_by_num, FR_TYPE_STRING, xlat_dict_attr_by_num_args);
+       XLAT_REGISTER("dict.attr.by.oid", xlat_dict_attr_by_oid, FR_TYPE_STRING, xlat_dict_attr_by_oid_args);
+       XLAT_REGISTER("dict.vendor", xlat_vendor, FR_TYPE_STRING, xlat_vendor_args);
+       XLAT_REGISTER("dict.vendor.num", xlat_vendor_num, FR_TYPE_UINT32, xlat_vendor_num_args);
+       XLAT_REGISTER("dict.attr", xlat_attr, FR_TYPE_STRING, xlat_attr_args);
+       XLAT_REGISTER("dict.attr.num", xlat_attr_num, FR_TYPE_UINT32, xlat_attr_num_args);
+       XLAT_REGISTER("dict.attr.type", xlat_attr_type, FR_TYPE_STRING, xlat_attr_args);
        return 0;
 }
 
 static void mod_unload(void)
 {
-       xlat_func_unregister("attr_by_num");
-       xlat_func_unregister("attr_by_oid");
-       xlat_func_unregister("vendor");
-       xlat_func_unregister("vendor_num");
-       xlat_func_unregister("attr");
-       xlat_func_unregister("attr_num");
+       xlat_func_unregister("dict.attr.by.num");
+       xlat_func_unregister("dict.attr.by.oid");
+       xlat_func_unregister("dict.vendor");
+       xlat_func_unregister("dict.vendor.num");
+       xlat_func_unregister("dict.attr");
+       xlat_func_unregister("dict.attr.num");
 }
 
 extern module_rlm_t rlm_dict;
index da936386c63e0bd21e7ef919cf5d3a0ae97cff18..7efe536e6f6464117d5d95aa5f47a3e80a420952 100644 (file)
@@ -2,57 +2,65 @@
 
 &Reply-Message := 'foo'
 
-if ("%(attr_by_num:1)" != 'User-Name') {
+if (%dict.attr.by.num(1) != 'User-Name') {
        test_fail
 }
 
-if ("%(attr_by_oid:1)" != 'User-Name') {
+if (%dict.attr.by.oid(1) != 'User-Name') {
        test_fail
 }
 
 # Should fail
-if ("%(attr_by_oid:26)" != 'Vendor-Specific') {
+if (%dict.attr.by.oid(26) != 'Vendor-Specific') {
        test_fail
 }
 
 # Should fail
-if ("%(attr_by_oid:26.11344)" != 'FreeRADIUS') {
+if (%dict.attr.by.oid(26.11344) != 'FreeRADIUS') {
        test_fail
 }
 
-if ("%(attr_by_oid:26.11344.1)" != 'Proxied-To') {
+if (%dict.attr.by.oid(26.11344.1) != 'Proxied-To') {
        test_fail
 }
 
-if ("%(attr:Vendor-Specific.FreeRADIUS.Proxied-To)" != 'Proxied-To') {
+if (%dict.attr('Vendor-Specific.FreeRADIUS.Proxied-To') != 'Proxied-To') {
        test_fail
 }
 
-if ("%(attr_num:Vendor-Specific.FreeRADIUS.Proxied-To)" != 1) {
+if (%dict.attr.num('Vendor-Specific.FreeRADIUS.Proxied-To') != 1) {
        test_fail
 }
 
-if ("%(vendor:Vendor-Specific.FreeRADIUS.Proxied-To)" != 'FreeRADIUS') {
+if (%dict.vendor('Vendor-Specific.FreeRADIUS.Proxied-To') != 'FreeRADIUS') {
        test_fail
 }
 
-if ("%(vendor_num:Vendor-Specific.FreeRADIUS.Proxied-To)" != 11344) {
+if (%dict.vendor.num('Vendor-Specific.FreeRADIUS.Proxied-To') != 11344) {
        test_fail
 }
 
-if ("%(attr:Reply-Message)" != 'Reply-Message') {
+if (%dict.attr('Reply-Message') != 'Reply-Message') {
        test_fail
 }
 
-if ("%(attr_num:Reply-Message)" != 18) {
+if (%dict.attr.num('Reply-Message') != 18) {
        test_fail
 }
 
-if ("%(vendor:Reply-Message)" != '') {
+if %dict.vendor('Reply-Message') {
        test_fail
 }
 
-if ("%(vendor_num:Reply-Message)" != 0) {
+if (%dict.vendor.num('Reply-Message') != 0) {
+       test_fail
+}
+
+if (%dict.attr.type ('User-Name') != 'string') {
+       test_fail
+}
+
+if (%dict.attr.type ('Vendor-Specific') != 'vendor') {
        test_fail
 }