Using attribute reference from variable content in unlang

Charles-Antoine Guillat-Guignard xarli at xarli.net
Mon Jan 30 15:47:11 UTC 2023



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 at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 236 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freeradius.org/pipermail/freeradius-users/attachments/20230130/5f80d1dc/attachment-0001.sig>


More information about the Freeradius-Users mailing list