The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Functions | Variables
rlm_sql_postgresql.c File Reference
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/util/debug.h>
#include <sys/stat.h>
#include <libpq-fe.h>
#include <postgres_ext.h>
#include "config.h"
#include "rlm_sql.h"
+ Include dependency graph for rlm_sql_postgresql.c:

Go to the source code of this file.

Data Structures

struct  rlm_sql_postgres_conn_t
 
struct  rlm_sql_postgresql_t
 PostgreSQL configuration. More...
 

Macros

#define LOG_PREFIX   "sql - postgresql"
 
#define NAMEDATALEN   64
 

Functions

static int _sql_socket_destructor (rlm_sql_postgres_conn_t *conn)
 
static int affected_rows (PGresult *result)
 Return the number of affected rows of the result as an int instead of the string that postgresql provides. More...
 
static void free_result_row (rlm_sql_postgres_conn_t *conn)
 Free the row of the current result that's stored in the conn struct. More...
 
static int mod_bootstrap (module_inst_ctx_t const *mctx)
 
static int mod_load (void)
 
static int sql_affected_rows (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
 
static sql_rcode_t sql_classify_error (UNUSED PGresult const *result)
 
static size_t sql_error (TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen, rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
 Retrieves any errors associated with the connection handle. More...
 
static size_t sql_escape_func (request_t *request, char *out, size_t outlen, char const *in, void *arg)
 
static sql_rcode_t sql_fetch_row (rlm_sql_row_t *out, rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
 
static sql_rcode_t sql_fields (char const **out[], rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
 
static sql_rcode_t sql_free_result (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
 
static int sql_num_fields (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
 
static sql_rcode_t sql_query (rlm_sql_handle_t *handle, rlm_sql_config_t const *config, char const *query)
 
static sql_rcode_t sql_select_query (rlm_sql_handle_t *handle, rlm_sql_config_t const *config, char const *query)
 
static int sql_socket_init (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config, UNUSED fr_time_delta_t timeout)
 

Variables

static conf_parser_t driver_config []
 
rlm_sql_driver_t rlm_sql_postgresql
 
static sql_state_entry_t sql_state_table []
 These are PostgreSQL specific error codes which are not covered in SQL 2011. More...
 

Data Structure Documentation

◆ rlm_sql_postgres_conn_t

struct rlm_sql_postgres_conn_t

Definition at line 68 of file rlm_sql_postgresql.c.

Data Fields
int affected_rows
int cur_row
PGconn * db
int num_fields
PGresult * result
char ** row

◆ rlm_sql_postgresql_t

struct rlm_sql_postgresql_t

PostgreSQL configuration.

Definition at line 62 of file rlm_sql_postgresql.c.

+ Collaboration diagram for rlm_sql_postgresql_t:
Data Fields
char const * db_string Text based configuration string.
bool send_application_name Whether we send the application name to PostgreSQL.
fr_trie_t * states sql state trie.

Macro Definition Documentation

◆ LOG_PREFIX

#define LOG_PREFIX   "sql - postgresql"

Definition at line 42 of file rlm_sql_postgresql.c.

◆ NAMEDATALEN

#define NAMEDATALEN   64

Definition at line 56 of file rlm_sql_postgresql.c.

Function Documentation

◆ _sql_socket_destructor()

static int _sql_socket_destructor ( rlm_sql_postgres_conn_t conn)
static

Definition at line 223 of file rlm_sql_postgresql.c.

+ Here is the caller graph for this function:

◆ affected_rows()

static int affected_rows ( PGresult *  result)
static

Return the number of affected rows of the result as an int instead of the string that postgresql provides.

Definition at line 137 of file rlm_sql_postgresql.c.

+ Here is the caller graph for this function:

◆ free_result_row()

static void free_result_row ( rlm_sql_postgres_conn_t conn)
static

Free the row of the current result that's stored in the conn struct.

Definition at line 145 of file rlm_sql_postgresql.c.

+ Here is the caller graph for this function:

◆ mod_bootstrap()

static int mod_bootstrap ( module_inst_ctx_t const *  mctx)
static

Definition at line 547 of file rlm_sql_postgresql.c.

+ Here is the call graph for this function:

◆ mod_load()

static int mod_load ( void  )
static

Definition at line 657 of file rlm_sql_postgresql.c.

◆ sql_affected_rows()

static int sql_affected_rows ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t const *  config 
)
static

Definition at line 518 of file rlm_sql_postgresql.c.

◆ sql_classify_error()

static sql_rcode_t sql_classify_error ( UNUSED PGresult const *  result)
static

Definition at line 216 of file rlm_sql_postgresql.c.

+ Here is the caller graph for this function:

◆ sql_error()

static size_t sql_error ( TALLOC_CTX *  ctx,
sql_log_entry_t  out[],
size_t  outlen,
rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t const *  config 
)
static

Retrieves any errors associated with the connection handle.

Note
Caller will free any memory allocated in ctx.
Parameters
ctxto allocate temporary error buffers in.
outArray of sql_log_entrys to fill.
outlenLength of out array.
handlerlm_sql connection handle.
configrlm_sql config.
Returns
number of errors written to the sql_log_entry_t array.

Definition at line 493 of file rlm_sql_postgresql.c.

+ Here is the call graph for this function:

◆ sql_escape_func()

static size_t sql_escape_func ( request_t request,
char *  out,
size_t  outlen,
char const *  in,
void *  arg 
)
static

Definition at line 525 of file rlm_sql_postgresql.c.

◆ sql_fetch_row()

static sql_rcode_t sql_fetch_row ( rlm_sql_row_t out,
rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t const *  config 
)
static

Definition at line 426 of file rlm_sql_postgresql.c.

+ Here is the call graph for this function:

◆ sql_fields()

static sql_rcode_t sql_fields ( char const **  out[],
rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t const *  config 
)
static

Definition at line 408 of file rlm_sql_postgresql.c.

+ Here is the call graph for this function:

◆ sql_free_result()

static sql_rcode_t sql_free_result ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t const *  config 
)
static

Definition at line 468 of file rlm_sql_postgresql.c.

+ Here is the call graph for this function:

◆ sql_num_fields()

static int sql_num_fields ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t const *  config 
)
static

Definition at line 458 of file rlm_sql_postgresql.c.

◆ sql_query()

static sql_rcode_t sql_query ( rlm_sql_handle_t handle,
rlm_sql_config_t const *  config,
char const *  query 
)
static

Definition at line 264 of file rlm_sql_postgresql.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sql_select_query()

static sql_rcode_t sql_select_query ( rlm_sql_handle_t handle,
rlm_sql_config_t const *  config,
char const *  query 
)
static

Definition at line 403 of file rlm_sql_postgresql.c.

+ Here is the call graph for this function:

◆ sql_socket_init()

static int sql_socket_init ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t const *  config,
UNUSED fr_time_delta_t  timeout 
)
static

Definition at line 235 of file rlm_sql_postgresql.c.

+ Here is the call graph for this function:

Variable Documentation

◆ driver_config

conf_parser_t driver_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("send_application_name", rlm_sql_postgresql_t, send_application_name), .dflt = "yes" },
}
#define CONF_PARSER_TERMINATOR
Definition: cf_parse.h:626
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:268
PostgreSQL configuration.

