27RCSID(
"$Id: b6fbff0dfcd0570fa97dfe40577d722a66276e8d $")
29#include <freeradius-devel/server/base.h>
30#include <freeradius-devel/server/module_rlm.h>
31#include <freeradius-devel/server/map_proc.h>
32#include <freeradius-devel/util/debug.h>
33#include <freeradius-devel/unlang/xlat_func.h>
45 map_t const *map,
void *uctx)
66 RWDEBUG(
"Failed expanding string");
74 RWDEBUG(
"No such attribute '%s'", attr);
120 request_t *request, fr_value_box_list_t *client_override, map_list_t
const *maps)
123 map_t const *map = NULL;
127 if (!fr_value_box_list_empty(client_override)) {
129 char const *client_str;
130 fr_value_box_t *client_override_head = fr_value_box_list_head(client_override);
140 REDEBUG(
"Failed concatenating input data");
143 client_str = client_override_head->vb_strvalue;
145 if (
fr_inet_pton(&ip, client_str, -1, AF_UNSPEC,
false,
true) < 0) {
146 REDEBUG(
"\"%s\" is not a valid IPv4 or IPv6 address", client_str);
153 RDEBUG(
"No client found with IP \"%s\"", client_str);
159 char const *filename;
166 RDEBUG2(
"Found client matching \"%s\". Defined in \"%s\" line %i",
167 client_str, filename,
line);
169 RDEBUG2(
"Found client matching \"%s\"", client_str);
175 REDEBUG(
"No client associated with this request");
179 uctx.
cs = client->
cs;
182 while ((map = map_list_next(maps, map))) {
185 if (
tmpl_aexpand(request, &field, request, map->
rhs, NULL, NULL) < 0) {
186 REDEBUG(
"Failed expanding RHS at %s", map->
lhs->name);
194 RDEBUG3(
"No matching client property \"%s\", skipping...", field);
238 char const *
value = NULL;
247 if (
fr_inet_pton(&ip, client_ip->vb_strvalue, -1, AF_UNSPEC,
false,
true) < 0) {
248 RDEBUG(
"Invalid client IP address \"%s\"", client_ip->vb_strvalue);
254 RDEBUG(
"No client found with IP \"%s\"", client_ip->vb_strvalue);
260 REDEBUG(
"No client associated with this request");
267 if (strcmp(field->vb_strvalue,
"shortname") == 0 && client->
shortname) {
270 else if (strcmp(field->vb_strvalue,
"nas_type") == 0 && client->
nas_type) {
303 if ((request->packet->socket.inet.src_port != 0) || (!
fr_pair_list_empty(&request->request_pairs)) ||
304 (request->parent != NULL)) {
305 REDEBUG(
"Improper configuration");
310 if (!client || !client->
cs) {
311 REDEBUG(
"Unknown client definition");
317 REDEBUG(
"No directory configuration in the client");
323 REDEBUG(
"No value given for the directory entry in the client");
327 length = strlen(
value);
328 if (length > (
sizeof(
buffer) - 256)) {
329 REDEBUG(
"Directory name too long");
348 request->client = client;
384 .name =
"dynamic_clients",
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
static int const char char buffer[256]
Configuration AVP similar to a fr_pair_t.
A section grouping multiple CONF_PAIR.
CONF_PAIR * cf_pair_find_next(CONF_SECTION const *cs, CONF_PAIR const *prev, char const *attr)
Find a pair with a name matching attr, after specified pair.
CONF_PAIR * cf_pair_find(CONF_SECTION const *cs, char const *attr)
Search for a CONF_PAIR with a specific name.
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
API to create and manipulate internal format configurations.
static int fr_dcursor_append(fr_dcursor_t *cursor, void *v)
Insert a single item at the end of the list.
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 * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
static xlat_action_t xlat_client(TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
xlat to get client config data
char const * fr_inet_ntoh(fr_ipaddr_t const *src, char *out, size_t outlen)
Perform reverse resolution of an IP address.
int fr_inet_pton(fr_ipaddr_t *out, char const *value, ssize_t inlen, int af, bool resolve, bool mask)
Simple wrapper to decide whether an IP value is v4 or v6 and call the appropriate parser.
char const * server
Name of the virtual server client is associated with.
char const * nas_type
Type of client (arbitrary).
CONF_SECTION * cs
CONF_SECTION that was parsed to generate the client.
char const * shortname
Client nickname.
CONF_SECTION * server_cs
Virtual server that the client is associated with.
Describes a host allowed to send packets to the server.
#define REXDENT()
Exdent (unindent) R* messages by one level.
#define RINDENT()
Indent R* messages by one level.
int map_to_request(request_t *request, map_t const *map, radius_map_getvalue_t func, void *ctx)
Convert map_t to fr_pair_t (s) and add them to a request_t.
int map_proc_unregister(char const *name)
Unregister a map processor by name.
int map_proc_register(TALLOC_CTX *ctx, void const *mod_inst, char const *name, map_proc_func_t evaluate, map_proc_instantiate_t instantiate, size_t inst_size, fr_value_box_safe_for_t literals_safe_for)
Register a map processor.
@ FR_TYPE_STRING
String of printable characters.
Temporary structure to hold arguments for module calls.
module_t common
Common fields presented by all modules.
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
int fr_pair_value_from_str(fr_pair_t *vp, char const *value, size_t inlen, fr_sbuff_unescape_rules_t const *uerules, bool tainted)
Convert string value to native attribute value.
static void client_read(fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
#define RETURN_MODULE_NOOP
#define RETURN_MODULE_RCODE(_rcode)
#define RETURN_MODULE_FAIL
rlm_rcode_t
Return codes indicating the result of the module call.
@ RLM_MODULE_OK
The module is OK, continue.
@ RLM_MODULE_FAIL
Module failed, don't reply.
@ RLM_MODULE_NOTFOUND
User not found.
@ RLM_MODULE_UPDATED
OK (pairs modified).
static int mod_load(void)
static unlang_action_t map_proc_client(rlm_rcode_t *p_result, UNUSED void const *mod_inst, UNUSED void *proc_inst, request_t *request, fr_value_box_list_t *client_override, map_list_t const *maps)
Map multiple attributes from a client into the request.
static void mod_unload(void)
CONF_PAIR * cp
First instance of the field in the client's CONF_SECTION.
CONF_SECTION * cs
Client's CONF_SECTION.
static xlat_arg_parser_t const xlat_client_args[]
char const * field
Field name.
static unlang_action_t mod_authorize(rlm_rcode_t *p_result, UNUSED module_ctx_t const *mctx, request_t *request)
static int _map_proc_client_get_vp(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map, void *uctx)
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Named methods exported by a module.
#define tmpl_is_attr(vpt)
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
#define tmpl_aexpand(_ctx, _out, _request, _vpt, _escape, _escape_ctx)
Expand a tmpl to a C type, allocing a new buffer to hold the string.
fr_client_t * client_find(fr_client_list_t const *clients, fr_ipaddr_t const *ipaddr, int proto)
fr_client_t * client_from_request(request_t *request)
Search up a list of requests trying to locate one which has a client.
fr_token_t op
The operator that controls insertion of the dst attribute.
tmpl_t * lhs
Typically describes the attribute to add, modify or compare.
tmpl_t * rhs
Typically describes a literal value or a src attribute to copy or compare.
Stores an attribute, a value and various bits of other data.
bool required
Argument must be present, and non-empty.
#define XLAT_ARG_PARSER_TERMINATOR
@ XLAT_ACTION_FAIL
An xlat function failed.
@ XLAT_ACTION_DONE
We're done evaluating this level of nesting.
Definition for a single argument consumend by an xlat function.
bool fr_pair_list_empty(fr_pair_list_t const *list)
Is a valuepair list empty.
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src)
Appends a list of fr_pair_t from a temporary list to a destination list.
char const * fr_strerror(void)
Get the last library error.
int fr_value_box_strdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted)
Copy a nul terminated string to a fr_value_box_t.
int fr_value_box_list_concat_in_place(TALLOC_CTX *ctx, fr_value_box_t *out, fr_value_box_list_t *list, fr_type_t type, fr_value_box_list_action_t proc_action, bool flatten, size_t max_size)
Concatenate a list of value boxes.
#define fr_box_strvalue(_val)
#define fr_value_box_alloc_null(_ctx)
Allocate a value box for later use with a value assignment function.
static size_t char ** out
int xlat_func_args_set(xlat_t *x, xlat_arg_parser_t const args[])
Register the arguments of an xlat.
xlat_t * xlat_func_register(TALLOC_CTX *ctx, char const *name, xlat_func_t func, fr_type_t return_type)
Register an xlat function.
void xlat_func_unregister(char const *name)
Unregister an xlat function.