<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
{margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:Arial;}
@page Section1
{size:595.3pt 841.9pt;
margin:70.85pt 107.65pt 2.0cm 107.65pt;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=IT link=blue vlink=purple>
<div class=Section1>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'>My environment is freeRADIUS 1.1.0 with mySQL 5.0.<o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'>MySQ 5.0 support stored procedures and function, so I’ve
defined a function called mac_check as follows:<o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'><o:p> </o:p></span></font></p>
<p class=MsoPlainText style='text-indent:35.4pt'><font size=2 face=Arial><span
lang=EN-GB style='font-size:10.0pt'>CREATE FUNCTION `mac_check`(utente
VARCHAR(20),mac VARCHAR(30)) RETURNS varchar(50)<o:p></o:p></span></font></p>
<p class=MsoPlainText style='text-indent:35.4pt'><font size=2 face=Arial><span
lang=EN-GB style='font-size:10.0pt'> DETERMINISTIC<o:p></o:p></span></font></p>
<p class=MsoPlainText style='text-indent:35.4pt'><font size=2 face=Arial><span
lang=EN-GB style='font-size:10.0pt'>BEGIN<o:p></o:p></span></font></p>
<p class=MsoPlainText style='text-indent:35.4pt'><font size=2 face=Arial><span
lang=EN-GB style='font-size:10.0pt'>IF (SELECT (SELECT
MAX((Attribute='Calling-Station-Id')) from radcheck WHERE UserName=utente))<o:p></o:p></span></font></p>
<p class=MsoPlainText style='text-indent:35.4pt'><font size=2 face=Arial><span
lang=EN-GB style='font-size:10.0pt'>THEN<o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'> RETURN
'record already present';<o:p></o:p></span></font></p>
<p class=MsoPlainText style='text-indent:35.4pt'><font size=2 face=Arial><span
lang=EN-GB style='font-size:10.0pt'>END IF;<o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'> INSERT
INTO radcheck (UserName,Attribute,op,Value) VALUES
(utente,'Calling-Station-Id',':=', mac);<o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'> RETURN
'record inserted';<o:p></o:p></span></font></p>
<p class=MsoPlainText style='text-indent:35.4pt'><font size=2 face=Arial><span
lang=EN-GB style='font-size:10.0pt'>END<o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'><o:p> </o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'>The function mac_check controls if Calling-Station-Id
is already present into radcheck table for key “utente”, if not “mac”
will be inserted.<o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'>The function will then be called from raddb/sql.conf
simply modifying the content of postauth_query:<o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'><o:p> </o:p></span></font></p>
<p class=MsoPlainText style='text-indent:35.4pt'><font size=2 face=Arial><span
lang=EN-GB style='font-size:10.0pt'>was<o:p></o:p></span></font></p>
<p class=MsoNormal style='margin-left:35.4pt;text-autospace:none'><font size=2
face=Arial><span lang=EN-GB style='font-size:10.0pt;font-family:Arial'>postauth_query
= "INSERT into ${postauth_table} (id, user, pass, reply, date) values ('',
'%{User-Name}', '%{User-Password:-Chap-Password}', '%{reply:Packet-Type}',
NOW())" <o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'> become<o:p></o:p></span></font></p>
<p class=MsoNormal style='margin-left:35.4pt;text-autospace:none'><font size=2
face=Arial><span lang=EN-GB style='font-size:10.0pt;font-family:Arial'>postauth_query
= "SELECT mac_check(${postauth_table}, %{User-Name},
%{User-Password:-Chap-Password}, %{reply:Packet-Type}, %{Called-Station-Id})"<o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'><o:p> </o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'>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.<o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'>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.... ;-(<o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'>I suppose that there is something to change into
rlm_sql.c file....<o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'><o:p> </o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'>Any advice?<o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'>Thank you in advance<o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face=Arial><span lang=EN-GB
style='font-size:10.0pt'>Carlo<o:p></o:p></span></font></p>
</div>
</body>
</html>