Creating in C++ Module for FreeRadius

Arran Cudbard-Bell a.cudbardb at freeradius.org
Mon Mar 11 15:41:31 CET 2013


> 
> 	• 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

You have to link to libc explicitly?

> 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)
> {
> ...
> }
> }

Still not 100% sure whether this is required, my suspicion is that the module will still link and execute, but that it's probably good practice to declare the C linkages explicity.

In any case I think you can just do :

extern "C" static int cpp_authorize(void *instance, REQUEST *request)
{

}

Looks cleaner.

> 
> 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

You mean in C++, they're not reserved keywords in C. I already changed "op" in master, i'll have a look at template.

> At the end I needed to change the the struct. First I changed the struct in radiusd.conf

radiusd.conf is a configuration file...

> 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!

Does the _t have a special significance in C++ or did you just want to follow convention?

> 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!

Sure. This is nice and all, but if you want your modules in the standard distribution of FreeRADIUS it's probably better to just write them in C. The only exception would be if they dependended on an external library for which there was no C equivalent, or which did not expose a C API (the MySQL ndb client library is like this, which is why i've also been investigating).

Interesting all the same. Thanks for posting the info.

-Arran


More information about the Freeradius-Devel mailing list