26 RCSID(
"$Id: de9c1b74923382bbaef88f8c8808dc8844c61704 $")
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\"",
99 attr_str =
talloc_bstrndup(NULL, self->values[i]->bv_val, self->values[i]->bv_len);
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 map_t const *map = NULL;
274 unsigned int total = 0;
276 TALLOC_CTX *our_ctx = NULL;
278 char attr_buff[1024 + 1];
280 while ((map = map_list_next(maps, map))) {
281 if (
tmpl_expand(&attr, attr_buff,
sizeof(attr_buff), request, map->
rhs, NULL, NULL) < 0) {
282 REDEBUG(
"Expansion of LDAP attribute \"%s\" failed", map->
rhs->name);
283 TALLOC_FREE(our_ctx);
290 if (attr == attr_buff) {
291 if (!our_ctx) our_ctx = talloc_new(ctx);
292 expanded->
attrs[total++] = talloc_strdup(our_ctx, attr_buff);
295 expanded->
attrs[total++] = attr;
298 if (generic_attr) expanded->
attrs[total++] = generic_attr;
300 expanded->
attrs[total] = NULL;
301 expanded->
count = total;
302 expanded->
maps = maps;
324 char const *valuepair_attr,
fr_ldap_map_exp_t const *expanded, LDAPMessage *entry)
326 map_t const *map = NULL;
327 unsigned int total = 0;
334 while ((map = map_list_next(expanded->
maps, map))) {
342 result.
values = ldap_get_values_len(handle, entry,
name);
344 RDEBUG3(
"Attribute \"%s\" not found in LDAP object",
name);
353 result.
count = ldap_count_values_len(result.
values);
361 if (ret == -1)
return -1;
369 ldap_value_free_len(result.
values);
377 if (valuepair_attr) {
378 struct berval **values;
381 values = ldap_get_values_len(handle, entry, valuepair_attr);
382 count = ldap_count_values_len(values);
384 for (i = 0; i <
count; i++) {
403 &parse_rules, &parse_rules) < 0) {
404 RPWDEBUG(
"Failed parsing '%s' value \"%s\" as valuepair, skipping...",
405 valuepair_attr,
value);
410 RWDEBUG(
"Failed adding \"%s\" to request, skipping...",
value);
417 ldap_value_free_len(values);
#define USES_APPLE_DEPRECATED_API
#define cf_log_err(_cf, _fmt,...)
fr_dcursor_eval_t void const * uctx
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.
int count
Number of values.
char * fr_ldap_berval_to_string(TALLOC_CTX *ctx, struct berval const *in)
Convert a berval to a talloced string.
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.
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)
Expand values in an attribute map where needed.
int fr_ldap_map_do(request_t *request, char const *valuepair_attr, fr_ldap_map_exp_t const *expanded, LDAPMessage *entry)
Convert attribute map into valuepairs.
#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.
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.
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
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
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_list_name(fr_dict_attr_t const *list, char const *def)
Return the name of a tmpl list or def if list not provided.
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
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 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 char const * tmpl_attr_tail_unresolved(tmpl_t const *vpt)
Return the last attribute reference unresolved da.
static fr_dict_attr_t const * tmpl_list(tmpl_t const *vpt)
#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.
static char const * tmpl_type_to_str(tmpl_type_t type)
Return a static string containing the type name.
Optional arguments passed to vp_tmpl functions.
MEM(pair_append_request(&vp, attr_eap_aka_sim_identity) >=0)
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[]
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_box_strvalue_len(_val, _len)
static size_t char ** out