24 RCSID(
"$Id: 2acf642fcd61161be0c9b442fab28f12c0e5dafb $")
26 #include <freeradius-devel/server/base.h>
27 #include <freeradius-devel/server/cf_util.h>
28 #include <freeradius-devel/server/exfile.h>
29 #include <freeradius-devel/server/module_rlm.h>
30 #include <freeradius-devel/util/debug.h>
31 #include <freeradius-devel/util/perm.h>
155 gid = strtol(group, &endptr, 10);
156 if (*endptr !=
'\0') {
158 cf_log_err(ci,
"Unable to find system group '%s'", group);
162 *((gid_t *)
out) = gid;
170 return fr_hash(&da,
sizeof(da));
226 RWDEBUG(
"Skipping empty packet");
230 #define WRITE(fmt, ...) do {\
231 if (fprintf(out, fmt, ## __VA_ARGS__) < 0) {\
232 RERROR("Failed writing to detail file: %s", fr_syserror(errno));\
237 WRITE(
"%s\n", header->vb_strvalue);
244 char const *
name = NULL;
256 WRITE(
"\tPacket-Type = %u\n", packet->
code);
263 if (
inst->log_srcdst) {
292 while (da->depth >
attr_net->depth) {
343 if (
inst->group_is_set) {
344 if (chown(env->
filename.vb_strvalue, -1,
inst->group) == -1) {
352 RERROR(
"Failed to dup() file descriptor for detail file");
359 if ((outfp = fdopen(dupfd,
"a")) == NULL) {
362 if (outfp) fclose(outfp);
386 return detail_do(p_result, mctx, request, request->packet, &request->request_pairs,
true);
394 return detail_do(p_result, mctx, request, request->packet, &request->request_pairs,
false);
402 return detail_do(p_result, mctx, request, request->reply, &request->reply_pairs,
false);
414 our_rules = *t_rules;
424 &our_rules) < 0)
return -1;
426 *(
void **)
out = parsed;
455 cf_log_perr(to_parse,
"Failed resolving attribute");
463 cf_log_warn(to_parse,
"Ignoring duplicate entry '%s'", attr);
468 cf_log_perr(to_parse,
"Failed inserting '%s' into suppression table", attr);
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
void call_env_parsed_free(call_env_parsed_head_t *parsed, call_env_parsed_t *ptr)
Remove a call_env_parsed_t from the list of parsed call envs.
call_env_parsed_t * call_env_parsed_add(TALLOC_CTX *ctx, call_env_parsed_head_t *head, call_env_parser_t const *rule)
Allocate a new call_env_parsed_t structure and add it to the list of parsed call envs.
void call_env_parsed_set_data(call_env_parsed_t *parsed, void const *data)
Assign data to a call_env_parsed_t.
#define CALL_ENV_TERMINATOR
#define FR_CALL_ENV_PARSE_OFFSET(_name, _cast_type, _flags, _struct, _field, _parse_field)
Specify a call_env_parser_t which writes out runtime results and the result of the parsing phase to t...
#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...
@ CALL_ENV_FLAG_CONCAT
If the tmpl produced multiple boxes they should be concatenated.
@ CALL_ENV_FLAG_REQUIRED
Associated conf pair or section is required.
module_instance_t const * mi
Module instance that the callenv is registered to.
#define FR_CALL_ENV_SUBSECTION_FUNC(_name, _name2, _flags, _func)
Specify a call_env_parser_t which parses a subsection using a callback function.
#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.
#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.
#define CONF_PARSER_TERMINATOR
#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
#define FR_CONF_OFFSET_IS_SET(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct,...
Defines a CONF_PAIR to C data type mapping.
Common header for all CONF_* types.
Configuration AVP similar to a fr_pair_t.
A section grouping multiple CONF_PAIR.
bool cf_item_is_pair(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_PAIR.
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
char const * cf_pair_attr(CONF_PAIR const *pair)
Return the attr of a CONF_PAIR.
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
fr_token_t cf_pair_value_quote(CONF_PAIR const *pair)
Return the value (rhs) quoting of a pair.
char const * cf_section_name(CONF_SECTION const *cs)
Return name2 if set, else name1.
#define cf_log_err(_cf, _fmt,...)
#define cf_log_perr(_cf, _fmt,...)
#define cf_log_warn(_cf, _fmt,...)
#define cf_item_next(_ci, _curr)
fr_dict_attr_t const * fr_dict_attr_search_by_qualified_oid(fr_dict_attr_err_t *err, fr_dict_t const *dict_def, char const *attr, bool internal, bool foreign))
Locate a qualified fr_dict_attr_t by its name and a dictionary qualifier.
fr_dict_attr_t const * fr_dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *attr))
Locate a fr_dict_attr_t by its name.
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
fr_dict_t const * fr_dict_by_da(fr_dict_attr_t const *da)
Attempt to locate the protocol dictionary containing an attribute.
char const * fr_dict_enum_name_by_value(fr_dict_attr_t const *da, fr_value_box_t const *value)
Lookup the name of an enum value in a fr_dict_attr_t.
Specifies an attribute which must be present for the module to function.
Specifies a dictionary which must be loaded/loadable for the module to function.
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
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.
uint32_t fr_hash(void const *data, size_t size)
void fr_hash_table_fill(fr_hash_table_t *ht)
Ensure all buckets are filled.
void * fr_hash_table_find(fr_hash_table_t *ht, void const *data)
bool fr_hash_table_insert(fr_hash_table_t *ht, void const *data)
#define fr_hash_table_alloc(_ctx, _hash_node, _cmp_node, _free_node)
uint32_t fr_hash_table_num_elements(fr_hash_table_t *ht)
int rad_filename_box_escape(fr_value_box_t *vb, UNUSED void *uxtc)
int rad_filename_box_make_safe(fr_value_box_t *vb, UNUSED void *uxtc)
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
void * env_data
Per call environment data.
module_instance_t const * mi
Instance of the module being instantiated.
module_instance_t * mi
Instance of the module being instantiated.
Temporary structure to hold arguments for module calls.
Temporary structure to hold arguments for instantiation calls.
exfile_t * module_rlm_exfile_init(TALLOC_CTX *ctx, CONF_SECTION *module, uint32_t max_entries, fr_time_delta_t max_idle, bool locking, char const *trigger_prefix, fr_pair_list_t *trigger_args)
Initialise a module specific exfile handle.
module_t common
Common fields presented by all modules.
fr_pair_t * fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp)
Copy a single valuepair.
fr_pair_t * fr_pair_find_by_da_nested(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find a pair with a matching fr_dict_attr_t, by walking the nested fr_dict_attr_t tree.
int fr_perm_gid_from_str(TALLOC_CTX *ctx, gid_t *out, char const *name)
Resolve a group name to a GID.
static const conf_parser_t config[]
rlm_rcode_t
Return codes indicating the result of the module call.
@ RLM_MODULE_FAIL
Module failed, don't reply.
static void detail_fr_pair_fprint(TALLOC_CTX *ctx, FILE *out, fr_pair_t const *stacked)
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 fr_dict_attr_t const * attr_user_password
bool group_is_set
Whether group was set.
static int call_env_suppress_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, UNUSED call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
static fr_dict_attr_t const * attr_protocol
fr_value_box_t filename
File / path to write to.
static fr_dict_attr_t const * attr_net_dst_port
gid_t group
Resolved group.
static const call_env_method_t method_env
static fr_dict_t const * dict_freeradius
int detail_group_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static fr_dict_attr_t const * attr_net
bool escape
do filename escaping, yes / no
static fr_dict_attr_t const * attr_net_src_address
static fr_dict_t const * dict_radius
tmpl_t * filename_tmpl
tmpl used to expand filename (for debug output)
exfile_t * ef
Log file handler.
uint32_t perm
Permissions to use for new files.
bool log_srcdst
Add IP src/dst attributes to entries.
static unlang_action_t mod_accounting(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
fr_value_box_t header
Header format.
static unlang_action_t mod_authorize(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
static fr_dict_attr_t const * attr_net_dst_address
fr_dict_attr_autoload_t rlm_detail_dict_attr[]
static const conf_parser_t module_config[]
static uint32_t detail_hash(void const *data)
static void fr_pair_fprint(FILE *fp, fr_pair_t const *vp)
Print one attribute and value to FP.
static int detail_write(FILE *out, rlm_detail_t const *inst, request_t *request, fr_value_box_t *header, fr_packet_t *packet, fr_pair_list_t *list, bool compat, fr_hash_table_t *ht)
Write a single detail entry to file pointer.
bool locking
Whether the file should be locked.
static fr_dict_attr_t const * attr_net_src_port
static int mod_instantiate(module_inst_ctx_t const *mctx)
fr_dict_autoload_t rlm_detail_dict[]
static int8_t detail_cmp(void const *a, void const *b)
fr_hash_table_t * ht
Holds suppressed attributes.
static unlang_action_t detail_do(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request, fr_packet_t *packet, fr_pair_list_t *list, bool compat)
static unlang_action_t mod_post_auth(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Instance configuration for rlm_detail.
static int instantiate(module_inst_ctx_t const *mctx)
#define FR_SBUFF_IN(_start, _len_or_end)
#define FR_SBUFF_OUT(_start, _len_or_end)
#define fr_sbuff_in_char(_sbuff,...)
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
CONF_SECTION * conf
Module's instance configuration.
void * data
Module's instance data.
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Named methods exported by a module.
tmpl_escape_t escape
How escaping should be handled during evaluation.
fr_value_box_safe_for_t literals_safe_for
safe_for value assigned to literal values in xlats, execs, and data.
ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_token_t quote, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Convert an arbitrary string into a tmpl_t.
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
Optional arguments passed to vp_tmpl functions.
static char buff[sizeof("18446744073709551615")+3]
MEM(pair_append_request(&vp, attr_eap_aka_sim_identity) >=0)
eap_aka_sim_process_conf_t * inst
fr_dict_t const * dict_def
Default dictionary to use with unqualified attribute references.
Stores an attribute, a value and various bits of other data.
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
#define talloc_get_type_abort_const
static int64_t fr_time_to_sec(fr_time_t when)
Convert an fr_time_t (internal time) to number of sec since the unix epoch (wallclock time)
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
fr_value_box_escape_t func
How to escape when returned from evaluation.
@ TMPL_ESCAPE_PRE_CONCAT
Pre-concatenation escaping is useful for DSLs where elements of the expansion are static,...
fr_value_box_safe_for_t safe_for
Value to set on boxes which have been escaped by the fr_value_box_escape_t function.
tmpl_escape_mode_t mode
Whether to apply escape function after concatenation, i.e.
unsigned int code
Packet code (type).
bool fr_pair_list_empty(fr_pair_list_t const *list)
Is a valuepair list empty.
static fr_slen_t quote ssize_t fr_pair_print(fr_sbuff_t *out, fr_dict_attr_t const *parent, fr_pair_t const *vp))
Print one attribute and value to a string.
#define fr_pair_list_foreach_leaf(_list_head, _iter)
Iterate over the leaf nodes of a fr_pair_list_t.
fr_sbuff_parse_rules_t const * value_parse_rules_quoted[T_TOKEN_LAST]
Parse rules for quoted strings.
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
#define fr_box_uint32(_val)
static size_t char ** out