26RCSID(
"$Id: 3db234257e14ee50e4f366f8ca3711892701d286 $")
30#include <freeradius-devel/util/debug.h>
31#include <freeradius-devel/ldap/base.h>
74 .request_def = tmpl_request(map->
lhs),
93 RDEBUG3(
"Parsing valuepair string \"%pV\"",
103 RWDEBUG(
"Failed making attribute string safe");
109 &lhs_rules, &rhs_rules) < 0) {
110 RPWDEBUG(
"Failed parsing \"%pV\" as valuepair, skipping...",
119 RWDEBUG(
"Failed parsing left side of \"%pV\", skipping...",
132 RWDEBUG(
"valuepair \"%pV\" has conflicting request qualifier (%s vs %s), skipping...",
134 attr_request, map_request);
145 RWDEBUG(
"valuepair \"%pV\" has conflicting list qualifier (%s vs %s), skipping...",
153 RWDEBUG(
"Failed creating attribute for valuepair \"%pV\", skipping...",
174 if (!
value->bv_len)
continue;
179 value->bv_len, NULL,
true) < 0) {
180 RPWDEBUG(
"Failed parsing value \"%pV\" for attribute %s",
212 char const *dn = uctx;
222 RERROR(
"Cannot store DN in %s",
230 RPWDEBUG(
"Failed parsing value \"%pV\" for attribute %s", dn,
247 switch (map->
lhs->type) {
256 cf_log_err(map->
ci,
"Left hand side of map must be an attribute or list, not a %s",
265 switch (map->
rhs->type) {
284 cf_log_err(map->
ci,
"Right hand side of map must be an xlat, attribute, exec, or literal, not a %s",
300 cf_log_err(map->
ci,
"Operator \"%s\" not allowed for LDAP mappings",
322 char const *generic_attr,
char const *check_attr,
char const *fallthrough_attr)
324 map_t const *map = NULL;
325 unsigned int total = 0;
327 TALLOC_CTX *our_ctx = NULL;
329 char attr_buff[1024 + 1];
331 while ((map = map_list_next(maps, map))) {
332 if (
tmpl_expand(&attr, attr_buff,
sizeof(attr_buff), request, map->
rhs) < 0) {
333 REDEBUG(
"Expansion of LDAP attribute \"%s\" failed", map->
rhs->name);
334 TALLOC_FREE(our_ctx);
341 if (attr == attr_buff) {
342 if (!our_ctx) our_ctx = talloc_new(ctx);
346 expanded->
attrs[total++] = attr;
349 if (generic_attr) expanded->
attrs[total++] = generic_attr;
350 if (check_attr) expanded->
attrs[total++] = check_attr;
351 if (fallthrough_attr) expanded->
attrs[total++] = fallthrough_attr;
353 expanded->
attrs[total] = NULL;
354 expanded->
count = total;
355 expanded->
maps = maps;
378 char const *valuepair_attr,
fr_ldap_map_exp_t const *expanded, LDAPMessage *entry)
380 map_t const *map = NULL;
381 unsigned int total = 0;
389 struct berval *check_value;
407 fr_value_box_list_t res;
413 NULL, &parse_rules) < 0) {
414 RPEDEBUG(
"Failed parsing '%s' value \"%s\"", check_attr,
value);
425 fr_strerror_const(
"Condition expression cannot depend on functions which call external databases");
430 fr_value_box_list_init(&res);
432 RPEDEBUG(
"Failed evaluating condition");
436 RDEBUG2(
"Failed match: skipping this profile");
437 fr_value_box_list_talloc_free(&res);
442 fr_value_box_list_talloc_free(&res);
446 RPERROR(
"Failed parsing entry");
451 while ((map = map_list_next(expanded->
maps, map))) {
453 int ret, iter_err = 0;
460 RPERROR(
"Failed parsing entry");
469 char *dn = ldap_get_dn(handle, entry);
473 if (ret == -1)
return -1;
478 RDEBUG3(
"Attribute \"%s\" not found in LDAP object",
name);
489 if (ret == -1)
return -1;
502 if (valuepair_attr) {
504 struct berval *vp_value;
527 &parse_rules, &parse_rules) < 0) {
528 RPWDEBUG(
"Failed parsing '%s' value \"%s\" as valuepair, skipping...",
529 valuepair_attr,
value);
534 RWDEBUG(
"Failed adding \"%s\" to request, skipping...",
value);
543 RPERROR(
"Failed parsing entry");
#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 * fr_ldap_value_iter_init(int *err, fr_ldap_value_iter_t *iter, LDAP *handle, LDAPMessage *entry, char const *attr)
Start an in place iteration over an attribute's values in an entry.
size_t fr_ldap_util_normalise_dn(char *out, char const *in)
Normalise escape sequences in a DN.
int count
Index on next free element.
void fr_ldap_value_iter_done(fr_ldap_value_iter_t *iter)
Release value iteration state.
map_list_t const * maps
Head of list of maps we expanded the RHS of.
struct berval * fr_ldap_value_iter_next(int *err, fr_ldap_value_iter_t *iter)
Return the next value of the iterated attribute.
char * fr_ldap_berval_to_string(TALLOC_CTX *ctx, struct berval const *in)
Convert a berval to a talloced string.
#define LDAP_VIRTUAL_DN_ATTR
'Virtual' attribute which maps to the DN of the object.
char const * attrs[LDAP_MAX_ATTRMAP+LDAP_MAP_RESERVED+1]
Reserve some space for access attributes.
struct berval * fr_ldap_value_iter_alloc(int *err, fr_ldap_value_iter_t **out, TALLOC_CTX *ctx, LDAP *handle, LDAPMessage *entry, char const *attr)
Allocate a value iterator, released when the iterator is freed.
struct berval value
Value the iterator is positioned on.
Result of expanding the RHS of a set of maps.
State of an in place iteration over an attribute's 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.
int fr_ldap_map_getdn(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map, void *uctx)
Callback for map_to_request.
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_verify(map_t *map, UNUSED void *instance)
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, char const *fallthrough_attr)
Expand values in an attribute map where needed.
#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.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_OCTETS
Raw octets.
int fr_pair_value_from_str(fr_pair_t *vp, char const *value, size_t inlen, fr_sbuff_unescape_rules_t const *uerules, UNUSED bool tainted)
Convert string value to native attribute value.
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.
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.
int tmpl_resolve(tmpl_t *vpt, tmpl_res_rules_t const *tr_rules))
Attempt to resolve functions and attributes in xlats and attribute references.
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
Value in native boxed format.
@ 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_expand(_out, _buff, _buff_len, _request, _vpt)
Expand a tmpl to a C type, using existing storage to hold variably sized types.
#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.
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.
#define talloc_strdup(_ctx, _str)
static size_t talloc_strlen(char const *s)
Returns the length of a talloc array containing a string.
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)
fr_table_num_ordered_t const fr_type_table[]
Map data types to names representing those types.
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