Index is not an integer

Alan DeKok aland at deployingradius.com
Tue Dec 15 14:24:36 CET 2015


On Dec 15, 2015, at 8:17 AM, Franks Andy (IT Technical Architecture Manager) <Andy.Franks at sath.nhs.uk> wrote:
> Has anyone had any direct experience with using "%{xlat:..}". I can't seem to find much about using it directly, obviously xlats are used in ldap/sql/files etc a lot, any time you want to do anything directly outside a module, and they are super-useful but I haven't seen this used before to allow resolution of various levels of variable.

  The "%{foo}" thing is a normal expansion.  The difficulty is that sometimes you want to build custom expansions at run-time, and the server doesn't allow for that.

  e.g. if you build the expansion like this:

	update request {
		Tmp-String-0 := "sql:SELECT ..."
	}

  Then doing this:

	Foo = "%{Tmp-String-0}"

  will get you the *string value* of Tmp-String-0.  It won't run the expansion you've put into that string.

  The solution is %{xlat:...}.  It does *another* round of expansion on the input string.  So if "%{Tmp-String-0}" gets you the string for the SQL expansion, then "%{xlat:%{Tmp-String-0}}" will run the SQL expansion, and call SQL.

> I can't get it to do much, tried a simple:
> 
> Update control {
>  Tmp-Integer-0 := 3
>  Tmp-String-1 := "%{control:Tmp-Integer-0}"
>  Tmp-String-1 := "%{xlat:%{control:Tmp-Integer-0}}"
> }

  Well, yes.  Integers aren't strings.  The xlat expansion of "3" is equivalent to "%{3}".  Which is empty if you haven't done any regular expression matching.

> .. the first works as it should, but this xlat one is a mystery. Sorry for being a bit thick, possibly got it completely wrong.
> I could do a switch .. case dependent on a tracked variable, but it's not very nice and would result it lots of identical code blocks to maintain.
> 
> Sorry to be a pain, I did search around first even had a look at the source code, but it hurts my head.

  No worries.  Sometimes it hurts *my* head, and I've been doing this for almost 20 years.

  Alan DeKok.




More information about the Freeradius-Users mailing list