Definition at line 77 of file rlm_sql_postgresql.c.

◆ rlm_sql_postgresql

rlm_sql_driver_t rlm_sql_postgresql
Initial value:
= {
.common = {
.name = "sql_postgresql",
.inst_size = sizeof(rlm_sql_postgresql_t),
.onload = mod_load,
.bootstrap = mod_bootstrap
},
.number = 2,
.sql_socket_init = sql_socket_init,
.sql_query = sql_query,
.sql_select_query = sql_select_query,
.sql_num_fields = sql_num_fields,
.sql_fields = sql_fields,
.sql_fetch_row = sql_fetch_row,
.sql_error = sql_error,
.sql_finish_query = sql_free_result,
.sql_finish_select_query = sql_free_result,
.sql_affected_rows = sql_affected_rows,
.sql_escape_func = sql_escape_func
}
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:65
static const conf_parser_t config[]
Definition: base.c:188
#define RLM_SQL_RCODE_FLAGS_ALT_QUERY
Can distinguish between other errors and those.
Definition: rlm_sql.h:116
static int mod_load(void)
static size_t sql_escape_func(request_t *request, char *out, size_t outlen, char const *in, void *arg)
static size_t sql_error(TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen, rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
Retrieves any errors associated with the connection handle.
static int sql_socket_init(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config, UNUSED fr_time_delta_t timeout)
static sql_rcode_t sql_fetch_row(rlm_sql_row_t *out, rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
static conf_parser_t driver_config[]
static int mod_bootstrap(module_inst_ctx_t const *mctx)
static sql_rcode_t sql_free_result(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
static sql_rcode_t sql_select_query(rlm_sql_handle_t *handle, rlm_sql_config_t const *config, char const *query)
static int sql_affected_rows(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
static int sql_num_fields(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
static sql_rcode_t sql_query(rlm_sql_handle_t *handle, rlm_sql_config_t const *config, char const *query)
static sql_rcode_t sql_fields(char const **out[], rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)

Definition at line 671 of file rlm_sql_postgresql.c.

◆ sql_state_table

sql_state_entry_t sql_state_table[]
static
Initial value:
= {
{ "03", "SQL statement not yet complete", RLM_SQL_OK },
{ "0B", "Invalid transaction initiation", RLM_SQL_ERROR },
{ "53", "Insufficient resources", RLM_SQL_ERROR },
{ "54", "Program limit exceeded", RLM_SQL_QUERY_INVALID },
{ "55", "Object not in prerequisite state", RLM_SQL_ERROR },
{ "55P03", "Lock not available", RLM_SQL_ERROR },
{ "57", "Operator intervention", RLM_SQL_ERROR },
{ "57014", "Query cancelled", RLM_SQL_ERROR },
{ "57P01", "Admin shutdown", RLM_SQL_RECONNECT },
{ "57P02", "Crash shutdown", RLM_SQL_RECONNECT },
{ "57P03", "Cannot connect now", RLM_SQL_RECONNECT },
{ "58", "System error", RLM_SQL_RECONNECT },
{ "72", "Snapshot failure", RLM_SQL_ERROR },
{ "F0", "Configuration file error", RLM_SQL_ERROR },
{ "P0", "PL/PGSQL error", RLM_SQL_ERROR },
{ "XX", "Internal error", RLM_SQL_ERROR },
{ NULL, NULL, RLM_SQL_ERROR }
}
@ RLM_SQL_QUERY_INVALID
Query syntax error.
Definition: rlm_sql.h:43
@ RLM_SQL_RECONNECT
Stale connection, should reconnect.
Definition: rlm_sql.h:46
@ RLM_SQL_ERROR
General connection/server error.
Definition: rlm_sql.h:44
@ RLM_SQL_OK
Success.
Definition: rlm_sql.h:45

These are PostgreSQL specific error codes which are not covered in SQL 2011.

Definition at line 85 of file rlm_sql_postgresql.c.