Using attribute reference from variable content in unlang
Hello, I am trying to implement some db based attribute handling (names, operator and values from db), and I am struggling with a dynamic handling of attributes references (names). Looking at https://freeradius.org/radiusd/man/unlang.txt (ATTRIBUTE REFERENCES section), I see no exemple matching what I want to do (attribute name is always known, and static). What I try to achieve would look a bit like that (which doesn't work) : : # Exemple for Attributes-Actions values # A-AL-AAA,:=,1 # A-AL-DHCP,:=,0 foreach &Attributes-Actions { update request { Attributes-Action := "%{Foreach-Variable-2}" } %{explode:Attributes-Action ,} update reply { # for debugging, contains expected value Reply-Message += "index 0 : %{Attributes-Action[0]}" # this fails "%{Attributes-Action[0]}" := "%{Attributes-Action[2]}" } } Am I missing something? Is there another way to achieve dynamic handling of attributes names, to be able to modify an attribute whose name/reference is not pre-declared in unlang script (unknown in unlang script, but ofc declared in dictionary). Thank you in advance. Kind regards, Charles-Antoine Guillat-Guignard
Even if I doubt it changes anything, my Freeradius version is 3.0.12, sorry I forgot to precise. Kind regards, Charles-Antoine Guillat-Guignard Le 30/01/2023 à 10:19, Charles-Antoine Guillat-Guignard via Freeradius-Users a écrit :
Hello,
I am trying to implement some db based attribute handling (names, operator and values from db), and I am struggling with a dynamic handling of attributes references (names).
Looking at https://freeradius.org/radiusd/man/unlang.txt (ATTRIBUTE REFERENCES section), I see no exemple matching what I want to do (attribute name is always known, and static).
What I try to achieve would look a bit like that (which doesn't work) : :
# Exemple for Attributes-Actions values # A-AL-AAA,:=,1 # A-AL-DHCP,:=,0
foreach &Attributes-Actions { update request { Attributes-Action := "%{Foreach-Variable-2}" }
%{explode:Attributes-Action ,}
update reply { # for debugging, contains expected value Reply-Message += "index 0 : %{Attributes-Action[0]}" # this fails "%{Attributes-Action[0]}" := "%{Attributes-Action[2]}" } }
Am I missing something? Is there another way to achieve dynamic handling of attributes names, to be able to modify an attribute whose name/reference is not pre-declared in unlang script (unknown in unlang script, but ofc declared in dictionary).
Thank you in advance.
Kind regards,
Charles-Antoine Guillat-Guignard
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
On Jan 30, 2023, at 4:19 AM, Charles-Antoine Guillat-Guignard via Freeradius-Users <freeradius-users@lists.freeradius.org> wrote:
I am trying to implement some db based attribute handling (names, operator and values from db), and I am struggling with a dynamic handling of attributes references (names).
Looking at https://freeradius.org/radiusd/man/unlang.txt (ATTRIBUTE REFERENCES section), I see no exemple matching what I want to do (attribute name is always known, and static).
Yes.
What I try to achieve would look a bit like that (which doesn't work) : :
# Exemple for Attributes-Actions values # A-AL-AAA,:=,1 # A-AL-DHCP,:=,0
You could just put those fieds into a DB, and use the existing DB queries, such as SQL, but it doesn't matter a lot.
foreach &Attributes-Actions { update request { Attributes-Action := "%{Foreach-Variable-2}" }
%{explode:Attributes-Action ,}
update reply { # for debugging, contains expected value Reply-Message += "index 0 : %{Attributes-Action[0]}" # this fails "%{Attributes-Action[0]}" := "%{Attributes-Action[2]}" } }
The "update" syntax allows things like: update control { Tmp-String-0 := "&reply:Reply-Message" } update { "%{control:Tmp-String-0}" += "Hello" } That works. It's not well documented, but it does work. I'll see if I can poke it. Oh, and don't use 3.0.12. It's very old. There are updated packages available at http://packages.networkradius.com Alan DeKok.
Le 30/01/2023 à 14:33, Alan DeKok a écrit :
On Jan 30, 2023, at 4:19 AM, Charles-Antoine Guillat-Guignard via Freeradius-Users <freeradius-users@lists.freeradius.org> wrote:
I am trying to implement some db based attribute handling (names, operator and values from db), and I am struggling with a dynamic handling of attributes references (names).
Looking at https://freeradius.org/radiusd/man/unlang.txt (ATTRIBUTE REFERENCES section), I see no exemple matching what I want to do (attribute name is always known, and static).
Yes.
What I try to achieve would look a bit like that (which doesn't work) : :
# Exemple for Attributes-Actions values # A-AL-AAA,:=,1 # A-AL-DHCP,:=,0
You could just put those fieds into a DB, and use the existing DB queries, such as SQL, but it doesn't matter a lot.
That is one of the goals, and already done (which explain the missing depths of the Foreach-Variable-N), I did just cut out stuff that did not seem relevant to my issues to ask on the list.
foreach &Attributes-Actions { update request { Attributes-Action := "%{Foreach-Variable-2}" }
%{explode:Attributes-Action ,}
update reply { # for debugging, contains expected value Reply-Message += "index 0 : %{Attributes-Action[0]}" # this fails "%{Attributes-Action[0]}" := "%{Attributes-Action[2]}" } }
The "update" syntax allows things like:
update control { Tmp-String-0 := "&reply:Reply-Message" }
update { "%{control:Tmp-String-0}" += "Hello" }
That works. It's not well documented, but it does work. I'll see if I can poke it.
Struggling with my vendor specific attributes, but with your exemple it is of course working great. I will keep digging =)
Oh, and don't use 3.0.12. It's very old. There are updated packages available at http://packages.networkradius.com
Yes I am totally aware, sorry about that =/
Alan DeKok.
Thank you a lot for the syntax and quick answer! Kind regards, Charles-Antoine Guillat-Guignard
On Jan 30, 2023, at 10:47 AM, Charles-Antoine Guillat-Guignard via Freeradius-Users <freeradius-users@lists.freeradius.org> wrote:
Struggling with my vendor specific attributes, but with your exemple it is of course working great. I will keep digging =)
The VSAs are just like anything else. They have a name, and you use the name. But the name has to exist in the dictionaries. And I guarantee that "A-AL-AAA" isn't an attribute in the FreeRADIUS dictionaries. Alan DeKok.
participants (2)
-
Alan DeKok -
Charles-Antoine Guillat-Guignard