More efficient programming of the unlang language

Matthew Newton mcn at freeradius.org
Mon Apr 23 16:13:04 CEST 2018


On Mon, 2018-04-23 at 15:56 +0200, Marijn van Gool wrote:
> 
> if ("%{sql:SELECT username FROM radcheck WHERE username LIKE
> '%{string:&ADSL-Agent-Remote-Id}@%%' LIMIT 1}" != "") {
> 	update request {
>         	User-Name := "%{sql:SELECT username FROM radcheck
> WHERE username LIKE '%{string:&ADSL-Agent-Remote-Id}@%%' LIMIT 1}"
> 	}        
> }
> 
> Basically what Iā€™m trying to do is to check if the query in question
> returns the username and to use this username in a self created
> variable later on.
> Something like this:
> 
> username-var = SELECT query;
> 
> if (username-var != ā€œā€) {
> 	update-request {
> 		User-Name := username-var
> 	}
> }
> 
> How would I achieve this? What is the syntax that can be used here?

Pretty much what you've written? This is all in the unlang man page.

Use a temporary attribute, something like

update control {
	&Tmp-String-1 := "%{sql:SELECT username .....}"
}        

if (&control:Tmp-String-1) {
	update request {
        	&User-Name := &control:Tmp-String-1
	}        
}

I'd update the things that use the User-Name attribute, though, rather
than changing the attribute itself.

-- 
Matthew



More information about the Freeradius-Users mailing list