26 RCSID(
"$Id: 5c24a61dec4bd03f8ea9c06b89f07c30b01b99e7 $")
28 #include <freeradius-devel/radiusd.h>
29 #include <freeradius-devel/rad_assert.h>
35 #define MAX_QUERY_LEN 4096
195 for (p = fmt; *p ; p++) {
200 freespace = outlen - (q - out);
221 if (param && param_len > 0) {
222 if (param_len > freespace) {
227 memcpy(q, param, param_len);
248 DEBUG2(
"sqlippool_expand: \"%s\"", out);
270 char *param,
int param_len)
273 char *expanded = NULL;
280 if (!fmt || !*fmt)
return 0;
293 talloc_free(expanded);
296 talloc_free(expanded);
306 #define DO(_x) sqlippool_command(inst->_x, handle, inst, request, NULL, 0)
311 static int CC_HINT(nonnull (1, 3, 4, 5)) sqlippool_query1(
char *out,
int outlen,
char const *fmt,
313 REQUEST *request,
char *param,
int param_len)
316 char *expanded = NULL;
332 if (
radius_axlat(&expanded, request, query, data->sql_inst->sql_escape_func, handle) < 0) {
335 retval = data->sql_inst->sql_select_query(data->sql_inst, request, &handle, expanded);
336 talloc_free(expanded);
339 REDEBUG(
"database query error on '%s'", query);
343 if (data->sql_inst->sql_fetch_row(&row, data->sql_inst, request, &handle) < 0) {
344 REDEBUG(
"Failed fetching query result");
349 REDEBUG(
"SQL query did not return any results");
354 REDEBUG(
"The first column of the result was NULL");
358 rlen = strlen(row[0]);
359 if (rlen >= outlen) {
360 RDEBUG(
"insufficient string space");
367 (data->sql_inst->module->sql_finish_select_query)(handle, data->sql_inst->config);
386 char const *pool_name = NULL;
389 if (pool_name != NULL) {
408 if (strcmp(sql_inst->
entry->
name,
"rlm_sql") != 0) {
410 " is not an instance of the rlm_sql module",
426 char *expanded = NULL;
428 if (!str || !*str)
return rcode;
430 if (
radius_axlat(&expanded, request, str, NULL, NULL) < 0) {
436 talloc_free(expanded);
458 RDEBUG(
"Framed-IP-Address already exists");
464 RDEBUG(
"No Pool-Name defined");
471 REDEBUG(
"cannot get sql connection");
497 allocation_len = sqlippool_query1(allocation,
sizeof(allocation),
499 inst, request, (
char *) NULL, 0);
504 if (allocation_len == 0) {
516 allocation_len = sqlippool_query1(allocation,
sizeof(allocation),
522 if (allocation_len) {
532 RDEBUG(
"pool appears to be full");
543 RDEBUG(
"IP address could not be allocated as no pool exists with that name");
550 RDEBUG(
"IP address could not be allocated");
562 RDEBUG(
"Invalid IP number [%s] returned from instbase query.", allocation);
567 RDEBUG(
"Allocated IP %s", allocation);
574 allocation, allocation_len);
641 int acct_status_type;
647 RDEBUG(
"Could not find account status type in packet");
650 acct_status_type = vp->vp_integer;
652 switch (acct_status_type) {
667 RDEBUG(
"Cannot allocate sql connection");
675 switch (acct_status_type) {
717 .config = module_config,
ssize_t ssize_t ssize_t radius_axlat(char **out, REQUEST *request, char const *fmt, xlat_escape_t escape, void *escape_ctx) CC_HINT(nonnull(1
char const * off_begin
SQL query to begin.
static int mod_accounting_alive(rlm_sql_handle_t *handle, rlm_sqlippool_t *inst, REQUEST *request)
char const * start_begin
SQL query to begin.
char const * start_update
SQL query to update an IP entry.
Main server configuration.
static rlm_rcode_t mod_accounting(void *instance, REQUEST *request)
Write accounting data to Couchbase documents.
Prototypes and functions for the SQL module.
The module is OK, continue.
char const * sql_instance_name
static rlm_rcode_t mod_post_auth(void *instance, REQUEST *request) CC_HINT(nonnull)
Metadata exported by the module.
char const * alive_begin
SQL query to begin.
VALUE_PAIR * fr_pair_afrom_num(TALLOC_CTX *ctx, unsigned int vendor, unsigned int attr)
Create a new valuepair.
char const * log_failed
Failed to allocate ip from the pool.
char const * allocate_begin
SQL query to begin.
char const * alive_update
SQL query to update an IP entry.
7 methods index for postauth section.
char const * stop_clear
SQL query to clear an IP.
char const * on_clear
SQL query to clear an entire NAS.
#define RLM_TYPE_THREAD_SAFE
Module is threadsafe.
char const * allocate_clear
SQL query to clear an IP.
#define CONF_PARSER_TERMINATOR
static int sqlippool_expand(char *out, int outlen, char const *fmt, rlm_sqlippool_t *data, char *param, int param_len)
module_instance_t * module_instantiate(CONF_SECTION *modules, char const *askedname)
Load a module, and instantiate it.
char const * allocate_update
SQL query to mark an IP as used.
char const * alive_commit
SQL query to commit.
#define PW_TYPE_SUBSECTION
Defines a CONF_PAIR to C data type mapping.
char const * stop_commit
SQL query to commit.
static CONF_PARSER module_config[]
int(* sql_set_user)(rlm_sql_t const *inst, REQUEST *request, char const *username)
static int mod_accounting_on(rlm_sql_handle_t *handle, rlm_sqlippool_t *inst, REQUEST *request)
char const * log_exists
There was an ip address already assigned.
#define pair_make_config(_a, _b, _c)
void fr_pair_add(VALUE_PAIR **head, VALUE_PAIR *vp)
Add a VP to the end of the list.
#define PW_TYPE_XLAT
string will be dynamically expanded.
xlat_escape_t sql_escape_func
3 methods index for accounting section.
static int mod_instantiate(CONF_SECTION *conf, void *instance)
Stores an attribute, a value and various bits of other data.
void void cf_log_err_cs(CONF_SECTION const *cs, char const *fmt,...) CC_HINT(format(printf
rlm_sql_config_t * config
char const * log_clear
We successfully deallocated ip address from pool.
enum rlm_rcodes rlm_rcode_t
Return codes indicating the result of the module call.
int fr_pair_value_from_str(VALUE_PAIR *vp, char const *value, size_t len)
Convert string value to native attribute value.
char const * pool_check
Query to check for the existence of the pool.
CONF_SECTION * cf_section_sub_find(CONF_SECTION const *, char const *name)
Find a sub-section in a section.
struct rlm_sqlippool_t rlm_sqlippool_t
char const * allocate_commit
SQL query to commit.
Module succeeded without doing anything.
static int do_logging(REQUEST *request, char const *str, int rcode)
uint64_t magic
Used to validate module struct.
Module failed, don't reply.
CONF_SECTION * config
Root of the server config.
#define FR_CONF_OFFSET(_n, _t, _s, _f)
static int CC_HINT(nonnull(1, 3, 4, 5))
char const * off_commit
SQL query to commit.
void * fr_connection_get(fr_connection_pool_t *pool)
Reserve a connection in the connection pool.
time_t last_clear
So we only do it once a second.
char const * log_nopool
There was no Framed-IP-Address but also no Pool-Name.
#define PW_STATUS_ACCOUNTING_ON
char const * off_clear
SQL query to clear an entire NAS.
static int mod_accounting_off(rlm_sql_handle_t *handle, rlm_sqlippool_t *inst, REQUEST *request)
#define PW_TYPE_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
VALUE_PAIR * fr_pair_find_by_num(VALUE_PAIR *head, unsigned int vendor, unsigned int attr, int8_t tag)
Find the pair with the matching attribute.
bool ipv6
Whether or not we do IPv6 pools.
static CONF_PARSER message_config[]
char const * stop_begin
SQL query to begin.
char const * start_commit
SQL query to commit.
size_t strlcpy(char *dst, char const *src, size_t siz)
sql_rcode_t(* sql_query)(rlm_sql_t const *inst, REQUEST *request, rlm_sql_handle_t **handle, char const *query)
char const * defaultpool
Default Pool-Name if there is none in the check items.
sql_rcode_t(* sql_finish_query)(rlm_sql_handle_t *handle, rlm_sql_config_t *config)
void fr_connection_release(fr_connection_pool_t *pool, void *conn)
Release a connection.
char const * allocate_find
SQL query to find an unused IP.
String of printable characters.
#define FR_CONF_POINTER(_n, _t, _p)
char const * log_success
We successfully allocated ip address from pool.
static int mod_accounting_stop(rlm_sql_handle_t *handle, rlm_sqlippool_t *inst, REQUEST *request)
rlm_sql_module_t * module
char const * on_commit
SQL query to commit.
int framed_ip_address
the attribute number for Framed-IP(v6)-Address
char * talloc_typed_strdup(void const *t, char const *p)
Call talloc strdup, setting the type on the new chunk correctly.
static int mod_accounting_start(rlm_sql_handle_t *handle, rlm_sqlippool_t *inst, REQUEST *request)
fr_connection_pool_t * pool
#define PW_STATUS_ACCOUNTING_OFF
char const * cf_section_name2(CONF_SECTION const *cs)
static int sqlippool_command(char const *fmt, rlm_sql_handle_t *handle, rlm_sqlippool_t *data, REQUEST *request, char *param, int param_len)
Perform a single sqlippool query.
char const * on_begin
SQL query to begin.