Using attribute reference from variable content in unlang

Alan DeKok aland at deployingradius.com
Mon Jan 30 13:33:11 UTC 2023


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.

> 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.



More information about the Freeradius-Users mailing list