The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Enumerations | Functions | Variables
rlm_linelog.c File Reference
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/exfile.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/server/tmpl_dcursor.h>
#include <freeradius-devel/server/rcode.h>
#include <freeradius-devel/server/tmpl.h>
#include <freeradius-devel/unlang/call_env.h>
#include <freeradius-devel/unlang/tmpl.h>
#include <freeradius-devel/unlang/module.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/iovec.h>
#include <freeradius-devel/util/perm.h>
#include <freeradius-devel/util/print.h>
#include <freeradius-devel/util/value.h>
#include <freeradius-devel/util/types.h>
#include <freeradius-devel/unlang/xlat_func.h>
#include <sys/uio.h>
+ Include dependency graph for rlm_linelog.c:

Go to the source code of this file.

Data Structures

struct  linelog_call_env_t
 
struct  linelog_conn_t
 
struct  linelog_net_t
 
struct  rlm_linelog_rctx_t
 
struct  rlm_linelog_t
 linelog module instance More...
 
struct  rlm_linelog_t.file
 
struct  rlm_linelog_t.syslog
 
struct  rlm_linelog_t.unix_sock
 

Macros

#define VECTOR_INCREMENT   20
 

Enumerations

enum  linefr_log_dst_t {
  LINELOG_DST_INVALID = 0 ,
  LINELOG_DST_FILE ,
  LINELOG_DST_REQUEST ,
  LINELOG_DST_SYSLOG ,
  LINELOG_DST_UNIX ,
  LINELOG_DST_UDP ,
  LINELOG_DST_TCP ,
  LINELOG_DST_STDOUT ,
  LINELOG_DST_STDERR
}
 

Functions

static int _mod_conn_free (linelog_conn_t *conn)
 
