<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hello everybody I wantd to read out my huntgroups inside an Module
and not like normal in the "radiusd.conf" with preprocess !<br>
For that i needed to do the following changes in an C-Module :<br>
<br>
<font face="Courier New" size="1">typedef struct rlm_huntgroups_t {</font>
<br>
<font face="Courier New" size="1"> char
*huntgroup_file;</font>
<br>
<font face="Courier New" size="1"> PAIR_LIST
*huntgroups;</font>
<br>
<font face="Courier New" size="1"> </font>
<br>
<font face="Courier New" size="1">}rlm_huntgroups_t;</font>
<br>
<br>
<font face="Courier New" size="1">}</font>
<br>
<br>
<font face="Courier New" size="1">static const CONF_PARSER
module_config[]
= {</font>
<br>
<font face="Courier New" size="1"> { "huntgroups",
PW_TYPE_FILENAME,offsetof(rlm_huntgroups_t,huntgroup_file), NULL,
"${raddbdir}/huntgroups"},
</font>
<br>
<font face="Courier New" size="1"> </font>
<br>
<font face="Courier New" size="1"> { NULL,
-1, 0, NULL, NULL } /* end the list
*/</font>
<br>
<font face="Courier New" size="1">}; </font>
<br>
<br>
<br>
/* This function ist imported from the preprocess C-FIle */<br>
<font face="Courier New" size="1">static int hunt_paircmp(REQUEST
*req,
VALUE_PAIR *request, VALUE_PAIR *check)</font>
<br>
<font face="Courier New" size="1">{</font>
<br>
<font face="Courier New" size="1"> VALUE_PAIR
*check_item = check;</font>
<br>
<font face="Courier New" size="1"> VALUE_PAIR
*tmp;</font>
<br>
<font face="Courier New" size="1"> int
result = -1;</font>
<br>
<br>
<font face="Courier New" size="1"> if (check
== NULL) return 0;</font>
<br>
<br>
<font face="Courier New" size="1"> while (result
!= 0 && check_item != NULL) {</font>
<br>
<br>
<font face="Courier New" size="1">
tmp = check_item->next;</font>
<br>
<font face="Courier New" size="1">
check_item->next = NULL;</font>
<br>
<br>
<font face="Courier New" size="1">
result = paircompare(req, request, check_item, NULL);</font>
<br>
<br>
<font face="Courier New" size="1">
check_item->next = tmp;</font>
<br>
<font face="Courier New" size="1">
check_item = check_item->next;</font>
<br>
<font face="Courier New" size="1"> }</font>
<br>
<br>
<font face="Courier New" size="1"> return
result;</font>
<br>
<font face="Courier New" size="1">}</font>
<br>
<br>
<br>
<br>
<br>
<br>
/* This function ist imported from the preprocess C-FIle */<br>
<font face="Courier New" size="1">static int
huntgroup_access(REQUEST
*request, PAIR_LIST *huntgroups)</font>
<br>
<font face="Courier New" size="1">{</font>
<br>
<font face="Courier New" size="1"> PAIR_LIST
*i;</font>
<br>
<font face="Courier New" size="1"> int
r = RLM_MODULE_OK;</font>
<br>
<font face="Courier New" size="1"> VALUE_PAIR
*request_pairs = request->packet->vps;</font>
<br>
<br>
<font face="Courier New" size="1"> /*</font>
<br>
<font face="Courier New" size="1">
* We're not controlling access by huntgroups:</font>
<br>
<font face="Courier New" size="1">
* Allow them in.</font>
<br>
<font face="Courier New" size="1">
*/</font>
<br>
<font face="Courier New" size="1"> if
(huntgroups == NULL)</font>
<br>
<font face="Courier New" size="1">
return RLM_MODULE_OK;</font>
<br>
<br>
<font face="Courier New" size="1"> for(i
= huntgroups; i; i = i->next) {</font>
<br>
<font face="Courier New" size="1">
/*</font>
<br>
<font face="Courier New" size="1">
* See if this entry matches.</font>
<br>
<font face="Courier New" size="1">
*/</font>
<br>
<font face="Courier New" size="1">
if (paircompare(request, request_pairs, i->check,
NULL) != 0)</font>
<br>
<font face="Courier New" size="1">
continue;</font>
<br>
<br>
<font face="Courier New" size="1">
/*</font>
<br>
<font face="Courier New" size="1">
* Now check for access.</font>
<br>
<font face="Courier New" size="1">
*/</font>
<br>
<font face="Courier New" size="1">
r = RLM_MODULE_REJECT;</font>
<br>
<font face="Courier New" size="1">
if (hunt_paircmp(request, request_pairs, i->reply)
== 0) {</font>
<br>
<font face="Courier New" size="1">
VALUE_PAIR *vp;</font>
<br>
<br>
<font face="Courier New" size="1">
/*</font>
<br>
<font face="Courier New" size="1">
* We've matched
the huntgroup, so add it in</font>
<br>
<font face="Courier New" size="1">
* to the
list of request pairs.</font>
<br>
<font face="Courier New" size="1">
*/</font>
<br>
<font face="Courier New" size="1">
vp = pairfind(request_pairs,
PW_HUNTGROUP_NAME);</font>
<br>
<font face="Courier New" size="1">
if (!vp) {</font>
<br>
<font face="Courier New" size="1">
vp = radius_paircreate(request,</font>
<br>
<font face="Courier New" size="1">
&request->packet->vps,</font>
<br>
<font face="Courier New" size="1">
PW_HUNTGROUP_NAME,</font>
<br>
<font face="Courier New" size="1">
PW_TYPE_STRING);</font>
<br>
<font face="Courier New" size="1">
strlcpy(vp->vp_strvalue, i->name,</font>
<br>
<font face="Courier New" size="1">
sizeof(vp->vp_strvalue));</font>
<br>
<font face="Courier New" size="1">
vp->length = strlen(vp->vp_strvalue);</font>
<br>
<font face="Courier New" size="1">
}</font>
<br>
<font face="Courier New" size="1">
r = RLM_MODULE_OK;</font>
<br>
<font face="Courier New" size="1">
}</font>
<br>
<font face="Courier New" size="1">
break;</font>
<br>
<font face="Courier New" size="1"> }</font>
<br>
<br>
<font face="Courier New" size="1"> return
r;</font>
<br>
<font face="Courier New" size="1">}</font>
<br>
<br>
<br>
<br>
<br>
<font face="Courier New" size="1">static int
cpp_instantiate(CONF_SECTION
*conf, void **instance)</font>
<br>
<font face="Courier New" size="1">{</font>
<br>
<br>
<font face="Courier New" size="1"> rlm_huntgroups_t
*data;</font>
<br>
<font face="Courier New" size="1"> int rcode;</font>
<br>
<font face="Courier New" size="1"> </font>
<br>
<font face="Courier New" size="1"> /* Allocate
room to put the module's instantiation data */</font>
<br>
<font face="Courier New" size="1"> data =
(rlm_huntgroups_t *) rad_malloc(sizeof(*data));</font>
<br>
<font face="Courier New" size="1">
memset(data,0,sizeof(*data));</font>
<br>
<font face="Courier New" size="1"> </font>
<br>
<font face="Courier New" size="1"> /* Read
this modules configuration data */</font>
<br>
<font face="Courier New" size="1"> if (cf_section_parse(conf,
data, module_config) < 0) {</font>
<br>
<font face="Courier New" size="1">
free(data);</font>
<br>
<font face="Courier New" size="1">
return -1;</font>
<br>
<font face="Courier New" size="1"> }</font>
<br>
<font face="Courier New" size="1"> </font>
<br>
<font face="Courier New" size="1"> data->huntgroups
= NULL;</font>
<br>
<font face="Courier New" size="1">
</font>
<br>
<font face="Courier New" size="1"> /* Read
the huntgroups file */</font>
<br>
<font face="Courier New" size="1">
if(data->huntgroup_file)</font>
<br>
<font face="Courier New" size="1"> {</font>
<br>
<font face="Courier New" size="1">
rcode =
pairlist_read(data->huntgroup_file,&(data->huntgroups),0);</font>
<br>
<font face="Courier New" size="1">
if (rcode < 0)</font>
<br>
<font face="Courier New" size="1">
{</font>
<br>
<font face="Courier New" size="1">
radlog(L_ERR|L_CONS, "rlm_preprocess: Error reading
%s", data->huntgroup_file);</font>
<br>
<font face="Courier New" size="1">
return -1;</font>
<br>
<font face="Courier New" size="1">
}</font>
<br>
<font face="Courier New" size="1"> }</font>
<br>
<font face="Courier New" size="1"> </font>
<br>
<font face="Courier New" size="1"> /* Save
the instantiation data for later */</font>
<br>
<font face="Courier New" size="1"> *instance
= data;</font>
<br>
<font face="Courier New" size="1"> return
RLM_MODULE_OK;</font>
<br>
<font face="Courier New" size="1">}</font>
<br>
<br>
<br>
<br>
<font face="Courier New" size="1">static int cpp_authorize(void
*instance,
REQUEST *request)</font>
<br>
<font face="Courier New" size="1">{</font>
<br>
<font face="Courier New" size="1"> /* quiet the compiler
*/</font>
<br>
<font face="Courier New" size="1"> instance = instance;</font>
<br>
<font face="Courier New" size="1"> request = request;
</font>
<br>
<font face="Courier New" size="1"> </font>
<br>
<font face="Courier New" size="1"> rlm_huntgroups_t *data
= (rlm_huntgroups_t *) instance;</font>
<br>
<font face="Courier New" size="1">
</font>
<br>
<font face="Courier New" size="1"> int r;</font>
<br>
<font face="Courier New" size="1"> </font>
<br>
<font face="Courier New" size="1"> if((r =
huntgroup_access(request,data->huntgroups))
!= RLM_MODULE_OK) {</font>
<br>
<font face="Courier New" size="1"> char buf[1024];</font>
<br>
<font face="Courier New" size="1"> radlog_request(L_INFO,
0, request, "No huntgroup access: [%s] (%s)",</font>
<br>
<font face="Courier New" size="1"> request->username
? request->username->vp_strvalue : "<NO User-Name>",</font>
<br>
<font face="Courier New" size="1"> auth_name(buf,
sizeof(buf), request, 1));</font>
<br>
<font face="Courier New" size="1"> return r;</font>
<br>
<font face="Courier New" size="1"> }</font>
<br>
<font face="Courier New" size="1">
</font>
<br>
<font face="Courier New" size="1"> return RLM_MODULE_OK;
</font>
<br>
<font face="Courier New" size="1">}</font>
<br>
<br>
<br>
<br>
<font face="Courier New" size="1">extern "C" {</font>
<br>
<br>
<font face="Courier New" size="1">/*</font>
<br>
<font face="Courier New" size="1"> * Clean up
the module's instance.</font>
<br>
<font face="Courier New" size="1"> */</font>
<br>
<font face="Courier New" size="1">static int cpp_detach(void
*instance)</font>
<br>
<font face="Courier New" size="1">{</font>
<br>
<font face="Courier New" size="1"> rlm_huntgroups_t
*data = (rlm_huntgroups_t *) instance;</font>
<br>
<font face="Courier New" size="1">
</font>
<br>
<font face="Courier New" size="1">
pairlist_free(&(data->huntgroups));</font>
<br>
<font face="Courier New" size="1">
</font>
<br>
<font face="Courier New" size="1"> free(data);</font>
<br>
<font face="Courier New" size="1">
</font>
<br>
<font face="Courier New" size="1"> return 0;</font>
<br>
<font face="Courier New" size="1">}</font>
<br>
<font face="Courier New" size="1">}</font>
<br>
<br>
<br>
<br>
<font face="Courier New" size="1">extern "C" {</font>
<br>
<font face="Courier New" size="1">module_t rlm_cpp = {</font>
<br>
<font face="Courier New" size="1"> RLM_MODULE_INIT,</font>
<br>
<font face="Courier New" size="1"> "cpp",</font>
<br>
<font face="Courier New" size="1"> RLM_TYPE_THREAD_SAFE,
/* type */</font>
<br>
<font face="Courier New" size="1"> cpp_instantiate,
/* instantiation */</font>
<br>
<font face="Courier New" size="1"> cpp_detach,
/* detach */</font>
<br>
<font face="Courier New" size="1"> {</font>
<br>
<font face="Courier New" size="1">
NULL,
/* authentication */</font>
<br>
<font face="Courier New" size="1">
cpp_authorize,
/* authorization */</font>
<br>
<font face="Courier New" size="1">
NULL,
/* preaccounting */</font>
<br>
<font face="Courier New" size="1">
NULL,
/* accounting */</font>
<br>
<font face="Courier New" size="1">
NULL,
/* checksimul */</font>
<br>
<font face="Courier New" size="1">
NULL, /*
pre-proxy */</font>
<br>
<font face="Courier New" size="1">
NULL, /*
post-proxy */</font>
<br>
<font face="Courier New" size="1">
NULL
/* post-auth */</font>
<br>
<font face="Courier New" size="1"> },</font>
<br>
<font face="Courier New" size="1">};</font>
<br>
<font face="Courier New" size="1">} </font>
<br>
<br>
<br>
<br>
<br>
Greetz<br>
Patrick<br>
</body>
</html>