My environment is freeRADIUS 1.1.0 with mySQL 5.0.
MySQ 5.0 support stored procedures and function, so I’ve
defined a function called mac_check as follows:
CREATE FUNCTION `mac_check`(utente
VARCHAR(20),mac VARCHAR(30)) RETURNS varchar(50)
DETERMINISTIC
BEGIN
IF (SELECT (SELECT
MAX((Attribute='Calling-Station-Id')) from radcheck WHERE UserName=utente))
THEN
RETURN
'record already present';
END IF;
INSERT
INTO radcheck (UserName,Attribute,op,Value) VALUES
(utente,'Calling-Station-Id',':=', mac);
RETURN
'record inserted';
END
The function mac_check controls if Calling-Station-Id
is already present into radcheck table for key “utente”, if not “mac”
will be inserted.
The function will then be called from raddb/sql.conf
simply modifying the content of postauth_query:
was
postauth_query
= "INSERT into ${postauth_table} (id, user, pass, reply, date) values ('',
'%{User-Name}', '%{User-Password:-Chap-Password}', '%{reply:Packet-Type}',
NOW())"
become
postauth_query
= "SELECT mac_check(${postauth_table}, %{User-Name},
%{User-Password:-Chap-Password}, %{reply:Packet-Type}, %{Called-Station-Id})"
in this way I lost the entry into radpostauth table,
but this is not a big problem. I’ve modified the postauth_query thinking
that, acting like this, no modifications where necessary to rlm_sql.c file. In
fact, if I change the INSERT into postauth_query with a different one, this
work pretty good.
Unfortunately things seem to work in a dufferent way,
because the mac_check function is not recognized by freeRADIUS: from logs I can
see that it is not executed.... ;-(
I suppose that there is something to change into
rlm_sql.c file....
Any advice?
Thank you in advance
Carlo