27 #include <freeradius-devel/rad_assert.h>
58 for (i = 0; i <
self->count; i++) {
61 RDEBUG3(
"Parsing valuepair string \"%s\"", self->values[i]->bv_val);
63 map->
lhs->tmpl_request, map->
lhs->tmpl_list,
66 self->values[i]->bv_val);
70 if (attr->
lhs->tmpl_request != map->
lhs->tmpl_request) {
71 RWDEBUG(
"valuepair \"%s\" has conflicting request qualifier (%s vs %s), skipping...",
72 self->values[i]->bv_val,
80 if ((attr->
lhs->tmpl_list != map->
lhs->tmpl_list)) {
81 RWDEBUG(
"valuepair \"%s\" has conflicting list qualifier (%s vs %s), skipping...",
82 self->values[i]->bv_val,
88 if (
map_to_vp(request, &vp, request, attr, NULL) < 0) {
89 RWDEBUG(
"Failed creating attribute for valuepair \"%s\", skipping...",
90 self->values[i]->bv_val);
110 for (i = 0; i <
self->count; i++) {
111 if (!self->values[i]->bv_len)
continue;
119 escaped =
fr_asprint(vp, self->values[i]->bv_val, self->values[i]->bv_len,
'"');
120 RWDEBUG(
"Failed parsing value \"%s\" for attribute %s: %s", escaped,
160 cf_log_err(map->
ci,
"Unknown attribute %s", map->
lhs->tmpl_unknown_name);
164 cf_log_err(map->
ci,
"Left hand side of map must be an attribute or list, not a %s",
181 cf_log_err(map->
ci,
"Unknown attribute %s", map->
rhs->tmpl_unknown_name);
185 cf_log_err(map->
ci,
"Right hand side of map must be an xlat, attribute, exec, or literal, not a %s",
201 cf_log_err(map->
ci,
"Operator \"%s\" not allowed for LDAP mappings",
213 switch (map->
lhs->tmpl_da->attr) {
214 case PW_CLEARTEXT_PASSWORD:
216 case PW_USER_PASSWORD:
217 case PW_PASSWORD_WITH_HEADER:
218 case PW_CRYPT_PASSWORD:
224 LDAP_DBGW(
"Mapping LDAP (%s) attribute to \"known good\" password attribute "
225 "(%s) in %s list. This is probably *NOT* the correct list, "
226 "you should prepend \"control:\" to password attribute "
254 unsigned int total = 0;
256 TALLOC_CTX *ctx = NULL;
258 char attr_buff[1024 + 1];
260 for (map = maps; map != NULL; map = map->
next) {
261 if (
tmpl_expand(&attr, attr_buff,
sizeof(attr_buff), request, map->
rhs, NULL, NULL) < 0) {
262 RDEBUG(
"Expansion of LDAP attribute \"%s\" failed", map->
rhs->
name);
270 if (attr == attr_buff) {
271 if (!ctx) ctx = talloc_new(NULL);
272 expanded->
attrs[total++] = talloc_strdup(ctx, attr_buff);
275 expanded->
attrs[total++] = attr;
277 expanded->
attrs[total] = NULL;
279 expanded->
count = total;
280 expanded->
maps = maps;
306 unsigned int total = 0;
312 for (map = expanded->
maps; map != NULL; map = map->
next) {
315 name = expanded->
attrs[total++];
320 result.
values = ldap_get_values_len(handle, entry, name);
322 RDEBUG3(
"Attribute \"%s\" not found in LDAP object", name);
331 result.
count = ldap_count_values_len(result.
values);
339 if (ret == -1)
return -1;
347 ldap_value_free_len(result.
values);
356 struct berval **values;
359 values = ldap_get_values_len(handle, entry, inst->
valuepair_attr);
360 count = ldap_count_values_len(values);
362 for (i = 0; i < count; i++) {
367 RDEBUG3(
"Parsing attribute string '%s'", value);
371 RWDEBUG(
"Failed parsing '%s' value \"%s\" as valuepair (%s), skipping...",
377 RWDEBUG(
"Failed adding \"%s\" to request, skipping...", value);
384 ldap_value_free_len(values);
#define LDAP_DBGW(fmt,...)
ssize_t tmpl_expand(char const **out, char *buff, size_t outlen, REQUEST *request, vp_tmpl_t const *vpt, xlat_escape_t escape, void *escape_ctx)
Expand a vp_tmpl_t to a string writing the result to a buffer.
int int map_to_request(REQUEST *request, vp_map_t const *map, radius_map_getvalue_t func, void *ctx)
Convert vp_map_t to VALUE_PAIR (s) and add them to a REQUEST.
char const * name
Raw string used to create the template.
vp_tmpl_t * lhs
Typically describes the attribute to add, modify or compare.
vp_tmpl_t * rhs
Typically describes a literal value or a src attribute to copy or compare.
const FR_NAME_NUMBER fr_tokens_table[]
VALUE_PAIR * fr_cursor_init(vp_cursor_t *cursor, VALUE_PAIR *const *node)
Setup a cursor to iterate over attribute pairs.
vp_map_t const * maps
Head of list of maps we expanded the RHS of.
Abstraction to allow iterating over different configurations of VALUE_PAIRs.
struct vp_map * next
The next valuepair map.
Attribute not found in the global dictionary.
char const * valuepair_attr
Generic dynamic mapping attribute, contains a RADIUS attribute and value.
const FR_NAME_NUMBER request_refs[]
Map keywords to request_refs_t values.
Result of expanding the RHS of a set of maps.
void fr_cursor_merge(vp_cursor_t *cursor, VALUE_PAIR *vp)
Merges multiple VALUE_PAIR into the cursor.
void fr_cursor_insert(vp_cursor_t *cursor, VALUE_PAIR *vp)
Insert a single VALUE_PAIR at the end of the list.
Attributes in incoming or internally proxied request.
int count
Number of values.
Stores an attribute, a value and various bits of other data.
Contains a collection of values.
int fr_pair_value_from_str(VALUE_PAIR *vp, char const *value, size_t len)
Convert string value to native attribute value.
tmpl_type_t type
What type of value tmpl refers to.
char const * fr_strerror(void)
Get the last library error.
int count
Index on next free element.
Callout to an external script or program.
int rlm_ldap_map_expand(rlm_ldap_map_exp_t *expanded, REQUEST *request, vp_map_t const *maps)
Expand values in an attribute map where needed.
void cf_log_err(CONF_ITEM const *ci, char const *fmt,...) CC_HINT(format(printf
int int map_afrom_attr_str(TALLOC_CTX *ctx, vp_map_t **out, char const *raw, request_refs_t dst_request_def, pair_lists_t dst_list_def, request_refs_t src_request_def, pair_lists_t src_list_def)
Convert a value pair string to valuepair map.
FR_TOKEN op
The operator that controls insertion of the dst attribute.
struct berval ** values
libldap struct containing bv_val (char *) and length bv_len.
int rlm_ldap_map_getvalue(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, vp_map_t const *map, void *uctx)
Callback for map_to_request.
char * fr_asprint(TALLOC_CTX *ctx, char const *in, ssize_t inlen, char quote)
Escape string that may contain binary data, and write it to a new buffer.
Attributes to send in the response.
int rlm_ldap_map_do(const rlm_ldap_t *inst, REQUEST *request, LDAP *handle, rlm_ldap_map_exp_t const *expanded, LDAPMessage *entry)
Convert attribute map into valuepairs.
char const * attrs[LDAP_MAX_ATTRMAP+LDAP_MAP_RESERVED+1]
Reserve some space for access attributes.
int map_to_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, vp_map_t const *map, void *uctx) CC_HINT(nonnull(2
TALLOC_CTX * ctx
Context to allocate new attributes in.
VALUE_PAIR * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute.
char const * fr_int2str(FR_NAME_NUMBER const *table, int number, char const *def)
char * rlm_ldap_berval_to_string(TALLOC_CTX *ctx, struct berval const *in)
Convert a berval to a talloced string.
Attributes that change the behaviour of modules.
int rlm_ldap_map_verify(vp_map_t *map, void *instance)
LDAP authorization and authentication module headers.
bool expect_password
True if the user_map included a mapping between an LDAP attribute and one of our password reference a...
const FR_NAME_NUMBER tmpl_names[]
Map tmpl_type_t values to descriptive strings.
CONF_ITEM * ci
Config item that the map was created from.