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 "rlm_sql_trunk.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 void _sql_connect_io_notify (fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
 
static void _sql_connection_close (fr_event_list_t *el, void *h, UNUSED void *uctx)
 
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...
 
 CC_NO_UBSAN (function)
 
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_instantiate (module_inst_ctx_t const *mctx)
 
static int mod_load (void)
 
static int sql_affected_rows (fr_sql_query_t *query_ctx, 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, fr_sql_query_t *query_ctx)
 Retrieves any errors associated with the query context. More...
 
static void * sql_escape_arg_alloc (TALLOC_CTX *ctx, fr_event_list_t *el, void *uctx)
 
static void sql_escape_arg_free (void *uctx)
 
static ssize_t sql_escape_func (request_t *request, char *out, size_t outlen, char const *in, void *arg)
 
static unlang_action_t sql_fetch_row (rlm_rcode_t *p_result, UNUSED int *priority, UNUSED request_t *request, void *uctx)
 
SQL_QUERY_FAIL static SQL_QUERY_RESUME sql_rcode_t sql_fields (char const **out[], fr_sql_query_t *query_ctx, UNUSED 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)
 

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 69 of file rlm_sql_postgresql.c.

+ Collaboration diagram for rlm_sql_postgres_conn_t:
Data Fields
int affected_rows
connection_t * conn Generic connection structure for this connection.
int cur_row
PGconn * db
int fd fd for this connection's I/O events.
int num_fields
fr_sql_query_t * query_ctx Current query running on this connection.
PGresult * result
char ** row

◆ rlm_sql_postgresql_t

struct rlm_sql_postgresql_t

PostgreSQL configuration.

Definition at line 63 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 57 of file rlm_sql_postgresql.c.

Function Documentation

◆ _sql_connect_io_notify()

static void _sql_connect_io_notify ( fr_event_list_t el,
int  fd,
UNUSED int  flags,
void *  uctx 
)
static

Definition at line 230 of file rlm_sql_postgresql.c.

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

◆ _sql_connection_close()

static void _sql_connection_close ( fr_event_list_t el,
void *  h,
UNUSED void *  uctx 
)
static

Definition at line 330 of file rlm_sql_postgresql.c.

+ Here is the call graph for this function:
+ 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 141 of file rlm_sql_postgresql.c.

+ Here is the caller graph for this function:

◆ CC_NO_UBSAN()

CC_NO_UBSAN ( function  )

Definition at line 274 of file rlm_sql_postgresql.c.

+ Here is the call 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 149 of file rlm_sql_postgresql.c.

+ Here is the caller graph for this function:

◆ mod_instantiate()

static int mod_instantiate ( module_inst_ctx_t const *  mctx)
static

Definition at line 687 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 797 of file rlm_sql_postgresql.c.

◆ sql_affected_rows()

static int sql_affected_rows ( fr_sql_query_t query_ctx,
UNUSED rlm_sql_config_t const *  config 
)
static

Definition at line 651 of file rlm_sql_postgresql.c.

◆ sql_classify_error()

static sql_rcode_t sql_classify_error ( UNUSED PGresult const *  result)
static

Definition at line 223 of file rlm_sql_postgresql.c.

◆ sql_error()

static size_t sql_error ( TALLOC_CTX *  ctx,
sql_log_entry_t  out[],
size_t  outlen,
fr_sql_query_t query_ctx 
)
static

Retrieves any errors associated with the query context.

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.
query_ctxQuery context to retrieve error for.
configrlm_sql config.
Returns
number of errors written to the sql_log_entry_t array.

Definition at line 626 of file rlm_sql_postgresql.c.

+ Here is the call graph for this function:

◆ sql_escape_arg_alloc()

static void* sql_escape_arg_alloc ( TALLOC_CTX *  ctx,
fr_event_list_t el,
void *  uctx 
)
static

Definition at line 809 of file rlm_sql_postgresql.c.

+ Here is the call graph for this function:

◆ sql_escape_arg_free()

static void sql_escape_arg_free ( void *  uctx)
static

Definition at line 831 of file rlm_sql_postgresql.c.

+ Here is the call graph for this function:

◆ sql_escape_func()

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

Definition at line 658 of file rlm_sql_postgresql.c.

◆ sql_fetch_row()

static unlang_action_t sql_fetch_row ( rlm_rcode_t p_result,
UNUSED int *  priority,
UNUSED request_t request,
void *  uctx 
)
static

Definition at line 559 of file rlm_sql_postgresql.c.

+ Here is the call graph for this function:

◆ sql_fields()

SQL_QUERY_FAIL static SQL_QUERY_RESUME sql_rcode_t sql_fields ( char const **  out[],
fr_sql_query_t query_ctx,
UNUSED rlm_sql_config_t const *  config 
)
static

Definition at line 541 of file rlm_sql_postgresql.c.

+ Here is the call graph for this function:

◆ sql_free_result()

static sql_rcode_t sql_free_result ( fr_sql_query_t query_ctx,
UNUSED rlm_sql_config_t const *  config 
)
static

Definition at line 592 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:627
#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 81 of file rlm_sql_postgresql.c.

◆ rlm_sql_postgresql

rlm_sql_driver_t rlm_sql_postgresql

Definition at line 839 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:45
@ RLM_SQL_RECONNECT
Stale connection, should reconnect.
Definition: rlm_sql.h:48
@ RLM_SQL_ERROR
General connection/server error.
Definition: rlm_sql.h:46
@ RLM_SQL_OK
Success.
Definition: rlm_sql.h:47

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

Definition at line 89 of file rlm_sql_postgresql.c.