28 RCSIDH(rlm_sql_h,
"$Id: 76d359c8268173a106db85087ae0b6395f143df8 $")
30 #include <freeradius-devel/server/base.h>
31 #include <freeradius-devel/server/pool.h>
32 #include <freeradius-devel/server/modpriv.h>
33 #include <freeradius-devel/server/exfile.h>
34 #include <freeradius-devel/server/trunk.h>
35 #include <freeradius-devel/unlang/function.h>
37 #define FR_ITEM_CHECK 0
38 #define FR_ITEM_REPLY 1
172 #define RLM_SQL_RCODE_FLAGS_ALT_QUERY 1
174 #define RLM_SQL_MULTI_QUERY_CONN 2
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
A section grouping multiple CONF_PAIR.
fr_dcursor_eval_t void const * uctx
static fr_time_delta_t timeout
unlang_action_t(* unlang_function_t)(rlm_rcode_t *p_result, int *priority, request_t *request, void *uctx)
A generic function pushed by a module or xlat to functions deeper in the C call stack to create resum...
Stores all information relating to an event list.
size_t(* xlat_escape_legacy_t)(request_t *request, char *out, size_t outlen, char const *in, void *arg)
static const conf_parser_t config[]
rlm_rcode_t
Return codes indicating the result of the module call.
char const * msg
Log message.
rlm_sql_t const * inst
The rlm_sql instance this connection belongs to.
int sql_state_entries_from_table(fr_trie_t *states, sql_state_entry_t const table[])
Insert the contents of a state table into the state trie.
sql_rcode_t rcode
What should happen if we receive this error.
char const * sql_db
Database to run queries against.
fr_log_type_t type
Type of log entry L_ERR, L_WARN, L_INFO, L_DBG etc.
trunk_t * trunk
Trunk connection for this thread.
fr_sql_query_status_t status
Status of the query.
trunk_connection_t * tconn
Trunk connection this query is being run on.
TALLOC_CTX * log_ctx
Talloc pool used to avoid allocing memory when log strings need to be copied.
size_t sql_rcode_table_len
rlm_sql_t const * inst
Module instance data.
fr_sql_query_type_t type
Type of 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 * conn
Database specific connection handle.
unlang_action_t rlm_sql_query(rlm_rcode_t *p_result, int *priority, request_t *request, void *uctx)
void rlm_sql_query_log(rlm_sql_t const *inst, char const *filename, char const *query)
unlang_action_t sql_get_map_list(request_t *request, fr_sql_map_ctx_t *map_ctx, rlm_sql_handle_t **handle, trunk_t *trunk)
Submit the query to get any user / group check or reply pairs.
unlang_action_t rlm_sql_select_query(rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
Call the driver's sql_select_query method, reconnecting if necessary.
char const * meaning
Verbose description.
void * uctx
Driver specific data.
trunk_t * trunk
Trunk this query is being run on.
rlm_sql_handle_t * handle
fr_table_num_sorted_t const sql_rcode_table[]
char const * group_attribute
Name of the group attribute.
fr_trie_t * sql_state_trie_alloc(TALLOC_CTX *ctx)
Allocate a sql_state trie, and insert the initial set of entries.
char const * allowed_chars
Chars which done need escaping..
rlm_sql_t const * inst
Module instance for this query.
char const * query_str
Query string to run.
request_t * request
Request this query relates to.
fr_sql_query_t * query_ctx
Query context.
map_list_t * out
List to append entries to.
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.
fr_time_delta_t query_timeout
How long to allow queries to run for.
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.
bool cache_groups
cache group names in &control.SQL-Group
rlm_sql_handle_t * handle
Connection handle this query is being run on.
char const * sql_server
Server to connect to.
TALLOC_CTX * ctx
To allocate map entries in.
void * sql_escape_arg
Thread specific argument to be passed to escape function.
char const * sql_state
2-5 char error code.
size_t(* sql_error_t)(TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen, fr_sql_query_t *handle)
Retrieve errors from the last query operation.
rlm_sql_t const * inst
Module instance data.
char const * sql_login
Login credentials to use.
int rows
How many rows the query returned.
sql_state_entry_t const * sql_state_entry_find(fr_trie_t const *states, char const *sql_state)
Lookup an SQL state based on an error code returned from the SQL server or client library.
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.
rlm_sql_row_t row
Row data from the last query.
int sql_state_entries_from_cs(fr_trie_t *states, CONF_SECTION *overrides)
Insert the contents of a CONF_SECTION into the state trie.
sql_rcode_t rcode
Result code.
char const * sql_password
Login password to use.
void * sql_mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
fr_value_box_t * query
Query string used for fetching pairs.
trunk_request_t * treq
Trunk request for this query.
bool read_profiles
Read user profiles by default.
uint32_t sql_port
Port to connect to.
fr_sql_query_t * fr_sql_query_alloc(TALLOC_CTX *ctx, rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t *handle, trunk_t *trunk, char const *query_str, fr_sql_query_type_t type)
Allocate an sql query structure.
size_t sql_rcode_description_table_len
char const * connect_query
Query executed after establishing new connection.
trunk_conf_t trunk_conf
Configuration for trunk connections.
fr_table_num_sorted_t const sql_rcode_description_table[]
fr_sql_query_status_t
Status of an SQL query.
@ SQL_QUERY_CANCELLED
A cancellation has been sent to the server.
@ SQL_QUERY_RETURNED
Query has executed.
@ SQL_QUERY_FETCHING_RESULTS
Fetching results from server.
@ SQL_QUERY_FAILED
Failed to submit.
@ SQL_QUERY_SUBMITTED
Submitted for execution.
@ SQL_QUERY_PREPARED
Ready to submit.
@ SQL_QUERY_RESULTS_FETCHED
Results fetched from the server.
fr_dict_attr_t const * list
Default list for pair evaluation.
bool read_groups
Read user groups by default.
Context used when fetching attribute value pairs as a map list.
static sql_rcode_t sql_fields(char const **out[], fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
static int sql_num_rows(fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
static int sql_affected_rows(UNUSED fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
static sql_rcode_t sql_finish_query(fr_sql_query_t *query_ctx, rlm_sql_config_t const *config)
static sql_rcode_t sql_free_result(fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
static sql_rcode_t sql_finish_select_query(fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
static void sql_escape_arg_free(void *uctx)
static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config, UNUSED fr_time_delta_t timeout)
Struct exported by a rlm_* module.
eap_aka_sim_process_conf_t * inst
fr_aka_sim_id_type_t type
module_t common
Common fields for all loadable modules.
unlang_function_t sql_query
Run an SQL query on a pool connection.
sql_error_t sql_error
Get any errors from the previous query.
bool uses_trunks
Transitional flag for drivers which use trunks.
trunk_io_funcs_t trunk_io_funcs
Trunk callback functions for this driver.
xlat_escape_legacy_t sql_escape_func
unlang_function_t sql_query_resume
Callback run after an SQL trunk query is run.
unlang_function_t sql_fetch_row
unlang_function_t sql_select_query
Run an SQL select query on a pool connection.
unlang_function_t sql_select_query_resume
Callback run after an SQL select trunk query is run.
unlang_function_t fetch_row
module_instance_t * driver_submodule
Driver's submodule.
char const * name
Module instance name.
fr_dict_attr_t const * group_da
Group dictionary attribute.
fr_dict_attr_t const * sql_user
Cached pointer to SQL-User-Name dictionary attribute.
fr_value_box_escape_t box_escape_func
rlm_sql_driver_t const * driver
Driver's exported interface.
xlat_escape_legacy_t sql_escape_func
module_instance_t const * mi
Module instance data for thread lookups.
void * sql_escape_arg
Instance specific argument to be passed to escape function.
An element in a lexicographically sorted array of name to num mappings.
A time delta, a difference in time measured in nanoseconds.
Associates request queues with a connection.
Main trunk management handle.
Common configuration parameters for a trunk.
I/O functions to pass to trunk_alloc.
static fr_event_list_t * el
int(* fr_value_box_escape_t)(fr_value_box_t *vb, void *uctx)
Escape a value box.
static size_t char ** out