freeradius

How do I make FreeRADIUS run an SQL query in default site?


What I want to do is to make FreeRADIUS run an SQL statement in a site file:

if(such and such condition is met){
  run_some_sql_query
}

How do I do that?


Solution

  • I Assume that you are trying to run the SQL on Unlang. (This file is located on sites-enabled/default or sites-available/default)

    First thing first, you should read about freeradius SQL https://wiki.freeradius.org/guide/sql-howto and https://wiki.freeradius.org/modules/Rlm_sql

    Later, you can use the SQL Xlat as written there

    Assumed that your unlang and sql module configuration is all set (your SQL module name is 'sql'), you can do something like this:

    if(such and such condition is met){
      "%{sql:SELECT * FROM radcheck WHERE username = '%{User-Name}'}"
      "%{sql:INSERT INTO radcheck (username, attribute, op, value) VALUES ('%{User-Name}', 'Cleartext-Password', ':=', 'dummyPassword');}"
    }