continue;
}
- cf_section_parse_free(cs, mh->insthandle);
-
- if (node->entry->module->detach) {
- if ((node->entry->module->detach)(mh->insthandle) < 0) {
- DEBUGW("Failed detaching module %s cleanly. Doing forcible shutdown", node->name);
-
- }
- } else {
- talloc_free(mh->insthandle);
- }
+ talloc_free(mh->insthandle);
*last = mh->next;
talloc_free(mh);
module_instance_free_old(this->cs, this, time(NULL) + 100);
- cf_section_parse_free(this->cs, this->insthandle);
-
- if (this->entry->module->detach) {
- (this->entry->module->detach)(this->insthandle);
- }
-
#ifdef HAVE_PTHREAD_H
if (this->mutex) {
/*
/*
* Free a module entry.
*/
-static void module_entry_free(void *data)
+static int module_entry_free(void *ctx)
{
- module_entry_t *this = data;
+ module_entry_t *this;
+
+ this = talloc_get_type_abort(ctx, module_entry_t);
lt_dlclose(this->handle); /* ignore any errors */
- memset(this, 0, sizeof(*this));
- talloc_free(this);
+ return 0;
}
/* make room for the module type */
node = talloc_zero(cs, module_entry_t);
+ talloc_set_destructor((void *) node, module_entry_free);
strlcpy(node->name, module_name, sizeof(node->name));
node->module = module;
node->handle = handle;
cf_log_err(cf_sectiontoitem(cs),
"Instantiation failed for module \"%s\"",
instname);
+ if (node->entry->module->detach) {
+ talloc_set_destructor((void *) node->insthandle,
+ node->entry->module->detach);
+ }
+ talloc_free(node->insthandle);
talloc_free(node);
return NULL;
}
+ if (node->insthandle) {
+ talloc_set_destructor((void *) node->insthandle,
+ node->entry->module->detach);
+ talloc_steal(node, node->insthandle);
+ }
+
/*
* We're done. Fill in the rest of the data structure,
* and link it to the module instance list.
/*
* Set up the internal module struct.
*/
- module_tree = rbtree_create(module_entry_cmp,
- module_entry_free, 0);
+ module_tree = rbtree_create(module_entry_cmp, NULL, 0);
if (!module_tree) {
radlog(L_ERR, "Failed to initialize modules\n");
return -1;
/*
* A mapping of configuration file names to internal variables.
- *
- * Note that the string is dynamically allocated, so it MUST
- * be freed. When the configuration file parse re-reads the string,
- * it free's the old one, and strdup's the new one, placing the pointer
- * to the strdup'd string into 'config.string'. This gets around
- * buffer over-flows.
*/
static const CONF_PARSER module_config[] = {
{ "rcode", PW_TYPE_STRING_PTR, offsetof(rlm_always_t,rcode_str),
static int always_instantiate(CONF_SECTION *conf, void **instance)
{
- rlm_always_t *data;
+ rlm_always_t *inst;
/*
* Set up a storage area for instance data
*/
- data = rad_malloc(sizeof(*data));
- if (!data) {
+ *instance = inst = talloc_zero(conf, rlm_always_t);
+ if (!inst) {
return -1;
}
- memset(data, 0, sizeof(*data));
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
- if (cf_section_parse(conf, data, module_config) < 0) {
- free(data);
+ if (cf_section_parse(conf, inst, module_config) < 0) {
return -1;
}
/*
* Convert the rcode string to an int, and get rid of it
*/
- data->rcode = str2rcode(data->rcode_str);
- if (data->rcode == RLM_MODULE_UNKNOWN) {
- free(data);
+ inst->rcode = str2rcode(inst->rcode_str);
+ if (inst->rcode == RLM_MODULE_UNKNOWN) {
return -1;
}
- *instance = data;
-
return 0;
}
}
#endif
-static int always_detach(void *instance)
-{
- free(instance);
- return 0;
-}
-
module_t rlm_always = {
RLM_MODULE_INIT,
"always",
RLM_TYPE_CHECK_CONFIG_SAFE, /* type */
always_instantiate, /* instantiation */
- always_detach, /* detach */
+ NULL, /* detach */
{
always_return, /* authentication */
always_return, /* authorization */
* Define a structure with the module configuration, so it can
* be used as the instance handle.
*/
-struct attr_filter_instance {
- char *file;
- char *key;
- int relaxed;
- PAIR_LIST *attrs;
-};
+typedef struct rlm_attr_filter {
+ char *file;
+ char *key;
+ int relaxed;
+ PAIR_LIST *attrs;
+} rlm_attr_filter_t;
static const CONF_PARSER module_config[] = {
{ "file", PW_TYPE_FILENAME,
- offsetof(struct attr_filter_instance,file), NULL, "${raddbdir}/attrs" },
+ offsetof(rlm_attr_filter_t, file), NULL, "${raddbdir}/attrs" },
{ "key", PW_TYPE_STRING_PTR,
- offsetof(struct attr_filter_instance,key), NULL, "%{Realm}" },
+ offsetof(rlm_attr_filter_t, key), NULL, "%{Realm}" },
{ "relaxed", PW_TYPE_BOOLEAN,
- offsetof(struct attr_filter_instance,relaxed), NULL, "no" },
+ offsetof(rlm_attr_filter_t, relaxed), NULL, "no" },
{ NULL, -1, 0, NULL, NULL }
};
*/
static int attr_filter_detach(void *instance)
{
- struct attr_filter_instance *inst = instance;
+ rlm_attr_filter_t *inst = instance;
pairlist_free(&inst->attrs);
- free(inst);
+
return 0;
}
*/
static int attr_filter_instantiate(CONF_SECTION *conf, void **instance)
{
- struct attr_filter_instance *inst;
+ rlm_attr_filter_t *inst;
int rcode;
- inst = rad_malloc(sizeof *inst);
+ *instance = inst = talloc_zero(conf, rlm_attr_filter_t);
if (!inst) {
return -1;
}
- memset(inst, 0, sizeof(*inst));
if (cf_section_parse(conf, inst, module_config) < 0) {
- attr_filter_detach(inst);
return -1;
}
rcode = attr_filter_getfile(inst->file, &inst->attrs);
if (rcode != 0) {
radlog(L_ERR, "Errors reading %s", inst->file);
- attr_filter_detach(inst);
+
return -1;
}
- *instance = inst;
+
return 0;
}
static rlm_rcode_t attr_filter_common(void *instance, REQUEST *request,
RADIUS_PACKET *packet)
{
- struct attr_filter_instance *inst = instance;
+ rlm_attr_filter_t *inst = instance;
VALUE_PAIR *vp;
VALUE_PAIR *output;
VALUE_PAIR **output_tail;
#define RLM_REGEX_INPROXY 3
#define RLM_REGEX_INPROXYREPLY 4
-typedef struct rlm_attr_rewrite_t {
+typedef struct rlm_attr_rewrite {
char *attribute; //!< The attribute to search for.
const DICT_ATTR *da; //!< The attribute definition.
char *search; //!< The pattern to search for.
} rlm_attr_rewrite_t;
static const CONF_PARSER module_config[] = {
- { "attribute", PW_TYPE_STRING_PTR, offsetof(rlm_attr_rewrite_t,attribute), NULL, NULL },
- { "searchfor", PW_TYPE_STRING_PTR, offsetof(rlm_attr_rewrite_t,search), NULL, NULL },
- { "searchin", PW_TYPE_STRING_PTR, offsetof(rlm_attr_rewrite_t,searchin_str), NULL, "packet" },
- { "replacewith", PW_TYPE_STRING_PTR, offsetof(rlm_attr_rewrite_t,replace), NULL, NULL },
- { "append", PW_TYPE_BOOLEAN, offsetof(rlm_attr_rewrite_t,append),NULL, "no" },
- { "ignore_case", PW_TYPE_BOOLEAN, offsetof(rlm_attr_rewrite_t,nocase), NULL, "yes" },
- { "new_attribute", PW_TYPE_BOOLEAN, offsetof(rlm_attr_rewrite_t,new_attr), NULL, "no" },
- { "max_matches", PW_TYPE_INTEGER, offsetof(rlm_attr_rewrite_t,num_matches), NULL, "10" },
+ { "attribute", PW_TYPE_STRING_PTR,
+ offsetof(rlm_attr_rewrite_t,attribute), NULL, NULL },
+ { "searchfor", PW_TYPE_STRING_PTR,
+ offsetof(rlm_attr_rewrite_t,search), NULL, NULL },
+ { "searchin", PW_TYPE_STRING_PTR,
+ offsetof(rlm_attr_rewrite_t,searchin_str), NULL, "packet" },
+ { "replacewith", PW_TYPE_STRING_PTR,
+ offsetof(rlm_attr_rewrite_t,replace), NULL, NULL },
+ { "append", PW_TYPE_BOOLEAN,
+ offsetof(rlm_attr_rewrite_t,append),NULL, "no" },
+ { "ignore_case", PW_TYPE_BOOLEAN,
+ offsetof(rlm_attr_rewrite_t,nocase), NULL, "yes" },
+ { "new_attribute", PW_TYPE_BOOLEAN,
+ offsetof(rlm_attr_rewrite_t,new_attr), NULL, "no" },
+ { "max_matches", PW_TYPE_INTEGER,
+ offsetof(rlm_attr_rewrite_t,num_matches), NULL, "10" },
{ NULL, -1, 0, NULL, NULL }
};
static int attr_rewrite_instantiate(CONF_SECTION *conf, void **instance)
{
- rlm_attr_rewrite_t *data;
+ rlm_attr_rewrite_t *inst;
const DICT_ATTR *dattr;
/*
* Set up a storage area for instance data
*/
- data = rad_malloc(sizeof(*data));
- if (!data) {
+ *instance = inst = talloc_zero(conf, rlm_attr_rewrite_t);
+ if (!inst) {
return -1;
}
- memset(data, 0, sizeof(*data));
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
- if (cf_section_parse(conf, data, module_config) < 0) {
- free(data);
+ if (cf_section_parse(conf, inst, module_config) < 0) {
return -1;
}
/*
* Discover the attribute number of the key.
*/
- if (data->attribute == NULL) {
+ if (inst->attribute == NULL) {
radlog(L_ERR, "rlm_attr_rewrite: 'attribute' must be set.");
return -1;
}
- if (data->search == NULL || data->replace == NULL) {
+ if (inst->search == NULL || inst->replace == NULL) {
radlog(L_ERR, "rlm_attr_rewrite: search/replace strings must be set.");
return -1;
}
- data->search_len = strlen(data->search);
- data->replace_len = strlen(data->replace);
+ inst->search_len = strlen(inst->search);
+ inst->replace_len = strlen(inst->replace);
- if (data->replace_len == 0 && data->new_attr){
+ if (inst->replace_len == 0 && inst->new_attr){
radlog(L_ERR, "rlm_attr_rewrite: replace string must not be zero length in order to create new attribute.");
return -1;
}
- if (data->num_matches < 1 || data->num_matches > MAX_STRING_LEN) {
+ if (inst->num_matches < 1 || inst->num_matches > MAX_STRING_LEN) {
radlog(L_ERR, "rlm_attr_rewrite: Illegal range for match number.");
return -1;
}
- if (data->searchin_str == NULL) {
+ if (inst->searchin_str == NULL) {
radlog(L_ERR, "rlm_attr_rewrite: Illegal searchin directive given. Assuming packet.");
- data->searchin = RLM_REGEX_INPACKET;
+ inst->searchin = RLM_REGEX_INPACKET;
}
else{
- if (strcmp(data->searchin_str, "packet") == 0)
- data->searchin = RLM_REGEX_INPACKET;
- else if (strcmp(data->searchin_str, "config") == 0)
- data->searchin = RLM_REGEX_INCONFIG;
- else if (strcmp(data->searchin_str, "control") == 0)
- data->searchin = RLM_REGEX_INCONFIG;
- else if (strcmp(data->searchin_str, "reply") == 0)
- data->searchin = RLM_REGEX_INREPLY;
+ if (strcmp(inst->searchin_str, "packet") == 0)
+ inst->searchin = RLM_REGEX_INPACKET;
+ else if (strcmp(inst->searchin_str, "config") == 0)
+ inst->searchin = RLM_REGEX_INCONFIG;
+ else if (strcmp(inst->searchin_str, "control") == 0)
+ inst->searchin = RLM_REGEX_INCONFIG;
+ else if (strcmp(inst->searchin_str, "reply") == 0)
+ inst->searchin = RLM_REGEX_INREPLY;
#ifdef WITH_PROXY
- else if (strcmp(data->searchin_str, "proxy") == 0)
- data->searchin = RLM_REGEX_INPROXY;
- else if (strcmp(data->searchin_str, "proxy_reply") == 0)
- data->searchin = RLM_REGEX_INPROXYREPLY;
+ else if (strcmp(inst->searchin_str, "proxy") == 0)
+ inst->searchin = RLM_REGEX_INPROXY;
+ else if (strcmp(inst->searchin_str, "proxy_reply") == 0)
+ inst->searchin = RLM_REGEX_INPROXYREPLY;
#endif
else {
radlog(L_ERR, "rlm_attr_rewrite: Illegal searchin directive given. Assuming packet.");
- data->searchin = RLM_REGEX_INPACKET;
+ inst->searchin = RLM_REGEX_INPACKET;
}
}
- dattr = dict_attrbyname(data->attribute);
+ dattr = dict_attrbyname(inst->attribute);
if (dattr == NULL) {
radlog(L_ERR, "rlm_attr_rewrite: No such attribute %s",
- data->attribute);
+ inst->attribute);
return -1;
}
- data->da = dattr;
+ inst->da = dattr;
/* Add the module instance name */
- data->name = cf_section_name2(conf); /* may be NULL */
-
- *instance = data;
+ inst->name = cf_section_name2(conf); /* may be NULL */
return 0;
}
static rlm_rcode_t do_attr_rewrite(void *instance, REQUEST *request)
{
- rlm_attr_rewrite_t *data = (rlm_attr_rewrite_t *) instance;
+ rlm_attr_rewrite_t *inst = (rlm_attr_rewrite_t *) instance;
rlm_rcode_t rcode = RLM_MODULE_NOOP;
VALUE_PAIR *attr_vp = NULL;
VALUE_PAIR *tmp = NULL;
char replace_STR[MAX_STRING_LEN];
if ((attr_vp = pairfind(request->config_items, PW_REWRITE_RULE, 0, TAG_ANY)) != NULL){
- if (data->name == NULL || strcmp(data->name,attr_vp->vp_strvalue))
+ if (inst->name == NULL || strcmp(inst->name,attr_vp->vp_strvalue))
return RLM_MODULE_NOOP;
}
- if (data->new_attr){
+ if (inst->new_attr){
/* new_attribute = yes */
- if (!radius_xlat(replace_STR, sizeof(replace_STR), data->replace, request, NULL, NULL)) {
- DEBUG2("%s: xlat on replace string failed.", data->name);
+ if (!radius_xlat(replace_STR, sizeof(replace_STR), inst->replace, request, NULL, NULL)) {
+ DEBUG2("%s: xlat on replace string failed.", inst->name);
return rcode;
}
- attr_vp = pairmake(data->attribute,replace_STR,0);
+ attr_vp = pairmake(inst->attribute,replace_STR,0);
if (attr_vp == NULL){
- DEBUG2("%s: Could not add new attribute %s with value '%s'", data->name,
- data->attribute,replace_STR);
+ DEBUG2("%s: Could not add new attribute %s with value '%s'", inst->name,
+ inst->attribute,replace_STR);
return rcode;
}
- switch(data->searchin){
+ switch(inst->searchin){
case RLM_REGEX_INPACKET:
pairadd(&request->packet->vps,attr_vp);
break;
break;
#endif
default:
- radlog(L_ERR, "%s: Illegal value for searchin. Changing to packet.", data->name);
- data->searchin = RLM_REGEX_INPACKET;
+ radlog(L_ERR, "%s: Illegal value for searchin. Changing to packet.", inst->name);
+ inst->searchin = RLM_REGEX_INPACKET;
pairadd(&request->packet->vps,attr_vp);
break;
}
- DEBUG2("%s: Added attribute %s with value '%s'", data->name,data->attribute,replace_STR);
+ DEBUG2("%s: Added attribute %s with value '%s'", inst->name,inst->attribute,replace_STR);
rcode = RLM_MODULE_OK;
} else {
int replace_len = 0;
/* new_attribute = no */
- switch (data->searchin) {
+ switch (inst->searchin) {
case RLM_REGEX_INPACKET:
- if (!data->da->vendor && (data->da->attr == PW_USER_NAME))
+ if (!inst->da->vendor && (inst->da->attr == PW_USER_NAME))
attr_vp = request->username;
- else if (!data->da->vendor && (data->da->attr == PW_USER_PASSWORD))
+ else if (!inst->da->vendor && (inst->da->attr == PW_USER_PASSWORD))
attr_vp = request->password;
else
tmp = request->packet->vps;
break;
#endif
default:
- radlog(L_ERR, "%s: Illegal value for searchin. Changing to packet.", data->name);
- data->searchin = RLM_REGEX_INPACKET;
- attr_vp = pairfind(request->packet->vps, data->da->attr, data->da->vendor, TAG_ANY);
+ radlog(L_ERR, "%s: Illegal value for searchin. Changing to packet.", inst->name);
+ inst->searchin = RLM_REGEX_INPACKET;
+ attr_vp = pairfind(request->packet->vps, inst->da->attr, inst->da->vendor, TAG_ANY);
break;
}
do_again:
if (tmp != NULL)
- attr_vp = pairfind(tmp, data->da->attr, data->da->vendor, TAG_ANY);
+ attr_vp = pairfind(tmp, inst->da->attr, inst->da->vendor, TAG_ANY);
if (attr_vp == NULL) {
- DEBUG2("%s: Could not find value pair for attribute %s", data->name,data->attribute);
+ DEBUG2("%s: Could not find value pair for attribute %s", inst->name,inst->attribute);
return rcode;
}
if (attr_vp->length == 0){
- DEBUG2("%s: Attribute %s string value NULL or of zero length", data->name,data->attribute);
+ DEBUG2("%s: Attribute %s string value NULL or of zero length", inst->name,inst->attribute);
return rcode;
}
cflags |= REG_EXTENDED;
- if (data->nocase)
+ if (inst->nocase)
cflags |= REG_ICASE;
- if (!radius_xlat(search_STR, sizeof(search_STR), data->search, request, NULL, NULL) && data->search_len != 0) {
- DEBUG2("%s: xlat on search string failed.", data->name);
+ if (!radius_xlat(search_STR, sizeof(search_STR), inst->search, request, NULL, NULL) && inst->search_len != 0) {
+ DEBUG2("%s: xlat on search string failed.", inst->name);
return rcode;
}
if ((err = regcomp(&preg,search_STR,cflags))) {
regerror(err, &preg, err_msg, MAX_STRING_LEN);
- DEBUG2("%s: regcomp() returned error: %s", data->name,err_msg);
+ DEBUG2("%s: regcomp() returned error: %s", inst->name,err_msg);
return rcode;
}
ptr2 = attr_vp->vp_strvalue;
counter = 0;
- for ( i = 0 ;i < (unsigned)data->num_matches; i++) {
+ for ( i = 0 ;i < (unsigned)inst->num_matches; i++) {
err = regexec(&preg, ptr2, REQUEST_MAX_REGEX, pmatch, 0);
if (err == REG_NOMATCH) {
if (i == 0) {
- DEBUG2("%s: Does not match: %s = %s", data->name,
- data->attribute, attr_vp->vp_strvalue);
+ DEBUG2("%s: Does not match: %s = %s", inst->name,
+ inst->attribute, attr_vp->vp_strvalue);
regfree(&preg);
goto to_do_again;
} else
}
if (err != 0) {
regfree(&preg);
- radlog(L_ERR, "%s: match failure for attribute %s with value '%s'", data->name,
- data->attribute, attr_vp->vp_strvalue);
+ radlog(L_ERR, "%s: match failure for attribute %s with value '%s'", inst->name,
+ inst->attribute, attr_vp->vp_strvalue);
return rcode;
}
if (pmatch[0].rm_so == -1)
break;
len = pmatch[0].rm_so;
- if (data->append) {
+ if (inst->append) {
len = len + (pmatch[0].rm_eo - pmatch[0].rm_so);
}
counter += len;
if (counter >= MAX_STRING_LEN) {
regfree(&preg);
- DEBUG2("%s: Replacement out of limits for attribute %s with value '%s'", data->name,
- data->attribute, attr_vp->vp_strvalue);
+ DEBUG2("%s: Replacement out of limits for attribute %s with value '%s'", inst->name,
+ inst->attribute, attr_vp->vp_strvalue);
return rcode;
}
}
if (!done_xlat){
- if (data->replace_len != 0 &&
- radius_xlat(replace_STR, sizeof(replace_STR), data->replace, request, NULL, NULL) == 0) {
- DEBUG2("%s: xlat on replace string failed.", data->name);
+ if (inst->replace_len != 0 &&
+ radius_xlat(replace_STR, sizeof(replace_STR), inst->replace, request, NULL, NULL) == 0) {
+ DEBUG2("%s: xlat on replace string failed.", inst->name);
return rcode;
}
- replace_len = (data->replace_len != 0) ? strlen(replace_STR) : 0;
+ replace_len = (inst->replace_len != 0) ? strlen(replace_STR) : 0;
done_xlat = 1;
}
counter += replace_len;
if (counter >= MAX_STRING_LEN) {
regfree(&preg);
- DEBUG2("%s: Replacement out of limits for attribute %s with value '%s'", data->name,
- data->attribute, attr_vp->vp_strvalue);
+ DEBUG2("%s: Replacement out of limits for attribute %s with value '%s'", inst->name,
+ inst->attribute, attr_vp->vp_strvalue);
return rcode;
}
if (replace_len){
len = strlen(ptr2) + 1; /* We add the ending NULL */
counter += len;
if (counter >= MAX_STRING_LEN){
- DEBUG2("%s: Replacement out of limits for attribute %s with value '%s'", data->name,
- data->attribute, attr_vp->vp_strvalue);
+ DEBUG2("%s: Replacement out of limits for attribute %s with value '%s'", inst->name,
+ inst->attribute, attr_vp->vp_strvalue);
return rcode;
}
memcpy(ptr, ptr2, len);
ptr[len] = '\0';
- DEBUG2("%s: Changed value for attribute %s from '%s' to '%s'", data->name,
- data->attribute, attr_vp->vp_strvalue, new_str);
+ DEBUG2("%s: Changed value for attribute %s from '%s' to '%s'", inst->name,
+ inst->attribute, attr_vp->vp_strvalue, new_str);
if (!pairparsevalue(attr_vp, new_str)) {
- DEBUG2("%s: Could not write value '%s' into attribute %s: %s", data->name, new_str, data->attribute, fr_strerror());
+ DEBUG2("%s: Could not write value '%s' into attribute %s: %s", inst->name, new_str, inst->attribute, fr_strerror());
return rcode;
}
return do_attr_rewrite(instance, request);
}
-static int attr_rewrite_detach(void *instance)
-{
- free(instance);
- return 0;
-}
-
/*
* The module name should be the only globally exported symbol.
* That is, everything else should be 'static'.
module_t rlm_attr_rewrite = {
RLM_MODULE_INIT,
"attr_rewrite",
- RLM_TYPE_THREAD_UNSAFE, /* type */
+ RLM_TYPE_THREAD_UNSAFE, /* type */
attr_rewrite_instantiate, /* instantiation */
- attr_rewrite_detach, /* detach */
+ NULL, /* detach */
{
attr_rewrite_authenticate, /* authentication */
attr_rewrite_authorize, /* authorization */
{
rlm_cache_entry_t *c = data;
- rad_cfree(c->key);
pairfree(&c->control);
pairfree(&c->request);
pairfree(&c->reply);
- free(c);
+
+ talloc_free(c);
}
/*
vp = pairfind(request->config_items, PW_CACHE_TTL, 0, TAG_ANY);
if (vp && (vp->vp_integer == 0)) return NULL;
- c = rad_calloc(sizeof(*c));
- c->key = strdup(key);
+ c = talloc_zero(NULL, rlm_cache_entry_t);
+ c->key = talloc_strdup(c, key);
c->created = c->expires = request->timestamp;
/*
static int cache_detach(void *instance)
{
rlm_cache_t *inst = instance;
-
- rad_cfree(inst->xlat_name);
radius_mapfree(&inst->maps);
fr_heap_delete(inst->heap);
rbtree_free(inst->cache);
+
#ifdef HAVE_PTHREAD_H
pthread_mutex_destroy(&inst->cache_mutex);
#endif
- free(instance);
return 0;
}
*/
static int cache_instantiate(CONF_SECTION *conf, void **instance)
{
- const char *xlat_name;
rlm_cache_t *inst;
- inst = rad_calloc(sizeof(*inst));
+ *instance = inst = talloc_zero(conf, rlm_cache_t);
inst->cs = conf;
/*
* fail.
*/
if (cf_section_parse(conf, inst, module_config) < 0) {
- free(inst);
return -1;
}
- xlat_name = cf_section_name2(conf);
- if (xlat_name == NULL) {
- xlat_name = cf_section_name1(conf);
+ inst->xlat_name = cf_section_name2(conf);
+ if (!inst->xlat_name) {
+ inst->xlat_name = cf_section_name1(conf);
}
-
- rad_assert(xlat_name);
/*
* Register the cache xlat function
*/
- inst->xlat_name = strdup(xlat_name);
- xlat_register(xlat_name, cache_xlat, inst);
+ xlat_register(inst->xlat_name, cache_xlat, inst);
if (!inst->key || !*inst->key) {
radlog(L_ERR, "rlm_cache: You must specify a key");
- cache_detach(inst);
return -1;
}
if (inst->ttl == 0) {
radlog(L_ERR, "rlm_cache: TTL must be greater than zero");
- cache_detach(inst);
return -1;
}
if (inst->epoch != 0){
radlog(L_ERR, "rlm_cache: Epoch should only be set dynamically");
- cache_detach(inst);
return -1;
}
#ifdef HAVE_PTHREAD_H
if (pthread_mutex_init(&inst->cache_mutex, NULL) < 0) {
- radlog(L_ERR, "rlm_cache: Failed initializing mutex: %s", strerror(errno));
- cache_detach(inst);
+ radlog(L_ERR, "rlm_cache: Failed initializing mutex: %s",
+ strerror(errno));
return -1;
}
#endif
inst->cache = rbtree_create(cache_entry_cmp, cache_entry_free, 0);
if (!inst->cache) {
radlog(L_ERR, "rlm_cache: Failed to create cache");
- cache_detach(inst);
return -1;
}
offsetof(rlm_cache_entry_t, offset));
if (!inst->heap) {
radlog(L_ERR, "rlm_cache: Failed to create cache");
- cache_detach(inst);
return -1;
}
* Make sure the users don't screw up too badly.
*/
if (cache_verify(inst, &inst->maps) < 0) {
- cache_detach(inst);
return -1;
}
- *instance = inst;
-
return 0;
}
{ NULL, -1, 0, NULL, NULL } /* end the list */
};
-
-static int checkval_detach(void *instance)
-{
- free(instance);
- return 0;
-}
-
/*
* Do any per-module initialization that is separate to each
* configured instance of the module. e.g. set up connections
/*
* Set up a storage area for instance data
*/
- inst = rad_malloc(sizeof(*inst));
+ *instance = inst = talloc_zero(conf, rlm_checkval_t);
if (!inst) {
return -1;
}
- memset(inst, 0, sizeof(*inst));
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, inst, module_config) < 0) {
- checkval_detach(inst);
return -1;
}
*/
if (!inst->data_type || !*inst->data_type){
radlog(L_ERR, "rlm_checkval: Data type not defined");
- checkval_detach(inst);
return -1;
}
if (!inst->item_name || !*inst->item_name){
radlog(L_ERR, "rlm_checkval: Item name not defined");
- checkval_detach(inst);
return -1;
}
if (!inst->check_name || !*inst->check_name){
radlog(L_ERR, "rlm_checkval: Check item name not defined");
- checkval_detach(inst);
return -1;
}
if (!da) {
radlog(L_ERR, "rlm_checkval: No such attribute %s",
inst->item_name);
- checkval_detach(inst);
return -1;
}
inst->item = da;
if (!da){
radlog(L_ERR, "rlm_checkval: No such attribute %s",
inst->check_name);
- checkval_detach(inst);
return -1;
}
inst->check = da;
if (!inst->type) {
radlog(L_ERR, "rlm_checkval: Data type %s in not known",
inst->data_type);
- checkval_detach(inst);
return -1;
}
- *instance = inst;
-
return 0;
}
module_t rlm_checkval = {
RLM_MODULE_INIT,
"checkval",
- 0, /* type */
+ 0, /* type */
checkval_instantiate, /* instantiation */
- checkval_detach, /* detach */
+ NULL, /* detach */
{
NULL, /* authentication */
checkval_authorize, /* authorization */
/*
* Set up a storage area for instance data
*/
- inst = rad_malloc(sizeof(*inst));
- if (!inst) {
- radlog(L_ERR, "rlm_counter: rad_malloc() failed.");
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, rlm_counter_t);
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, inst, module_config) < 0) {
- free(inst);
return -1;
}
cache_size = inst->cache_size;
*/
if (inst->counter_name == NULL) {
radlog(L_ERR, "rlm_counter: 'counter-name' must be set.");
- counter_detach(inst);
return -1;
}
if (dattr == NULL) {
radlog(L_ERR, "rlm_counter: Failed to create counter attribute %s",
inst->counter_name);
- counter_detach(inst);
return -1;
}
inst->dict_attr = dattr->attr;
*/
if (inst->check_name == NULL) {
radlog(L_ERR, "rlm_counter: 'check-name' must be set.");
- counter_detach(inst);
return -1;
}
dict_addattr(inst->check_name, 0, PW_TYPE_INTEGER, -1, flags);
if (dattr == NULL) {
radlog(L_ERR, "rlm_counter: Failed to create check attribute %s",
inst->counter_name);
- counter_detach(inst);
return -1;
}
inst->check_attr = dattr->attr;
if ((dval = dict_valbyname(PW_SERVICE_TYPE, 0, inst->service_type)) == NULL) {
radlog(L_ERR, "rlm_counter: Failed to find attribute number for %s",
inst->service_type);
- counter_detach(inst);
return -1;
}
inst->service_val = dval->value;
*/
if (inst->reset == NULL) {
radlog(L_ERR, "rlm_counter: 'reset' must be set.");
- counter_detach(inst);
return -1;
}
now = time(NULL);
if (find_next_reset(inst,now) == -1){
radlog(L_ERR, "rlm_counter: find_next_reset() returned -1. Exiting.");
- counter_detach(inst);
return -1;
}
if (inst->filename == NULL) {
radlog(L_ERR, "rlm_counter: 'filename' must be set.");
- counter_detach(inst);
return -1;
}
inst->gdbm = gdbm_open(inst->filename, sizeof(int),
if (inst->gdbm == NULL) {
radlog(L_ERR, "rlm_counter: Failed to open file %s: %s",
inst->filename, strerror(errno));
- counter_detach(inst);
return -1;
}
if (gdbm_setopt(inst->gdbm, GDBM_CACHESIZE, &cache_size,
ret = reset_db(inst);
if (ret != RLM_MODULE_OK){
radlog(L_ERR, "rlm_counter: reset_db() failed");
- counter_detach(inst);
return -1;
}
} else {
ret = add_defaults(inst);
if (ret != RLM_MODULE_OK){
radlog(L_ERR, "rlm_counter: add_defaults() failed");
- counter_detach(inst);
return -1;
}
}
*/
pthread_mutex_init(&inst->mutex, NULL);
- *instance = inst;
-
return 0;
}
pthread_mutex_destroy(&inst->mutex);
- free(instance);
return 0;
}
return 0;
}
-static int rlm_dbm_instantiate(CONF_SECTION *conf, void **instance) {
+static int rlm_dbm_instantiate(CONF_SECTION *conf, void **instance)
+{
struct rlm_dbm_t *inst;
- inst = rad_malloc(sizeof(rlm_dbm_t));
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, struct rlm_dbm_t);
+ if (!inst) return -1;
if (cf_section_parse(conf, inst, module_config) < 0) {
- free(inst);
return -1;
}
- *instance = inst;
+
return 0;
}
static rlm_rcode_t rlm_dbm_authorize(void *instance, REQUEST *request)
return found;
}
-static int rlm_dbm_detach(void *instance)
-{
- struct rlm_dbm_t *inst = instance;
- free(inst);
- return 0;
-}
-
-
/* globally exported name */
module_t rlm_dbm = {
RLM_MODULE_INIT,
"dbm",
0, /* type: reserved */
rlm_dbm_instantiate, /* instantiation */
- rlm_dbm_detach, /* detach */
+ NULL, /* detach */
{
NULL, /* authentication */
rlm_dbm_authorize, /* authorization */
{
struct detail_instance *inst = instance;
if (inst->ht) fr_hash_table_free(inst->ht);
-
- free(inst);
return 0;
}
detail_instance_t *inst;
CONF_SECTION *cs;
- inst = rad_malloc(sizeof(*inst));
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, detail_instance_t);
+ if (!inst) return -1;
if (cf_section_parse(conf, inst, module_config) < 0) {
detail_detach(inst);
}
}
-
- *instance = inst;
return 0;
}
/*
- * A mapping of configuration file names to internal variables.
- *
- * Note that the string is dynamically allocated, so it MUST
- * be freed. When the configuration file parse re-reads the string,
- * it free's the old one, and strdup's the new one, placing the pointer
- * to the strdup'd string into 'config.string'. This gets around
- * buffer over-flows.
- */
-static const CONF_PARSER module_config[] = {
- { NULL, -1, 0, NULL, NULL } /* end the list */
-};
-
-
-/*
* Only free memory we allocated. The strings allocated via
* cf_section_parse() do not need to be freed.
*/
static int dhcp_detach(void *instance)
{
- free(instance);
+ xlat_unregister("dhcp_options", dhcp_options_xlat, instance);
return 0;
}
{
rlm_dhcp_t *inst;
- inst = rad_malloc(sizeof(*inst));
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, rlm_dhcp_t);
+ if (!inst) return -1;
xlat_register("dhcp_options", dhcp_options_xlat, inst);
- /*
- * If the configuration parameters can't be parsed, then
- * fail.
- */
- if (cf_section_parse(conf, inst, module_config) < 0) {
- free(inst);
- return -1;
- }
-
- *instance = inst;
-
return 0;
}
inst->types[i] = NULL;
}
- free(inst);
-
return 0;
}
CONF_SECTION *scs;
rlm_eap_t *inst;
- inst = (rlm_eap_t *) malloc(sizeof(*inst));
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(cs, rlm_eap_t);
+ if (!inst) return -1;
+
if (cf_section_parse(cs, inst, module_config) < 0) {
eap_detach(inst);
return -1;
}
#endif
- *instance = inst;
return 0;
}
pthread_mutex_destroy(&(inst->session_mutex));
- free(inst);
-
return 0;
}
rlm_eap_t *inst;
CONF_SECTION *scs;
- inst = (rlm_eap_t *) malloc(sizeof(*inst));
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, rlm_eap_t);
+ if (!inst) return -1;
+
if (cf_section_parse(cs, inst, module_config) < 0) {
eap_detach(inst);
return -1;
}
pthread_mutex_init(&(inst->session_mutex), NULL);
-
- *instance = inst;
return 0;
}
/*
* Set up a storage area for instance data
*/
- data = rad_malloc(sizeof(*data));
- if (!data) {
- return -1;
- }
- memset(data, 0, sizeof(*data));
+ *instance = data = talloc_zero(conf, rlm_example_t);
+ if (!data) return -1;
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, data, module_config) < 0) {
- free(data);
return -1;
}
- *instance = data;
-
return 0;
}
*/
static int example_detach(void *instance)
{
- free(instance);
+ /* free things here */
return 0;
}
if (inst->xlat_name) {
xlat_unregister(inst->xlat_name, exec_xlat, instance);
- free(inst->xlat_name);
}
- free(inst);
return 0;
}
/*
* Set up a storage area for instance data
*/
-
- inst = rad_malloc(sizeof(rlm_exec_t));
- if (!inst)
- return -1;
- memset(inst, 0, sizeof(rlm_exec_t));
+ *instance = inst = talloc_zero(conf, rlm_exec_t);
+ if (!inst) return -1;
xlat_name = cf_section_name2(conf);
- if (xlat_name == NULL) {
+ if (!xlat_name) {
xlat_name = cf_section_name1(conf);
inst->bare = 1;
}
- if (xlat_name){
- inst->xlat_name = strdup(xlat_name);
+ if (xlat_name) {
+ inst->xlat_name = xlat_name;
xlat_register(xlat_name, exec_xlat, inst);
}
inst->packet_code = dval->value;
}
- *instance = inst;
-
return 0;
}
static int expiration_detach(void *instance)
{
paircompare_unregister(PW_EXPIRATION, expirecmp);
- free(instance);
return 0;
}
/*
* Set up a storage area for instance data
*/
- data = rad_malloc(sizeof(*data));
- if (!data) {
- radlog(L_ERR, "rlm_expiration: rad_malloc() failed.");
- return -1;
- }
- memset(data, 0, sizeof(*data));
+ *instance = data = talloc_zero(conf, rlm_expiration_t);
+ if (!data) return -1;
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, data, module_config) < 0) {
- free(data);
radlog(L_ERR, "rlm_expiration: Configuration parsing failed.");
return -1;
}
* Register the expiration comparison operation.
*/
paircompare_register(PW_EXPIRATION, 0, expirecmp, data);
-
- *instance = data;
-
return 0;
}
xlat_unregister(inst->xlat_name, expr_xlat, instance);
pair_builtincompare_detach();
- free(inst->xlat_name);
-
- free(inst);
return 0;
}
static int expr_instantiate(CONF_SECTION *conf, void **instance)
{
rlm_expr_t *inst;
- const char *xlat_name;
/*
* Set up a storage area for instance data
*/
-
- inst = rad_malloc(sizeof(rlm_expr_t));
- if (!inst)
- return -1;
- memset(inst, 0, sizeof(rlm_expr_t));
+ *instance = inst = talloc_zero(conf, rlm_expr_t);
+ if (!inst) return -1;
if (cf_section_parse(conf, inst, module_config) < 0) {
expr_detach(inst);
return -1;
}
- xlat_name = cf_section_name2(conf);
- if (xlat_name == NULL)
- xlat_name = cf_section_name1(conf);
- if (xlat_name){
- inst->xlat_name = strdup(xlat_name);
- xlat_register(xlat_name, expr_xlat, inst);
+ inst->xlat_name = cf_section_name2(conf);
+ if (!inst->xlat_name) {
+ inst->xlat_name = cf_section_name1(conf);
}
+ xlat_register(inst->xlat_name, expr_xlat, inst);
xlat_register("rand", rand_xlat, inst);
xlat_register("randstr", randstr_xlat, inst);
xlat_register("base64tohex", base64_to_hex_xlat, inst);
/*
- * Initialize various paircompare functions
+ * Initialize various paircompare functions
*/
pair_builtincompare_init();
- *instance = inst;
-
return 0;
}
#endif
fr_hash_table_free(inst->auth_users);
fr_hash_table_free(inst->postauth_users);
- free(inst);
return 0;
}
struct file_instance *inst;
int rcode;
- inst = rad_malloc(sizeof *inst);
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, struct file_instance);
+ if (!inst) return -1;
if (cf_section_parse(conf, inst, module_config) < 0) {
- free(inst);
return -1;
}
/*
* Set up a storage area for instance data
*/
- data = rad_malloc(sizeof(*data));
- if (!data) {
- return -1;
- }
- memset(data, 0, sizeof(*data));
+ *instance = data = talloc_zero(conf, rlm_ippool_t);
+ if (!data) return -1;
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, data, module_config) < 0) {
- free(data);
return -1;
}
cache_size = data->cache_size;
if (data->session_db == NULL) {
radlog(L_ERR, "rlm_ippool: 'session-db' must be set.");
- free(data);
return -1;
}
if (data->ip_index == NULL) {
radlog(L_ERR, "rlm_ippool: 'ip-index' must be set.");
- free(data);
return -1;
}
data->range_start = htonl(data->range_start);
if (data->range_start == 0 || data->range_stop == 0 || \
data->range_start >= data->range_stop ) {
radlog(L_ERR, "rlm_ippool: Invalid configuration data given.");
- free(data);
return -1;
}
data->session_db, gdbm_strerror(gdbm_errno));
gdbm_close(data->gdbm);
gdbm_close(data->ip);
- free(data);
return -1;
}
}
data->name = strdup(pool_name);
pthread_mutex_init(&data->op_mutex, NULL);
- *instance = data;
return 0;
}
gdbm_close(data->gdbm);
gdbm_close(data->ip);
pthread_mutex_destroy(&data->op_mutex);
-
- free(instance);
return 0;
}
return -1;
}
- inst = rad_calloc(sizeof(*inst));
+ *instance = inst = talloc_zero(conf, rlm_krb5_t);
if (cf_section_parse(conf, inst, module_config) < 0) {
- free(inst);
return -1;
}
if (!inst->xlat_name) {
inst->xlat_name = cf_section_name1(conf);
}
-
- rad_assert(inst->xlat_name);
context = inst->context = rad_calloc(sizeof(*context));
ret = krb5_init_context(context);
}
#endif
- *instance = inst;
return 0;
error:
ldap_msgfree(result);
ldap_release_socket(inst, conn);
- if (!found){
+ if (!found) {
RDEBUG("User is not a member of specified group");
return 1;
}
static int ldap_detach(void *instance)
{
ldap_instance *inst = instance;
-
- if (inst->postauth) free(inst->postauth);
- if (inst->accounting) free(inst->accounting);
fr_connection_pool_delete(inst->pool);
-
+
if (inst->user_map) {
radius_mapfree(&inst->user_map);
}
- free(inst);
-
return 0;
}
return 0;
}
- *config = rad_calloc(sizeof(**config));
+ *config = talloc_zero(inst, ldap_acct_section_t);
if (cf_section_parse(cs, *config, acct_section_config) < 0) {
radlog(L_ERR, "rlm_ldap (%s): Failed parsing configuration for "
"section %s", inst->xlat_name, name);
-
- free(*config);
- *config = NULL;
-
return -1;
}
{
ldap_instance *inst;
- inst = rad_calloc(sizeof *inst);
+ *instance = inst = talloc_zero(conf, ldap_instance);
+ if (!inst) return -1;
+
inst->cs = conf;
inst->chase_referrals = 2; /* use OpenLDAP defaults */
if (!inst->xlat_name) {
inst->xlat_name = cf_section_name1(conf);
}
-
- rad_assert(inst->xlat_name);
/*
* If the configuration parameters can't be parsed, then fail.
return -1;
}
- *instance = inst;
return 0;
-
- error:
+
+error:
ldap_detach(inst);
return -1;
}
};
-static int linelog_detach(void *instance)
-{
- rlm_linelog_t *inst = instance;
-
- free(inst);
- return 0;
-}
-
/*
* Instantiate the module.
*/
/*
* Set up a storage area for instance data
*/
- inst = rad_malloc(sizeof(*inst));
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, rlm_linelog_t);
+ if (!inst) return -1;
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, inst, module_config) < 0) {
- linelog_detach(inst);
return -1;
}
if (!inst->filename) {
radlog(L_ERR, "rlm_linelog: Must specify an output filename");
- linelog_detach(inst);
return -1;
}
#ifndef HAVE_SYSLOG_H
if (strcmp(inst->filename, "syslog") == 0) {
radlog(L_ERR, "rlm_linelog: Syslog output is not supported");
- linelog_detach(inst);
return -1;
}
#else
inst->facility = fr_str2int(syslog_str2fac, inst->syslog_facility, -1);
if (inst->facility < 0) {
radlog(L_ERR, "rlm_linelog: Bad syslog facility '%s'", inst->syslog_facility);
- linelog_detach(inst);
return -1;
}
}
if (!inst->line) {
radlog(L_ERR, "rlm_linelog: Must specify a log format");
- linelog_detach(inst);
return -1;
}
inst->cs = conf;
- *instance = inst;
-
return 0;
}
"linelog",
RLM_TYPE_CHECK_CONFIG_SAFE, /* type */
linelog_instantiate, /* instantiation */
- linelog_detach, /* detach */
+ NULL, /* detach */
{
do_linelog, /* authentication */
do_linelog, /* authorization */
{ NULL, -1, 0, NULL, NULL }
};
-static int logintime_detach(void *instance);
/*
* Compare the current time to a range.
/*
* Set up a storage area for instance data
*/
- data = rad_malloc(sizeof(*data));
- if (!data) {
- radlog(L_ERR, "rlm_logintime: rad_malloc() failed.");
- return -1;
- }
- memset(data, 0, sizeof(*data));
+ *instance = data = talloc_zero(conf, rlm_logintime_t);
+ if (!data) return -1;
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, data, module_config) < 0) {
- free(data);
radlog(L_ERR, "rlm_logintime: Configuration parsing failed.");
return -1;
}
if (data->min_time == 0){
radlog(L_ERR, "rlm_logintime: Minimum timeout should be non zero.");
- free(data);
return -1;
}
paircompare_register(PW_CURRENT_TIME, 0, timecmp, data);
paircompare_register(PW_TIME_OF_DAY, 0, time_of_day, data);
- *instance = data;
-
return 0;
}
-static int logintime_detach(void *instance)
+static int logintime_detach(UNUSED void *instance)
{
paircompare_unregister(PW_CURRENT_TIME, timecmp);
paircompare_unregister(PW_TIME_OF_DAY, time_of_day);
- free(instance);
return 0;
}
* deinstantiate module, free all memory allocated during
* mschap_instantiate()
*/
-static int mschap_detach(void *instance){
-#define inst ((rlm_mschap_t *)instance)
+static int mschap_detach(void *instance)
+{
+ rlm_mschap_t *inst = instance;
if (inst->xlat_name) {
xlat_unregister(inst->xlat_name, mschap_xlat, instance);
- free(inst->xlat_name);
}
- free(instance);
return 0;
-#undef inst
}
/*
const char *name;
rlm_mschap_t *inst;
- inst = *instance = rad_malloc(sizeof(*inst));
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, rlm_mschap_t);
+ if (!inst) return -1;
if (cf_section_parse(conf, inst, module_config) < 0) {
- free(inst);
return -1;
}
*/
if (inst->passwd_file) {
radlog(L_ERR, "rlm_mschap: SMB password file is no longer supported in this module. Use rlm_passwd module instead");
- mschap_detach(inst);
return -1;
}
*/
name = cf_section_name2(conf);
if (!name) name = cf_section_name1(conf);
- inst->xlat_name = strdup(name);
+ inst->xlat_name = name;
xlat_register(inst->xlat_name, mschap_xlat, inst);
/*
*/
static rlm_rcode_t mschap_authorize(void * instance, REQUEST *request)
{
-#define inst ((rlm_mschap_t *)instance)
+ rlm_mschap_t *inst = instance;
VALUE_PAIR *challenge = NULL;
challenge = pairfind(request->packet->vps, PW_MSCHAP_CHALLENGE, VENDORPEC_MICROSOFT, TAG_ANY);
}
return RLM_MODULE_OK;
-#undef inst
}
/*
otp_option_t *opt;
/* Set up a storage area for instance data. */
- opt = rad_calloc(sizeof(*opt));
+ *instance = opt = talloc_zero(conf, otp_option_t);
+ if (!opt) return -1;
/* If the configuration parameters can't be parsed, then fail. */
if (cf_section_parse(conf, opt, module_config) < 0) {
- free(opt);
return -1;
}
if (!opt->allow_sync && !opt->allow_async) {
radlog(L_ERR, "rlm_otp: %s: at least one of {allow_async, "
"allow_sync} must be set", __func__);
- free(opt);
-
return -1;
}
if (!opt->name) {
radlog(L_ERR, "rlm_otp: %s: no instance name "
"(this can't happen)", __func__);
- free(opt);
return -1;
}
- *instance = opt;
-
return 0;
}
return rc;
}
-
-/*
- * Per-instance destruction
- */
-static int otp_detach(void *instance)
-{
- free(instance);
- /*
- * Only the main thread instantiates and detaches instances,
- * so this does not need mutex protection.
- */
- if (--ninstance == 0) {
- (void) memset(hmac_key, 0, sizeof(hmac_key));
- }
-
- return 0;
-}
-
/*
* If the module needs to temporarily modify it's instantiation
* data, the type should be changed to RLM_TYPE_THREAD_UNSAFE.
"otp",
RLM_TYPE_THREAD_SAFE, /* type */
otp_instantiate, /* instantiation */
- otp_detach, /* detach */
+ NULL, /* detach */
{
otp_authenticate, /* authentication */
otp_authorize, /* authorization */
{
rlm_pam_t *data;
- data = rad_malloc(sizeof(*data));
- if (!data) {
- return -1;
- }
- memset(data, 0, sizeof(*data));
+ *instance = data = talloc_zero(conf, rlm_pam_t);
+ if (!data) return -1;
if (cf_section_parse(conf, data, module_config) < 0) {
- free(data);
return -1;
}
- *instance = data;
- return 0;
-}
-
-/*
- * Clean up.
- */
-static int pam_detach(void *instance)
-{
- rlm_pam_t *data = (rlm_pam_t *) instance;
-
- free((char *) data);
return 0;
}
"pam",
RLM_TYPE_THREAD_UNSAFE, /* The PAM libraries are not thread-safe */
pam_instantiate, /* instantiation */
- pam_detach, /* detach */
+ NULL, /* detach */
{
pam_auth, /* authenticate */
NULL, /* authorize */
};
-static int pap_detach(void *instance)
-{
- rlm_pap_t *inst = (rlm_pap_t *) instance;
-
- free(inst);
-
- return 0;
-}
-
-
static int pap_instantiate(CONF_SECTION *conf, void **instance)
{
rlm_pap_t *inst;
/*
* Set up a storage area for instance data
*/
- inst = rad_malloc(sizeof(*inst));
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, rlm_pap_t);
+ if (!inst) return -1;
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, inst, module_config) < 0) {
- pap_detach(inst);
return -1;
}
inst->auth_type = 0;
}
- *instance = inst;
-
return 0;
}
"PAP",
RLM_TYPE_CHECK_CONFIG_SAFE | RLM_TYPE_HUP_SAFE, /* type */
pap_instantiate, /* instantiation */
- pap_detach, /* detach */
+ NULL, /* detach */
{
pap_authenticate, /* authentication */
pap_authorize, /* authorization */
free(ht);
return NULL;
}
+
+ /*
+ * @todo: This code is SHIT. It's badly formatted. It's
+ * hard to understand. It re-implements tons of things
+ * which are already in the server core.
+ */
memset(ht->buffer, 0, 1024);
ht->table = (struct mypasswd **) rad_malloc (tablesize * sizeof(struct mypasswd *));
if (!ht->table) {
static int passwd_instantiate(CONF_SECTION *conf, void **instance)
{
-#define inst ((struct passwd_instance *)*instance)
int nfields=0, keyfield=-1, listable=0;
char *s;
char *lf=NULL; /* destination list flags temporary */
size_t len;
int i;
const DICT_ATTR * da;
+ struct passwd_instance *inst;
+
+ *instance = inst = talloc_zero(conf, struct passwd_instance);
+ if (inst) return -1;
- *instance = rad_malloc(sizeof(struct passwd_instance));
- if ( !*instance) {
- radlog(L_ERR, "rlm_passwd: cann't alloc instance");
- return -1;
- }
- memset(*instance, 0, sizeof(struct passwd_instance));
if (cf_section_parse(conf, inst, module_config) < 0) {
- free(inst);
radlog(L_ERR, "rlm_passwd: cann't parse configuration");
return -1;
}
if(!inst->filename || *inst->filename == '\0' || !inst->format || *inst->format == '\0') {
radlog(L_ERR, "rlm_passwd: can't find passwd file and/or format in configuration");
- free(inst);
return -1;
}
if (inst->hashsize == 0) {
radlog(L_ERR, "rlm_passwd: hashsize=0 is no longer permitted as it will break the server.");
- free(inst);
return -1;
}
- lf=strdup(inst->format);
+ lf = talloc_strdup(inst, inst->format);
if ( lf == NULL) {
radlog(L_ERR, "rlm_passwd: memory allocation failed for lf");
- free(inst);
return -1;
}
memset(lf, 0, strlen(inst->format));
}while(*s);
if(keyfield < 0) {
radlog(L_ERR, "rlm_passwd: no field market as key in format: %s", inst->format);
- free(lf);
return -1;
}
if (! (inst->ht = build_hash_table (inst->filename, nfields, keyfield, listable, inst->hashsize, inst->ignorenislike, *inst->delimiter)) ){
radlog(L_ERR, "rlm_passwd: can't build hashtable from passwd file");
- free(lf);
return -1;
}
if (! (inst->pwdfmt = mypasswd_malloc(inst->format, nfields, &len)) ){
radlog(L_ERR, "rlm_passwd: memory allocation failed");
release_ht(inst->ht);
- free(lf);
return -1;
}
if (!string_to_entry(inst->format, nfields, ':', inst->pwdfmt , len)) {
radlog(L_ERR, "rlm_passwd: unable to convert format entry");
release_ht(inst->ht);
- free(lf);
return -1;
}
memcpy(inst->pwdfmt->listflag, lf, nfields);
- free(lf);
+ talloc_free(lf);
for (i=0; i<nfields; i++) {
if (*inst->pwdfmt->field[i] == '*') inst->pwdfmt->field[i]++;
if (*inst->pwdfmt->field[i] == ',') inst->pwdfmt->field[i]++;
static int passwd_detach (void *instance) {
#define inst ((struct passwd_instance *)instance)
if(inst->ht) release_ht(inst->ht);
- free(instance);
return 0;
#undef inst
}
const char *xlat_name;
int exitstatus = 0, argc=0;
- embed = rad_malloc(4 * sizeof(char *));
- memset(embed, 0, 4 *sizeof(char *));
/*
* Set up a storage area for instance data
*/
- inst = rad_malloc(sizeof(PERL_INST));
- memset(inst, 0, sizeof(PERL_INST));
+ *instance = inst = talloc_zero(conf, PERL_INST);
+ if (!inst) return -1;
+
+ embed = talloc_size(inst, 4 * sizeof(char *));
+ memset(embed, 0, 4 *sizeof(char *));
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, inst, module_config) < 0) {
- free(embed);
- free(inst);
return -1;
}
#ifdef USE_ITHREADS
if ((inst->perl = perl_alloc()) == NULL) {
radlog(L_DBG, "rlm_perl: No memory for allocating new perl !");
- free(embed);
- free(inst);
return (-1);
}
#else
if ((inst->perl = perl_alloc()) == NULL) {
radlog(L_ERR, "rlm_perl: No memory for allocating new perl !");
- free(embed);
- free(inst);
return -1;
}
exitstatus = perl_run(inst->perl);
} else {
radlog(L_ERR,"rlm_perl: perl_parse failed: %s not found or has syntax errors. \n", inst->module);
- free(embed);
- free(inst);
return (-1);
}
xlat_name = cf_section_name2(conf);
if (xlat_name == NULL)
xlat_name = cf_section_name1(conf);
- if (xlat_name){
- inst->xlat_name = strdup(xlat_name);
+ if (xlat_name) {
xlat_register(xlat_name, perl_xlat, inst);
}
- *instance = inst;
-
return 0;
}
}
xlat_unregister(inst->xlat_name, perl_xlat, instance);
- free(inst->xlat_name);
#ifdef USE_ITHREADS
rlm_perl_destruct(inst->perl);
#endif
PERL_SYS_TERM();
- free(inst);
return exitstatus;
}
/*
* Allocate room to put the module's instantiation data.
*/
- data = (rlm_preprocess_t *) rad_malloc(sizeof(*data));
- memset(data, 0, sizeof(*data));
+ *instance = data = talloc_zero(conf, rlm_preprocess_t);
+ if (!data) return -1;
/*
* Read this modules configuration data.
*/
if (cf_section_parse(conf, data, module_config) < 0) {
- free(data);
return -1;
}
}
}
- /*
- * Save the instantiation data for later.
- */
- *instance = data;
-
return 0;
}
pairlist_free(&(data->huntgroups));
pairlist_free(&(data->hints));
- free(data);
-
return 0;
}
/*
* Set up a storage area for instance data
*/
- if ((data = malloc(sizeof(*data))) == NULL)
- return -1;
- memset(data, 0, sizeof(*data));
+ *instance = data = talloc_zero(conf, struct rlm_python_t);
+ if (!data) return -1;
if (python_init() != 0) {
- free(data);
return -1;
}
* fail.
*/
if (cf_section_parse(conf, data, module_config) < 0) {
- free(data);
return -1;
}
#undef A
- *instance = data;
-
/*
* Call the instantiate function. No request. Use the
* return value.
failed:
python_error();
python_instance_clear(data);
- free(data);
return -1;
}
ret = python_function(NULL, data->detach.function, "detach");
python_instance_clear(data);
-
- free(data);
return ret;
}
{
rlm_radutmp_t *inst;
- inst = rad_malloc(sizeof(*inst));
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, rlm_radutmp_t);
+ if (!inst) return -1;
if (cf_section_parse(conf, inst, module_config)) {
- free(inst);
return -1;
}
inst->nas_port_list = NULL;
- *instance = inst;
- return 0;
-}
-
-
-/*
- * Detach.
- */
-static int radutmp_detach(void *instance)
-{
- NAS_PORT *p, *next;
- rlm_radutmp_t *inst = instance;
-
- for (p = inst->nas_port_list ; p ; p=next) {
- next = p->next;
- free(p);
- }
- free(inst);
return 0;
}
* Remember where the entry was, because it's
* easier than searching through the entire file.
*/
- if (cache == NULL) {
- cache = rad_malloc(sizeof(NAS_PORT));
- cache->nasaddr = ut.nas_address;
- cache->port = ut.nas_port;
- cache->offset = off;
- cache->next = inst->nas_port_list;
- inst->nas_port_list = cache;
+ if (!cache) {
+ cache = talloc_zero(inst, NAS_PORT);
+ if (cache) {
+ cache->nasaddr = ut.nas_address;
+ cache->port = ut.nas_port;
+ cache->offset = off;
+ cache->next = inst->nas_port_list;
+ inst->nas_port_list = cache;
+ }
}
ut.type = P_LOGIN;
module_t rlm_radutmp = {
RLM_MODULE_INIT,
"radutmp",
- RLM_TYPE_CHECK_CONFIG_SAFE | RLM_TYPE_HUP_SAFE, /* type */
+ RLM_TYPE_THREAD_UNSAFE | RLM_TYPE_CHECK_CONFIG_SAFE | RLM_TYPE_HUP_SAFE, /* type */
radutmp_instantiate, /* instantiation */
- radutmp_detach, /* detach */
+ NULL, /* detach */
{
NULL, /* authentication */
NULL, /* authorization */
struct realm_config_t *inst;
/* setup a storage area for instance data */
- inst = rad_malloc(sizeof(*inst));
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, struct realm_config_t);
+ if (!inst) return -1;
if(cf_section_parse(conf, inst, module_config) < 0) {
- free(inst);
return -1;
}
if(strcasecmp(inst->formatstring, "suffix") == 0) {
inst->format = REALM_FORMAT_SUFFIX;
+
} else if(strcasecmp(inst->formatstring, "prefix") == 0) {
inst->format = REALM_FORMAT_PREFIX;
+
} else {
radlog(L_ERR, "Bad value \"%s\" for realm format value", inst->formatstring);
- free(inst);
return -1;
}
if(strlen(inst->delim) != 1) {
radlog(L_ERR, "Bad value \"%s\" for realm delimiter value", inst->delim);
- free(inst);
return -1;
}
- *instance = inst;
return 0;
-
}
-
-
-
/*
* Examine a request for a username with an realm, and if it
* corresponds to something in the realms file, set that realm as
}
#endif
-static int realm_detach(void *instance)
-{
- free(instance);
- return 0;
-}
-
/* globally exported name */
module_t rlm_realm = {
RLM_MODULE_INIT,
"realm",
RLM_TYPE_CHECK_CONFIG_SAFE | RLM_TYPE_HUP_SAFE, /* type */
realm_instantiate, /* instantiation */
- realm_detach, /* detach */
+ NULL, /* detach */
{
NULL, /* authentication */
realm_authorize, /* authorization */
if (inst->xlat_name) {
xlat_unregister(inst->xlat_name, redis_xlat, instance);
- free(inst->xlat_name);
}
- free(inst->xlat_name);
- free(inst);
return 0;
}
/*
* Set up a storage area for instance data
*/
- inst = rad_malloc(sizeof (REDIS_INST));
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof (*inst));
+ *instance = inst = talloc_zero(conf, REDIS_INST);
+ if (!inst) return -1;
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, inst, module_config) < 0) {
- free(inst);
return -1;
}
if (!xlat_name)
xlat_name = cf_section_name1(conf);
- inst->xlat_name = strdup(xlat_name);
xlat_register(inst->xlat_name, redis_xlat, inst);
inst->pool = fr_connection_pool_init(conf, inst,
redis_create_conn, NULL,
redis_delete_conn);
if (!inst->pool) {
- redis_detach(inst);
return -1;
}
inst->redis_finish_query = rlm_redis_finish_query;
inst->redis_escape_func = redis_escape_func;
- *instance = inst;
-
return 0;
}
return result;
}
-static int rediswho_detach(void *instance)
-{
- rlm_rediswho_t *inst;
-
- inst = instance;
- free(inst);
-
- return 0;
-}
-
-static int rediswho_instantiate(CONF_SECTION * conf, void ** instance)
+static int rediswho_instantiate(CONF_SECTION *conf, void ** instance)
{
module_instance_t *modinst;
rlm_rediswho_t *inst;
/*
* Set up a storage area for instance data
*/
- inst = *instance = rad_malloc(sizeof (*inst));
- memset(inst, 0, sizeof (*inst));
+ *instance = inst = talloc_zero(conf, rlm_rediswho_t);
+ if (!inst) return -1;
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, inst, module_config) < 0) {
- free(inst);
return -1;
}
if (!inst->xlat_name)
inst->xlat_name = cf_section_name1(conf);
- inst->xlat_name = strdup(inst->xlat_name);
inst->cs = conf;
modinst = find_module_instance(cf_section_find("modules"),
radlog(L_ERR,
"rediswho: failed to find module instance \"%s\"",
inst->redis_instance_name);
-
- rediswho_detach(inst);
return -1;
}
radlog(L_ERR, "rediswho: Module \"%s\""
" is not an instance of the redis module",
inst->redis_instance_name);
-
- rediswho_detach(inst);
return -1;
}
module_t rlm_rediswho = {
RLM_MODULE_INIT,
"rediswho",
- RLM_TYPE_THREAD_SAFE, /* type */
- rediswho_instantiate, /* instantiation */
- rediswho_detach, /* detach */
+ RLM_TYPE_THREAD_SAFE, /* type */
+ rediswho_instantiate, /* instantiation */
+ NULL, /* detach */
{
NULL, /* authentication */
NULL, /* authorization */
/*
* Allocate memory for instance data.
*/
- data = rad_malloc(sizeof(*data));
- if (!data) {
- return -1;
- }
- memset(data, 0, sizeof(*data));
+ *instance = data = talloc_zero(conf, rlm_rest_t);
+ if (!data) return -1;
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, data, module_config) < 0) {
- free(data);
return -1;
}
return -1;
}
- *instance = data;
-
return 0;
}
fr_connection_pool_delete(my_instance->conn_pool);
- free(my_instance);
-
/* Free any memory used by libcurl */
rest_cleanup();
* to the strdup'd string into 'config.string'. This gets around
* buffer over-flows.
*/
-
-
static const CONF_PARSER module_config[] = {
{ "scriptfile", PW_TYPE_FILENAME,
offsetof(struct rlm_ruby_t, scriptFile), NULL, NULL},
* in *instance otherwise put a null pointer there.
*
*/
-static int ruby_instantiate(CONF_SECTION *conf, void **instance) {
+static int ruby_instantiate(CONF_SECTION *conf, void **instance)
+{
rlm_ruby_t *data;
VALUE module;
int idx;
* Initialize Ruby interpreter. Fatal error if this fails.
*/
- radlog(L_DBG, "[rlm_ruby]: ruby_instantiate");
ruby_init();
ruby_init_loadpath();
ruby_script("radiusd");
/*
* Set up a storage area for instance data
*/
- data = rad_malloc(sizeof (*data));
- if (!data) {
- return -1;
- }
- memset(data, 0, sizeof (*data));
+ *instance = data = talloc_zero(conf, rlm_ruby_t);
+ if (!data) return -1;
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, data, module_config) < 0) {
- free(data);
return -1;
}
if ((module = data->pModule_builtin = rb_define_module(data->moduleName)) == 0) {
radlog(L_ERR, "Ruby rb_define_module failed");
- free(data);
return -1;
}
/*
* Import user modules.
*/
#define RLM_RUBY_LOAD(foo) if (load_ruby_function(#foo, &data->func_##foo, data->pModule_builtin)==-1) { \
- /* TODO: check if we need to cleanup data */ \
return -1; \
}
#endif
RLM_RUBY_LOAD(detach);
- *instance = data;
-
/* Call the instantiate function. No request. Use the return value. */
return ruby_function(NULL, data->func_instantiate, data->pModule_builtin, "instantiate");
}
RLM_RUBY_FUNC(sendcoa)
#endif
-static int ruby_detach(void *instance) {
- int return_value;
-
- /* Default return value is failure */
- return_value = -1;
- free(instance);
+static int ruby_detach(UNUSED void *instance)
+{
ruby_finalize();
ruby_cleanup(0);
- radlog(L_DBG, "ruby_detach done");
-
- //Ok, we cheat, and returon ok value for now :)
- return_value = RLM_MODULE_OK;
- /* Return the specified by the Ruby module */
- return return_value;
+ return 0;
}
-
/*
* The module name should be the only globally exported symbol.
* That is, everything else should be 'static'.
pthread_mutex_destroy(&(inst->session_mutex));
- free(inst);
return 0;
}
rlm_securid_t *inst;
/* Set up a storage area for instance data */
- inst = rad_malloc(sizeof(*inst));
- if (!inst) return -1;
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, rlm_securid_t);
+ if (!inst) return -1;
/* If the configuration parameters can't be parsed, then fail. */
if (cf_section_parse(conf, inst, module_config) < 0) {
radlog(L_ERR, "rlm_securid: Unable to parse configuration section.");
- securid_detach(inst);
return -1;
}
inst->session_tree = rbtree_create(securid_session_cmp, NULL, 0);
if (!inst->session_tree) {
radlog(L_ERR, "rlm_securid: Cannot initialize session tree.");
- securid_detach(inst);
return -1;
}
pthread_mutex_init(&(inst->session_mutex), NULL);
-
- *instance = inst;
return 0;
}
{
struct sim_file_instance *inst;
- inst = rad_malloc(sizeof *inst);
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, struct sim_file_instance);
+ if (!inst) return -1;
if (cf_section_parse(conf, inst, module_config) < 0) {
- free(inst);
return -1;
}
- *instance = inst;
return 0;
}
}
-/*
- * Clean up.
- */
-static int sim_file_detach(void *instance)
-{
- struct sim_file_instance *inst = instance;
-
- free(inst);
- return 0;
-}
-
-
/* globally exported name */
module_t rlm_sim_files = {
RLM_MODULE_INIT,
"sim_files",
0, /* type: reserved */
sim_file_instantiate, /* instantiation */
- sim_file_detach, /* detach */
+ NULL, /* detach */
{
NULL, /* authentication */
sim_file_authorize, /* authorization */
/*
* Set up a storage area for instance data
*/
- data = rad_malloc(sizeof(*data));
- if (!data) {
- return -1;
- }
- memset(data, 0, sizeof(*data));
+ *instance = data = talloc_zero(conf, rlm_smsotp_t);
+ if (!data) return -1;
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, data, module_config) < 0) {
- free(data);
return -1;
}
- *instance = data;
-
return 0;
}
return RLM_MODULE_OK;
}
-/*
- * Only free memory we allocated. The strings allocated via
- * cf_section_parse() do not need to be freed.
- */
-static int smsotp_detach(void *instance)
-{
- free(instance);
- return 0;
-}
-
/* forward declarations */
static smsotp_fd_t *smsotp_fd_head = NULL;
static pthread_mutex_t smsotp_fd_head_mutex = PTHREAD_MUTEX_INITIALIZER;
"smsotp",
RLM_TYPE_THREAD_SAFE, /* type */
smsotp_instantiate, /* instantiation */
- smsotp_detach, /* detach */
+ NULL, /* detach */
{
smsotp_authenticate, /* authentication */
smsotp_authorize, /* authorization */
{ NULL, -1, 0, NULL, NULL } /* end the list */
};
-static int soh_detach(void *instance) {
+static int soh_detach(void *instance)
+{
rlm_soh_t *inst = instance;
if (inst->xlat_name) {
xlat_unregister(inst->xlat_name, soh_xlat, instance);
- free(inst->xlat_name);
}
- free(instance);
return 0;
}
-static int soh_instantiate(CONF_SECTION *conf, void **instance) {
+static int soh_instantiate(CONF_SECTION *conf, void **instance)
+{
const char *name;
rlm_soh_t *inst;
- inst = *instance = rad_malloc(sizeof(*inst));
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, rlm_soh_t);
+ if (!inst) return -1;
if (cf_section_parse(conf, inst, module_config) < 0) {
- free(inst);
return -1;
}
name = cf_section_name2(conf);
if (!name) name = cf_section_name1(conf);
- inst->xlat_name = strdup(name);
+ inst->xlat_name = name;
+ if (!inst->xlat_name) return -1;
xlat_register(inst->xlat_name, soh_xlat, inst);
return 0;
"SoH",
RLM_TYPE_THREAD_SAFE, /* type */
soh_instantiate, /* instantiation */
- soh_detach, /* detach */
+ soh_detach, /* detach */
{
NULL, /* authenticate */
soh_authorize, /* authorize */
}
}
-static int sometimes_detach(void *instance)
-{
- rlm_sometimes_t *inst = instance;
-
- free(inst->rcode_str);
- free(inst->key);
- free(inst);
-
- return 0;
-}
-
static int sometimes_instantiate(CONF_SECTION *conf, void **instance)
{
rlm_sometimes_t *inst;
/*
* Set up a storage area for instance data
*/
- inst = rad_malloc(sizeof(*inst));
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, rlm_sometimes_t);
+ if (!inst) return -1;
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, inst, module_config) < 0) {
- sometimes_detach(inst);
return -1;
}
*/
inst->rcode = str2rcode(inst->rcode_str);
if (inst->rcode == -1) {
- sometimes_detach(inst);
return -1;
}
if (!inst->da) {
radlog(L_ERR, "rlm_sometimes; Unknown attributes %s", inst->key);
return -1;
- return -1;
}
*instance = inst;
"sometimes",
RLM_TYPE_CHECK_CONFIG_SAFE | RLM_TYPE_HUP_SAFE, /* type */
sometimes_instantiate, /* instantiation */
- sometimes_detach, /* detach */
+ NULL, /* detach */
{
sometimes_packet, /* authentication */
sometimes_packet, /* authorization */
DEBUG("rlm_sql (%s): Read entry nasname=%s,shortname=%s,secret=%s",inst->config->xlat_name,
row[1],row[2],row[4]);
- c = rad_malloc(sizeof(*c));
- memset(c, 0, sizeof(*c));
+ c = talloc_zero(inst, RADCLIENT);
#ifdef WITH_DYNAMIC_CLIENTS
c->dynamic = 1;
if ((c->prefix < 0) || (c->prefix > 128)) {
radlog(L_ERR, "rlm_sql (%s): Invalid Prefix value '%s' for IP.",
inst->config->xlat_name, prefix_ptr + 1);
- free(c);
+ talloc_free(c);
continue;
}
/* Replace '/' with '\0' */
radlog(L_ERR, "rlm_sql (%s): Failed to look up hostname %s: %s",
inst->config->xlat_name,
row[1], fr_strerror());
- free(c);
+ talloc_free(c);
continue;
} else {
char buffer[256];
ip_ntoh(&c->ipaddr, buffer, sizeof(buffer));
- c->longname = strdup(buffer);
+ c->longname = talloc_strdup(c, buffer);
}
if (c->prefix < 0) switch (c->ipaddr.af) {
/*
* Other values (secret, shortname, nastype, virtual_server)
*/
- c->secret = strdup(row[4]);
- c->shortname = strdup(row[2]);
+ c->secret = talloc_strdup(c, row[4]);
+ c->shortname = talloc_strdup(c, row[2]);
if(row[3] != NULL)
c->nastype = strdup(row[3]);
paircompare_unregister(PW_SQL_GROUP, sql_groupcmp);
if (inst->config) {
- if (inst->config->postauth) free(inst->config->postauth);
- if (inst->config->accounting) free(inst->config->accounting);
-
if (inst->pool) sql_poolfree(inst);
if (inst->config->xlat_name) {
xlat_unregister(inst->config->xlat_name, sql_xlat, instance);
- rad_cfree(inst->config->xlat_name);
}
-
- free(inst->config);
- inst->config = NULL;
}
if (inst->handle) {
lt_dlclose(inst->handle); /* ignore any errors */
#endif
}
- free(inst);
return 0;
}
return 0;
}
- *config = rad_calloc(sizeof(**config));
+ *config = talloc_zero(parent, sql_acct_section_t);
if (cf_section_parse(cs, *config, acct_section_config) < 0) {
radlog(L_ERR, "rlm_sql (%s): Couldn't find configuration for "
"%s, will return NOOP for calls from this section",
inst->config->xlat_name, name);
-
- free(*config);
- *config = NULL;
-
return -1;
}
return 0;
}
-static int rlm_sql_instantiate(CONF_SECTION * conf, void **instance)
+static int rlm_sql_instantiate(CONF_SECTION *conf, void **instance)
{
SQL_INST *inst;
const char *xlat_name;
- inst = rad_calloc(sizeof(SQL_INST));
+ *instance = inst = talloc_zero(conf, SQL_INST);
+ if (!inst) return -1;
/*
* Cache the SQL-User-Name DICT_ATTR, so we can be slightly
* more efficient about creating SQL-User-Name attributes.
*/
inst->sql_user = dict_attrbyname("SQL-User-Name");
- if (!inst->sql_user) {
- goto error;
- }
+ if (!inst->sql_user) return -1;
/*
* Export these methods, too. This avoids RTDL_GLOBAL.
inst->sql_select_query = rlm_sql_select_query;
inst->sql_fetch_row = rlm_sql_fetch_row;
- inst->config = rad_calloc(sizeof(SQL_CONFIG));
+ inst->config = talloc_zero(inst, SQL_CONFIG);
inst->cs = conf;
xlat_name = cf_section_name2(conf);
/*
* Allocate room for <instance>-SQL-Group
*/
- group_name = rad_malloc((strlen(xlat_name) + 1 + 11) * sizeof(char));
- sprintf(group_name,"%s-SQL-Group", xlat_name);
+ group_name = talloc_asprintf(inst, "%s-SQL-Group", xlat_name);
DEBUG("rlm_sql (%s): Creating new attribute %s",
xlat_name, group_name);
radlog(L_ERR, "rlm_sql (%s): Failed to create "
"attribute %s: %s", xlat_name, group_name,
fr_strerror());
- free(group_name);
- goto error;
+ return -1;
}
dattr = dict_attrbyname(group_name);
- if (dattr == NULL){
+ if (!dattr) {
radlog(L_ERR, "rlm_sql (%s): Failed to create "
"attribute %s", xlat_name, group_name);
-
- free(group_name);
-
- goto error;
+ return -1;
}
if (inst->config->groupmemb_query &&
paircompare_register(dattr->attr, PW_USER_NAME,
sql_groupcmp, inst);
}
-
- free(group_name);
}
rad_assert(xlat_name);
-
/*
* Register the SQL xlat function
*/
- inst->config->xlat_name = strdup(xlat_name);
+ inst->config->xlat_name = talloc_strdup(inst->config, xlat_name);
xlat_register(xlat_name, sql_xlat, inst);
/*
RLM_COMPONENT_POST_AUTH) < 0)) {
radlog(L_ERR, "rlm_sql (%s): Failed parsing configuration",
inst->config->xlat_name);
- goto error;
+ return -1;
}
/*
if (strncmp(inst->config->sql_driver, "rlm_sql_", 8) != 0) {
radlog(L_ERR, "rlm_sql (%s): \"%s\" is NOT an SQL driver!",
inst->config->xlat_name, inst->config->sql_driver);
- goto error;
+ return -1;
}
/*
lt_dlerror());
radlog(L_ERR, "Make sure it (and all its dependent libraries!)"
"are in the search path of your system's ld.");
-
- goto error;
+ return -1;
}
inst->module = (rlm_sql_module_t *) lt_dlsym(inst->handle,
radlog(L_ERR, "Could not link symbol %s: %s",
inst->config->sql_driver,
lt_dlerror());
-
- goto error;
+ return -1;
}
radlog(L_INFO, "rlm_sql (%s): Driver %s (module %s) loaded and linked",
inst->config->sql_server, inst->config->sql_port,
inst->config->sql_db);
- if (sql_init_socketpool(inst) < 0)
- goto error;
+ if (sql_init_socketpool(inst) < 0) return -1;
if (inst->config->groupmemb_query &&
inst->config->groupmemb_query[0]) {
if (inst->config->do_clients) {
if (generate_sql_clients(inst) == -1){
radlog(L_ERR, "Failed to load clients from SQL.");
-
- goto error;
+ return -1;
}
}
- *instance = inst;
-
return RLM_MODULE_OK;
-
- error:
- rlm_sql_detach(inst);
-
- return -1;
}
#define MAX_QUERY_LEN 1024
-static int sqlcounter_detach(void *instance);
-
/*
* Note: When your counter spans more than 1 period (ie 3 months
* or 2 weeks), this module probably does NOT do what you want! It
}
+static int sqlcounter_detach(void *instance)
+{
+ rlm_sqlcounter_t *inst = (rlm_sqlcounter_t *)instance;
+
+ paircompare_unregister(inst->dict_attr->attr, sqlcounter_cmp);
+
+ return 0;
+}
+
/*
* Do any per-module initialization that is separate to each
* configured instance of the module. e.g. set up connections
/*
* Set up a storage area for instance data
*/
- data = rad_malloc(sizeof(*data));
- if (!data) {
- radlog(L_ERR, "rlm_sqlcounter: Not enough memory.");
- return -1;
- }
- memset(data, 0, sizeof(*data));
+ *instance = data = talloc_zero(conf, rlm_sqlcounter_t);
+ if (!data) return -1;
/*
* If the configuration parameters can't be parsed, then
*/
if (cf_section_parse(conf, data, module_config) < 0) {
radlog(L_ERR, "rlm_sqlcounter: Unable to parse parameters.");
- sqlcounter_detach(data);
return -1;
}
*/
if (data->query == NULL) {
radlog(L_ERR, "rlm_sqlcounter: 'query' must be set.");
- sqlcounter_detach(data);
return -1;
}
*/
if (data->key_name == NULL) {
radlog(L_ERR, "rlm_sqlcounter: 'key' must be set.");
- sqlcounter_detach(data);
return -1;
}
dattr = dict_attrbyname(data->key_name);
if (dattr == NULL) {
radlog(L_ERR, "rlm_sqlcounter: No such attribute %s",
data->key_name);
- sqlcounter_detach(data);
return -1;
}
data->key_attr = dattr;
if (dattr == NULL) {
radlog(L_ERR, "rlm_sqlcounter: No such attribute %s",
data->reply_name);
- sqlcounter_detach(data);
return -1;
}
data->reply_attr = dattr;
*/
if (data->sqlmod_inst == NULL) {
radlog(L_ERR, "rlm_sqlcounter: 'sqlmod-inst' must be set.");
- sqlcounter_detach(data);
return -1;
}
*/
if (data->counter_name == NULL) {
radlog(L_ERR, "rlm_sqlcounter: 'counter-name' must be set.");
- sqlcounter_detach(data);
return -1;
}
if (dattr == NULL) {
radlog(L_ERR, "rlm_sqlcounter: Failed to create counter attribute %s",
data->counter_name);
- sqlcounter_detach(data);
return -1;
}
if (dattr->vendor != 0) {
radlog(L_ERR, "Counter attribute must not be a VSA");
- sqlcounter_detach(data);
return -1;
}
data->dict_attr = dattr;
*/
if (data->check_name == NULL) {
radlog(L_ERR, "rlm_sqlcounter: 'check-name' must be set.");
- sqlcounter_detach(data);
return -1;
}
dict_addattr(data->check_name, 0, PW_TYPE_INTEGER, -1, flags);
if (dattr == NULL) {
radlog(L_ERR, "rlm_sqlcounter: Failed to create check attribute %s",
data->check_name);
- sqlcounter_detach(data);
return -1;
}
DEBUG2("rlm_sqlcounter: Check attribute %s is number %d",
*/
if (data->reset == NULL) {
radlog(L_ERR, "rlm_sqlcounter: 'reset' must be set.");
- sqlcounter_detach(data);
return -1;
}
now = time(NULL);
if (find_next_reset(data,now) == -1) {
radlog(L_ERR, "rlm_sqlcounter: Failed to find the next reset time.");
- sqlcounter_detach(data);
return -1;
}
if (find_prev_reset(data,now) == -1) {
radlog(L_ERR, "rlm_sqlcounter: Failed to find the previous reset time.");
- sqlcounter_detach(data);
return -1;
}
return rcode;
}
-static int sqlcounter_detach(void *instance)
-{
- rlm_sqlcounter_t *inst = (rlm_sqlcounter_t *)instance;
-
- paircompare_unregister(inst->dict_attr->attr, sqlcounter_cmp);
-
- free(inst);
- return 0;
-}
-
/*
* The module name should be the only globally exported symbol.
* That is, everything else should be 'static'.
return 1;
}
-static int sqlhpwippool_detach(void *instance)
-{
- rlm_sqlhpwippool_t *data = (rlm_sqlhpwippool_t *) instance;
-
- /* (*data) is zeroed on instantiation */
- if (data->sqlinst_name) free(data->sqlinst_name);
- if (data->db_name) free(data->db_name);
- free(data);
-
- return 0;
-}
-
/* standard foobar code */
static int sqlhpwippool_instantiate(CONF_SECTION *conf, void **instance)
{
- rlm_sqlhpwippool_t *data;
- module_instance_t *modinst;
+ rlm_sqlhpwippool_t *inst;
+ module_instance_t *sqlinst;
/* set up a storage area for instance data */
- data = rad_malloc(sizeof(*data));
- if (!data) return -1;
- memset(data, 0, sizeof(*data)); /* so _detach will know what to free */
+ *instance = inst = talloc_zero(conf, rlm_sqlhpwippool_t);
+ if (!inst) return -1;
/* fail if the configuration parameters can't be parsed */
- if (cf_section_parse(conf, data, module_config) < 0) {
- sqlhpwippool_detach(*instance);
+ if (cf_section_parse(conf, inst, module_config) < 0) {
return -1;
}
/* save my name */
- data->myname = cf_section_name2(conf);
- if (!data->myname) {
- data->myname = "(no name)";
+ inst->myname = cf_section_name2(conf);
+ if (!inst->myname) {
+ inst->myname = "(no name)";
}
- data->sincesync = 0;
+ inst->sincesync = 0;
- modinst = find_module_instance(cf_section_find("modules"), (data->sqlinst_name), 1 );
- if (!modinst) {
- nvp_log(__LINE__, data, L_ERR,
+ sqlinst = find_module_instance(cf_section_find("modules"), (inst->sqlinst_name), 1 );
+ if (!sqlinst) {
+ nvp_log(__LINE__, inst, L_ERR,
"sqlhpwippool_instantiate(): cannot find module instance "
"named \"%s\"",
- data->sqlinst_name);
+ inst->sqlinst_name);
return -1;
}
/* check if the given instance is really a rlm_sql instance */
- if (strcmp(modinst->entry->name, "rlm_sql") != 0) {
- nvp_log(__LINE__, data, L_ERR,
+ if (strcmp(sqlinst->entry->name, "rlm_sql") != 0) {
+ nvp_log(__LINE__, inst, L_ERR,
"sqlhpwippool_instantiate(): given instance (%s) is not "
"an instance of the rlm_sql module",
- data->sqlinst_name);
+ inst->sqlinst_name);
return -1;
}
/* save pointers to useful "objects" */
- data->sqlinst = (SQL_INST *) modinst->insthandle;
- data->db = (rlm_sql_module_t *) data->sqlinst->module;
-
- /* everything went ok, cleanup pool */
- *instance = data;
+ inst->sqlinst = (SQL_INST *) sqlinst->insthandle;
+ inst->db = (rlm_sql_module_t *) inst->sqlinst->module;
- return ((nvp_cleanup(data)) ? 0 : -1);
+ return ((nvp_cleanup(inst)) ? 0 : -1);
}
/* assign new IP address, if required */
weights_sum, used_sum, ip_start, ip_stop, connid;
long prio;
- rlm_sqlhpwippool_t *data = (rlm_sqlhpwippool_t *) instance;
+ rlm_sqlhpwippool_t *inst = (rlm_sqlhpwippool_t *) instance;
/* if IP is already there, then nothing to do */
vp = pairfind(request->reply->vps, PW_FRAMED_IP_ADDRESS, 0, TAG_ANY);
if (vp) {
- nvp_log(__LINE__, data, L_DBG,
+ nvp_log(__LINE__, inst, L_DBG,
"sqlhpwippool_postauth(): IP address "
"already in the reply packet - exiting");
return RLM_MODULE_NOOP;
vp = pairfind(request->reply->vps, ASN_IP_POOL_NAME, VENDORPEC_ASN, TAG_ANY);
if (vp) {
pname = vp->vp_strvalue;
- nvp_log(__LINE__, data, L_DBG,
+ nvp_log(__LINE__, inst, L_DBG,
"sqlhpwippool_postauth(): pool name = '%s'",
pname);
}
else {
- nvp_log(__LINE__, data, L_DBG,
+ nvp_log(__LINE__, inst, L_DBG,
"sqlhpwippool_postauth(): no IP pool name - exiting");
return RLM_MODULE_NOOP;
}
}
else {
nasip = 0;
- nvp_log(__LINE__, data, L_DBG,
+ nvp_log(__LINE__, inst, L_DBG,
"sqlhpwippool_postauth(): no NAS IP address in "
"the request packet - using \"0.0.0.0/0\" (any)");
}
/* get our database connection */
- sqlsock = sql_get_socket(data->sqlinst);
+ sqlsock = sql_get_socket(inst->sqlinst);
if (!sqlsock) {
- nvp_log(__LINE__, data, L_ERR,
+ nvp_log(__LINE__, inst, L_ERR,
"sqlhpwippool_postauth(): error while requesting an SQL socket");
return RLM_MODULE_FAIL;
}
/* get connection id as temporary unique integer */
- if (nvp_select(__LINE__, data, sqlsock, "SELECT CONNECTION_ID()") < 1) {
- nvp_log(__LINE__, data, L_ERR, "sqlhpwippool_postauth(): WTF ;-)!");
- nvp_select_finish(data, sqlsock);
- sql_release_socket(data->sqlinst, sqlsock);
+ if (nvp_select(__LINE__, inst, sqlsock, "SELECT CONNECTION_ID()") < 1) {
+ nvp_log(__LINE__, inst, L_ERR, "sqlhpwippool_postauth(): WTF ;-)!");
+ nvp_select_finish(inst, sqlsock);
+ sql_release_socket(inst->sqlinst, sqlsock);
return RLM_MODULE_FAIL;
}
connid = strtoul(sqlsock->row[0], (char **) NULL, 10);
- nvp_select_finish(data, sqlsock);
+ nvp_select_finish(inst, sqlsock);
/* synchronize with radacct db, if needed */
- if (++data->sincesync >= data->syncafter
+ if (++inst->sincesync >= inst->syncafter
#ifdef HAVE_PTHREAD_D
- && (pthread_mutex_trylock(&data->mutex)) == 0
+ && (pthread_mutex_trylock(&inst->mutex)) == 0
#endif
) {
int r;
- data->sincesync = 0;
+ inst->sincesync = 0;
- nvp_log(__LINE__, data, L_DBG,
+ nvp_log(__LINE__, inst, L_DBG,
"sqlhpwippool_postauth(): syncing with radacct table");
- r = (nvp_freeclosed(data, sqlsock) && nvp_syncfree(data, sqlsock));
+ r = (nvp_freeclosed(inst, sqlsock) && nvp_syncfree(inst, sqlsock));
#ifdef HAVE_PTHREAD_D
- pthread_mutex_unlock(&data->mutex);
+ pthread_mutex_unlock(&inst->mutex);
#endif
if (!r) {
- nvp_log(__LINE__, data, L_ERR,
+ nvp_log(__LINE__, inst, L_ERR,
"sqlhpwippool_postauth(): synchronization failed");
- sql_release_socket(data->sqlinst, sqlsock);
+ sql_release_socket(inst->sqlinst, sqlsock);
return RLM_MODULE_FAIL;
}
}
for (s_gid = 0; s_gid < RLM_NETVIM_MAX_ROWS && !(ip.s_addr); s_gid++) {
- nvp_log(__LINE__, data, L_DBG,
+ nvp_log(__LINE__, inst, L_DBG,
"sqlhpwippool_postauth(): selecting gid on position %lu",
s_gid);
/* find the most specific group which NAS belongs to */
- switch (nvp_select(__LINE__, data, sqlsock,
+ switch (nvp_select(__LINE__, inst, sqlsock,
"SELECT `host_groups`.`gid` "
"FROM "
"`%s`.`host_groups`, "
"%lu BETWEEN `gid_ip`.`ip_start` AND `gid_ip`.`ip_stop` "
"ORDER BY (`gid_ip`.`ip_stop` - `gid_ip`.`ip_start`) ASC "
"LIMIT %lu, 1",
- data->db_name, nasip, s_gid)) {
+ inst->db_name, nasip, s_gid)) {
case -1:
- nvp_log(__LINE__, data, L_ERR,
+ nvp_log(__LINE__, inst, L_ERR,
"sqlhpwippool_postauth(): couldn't find "
"any more matching host groups");
goto end_gid; /* exit the main loop */
case 0:
- sql_release_socket(data->sqlinst, sqlsock);
+ sql_release_socket(inst->sqlinst, sqlsock);
return RLM_MODULE_FAIL;
}
/* store the group ID and free memory occupied by results */
gid = strtoul(sqlsock->row[0], (char **) NULL, 10);
- nvp_select_finish(data, sqlsock);
+ nvp_select_finish(inst, sqlsock);
for (s_prio = 0; s_prio < RLM_NETVIM_MAX_ROWS && !(ip.s_addr); s_prio++) {
- nvp_log(__LINE__, data, L_DBG,
+ nvp_log(__LINE__, inst, L_DBG,
"sqlhpwippool_postauth(): selecting prio on position %lu",
s_prio);
/* prepare to search for best fit pool */
- switch (nvp_select(__LINE__, data, sqlsock,
+ switch (nvp_select(__LINE__, inst, sqlsock,
"SELECT "
"`ip_pools`.`prio`, "
"SUM(`ip_pools`.`weight`) AS `weights_sum`, "
"GROUP BY `prio` "
"ORDER BY `prio` ASC "
"LIMIT %lu, 1",
- data->db_name, gid, pname, s_prio)) {
+ inst->db_name, gid, pname, s_prio)) {
case -1:
- nvp_log(__LINE__, data, L_DBG,
+ nvp_log(__LINE__, inst, L_DBG,
"sqlhpwippool_postauth(): couldn't find "
"any more matching pools for gid = %u",
gid);
goto end_prio; /* select next gid */
case 0:
- sql_release_socket(data->sqlinst, sqlsock);
+ sql_release_socket(inst->sqlinst, sqlsock);
return RLM_MODULE_FAIL;
}
used_sum = strtoul(sqlsock->row[2], (char **) NULL, 10);
/* free memory */
- nvp_select_finish(data, sqlsock);
+ nvp_select_finish(inst, sqlsock);
for (s_pid = 0; s_pid < RLM_NETVIM_MAX_ROWS && !(ip.s_addr); s_pid++) {
- nvp_log(__LINE__, data, L_DBG,
+ nvp_log(__LINE__, inst, L_DBG,
"sqlhpwippool_postauth(): selecting PID on position %lu",
s_pid);
/* search for best fit pool */
- switch (nvp_select(__LINE__, data, sqlsock,
+ switch (nvp_select(__LINE__, inst, sqlsock,
"SELECT "
"`ip_pools`.`pid`, "
"`ip_pools`.`ip_start`, "
"`prio` = %ld "
"ORDER BY (`weight`/%lu.0000 - (`total` - `free`)/%lu) DESC "
"LIMIT %lu, 1",
- data->db_name, gid, pname, prio,
+ inst->db_name, gid, pname, prio,
weights_sum, used_sum, s_pid)) {
case -1:
- nvp_log(__LINE__, data, L_DBG,
+ nvp_log(__LINE__, inst, L_DBG,
"sqlhpwippool_postauth(): couldn't find any more "
"matching pools of prio = %ld for gid = %lu",
prio, gid);
goto end_pid; /* select next prio */
case 0:
- sql_release_socket(data->sqlinst, sqlsock);
+ sql_release_socket(inst->sqlinst, sqlsock);
return RLM_MODULE_FAIL;
}
- /* store the data and free memory occupied by results */
+ /* store the inst and free memory occupied by results */
pid = strtoul(sqlsock->row[0], (char **) NULL, 10);
ip_start = strtoul(sqlsock->row[1], (char **) NULL, 10);
ip_stop = strtoul(sqlsock->row[2], (char **) NULL, 10);
- nvp_select_finish(data, sqlsock);
+ nvp_select_finish(inst, sqlsock);
/* reserve an IP address */
- if (!nvp_query(__LINE__, data, sqlsock,
+ if (!nvp_query(__LINE__, inst, sqlsock,
"UPDATE `%s`.`ips` "
"SET "
"`pid` = %lu, "
") "
"ORDER BY RAND() "
"LIMIT 1",
- data->db_name, pid, connid, data->freeafter, ip_start, ip_stop)) {
- sql_release_socket(data->sqlinst, sqlsock);
+ inst->db_name, pid, connid, inst->freeafter, ip_start, ip_stop)) {
+ sql_release_socket(inst->sqlinst, sqlsock);
return RLM_MODULE_FAIL;
}
else {
- nvp_finish(data, sqlsock);
+ nvp_finish(inst, sqlsock);
}
/* select assigned IP address */
- switch (nvp_select(__LINE__, data, sqlsock,
+ switch (nvp_select(__LINE__, inst, sqlsock,
"SELECT `ip` "
"FROM `%s`.`ips` "
"WHERE `rsv_by` = '" RLM_NETVIM_TMP_PREFIX "%lu' "
"ORDER BY `rsv_since` DESC "
"LIMIT 1",
- data->db_name, connid)) {
+ inst->db_name, connid)) {
case -1:
- nvp_log(__LINE__, data, L_ERR,
+ nvp_log(__LINE__, inst, L_ERR,
"sqlhpwippool_postauth(): couldn't reserve an IP address "
"from pool of pid = %lu (prio = %ld, gid = %lu)",
pid, prio, gid);
continue; /* select next pid */
case 0:
- sql_release_socket(data->sqlinst, sqlsock);
+ sql_release_socket(inst->sqlinst, sqlsock);
return RLM_MODULE_FAIL;
}
/* update free IPs count */
- if (!nvp_query(__LINE__, data, sqlsock,
+ if (!nvp_query(__LINE__, inst, sqlsock,
"UPDATE `%s`.`ip_pools` "
"SET "
"`free` = `free` - 1 "
"WHERE "
"`pid` = %lu "
"LIMIT 1",
- data->db_name, pid)) {
- sql_release_socket(data->sqlinst, sqlsock);
+ inst->db_name, pid)) {
+ sql_release_socket(inst->sqlinst, sqlsock);
return RLM_MODULE_FAIL;
}
else {
- nvp_finish(data, sqlsock);
+ nvp_finish(inst, sqlsock);
}
/* get assigned IP and free memory */
ip.s_addr = htonl(strtoul(sqlsock->row[0], (char **) NULL, 10));
- nvp_select_finish(data, sqlsock);
+ nvp_select_finish(inst, sqlsock);
} /* pid */
end_pid: continue; /* stupid */
} /* prio */
end_gid:
/* release SQL socket */
- sql_release_socket(data->sqlinst, sqlsock);
+ sql_release_socket(inst->sqlinst, sqlsock);
/* no free IP address found */
if (!ip.s_addr) {
- nvp_log(__LINE__, data, L_INFO,
+ nvp_log(__LINE__, inst, L_INFO,
"sqlhpwippool_postauth(): no free IP address found!");
- if (data->nofreefail) {
- nvp_log(__LINE__, data, L_DBG, "sqlhpwippool_postauth(): rejecting user");
+ if (inst->nofreefail) {
+ nvp_log(__LINE__, inst, L_DBG, "sqlhpwippool_postauth(): rejecting user");
return RLM_MODULE_REJECT;
}
else {
- nvp_log(__LINE__, data, L_DBG, "sqlhpwippool_postauth(): exiting");
+ nvp_log(__LINE__, inst, L_DBG, "sqlhpwippool_postauth(): exiting");
return RLM_MODULE_NOOP;
}
}
PW_FRAMED_IP_ADDRESS, 0);
vp->vp_ipaddr = ip.s_addr;
- nvp_log(__LINE__, data, L_DBG, "sqlhpwippool_postauth(): returning %s",
+ nvp_log(__LINE__, inst, L_DBG, "sqlhpwippool_postauth(): returning %s",
inet_ntoa(ip));
return RLM_MODULE_OK;
}
uint32_t framedip = 0; /* client's IP, host byte order */
uint32_t acct_type;
- rlm_sqlhpwippool_t *data = (rlm_sqlhpwippool_t *) instance;
+ rlm_sqlhpwippool_t *inst = (rlm_sqlhpwippool_t *) instance;
/* if no unique session ID, don't even try */
vp = pairfind(request->packet->vps, PW_ACCT_UNIQUE_SESSION_ID, 0, TAG_ANY);
sessid = vp->vp_strvalue;
}
else {
- nvp_log(__LINE__, data, L_ERR,
+ nvp_log(__LINE__, inst, L_ERR,
"sqlhpwippool_accounting(): unique session ID not found");
return RLM_MODULE_FAIL;
}
acct_type = vp->vp_integer;
}
else {
- nvp_log(__LINE__, data, L_ERR, "sqlhpwippool_accounting(): "
+ nvp_log(__LINE__, inst, L_ERR, "sqlhpwippool_accounting(): "
"couldn't find type of accounting packet");
return RLM_MODULE_FAIL;
}
}
/* connect to database */
- sqlsock = sql_get_socket(data->sqlinst);
+ sqlsock = sql_get_socket(inst->sqlinst);
if (!sqlsock) {
- nvp_log(__LINE__, data, L_ERR,
+ nvp_log(__LINE__, inst, L_ERR,
"sqlhpwippool_accounting(): couldn't connect to database");
return RLM_MODULE_FAIL;
}
case PW_STATUS_ALIVE:
vp = pairfind(request->packet->vps, PW_FRAMED_IP_ADDRESS, 0, TAG_ANY);
if (!vp) {
- nvp_log(__LINE__, data, L_ERR, "sqlhpwippool_accounting(): no framed IP");
- sql_release_socket(data->sqlinst, sqlsock);
+ nvp_log(__LINE__, inst, L_ERR, "sqlhpwippool_accounting(): no framed IP");
+ sql_release_socket(inst->sqlinst, sqlsock);
return RLM_MODULE_FAIL;
}
framedip = ntohl(vp->vp_ipaddr);
- if (!nvp_query(__LINE__, data, sqlsock,
+ if (!nvp_query(__LINE__, inst, sqlsock,
"UPDATE `%s`.`ips` "
"SET "
"`rsv_until` = 0, "
"`rsv_by` = '%s' "
"WHERE `ip` = %lu",
- data->db_name, sessid, framedip)) {
- sql_release_socket(data->sqlinst, sqlsock);
+ inst->db_name, sessid, framedip)) {
+ sql_release_socket(inst->sqlinst, sqlsock);
return RLM_MODULE_FAIL;
}
- nvp_finish(data, sqlsock);
+ nvp_finish(inst, sqlsock);
break;
case PW_STATUS_STOP:
- if (!nvp_query(__LINE__, data, sqlsock,
+ if (!nvp_query(__LINE__, inst, sqlsock,
"UPDATE `%s`.`ips`, `%1$s`.`ip_pools` "
"SET "
"`ips`.`rsv_until` = NOW() + INTERVAL %u SECOND, "
"WHERE "
"`ips`.`rsv_by` = '%s' AND "
"`ips`.`ip` BETWEEN `ip_pools`.`ip_start` AND `ip_pools`.`ip_stop`",
- data->db_name, data->freeafter, sessid)) {
- sql_release_socket(data->sqlinst, sqlsock);
+ inst->db_name, inst->freeafter, sessid)) {
+ sql_release_socket(inst->sqlinst, sqlsock);
return RLM_MODULE_FAIL;
}
- nvp_finish(data, sqlsock);
+ nvp_finish(inst, sqlsock);
break;
case PW_STATUS_ACCOUNTING_OFF:
case PW_STATUS_ACCOUNTING_ON:
vp = pairfind(request->packet->vps, PW_NAS_IP_ADDRESS, 0, TAG_ANY);
if (!vp) {
- nvp_log(__LINE__, data, L_ERR, "sqlhpwippool_accounting(): no NAS IP");
- sql_release_socket(data->sqlinst, sqlsock);
+ nvp_log(__LINE__, inst, L_ERR, "sqlhpwippool_accounting(): no NAS IP");
+ sql_release_socket(inst->sqlinst, sqlsock);
return RLM_MODULE_FAIL;
}
nasip.s_addr = vp->vp_ipaddr;
strlcpy(nasipstr, inet_ntoa(nasip), sizeof(nasipstr));
- if (!nvp_query(__LINE__, data, sqlsock,
+ if (!nvp_query(__LINE__, inst, sqlsock,
"UPDATE `%s`.`ips`, `radacct` "
"SET `ips`.`rsv_until` = NOW() + INTERVAL %u SECOND "
"WHERE "
"`radacct`.`nasipaddress` = '%s' AND "
"`ips`.`rsv_by` = `radacct`.`acctuniqueid`",
- data->db_name, data->freeafter, nasipstr)) {
- sql_release_socket(data->sqlinst, sqlsock);
+ inst->db_name, inst->freeafter, nasipstr)) {
+ sql_release_socket(inst->sqlinst, sqlsock);
return RLM_MODULE_FAIL;
}
- nvp_finish(data, sqlsock);
+ nvp_finish(inst, sqlsock);
break;
}
- sql_release_socket(data->sqlinst, sqlsock);
+ sql_release_socket(inst->sqlinst, sqlsock);
return RLM_MODULE_OK;
}
"sqlhpwippool", /* name */
RLM_TYPE_THREAD_SAFE, /* type */
sqlhpwippool_instantiate, /* instantiation */
- sqlhpwippool_detach, /* detach */
+ NULL, /* detach */
{
NULL, /* authentication */
NULL, /* authorization */
return retval;
}
-static int sqlippool_detach(void *instance)
-{
- free(instance);
- return 0;
-}
-
#define IS_EMPTY(_x) (!_x ||!*_x)
/*
* that must be referenced in later calls, store a handle to it
* in *instance otherwise put a null pointer there.
*/
-static int sqlippool_instantiate(CONF_SECTION * conf, void ** instance)
+static int sqlippool_instantiate(CONF_SECTION *conf, void **instance)
{
- module_instance_t *modinst;
- rlm_sqlippool_t * data;
+ module_instance_t *sqlinst;
+ rlm_sqlippool_t *inst;
const char * pool_name = NULL;
/*
* Set up a storage area for instance data
*/
- data = rad_malloc(sizeof(*data));
- memset(data, 0, sizeof(*data));
+ *instance = inst = talloc_zero(conf, rlm_sqlippool_t);
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
- if (cf_section_parse(conf, data, module_config) < 0) {
- free(data);
+ if (cf_section_parse(conf, inst, module_config) < 0) {
return -1;
}
- if (IS_EMPTY(data->sql_instance_name)) {
+ if (IS_EMPTY(inst->sql_instance_name)) {
radlog(L_ERR, "rlm_sqlippool: the 'sql-instance-name' variable must be set.");
- sqlippool_detach(data);
return -1;
}
* Check that all the queries are in place
*/
- if (IS_EMPTY(data->allocate_clear)) {
+ if (IS_EMPTY(inst->allocate_clear)) {
radlog(L_ERR, "rlm_sqlippool: the 'allocate-clear' statement must be set.");
- sqlippool_detach(data);
return -1;
}
- if (IS_EMPTY(data->allocate_find)) {
+ if (IS_EMPTY(inst->allocate_find)) {
radlog(L_ERR, "rlm_sqlippool: the 'allocate-find' statement must be set.");
- sqlippool_detach(data);
return -1;
}
- if (IS_EMPTY(data->allocate_update)) {
+ if (IS_EMPTY(inst->allocate_update)) {
radlog(L_ERR, "rlm_sqlippool: the 'allocate-update' statement must be set.");
- sqlippool_detach(data);
return -1;
}
- if (IS_EMPTY(data->start_update)) {
+ if (IS_EMPTY(inst->start_update)) {
radlog(L_ERR, "rlm_sqlippool: the 'start-update' statement must be set.");
- sqlippool_detach(data);
return -1;
}
- if (IS_EMPTY(data->alive_update)) {
+ if (IS_EMPTY(inst->alive_update)) {
radlog(L_ERR, "rlm_sqlippool: the 'alive-update' statement must be set.");
- sqlippool_detach(data);
return -1;
}
- if (IS_EMPTY(data->stop_clear)) {
+ if (IS_EMPTY(inst->stop_clear)) {
radlog(L_ERR, "rlm_sqlippool: the 'stop-clear' statement must be set.");
- sqlippool_detach(data);
return -1;
}
- if (IS_EMPTY(data->on_clear)) {
+ if (IS_EMPTY(inst->on_clear)) {
radlog(L_ERR, "rlm_sqlippool: the 'on-clear' statement must be set.");
- sqlippool_detach(data);
return -1;
}
- if (IS_EMPTY(data->off_clear)) {
+ if (IS_EMPTY(inst->off_clear)) {
radlog(L_ERR, "rlm_sqlippool: the 'off-clear' statement must be set.");
- sqlippool_detach(data);
return -1;
}
pool_name = cf_section_name2(conf);
if (pool_name != NULL)
- data->pool_name = strdup(pool_name);
+ inst->pool_name = talloc_strdup(inst, pool_name);
else
- data->pool_name = strdup("ippool");
+ inst->pool_name = talloc_strdup(inst, "ippool");
- modinst = find_module_instance(cf_section_find("modules"),
- data->sql_instance_name, 1);
- if (!modinst) {
- radlog(L_ERR, "sqlippool_instantiate: failed to find sql instance named %s", data->sql_instance_name);
- sqlippool_detach(data);
+ sqlinst = find_module_instance(cf_section_find("modules"),
+ inst->sql_instance_name, 1);
+ if (!sqlinst) {
+ radlog(L_ERR, "sqlippool_instantiate: failed to find sql instance named %s", inst->sql_instance_name);
return -1;
}
- if (strcmp(modinst->entry->name, "rlm_sql") != 0) {
+ if (strcmp(sqlinst->entry->name, "rlm_sql") != 0) {
radlog(L_ERR, "sqlippool_instantiate: Module \"%s\""
" is not an instance of the rlm_sql module",
- data->sql_instance_name);
- sqlippool_detach(data);
+ inst->sql_instance_name);
return -1;
}
- data->sql_inst = (SQL_INST *) modinst->insthandle;
-
- *instance = data;
+ inst->sql_inst = (SQL_INST *) sqlinst->insthandle;
return 0;
}
*/
static rlm_rcode_t sqlippool_postauth(void *instance, REQUEST * request)
{
- rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
+ rlm_sqlippool_t * inst = (rlm_sqlippool_t *) instance;
char allocation[MAX_STRING_LEN];
int allocation_len;
uint32_t ip_allocation;
*/
if (pairfind(request->reply->vps, PW_FRAMED_IP_ADDRESS, 0, TAG_ANY) != NULL) {
/* We already have a Framed-IP-Address */
- radius_xlat(logstr, sizeof(logstr), data->log_exists,
+ radius_xlat(logstr, sizeof(logstr), inst->log_exists,
request, NULL, NULL);
RDEBUG("Framed-IP-Address already exists");
if (pairfind(request->config_items, PW_POOL_NAME, 0, TAG_ANY) == NULL) {
RDEBUG("No Pool-Name defined.");
- radius_xlat(logstr, sizeof(logstr), data->log_nopool,
+ radius_xlat(logstr, sizeof(logstr), inst->log_nopool,
request, NULL, NULL);
return do_logging(logstr, RLM_MODULE_NOOP);
}
- sqlsocket = data->sql_inst->sql_get_socket(data->sql_inst);
+ sqlsocket = inst->sql_inst->sql_get_socket(inst->sql_inst);
if (sqlsocket == NULL) {
RDEBUG("cannot allocate sql connection");
return RLM_MODULE_FAIL;
}
- if (data->sql_inst->sql_set_user(data->sql_inst, request, NULL) < 0) {
+ if (inst->sql_inst->sql_set_user(inst->sql_inst, request, NULL) < 0) {
return RLM_MODULE_FAIL;
}
/*
* BEGIN
*/
- sqlippool_command(data->allocate_begin, sqlsocket, data, request,
+ sqlippool_command(inst->allocate_begin, sqlsocket, inst, request,
(char *) NULL, 0);
/*
* CLEAR
*/
- sqlippool_command(data->allocate_clear, sqlsocket, data, request,
+ sqlippool_command(inst->allocate_clear, sqlsocket, inst, request,
(char *) NULL, 0);
/*
* FIND
*/
allocation_len = sqlippool_query1(allocation, sizeof(allocation),
- data->allocate_find, sqlsocket,
- data, request, (char *) NULL, 0);
+ inst->allocate_find, sqlsocket,
+ inst, request, (char *) NULL, 0);
/*
* Nothing found...
/*
* COMMIT
*/
- sqlippool_command(data->allocate_commit, sqlsocket, instance,
+ sqlippool_command(inst->allocate_commit, sqlsocket, instance,
request, (char *) NULL, 0);
/*
* Should we perform pool-check ?
*/
- if (data->pool_check && *data->pool_check) {
+ if (inst->pool_check && *inst->pool_check) {
/*
* Ok, so the allocate-find query found nothing ...
* Let's check if the pool exists at all
*/
allocation_len = sqlippool_query1(allocation, sizeof(allocation),
- data->pool_check, sqlsocket, data, request,
+ inst->pool_check, sqlsocket, inst, request,
(char *) NULL, 0);
- data->sql_inst->sql_release_socket(data->sql_inst, sqlsocket);
+ inst->sql_inst->sql_release_socket(inst->sql_inst, sqlsocket);
if (allocation_len) {
* NOTFOUND
*/
RDEBUG("pool appears to be full");
- radius_xlat(logstr, sizeof(logstr), data->log_failed, request, NULL, NULL);
+ radius_xlat(logstr, sizeof(logstr), inst->log_failed, request, NULL, NULL);
return do_logging(logstr, RLM_MODULE_NOTFOUND);
}
}
- data->sql_inst->sql_release_socket(data->sql_inst, sqlsocket);
+ inst->sql_inst->sql_release_socket(inst->sql_inst, sqlsocket);
RDEBUG("IP address could not be allocated.");
- radius_xlat(logstr, sizeof(logstr), data->log_failed,
+ radius_xlat(logstr, sizeof(logstr), inst->log_failed,
request, NULL, NULL);
return do_logging(logstr, RLM_MODULE_NOOP);
/*
* COMMIT
*/
- sqlippool_command(data->allocate_commit, sqlsocket, instance,
+ sqlippool_command(inst->allocate_commit, sqlsocket, instance,
request, (char *) NULL, 0);
- RDEBUG("Invalid IP number [%s] returned from database query.", allocation);
- data->sql_inst->sql_release_socket(data->sql_inst, sqlsocket);
- radius_xlat(logstr, sizeof(logstr), data->log_failed,
+ RDEBUG("Invalid IP number [%s] returned from instbase query.", allocation);
+ inst->sql_inst->sql_release_socket(inst->sql_inst, sqlsocket);
+ radius_xlat(logstr, sizeof(logstr), inst->log_failed,
request, NULL, NULL);
return do_logging(logstr, RLM_MODULE_NOOP);
/*
* UPDATE
*/
- sqlippool_command(data->allocate_update, sqlsocket, data, request,
+ sqlippool_command(inst->allocate_update, sqlsocket, inst, request,
allocation, allocation_len);
RDEBUG("Allocated IP %s [%08x]", allocation, ip_allocation);
/*
* COMMIT
*/
- sqlippool_command(data->allocate_commit, sqlsocket, data, request,
+ sqlippool_command(inst->allocate_commit, sqlsocket, inst, request,
(char *) NULL, 0);
- data->sql_inst->sql_release_socket(data->sql_inst, sqlsocket);
- radius_xlat(logstr, sizeof(logstr), data->log_success, request, NULL, NULL);
+ inst->sql_inst->sql_release_socket(inst->sql_inst, sqlsocket);
+ radius_xlat(logstr, sizeof(logstr), inst->log_success, request, NULL, NULL);
return do_logging(logstr, RLM_MODULE_OK);
}
static int sqlippool_accounting_start(SQLSOCK * sqlsocket,
- rlm_sqlippool_t *data, REQUEST *request)
+ rlm_sqlippool_t *inst, REQUEST *request)
{
/*
* BEGIN
*/
- sqlippool_command(data->start_begin, sqlsocket, data, request,
+ sqlippool_command(inst->start_begin, sqlsocket, inst, request,
(char *) NULL, 0);
/*
* UPDATE
*/
- sqlippool_command(data->start_update, sqlsocket, data, request,
+ sqlippool_command(inst->start_update, sqlsocket, inst, request,
(char *) NULL, 0);
/*
* COMMIT
*/
- sqlippool_command(data->start_commit, sqlsocket, data, request,
+ sqlippool_command(inst->start_commit, sqlsocket, inst, request,
(char *) NULL, 0);
return RLM_MODULE_OK;
}
static int sqlippool_accounting_alive(SQLSOCK * sqlsocket,
- rlm_sqlippool_t *data, REQUEST *request)
+ rlm_sqlippool_t *inst, REQUEST *request)
{
/*
* BEGIN
*/
- sqlippool_command(data->alive_begin, sqlsocket, data, request,
+ sqlippool_command(inst->alive_begin, sqlsocket, inst, request,
(char *) NULL, 0);
/*
* UPDATE
*/
- sqlippool_command(data->alive_update, sqlsocket, data, request,
+ sqlippool_command(inst->alive_update, sqlsocket, inst, request,
(char *) NULL, 0);
/*
* COMMIT
*/
- sqlippool_command(data->alive_commit, sqlsocket, data, request,
+ sqlippool_command(inst->alive_commit, sqlsocket, inst, request,
(char *) NULL, 0);
return RLM_MODULE_OK;
}
static int sqlippool_accounting_stop(SQLSOCK * sqlsocket,
- rlm_sqlippool_t *data, REQUEST *request)
+ rlm_sqlippool_t *inst, REQUEST *request)
{
char logstr[MAX_STRING_LEN];
/*
* BEGIN
*/
- sqlippool_command(data->stop_begin, sqlsocket, data, request,
+ sqlippool_command(inst->stop_begin, sqlsocket, inst, request,
(char *) NULL, 0);
/*
* CLEAR
*/
- sqlippool_command(data->stop_clear, sqlsocket, data, request,
+ sqlippool_command(inst->stop_clear, sqlsocket, inst, request,
(char *) NULL, 0);
/*
* COMMIT
*/
- sqlippool_command(data->stop_commit, sqlsocket, data, request,
+ sqlippool_command(inst->stop_commit, sqlsocket, inst, request,
(char *) NULL, 0);
- radius_xlat(logstr, sizeof(logstr), data->log_clear, request, NULL, NULL);
+ radius_xlat(logstr, sizeof(logstr), inst->log_clear, request, NULL, NULL);
return do_logging(logstr, RLM_MODULE_OK);
}
static int sqlippool_accounting_on(SQLSOCK * sqlsocket,
- rlm_sqlippool_t *data, REQUEST *request)
+ rlm_sqlippool_t *inst, REQUEST *request)
{
/*
* BEGIN
*/
- sqlippool_command(data->on_begin, sqlsocket, data, request,
+ sqlippool_command(inst->on_begin, sqlsocket, inst, request,
(char *) NULL, 0);
/*
* CLEAR
*/
- sqlippool_command(data->on_clear, sqlsocket, data, request,
+ sqlippool_command(inst->on_clear, sqlsocket, inst, request,
(char *) NULL, 0);
/*
* COMMIT
*/
- sqlippool_command(data->on_commit, sqlsocket, data, request,
+ sqlippool_command(inst->on_commit, sqlsocket, inst, request,
(char *) NULL, 0);
return RLM_MODULE_OK;
}
static int sqlippool_accounting_off(SQLSOCK * sqlsocket,
- rlm_sqlippool_t *data, REQUEST *request)
+ rlm_sqlippool_t *inst, REQUEST *request)
{
/*
* BEGIN
*/
- sqlippool_command(data->off_begin, sqlsocket, data, request,
+ sqlippool_command(inst->off_begin, sqlsocket, inst, request,
(char *) NULL, 0);
/*
* CLEAR
*/
- sqlippool_command(data->off_clear, sqlsocket, data, request,
+ sqlippool_command(inst->off_clear, sqlsocket, inst, request,
(char *) NULL, 0);
/*
* COMMIT
*/
- sqlippool_command(data->off_commit, sqlsocket, data, request,
+ sqlippool_command(inst->off_commit, sqlsocket, inst, request,
(char *) NULL, 0);
return RLM_MODULE_OK;
int rcode;
VALUE_PAIR * vp;
int acct_status_type;
- rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
+ rlm_sqlippool_t * inst = (rlm_sqlippool_t *) instance;
SQLSOCK * sqlsocket;
vp = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE, 0, TAG_ANY);
return RLM_MODULE_NOOP;
}
- sqlsocket = data->sql_inst->sql_get_socket(data->sql_inst);
+ sqlsocket = inst->sql_inst->sql_get_socket(inst->sql_inst);
if (sqlsocket == NULL) {
RDEBUG("cannot allocate sql connection");
return RLM_MODULE_NOOP;
}
- if (data->sql_inst->sql_set_user(data->sql_inst, request, NULL) < 0) {
+ if (inst->sql_inst->sql_set_user(inst->sql_inst, request, NULL) < 0) {
return RLM_MODULE_FAIL;
}
switch (acct_status_type) {
case PW_STATUS_START:
- rcode = sqlippool_accounting_start(sqlsocket, data, request);
+ rcode = sqlippool_accounting_start(sqlsocket, inst, request);
break;
case PW_STATUS_ALIVE:
- rcode = sqlippool_accounting_alive(sqlsocket, data, request);
+ rcode = sqlippool_accounting_alive(sqlsocket, inst, request);
break;
case PW_STATUS_STOP:
- rcode = sqlippool_accounting_stop(sqlsocket, data, request);
+ rcode = sqlippool_accounting_stop(sqlsocket, inst, request);
break;
case PW_STATUS_ACCOUNTING_ON:
- rcode = sqlippool_accounting_on(sqlsocket, data, request);
+ rcode = sqlippool_accounting_on(sqlsocket, inst, request);
break;
case PW_STATUS_ACCOUNTING_OFF:
- rcode = sqlippool_accounting_off(sqlsocket, data, request);
+ rcode = sqlippool_accounting_off(sqlsocket, inst, request);
break;
}
- data->sql_inst->sql_release_socket(data->sql_inst, sqlsocket);
+ inst->sql_inst->sql_release_socket(inst->sql_inst, sqlsocket);
return rcode;
}
"SQL IP Pool",
RLM_TYPE_THREAD_SAFE, /* type */
sqlippool_instantiate, /* instantiation */
- sqlippool_detach, /* detach */
+ NULL, /* detach */
{
NULL, /* authentication */
NULL, /* authorization */
/*
* Detach.
*/
-static int unix_detach(void *instance)
+static int unix_detach(UNUSED void *instance)
{
#define inst ((struct unix_instance *)instance)
paircompare_unregister(PW_GROUP_NAME, groupcmp);
#endif
#undef inst
- free(instance);
return 0;
}
/*
* Allocate room for the instance.
*/
- inst = *instance = rad_malloc(sizeof(*inst));
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, struct unix_instance);
+ if (!inst) return -1;
/*
* Parse the configuration, failing if we can't do so.
*/
if (cf_section_parse(conf, inst, module_config) < 0) {
- unix_detach(inst);
return -1;
}
paircompare_register(PW_GROUP_NAME, PW_USER_NAME, groupcmp, NULL);
#endif
-#undef inst
-
return 0;
}
{ NULL, -1, 0, NULL, NULL } /* end the list */
};
-
-/*
- * Only free memory we allocated. The strings allocated via
- * cf_section_parse() do not need to be freed.
- */
-static int wimax_detach(void *instance)
-{
- free(instance);
- return 0;
-}
-
/*
* Do any per-module initialization that is separate to each
* configured instance of the module. e.g. set up connections
/*
* Set up a storage area for instance data
*/
- inst = rad_malloc(sizeof(*inst));
- if (!inst) {
- return -1;
- }
- memset(inst, 0, sizeof(*inst));
+ *instance = inst = talloc_zero(conf, rlm_wimax_t);
+ if (!inst) return -1;
/*
* If the configuration parameters can't be parsed, then
* fail.
*/
if (cf_section_parse(conf, inst, module_config) < 0) {
- wimax_detach(inst);
return -1;
}
- *instance = inst;
-
return 0;
}
"wimax",
RLM_TYPE_THREAD_SAFE, /* type */
wimax_instantiate, /* instantiation */
- wimax_detach, /* detach */
+ NULL, /* detach */
{
NULL, /* authentication */
wimax_authorize, /* authorization */