27 RCSID(
"$Id: c31ea652034c7c5d82b1bd9c6cb5597d63bd6a76 $")
29 #define LOG_PREFIX inst->name
31 #include <freeradius-devel/server/base.h>
32 #include <freeradius-devel/util/debug.h>
76 if (!handle)
return NULL;
78 handle->
log_ctx = talloc_pool(handle, 2048);
90 rcode = (
inst->driver->sql_socket_init)(handle, &
inst->config,
timeout);
100 if (
inst->config.connect_query) {
102 (
inst->driver->sql_finish_select_query)(handle, &
inst->config);
119 char const *ptr, *
value;
129 if (!row[2] || row[2][0] ==
'\0') {
130 REDEBUG(
"Attribute field is empty or NULL, skipping the entire row");
137 if (row[4] != NULL && row[4][0] !=
'\0') {
139 op =
gettoken(&ptr, buf,
sizeof(buf),
false);
141 REDEBUG(
"Invalid op \"%s\" for attribute %s", row[4], row[2]);
150 REDEBUG(
"The op field for attribute '%s = %s' is NULL, or non-existent.", row[2], row[3]);
151 REDEBUG(
"You MUST FIX THIS if you want the configuration to behave as you expect");
158 REDEBUG(
"Value field is empty or NULL, skipping the entire row");
170 if (row[3] != NULL &&
171 ((row[3][0] ==
'\'') || (row[3][0] ==
'`') || (row[3][0] ==
'"')) &&
172 (row[3][0] == row[3][strlen(row[3])-1])) {
205 if (row[2][0] ==
'.') {
206 char const *p = row[2];
209 REDEBUG(
"Relative attribute '%s' can only be used immediately after an attribute of type 'group'", row[2]);
214 if (!da)
goto unknown;
216 my_list = &(*relative_vp)->vp_group;
217 my_ctx = *relative_vp;
231 RPEDEBUG(
"Unknown attribute '%s'", row[2]);
263 if (my_list ==
out)
switch (da->type) {
278 if (*relative_vp && (
vp != *relative_vp) && (my_ctx != *relative_vp)) {
310 ret = (
inst->driver->sql_fetch_row)(
out, *handle, &
inst->config);
339 char const *driver =
inst->driver_submodule->name;
349 for (i = 0; i < num; i++) {
350 if (force_debug)
goto debug;
352 switch (log[i].
type) {
373 talloc_free_children(handle->
log_ctx);
401 if (query[0] ==
'\0') {
402 if (request)
REDEBUG(
"Zero length query");
415 for (i = 0; i < (
count + 1); i++) {
418 ret = (
inst->driver->sql_query)(*handle, &
inst->config, query);
439 (
inst->driver->sql_finish_query)(*handle, &
inst->config);
454 (
inst->driver->sql_finish_query)(*handle, &
inst->config);
465 (
inst->driver->sql_finish_query)(*handle, &
inst->config);
502 if (query[0] ==
'\0') {
503 if (request)
REDEBUG(
"Zero length query");
516 for (i = 0; i < (
count + 1); i++) {
519 ret = (
inst->driver->sql_select_query)(*handle, &
inst->config, query);
539 (
inst->driver->sql_finish_select_query)(*handle, &
inst->config);
580 .allow_unresolved =
false
597 RPEDEBUG(
"Error parsing user data from database result");
598 (
inst->driver->sql_finish_select_query)(*handle, &
inst->config);
601 if (!map->
parent) map_list_insert_tail(
out, map);
605 (
inst->driver->sql_finish_select_query)(*handle, &
inst->config);
628 if ((write(fd, query, len) < 0) || (write(fd,
";\n", 2) < 0)) failed =
true;
630 if (failed)
ERROR(
"Failed writing to logfile '%s': %s", filename,
fr_syserror(errno));
#define L(_str)
Helper for initialising arrays of string literals.
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
static fr_time_delta_t timeout
fr_dict_attr_t const * fr_dict_attr_by_oid(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *oid))
Resolve an attribute using an OID string.
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
fr_dict_t const * fr_dict_internal(void)
int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, off_t *offset)
Open a new log file, or maybe an existing one.
int exfile_close(exfile_t *ef, int fd)
Close the log file.
#define ROPTIONAL(_l_request, _l_global, _fmt,...)
Use different logging functions depending on whether request is NULL or not.
#define RPEDEBUG(fmt,...)
int map_afrom_fields(TALLOC_CTX *ctx, map_t **out, map_t **parent_p, request_t *request, char const *lhs, char const *op_str, char const *rhs, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules)
Convert a fr_pair_t into a map.
@ L_INFO
Informational message.
@ L_DBG
Only displayed when debugging is enabled.
@ TMPL_ATTR_REF_PREFIX_AUTO
Attribute refs may have a '&' prefix.
@ TMPL_ATTR_REF_PREFIX_YES
Attribute refs must have '&' prefix.
@ FR_TYPE_TLV
Contains nested attributes.
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
fr_pair_t * fr_pair_afrom_da_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da)
Create a pair (and all intermediate parents), and append it to the list.
int fr_pair_value_from_str(fr_pair_t *vp, char const *value, size_t inlen, fr_sbuff_unescape_rules_t const *uerules, bool tainted)
Convert string value to native attribute value.
fr_pool_state_t const * fr_pool_state(fr_pool_t *pool)
Get the number of connections currently in the pool.
void * fr_pool_connection_reconnect(fr_pool_t *pool, request_t *request, void *conn)
Reconnect a suspected inviable connection.
uint32_t num
Number of connections in the pool.
fr_dict_attr_t const * request_attr_request
Prototypes and functions for the SQL module.
rlm_sql_t const * inst
The rlm_sql instance this connection belongs to.
TALLOC_CTX * log_ctx
Talloc pool used to avoid allocing memory when log strings need to be copied.
void * conn
Database specific connection handle.
sql_rcode_t
Action to take at end of an SQL query.
@ RLM_SQL_QUERY_INVALID
Query syntax error.
@ RLM_SQL_ALT_QUERY
Key constraint violation, use an alternative query.
@ RLM_SQL_RECONNECT
Stale connection, should reconnect.
@ RLM_SQL_ERROR
General connection/server error.
@ RLM_SQL_NO_MORE_ROWS
No more rows available.
#define RLM_SQL_RCODE_FLAGS_ALT_QUERY
Can distinguish between other errors and those.
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
@ TMPL_ATTR_LIST_ALLOW
Attribute refs are allowed to have a list.
struct tmpl_rules_s tmpl_rules_t
Optional arguments passed to vp_tmpl functions.
size_t sql_rcode_table_len
void rlm_sql_query_log(rlm_sql_t const *inst, char const *filename, char const *query)
sql_rcode_t rlm_sql_select_query(rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t **handle, char const *query)
Call the driver's sql_select_query method, reconnecting if necessary.
sql_rcode_t rlm_sql_fetch_row(rlm_sql_row_t *out, rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t **handle)
Call the driver's sql_fetch_row function.
int sql_get_map_list(TALLOC_CTX *ctx, rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t **handle, map_list_t *out, char const *query, fr_dict_attr_t const *list)
fr_table_num_sorted_t const sql_rcode_table[]
void * sql_mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
size_t sql_rcode_description_table_len
fr_table_num_sorted_t const sql_rcode_description_table[]
sql_rcode_t rlm_sql_query(rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t **handle, char const *query)
Call the driver's sql_query method, reconnecting if necessary.
void rlm_sql_print_error(rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t *handle, bool force_debug)
Retrieve any errors from the SQL driver.
MEM(pair_append_request(&vp, attr_eap_aka_sim_identity) >=0)
eap_aka_sim_process_conf_t * inst
fr_aka_sim_id_type_t type
fr_dict_attr_t const * list_def
Default list to use with unqualified attribute reference.
fr_dict_t const * dict_def
Default dictionary to use with unqualified attribute references.
tmpl_attr_prefix_t prefix
Whether the attribute reference requires a prefix.
Stores an attribute, a value and various bits of other data.
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
An element in a lexicographically sorted array of name to num mappings.
A time delta, a difference in time measured in nanoseconds.
const bool fr_assignment_op[T_TOKEN_LAST]
fr_token_t gettoken(char const **ptr, char *buf, int buflen, bool unescape)
fr_table_num_ordered_t const fr_tokens_table[]
const bool fr_comparison_op[T_TOKEN_LAST]
#define FR_TYPE_STRUCTURAL
#define FR_MAX_STRING_LEN
static size_t char ** out