Rlm_sql: dynamic queries

Dan-Cristian Bogos danb.lists at googlemail.com
Tue Mar 2 10:56:16 CET 2010


Hey Guys,

I came to need of doing dynamic queries with rlm_sql. However after
digging the docs and my way of understanding the architecture of
rlm_sql I am not sure I can do it in the way I want it.

Here is my scenaro:

I receive accounting records with more attributes with the same name
(resulting into freeradius in attribute lists).
I would like to run mysql multiple inserts in one query (possible with
mysql by enumerating values between brackets, eg: insert into table
(a, b) values (user-name[0], destination), (username[1], destination),
(username[2], destination). ).

My problem comes with the fact that the number of attributes in the
attribute list is variable, so I do not know how many attributes I
will get.

The solution I found is not very nice from my point of view:  I have
defined one rlm_sql instance for each fixed number of attributes in
the list with a static query and filtered the request in sites-enabled
based on the number of elements in the list, using something like:
switch "%{User-Name[#]}" {
       case 2 {
           sql_inst2
       }
       case 3 {
           sql_inst3
       }
       case {
           sql_inst1
       }
   }

Can anyone recommend me any better way of doing it (so I do not need
to define a query for a number of attributes, but have the query
generated in some automatic way, so I will only need one sql
instance)?

Ta,
DanB




More information about the Freeradius-Users mailing list