From: Alan T. DeKok Date: Mon, 27 Nov 2023 15:50:17 +0000 (-0500) Subject: move to using new function syntax X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03a8e4bb6c220ef0acf573f5721a2d791dd79d40;p=thirdparty%2Ffreeradius-server.git move to using new function syntax and regularize the names. --- diff --git a/doc/antora/modules/raddb/nav.adoc b/doc/antora/modules/raddb/nav.adoc index 0aab4be4ee9..9cc199a2b6b 100644 --- a/doc/antora/modules/raddb/nav.adoc +++ b/doc/antora/modules/raddb/nav.adoc @@ -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 index 00000000000..915af5569bd --- /dev/null +++ b/doc/antora/modules/raddb/pages/mods-available/dict.adoc @@ -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(__) + +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(__) + +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(__) + +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(__) + +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(__) + +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(__) + +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(__) + +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 index 00000000000..bc19695c1d9 --- /dev/null +++ b/raddb/mods-available/dict @@ -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(__) +# +# 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(__) +# +# 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(__) +# +# 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(__) +# +# 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(__) +# +# 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(__) +# +# 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(__) +# +# 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 { + +} diff --git a/src/modules/rlm_dict/rlm_dict.c b/src/modules/rlm_dict/rlm_dict.c index 9f6ba3946d2..9cff7d61177 100644 --- a/src/modules/rlm_dict/rlm_dict.c +++ b/src/modules/rlm_dict/rlm_dict.c @@ -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; diff --git a/src/tests/modules/dict/map.unlang b/src/tests/modules/dict/map.unlang index da936386c63..7efe536e6f6 100644 --- a/src/tests/modules/dict/map.unlang +++ b/src/tests/modules/dict/map.unlang @@ -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 }