Using configuration items in strings

Alan DeKok aland at deployingradius.com
Fri Feb 14 20:47:48 CET 2014


Caines, Max wrote:
> I'm trying to make some of my configuration dependent on whether I've configured SQL, so I can create an easy way to turn off all use of SQL by our servers (we don't have a cluster, and we don't use the SQL server for authentication, so if it went down, we could do without it for a bit). I've used an "if" statement testing "%{config:modules.sql.server}", which I expected to give me the value "NPS" if I had set the value and null otherwise.

  No.  You are mixing up run-time variables and configuration variables.

  $[...} are configuration variables.  They are expanded when the server
reads the configuration files, and are *static* after that.

  %{...} are run-time variables.  They exist ONLY when the server
processes a request.

  So %{config:...} is only expanded when the server is processing a
request, and NEVER otherwise.

  I'm really not clear what you're trying to do here.  You've posted a
long explanation, and a big debug output.  But there's no simple example:

  I tried "X" and I expected to see "Y".  Instead I saw "Z".

  My guess is that you're trying to conditionally disable parts of the
configuration when the server loads.  This is not possible in 2.x.  You
will need to run version 3 for that.

  In version 3, you can do:

	if (condition) {
		blah
	}

  If the condition statically evaluates to zero, the following block is
ignored.  If the condition statically evaluates to non-zero, then the
block is used, and the "if" statement acts like it's not there.

  e.g.

	foo = 0
	...
	authorize {
		...
		if (${foo}) {
			sql
		}
		...
	}

  Will cause the "sql" reference to be ignored.

  Note that you CANNOT do:

		if ("${foo}") {

		}

  The use of a double-quoted string tells the server that the string is
expanded dynamically at run-time, and therefore the text is used as-is
when the server starts up

  Alan DeKok.


More information about the Freeradius-Users mailing list