static int call_env_filename_parse (TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
 
static int linelog_escape_func (fr_value_box_t *vb, UNUSED void *uctx)
 Escape unprintable characters. More...
 
static void linelog_hexdump (request_t *request, struct iovec *vector_p, size_t vector_len, char const *msg)
 
static int linelog_write (rlm_linelog_t const *inst, linelog_call_env_t const *call_env, request_t *request, struct iovec *vector_p, size_t vector_len, bool with_delim)
 
static xlat_action_t linelog_xlat (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *args)
 
static int mod_bootstrap (module_inst_ctx_t const *mctx)
 
static void * mod_conn_create (TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
 
static int mod_detach (module_detach_ctx_t const *mctx)
 
static unlang_action_t mod_do_linelog (rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 Write a linelog message. More...
 
static unlang_action_t mod_do_linelog_resume (rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 
static int mod_instantiate (module_inst_ctx_t const *mctx)
 

Variables

static const conf_parser_t file_config []
 
static fr_table_num_sorted_t const linefr_log_dst_table []
 
static size_t linefr_log_dst_table_len = NUM_ELEMENTS(linefr_log_dst_table)
 
static const call_env_method_t linelog_method_env
 
static const call_env_method_t linelog_xlat_method_env
 
static const conf_parser_t module_config []
 
module_rlm_t rlm_linelog
 
static const conf_parser_t syslog_config []
 
static const conf_parser_t tcp_config []
 
static const conf_parser_t udp_config []
 
static const conf_parser_t unix_config []
 

Data Structure Documentation

◆ linelog_call_env_t

struct linelog_call_env_t

Definition at line 201 of file rlm_linelog.c.

+ Collaboration diagram for linelog_call_env_t:
Data Fields
fr_value_box_t * filename File name, if output is to a file.
fr_value_box_t * log_head Header to add to each new log file.
fr_value_box_t * log_ref Path to a CONF_PAIR (to use as the source of log messages).
tmpl_t * log_src Source of log messages.

◆ linelog_conn_t

struct linelog_conn_t

Definition at line 138 of file rlm_linelog.c.

Data Fields
int sockfd File descriptor associated with socket.

◆ linelog_net_t

struct linelog_net_t

Definition at line 94 of file rlm_linelog.c.

+ Collaboration diagram for linelog_net_t:
Data Fields
fr_ipaddr_t dst_ipaddr Network server.
uint16_t port Network port.
fr_ipaddr_t src_ipaddr Send requests from a given src_ipaddr.
fr_time_delta_t timeout How long to wait for read/write operations.

◆ rlm_linelog_rctx_t

struct rlm_linelog_rctx_t

Definition at line 612 of file rlm_linelog.c.

Data Fields
fr_value_box_list_t expanded The result of expanding the fmt tmpl.
bool with_delim Whether to add a delimiter.

◆ rlm_linelog_t

struct rlm_linelog_t

linelog module instance

Definition at line 103 of file rlm_linelog.c.

+ Collaboration diagram for rlm_linelog_t:
Data Fields
CONF_SECTION * cs CONF_SECTION to use as the root for #log_ref lookups.
char const * delimiter Line termination string (usually
).
size_t delimiter_len Length of line termination string.
struct rlm_linelog_t file
linefr_log_dst_t log_dst Logging destination.
char const * log_dst_str Logging destination string.
fr_pool_t * pool Connection pool instance.
struct rlm_linelog_t syslog
linelog_net_t tcp TCP server.
linelog_net_t udp UDP server.
struct rlm_linelog_t unix_sock

◆ rlm_linelog_t.file

struct rlm_linelog_t.file

Definition at line 118 of file rlm_linelog.c.

Data Fields
exfile_t * ef Exclusive file access handle.
bool escape Do filename escaping, yes / no.
bool fsync fsync after each write.
gid_t group Resolved gid.
char const * group_str Group to set on new files.
uint32_t permissions Permissions to use when creating new files.

◆ rlm_linelog_t.syslog

struct rlm_linelog_t.syslog

Definition at line 112 of file rlm_linelog.c.

Data Fields
char const * facility Syslog facility string.
int priority Bitwise | of severity and facility.
char const * severity Syslog severity string.

◆ rlm_linelog_t.unix_sock

struct rlm_linelog_t.unix_sock

Definition at line 127 of file rlm_linelog.c.

Data Fields
char const * path Where the UNIX socket lives.
fr_time_delta_t timeout How long to wait for read/write operations.

Macro Definition Documentation

◆ VECTOR_INCREMENT

#define VECTOR_INCREMENT   20

Enumeration Type Documentation

◆ linefr_log_dst_t

Enumerator
LINELOG_DST_INVALID 
LINELOG_DST_FILE 

Log to a file.

LINELOG_DST_REQUEST 

Log to the request->log.

LINELOG_DST_SYSLOG 

Log to syslog.

LINELOG_DST_UNIX 

Log via Unix socket.

LINELOG_DST_UDP 

Log via UDP.

LINELOG_DST_TCP 

Log via TCP.

LINELOG_DST_STDOUT 

Log to stdout.

LINELOG_DST_STDERR 

Log to stderr.

Definition at line 69 of file rlm_linelog.c.

Function Documentation

◆ _mod_conn_free()

static int _mod_conn_free ( linelog_conn_t conn)
static

Definition at line 242 of file rlm_linelog.c.

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

◆ call_env_filename_parse()

static int call_env_filename_parse ( TALLOC_CTX *  ctx,
void *  out,
tmpl_rules_t const *  t_rules,
CONF_ITEM ci,
call_env_ctx_t const *  cec,
UNUSED call_env_parser_t const *  rule 
)
static

Definition at line 884 of file rlm_linelog.c.

+ Here is the call graph for this function:

◆ linelog_escape_func()

static int linelog_escape_func ( fr_value_box_t vb,
UNUSED void *  uctx 
)
static

Escape unprintable characters.

  • Newline is escaped as \\n.
  • Return is escaped as \\r.
  • All other unprintables are escaped as
    \<oct><oct><oct> 
    .
Parameters
vbValue box to escape.
uctxunused.

Definition at line 341 of file rlm_linelog.c.

+ Here is the call graph for this function:

◆ linelog_hexdump()

static void linelog_hexdump ( request_t request,
struct iovec *  vector_p,
size_t  vector_len,
char const *  msg 
)
static

Definition at line 353 of file rlm_linelog.c.

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

◆ linelog_write()

static int linelog_write ( rlm_linelog_t const *  inst,
linelog_call_env_t const *  call_env,
request_t request,
struct iovec *  vector_p,
size_t  vector_len,
bool  with_delim 
)
static

Definition at line 363 of file rlm_linelog.c.

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

◆ linelog_xlat()

static xlat_action_t linelog_xlat ( TALLOC_CTX *  ctx,
fr_dcursor_t out,
xlat_ctx_t const *  xctx,
request_t request,
fr_value_box_list_t *  args 
)
static

Definition at line 576 of file rlm_linelog.c.

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

◆ mod_bootstrap()

static int mod_bootstrap ( module_inst_ctx_t const *  mctx)
static

Definition at line 1040 of file rlm_linelog.c.

+ Here is the call graph for this function:

◆ mod_conn_create()

static void* mod_conn_create ( TALLOC_CTX *  ctx,
void *  instance,
fr_time_delta_t  timeout 
)
static

Definition at line 250 of file rlm_linelog.c.

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

◆ mod_detach()

static int mod_detach ( module_detach_ctx_t const *  mctx)
static

Definition at line 913 of file rlm_linelog.c.

+ Here is the call graph for this function:

◆ mod_do_linelog()

static unlang_action_t mod_do_linelog ( rlm_rcode_t p_result,
module_ctx_t const *  mctx,
request_t request 
)
static

Write a linelog message.

Write a log message to syslog or a flat file.

Parameters
[in]p_resultthe result of the module call:
[in]mctxmodule calling context.
[in]requestThe current request.

Definition at line 684 of file rlm_linelog.c.

+ Here is the call graph for this function:

◆ mod_do_linelog_resume()

static unlang_action_t mod_do_linelog_resume ( rlm_rcode_t p_result,
module_ctx_t const *  mctx,
request_t request 
)
static

Definition at line 617 of file rlm_linelog.c.

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

◆ mod_instantiate()

static int mod_instantiate ( module_inst_ctx_t const *  mctx)
static

Definition at line 925 of file rlm_linelog.c.

+ Here is the call graph for this function:

Variable Documentation

◆ file_config

const conf_parser_t file_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("permissions", rlm_linelog_t, file.permissions), .dflt = "0600" },
{ FR_CONF_OFFSET("group", rlm_linelog_t, file.group_str) },
{ FR_CONF_OFFSET("escape_filenames", rlm_linelog_t, file.escape), .dflt = "no" },
{ FR_CONF_OFFSET("fsync", rlm_linelog_t, file.fsync), .dflt = "no" },
}
int const char * file
Definition: acutest.h:702
#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
linelog module instance
Definition: rlm_linelog.c:103

Definition at line 143 of file rlm_linelog.c.

◆ linefr_log_dst_table

fr_table_num_sorted_t const linefr_log_dst_table[]
static
Initial value:
= {
{ L("file"), LINELOG_DST_FILE },
{ L("files"), LINELOG_DST_FILE },
{ L("request"), LINELOG_DST_REQUEST },
{ L("stderr"), LINELOG_DST_STDERR },
{ L("stdout"), LINELOG_DST_STDOUT },
{ L("syslog"), LINELOG_DST_SYSLOG },
{ L("tcp"), LINELOG_DST_TCP },
{ L("udp"), LINELOG_DST_UDP },
{ L("unix"), LINELOG_DST_UNIX }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
@ LINELOG_DST_FILE
Log to a file.
Definition: rlm_linelog.c:71
@ LINELOG_DST_STDERR
Log to stderr.
Definition: rlm_linelog.c:78
@ LINELOG_DST_UNIX
Log via Unix socket.
Definition: rlm_linelog.c:74
@ LINELOG_DST_STDOUT
Log to stdout.
Definition: rlm_linelog.c:77
@ LINELOG_DST_TCP
Log via TCP.
Definition: rlm_linelog.c:76
@ LINELOG_DST_REQUEST
Log to the request->log.
Definition: rlm_linelog.c:72
@ LINELOG_DST_UDP
Log via UDP.
Definition: rlm_linelog.c:75
@ LINELOG_DST_SYSLOG
Log to syslog.
Definition: rlm_linelog.c:73

Definition at line 81 of file rlm_linelog.c.

◆ linefr_log_dst_table_len

size_t linefr_log_dst_table_len = NUM_ELEMENTS(linefr_log_dst_table)
static

Definition at line 92 of file rlm_linelog.c.

◆ linelog_method_env

const call_env_method_t linelog_method_env
static
Initial value:
= {
.env = (call_env_parser_t[]) {
.pair.func = call_env_filename_parse },
})) },
}
}
#define CALL_ENV_TERMINATOR
Definition: call_env.h:231
#define FR_CALL_ENV_METHOD_OUT(_inst)
Helper macro for populating the size/type fields of a call_env_method_t from the output structure typ...
Definition: call_env.h:235
#define FR_CALL_ENV_SUBSECTION(_name, _name2, _flags, _subcs)
Specify a call_env_parser_t which defines a nested subsection.
Definition: call_env.h:397
@ CALL_ENV_FLAG_CONCAT
If the tmpl produced multiple boxes they should be concatenated.
Definition: call_env.h:76
@ CALL_ENV_FLAG_PARSE_ONLY
The result of parsing will not be evaluated at runtime.
Definition: call_env.h:85
@ CALL_ENV_FLAG_NONE
Definition: call_env.h:74
#define FR_CALL_ENV_OFFSET(_name, _cast_type, _flags, _struct, _field)
Specify a call_env_parser_t which writes out runtime results to the specified field.
Definition: call_env.h:335
#define FR_CALL_ENV_PARSE_ONLY_OFFSET(_name, _cast_type, _flags, _struct, _parse_field)
Specify a call_env_parser_t which writes out the result of the parsing phase to the field specified.
Definition: call_env.h:384
Per method call config.
Definition: call_env.h:175
@ FR_TYPE_STRING
String of printable characters.
Definition: merged_model.c:83
static int call_env_filename_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
Definition: rlm_linelog.c:884
static int linelog_escape_func(fr_value_box_t *vb, UNUSED void *uctx)
Escape unprintable characters.
Definition: rlm_linelog.c:341

