27RCSID(
"$Id: 0320b71ad6b2a7eab816d4e9431faaad1ffcc995 $")
29#define LOG_PREFIX inst->name
31#include <freeradius-devel/server/base.h>
32#include <freeradius-devel/util/debug.h>
85 if (!query_ctx->
tconn) {
96 (
inst->driver->sql_fetch_row)(p_result, NULL, request, query_ctx);
97 switch (query_ctx->
rcode) {
125 char const *driver =
inst->driver_submodule->name;
128 TALLOC_CTX *log_ctx = talloc_new(NULL);
130 num = (
inst->driver->sql_error)(log_ctx, log, (
NUM_ELEMENTS(log)), query_ctx);
137 for (i = 0; i < num; i++) {
138 if (force_debug)
goto debug;
140 switch (log[i].
type) {
170 if (to_free->
status > 0) {
193 .query_str = query_str,
214 if (!query_ctx->
treq)
return;
224 query_ctx->
treq = NULL;
244 if (request)
REDEBUG(
"Zero length query");
285 REDEBUG(
"Unable to enqueue SQL query");
302 .list_def = map_ctx->
list,
321 row = query_ctx->
row;
322 if (!row[2] || !row[3] || !row[4]) {
323 RPERROR(
"SQL query returned NULL values");
327 RPEDEBUG(
"Error parsing user data from database result");
330 if (!map->
parent) map_list_insert_tail(map_ctx->
out, map);
374 if ((write(fd, query, len) < 0) || (write(fd,
";\n", 2) < 0)) failed =
true;
376 if (failed)
ERROR(
"Failed writing to logfile '%s': %s", filename,
fr_syserror(errno));
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
@ UNLANG_ACTION_PUSHED_CHILD
unlang_t pushed a new child onto the stack, execute it instead of continuing.
@ UNLANG_ACTION_FAIL
Encountered an unexpected error.
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
@ UNLANG_ACTION_YIELD
Temporarily pause execution until an event occurs.
#define L(_str)
Helper for initialising arrays of string literals.
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 unlang_function_push(_request, _func, _repeat, _signal, _sigmask, _top_frame, _uctx)
Push a generic function onto the unlang stack.
#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.
#define RETURN_MODULE_INVALID
#define RETURN_MODULE_FAIL
rlm_rcode_t
Return codes indicating the result of the module call.
@ RLM_MODULE_OK
The module is OK, continue.
fr_dict_attr_t const * request_attr_request
Prototypes and functions for the SQL module.
fr_sql_query_status_t status
Status of the query.
trunk_connection_t * tconn
Trunk connection this query is being run on.
fr_sql_query_type_t type
Type of query.
trunk_t * trunk
Trunk this query is being run on.
rlm_sql_t const * inst
Module instance for this query.
char const * query_str
Query string to run.
fr_sql_query_t * query_ctx
Query context.
map_list_t * out
List to append entries to.
@ 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.
TALLOC_CTX * ctx
To allocate map entries in.
rlm_sql_t const * inst
Module instance data.
int rows
How many rows the query returned.
rlm_sql_row_t row
Row data from the last query.
sql_rcode_t rcode
Result code.
fr_value_box_t * query
Query string used for fetching pairs.
trunk_request_t * treq
Trunk request for this query.
@ SQL_QUERY_FAILED
Failed to submit.
fr_dict_attr_t const * list
Default list for pair evaluation.
Context used when fetching attribute value pairs as a map list.
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.
fr_signal_t
Signals that can be generated/processed by request signal handlers.
fr_sql_query_t * fr_sql_query_alloc(TALLOC_CTX *ctx, rlm_sql_t const *inst, request_t *request, trunk_t *trunk, char const *query_str, fr_sql_query_type_t type)
Allocate an sql query structure.
size_t sql_rcode_table_len
static int fr_sql_query_free(fr_sql_query_t *to_free)
Automatically run the correct finish function when freeing an SQL query.
unlang_action_t rlm_sql_fetch_row(rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
Call the driver's sql_fetch_row function.
void rlm_sql_query_log(rlm_sql_t const *inst, char const *filename, char const *query)
fr_table_num_sorted_t const sql_rcode_table[]
unlang_action_t sql_get_map_list(request_t *request, fr_sql_map_ctx_t *map_ctx, trunk_t *trunk)
Submit the query to get any user / group check or reply pairs.
unlang_action_t rlm_sql_trunk_query(rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
Submit an SQL query using a trunk connection.
static void sql_trunk_query_cancel(UNUSED request_t *request, UNUSED fr_signal_t action, void *uctx)
Cancel an SQL query submitted on a trunk.
static unlang_action_t sql_trunk_query_start(UNUSED rlm_rcode_t *p_result, UNUSED int *priority, UNUSED request_t *request, UNUSED void *uctx)
Yield processing after submitting a trunk request.
static unlang_action_t sql_get_map_list_resume(rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
Process the results of an SQL query to produce a map list.
void rlm_sql_print_error(rlm_sql_t const *inst, request_t *request, fr_sql_query_t *query_ctx, bool force_debug)
Retrieve any errors from the SQL driver.
size_t sql_rcode_description_table_len
fr_table_num_sorted_t const sql_rcode_description_table[]
eap_aka_sim_process_conf_t * inst
fr_aka_sim_id_type_t type
trunk_io_funcs_t trunk_io_funcs
Trunk callback functions for this driver.
unlang_function_t sql_query_resume
Callback run after an SQL trunk query is run.
sql_rcode_t(* sql_finish_query)(fr_sql_query_t *query_ctx, rlm_sql_config_t const *config)
sql_rcode_t(* sql_finish_select_query)(fr_sql_query_t *query_ctx, rlm_sql_config_t const *config)
unlang_function_t sql_select_query_resume
Callback run after an SQL select trunk query is run.
rlm_sql_driver_t const * driver
Driver's exported interface.
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.
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
An element in a lexicographically sorted array of name to num mappings.
trunk_enqueue_t trunk_request_enqueue(trunk_request_t **treq_out, trunk_t *trunk, request_t *request, void *preq, void *rctx)
Enqueue a request that needs data written to the trunk.
trunk_enqueue_t trunk_request_requeue(trunk_request_t *treq)
Re-enqueue a request on the same connection.
void trunk_request_signal_cancel(trunk_request_t *treq)
Cancel a trunk request.
void trunk_request_signal_complete(trunk_request_t *treq)
Signal that a trunk request is complete.
Main trunk management handle.
@ TRUNK_ENQUEUE_OK
Operation was successful.
@ TRUNK_ENQUEUE_IN_BACKLOG
Request should be enqueued in backlog.
trunk_request_cancel_mux_t request_cancel_mux
!< Read one or more requests from a connection.
@ TRUNK_REQUEST_STATE_REAPABLE
Request has been written, needs to persist, but we are not currently waiting for any response.
@ TRUNK_REQUEST_STATE_INIT
Initial state.