Skip to content

Commit 8edf5b7

Browse files
committed
Add check attribute processing to rlm_ldap profile handling
Comparable to check items in rlm_files and check entries in rlm_sql with comparison operators.
1 parent c4f3e5f commit 8edf5b7

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

src/lib/ldap/base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ int fr_ldap_map_verify(map_t *map, void *instance);
857857
int fr_ldap_map_expand(TALLOC_CTX *ctx, fr_ldap_map_exp_t *expanded, request_t *request,
858858
map_list_t const *maps, char const *generic_attr, char const *check_attr);
859859

860-
int fr_ldap_map_do(request_t *request,
860+
int fr_ldap_map_do(request_t *request, char const *check_attr,
861861
char const *valuepair_attr, fr_ldap_map_exp_t const *expanded, LDAPMessage *entry);
862862

863863
/*

src/lib/ldap/map.c

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ int fr_ldap_map_expand(TALLOC_CTX *ctx, fr_ldap_map_exp_t *expanded, request_t *
322322
* - Number of maps successfully applied.
323323
* - -1 on failure.
324324
*/
325-
int fr_ldap_map_do(request_t *request,
325+
int fr_ldap_map_do(request_t *request, char const *check_attr,
326326
char const *valuepair_attr, fr_ldap_map_exp_t const *expanded, LDAPMessage *entry)
327327
{
328328
map_t const *map = NULL;
@@ -333,6 +333,62 @@ int fr_ldap_map_do(request_t *request,
333333
char const *name;
334334
LDAP *handle = fr_ldap_handle_thread_local();
335335

336+
if (check_attr) {
337+
struct berval **values;
338+
int count, i;
339+
tmpl_rules_t const parse_rules = {
340+
.attr = {
341+
.dict_def = request->dict,
342+
.list_def = request_attr_request,
343+
.prefix = TMPL_ATTR_REF_PREFIX_AUTO
344+
},
345+
.xlat = {
346+
.runtime_el = unlang_interpret_event_list(request),
347+
},
348+
.at_runtime = true,
349+
};
350+
351+
values = ldap_get_values_len(handle, entry, check_attr);
352+
count = ldap_count_values_len(values);
353+
354+
for (i = 0; i < count; i++) {
355+
map_t *check = NULL;
356+
char *value = fr_ldap_berval_to_string(request, values[i]);
357+
358+
RDEBUG3("Parsing condition %s", value);
359+
if (map_afrom_attr_str(request, &check, value, &parse_rules, &parse_rules) < 0) {
360+
RPEDEBUG("Failed parsing '%s' value \"%s\"", check_attr, value);
361+
fail:
362+
applied = -1;
363+
free:
364+
talloc_free(check);
365+
talloc_free(value);
366+
ldap_value_free_len(values);
367+
return applied;
368+
}
369+
370+
if (!fr_comparison_op[check->op]) {
371+
REDEBUG("Invalid operator '%s'", fr_tokens[check->op]);
372+
goto fail;
373+
}
374+
375+
if (fr_type_is_structural(tmpl_attr_tail_da(check->lhs)->type) &&
376+
(check->op != T_OP_CMP_TRUE) && (check->op != T_OP_CMP_FALSE)) {
377+
REDEBUG("Invalid comparison for structural type");
378+
goto fail;
379+
}
380+
381+
RDEBUG2("Checking condition %s %s %s", check->lhs->name, fr_tokens[check->op], check->rhs->name);
382+
if (radius_legacy_map_cmp(request, check) != 1) {
383+
RDEBUG2("Failed match: skipping this profile");
384+
goto free;
385+
}
386+
talloc_free(value);
387+
talloc_free(check);
388+
}
389+
ldap_value_free_len(values);
390+
}
391+
336392
while ((map = map_list_next(expanded->maps, map))) {
337393
int ret;
338394

src/modules/rlm_ldap/profile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static unlang_action_t ldap_map_profile_resume(UNUSED rlm_rcode_t *p_result, UNU
9999
ldap_memfree(dn);
100100
}
101101
RINDENT();
102-
if (fr_ldap_map_do(request, profile_ctx->inst->valuepair_attr,
102+
if (fr_ldap_map_do(request, profile_ctx->inst->profile_check_attr, profile_ctx->inst->valuepair_attr,
103103
profile_ctx->expanded, entry) < 0) {
104104
if (profile_ctx->ret) *profile_ctx->ret = LDAP_RESULT_ERROR;
105105
}

src/modules/rlm_ldap/rlm_ldap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ static unlang_action_t mod_authorize_resume(rlm_rcode_t *p_result, UNUSED int *p
17051705
if (!map_list_empty(call_env->user_map) || inst->valuepair_attr) {
17061706
RDEBUG2("Processing user attributes");
17071707
RINDENT();
1708-
if (fr_ldap_map_do(request, inst->valuepair_attr,
1708+
if (fr_ldap_map_do(request, NULL, inst->valuepair_attr,
17091709
&autz_ctx->expanded, autz_ctx->entry) > 0) rcode = RLM_MODULE_UPDATED;
17101710
REXDENT();
17111711
rlm_ldap_check_reply(request, inst, autz_ctx->dlinst->name, call_env->expect_password->vb_bool, autz_ctx->ttrunk);

0 commit comments

Comments
 (0)