Definition at line 212 of file rlm_linelog.c.

◆ linelog_xlat_method_env

const call_env_method_t linelog_xlat_method_env
static

◆ module_config

const conf_parser_t module_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET_FLAGS("destination", CONF_FLAG_REQUIRED, rlm_linelog_t, log_dst_str) },
{ FR_CONF_OFFSET("delimiter", rlm_linelog_t, delimiter), .dflt = "\n" },
{ FR_CONF_POINTER("file", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) file_config },
{ FR_CONF_POINTER("syslog", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) syslog_config },
{ FR_CONF_POINTER("unix", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) unix_config },
{ FR_CONF_DEPRECATED("permissions", rlm_linelog_t, file.permissions) },
{ FR_CONF_DEPRECATED("group", rlm_linelog_t, file.group_str) },
{ FR_CONF_DEPRECATED("syslog_facility", rlm_linelog_t, syslog.facility) },
{ FR_CONF_DEPRECATED("syslog_severity", rlm_linelog_t, syslog.severity) },
}
#define FR_CONF_DEPRECATED(_name, _struct, _field)
conf_parser_t entry which raises an error if a matching CONF_PAIR is found
Definition: cf_parse.h:385
#define FR_CONF_POINTER(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result
Definition: cf_parse.h:310
#define FR_CONF_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:256
#define FR_CONF_OFFSET_SUBSECTION(_name, _flags, _struct, _field, _subcs)
conf_parser_t which populates a sub-struct using a CONF_SECTION
Definition: cf_parse.h:297
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition: cf_parse.h:405
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition: cf_parse.h:399
static const conf_parser_t file_config[]
Definition: rlm_linelog.c:143
static const conf_parser_t syslog_config[]
Definition: rlm_linelog.c:151
static const conf_parser_t udp_config[]
Definition: rlm_linelog.c:162
static const conf_parser_t unix_config[]
Definition: rlm_linelog.c:157
static const conf_parser_t tcp_config[]
Definition: rlm_linelog.c:169

