*
* Inform the remote LDAP server that we no longer want responses to specific queries.
*
+ * @param[in] el For timer mangement.
* @param[in] tconn The trunk connection handle
* @param[in] conn The specific connection queries will be cancelled on
* @param[in] uctx Context provided to fr_trunk_alloc
*/
-static void ldap_request_cancel_mux(fr_trunk_connection_t *tconn, fr_connection_t *conn, UNUSED void *uctx)
+static void ldap_request_cancel_mux(UNUSED fr_event_list_t *el, fr_trunk_connection_t *tconn,
+ fr_connection_t *conn, UNUSED void *uctx)
{
fr_trunk_request_t *treq;
fr_ldap_connection_t *ldap_conn = talloc_get_type_abort(conn->h, fr_ldap_connection_t);
* only gather those which are complete before either following a referral or passing
* the head of the resulting chain of messages back.
*
+ * @param[in] el To insert timers into.
* @param[in] tconn Trunk connection associated with these results.
* @param[in] conn Connection handle for these results.
* @param[in] uctx Thread specific trunk structure - contains tree of pending queries.
*/
-static void ldap_trunk_request_demux(fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx)
+static void ldap_trunk_request_demux(fr_event_list_t *el, fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx)
{
fr_ldap_connection_t *ldap_conn = talloc_get_type_abort(conn->h, fr_ldap_connection_t);
fr_ldap_thread_trunk_t *ttrunk = talloc_get_type_abort(uctx, fr_ldap_thread_trunk_t);
/*
* Reset the idle timeout event
*/
- fr_event_timer_in(ttrunk, ttrunk->t->el, &ttrunk->ev,
+ fr_event_timer_in(ttrunk, el, &ttrunk->ev,
ttrunk->t->config->idle_timeout, _ldap_trunk_idle_timeout, ttrunk);
do {
return -1;
}
- if (dl_inst->module->common->detach) dl_inst->module->common->detach(dl_inst->data);
+ if (dl_inst->module->common->detach) dl_inst->module->common->detach(&(module_detach_ctx_t){ .inst = dl_inst });
return 0;
}
# define DL_EXTENSION ".so"
#endif
+typedef struct dl_module_instance_s dl_module_inst_t;
+
/** Stop people using different module/library/server versions together
*
*/
typedef struct dl_module_loader_s dl_module_loader_t;
+typedef struct {
+ dl_module_inst_t const *inst;
+} module_detach_ctx_t;
+
/** Module detach callback
*
* Is called just before the server exits, and after re-instantiation on HUP,
* Detach should close all handles associated with the module instance, and
* free any memory allocated during instantiate.
*
- * @param[in] instance to free.
+ * @param[in] inst to free.
* @return
* - 0 on success.
* - -1 if detach failed.
*/
-typedef int (*module_detach_t)(void *instance);
+typedef int (*module_detach_t)(module_detach_ctx_t const *inst);
/** Callback to call when a module is first loaded
*
*
* Used to pass data back from dl_module_instance_parse_func
*/
-typedef struct dl_module_instance_s dl_module_inst_t;
struct dl_module_instance_s {
char const * _CONST name; //!< Instance name.
dl_module_t const * _CONST module; //!< Module
* and should be removed along with
* starting the instance number at 0
*/
- if (ti->mi && ti->mi->module->thread_detach) ti->mi->module->thread_detach(ti->el, ti->data);
+ if (ti->mi && ti->mi->module->thread_detach) {
+ ti->mi->module->thread_detach(&(module_thread_inst_ctx_t const ){
+ .inst = ti->mi->dl_inst,
+ .thread = ti->data,
+ .el = ti->el
+ });
+ }
talloc_free(ti);
}
DEBUG4("Worker alloced %s thread instance data (%p/%p)", ti->mi->module->name, ti, ti->data);
if (mi->module->thread_instantiate) {
- if (mi->module->thread_instantiate(mi->dl_inst->conf, mi->dl_inst->data, el, ti->data) < 0) {
+ if (mi->module->thread_instantiate(&(module_thread_inst_ctx_t){
+ .inst = mi->dl_inst,
+ .thread = ti->data,
+ .el = el
+ }) < 0) {
PERROR("Thread instantiation failed for module \"%s\"", mi->name);
TALLOC_FREE(module_thread_inst_array);
return -1;
/*
* Call the module's instantiation routine.
*/
- if ((mi->module->instantiate)(mi->dl_inst->data, mi->dl_inst->conf) < 0) {
+ if ((mi->module->instantiate)(&(module_inst_ctx_t){
+ .inst = mi->dl_inst
+ }) < 0) {
cf_log_err(mi->dl_inst->conf, "Instantiation failed for module \"%s\"",
mi->name);
if (mi->module->bootstrap) {
cf_log_debug(mi->dl_inst->conf, "Bootstrapping module \"%s\"", mi->name);
- if ((mi->module->bootstrap)(mi->dl_inst->data, cs) < 0) {
+ if ((mi->module->bootstrap)(&(module_inst_ctx_t){
+ .inst = mi->dl_inst,
+ }) < 0) {
cf_log_err(cs, "Bootstrap failed for module \"%s\"", mi->name);
talloc_free(mi);
return NULL;
typedef struct module_instance_s module_instance_t;
typedef struct module_thread_instance_s module_thread_instance_t;
typedef struct module_ctx_s module_ctx_t;
+typedef struct module_inst_ctx_s module_inst_ctx_t;
+typedef struct module_thread_inst_ctx_s module_thread_inst_ctx_t;
#define RLM_TYPE_THREAD_SAFE (0 << 0) //!< Module is threadsafe.
#define RLM_TYPE_THREAD_UNSAFE (1 << 0) //!< Module is not threadsafe.
* Is called once per module instance. Is not called when new threads are
* spawned. See module_thread_instantiate_t for that.
*
- * @param[in] mod_cs Module instance's configuration section.
- * @param[in] instance data, specific to an instantiated module.
- * Pre-allocated, and populated during the
- * bootstrap and instantiate calls.
+ * @param[in] mctx Holds global instance data.
* @return
* - 0 on success.
* - -1 if instantiation failed.
*/
-typedef int (*module_instantiate_t)(void *instance, CONF_SECTION *mod_cs);
+typedef int (*module_instantiate_t)(module_inst_ctx_t const *mctx);
/** Module thread creation callback
*
* Called whenever a new thread is created.
*
- * @param[in] mod_cs Module instance's configuration section.
- * @param[in] instance data, specific to an instantiated module.
- * Pre-allocated, and populated during the
- * bootstrap and instantiate calls.
- * @param[in] el The event list serviced by this thread.
- * @param[in] thread data specific to this module instance.
+ * @param[in] mctx Holds global instance data, thread instance
+ * data, and the thread-specific event list.
* @return
* - 0 on success.
* - -1 if instantiation failed.
*/
-typedef int (*module_thread_instantiate_t)(CONF_SECTION const *mod_cs, void *instance, fr_event_list_t *el, void *thread);
+typedef int (*module_thread_instantiate_t)(module_thread_inst_ctx_t const *mctx);
/** Module thread destruction callback
*
* Destroy a module/thread instance.
*
- * @param[in] thread data specific to this module instance.
+ * @param[in] mctx Holds global instance data, thread instance
+ * data, and the thread-specific event list.
* @return
* - 0 on success.
* - -1 if instantiation failed.
*/
-typedef int (*module_thread_detach_t)(fr_event_list_t *el, void *thread);
+typedef int (*module_thread_detach_t)(module_thread_inst_ctx_t const *mctx);
#define FR_MODULE_COMMON \
struct { \
void *rctx; //!< Resume ctx that a module previously set.
};
+/** Temporary structure to hold arguments for instantiation calls
+ *
+ */
+struct module_inst_ctx_s {
+ dl_module_inst_t const *inst; //!< Dynamic loader API handle for the module.
+};
+
+/** Temporary structure to hold arguments for thread_instantiation calls
+ *
+ */
+struct module_thread_inst_ctx_s {
+ dl_module_inst_t const *inst; //!< Dynamic loader API handle for the module.
+ ///< Must come first to allow cast between
+ ///< module_inst_ctx.
+ void *thread; //!< Thread instance data.
+ fr_event_list_t *el; //!< Event list to register any IO handlers
+ ///< and timers against.
+};
+
/** @name Convenience wrappers around other internal APIs to make them easier to instantiate with modules
*
* @{
(_tconn)->pub.conn, \
(_tconn)->pub.trunk->uctx); \
(_tconn)->pub.trunk->in_handler = (void *)(_tconn)->pub.trunk->funcs.request_demux; \
- (_tconn)->pub.trunk->funcs.request_demux((_tconn), (_tconn)->pub.conn, (_tconn)->pub.trunk->uctx); \
+ (_tconn)->pub.trunk->funcs.request_demux((_tconn)->pub.trunk->el, (_tconn), (_tconn)->pub.conn, (_tconn)->pub.trunk->uctx); \
(_tconn)->pub.trunk->in_handler = _prev; \
} while(0)
(_tconn)->pub.conn, \
(_tconn)->pub.trunk->uctx); \
(_tconn)->pub.trunk->in_handler = (void *)(_tconn)->pub.trunk->funcs.request_cancel_mux; \
- (_tconn)->pub.trunk->funcs.request_cancel_mux((_tconn), (_tconn)->pub.conn, (_tconn)->pub.trunk->uctx); \
+ (_tconn)->pub.trunk->funcs.request_cancel_mux((_tconn)->pub.trunk->el, (_tconn), (_tconn)->pub.conn, (_tconn)->pub.trunk->uctx); \
(_tconn)->pub.trunk->in_handler = _prev; \
} \
} while(0)
* popping/processing other requests.
*
* @param[in] el For timer management.
- *
* @param[in] tconn The trunk connection to dequeue trunk
* requests from.
* @param[in] conn Connection to write the request to.
* used for reporting failures at an I/O layer level not failures of queries or
* external services.
*
+ * @param[in] el For timer management.
* @param[in] tconn The trunk connection.
* @param[in] conn Connection to read the request from.
* Use conn->h to access the
* connection handle or file descriptor.
* @param[in] uctx User context data passed to #fr_trunk_alloc.
*/
-typedef void (*fr_trunk_request_demux_t)(fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx);
+typedef void (*fr_trunk_request_demux_t)(fr_event_list_t *el,
+ fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx);
/** Inform a remote service like a datastore that a request should be cancelled
*
* remove the entry from the tracking tree and call
* #fr_trunk_request_signal_cancel_complete.
*
+ * @param[in] el To insert any timers into.
+ *
* @param[in] tconn The trunk connection used to dequeue
* cancellation requests.
* @param[in] conn Connection to write the request to.
* connection handle or file descriptor.
* @param[in] uctx User context data passed to #fr_trunk_alloc.
*/
-typedef void (*fr_trunk_request_cancel_mux_t)(fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx);
+typedef void (*fr_trunk_request_cancel_mux_t)(fr_event_list_t *el,
+ fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx);
/** Remove an outstanding "sent" request from a tracking/matching structure
*
TEST_CHECK(count > 0);
}
-static void test_cancel_mux(fr_trunk_connection_t *tconn, fr_connection_t *conn, UNUSED void *uctx)
+static void test_cancel_mux(UNUSED fr_event_list_t *el, fr_trunk_connection_t *tconn, fr_connection_t *conn, UNUSED void *uctx)
{
fr_trunk_request_t *treq;
size_t count = 0;
TEST_CHECK(count > 0);
}
-static void test_demux(UNUSED fr_trunk_connection_t *tconn, fr_connection_t *conn, UNUSED void *uctx)
+static void test_demux(UNUSED fr_event_list_t *el, UNUSED fr_trunk_connection_t *tconn, fr_connection_t *conn, UNUSED void *uctx)
{
int fd = *(talloc_get_type_abort(conn->h, int));
test_proto_request_t *preq;
fr_process_module_t const *process = (fr_process_module_t const *) dl_inst->module->common;
if (process->instantiate &&
- (process->instantiate(dl_inst->data, dl_inst->conf) < 0)) {
+ (process->instantiate(&(module_inst_ctx_t){
+ .inst = dl_inst
+ }) < 0)) {
cf_log_err(dl_inst->conf, "Instantiate failed");
return -1;
}
fr_process_module_t const *process = (fr_process_module_t const *) dl_inst->module->common;
if (process->bootstrap &&
- (process->bootstrap(dl_inst->data,
- dl_inst->conf) < 0)) {
+ (process->bootstrap(&(module_inst_ctx_t){
+ .inst = dl_inst
+ }) < 0)) {
cf_log_err(dl_inst->conf, "Bootstrap failed");
return -1;
}
return ((uint16_t) ~sum);
}
-uint16_t fr_ip6_pesudo_header_checksum(struct in6_addr *src, struct in6_addr *dst, uint16_t ip_len, uint8_t ip_next)
+uint16_t fr_ip6_pesudo_header_checksum(struct in6_addr const *src, struct in6_addr const *dst, uint16_t ip_len, uint8_t ip_next)
{
uint64_t sum = 0;
ip_pseudo_header6_t ip6; /* Keep correct alignment for the pointer */
struct in_addr const src_addr, struct in_addr const dst_addr);
int fr_udp_header_check(uint8_t const *data, uint16_t remaining, ip_header_t const *ip);
uint16_t fr_ip_header_checksum(uint8_t const *data, uint8_t ihl);
-uint16_t fr_ip6_pesudo_header_checksum(struct in6_addr *src, struct in6_addr *dst, uint16_t ip_len, uint8_t ip_next);
+uint16_t fr_ip6_pesudo_header_checksum(struct in6_addr const *src, struct in6_addr const *dst, uint16_t ip_len, uint8_t ip_next);
/** Write out an unsigned 16bit integer in wire format (big endian)
*
*/
RCSID("$Id$")
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX mctx->inst->name
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module.h>
* going to return.
*/
typedef struct {
- char const *name;
char const *rcode_str; //!< The base value.
module_instance_t *mi;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_always_t *inst = instance;
+ rlm_always_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_always_t);
xlat_t *xlat;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- inst->mi = module_by_name(NULL, inst->name);
+ inst->mi = module_by_name(NULL, mctx->inst->name);
if (!inst->mi) {
- cf_log_err(conf, "Can't find the module instance data for this module: %s", inst->name);
+ cf_log_err(mctx->inst->conf, "Can't find the module instance data for this module: %s", mctx->inst->name);
return -1;
}
- xlat = xlat_register(inst, inst->name, always_xlat, false);
+ xlat = xlat_register(inst, mctx->inst->name, always_xlat, false);
xlat_func_args(xlat, always_xlat_args);
xlat_async_instantiate_set(xlat, always_xlat_instantiate, rlm_always_t *, NULL, inst);
return 0;
}
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_always_t *inst = instance;
+ rlm_always_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_always_t);
/*
* Convert the rcode string to an int
*/
inst->rcode = fr_table_value_by_str(rcode_table, inst->rcode_str, RLM_MODULE_NOT_SET);
if (inst->rcode == RLM_MODULE_NOT_SET) {
- cf_log_err(conf, "rcode value \"%s\" is invalid", inst->rcode_str);
+ cf_log_err(mctx->inst->conf, "rcode value \"%s\" is invalid", inst->rcode_str);
return -1;
}
*/
RCSID("$Id$")
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX mctx->inst->name
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module.h>
* be used as the instance handle.
*/
typedef struct {
- char const *name;
char const *filename;
tmpl_t *key;
bool relaxed;
return;
}
-static int attr_filter_getfile(TALLOC_CTX *ctx, rlm_attr_filter_t *inst, char const *filename, PAIR_LIST_LIST *pair_list)
+static int attr_filter_getfile(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx, char const *filename, PAIR_LIST_LIST *pair_list)
{
int rcode;
PAIR_LIST *entry = NULL;
return 0;
}
-
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
-{
- rlm_attr_filter_t *inst = instance;
-
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- return 0;
-}
-
/*
* (Re-)read the "attrs" file into memory.
*/
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_attr_filter_t *inst = instance;
+ rlm_attr_filter_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_attr_filter_t);
int rcode;
pairlist_list_init(&inst->attrs);
- rcode = attr_filter_getfile(inst, inst, inst->filename, &inst->attrs);
+ rcode = attr_filter_getfile(inst, mctx, inst->filename, &inst->attrs);
if (rcode != 0) {
ERROR("Errors reading %s", inst->filename);
* Common attr_filter checks
*/
static unlang_action_t CC_HINT(nonnull(1,2)) attr_filter_common(rlm_rcode_t *p_result,
- void const *instance, request_t *request,
+ module_ctx_t const *mctx, request_t *request,
fr_radius_packet_t *packet, fr_pair_list_t *list)
{
- rlm_attr_filter_t const *inst = talloc_get_type_abort_const(instance, rlm_attr_filter_t);
+ rlm_attr_filter_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_attr_filter_t);
fr_pair_list_t output;
PAIR_LIST *pl = NULL;
int found = 0;
#define RLM_AF_FUNC(_x, _y, _z) static unlang_action_t CC_HINT(nonnull) mod_##_x(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request) \
{ \
- return attr_filter_common(p_result, mctx->inst->data, request, request->_y, &request->_z##_pairs); \
+ return attr_filter_common(p_result, mctx, request, request->_y, &request->_z##_pairs); \
}
RLM_AF_FUNC(authorize, packet, request)
.name = "attr_filter",
.inst_size = sizeof(rlm_attr_filter_t),
.config = module_config,
- .bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.methods = {
[MOD_AUTHORIZE] = mod_authorize,
/** Create a new rlm_cache_memcached instance
*
- * @param instance A uint8_t array of inst_size if inst_size > 0, else NULL,
- * this should contain the result of parsing the driver's
- * CONF_PARSER array that it specified in the interface struct.
- * @param conf section holding driver specific #CONF_PAIR (s).
+ * @param[in] mctx Data required for instantiation.
* @return
* - 0 on success.
* - -1 on failure.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_cache_memcached_t *driver = instance;
+ rlm_cache_memcached_t *driver = talloc_get_type_abort(mctx->inst->data, rlm_cache_memcached_t);
+ CONF_SECTION *conf = mctx->inst->conf;
memcached_return_t ret;
char buffer[256];
- rlm_cache_config_t const *config = dl_module_parent_data_by_child_data(instance);
+ rlm_cache_config_t const *config = talloc_get_type_abort(mctx->inst->parent->data, rlm_cache_config_t);
fr_assert(config);
- snprintf(buffer, sizeof(buffer), "rlm_cache (%s)", config->name);
+ snprintf(buffer, sizeof(buffer), "rlm_cache (%s)", mctx->inst->parent->name);
ret = libmemcached_check_configuration(driver->options, talloc_array_length(driver->options) -1,
buffer, sizeof(buffer));
/** Cleanup a cache_rbtree instance
*
*/
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t const *mctx)
{
- rlm_cache_rbtree_t *driver = talloc_get_type_abort(instance, rlm_cache_rbtree_t);
+ rlm_cache_rbtree_t *driver = talloc_get_type_abort(mctx->inst->data, rlm_cache_rbtree_t);
if (driver->cache) {
fr_rb_iter_inorder_t iter;
/** Create a new cache_rbtree instance
*
- * @param instance A uint8_t array of inst_size if inst_size > 0, else NULL,
- * this should contain the result of parsing the driver's
- * CONF_PARSER array that it specified in the interface struct.
- * @param conf section holding driver specific #CONF_PAIR (s).
+ * @param[in] mctx Data required for instantiation.
* @return
* - 0 on success.
* - -1 on failure.
*/
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_cache_rbtree_t *driver = talloc_get_type_abort(instance, rlm_cache_rbtree_t);
+ rlm_cache_rbtree_t *driver = talloc_get_type_abort(mctx->inst->data, rlm_cache_rbtree_t);
/*
* The cache.
.instantiate = mod_instantiate,
.detach = mod_detach,
.inst_size = sizeof(rlm_cache_rbtree_t),
+ .inst_type = "rlm_cache_rbtree_t",
.alloc = cache_entry_alloc,
.find = cache_entry_find,
/** Create a new rlm_cache_redis instance
*
- * @param instance A uint8_t array of inst_size if inst_size > 0, else NULL,
- * this should contain the result of parsing the driver's
- * CONF_PARSER array that it specified in the interface struct.
- * @param conf section holding driver specific #CONF_PAIR (s).
+ * @param[in] mctx Data required for instantiation.
* @return
* - 0 on success.
* - -1 on failure.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_cache_redis_t *driver = instance;
+ rlm_cache_redis_t *driver = talloc_get_type_abort(mctx->inst->data, rlm_cache_redis_t);
char buffer[256];
- rlm_cache_config_t const *config = dl_module_parent_data_by_child_data(instance);
-
- fr_assert(config);
buffer[0] = '\0';
- if (cf_section_rules_push(conf, driver_config) < 0) return -1;
- if (cf_section_parse(driver, driver, conf) < 0) return -1;
+ if (cf_section_rules_push(mctx->inst->conf, driver_config) < 0) return -1;
+ if (cf_section_parse(driver, driver, mctx->inst->conf) < 0) return -1;
- snprintf(buffer, sizeof(buffer), "rlm_cache (%s)", config->name);
+ snprintf(buffer, sizeof(buffer), "rlm_cache (%s)", mctx->inst->parent->name);
- driver->cluster = fr_redis_cluster_alloc(driver, conf, &driver->conf, true,
+ driver->cluster = fr_redis_cluster_alloc(driver, mctx->inst->conf, &driver->conf, true,
buffer, "modules.cache.pool", NULL);
if (!driver->cluster) {
ERROR("Cluster failure");
*/
RCSID("$Id$")
-#define LOG_PREFIX inst->config.name
+#define LOG_PREFIX mctx->inst->name
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module.h>
/** Free any memory allocated under the instance
*
*/
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t const *mctx)
{
- rlm_cache_t *inst = instance;
+ rlm_cache_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_cache_t);
/*
* We need to explicitly free all children, so if the driver
/** Register module xlats
*
*/
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_cache_t *inst = instance;
+ rlm_cache_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_cache_t );
+ CONF_SECTION *conf = mctx->inst->conf;
CONF_SECTION *driver_cs;
char const *name;
xlat_t *xlat;
- inst->config.name = cf_section_name2(conf);
- if (!inst->config.name) inst->config.name = cf_section_name1(conf);
-
name = strrchr(inst->config.driver_name, '_');
if (!name) {
name = inst->config.driver_name;
/*
* Register the cache xlat function
*/
- xlat = xlat_register(inst, inst->config.name, cache_xlat, true);
+ xlat = xlat_register(inst, mctx->inst->name, cache_xlat, true);
xlat_func_args(xlat, cache_xlat_args);
xlat_async_thread_instantiate_set(xlat, mod_xlat_thread_instantiate, cache_xlat_thread_inst_t, NULL, inst);
/** Create a new rlm_cache_instance
*
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_cache_t *inst = instance;
+ rlm_cache_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_cache_t);
+ CONF_SECTION *conf = mctx->inst->conf;
CONF_SECTION *update;
fr_assert(inst->config.key);
rlm_cache_entry_t *entry = NULL;
rlm_cache_handle_t *handle = NULL;
- DEBUG3("Calling %s.status", inst->config.name);
+ DEBUG3("Calling %s.status", mctx->inst->name);
key_len = tmpl_expand((char const **)&key, (char *)buffer, sizeof(buffer),
request, inst->config.key, NULL, NULL);
rlm_cache_entry_t *entry = NULL;
rlm_cache_handle_t *handle = NULL;
- DEBUG3("Calling %s.load", inst->config.name);
+ DEBUG3("Calling %s.load", mctx->inst->name);
key_len = tmpl_expand((char const **)&key, (char *)buffer, sizeof(buffer),
request, inst->config.key, NULL, NULL);
rlm_cache_handle_t *handle = NULL;
fr_pair_t *vp;
- DEBUG3("Calling %s.store", inst->config.name);
+ DEBUG3("Calling %s.store", mctx->inst->name);
key_len = tmpl_expand((char const **)&key, (char *)buffer, sizeof(buffer),
request, inst->config.key, NULL, NULL);
rlm_cache_entry_t *entry = NULL;
rlm_cache_handle_t *handle = NULL;
- DEBUG3("Calling %s.clear", inst->config.name);
+ DEBUG3("Calling %s.clear", mctx->inst->name);
key_len = tmpl_expand((char const **)&key, (char *)buffer, sizeof(buffer),
request, inst->config.key, NULL, NULL);
rlm_cache_handle_t *handle = NULL;
fr_pair_t *vp;
- DEBUG3("Calling %s.ttl", inst->config.name);
+ DEBUG3("Calling %s.ttl", mctx->inst->name);
key_len = tmpl_expand((char const **)&key, (char *)buffer, sizeof(buffer),
request, inst->config.key, NULL, NULL);
* rlm_cache instance data.
*/
typedef struct {
- char const *name; //!< Name of xlat function to register.
char const *driver_name; //!< Driver name.
tmpl_t *key; //!< What to expand to get the value of the key.
fr_time_delta_t ttl; //!< How long an entry is valid for.
*/
RCSID("$Id$")
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX mctx->inst->name
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/password.h>
#include <freeradius-devel/radius/radius.h>
typedef struct {
- char const *name; //!< Auth-Type value for this module instance.
fr_dict_enum_value_t *auth_type;
} rlm_chap_t;
rlm_chap_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_chap_t);
if (fr_pair_find_by_da_idx(&request->control_pairs, attr_auth_type, 0) != NULL) {
- RDEBUG3("Auth-Type is already set. Not setting 'Auth-Type := %s'", inst->name);
+ RDEBUG3("Auth-Type is already set. Not setting 'Auth-Type := %s'", mctx->inst->name);
RETURN_MODULE_NOOP;
}
if (!inst->auth_type) {
WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup CHAP authentication",
- inst->name, inst->name);
+ mctx->inst->name, mctx->inst->name);
RETURN_MODULE_NOOP;
}
RETURN_MODULE_OK;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
-{
- rlm_chap_t *inst = instance;
-
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- return 0;
-}
-
/*
* Create instance for our module. Allocate space for
* instance structure and read configuration parameters
*/
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_chap_t *inst = instance;
+ rlm_chap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_chap_t);
- inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1);
+ inst->auth_type = fr_dict_enum_by_name(attr_auth_type, mctx->inst->name, -1);
if (!inst->auth_type) {
WARN("Failed to find 'authenticate %s {...}' section. CHAP authentication will likely not work",
- inst->name);
+ mctx->inst->name);
}
return 0;
.inst_size = sizeof(rlm_chap_t),
.onload = mod_load,
.unload = mod_unload,
- .bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.dict = &dict_radius,
.methods = {
*
*/
typedef struct {
- char const *name; //!< Name of xlat we registered.
cipher_type_t type; //!< Type of encryption to use.
/** Supported cipher types
*
* @return 0.
*/
-static int cipher_rsa_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instance,
- UNUSED fr_event_list_t *el, void *thread)
+static int cipher_rsa_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_cipher_t const *inst = talloc_get_type_abort(instance, rlm_cipher_t);
- rlm_cipher_rsa_thread_inst_t *ti = thread;
+ rlm_cipher_t const *inst = talloc_get_type_abort(mctx->inst->data, rlm_cipher_t);
+ rlm_cipher_rsa_thread_inst_t *ti = talloc_get_type_abort(mctx->thread, rlm_cipher_rsa_thread_inst_t);
/*
* Pre-allocate different contexts for the different operations
return 0;
}
-static int mod_thread_instantiate(CONF_SECTION const *conf, void *instance,
- fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_cipher_t *inst = talloc_get_type_abort(instance, rlm_cipher_t);
+ rlm_cipher_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_cipher_t);
switch (inst->type) {
case RLM_CIPHER_TYPE_RSA:
- talloc_set_type(thread, rlm_cipher_rsa_thread_inst_t);
- return cipher_rsa_thread_instantiate(conf, instance, el, thread);
+ talloc_set_type(mctx->thread, rlm_cipher_rsa_thread_inst_t);
+ return cipher_rsa_thread_instantiate(mctx);
case RLM_CIPHER_TYPE_INVALID:
fr_assert(0);
* to external databases, read configuration files, set up
* dictionary entries, etc.
*/
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_cipher_t *inst = talloc_get_type_abort(instance, rlm_cipher_t);
-
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
+ rlm_cipher_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_cipher_t);
+ CONF_SECTION *conf = mctx->inst->conf;
switch (inst->type) {
case RLM_CIPHER_TYPE_RSA:
/*
* Register decrypt xlat
*/
- xlat_name = talloc_asprintf(inst, "%s_decrypt", inst->name);
+ xlat_name = talloc_asprintf(inst, "%s_decrypt", mctx->inst->name);
xlat = xlat_register(inst, xlat_name, cipher_rsa_decrypt_xlat, false);
xlat_func_mono(xlat, &cipher_rsa_decrypt_xlat_arg);
xlat_async_instantiate_set(xlat, cipher_xlat_instantiate,
/*
* Verify sign xlat
*/
- xlat_name = talloc_asprintf(inst, "%s_verify", inst->name);
+ xlat_name = talloc_asprintf(inst, "%s_verify", mctx->inst->name);
xlat = xlat_register(inst, xlat_name, cipher_rsa_verify_xlat, false);
xlat_func_args(xlat, cipher_rsa_verify_xlat_arg);
xlat_async_instantiate_set(xlat, cipher_xlat_instantiate,
/*
* Register encrypt xlat
*/
- xlat_name = talloc_asprintf(inst, "%s_encrypt", inst->name);
+ xlat_name = talloc_asprintf(inst, "%s_encrypt", mctx->inst->name);
xlat = xlat_register(inst, xlat_name, cipher_rsa_encrypt_xlat, false);
xlat_func_mono(xlat, &cipher_rsa_encrypt_xlat_arg);
xlat_async_instantiate_set(xlat, cipher_xlat_instantiate,
/*
* Register sign xlat
*/
- xlat_name = talloc_asprintf(inst, "%s_sign", inst->name);
+ xlat_name = talloc_asprintf(inst, "%s_sign", mctx->inst->name);
xlat = xlat_register(inst, xlat_name, cipher_rsa_sign_xlat, false);
xlat_func_mono(xlat, &cipher_rsa_sign_xlat_arg);
xlat_async_instantiate_set(xlat, cipher_xlat_instantiate,
inst);
talloc_free(xlat_name);
- xlat_name = talloc_asprintf(inst, "%s_certificate", inst->name);
+ xlat_name = talloc_asprintf(inst, "%s_certificate", mctx->inst->name);
xlat = xlat_register(inst, xlat_name, cipher_certificate_xlat, false);
xlat_func_args(xlat, cipher_certificate_xlat_args);
xlat_async_instantiate_set(xlat, cipher_xlat_instantiate,
* that must be referenced in later calls, store a handle to it
* in *instance otherwise put a null pointer there.
*/
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
+ CONF_SECTION *conf = mctx->inst->conf;
xlat_t *xlat;
if (cf_section_name2(conf)) return 0;
- xlat = xlat_register(instance, "client", xlat_client, false);
+ xlat = xlat_register(mctx->inst->data, "client", xlat_client, false);
xlat_func_args(xlat, xlat_client_args);
- map_proc_register(instance, "client", map_proc_client, NULL, 0);
+ map_proc_register(mctx->inst->data, "client", map_proc_client, NULL, 0);
return 0;
}
*/
int mod_free_api_opts(void *instance)
{
- rlm_couchbase_t *inst = instance; /* our module instance */
+ rlm_couchbase_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_couchbase_t); /* our module instance */
couchbase_opts_t *opts = inst->api_opts;
if (!opts) return 0;
*/
int mod_build_api_opts(CONF_SECTION *conf, void *instance)
{
- rlm_couchbase_t *inst = instance; /* our module instance */
+ rlm_couchbase_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_couchbase_t); /* our module instance */
CONF_SECTION *cs; /* module config list */
CONF_ITEM *ci; /* config item */
CONF_PAIR *cp; /* config pair */
*/
int mod_build_attribute_element_map(CONF_SECTION *conf, void *instance)
{
- rlm_couchbase_t *inst = instance; /* our module instance */
+ rlm_couchbase_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_couchbase_t); /* our module instance */
CONF_SECTION *cs; /* module config list */
CONF_ITEM *ci; /* config item */
CONF_PAIR *cp; /* conig pair */
*/
static int mod_detach(void *instance)
{
- rlm_couchbase_t *inst = instance;
+ rlm_couchbase_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_couchbase_t);
if (inst->map) json_object_put(inst->map);
if (inst->pool) fr_pool_free(inst->pool);
return 0;
}
-/** Bootstrap the module
- *
- * Define attributes.
- *
- * @param conf to parse.
- * @param instance configuration data.
- * @return
- * - 0 on success.
- * - < 0 on failure.
- */
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
-{
- rlm_couchbase_t *inst = instance;
-
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- return 0;
-}
-
/** Initialize the rlm_couchbase module
*
* Intialize the module and create the initial Couchbase connection pool.
* - 0 on success.
* - -1 on failure.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_couchbase_t *inst = instance; /* our module instance */
+ rlm_couchbase_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_couchbase_t); /* our module instance */
{
char *server, *p;
.type = RLM_TYPE_THREAD_SAFE,
.inst_size = sizeof(rlm_couchbase_t),
.config = module_config,
- .bootstrap = mod_bootstrap,
.onload = mod_load,
.instantiate = mod_instantiate,
.detach = mod_detach,
* be used as the instance handle.
*/
typedef struct {
- char const *name;
char const *filename;
char const *delimiter;
char const *fields;
*/
static int csv_map_verify(map_t *map, void *instance)
{
- rlm_csv_t *inst = instance;
+ rlm_csv_t *inst = talloc_get_type_abort(instance, rlm_csv_t);
int offset;
fr_type_t type = FR_TYPE_NULL;
* that must be referenced in later calls, store a handle to it
* in *instance otherwise put a null pointer there.
*/
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_csv_t *inst = instance;
- int i;
- char const *p;
- char *q;
- char *fields;
+ rlm_csv_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_csv_t);
+ CONF_SECTION *conf = mctx->inst->conf;
+ int i;
+ char const *p;
+ char *q;
+ char *fields;
fr_htrie_type_t htype;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
if (inst->delimiter[1]) {
cf_log_err(conf, "'delimiter' must be one character long");
return -1;
/*
* And register the `map csv <key> { ... }` function.
*/
- map_proc_register(inst, inst->name, mod_map_proc, csv_maps_verify, 0);
+ map_proc_register(inst, mctx->inst->name, mod_map_proc, csv_maps_verify, 0);
return 0;
}
*
* Creates a new instance of the module reading parameters from a configuration section.
*
- * @param conf to parse.
- * @param instance configuration data.
+ * @param[in] mctx configuration data.
* @return
* - 0 on success.
* - < 0 on failure.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_csv_t *inst = instance;
- CONF_SECTION *cs;
- int lineno;
- FILE *fp;
+ rlm_csv_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_csv_t);
+ CONF_SECTION *conf = mctx->inst->conf;
+ CONF_SECTION *cs;
+ int lineno;
+ FILE *fp;
tmpl_rules_t parse_rules = {
.allow_foreign = true /* Because we don't know where we'll be called */
};
#include <time.h>
typedef struct {
- char const *name;
char const *fmt;
bool utc;
} rlm_date_t;
char *p;
/*
- *
+ *
*/
MEM(my_str = talloc_strdup(ctx, str));
p = my_str + (tz - str);
talloc_free(my_str);
return XLAT_ACTION_FAIL;
}
- talloc_free(my_str);
+ talloc_free(my_str);
/*
* The output is converted to the local time zone, so
return XLAT_ACTION_FAIL;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_date_t *inst = instance;
+ rlm_date_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_date_t );
xlat_t *xlat;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- xlat = xlat_register(inst, inst->name, xlat_date_convert, false);
+ xlat = xlat_register(inst, mctx->inst->name, xlat_date_convert, false);
xlat_func_args(xlat,xlat_date_convert_args);
xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_date_t *, NULL, inst);
#include <freeradius-devel/util/time.h>
typedef struct {
- char const *name; //!< Name of our xlat function.
- tmpl_t *delay; //!< How long we delay for.
+ tmpl_t *delay; //!< How long we delay for.
bool relative; //!< Whether the delay is relative to the start of request processing.
bool force_reschedule; //!< Whether we should force rescheduling of the request.
} rlm_delay_t;
return 0;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_delay_t *inst = instance;
+ rlm_delay_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_delay_t);
xlat_t *xlat;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- xlat = xlat_register(inst, inst->name, xlat_delay, true);
+ xlat = xlat_register(inst, mctx->inst->name, xlat_delay, true);
xlat_func_args(xlat, xlat_delay_args);
xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_delay_t *, NULL, inst);
return 0;
*/
RCSID("$Id$")
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX mctx->inst->name
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/exfile.h>
* Holds the configuration and preparsed data for a instance of rlm_detail.
*/
typedef struct {
- char const *name; //!< Instance name.
char const *filename; //!< File/path to write to.
uint32_t perm; //!< Permissions to use for new files.
char const *group; //!< Group to use for new files.
/*
* (Re-)read radiusd.conf into memory.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_detail_t *inst = instance;
+ rlm_detail_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_detail_t);
+ CONF_SECTION *conf = mctx->inst->conf;
CONF_SECTION *cs;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
/*
* Escape filenames only if asked.
*/
* be used as the instance handle.
*/
typedef struct {
- char const *name;
-
fr_udp_queue_config_t config; //!< UDP queue config
uint32_t max_packet_size; //!< Maximum packet size.
*
* Bootstrap I/O and type submodules.
*
- * @param[in] instance Ctx data for this module
- * @param[in] conf our configuration section parsed to give us instance.
+ * @param[in] mctx data for this module
* @return
* - 0 on success.
* - -1 on failure.
*/
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_dhcpv4_t *inst = talloc_get_type_abort(instance, rlm_dhcpv4_t);
-
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
+ rlm_dhcpv4_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_dhcpv4_t);
+ CONF_SECTION *conf = mctx->inst->conf;
/*
* Ensure that we have a destination address.
/** Instantiate thread data for the submodule.
*
*/
-static int mod_thread_instantiate(CONF_SECTION const *cs, void *instance, fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_dhcpv4_t *inst = talloc_get_type_abort(instance, rlm_dhcpv4_t);
- rlm_dhcpv4_thread_t *t = talloc_get_type_abort(thread, rlm_dhcpv4_thread_t);
+ rlm_dhcpv4_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_dhcpv4_t);
+ rlm_dhcpv4_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_dhcpv4_thread_t);
+ CONF_SECTION *conf = mctx->inst->conf;
t->buffer = talloc_array(t, uint8_t, inst->max_packet_size);
if (!t->buffer) {
- cf_log_err(cs, "Failed allocating buffer");
+ cf_log_err(conf, "Failed allocating buffer");
return -1;
}
t->buffer_size = inst->max_packet_size;
- t->uq = fr_udp_queue_alloc(t, &inst->config, el, dhcpv4_queue_resume);
+ t->uq = fr_udp_queue_alloc(t, &inst->config, mctx->el, dhcpv4_queue_resume);
if (!t->uq) {
- cf_log_err(cs, "Failed allocating outbound udp queue - %s", fr_strerror());
+ cf_log_err(conf, "Failed allocating outbound udp queue - %s", fr_strerror());
return -1;
}
* that must be referenced in later calls, store a handle to it
* in *instance otherwise put a null pointer there.
*/
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
+ void *inst = mctx->inst->data;
+
xlat_t *xlat;
/*
* Only register these xlats for the first instance of the dictionary module.
*/
- if (cf_section_name2(conf) != NULL) return 0;
+ if (cf_section_name2(mctx->inst->conf) != NULL) return 0;
- xlat = xlat_register(instance, "attr_by_num", xlat_dict_attr_by_num, false);
+ xlat = xlat_register(inst, "attr_by_num", xlat_dict_attr_by_num, false);
xlat_func_args(xlat, xlat_dict_attr_by_num_args);
- xlat = xlat_register(instance, "attr_by_oid", xlat_dict_attr_by_oid, false);
+ xlat = xlat_register(inst, "attr_by_oid", xlat_dict_attr_by_oid, false);
xlat_func_args(xlat, xlat_dict_attr_by_oid_args);
- xlat = xlat_register(instance, "vendor", xlat_vendor, false);
+ xlat = xlat_register(inst, "vendor", xlat_vendor, false);
xlat_func_args(xlat, xlat_vendor_args);
- xlat = xlat_register(instance, "vendor_num", xlat_vendor_num, false);
+ xlat = xlat_register(inst, "vendor_num", xlat_vendor_num, false);
xlat_func_args(xlat, xlat_vendor_num_args);
- xlat = xlat_register(instance, "attr", xlat_attr, false);
+ xlat = xlat_register(inst, "attr", xlat_attr, false);
xlat_func_args(xlat, xlat_attr_args);
- xlat = xlat_register(instance, "attr_num", xlat_attr_num, false);
+ xlat = xlat_register(inst, "attr_num", xlat_attr_num, false);
xlat_func_args(xlat, xlat_attr_num_args);
return 0;
#include <freeradius-devel/util/md5.h>
typedef struct {
- char const *name; //!< Auth-Type value for this module instance.
fr_dict_enum_value_t *auth_type;
} rlm_digest_t;
if (!inst->auth_type) {
WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup Digest authentication",
- inst->name, inst->name);
+ mctx->inst->name, mctx->inst->name);
RETURN_MODULE_NOOP;
}
RETURN_MODULE_REJECT;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
-{
- char const *name;
- rlm_digest_t *inst = instance;
-
- /*
- * Create the dynamic translation.
- */
- name = cf_section_name2(conf);
- if (!name) name = cf_section_name1(conf);
- inst->name = name;
-
- return 0;
-}
/*
* Create instance for our module. Allocate space for
* instance structure and read configuration parameters
*/
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_digest_t *inst = instance;
+ rlm_digest_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_digest_t);
- inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1);
+ inst->auth_type = fr_dict_enum_by_name(attr_auth_type, mctx->inst->name, -1);
if (!inst->auth_type) {
WARN("Failed to find 'authenticate %s {...}' section. Digest authentication will likely not work",
- inst->name);
+ mctx->inst->name);
}
return 0;
.magic = RLM_MODULE_INIT,
.name = "digest",
.inst_size = sizeof(rlm_digest_t),
- .bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.dict = &dict_radius,
.methods = {
*/
RCSID("$Id$")
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX mctx->inst->name
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module.h>
case FR_EAP_METHOD_AKA:
case FR_EAP_METHOD_SIM:
{
- rlm_eap_t *inst = ((dl_module_inst_t *)cf_data_value(cf_data_find(eap_cs,
- dl_module_inst_t, "rlm_eap")))->data;
-
+ module_inst_ctx_t *mctx = &(module_inst_ctx_t){
+ .inst = ((dl_module_inst_t *)cf_data_value(cf_data_find(eap_cs,
+ dl_module_inst_t, "rlm_eap")))
+ };
WARN("Ignoring EAP method %s because we don't have OpenSSL support", name);
talloc_free(our_name);
if (!inst->auth_type) {
WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup EAP authentication",
- inst->name, inst->name);
+ mctx->inst->name, mctx->inst->name);
RETURN_MODULE_NOOP;
}
static unlang_action_t mod_post_auth(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
{
- rlm_eap_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_eap_t);
fr_pair_t *vp;
eap_session_t *eap_session;
fr_pair_t *username;
* Was *NOT* an EAP-Failure, so we now need to turn it into one.
*/
REDEBUG("Request rejected after last call to module \"%s\", transforming response into EAP-Failure",
- inst->name);
+ mctx->inst->name);
eap_fail(eap_session); /* Compose an EAP failure */
eap_session_destroy(&eap_session); /* Free the EAP session, and dissociate it from the request */
RETURN_MODULE_UPDATED;
}
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *cs)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_eap_t *inst = talloc_get_type_abort(instance, rlm_eap_t);
+ rlm_eap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_t);
size_t i;
- inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1);
+ inst->auth_type = fr_dict_enum_by_name(attr_auth_type, mctx->inst->name, -1);
if (!inst->auth_type) {
WARN("Failed to find 'authenticate %s {...}' section. EAP authentication will likely not work",
- inst->name);
+ mctx->inst->name);
}
/*
return 0;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *cs)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_eap_t *inst = talloc_get_type_abort(instance, rlm_eap_t);
+ rlm_eap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_t);
size_t i, j, loaded, count = 0;
- inst->name = cf_section_name2(cs);
- if (!inst->name) inst->name = cf_section_name1(cs);
-
/*
* Load and bootstrap the submodules now
* We have to do that here instead of in a parse function
* allowed by the config.
*/
if (inst->default_method_is_set && !inst->methods[inst->default_method].submodule) {
- cf_log_err_by_child(cs, "default_eap_type", "EAP-Type \"%s\" is not enabled",
+ cf_log_err_by_child(mctx->inst->conf, "default_eap_type", "EAP-Type \"%s\" is not enabled",
eap_type2name(inst->default_method));
return -1;
}
if (count == 0) {
- cf_log_err(cs, "No EAP method(s) configured, module cannot do anything");
+ cf_log_err(mctx->inst->conf, "No EAP method(s) configured, module cannot do anything");
return -1;
}
static int mod_load(void)
{
- rlm_eap_t instance = { .name = "global" };
- rlm_eap_t *inst = &instance;
-
if (eap_base_init() < 0) {
- PERROR("Failed initialising EAP base library");
+ fr_perror("Failed initialising EAP base library");
return -1;
}
return 0;
return eap_session->process(p_result, mctx, request);
}
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- eap_aka_sim_module_conf_t *inst = talloc_get_type_abort(instance, eap_aka_sim_module_conf_t);
+ eap_aka_sim_module_conf_t *inst = talloc_get_type_abort(mctx->inst->data, eap_aka_sim_module_conf_t);
+ CONF_SECTION *conf = mctx->inst->conf;
inst->type = rlm_eap_aka.provides[0];
return eap_session->process(p_result, mctx, request);
}
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- eap_aka_sim_module_conf_t *inst = talloc_get_type_abort(instance, eap_aka_sim_module_conf_t);
+ eap_aka_sim_module_conf_t *inst = talloc_get_type_abort(mctx->inst->data, eap_aka_sim_module_conf_t);
inst->type = rlm_eap_aka_prime.provides[0];
RETURN_MODULE_HANDLED;
}
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance,
- UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_eap_fast_t *inst = talloc_get_type_abort(instance, rlm_eap_fast_t);
- rlm_eap_fast_thread_t *t = talloc_get_type_abort(thread, rlm_eap_fast_thread_t);
+ rlm_eap_fast_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_fast_t);
+ rlm_eap_fast_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_fast_thread_t);
t->ssl_ctx = fr_tls_ctx_alloc(inst->tls_conf, false);
if (!t->ssl_ctx) return -1;
return 0;
}
-static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- rlm_eap_fast_thread_t *t = talloc_get_type_abort(thread, rlm_eap_fast_thread_t);
+ rlm_eap_fast_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_fast_thread_t);
if (likely(t->ssl_ctx != NULL)) SSL_CTX_free(t->ssl_ctx);
t->ssl_ctx = NULL;
/*
* Attach the module.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *cs)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_eap_fast_t *inst = talloc_get_type_abort(instance, rlm_eap_fast_t);
+ rlm_eap_fast_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_fast_t);
+ CONF_SECTION *conf = mctx->inst->conf;
if (!virtual_server_find(inst->virtual_server)) {
- cf_log_err_by_child(cs, "virtual_server", "Unknown virtual server '%s'", inst->virtual_server);
+ cf_log_err_by_child(mctx->inst->conf, "virtual_server", "Unknown virtual server '%s'",
+ inst->virtual_server);
return -1;
}
inst->default_provisioning_method = eap_name2type(inst->default_provisioning_method_name);
if (!inst->default_provisioning_method) {
- cf_log_err_by_child(cs, "default_provisioning_eap_type", "Unknown EAP type %s",
+ cf_log_err_by_child(conf, "default_provisioning_eap_type", "Unknown EAP type %s",
inst->default_provisioning_method_name);
return -1;
}
* Read tls configuration, either from group given by 'tls'
* option, or from the eap-tls configuration.
*/
- inst->tls_conf = eap_tls_conf_parse(cs, "tls");
+ inst->tls_conf = eap_tls_conf_parse(conf, "tls");
if (!inst->tls_conf) {
- cf_log_err_by_child(cs, "tls", "Failed initializing SSL context");
+ cf_log_err_by_child(conf, "tls", "Failed initializing SSL context");
return -1;
}
if (talloc_array_length(inst->pac_opaque_key) - 1 != 32) {
- cf_log_err_by_child(cs, "pac_opaque_key", "Must be 32 bytes long");
+ cf_log_err_by_child(conf, "pac_opaque_key", "Must be 32 bytes long");
return -1;
}
* disable TLSv1.2 later.
*/
if (inst->tls_conf->tls_min_version > (float) 1.1) {
- cf_log_err_by_child(cs, "tls_min_version", "require tls_min_version <= 1.1");
+ cf_log_err_by_child(conf, "tls_min_version", "require tls_min_version <= 1.1");
return -1;
}
if (!fr_time_delta_ispos(inst->pac_lifetime)) {
- cf_log_err_by_child(cs, "pac_lifetime", "must be non-zero");
+ cf_log_err_by_child(conf, "pac_lifetime", "must be non-zero");
return -1;
}
/*
* Attach the module.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *cs)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_eap_mschapv2_t *inst = talloc_get_type_abort(instance, rlm_eap_mschapv2_t);
+ rlm_eap_mschapv2_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_mschapv2_t);
if (inst->identity && (strlen(inst->identity) > 255)) {
- cf_log_err(cs, "identity is too long");
+ cf_log_err(mctx->inst->conf, "identity is too long");
return -1;
}
RETURN_MODULE_HANDLED;
}
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance,
- UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_eap_peap_t *inst = talloc_get_type_abort(instance, rlm_eap_peap_t);
- rlm_eap_peap_thread_t *t = talloc_get_type_abort(thread, rlm_eap_peap_thread_t);
+ rlm_eap_peap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_peap_t);
+ rlm_eap_peap_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_peap_thread_t);
t->ssl_ctx = fr_tls_ctx_alloc(inst->tls_conf, false);
if (!t->ssl_ctx) return -1;
return 0;
}
-static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- rlm_eap_peap_thread_t *t = talloc_get_type_abort(thread, rlm_eap_peap_thread_t);
+ rlm_eap_peap_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_peap_thread_t);
if (likely(t->ssl_ctx != NULL)) SSL_CTX_free(t->ssl_ctx);
t->ssl_ctx = NULL;
/*
* Attach the module.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *cs)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_eap_peap_t *inst = talloc_get_type_abort(instance, rlm_eap_peap_t);
+ rlm_eap_peap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_peap_t);
+ CONF_SECTION *conf = mctx->inst->conf;
if (!virtual_server_find(inst->virtual_server)) {
- cf_log_err_by_child(cs, "virtual_server", "Unknown virtual server '%s'", inst->virtual_server);
+ cf_log_err_by_child(conf, "virtual_server", "Unknown virtual server '%s'", inst->virtual_server);
return -1;
}
if (inst->soh_virtual_server) {
if (!virtual_server_find(inst->soh_virtual_server)) {
- cf_log_err_by_child(cs, "soh_virtual_server", "Unknown virtual server '%s'", inst->virtual_server);
+ cf_log_err_by_child(conf, "soh_virtual_server", "Unknown virtual server '%s'", inst->virtual_server);
return -1;
}
}
* Read tls configuration, either from group given by 'tls'
* option, or from the eap-tls configuration.
*/
- inst->tls_conf = eap_tls_conf_parse(cs, "tls");
+ inst->tls_conf = eap_tls_conf_parse(conf, "tls");
if (!inst->tls_conf) {
- cf_log_err(cs, "Failed initializing SSL context");
+ cf_log_err(conf, "Failed initializing SSL context");
return -1;
}
RETURN_MODULE_HANDLED;
}
-static int mod_detach(void *arg)
+static int mod_detach(module_detach_ctx_t const *mctx)
{
- rlm_eap_pwd_t *inst;
-
- inst = (rlm_eap_pwd_t *) arg;
+ rlm_eap_pwd_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_pwd_t);
if (inst->bnctx) BN_CTX_free(inst->bnctx);
return 0;
}
-static int mod_instantiate(void *instance, CONF_SECTION *cs)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_eap_pwd_t *inst = talloc_get_type_abort(instance, rlm_eap_pwd_t);
+ rlm_eap_pwd_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_pwd_t);
+ CONF_SECTION *conf = mctx->inst->conf;
if (inst->fragment_size < 100) {
- cf_log_err(cs, "Fragment size is too small");
+ cf_log_err(conf, "Fragment size is too small");
return -1;
}
break;
default:
- cf_log_err_by_child(cs, "group", "Group %i is not supported", inst->group);
+ cf_log_err_by_child(conf, "group", "Group %i is not supported", inst->group);
return -1;
}
inst->bnctx = BN_CTX_new();
if (!inst->bnctx) {
- cf_log_err(cs, "Failed to get BN context");
+ cf_log_err(conf, "Failed to get BN context");
return -1;
}
return eap_session->process(p_result, mctx, request);
}
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- eap_aka_sim_module_conf_t *inst = talloc_get_type_abort(instance, eap_aka_sim_module_conf_t);
+ eap_aka_sim_module_conf_t *inst = talloc_get_type_abort(mctx->inst->data, eap_aka_sim_module_conf_t);
inst->type = rlm_eap_sim.provides[0];
RETURN_MODULE_HANDLED;
}
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance,
- UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_eap_tls_t *inst = talloc_get_type_abort(instance, rlm_eap_tls_t);
- rlm_eap_tls_thread_t *t = talloc_get_type_abort(thread, rlm_eap_tls_thread_t);
+ rlm_eap_tls_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_tls_t);
+ rlm_eap_tls_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_tls_thread_t);
t->ssl_ctx = fr_tls_ctx_alloc(inst->tls_conf, false);
if (!t->ssl_ctx) return -1;
return 0;
}
-static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- rlm_eap_tls_thread_t *t = talloc_get_type_abort(thread, rlm_eap_tls_thread_t);
+ rlm_eap_tls_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_tls_thread_t);
if (likely(t->ssl_ctx != NULL)) SSL_CTX_free(t->ssl_ctx);
t->ssl_ctx = NULL;
/*
* Attach the EAP-TLS module.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *cs)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_eap_tls_t *inst = talloc_get_type_abort(instance, rlm_eap_tls_t);
+ rlm_eap_tls_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_tls_t);
+ CONF_SECTION *conf = mctx->inst->conf;
- inst->tls_conf = eap_tls_conf_parse(cs, "tls");
+ inst->tls_conf = eap_tls_conf_parse(conf, "tls");
if (!inst->tls_conf) {
- cf_log_err(cs, "Failed initializing SSL context");
+ cf_log_err(conf, "Failed initializing SSL context");
return -1;
}
if (inst->virtual_server && !virtual_server_find(inst->virtual_server)) {
- cf_log_err_by_child(cs, "virtual_server", "Unknown virtual server '%s'", inst->virtual_server);
+ cf_log_err_by_child(conf, "virtual_server", "Unknown virtual server '%s'", inst->virtual_server);
return -1;
}
RETURN_MODULE_OK;
}
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance,
- UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_eap_ttls_t *inst = talloc_get_type_abort(instance, rlm_eap_ttls_t);
- rlm_eap_ttls_thread_t *t = talloc_get_type_abort(thread, rlm_eap_ttls_thread_t);
+ rlm_eap_ttls_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_ttls_t);
+ rlm_eap_ttls_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_ttls_thread_t);
t->ssl_ctx = fr_tls_ctx_alloc(inst->tls_conf, false);
if (!t->ssl_ctx) return -1;
return 0;
}
-static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- rlm_eap_ttls_thread_t *t = talloc_get_type_abort(thread, rlm_eap_ttls_thread_t);
+ rlm_eap_ttls_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_ttls_thread_t);
if (likely(t->ssl_ctx != NULL)) SSL_CTX_free(t->ssl_ctx);
t->ssl_ctx = NULL;
/*
* Attach the module.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *cs)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_eap_ttls_t *inst = talloc_get_type_abort(instance, rlm_eap_ttls_t);
+ rlm_eap_ttls_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_ttls_t);
+ CONF_SECTION *conf = mctx->inst->conf;
if (!virtual_server_find(inst->virtual_server)) {
- cf_log_err_by_child(cs, "virtual_server", "Unknown virtual server '%s'", inst->virtual_server);
+ cf_log_err_by_child(conf, "virtual_server", "Unknown virtual server '%s'", inst->virtual_server);
return -1;
}
* Read tls configuration, either from group given by 'tls'
* option, or from the eap-tls configuration.
*/
- inst->tls_conf = eap_tls_conf_parse(cs, "tls");
+ inst->tls_conf = eap_tls_conf_parse(conf, "tls");
if (!inst->tls_conf) {
- cf_log_err(cs, "Failed initializing SSL context");
+ cf_log_err(conf, "Failed initializing SSL context");
return -1;
}
* Define a structure for our module configuration.
*/
typedef struct {
- char const *name;
char const *allowed_chars;
} rlm_escape_t;
* that must be referenced in later calls, store a handle to it
* in *instance otherwise put a null pointer there.
*/
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_escape_t *inst = instance;
+ rlm_escape_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_escape_t);
char *unescape;
xlat_t *xlat;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- MEM(unescape = talloc_asprintf(NULL, "un%s", inst->name));
- xlat = xlat_register(NULL, inst->name, escape_xlat, false);
+ MEM(unescape = talloc_asprintf(NULL, "un%s", mctx->inst->name));
+ xlat = xlat_register(NULL, mctx->inst->name, escape_xlat, false);
xlat_func_mono(xlat, &escape_xlat_arg);
xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_escape_t *, NULL, inst);
*/
RCSID("$Id$")
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX mctx->inst->name
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module.h>
* Define a structure for our module configuration.
*/
typedef struct {
- char const *name;
bool wait;
char const *program;
char const *input;
* that must be referenced in later calls, store a handle to it
* in *instance otherwise put a null pointer there.
*/
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- char const *p;
- rlm_exec_t *inst = instance;
+ rlm_exec_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_exec_t);
+ CONF_SECTION *conf = mctx->inst->conf;
xlat_t *xlat;
+ char const *p;
- inst->name = cf_section_name2(conf);
- if (!inst->name) {
- inst->name = cf_section_name1(conf);
- }
-
- xlat = xlat_register(NULL, inst->name, exec_xlat, true);
+ xlat = xlat_register(NULL, mctx->inst->name, exec_xlat, true);
xlat_func_args(xlat, exec_xlat_args);
xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_exec_t *, NULL, inst);
*
* Creates a new instance of the module reading parameters from a configuration section.
*
- * @param conf to parse.
- * @param instance configuration data.
+ * @param[in] mctx to parse.
* @return
* - 0 on success.
* - < 0 on failure.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_exec_t *inst = instance;
+ rlm_exec_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_exec_t);
+ CONF_SECTION *conf = mctx->inst->conf;
ssize_t slen;
if (!inst->program) return 0;
#include "rlm_expr.h"
-/*
- * Define a structure for our module configuration.
- */
-typedef struct {
- char const *name;
-} rlm_expr_t;
-
/** Calculate powers
*
* @author Orson Peters
* that must be referenced in later calls, store a handle to it
* in *instance otherwise put a null pointer there.
*/
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_expr_t *inst = instance;
xlat_t *xlat;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- xlat = xlat_register(inst, inst->name, expr_xlat, false);
+ xlat = xlat_register(mctx->inst->data, mctx->inst->name, expr_xlat, false);
xlat_func_mono(xlat, &expr_xlat_arg);
return 0;
module_t rlm_expr = {
.magic = RLM_MODULE_INIT,
.name = "expr",
- .inst_size = sizeof(rlm_expr_t),
.bootstrap = mod_bootstrap,
};
/*
* (Re-)read the "users" file into memory.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_files_t *inst = instance;
+ rlm_files_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_files_t);
inst->key_data_type = tmpl_expanded_type(inst->key);
if (fr_htrie_hint(inst->key_data_type) == FR_HTRIE_INVALID) {
- cf_log_err(conf, "Invalid data type '%s' for 'files' module.",
+ cf_log_err(mctx->inst->conf, "Invalid data type '%s' for 'files' module.",
fr_table_str_by_value(fr_value_box_type_table, inst->key_data_type, "???"));
return -1;
}
*/
RCSID("$Id$")
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX mctx->inst->name
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module.h>
* Define a structure for our module configuration.
*/
typedef struct {
- char const *name;
char const *interface;
fr_time_delta_t timeout;
fr_ipaddr_t src_ipaddr;
} rlm_icmp_t;
typedef struct {
- rlm_icmp_t *inst;
fr_rb_tree_t *tree;
int fd;
- fr_event_list_t *el;
uint32_t data;
uint16_t ident;
* Start off with the IPv6 pseudo-header checksum
*/
if (thread->t->ipaddr_type == FR_TYPE_IPV6_ADDR) {
- checksum = fr_ip6_pesudo_header_checksum(&thread->t->inst->src_ipaddr.addr.v6, &echo->ip->vb_ip.addr.v6,
+ checksum = fr_ip6_pesudo_header_checksum(&inst->src_ipaddr.addr.v6, &echo->ip->vb_ip.addr.v6,
sizeof(ip_header6_t) + sizeof(icmp), IPPROTO_ICMPV6);
}
return CMP(a->counter, b->counter);
}
-static void mod_icmp_read(UNUSED fr_event_list_t *el, UNUSED int sockfd, UNUSED int flags, void *ctx)
+static void mod_icmp_read(UNUSED fr_event_list_t *el, UNUSED int sockfd, UNUSED int flags, void *uctx)
{
- rlm_icmp_thread_t *t = talloc_get_type_abort(ctx, rlm_icmp_thread_t);
- rlm_icmp_t *inst = t->inst;
- ssize_t len;
- icmp_header_t *icmp;
- rlm_icmp_echo_t my_echo, *echo;
- uint64_t buffer[256];
+ module_thread_inst_ctx_t const *mctx = talloc_get_type_abort(uctx, module_thread_inst_ctx_t);
+ rlm_icmp_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_icmp_thread_t);
+
+ ssize_t len;
+ icmp_header_t *icmp;
+ rlm_icmp_echo_t my_echo, *echo;
+ uint64_t buffer[256];
len = read(t->fd, (char *) buffer, sizeof(buffer));
if (len <= 0) return;
}
static void mod_icmp_error(fr_event_list_t *el, UNUSED int sockfd, UNUSED int flags,
- UNUSED int fd_errno, void *ctx)
+ UNUSED int fd_errno, void *uctx)
{
- rlm_icmp_thread_t *t = talloc_get_type_abort(ctx, rlm_icmp_thread_t);
- rlm_icmp_t *inst = t->inst;
+ module_ctx_t const *mctx = talloc_get_type_abort(uctx, module_ctx_t);
+ rlm_icmp_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_icmp_thread_t);
ERROR("Failed reading from ICMP socket - Closing it");
/** Instantiate thread data for the submodule.
*
*/
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
+ module_thread_inst_ctx_t *our_mctx;
+ rlm_icmp_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_icmp_t);
+ rlm_icmp_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_icmp_thread_t);
+ fr_ipaddr_t ipaddr, *src;
+
int fd, af, proto;
- rlm_icmp_t *inst = talloc_get_type_abort(instance, rlm_icmp_t);
- rlm_icmp_thread_t *t = talloc_get_type_abort(thread, rlm_icmp_thread_t);
- fr_ipaddr_t ipaddr, *src;
+
+ /*
+ * Create a copy of the mctx on the heap that we can
+ * pass as the uctx to the io functions.
+ */
+ MEM(our_mctx = talloc_zero(t, module_thread_inst_ctx_t));
+ memcpy(our_mctx, mctx, sizeof(*our_mctx));
MEM(t->tree = fr_rb_inline_alloc(t, rlm_icmp_echo_t, node, echo_cmp, NULL));
- t->inst = inst;
- t->el = el;
/*
* Since these fields are random numbers, we don't care
* We assume that the outbound socket is always writable.
* If not, too bad. Packets will get lost.
*/
- if (fr_event_fd_insert(t, el, fd,
+ if (fr_event_fd_insert(t, mctx->el, fd,
mod_icmp_read,
NULL,
mod_icmp_error,
- t) < 0) {
+ our_mctx) < 0) {
fr_strerror_const_push("Failed adding socket to event loop");
close(fd);
return -1;
return 0;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_icmp_t *inst = instance;
+ rlm_icmp_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_icmp_t);
xlat_t *xlat;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- xlat = xlat_register(inst, inst->name, xlat_icmp, true);
+ xlat = xlat_register(inst, mctx->inst->name, xlat_icmp, true);
xlat_func_args(xlat, xlat_icmp_args);
xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_icmp_t *, NULL, inst);
xlat_async_thread_instantiate_set(xlat, mod_xlat_thread_instantiate, xlat_icmp_thread_inst_t, NULL, inst);
/** Destroy thread data for the submodule.
*
*/
-static int mod_thread_detach(fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- rlm_icmp_thread_t *t = talloc_get_type_abort(thread, rlm_icmp_thread_t);
+ rlm_icmp_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_icmp_thread_t);
if (t->fd < 0) return 0;
- (void) fr_event_fd_delete(el, t->fd, FR_EVENT_FILTER_IO);
+ (void) fr_event_fd_delete(mctx->el, t->fd, FR_EVENT_FILTER_IO);
close(t->fd);
t->fd = -1;
* Structure for module configuration
*/
typedef struct {
- char const *name;
bool use_std3_ascii_rules;
bool allow_unassigned;
} rlm_idn_t;
return XLAT_ACTION_DONE;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_idn_t *inst = instance;
+ rlm_idn_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_idn_t);
xlat_t *xlat;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- xlat = xlat_register(inst, inst->name, xlat_idna, false);
+ xlat = xlat_register(inst, mctx->inst->name, xlat_idna, false);
xlat_func_mono(xlat, &xlat_idna_arg);
xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_idn_t *, NULL, inst);
} rlm_imap_t;
typedef struct {
- rlm_imap_t const *inst; //!< Instance of rlm_imap.
fr_curl_handle_t *mhandle; //!< Thread specific multi handle. Serves as the dispatch and coralling structure for imap requests.
} rlm_imap_thread_t;
/*
* Initialize a new thread with a curl instance
*/
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instance, fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_imap_thread_t *t = thread;
+ rlm_imap_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_imap_thread_t);
fr_curl_handle_t *mhandle;
- t->inst = instance;
-
- mhandle = fr_curl_io_init(t, el, false);
+ mhandle = fr_curl_io_init(t, mctx->el, false);
if (!mhandle) return -1;
t->mhandle = mhandle;
/*
* Close the thread and free the memory
*/
-static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- rlm_imap_thread_t *t = thread;
+ rlm_imap_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_imap_thread_t);
- talloc_free(t->mhandle);
- return 0;
+ talloc_free(t->mhandle);
+ return 0;
}
/*
* be used as the instance handle.
*/
typedef struct {
- char const *name;
char const *filename;
bool debug;
bool pedantic;
return 1;
}
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- int ret;
- rlm_isc_dhcp_t *inst = instance;
- rlm_isc_dhcp_info_t *info;
-
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
+ rlm_isc_dhcp_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_isc_dhcp_t);
+ CONF_SECTION *conf = mctx->inst->conf;
+ rlm_isc_dhcp_info_t *info;
+ int ret;
- inst->head = info = talloc_zero(inst, rlm_isc_dhcp_info_t);
+ MEM(inst->head = info = talloc_zero(inst, rlm_isc_dhcp_info_t));
fr_pair_list_init(&info->options);
info->last = &(info->child);
*
*/
typedef struct {
- char const *name;
fr_json_format_t *format;
} rlm_json_t;
return rcode;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_json_t *inst = talloc_get_type_abort(instance, rlm_json_t);
+ rlm_json_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_json_t);
+ CONF_SECTION *conf = mctx->inst->conf;
xlat_t *xlat;
char *name;
fr_json_format_t *format = inst->format;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- xlat = xlat_register(instance, "jsonquote", json_quote_xlat, false);
+ xlat = xlat_register(inst, "jsonquote", json_quote_xlat, false);
if (xlat) xlat_func_mono(xlat, &json_quote_xlat_arg);
- xlat = xlat_register(instance, "jpathvalidate", jpath_validate_xlat, false);
+ xlat = xlat_register(inst, "jpathvalidate", jpath_validate_xlat, false);
if (xlat) xlat_func_mono(xlat, &jpath_validate_xlat_arg);
- name = talloc_asprintf(inst, "%s_encode", inst->name);
- xlat = xlat_register(instance, name, json_encode_xlat, false);
+ name = talloc_asprintf(inst, "%s_encode", mctx->inst->name);
+ xlat = xlat_register(inst, name, json_encode_xlat, false);
xlat_func_mono(xlat, &json_encode_xlat_arg);
xlat_async_instantiate_set(xlat, json_xlat_instantiate,
rlm_json_t *, NULL, inst);
}
fr_json_format_verify(format, true);
- if (map_proc_register(instance, "json", mod_map_proc,
+ if (map_proc_register(inst, "json", mod_map_proc,
mod_map_proc_instantiate, sizeof(rlm_json_jpath_cache_t)) < 0) return -1;
return 0;
}
{ NULL }
};
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t const *mctx)
{
- rlm_krb5_t *inst = instance;
+ rlm_krb5_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_krb5_t);
#ifndef HEIMDAL_KRB5
talloc_free(inst->vic_options);
return 0;
}
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_krb5_t *inst = instance;
+ rlm_krb5_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_krb5_t);
krb5_error_code ret;
#ifndef HEIMDAL_KRB5
krb5_keytab keytab;
#endif
}
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
ret = krb5_init_context(&inst->context);
if (ret) {
ERROR("Context initialisation failed: %s", rlm_krb5_error(inst, NULL, ret));
/*
* Initialize the socket pool.
*/
- inst->pool = module_connection_pool_init(conf, inst, krb5_mod_conn_create, NULL, NULL, NULL, NULL);
+ inst->pool = module_connection_pool_init(mctx->inst->conf, inst, krb5_mod_conn_create, NULL, NULL, NULL, NULL);
if (!inst->pool) return -1;
#else
inst->conn = krb5_mod_conn_create(inst, inst, fr_time_delta_wrap(0));
if (fr_ldap_map_do(request, handle, inst->valuepair_attr,
&expanded, entry) > 0) rcode = RLM_MODULE_UPDATED;
REXDENT();
- rlm_ldap_check_reply(inst, request, ttrunk);
+ rlm_ldap_check_reply(mctx, request, ttrunk);
}
finish:
/** Detach from the LDAP server and cleanup internal state.
*
*/
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t const *mctx)
{
- rlm_ldap_t *inst = instance;
+ rlm_ldap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_ldap_t);
#ifdef HAVE_LDAP_CREATE_SORT_CONTROL
if (inst->userobj_sort_ctrl) ldap_control_free(inst->userobj_sort_ctrl);
*
* Allocate a new ldap_acct_section_t and write the config data into it.
*
- * @param[in] inst rlm_ldap configuration.
+ * @param[in] mctx rlm_ldap configuration.
* @param[in] parent of the config section.
* @param[out] config to write the sub section parameters to.
* @param[in] comp The section name were parsing the config for.
* - 0 on success.
* - < 0 on failure.
*/
-static int parse_sub_section(rlm_ldap_t *inst, CONF_SECTION *parent, ldap_acct_section_t **config,
+static int parse_sub_section(module_inst_ctx_t const *mctx,
+ CONF_SECTION *parent, ldap_acct_section_t **config,
rlm_components_t comp)
{
- CONF_SECTION *cs;
+ rlm_ldap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_ldap_t);
+ CONF_SECTION *cs;
char const *name = section_type_value[comp];
cs = cf_section_find(parent, name, NULL);
if (!cs) {
DEBUG2("rlm_ldap (%s) - Couldn't find configuration for %s, will return NOOP for calls "
- "from this section", inst->name, name);
+ "from this section", mctx->inst->name, name);
return 0;
}
*config = talloc_zero(inst, ldap_acct_section_t);
if (cf_section_parse(*config, *config, cs) < 0) {
- PERROR("rlm_ldap (%s) - Failed parsing configuration for section %s", inst->name, name);
+ PERROR("rlm_ldap (%s) - Failed parsing configuration for section %s", mctx->inst->name, name);
return -1;
}
/** Initialise thread specific data structure
*
*/
-static int mod_thread_instatiate(UNUSED CONF_SECTION const *conf, void *instance,
- fr_event_list_t *el, void *thread)
+static int mod_thread_instatiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_ldap_t *inst = instance;
- fr_ldap_thread_t *this_thread = thread;
+ rlm_ldap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_ldap_t);
+ fr_ldap_thread_t *t = talloc_get_type_abort(mctx->thread, fr_ldap_thread_t);
fr_ldap_thread_trunk_t *ttrunk;
/*
* Initialise tree for connection trunks used by this thread
*/
- MEM(this_thread->trunks = fr_rb_inline_talloc_alloc(this_thread, fr_ldap_thread_trunk_t, node, fr_ldap_trunk_cmp, NULL));
+ MEM(t->trunks = fr_rb_inline_talloc_alloc(t, fr_ldap_thread_trunk_t, node, fr_ldap_trunk_cmp, NULL));
- this_thread->config = &inst->handle_config;
- this_thread->trunk_conf = &inst->trunk_conf;
- this_thread->el = el;
+ t->config = &inst->handle_config;
+ t->trunk_conf = &inst->trunk_conf;
+ t->el = mctx->el;
/*
* Launch trunk for module default connection
*/
- ttrunk = fr_thread_ldap_trunk_get(this_thread, inst->handle_config.server, inst->handle_config.admin_identity,
+ ttrunk = fr_thread_ldap_trunk_get(t, inst->handle_config.server, inst->handle_config.admin_identity,
inst->handle_config.admin_password, NULL, &inst->handle_config);
if (!ttrunk) {
ERROR("Unable to launch LDAP trunk");
/*
* Set up a per-thread LDAP connection to use for bind auths
*/
- this_thread->conn = fr_ldap_connection_state_alloc(this_thread, el, this_thread->config, inst->name);
- fr_connection_add_watch_post(this_thread->conn, FR_CONNECTION_STATE_CONNECTED, _ldap_async_bind_auth_watch, false, this_thread);
- fr_connection_signal_init(this_thread->conn);
+ t->conn = fr_ldap_connection_state_alloc(t, mctx->el, t->config, mctx->inst->name);
+ fr_connection_add_watch_post(t->conn, FR_CONNECTION_STATE_CONNECTED, _ldap_async_bind_auth_watch, false, t);
+ fr_connection_signal_init(t->conn);
- MEM(this_thread->binds = fr_rb_inline_talloc_alloc(this_thread, fr_ldap_bind_auth_ctx_t, node, fr_ldap_bind_auth_cmp, NULL));
+ MEM(t->binds = fr_rb_inline_talloc_alloc(t, fr_ldap_bind_auth_ctx_t, node, fr_ldap_bind_auth_cmp, NULL));
return 0;
}
/** Clean up thread specific data structure
*
*/
-static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- fr_ldap_thread_t *this_thread = thread;
+ fr_ldap_thread_t *t = talloc_get_type_abort(mctx->thread, fr_ldap_thread_t);
void **trunks_to_free;
int i;
- if (fr_rb_flatten_inorder(NULL, &trunks_to_free, this_thread->trunks) < 0) return -1;
+ if (fr_rb_flatten_inorder(NULL, &trunks_to_free, t->trunks) < 0) return -1;
for (i = talloc_array_length(trunks_to_free) - 1; i >= 0; i--) talloc_free(trunks_to_free[i]);
talloc_free(trunks_to_free);
- talloc_free(this_thread->trunks);
+ talloc_free(t->trunks);
return 0;
}
*
* Define attributes.
*
- * @param conf to parse.
- * @param instance configuration data.
+ * @param[in] mctx configuration data.
* @return
* - 0 on success.
* - < 0 on failure.
*/
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_ldap_t *inst = instance;
+ rlm_ldap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_ldap_t);
+ CONF_SECTION *conf = mctx->inst->conf;
char buffer[256];
char const *group_attribute;
xlat_t *xlat;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- inst->handle_config.name = talloc_typed_asprintf(inst, "rlm_ldap (%s)", inst->name);
+ inst->handle_config.name = talloc_typed_asprintf(inst, "rlm_ldap (%s)", mctx->inst->name);
if (inst->group_attribute) {
group_attribute = inst->group_attribute;
} else if (cf_section_name2(conf)) {
- snprintf(buffer, sizeof(buffer), "%s-LDAP-Group", inst->name);
+ snprintf(buffer, sizeof(buffer), "%s-LDAP-Group", mctx->inst->name);
group_attribute = buffer;
} else {
group_attribute = "LDAP-Group";
inst->cache_da = inst->group_da; /* Default to the group_da */
}
- xlat = xlat_register(NULL, inst->name, ldap_xlat, false);
+ xlat = xlat_register(NULL, mctx->inst->name, ldap_xlat, false);
xlat_func_mono(xlat, &ldap_xlat_arg);
xlat_async_thread_instantiate_set(xlat, mod_xlat_thread_instantiate, ldap_xlat_thread_inst_t, NULL, inst);
xlat = xlat_register(NULL, "ldap_unescape", ldap_unescape_xlat, false);
if (xlat) xlat_func_mono(xlat, &ldap_escape_xlat_arg);
- map_proc_register(inst, inst->name, mod_map_proc, ldap_map_verify, 0);
+ map_proc_register(inst, mctx->inst->name, mod_map_proc, ldap_map_verify, 0);
return 0;
}
*
* Creates a new instance of the module reading parameters from a configuration section.
*
- * @param conf to parse.
- * @param instance configuration data.
+ * @param [in] mctx configuration data.
* @return
* - 0 on success.
* - < 0 on failure.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
size_t i;
CONF_SECTION *options, *update;
- rlm_ldap_t *inst = instance;
+ rlm_ldap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_ldap_t);
+ CONF_SECTION *conf = mctx->inst->conf;
fr_map_list_init(&inst->user_map);
/*
* If the configuration parameters can't be parsed, then fail.
*/
- if ((parse_sub_section(inst, conf, &inst->accounting, MOD_ACCOUNTING) < 0) ||
- (parse_sub_section(inst, conf, &inst->postauth, MOD_POST_AUTH) < 0)) {
+ if ((parse_sub_section(mctx, conf, &inst->accounting, MOD_ACCOUNTING) < 0) ||
+ (parse_sub_section(mctx, conf, &inst->postauth, MOD_POST_AUTH) < 0)) {
cf_log_err(conf, "Failed parsing configuration");
goto error;
*/
if (inst->handle_config.server) {
inst->handle_config.server[talloc_array_length(inst->handle_config.server) - 2] = '\0';
- DEBUG4("rlm_ldap (%s) - LDAP server string: %s", inst->name, inst->handle_config.server);
+ DEBUG4("rlm_ldap (%s) - LDAP server string: %s", mctx->inst->name, inst->handle_config.server);
}
#ifdef LDAP_OPT_X_TLS_NEVER
} ldap_acct_section_t;
typedef struct {
- char const *name; //!< Instance name.
-
bool expect_password; //!< True if the user_map included a mapping between an LDAP
//!< attribute and one of our password reference attributes.
rlm_rcode_t rlm_ldap_check_access(rlm_ldap_t const *inst, request_t *request, LDAP *handle, LDAPMessage *entry);
-void rlm_ldap_check_reply(rlm_ldap_t const *inst, request_t *request, fr_ldap_thread_trunk_t const *ttrunk);
+void rlm_ldap_check_reply(module_ctx_t const *mctx, request_t *request, fr_ldap_thread_trunk_t const *ttrunk);
/*
* groups.c - Group membership functions.
#include <freeradius-devel/util/debug.h>
#include <ctype.h>
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX mctx->inst->name
#include "rlm_ldap.h"
*
* Checks to see if after the LDAP to RADIUS mapping has been completed that a reference password.
*
- * @param inst rlm_ldap configuration.
- * @param request Current request.
- * @param ttrunk the connection thread trunk.
+ * @param[in] mctx rlm_ldap configuration.
+ * @param[in] request Current request.
+ * @param[in] ttrunk the connection thread trunk.
*/
-void rlm_ldap_check_reply(rlm_ldap_t const *inst, request_t *request, fr_ldap_thread_trunk_t const *ttrunk)
+void rlm_ldap_check_reply(module_ctx_t const *mctx, request_t *request, fr_ldap_thread_trunk_t const *ttrunk)
{
+ rlm_ldap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_ldap_t);
+
/*
* More warning messages for people who can't be bothered to read the documentation.
*
RWDEBUG2("!!! - Configure authentication via wbclient (mschapv2 only)");
RWDEBUG2("!!! that password attribute");
RWDEBUG2("!!! - Bind as the user by listing %s in the authenticate section, and",
- inst->name);
+ mctx->inst->name);
RWDEBUG2("!!! setting attribute &control.Auth-Type := '%s' in the authorize section",
- inst->name);
+ mctx->inst->name);
RWDEBUG2("!!! (pap only)");
break;
RWDEBUG2("!!! eDir server (recommended)");
RWDEBUG2("!!! that password attribute");
RWDEBUG2("!!! - Bind as the user by listing %s in the authenticate section, and",
- inst->name);
+ mctx->inst->name);
RWDEBUG2("!!! setting attribute &control.Auth-Type := '%s' in the authorize section",
- inst->name);
+ mctx->inst->name);
RWDEBUG("!!! (pap only)");
break;
RWDEBUG2("!!! \"%s\" has permission to read that password attribute (recommended)",
ttrunk->config.admin_identity);
RWDEBUG2("!!! - Bind as the user by listing %s in the authenticate section, and",
- inst->name);
+ mctx->inst->name);
RWDEBUG2("!!! setting attribute &control.Auth-Type := '%s' in the authorize section",
- inst->name);
+ mctx->inst->name);
RWDEBUG2("!!! (pap only)");
} else {
RWDEBUG2("!!! No \"known good\" password added");
RWDEBUG2("!!! 'identity' is set to the DN of an account that has permission to read");
RWDEBUG2("!!! that password attribute");
RWDEBUG2("!!! - Bind as the user by listing %s in the authenticate section, and",
- inst->name);
+ mctx->inst->name);
RWDEBUG2("!!! setting attribute &control.Auth-Type := '%s' in the authorize section",
- inst->name);
+ mctx->inst->name);
RWDEBUG2("!!! (pap only)");
}
break;
/** linelog module instance
*/
typedef struct {
- char const *name; //!< Module instance name.
fr_pool_t *pool; //!< Connection pool instance.
char const *delimiter; //!< Line termination string (usually \n).
static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
{
- rlm_linelog_t const *inst = instance;
- linelog_conn_t *conn;
- int sockfd = -1;
+ rlm_linelog_t const *inst = talloc_get_type_abort(instance, rlm_linelog_t const);
+ linelog_conn_t *conn;
+ int sockfd = -1;
switch (inst->log_dst) {
case LINELOG_DST_UNIX:
return conn;
}
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t const *mctx)
{
- rlm_linelog_t *inst = instance;
+ rlm_linelog_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_linelog_t);
fr_pool_free(inst->pool);
/*
* Instantiate the module.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_linelog_t *inst = instance;
+ rlm_linelog_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_linelog_t);
+ CONF_SECTION *conf = mctx->inst->conf;
char prefix[100];
/*
return -1;
}
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- snprintf(prefix, sizeof(prefix), "rlm_linelog (%s)", inst->name);
+ snprintf(prefix, sizeof(prefix), "rlm_linelog (%s)", mctx->inst->name);
/*
* Setup the logging destination
* that must be referenced in later calls, store a handle to it
* in *instance otherwise put a null pointer there.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_logintime_t *inst = instance;
+ rlm_logintime_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_logintime_t);
+ CONF_SECTION *conf = mctx->inst->conf;
if (!fr_time_delta_ispos(inst->min_time)) {
cf_log_err(conf, "Invalid value '0' for minimum_timeout");
/** Create thread-specific connections and buffers
*
- * @param[in] conf section containing the configuration of this module instance.
- * @param[in] instance of rlm_logtee_t.
- * @param[in] el The event list serviced by this thread.
- * @param[in] thread specific data.
+ * @param[in] mctx specific data.
* @return
* - 0 on success.
* - -1 on failure.
*/
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instance, fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_logtee_t *inst = talloc_get_type_abort(instance, rlm_logtee_t);
- rlm_logtee_thread_t *t = talloc_get_type_abort(thread, rlm_logtee_thread_t);
+ rlm_logtee_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_logtee_t);
+ rlm_logtee_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_logtee_thread_t);
MEM(t->fring = fr_fring_alloc(t, inst->buffer_depth, false));
t->inst = inst;
- t->el = el;
+ t->el = mctx->el;
/*
* Pre-allocate temporary attributes
/*
* This opens the outbound connection
*/
- t->conn = fr_connection_alloc(t, el,
+ t->conn = fr_connection_alloc(t, t->el,
&(fr_connection_funcs_t){
.init = _logtee_conn_init,
.open = _logtee_conn_open,
/*
* Instantiate the module.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_logtee_t *inst = instance;
+ rlm_logtee_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_logtee_t);
+ CONF_SECTION *conf = mctx->inst->conf;
char prefix[100];
/*
return -1;
}
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
snprintf(prefix, sizeof(prefix), "rlm_logtee (%s)", inst->name);
FR_SIZE_BOUND_CHECK("buffer_depth", inst->buffer_depth, >=, (size_t)1);
*/
RCSID("$Id$")
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX mctx->inst->name
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/util/debug.h>
*/
static int _lua_pair_set(lua_State *L)
{
- rlm_lua_t const *inst = fr_lua_util_get_inst();
- request_t *request = fr_lua_util_get_request();
+ module_ctx_t const *mctx = fr_lua_util_get_mctx();
+ rlm_lua_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_lua_t);
+ request_t *request = fr_lua_util_get_request();
fr_dcursor_t cursor;
fr_dict_attr_t const *da;
fr_pair_t *vp = NULL, *new;
lua_Integer index;
bool delete = false;
-
/*
* This function should only be called as a closure.
* As we control the upvalues, we should assert on errors.
*
* Also check what was loaded there is a function and that it accepts the correct arguments.
*
- * @param inst Current instance of fr_lua
- * @param L the lua state
- * @param name of function to check.
+ * @param[in] mctx module instantiation data.
+ * @param[in] L the lua state.
+ * @param[in] name of function to check.
* @returns 0 on success (function is present and correct), or -1 on failure.
*/
-static int fr_lua_check_func(rlm_lua_t const *inst, lua_State *L, char const *name)
+static int fr_lua_check_func(module_inst_ctx_t const *mctx, lua_State *L, char const *name)
{
int ret;
int type;
unlang_action_t fr_lua_run(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request, char const *funcname)
{
- rlm_lua_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_lua_t);
rlm_lua_thread_t *thread = talloc_get_type_abort(mctx->thread, rlm_lua_thread_t);
lua_State *L = thread->interpreter;
rlm_rcode_t rcode = RLM_MODULE_OK;
- fr_lua_util_set_inst(inst);
+ fr_lua_util_set_mctx(mctx);
fr_lua_util_set_request(request);
ROPTIONAL(RDEBUG2, DEBUG2, "Calling %s() in interpreter %p", funcname, L);
*/
if (fr_lua_get_field(L, request, funcname) < 0) {
error:
- fr_lua_util_set_inst(NULL);
+ fr_lua_util_set_mctx(NULL);
fr_lua_util_set_request(NULL);
RETURN_MODULE_FAIL;
}
done:
- fr_lua_util_set_inst(NULL);
+ fr_lua_util_set_mctx(NULL);
fr_lua_util_set_request(NULL);
RETURN_MODULE_RCODE(rcode);
* Creates a new lua_State and verifies all required functions have been loaded correctly.
*
* @param[in] out Where to write a pointer to the new state.
- * @param[in] instance Current instance of fr_lua, a talloc marker
- * context will be inserted into the context of instance
- * to ensure the interpreter is freed when instance data is freed.
+ * @parma[in] mctx configuration data for the
* @return 0 on success else -1.
*/
-int fr_lua_init(lua_State **out, rlm_lua_t const *instance)
+int fr_lua_init(lua_State **out, module_inst_ctx_t const *mctx)
{
- rlm_lua_t const *inst = talloc_get_type_abort_const(instance, rlm_lua_t);
+ rlm_lua_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_lua_t);
lua_State *L;
- fr_lua_util_set_inst(inst);
+ fr_lua_util_set_mctx(&(module_ctx_t){ .inst = mctx->inst });
L = luaL_newstate();
if (!L) {
error:
*out = NULL;
- fr_lua_util_set_inst(NULL);
+ fr_lua_util_set_mctx(NULL);
lua_close(L);
return -1;
}
*/
if (inst->jit) {
DEBUG4("Initialised new LuaJIT interpreter %p", L);
- if (fr_lua_util_jit_log_register(inst, L) < 0) goto error;
+ if (fr_lua_util_jit_log_register(L) < 0) goto error;
} else {
DEBUG4("Initialised new Lua interpreter %p", L);
- if (fr_lua_util_log_register(inst, L) < 0) goto error;
+ if (fr_lua_util_log_register(L) < 0) goto error;
}
/*
/*
* Verify all the functions were provided.
*/
- if (fr_lua_check_func(inst, L, inst->func_authorize)
- || fr_lua_check_func(inst, L, inst->func_authenticate)
- || fr_lua_check_func(inst, L, inst->func_preacct)
- || fr_lua_check_func(inst, L, inst->func_accounting)
- || fr_lua_check_func(inst, L, inst->func_post_auth)
- || fr_lua_check_func(inst, L, inst->func_instantiate)
- || fr_lua_check_func(inst, L, inst->func_detach)
- || fr_lua_check_func(inst, L, inst->func_xlat)) {
+ if (fr_lua_check_func(mctx, L, inst->func_authorize)
+ || fr_lua_check_func(mctx, L, inst->func_authenticate)
+ || fr_lua_check_func(mctx, L, inst->func_preacct)
+ || fr_lua_check_func(mctx, L, inst->func_accounting)
+ || fr_lua_check_func(mctx, L, inst->func_post_auth)
+ || fr_lua_check_func(mctx, L, inst->func_instantiate)
+ || fr_lua_check_func(mctx, L, inst->func_detach)
+ || fr_lua_check_func(mctx, L, inst->func_xlat)) {
goto error;
}
//!< basis, or use a single mutex protected interpreter.
bool jit; //!< Whether the linked interpreter is Lua 5.1 or LuaJIT.
- const char *name; //!< Name of this instance.
const char *module; //!< Full path to lua script to load and execute.
const char *func_instantiate; //!< Name of function to run on instantiation.
} rlm_lua_thread_t;
/* lua.c */
-int fr_lua_init(lua_State **out, rlm_lua_t const *instance);
+int fr_lua_init(lua_State **out, module_inst_ctx_t const *mctx);
unlang_action_t fr_lua_run(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request, char const *funcname);
bool fr_lua_isjit(lua_State *L);
char const *fr_lua_version(lua_State *L);
void fr_lua_util_jit_log_warn(char const *msg);
void fr_lua_util_jit_log_error(char const *msg);
-int fr_lua_util_jit_log_register(rlm_lua_t const *inst, lua_State *L);
-int fr_lua_util_log_register(rlm_lua_t const *inst, lua_State *L);
-void fr_lua_util_set_inst(rlm_lua_t const *inst);
-rlm_lua_t const *fr_lua_util_get_inst(void);
+int fr_lua_util_jit_log_register(lua_State *L);
+int fr_lua_util_log_register(lua_State *L);
+void fr_lua_util_set_mctx(module_ctx_t const *mctx);
+module_ctx_t const *fr_lua_util_get_mctx(void);
void fr_lua_util_set_request(request_t *request);
request_t *fr_lua_util_get_request(void);
void fr_lua_util_fr_register(lua_State *L);
*/
RCSID("$Id$")
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX mctx->inst->name
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/util/debug.h>
/** Free any thread specific interpreters
*
*/
-static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- rlm_lua_thread_t *this_thread = thread;
+ rlm_lua_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_lua_thread_t);
/*
* May be NULL if fr_lua_init failed
*/
- if (this_thread->interpreter) lua_close(this_thread->interpreter);
+ if (t->interpreter) lua_close(t->interpreter);
return 0;
}
/** Create thread-specific connections and buffers
*
- * @param[in] conf section containing the configuration of this module instance.
- * @param[in] instance of rlm_lua_t.
- * @param[in] el The event list serviced by this thread.
- * @param[in] thread specific data (where we write the interpreter).
+ * @param[in] mctx specific data (where we write the interpreter).
* @return
* - 0 on success.
* - -1 on failure.
*/
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instance,
- UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_lua_thread_t *this_thread = thread;
+ rlm_lua_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_lua_thread_t);
- if (fr_lua_init(&this_thread->interpreter, instance) < 0) return -1;
+ if (fr_lua_init(&t->interpreter, (module_inst_ctx_t const *)mctx) < 0) return -1;
return 0;
}
/** Close the global interpreter
*
*/
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t const *mctx)
{
- rlm_lua_t *inst = instance;
+ rlm_lua_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_lua_t);
rlm_rcode_t ret = 0;
/*
if (inst->interpreter) {
if (inst->func_detach) {
fr_lua_run(&ret, &(module_ctx_t){
- .inst = dl_module_instance_by_data(instance),
+ .inst = mctx->inst,
.thread = &(rlm_lua_thread_t){
.interpreter = inst->interpreter
}
return ret;
}
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_lua_t *inst = instance;
+ rlm_lua_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_lua_t);
rlm_rcode_t rcode;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
/*
* Get an instance global interpreter to use with various things...
*/
- if (fr_lua_init(&inst->interpreter, inst) < 0) return -1;
+ if (fr_lua_init(&inst->interpreter, mctx) < 0) return -1;
inst->jit = fr_lua_isjit(inst->interpreter);
if (!inst->jit) WARN("Using standard Lua interpreter, performance will be suboptimal");
if (inst->func_instantiate) {
fr_lua_run(&rcode, &(module_ctx_t){
- .inst = dl_module_instance_by_data(instance),
- .thread = &(rlm_lua_thread_t){
- .interpreter = inst->interpreter
- }
- },
+ .inst = mctx->inst,
+ .thread = &(rlm_lua_thread_t){
+ .interpreter = inst->interpreter
+ }
+ },
NULL, inst->func_instantiate);
}
*/
RCSID("$Id$")
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX fr_lua_mctx->inst->name
#include <freeradius-devel/server/base.h>
#include <lualib.h>
static _Thread_local request_t *fr_lua_request;
-static _Thread_local rlm_lua_t const *fr_lua_inst;
+static _Thread_local module_ctx_t const *fr_lua_mctx;
void fr_lua_util_fr_register(lua_State *L)
{
*/
static int _util_log_debug(lua_State *L)
{
- rlm_lua_t const *inst = fr_lua_inst;
- request_t *request = fr_lua_request;
+ request_t *request = fr_lua_request;
int idx;
while ((idx = lua_gettop(L))) {
*/
static int _util_log_info(lua_State *L)
{
- rlm_lua_t const *inst = fr_lua_inst;
- request_t *request = fr_lua_request;
+ request_t *request = fr_lua_request;
int idx;
while ((idx = lua_gettop(L))) {
*/
static int _util_log_warn(lua_State *L)
{
- rlm_lua_t const *inst = fr_lua_inst;
- request_t *request = fr_lua_request;
+ request_t *request = fr_lua_request;
int idx;
while ((idx = lua_gettop(L))) {
*/
static int _util_log_error(lua_State *L)
{
- rlm_lua_t const *inst = fr_lua_inst;
- request_t *request = fr_lua_request;
+ request_t *request = fr_lua_request;
int idx;
while ((idx = lua_gettop(L))) {
*/
void fr_lua_util_jit_log_debug(char const *msg)
{
- rlm_lua_t const *inst = fr_lua_inst;
- request_t *request = fr_lua_request;
+ request_t *request = fr_lua_request;
ROPTIONAL(RDEBUG2, DEBUG2, "%s", msg);
}
*/
void fr_lua_util_jit_log_info(char const *msg)
{
- rlm_lua_t const *inst = fr_lua_inst;
- request_t *request = fr_lua_request;
+ request_t *request = fr_lua_request;
ROPTIONAL(RINFO, INFO, "%s", msg);
}
*/
void fr_lua_util_jit_log_warn(char const *msg)
{
- rlm_lua_t const *inst = fr_lua_inst;
- request_t *request = fr_lua_request;
+ request_t *request = fr_lua_request;
ROPTIONAL(RWARN, WARN, "%s", msg);
}
*/
void fr_lua_util_jit_log_error(char const *msg)
{
- rlm_lua_t const *inst = fr_lua_inst;
- request_t *request = fr_lua_request;
+ request_t *request = fr_lua_request;
ROPTIONAL(RERROR, ERROR, "%s", msg);
}
* For LuaJIT using the FFI is significantly faster than the Lua interface.
* Help people wishing to use the FFI by inserting cdefs for standard functions.
*
- * @param inst Current instance of the fr_lua module.
* @param L Lua interpreter.
* @return 0 (no arguments).
*/
-int fr_lua_util_jit_log_register(rlm_lua_t const *inst, lua_State *L)
+int fr_lua_util_jit_log_register(lua_State *L)
{
char const *search_path;
char *lua_str;
int ret;
+ fr_assert(fr_lua_mctx);
+
search_path = dl_module_search_path();
lua_str = talloc_asprintf(NULL, "\
ffi = require(\"ffi\")\
/** Register utililiary functions in the lua environment
*
- * @param inst Current instance of the fr_lua module.
* @param L Lua interpreter.
* @return 0 (no arguments).
*/
-int fr_lua_util_log_register(UNUSED rlm_lua_t const *inst, lua_State *L)
+int fr_lua_util_log_register(lua_State *L)
{
/* fr.{} */
lua_getglobal(L, "fr");
/** Set the thread local instance
*
- * @param[in] inst all helper and C functions callable from Lua should use.
+ * @param[in] mctx all helper and C functions callable from Lua should use.
*/
-void fr_lua_util_set_inst(rlm_lua_t const *inst)
+void fr_lua_util_set_mctx(module_ctx_t const *mctx)
{
- fr_lua_inst = inst;
+ fr_lua_mctx = mctx;
}
/** Get the thread local instance
*
- * @return inst all helper and C functions callable from Lua should use.
+ * @return mctx all helper and C functions callable from Lua should use.
*/
-rlm_lua_t const *fr_lua_util_get_inst(void)
+module_ctx_t const *fr_lua_util_get_mctx(void)
{
- return fr_lua_inst;
+ return fr_lua_mctx;
}
/** Set the thread local request
* to external databases, read configuration files, set up
* dictionary entries, etc.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_mruby_t *inst = instance;
+ rlm_mruby_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_mruby_t);
mrb_state *mrb;
CONF_SECTION *cs;
FILE *f;
*/
static int mod_detach(void *instance)
{
- rlm_mruby_t *inst = instance;
+ rlm_mruby_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_mruby_t);
mrb_close(inst->mrb);
/* MPPE support from Takahiro Wagatsuma <waga@sic.shibaura-it.ac.jp> */
RCSID("$Id$")
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX mctx->inst->name
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/exec_legacy.h>
*/
static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, UNUSED fr_time_delta_t timeout)
{
- struct wbcContext **wb_ctx;
- rlm_mschap_t const *inst = talloc_get_type_abort_const(instance, rlm_mschap_t);
+ struct wbcContext **wb_ctx;
+ module_inst_ctx_t *mctx = &(module_inst_ctx_t){ .inst = dl_module_instance_by_data(instance) };
wb_ctx = talloc_zero(ctx, struct wbcContext *);
*wb_ctx = wbcCtxCreate();
if (!inst->auth_type) {
WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup MS-CHAP authentication",
- inst->name, inst->name);
+ mctx->inst->name, mctx->inst->name);
RETURN_MODULE_NOOP;
}
challenge = fr_pair_find_by_da_idx(&request->request_pairs, attr_ms_chap_challenge, 0);
if (!challenge) {
REDEBUG("&control.Auth-Type = %s set for a request that does not contain &%s",
- inst->name, attr_ms_chap_challenge->name);
+ mctx->inst->name, attr_ms_chap_challenge->name);
rcode = RLM_MODULE_INVALID;
goto finish;
}
if (rcode != RLM_MODULE_OK) goto finish;
} else { /* Neither CHAPv1 or CHAPv2 response: die */
REDEBUG("&control.Auth-Type = %s set for a request that does not contain &%s or &%s attributes",
- inst->name, attr_ms_chap_response->name, attr_ms_chap2_response->name);
+ mctx->inst->name, attr_ms_chap_response->name, attr_ms_chap2_response->name);
rcode = RLM_MODULE_INVALID;
goto finish;
}
* Create instance for our module. Allocate space for
* instance structure and read configuration parameters
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_mschap_t *inst = instance;
+ rlm_mschap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_mschap_t);
+ CONF_SECTION *conf = mctx->inst->conf;
- inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1);
+ inst->auth_type = fr_dict_enum_by_name(attr_auth_type, mctx->inst->name, -1);
if (!inst->auth_type) {
WARN("Failed to find 'authenticate %s {...}' section. MS-CHAP authentication will likely not work",
- inst->name);
+ mctx->inst->name);
}
/*
return 0;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_mschap_t *inst = instance;
+ rlm_mschap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_mschap_t);
xlat_t *xlat;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- xlat = xlat_register(inst, inst->name, mschap_xlat, false);
+ xlat = xlat_register(inst, mctx->inst->name, mschap_xlat, false);
xlat_func_args(xlat, mschap_xlat_args);
xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_mschap_t *, NULL, inst);
#ifndef WITH_AUTH_WINBIND
UNUSED
#endif
- void *instance)
+ module_detach_ctx_t const *mctx)
{
#ifdef WITH_AUTH_WINBIND
- rlm_mschap_t *inst = instance;
+ rlm_mschap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_mschap_t);
fr_pool_free(inst->wb_pool);
#endif
extern HIDDEN fr_dict_attr_t const *attr_ms_chap2_cpw;
typedef struct {
- char const *name;
- fr_dict_enum_value_t *auth_type;
+ fr_dict_enum_value_t *auth_type;
bool normify;
#include <membership.h>
typedef struct {
- char const *name; //!< Auth-Type value for this module instance.
fr_dict_enum_value_t *auth_type;
} rlm_opendirectory_t;
setup_auth_type:
if (!inst->auth_type) {
WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup OpenDirectory authentication",
- inst->name, inst->name);
+ mctx->inst->name, mctx->inst->name);
RETURN_MODULE_NOOP;
}
RETURN_MODULE_OK;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_opendirectory_t *inst = instance;
+ rlm_opendirectory_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_opendirectory_t);
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- return 0;
-}
-
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf)
-{
- rlm_opendirectory_t *inst = instance;
-
- inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1);
+ inst->auth_type = fr_dict_enum_by_name(attr_auth_type, mctx->inst->name, -1);
if (!inst->auth_type) {
WARN("Failed to find 'authenticate %s {...}' section. OpenDirectory authentication will likely not work",
- inst->name);
+ mctx->inst->name);
}
return 0;
.name = "opendirectory",
.inst_size = sizeof(rlm_opendirectory_t),
.type = RLM_TYPE_THREAD_SAFE,
- .bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.methods = {
[MOD_AUTHENTICATE] = mod_authenticate,
{ NULL }
};
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_pam_t *inst = instance;
+ rlm_pam_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_pam_t);
if (!inst->pam_auth_name) inst->pam_auth_name = main_config->name;
* be used as the instance handle.
*/
typedef struct {
- char const *name;
- fr_dict_enum_value_t *auth_type;
+ fr_dict_enum_value_t *auth_type;
bool normify;
} rlm_pap_t;
fr_pair_t *password;
if (fr_pair_find_by_da_idx(&request->control_pairs, attr_auth_type, 0) != NULL) {
- RDEBUG3("Auth-Type is already set. Not setting 'Auth-Type := %s'", inst->name);
+ RDEBUG3("Auth-Type is already set. Not setting 'Auth-Type := %s'", mctx->inst->name);
RETURN_MODULE_NOOP;
}
if (!inst->auth_type) {
WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup PAP authentication.",
- inst->name, inst->name);
+ mctx->inst->name, mctx->inst->name);
RETURN_MODULE_NOOP;
}
RETURN_MODULE_RCODE(rcode);
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- char const *name;
- rlm_pap_t *inst = instance;
+ rlm_pap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_pap_t);
- /*
- * Create the dynamic translation.
- */
- name = cf_section_name2(conf);
- if (!name) name = cf_section_name1(conf);
- inst->name = name;
-
- return 0;
-}
-
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *cs)
-{
- rlm_pap_t *inst = talloc_get_type_abort(instance, rlm_pap_t);
-
- inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1);
+ inst->auth_type = fr_dict_enum_by_name(attr_auth_type, mctx->inst->name, -1);
if (!inst->auth_type) {
WARN("Failed to find 'authenticate %s {...}' section. PAP will likely not work",
- inst->name);
+ mctx->inst->name);
}
return 0;
.onload = mod_load,
.unload = mod_unload,
.config = module_config,
- .bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.methods = {
[MOD_AUTHENTICATE] = mod_authenticate,
CONF_PARSER_TERMINATOR
};
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
int num_fields = 0, key_field = -1, listable = 0;
char const *s;
size_t len;
int i;
fr_dict_attr_t const *da;
- rlm_passwd_t *inst = instance;
+ rlm_passwd_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_passwd_t);
+ CONF_SECTION *conf = mctx->inst->conf;
fr_assert(inst->filename && *inst->filename);
fr_assert(inst->format && *inst->format);
#undef inst
}
-static int mod_detach (void *instance) {
-#define inst ((rlm_passwd_t *)instance)
- if(inst->ht) {
+static int mod_detach(module_detach_ctx_t const *mctx)
+{
+ rlm_passwd_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_passwd_t);
+ if (inst->ht) {
release_ht(inst->ht);
inst->ht = NULL;
}
talloc_free(inst->pwd_fmt);
return 0;
-#undef inst
}
static void result_add(TALLOC_CTX *ctx, rlm_passwd_t const *inst, request_t *request,
* be used as the instance handle.
*/
typedef struct {
- char const *name;
-
/* Name of the perl module */
char const *module;
DEBUG("%*s}", indent_section, " ");
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_perl_t *inst = instance;
+ rlm_perl_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_perl_t);
xlat_t *xlat;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- xlat = xlat_register(NULL, inst->name, perl_xlat, false);
+ xlat = xlat_register(NULL, mctx->inst->name, perl_xlat, false);
xlat_func_args(xlat, perl_xlat_args);
xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_perl_xlat_t, NULL, inst);
* Store all vps in hashes %RAD_CONFIG %RAD_REPLY %RAD_REQUEST
*
*/
-static unlang_action_t do_perl(rlm_rcode_t *p_result, void *instance, request_t *request,
+static unlang_action_t do_perl(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request,
PerlInterpreter *interp, char const *function_name)
{
- rlm_perl_t *inst = instance;
+ rlm_perl_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_perl_t);
fr_pair_list_t vps;
int ret=0, count;
STRLEN n_a;
static unlang_action_t CC_HINT(nonnull) mod_##_x(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request) \
{ \
rlm_perl_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_perl_t); \
- return do_perl(p_result, inst, request, \
+ return do_perl(p_result, mctx, request, \
((rlm_perl_thread_t *)talloc_get_type_abort(mctx->thread, rlm_perl_thread_t))->perl, \
inst->func_##_x); \
}
break;
}
- return do_perl(p_result, inst, request,
+ return do_perl(p_result, mctx, request,
((rlm_perl_thread_t *)talloc_get_type_abort(mctx->thread, rlm_perl_thread_t))->perl, func);
}
DIAG_ON(shadow)
DIAG_ON(DIAG_UNKNOWN_PRAGMAS)
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance,
- UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_perl_t *inst = talloc_get_type_abort(instance, rlm_perl_t);
- rlm_perl_thread_t *t = talloc_get_type_abort(thread, rlm_perl_thread_t);
+ rlm_perl_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_perl_t);
+ rlm_perl_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_perl_thread_t);
PerlInterpreter *interp;
UV clone_flags = 0;
return 0;
}
-static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- rlm_perl_thread_t *t = talloc_get_type_abort(thread, rlm_perl_thread_t);
+ rlm_perl_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_perl_thread_t);
rlm_perl_interp_free(t->perl);
* parse a module and give it a chance to live
*
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_perl_t *inst = instance;
+ rlm_perl_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_perl_t);
+ CONF_SECTION *conf = mctx->inst->conf;
AV *end_AV;
char const **embed_c; /* Stupid Perl and lack of const consistency */
* Detach a instance give a chance to a module to make some internal setup ...
*/
DIAG_OFF(nested-externs)
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t const *mctx)
{
- rlm_perl_t *inst = (rlm_perl_t *) instance;
+ rlm_perl_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_perl_t);
int ret = 0, count = 0;
*/
RCSID("$Id$")
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX mctx->inst->name
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module.h>
PyThreadState *state; //!< Module instance/thread specific state.
} rlm_python_thread_t;
-static void *python_dlhandle;
-static PyThreadState *global_interpreter; //!< Our first interpreter.
+static void *python_dlhandle;
+static PyThreadState *global_interpreter; //!< Our first interpreter.
-static rlm_python_t *current_inst; //!< Used for communication with inittab functions.
-static CONF_SECTION *current_conf; //!< Used for communication with inittab functions.
-static char *default_path; //!< The default python path.
+static module_ctx_t const *current_mctx; //!< Used for communication with inittab functions.
+static CONF_SECTION *current_conf; //!< Used for communication with inittab functions.
+static char *default_path; //!< The default python path.
/*
* As of Python 3.8 the GIL will be per-interpreter
*
* Must be called with a valid thread state set
*/
-static void python_error_log(const rlm_python_t *inst, request_t *request)
+static void python_error_log(module_ctx_t const *mctx, request_t *request)
{
PyObject *p_type = NULL, *p_value = NULL, *p_traceback = NULL, *p_str_1 = NULL, *p_str_2 = NULL;
Py_XDECREF(p_traceback);
}
-static void mod_vptuple(TALLOC_CTX *ctx, rlm_python_t const *inst, request_t *request,
+static void mod_vptuple(TALLOC_CTX *ctx, module_ctx_t const *mctx, request_t *request,
fr_pair_list_t *vps, PyObject *p_value, char const *funcname, char const *list_name)
{
int i;
Py_ssize_t tuple_len;
- tmpl_t *dst;
+ tmpl_t *dst;
fr_pair_t *vp;
- request_t *current = request;
+ request_t *current = request;
fr_pair_list_t tmp_list;
fr_pair_list_init(&tmp_list);
* This is the core Python function that the others wrap around.
* Pass the value-pair print strings in a tuple.
*/
-static int mod_populate_vptuple(rlm_python_t const *inst, request_t *request, PyObject *pp, fr_pair_t *vp)
+static int mod_populate_vptuple(module_ctx_t const *mctx, request_t *request, PyObject *pp, fr_pair_t *vp)
{
PyObject *attribute = NULL;
PyObject *value = NULL;
if (slen < 0) {
error:
ROPTIONAL(REDEBUG, ERROR, "Failed marshalling %pP to Python value", vp);
- python_error_log(inst, request);
+ python_error_log(mctx, request);
Py_XDECREF(attribute);
return -1;
}
return 0;
}
-static unlang_action_t do_python_single(rlm_rcode_t *p_result,
- rlm_python_t const *inst, request_t *request, PyObject *p_func, char const *funcname)
+static unlang_action_t do_python_single(rlm_rcode_t *p_result, module_ctx_t const *mctx,
+ request_t *request, PyObject *p_func, char const *funcname)
{
fr_pair_t *vp;
PyObject *p_ret = NULL;
goto finish;
}
- if (mod_populate_vptuple(inst, request, pp, vp) == 0) {
+ if (mod_populate_vptuple(mctx, request, pp, vp) == 0) {
/* Put the tuple inside the container */
PyTuple_SET_ITEM(p_arg, i, pp);
} else {
/* Call Python function. */
p_ret = PyObject_CallFunctionObjArgs(p_func, p_arg, NULL);
if (!p_ret) {
- python_error_log(inst, request); /* Needs valid thread with GIL */
+ python_error_log(mctx, request); /* Needs valid thread with GIL */
rcode = RLM_MODULE_FAIL;
goto finish;
}
/* Now have the return value */
rcode = PyLong_AsLong(p_tuple_int);
/* Reply item tuple */
- mod_vptuple(request->reply_ctx, inst, request, &request->reply_pairs,
+ mod_vptuple(request->reply_ctx, mctx, request, &request->reply_pairs,
PyTuple_GET_ITEM(p_ret, 1), funcname, "reply");
/* Config item tuple */
- mod_vptuple(request->control_ctx, inst, request, &request->control_pairs,
+ mod_vptuple(request->control_ctx, mctx, request, &request->control_pairs,
PyTuple_GET_ITEM(p_ret, 2), funcname, "config");
} else if (PyNumber_Check(p_ret)) {
}
finish:
- if (rcode == RLM_MODULE_FAIL) python_error_log(inst, request);
+ if (rcode == RLM_MODULE_FAIL) python_error_log(mctx, request);
Py_XDECREF(p_arg);
Py_XDECREF(p_ret);
*
* Will swap in thread state specific to module/thread.
*/
-static unlang_action_t do_python(rlm_rcode_t *p_result, rlm_python_t const *inst, rlm_python_thread_t *this_thread,
- request_t *request, PyObject *p_func, char const *funcname)
+static unlang_action_t do_python(rlm_rcode_t *p_result, module_ctx_t const *mctx,
+ request_t *request, PyObject *p_func, char const *funcname)
{
+ rlm_python_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_python_thread_t);
rlm_rcode_t rcode;
/*
*/
if (!p_func) RETURN_MODULE_NOOP;
- RDEBUG3("Using thread state %p/%p", inst, this_thread->state);
+ RDEBUG3("Using thread state %p/%p", mctx->inst->data, t->state);
- PyEval_RestoreThread(this_thread->state); /* Swap in our local thread state */
- do_python_single(&rcode, inst, request, p_func, funcname);
- (void)fr_cond_assert(PyEval_SaveThread() == this_thread->state);
+ PyEval_RestoreThread(t->state); /* Swap in our local thread state */
+ do_python_single(&rcode, mctx, request, p_func, funcname);
+ (void)fr_cond_assert(PyEval_SaveThread() == t->state);
RETURN_MODULE_RCODE(rcode);
}
static unlang_action_t CC_HINT(nonnull) mod_##x(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request) \
{ \
rlm_python_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_python_t); \
- rlm_python_thread_t *thread = talloc_get_type_abort(mctx->thread, rlm_python_thread_t); \
- return do_python(p_result, inst, thread, request, inst->x.function, #x);\
+ return do_python(p_result, mctx, request, inst->x.function, #x);\
}
MOD_FUNC(authenticate)
/** Import a user module and load a function from it
*
*/
-static int python_function_load(rlm_python_t *inst, python_func_def_t *def)
+static int python_function_load(module_inst_ctx_t const *mctx, python_func_def_t *def)
{
char const *funcname = "python_function_load";
if (!def->module) {
ERROR("%s - Module '%s' load failed", funcname, def->module_name);
error:
- python_error_log(inst, NULL);
+ python_error_log(&(module_ctx_t){ .inst = mctx->inst }, NULL);
Py_XDECREF(def->function);
def->function = NULL;
Py_XDECREF(def->module);
* Parse a configuration section, and populate a dict.
* This function is recursively called (allows to have nested dicts.)
*/
-static int python_parse_config(rlm_python_t *inst, CONF_SECTION *cs, int lvl, PyObject *dict)
+static int python_parse_config(module_inst_ctx_t const *mctx, CONF_SECTION *cs, int lvl, PyObject *dict)
{
int indent_section = (lvl * 4);
int indent_item = (lvl + 1) * 4;
MEM(sub_dict = PyDict_New());
(void)PyDict_SetItem(dict, p_key, sub_dict);
- ret = python_parse_config(inst, sub_cs, lvl + 1, sub_dict);
+ ret = python_parse_config(mctx, sub_cs, lvl + 1, sub_dict);
if (ret < 0) break;
} else if (cf_item_is_pair(ci)) {
CONF_PAIR *cp = cf_item_to_pair(ci);
/** Make the current instance's config available within the module we're initialising
*
*/
-static int python_module_import_config(rlm_python_t *inst, CONF_SECTION *conf, PyObject *module)
+static int python_module_import_config(module_inst_ctx_t const *mctx, CONF_SECTION *conf, PyObject *module)
{
+ rlm_python_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_python_t);
CONF_SECTION *cs;
/*
error:
Py_XDECREF(inst->pythonconf_dict);
inst->pythonconf_dict = NULL;
- python_error_log(inst, NULL);
+ python_error_log(&(module_ctx_t){ .inst = mctx->inst }, NULL);
return -1;
}
cs = cf_section_find(conf, "config", NULL);
if (cs) {
DEBUG("Inserting \"config\" section into python environment as radiusd.config");
- if (python_parse_config(inst, cs, 0, inst->pythonconf_dict) < 0) goto error;
+ if (python_parse_config(mctx, cs, 0, inst->pythonconf_dict) < 0) goto error;
}
/*
/** Import integer constants into the module we're initialising
*
*/
-static int python_module_import_constants(rlm_python_t *inst, PyObject *module)
+static int python_module_import_constants(module_inst_ctx_t const *mctx, PyObject *module)
{
size_t i;
for (i = 0; freeradius_constants[i].name; i++) {
if ((PyModule_AddIntConstant(module, freeradius_constants[i].name, freeradius_constants[i].value)) < 0) {
ERROR("Failed adding constant to module");
- python_error_log(inst, NULL);
+ python_error_log(&(module_ctx_t){ .inst = mctx->inst }, NULL);
return -1;
}
}
*/
static PyObject *python_module_init(void)
{
- rlm_python_t *inst = current_inst;
- PyObject *module;
+ PyObject *module;
static struct PyModuleDef py_module_def = {
PyModuleDef_HEAD_INIT,
.m_methods = module_methods
};
- fr_assert(inst);
+ fr_assert(current_mctx);
module = PyModule_Create(&py_module_def);
if (!module) {
- python_error_log(inst, NULL);
+ python_error_log(current_mctx, NULL);
Py_RETURN_NONE;
}
return module;
}
-static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
+static int python_interpreter_init(module_inst_ctx_t const *mctx)
{
+ rlm_python_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_python_t);
+ CONF_SECTION *conf = mctx->inst->conf;
char *path;
PyObject *module;
wchar_t *wide_path;
* called during interpreter initialisation
* it can get at the current instance config.
*/
- current_inst = inst;
+ current_mctx = &(module_ctx_t){ .inst = mctx->inst };
current_conf = conf;
PyEval_RestoreThread(global_interpreter);
ERROR("Failed importing \"freeradius\" module into interpreter %p", inst->interpreter);
return -1;
}
- if ((python_module_import_config(inst, conf, module) < 0) ||
- (python_module_import_constants(inst, module) < 0)) {
+ if ((python_module_import_config(mctx, conf, module) < 0) ||
+ (python_module_import_constants(mctx, module) < 0)) {
Py_DECREF(module);
return -1;
}
* in *instance otherwise put a null pointer there.
*
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_python_t *inst = instance;
-
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
+ rlm_python_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_python_t);
- if (python_interpreter_init(inst, conf) < 0) return -1;
+ if (python_interpreter_init(mctx) < 0) return -1;
/*
* Switch to our module specific interpreter
/*
* Process the various sections
*/
-#define PYTHON_FUNC_LOAD(_x) if (python_function_load(inst, &inst->_x) < 0) goto error
+#define PYTHON_FUNC_LOAD(_x) if (python_function_load(mctx, &inst->_x) < 0) goto error
PYTHON_FUNC_LOAD(instantiate);
PYTHON_FUNC_LOAD(authenticate);
PYTHON_FUNC_LOAD(authorize);
if (inst->instantiate.function) {
rlm_rcode_t rcode;
- do_python_single(&rcode, inst, NULL, inst->instantiate.function, "instantiate");
+ do_python_single(&rcode, &(module_ctx_t){ .inst = mctx->inst }, NULL, inst->instantiate.function, "instantiate");
switch (rcode) {
case RLM_MODULE_FAIL:
case RLM_MODULE_REJECT:
return 0;
}
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t const *mctx)
{
- rlm_python_t *inst = instance;
+ rlm_python_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_python_t);
/*
* If we don't have a interpreter
if (inst->detach.function) {
rlm_rcode_t rcode;
- (void)do_python_single(&rcode, inst, NULL, inst->detach.function, "detach");
+ (void)do_python_single(&rcode, &(module_ctx_t){ .inst = mctx->inst }, NULL, inst->detach.function, "detach");
}
#define PYTHON_FUNC_DESTROY(_x) python_function_destroy(&inst->_x)
return 0;
}
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instance,
- UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
PyThreadState *state;
- rlm_python_t *inst = instance;
- rlm_python_thread_t *this_thread = thread;
+ rlm_python_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_python_t);
+ rlm_python_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_python_thread_t);
state = PyThreadState_New(inst->interpreter->interp);
if (!state) {
}
DEBUG3("Initialised new thread state %p", state);
- this_thread->state = state;
+ t->state = state;
return 0;
}
-static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- rlm_python_thread_t *this_thread = thread;
+ rlm_python_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_python_thread_t);
- PyEval_RestoreThread(this_thread->state); /* Swap in our local thread state */
- PyThreadState_Clear(this_thread->state);
+ PyEval_RestoreThread(t->state); /* Swap in our local thread state */
+ PyThreadState_Clear(t->state);
PyEval_SaveThread();
- PyThreadState_Delete(this_thread->state); /* Don't need to hold lock for this */
+ PyThreadState_Delete(t->state); /* Don't need to hold lock for this */
return 0;
}
/** Destroy thread data for the submodule.
*
*/
-static int mod_thread_detach(fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- rlm_radius_thread_t *t = talloc_get_type_abort(thread, rlm_radius_thread_t);
- rlm_radius_t const *inst = t->inst;
+ rlm_radius_t const *inst = talloc_get_type_abort(mctx->inst->data, rlm_radius_t);
+ rlm_radius_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_radius_thread_t);
/*
* Tell the submodule to shut down all of its
* connections.
*/
if (inst->io->thread_detach &&
- (inst->io->thread_detach(el, t->io_thread) < 0)) {
+ (inst->io->thread_detach(&(module_thread_inst_ctx_t){
+ .inst = inst->io_submodule,
+ .thread = t->io_thread,
+ .el = mctx->el
+ }) < 0)) {
return -1;
}
/** Instantiate thread data for the submodule.
*
*/
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_radius_t *inst = talloc_get_type_abort(instance, rlm_radius_t);
- rlm_radius_thread_t *t = talloc_get_type_abort(thread, rlm_radius_thread_t);
-
- t->inst = instance;
+ rlm_radius_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_radius_t);
+ rlm_radius_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_radius_thread_t);
/*
* Allocate thread-specific data. The connections should
* sockets, set timers, etc.
*/
if (inst->io->thread_instantiate &&
- inst->io->thread_instantiate(inst->io_conf, inst->io_instance, el, t->io_thread) < 0) return -1;
+ inst->io->thread_instantiate(&(module_thread_inst_ctx_t){
+ .inst = inst->io_submodule,
+ .thread = t->io_thread,
+ .el = mctx->el
+ }) < 0) return -1;
return 0;
}
-/** Instantiate the module
- *
- * Instantiate I/O and type submodules.
- *
- * @param[in] instance Ctx data for this module
- * @param[in] conf our configuration section parsed to give us instance.
- * @return
- * - 0 on success.
- * - -1 on failure.
- */
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_radius_t *inst = talloc_get_type_abort(instance, rlm_radius_t);
+ rlm_radius_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_radius_t);
- if (inst->io->instantiate && inst->io->instantiate(inst->io_instance, inst->io_conf) < 0) return -1;
+ if (inst->io->instantiate &&
+ inst->io->instantiate(&(module_inst_ctx_t){
+ .inst = inst->io_submodule
+ }) < 0) return -1;
return 0;
}
-/** Bootstrap the module
- *
- * Bootstrap I/O and type submodules.
- *
- * @param[in] instance Ctx data for this module
- * @param[in] conf our configuration section parsed to give us instance.
- * @return
- * - 0 on success.
- * - -1 on failure.
- */
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
size_t i, num_types;
- rlm_radius_t *inst = talloc_get_type_abort(instance, rlm_radius_t);
+ rlm_radius_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_radius_t);
+ CONF_SECTION *conf = mctx->inst->conf;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
+ inst->name = mctx->inst->name;
/*
* These limits are specific to RADIUS, and cannot be over-ridden
setup_io_submodule:
inst->io = (rlm_radius_io_t const *) inst->io_submodule->module->common;
- inst->io_instance = inst->io_submodule->data;
- inst->io_conf = inst->io_submodule->conf;
-
fr_assert(inst->io->thread_inst_size > 0);
fr_assert(inst->io->bootstrap != NULL);
fr_assert(inst->io->instantiate != NULL);
/*
* Bootstrap the submodule.
*/
- if (inst->io->bootstrap(inst->io_instance, inst->io_conf) < 0) return -1;
+ if (inst->io->bootstrap &&
+ inst->io->bootstrap(&(module_inst_ctx_t){
+ .inst = inst->io_submodule
+ }) < 0) return -1;
return 0;
}
* Contains buffers and connection handles specific to the thread.
*/
typedef struct {
- rlm_radius_t const *inst; //!< Instance of the module.
void *io_thread; //!< thread context for the IO submodule
} rlm_radius_thread_t;
* Define a structure for our module configuration.
*/
struct rlm_radius_s {
- char const *name; //!< Module instance name.
-
+ char const *name;
dl_module_inst_t *io_submodule; //!< As provided by the transport_parse
rlm_radius_io_t const *io; //!< Easy access to the IO handle
void *io_instance; //!< Easy access to the IO instance
fr_trunk_connection_signal_active(treq->tconn);
}
-static void request_demux(fr_trunk_connection_t *tconn, fr_connection_t *conn, UNUSED void *uctx)
+static void request_demux(UNUSED fr_event_list_t *el, fr_trunk_connection_t *tconn, fr_connection_t *conn, UNUSED void *uctx)
{
udp_handle_t *h = talloc_get_type_abort(conn->h, udp_handle_t);;
/** Instantiate thread data for the submodule.
*
*/
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, fr_event_list_t *el, void *tctx)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_radius_udp_t *inst = talloc_get_type_abort(instance, rlm_radius_udp_t);
- udp_thread_t *thread = talloc_get_type_abort(tctx, udp_thread_t);
+ rlm_radius_udp_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_radius_udp_t);
+ udp_thread_t *thread = talloc_get_type_abort(mctx->thread, udp_thread_t);
static fr_trunk_io_funcs_t io_funcs = {
.connection_alloc = thread_conn_alloc,
inst->trunk_conf->req_pool_headers = 4; /* One for the request, one for the buffer, one for the tracking binding, one for Proxy-State VP */
inst->trunk_conf->req_pool_size = sizeof(udp_request_t) + inst->max_packet_size + sizeof(radius_track_entry_t ***) + sizeof(fr_pair_t) + 20;
- thread->el = el;
+ thread->el = mctx->el;
thread->inst = inst;
- thread->trunk = fr_trunk_alloc(thread, el, inst->replicate ? &io_funcs_replicate : &io_funcs,
+ thread->trunk = fr_trunk_alloc(thread, mctx->el, inst->replicate ? &io_funcs_replicate : &io_funcs,
inst->trunk_conf, inst->parent->name, thread, false);
if (!thread->trunk) return -1;
return 0;
}
-/** Instantiate the module
- *
- * Instantiate I/O and type submodules.
- *
- * @param[in] instance data for this module
- * @param[in] conf our configuration section parsed to give us instance.
- * @return
- * - 0 on success.
- * - -1 on failure.
- */
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_radius_t *parent = talloc_get_type_abort(dl_module_parent_data_by_child_data(instance),
- rlm_radius_t);
- rlm_radius_udp_t *inst = talloc_get_type_abort(instance, rlm_radius_udp_t);
+ rlm_radius_t *parent = talloc_get_type_abort(mctx->inst->parent->data, rlm_radius_t);
+ rlm_radius_udp_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_radius_udp_t);
+ CONF_SECTION *conf = mctx->inst->conf;
if (!parent) {
ERROR("IO module cannot be instantiated directly");
return 0;
}
-/** Bootstrap the module
- *
- * Bootstrap I/O and type submodules.
- *
- * @param[in] instance Ctx data for this module
- * @param[in] conf our configuration section parsed to give us instance.
- * @return
- * - 0 on success.
- * - -1 on failure.
- */
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
-{
- rlm_radius_udp_t *inst = talloc_get_type_abort(instance, rlm_radius_udp_t);
-
- (void) talloc_set_type(inst, rlm_radius_udp_t);
- inst->config = conf;
-
- return 0;
-}
-
extern rlm_radius_io_t rlm_radius_udp;
rlm_radius_io_t rlm_radius_udp = {
.magic = RLM_MODULE_INIT,
.thread_inst_type = "udp_thread_t",
.config = module_config,
- .bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.thread_instantiate = mod_thread_instantiate,
fr_redis_conf_t conf; //!< Connection parameters for the Redis server.
//!< Must be first field in this struct.
- char const *name; //!< Instance name.
-
fr_redis_cluster_t *cluster; //!< Redis cluster.
} rlm_redis_t;
return action;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_redis_t *inst = instance;
+ rlm_redis_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_redis_t);
char *name;
xlat_t *xlat;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- xlat = xlat_register(inst, inst->name, redis_xlat, false);
+ xlat = xlat_register(inst, mctx->inst->name, redis_xlat, false);
xlat_func_args(xlat, redis_args);
xlat_async_instantiate_set(xlat, redis_xlat_instantiate, rlm_redis_t *, NULL, inst);
/*
* %(redis_node:<key>[ idx])
*/
- name = talloc_asprintf(NULL, "%s_node", inst->name);
+ name = talloc_asprintf(NULL, "%s_node", mctx->inst->name);
xlat = xlat_register(inst, name, redis_node_xlat, false);
xlat_func_args(xlat, redis_node_xlat_args);
xlat_async_instantiate_set(xlat, redis_xlat_instantiate, rlm_redis_t *, NULL, inst);
talloc_free(name);
- name = talloc_asprintf(NULL, "%s_remap", inst->name);
+ name = talloc_asprintf(NULL, "%s_remap", mctx->inst->name);
xlat = xlat_register(inst, name, redis_remap_xlat, false);
xlat_func_args(xlat, redis_remap_xlat_args);
xlat_async_instantiate_set(xlat, redis_xlat_instantiate, rlm_redis_t *, NULL, inst);
return 0;
}
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_redis_t *inst = instance;
+ rlm_redis_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_redis_t);
- inst->cluster = fr_redis_cluster_alloc(inst, conf, &inst->conf, true, NULL, NULL, NULL);
+ inst->cluster = fr_redis_cluster_alloc(inst, mctx->inst->conf, &inst->conf, true, NULL, NULL, NULL);
if (!inst->cluster) return -1;
return 0;
return mod_action(p_result, inst, request, vp ? vp->vp_uint32 : POOL_ACTION_RELEASE);
}
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
static bool done_hash = false;
- CONF_SECTION *subcs = cf_section_find(conf, "redis", NULL);
+ CONF_SECTION *subcs = cf_section_find(mctx->inst->conf, "redis", NULL);
- rlm_redis_ippool_t *inst = instance;
+ rlm_redis_ippool_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_redis_ippool_t);
fr_assert(tmpl_is_attr(inst->allocated_address_attr));
fr_assert(subcs);
fr_redis_conf_t conf; //!< Connection parameters for the Redis server.
//!< Must be first field in this struct.
- char const *name; //!< Instance name.
- CONF_SECTION *cs;
fr_redis_cluster_t *cluster; //!< Pool O pools
int expiry_time; //!< Expiry time in seconds if no updates are received for a user
static unlang_action_t CC_HINT(nonnull) mod_accounting(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
{
rlm_rediswho_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_rediswho_t);
+ CONF_SECTION *conf = mctx->inst->conf;
rlm_rcode_t rcode;
fr_pair_t *vp;
- fr_dict_enum_value_t *dv;
+ fr_dict_enum_value_t *dv;
CONF_SECTION *cs;
char const *insert, *trim, *expire;
RETURN_MODULE_NOOP;
}
- cs = cf_section_find(inst->cs, dv->name, NULL);
+ cs = cf_section_find(conf, dv->name, NULL);
if (!cs) {
RDEBUG2("No subsection %s", dv->name);
RETURN_MODULE_NOOP;
return mod_accounting_all(&rcode, inst, request, insert, trim, expire);
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
-{
- rlm_rediswho_t *inst = instance;
-
- inst->cs = conf;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- return 0;
-}
-
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_rediswho_t *inst = instance;
+ rlm_rediswho_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_rediswho_t);
+ CONF_SECTION *conf = mctx->inst->conf;
inst->cluster = fr_redis_cluster_alloc(inst, conf, &inst->conf, true, NULL, NULL, NULL);
if (!inst->cluster) return -1;
.config = module_config,
.onload = mod_load,
.instantiate = mod_instantiate,
- .bootstrap = mod_bootstrap,
.methods = {
[MOD_ACCOUNTING] = mod_accounting
},
* @brief Functions and datatypes for the REST (HTTP) transport.
* @file rest.c
*
- * @copyright 2012-2019 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
+ * @copyright 2012-2021 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
*/
RCSID("$Id$")
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX mctx->inst->name
#include <ctype.h>
#include <string.h>
* data will be sent using multiple HTTP requests, or contiguous mode where
* the request data will be sent in a single HTTP request.
*
- * @param[in] inst configuration data.
+ * @param[in] mctx Call data.
* @param[in] section configuration data.
* @param[in] request Current request.
* @param[in] randle fr_curl_io_request_t to configure.
* - 0 on success.
* - -1 on failure.
*/
-static int rest_request_config_body(rlm_rest_t const *inst, rlm_rest_section_t const *section,
+static int rest_request_config_body(module_ctx_t const *mctx, rlm_rest_section_t const *section,
request_t *request, fr_curl_io_request_t *randle, rest_read_t func)
{
+ rlm_rest_t const *inst = talloc_get_type_abort(mctx->inst, rlm_rest_t);
rlm_rest_curl_context_t *uctx = talloc_get_type_abort(randle->uctx, rlm_rest_curl_context_t);
-
ssize_t len;
/*
*
* Sets up callbacks for all response processing (buffers and body data).
*
- * @param[in] inst configuration data.
- * @param[in] t Thread specific instance data.
+ * @param[in] mctx call data.
* @param[in] section configuration data.
* @param[in] randle to configure.
* @param[in] request Current request.
* - 0 on success (all opts configured).
* - -1 on failure.
*/
-int rest_request_config(rlm_rest_t const *inst, rlm_rest_thread_t *t, rlm_rest_section_t const *section,
+int rest_request_config(module_ctx_t const *mctx, rlm_rest_section_t const *section,
request_t *request, fr_curl_io_request_t *randle, http_method_t method,
http_body_type_t type,
char const *uri, char const *username, char const *password)
{
+ rlm_rest_t const *inst = talloc_get_type_abort(mctx->inst, rlm_rest_t);
+ rlm_rest_thread_t const *t = talloc_get_type_abort(mctx->inst, rlm_rest_thread_t);
rlm_rest_curl_context_t *ctx = talloc_get_type_abort(randle->uctx, rlm_rest_curl_context_t);
CURL *candle = randle->candle;
fr_time_delta_t timeout;
*/
switch (type) {
case REST_HTTP_BODY_NONE:
- if (rest_request_config_body(inst, section, request, randle, NULL) < 0) return -1;
+ if (rest_request_config_body(mctx, section, request, randle, NULL) < 0) return -1;
break;
/* Use the encoder specific pointer to store the data we need to encode */
ctx->request.encoder = data;
- if (rest_request_config_body(inst, section, request, randle, rest_encode_custom) < 0) {
+ if (rest_request_config_body(mctx, section, request, randle, rest_encode_custom) < 0) {
TALLOC_FREE(ctx->request.encoder);
return -1;
}
/* Use the encoder specific pointer to store the data we need to encode */
ctx->request.encoder = data;
- if (rest_request_config_body(inst, section, request, randle, rest_encode_custom) < 0) {
+ if (rest_request_config_body(mctx, section, request, randle, rest_encode_custom) < 0) {
TALLOC_FREE(ctx->request.encoder);
return -1;
}
rest_request_init(section, request, &ctx->request);
- if (rest_request_config_body(inst, section, request, randle, rest_encode_json) < 0) return -1;
+ if (rest_request_config_body(mctx, section, request, randle, rest_encode_json) < 0) return -1;
}
break;
rest_request_init(section, request, &ctx->request);
fr_pair_dcursor_init(&(ctx->request.cursor), &request->request_pairs);
- if (rest_request_config_body(inst, section, request, randle, rest_encode_post) < 0) return -1;
+ if (rest_request_config_body(mctx, section, request, randle, rest_encode_post) < 0) return -1;
break;
* Structure for module configuration
*/
typedef struct {
- char const *name; //!< Instance name.
-
char const *connect_proxy; //!< Send request via this proxy.
int http_negotiation; //!< What HTTP version to negotiate, and how to
/*
* Request processing API
*/
-int rest_request_config(rlm_rest_t const *instance, rlm_rest_thread_t *thread,
+int rest_request_config(module_ctx_t const *mctx,
rlm_rest_section_t const *section, request_t *request,
fr_curl_io_request_t *randle, http_method_t method,
http_body_type_t type, char const *uri,
- char const *username, char const *password) CC_HINT(nonnull (1,2,3,5,8));
+ char const *username, char const *password) CC_HINT(nonnull (1,2,4,7));
int rest_response_decode(rlm_rest_t const *instance,
UNUSED rlm_rest_section_t const *section, request_t *request,
return 0;
}
-static int rlm_rest_perform(rlm_rest_t const *instance, rlm_rest_thread_t *t,
+static int rlm_rest_perform(module_ctx_t const *mctx,
rlm_rest_section_t const *section, fr_curl_io_request_t *randle,
request_t *request, char const *username, char const *password)
{
- ssize_t uri_len;
- char *uri = NULL;
- int ret;
+ rlm_rest_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_rest_t);
+ rlm_rest_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_rest_thread_t);
+ ssize_t uri_len;
+ char *uri = NULL;
+ int ret;
RDEBUG2("Expanding URI components");
* Build xlat'd URI, this allows REST servers to be specified by
* request attributes.
*/
- uri_len = rest_uri_build(&uri, instance, request, section->uri);
+ uri_len = rest_uri_build(&uri, inst, request, section->uri);
if (uri_len <= 0) return -1;
RDEBUG2("Sending HTTP %s to \"%s\"", fr_table_str_by_value(http_method_table, section->method, NULL), uri);
* Configure various CURL options, and initialise the read/write
* context data.
*/
- ret = rest_request_config(instance, t, section, request, randle, section->method, section->body,
+ ret = rest_request_config(mctx, section, request, randle, section->method, section->body,
uri, username, password);
talloc_free(uri);
if (ret < 0) return -1;
*
* @todo We could extract the User-Name and password from the URL string.
*/
- ret = rest_request_config(mod_inst, t, section, request, randle, section->method,
+ ret = rest_request_config(&(module_ctx_t){ .inst = dl_module_instance_by_data(mod_inst), .thread = t },
+ section, request, randle, section->method,
section->body, uri_vb->vb_strvalue, NULL, NULL);
if (ret < 0) goto error;
handle = fr_pool_connection_get(t->pool, request);
if (!handle) RETURN_MODULE_FAIL;
- ret = rlm_rest_perform(inst, t, section, handle, request, NULL, NULL);
+ ret = rlm_rest_perform(mctx, section, handle, request, NULL, NULL);
if (ret < 0) {
rest_request_cleanup(inst, handle);
fr_pool_connection_release(t->pool, request, handle);
handle = fr_pool_connection_get(t->pool, request);
if (!handle) RETURN_MODULE_FAIL;
- ret = rlm_rest_perform(inst, t, section,
+ ret = rlm_rest_perform(mctx, section,
handle, request, username->vp_strvalue, password->vp_strvalue);
if (ret < 0) {
rest_request_cleanup(inst, handle);
handle = fr_pool_connection_get(t->pool, request);
if (!handle) RETURN_MODULE_FAIL;
- ret = rlm_rest_perform(inst, t, section, handle, request, NULL, NULL);
+ ret = rlm_rest_perform(mctx, section, handle, request, NULL, NULL);
if (ret < 0) {
rest_request_cleanup(inst, handle);
fr_pool_connection_release(t->pool, request, handle);
handle = fr_pool_connection_get(t->pool, request);
if (!handle) RETURN_MODULE_FAIL;
- ret = rlm_rest_perform(inst, t, section, handle, request, NULL, NULL);
+ ret = rlm_rest_perform(mctx, section, handle, request, NULL, NULL);
if (ret < 0) {
rest_request_cleanup(inst, handle);
* Easy handles representing requests are added to the curl multihandle
* with the multihandle used for mux/demux.
*
- * @param[in] conf section containing the configuration of this module instance.
- * @param[in] instance of rlm_rest_t.
- * @param[in] thread specific data.
- * @param[in] el The event list serviced by this thread.
+ * @param[in] mctx Thread instantiation data.
* @return
* - 0 on success.
* - -1 on failure.
*/
-static int mod_thread_instantiate(CONF_SECTION const *conf, void *instance, fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_rest_t *inst = instance;
- rlm_rest_thread_t *t = thread;
+ rlm_rest_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_rest_t);
+ rlm_rest_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_rest_thread_t);
+ CONF_SECTION *conf = mctx->inst->conf;
fr_curl_handle_t *mhandle;
CONF_SECTION *my_conf;
- t->inst = instance;
+ t->inst = inst;
/*
* Temporary hack to make config parsing
* thread safe.
*/
my_conf = cf_section_dup(NULL, NULL, conf, cf_section_name1(conf), cf_section_name2(conf), true);
- t->pool = fr_pool_init(NULL, my_conf, instance, rest_mod_conn_create, NULL, inst->name);
+ t->pool = fr_pool_init(NULL, my_conf, inst, rest_mod_conn_create, NULL, mctx->inst->name);
talloc_free(my_conf);
if (!t->pool) {
return -1;
}
- mhandle = fr_curl_io_init(t, el, inst->multiplex);
+ mhandle = fr_curl_io_init(t, mctx->el, inst->multiplex);
if (!mhandle) return -1;
t->mhandle = mhandle;
* Destroys all curl easy handles, and then the multihandle associated
* with this thread.
*
- * @param[in] el for this thread.
- * @param[in] thread specific data to destroy.
+ * @param[in] mctx data to destroy.
* @return 0
*/
-static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- rlm_rest_thread_t *t = thread;
+ rlm_rest_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_rest_thread_t);
talloc_free(t->mhandle); /* Ensure this is shutdown before the pool */
fr_pool_free(t->pool);
* that must be referenced in later calls, store a handle to it
* in *instance otherwise put a null pointer there.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_rest_t *inst = instance;
+ rlm_rest_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_rest_t);
+ CONF_SECTION *conf = mctx->inst->conf;
inst->xlat.method_str = "GET";
inst->xlat.body = REST_HTTP_BODY_NONE;
return 0;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_rest_t *inst = instance;
+ rlm_rest_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_rest_t);
xlat_t *xlat;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- xlat = xlat_register(inst, inst->name, rest_xlat, true);
+ xlat = xlat_register(inst, mctx->inst->name, rest_xlat, true);
xlat_func_args(xlat, rest_xlat_args);
xlat_async_thread_instantiate_set(xlat, mod_xlat_thread_instantiate, rest_xlat_thread_inst_t, NULL, inst);
}
/******************************************/
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t *mctx)
{
- rlm_securid_t *inst = (rlm_securid_t *) instance;
+ rlm_securid_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_securid_t);
/* delete session tree */
if (inst->session_tree) {
}
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_securid_t *inst = instance;
+ rlm_securid_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_securid_t);
/*
* Lookup sessions in the tree. We don't free them in
*/
RCSID("$Id$")
-#define LOG_PREFIX_ARGS inst->name
+#define LOG_PREFIX_ARGS mctx->inst->name
#include <osmocom/core/linuxlist.h>
return 0;
}
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance,
- fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t *mctx)
{
- rlm_sigtran_t *inst = instance;
- rlm_sigtran_thread_t *t = thread;
+ rlm_sigtran_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sigtran_t);
+ rlm_sigtran_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_sigtran_thread_t);
int fd;
t->inst = instance;
return 0;
}
-static int mod_thread_detach(fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t *mctx)
{
- rlm_sigtran_thread_t *t = thread;
+ rlm_sigtran_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_sigtran_thread_t);
sigtran_client_thread_unregister(el, t->fd); /* Also closes our side */
return 0;
}
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_sigtran_t *inst = instance;
-
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
+ rlm_sigtran_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sigtran_t);
/*
* Translate traffic mode string to integer
/**
* Cleanup internal state.
*/
-static int mod_detach(UNUSED void *instance)
+static int mod_detach(module_detach_ctx_t *mctx)
{
- rlm_sigtran_t *inst = instance;
+ rlm_sigtran_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sigtran_t);
/*
* If we're just checking the config we didn't start the
} sigtran_map_send_auth_info_res_t;
typedef struct rlm_sigtran {
- char const *name; //!< Instance name.
-
sigtran_conn_t const *conn; //!< Linkset associated with this instance.
sigtran_conn_conf_t conn_conf; //!< Connection configuration
- tmpl_t *imsi; //!< Subscriber identifier.
+ tmpl_t *imsi; //!< Subscriber identifier.
} rlm_sigtran_t;
typedef struct rlm_sigtran_thread {
} rlm_smtp_t;
typedef struct {
- rlm_smtp_t const *inst; //!< Instance of rlm_smtp.
fr_curl_handle_t *mhandle; //!< Thread specific multi handle. Serves as the dispatch and coralling structure for smtp requests
} rlm_smtp_thread_t;
return 0;
}
-static int mod_bootstrap(void *instance, UNUSED CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_smtp_t *inst = instance;
+ rlm_smtp_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_smtp_t );
talloc_foreach(inst->recipient_addrs, vpt) INFO("NAME: %s", vpt->name);
}
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_smtp_t *inst = instance;
+ rlm_smtp_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_smtp_t);
+ CONF_SECTION *conf = mctx->inst->conf;
CONF_SECTION *header;
fr_map_list_init(&inst->header_maps);
/*
* Initialize a new thread with a curl instance
*/
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instance, fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_smtp_thread_t *t = thread;
+ rlm_smtp_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_smtp_thread_t);
fr_curl_handle_t *mhandle;
- t->inst = instance;
-
- mhandle = fr_curl_io_init(t, el, false);
+ mhandle = fr_curl_io_init(t, mctx->el, false);
if (!mhandle) return -1;
t->mhandle = mhandle;
/*
* Close the thread and free the memory
*/
-static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- rlm_smtp_thread_t *t = thread;
+ rlm_smtp_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_smtp_thread_t);
talloc_free(t->mhandle);
return 0;
}
#include <freeradius-devel/soh/base.h>
typedef struct {
- char const *name;
bool dhcp;
} rlm_soh_t;
RETURN_MODULE_OK;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_soh_t *inst = instance;
+ rlm_soh_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_soh_t);
xlat_t *xlat;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- xlat = xlat_register(inst, inst->name, soh_xlat, false);
+ xlat = xlat_register(inst, mctx->inst->name, soh_xlat, false);
xlat_func_args(xlat, soh_xlat_args);
return 0;
CONF_PARSER_TERMINATOR
};
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_sometimes_t *inst = instance;
+ rlm_sometimes_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sometimes_t);
+ CONF_SECTION *conf = mctx->inst->conf;
/*
* Convert the rcode string to an int, and get rid of it
/*
* A lie! It always returns!
*/
-static unlang_action_t sometimes_return(rlm_rcode_t *p_result, void const *instance, request_t *request,
+static unlang_action_t sometimes_return(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request,
fr_radius_packet_t *packet, fr_radius_packet_t *reply)
{
+ rlm_sometimes_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_sometimes_t);
uint32_t hash;
- rlm_sometimes_t const *inst = talloc_get_type_abort_const(instance, rlm_sometimes_t);
fr_pair_t *vp;
float value;
static unlang_action_t CC_HINT(nonnull) mod_sometimes_packet(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
{
- return sometimes_return(p_result, mctx->inst->data, request, request->packet, request->reply);
+ return sometimes_return(p_result, mctx, request, request->packet, request->reply);
}
static unlang_action_t CC_HINT(nonnull) mod_sometimes_reply(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
{
- return sometimes_return(p_result, mctx->inst->data, request, request->reply, NULL);
+ return sometimes_return(p_result, mctx, request, request->reply, NULL);
}
extern module_t rlm_sometimes;
return 1;
}
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t const *mctx)
{
- rlm_sql_cassandra_t *inst = instance;
+ rlm_sql_cassandra_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sql_cassandra_t);
if (inst->ssl) cass_ssl_free(inst->ssl);
if (inst->session) cass_session_free(inst->session); /* also synchronously closes the session */
{
bool do_tls = false;
bool do_latency_aware_routing = false;
- rlm_sql_cassandra_t *inst = instance;
+ rlm_sql_cassandra_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sql_cassandra_t);
CassCluster *cluster;
static int mod_instantiate(UNUSED rlm_sql_config_t const *config, void *instance, UNUSED CONF_SECTION *cs)
{
- rlm_sql_mysql_t *inst = instance;
+ rlm_sql_mysql_t *inst = talloc_get_type_abort(instance, rlm_sql_mysql_t);
int warnings;
warnings = fr_table_value_by_str(server_warnings_table, inst->warnings_str, -1);
return 1;
}
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t const *mctx)
{
- rlm_sql_oracle_t *inst = instance;
+ rlm_sql_oracle_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sql_oracle_t);
if (inst->pool) OCISessionPoolDestroy((dvoid *)inst->pool, (dvoid *)inst->error, OCI_DEFAULT );
if (inst->error) OCIHandleFree((dvoid *)inst->error, OCI_HTYPE_ERROR);
{
char errbuff[512];
sb4 errcode = 0;
- rlm_sql_oracle_t *inst = instance;
+ rlm_sql_oracle_t *inst = talloc_get_type_abort(instance, rlm_sql_oracle_t);
OraText *sql_password = NULL;
OraText *sql_login = NULL;
static int mod_instantiate(rlm_sql_config_t const *config, void *instance, CONF_SECTION *conf)
{
- rlm_sql_postgres_t *inst = instance;
+ rlm_sql_postgres_t *inst = talloc_get_type_abort(instance, rlm_sql_postgres_t);
char application_name[NAMEDATALEN];
char *db_string;
static int mod_instantiate(rlm_sql_config_t const *config, void *instance, CONF_SECTION *cs)
{
bool exists;
- rlm_sql_sqlite_t *inst = instance;
+ rlm_sql_sqlite_t *inst = talloc_get_type_abort(instance, rlm_sql_sqlite_t);
struct stat buf;
if (!inst->filename) {
return 0;
}
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t const *mctx)
{
- rlm_sql_t *inst = talloc_get_type_abort(instance, rlm_sql_t);
+ rlm_sql_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sql_t);
if (inst->pool) fr_pool_free(inst->pool);
return 0;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_sql_t *inst = talloc_get_type_abort(instance, rlm_sql_t);
+ rlm_sql_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sql_t);
+ CONF_SECTION *conf = mctx->inst->conf;
CONF_SECTION *driver_cs;
char const *name;
xlat_t *xlat;
}
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_sql_t *inst = instance;
+ rlm_sql_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sql_t);
+ CONF_SECTION *conf = mctx->inst->conf;
/*
* Sanity check for crazy people.
void *sql_mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
{
int rcode;
- rlm_sql_t *inst = instance;
+ rlm_sql_t *inst = talloc_get_type_abort(instance, rlm_sql_t);
rlm_sql_handle_t *handle;
/*
* that must be referenced in later calls, store a handle to it
* in *instance otherwise put a null pointer there.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_sqlcounter_t *inst = instance;
+ rlm_sqlcounter_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sqlcounter_t);
+ CONF_SECTION *conf = mctx->inst->conf;
fr_assert(inst->query && *inst->query);
return 0;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_sqlcounter_t *inst = instance;
- fr_dict_attr_flags_t flags;
+ rlm_sqlcounter_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sqlcounter_t);
+ CONF_SECTION *conf = mctx->inst->conf;
+ fr_dict_attr_flags_t flags;
/*
* Create a new attribute for the counter.
return retval;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_sqlippool_t *inst = instance;
- char const *name;
-
- name = cf_section_name2(conf);
- if (!name) name = cf_section_name1(conf);
-
- inst->name = talloc_asprintf(inst, "%s - %s", name, inst->sql_instance_name);
+ rlm_sqlippool_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sqlippool_t);
+ inst->name = talloc_asprintf(inst, "%s - %s", mctx->inst->name, inst->sql_instance_name);
return 0;
}
* that must be referenced in later calls, store a handle to it
* in *instance otherwise put a null pointer there.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
module_instance_t *sql_inst;
- rlm_sqlippool_t *inst = instance;
+ rlm_sqlippool_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sqlippool_t);
+ CONF_SECTION *conf = mctx->inst->conf;
char const *pool_name = NULL;
pool_name = cf_section_name2(conf);
/** Instantiate thread data for the submodule.
*
*/
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_stats_t *inst = talloc_get_type_abort(instance, rlm_stats_t);
- rlm_stats_thread_t *t = thread;
+ rlm_stats_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_stats_t);
+ rlm_stats_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_stats_thread_t);
(void) talloc_set_type(t, rlm_stats_thread_t);
/** Destroy thread data for the submodule.
*
*/
-static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- rlm_stats_thread_t *t = talloc_get_type_abort(thread, rlm_stats_thread_t);
+ rlm_stats_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_stats_thread_t);
rlm_stats_t *inst = t->inst;
int i;
return 0;
}
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_stats_t *inst = instance;
+ rlm_stats_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_stats_t);
pthread_mutex_init(&inst->mutex, NULL);
fr_dlist_init(&inst->list, rlm_stats_thread_t, entry);
* Only free memory we allocated. The strings allocated via
* cf_section_parse() do not need to be freed.
*/
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t const *mctx)
{
- rlm_stats_t *inst = talloc_get_type_abort(instance, rlm_stats_t);
+ rlm_stats_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_stats_t);
pthread_mutex_destroy(&inst->mutex);
}
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, UNUSED fr_event_list_t *el,
- void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_test_t *inst = instance;
- rlm_test_thread_t *t = thread;
+ rlm_test_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_test_t);
+ rlm_test_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_test_thread_t);
t->inst = inst;
t->value = pthread_self();
return 0;
}
-static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- rlm_test_thread_t *t = thread;
- rlm_test_t *inst = t->inst;
+ rlm_test_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_test_t);
+ rlm_test_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_test_thread_t);
INFO("Performing detach for thread %p", (void *)t->value);
* that must be referenced in later calls, store a handle to it
* in *instance otherwise put a null pointer there.
*/
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
+ rlm_test_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_test_t);
xlat_t *xlat;
- rlm_test_t *inst = instance;
- char const *name2;
- inst->name = name2 = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
- if (!name2) {
+ if (!cf_section_name2(mctx->inst->conf)) {
if (paircmp_register_by_name("Test-Paircmp", attr_user_name, false,
rlm_test_cmp, inst) < 0) {
PERROR("Failed registering \"Test-Paircmp\"");
INFO("inst->tmpl_m is NULL");
}
- if (!name2) {
- if (!(xlat = xlat_register(instance, "test_trigger", trigger_test_xlat, false))) return -1;
+ if (!cf_section_name2(mctx->inst->conf)) {
+ if (!(xlat = xlat_register(inst, "test_trigger", trigger_test_xlat, false))) return -1;
xlat_func_args(xlat, trigger_test_xlat_args);
- if (!(xlat = xlat_register(instance, "test", test_xlat, false))) return -1;
+ if (!(xlat = xlat_register(inst, "test", test_xlat, false))) return -1;
xlat_func_args(xlat, test_xlat_args);
} else {
- if (!(xlat = xlat_register(instance, name2, test_xlat, false))) return -1;
+ if (!(xlat = xlat_register(inst, mctx->inst->name, test_xlat, false))) return -1;
xlat_func_args(xlat, test_xlat_args);
}
return 0;
}
-static int mod_detach(UNUSED void *instance)
-{
- /* free things here */
- return 0;
-}
-
/*
* The module name should be the only globally exported symbol.
* That is, everything else should be 'static'.
.bootstrap = mod_bootstrap,
.thread_instantiate = mod_thread_instantiate,
.thread_detach = mod_thread_detach,
- .detach = mod_detach,
.methods = {
[MOD_AUTHENTICATE] = mod_authenticate,
[MOD_AUTHORIZE] = mod_authorize,
*/
RCSID("$Id$")
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX mctx->inst->name
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module.h>
typedef struct {
char const *name;
-
uint32_t timeout;
char const *filename; //!< Unbound configuration file
return 0;
}
-static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, fr_event_list_t *el, void *thread)
+static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
{
- rlm_unbound_t *inst = talloc_get_type_abort(instance, rlm_unbound_t);
- rlm_unbound_thread_t *t = talloc_get_type_abort(thread, rlm_unbound_thread_t);
+ rlm_unbound_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_unbound_t);
+ rlm_unbound_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_unbound_thread_t);
int res;
t->inst = inst;
- if (unbound_io_init(t, &t->ev_b, el) < 0) {
+ if (unbound_io_init(t, &t->ev_b, mctx->el) < 0) {
PERROR("Unable to create unbound event base");
return -1;
}
return 0;
}
-static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread)
+static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
{
- rlm_unbound_thread_t *t = talloc_get_type_abort(thread, rlm_unbound_thread_t);
+ rlm_unbound_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_unbound_thread_t);
talloc_free(t->u_log);
talloc_free(t->ev_b);
return 0;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_unbound_t *inst = instance;
+ rlm_unbound_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_unbound_t);
xlat_t *xlat;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
if (inst->timeout > 10000) {
- cf_log_err(conf, "timeout must be 0 to 10000");
+ cf_log_err(mctx->inst->conf, "timeout must be 0 to 10000");
return -1;
}
- if(!(xlat = xlat_register(NULL, inst->name, xlat_unbound, true))) return -1;
+ if(!(xlat = xlat_register(NULL, mctx->inst->name, xlat_unbound, true))) return -1;
xlat_func_args(xlat, xlat_unbound_args);
xlat_async_thread_instantiate_set(xlat, mod_xlat_thread_instantiate, unbound_xlat_thread_inst_t, NULL, inst);
RCSID("$Id$")
USES_APPLE_DEPRECATED_API
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX mctx->inst->name
#include <freeradius-devel/radius/radius.h>
#include <freeradius-devel/server/base.h>
#define ENC(c) trans[c]
typedef struct {
- char const *name; //!< Instance name.
char const *radwtmp;
} rlm_unix_t;
/*
* Read the config
*/
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_unix_t *inst = instance;
-
- inst->name = cf_section_name2(conf);
- if (!inst->name) {
- inst->name = cf_section_name1(conf);
+ rlm_unix_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_unix_t);
+ if (!cf_section_name2(mctx->inst->conf)) {
if (paircmp_register_by_name("Unix-Group", attr_user_name, false, groupcmp, inst) < 0) {
PERROR("Failed registering Unix-Group");
return -1;
}
} else {
- char *unix_group = talloc_asprintf(inst, "%s-Unix-Group", inst->name);
+ char *unix_group = talloc_asprintf(inst, "%s-Unix-Group", mctx->inst->name);
if (paircmp_register_by_name(unix_group, attr_user_name, false, groupcmp, inst) < 0) {
PERROR("Failed registering %s", unix_group);
/*
* Register the xlats
*/
-static int mod_bootstrap(UNUSED void *instance, UNUSED CONF_SECTION *conf)
+static int mod_bootstrap(UNUSED module_inst_ctx_t const *mctx)
{
xlat_t *xlat;
*/
static int winbind_group_cmp(void *instance, request_t *request, UNUSED fr_pair_list_t *request_list, fr_pair_t const *check)
{
- rlm_winbind_t *inst = instance;
+ rlm_winbind_t *inst = talloc_get_type_abort(instance, rlm_winbind_t);
int ret = 1;
struct wbcContext *wb_ctx;
wbcErr err;
* - 0 success
* - -1 failure
*/
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_winbind_t *inst = instance;
+ rlm_winbind_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_winbind_t);
char const *group_attribute;
char buffer[256];
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
if (inst->group_attribute) {
group_attribute = inst->group_attribute;
- } else if (cf_section_name2(conf)) {
- snprintf(buffer, sizeof(buffer), "%s-Winbind-Group", inst->name);
+ } else if (cf_section_name2(mctx->inst->conf)) {
+ snprintf(buffer, sizeof(buffer), "%s-Winbind-Group", mctx->inst->name);
group_attribute = buffer;
} else {
group_attribute = "Winbind-Group";
}
- if (paircmp_register_by_name(group_attribute, attr_user_name, false,
- winbind_group_cmp, inst) < 0) {
+ if (paircmp_register_by_name(group_attribute, attr_user_name, false, winbind_group_cmp, inst) < 0) {
PERROR("Error registering group comparison");
return -1;
}
* - 0 instantiation succeeded
* - -1 instantiation failed
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_winbind_t *inst = instance;
+ rlm_winbind_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_winbind_t);
struct wbcInterfaceDetails *wb_info = NULL;
+ CONF_SECTION *conf = mctx->inst->conf;
if (!inst->wb_username) {
cf_log_err(conf, "winbind_username must be defined to use rlm_winbind");
return -1;
}
- inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1);
+ inst->auth_type = fr_dict_enum_by_name(attr_auth_type, mctx->inst->name, -1);
if (!inst->auth_type) {
WARN("Failed to find 'authenticate %s {...}' section. Winbind authentication will likely not work",
- inst->name);
+ mctx->inst->name);
}
/*
goto no_domain;
}
- tmpl_afrom_substr(instance, &inst->wb_domain,
+ tmpl_afrom_substr(inst, &inst->wb_domain,
&FR_SBUFF_IN(wb_info->netbios_domain, strlen(wb_info->netbios_domain)),
T_SINGLE_QUOTED_STRING,
NULL,
* @param[in] instance This module's instance (unused)
* @return 0
*/
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t const *mctx)
{
- rlm_winbind_t *inst = instance;
+ rlm_winbind_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_winbind_t);
fr_pool_free(inst->wb_pool);
if (!inst->auth_type) {
WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup Winbind authentication",
- inst->name, inst->name);
+ mctx->inst->name, mctx->inst->name);
RETURN_MODULE_NOOP;
}
* Structure for the module configuration.
*/
typedef struct {
- char const *name;
fr_pool_t *wb_pool;
fr_dict_enum_value_t *auth_type;
/** Decrypt a Yubikey OTP AES block
*
* @param[out] p_result The result of attempt to decrypt the token.
- * @param[in] inst Module configuration.
+ * @param[in] mctx call data.
* @param[in] request The current request.
* @param[in] passcode string to decrypt.
*/
-unlang_action_t rlm_yubikey_decrypt(rlm_rcode_t *p_result, rlm_yubikey_t const *inst, request_t *request, char const *passcode)
+unlang_action_t rlm_yubikey_decrypt(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request, char const *passcode)
{
+ rlm_yubikey_t const *inst = talloc_get_type_abort(mctx->inst->data, rlm_yubikey_t);
uint32_t counter, timestamp;
yubikey_token_st token;
fr_dict_autofree(rlm_yubikey_dict);
}
-static int mod_bootstrap(void *instance, CONF_SECTION *conf)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- rlm_yubikey_t *inst = instance;
+ rlm_yubikey_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_yubikey_t);
xlat_t *xlat;
- inst->name = cf_section_name2(conf);
- if (!inst->name) inst->name = cf_section_name1(conf);
-
#ifndef HAVE_YUBIKEY
if (inst->decrypt) {
cf_log_err(conf, "Requires libyubikey for OTP decryption");
* that must be referenced in later calls, store a handle to it
* in *instance otherwise put a null pointer there.
*/
-static int mod_instantiate(void *instance, CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- rlm_yubikey_t *inst = instance;
+ rlm_yubikey_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_yubikey_t);
+ CONF_SECTION *conf = mctx->inst->conf;
+
+ inst->name = mctx->inst->name;
inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1);
if (!inst->auth_type) {
WARN("Failed to find 'authenticate %s {...}' section. Yubikey authentication will likely not work",
- inst->name);
+ mctx->inst->name);
}
if (inst->validate) {
}
#ifdef HAVE_YKCLIENT
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t const *mctx)
{
- rlm_yubikey_ykclient_detach((rlm_yubikey_t *) instance);
+ rlm_yubikey_ykclient_detach(talloc_get_type_abort(mctx->inst->data, rlm_yubikey_t));
return 0;
}
#endif
if (!inst->auth_type) {
WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup Yubikey authentication",
- inst->name, inst->name);
+ mctx->inst->name, mctx->inst->name);
RETURN_MODULE_NOOP;
}
#ifdef HAVE_YUBIKEY
if (inst->decrypt) {
- rlm_yubikey_decrypt(&rcode, inst, request, passcode);
+ rlm_yubikey_decrypt(&rcode, mctx, request, passcode);
if (rcode != RLM_MODULE_OK) RETURN_MODULE_RCODE(rcode);
/* Fall-Through to doing ykclient auth in addition to local auth */
}
#endif
#ifdef HAVE_YKCLIENT
- if (inst->validate) return rlm_yubikey_validate(p_result, inst, request, passcode);
+ if (inst->validate) return rlm_yubikey_validate(p_result, mctx, request, passcode);
#endif
RETURN_MODULE_RCODE(rcode);
}
* be used as the instance handle.
*/
typedef struct {
- char const *name; //!< Instance name.
- fr_dict_enum_value_t *auth_type; //!< Our Auth-Type.
+ char const *name;
+ fr_dict_enum_value_t *auth_type; //!< Our Auth-Type.
unsigned int id_len; //!< The length of the Public ID portion of the OTP string.
bool split; //!< Split password string into components.
bool decrypt; //!< Decrypt the OTP string using the yubikey library.
unsigned int client_id; //!< Validation API client ID.
char const *api_key; //!< Validation API signing key.
ykclient_t *ykc; //!< ykclient configuration.
- fr_pool_t *pool; //!< Connection pool instance.
+ fr_pool_t *pool; //!< Connection pool instance.
#endif
} rlm_yubikey_t;
/*
* decrypt.c - Decryption functions
*/
-unlang_action_t rlm_yubikey_decrypt(rlm_rcode_t *p_result, rlm_yubikey_t const *inst, request_t *request, char const *passcode);
+unlang_action_t rlm_yubikey_decrypt(rlm_rcode_t *p_result, module_ctx_t const *mctx,
+ request_t *request, char const *passcode);
/*
* validate.c - Connection pool and validation functions
int rlm_yubikey_ykclient_detach(rlm_yubikey_t *inst);
-unlang_action_t rlm_yubikey_validate(rlm_rcode_t *p_result, rlm_yubikey_t const *inst, request_t *request, char const *passcode);
+unlang_action_t rlm_yubikey_validate(rlm_rcode_t *p_result, module_ctx_t const *mctx,
+ request_t *request, char const *passcode);
extern HIDDEN fr_dict_attr_t const *attr_auth_type;
extern HIDDEN fr_dict_attr_t const *attr_user_password;
return 0;
}
-unlang_action_t rlm_yubikey_validate(rlm_rcode_t *p_result, rlm_yubikey_t const *inst, request_t *request, char const *passcode)
+unlang_action_t rlm_yubikey_validate(rlm_rcode_t *p_result, module_ctx_t const *mctx,
+ request_t *request, char const *passcode)
{
+ rlm_yubikey_t const *inst = talloc_get_type_abort(mctx->inst->data, rlm_yubikey_t);
rlm_rcode_t rcode = RLM_MODULE_OK;
ykclient_rc status;
ykclient_handle_t *yandle;
return state->recv(p_result, mctx, request);
}
-static int mod_bootstrap(void *instance, CONF_SECTION *cs)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- process_dhcpv6_t *inst = instance;
+ process_dhcpv6_t *inst = talloc_get_type_abort(mctx->inst->data, process_dhcpv6_t);
- inst->server_cs = cf_section_find_in_parent(cs, "server", CF_IDENT_ANY);
+ inst->server_cs = cf_section_find_in_parent(mctx->inst->conf, "server", CF_IDENT_ANY);
return 0;
}
COMPILE_TERMINATOR
};
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- eap_aka_sim_process_conf_t *inst = talloc_get_type_abort(instance, eap_aka_sim_process_conf_t);
+ eap_aka_sim_process_conf_t *inst = talloc_get_type_abort(mctx->inst->data, eap_aka_sim_process_conf_t);
inst->type = FR_EAP_METHOD_AKA;
COMPILE_TERMINATOR
};
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- eap_aka_sim_process_conf_t *inst = talloc_get_type_abort(instance, eap_aka_sim_process_conf_t);
+ eap_aka_sim_process_conf_t *inst = talloc_get_type_abort(mctx->inst->data, eap_aka_sim_process_conf_t);
inst->type = FR_EAP_METHOD_AKA_PRIME;
COMPILE_TERMINATOR
};
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- eap_aka_sim_process_conf_t *inst = talloc_get_type_abort(instance, eap_aka_sim_process_conf_t);
+ eap_aka_sim_process_conf_t *inst = talloc_get_type_abort(mctx->inst->data, eap_aka_sim_process_conf_t);
inst->type = FR_EAP_METHOD_SIM;
return state->recv(p_result, mctx, request);
}
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *process_app_cs)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- process_radius_t *inst = instance;
+ process_radius_t *inst = talloc_get_type_abort(mctx->inst->data, process_radius_t);
inst->auth.state_tree = fr_state_tree_init(inst, attr_state, main_config->spawn_workers, inst->auth.max_session,
inst->auth.session_timeout, inst->auth.state_server_id,
return 0;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *cs)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- process_radius_t *inst = instance;
+ process_radius_t *inst = talloc_get_type_abort(mctx->inst->data, process_radius_t);
- inst->server_cs = cf_section_find_in_parent(cs, "server", CF_IDENT_ANY);
+ inst->server_cs = cf_section_find_in_parent(mctx->inst->conf, "server", CF_IDENT_ANY);
if (virtual_server_section_attribute_define(inst->server_cs, "authenticate", attr_auth_type) < 0) return -1;
return 0;
}
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *process_app_cs)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- process_tacacs_t *inst = instance;
+ process_tacacs_t *inst = talloc_get_type_abort(mctx->inst->data, process_tacacs_t);
/*
* Usually we use the 'State' attribute. But, in this
return 0;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *process_app_cs)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- process_tacacs_t *inst = instance;
- CONF_SECTION *server_cs = cf_item_to_section(cf_parent(process_app_cs));
+ process_tacacs_t *inst = talloc_get_type_abort(mctx->inst->data, process_tacacs_t);
+ CONF_SECTION *server_cs = cf_item_to_section(cf_parent(mctx->inst->conf));
- fr_assert(process_app_cs);
+ fr_assert(mctx->inst->conf);
fr_assert(server_cs);
fr_assert(strcmp(cf_section_name1(server_cs), "server") == 0);
return state->recv(p_result, mctx, request);
}
-static int mod_instantiate(void *instance, UNUSED CONF_SECTION *process_app_cs)
+static int mod_instantiate(module_inst_ctx_t const *mctx)
{
- process_ttls_t *inst = instance;
+ process_ttls_t *inst = talloc_get_type_abort(mctx->inst->data, process_ttls_t);
inst->auth.state_tree = fr_state_tree_init(inst, attr_state, main_config->spawn_workers, inst->auth.max_session,
inst->auth.session_timeout, inst->auth.state_server_id,
return 0;
}
-static int mod_bootstrap(void *instance, CONF_SECTION *cs)
+static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
- process_ttls_t *inst = instance;
+ process_ttls_t *inst = talloc_get_type_abort(mctx->inst->data, process_ttls_t);
- inst->server_cs = cf_section_find_in_parent(cs, "server", CF_IDENT_ANY);
+ inst->server_cs = cf_section_find_in_parent(mctx->inst->conf, "server", CF_IDENT_ANY);
if (virtual_server_section_attribute_define(inst->server_cs, "authenticate", attr_auth_type) < 0) return -1;
return 0;