Hello everybody,<br>here are my Steps how i created an C++ Module for
FreeRadius.<br>
<ul><li><b>Adaptions in the radiusd.conf</b> </li></ul> Create an new Module
Section like:<br><br>
<p>modules {
</p>
<p> cpp { </p>
<p> … </p>
<p> } </p>
<p> } </p>
<p><br></p>
<ul><li>Creating an new Directory in the modules Directory </li></ul> I
created an new Directory named "<b>rlm_cpp</b>" where I putted an Makefile and
my <b>rlm_cpp.cpp</b> File<br><br><br>
<b>Makefile:</b><br><br> <i>TARGET = rlm_cpp</i>
<br><i>SRCS = rlm_cpp.cpp </i><br><i>HEADERS = <br>RLM_CFLAGS =
-I/usr/include<br>RLM_LIBS = -lc<br>RLM_INSTALL = install-example<br><br>##
this uses the RLM_CFLAGS and RLM_LIBS and SRCS defs to make TARGET.<br>include
../rules.mak<br><br>$(LT_OBJS): $(HEADERS)<br><br>## the rule that RLM_INSTALL
tells the parent rules.mak to use.<br>install-example:<br> touch
.</i><br><br><br>My outgoing rlm_cpp.cpp File was the *.c File I took.<br>Then I
need to change every function of this file like this:<br><b><br>extern "C"</b> {
<br>static int cpp_authorize(void *instance, REQUEST *request)<br>{ <br>...
<br>} <br>}<br><br>Then I added two DEFINES at the TOP of my rlm_cpp.cpp File,
because the two words are reserved names in in C.<br><b><br>#define operator
op3578000<br>#define template tem34123</b><br><br>At the end I needed to change
the the struct. First I changed the struct in radiusd.conf<br><br>struct
auth_req { <br>...<br>home_server<b>_t </b>
*home_server<br>... <br>}<br><br>typedef struct radclient {<br>...
<br>home_server<b>_t </b> *coa_server; <br>...<br>}
RADCLIENT;<br><br>Also change the Typedef to:<br><br>typedef struct home_server
{<br>...<br>}home_server<b>_t;</b><br><br>Every struct in the Source of
FreeRadius need to be changed to <b>home_server_t</b>!<br><br><br>now you should
made finallay the main make and see the all should be fine compiled! at the end
run "make install " and implement the new C++ Module in an Section in the
radiusd.conf and it will run!<br><br>My class looks so:<br><br>
<div class="moz-text-html" lang="x-western"><font face="sans-serif">#define
operator op3578000</font> <br><font face="sans-serif">#define template
tem34123</font> <br><br><font face="sans-serif">extern "C" {</font>
<br><font face="sans-serif"> #include
<freeradius-devel/ident.h></font> <br><font face="sans-serif">
#include <stdio.h></font> <br><font face="sans-serif"> #include
<stdlib.h></font> <br><font face="sans-serif"> #include
<string.h></font> <br><font face="sans-serif"> RCSID("$Id$")
</font> <br><font face="sans-serif"> #include
<freeradius-devel/radiusd.h></font> <br><font face="sans-serif">
#include <freeradius-devel/modules.h></font> <br><br><font face="sans-serif"> </font> <br><font face="sans-serif">typedef struct
rlm_cpp_t {</font> <br><font face="sans-serif"> int
boolean;</font> <br><font face="sans-serif"> int
value;</font> <br><font face="sans-serif"> char
*string;</font> <br><font face="sans-serif"> uint32_t
ipaddr;</font> <br><font face="sans-serif">} rlm_cpp_t;</font>
<br><br><br><br><font face="sans-serif">extern "C" </font><br><font face="sans-serif">const CONF_PARSER module_config[] = {</font> <br><font face="sans-serif"> { "integer", PW_TYPE_INTEGER, offsetof(rlm_cpp_t,value),
NULL, "1" },</font> <br><font face="sans-serif"> { "boolean",
PW_TYPE_BOOLEAN, offsetof(rlm_cpp_t,boolean), NULL, "no"},</font> <br><font face="sans-serif"> { "string", PW_TYPE_STRING_PTR,
offsetof(rlm_cpp_t,string), NULL, NULL},</font> <br><font face="sans-serif"> { "ipaddr", PW_TYPE_IPADDR, offsetof(rlm_cpp_t,ipaddr),
NULL, "*"},</font> <br><font face="sans-serif"> </font><br><br><font face="sans-serif"> { NULL, -1, 0, NULL, NULL } /* end the list
*/</font> <br><font face="sans-serif">};</font>
<br><br><br><br><br><br><font face="sans-serif">extern "C" {</font>
<br><font face="sans-serif">static int cpp_instantiate(CONF_SECTION *conf,
void **instance)</font> <br><font face="sans-serif">{</font> <br><font face="sans-serif"> ...</font> <br><font face="sans-serif">
return RLM_MODULE_OK;</font> <br><font face="sans-serif">}</font>
<br><font face="sans-serif">}</font> <br><br><br><font face="sans-serif">extern "C" {</font> <br><font face="sans-serif">static int
cpp_post_auth(void *instance, REQUEST *request)</font> <br><font face="sans-serif">{ </font><br><font face="sans-serif"> VALUE_PAIR
*reply;</font> <br><font face="sans-serif"> VALUE_PAIR *state;</font>
<br><br><font face="sans-serif"> </font><br><font face="sans-serif"> ...</font> <br><br><font face="sans-serif"> return
RLM_MODULE_OK;</font> <br><font face="sans-serif">}</font> <br><font face="sans-serif">}</font> <br><br><br><br><font face="sans-serif">extern "C"
{</font> <br><font face="sans-serif">static int cpp_preacct(void *instance,
REQUEST *request)</font> <br><font face="sans-serif">{</font> <br><font face="sans-serif"> /* quiet the compiler */</font> <br><font face="sans-serif"> instance = instance;</font> <br><font face="sans-serif"> request = request; </font><br>
<font face="sans-serif"> </font><br><font face="sans-serif"> ...</font>
<br><font face="sans-serif"> </font> <br><font face="sans-serif"> return RLM_MODULE_OK;</font> <br><font face="sans-serif">}</font> <br><font face="sans-serif">}</font>
<br><br><br><font face="sans-serif">extern "C" {</font> <br><font face="sans-serif">static int cpp_authorize(void *instance, REQUEST
*request)</font> <br><font face="sans-serif">{</font> <br><font face="sans-serif"> /* quiet the compiler */</font> <br><font face="sans-serif"> instance = instance;</font> <br><font face="sans-serif"> request = request; </font><br>
<br><font face="sans-serif"> ...</font> <br><br><font face="sans-serif"> return
RLM_MODULE_OK; </font> <br><font face="sans-serif">}</font> <br><font face="sans-serif">}</font> <br><br><br><br><br><br><font face="sans-serif">extern "C" {</font> <br><font face="sans-serif">module_t
rlm_cpp = {</font> <br><font face="sans-serif">
RLM_MODULE_INIT,</font> <br><font face="sans-serif"> "cpp",</font>
<br><font face="sans-serif"> RLM_TYPE_THREAD_SAFE, /* type
*/</font> <br><font face="sans-serif"> cpp_instantiate, /*
instantiation */</font> <br><font face="sans-serif"> NULL,
/* detach */</font> <br><font face="sans-serif">
{</font> <br><font face="sans-serif"> NULL,
/* authentication */</font> <br><font face="sans-serif">
cpp_authorize, /* authorization */</font> <br><font face="sans-serif"> cpp_preacct, /* preaccounting */</font>
<br><font face="sans-serif"> NULL, /*
accounting */</font> <br><font face="sans-serif"> NULL,
/* checksimul */</font> <br><font face="sans-serif">
NULL, /* pre-proxy */</font> <br><font face="sans-serif">
NULL, /* post-proxy */</font> <br><font face="sans-serif"> cpp_post_auth /* post-auth */</font>
<br><font face="sans-serif"> },</font> <br><font face="sans-serif">};</font> <br><font face="sans-serif">} </font>
</div><br><br><br><br>Greetz<br>Patrick