Definition at line 176 of file rlm_linelog.c.

◆ rlm_linelog

module_rlm_t rlm_linelog
Initial value:
= {
.common = {
.name = "linelog",
.inst_size = sizeof(rlm_linelog_t),
.bootstrap = mod_bootstrap,
.detach = mod_detach
},
.method_group = {
.bindings = (module_method_binding_t[]){
{ .section = SECTION_NAME(CF_IDENT_ANY, CF_IDENT_ANY), .method = mod_do_linelog, .method_env = &linelog_method_env },
}
}
}
#define CF_IDENT_ANY
Definition: cf_util.h:78
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:63
static const conf_parser_t config[]
Definition: base.c:183
static int mod_detach(module_detach_ctx_t const *mctx)
Definition: rlm_linelog.c:913
static unlang_action_t mod_do_linelog(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Write a linelog message.
Definition: rlm_linelog.c:684
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Definition: rlm_linelog.c:1040
static const call_env_method_t linelog_method_env
Definition: rlm_linelog.c:212
static const conf_parser_t module_config[]
Definition: rlm_linelog.c:176
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition: rlm_linelog.c:925
static int instantiate(module_inst_ctx_t const *mctx)
Definition: rlm_rest.c:1302
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition: section.h:40
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Definition: module.h:151
Named methods exported by a module.
Definition: module.h:173

Definition at line 1060 of file rlm_linelog.c.

◆ syslog_config

const conf_parser_t syslog_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("facility", rlm_linelog_t, syslog.facility) },
{ FR_CONF_OFFSET("severity", rlm_linelog_t, syslog.severity), .dflt = "info" },
}

Definition at line 151 of file rlm_linelog.c.

◆ tcp_config

const conf_parser_t tcp_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("port", linelog_net_t, port) },
{ FR_CONF_OFFSET("timeout", linelog_net_t, timeout), .dflt = "1000" },
}
#define FR_CONF_OFFSET_TYPE_FLAGS(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:241
static fr_time_delta_t timeout
Definition: dhcpclient.c:54
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
Definition: merged_model.c:91

Definition at line 169 of file rlm_linelog.c.

◆ udp_config

const conf_parser_t udp_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("port", linelog_net_t, port) },
{ FR_CONF_OFFSET("timeout", linelog_net_t, timeout), .dflt = "1000" },
}

Definition at line 162 of file rlm_linelog.c.

◆ unix_config

const conf_parser_t unix_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET_FLAGS("filename", CONF_FLAG_FILE_INPUT, rlm_linelog_t, unix_sock.path) },
}
@ CONF_FLAG_FILE_INPUT
File matching value must exist, and must be readable.
Definition: cf_parse.h:411

Definition at line 157 of file rlm_linelog.c.