Creating in C++ Module for FreeRadius

Ruslan Shevchenko ruslan at shevchenko.kiev.ua
Mon Mar 11 16:35:52 CET 2013


Some time ago  I wrote C++ module for freeradius (to interact with billing
interface)  with next approach:

1.  write special c file where freeradius API is imported, and API which is
callable from "C++" for access to radius struct

2.  and special .h "freeradius_cpp_api.h" file where prototypes with this
"accessors from C++" is defined with external "C" linkage.

3.   import in c++ "freeradius_cpp_api.h" instead freeradius headers.

and at least with gcc - all works fine after linking with right libraries.



On Mon, Mar 11, 2013 at 3:58 PM, Patrick Ko <patrick0585 at googlemail.com>wrote:

> Hello everybody,
> here are my Steps how i created an C++ Module for FreeRadius.
>
>
>    - *Adaptions in the radiusd.conf*
>
>          Create an new Module Section like:
>
>
>
> modules {
>
>
>                         cpp {
>
>>
>                                }
>
>                 }
>
>
>
>    - Creating an new Directory in the modules Directory
>
>           I created an new Directory named "*rlm_cpp*" where I putted an
> Makefile and my *rlm_cpp.cpp* File
>
>
>           *Makefile:*
>
>           *TARGET      = rlm_cpp
> *
> *SRCS        = rlm_cpp.cpp
> *
> *HEADERS     =
> RLM_CFLAGS  =  -I/usr/include
> RLM_LIBS    =  -lc
> RLM_INSTALL = install-example
>
> ## this uses the RLM_CFLAGS and RLM_LIBS and SRCS defs to make TARGET.
> include ../rules.mak
>
> $(LT_OBJS): $(HEADERS)
>
> ## the rule that RLM_INSTALL tells the parent rules.mak to use.
> install-example:
>         touch .*
>
>
> My outgoing rlm_cpp.cpp File was the *.c File I took.
> Then I need to change every function of this file like this:
>
> *extern "C"* {
> static int cpp_authorize(void *instance, REQUEST *request)
> {
> ...
> }
> }
>
> Then I added two DEFINES at the TOP of my rlm_cpp.cpp File, because the
> two words are reserved names in in C.
>
> *#define operator op3578000
> #define template tem34123*
>
> At the end I needed to change the the struct. First I changed the struct
> in radiusd.conf
>
> struct auth_req {
> ...
> home_server*_t *                    *home_server
> ...
> }
>
> typedef struct radclient {
> ...
> home_server*_t *          *coa_server;
> ...
> } RADCLIENT;
>
> Also change the Typedef to:
>
> typedef struct home_server {
> ...
> }home_server*_t;*
>
> Every struct in the Source of FreeRadius need to be changed to *
> home_server_t*!
>
>
> 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!
>
>
> Greetz
> Patrick
>
>
> -
> List info/subscribe/unsubscribe? See
> http://www.freeradius.org/list/devel.html
>



-- 
Ruslan Shevchenko
Software Engineer.
http://ua.linkedin.com/in/ruslanshevchenko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freeradius.org/pipermail/freeradius-devel/attachments/20130311/7108c5d5/attachment.html>


More information about the Freeradius-Devel mailing list