The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
rlm_ldap.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: fc73099d1bc01ce5365d497c661e9883ffb2da81 $
19 * @file rlm_ldap.c
20 * @brief LDAP authorization and authentication module.
21 *
22 * @author Arran Cudbard-Bell (a.cudbardb@freeradius.org)
23 * @author Alan DeKok (aland@freeradius.org)
24 *
25 * @copyright 2012,2015 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
26 * @copyright 2013,2015 Network RADIUS SAS (legal@networkradius.com)
27 * @copyright 2012 Alan DeKok (aland@freeradius.org)
28 * @copyright 1999-2013 The FreeRADIUS Server Project.
29 */
30RCSID("$Id: fc73099d1bc01ce5365d497c661e9883ffb2da81 $")
31
33
34#include <freeradius-devel/util/debug.h>
35#include <freeradius-devel/util/table.h>
36#include <freeradius-devel/util/uri.h>
37
38#include <freeradius-devel/ldap/conf.h>
39
40#include <freeradius-devel/server/map_proc.h>
41#include <freeradius-devel/server/module_rlm.h>
42
43#include <freeradius-devel/unlang/xlat_func.h>
44#include <freeradius-devel/unlang/map.h>
45
46#include "rlm_ldap.h"
47
53
62
63typedef struct {
64 char const *attr;
66 tmpl_t const *tmpl;
73
74/** Call environment used in the profile xlat
75 */
76typedef struct {
77 fr_value_box_t profile_filter; //!< Filter to use when searching for users.
78 map_list_t *profile_map; //!< List of maps to apply to the profile.
80
81static int ldap_update_section_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, call_env_parser_t const *rule);
82static int ldap_mod_section_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, call_env_parser_t const *rule);
83
84static int ldap_group_filter_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule);
85
93
100
102 { FR_CONF_OFFSET("scope", rlm_ldap_t, profile.obj_scope), .dflt = "base",
103 .func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = fr_ldap_scope, .len = &fr_ldap_scope_len } },
104 { FR_CONF_OFFSET("search_mode", rlm_ldap_t, profile.search_mode), .dflt = "auto",
106 { FR_CONF_DEPRECATED("attribute", rlm_ldap_t, user.profile_attr) },
107 { FR_CONF_DEPRECATED("attribute_suspend", rlm_ldap_t, user.profile_attr_suspend) },
108 { FR_CONF_OFFSET("check_attribute", rlm_ldap_t, profile.check_attr) },
109 { FR_CONF_OFFSET("sort_by", rlm_ldap_t, profile.obj_sort_by) },
110 { FR_CONF_OFFSET("fallthrough_attribute", rlm_ldap_t, profile.fallthrough_attr) },
111 { FR_CONF_OFFSET("fallthrough_default", rlm_ldap_t, profile.fallthrough_def), .dflt = "yes" },
113};
114
115/*
116 * User configuration
117 */
119 { FR_CONF_OFFSET("scope", rlm_ldap_t, user.obj_scope), .dflt = "sub",
120 .func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = fr_ldap_scope, .len = &fr_ldap_scope_len } },
121 { FR_CONF_OFFSET("sort_by", rlm_ldap_t, user.obj_sort_by) },
122
123 { FR_CONF_OFFSET("access_attribute", rlm_ldap_t, user.obj_access_attr) },
124 { FR_CONF_OFFSET("access_positive", rlm_ldap_t, user.access_positive), .dflt = "yes" },
125 { FR_CONF_OFFSET("access_value_negate", rlm_ldap_t, user.access_value_negate), .dflt = "false" },
126 { FR_CONF_OFFSET("access_value_suspend", rlm_ldap_t, user.access_value_suspend), .dflt = "suspended" },
127 { FR_CONF_OFFSET("dn_attribute", rlm_ldap_t, user.dn_attr_str), .dflt = "LDAP-UserDN" },
128 { FR_CONF_OFFSET_IS_SET("expect_password", FR_TYPE_BOOL, 0, rlm_ldap_t, user.expect_password) },
129 { FR_CONF_OFFSET("profile_attribute", rlm_ldap_t, user.profile_attr) },
130 { FR_CONF_OFFSET("profile_attribute_suspend", rlm_ldap_t, user.profile_attr_suspend) },
132};
133
134/*
135 * Group configuration
136 */
138 { FR_CONF_OFFSET("filter", rlm_ldap_t, group.obj_filter) },
139 { FR_CONF_OFFSET("scope", rlm_ldap_t, group.obj_scope), .dflt = "sub",
140 .func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = fr_ldap_scope, .len = &fr_ldap_scope_len } },
141
142 { FR_CONF_OFFSET("name_attribute", rlm_ldap_t, group.obj_name_attr), .dflt = "cn" },
143 { FR_CONF_OFFSET("membership_attribute", rlm_ldap_t, group.userobj_membership_attr) },
144 { FR_CONF_OFFSET_FLAGS("membership_filter", CONF_FLAG_XLAT, rlm_ldap_t, group.obj_membership_filter) },
145 { FR_CONF_OFFSET("cacheable_name", rlm_ldap_t, group.cacheable_name), .dflt = "no" },
146 { FR_CONF_OFFSET("cacheable_dn", rlm_ldap_t, group.cacheable_dn), .dflt = "no" },
147 { FR_CONF_OFFSET("cache_attribute", rlm_ldap_t, group.cache_attr_str) },
148 { FR_CONF_OFFSET("group_attribute", rlm_ldap_t, group.attribute) },
149 { FR_CONF_OFFSET("allow_dangling_group_ref", rlm_ldap_t, group.allow_dangling_refs), .dflt = "no" },
150 { FR_CONF_OFFSET("skip_on_suspend", rlm_ldap_t, group.skip_on_suspend), .dflt = "yes"},
151 { FR_CONF_OFFSET("profile_attribute", rlm_ldap_t, group.profile_attr) },
152 { FR_CONF_OFFSET("profile_attribute_suspend", rlm_ldap_t, group.profile_attr_suspend) },
154};
155
156static const conf_parser_t module_config[] = {
157 /*
158 * Pool config items
159 */
160 { FR_CONF_OFFSET_FLAGS("server", CONF_FLAG_MULTI, rlm_ldap_t, handle_config.server_str) }, /* Do not set to required */
161
162 /*
163 * Common LDAP conf parsers
164 */
166
167 { FR_CONF_OFFSET("valuepair_attribute", rlm_ldap_t, valuepair_attr) },
168
169 { FR_CONF_OFFSET("dn_attribute", rlm_ldap_t, dn_attr) },
170
171#ifdef LDAP_CONTROL_X_SESSION_TRACKING
172 { FR_CONF_OFFSET("session_tracking", rlm_ldap_t, session_tracking), .dflt = "no" },
173#endif
174
175#ifdef WITH_EDIR
176 /* support for eDirectory Universal Password */
177 { FR_CONF_OFFSET("edir", rlm_ldap_t, edir) }, /* NULL defaults to "no" */
178
179 /*
180 * Attempt to bind with the cleartext password we got from eDirectory
181 * Universal password for additional authorization checks.
182 */
183 { FR_CONF_OFFSET("edir_autz", rlm_ldap_t, edir_autz) }, /* NULL defaults to "no" */
184#endif
185
186 { FR_CONF_POINTER("user", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) user_config },
187
188 { FR_CONF_POINTER("group", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) group_config },
189
190 { FR_CONF_POINTER("profile", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) profile_config },
191
192 { FR_CONF_OFFSET_SUBSECTION("pool", 0, rlm_ldap_t, trunk_conf, trunk_config ) },
193
194 { FR_CONF_OFFSET_SUBSECTION("bind_pool", 0, rlm_ldap_t, bind_trunk_conf, trunk_config ) },
195
197};
198
199#define LDAP_DN_CALL_ENV_ESCAPE \
200 .pair.escape = { \
201 .box_escape = { \
202 .func = fr_ldap_dn_box_escape, \
203 .safe_for = LDAP_DN_SAFE_FOR, \
204 .always_escape = false, \
205 }, \
206 .mode = TMPL_ESCAPE_PRE_CONCAT \
207 }, \
208 .pair.literals_safe_for = LDAP_DN_SAFE_FOR
209
210#define LDAP_FILTER_CALL_ENV_ESCAPE \
211 .pair.escape = { \
212 .box_escape = { \
213 .func = fr_ldap_filter_box_escape, \
214 .safe_for = LDAP_FILTER_SAFE_FOR, \
215 .always_escape = false, \
216 }, \
217 .mode = TMPL_ESCAPE_PRE_CONCAT \
218 }, \
219 .pair.literals_safe_for = LDAP_FILTER_SAFE_FOR
220
221#define USER_CALL_ENV_COMMON(_struct) \
222 { FR_CALL_ENV_OFFSET("base_dn", FR_TYPE_STRING, CALL_ENV_FLAG_REQUIRED | CALL_ENV_FLAG_CONCAT, _struct, user_base), \
223 .pair.dflt = "", .pair.dflt_quote = T_SINGLE_QUOTED_STRING, LDAP_DN_CALL_ENV_ESCAPE }, \
224 { FR_CALL_ENV_OFFSET("filter", FR_TYPE_STRING, CALL_ENV_FLAG_NULLABLE | CALL_ENV_FLAG_CONCAT, _struct, user_filter), \
225 .pair.dflt = "(&)", .pair.dflt_quote = T_SINGLE_QUOTED_STRING, LDAP_FILTER_CALL_ENV_ESCAPE }
226
242
243/** Parameters to allow ldap_update_section_parse to be reused
244 */
249
252 .env = (call_env_parser_t[]) {
255 .map_offset = offsetof(ldap_autz_call_env_t, user_map),
256 .expect_password_offset = offsetof(ldap_autz_call_env_t, expect_password)
257 } },
259 ((call_env_parser_t[]) {
262 })) },
264 ((call_env_parser_t[]) {
268 .pair.func = ldap_group_filter_parse,
270 },
272 })) },
274 ((call_env_parser_t[]) {
280 .pair.dflt = "(&)", .pair.dflt_quote = T_SINGLE_QUOTED_STRING,
283 } )) },
285 }
286};
287
288#define USERMOD_ENV(_section) static const call_env_method_t _section ## _usermod_method_env = { \
289 FR_CALL_ENV_METHOD_OUT(ldap_usermod_call_env_t), \
290 .env = (call_env_parser_t[]) { \
291 { FR_CALL_ENV_SUBSECTION("user", NULL, CALL_ENV_FLAG_REQUIRED, \
292 ((call_env_parser_t[]) { \
293 USER_CALL_ENV_COMMON(ldap_usermod_call_env_t), CALL_ENV_TERMINATOR \
294 })) }, \
295 { FR_CALL_ENV_SUBSECTION_FUNC(STRINGIFY(_section), CF_IDENT_ANY, CALL_ENV_FLAG_SUBSECTION | CALL_ENV_FLAG_PARSE_MISSING, ldap_mod_section_parse) }, \
296 CALL_ENV_TERMINATOR \
297 } \
298}
299
300USERMOD_ENV(accounting);
302
324
327 .env = (call_env_parser_t[]) {
330 .map_offset = offsetof(ldap_xlat_profile_call_env_t, profile_map),
331 .expect_password_offset = -1
332 } },
334 ((call_env_parser_t[]) {
336 .pair.dflt = "(&)", .pair.dflt_quote = T_SINGLE_QUOTED_STRING,
337 LDAP_FILTER_CALL_ENV_ESCAPE }, //!< Correct filter for when the DN is known.
339 })) },
341 }
342};
343
345
348 { .out = &dict_freeradius, .proto = "freeradius" },
350};
351
358
361 { .out = &attr_password, .name = "Password", .type = FR_TYPE_TLV, .dict = &dict_freeradius },
362 { .out = &attr_cleartext_password, .name = "Password.Cleartext", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
363 { .out = &attr_crypt_password, .name = "Password.Crypt", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
364 { .out = &attr_nt_password, .name = "Password.NT", .type = FR_TYPE_OCTETS, .dict = &dict_freeradius },
365 { .out = &attr_password_with_header, .name = "Password.With-Header", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
366 { .out = &attr_expr_bool_enum, .name = "Expr-Bool-Enum", .type = FR_TYPE_BOOL, .dict = &dict_freeradius },
367
369};
370
371extern global_lib_autoinst_t const *rlm_ldap_lib[];
376
377/** Holds state of in progress async authentication
378 *
379 */
387
388/** Holds state of in progress ldap user modifications
389 *
390 */
404
405/** Holds state of in progress LDAP map
406 *
407 */
408typedef struct {
409 map_list_t const *maps;
410 LDAPURLDesc *ldap_url;
413 LDAPControl *serverctrls[LDAP_MAX_CONTROLS];
415
421
423 { L("ldap://"), LDAP_SCHEME_UNIX },
424 { L("ldapi://"), LDAP_SCHEME_TCP },
425 { L("ldaps://"), LDAP_SCHEME_TCP_SSL },
426};
428
433
435 { .required = true, .concat = true, .type = FR_TYPE_STRING },
437};
438
439/** Escape a string for use in an RFC 4514 DN attribute value
440 *
441 * @ingroup xlat_functions
442 */
444 UNUSED xlat_ctx_t const *xctx,
445 request_t *request, fr_value_box_list_t *in)
446{
447 fr_value_box_t *in_vb, *in_group = fr_value_box_list_head(in);
448
449 fr_assert(in_group->type == FR_TYPE_GROUP);
450
451 while ((in_vb = fr_value_box_list_pop_head(&in_group->vb_group))) {
452 if (!fr_value_box_is_safe_for_only(in_vb, LDAP_DN_SAFE_FOR) && (fr_ldap_dn_box_escape(in_vb, NULL) < 0)) {
453 RPEDEBUG("Failed escaping DN attribute value");
454 talloc_free(in_vb);
455 return XLAT_ACTION_FAIL;
456 }
457
458 fr_dcursor_append(out, in_vb);
459 }
460 return XLAT_ACTION_DONE;
461}
462
463/** Escape a string for use as an RFC 4515 filter assertion value
464 *
465 * @ingroup xlat_functions
466 */
468 UNUSED xlat_ctx_t const *xctx,
469 request_t *request, fr_value_box_list_t *in)
470{
471 fr_value_box_t *in_vb, *in_group = fr_value_box_list_head(in);
472
473 fr_assert(in_group->type == FR_TYPE_GROUP);
474
475 while ((in_vb = fr_value_box_list_pop_head(&in_group->vb_group))) {
477 RPEDEBUG("Failed escaping filter assertion value");
478 talloc_free(in_vb);
479 return XLAT_ACTION_FAIL;
480 }
481
482 fr_dcursor_append(out, in_vb);
483 }
484 return XLAT_ACTION_DONE;
485}
486
491
492/** Unescape LDAP string
493 *
494 * @ingroup xlat_functions
495 */
497 UNUSED xlat_ctx_t const *xctx,
498 request_t *request, fr_value_box_list_t *in)
499{
500 fr_value_box_t *vb, *in_vb = NULL, *in_group = fr_value_box_list_head(in);
501 fr_sbuff_t sbuff;
502 fr_sbuff_uctx_talloc_t sbuff_ctx;
503 size_t len;
504
505 fr_assert(in_group->type == FR_TYPE_GROUP);
506
507 while ((in_vb = fr_value_box_list_next(&in_group->vb_group, in_vb))) {
508
509 MEM(vb = fr_value_box_alloc_null(ctx));
510 /*
511 * Maximum space needed for output will be the same as the input
512 */
513 if (!fr_sbuff_init_talloc(vb, &sbuff, &sbuff_ctx, in_vb->vb_length, in_vb->vb_length)) {
514 REDEBUG("Failed to allocate buffer for unescaped string");
515 talloc_free(vb);
516 return XLAT_ACTION_FAIL;
517 }
518
519 /*
520 * Call the unescape function, including the space for the trailing NULL
521 */
522 len = fr_ldap_uri_unescape_func(request, fr_sbuff_buff(&sbuff), in_vb->vb_length + 1, in_vb->vb_strvalue, NULL);
523
524 /*
525 * Trim buffer to fit used space and assign to box
526 */
527 fr_sbuff_trim_talloc(&sbuff, len);
528 fr_value_box_strdup_shallow(vb, NULL, fr_sbuff_buff(&sbuff), in_vb->tainted);
530 }
531
532 return XLAT_ACTION_DONE;
533}
534
535/** Callback when LDAP query times out
536 *
537 */
539{
540 fr_ldap_query_t *query = talloc_get_type_abort(uctx, fr_ldap_query_t);
541 trunk_request_t *treq;
542 request_t *request;
543
544 /*
545 * If the trunk request has completed but the query
546 * has not yet resumed, query->treq will be NULL
547 */
548 if (!query->treq) return;
549
550 treq = talloc_get_type_abort(query->treq, trunk_request_t);
551 request = treq->request;
552
553 ROPTIONAL(RERROR, ERROR, "Timeout waiting for LDAP query");
554
556
557 query->ret = LDAP_RESULT_TIMEOUT;
559}
560
562 { .required = true, .concat = true, .type = FR_TYPE_STRING },
563 { .required = true, .concat = true, .type = FR_TYPE_STRING },
565};
566
567/** Modify an LDAP URI to append an option to all attributes
568 *
569 * This is for the corner case where a URI is provided by a third party system
570 * and needs amending before being used. e.g. a CRL distribution point extracted
571 * from a certificate may need the "binary" option appending to the attribute
572 * being requested.
573 *
574 * @ingroup xlat_functions
575 */
577 request_t *request, fr_value_box_list_t *in)
578{
579 fr_value_box_t *uri, *option_vb;
580 char *attrs_fixed, **attr, port[6];
581 char const *option;
582 LDAPURLDesc *ldap_url;
583 fr_value_box_t *vb;
584 int ret;
585
586 XLAT_ARGS(in, &uri, &option_vb);
587
588#ifdef STATIC_ANALYZER
589 if (!option_vb) return XLAT_ACTION_FAIL;
590#endif
591
592 if (option_vb->vb_length < 1) {
593 RERROR("LDAP attriubte option must not be blank");
594 return XLAT_ACTION_FAIL;
595 }
596
597 if (!ldap_is_ldap_url(uri->vb_strvalue)) {
598 REDEBUG("String passed does not look like an LDAP URL");
599 return XLAT_ACTION_FAIL;
600 }
601
602 ret = ldap_url_parse(uri->vb_strvalue, &ldap_url);
603 if (ret != LDAP_URL_SUCCESS){
604 RPEDEBUG("Parsing LDAP URL failed - %s", fr_ldap_url_err_to_str(ret));
605 return XLAT_ACTION_FAIL;
606 }
607
608 /*
609 * No attributes, just return what was presented.
610 */
611 if (!ldap_url->lud_attrs || !ldap_url->lud_attrs[0] || !*ldap_url->lud_attrs[0]) {
612 xlat_arg_copy_out(ctx, out, in, uri);
613 goto done;
614 }
615
616 if (option_vb->vb_strvalue[0] != ';') {
617 option = talloc_asprintf(option_vb, ";%s", option_vb->vb_strvalue);
618 } else {
619 option = option_vb->vb_strvalue;
620 }
621
622 MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_STRING, NULL));
623 attrs_fixed = talloc_strdup(vb, "");
624
625 attr = ldap_url->lud_attrs;
626 while (*attr) {
627 attrs_fixed = talloc_strdup_append(attrs_fixed, *attr);
628 if (!strstr(*attr, option)) attrs_fixed = talloc_strdup_append(attrs_fixed, option);
629 attr++;
630 if (*attr) attrs_fixed = talloc_strdup_append(attrs_fixed, ",");
631 }
632
633 snprintf(port, sizeof(port), "%d", ldap_url->lud_port);
634 fr_value_box_asprintf(vb, vb, NULL, uri->tainted, "%s://%s%s%s/%s?%s?%s?%s",
635 ldap_url->lud_scheme,
636 ldap_url->lud_host ? ldap_url->lud_host : "",
637 ldap_url->lud_host ? ":" : "",
638 ldap_url->lud_host ? port : "",
639 ldap_url->lud_dn, attrs_fixed,
640 fr_table_str_by_value(fr_ldap_scope, ldap_url->lud_scope, ""),
641 ldap_url->lud_filter ? ldap_url->lud_filter : "");
642
644done:
645 ldap_free_urldesc(ldap_url);
646 return XLAT_ACTION_DONE;
647}
648
649/** Callback when resuming after async ldap query is completed
650 *
651 */
653 xlat_ctx_t const *xctx,
654 request_t *request, UNUSED fr_value_box_list_t *in)
655{
656 fr_ldap_query_t *query = talloc_get_type_abort(xctx->rctx, fr_ldap_query_t);
657 fr_ldap_connection_t *ldap_conn = query->ldap_conn;
658 fr_value_box_t *vb = NULL;
659 LDAPMessage *msg;
660 struct berval **values;
661 char const **attr;
662 int count, i;
663
664 if (query->ret != LDAP_RESULT_SUCCESS) return XLAT_ACTION_FAIL;
665
666 /*
667 * We only parse "entries"
668 */
669 for (msg = ldap_first_entry(ldap_conn->handle, query->result); msg; msg = ldap_next_entry(ldap_conn->handle, msg)) {
670 for (attr = query->search.attrs; *attr; attr++) {
671 values = ldap_get_values_len(ldap_conn->handle, msg, *attr);
672 if (!values) {
673 RDEBUG2("No \"%s\" attributes found in specified object", *attr);
674 continue;
675 }
676
677 count = ldap_count_values_len(values);
678 for (i = 0; i < count; i++) {
679 MEM(vb = fr_value_box_alloc_null(ctx));
680 if (fr_value_box_bstrndup(vb, vb, NULL, values[i]->bv_val, values[i]->bv_len, true) < 0) {
681 talloc_free(vb);
682 RPERROR("Failed creating value from LDAP response");
683 break;
684 }
686 }
687 ldap_value_free_len(values);
688 }
689 }
690
691 talloc_free(query);
692
693 return XLAT_ACTION_DONE;
694}
695
696/** Callback for signalling async ldap query
697 *
698 */
699static void ldap_xlat_signal(xlat_ctx_t const *xctx, request_t *request, UNUSED fr_signal_t action)
700{
701 fr_ldap_query_t *query = talloc_get_type_abort(xctx->rctx, fr_ldap_query_t);
702 trunk_request_t *treq = query->treq;
703
704 if (!treq) return;
705
706 RDEBUG2("Forcefully cancelling pending LDAP query");
707
708 /*
709 * The LDAP query needs to persist until the trunk
710 * request cancellation is complete.
711 */
712 talloc_steal(treq, query);
713 query->treq = NULL;
714
716}
717
718/*
719 * If a part doesn't have an escaping function, parsing will fail unless the input
720 * was marked up with a safe_for value by the ldap arg parsing, i.e. was a literal
721 * input argument to the xlat.
722 *
723 * This is equivalent to the old "tainted_allowed" flag.
724 */
726 { .name = "scheme", .safe_for = LDAP_DN_SAFE_FOR, .terminals = &FR_SBUFF_TERMS(L(":")), .part_adv = { [':'] = 1 }, .extra_skip = 2 },
727 { .name = "host", .safe_for = LDAP_DN_SAFE_FOR, .terminals = &FR_SBUFF_TERMS(L(":"), L("/")), .part_adv = { [':'] = 1, ['/'] = 2 } },
728 { .name = "port", .safe_for = LDAP_DN_SAFE_FOR, .terminals = &FR_SBUFF_TERMS(L("/")), .part_adv = { ['/'] = 1 } },
729 { .name = "dn", .safe_for = LDAP_DN_SAFE_FOR, .terminals = &FR_SBUFF_TERMS(L("?")), .part_adv = { ['?'] = 1 }, .func = fr_ldap_dn_box_escape },
730 { .name = "attrs", .safe_for = LDAP_DN_SAFE_FOR, .terminals = &FR_SBUFF_TERMS(L("?")), .part_adv = { ['?'] = 1 }},
731 { .name = "scope", .safe_for = LDAP_DN_SAFE_FOR, .terminals = &FR_SBUFF_TERMS(L("?")), .part_adv = { ['?'] = 1 }, .func = fr_ldap_dn_box_escape },
732 { .name = "filter", .safe_for = LDAP_DN_SAFE_FOR, .terminals = &FR_SBUFF_TERMS(L("?")), .part_adv = { ['?'] = 1}, .func = fr_ldap_dn_box_escape },
733 { .name = "exts", .safe_for = LDAP_DN_SAFE_FOR, .func = fr_ldap_dn_box_escape },
735};
736
737static fr_uri_part_t const ldap_dn_parts[] = {
738 { .name = "dn", .safe_for = LDAP_DN_SAFE_FOR , .func = fr_ldap_dn_box_escape },
740};
741
743 { .required = true, .type = FR_TYPE_STRING, .safe_for = LDAP_DN_SAFE_FOR, .will_escape = true, },
745};
746
747/** Produce canonical LDAP host URI for finding trunks
748 *
749 */
750static inline CC_HINT(always_inline)
751char *host_uri_canonify(request_t *request, LDAPURLDesc *url_parsed, fr_value_box_t *url_in)
752{
753 char *host;
754
755 LDAPURLDesc tmp_desc = {
756 .lud_scheme = url_parsed->lud_scheme,
757 .lud_host = url_parsed->lud_host,
758 .lud_port = url_parsed->lud_port,
759 .lud_scope = -1
760 };
761 host = ldap_url_desc2str(&tmp_desc);
762 if (unlikely(host == NULL)) REDEBUG("Invalid LDAP URL - %pV", url_in); \
763
764 return host;
765}
766
767/** Utility function for parsing LDAP URLs
768 *
769 * All LDAP xlat functions that work with LDAP URLs should call this function to parse the URL.
770 *
771 * @param[out] uri_parsed LDAP URL parsed. Must be freed with ldap_url_desc_free.
772 * @param[out] host_out host name to use for the query. Must be freed with ldap_mem_free
773 * if free_host_out is true.
774 * @param[out] free_host_out True if host_out should be freed.
775 * @param[in] request Request being processed.
776 * @param[in] host_default Default host to use if the URL does not specify a host.
777 * @param[in] uri_in URI to parse.
778 * @return
779 * - 0 on success.
780 * - -1 on failure.
781 */
782static int ldap_xlat_uri_parse(LDAPURLDesc **uri_parsed, char **host_out, bool *free_host_out,
783 request_t *request, char *host_default, fr_value_box_t *uri_in)
784{
785 fr_value_box_t *uri;
786 int ldap_url_ret;
787
788 *free_host_out = false;
789
790 if (fr_uri_escape_list(&uri_in->vb_group, ldap_uri_parts, NULL) < 0){
791 RPERROR("Failed to escape LDAP URI");
792 error:
793 *uri_parsed = NULL;
794 return -1;
795 }
796
797 /*
798 * Smush everything into the first URI box
799 */
800 uri = fr_value_box_list_head(&uri_in->vb_group);
801
802 if (fr_value_box_list_concat_in_place(uri, uri, &uri_in->vb_group,
803 FR_TYPE_STRING, FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
804 RPEDEBUG("Failed concatenating input");
805 goto error;
806 }
807
808 if (!ldap_is_ldap_url(uri->vb_strvalue)) {
809 REDEBUG("String passed does not look like an LDAP URL");
810 goto error;
811 }
812
813 ldap_url_ret = ldap_url_parse(uri->vb_strvalue, uri_parsed);
814 if (ldap_url_ret != LDAP_URL_SUCCESS){
815 RPEDEBUG("Parsing LDAP URL failed - %s", fr_ldap_url_err_to_str(ldap_url_ret));
816 goto error;
817 }
818
819 /*
820 * If the URL is <scheme>:/// the parsed host will be NULL - use config default
821 */
822 if (!(*uri_parsed)->lud_host) {
823 *host_out = host_default;
824 } else {
825 *host_out = host_uri_canonify(request, *uri_parsed, uri);
826 if (unlikely(*host_out == NULL)) {
827 ldap_free_urldesc(*uri_parsed);
828 *uri_parsed = NULL;
829 return -1;
830 }
831 *free_host_out = true;
832 }
833
834 return 0;
835}
836
837/** Expand an LDAP URL into a query, and return a string result from that query.
838 *
839 * @ingroup xlat_functions
840 */
842 xlat_ctx_t const *xctx,
843 request_t *request, fr_value_box_list_t *in)
844{
845 fr_ldap_thread_t *t = talloc_get_type_abort(xctx->mctx->thread, fr_ldap_thread_t);
846 fr_value_box_t *uri;
847 char *host;
848 bool free_host = false;
849 fr_ldap_config_t const *handle_config = t->config;
851 fr_ldap_query_t *query = NULL;
852
853 LDAPURLDesc *ldap_url;
854
855 XLAT_ARGS(in, &uri);
856
857 if (ldap_xlat_uri_parse(&ldap_url, &host, &free_host, request, handle_config->server, uri) < 0) return XLAT_ACTION_FAIL;
858
859 /*
860 * Nothing, empty string, "*" string, or got 2 things, die.
861 */
862 if (!ldap_url->lud_attrs || !ldap_url->lud_attrs[0] || !*ldap_url->lud_attrs[0] ||
863 (strcmp(ldap_url->lud_attrs[0], "*") == 0) || ldap_url->lud_attrs[1]) {
864 REDEBUG("Bad attributes list in LDAP URL. URL must specify exactly one attribute to retrieve");
865 ldap_free_urldesc(ldap_url);
866 return XLAT_ACTION_FAIL;
867 }
868
870 ldap_url->lud_dn, ldap_url->lud_scope, ldap_url->lud_filter,
871 (char const * const*)ldap_url->lud_attrs, NULL, NULL);
872 query->ldap_url = ldap_url; /* query destructor will free URL */
873
874 if (ldap_url->lud_exts) {
875 LDAPControl *serverctrls[LDAP_MAX_CONTROLS];
876 int i;
877
878 serverctrls[0] = NULL;
879
880 if (fr_ldap_parse_url_extensions(serverctrls, NUM_ELEMENTS(serverctrls),
881 query->ldap_url->lud_exts) < 0) {
882 RPERROR("Parsing URL extensions failed");
883 if (free_host) ldap_memfree(host);
884
885 query_error:
886 talloc_free(query);
887 return XLAT_ACTION_FAIL;
888 }
889
890 for (i = 0; i < LDAP_MAX_CONTROLS; i++) {
891 if (!serverctrls[i]) break;
892 query->serverctrls[i].control = serverctrls[i];
893 query->serverctrls[i].freeit = true;
894 }
895 }
896
897 /*
898 * Figure out what trunked connection we can use
899 * to communicate with the host.
900 *
901 * If free_host is true, we must free the host
902 * after deciding on a trunk connection as it
903 * was allocated by host_uri_canonify.
904 */
905 ttrunk = fr_thread_ldap_trunk_get(t, host, handle_config->admin_identity,
906 handle_config->admin_password, request, handle_config);
907 if (free_host) ldap_memfree(host);
908 if (!ttrunk) {
909 REDEBUG("Unable to get LDAP query for xlat");
910 goto query_error;
911 }
912
913 switch (trunk_request_enqueue(&query->treq, ttrunk->trunk, request, query, NULL)) {
914 case TRUNK_ENQUEUE_OK:
916 break;
917
918 default:
919 REDEBUG("Unable to enqueue LDAP query for xlat");
920 goto query_error;
921 }
922
923 if (fr_timer_in(query, unlang_interpret_event_list(request)->tl, &query->ev, handle_config->res_timeout,
924 false, ldap_query_timeout, query) < 0) {
925 REDEBUG("Unable to set timeout for LDAP query");
927 goto query_error;
928 }
929
931}
932
933/** User object lookup as part of group membership xlat
934 *
935 * Called if the ldap membership xlat is used and the user DN is not already known
936 */
938{
939 ldap_group_xlat_ctx_t *xlat_ctx = talloc_get_type_abort(uctx, ldap_group_xlat_ctx_t);
940
941 if (xlat_ctx->env_data->user_filter.type == FR_TYPE_STRING) xlat_ctx->filter = &xlat_ctx->env_data->user_filter;
942
943 xlat_ctx->basedn = &xlat_ctx->env_data->user_base;
944
946 /* discard, this function is only used by xlats */NULL,
947 xlat_ctx->inst, request,
948 xlat_ctx->basedn, xlat_ctx->filter,
949 xlat_ctx->ttrunk, xlat_ctx->attrs, &xlat_ctx->query);
950}
951
952/** Cancel an in-progress query for the LDAP group membership xlat
953 *
954 */
955static void ldap_group_xlat_cancel(UNUSED request_t *request, UNUSED fr_signal_t action, void *uctx)
956{
957 ldap_group_xlat_ctx_t *xlat_ctx = talloc_get_type_abort(uctx, ldap_group_xlat_ctx_t);
958
959 if (!xlat_ctx->query || !xlat_ctx->query->treq) return;
960
962}
963
964#define REPEAT_LDAP_MEMBEROF_XLAT_RESULTS \
965 if (unlang_function_repeat_set(request, ldap_group_xlat_results) < 0) do { \
966 RETURN_UNLANG_FAIL; \
967 } while (0)
968
969/** Run the state machine for the LDAP membership xlat
970 *
971 * This is called after each async lookup is completed
972 *
973 * Will stop early, and set p_result to unlang_result
974 */
976{
977 ldap_group_xlat_ctx_t *xlat_ctx = talloc_get_type_abort(uctx, ldap_group_xlat_ctx_t);
978 rlm_ldap_t const *inst = xlat_ctx->inst;
979
980 /*
981 * Check to see if rlm_ldap_check_groupobj_dynamic or rlm_ldap_check_userobj_dynamic failed
982 */
984
985 switch (xlat_ctx->status) {
987 if (!xlat_ctx->dn) xlat_ctx->dn = rlm_find_user_dn_cached(inst, request);
989
990 RDEBUG3("Entered GROUP_XLAT_FIND_USER with user DN \"%s\"", xlat_ctx->dn);
991 if (inst->group.obj_membership_filter) {
993 RDEBUG3("Checking for user in group objects");
997 }
998 }
1000
1002 if (xlat_ctx->found) RETURN_UNLANG_OK;
1003
1004 RDEBUG3("Entered GROUP_XLAT_MEMB_FILTER with user DN \"%s\"", xlat_ctx->dn);
1005 if (inst->group.userobj_membership_attr) {
1010 }
1011 }
1013
1015 RDEBUG3("Entered GROUP_XLAT_MEMB_ATTR with user DN \"%s\"", xlat_ctx->dn);
1016 if (xlat_ctx->found) RETURN_UNLANG_OK;
1017 break;
1018 }
1019
1021}
1022
1023/** Process the results of evaluating LDAP group membership
1024 *
1025 */
1027 UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
1028{
1029 ldap_group_xlat_ctx_t *xlat_ctx = talloc_get_type_abort(xctx->rctx, ldap_group_xlat_ctx_t);
1030 fr_value_box_t *vb;
1031
1033 vb->vb_bool = xlat_ctx->found;
1035
1036 return XLAT_ACTION_DONE;
1037}
1038
1040 { .required = true, .concat = true, .type = FR_TYPE_STRING, .safe_for = LDAP_DN_SAFE_FOR },
1042};
1043
1044/** Check for a user being in a LDAP group
1045 *
1046 * @ingroup xlat_functions
1047 */
1048static xlat_action_t ldap_group_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx,
1049 request_t *request, fr_value_box_list_t *in)
1050{
1051 fr_value_box_t *vb = NULL, *group_vb = fr_value_box_list_pop_head(in);
1053 fr_ldap_thread_t *t = talloc_get_type_abort(xctx->mctx->thread, fr_ldap_thread_t);
1054 ldap_xlat_memberof_call_env_t *env_data = talloc_get_type_abort(xctx->env_data, ldap_xlat_memberof_call_env_t);
1055 bool group_is_dn;
1057
1058 RDEBUG2("Searching for user in group \"%pV\"", group_vb);
1059
1060 if (group_vb->vb_length == 0) {
1061 REDEBUG("Cannot do comparison (group name is empty)");
1062 return XLAT_ACTION_FAIL;
1063 }
1064
1065 group_is_dn = fr_ldap_util_is_dn(group_vb->vb_strvalue, group_vb->vb_length);
1066 if (group_is_dn) {
1067 char *norm;
1068 size_t len;
1069
1070 MEM(norm = talloc_array(group_vb, char, talloc_array_length(group_vb->vb_strvalue)));
1071 len = fr_ldap_util_normalise_dn(norm, group_vb->vb_strvalue);
1072
1073 /*
1074 * Will clear existing buffer (i.e. group_vb->vb_strvalue)
1075 */
1076 fr_value_box_bstrdup_buffer_shallow(group_vb, group_vb, NULL, norm, group_vb->tainted);
1077
1078 /*
1079 * Trim buffer to match normalised DN
1080 */
1081 fr_value_box_bstr_realloc(group_vb, NULL, group_vb, len);
1082 }
1083
1084 if ((group_is_dn && inst->group.cacheable_dn) || (!group_is_dn && inst->group.cacheable_name)) {
1085 unlang_result_t our_result;
1086
1087 rlm_ldap_check_cached(&our_result, inst, request, group_vb);
1088 switch (our_result.rcode) {
1090 RDEBUG2("User is not a member of \"%pV\"", group_vb);
1091 return XLAT_ACTION_DONE;
1092
1093 case RLM_MODULE_OK:
1094 MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_BOOL, NULL));
1095 vb->vb_bool = true;
1097 return XLAT_ACTION_DONE;
1098
1099 /*
1100 * Fallback to dynamic search
1101 */
1102 default:
1103 break;
1104 }
1105 }
1106
1108
1110 .inst = inst,
1111 .group = group_vb,
1112 .dn = rlm_find_user_dn_cached(inst, request),
1113 .attrs = { inst->group.userobj_membership_attr, NULL },
1114 .group_is_dn = group_is_dn,
1115 .env_data = env_data
1116 };
1117
1118 xlat_ctx->ttrunk = fr_thread_ldap_trunk_get(t, inst->handle_config.server, inst->handle_config.admin_identity,
1119 inst->handle_config.admin_password, request, &inst->handle_config);
1120
1121 if (!xlat_ctx->ttrunk) {
1122 REDEBUG("Unable to get LDAP trunk for group membership check");
1123 error:
1125 return XLAT_ACTION_FAIL;
1126 }
1127
1128 if (unlang_xlat_yield(request, ldap_group_xlat_resume, NULL, 0, xlat_ctx) != XLAT_ACTION_YIELD) goto error;
1129
1131 request,
1134 ldap_group_xlat_cancel, ~FR_SIGNAL_CANCEL,
1136 xlat_ctx) < 0) goto error;
1137
1139}
1140
1147
1148/** Return whether evaluating the profile was successful
1149 *
1150 */
1152 UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
1153{
1154 ldap_xlat_profile_ctx_t *xlat_ctx = talloc_get_type_abort(xctx->rctx, ldap_xlat_profile_ctx_t);
1155 fr_value_box_t *vb;
1156
1158 vb->vb_bool = (xlat_ctx->ret == LDAP_RESULT_SUCCESS) && (xlat_ctx->applied > 0);
1160
1161 return XLAT_ACTION_DONE;
1162}
1163
1165{
1166 if (to_free->url) {
1167 ldap_free_urldesc(to_free->url);
1168 to_free->url = NULL;
1169 }
1170 return 0;
1171}
1172
1173/** Expand an LDAP URL into a query, applying the results using the user update map.
1174 *
1175 * For fetching profiles by DN.
1176 *
1177 * @ingroup xlat_functions
1178 */
1180 xlat_ctx_t const *xctx,
1181 request_t *request, fr_value_box_list_t *in)
1182{
1184 fr_ldap_thread_t *t = talloc_get_type_abort(xctx->mctx->thread, fr_ldap_thread_t);
1185 ldap_xlat_profile_call_env_t *env_data = talloc_get_type_abort(xctx->env_data, ldap_xlat_profile_call_env_t);
1186 fr_value_box_t *uri_components, *uri;
1187 char *host_url, *host = NULL;
1188 fr_ldap_config_t const *handle_config = t->config;
1189 fr_ldap_thread_trunk_t *ttrunk;
1191
1192 int ldap_url_ret;
1193
1194 char const *dn;
1195 char const *filter;
1196 int scope;
1197
1198 bool is_dn;
1199
1200 XLAT_ARGS(in, &uri_components);
1201
1202 is_dn = (fr_uri_has_scheme(&uri_components->vb_group, ldap_uri_scheme_table, ldap_uri_scheme_table_len, -1) < 0);
1203
1204 /*
1205 * Apply different escaping rules based on whether the first
1206 * arg lookgs like a URI or a DN.
1207 */
1208 if (is_dn) {
1209 if (fr_uri_escape_list(&uri_components->vb_group, ldap_dn_parts, NULL) < 0) {
1210 RPERROR("Failed to escape LDAP profile DN");
1211 return XLAT_ACTION_FAIL;
1212 }
1213 } else {
1214 if (fr_uri_escape_list(&uri_components->vb_group, ldap_uri_parts, NULL) < 0) {
1215 RPERROR("Failed to escape LDAP profile URI");
1216 return XLAT_ACTION_FAIL;
1217 }
1218 }
1219
1220 /*
1221 * Smush everything into the first URI box
1222 */
1223 uri = fr_value_box_list_head(&uri_components->vb_group);
1224 if (fr_value_box_list_concat_in_place(uri, uri, &uri_components->vb_group,
1225 FR_TYPE_STRING, FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
1226 RPEDEBUG("Failed concatenating input");
1227 return XLAT_ACTION_FAIL;
1228 }
1229
1230 /*
1231 * Allocate a resumption context to store temporary resource and results
1232 */
1234 talloc_set_destructor(xlat_ctx, ldap_xlat_profile_ctx_free);
1235
1236 if (is_dn) {
1237 host_url = handle_config->server;
1238 dn = talloc_typed_strdup_buffer(xlat_ctx, uri->vb_strvalue);
1239 filter = env_data->profile_filter.vb_strvalue;
1240 scope = inst->profile.obj_scope;
1241 } else {
1242 ldap_url_ret = ldap_url_parse(uri->vb_strvalue, &xlat_ctx->url);
1243 if (ldap_url_ret != LDAP_URL_SUCCESS){
1244 RPEDEBUG("Parsing LDAP URL failed - %s", fr_ldap_url_err_to_str(ldap_url_ret));
1245 error:
1247 return XLAT_ACTION_FAIL;
1248 }
1249
1250 /*
1251 * The URL must specify a DN
1252 */
1253 if (!xlat_ctx->url->lud_dn) {
1254 REDEBUG("LDAP URI must specify a profile DN");
1255 goto error;
1256 }
1257
1258 dn = xlat_ctx->url->lud_dn;
1259 /*
1260 * Either we use the filter from the URL or we use the default filter
1261 * configured for profiles.
1262 */
1263 filter = xlat_ctx->url->lud_filter ? xlat_ctx->url->lud_filter : env_data->profile_filter.vb_strvalue;
1264
1265 /*
1266 * Determine if the URL includes a scope.
1267 */
1268 scope = xlat_ctx->url->lud_scope == LDAP_SCOPE_DEFAULT ? inst->profile.obj_scope : xlat_ctx->url->lud_scope;
1269
1270 /*
1271 * If the URL is <scheme>:/// the parsed host will be NULL - use config default
1272 */
1273 if (!xlat_ctx->url->lud_host) {
1274 host_url = handle_config->server;
1275 } else {
1276 host_url = host = host_uri_canonify(request, xlat_ctx->url, uri);
1277 if (unlikely(host_url == NULL)) goto error;
1278 }
1279 }
1280
1281 /*
1282 * Synchronous expansion of maps (fixme!)
1283 */
1284 if (fr_ldap_map_expand(xlat_ctx, &xlat_ctx->expanded, request, env_data->profile_map,
1285 inst->valuepair_attr, inst->profile.check_attr, inst->profile.fallthrough_attr) < 0) goto error;
1286 ttrunk = fr_thread_ldap_trunk_get(t, host_url, handle_config->admin_identity,
1287 handle_config->admin_password, request, handle_config);
1288 if (host) ldap_memfree(host);
1289 if (!ttrunk) {
1290 REDEBUG("Unable to get LDAP query for xlat");
1291 goto error;
1292 }
1293
1294 if (unlang_xlat_yield(request, ldap_profile_xlat_resume, NULL, 0, xlat_ctx) != XLAT_ACTION_YIELD) goto error;
1295
1296 /*
1297 * Pushes a frame onto the stack to retrieve and evaluate a profile
1298 */
1299 if (rlm_ldap_map_profile(&xlat_ctx->ret, &xlat_ctx->applied, inst, request, ttrunk, dn,
1300 scope, filter, &xlat_ctx->expanded) < 0) goto error;
1301
1303}
1304
1305/** State of an in progress whoami extended operation
1306 *
1307 */
1308typedef struct {
1309 fr_ldap_query_t *query; //!< Current query performing the whoami operation.
1311
1312/** Return the authorization identity from the whoami response
1313 *
1314 * @ingroup xlat_functions
1315 */
1317 request_t *request, UNUSED fr_value_box_list_t *in)
1318{
1319 ldap_xlat_whoami_ctx_t *xlat_ctx = talloc_get_type_abort(xctx->rctx, ldap_xlat_whoami_ctx_t);
1320 fr_ldap_query_t *query = xlat_ctx->query;
1321 fr_value_box_t *vb;
1322 struct berval *authz_id = NULL;
1323 char const *p;
1324 size_t len;
1325 int err;
1326
1327 if (query->ret != LDAP_RESULT_SUCCESS) {
1328 REDEBUG("Whoami extended operation failed");
1329 return XLAT_ACTION_FAIL;
1330 }
1331
1332 err = ldap_parse_extended_result(query->ldap_conn->handle, query->result, NULL, &authz_id, false);
1333 if (err != LDAP_SUCCESS) {
1334 REDEBUG("Failed parsing whoami response: %s", ldap_err2string(err));
1335 return XLAT_ACTION_FAIL;
1336 }
1337
1338 /*
1339 * An empty authzId means the connection is bound anonymously.
1340 */
1341 if (!authz_id || (authz_id->bv_len == 0)) {
1342 if (authz_id) ber_bvfree(authz_id);
1343 return XLAT_ACTION_DONE;
1344 }
1345
1346 /*
1347 * RFC 4532 returns an authzId (RFC 4513), "dn:<dn>" for
1348 * distinguished names. Strip the prefix, "u:<user>" forms
1349 * are returned unmodified.
1350 */
1351 p = authz_id->bv_val;
1352 len = authz_id->bv_len;
1353 if ((len >= 3) && (memcmp(p, "dn:", 3) == 0)) {
1354 p += 3;
1355 len -= 3;
1356 }
1357
1358 MEM(vb = fr_value_box_alloc_null(ctx));
1359 MEM(fr_value_box_bstrndup(vb, vb, NULL, p, len, false) == 0);
1361
1362 ber_bvfree(authz_id);
1363
1364 return XLAT_ACTION_DONE;
1365}
1366
1367/** Perform the RFC 4532 whoami extended operation
1368 *
1369 * Runs on the same connections as the module's queries, so the identity
1370 * returned is the one the directory resolved for the admin bind.
1371 *
1372 * @ingroup xlat_functions
1373 */
1375 xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in)
1376{
1377 fr_ldap_thread_t *t = talloc_get_type_abort(xctx->mctx->thread, fr_ldap_thread_t);
1378 fr_ldap_config_t const *handle_config = t->config;
1379 fr_ldap_thread_trunk_t *ttrunk;
1381
1382 ttrunk = fr_thread_ldap_trunk_get(t, handle_config->server, handle_config->admin_identity,
1383 handle_config->admin_password, request, handle_config);
1384 if (!ttrunk) {
1385 REDEBUG("Unable to get LDAP trunk for whoami");
1386 return XLAT_ACTION_FAIL;
1387 }
1388
1390
1392 error:
1394 return XLAT_ACTION_FAIL;
1395 }
1396
1397 if (fr_ldap_trunk_extended(xlat_ctx, &xlat_ctx->query, request, ttrunk,
1398 LDAP_EXOP_WHO_AM_I, NULL, NULL, NULL) != UNLANG_ACTION_PUSHED_CHILD) goto error;
1399
1401}
1402
1403/*
1404 * Verify the result of the map.
1405 */
1406static int ldap_map_verify(CONF_SECTION *cs, UNUSED void const *mod_inst, UNUSED void *proc_inst,
1407 tmpl_t const *src, UNUSED map_list_t const *maps)
1408{
1409 if (!src) {
1410 cf_log_err(cs, "Missing LDAP URI");
1411
1412 return -1;
1413 }
1414
1415 return 0;
1416}
1417
1418/** Process the results of an LDAP map query
1419 *
1420 * @param[out] p_result Result of map expansion:
1421 * - #RLM_MODULE_NOOP no rows were returned.
1422 * - #RLM_MODULE_UPDATED if one or more #fr_pair_t were added to the #request_t.
1423 * - #RLM_MODULE_FAIL if an error occurred.
1424 * @param[in] mpctx module map ctx.
1425 * @param[in,out] request The current request.
1426 * @param[in] url LDAP url specifying base DN and filter.
1427 * @param[in] maps Head of the map list.
1428 * @return One of UNLANG_ACTION_*
1429 */
1430static unlang_action_t mod_map_resume(unlang_result_t *p_result, map_ctx_t const *mpctx, request_t *request,
1431 UNUSED fr_value_box_list_t *url, UNUSED map_list_t const *maps)
1432{
1433 ldap_map_ctx_t *map_ctx = talloc_get_type_abort(mpctx->rctx, ldap_map_ctx_t);
1434 fr_ldap_query_t *query = map_ctx->query;
1435 fr_ldap_map_exp_t *expanded = &map_ctx->expanded;
1437 LDAPMessage *entry;
1438 map_t const *map;
1439
1440 switch (query->ret) {
1442 rcode = RLM_MODULE_UPDATED;
1443 break;
1444
1446 case LDAP_RESULT_BAD_DN:
1447 goto finish;
1448
1450 goto finish;
1451
1452 default:
1453 rcode = RLM_MODULE_FAIL;
1454 goto finish;
1455 }
1456
1457 for (entry = ldap_first_entry(query->ldap_conn->handle, query->result);
1458 entry;
1459 entry = ldap_next_entry(query->ldap_conn->handle, entry)) {
1460 char *dn = NULL;
1461 int i;
1462
1463 if (RDEBUG_ENABLED2) {
1464 dn = ldap_get_dn(query->ldap_conn->handle, entry);
1465 RDEBUG2("Processing \"%s\"", dn);
1466 }
1467
1468 RINDENT();
1469 for (map = map_list_head(map_ctx->maps), i = 0;
1470 map != NULL;
1471 map = map_list_next(map_ctx->maps, map), i++) {
1473 int ret, iter_err = 0;
1474
1475 if (!fr_ldap_value_iter_alloc(&iter_err, &iter, request, query->ldap_conn->handle, entry,
1476 expanded->attrs[i])) {
1477 talloc_free(iter);
1478 if (unlikely(iter_err < 0)) {
1479 RPERROR("Failed parsing entry");
1480 rcode = RLM_MODULE_FAIL;
1481 ldap_memfree(dn);
1482 goto finish;
1483 }
1484
1485 /*
1486 * Many LDAP directories don't expose the DN of
1487 * the object as an attribute, so we need this
1488 * hack, to allow the user to retrieve it.
1489 */
1490 if (strcmp(LDAP_VIRTUAL_DN_ATTR, expanded->attrs[i]) == 0) {
1491 if (!dn) dn = ldap_get_dn(query->ldap_conn->handle, entry);
1492
1493 ret = map_to_request(request, map, fr_ldap_map_getdn, dn);
1494 if (ret == -1) {
1495 rcode = RLM_MODULE_FAIL;
1496 ldap_memfree(dn);
1497 goto finish;
1498 }
1499 continue;
1500 }
1501
1502 RDEBUG3("Attribute \"%s\" not found in LDAP object", expanded->attrs[i]);
1503
1504 continue;
1505 }
1506
1507 ret = map_to_request(request, map, fr_ldap_map_getvalue, iter);
1508 talloc_free(iter);
1509 if (ret == -1) {
1510 rcode = RLM_MODULE_FAIL;
1511 ldap_memfree(dn);
1512 goto finish;
1513 }
1514 }
1515 ldap_memfree(dn);
1516 REXDENT();
1517 }
1518
1519finish:
1520 RETURN_UNLANG_RCODE(rcode);
1521}
1522
1523/** Ensure map context is properly cleared up
1524 *
1525 */
1527{
1528 int i = 0;
1529 talloc_free(map_ctx->expanded.ctx);
1530 ldap_free_urldesc(map_ctx->ldap_url);
1531 while ((i < LDAP_MAX_CONTROLS) && map_ctx->serverctrls[i]) {
1532 ldap_control_free(map_ctx->serverctrls[i]);
1533 i++;
1534 }
1535 return (0);
1536}
1537
1538/** Perform a search and map the result of the search to server attributes
1539 *
1540 * Unlike LDAP xlat, this can be used to process attributes from multiple entries.
1541 *
1542 * @todo For xlat expansions we need to parse the raw URL first, and then apply
1543 * different escape functions to the different parts.
1544 *
1545 * @param[out] p_result Result of map expansion:
1546 * - #RLM_MODULE_NOOP no rows were returned.
1547 * - #RLM_MODULE_UPDATED if one or more #fr_pair_t were added to the #request_t.
1548 * - #RLM_MODULE_FAIL if an error occurred.
1549 * @param[in] mpctx module map ctx.
1550 * @param[in,out] request The current request.
1551 * @param[in] url LDAP url specifying base DN and filter.
1552 * @param[in] maps Head of the map list.
1553 * @return UNLANG_ACTION_CALCULATE_RESULT
1554 */
1555static unlang_action_t mod_map_proc(unlang_result_t *p_result, map_ctx_t const *mpctx, request_t *request,
1556 fr_value_box_list_t *url, map_list_t const *maps)
1557{
1559 fr_ldap_thread_t *thread = talloc_get_type_abort(module_thread(inst->mi)->data, fr_ldap_thread_t);
1560
1561 LDAPURLDesc *ldap_url;
1562 int ldap_url_ret;
1563 fr_ldap_thread_trunk_t *ttrunk;
1564
1565 fr_value_box_t *url_head;
1567 char *host_url, *host = NULL;
1568
1569 if (fr_uri_escape_list(url, ldap_uri_parts, NULL) < 0) {
1570 RPERROR("Failed to escape LDAP map URI");
1572 }
1573
1574 url_head = fr_value_box_list_head(url);
1575 if (!url_head) {
1576 REDEBUG("LDAP URL cannot be empty");
1578 }
1579
1580 if (fr_value_box_list_concat_in_place(url_head, url_head, url, FR_TYPE_STRING,
1581 FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
1582 RPEDEBUG("Failed concatenating input");
1584 }
1585
1586 if (!ldap_is_ldap_url(url_head->vb_strvalue)) {
1587 REDEBUG("Map query string does not look like a valid LDAP URI");
1589 }
1590
1592 talloc_set_destructor(map_ctx, map_ctx_free);
1593 map_ctx->maps = maps;
1594
1595 ldap_url_ret = ldap_url_parse(url_head->vb_strvalue, &map_ctx->ldap_url);
1596 if (ldap_url_ret != LDAP_URL_SUCCESS){
1597 RPEDEBUG("Parsing LDAP URL failed - %s", fr_ldap_url_err_to_str(ldap_url_ret));
1598 fail:
1601 }
1602 ldap_url = map_ctx->ldap_url;
1603
1604 if (ldap_url->lud_exts) {
1605 if (fr_ldap_parse_url_extensions(map_ctx->serverctrls, NUM_ELEMENTS(map_ctx->serverctrls),
1606 ldap_url->lud_exts) < 0) {
1607 RPERROR("Parsing URL extensions failed");
1608 goto fail;
1609 }
1610 }
1611
1612 /*
1613 * Expand the RHS of the maps to get the name of the attributes.
1614 */
1615 if (fr_ldap_map_expand(map_ctx, &map_ctx->expanded, request, maps, NULL, NULL, NULL) < 0) goto fail;
1616
1617 /*
1618 * If the URL is <scheme>:/// the parsed host will be NULL - use config default
1619 */
1620 if (!ldap_url->lud_host) {
1621 host_url = inst->handle_config.server;
1622 } else {
1623 host_url = host = host_uri_canonify(request, ldap_url, url_head);
1624 if (unlikely(host_url == NULL)) goto fail;
1625 }
1626
1627 ttrunk = fr_thread_ldap_trunk_get(thread, host_url, inst->handle_config.admin_identity,
1628 inst->handle_config.admin_password, request, &inst->handle_config);
1629 if (host) ldap_memfree(host);
1630 if (!ttrunk) goto fail;
1631
1632 if (unlikely(unlang_map_yield(request, mod_map_resume, NULL, 0, map_ctx) != UNLANG_ACTION_YIELD)) goto fail;
1633
1634 return fr_ldap_trunk_search(map_ctx, &map_ctx->query, request, ttrunk, ldap_url->lud_dn,
1635 ldap_url->lud_scope, ldap_url->lud_filter, map_ctx->expanded.attrs,
1636 map_ctx->serverctrls, NULL);
1637}
1638
1639static unlang_action_t CC_HINT(nonnull) mod_authenticate(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1640{
1642 fr_ldap_thread_t *thread = talloc_get_type_abort(module_thread(inst->mi)->data, fr_ldap_thread_t);
1643 ldap_auth_ctx_t *auth_ctx;
1644 ldap_auth_call_env_t *call_env = talloc_get_type_abort(mctx->env_data, ldap_auth_call_env_t);
1645
1646 if (call_env->password.type != FR_TYPE_STRING) {
1647 RWDEBUG("You have set \"Auth-Type := LDAP\" somewhere");
1648 RWDEBUG("without checking if %s is present", call_env->password_tmpl->name);
1649 RWDEBUG("*********************************************");
1650 RWDEBUG("* THAT CONFIGURATION IS WRONG. DELETE IT. ");
1651 RWDEBUG("* YOU ARE PREVENTING THE SERVER FROM WORKING");
1652 RWDEBUG("*********************************************");
1653
1654 REDEBUG("Attribute \"%s\" is required for authentication", call_env->password_tmpl->name);
1656 }
1657
1658 auth_ctx = talloc(unlang_interpret_frame_talloc_ctx(request), ldap_auth_ctx_t);
1659 *auth_ctx = (ldap_auth_ctx_t){
1660 .password = call_env->password.vb_strvalue,
1661 .thread = thread,
1662 .inst = inst,
1663 .call_env = call_env
1664 };
1665
1666 /*
1667 * Find the user's DN
1668 */
1669 auth_ctx->dn = rlm_find_user_dn_cached(inst, request);
1670
1671 /*
1672 * The DN is required for non-SASL auth
1673 */
1674 if (!auth_ctx->dn && (call_env->user_sasl_mech.type != FR_TYPE_STRING)) {
1675 REDEBUG("No DN found for authentication. Populate control.%s with the DN to use in authentication.",
1676 inst->user.da->name);
1677 REDEBUG("You should call %s in the recv section and check its return.", inst->mi->name);
1678 talloc_free(auth_ctx);
1680 }
1681
1682 /*
1683 * Log the password
1684 */
1685 if (RDEBUG_ENABLED3) {
1686 RDEBUG("Login attempt with password \"%pV\"", &call_env->password);
1687 } else {
1688 RDEBUG2("Login attempt with password");
1689 }
1690
1691 /*
1692 * SASL bind auth will have the mech set.
1693 */
1694 if (auth_ctx->call_env->user_sasl_mech.type == FR_TYPE_STRING) {
1695#ifdef WITH_SASL
1696 RDEBUG2("Login attempt using identity \"%pV\"", &call_env->user_sasl_authname);
1697
1698 return fr_ldap_sasl_bind_auth_async(p_result, request, auth_ctx->thread, call_env->user_sasl_mech.vb_strvalue,
1699 call_env->user_sasl_authname.vb_strvalue,
1700 auth_ctx->password, call_env->user_sasl_proxy.vb_strvalue,
1701 call_env->user_sasl_realm.vb_strvalue);
1702#else
1703 RDEBUG("Configuration item 'sasl.mech' is not supported. "
1704 "The linked version of libldap does not provide ldap_sasl_bind( function");
1706#endif
1707 }
1708
1709 RDEBUG2("Login attempt as \"%s\"", auth_ctx->dn);
1710
1711 return fr_ldap_bind_auth_async(p_result, request, auth_ctx->thread, auth_ctx->dn, auth_ctx->password);
1712}
1713
1714/** Remove duplicate DNs from a NULL terminated list, keeping the first occurrence
1715 *
1716 * A profile referenced by both a group object and the user object must
1717 * only be applied once.
1718 */
1719static void profile_dn_list_dedupe(char const **dn_list)
1720{
1721 int i, j, n;
1722
1723 for (n = 0; dn_list[n]; n++);
1724
1725 for (i = 1; i < n; i++) {
1726 for (j = 0; j < i; j++) {
1727 if (strcasecmp(dn_list[i], dn_list[j]) != 0) continue;
1728
1729 memmove(&dn_list[i], &dn_list[i + 1], (n - i) * sizeof(dn_list[0]));
1730 n--;
1731 i--;
1732 break;
1733 }
1734 }
1735}
1736
1737#define REPEAT_MOD_AUTHORIZE_RESUME \
1738 if (unlang_module_yield(request, mod_authorize_resume, NULL, 0, autz_ctx) == UNLANG_ACTION_FAIL) do { \
1739 p_result->rcode = RLM_MODULE_FAIL; \
1740 goto finish; \
1741 } while (0)
1742
1743/** Resume function called after each potential yield in LDAP authorization
1744 *
1745 * Some operations may or may not yield. E.g. if group membership is
1746 * read from an attribute returned with the user object and is already
1747 * in the correct form, that will not yield.
1748 * Hence, each state may fall through to the next.
1749 *
1750 * @param p_result Result of current authorization.
1751 * @param mctx Module context.
1752 * @param request Current request.
1753 * @return An rcode.
1754 */
1756{
1757 ldap_autz_ctx_t *autz_ctx = talloc_get_type_abort(mctx->rctx, ldap_autz_ctx_t);
1759 ldap_autz_call_env_t *call_env = talloc_get_type_abort(autz_ctx->call_env, ldap_autz_call_env_t);
1760 int ldap_errno;
1761 LDAP *handle = fr_ldap_handle_thread_local();
1763
1764 /*
1765 * If a previous async call returned one of the "failure" results just return.
1766 */
1767 switch (p_result->rcode) {
1768 case RLM_MODULE_REJECT:
1769 case RLM_MODULE_FAIL:
1770 case RLM_MODULE_HANDLED:
1771 case RLM_MODULE_INVALID:
1773 goto finish;
1774
1775 default:
1776 break;
1777 }
1778
1779 switch (autz_ctx->status) {
1780 case LDAP_AUTZ_FIND:
1781 /*
1782 * If a user entry has been found the current rcode will be OK
1783 */
1784 if (p_result->rcode != RLM_MODULE_OK) return UNLANG_ACTION_CALCULATE_RESULT;
1785
1786 autz_ctx->entry = ldap_first_entry(handle, autz_ctx->query->result);
1787 if (!autz_ctx->entry) {
1788 ldap_get_option(handle, LDAP_OPT_RESULT_CODE, &ldap_errno);
1789 REDEBUG("Failed retrieving entry: %s", ldap_err2string(ldap_errno));
1790
1791 goto finish;
1792 }
1793
1794 /*
1795 * Check for access.
1796 */
1797 if (inst->user.obj_access_attr) {
1798 autz_ctx->access_state = rlm_ldap_check_access(inst, request, autz_ctx->entry);
1799 switch (autz_ctx->access_state) {
1801 break;
1802
1804 if (inst->group.skip_on_suspend) goto post_group;
1805 break;
1806
1808 p_result->rcode = RLM_MODULE_DISALLOW;
1809 goto finish;
1810 }
1811 }
1812
1813 /*
1814 * Check if we need to cache group memberships,
1815 * or record group DNs for the group profile search.
1816 */
1817 if ((inst->group.cacheable_dn || inst->group.cacheable_name ||
1818 rlm_ldap_profile_attr_select(inst->group.profile_attr, inst->group.profile_attr_suspend,
1819 autz_ctx->access_state)) &&
1820 (inst->group.userobj_membership_attr)) {
1822 if (rlm_ldap_cacheable_userobj(p_result, request, autz_ctx,
1823 inst->group.userobj_membership_attr) == UNLANG_ACTION_PUSHED_CHILD) {
1824 autz_ctx->status = LDAP_AUTZ_GROUP;
1826 }
1827 if (p_result->rcode != RLM_MODULE_OK) goto finish;
1828 }
1830
1831 case LDAP_AUTZ_GROUP:
1832 if (inst->group.cacheable_dn || inst->group.cacheable_name ||
1833 rlm_ldap_profile_attr_select(inst->group.profile_attr, inst->group.profile_attr_suspend,
1834 autz_ctx->access_state)) {
1836 if (rlm_ldap_cacheable_groupobj(p_result, request, autz_ctx) == UNLANG_ACTION_PUSHED_CHILD) {
1837 autz_ctx->status = LDAP_AUTZ_GROUP_PROFILES;
1839 }
1840 if (p_result->rcode != RLM_MODULE_OK) goto finish;
1841 }
1843
1845 if (rlm_ldap_profile_attr_select(inst->group.profile_attr, inst->group.profile_attr_suspend,
1846 autz_ctx->access_state) &&
1847 autz_ctx->group_dn_list && (talloc_str_list_num(autz_ctx->group_dn_list) > 0)) {
1849 if (rlm_ldap_group_profiles(p_result, request, autz_ctx) == UNLANG_ACTION_PUSHED_CHILD) {
1850 autz_ctx->status = LDAP_AUTZ_POST_GROUP;
1852 }
1853 if (p_result->rcode != RLM_MODULE_OK) goto finish;
1854 }
1856
1858 post_group:
1859#ifdef WITH_EDIR
1860 /*
1861 * We already have a Password.Cleartext. Skip edir.
1862 */
1863 if (fr_pair_find_by_da_nested(&request->control_pairs, attr_cleartext_password)) goto skip_edir;
1864
1865 /*
1866 * Retrieve Universal Password if we use eDirectory
1867 */
1868 if (inst->edir) {
1869 autz_ctx->dn = rlm_find_user_dn_cached(inst, request);
1870
1871 /*
1872 * Retrieve universal password
1873 */
1875 autz_ctx->status = LDAP_AUTZ_EDIR_BIND;
1876 return fr_ldap_edir_get_password(p_result, request, autz_ctx->dn, autz_ctx->ttrunk,
1878 }
1880
1881 case LDAP_AUTZ_EDIR_BIND:
1882 if (inst->edir && inst->edir_autz) {
1883 fr_pair_t *password = fr_pair_find_by_da(&request->control_pairs,
1885 fr_ldap_thread_t *thread = talloc_get_type_abort(module_thread(inst->mi)->data,
1887
1888 if (!password) {
1889 REDEBUG("Failed to find control.Password.Cleartext");
1890 p_result->rcode = RLM_MODULE_FAIL;
1891 goto finish;
1892 }
1893
1894 RDEBUG2("Binding as %s for eDirectory authorization checks", autz_ctx->dn);
1895
1896 /*
1897 * Bind as the user
1898 */
1900 autz_ctx->status = LDAP_AUTZ_POST_EDIR;
1901 return fr_ldap_bind_auth_async(p_result, request, thread, autz_ctx->dn, password->vp_strvalue);
1902 }
1903 goto skip_edir;
1904
1905 case LDAP_AUTZ_POST_EDIR:
1906 {
1907 /*
1908 * The result of the eDirectory user bind will be in p_result.
1909 * Anything other than RLM_MODULE_OK is a failure.
1910 */
1911 break;
1912
1913 }
1914#endif
1915 case LDAP_AUTZ_MAP:
1916#ifdef WITH_EDIR
1917 skip_edir:
1918#endif
1919 if (!map_list_empty(call_env->user_map) || inst->valuepair_attr) {
1920 RDEBUG2("Processing user attributes");
1921 RINDENT();
1922 if (fr_ldap_map_do(request, NULL, inst->valuepair_attr,
1923 &autz_ctx->expanded, autz_ctx->entry) > 0) autz_ctx->rcode = RLM_MODULE_UPDATED;
1924 REXDENT();
1925 rlm_ldap_check_reply(request, inst, autz_ctx->dlinst->name, call_env->expect_password->vb_bool, autz_ctx->ttrunk);
1926 }
1928
1929 case LDAP_AUTZ_PROFILES:
1930 {
1931 talloc_str_list_t *list;
1932 char const *profile_attr;
1933 char const **dn_p;
1934 bool have_default = !fr_box_is_null(&call_env->default_profile);
1935 size_t count = 0, strings_len = 0, group_count = 0, i;
1936
1937 /*
1938 * Which set of profiles to apply depends on the user's
1939 * access state. The default profile always applies.
1940 */
1941 profile_attr = rlm_ldap_profile_attr_select(inst->user.profile_attr, inst->user.profile_attr_suspend,
1942 autz_ctx->access_state);
1943 if (profile_attr) {
1944 if (unlikely(fr_ldap_result_values_len(&count, &strings_len, handle,
1945 autz_ctx->query->result, profile_attr) < 0)) {
1946 RPERROR("Failed parsing user object");
1947 p_result->rcode = RLM_MODULE_FAIL;
1948 goto finish;
1949 }
1950 if (count > 0) {
1951 RDEBUG2("Processing %zu profile(s) found in attribute \"%s\"", count, profile_attr);
1952 } else {
1953 RDEBUG2("No profile(s) found in attribute \"%s\"", profile_attr);
1954 }
1955 }
1956
1957 if (autz_ctx->group_profile_dn_list) {
1958 group_count = talloc_str_list_num(autz_ctx->group_profile_dn_list);
1959 RDEBUG2("Processing %zu profile(s) found in group objects", group_count);
1960 }
1961
1962 if (!have_default && (group_count == 0) && (count == 0)) break;
1963
1964 /*
1965 * Build the list of profile DNs to apply, the default
1966 * profile first, then the profiles from the group
1967 * objects, then the profiles from the user object.
1968 */
1969 MEM(list = fr_ldap_str_list_afrom_result(autz_ctx, handle, autz_ctx->query->result,
1970 count ? profile_attr : NULL,
1971 (have_default ? 1 : 0) + group_count));
1972 dn_p = list->strings;
1973 if (have_default) *dn_p++ = call_env->default_profile.vb_strvalue;
1974 for (i = 0; i < group_count; i++) *dn_p++ = autz_ctx->group_profile_dn_list->strings[i];
1975
1976 /*
1977 * Evaluate the child object below each profile instead
1978 * of the profile itself.
1979 */
1980 if (!fr_box_is_null(&call_env->profile_child_rdn) && (call_env->profile_child_rdn.vb_length > 0)) {
1981 for (dn_p = list->strings; *dn_p; dn_p++) {
1982 MEM(*dn_p = talloc_asprintf(list, "%s,%s",
1983 call_env->profile_child_rdn.vb_strvalue, *dn_p));
1984 }
1985 }
1986
1987 autz_ctx->profile_dn_list = list->strings;
1989
1990 if (!autz_ctx->profile_dn_list[0]) break;
1991
1992 if (RDEBUG_ENABLED3) {
1993 for (dn_p = autz_ctx->profile_dn_list; *dn_p; dn_p++) {
1994 RDEBUG3("Will evaluate profile with DN \"%s\"", *dn_p);
1995 }
1996 }
1997
1999 ret = rlm_ldap_map_profiles(NULL, &autz_ctx->profiles_applied, inst, request, autz_ctx->ttrunk,
2000 autz_ctx->profile_dn_list, call_env->profile_filter.vb_strvalue,
2001 &autz_ctx->expanded);
2002 switch (ret) {
2003 case UNLANG_ACTION_FAIL:
2004 p_result->rcode = RLM_MODULE_FAIL;
2005 goto finish;
2006
2008 autz_ctx->status = LDAP_AUTZ_POST_PROFILES;
2010
2011 default:
2012 break;
2013 }
2014 }
2016
2018 if (autz_ctx->profiles_applied > 0) autz_ctx->rcode = RLM_MODULE_UPDATED;
2019 break;
2020 }
2021
2022 p_result->rcode = autz_ctx->rcode;
2023
2024finish:
2025 return ret;
2026}
2027
2028/** Clear up when cancelling a mod_authorize call
2029 *
2030 */
2031static void mod_authorize_cancel(module_ctx_t const *mctx, UNUSED request_t *request, UNUSED fr_signal_t action)
2032{
2033 ldap_autz_ctx_t *autz_ctx = talloc_get_type_abort(mctx->rctx, ldap_autz_ctx_t);
2034
2035 if (autz_ctx->query && autz_ctx->query->treq) trunk_request_signal_cancel(autz_ctx->query->treq);
2036}
2037
2038/** Ensure authorization context is properly cleared up
2039 *
2040 */
2041static int autz_ctx_free(ldap_autz_ctx_t *autz_ctx)
2042{
2043 talloc_free(autz_ctx->expanded.ctx);
2044 return 0;
2045}
2046
2047static unlang_action_t CC_HINT(nonnull) mod_authorize(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
2048{
2050 fr_ldap_thread_t *thread = talloc_get_type_abort(module_thread(inst->mi)->data, fr_ldap_thread_t);
2051 ldap_autz_ctx_t *autz_ctx;
2052 fr_ldap_map_exp_t *expanded;
2053 ldap_autz_call_env_t *call_env = talloc_get_type_abort(mctx->env_data, ldap_autz_call_env_t);
2054
2055 MEM(autz_ctx = talloc_zero(unlang_interpret_frame_talloc_ctx(request), ldap_autz_ctx_t));
2056 talloc_set_destructor(autz_ctx, autz_ctx_free);
2057 expanded = &autz_ctx->expanded;
2058
2059 /*
2060 * Don't be tempted to add a check for User-Name or
2061 * User-Password here. LDAP authorization can be used
2062 * for many things besides searching for users.
2063 */
2064 if (fr_ldap_map_expand(autz_ctx, expanded, request, call_env->user_map, inst->valuepair_attr,
2065 inst->profile.check_attr, inst->profile.fallthrough_attr) < 0) {
2066 fail:
2067 talloc_free(autz_ctx);
2069 }
2070
2071 autz_ctx->ttrunk = fr_thread_ldap_trunk_get(thread, inst->handle_config.server, inst->handle_config.admin_identity,
2072 inst->handle_config.admin_password, request, &inst->handle_config);
2073 if (!autz_ctx->ttrunk) goto fail;
2074
2075#define CHECK_EXPANDED_SPACE(_expanded) fr_assert((size_t)_expanded->count < (NUM_ELEMENTS(_expanded->attrs) - 1));
2076
2077 /*
2078 * Add any additional attributes we need for checking access, memberships, and profiles
2079 */
2080 if (inst->user.obj_access_attr) {
2081 CHECK_EXPANDED_SPACE(expanded);
2082 expanded->attrs[expanded->count++] = inst->user.obj_access_attr;
2083 }
2084
2085 if (inst->group.userobj_membership_attr &&
2086 (inst->group.cacheable_dn || inst->group.cacheable_name ||
2087 inst->group.profile_attr || inst->group.profile_attr_suspend)) {
2088 CHECK_EXPANDED_SPACE(expanded);
2089 expanded->attrs[expanded->count++] = inst->group.userobj_membership_attr;
2090 }
2091
2092 if (inst->user.profile_attr) {
2093 CHECK_EXPANDED_SPACE(expanded);
2094 expanded->attrs[expanded->count++] = inst->user.profile_attr;
2095 }
2096
2097 if (inst->user.profile_attr_suspend) {
2098 CHECK_EXPANDED_SPACE(expanded);
2099 expanded->attrs[expanded->count++] = inst->user.profile_attr_suspend;
2100 }
2101 expanded->attrs[expanded->count] = NULL;
2102
2103 autz_ctx->dlinst = mctx->mi;
2104 autz_ctx->inst = inst;
2105 autz_ctx->call_env = call_env;
2106 autz_ctx->status = LDAP_AUTZ_FIND;
2107 autz_ctx->rcode = RLM_MODULE_OK;
2108
2109 if (unlikely(unlang_module_yield(request,
2112 autz_ctx) == UNLANG_ACTION_FAIL)) {
2113 talloc_free(autz_ctx);
2115 }
2116
2117 return rlm_ldap_find_user_async(autz_ctx, p_result,
2118 autz_ctx->inst, request, &autz_ctx->call_env->user_base,
2119 &autz_ctx->call_env->user_filter, autz_ctx->ttrunk, autz_ctx->expanded.attrs,
2120 &autz_ctx->query);
2121}
2122
2123/** Cancel an in progress user modification.
2124 *
2125 */
2126static void user_modify_cancel(module_ctx_t const *mctx, UNUSED request_t *request, UNUSED fr_signal_t action)
2127{
2128 ldap_user_modify_ctx_t *usermod_ctx = talloc_get_type_abort(mctx->rctx, ldap_user_modify_ctx_t);
2129
2130 if (!usermod_ctx->query || !usermod_ctx->query->treq) return;
2131
2132 trunk_request_signal_cancel(usermod_ctx->query->treq);
2133}
2134
2135/** Handle results of user modification.
2136 *
2137 */
2138static unlang_action_t CC_HINT(nonnull) user_modify_final(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
2139{
2140 ldap_user_modify_ctx_t *usermod_ctx = talloc_get_type_abort(mctx->rctx, ldap_user_modify_ctx_t);
2141 fr_ldap_query_t *query = usermod_ctx->query;
2142 rlm_rcode_t rcode = RLM_MODULE_OK;
2143
2144 switch (query->ret) {
2146 break;
2147
2149 case LDAP_RESULT_BAD_DN:
2150 RDEBUG2("User object \"%s\" not modified", usermod_ctx->dn);
2151 rcode = RLM_MODULE_INVALID;
2152 break;
2153
2155 rcode = RLM_MODULE_TIMEOUT;
2156 break;
2157
2158 default:
2159 rcode = RLM_MODULE_FAIL;
2160 break;
2161 }
2162
2163 talloc_free(usermod_ctx);
2164 RETURN_UNLANG_RCODE(rcode);
2165}
2166
2168{
2169 ldap_user_modify_ctx_t *usermod_ctx = talloc_get_type_abort(mctx->rctx, ldap_user_modify_ctx_t);
2170 ldap_usermod_call_env_t *call_env = usermod_ctx->call_env;
2171 LDAPMod **modify;
2172 ldap_mod_tmpl_t *mod;
2173 fr_value_box_t *vb = NULL;
2174 int mod_no = usermod_ctx->expanded_mods, i = 0;
2175 struct berval **value_refs;
2176 struct berval *values;
2177
2178 mod = call_env->mod[usermod_ctx->current_mod];
2179
2180 /*
2181 * If the tmpl produced no boxes, skip
2182 */
2183 if ((mod->op != T_OP_CMP_FALSE) && (fr_value_box_list_num_elements(&usermod_ctx->expanded) == 0)) {
2184 RDEBUG2("Expansion \"%s\" produced no value, skipping attribute \"%s\"", mod->tmpl->name, mod->attr);
2185 goto next;
2186 }
2187
2188 switch (mod->op) {
2189 /*
2190 * T_OP_EQ is *NOT* supported, it is impossible to
2191 * support because of the lack of transactions in LDAP
2192 *
2193 * To allow for binary data, all data is provided as berval which
2194 * requires the operation to be logical ORed with LDAP_MOD_BVALUES
2195 */
2196 case T_OP_ADD_EQ:
2197 usermod_ctx->mod_s[mod_no].mod_op = LDAP_MOD_ADD | LDAP_MOD_BVALUES;
2198 break;
2199
2200 case T_OP_SET:
2201 usermod_ctx->mod_s[mod_no].mod_op = LDAP_MOD_REPLACE | LDAP_MOD_BVALUES;
2202 break;
2203
2204 case T_OP_SUB_EQ:
2205 case T_OP_CMP_FALSE:
2206 usermod_ctx->mod_s[mod_no].mod_op = LDAP_MOD_DELETE | LDAP_MOD_BVALUES;
2207 break;
2208
2209 case T_OP_INCRM:
2210 usermod_ctx->mod_s[mod_no].mod_op = LDAP_MOD_INCREMENT | LDAP_MOD_BVALUES;
2211 break;
2212
2213 default:
2214 REDEBUG("Operator '%s' is not supported for LDAP modify operations",
2215 fr_table_str_by_value(fr_tokens_table, mod->op, "<INVALID>"));
2216
2218 }
2219
2220 if (mod->op == T_OP_CMP_FALSE) {
2221 MEM(value_refs = talloc_zero_array(usermod_ctx, struct berval *, 1));
2222 } else {
2223 MEM(value_refs = talloc_zero_array(usermod_ctx, struct berval *,
2224 fr_value_box_list_num_elements(&usermod_ctx->expanded) + 1));
2225 MEM(values = talloc_zero_array(usermod_ctx, struct berval,
2226 fr_value_box_list_num_elements(&usermod_ctx->expanded)));
2227 while ((vb = fr_value_box_list_pop_head(&usermod_ctx->expanded))) {
2228 switch (vb->type) {
2229 case FR_TYPE_OCTETS:
2230 if (vb->vb_length == 0) continue;
2231 memcpy(&values[i].bv_val, &vb->vb_octets, sizeof(values[i].bv_val));
2232 values[i].bv_len = vb->vb_length;
2233 break;
2234
2235 case FR_TYPE_STRING:
2236 populate_string:
2237 if (vb->vb_length == 0) continue;
2238 memcpy(&values[i].bv_val, &vb->vb_strvalue, sizeof(values[i].bv_val));
2239 values[i].bv_len = vb->vb_length;
2240 break;
2241
2242 case FR_TYPE_GROUP:
2243 {
2244 fr_value_box_t *vb_head = fr_value_box_list_head(&vb->vb_group);
2245 if (fr_value_box_list_concat_in_place(vb_head, vb_head, &vb->vb_group, FR_TYPE_STRING,
2246 FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
2247 RPEDEBUG("Failed concatenating update value");
2249 }
2250 vb = vb_head;
2251 goto populate_string;
2252 }
2253
2254 case FR_TYPE_FIXED_SIZE:
2255 if (fr_value_box_cast_in_place(vb, vb, FR_TYPE_STRING, NULL) < 0) {
2256 RPEDEBUG("Failed casting update value");
2258 }
2259 goto populate_string;
2260
2261 default:
2262 fr_assert(0);
2263
2264 }
2265 value_refs[i] = &values[i];
2266 i++;
2267 }
2268 if (i == 0) {
2269 RDEBUG2("Expansion \"%s\" produced zero length value, skipping attribute \"%s\"", mod->tmpl->name, mod->attr);
2270 goto next;
2271 }
2272 }
2273
2274 /*
2275 * Now everything is evaluated, set up the pointers for the LDAPMod
2276 */
2277 memcpy(&(usermod_ctx->mod_s[mod_no].mod_type), &mod->attr, sizeof(usermod_ctx->mod_s[mod_no].mod_type));
2278 usermod_ctx->mod_s[mod_no].mod_bvalues = value_refs;
2279 usermod_ctx->mod_p[mod_no] = &usermod_ctx->mod_s[mod_no];
2280
2281 usermod_ctx->expanded_mods++;
2282 usermod_ctx->mod_p[usermod_ctx->expanded_mods] = NULL;
2283
2284next:
2285 usermod_ctx->current_mod++;
2286
2287 /*
2288 * Keep calling until we've completed all the modifications
2289 */
2290 if (usermod_ctx->current_mod < usermod_ctx->num_mods) {
2292 if (unlang_tmpl_push(usermod_ctx, NULL, &usermod_ctx->expanded, request,
2293 usermod_ctx->call_env->mod[usermod_ctx->current_mod]->tmpl, NULL, UNLANG_SUB_FRAME) < 0) RETURN_UNLANG_FAIL;
2295 }
2296
2297 modify = usermod_ctx->mod_p;
2298
2300
2301 return fr_ldap_trunk_modify(usermod_ctx, &usermod_ctx->query, request, usermod_ctx->ttrunk,
2302 usermod_ctx->dn, modify, NULL, NULL);
2303}
2304
2305/** Take the retrieved user DN and launch the async tmpl expansion of mod_values.
2306 *
2307 */
2308static unlang_action_t CC_HINT(nonnull) user_modify_resume(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
2309{
2310 ldap_user_modify_ctx_t *usermod_ctx = talloc_get_type_abort(mctx->rctx, ldap_user_modify_ctx_t);
2311
2312 /*
2313 * If an LDAP search was used to find the user DN
2314 * usermod_ctx->dn will be NULL.
2315 */
2316 if (!usermod_ctx->dn) usermod_ctx->dn = rlm_find_user_dn_cached(mctx->mi->data, request);
2317
2318 if (!usermod_ctx->dn) {
2319 fail:
2320 talloc_free(usermod_ctx);
2322 }
2323
2324 /*
2325 * Allocate arrays to hold mods. mod_p is one element longer to hold a terminating NULL entry
2326 */
2327 MEM(usermod_ctx->mod_p = talloc_zero_array(usermod_ctx, LDAPMod *, usermod_ctx->num_mods + 1));
2328 MEM(usermod_ctx->mod_s = talloc_array(usermod_ctx, LDAPMod, usermod_ctx->num_mods));
2329 fr_value_box_list_init(&usermod_ctx->expanded);
2330
2331 if (unlang_module_yield(request, user_modify_mod_build_resume, NULL, 0, usermod_ctx) == UNLANG_ACTION_FAIL) goto fail;
2332;
2333 if (unlang_tmpl_push(usermod_ctx, NULL, &usermod_ctx->expanded, request,
2334 usermod_ctx->call_env->mod[0]->tmpl, NULL, UNLANG_SUB_FRAME) < 0) goto fail;
2335
2337}
2338
2339/** Modify user's object in LDAP
2340 *
2341 * Process a modification map to update a user object in the LDAP directory.
2342 *
2343 * The module method called in "accouting" and "send" sections.
2344 */
2345static unlang_action_t CC_HINT(nonnull) mod_modify(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
2346{
2348 ldap_usermod_call_env_t *call_env = talloc_get_type_abort(mctx->env_data, ldap_usermod_call_env_t);
2349 fr_ldap_thread_t *thread = talloc_get_type_abort(module_thread(inst->mi)->data, fr_ldap_thread_t);
2350 ldap_user_modify_ctx_t *usermod_ctx = NULL;
2351
2352 size_t num_mods = talloc_array_length(call_env->mod);
2353
2354 if (num_mods == 0) RETURN_UNLANG_NOOP;
2355
2356 /*
2357 * Include a talloc pool allowing for one value per modification
2358 */
2360 2 * num_mods + 2,
2361 (sizeof(struct berval) + (sizeof(struct berval *) * 2) +
2362 (sizeof(LDAPMod) + sizeof(LDAPMod *))) * num_mods));
2363 *usermod_ctx = (ldap_user_modify_ctx_t) {
2364 .inst = inst,
2365 .call_env = call_env,
2366 .num_mods = num_mods
2367 };
2368
2369 usermod_ctx->ttrunk = fr_thread_ldap_trunk_get(thread, inst->handle_config.server,
2370 inst->handle_config.admin_identity,
2371 inst->handle_config.admin_password,
2372 request, &inst->handle_config);
2373 if (!usermod_ctx->ttrunk) {
2374 REDEBUG("Unable to get LDAP trunk for update");
2375 talloc_free(usermod_ctx);
2377 }
2378
2379 usermod_ctx->dn = rlm_find_user_dn_cached(inst, request);
2380 /*
2381 * Find the user first
2382 */
2383 if (!usermod_ctx->dn) {
2384 if (unlang_module_yield(request, user_modify_resume, NULL, 0, usermod_ctx) == UNLANG_ACTION_FAIL) {
2385 talloc_free(usermod_ctx);
2387 }
2388
2389 /* Pushes a frame for user resolution */
2390 if (rlm_ldap_find_user_async(usermod_ctx,
2391 p_result,
2392 usermod_ctx->inst, request,
2393 &usermod_ctx->call_env->user_base,
2394 &usermod_ctx->call_env->user_filter,
2395 usermod_ctx->ttrunk, NULL, NULL) == UNLANG_ACTION_FAIL) {
2397 }
2398
2400 }
2401
2402 {
2403 module_ctx_t our_mctx = *mctx;
2404 our_mctx.rctx = usermod_ctx;
2405
2406 return user_modify_resume(p_result, &our_mctx, request);
2407 }
2408}
2409
2410/** Detach from the LDAP server and cleanup internal state.
2411 *
2412 */
2413static int mod_detach(module_detach_ctx_t const *mctx)
2414{
2415 rlm_ldap_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_ldap_t);
2416
2417 if (inst->user.obj_sort_ctrl) ldap_control_free(inst->user.obj_sort_ctrl);
2418 if (inst->profile.obj_sort_ctrl) ldap_control_free(inst->profile.obj_sort_ctrl);
2419
2420 return 0;
2421}
2422
2423static int ldap_update_section_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules,
2424 CONF_ITEM *ci,
2425 UNUSED call_env_ctx_t const *cec, call_env_parser_t const *rule)
2426{
2427 map_list_t *maps;
2428 CONF_SECTION *update = cf_item_to_section(ci);
2429 ldap_update_rules_t const *ur = rule->uctx;
2430
2431 bool expect_password = false;
2432
2433 /*
2434 * Build the attribute map
2435 */
2436 {
2437 map_t const *map = NULL;
2438 tmpl_attr_t const *ar;
2439 call_env_parsed_t *parsed;
2440
2441 MEM(parsed = call_env_parsed_add(ctx, out,
2443 .name = "update",
2444 .flags = CALL_ENV_FLAG_PARSE_ONLY,
2445 .pair = {
2446 .parsed = {
2447 .offset = ur->map_offset,
2449 }
2450 }
2451 }));
2452
2453 MEM(maps = talloc(parsed, map_list_t));
2454 map_list_init(maps);
2455
2456 if (update && (map_afrom_cs(maps, maps, update, t_rules, t_rules, fr_ldap_map_verify,
2457 NULL, LDAP_MAX_ATTRMAP)) < 0) {
2458 call_env_parsed_free(out, parsed);
2459 return -1;
2460 }
2461 /*
2462 * Check map to see if a password is being retrieved.
2463 * fr_ldap_map_verify ensures that all maps have attributes on the LHS.
2464 * All passwords have a common parent attribute of attr_password
2465 */
2466 while ((map = map_list_next(maps, map))) {
2467 ar = tmpl_attr_tail(map->lhs);
2468 if (ar->da->parent == attr_password) {
2469 expect_password = true;
2470 break;
2471 }
2472 }
2473 call_env_parsed_set_data(parsed, maps);
2474 }
2475
2476 /*
2477 * Write out whether we expect a password to be returned from the ldap data
2478 */
2479 if (ur->expect_password_offset >= 0) {
2480 call_env_parsed_t *parsed;
2481 fr_value_box_t *vb;
2482
2483 MEM(parsed = call_env_parsed_add(ctx, out,
2485 .name = "expect_password",
2486 .flags = CALL_ENV_FLAG_PARSE_ONLY,
2487 .pair = {
2488 .parsed = {
2489 .offset = ur->expect_password_offset,
2491 }
2492 }
2493 }));
2494 MEM(vb = fr_value_box_alloc(parsed, FR_TYPE_BOOL, NULL));
2495 vb->vb_bool = expect_password;
2496 call_env_parsed_set_value(parsed, vb);
2497 }
2498
2499 return 0;
2500}
2501
2502static int ldap_mod_section_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules,
2503 CONF_ITEM *ci, call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
2504{
2505 CONF_SECTION const *subcs = NULL;
2506 CONF_PAIR const *to_parse = NULL;
2507 tmpl_t *parsed_tmpl;
2508 call_env_parsed_t *parsed_env;
2509 char *section2, *p;
2510 ssize_t count, multi_index = 0;
2511 fr_slen_t slen;
2512 ldap_mod_tmpl_t *mod;
2513
2515
2516 section2 = talloc_strdup(NULL, section_name_str(cec->asked->name2));
2517 p = section2;
2518 while (*p != '\0') {
2519 *(p) = tolower((uint8_t)*p);
2520 p++;
2521 }
2522
2523 if (!ci) {
2524 not_found:
2525 cf_log_warn(ci, "No section found for \"%s.%s\" in module \"%s\", this call will have no effect.",
2526 section_name_str(cec->asked->name1), section2, cec->mi->name);
2527 free:
2528 talloc_free(section2);
2529 return 0;
2530 }
2531
2532 subcs = cf_section_find(cf_item_to_section(ci), section2, CF_IDENT_ANY);
2533 if (!subcs) goto not_found;
2534
2535 subcs = cf_section_find(subcs, "update", CF_IDENT_ANY);
2536 if (!subcs) {
2537 cf_log_warn(ci, "No update found inside \"%s -> %s\" in module \"%s\"",
2538 section_name_str(cec->asked->name1), section2, cec->mi->name);
2539 goto free;
2540 }
2541
2543 if (count == 0) {
2544 cf_log_warn(ci, "No modifications found for \"%s.%s\" in module \"%s\"",
2545 section_name_str(cec->asked->name1), section2, cec->mi->name);
2546 goto free;
2547 }
2548 talloc_free(section2);
2549
2550 while ((to_parse = cf_pair_next(subcs, to_parse))) {
2551 switch (cf_pair_operator(to_parse)) {
2552 case T_OP_SET:
2553 case T_OP_ADD_EQ:
2554 case T_OP_SUB_EQ:
2555 case T_OP_CMP_FALSE:
2556 case T_OP_INCRM:
2557 break;
2558
2559 default:
2560 cf_log_perr(to_parse, "Invalid operator for LDAP modification");
2561 return -1;
2562 }
2563
2564 MEM(parsed_env = call_env_parsed_add(ctx, out,
2569 }));
2570
2571 slen = tmpl_afrom_substr(parsed_env, &parsed_tmpl,
2572 &FR_SBUFF_IN(cf_pair_value(to_parse), talloc_strlen(cf_pair_value(to_parse))),
2574 t_rules);
2575
2576 if (slen <= 0) {
2577 cf_canonicalize_error(to_parse, slen, "Failed parsing LDAP modification \"%s\"", cf_pair_value(to_parse));
2578 error:
2579 call_env_parsed_free(out, parsed_env);
2580 return -1;
2581 }
2582 if (tmpl_needs_resolving(parsed_tmpl) &&
2583 (tmpl_resolve(parsed_tmpl, &(tmpl_res_rules_t){ .dict_def = t_rules->attr.dict_def }) <0)) {
2584 cf_log_perr(to_parse, "Failed resolving LDAP modification \"%s\"", cf_pair_value(to_parse));
2585 goto error;
2586 }
2587
2588 MEM(mod = talloc(parsed_env, ldap_mod_tmpl_t));
2589 mod->attr = cf_pair_attr(to_parse);
2590 mod->tmpl = parsed_tmpl;
2591 mod->op = cf_pair_operator(to_parse);
2592
2593 call_env_parsed_set_multi_index(parsed_env, count, multi_index++);
2594 call_env_parsed_set_data(parsed_env, mod);
2595 }
2596
2597 return 0;
2598}
2599
2600static int ldap_group_filter_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, UNUSED CONF_ITEM *ci,
2601 call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
2602{
2604 char const *filters[] = { inst->group.obj_filter, inst->group.obj_membership_filter };
2605 tmpl_t *parsed;
2606
2607 if (fr_ldap_filter_to_tmpl(ctx, t_rules, filters, NUM_ELEMENTS(filters), &parsed) < 0) return -1;
2608
2609 *(void **)out = parsed;
2610 return 0;
2611}
2612
2613/** Clean up thread specific data structure
2614 *
2615 */
2617{
2618 fr_ldap_thread_t *t = talloc_get_type_abort(mctx->thread, fr_ldap_thread_t);
2619 void **trunks_to_free;
2620 int i;
2621
2622 if (fr_rb_flatten_inorder(NULL, &trunks_to_free, t->trunks) < 0) return -1;
2623
2624 for (i = talloc_array_length(trunks_to_free) - 1; i >= 0; i--) talloc_free(trunks_to_free[i]);
2625 talloc_free(trunks_to_free);
2626 talloc_free(t->trunks);
2627
2628 return 0;
2629}
2630
2631/** Initialise thread specific data structure
2632 *
2633 */
2635{
2636 rlm_ldap_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_ldap_t);
2637 fr_ldap_thread_t *t = talloc_get_type_abort(mctx->thread, fr_ldap_thread_t);
2638 fr_ldap_thread_trunk_t *ttrunk;
2639
2640 /*
2641 * Initialise tree for connection trunks used by this thread
2642 */
2644
2645 t->config = &inst->handle_config;
2646 t->trunk_conf = &inst->trunk_conf;
2647 t->bind_trunk_conf = &inst->bind_trunk_conf;
2648 t->el = mctx->el;
2649 t->trigger_args = inst->trigger_args;
2650 t->bind_trigger_args = inst->bind_trigger_args;
2651
2652 /*
2653 * Launch trunk for module default connection
2654 */
2655 ttrunk = fr_thread_ldap_trunk_get(t, inst->handle_config.server, inst->handle_config.admin_identity,
2656 inst->handle_config.admin_password, NULL, &inst->handle_config);
2657 if (!ttrunk) {
2658 ERROR("Unable to launch LDAP trunk");
2659 return -1;
2660 }
2661
2662 /*
2663 * Set up a per-thread LDAP trunk to use for bind auths
2664 */
2666
2668
2669 return 0;
2670}
2671
2672/** Instantiate the module
2673 *
2674 * Creates a new instance of the module reading parameters from a configuration section.
2675 *
2676 * @param [in] mctx configuration data.
2677 * @return
2678 * - 0 on success.
2679 * - < 0 on failure.
2680 */
2681static int mod_instantiate(module_inst_ctx_t const *mctx)
2682{
2683 size_t i;
2684
2685 CONF_SECTION *options;
2686 rlm_ldap_boot_t const *boot = talloc_get_type_abort(mctx->mi->boot, rlm_ldap_boot_t);
2687 rlm_ldap_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_ldap_t);
2688 CONF_SECTION *conf = mctx->mi->conf;
2689
2690 inst->mi = mctx->mi; /* Cached for IO callbacks */
2691 inst->group.da = boot->group_da;
2692 inst->group.cache_da = boot->cache_da;
2693 inst->user.da = boot->user_da;
2694
2695 inst->handle_config.name = talloc_typed_asprintf(inst, "rlm_ldap (%s)", mctx->mi->name);
2696
2697 /*
2698 * Trunks used for bind auth can only have one request in flight per connection.
2699 */
2700 inst->bind_trunk_conf.target_req_per_conn = 1;
2701 inst->bind_trunk_conf.max_req_per_conn = 1;
2702
2703 /*
2704 * Set sizes for trunk request pool.
2705 */
2706 inst->bind_trunk_conf.req_pool_headers = 2;
2707 inst->bind_trunk_conf.req_pool_size = sizeof(fr_ldap_bind_auth_ctx_t) + sizeof(fr_ldap_sasl_ctx_t);
2708
2709 options = cf_section_find(conf, "options", NULL);
2710 if (!options || !cf_pair_find(options, "chase_referrals")) {
2711 inst->handle_config.chase_referrals_unset = true; /* use OpenLDAP defaults */
2712 }
2713
2714 /*
2715 * Sanity checks for cacheable groups code.
2716 */
2717 if (inst->group.cacheable_name && inst->group.obj_membership_filter) {
2718 if (!inst->group.obj_name_attr) {
2719 cf_log_err(conf, "Configuration item 'group.name_attribute' must be set if cacheable "
2720 "group names are enabled");
2721
2722 return -1;
2723 }
2724 }
2725
2726 /*
2727 * If we have a *pair* as opposed to a *section*
2728 * then the module is referencing another ldap module's
2729 * connection pool.
2730 */
2731 if (!cf_pair_find(conf, "pool")) {
2732 if (!inst->handle_config.server_str) {
2733 cf_log_err(conf, "Configuration item 'server' must have a value");
2734 return -1;
2735 }
2736 }
2737
2738#ifndef WITH_SASL
2739 if (inst->handle_config.admin_sasl.mech) {
2740 cf_log_err(conf, "Configuration item 'sasl.mech' not supported. "
2741 "Linked libldap does not provide ldap_sasl_interactive_bind function");
2742 return -1;
2743 }
2744#endif
2745
2746 /*
2747 * Initialise server with zero length string to
2748 * make code below simpler.
2749 */
2750 inst->handle_config.server = talloc_strdup(inst, "");
2751
2752 /*
2753 * Now iterate over all the 'server' config items
2754 */
2755 for (i = 0; i < talloc_array_length(inst->handle_config.server_str); i++) {
2756 char const *value = inst->handle_config.server_str[i];
2757 size_t j;
2758
2759 /*
2760 * Explicitly prevent multiple server definitions
2761 * being used in the same string.
2762 */
2763 for (j = 0; j < talloc_strlen(value); j++) {
2764 switch (value[j]) {
2765 case ' ':
2766 case ',':
2767 case ';':
2768 cf_log_err(conf, "Invalid character '%c' found in 'server' configuration item",
2769 value[j]);
2770 return -1;
2771
2772 default:
2773 continue;
2774 }
2775 }
2776
2777 /*
2778 * Split original server value out into URI, server and port
2779 * so whatever initialization function we use later will have
2780 * the server information in the format it needs.
2781 */
2782 if (ldap_is_ldap_url(value)) {
2783 if (fr_ldap_server_url_check(&inst->handle_config, value, conf) < 0) return -1;
2784 } else
2785 /*
2786 * If it's not an URL, then just treat server as a hostname.
2787 */
2788 {
2789 if (fr_ldap_server_config_check(&inst->handle_config, value, conf) < 0) return -1;
2790 }
2791 }
2792
2793 /*
2794 * inst->handle_config.server be unset if connection pool sharing is used.
2795 */
2796 if (inst->handle_config.server) {
2797 inst->handle_config.server[talloc_array_length(inst->handle_config.server) - 2] = '\0';
2798 DEBUG4("rlm_ldap (%s) - LDAP server string: %s", mctx->mi->name, inst->handle_config.server);
2799 }
2800
2801 /*
2802 * Workaround for servers which support LDAPS but not START TLS
2803 */
2804 if (inst->handle_config.port == LDAPS_PORT || inst->handle_config.tls_mode) {
2805 inst->handle_config.tls_mode = LDAP_OPT_X_TLS_HARD;
2806 } else {
2807 inst->handle_config.tls_mode = 0;
2808 }
2809
2810 /*
2811 * Convert dereference strings to enumerated constants
2812 */
2813 if (inst->handle_config.dereference_str) {
2814 inst->handle_config.dereference = fr_table_value_by_str(fr_ldap_dereference,
2815 inst->handle_config.dereference_str, -1);
2816 if (inst->handle_config.dereference < 0) {
2817 cf_log_err(conf, "Invalid 'dereference' value \"%s\", expected 'never', 'searching', "
2818 "'finding' or 'always'", inst->handle_config.dereference_str);
2819 return -1;
2820 }
2821 }
2822
2823 /*
2824 * Build the server side sort control for user / profile objects
2825 */
2826#define SSS_CONTROL_BUILD(_obj) if (inst->_obj.obj_sort_by) { \
2827 LDAPSortKey **keys; \
2828 int ret; \
2829 ret = ldap_create_sort_keylist(&keys, UNCONST(char *, inst->_obj.obj_sort_by)); \
2830 if (ret != LDAP_SUCCESS) { \
2831 cf_log_err(conf, "Invalid " STRINGIFY(_obj) ".sort_by value \"%s\": %s", \
2832 inst->_obj.obj_sort_by, ldap_err2string(ret)); \
2833 return -1; \
2834 } \
2835 /* \
2836 * Always set the control as critical, if it's not needed \
2837 * the user can comment it out... \
2838 */ \
2839 ret = ldap_create_sort_control(ldap_global_handle, keys, 1, &inst->_obj.obj_sort_ctrl); \
2840 ldap_free_sort_keylist(keys); \
2841 if (ret != LDAP_SUCCESS) { \
2842 ERROR("Failed creating server sort control: %s", ldap_err2string(ret)); \
2843 return -1; \
2844 } \
2845 }
2846
2847 SSS_CONTROL_BUILD(user)
2848 SSS_CONTROL_BUILD(profile)
2849
2850 /*
2851 * Bulk retrieval matches profile objects by their exact DN,
2852 * so subtree (non-base scope) semantics cannot be preserved.
2853 */
2854 switch (inst->profile.search_mode) {
2856 if (inst->profile.obj_sort_ctrl && (inst->profile.obj_scope == LDAP_SCOPE_BASE)) {
2857 inst->profile.search_mode = LDAP_PROFILE_SEARCH_MODE_BULK;
2858 } else {
2859 inst->profile.search_mode = LDAP_PROFILE_SEARCH_MODE_SEQ;
2860 }
2861 break;
2862
2864 if (inst->profile.obj_scope != LDAP_SCOPE_BASE) {
2865 cf_log_err(conf, "'profile.search_mode = bulk' requires 'profile.scope = base'");
2866 return -1;
2867 }
2868 if (!inst->profile.obj_sort_ctrl) {
2869 cf_log_err(conf, "'profile.search_mode = bulk' requires 'profile.sort_by', "
2870 "else profile evaluation order is non-deterministic");
2871 return -1;
2872 }
2873 break;
2874
2876 break;
2877 }
2878
2879 if (inst->handle_config.tls_require_cert_str) {
2880 /*
2881 * Convert cert strictness to enumerated constants
2882 */
2883 inst->handle_config.tls_require_cert = fr_table_value_by_str(fr_ldap_tls_require_cert,
2884 inst->handle_config.tls_require_cert_str, -1);
2885 if (inst->handle_config.tls_require_cert < 0) {
2886 cf_log_err(conf, "Invalid 'tls.require_cert' value \"%s\", expected 'never', "
2887 "'demand', 'allow', 'try' or 'hard'", inst->handle_config.tls_require_cert_str);
2888 return -1;
2889 }
2890 }
2891
2892 if (inst->handle_config.tls_min_version_str) {
2893#ifdef LDAP_OPT_X_TLS_PROTOCOL_TLS1_3
2894 if (strcmp(inst->handle_config.tls_min_version_str, "1.3") == 0) {
2895 inst->handle_config.tls_min_version = LDAP_OPT_X_TLS_PROTOCOL_TLS1_3;
2896
2897 } else
2898#endif
2899 if (strcmp(inst->handle_config.tls_min_version_str, "1.2") == 0) {
2900 inst->handle_config.tls_min_version = LDAP_OPT_X_TLS_PROTOCOL_TLS1_2;
2901
2902 } else if (strcmp(inst->handle_config.tls_min_version_str, "1.1") == 0) {
2903 inst->handle_config.tls_min_version = LDAP_OPT_X_TLS_PROTOCOL_TLS1_1;
2904
2905 } else if (strcmp(inst->handle_config.tls_min_version_str, "1.0") == 0) {
2906 inst->handle_config.tls_min_version = LDAP_OPT_X_TLS_PROTOCOL_TLS1_0;
2907
2908 } else {
2909 cf_log_err(conf, "Invalid 'tls.tls_min_version' value \"%s\"", inst->handle_config.tls_min_version_str);
2910 return -1;
2911 }
2912 }
2913
2914 if (inst->trunk_conf.conn_triggers) {
2915 MEM(inst->trigger_args = fr_pair_list_alloc(inst));
2916 if (module_trigger_args_build(inst->trigger_args, inst->trigger_args, cf_section_find(conf, "pool", NULL),
2918 .module = mctx->mi->module->name,
2919 .name = mctx->mi->name,
2920 .server = inst->handle_config.server,
2921 .port = inst->handle_config.port
2922 }) < 0) return -1;
2923 }
2924
2925 if (inst->bind_trunk_conf.conn_triggers) {
2926 MEM(inst->bind_trigger_args = fr_pair_list_alloc(inst));
2927 if (module_trigger_args_build(inst->bind_trigger_args, inst->bind_trigger_args, cf_section_find(conf, "bind_pool", NULL),
2929 .module = mctx->mi->module->name,
2930 .name = mctx->mi->name,
2931 .server = inst->handle_config.server,
2932 .port = inst->handle_config.port
2933 }) < 0) return -1;
2934 }
2935 return 0;
2936}
2937
2938/** Bootstrap the module
2939 *
2940 * Define attributes.
2941 *
2942 * @param[in] mctx configuration data.
2943 * @return
2944 * - 0 on success.
2945 * - < 0 on failure.
2946 */
2947static int mod_bootstrap(module_inst_ctx_t const *mctx)
2948{
2949 rlm_ldap_boot_t *boot = talloc_get_type_abort(mctx->mi->boot, rlm_ldap_boot_t);
2950 rlm_ldap_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_ldap_t);
2951 CONF_SECTION *conf = mctx->mi->conf;
2952 char buffer[256];
2953 char const *group_attribute;
2954 xlat_t *xlat;
2955
2956 if (inst->group.attribute) {
2957 group_attribute = inst->group.attribute;
2958 } else if (cf_section_name2(conf)) {
2959 snprintf(buffer, sizeof(buffer), "%s-LDAP-Group", mctx->mi->name);
2960 group_attribute = buffer;
2961 } else {
2962 group_attribute = "LDAP-Group";
2963 }
2964
2965 boot->group_da = fr_dict_attr_by_name(NULL, fr_dict_root(dict_freeradius), group_attribute);
2966
2967 /*
2968 * If the group attribute was not in the dictionary, create it
2969 */
2970 if (!boot->group_da) {
2972 group_attribute, FR_TYPE_STRING, NULL) < 0) {
2973 PERROR("Error creating group attribute");
2974 return -1;
2975
2976 }
2977 boot->group_da = fr_dict_attr_by_name(NULL, fr_dict_root(dict_freeradius), group_attribute);
2978 }
2979
2980 /*
2981 * Setup the cache attribute
2982 */
2983 if (inst->group.cache_attr_str) {
2984 boot->cache_da = fr_dict_attr_by_name(NULL, fr_dict_root(dict_freeradius), inst->group.cache_attr_str);
2985 if (!boot->cache_da) {
2987 inst->group.cache_attr_str, FR_TYPE_STRING, NULL) < 0) {
2988 PERROR("Error creating cache attribute");
2989 return -1;
2990 }
2991 boot->cache_da = fr_dict_attr_by_name(NULL, fr_dict_root(dict_freeradius), inst->group.cache_attr_str);
2992 }
2993 } else {
2994 boot->cache_da = boot->group_da; /* Default to the group_da */
2995 }
2996
2997
2998 if (inst->user.dn_attr_str) {
2999 boot->user_da = fr_dict_attr_by_name(NULL, fr_dict_root(dict_freeradius), inst->user.dn_attr_str);
3000 if (!boot->user_da) {
3002 inst->user.dn_attr_str, FR_TYPE_STRING, NULL) < 0) {
3003 PERROR("Error creating user DN cache attribute");
3004 return -1;
3005 }
3006 boot->user_da = fr_dict_attr_by_name(NULL, fr_dict_root(dict_freeradius), inst->user.dn_attr_str);
3007 }
3008 }
3009
3010 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, NULL, ldap_xlat, FR_TYPE_STRING);
3012
3013 if (unlikely(!(xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, "group", ldap_group_xlat,
3014 FR_TYPE_BOOL)))) return -1;
3017
3018 if (unlikely(!(xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, "profile", ldap_profile_xlat,
3019 FR_TYPE_BOOL)))) return -1;
3022
3023 if (unlikely(!module_rlm_xlat_register(mctx->mi->boot, mctx, "whoami", ldap_whoami_xlat,
3024 FR_TYPE_STRING))) return -1;
3025
3027
3028 return 0;
3029}
3030
3031static int mod_load(void)
3032{
3033 xlat_t *xlat;
3034
3035 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.dn.escape", ldap_dn_escape_xlat, FR_TYPE_STRING)))) return -1;
3039
3040 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.dn.safe", xlat_transparent, FR_TYPE_STRING)))) return -1;
3044
3045 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.dn.unescape", ldap_uri_unescape_xlat, FR_TYPE_STRING)))) return -1;
3048
3049 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.filter.escape", ldap_filter_escape_xlat, FR_TYPE_STRING)))) return -1;
3053
3054 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.filter.safe", xlat_transparent, FR_TYPE_STRING)))) return -1;
3058
3059 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.filter.unescape", ldap_uri_unescape_xlat, FR_TYPE_STRING)))) return -1;
3062
3063 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.uri.attr_option", ldap_xlat_uri_attr_option, FR_TYPE_STRING)))) return -1;
3066
3067 /*
3068 * ldap.uri.* are kept as aliases for ldap.dn.* so that existing configs
3069 * continue to work. They use the same safe_for token for now; if the URI
3070 * context ever needs its own rules, a separate token can be introduced.
3071 */
3072 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.uri.escape", ldap_dn_escape_xlat, FR_TYPE_STRING)))) return -1;
3076
3077 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.uri.safe", xlat_transparent, FR_TYPE_STRING)))) return -1;
3081
3082 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.uri.unescape", ldap_uri_unescape_xlat, FR_TYPE_STRING)))) return -1;
3085
3086 return 0;
3087}
3088
3089static void mod_unload(void)
3090{
3091 xlat_func_unregister("ldap.dn.escape");
3092 xlat_func_unregister("ldap.dn.safe");
3093 xlat_func_unregister("ldap.dn.unescape");
3094 xlat_func_unregister("ldap.filter.escape");
3095 xlat_func_unregister("ldap.filter.safe");
3096 xlat_func_unregister("ldap.filter.unescape");
3097 xlat_func_unregister("ldap.uri.escape");
3098 xlat_func_unregister("ldap.uri.safe");
3099 xlat_func_unregister("ldap.uri.unescape");
3100}
3102/* globally exported name */
3103extern module_rlm_t rlm_ldap;
3105 .common = {
3106 .magic = MODULE_MAGIC_INIT,
3107 .name = "ldap",
3108 .flags = 0,
3111 .config = module_config,
3112 .onload = mod_load,
3113 .unload = mod_unload,
3114 .bootstrap = mod_bootstrap,
3115 .instantiate = mod_instantiate,
3116 .detach = mod_detach,
3118 .thread_instantiate = mod_thread_instantiate,
3119 .thread_detach = mod_thread_detach,
3120 },
3121 .method_group = {
3122 .bindings = (module_method_binding_t[]){
3123 /*
3124 * Hack to support old configurations
3125 */
3126 { .section = SECTION_NAME("accounting", CF_IDENT_ANY), .method = mod_modify, .method_env = &accounting_usermod_method_env },
3127 { .section = SECTION_NAME("authenticate", CF_IDENT_ANY), .method = mod_authenticate, .method_env = &authenticate_method_env },
3128 { .section = SECTION_NAME("authorize", CF_IDENT_ANY), .method = mod_authorize, .method_env = &authorize_method_env },
3129
3130 { .section = SECTION_NAME("recv", CF_IDENT_ANY), .method = mod_authorize, .method_env = &authorize_method_env },
3131 { .section = SECTION_NAME("send", CF_IDENT_ANY), .method = mod_modify, .method_env = &send_usermod_method_env },
3133 }
3134 }
3135};
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_PUSHED_CHILD
unlang_t pushed a new child onto the stack, execute it instead of continuing.
Definition action.h:39
@ UNLANG_ACTION_FAIL
Encountered an unexpected error.
Definition action.h:36
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
Definition action.h:37
@ UNLANG_ACTION_YIELD
Temporarily pause execution until an event occurs.
Definition action.h:41
static int const char char buffer[256]
Definition acutest.h:576
int n
Definition acutest.h:577
log_entry msg
Definition acutest.h:794
#define USES_APPLE_DEPRECATED_API
Definition build.h:547
#define RCSID(id)
Definition build.h:560
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:228
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
Definition build.h:391
#define unlikely(_x)
Definition build.h:455
#define UNUSED
Definition build.h:384
#define NUM_ELEMENTS(_t)
Definition build.h:406
void call_env_parsed_free(call_env_parsed_head_t *parsed, call_env_parsed_t *ptr)
Remove a call_env_parsed_t from the list of parsed call envs.
Definition call_env.c:776
call_env_parsed_t * call_env_parsed_add(TALLOC_CTX *ctx, call_env_parsed_head_t *head, call_env_parser_t const *rule)
Allocate a new call_env_parsed_t structure and add it to the list of parsed call envs.
Definition call_env.c:689
void call_env_parsed_set_multi_index(call_env_parsed_t *parsed, size_t count, size_t index)
Assign a count and index to a call_env_parsed_t.
Definition call_env.c:761
void call_env_parsed_set_data(call_env_parsed_t *parsed, void const *data)
Assign data to a call_env_parsed_t.
Definition call_env.c:746
void call_env_parsed_set_value(call_env_parsed_t *parsed, fr_value_box_t const *vb)
Assign a value box to a call_env_parsed_t.
Definition call_env.c:732
#define CALL_ENV_TERMINATOR
Definition call_env.h:236
call_env_ctx_type_t type
Type of callenv ctx.
Definition call_env.h:227
@ CALL_ENV_CTX_TYPE_MODULE
The callenv is registered to a module method.
Definition call_env.h:222
#define FR_CALL_ENV_PARSE_OFFSET(_name, _cast_type, _flags, _struct, _field, _parse_field)
Specify a call_env_parser_t which writes out runtime results and the result of the parsing phase to t...
Definition call_env.h:365
#define FR_CALL_ENV_METHOD_OUT(_inst)
Helper macro for populating the size/type fields of a call_env_method_t from the output structure typ...
Definition call_env.h:240
call_env_parser_t const * env
Parsing rules for call method env.
Definition call_env.h:247
section_name_t const * asked
The actual name1/name2 that resolved to a module_method_binding_t.
Definition call_env.h:232
void const * uctx
User context for callback functions.
Definition call_env.h:218
#define FR_CALL_ENV_SUBSECTION(_name, _name2, _flags, _subcs)
Specify a call_env_parser_t which defines a nested subsection.
Definition call_env.h:402
@ CALL_ENV_FLAG_CONCAT
If the tmpl produced multiple boxes they should be concatenated.
Definition call_env.h:76
@ CALL_ENV_FLAG_ATTRIBUTE
Tmpl MUST contain an attribute reference.
Definition call_env.h:86
@ CALL_ENV_FLAG_PARSE_ONLY
The result of parsing will not be evaluated at runtime.
Definition call_env.h:85
@ CALL_ENV_FLAG_NONE
Definition call_env.h:74
@ CALL_ENV_FLAG_MULTI
Multiple instances of the conf pairs are allowed.
Definition call_env.h:78
@ CALL_ENV_FLAG_REQUIRED
Associated conf pair or section is required.
Definition call_env.h:75
@ CALL_ENV_FLAG_PARSE_MISSING
If this subsection is missing, still parse it.
Definition call_env.h:88
@ CALL_ENV_FLAG_BARE_WORD_ATTRIBUTE
bare words are treated as an attribute, but strings may be xlats.
Definition call_env.h:92
@ CALL_ENV_FLAG_NULLABLE
Tmpl expansions are allowed to produce no output.
Definition call_env.h:80
@ CALL_ENV_PARSE_TYPE_VALUE_BOX
Output of the parsing phase is a single value box (static data).
Definition call_env.h:61
@ CALL_ENV_PARSE_TYPE_VOID
Output of the parsing phase is undefined (a custom structure).
Definition call_env.h:62
module_instance_t const * mi
Module instance that the callenv is registered to.
Definition call_env.h:229
#define FR_CALL_ENV_SUBSECTION_FUNC(_name, _name2, _flags, _func)
Specify a call_env_parser_t which parses a subsection using a callback function.
Definition call_env.h:412
#define FR_CALL_ENV_OFFSET(_name, _cast_type, _flags, _struct, _field)
Specify a call_env_parser_t which writes out runtime results to the specified field.
Definition call_env.h:340
#define FR_CALL_ENV_PARSE_ONLY_OFFSET(_name, _cast_type, _flags, _struct, _parse_field)
Specify a call_env_parser_t which writes out the result of the parsing phase to the field specified.
Definition call_env.h:389
Per method call config.
Definition call_env.h:180
int cf_table_parse_int(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic function for parsing conf pair values as int.
Definition cf_parse.c:1724
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:669
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:623
#define FR_CONF_DEPRECATED(_name, _struct, _field)
conf_parser_t entry which raises an error if a matching CONF_PAIR is found
Definition cf_parse.h:409
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:280
#define FR_CONF_POINTER(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result
Definition cf_parse.h:334
#define FR_CONF_OFFSET_IS_SET(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct,...
Definition cf_parse.h:294
#define FR_CONF_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:268
#define FR_CONF_OFFSET_SUBSECTION(_name, _flags, _struct, _field, _subcs)
conf_parser_t which populates a sub-struct using a CONF_SECTION
Definition cf_parse.h:309
@ CONF_FLAG_MULTI
CONF_PAIR can have multiple copies.
Definition cf_parse.h:446
@ CONF_FLAG_XLAT
string will be dynamically expanded.
Definition cf_parse.h:443
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition cf_parse.h:423
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:606
Common header for all CONF_* types.
Definition cf_priv.h:54
Configuration AVP similar to a fr_pair_t.
Definition cf_priv.h:77
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:106
unsigned int cf_pair_count_descendents(CONF_SECTION const *cs)
Count the number of conf pairs beneath a section.
Definition cf_util.c:1664
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1363
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
Definition cf_util.c:1205
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:696
CONF_PAIR * cf_pair_find(CONF_SECTION const *cs, char const *attr)
Search for a CONF_PAIR with a specific name.
Definition cf_util.c:1598
fr_token_t cf_pair_operator(CONF_PAIR const *pair)
Return the operator of a pair.
Definition cf_util.c:1730
fr_token_t cf_pair_value_quote(CONF_PAIR const *pair)
Return the value (rhs) quoting of a pair.
Definition cf_util.c:1760
CONF_PAIR * cf_pair_next(CONF_SECTION const *cs, CONF_PAIR const *curr)
Return the next child that's a CONF_PAIR.
Definition cf_util.c:1572
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1716
char const * cf_pair_attr(CONF_PAIR const *pair)
Return the attr of a CONF_PAIR.
Definition cf_util.c:1700
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:343
#define cf_canonicalize_error(_ci, _slen, _msg, _str)
Definition cf_util.h:421
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:350
#define cf_log_warn(_cf, _fmt,...)
Definition cf_util.h:344
#define CF_IDENT_ANY
Definition cf_util.h:80
static int fr_dcursor_append(fr_dcursor_t *cursor, void *v)
Insert a single item at the end of the list.
Definition dcursor.h:406
#define MEM(x)
Definition debug.h:38
#define ERROR(fmt,...)
Definition dhcpclient.c:40
int fr_dict_attr_add_name_only(fr_dict_t *dict, fr_dict_attr_t const *parent, char const *name, fr_type_t type, fr_dict_attr_flags_t const *flags))
Add an attribute to the dictionary.
Definition dict_util.c:2062
fr_dict_t * fr_dict_unconst(fr_dict_t const *dict)
Coerce to non-const.
Definition dict_util.c:5011
static fr_slen_t err
Definition dict.h:906
fr_dict_attr_t const * fr_dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *attr))
Locate a fr_dict_attr_t by its name.
Definition dict_util.c:3601
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
Definition dict_util.c:2720
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:316
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:329
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:335
static fr_slen_t in
Definition dict.h:906
Specifies an attribute which must be present for the module to function.
Definition dict.h:315
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:328
Test enumeration values.
Definition dict_test.h:92
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
Definition dwarf.c:424
#define unlang_function_push_with_result(_result_p, _request, _func, _repeat, _signal, _sigmask, _top_frame, _uctx)
Push a generic function onto the unlang stack that produces a result.
Definition function.h:144
#define GLOBAL_LIB_TERMINATOR
Definition global_lib.h:51
Structure to define how to initialise libraries with global configuration.
Definition global_lib.h:38
static xlat_action_t ldap_filter_escape_xlat(UNUSED TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
Escape a string for use as an RFC 4515 filter assertion value.
Definition rlm_ldap.c:467
static xlat_action_t ldap_xlat(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
Expand an LDAP URL into a query, and return a string result from that query.
Definition rlm_ldap.c:841
static xlat_action_t ldap_whoami_xlat_resume(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in)
Return the authorization identity from the whoami response.
Definition rlm_ldap.c:1316
static xlat_action_t ldap_dn_escape_xlat(UNUSED TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
Escape a string for use in an RFC 4514 DN attribute value.
Definition rlm_ldap.c:443
static xlat_action_t ldap_group_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
Check for a user being in a LDAP group.
Definition rlm_ldap.c:1048
static xlat_action_t ldap_whoami_xlat(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in)
Perform the RFC 4532 whoami extended operation.
Definition rlm_ldap.c:1374
static xlat_action_t ldap_profile_xlat(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
Expand an LDAP URL into a query, applying the results using the user update map.
Definition rlm_ldap.c:1179
static xlat_action_t ldap_xlat_uri_attr_option(TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
Modify an LDAP URI to append an option to all attributes.
Definition rlm_ldap.c:576
static xlat_action_t ldap_uri_unescape_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
Unescape LDAP string.
Definition rlm_ldap.c:496
unlang_action_t rlm_ldap_cacheable_groupobj(unlang_result_t *p_result, request_t *request, ldap_autz_ctx_t *autz_ctx)
Convert group membership information into attributes.
Definition groups.c:749
unlang_action_t rlm_ldap_check_groupobj_dynamic(unlang_result_t *p_result, request_t *request, ldap_group_xlat_ctx_t *xlat_ctx)
Initiate an LDAP search to determine group membership, querying group objects.
Definition groups.c:951
unlang_action_t rlm_ldap_cacheable_userobj(unlang_result_t *p_result, request_t *request, ldap_autz_ctx_t *autz_ctx, char const *attr)
Convert group membership information into attributes.
Definition groups.c:439
unlang_action_t rlm_ldap_check_userobj_dynamic(unlang_result_t *p_result, request_t *request, ldap_group_xlat_ctx_t *xlat_ctx)
Query the LDAP directory to check if a user object is a member of a group.
Definition groups.c:1301
unlang_action_t rlm_ldap_group_profiles(unlang_result_t *p_result, request_t *request, ldap_autz_ctx_t *autz_ctx)
Search for profile DNs in the group objects the user is a member of.
Definition groups.c:853
unlang_action_t rlm_ldap_check_cached(unlang_result_t *p_result, rlm_ldap_t const *inst, request_t *request, fr_value_box_t const *check)
Check group membership attributes to see if a user is a member.
Definition groups.c:1344
free(array)
talloc_free(hp)
void unlang_interpret_mark_runnable(request_t *request)
Mark a request as resumable.
Definition interpret.c:2008
TALLOC_CTX * unlang_interpret_frame_talloc_ctx(request_t *request)
Get a talloc_ctx which is valid only for this frame.
Definition interpret.c:2053
fr_event_list_t * unlang_interpret_event_list(request_t *request)
Get the event list for the current interpreter.
Definition interpret.c:2538
#define UNLANG_SUB_FRAME
Definition interpret.h:37
rlm_rcode_t rcode
The current rcode, from executing the instruction or merging the result from a frame.
Definition interpret.h:140
char const * fr_ldap_url_err_to_str(int ldap_url_err)
Translate the error code emitted from ldap_url_parse and friends into something accessible with fr_st...
Definition util.c:1136
int fr_ldap_map_verify(map_t *map, void *instance)
size_t fr_ldap_uri_unescape_func(UNUSED request_t *request, char *out, size_t outlen, char const *in, UNUSED void *arg))
Converts escaped DNs and filter strings into normal.
Definition util.c:194
size_t fr_ldap_util_normalise_dn(char *out, char const *in)
Normalise escape sequences in a DN.
Definition util.c:794
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.
Definition map.c:39
int fr_ldap_filter_to_tmpl(TALLOC_CTX *ctx, tmpl_rules_t const *t_rules, char const **sub, size_t sublen, tmpl_t **out))
Combine filters and tokenize to a tmpl.
Definition util.c:910
fr_ldap_control_t serverctrls[LDAP_MAX_CONTROLS]
Server controls specific to this query.
Definition base.h:452
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.
Definition map.c:377
#define LDAP_DN_SAFE_FOR
Marks a value box as already escaped for use as a DN attribute value.
Definition base.h:1012
fr_time_delta_t res_timeout
How long we wait for results.
Definition base.h:307
char const * admin_password
Password used in administrative bind.
Definition base.h:240
int fr_ldap_filter_box_escape(fr_value_box_t *vb, UNUSED void *uctx)
Escape a value box for use as an RFC 4515 filter assertion value.
Definition util.c:172
fr_ldap_config_t * config
Module instance config.
Definition base.h:383
int count
Index on next free element.
Definition base.h:375
bool fr_ldap_util_is_dn(char const *in, size_t inlen)
Check whether a string looks like a DN.
Definition util.c:242
char * server
Initial server to bind to.
Definition base.h:233
LDAP * handle
libldap handle.
Definition base.h:342
char const * admin_identity
Identity we bind as when we need to query the LDAP directory.
Definition base.h:238
fr_ldap_result_code_t ret
Result code.
Definition base.h:472
bool freeit
Whether the control should be freed after we've finished using it.
Definition base.h:135
fr_rb_tree_t * trunks
Tree of LDAP trunks used by this thread.
Definition base.h:382
trunk_conf_t * trunk_conf
Module trunk config.
Definition base.h:384
trunk_request_t * treq
Trunk request this query is associated with.
Definition base.h:458
#define LDAP_FILTER_SAFE_FOR
Marks a value box as already escaped for use as a filter assertion value.
Definition base.h:1016
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.
Definition map.c:210
fr_ldap_thread_trunk_t * fr_thread_ldap_trunk_get(fr_ldap_thread_t *thread, char const *uri, char const *bind_dn, char const *bind_password, request_t *request, fr_ldap_config_t const *config)
Find a thread specific LDAP connection for a specific URI / bind DN.
Definition connection.c:940
int fr_ldap_result_values_len(size_t *num, size_t *strings_len, LDAP *handle, LDAPMessage *result, char const *attr)
Sum the lengths of an attribute's values across every entry of a result.
Definition util.c:620
int fr_ldap_server_url_check(fr_ldap_config_t *handle_config, char const *server, CONF_SECTION const *cs)
Check an LDAP server entry in URL format is valid.
Definition util.c:998
#define LDAP_MAX_ATTRMAP
Maximum number of mappings between LDAP and FreeRADIUS attributes.
Definition base.h:96
static fr_cmp_ret_t fr_ldap_bind_auth_cmp(void const *one, void const *two)
Compare two ldap bind auth structures on msgid.
Definition base.h:726
int fr_ldap_server_config_check(fr_ldap_config_t *handle_config, char const *server, CONF_SECTION *cs)
Check an LDAP server config in server:port format is valid.
Definition util.c:1095
talloc_str_list_t * fr_ldap_str_list_afrom_result(TALLOC_CTX *ctx, LDAP *handle, LDAPMessage *result, char const *attr, size_t extra)
Copy an attribute's values from every entry of a result into a string list.
Definition util.c:663
int fr_ldap_dn_box_escape(fr_value_box_t *vb, UNUSED void *uctx)
Escape a value box for use as an RFC 4514 DN attribute value.
Definition util.c:161
unlang_action_t fr_ldap_edir_get_password(unlang_result_t *p_result, request_t *request, char const *dn, fr_ldap_thread_trunk_t *ttrunk, fr_dict_attr_t const *password_da)
Initiate retrieval of the universal password from Novell eDirectory.
Definition edir.c:293
fr_pair_list_t * bind_trigger_args
Passed to trigger request for bind trunks.
Definition base.h:390
fr_ldap_connection_t * ldap_conn
LDAP connection this query is running on.
Definition base.h:459
fr_ldap_result_code_t
LDAP query result codes.
Definition base.h:188
@ LDAP_RESULT_TIMEOUT
The query timed out.
Definition base.h:192
@ LDAP_RESULT_SUCCESS
Successfully got LDAP results.
Definition base.h:190
@ LDAP_RESULT_NO_RESULT
No results returned.
Definition base.h:194
@ LDAP_RESULT_BAD_DN
The requested DN does not exist.
Definition base.h:193
fr_ldap_thread_trunk_t * fr_thread_ldap_bind_trunk_get(fr_ldap_thread_t *thread)
Find the thread specific trunk to use for LDAP bind auths.
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.
Definition map.c:321
#define LDAP_MAX_CONTROLS
Maximum number of client/server controls.
Definition base.h:94
trunk_conf_t * bind_trunk_conf
Trunk config for bind auth trunk.
Definition base.h:385
#define LDAP_VIRTUAL_DN_ATTR
'Virtual' attribute which maps to the DN of the object.
Definition base.h:112
int fr_ldap_parse_url_extensions(LDAPControl **sss, size_t sss_len, char *extensions[])
Parse a subset (just server side sort and virtual list view for now) of LDAP URL extensions.
Definition util.c:340
static fr_cmp_ret_t fr_ldap_trunk_cmp(void const *one, void const *two)
Compare two ldap trunk structures on connection URI / DN.
Definition base.h:697
LDAPMessage * result
Head of LDAP results list.
Definition base.h:470
fr_event_list_t * el
Thread event list for callbacks / timeouts.
Definition base.h:386
LDAPControl * control
LDAP control.
Definition base.h:134
char const * attrs[LDAP_MAX_ATTRMAP+LDAP_MAP_RESERVED+1]
Reserve some space for access attributes.
Definition base.h:372
fr_ldap_thread_trunk_t * bind_trunk
LDAP trunk used for bind auths.
Definition base.h:387
trunk_t * trunk
Connection trunk.
Definition base.h:407
fr_pair_list_t * trigger_args
Passed to trigger request for normal trunks.
Definition base.h:389
unlang_action_t fr_ldap_bind_auth_async(unlang_result_t *p_result, request_t *request, fr_ldap_thread_t *thread, char const *bind_dn, char const *password)
Initiate an async LDAP bind for authentication.
Definition bind.c:328
fr_timer_t * ev
Event for timing out the query.
Definition base.h:461
TALLOC_CTX * ctx
Context to allocate new attributes in.
Definition base.h:374
fr_rb_tree_t * binds
Tree of outstanding bind auths.
Definition base.h:388
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.
Definition util.c:590
LDAPURLDesc * ldap_url
parsed URL for current query if the source of the query was a URL.
Definition base.h:428
Holds arguments for async bind auth requests.
Definition base.h:615
Connection configuration.
Definition base.h:230
Tracks the state of a libldap connection handle.
Definition base.h:341
Result of expanding the RHS of a set of maps.
Definition base.h:370
LDAP query structure.
Definition base.h:424
Holds arguments for the async SASL bind operation.
Definition base.h:508
Thread specific structure to manage LDAP trunk connections.
Definition base.h:381
Thread LDAP trunk structure.
Definition base.h:401
State of an in place iteration over an attribute's values.
Definition base.h:965
#define FR_LDAP_COMMON_CONF(_conf)
Definition conf.h:19
size_t fr_ldap_scope_len
Definition base.c:75
LDAP * fr_ldap_handle_thread_local(void)
Get a thread local dummy LDAP handle.
Definition base.c:1131
global_lib_autoinst_t fr_libldap_global_config
Definition base.c:134
unlang_action_t fr_ldap_trunk_modify(TALLOC_CTX *ctx, fr_ldap_query_t **out, request_t *request, fr_ldap_thread_trunk_t *ttrunk, char const *dn, LDAPMod *mods[], LDAPControl **serverctrls, LDAPControl **clientctrls)
Run an async modification LDAP query on a trunk connection.
Definition base.c:771
fr_table_num_sorted_t const fr_ldap_tls_require_cert[]
Definition base.c:77
fr_table_num_sorted_t const fr_ldap_dereference[]
Definition base.c:86
fr_ldap_query_t * fr_ldap_search_alloc(TALLOC_CTX *ctx, char const *base_dn, int scope, char const *filter, char const *const *attrs, LDAPControl **serverctrls, LDAPControl **clientctrls)
Allocate a new search object.
Definition base.c:1052
unlang_action_t fr_ldap_trunk_extended(TALLOC_CTX *ctx, fr_ldap_query_t **out, request_t *request, fr_ldap_thread_trunk_t *ttrunk, char const *reqoid, struct berval *reqdata, LDAPControl **serverctrls, LDAPControl **clientctrls)
Run an async LDAP "extended operation" query on a trunk connection.
Definition base.c:903
unlang_action_t fr_ldap_trunk_search(TALLOC_CTX *ctx, fr_ldap_query_t **out, request_t *request, fr_ldap_thread_trunk_t *ttrunk, char const *base_dn, int scope, char const *filter, char const *const *attrs, LDAPControl **serverctrls, LDAPControl **clientctrls)
Run an async search LDAP query on a trunk connection.
Definition base.c:719
fr_table_num_sorted_t const fr_ldap_scope[]
Definition base.c:69
#define PERROR(_fmt,...)
Definition log.h:233
#define REXDENT()
Exdent (unindent) R* messages by one level.
Definition log.h:460
#define ROPTIONAL(_l_request, _l_global, _fmt,...)
Use different logging functions depending on whether request is NULL or not.
Definition log.h:545
#define RWDEBUG(fmt,...)
Definition log.h:378
#define RDEBUG_ENABLED3
True if request debug level 1-3 messages are enabled.
Definition log.h:352
#define RDEBUG3(fmt,...)
Definition log.h:360
#define RERROR(fmt,...)
Definition log.h:315
#define DEBUG4(_fmt,...)
Definition log.h:272
#define RPERROR(fmt,...)
Definition log.h:319
#define RPEDEBUG(fmt,...)
Definition log.h:393
#define RINDENT()
Indent R* messages by one level.
Definition log.h:447
int map_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION const *cs, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, map_validate_t validate, void *uctx, unsigned int max)
Convert a config section into an attribute map.
Definition map.c:1136
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.
Definition map.c:1814
unlang_action_t unlang_map_yield(request_t *request, map_proc_func_t resume, unlang_map_signal_t signal, fr_signal_t sigmask, void *rctx)
Yield a request back to the interpreter from within a module.
Definition map.c:109
static TALLOC_CTX * map_ctx
Definition map_builtin.c:32
int map_proc_register(TALLOC_CTX *ctx, void const *mod_inst, char const *name, map_proc_func_t evaluate, map_proc_instantiate_t instantiate, size_t inst_size, fr_value_box_safe_for_t literals_safe_for)
Register a map processor.
Definition map_proc.c:127
void * rctx
Resume ctx that a module previously set.
Definition map_proc.h:53
void const * moi
Map module instance.
Definition map_proc.h:54
Temporary structure to hold arguments for map calls.
Definition map_proc.h:52
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_VOID
User data.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_OCTETS
Raw octets.
@ FR_TYPE_GROUP
A grouping of other attributes.
long int ssize_t
unsigned char uint8_t
ssize_t fr_slen_t
int strcasecmp(char *s1, char *s2)
Definition missing.c:65
void * env_data
Per call environment data.
Definition module_ctx.h:44
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:42
void * thread
Thread specific instance data.
Definition module_ctx.h:43
void * rctx
Resume ctx that a module previously set.
Definition module_ctx.h:45
fr_event_list_t * el
Event list to register any IO handlers and timers against.
Definition module_ctx.h:68
module_instance_t * mi
Module instance to detach.
Definition module_ctx.h:57
void * thread
Thread instance data.
Definition module_ctx.h:67
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:64
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
Temporary structure to hold arguments for detach calls.
Definition module_ctx.h:56
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
Temporary structure to hold arguments for thread_instantiation calls.
Definition module_ctx.h:63
xlat_t * module_rlm_xlat_register(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx, char const *name, xlat_func_t func, fr_type_t return_type)
Definition module_rlm.c:234
module_t common
Common fields presented by all modules.
Definition module_rlm.h:39
fr_pair_t * fr_pair_find_by_da_nested(fr_pair_list_t const *list, fr_dict_attr_t const *da)
Find a pair with a matching fr_dict_attr_t, by walking the nested fr_dict_attr_t tree.
Definition pair.c:783
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
Definition pair.c:708
fr_pair_list_t * fr_pair_list_alloc(TALLOC_CTX *ctx)
Allocate a new pair list on the heap.
Definition pair.c:120
unlang_action_t rlm_ldap_map_profiles(fr_ldap_result_code_t *ret, int *applied, rlm_ldap_t const *inst, request_t *request, fr_ldap_thread_trunk_t *ttrunk, char const *const *dn_list, char const *filter, fr_ldap_map_exp_t const *expanded)
Search for and apply a set of LDAP profiles.
Definition profile.c:311
unlang_action_t rlm_ldap_map_profile(fr_ldap_result_code_t *ret, int *applied, rlm_ldap_t const *inst, request_t *request, fr_ldap_thread_trunk_t *ttrunk, char const *dn, int scope, char const *filter, fr_ldap_map_exp_t const *expanded)
Search for and apply an LDAP profile.
Definition profile.c:269
static char const * url[FR_RADIUS_FAIL_MAX+1]
#define fr_assert(_expr)
Definition rad_assert.h:37
#define REDEBUG(fmt,...)
#define RDEBUG_ENABLED2()
#define RDEBUG2(fmt,...)
#define RDEBUG(fmt,...)
static bool done
Definition radclient.c:80
static rs_t * conf
Definition radsniff.c:52
#define fr_rb_inline_talloc_alloc(_ctx, _type, _field, _data_cmp, _data_free)
Allocs a red black that verifies elements are of a specific talloc type.
Definition rb.h:244
int fr_rb_flatten_inorder(TALLOC_CTX *ctx, void **out[], fr_rb_tree_t *tree)
#define RETURN_UNLANG_INVALID
Definition rcode.h:66
#define RETURN_UNLANG_RCODE(_rcode)
Definition rcode.h:61
#define RETURN_UNLANG_NOTFOUND
Definition rcode.h:68
#define RETURN_UNLANG_FAIL
Definition rcode.h:63
#define RETURN_UNLANG_OK
Definition rcode.h:64
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:44
@ RLM_MODULE_INVALID
The module considers the request invalid.
Definition rcode.h:51
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:49
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:48
@ RLM_MODULE_DISALLOW
Reject the request (user is locked out).
Definition rcode.h:52
@ RLM_MODULE_REJECT
Immediately reject the request.
Definition rcode.h:47
@ RLM_MODULE_TIMEOUT
Module (or section) timed out.
Definition rcode.h:56
@ RLM_MODULE_NOTFOUND
User not found.
Definition rcode.h:53
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition rcode.h:55
@ RLM_MODULE_HANDLED
The module handled the request, so stop.
Definition rcode.h:50
#define RETURN_UNLANG_NOOP
Definition rcode.h:69
static unlang_action_t mod_map_proc(unlang_result_t *p_result, map_ctx_t const *mpctx, request_t *request, fr_value_box_list_t *url, map_list_t const *maps)
Perform a search and map the result of the search to server attributes.
Definition rlm_ldap.c:1555
tmpl_t const * tmpl
Definition rlm_ldap.c:66
static void mod_authorize_cancel(module_ctx_t const *mctx, UNUSED request_t *request, UNUSED fr_signal_t action)
Clear up when cancelling a mod_authorize call.
Definition rlm_ldap.c:2031
static const call_env_method_t xlat_memberof_method_env
Definition rlm_ldap.c:303
static int mod_detach(module_detach_ctx_t const *mctx)
Detach from the LDAP server and cleanup internal state.
Definition rlm_ldap.c:2413
static int mod_load(void)
Definition rlm_ldap.c:3028
static xlat_action_t ldap_profile_xlat_resume(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
Return whether evaluating the profile was successful.
Definition rlm_ldap.c:1151
map_list_t * profile_map
List of maps to apply to the profile.
Definition rlm_ldap.c:78
#define REPEAT_LDAP_MEMBEROF_XLAT_RESULTS
Definition rlm_ldap.c:964
static conf_parser_t profile_config[]
Definition rlm_ldap.c:101
static int ldap_map_verify(CONF_SECTION *cs, UNUSED void const *mod_inst, UNUSED void *proc_inst, tmpl_t const *src, UNUSED map_list_t const *maps)
Definition rlm_ldap.c:1406
fr_dict_attr_t const * attr_nt_password
Definition rlm_ldap.c:355
static xlat_arg_parser_t const ldap_safe_xlat_arg[]
Definition rlm_ldap.c:434
ldap_auth_call_env_t * call_env
Definition rlm_ldap.c:385
static const call_env_method_t authenticate_method_env
Definition rlm_ldap.c:227
fr_ldap_result_code_t ret
Definition rlm_ldap.c:1142
global_lib_autoinst_t const * rlm_ldap_lib[]
Definition rlm_ldap.c:372
static const call_env_method_t authorize_method_env
Definition rlm_ldap.c:250
#define USERMOD_ENV(_section)
Definition rlm_ldap.c:288
fr_value_box_t password
Definition rlm_ldap.c:55
#define SSS_CONTROL_BUILD(_obj)
static xlat_arg_parser_t const ldap_uri_unescape_xlat_arg[]
Definition rlm_ldap.c:487
static const call_env_method_t xlat_profile_method_env
Definition rlm_ldap.c:325
static xlat_arg_parser_t const ldap_uri_attr_option_xlat_arg[]
Definition rlm_ldap.c:561
static int ldap_mod_section_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, call_env_parser_t const *rule)
#define CHECK_EXPANDED_SPACE(_expanded)
static unlang_action_t mod_map_resume(unlang_result_t *p_result, map_ctx_t const *mpctx, request_t *request, UNUSED fr_value_box_list_t *url, UNUSED map_list_t const *maps)
Process the results of an LDAP map query.
Definition rlm_ldap.c:1430
static unlang_action_t mod_authorize_resume(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Resume function called after each potential yield in LDAP authorization.
Definition rlm_ldap.c:1755
#define LDAP_FILTER_CALL_ENV_ESCAPE
Definition rlm_ldap.c:210
map_list_t const * maps
Definition rlm_ldap.c:409
static size_t profile_search_mode_table_len
Definition rlm_ldap.c:99
fr_dict_attr_t const * attr_crypt_password
Definition rlm_ldap.c:354
fr_value_box_t user_filter
Definition rlm_ldap.c:70
static int ldap_group_filter_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
static fr_dict_t const * dict_freeradius
Definition rlm_ldap.c:344
static int map_ctx_free(ldap_map_ctx_t *map_ctx)
Ensure map context is properly cleared up.
Definition rlm_ldap.c:1526
fr_dict_attr_t const * cache_da
Definition rlm_ldap.c:50
static void ldap_query_timeout(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx)
Callback when LDAP query times out.
Definition rlm_ldap.c:538
static unlang_action_t user_modify_mod_build_resume(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition rlm_ldap.c:2167
fr_ldap_query_t * query
Current query performing the whoami operation.
Definition rlm_ldap.c:1309
static conf_parser_t user_config[]
Definition rlm_ldap.c:118
static fr_dict_attr_t const * attr_expr_bool_enum
Definition rlm_ldap.c:357
static fr_table_num_sorted_t const ldap_uri_scheme_table[]
Definition rlm_ldap.c:422
static xlat_arg_parser_t const ldap_xlat_arg[]
Definition rlm_ldap.c:742
static unlang_action_t mod_modify(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Modify user's object in LDAP.
Definition rlm_ldap.c:2345
static xlat_arg_parser_t const ldap_escape_xlat_arg[]
Definition rlm_ldap.c:429
fr_dict_attr_t const * group_da
Definition rlm_ldap.c:49
static unlang_action_t ldap_group_xlat_user_find(UNUSED unlang_result_t *p_result, request_t *request, void *uctx)
User object lookup as part of group membership xlat.
Definition rlm_ldap.c:937
fr_dict_attr_t const * attr_password
Definition rlm_ldap.c:352
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Bootstrap the module.
Definition rlm_ldap.c:2944
#define REPEAT_MOD_AUTHORIZE_RESUME
Definition rlm_ldap.c:1737
fr_value_box_t user_sasl_proxy
Definition rlm_ldap.c:59
fr_ldap_thread_trunk_t * ttrunk
Definition rlm_ldap.c:397
fr_value_box_t user_sasl_authname
Definition rlm_ldap.c:58
fr_dict_attr_t const * attr_password_with_header
Definition rlm_ldap.c:356
static int ldap_update_section_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, call_env_parser_t const *rule)
static unlang_action_t mod_authorize(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition rlm_ldap.c:2047
rlm_ldap_t const * inst
Definition rlm_ldap.c:392
static conf_parser_t group_config[]
Definition rlm_ldap.c:137
fr_ldap_query_t * query
Definition rlm_ldap.c:411
static void mod_unload(void)
Definition rlm_ldap.c:3086
fr_dict_attr_autoload_t rlm_ldap_dict_attr[]
Definition rlm_ldap.c:360
#define LDAP_DN_CALL_ENV_ESCAPE
Definition rlm_ldap.c:199
ldap_mod_tmpl_t ** mod
Definition rlm_ldap.c:71
static xlat_action_t ldap_group_xlat_resume(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
Process the results of evaluating LDAP group membership.
Definition rlm_ldap.c:1026
char const * attr
Definition rlm_ldap.c:64
static unlang_action_t ldap_group_xlat_results(unlang_result_t *p_result, request_t *request, void *uctx)
Run the state machine for the LDAP membership xlat.
Definition rlm_ldap.c:975
static void ldap_group_xlat_cancel(UNUSED request_t *request, UNUSED fr_signal_t action, void *uctx)
Cancel an in-progress query for the LDAP group membership xlat.
Definition rlm_ldap.c:955
ssize_t expect_password_offset
Definition rlm_ldap.c:247
static int ldap_xlat_uri_parse(LDAPURLDesc **uri_parsed, char **host_out, bool *free_host_out, request_t *request, char *host_default, fr_value_box_t *uri_in)
Utility function for parsing LDAP URLs.
Definition rlm_ldap.c:782
static unlang_action_t user_modify_final(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Handle results of user modification.
Definition rlm_ldap.c:2138
static int ldap_xlat_profile_ctx_free(ldap_xlat_profile_ctx_t *to_free)
Definition rlm_ldap.c:1164
static char * host_uri_canonify(request_t *request, LDAPURLDesc *url_parsed, fr_value_box_t *url_in)
Produce canonical LDAP host URI for finding trunks.
Definition rlm_ldap.c:751
fr_dict_attr_t const * attr_cleartext_password
Definition rlm_ldap.c:353
tmpl_t const * password_tmpl
Definition rlm_ldap.c:56
static xlat_action_t ldap_xlat_resume(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in)
Callback when resuming after async ldap query is completed.
Definition rlm_ldap.c:652
fr_value_box_t user_sasl_mech
Definition rlm_ldap.c:57
fr_dict_autoload_t rlm_ldap_dict[]
Definition rlm_ldap.c:347
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
Initialise thread specific data structure.
Definition rlm_ldap.c:2634
module_rlm_t rlm_ldap
Definition rlm_ldap.c:3101
char const * password
Definition rlm_ldap.c:382
static unlang_action_t mod_authenticate(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition rlm_ldap.c:1639
static int autz_ctx_free(ldap_autz_ctx_t *autz_ctx)
Ensure authorization context is properly cleared up.
Definition rlm_ldap.c:2041
ldap_schemes_t
Definition rlm_ldap.c:416
@ LDAP_SCHEME_UNIX
Definition rlm_ldap.c:417
@ LDAP_SCHEME_TCP_SSL
Definition rlm_ldap.c:419
@ LDAP_SCHEME_TCP
Definition rlm_ldap.c:418
fr_token_t op
Definition rlm_ldap.c:65
fr_value_box_t user_base
Definition rlm_ldap.c:69
fr_ldap_map_exp_t expanded
Definition rlm_ldap.c:1145
static void ldap_xlat_signal(xlat_ctx_t const *xctx, request_t *request, UNUSED fr_signal_t action)
Callback for signalling async ldap query.
Definition rlm_ldap.c:699
fr_ldap_query_t * query
Definition rlm_ldap.c:398
static fr_table_num_sorted_t const profile_search_mode_table[]
Definition rlm_ldap.c:94
fr_ldap_thread_t * thread
Definition rlm_ldap.c:384
static size_t ldap_uri_scheme_table_len
Definition rlm_ldap.c:427
static fr_uri_part_t const ldap_dn_parts[]
Definition rlm_ldap.c:737
static const conf_parser_t module_config[]
Definition rlm_ldap.c:156
#define USER_CALL_ENV_COMMON(_struct)
Definition rlm_ldap.c:221
ldap_usermod_call_env_t * call_env
Definition rlm_ldap.c:393
fr_value_box_t profile_filter
Filter to use when searching for users.
Definition rlm_ldap.c:77
static void user_modify_cancel(module_ctx_t const *mctx, UNUSED request_t *request, UNUSED fr_signal_t action)
Cancel an in progress user modification.
Definition rlm_ldap.c:2126
static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
Clean up thread specific data structure.
Definition rlm_ldap.c:2616
static int mod_instantiate(module_inst_ctx_t const *mctx)
Instantiate the module.
Definition rlm_ldap.c:2681
fr_ldap_map_exp_t expanded
Definition rlm_ldap.c:412
LDAPURLDesc * ldap_url
Definition rlm_ldap.c:410
static const call_env_parser_t sasl_call_env[]
Definition rlm_ldap.c:86
fr_value_box_t user_sasl_realm
Definition rlm_ldap.c:60
fr_value_box_list_t expanded
Definition rlm_ldap.c:399
static fr_uri_part_t const ldap_uri_parts[]
Definition rlm_ldap.c:725
fr_dict_attr_t const * user_da
Definition rlm_ldap.c:51
static unlang_action_t user_modify_resume(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Take the retrieved user DN and launch the async tmpl expansion of mod_values.
Definition rlm_ldap.c:2308
static void profile_dn_list_dedupe(char const **dn_list)
Remove duplicate DNs from a NULL terminated list, keeping the first occurrence.
Definition rlm_ldap.c:1719
char const * dn
Definition rlm_ldap.c:381
static xlat_arg_parser_t const ldap_group_xlat_arg[]
Definition rlm_ldap.c:1039
rlm_ldap_t const * inst
Definition rlm_ldap.c:383
Holds state of in progress async authentication.
Definition rlm_ldap.c:380
Holds state of in progress LDAP map.
Definition rlm_ldap.c:408
Parameters to allow ldap_update_section_parse to be reused.
Definition rlm_ldap.c:245
Holds state of in progress ldap user modifications.
Definition rlm_ldap.c:391
Call environment used in the profile xlat.
Definition rlm_ldap.c:76
State of an in progress whoami extended operation.
Definition rlm_ldap.c:1308
LDAP authorization and authentication module headers.
static char const * rlm_ldap_profile_attr_select(char const *attr, char const *attr_suspend, ldap_access_state_t access_state)
Return the profile attribute matching the user's access state.
Definition rlm_ldap.h:249
@ LDAP_PROFILE_SEARCH_MODE_AUTO
Resolved at instantiation, LDAP_PROFILE_SEARCH_MODE_BULK when server side sorting is configured and t...
Definition rlm_ldap.h:24
@ LDAP_PROFILE_SEARCH_MODE_BULK
A single search retrieving every profile object, applied in result order.
Definition rlm_ldap.h:28
@ LDAP_PROFILE_SEARCH_MODE_SEQ
One search per profile DN, applied in list order.
Definition rlm_ldap.h:27
fr_ldap_map_exp_t expanded
Definition rlm_ldap.h:227
ldap_autz_call_env_t * call_env
Definition rlm_ldap.h:230
@ LDAP_ACCESS_SUSPENDED
User account has been suspended.
Definition rlm_ldap.h:218
@ LDAP_ACCESS_ALLOWED
User is allowed to login.
Definition rlm_ldap.h:216
@ LDAP_ACCESS_DISALLOWED
User it not allow to login (disabled)
Definition rlm_ldap.h:217
fr_ldap_thread_trunk_t * ttrunk
Definition rlm_ldap.h:229
rlm_ldap_t const * inst
Definition rlm_ldap.h:226
fr_value_box_t profile_filter
Filter to use when searching for profiles.
Definition rlm_ldap.h:177
fr_value_box_t user_filter
Filter to use when searching for users.
Definition rlm_ldap.h:169
LDAPMessage * entry
Definition rlm_ldap.h:231
@ LDAP_AUTZ_GROUP
Definition rlm_ldap.h:200
@ LDAP_AUTZ_POST_PROFILES
Definition rlm_ldap.h:209
@ LDAP_AUTZ_FIND
Definition rlm_ldap.h:199
@ LDAP_AUTZ_PROFILES
Definition rlm_ldap.h:208
@ LDAP_AUTZ_MAP
Definition rlm_ldap.h:207
@ LDAP_AUTZ_GROUP_PROFILES
Definition rlm_ldap.h:201
@ LDAP_AUTZ_POST_GROUP
Definition rlm_ldap.h:202
char const ** profile_dn_list
List of profile DNs to apply, default profile first, then group profiles, then profiles from the user...
Definition rlm_ldap.h:233
ldap_autz_status_t status
Definition rlm_ldap.h:232
fr_value_box_t profile_child_rdn
RDN of a child object to evaluate below each profile.
Definition rlm_ldap.h:176
fr_ldap_query_t * query
Definition rlm_ldap.h:228
ldap_access_state_t access_state
What state a user's account is in.
Definition rlm_ldap.h:240
unlang_action_t rlm_ldap_find_user_async(TALLOC_CTX *ctx, unlang_result_t *p_result, rlm_ldap_t const *inst, request_t *request, fr_value_box_t *base, fr_value_box_t *filter_box, fr_ldap_thread_trunk_t *ttrunk, char const *attrs[], fr_ldap_query_t **query_out)
Initiate asynchronous retrieval of the DN of a user object.
Definition user.c:166
fr_value_box_t user_base
Base DN in which to search for users.
Definition rlm_ldap.h:168
int profiles_applied
Number of profile maps applied.
Definition rlm_ldap.h:238
char const * dn
Definition rlm_ldap.h:239
map_list_t * user_map
Attribute map applied to users and profiles.
Definition rlm_ldap.h:179
rlm_rcode_t rcode
What rcode we'll finally respond with.
Definition rlm_ldap.h:241
static char const * rlm_find_user_dn_cached(rlm_ldap_t const *inst, request_t *request)
Definition rlm_ldap.h:305
talloc_str_list_t * group_profile_dn_list
Profile DNs found in the user's group objects.
Definition rlm_ldap.h:237
void rlm_ldap_check_reply(request_t *request, rlm_ldap_t const *inst, char const *inst_name, bool expect_password, fr_ldap_thread_trunk_t const *ttrunk)
Verify we got a password from the search.
Definition user.c:258
fr_value_box_t const * expect_password
True if the user_map included a mapping between an LDAP attribute and one of our password reference a...
Definition rlm_ldap.h:181
fr_value_box_t default_profile
If this is set, we will search for a profile object with this name, and map any attributes it contain...
Definition rlm_ldap.h:172
@ GROUP_XLAT_MEMB_FILTER
Definition rlm_ldap.h:270
@ GROUP_XLAT_MEMB_ATTR
Definition rlm_ldap.h:271
@ GROUP_XLAT_FIND_USER
Definition rlm_ldap.h:269
talloc_str_list_t * group_dn_list
DNs of the group objects the user is a member of.
Definition rlm_ldap.h:236
module_instance_t const * dlinst
Definition rlm_ldap.h:225
ldap_access_state_t rlm_ldap_check_access(rlm_ldap_t const *inst, request_t *request, LDAPMessage *entry)
Check for presence of access attribute in result.
Definition user.c:212
Call environment used in LDAP authorization.
Definition rlm_ldap.h:167
Holds state of in progress async authorization.
Definition rlm_ldap.h:224
Holds state of in progress group membership check xlat.
Definition rlm_ldap.h:277
Call environment used in group membership xlat.
Definition rlm_ldap.h:188
unlang_action_t fr_ldap_sasl_bind_auth_async(unlang_result_t *p_result, request_t *request, fr_ldap_thread_t *thread, char const *mechs, char const *identity, char const *password, char const *proxy, char const *realm)
Initiate an async SASL LDAP bind for authentication.
Definition sasl.c:504
int fr_sbuff_trim_talloc(fr_sbuff_t *sbuff, size_t len)
Trim a talloced sbuff to the minimum length required to represent the contained string.
Definition sbuff.c:433
#define FR_SBUFF_IN(_start, _len_or_end)
#define FR_SBUFF_TERMS(...)
Initialise a terminal structure with a list of sorted strings.
Definition sbuff.h:190
#define fr_sbuff_buff(_sbuff_or_marker)
Talloc sbuff extension structure.
Definition sbuff.h:137
static char const * section_name_str(char const *name)
Return a printable string for the section name.
Definition section.h:97
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:39
char const * name2
Second section name. Usually a packet type like 'access-request', 'access-accept',...
Definition section.h:45
char const * name1
First section name. Usually a verb like 'recv', 'send', etc...
Definition section.h:44
#define MODULE_THREAD_INST(_ctype)
Definition module.h:260
char const * name
Instance name e.g. user_database.
Definition module.h:359
module_flags_t flags
Flags that control how a module starts up and how a module is called.
Definition module.h:236
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:353
void * data
Module's instance data.
Definition module.h:295
#define MODULE_BOOT(_ctype)
Definition module.h:258
void * boot
Data allocated during the boostrap phase.
Definition module.h:298
void * data
Thread specific instance data.
Definition module.h:376
static module_thread_instance_t * module_thread(module_instance_t const *mi)
Retrieve module/thread specific instance for a module.
Definition module.h:515
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Definition module.h:152
#define MODULE_INST(_ctype)
Definition module.h:259
Named methods exported by a module.
Definition module.h:174
static tmpl_attr_t const * tmpl_attr_tail(tmpl_t const *vpt)
Return the last attribute reference.
Definition tmpl.h:790
int tmpl_resolve(tmpl_t *vpt, tmpl_res_rules_t const *tr_rules))
Attempt to resolve functions and attributes in xlats and attribute references.
ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_token_t quote, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Convert an arbitrary string into a tmpl_t.
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
Definition tmpl.h:339
#define tmpl_needs_resolving(vpt)
Definition tmpl.h:223
Similar to tmpl_rules_t, but used to specify parameters that may change during subsequent resolution ...
Definition tmpl.h:368
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:336
fr_signal_t
Signals that can be generated/processed by request signal handlers.
Definition signal.h:38
@ FR_SIGNAL_CANCEL
Request has been cancelled.
Definition signal.h:40
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
Definition snprintf.c:689
unlang_action_t unlang_module_yield(request_t *request, module_method_t resume, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx)
Yield a request back to the interpreter from within a module.
Definition module.c:431
eap_aka_sim_process_conf_t * inst
Value pair map.
Definition map.h:77
tmpl_t * lhs
Typically describes the attribute to add, modify or compare.
Definition map.h:78
fr_dict_t const * dict_def
Default dictionary to use with unqualified attribute references.
Definition tmpl.h:273
An element in a list of nested attribute references.
Definition tmpl.h:434
fr_dict_attr_t const *_CONST da
Resolved dictionary attribute.
Definition tmpl.h:438
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
#define fr_table_value_by_str(_table, _name, _def)
Convert a string to a value using a sorted or ordered table.
Definition table.h:685
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
Definition table.h:804
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
char * talloc_typed_strdup_buffer(TALLOC_CTX *ctx, char const *p)
Call talloc_strndup, setting the type on the new chunk correctly.
Definition talloc.c:496
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
Definition talloc.c:546
#define talloc_get_type_abort_const
Definition talloc.h:117
char const ** strings
NULL terminated array of strings.
Definition talloc.h:254
static size_t talloc_str_list_num(talloc_str_list_t const *list)
Return the number of strings in a string list.
Definition talloc.h:268
#define talloc_asprintf
Definition talloc.h:151
#define talloc_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size)
Definition talloc.h:211
#define talloc_strdup(_ctx, _str)
Definition talloc.h:149
static size_t talloc_strlen(char const *s)
Returns the length of a talloc array containing a string.
Definition talloc.h:143
A NULL terminated array of strings with an append cursor.
Definition talloc.h:253
"server local" time.
Definition time.h:69
An event timer list.
Definition timer.c:49
#define fr_timer_in(...)
Definition timer.h:87
int unlang_tmpl_push(TALLOC_CTX *ctx, unlang_result_t *p_result, fr_value_box_list_t *out, request_t *request, tmpl_t const *tmpl, unlang_tmpl_args_t *args, bool top_frame)
Push a tmpl onto the stack for evaluation.
Definition tmpl.c:276
fr_table_num_ordered_t const fr_tokens_table[]
Definition token.c:33
enum fr_token fr_token_t
@ T_OP_SUB_EQ
Definition token.h:68
@ T_SINGLE_QUOTED_STRING
Definition token.h:120
@ T_BARE_WORD
Definition token.h:118
@ T_OP_SET
Definition token.h:82
@ T_OP_ADD_EQ
Definition token.h:67
@ T_OP_CMP_FALSE
Definition token.h:103
@ T_OP_INCRM
Definition token.h:111
int module_trigger_args_build(TALLOC_CTX *ctx, fr_pair_list_t *list, CONF_SECTION const *cs, module_trigger_args_t *args)
Build trigger args pair list for modules.
Definition trigger.c:504
Common values used by modules when building trigger args.
Definition trigger.h:42
trunk_enqueue_t trunk_request_enqueue(trunk_request_t **treq_out, trunk_t *trunk, request_t *request, void *preq, void *rctx)
Enqueue a request that needs data written to the trunk.
Definition trunk.c:2657
void trunk_request_signal_cancel(trunk_request_t *treq)
Cancel a trunk request.
Definition trunk.c:2216
conf_parser_t const trunk_config[]
Config parser definitions to populate a trunk_conf_t.
Definition trunk.c:345
Wraps a normal request.
Definition trunk.c:99
@ TRUNK_ENQUEUE_OK
Operation was successful.
Definition trunk.h:160
@ TRUNK_ENQUEUE_IN_BACKLOG
Request should be enqueued in backlog.
Definition trunk.h:159
static unsigned count
Definition unittest.c:47
xlat_action_t unlang_xlat_yield(request_t *request, xlat_func_t resume, xlat_func_signal_t signal, fr_signal_t sigmask, void *rctx)
Yield a request back to the interpreter from within a module.
Definition xlat.c:543
void xlat_arg_copy_out(TALLOC_CTX *ctx, fr_dcursor_t *cursor, fr_value_box_list_t *in, fr_value_box_t *vb)
Copy an argument from the input list to the output cursor.
xlat_action_t xlat_transparent(UNUSED TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *args)
#define XLAT_ARGS(_list,...)
Populate local variables with value boxes from the input list.
Definition xlat.h:373
unsigned int required
Argument must be present, and non-empty.
Definition xlat.h:136
#define XLAT_ARG_PARSER_TERMINATOR
Definition xlat.h:160
xlat_action_t
Definition xlat.h:37
@ XLAT_ACTION_FAIL
An xlat function failed.
Definition xlat.h:44
@ XLAT_ACTION_YIELD
An xlat function pushed a resume frame onto the stack.
Definition xlat.h:42
@ XLAT_ACTION_PUSH_UNLANG
An xlat function pushed an unlang frame onto the unlang stack.
Definition xlat.h:39
@ XLAT_ACTION_DONE
We're done evaluating this level of nesting.
Definition xlat.h:43
Definition for a single argument consumed by an xlat function.
Definition xlat.h:135
int fr_uri_escape_list(fr_value_box_list_t *uri, fr_uri_part_t const *uri_parts, void *uctx)
Parse a list of value boxes representing a URI.
Definition uri.c:148
int fr_uri_has_scheme(fr_value_box_list_t *uri, fr_table_num_sorted_t const *schemes, size_t schemes_len, int def)
Searches for a matching scheme in the table of schemes, using a list of value boxes representing the ...
Definition uri.c:175
#define XLAT_URI_PART_TERMINATOR
Definition uri.h:66
char const * name
Name of this part of the URI.
Definition uri.h:47
Definition for a single part of a URI.
Definition uri.h:46
#define FR_TYPE_FIXED_SIZE
Definition types.h:310
int fr_value_box_asprintf(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, bool tainted, char const *fmt,...)
Print a formatted string using our internal printf wrapper and assign it to a value box.
Definition value.c:4737
fr_sbuff_parse_rules_t const * value_parse_rules_quoted[T_TOKEN_LAST]
Parse rules for quoted strings.
Definition value.c:611
int fr_value_box_cast_in_place(TALLOC_CTX *ctx, fr_value_box_t *vb, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv)
Convert one type of fr_value_box_t to another in place.
Definition value.c:4224
void fr_value_box_strdup_shallow(fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted)
Assign a buffer containing a nul terminated string to a box, but don't copy it.
Definition value.c:4759
int fr_value_box_bstr_realloc(TALLOC_CTX *ctx, char **out, fr_value_box_t *dst, size_t len)
Change the length of a buffer already allocated to a value box.
Definition value.c:4859
int fr_value_box_bstrndup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, size_t len, bool tainted)
Copy a string to to a fr_value_box_t.
Definition value.c:4900
int fr_value_box_bstrdup_buffer_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted)
Assign a talloced buffer containing a nul terminated string to a box, but don't copy it.
Definition value.c:5008
int fr_value_box_list_concat_in_place(TALLOC_CTX *ctx, fr_value_box_t *out, fr_value_box_list_t *list, fr_type_t type, fr_value_box_list_action_t proc_action, bool flatten, size_t max_size)
Concatenate a list of value boxes.
Definition value.c:6669
@ FR_VALUE_BOX_LIST_FREE
Definition value.h:261
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
Definition value.h:669
#define fr_value_box_is_safe_for_only(_box, _safe_for)
Definition value.h:1133
#define fr_box_is_null(_x)
Definition value.h:449
int nonnull(2, 5))
#define fr_value_box_alloc_null(_ctx)
Allocate a value box for later use with a value assignment function.
Definition value.h:680
static size_t char ** out
Definition value.h:1062
static TALLOC_CTX * xlat_ctx
void * rctx
Resume context.
Definition xlat_ctx.h:54
void * env_data
Expanded call env data.
Definition xlat_ctx.h:53
module_ctx_t const * mctx
Synthesised module calling ctx.
Definition xlat_ctx.h:52
An xlat calling ctx.
Definition xlat_ctx.h:49
void xlat_func_flags_set(xlat_t *x, xlat_func_flags_t flags)
Specify flags that alter the xlat's behaviour.
Definition xlat_func.c:401
int xlat_func_args_set(xlat_t *x, xlat_arg_parser_t const args[])
Register the arguments of an xlat.
Definition xlat_func.c:374
void xlat_func_call_env_set(xlat_t *x, call_env_method_t const *env_method)
Register call environment of an xlat.
Definition xlat_func.c:391
xlat_t * xlat_func_register(TALLOC_CTX *ctx, char const *name, xlat_func_t func, fr_type_t return_type)
Register an xlat function.
Definition xlat_func.c:225
void xlat_func_unregister(char const *name)
Unregister an xlat function.
Definition xlat_func.c:519
#define xlat_func_safe_for_set(_xlat, _escaped)
Set the escaped values for output boxes.
Definition xlat_func.h:83
@ XLAT_FUNC_FLAG_PURE
Definition xlat_func.h:38