unlang, variable and SQL (freeradius 3.0.15)

petr.linke at seznam.cz petr.linke at seznam.cz
Tue Oct 3 16:19:08 CEST 2017


Hi,
I try to store result from SQL into local variable to eliminate running same
queries at time.

I prepare following scenario:

1/ define new attribute (will be used for store the result from SQL) in the 
dictionary, attribute type is string (e.g. ATTRIBUTE       SQLRESULT        
        3000    string)
2/ in inner tunnel post-auth section:
update control {
               &SQLRESULT = "%{sql::SELECT count(*) from some_table where ..
.}"
}
if ( %{integer:SQLRESULT} == some_value ) {
    ...
}
elsif ( %{integer:SQLRESULT} == other_value ) {
...
}

in debug I can see, that the SQL return some value, and the value is filled 
into attribute &SQLRESULT, but afterwards condition do not match (attribute 
has no value)

(10)         EXPAND %{sql:SELECT count(*) from table where username = '%
{User-Name}' ...
(10)            --> 2
(10)         &SQLRESULT = 2
(10)       } # update control = noop
(10)       if ("%{integer:SQLRESULT}" == 2) {
(10)       EXPAND %{integer:SQLRESULT}
(10)          --> 
(10)       if ("%{integer:SQLRESULT}" == 2)  -> FALSE

Maybe I do not fully understand unlang. Is possible to store the result from
SQL in some variable, and afterward use this variable in some conditions?

Thank you for any suggestion, Petr Linke


More information about the Freeradius-Users mailing list