26RCSID(
"$Id: 95b77b350bdcbc8a37e4018ca150beb6db433195 $")
30#include <freeradius-devel/util/debug.h>
31#include <freeradius-devel/ldap/base.h>
64 for (i = 0; i < self->
count; i++) {
71 .request_def = tmpl_request(map->
lhs),
91 RDEBUG3(
"Parsing valuepair string \"%pV\"",
101 RWDEBUG(
"Failed making attribute string safe");
107 &lhs_rules, &rhs_rules) < 0) {
108 RPWDEBUG(
"Failed parsing \"%pV\" as valuepair, skipping...",
117 RWDEBUG(
"Failed parsing left side of \"%pV\", skipping...",
130 RWDEBUG(
"valuepair \"%pV\" has conflicting request qualifier (%s vs %s), skipping...",
132 attr_request, map_request);
143 RWDEBUG(
"valuepair \"%pV\" has conflicting list qualifier (%s vs %s), skipping...",
151 RWDEBUG(
"Failed creating attribute for valuepair \"%pV\", skipping...",
171 for (i = 0; i < self->
count; i++) {
172 if (!self->
values[i]->bv_len)
continue;
177 self->
values[i]->bv_len, NULL,
true) < 0) {
178 RPWDEBUG(
"Failed parsing value \"%pV\" for attribute %s",
206 switch (map->
lhs->type) {
215 cf_log_err(map->
ci,
"Left hand side of map must be an attribute or list, not a %s",
224 switch (map->
rhs->type) {
236 cf_log_err(map->
ci,
"Right hand side of map must be an xlat, attribute, exec, or literal, not a %s",
252 cf_log_err(map->
ci,
"Operator \"%s\" not allowed for LDAP mappings",
273 char const *generic_attr,
char const *check_attr)
275 map_t const *map = NULL;
276 unsigned int total = 0;
278 TALLOC_CTX *our_ctx = NULL;
280 char attr_buff[1024 + 1];
282 while ((map = map_list_next(maps, map))) {
283 if (
tmpl_expand(&attr, attr_buff,
sizeof(attr_buff), request, map->
rhs, NULL, NULL) < 0) {
284 REDEBUG(
"Expansion of LDAP attribute \"%s\" failed", map->
rhs->name);
285 TALLOC_FREE(our_ctx);
292 if (attr == attr_buff) {
293 if (!our_ctx) our_ctx = talloc_new(ctx);
294 expanded->
attrs[total++] = talloc_strdup(our_ctx, attr_buff);
297 expanded->
attrs[total++] = attr;
300 if (generic_attr) expanded->
attrs[total++] = generic_attr;
301 if (check_attr) expanded->
attrs[total++] = check_attr;
303 expanded->
attrs[total] = NULL;
304 expanded->
count = total;
305 expanded->
maps = maps;
328 char const *valuepair_attr,
fr_ldap_map_exp_t const *expanded, LDAPMessage *entry)
330 map_t const *map = NULL;
331 unsigned int total = 0;
339 struct berval **values;
353 values = ldap_get_values_len(handle, entry, check_attr);
354 count = ldap_count_values_len(values);
356 for (i = 0; i <
count; i++) {
359 fr_value_box_list_t res;
365 NULL, &parse_rules) < 0) {
366 RPEDEBUG(
"Failed parsing '%s' value \"%s\"", check_attr,
value);
372 ldap_value_free_len(values);
377 fr_strerror_const(
"Condition expression cannot depend on functions which call external databases");
382 fr_value_box_list_init(&res);
384 RPEDEBUG(
"Failed evaluating condition");
388 RDEBUG2(
"Failed match: skipping this profile");
394 ldap_value_free_len(values);
397 while ((map = map_list_next(expanded->
maps, map))) {
405 result.
values = ldap_get_values_len(handle, entry,
name);
407 RDEBUG3(
"Attribute \"%s\" not found in LDAP object",
name);
416 result.
count = ldap_count_values_len(result.
values);
424 if (ret == -1)
return -1;
432 ldap_value_free_len(result.
values);
440 if (valuepair_attr) {
441 struct berval **values;
444 values = ldap_get_values_len(handle, entry, valuepair_attr);
445 count = ldap_count_values_len(values);
447 for (i = 0; i <
count; i++) {
466 &parse_rules, &parse_rules) < 0) {
467 RPWDEBUG(
"Failed parsing '%s' value \"%s\" as valuepair, skipping...",
468 valuepair_attr,
value);
473 RWDEBUG(
"Failed adding \"%s\" to request, skipping...",
value);
480 ldap_value_free_len(values);
#define USES_APPLE_DEPRECATED_API
#define cf_log_err(_cf, _fmt,...)
fr_event_list_t * unlang_interpret_event_list(request_t *request)
Get the event list for the current interpreter.
struct berval ** values
libldap struct containing bv_val (char *) and length bv_len.
int count
Index on next free element.
map_list_t const * maps
Head of list of maps we expanded the RHS of.
char * fr_ldap_berval_to_string(TALLOC_CTX *ctx, struct berval const *in)
Convert a berval to a talloced string.
int count
Number of values.
char const * attrs[LDAP_MAX_ATTRMAP+LDAP_MAP_RESERVED+1]
Reserve some space for access attributes.
Result of expanding the RHS of a set of maps.
Contains a collection of values.
LDAP * fr_ldap_handle_thread_local(void)
Get a thread local dummy LDAP handle.
int fr_ldap_map_do(request_t *request, char const *check_attr, char const *valuepair_attr, fr_ldap_map_exp_t const *expanded, LDAPMessage *entry)
Convert attribute map into valuepairs.
USES_APPLE_DEPRECATED_API int fr_ldap_map_getvalue(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map, void *uctx)
Callback for map_to_request.
int fr_ldap_map_expand(TALLOC_CTX *ctx, fr_ldap_map_exp_t *expanded, request_t *request, map_list_t const *maps, char const *generic_attr, char const *check_attr)
Expand values in an attribute map where needed.
int fr_ldap_map_verify(map_t *map, UNUSED void *instance)
#define RPEDEBUG(fmt,...)
#define RPWDEBUG(fmt,...)
int map_to_vp(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map, UNUSED void *uctx)
Convert a map to a fr_pair_t.
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_afrom_attr_str(TALLOC_CTX *ctx, map_t **out, char const *vp_str, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules)
Convert a value pair string to valuepair map.
@ TMPL_ATTR_REF_PREFIX_AUTO
Attribute refs may have a '&' prefix.
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.
fr_dict_attr_t const * request_attr_request
#define FR_SBUFF_IN(_start, _len_or_end)
int8_t tmpl_request_ref_list_cmp(FR_DLIST_HEAD(tmpl_request_list) const *a, FR_DLIST_HEAD(tmpl_request_list) const *b)
Compare a list of request qualifiers.
static char const * tmpl_type_to_str(tmpl_type_t type)
Return a static string containing the type name.
static fr_dict_attr_t const * tmpl_list(tmpl_t const *vpt)
static fr_slen_t tmpl_request_ref_list_aprint(TALLOC_CTX *ctx, char **out, FR_DLIST_HEAD(tmpl_request_list) const *rql) 1(tmpl_request_ref_list_print
@ TMPL_TYPE_ATTR_UNRESOLVED
An attribute reference that we couldn't resolve but looked valid.
@ TMPL_TYPE_ATTR
Reference to one or more attributes.
@ TMPL_TYPE_EXEC
Callout to an external script or program.
@ TMPL_TYPE_DATA_UNRESOLVED
Unparsed literal string.
@ TMPL_TYPE_XLAT_UNRESOLVED
A xlat expansion with unresolved xlat functions or attribute references.
tmpl_xlat_rules_t xlat
Rules/data for parsing xlats.
static char const * tmpl_attr_tail_unresolved(tmpl_t const *vpt)
Return the last attribute reference unresolved da.
static bool tmpl_is_list(tmpl_t const *vpt)
#define tmpl_is_data_unresolved(vpt)
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
static char const * tmpl_list_name(fr_dict_attr_t const *list, char const *def)
Return the name of a tmpl list or def if list not provided.
#define tmpl_expand(_out, _buff, _buff_len, _request, _vpt, _escape, _escape_ctx)
Expand a tmpl to a C type, using existing storage to hold variably sized types.
fr_event_list_t * runtime_el
The eventlist to use for runtime instantiation of xlats.
Optional arguments passed to vp_tmpl functions.
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.
CONF_ITEM * ci
Config item that the map was created from.
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.
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
char * talloc_bstrndup(TALLOC_CTX *ctx, char const *in, size_t inlen)
Binary safe strndup function.
fr_table_num_ordered_t const fr_tokens_table[]
int unlang_xlat_eval(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, xlat_exp_head_t const *xlat)
Evaluate a "pure" (or not impure) xlat.
bool xlat_impure_func(xlat_exp_head_t const *head)
fr_slen_t xlat_tokenize_expression(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules)
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.
#define fr_strerror_const(_msg)
bool fr_value_box_is_truthy(fr_value_box_t const *in)
Check truthiness of values.
#define fr_box_strvalue_len(_val, _len)
static size_t char ** out