static int mod_instantiate(CONF_SECTION *conf, void *instance) { module_instance_t *modinst; rlm_rediswho_t *inst = instance; inst->xlat_name = cf_section_name2(conf); if (!inst->xlat_name) inst->xlat_name = cf_section_name1(conf); inst->cs = conf; modinst = find_module_instance(cf_section_find("modules"), inst->redis_instance_name, 1); if (!modinst) { ERROR("rediswho: failed to find module instance \"%s\"", inst->redis_instance_name); return -1; } if (strcmp(modinst->entry->name, "rlm_redis") != 0) { ERROR("rediswho: Module \"%s\"" " is not an instance of the redis module", inst->redis_instance_name); return -1; } inst->redis_inst = (REDIS_INST *) modinst->insthandle; return 0; }
/* * Do any per-module initialization that is separate to each * configured instance of the module. e.g. set up connections * to external databases, read configuration files, set up * dictionary entries, etc. * * If configuration information is given in the config section * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ static int mod_instantiate(CONF_SECTION *conf, void *instance) { module_instance_t *sqlinst; rlm_sqlippool_t *inst = instance; char const *pool_name = NULL; pool_name = cf_section_name2(conf); if (pool_name != NULL) { inst->pool_name = talloc_typed_strdup(inst, pool_name); } else { inst->pool_name = talloc_typed_strdup(inst, "ippool"); } sqlinst = find_module_instance(cf_section_find("modules"), inst->sql_instance_name, 1); if (!sqlinst) { cf_log_err_cs(conf, "failed to find sql instance named %s", inst->sql_instance_name); return -1; } if (strcmp(sqlinst->entry->name, "rlm_sql") != 0) { cf_log_err_cs(conf, "Module \"%s\"" " is not an instance of the rlm_sql module", inst->sql_instance_name); return -1; } inst->sql_inst = (rlm_sql_t *) sqlinst->insthandle; return 0; }
static int rediswho_instantiate(CONF_SECTION * conf, void ** instance) { module_instance_t *modinst; rlm_rediswho_t *inst; /* * Set up a storage area for instance data */ inst = *instance = rad_malloc(sizeof (*inst)); memset(inst, 0, sizeof (*inst)); /* * If the configuration parameters can't be parsed, then * fail. */ if (cf_section_parse(conf, inst, module_config) < 0) { free(inst); return -1; } inst->xlat_name = cf_section_name2(conf); if (!inst->xlat_name) inst->xlat_name = cf_section_name1(conf); inst->xlat_name = strdup(inst->xlat_name); inst->cs = conf; modinst = find_module_instance(cf_section_find("modules"), inst->redis_instance_name, 1); if (!modinst) { radlog(L_ERR, "rediswho: failed to find module instance \"%s\"", inst->redis_instance_name); rediswho_detach(inst); return -1; } if (strcmp(modinst->entry->name, "rlm_redis") != 0) { radlog(L_ERR, "rediswho: Module \"%s\"" " is not an instance of the redis module", inst->redis_instance_name); rediswho_detach(inst); return -1; } inst->redis_inst = (REDIS_INST *) modinst->insthandle; return 0; }
/* standard foobar code */ static int sqlhpwippool_instantiate(CONF_SECTION *conf, void **instance) { rlm_sqlhpwippool_t *data; module_instance_t *modinst; /* set up a storage area for instance data */ data = rad_malloc(sizeof(*data)); if (!data) return -1; memset(data, 0, sizeof(*data)); /* so _detach will know what to free */ /* fail if the configuration parameters can't be parsed */ if (cf_section_parse(conf, data, module_config) < 0) { sqlhpwippool_detach(*instance); return -1; } /* save my name */ data->myname = cf_section_name2(conf); if (!data->myname) { data->myname = "(no name)"; } data->sincesync = 0; modinst = find_module_instance(cf_section_find("modules"), (data->sqlinst_name), 1 ); if (!modinst) { nvp_log(__LINE__, data, L_ERR, "sqlhpwippool_instantiate(): cannot find module instance " "named \"%s\"", data->sqlinst_name); return -1; } /* check if the given instance is really a rlm_sql instance */ if (strcmp(modinst->entry->name, "rlm_sql") != 0) { nvp_log(__LINE__, data, L_ERR, "sqlhpwippool_instantiate(): given instance (%s) is not " "an instance of the rlm_sql module", data->sqlinst_name); return -1; } /* save pointers to useful "objects" */ data->sqlinst = (SQL_INST *) modinst->insthandle; data->db = (rlm_sql_module_t *) data->sqlinst->module; /* everything went ok, cleanup pool */ *instance = data; return ((nvp_cleanup(data)) ? 0 : -1); }
/* standard foobar code */ static int mod_instantiate(CONF_SECTION *conf, void *instance) { rlm_sqlhpwippool_t *inst = instance; module_instance_t *sqlinst; /* save my name */ inst->myname = cf_section_name2(conf); if (!inst->myname) { inst->myname = "(no name)"; } inst->sincesync = 0; sqlinst = find_module_instance(cf_section_find("modules"), (inst->sql_module_instance), 1 ); if (!sqlinst) { nvp_log(__LINE__, inst, L_ERR, "mod_instantiate(): cannot find module instance " "named \"%s\"", inst->sql_module_instance); return -1; } /* check if the given instance is really a rlm_sql instance */ if (strcmp(sqlinst->entry->name, "rlm_sql") != 0) { nvp_log(__LINE__, inst, L_ERR, "mod_instantiate(): given instance (%s) is not " "an instance of the rlm_sql module", inst->sql_module_instance); return -1; } /* save pointers to useful "objects" */ inst->sqlinst = (rlm_sql_t *) sqlinst->insthandle; inst->db = (rlm_sql_module_t *) inst->sqlinst->module; return ((nvp_cleanup(inst)) ? 0 : -1); }
/* * Do any per-module initialization that is separate to each * configured instance of the module. e.g. set up connections * to external databases, read configuration files, set up * dictionary entries, etc. * * If configuration information is given in the config section * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ static int sqlippool_instantiate(CONF_SECTION * conf, void ** instance) { module_instance_t *modinst; rlm_sqlippool_t * data; const char * pool_name = NULL; /* * Set up a storage area for instance data */ data = rad_malloc(sizeof(*data)); memset(data, 0, sizeof(*data)); /* * If the configuration parameters can't be parsed, then * fail. */ if (cf_section_parse(conf, data, module_config) < 0) { free(data); return -1; } if (IS_EMPTY(data->sql_instance_name)) { radlog(L_ERR, "rlm_sqlippool: the 'sql-instance-name' variable must be set."); sqlippool_detach(data); return -1; } /* * Check that all the queries are in place */ if (IS_EMPTY(data->allocate_clear)) { radlog(L_ERR, "rlm_sqlippool: the 'allocate-clear' statement must be set."); sqlippool_detach(data); return -1; } if (IS_EMPTY(data->allocate_find)) { radlog(L_ERR, "rlm_sqlippool: the 'allocate-find' statement must be set."); sqlippool_detach(data); return -1; } if (IS_EMPTY(data->allocate_update)) { radlog(L_ERR, "rlm_sqlippool: the 'allocate-update' statement must be set."); sqlippool_detach(data); return -1; } if (IS_EMPTY(data->start_update)) { radlog(L_ERR, "rlm_sqlippool: the 'start-update' statement must be set."); sqlippool_detach(data); return -1; } if (IS_EMPTY(data->alive_update)) { radlog(L_ERR, "rlm_sqlippool: the 'alive-update' statement must be set."); sqlippool_detach(data); return -1; } if (IS_EMPTY(data->stop_clear)) { radlog(L_ERR, "rlm_sqlippool: the 'stop-clear' statement must be set."); sqlippool_detach(data); return -1; } if (IS_EMPTY(data->on_clear)) { radlog(L_ERR, "rlm_sqlippool: the 'on-clear' statement must be set."); sqlippool_detach(data); return -1; } if (IS_EMPTY(data->off_clear)) { radlog(L_ERR, "rlm_sqlippool: the 'off-clear' statement must be set."); sqlippool_detach(data); return -1; } pool_name = cf_section_name2(conf); if (pool_name != NULL) data->pool_name = strdup(pool_name); else data->pool_name = strdup("ippool"); modinst = find_module_instance(cf_section_find("modules"), data->sql_instance_name, 1); if (!modinst) { radlog(L_ERR, "sqlippool_instantiate: failed to find sql instance named %s", data->sql_instance_name); sqlippool_detach(data); return -1; } if (strcmp(modinst->entry->name, "rlm_sql") != 0) { radlog(L_ERR, "sqlippool_instantiate: Module \"%s\"" " is not an instance of the rlm_sql module", data->sql_instance_name); sqlippool_detach(data); return -1; } data->sql_inst = (SQL_INST *) modinst->insthandle; *instance = data; return 0; }
static int rediswho_instantiate(CONF_SECTION * conf, void ** instance) { module_instance_t *modinst; rlm_rediswho_t *inst; /* * Set up a storage area for instance data */ inst = *instance = rad_malloc(sizeof (*inst)); memset(inst, 0, sizeof (*inst)); /* * If the configuration parameters can't be parsed, then * fail. */ if (cf_section_parse(conf, inst, module_config) < 0) { free(inst); return -1; } inst->xlat_name = cf_section_name2(conf); if (!inst->xlat_name) inst->xlat_name = cf_section_name1(conf); inst->xlat_name = strdup(inst->xlat_name); DEBUG("xlat name %s\n", inst->xlat_name); /* * Check that all the queries are in place */ if ((inst->start_insert == NULL) || !*inst->start_insert) { radlog(L_ERR, "rlm_rediswho: the 'start_insert' statement must be set."); rediswho_detach(inst); return -1; } if ((inst->start_trim == NULL) || !*inst->start_trim) { radlog(L_ERR, "rlm_rediswho: the 'start_trim' statement must be set."); rediswho_detach(inst); return -1; } if ((inst->start_expire == NULL) || !*inst->start_expire) { radlog(L_ERR, "rlm_rediswho: the 'start_expire' statement must be set."); rediswho_detach(inst); return -1; } if ((inst->alive_insert == NULL) || !*inst->alive_insert) { radlog(L_ERR, "rlm_rediswho: the 'alive_insert' statement must be set."); rediswho_detach(inst); return -1; } if ((inst->alive_trim == NULL) || !*inst->alive_trim) { radlog(L_ERR, "rlm_rediswho: the 'alive_trim' statement must be set."); rediswho_detach(inst); return -1; } if ((inst->alive_expire == NULL) || !*inst->alive_expire) { radlog(L_ERR, "rlm_rediswho: the 'alive_expire' statement must be set."); rediswho_detach(inst); return -1; } if ((inst->stop_insert == NULL) || !*inst->stop_insert) { radlog(L_ERR, "rlm_rediswho: the 'stop_insert' statement must be set."); rediswho_detach(inst); return -1; } if ((inst->stop_trim == NULL) || !*inst->stop_trim) { radlog(L_ERR, "rlm_rediswho: the 'stop_trim' statement must be set."); rediswho_detach(inst); return -1; } if ((inst->stop_expire == NULL) || !*inst->stop_expire) { radlog(L_ERR, "rlm_rediswho: the 'stop_expire' statement must be set."); rediswho_detach(inst); return -1; } modinst = find_module_instance(cf_section_find("modules"), inst->redis_instance_name, 1); if (!modinst) { radlog(L_ERR, "rediswho: failed to find module instance \"%s\"", inst->redis_instance_name); rediswho_detach(inst); return -1; } if (strcmp(modinst->entry->name, "rlm_redis") != 0) { radlog(L_ERR, "rediswho: Module \"%s\"" " is not an instance of the redis module", inst->redis_instance_name); rediswho_detach(inst); return -1; } inst->redis_inst = (REDIS_INST *) modinst->insthandle; return 0; }