The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
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: 5c49561ded8961399492386af41bdf48f3072ea3 $
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: 5c49561ded8961399492386af41bdf48f3072ea3 $")
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_V3_DEPRECATED("attribute", rlm_ldap_t, user.profile_attr) },
107 { FR_CONF_V3_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
536 { .required = true, .concat = true, .type = FR_TYPE_STRING },
537 { .required = true, .concat = true, .type = FR_TYPE_STRING },
539};
540
541/** Modify an LDAP URI to append an option to all attributes
542 *
543 * This is for the corner case where a URI is provided by a third party system
544 * and needs amending before being used. e.g. a CRL distribution point extracted
545 * from a certificate may need the "binary" option appending to the attribute
546 * being requested.
547 *
548 * @ingroup xlat_functions
549 */
551 request_t *request, fr_value_box_list_t *in)
552{
553 fr_value_box_t *uri, *option_vb;
554 char *attrs_fixed, **attr, port[6];
555 char const *option;
556 LDAPURLDesc *ldap_url;
557 fr_value_box_t *vb;
558 int ret;
559
560 XLAT_ARGS(in, &uri, &option_vb);
561
562#ifdef STATIC_ANALYZER
563 if (!option_vb) return XLAT_ACTION_FAIL;
564#endif
565
566 if (option_vb->vb_length < 1) {
567 RERROR("LDAP attriubte option must not be blank");
568 return XLAT_ACTION_FAIL;
569 }
570
571 if (!ldap_is_ldap_url(uri->vb_strvalue)) {
572 REDEBUG("String passed does not look like an LDAP URL");
573 return XLAT_ACTION_FAIL;
574 }
575
576 ret = ldap_url_parse(uri->vb_strvalue, &ldap_url);
577 if (ret != LDAP_URL_SUCCESS){
578 RPEDEBUG("Parsing LDAP URL failed - %s", fr_ldap_url_err_to_str(ret));
579 return XLAT_ACTION_FAIL;
580 }
581
582 /*
583 * No attributes, just return what was presented.
584 */
585 if (!ldap_url->lud_attrs || !ldap_url->lud_attrs[0] || !*ldap_url->lud_attrs[0]) {
586 xlat_arg_copy_out(ctx, out, in, uri);
587 goto done;
588 }
589
590 if (option_vb->vb_strvalue[0] != ';') {
591 option = talloc_asprintf(option_vb, ";%s", option_vb->vb_strvalue);
592 } else {
593 option = option_vb->vb_strvalue;
594 }
595
596 MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_STRING, NULL));
597 attrs_fixed = talloc_strdup(vb, "");
598
599 attr = ldap_url->lud_attrs;
600 while (*attr) {
601 attrs_fixed = talloc_strdup_append(attrs_fixed, *attr);
602 if (!strstr(*attr, option)) attrs_fixed = talloc_strdup_append(attrs_fixed, option);
603 attr++;
604 if (*attr) attrs_fixed = talloc_strdup_append(attrs_fixed, ",");
605 }
606
607 snprintf(port, sizeof(port), "%d", ldap_url->lud_port);
608 fr_value_box_asprintf(vb, vb, NULL, uri->tainted, "%s://%s%s%s/%s?%s?%s?%s",
609 ldap_url->lud_scheme,
610 ldap_url->lud_host ? ldap_url->lud_host : "",
611 ldap_url->lud_host ? ":" : "",
612 ldap_url->lud_host ? port : "",
613 ldap_url->lud_dn, attrs_fixed,
614 fr_table_str_by_value(fr_ldap_scope, ldap_url->lud_scope, ""),
615 ldap_url->lud_filter ? ldap_url->lud_filter : "");
616
618done:
619 ldap_free_urldesc(ldap_url);
620 return XLAT_ACTION_DONE;
621}
622
623/** Callback when resuming after async ldap query is completed
624 *
625 */
627 xlat_ctx_t const *xctx,
628 request_t *request, UNUSED fr_value_box_list_t *in)
629{
630 fr_ldap_query_t *query = talloc_get_type_abort(xctx->rctx, fr_ldap_query_t);
631 fr_ldap_connection_t *ldap_conn = query->ldap_conn;
632 fr_value_box_t *vb = NULL;
633 LDAPMessage *msg;
634 struct berval **values;
635 char const **attr;
636 int count, i;
637
638 if (query->ret != LDAP_RESULT_SUCCESS) return XLAT_ACTION_FAIL;
639
640 /*
641 * We only parse "entries"
642 */
643 for (msg = ldap_first_entry(ldap_conn->handle, query->result); msg; msg = ldap_next_entry(ldap_conn->handle, msg)) {
644 for (attr = query->search.attrs; *attr; attr++) {
645 values = ldap_get_values_len(ldap_conn->handle, msg, *attr);
646 if (!values) {
647 RDEBUG2("No \"%s\" attributes found in specified object", *attr);
648 continue;
649 }
650
651 count = ldap_count_values_len(values);
652 for (i = 0; i < count; i++) {
653 MEM(vb = fr_value_box_alloc_null(ctx));
654 if (fr_value_box_bstrndup(vb, vb, NULL, values[i]->bv_val, values[i]->bv_len, true) < 0) {
655 talloc_free(vb);
656 RPERROR("Failed creating value from LDAP response");
657 break;
658 }
660 }
661 ldap_value_free_len(values);
662 }
663 }
664
665 talloc_free(query);
666
667 return XLAT_ACTION_DONE;
668}
669
670/** Callback for signalling async ldap query
671 *
672 */
674{
675 fr_ldap_query_t *query = talloc_get_type_abort(xctx->rctx, fr_ldap_query_t);
676 trunk_request_t *treq = query->treq;
677
678 if (!treq) return;
679
680 RDEBUG2("Forcefully cancelling pending LDAP query");
681
682 /*
683 * The LDAP query needs to persist until the trunk
684 * request cancellation is complete.
685 */
686 talloc_steal(treq, query);
687 query->treq = NULL;
688
690}
691
692/*
693 * If a part doesn't have an escaping function, parsing will fail unless the input
694 * was marked up with a safe_for value by the ldap arg parsing, i.e. was a literal
695 * input argument to the xlat.
696 *
697 * This is equivalent to the old "tainted_allowed" flag.
698 */
700 { .name = "scheme", .safe_for = LDAP_DN_SAFE_FOR, .terminals = &FR_SBUFF_TERMS(L(":")), .part_adv = { [':'] = 1 }, .extra_skip = 2 },
701 { .name = "host", .safe_for = LDAP_DN_SAFE_FOR, .terminals = &FR_SBUFF_TERMS(L(":"), L("/")), .part_adv = { [':'] = 1, ['/'] = 2 } },
702 { .name = "port", .safe_for = LDAP_DN_SAFE_FOR, .terminals = &FR_SBUFF_TERMS(L("/")), .part_adv = { ['/'] = 1 } },
703 { .name = "dn", .safe_for = LDAP_DN_SAFE_FOR, .terminals = &FR_SBUFF_TERMS(L("?")), .part_adv = { ['?'] = 1 }, .func = fr_ldap_dn_box_escape },
704 { .name = "attrs", .safe_for = LDAP_DN_SAFE_FOR, .terminals = &FR_SBUFF_TERMS(L("?")), .part_adv = { ['?'] = 1 }},
705 { .name = "scope", .safe_for = LDAP_DN_SAFE_FOR, .terminals = &FR_SBUFF_TERMS(L("?")), .part_adv = { ['?'] = 1 }, .func = fr_ldap_dn_box_escape },
706 { .name = "filter", .safe_for = LDAP_DN_SAFE_FOR, .terminals = &FR_SBUFF_TERMS(L("?")), .part_adv = { ['?'] = 1}, .func = fr_ldap_dn_box_escape },
707 { .name = "exts", .safe_for = LDAP_DN_SAFE_FOR, .func = fr_ldap_dn_box_escape },
709};
710
711static fr_uri_part_t const ldap_dn_parts[] = {
712 { .name = "dn", .safe_for = LDAP_DN_SAFE_FOR , .func = fr_ldap_dn_box_escape },
714};
715
717 { .required = true, .type = FR_TYPE_STRING, .safe_for = LDAP_DN_SAFE_FOR, .will_escape = true, },
719};
720
721/** Produce canonical LDAP host URI for finding trunks
722 *
723 */
724static inline CC_HINT(always_inline)
725char *host_uri_canonify(request_t *request, LDAPURLDesc *url_parsed, fr_value_box_t *url_in)
726{
727 char *host;
728
729 LDAPURLDesc tmp_desc = {
730 .lud_scheme = url_parsed->lud_scheme,
731 .lud_host = url_parsed->lud_host,
732 .lud_port = url_parsed->lud_port,
733 .lud_scope = -1
734 };
735 host = ldap_url_desc2str(&tmp_desc);
736 if (unlikely(host == NULL)) REDEBUG("Invalid LDAP URL - %pV", url_in); \
737
738 return host;
739}
740
741/** Utility function for parsing LDAP URLs
742 *
743 * All LDAP xlat functions that work with LDAP URLs should call this function to parse the URL.
744 *
745 * @param[out] uri_parsed LDAP URL parsed. Must be freed with ldap_url_desc_free.
746 * @param[out] host_out host name to use for the query. Must be freed with ldap_mem_free
747 * if free_host_out is true.
748 * @param[out] free_host_out True if host_out should be freed.
749 * @param[in] request Request being processed.
750 * @param[in] host_default Default host to use if the URL does not specify a host.
751 * @param[in] uri_in URI to parse.
752 * @return
753 * - 0 on success.
754 * - -1 on failure.
755 */
756static int ldap_xlat_uri_parse(LDAPURLDesc **uri_parsed, char **host_out, bool *free_host_out,
757 request_t *request, char *host_default, fr_value_box_t *uri_in)
758{
759 fr_value_box_t *uri;
760 int ldap_url_ret;
761
762 *free_host_out = false;
763
764 if (fr_uri_escape_list(&uri_in->vb_group, ldap_uri_parts, NULL) < 0){
765 RPERROR("Failed to escape LDAP URI");
766 error:
767 *uri_parsed = NULL;
768 return -1;
769 }
770
771 /*
772 * Smush everything into the first URI box
773 */
774 uri = fr_value_box_list_head(&uri_in->vb_group);
775
776 if (fr_value_box_list_concat_in_place(uri, uri, &uri_in->vb_group,
777 FR_TYPE_STRING, FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
778 RPEDEBUG("Failed concatenating input");
779 goto error;
780 }
781
782 if (!ldap_is_ldap_url(uri->vb_strvalue)) {
783 REDEBUG("String passed does not look like an LDAP URL");
784 goto error;
785 }
786
787 ldap_url_ret = ldap_url_parse(uri->vb_strvalue, uri_parsed);
788 if (ldap_url_ret != LDAP_URL_SUCCESS){
789 RPEDEBUG("Parsing LDAP URL failed - %s", fr_ldap_url_err_to_str(ldap_url_ret));
790 goto error;
791 }
792
793 /*
794 * If the URL is <scheme>:/// the parsed host will be NULL - use config default
795 */
796 if (!(*uri_parsed)->lud_host) {
797 *host_out = host_default;
798 } else {
799 *host_out = host_uri_canonify(request, *uri_parsed, uri);
800 if (unlikely(*host_out == NULL)) {
801 ldap_free_urldesc(*uri_parsed);
802 *uri_parsed = NULL;
803 return -1;
804 }
805 *free_host_out = true;
806 }
807
808 return 0;
809}
810
811/** Expand an LDAP URL into a query, and return a string result from that query.
812 *
813 * @ingroup xlat_functions
814 */
816 xlat_ctx_t const *xctx,
817 request_t *request, fr_value_box_list_t *in)
818{
819 fr_ldap_thread_t *t = talloc_get_type_abort(xctx->mctx->thread, fr_ldap_thread_t);
820 fr_value_box_t *uri;
821 char *host;
822 bool free_host = false;
823 fr_ldap_config_t const *handle_config = t->config;
825 fr_ldap_query_t *query = NULL;
826
827 LDAPURLDesc *ldap_url;
828
829 XLAT_ARGS(in, &uri);
830
831 if (ldap_xlat_uri_parse(&ldap_url, &host, &free_host, request, handle_config->server, uri) < 0) return XLAT_ACTION_FAIL;
832
833 /*
834 * Nothing, empty string, "*" string, or got 2 things, die.
835 */
836 if (!ldap_url->lud_attrs || !ldap_url->lud_attrs[0] || !*ldap_url->lud_attrs[0] ||
837 (strcmp(ldap_url->lud_attrs[0], "*") == 0) || ldap_url->lud_attrs[1]) {
838 REDEBUG("Bad attributes list in LDAP URL. URL must specify exactly one attribute to retrieve");
839 ldap_free_urldesc(ldap_url);
840 return XLAT_ACTION_FAIL;
841 }
842
844 ldap_url->lud_dn, ldap_url->lud_scope, ldap_url->lud_filter,
845 (char const * const*)ldap_url->lud_attrs, NULL, NULL);
846 query->ldap_url = ldap_url; /* query destructor will free URL */
847
848 if (ldap_url->lud_exts) {
849 LDAPControl *serverctrls[LDAP_MAX_CONTROLS];
850 int i;
851
852 serverctrls[0] = NULL;
853
854 if (fr_ldap_parse_url_extensions(serverctrls, NUM_ELEMENTS(serverctrls),
855 query->ldap_url->lud_exts) < 0) {
856 RPERROR("Parsing URL extensions failed");
857 if (free_host) ldap_memfree(host);
858
859 query_error:
860 talloc_free(query);
861 return XLAT_ACTION_FAIL;
862 }
863
864 for (i = 0; i < LDAP_MAX_CONTROLS; i++) {
865 if (!serverctrls[i]) break;
866 query->serverctrls[i].control = serverctrls[i];
867 query->serverctrls[i].freeit = true;
868 }
869 }
870
871 /*
872 * Figure out what trunked connection we can use
873 * to communicate with the host.
874 *
875 * If free_host is true, we must free the host
876 * after deciding on a trunk connection as it
877 * was allocated by host_uri_canonify.
878 */
879 ttrunk = fr_thread_ldap_trunk_get(t, host, handle_config->admin_identity,
880 handle_config->admin_password, request, handle_config);
881 if (free_host) ldap_memfree(host);
882 if (!ttrunk) {
883 REDEBUG("Unable to get LDAP query for xlat");
884 goto query_error;
885 }
886
887 switch (trunk_request_enqueue(&query->treq, ttrunk->trunk, request, query, NULL)) {
888 case TRUNK_ENQUEUE_OK:
890 break;
891
892 default:
893 REDEBUG("Unable to enqueue LDAP query for xlat");
894 goto query_error;
895 }
896
898}
899
900/** Cancel an in-progress query for the LDAP group membership xlat
901 *
902 */
904{
905 ldap_group_xlat_ctx_t *xlat_ctx = talloc_get_type_abort(uctx, ldap_group_xlat_ctx_t);
906
907 if (!xlat_ctx->query || !xlat_ctx->query->treq) return;
908
910}
911
912#define REPEAT_LDAP_MEMBEROF_XLAT_RESULTS \
913 if (unlang_function_repeat_set(request, ldap_group_xlat_results) < 0) do { \
914 RETURN_UNLANG_FAIL; \
915 } while (0)
916
917/** Run the state machine for the LDAP membership xlat
918 *
919 * This is called after each async lookup is completed
920 *
921 * Will stop early, and set p_result to unlang_result
922 */
924{
925 ldap_group_xlat_ctx_t *xlat_ctx = talloc_get_type_abort(uctx, ldap_group_xlat_ctx_t);
926 rlm_ldap_t const *inst = xlat_ctx->inst;
927
928 /*
929 * Check to see if rlm_ldap_check_groupobj_dynamic or rlm_ldap_check_userobj_dynamic failed
930 */
932
933 switch (xlat_ctx->status) {
937
938 RDEBUG3("Entered GROUP_XLAT_FIND_USER with user DN \"%s\"", xlat_ctx->dn);
939 if (inst->group.obj_membership_filter) {
941 RDEBUG3("Checking for user in group objects");
945 }
946 }
948
950 if (xlat_ctx->found) RETURN_UNLANG_OK;
951
952 RDEBUG3("Entered GROUP_XLAT_MEMB_FILTER with user DN \"%s\"", xlat_ctx->dn);
953 if (inst->group.userobj_membership_attr) {
958 }
959 }
961
963 RDEBUG3("Entered GROUP_XLAT_MEMB_ATTR with user DN \"%s\"", xlat_ctx->dn);
964 if (xlat_ctx->found) RETURN_UNLANG_OK;
965 break;
966 }
967
969}
970
971/** Process the results of evaluating LDAP group membership
972 *
973 */
974static xlat_action_t ldap_group_xlat_resume(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx,
975 UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
976{
977 ldap_group_xlat_ctx_t *xlat_ctx = talloc_get_type_abort(xctx->rctx, ldap_group_xlat_ctx_t);
978 fr_value_box_t *vb;
979
981 vb->vb_bool = xlat_ctx->found;
983
984 return XLAT_ACTION_DONE;
985}
986
988 { .required = true, .concat = true, .type = FR_TYPE_STRING, .safe_for = LDAP_DN_SAFE_FOR },
990};
991
992/** Check for a user being in a LDAP group
993 *
994 * @ingroup xlat_functions
995 */
996static xlat_action_t ldap_group_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx,
997 request_t *request, fr_value_box_list_t *in)
998{
999 fr_value_box_t *vb = NULL, *group_vb = fr_value_box_list_pop_head(in);
1001 fr_ldap_thread_t *t = talloc_get_type_abort(xctx->mctx->thread, fr_ldap_thread_t);
1002 ldap_xlat_memberof_call_env_t *env_data = talloc_get_type_abort(xctx->env_data, ldap_xlat_memberof_call_env_t);
1003 bool group_is_dn;
1005
1006 RDEBUG2("Searching for user in group \"%pV\"", group_vb);
1007
1008 if (group_vb->vb_length == 0) {
1009 REDEBUG("Cannot do comparison (group name is empty)");
1010 return XLAT_ACTION_FAIL;
1011 }
1012
1013 group_is_dn = fr_ldap_util_is_dn(group_vb->vb_strvalue, group_vb->vb_length);
1014 if (group_is_dn) {
1015 char *norm;
1016 size_t len;
1017
1018 MEM(norm = talloc_array(group_vb, char, talloc_array_length(group_vb->vb_strvalue)));
1019 len = fr_ldap_util_normalise_dn(norm, group_vb->vb_strvalue);
1020
1021 /*
1022 * Will clear existing buffer (i.e. group_vb->vb_strvalue)
1023 */
1024 fr_value_box_bstrdup_buffer_shallow(group_vb, group_vb, NULL, norm, group_vb->tainted);
1025
1026 /*
1027 * Trim buffer to match normalised DN
1028 */
1029 fr_value_box_bstr_realloc(group_vb, NULL, group_vb, len);
1030 }
1031
1032 if ((group_is_dn && inst->group.cacheable_dn) || (!group_is_dn && inst->group.cacheable_name)) {
1033 unlang_result_t our_result;
1034
1035 rlm_ldap_check_cached(&our_result, inst, request, group_vb);
1036 switch (our_result.rcode) {
1038 RDEBUG2("User is not a member of \"%pV\"", group_vb);
1039 return XLAT_ACTION_DONE;
1040
1041 case RLM_MODULE_OK:
1042 MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_BOOL, NULL));
1043 vb->vb_bool = true;
1045 return XLAT_ACTION_DONE;
1046
1047 /*
1048 * Fallback to dynamic search
1049 */
1050 default:
1051 break;
1052 }
1053 }
1054
1056
1058 .inst = inst,
1059 .group = group_vb,
1061 .attrs = { inst->group.userobj_membership_attr, NULL },
1062 .group_is_dn = group_is_dn,
1063 .env_data = env_data
1064 };
1065
1066 xlat_ctx->ttrunk = fr_thread_ldap_trunk_get(t, inst->handle_config.server, inst->handle_config.admin_identity,
1067 inst->handle_config.admin_password, request, &inst->handle_config);
1068
1069 if (!xlat_ctx->ttrunk) {
1070 REDEBUG("Unable to get LDAP trunk for group membership check");
1071 error:
1073 return XLAT_ACTION_FAIL;
1074 }
1075
1077
1079 request,
1080 NULL,
1084 xlat_ctx) < 0) goto error;
1085
1086 /*
1087 * The user DN is not known yet, so look the user up first.
1088 * ldap_group_xlat_results() runs once the search has completed.
1089 */
1090 if (!xlat_ctx->dn) {
1091 if (xlat_ctx->env_data->user_filter.type == FR_TYPE_STRING) xlat_ctx->filter = &xlat_ctx->env_data->user_filter;
1092 xlat_ctx->basedn = &xlat_ctx->env_data->user_base;
1093
1095 /* discard, this function is only used by xlats */NULL,
1096 xlat_ctx->inst, request,
1097 xlat_ctx->basedn, xlat_ctx->filter,
1098 xlat_ctx->ttrunk, xlat_ctx->attrs, &xlat_ctx->query) == UNLANG_ACTION_FAIL) {
1100 goto error;
1101 }
1102 }
1103
1105}
1106
1113
1114/** Return whether evaluating the profile was successful
1115 *
1116 */
1118 UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
1119{
1120 ldap_xlat_profile_ctx_t *xlat_ctx = talloc_get_type_abort(xctx->rctx, ldap_xlat_profile_ctx_t);
1121 fr_value_box_t *vb;
1122
1124 vb->vb_bool = (xlat_ctx->ret == LDAP_RESULT_SUCCESS) && (xlat_ctx->applied > 0);
1126
1127 return XLAT_ACTION_DONE;
1128}
1129
1131{
1132 if (to_free->url) {
1133 ldap_free_urldesc(to_free->url);
1134 to_free->url = NULL;
1135 }
1136 return 0;
1137}
1138
1139/** Expand an LDAP URL into a query, applying the results using the user update map.
1140 *
1141 * For fetching profiles by DN.
1142 *
1143 * @ingroup xlat_functions
1144 */
1146 xlat_ctx_t const *xctx,
1147 request_t *request, fr_value_box_list_t *in)
1148{
1150 fr_ldap_thread_t *t = talloc_get_type_abort(xctx->mctx->thread, fr_ldap_thread_t);
1151 ldap_xlat_profile_call_env_t *env_data = talloc_get_type_abort(xctx->env_data, ldap_xlat_profile_call_env_t);
1152 fr_value_box_t *uri_components, *uri;
1153 char *host_url, *host = NULL;
1154 fr_ldap_config_t const *handle_config = t->config;
1155 fr_ldap_thread_trunk_t *ttrunk;
1157
1158 int ldap_url_ret;
1159
1160 char const *dn;
1161 char const *filter;
1162 int scope;
1163
1164 bool is_dn;
1165
1166 XLAT_ARGS(in, &uri_components);
1167
1168 is_dn = (fr_uri_has_scheme(&uri_components->vb_group, ldap_uri_scheme_table, ldap_uri_scheme_table_len, -1) < 0);
1169
1170 /*
1171 * Apply different escaping rules based on whether the first
1172 * arg lookgs like a URI or a DN.
1173 */
1174 if (is_dn) {
1175 if (fr_uri_escape_list(&uri_components->vb_group, ldap_dn_parts, NULL) < 0) {
1176 RPERROR("Failed to escape LDAP profile DN");
1177 return XLAT_ACTION_FAIL;
1178 }
1179 } else {
1180 if (fr_uri_escape_list(&uri_components->vb_group, ldap_uri_parts, NULL) < 0) {
1181 RPERROR("Failed to escape LDAP profile URI");
1182 return XLAT_ACTION_FAIL;
1183 }
1184 }
1185
1186 /*
1187 * Smush everything into the first URI box
1188 */
1189 uri = fr_value_box_list_head(&uri_components->vb_group);
1190 if (fr_value_box_list_concat_in_place(uri, uri, &uri_components->vb_group,
1191 FR_TYPE_STRING, FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
1192 RPEDEBUG("Failed concatenating input");
1193 return XLAT_ACTION_FAIL;
1194 }
1195
1196 /*
1197 * Allocate a resumption context to store temporary resource and results
1198 */
1200 talloc_set_destructor(xlat_ctx, ldap_xlat_profile_ctx_free);
1201
1202 if (is_dn) {
1203 host_url = handle_config->server;
1204 dn = talloc_typed_strdup_buffer(xlat_ctx, uri->vb_strvalue);
1205 filter = env_data->profile_filter.vb_strvalue;
1206 scope = inst->profile.obj_scope;
1207 } else {
1208 ldap_url_ret = ldap_url_parse(uri->vb_strvalue, &xlat_ctx->url);
1209 if (ldap_url_ret != LDAP_URL_SUCCESS){
1210 RPEDEBUG("Parsing LDAP URL failed - %s", fr_ldap_url_err_to_str(ldap_url_ret));
1211 error:
1213 return XLAT_ACTION_FAIL;
1214 }
1215
1216 /*
1217 * The URL must specify a DN
1218 */
1219 if (!xlat_ctx->url->lud_dn) {
1220 REDEBUG("LDAP URI must specify a profile DN");
1221 goto error;
1222 }
1223
1224 dn = xlat_ctx->url->lud_dn;
1225 /*
1226 * Either we use the filter from the URL or we use the default filter
1227 * configured for profiles.
1228 */
1229 filter = xlat_ctx->url->lud_filter ? xlat_ctx->url->lud_filter : env_data->profile_filter.vb_strvalue;
1230
1231 /*
1232 * Determine if the URL includes a scope.
1233 */
1234 scope = xlat_ctx->url->lud_scope == LDAP_SCOPE_DEFAULT ? inst->profile.obj_scope : xlat_ctx->url->lud_scope;
1235
1236 /*
1237 * If the URL is <scheme>:/// the parsed host will be NULL - use config default
1238 */
1239 if (!xlat_ctx->url->lud_host) {
1240 host_url = handle_config->server;
1241 } else {
1242 host_url = host = host_uri_canonify(request, xlat_ctx->url, uri);
1243 if (unlikely(host_url == NULL)) goto error;
1244 }
1245 }
1246
1247 /*
1248 * Synchronous expansion of maps (fixme!)
1249 */
1250 if (fr_ldap_map_expand(xlat_ctx, &xlat_ctx->expanded, request, env_data->profile_map,
1251 inst->valuepair_attr, inst->profile.check_attr, inst->profile.fallthrough_attr) < 0) goto error;
1252 ttrunk = fr_thread_ldap_trunk_get(t, host_url, handle_config->admin_identity,
1253 handle_config->admin_password, request, handle_config);
1254 if (host) ldap_memfree(host);
1255 if (!ttrunk) {
1256 REDEBUG("Unable to get LDAP query for xlat");
1257 goto error;
1258 }
1259
1261
1262 /*
1263 * Pushes a frame onto the stack to retrieve and evaluate a profile
1264 */
1265 if (rlm_ldap_map_profile(&xlat_ctx->ret, &xlat_ctx->applied, inst, request, ttrunk, dn,
1266 scope, filter, &xlat_ctx->expanded) < 0) goto error;
1267
1269}
1270
1271/** State of an in progress whoami extended operation
1272 *
1273 */
1274typedef struct {
1275 fr_ldap_query_t *query; //!< Current query performing the whoami operation.
1277
1278/** Return the authorization identity from the whoami response
1279 *
1280 * @ingroup xlat_functions
1281 */
1283 request_t *request, UNUSED fr_value_box_list_t *in)
1284{
1285 ldap_xlat_whoami_ctx_t *xlat_ctx = talloc_get_type_abort(xctx->rctx, ldap_xlat_whoami_ctx_t);
1286 fr_ldap_query_t *query = xlat_ctx->query;
1287 fr_value_box_t *vb;
1288 struct berval *authz_id = NULL;
1289 char const *p;
1290 size_t len;
1291 int err;
1292
1293 if (query->ret != LDAP_RESULT_SUCCESS) {
1294 REDEBUG("Whoami extended operation failed");
1295 return XLAT_ACTION_FAIL;
1296 }
1297
1298 err = ldap_parse_extended_result(query->ldap_conn->handle, query->result, NULL, &authz_id, false);
1299 if (err != LDAP_SUCCESS) {
1300 REDEBUG("Failed parsing whoami response: %s", ldap_err2string(err));
1301 return XLAT_ACTION_FAIL;
1302 }
1303
1304 /*
1305 * An empty authzId means the connection is bound anonymously.
1306 */
1307 if (!authz_id || (authz_id->bv_len == 0)) {
1308 if (authz_id) ber_bvfree(authz_id);
1309 return XLAT_ACTION_DONE;
1310 }
1311
1312 /*
1313 * RFC 4532 returns an authzId (RFC 4513), "dn:<dn>" for
1314 * distinguished names. Strip the prefix, "u:<user>" forms
1315 * are returned unmodified.
1316 */
1317 p = authz_id->bv_val;
1318 len = authz_id->bv_len;
1319 if ((len >= 3) && (memcmp(p, "dn:", 3) == 0)) {
1320 p += 3;
1321 len -= 3;
1322 }
1323
1324 MEM(vb = fr_value_box_alloc_null(ctx));
1325 MEM(fr_value_box_bstrndup(vb, vb, NULL, p, len, false) == 0);
1327
1328 ber_bvfree(authz_id);
1329
1330 return XLAT_ACTION_DONE;
1331}
1332
1333/** Perform the RFC 4532 whoami extended operation
1334 *
1335 * Runs on the same connections as the module's queries, so the identity
1336 * returned is the one the directory resolved for the admin bind.
1337 *
1338 * @ingroup xlat_functions
1339 */
1341 xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in)
1342{
1343 fr_ldap_thread_t *t = talloc_get_type_abort(xctx->mctx->thread, fr_ldap_thread_t);
1344 fr_ldap_config_t const *handle_config = t->config;
1345 fr_ldap_thread_trunk_t *ttrunk;
1347
1348 ttrunk = fr_thread_ldap_trunk_get(t, handle_config->server, handle_config->admin_identity,
1349 handle_config->admin_password, request, handle_config);
1350 if (!ttrunk) {
1351 REDEBUG("Unable to get LDAP trunk for whoami");
1352 return XLAT_ACTION_FAIL;
1353 }
1354
1356
1358 error:
1360 return XLAT_ACTION_FAIL;
1361 }
1362
1363 if (fr_ldap_trunk_extended(xlat_ctx, &xlat_ctx->query, request, ttrunk,
1364 LDAP_EXOP_WHO_AM_I, NULL, NULL, NULL) != UNLANG_ACTION_PUSHED_CHILD) goto error;
1365
1367}
1368
1369/*
1370 * Verify the result of the map.
1371 */
1372static int ldap_map_verify(CONF_SECTION *cs, UNUSED void const *mod_inst, UNUSED void *proc_inst,
1373 tmpl_t const *src, UNUSED map_list_t const *maps)
1374{
1375 if (!src) {
1376 cf_log_err(cs, "Missing LDAP URI");
1377
1378 return -1;
1379 }
1380
1381 return 0;
1382}
1383
1384/** Process the results of an LDAP map query
1385 *
1386 * @param[out] p_result Result of map expansion:
1387 * - #RLM_MODULE_NOOP no rows were returned.
1388 * - #RLM_MODULE_UPDATED if one or more #fr_pair_t were added to the #request_t.
1389 * - #RLM_MODULE_FAIL if an error occurred.
1390 * @param[in] mpctx module map ctx.
1391 * @param[in,out] request The current request.
1392 * @param[in] url LDAP url specifying base DN and filter.
1393 * @param[in] maps Head of the map list.
1394 * @return One of UNLANG_ACTION_*
1395 */
1397 UNUSED fr_value_box_list_t *url, UNUSED map_list_t const *maps)
1398{
1399 ldap_map_ctx_t *map_ctx = talloc_get_type_abort(mpctx->rctx, ldap_map_ctx_t);
1400 fr_ldap_query_t *query = map_ctx->query;
1401 fr_ldap_map_exp_t *expanded = &map_ctx->expanded;
1403 LDAPMessage *entry;
1404 map_t const *map;
1405
1406 switch (query->ret) {
1408 rcode = RLM_MODULE_UPDATED;
1409 break;
1410
1412 case LDAP_RESULT_BAD_DN:
1413 goto finish;
1414
1416 goto finish;
1417
1418 default:
1419 rcode = RLM_MODULE_FAIL;
1420 goto finish;
1421 }
1422
1423 for (entry = ldap_first_entry(query->ldap_conn->handle, query->result);
1424 entry;
1425 entry = ldap_next_entry(query->ldap_conn->handle, entry)) {
1426 char *dn = NULL;
1427 int i;
1428
1429 if (RDEBUG_ENABLED2) {
1430 dn = ldap_get_dn(query->ldap_conn->handle, entry);
1431 RDEBUG2("Processing \"%s\"", dn);
1432 }
1433
1434 RINDENT();
1435 for (map = map_list_head(map_ctx->maps), i = 0;
1436 map != NULL;
1437 map = map_list_next(map_ctx->maps, map), i++) {
1439 int ret, iter_err = 0;
1440
1441 if (!fr_ldap_value_iter_alloc(&iter_err, &iter, request, query->ldap_conn->handle, entry,
1442 expanded->attrs[i])) {
1443 talloc_free(iter);
1444 if (unlikely(iter_err < 0)) {
1445 RPERROR("Failed parsing entry");
1446 rcode = RLM_MODULE_FAIL;
1447 ldap_memfree(dn);
1448 goto finish;
1449 }
1450
1451 /*
1452 * Many LDAP directories don't expose the DN of
1453 * the object as an attribute, so we need this
1454 * hack, to allow the user to retrieve it.
1455 */
1456 if (strcmp(LDAP_VIRTUAL_DN_ATTR, expanded->attrs[i]) == 0) {
1457 if (!dn) dn = ldap_get_dn(query->ldap_conn->handle, entry);
1458
1459 ret = map_to_request(request, map, fr_ldap_map_getdn, dn);
1460 if (ret == -1) {
1461 rcode = RLM_MODULE_FAIL;
1462 ldap_memfree(dn);
1463 goto finish;
1464 }
1465 continue;
1466 }
1467
1468 RDEBUG3("Attribute \"%s\" not found in LDAP object", expanded->attrs[i]);
1469
1470 continue;
1471 }
1472
1473 ret = map_to_request(request, map, fr_ldap_map_getvalue, iter);
1474 talloc_free(iter);
1475 if (ret == -1) {
1476 rcode = RLM_MODULE_FAIL;
1477 ldap_memfree(dn);
1478 goto finish;
1479 }
1480 }
1481 ldap_memfree(dn);
1482 REXDENT();
1483 }
1484
1485finish:
1486 RETURN_UNLANG_RCODE(rcode);
1487}
1488
1489/** Ensure map context is properly cleared up
1490 *
1491 */
1493{
1494 int i = 0;
1495 talloc_free(map_ctx->expanded.ctx);
1496 ldap_free_urldesc(map_ctx->ldap_url);
1497 while ((i < LDAP_MAX_CONTROLS) && map_ctx->serverctrls[i]) {
1498 ldap_control_free(map_ctx->serverctrls[i]);
1499 i++;
1500 }
1501 return (0);
1502}
1503
1504/** Perform a search and map the result of the search to server attributes
1505 *
1506 * Unlike LDAP xlat, this can be used to process attributes from multiple entries.
1507 *
1508 * @todo For xlat expansions we need to parse the raw URL first, and then apply
1509 * different escape functions to the different parts.
1510 *
1511 * @param[out] p_result Result of map expansion:
1512 * - #RLM_MODULE_NOOP no rows were returned.
1513 * - #RLM_MODULE_UPDATED if one or more #fr_pair_t were added to the #request_t.
1514 * - #RLM_MODULE_FAIL if an error occurred.
1515 * @param[in] mpctx module map ctx.
1516 * @param[in,out] request The current request.
1517 * @param[in] url LDAP url specifying base DN and filter.
1518 * @param[in] maps Head of the map list.
1519 * @return UNLANG_ACTION_CALCULATE_RESULT
1520 */
1522 fr_value_box_list_t *url, map_list_t const *maps)
1523{
1525 fr_ldap_thread_t *thread = talloc_get_type_abort(module_thread(inst->mi)->data, fr_ldap_thread_t);
1526
1527 LDAPURLDesc *ldap_url;
1528 int ldap_url_ret;
1529 fr_ldap_thread_trunk_t *ttrunk;
1530
1531 fr_value_box_t *url_head;
1533 char *host_url, *host = NULL;
1534
1535 if (fr_uri_escape_list(url, ldap_uri_parts, NULL) < 0) {
1536 RPERROR("Failed to escape LDAP map URI");
1538 }
1539
1540 url_head = fr_value_box_list_head(url);
1541 if (!url_head) {
1542 REDEBUG("LDAP URL cannot be empty");
1544 }
1545
1546 if (fr_value_box_list_concat_in_place(url_head, url_head, url, FR_TYPE_STRING,
1547 FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
1548 RPEDEBUG("Failed concatenating input");
1550 }
1551
1552 if (!ldap_is_ldap_url(url_head->vb_strvalue)) {
1553 REDEBUG("Map query string does not look like a valid LDAP URI");
1555 }
1556
1558 talloc_set_destructor(map_ctx, map_ctx_free);
1559 map_ctx->maps = maps;
1560
1561 ldap_url_ret = ldap_url_parse(url_head->vb_strvalue, &map_ctx->ldap_url);
1562 if (ldap_url_ret != LDAP_URL_SUCCESS){
1563 RPEDEBUG("Parsing LDAP URL failed - %s", fr_ldap_url_err_to_str(ldap_url_ret));
1564 fail:
1567 }
1568 ldap_url = map_ctx->ldap_url;
1569
1570 if (ldap_url->lud_exts) {
1571 if (fr_ldap_parse_url_extensions(map_ctx->serverctrls, NUM_ELEMENTS(map_ctx->serverctrls),
1572 ldap_url->lud_exts) < 0) {
1573 RPERROR("Parsing URL extensions failed");
1574 goto fail;
1575 }
1576 }
1577
1578 /*
1579 * Expand the RHS of the maps to get the name of the attributes.
1580 */
1581 if (fr_ldap_map_expand(map_ctx, &map_ctx->expanded, request, maps, NULL, NULL, NULL) < 0) goto fail;
1582
1583 /*
1584 * If the URL is <scheme>:/// the parsed host will be NULL - use config default
1585 */
1586 if (!ldap_url->lud_host) {
1587 host_url = inst->handle_config.server;
1588 } else {
1589 host_url = host = host_uri_canonify(request, ldap_url, url_head);
1590 if (unlikely(host_url == NULL)) goto fail;
1591 }
1592
1593 ttrunk = fr_thread_ldap_trunk_get(thread, host_url, inst->handle_config.admin_identity,
1594 inst->handle_config.admin_password, request, &inst->handle_config);
1595 if (host) ldap_memfree(host);
1596 if (!ttrunk) goto fail;
1597
1599
1600 return fr_ldap_trunk_search(map_ctx, &map_ctx->query, request, ttrunk, ldap_url->lud_dn,
1601 ldap_url->lud_scope, ldap_url->lud_filter, map_ctx->expanded.attrs,
1602 map_ctx->serverctrls, NULL);
1603}
1604
1606{
1608 fr_ldap_thread_t *thread = talloc_get_type_abort(module_thread(inst->mi)->data, fr_ldap_thread_t);
1609 ldap_auth_ctx_t *auth_ctx;
1610 ldap_auth_call_env_t *call_env = talloc_get_type_abort(mctx->env_data, ldap_auth_call_env_t);
1611
1612 if (call_env->password.type != FR_TYPE_STRING) {
1613 RWDEBUG("You have set \"Auth-Type := LDAP\" somewhere");
1614 RWDEBUG("without checking if %s is present", call_env->password_tmpl->name);
1615 RWDEBUG("*********************************************");
1616 RWDEBUG("* THAT CONFIGURATION IS WRONG. DELETE IT. ");
1617 RWDEBUG("* YOU ARE PREVENTING THE SERVER FROM WORKING");
1618 RWDEBUG("*********************************************");
1619
1620 REDEBUG("Attribute \"%s\" is required for authentication", call_env->password_tmpl->name);
1622 }
1623
1625 *auth_ctx = (ldap_auth_ctx_t){
1626 .password = call_env->password.vb_strvalue,
1627 .thread = thread,
1628 .inst = inst,
1629 .call_env = call_env
1630 };
1631
1632 /*
1633 * Find the user's DN
1634 */
1635 auth_ctx->dn = rlm_find_user_dn_cached(inst, request);
1636
1637 /*
1638 * The DN is required for non-SASL auth
1639 */
1640 if (!auth_ctx->dn && (call_env->user_sasl_mech.type != FR_TYPE_STRING)) {
1641 REDEBUG("No DN found for authentication. Populate control.%s with the DN to use in authentication.",
1642 inst->user.da->name);
1643 REDEBUG("You should call %s in the recv section and check its return.", inst->mi->name);
1644 talloc_free(auth_ctx);
1646 }
1647
1648 /*
1649 * Log the password
1650 */
1651 if (RDEBUG_ENABLED3) {
1652 RDEBUG("Login attempt with password \"%pV\"", &call_env->password);
1653 } else {
1654 RDEBUG2("Login attempt with password");
1655 }
1656
1657 /*
1658 * SASL bind auth will have the mech set.
1659 */
1660 if (auth_ctx->call_env->user_sasl_mech.type == FR_TYPE_STRING) {
1661#ifdef WITH_SASL
1662 RDEBUG2("Login attempt using identity \"%pV\"", &call_env->user_sasl_authname);
1663
1664 return fr_ldap_sasl_bind_auth_async(p_result, request, auth_ctx->thread, call_env->user_sasl_mech.vb_strvalue,
1665 call_env->user_sasl_authname.vb_strvalue,
1666 auth_ctx->password, call_env->user_sasl_proxy.vb_strvalue,
1667 call_env->user_sasl_realm.vb_strvalue);
1668#else
1669 RDEBUG("Configuration item 'sasl.mech' is not supported. "
1670 "The linked version of libldap does not provide ldap_sasl_bind( function");
1672#endif
1673 }
1674
1675 RDEBUG2("Login attempt as \"%s\"", auth_ctx->dn);
1676
1677 return fr_ldap_bind_auth_async(p_result, request, auth_ctx->thread, auth_ctx->dn, auth_ctx->password);
1678}
1679
1680/** Remove duplicate DNs from a NULL terminated list, keeping the first occurrence
1681 *
1682 * A profile referenced by both a group object and the user object must
1683 * only be applied once.
1684 */
1685static void profile_dn_list_dedupe(char const **dn_list)
1686{
1687 int i, j, n;
1688
1689 for (n = 0; dn_list[n]; n++);
1690
1691 for (i = 1; i < n; i++) {
1692 for (j = 0; j < i; j++) {
1693 if (strcasecmp(dn_list[i], dn_list[j]) != 0) continue;
1694
1695 memmove(&dn_list[i], &dn_list[i + 1], (n - i) * sizeof(dn_list[0]));
1696 n--;
1697 i--;
1698 break;
1699 }
1700 }
1701}
1702
1703#define REPEAT_MOD_AUTHORIZE_RESUME \
1704 if (unlang_module_yield(request, mod_authorize_resume, NULL, FR_SIGNAL_NONE, autz_ctx) == UNLANG_ACTION_FAIL) do { \
1705 p_result->rcode = RLM_MODULE_FAIL; \
1706 goto finish; \
1707 } while (0)
1708
1709/** Resume function called after each potential yield in LDAP authorization
1710 *
1711 * Some operations may or may not yield. E.g. if group membership is
1712 * read from an attribute returned with the user object and is already
1713 * in the correct form, that will not yield.
1714 * Hence, each state may fall through to the next.
1715 *
1716 * @param p_result Result of current authorization.
1717 * @param mctx Module context.
1718 * @param request Current request.
1719 * @return An rcode.
1720 */
1722{
1723 ldap_autz_ctx_t *autz_ctx = talloc_get_type_abort(mctx->rctx, ldap_autz_ctx_t);
1725 ldap_autz_call_env_t *call_env = talloc_get_type_abort(autz_ctx->call_env, ldap_autz_call_env_t);
1726 int ldap_errno;
1727 LDAP *handle = fr_ldap_handle_thread_local();
1729
1730 /*
1731 * If a previous async call returned one of the "failure" results just return.
1732 */
1733 switch (p_result->rcode) {
1734 case RLM_MODULE_REJECT:
1735 case RLM_MODULE_FAIL:
1736 case RLM_MODULE_HANDLED:
1737 case RLM_MODULE_INVALID:
1739 goto finish;
1740
1741 default:
1742 break;
1743 }
1744
1745 switch (autz_ctx->status) {
1746 case LDAP_AUTZ_FIND:
1747 /*
1748 * If a user entry has been found the current rcode will be OK
1749 */
1750 if (p_result->rcode != RLM_MODULE_OK) return UNLANG_ACTION_CALCULATE_RESULT;
1751
1752 autz_ctx->entry = ldap_first_entry(handle, autz_ctx->query->result);
1753 if (!autz_ctx->entry) {
1754 ldap_get_option(handle, LDAP_OPT_RESULT_CODE, &ldap_errno);
1755 REDEBUG("Failed retrieving entry: %s", ldap_err2string(ldap_errno));
1756
1757 goto finish;
1758 }
1759
1760 /*
1761 * Check for access.
1762 */
1763 if (inst->user.obj_access_attr) {
1764 autz_ctx->access_state = rlm_ldap_check_access(inst, request, autz_ctx->entry);
1765 switch (autz_ctx->access_state) {
1767 break;
1768
1770 if (inst->group.skip_on_suspend) goto post_group;
1771 break;
1772
1774 p_result->rcode = RLM_MODULE_DISALLOW;
1775 goto finish;
1776 }
1777 }
1778
1779 /*
1780 * Check if we need to cache group memberships,
1781 * or record group DNs for the group profile search.
1782 */
1783 if ((inst->group.cacheable_dn || inst->group.cacheable_name ||
1784 rlm_ldap_profile_attr_select(inst->group.profile_attr, inst->group.profile_attr_suspend,
1785 autz_ctx->access_state)) &&
1786 (inst->group.userobj_membership_attr)) {
1788 if (rlm_ldap_cacheable_userobj(p_result, request, autz_ctx,
1789 inst->group.userobj_membership_attr) == UNLANG_ACTION_PUSHED_CHILD) {
1790 autz_ctx->status = LDAP_AUTZ_GROUP;
1792 }
1793 if (p_result->rcode != RLM_MODULE_OK) goto finish;
1794 }
1796
1797 case LDAP_AUTZ_GROUP:
1798 if (inst->group.cacheable_dn || inst->group.cacheable_name ||
1799 rlm_ldap_profile_attr_select(inst->group.profile_attr, inst->group.profile_attr_suspend,
1800 autz_ctx->access_state)) {
1803 autz_ctx->status = LDAP_AUTZ_GROUP_PROFILES;
1805 }
1806 if (p_result->rcode != RLM_MODULE_OK) goto finish;
1807 }
1809
1811 if (rlm_ldap_profile_attr_select(inst->group.profile_attr, inst->group.profile_attr_suspend,
1812 autz_ctx->access_state) &&
1813 autz_ctx->group_dn_list && (talloc_str_list_num(autz_ctx->group_dn_list) > 0)) {
1815 if (rlm_ldap_group_profiles(p_result, request, autz_ctx) == UNLANG_ACTION_PUSHED_CHILD) {
1816 autz_ctx->status = LDAP_AUTZ_POST_GROUP;
1818 }
1819 if (p_result->rcode != RLM_MODULE_OK) goto finish;
1820 }
1822
1824 post_group:
1825#ifdef WITH_EDIR
1826 /*
1827 * We already have a Password.Cleartext. Skip edir.
1828 */
1829 if (fr_pair_find_by_da_nested(&request->control_pairs, attr_cleartext_password)) goto skip_edir;
1830
1831 /*
1832 * Retrieve Universal Password if we use eDirectory
1833 */
1834 if (inst->edir) {
1835 autz_ctx->dn = rlm_find_user_dn_cached(inst, request);
1836
1837 /*
1838 * Retrieve universal password
1839 */
1841 autz_ctx->status = LDAP_AUTZ_EDIR_BIND;
1842 return fr_ldap_edir_get_password(p_result, request, autz_ctx->dn, autz_ctx->ttrunk,
1844 }
1846
1847 case LDAP_AUTZ_EDIR_BIND:
1848 if (inst->edir && inst->edir_autz) {
1849 fr_pair_t *password = fr_pair_find_by_da(&request->control_pairs,
1851 fr_ldap_thread_t *thread = talloc_get_type_abort(module_thread(inst->mi)->data,
1853
1854 if (!password) {
1855 REDEBUG("Failed to find control.Password.Cleartext");
1856 p_result->rcode = RLM_MODULE_FAIL;
1857 goto finish;
1858 }
1859
1860 RDEBUG2("Binding as %s for eDirectory authorization checks", autz_ctx->dn);
1861
1862 /*
1863 * Bind as the user
1864 */
1866 autz_ctx->status = LDAP_AUTZ_POST_EDIR;
1867 return fr_ldap_bind_auth_async(p_result, request, thread, autz_ctx->dn, password->vp_strvalue);
1868 }
1869 goto skip_edir;
1870
1871 case LDAP_AUTZ_POST_EDIR:
1872 {
1873 /*
1874 * The result of the eDirectory user bind will be in p_result.
1875 * Anything other than RLM_MODULE_OK is a failure.
1876 */
1877 break;
1878
1879 }
1880#endif
1881 case LDAP_AUTZ_MAP:
1882#ifdef WITH_EDIR
1883 skip_edir:
1884#endif
1885 if (!map_list_empty(call_env->user_map) || inst->valuepair_attr) {
1886 RDEBUG2("Processing user attributes");
1887 RINDENT();
1888 if (fr_ldap_map_do(request, NULL, inst->valuepair_attr,
1889 &autz_ctx->expanded, autz_ctx->entry) > 0) autz_ctx->rcode = RLM_MODULE_UPDATED;
1890 REXDENT();
1891 rlm_ldap_check_reply(request, inst, autz_ctx->dlinst->name, call_env->expect_password->vb_bool, autz_ctx->ttrunk);
1892 }
1894
1895 case LDAP_AUTZ_PROFILES:
1896 {
1897 talloc_str_list_t *list;
1898 char const *profile_attr;
1899 char const **dn_p;
1900 bool have_default = !fr_box_is_null(&call_env->default_profile);
1901 size_t count = 0, strings_len = 0, group_count = 0, i;
1902
1903 /*
1904 * Which set of profiles to apply depends on the user's
1905 * access state. The default profile always applies.
1906 */
1907 profile_attr = rlm_ldap_profile_attr_select(inst->user.profile_attr, inst->user.profile_attr_suspend,
1908 autz_ctx->access_state);
1909 if (profile_attr) {
1910 if (unlikely(fr_ldap_result_values_len(&count, &strings_len, handle,
1911 autz_ctx->query->result, profile_attr) < 0)) {
1912 RPERROR("Failed parsing user object");
1913 p_result->rcode = RLM_MODULE_FAIL;
1914 goto finish;
1915 }
1916 if (count > 0) {
1917 RDEBUG2("Processing %zu profile(s) found in attribute \"%s\"", count, profile_attr);
1918 } else {
1919 RDEBUG2("No profile(s) found in attribute \"%s\"", profile_attr);
1920 }
1921 }
1922
1923 if (autz_ctx->group_profile_dn_list) {
1924 group_count = talloc_str_list_num(autz_ctx->group_profile_dn_list);
1925 RDEBUG2("Processing %zu profile(s) found in group objects", group_count);
1926 }
1927
1928 if (!have_default && (group_count == 0) && (count == 0)) break;
1929
1930 /*
1931 * Build the list of profile DNs to apply, the default
1932 * profile first, then the profiles from the group
1933 * objects, then the profiles from the user object.
1934 */
1935 MEM(list = fr_ldap_str_list_afrom_result(autz_ctx, handle, autz_ctx->query->result,
1936 count ? profile_attr : NULL,
1937 (have_default ? 1 : 0) + group_count));
1938 dn_p = list->strings;
1939 if (have_default) *dn_p++ = call_env->default_profile.vb_strvalue;
1940 for (i = 0; i < group_count; i++) *dn_p++ = autz_ctx->group_profile_dn_list->strings[i];
1941
1942 /*
1943 * Evaluate the child object below each profile instead
1944 * of the profile itself.
1945 */
1946 if (!fr_box_is_null(&call_env->profile_child_rdn) && (call_env->profile_child_rdn.vb_length > 0)) {
1947 for (dn_p = list->strings; *dn_p; dn_p++) {
1948 MEM(*dn_p = talloc_asprintf(list, "%s,%s",
1949 call_env->profile_child_rdn.vb_strvalue, *dn_p));
1950 }
1951 }
1952
1953 autz_ctx->profile_dn_list = list->strings;
1955
1956 if (!autz_ctx->profile_dn_list[0]) break;
1957
1958 if (RDEBUG_ENABLED3) {
1959 for (dn_p = autz_ctx->profile_dn_list; *dn_p; dn_p++) {
1960 RDEBUG3("Will evaluate profile with DN \"%s\"", *dn_p);
1961 }
1962 }
1963
1965 ret = rlm_ldap_map_profiles(NULL, &autz_ctx->profiles_applied, inst, request, autz_ctx->ttrunk,
1966 autz_ctx->profile_dn_list, call_env->profile_filter.vb_strvalue,
1967 &autz_ctx->expanded);
1968 switch (ret) {
1969 case UNLANG_ACTION_FAIL:
1970 p_result->rcode = RLM_MODULE_FAIL;
1971 goto finish;
1972
1974 autz_ctx->status = LDAP_AUTZ_POST_PROFILES;
1976
1977 default:
1978 break;
1979 }
1980 }
1982
1984 if (autz_ctx->profiles_applied > 0) autz_ctx->rcode = RLM_MODULE_UPDATED;
1985 break;
1986 }
1987
1988 p_result->rcode = autz_ctx->rcode;
1989
1990finish:
1991 return ret;
1992}
1993
1994/** Clear up when cancelling a mod_authorize call
1995 *
1996 */
1998{
1999 ldap_autz_ctx_t *autz_ctx = talloc_get_type_abort(mctx->rctx, ldap_autz_ctx_t);
2000
2001 if (autz_ctx->query && autz_ctx->query->treq) trunk_request_signal_cancel(autz_ctx->query->treq);
2002}
2003
2004/** Ensure authorization context is properly cleared up
2005 *
2006 */
2007static int autz_ctx_free(ldap_autz_ctx_t *autz_ctx)
2008{
2009 talloc_free(autz_ctx->expanded.ctx);
2010 return 0;
2011}
2012
2014{
2016 fr_ldap_thread_t *thread = talloc_get_type_abort(module_thread(inst->mi)->data, fr_ldap_thread_t);
2017 ldap_autz_ctx_t *autz_ctx;
2018 fr_ldap_map_exp_t *expanded;
2019 ldap_autz_call_env_t *call_env = talloc_get_type_abort(mctx->env_data, ldap_autz_call_env_t);
2020
2022 talloc_set_destructor(autz_ctx, autz_ctx_free);
2023 expanded = &autz_ctx->expanded;
2024
2025 /*
2026 * Don't be tempted to add a check for User-Name or
2027 * User-Password here. LDAP authorization can be used
2028 * for many things besides searching for users.
2029 */
2030 if (fr_ldap_map_expand(autz_ctx, expanded, request, call_env->user_map, inst->valuepair_attr,
2031 inst->profile.check_attr, inst->profile.fallthrough_attr) < 0) {
2032 fail:
2033 talloc_free(autz_ctx);
2035 }
2036
2037 autz_ctx->ttrunk = fr_thread_ldap_trunk_get(thread, inst->handle_config.server, inst->handle_config.admin_identity,
2038 inst->handle_config.admin_password, request, &inst->handle_config);
2039 if (!autz_ctx->ttrunk) goto fail;
2040
2041#define CHECK_EXPANDED_SPACE(_expanded) fr_assert((size_t)_expanded->count < (NUM_ELEMENTS(_expanded->attrs) - 1))
2042
2043 /*
2044 * Add any additional attributes we need for checking access, memberships, and profiles
2045 */
2046 if (inst->user.obj_access_attr) {
2047 CHECK_EXPANDED_SPACE(expanded);
2048 expanded->attrs[expanded->count++] = inst->user.obj_access_attr;
2049 }
2050
2051 if (inst->group.userobj_membership_attr &&
2052 (inst->group.cacheable_dn || inst->group.cacheable_name ||
2053 inst->group.profile_attr || inst->group.profile_attr_suspend)) {
2054 CHECK_EXPANDED_SPACE(expanded);
2055 expanded->attrs[expanded->count++] = inst->group.userobj_membership_attr;
2056 }
2057
2058 if (inst->user.profile_attr) {
2059 CHECK_EXPANDED_SPACE(expanded);
2060 expanded->attrs[expanded->count++] = inst->user.profile_attr;
2061 }
2062
2063 if (inst->user.profile_attr_suspend) {
2064 CHECK_EXPANDED_SPACE(expanded);
2065 expanded->attrs[expanded->count++] = inst->user.profile_attr_suspend;
2066 }
2067 expanded->attrs[expanded->count] = NULL;
2068
2069 autz_ctx->dlinst = mctx->mi;
2070 autz_ctx->inst = inst;
2071 autz_ctx->call_env = call_env;
2072 autz_ctx->status = LDAP_AUTZ_FIND;
2073 autz_ctx->rcode = RLM_MODULE_OK;
2074
2078 autz_ctx) == UNLANG_ACTION_FAIL)) {
2079 talloc_free(autz_ctx);
2081 }
2082
2083 return rlm_ldap_find_user_async(autz_ctx, p_result,
2084 autz_ctx->inst, request, &autz_ctx->call_env->user_base,
2085 &autz_ctx->call_env->user_filter, autz_ctx->ttrunk, autz_ctx->expanded.attrs,
2086 &autz_ctx->query);
2087}
2088
2089/** Cancel an in progress user modification.
2090 *
2091 */
2093{
2094 ldap_user_modify_ctx_t *usermod_ctx = talloc_get_type_abort(mctx->rctx, ldap_user_modify_ctx_t);
2095
2096 if (!usermod_ctx->query || !usermod_ctx->query->treq) return;
2097
2098 trunk_request_signal_cancel(usermod_ctx->query->treq);
2099}
2100
2101/** Handle results of user modification.
2102 *
2103 */
2105{
2106 ldap_user_modify_ctx_t *usermod_ctx = talloc_get_type_abort(mctx->rctx, ldap_user_modify_ctx_t);
2107 fr_ldap_query_t *query = usermod_ctx->query;
2108 rlm_rcode_t rcode = RLM_MODULE_OK;
2109
2110 switch (query->ret) {
2112 break;
2113
2115 case LDAP_RESULT_BAD_DN:
2116 RDEBUG2("User object \"%s\" not modified", usermod_ctx->dn);
2117 rcode = RLM_MODULE_INVALID;
2118 break;
2119
2121 rcode = RLM_MODULE_TIMEOUT;
2122 break;
2123
2124 default:
2125 rcode = RLM_MODULE_FAIL;
2126 break;
2127 }
2128
2129 talloc_free(usermod_ctx);
2130 RETURN_UNLANG_RCODE(rcode);
2131}
2132
2134{
2135 ldap_user_modify_ctx_t *usermod_ctx = talloc_get_type_abort(mctx->rctx, ldap_user_modify_ctx_t);
2136 ldap_usermod_call_env_t *call_env = usermod_ctx->call_env;
2137 LDAPMod **modify;
2138 ldap_mod_tmpl_t *mod;
2139 fr_value_box_t *vb = NULL;
2140 size_t mod_no = usermod_ctx->expanded_mods, i = 0;
2141 struct berval **value_refs;
2142 struct berval *values;
2143
2144 mod = call_env->mod[usermod_ctx->current_mod];
2145
2146 /*
2147 * If the tmpl produced no boxes, skip
2148 */
2149 if ((mod->op != T_OP_CMP_FALSE) && (fr_value_box_list_num_elements(&usermod_ctx->expanded) == 0)) {
2150 RDEBUG2("Expansion \"%s\" produced no value, skipping attribute \"%s\"", mod->tmpl->name, mod->attr);
2151 goto next;
2152 }
2153
2154 switch (mod->op) {
2155 /*
2156 * T_OP_EQ is *NOT* supported, it is impossible to
2157 * support because of the lack of transactions in LDAP
2158 *
2159 * To allow for binary data, all data is provided as berval which
2160 * requires the operation to be logical ORed with LDAP_MOD_BVALUES
2161 */
2162 case T_OP_ADD_EQ:
2163 usermod_ctx->mod_s[mod_no].mod_op = LDAP_MOD_ADD | LDAP_MOD_BVALUES;
2164 break;
2165
2166 case T_OP_SET:
2167 usermod_ctx->mod_s[mod_no].mod_op = LDAP_MOD_REPLACE | LDAP_MOD_BVALUES;
2168 break;
2169
2170 case T_OP_SUB_EQ:
2171 case T_OP_CMP_FALSE:
2172 usermod_ctx->mod_s[mod_no].mod_op = LDAP_MOD_DELETE | LDAP_MOD_BVALUES;
2173 break;
2174
2175 case T_OP_INCRM:
2176 usermod_ctx->mod_s[mod_no].mod_op = LDAP_MOD_INCREMENT | LDAP_MOD_BVALUES;
2177 break;
2178
2179 default:
2180 REDEBUG("Operator '%s' is not supported for LDAP modify operations",
2181 fr_table_str_by_value(fr_tokens_table, mod->op, "<INVALID>"));
2182
2184 }
2185
2186 if (mod->op == T_OP_CMP_FALSE) {
2187 MEM(value_refs = talloc_zero_array(usermod_ctx, struct berval *, 1));
2188 } else {
2189 MEM(value_refs = talloc_zero_array(usermod_ctx, struct berval *,
2190 fr_value_box_list_num_elements(&usermod_ctx->expanded) + 1));
2191 MEM(values = talloc_zero_array(usermod_ctx, struct berval,
2192 fr_value_box_list_num_elements(&usermod_ctx->expanded)));
2193 while ((vb = fr_value_box_list_pop_head(&usermod_ctx->expanded))) {
2194 switch (vb->type) {
2195 case FR_TYPE_OCTETS:
2196 if (vb->vb_length == 0) continue;
2197 memcpy(&values[i].bv_val, &vb->vb_octets, sizeof(values[i].bv_val));
2198 values[i].bv_len = vb->vb_length;
2199 break;
2200
2201 case FR_TYPE_STRING:
2202 populate_string:
2203 if (vb->vb_length == 0) continue;
2204 memcpy(&values[i].bv_val, &vb->vb_strvalue, sizeof(values[i].bv_val));
2205 values[i].bv_len = vb->vb_length;
2206 break;
2207
2208 case FR_TYPE_GROUP:
2209 {
2210 fr_value_box_t *vb_head = fr_value_box_list_head(&vb->vb_group);
2211 if (fr_value_box_list_concat_in_place(vb_head, vb_head, &vb->vb_group, FR_TYPE_STRING,
2212 FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
2213 RPEDEBUG("Failed concatenating update value");
2215 }
2216 vb = vb_head;
2217 goto populate_string;
2218 }
2219
2220 case FR_TYPE_FIXED_SIZE:
2221 if (fr_value_box_cast_in_place(vb, vb, FR_TYPE_STRING, NULL) < 0) {
2222 RPEDEBUG("Failed casting update value");
2224 }
2225 goto populate_string;
2226
2227 default:
2228 fr_assert(0);
2229
2230 }
2231 value_refs[i] = &values[i];
2232 i++;
2233 }
2234 if (i == 0) {
2235 RDEBUG2("Expansion \"%s\" produced zero length value, skipping attribute \"%s\"", mod->tmpl->name, mod->attr);
2236 goto next;
2237 }
2238 }
2239
2240 /*
2241 * Now everything is evaluated, set up the pointers for the LDAPMod
2242 */
2243 memcpy(&(usermod_ctx->mod_s[mod_no].mod_type), &mod->attr, sizeof(usermod_ctx->mod_s[mod_no].mod_type));
2244 usermod_ctx->mod_s[mod_no].mod_bvalues = value_refs;
2245 usermod_ctx->mod_p[mod_no] = &usermod_ctx->mod_s[mod_no];
2246
2247 usermod_ctx->expanded_mods++;
2248 usermod_ctx->mod_p[usermod_ctx->expanded_mods] = NULL;
2249
2250next:
2251 usermod_ctx->current_mod++;
2252
2253 /*
2254 * Keep calling until we've completed all the modifications
2255 */
2256 if (usermod_ctx->current_mod < usermod_ctx->num_mods) {
2258 if (unlang_tmpl_push(usermod_ctx, NULL, &usermod_ctx->expanded, request,
2259 usermod_ctx->call_env->mod[usermod_ctx->current_mod]->tmpl, NULL, UNLANG_SUB_FRAME) < 0) RETURN_UNLANG_FAIL;
2261 }
2262
2263 modify = usermod_ctx->mod_p;
2264
2266
2267 return fr_ldap_trunk_modify(usermod_ctx, &usermod_ctx->query, request, usermod_ctx->ttrunk,
2268 usermod_ctx->dn, modify, NULL, NULL);
2269}
2270
2271/** Take the retrieved user DN and launch the async tmpl expansion of mod_values.
2272 *
2273 */
2275{
2276 ldap_user_modify_ctx_t *usermod_ctx = talloc_get_type_abort(mctx->rctx, ldap_user_modify_ctx_t);
2277
2278 /*
2279 * If an LDAP search was used to find the user DN
2280 * usermod_ctx->dn will be NULL.
2281 */
2282 if (!usermod_ctx->dn) usermod_ctx->dn = rlm_find_user_dn_cached(mctx->mi->data, request);
2283
2284 if (!usermod_ctx->dn) {
2285 fail:
2286 talloc_free(usermod_ctx);
2288 }
2289
2290 /*
2291 * Allocate arrays to hold mods. mod_p is one element longer to hold a terminating NULL entry
2292 */
2293 MEM(usermod_ctx->mod_p = talloc_zero_array(usermod_ctx, LDAPMod *, usermod_ctx->num_mods + 1));
2294 MEM(usermod_ctx->mod_s = talloc_array(usermod_ctx, LDAPMod, usermod_ctx->num_mods));
2295 fr_value_box_list_init(&usermod_ctx->expanded);
2296
2298
2299 if (unlang_tmpl_push(usermod_ctx, NULL, &usermod_ctx->expanded, request,
2300 usermod_ctx->call_env->mod[0]->tmpl, NULL, UNLANG_SUB_FRAME) < 0) goto fail;
2301
2303}
2304
2305/** Modify user's object in LDAP
2306 *
2307 * Process a modification map to update a user object in the LDAP directory.
2308 *
2309 * The module method called in "accouting" and "send" sections.
2310 */
2312{
2314 ldap_usermod_call_env_t *call_env = talloc_get_type_abort(mctx->env_data, ldap_usermod_call_env_t);
2315 fr_ldap_thread_t *thread = talloc_get_type_abort(module_thread(inst->mi)->data, fr_ldap_thread_t);
2316 ldap_user_modify_ctx_t *usermod_ctx = NULL;
2317
2318 size_t num_mods = talloc_array_length(call_env->mod);
2319
2320 if (num_mods == 0) RETURN_UNLANG_NOOP;
2321
2322 /*
2323 * Include a talloc pool allowing for one value per modification
2324 */
2326 2 * num_mods + 2,
2327 (sizeof(struct berval) + (sizeof(struct berval *) * 2) +
2328 (sizeof(LDAPMod) + sizeof(LDAPMod *))) * num_mods));
2329 *usermod_ctx = (ldap_user_modify_ctx_t) {
2330 .inst = inst,
2331 .call_env = call_env,
2332 .num_mods = num_mods
2333 };
2334
2335 usermod_ctx->ttrunk = fr_thread_ldap_trunk_get(thread, inst->handle_config.server,
2336 inst->handle_config.admin_identity,
2337 inst->handle_config.admin_password,
2338 request, &inst->handle_config);
2339 if (!usermod_ctx->ttrunk) {
2340 REDEBUG("Unable to get LDAP trunk for update");
2341 talloc_free(usermod_ctx);
2343 }
2344
2345 usermod_ctx->dn = rlm_find_user_dn_cached(inst, request);
2346 /*
2347 * Find the user first
2348 */
2349 if (!usermod_ctx->dn) {
2351 talloc_free(usermod_ctx);
2353 }
2354
2355 /* Pushes a frame for user resolution */
2356 if (rlm_ldap_find_user_async(usermod_ctx,
2357 p_result,
2358 usermod_ctx->inst, request,
2359 &usermod_ctx->call_env->user_base,
2360 &usermod_ctx->call_env->user_filter,
2361 usermod_ctx->ttrunk, NULL, NULL) == UNLANG_ACTION_FAIL) {
2363 }
2364
2366 }
2367
2368 {
2369 module_ctx_t our_mctx = *mctx;
2370 our_mctx.rctx = usermod_ctx;
2371
2372 return user_modify_resume(p_result, &our_mctx, request);
2373 }
2374}
2375
2376/** Detach from the LDAP server and cleanup internal state.
2377 *
2378 */
2379static int mod_detach(module_detach_ctx_t const *mctx)
2380{
2381 rlm_ldap_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_ldap_t);
2382
2383 if (inst->user.obj_sort_ctrl) ldap_control_free(inst->user.obj_sort_ctrl);
2384 if (inst->profile.obj_sort_ctrl) ldap_control_free(inst->profile.obj_sort_ctrl);
2385
2386 return 0;
2387}
2388
2389static int ldap_update_section_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules,
2390 CONF_ITEM *ci,
2391 UNUSED call_env_ctx_t const *cec, call_env_parser_t const *rule)
2392{
2393 map_list_t *maps;
2394 CONF_SECTION *update = cf_item_to_section(ci);
2395 ldap_update_rules_t const *ur = rule->uctx;
2396
2397 bool expect_password = false;
2398
2399 /*
2400 * Build the attribute map
2401 */
2402 {
2403 map_t const *map = NULL;
2404 tmpl_attr_t const *ar;
2405 call_env_parsed_t *parsed;
2406
2407 MEM(parsed = call_env_parsed_add(ctx, out,
2409 .name = "update",
2410 .flags = CALL_ENV_FLAG_PARSE_ONLY,
2411 .pair = {
2412 .parsed = {
2413 .offset = ur->map_offset,
2415 }
2416 }
2417 }));
2418
2419 MEM(maps = talloc(parsed, map_list_t));
2420 map_list_init(maps);
2421
2422 if (update && (map_afrom_cs(maps, maps, update, t_rules, t_rules, fr_ldap_map_verify,
2423 NULL, LDAP_MAX_ATTRMAP)) < 0) {
2424 call_env_parsed_free(out, parsed);
2425 return -1;
2426 }
2427 /*
2428 * Check map to see if a password is being retrieved.
2429 * fr_ldap_map_verify ensures that all maps have attributes on the LHS.
2430 * All passwords have a common parent attribute of attr_password
2431 */
2432 while ((map = map_list_next(maps, map))) {
2433 ar = tmpl_attr_tail(map->lhs);
2434 if (ar->da->parent == attr_password) {
2435 expect_password = true;
2436 break;
2437 }
2438 }
2439 call_env_parsed_set_data(parsed, maps);
2440 }
2441
2442 /*
2443 * Write out whether we expect a password to be returned from the ldap data
2444 */
2445 if (ur->expect_password_offset >= 0) {
2446 call_env_parsed_t *parsed;
2447 fr_value_box_t *vb;
2448
2449 MEM(parsed = call_env_parsed_add(ctx, out,
2451 .name = "expect_password",
2452 .flags = CALL_ENV_FLAG_PARSE_ONLY,
2453 .pair = {
2454 .parsed = {
2455 .offset = ur->expect_password_offset,
2457 }
2458 }
2459 }));
2460 MEM(vb = fr_value_box_alloc(parsed, FR_TYPE_BOOL, NULL));
2461 vb->vb_bool = expect_password;
2462 call_env_parsed_set_value(parsed, vb);
2463 }
2464
2465 return 0;
2466}
2467
2468static int ldap_mod_section_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules,
2469 CONF_ITEM *ci, call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
2470{
2471 CONF_SECTION const *subcs = NULL;
2472 CONF_PAIR const *to_parse = NULL;
2473 tmpl_t *parsed_tmpl;
2474 call_env_parsed_t *parsed_env;
2475 char *section2, *p;
2476 ssize_t count, multi_index = 0;
2477 fr_slen_t slen;
2478 ldap_mod_tmpl_t *mod;
2479
2481
2482 section2 = talloc_strdup(NULL, section_name_str(cec->asked->name2));
2483 p = section2;
2484 while (*p != '\0') {
2485 *(p) = tolower((uint8_t)*p);
2486 p++;
2487 }
2488
2489 if (!ci) {
2490 not_found:
2491 cf_log_warn(ci, "No section found for \"%s.%s\" in module \"%s\", this call will have no effect.",
2492 section_name_str(cec->asked->name1), section2, cec->mi->name);
2493 free:
2494 talloc_free(section2);
2495 return 0;
2496 }
2497
2498 subcs = cf_section_find(cf_item_to_section(ci), section2, CF_IDENT_ANY);
2499 if (!subcs) goto not_found;
2500
2501 subcs = cf_section_find(subcs, "update", CF_IDENT_ANY);
2502 if (!subcs) {
2503 cf_log_warn(ci, "No update found inside \"%s -> %s\" in module \"%s\"",
2504 section_name_str(cec->asked->name1), section2, cec->mi->name);
2505 goto free;
2506 }
2507
2509 if (count == 0) {
2510 cf_log_warn(ci, "No modifications found for \"%s.%s\" in module \"%s\"",
2511 section_name_str(cec->asked->name1), section2, cec->mi->name);
2512 goto free;
2513 }
2514 talloc_free(section2);
2515
2516 while ((to_parse = cf_pair_next(subcs, to_parse))) {
2517 switch (cf_pair_operator(to_parse)) {
2518 case T_OP_SET:
2519 case T_OP_ADD_EQ:
2520 case T_OP_SUB_EQ:
2521 case T_OP_CMP_FALSE:
2522 case T_OP_INCRM:
2523 break;
2524
2525 default:
2526 cf_log_perr(to_parse, "Invalid operator for LDAP modification");
2527 return -1;
2528 }
2529
2530 MEM(parsed_env = call_env_parsed_add(ctx, out,
2535 }));
2536
2537 slen = tmpl_afrom_substr(parsed_env, &parsed_tmpl,
2538 &FR_SBUFF_IN(cf_pair_value(to_parse), talloc_strlen(cf_pair_value(to_parse))),
2540 t_rules);
2541
2542 if (slen <= 0) {
2543 cf_canonicalize_error(to_parse, slen, "Failed parsing LDAP modification \"%s\"", cf_pair_value(to_parse));
2544 error:
2545 call_env_parsed_free(out, parsed_env);
2546 return -1;
2547 }
2548 if (tmpl_needs_resolving(parsed_tmpl) &&
2549 (tmpl_resolve(parsed_tmpl, &(tmpl_res_rules_t){ .dict_def = t_rules->attr.dict_def }) <0)) {
2550 cf_log_perr(to_parse, "Failed resolving LDAP modification \"%s\"", cf_pair_value(to_parse));
2551 goto error;
2552 }
2553
2554 MEM(mod = talloc(parsed_env, ldap_mod_tmpl_t));
2555 mod->attr = cf_pair_attr(to_parse);
2556 mod->tmpl = parsed_tmpl;
2557 mod->op = cf_pair_operator(to_parse);
2558
2559 call_env_parsed_set_multi_index(parsed_env, count, multi_index++);
2560 call_env_parsed_set_data(parsed_env, mod);
2561 }
2562
2563 return 0;
2564}
2565
2566static int ldap_group_filter_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, UNUSED CONF_ITEM *ci,
2567 call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
2568{
2570 char const *filters[] = { inst->group.obj_filter, inst->group.obj_membership_filter };
2571 tmpl_t *parsed;
2572
2573 if (fr_ldap_filter_to_tmpl(ctx, t_rules, filters, NUM_ELEMENTS(filters), &parsed) < 0) return -1;
2574
2575 *(void **)out = parsed;
2576 return 0;
2577}
2578
2579/** Clean up thread specific data structure
2580 *
2581 */
2583{
2584 fr_ldap_thread_t *t = talloc_get_type_abort(mctx->thread, fr_ldap_thread_t);
2585 void **trunks_to_free;
2586 size_t i;
2587
2588 if (fr_rb_flatten_inorder(NULL, &trunks_to_free, t->trunks) < 0) return -1;
2589
2590 for (i = talloc_array_length(trunks_to_free); i > 0; i--) {
2591 talloc_free(trunks_to_free[i - 1]);
2592 }
2593 talloc_free(trunks_to_free);
2594 talloc_free(t->trunks);
2595
2596 return 0;
2597}
2598
2599/** Initialise thread specific data structure
2600 *
2601 */
2603{
2604 rlm_ldap_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_ldap_t);
2605 fr_ldap_thread_t *t = talloc_get_type_abort(mctx->thread, fr_ldap_thread_t);
2606 fr_ldap_thread_trunk_t *ttrunk;
2607
2608 /*
2609 * Initialise tree for connection trunks used by this thread
2610 */
2612
2613 t->config = &inst->handle_config;
2614 t->trunk_conf = &inst->trunk_conf;
2615 t->bind_trunk_conf = &inst->bind_trunk_conf;
2616 t->el = mctx->el;
2617 t->trigger_args = inst->trigger_args;
2618 t->bind_trigger_args = inst->bind_trigger_args;
2619
2620 /*
2621 * Launch trunk for module default connection
2622 */
2623 ttrunk = fr_thread_ldap_trunk_get(t, inst->handle_config.server, inst->handle_config.admin_identity,
2624 inst->handle_config.admin_password, NULL, &inst->handle_config);
2625 if (!ttrunk) {
2626 ERROR("Unable to launch LDAP trunk");
2627 return -1;
2628 }
2629
2630 /*
2631 * Set up a per-thread LDAP trunk to use for bind auths
2632 */
2634
2636
2637 return 0;
2638}
2639
2640/** Instantiate the module
2641 *
2642 * Creates a new instance of the module reading parameters from a configuration section.
2643 *
2644 * @param [in] mctx configuration data.
2645 * @return
2646 * - 0 on success.
2647 * - < 0 on failure.
2648 */
2649static int mod_instantiate(module_inst_ctx_t const *mctx)
2650{
2651 size_t i;
2652
2653 CONF_SECTION *options;
2654 rlm_ldap_boot_t const *boot = talloc_get_type_abort(mctx->mi->boot, rlm_ldap_boot_t);
2655 rlm_ldap_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_ldap_t);
2656 CONF_SECTION *conf = mctx->mi->conf;
2657
2658 inst->mi = mctx->mi; /* Cached for IO callbacks */
2659 inst->group.da = boot->group_da;
2660 inst->group.cache_da = boot->cache_da;
2661 inst->user.da = boot->user_da;
2662
2663 inst->handle_config.name = talloc_typed_asprintf(inst, "rlm_ldap (%s)", mctx->mi->name);
2664
2665 /*
2666 * Trunks used for bind auth can only have one request in flight per connection.
2667 */
2668 inst->bind_trunk_conf.target_req_per_conn = 1;
2669 inst->bind_trunk_conf.max_req_per_conn = 1;
2670
2671 /*
2672 * Set sizes for trunk request pool.
2673 */
2674 inst->bind_trunk_conf.req_pool_headers = 2;
2675 inst->bind_trunk_conf.req_pool_size = sizeof(fr_ldap_bind_auth_ctx_t) + sizeof(fr_ldap_sasl_ctx_t);
2676
2677 options = cf_section_find(conf, "options", NULL);
2678 if (!options || !cf_pair_find(options, "chase_referrals")) {
2679 inst->handle_config.chase_referrals_unset = true; /* use OpenLDAP defaults */
2680 }
2681
2682 /*
2683 * Sanity checks for cacheable groups code.
2684 */
2685 if (inst->group.cacheable_name && inst->group.obj_membership_filter) {
2686 if (!inst->group.obj_name_attr) {
2687 cf_log_err(conf, "Configuration item 'group.name_attribute' must be set if cacheable "
2688 "group names are enabled");
2689
2690 return -1;
2691 }
2692 }
2693
2694 /*
2695 * If we have a *pair* as opposed to a *section*
2696 * then the module is referencing another ldap module's
2697 * connection pool.
2698 */
2699 if (!cf_pair_find(conf, "pool")) {
2700 if (!inst->handle_config.server_str) {
2701 cf_log_err(conf, "Configuration item 'server' must have a value");
2702 return -1;
2703 }
2704 }
2705
2706#ifndef WITH_SASL
2707 if (inst->handle_config.admin_sasl.mech) {
2708 cf_log_err(conf, "Configuration item 'sasl.mech' not supported. "
2709 "Linked libldap does not provide ldap_sasl_interactive_bind function");
2710 return -1;
2711 }
2712#endif
2713
2714 /*
2715 * Initialise server with zero length string to
2716 * make code below simpler.
2717 */
2718 inst->handle_config.server = talloc_strdup(inst, "");
2719
2720 /*
2721 * Now iterate over all the 'server' config items
2722 */
2723 for (i = 0; i < talloc_array_length(inst->handle_config.server_str); i++) {
2724 char const *value = inst->handle_config.server_str[i];
2725 size_t j;
2726
2727 /*
2728 * Explicitly prevent multiple server definitions
2729 * being used in the same string.
2730 */
2731 for (j = 0; j < talloc_strlen(value); j++) {
2732 switch (value[j]) {
2733 case ' ':
2734 case ',':
2735 case ';':
2736 cf_log_err(conf, "Invalid character '%c' found in 'server' configuration item",
2737 value[j]);
2738 return -1;
2739
2740 default:
2741 continue;
2742 }
2743 }
2744
2745 /*
2746 * Split original server value out into URI, server and port
2747 * so whatever initialization function we use later will have
2748 * the server information in the format it needs.
2749 */
2750 if (ldap_is_ldap_url(value)) {
2751 if (fr_ldap_server_url_check(&inst->handle_config, value, conf) < 0) return -1;
2752 } else
2753 /*
2754 * If it's not an URL, then just treat server as a hostname.
2755 */
2756 {
2757 if (fr_ldap_server_config_check(&inst->handle_config, value, conf) < 0) return -1;
2758 }
2759 }
2760
2761 /*
2762 * inst->handle_config.server be unset if connection pool sharing is used.
2763 */
2764 if (inst->handle_config.server) {
2765 inst->handle_config.server[talloc_array_length(inst->handle_config.server) - 2] = '\0';
2766 DEBUG4("rlm_ldap (%s) - LDAP server string: %s", mctx->mi->name, inst->handle_config.server);
2767 }
2768
2769 /*
2770 * Workaround for servers which support LDAPS but not START TLS
2771 */
2772 if (inst->handle_config.port == LDAPS_PORT || inst->handle_config.tls_mode) {
2773 inst->handle_config.tls_mode = LDAP_OPT_X_TLS_HARD;
2774 } else {
2775 inst->handle_config.tls_mode = 0;
2776 }
2777
2778 /*
2779 * Convert dereference strings to enumerated constants
2780 */
2781 if (inst->handle_config.dereference_str) {
2782 inst->handle_config.dereference = fr_table_value_by_str(fr_ldap_dereference,
2783 inst->handle_config.dereference_str, -1);
2784 if (inst->handle_config.dereference < 0) {
2785 cf_log_err(conf, "Invalid 'dereference' value \"%s\", expected 'never', 'searching', "
2786 "'finding' or 'always'", inst->handle_config.dereference_str);
2787 return -1;
2788 }
2789 }
2790
2791 /*
2792 * Build the server side sort control for user / profile objects
2793 */
2794#define SSS_CONTROL_BUILD(_obj) if (inst->_obj.obj_sort_by) { \
2795 LDAPSortKey **keys; \
2796 int ret; \
2797 ret = ldap_create_sort_keylist(&keys, UNCONST(char *, inst->_obj.obj_sort_by)); \
2798 if (ret != LDAP_SUCCESS) { \
2799 cf_log_err(conf, "Invalid " STRINGIFY(_obj) ".sort_by value \"%s\": %s", \
2800 inst->_obj.obj_sort_by, ldap_err2string(ret)); \
2801 return -1; \
2802 } \
2803 /* \
2804 * Always set the control as critical, if it's not needed \
2805 * the user can comment it out... \
2806 */ \
2807 ret = ldap_create_sort_control(ldap_global_handle, keys, 1, &inst->_obj.obj_sort_ctrl); \
2808 ldap_free_sort_keylist(keys); \
2809 if (ret != LDAP_SUCCESS) { \
2810 ERROR("Failed creating server sort control: %s", ldap_err2string(ret)); \
2811 return -1; \
2812 } \
2813 }
2814
2815 SSS_CONTROL_BUILD(user)
2816 SSS_CONTROL_BUILD(profile)
2817
2818 /*
2819 * Bulk retrieval matches profile objects by their exact DN,
2820 * so subtree (non-base scope) semantics cannot be preserved.
2821 */
2822 switch (inst->profile.search_mode) {
2824 if (inst->profile.obj_sort_ctrl && (inst->profile.obj_scope == LDAP_SCOPE_BASE)) {
2825 inst->profile.search_mode = LDAP_PROFILE_SEARCH_MODE_BULK;
2826 } else {
2827 inst->profile.search_mode = LDAP_PROFILE_SEARCH_MODE_SEQ;
2828 }
2829 break;
2830
2832 if (inst->profile.obj_scope != LDAP_SCOPE_BASE) {
2833 cf_log_err(conf, "'profile.search_mode = bulk' requires 'profile.scope = base'");
2834 return -1;
2835 }
2836 if (!inst->profile.obj_sort_ctrl) {
2837 cf_log_err(conf, "'profile.search_mode = bulk' requires 'profile.sort_by', "
2838 "else profile evaluation order is non-deterministic");
2839 return -1;
2840 }
2841 break;
2842
2844 break;
2845 }
2846
2847 if (inst->handle_config.tls_require_cert_str) {
2848 /*
2849 * Convert cert strictness to enumerated constants
2850 */
2851 inst->handle_config.tls_require_cert = fr_table_value_by_str(fr_ldap_tls_require_cert,
2852 inst->handle_config.tls_require_cert_str, -1);
2853 if (inst->handle_config.tls_require_cert < 0) {
2854 cf_log_err(conf, "Invalid 'tls.require_cert' value \"%s\", expected 'never', "
2855 "'demand', 'allow', 'try' or 'hard'", inst->handle_config.tls_require_cert_str);
2856 return -1;
2857 }
2858 }
2859
2860 if (inst->handle_config.tls_min_version_str) {
2861#ifdef LDAP_OPT_X_TLS_PROTOCOL_TLS1_3
2862 if (strcmp(inst->handle_config.tls_min_version_str, "1.3") == 0) {
2863 inst->handle_config.tls_min_version = LDAP_OPT_X_TLS_PROTOCOL_TLS1_3;
2864
2865 } else
2866#endif
2867 if (strcmp(inst->handle_config.tls_min_version_str, "1.2") == 0) {
2868 inst->handle_config.tls_min_version = LDAP_OPT_X_TLS_PROTOCOL_TLS1_2;
2869
2870 } else if (strcmp(inst->handle_config.tls_min_version_str, "1.1") == 0) {
2871 inst->handle_config.tls_min_version = LDAP_OPT_X_TLS_PROTOCOL_TLS1_1;
2872
2873 } else if (strcmp(inst->handle_config.tls_min_version_str, "1.0") == 0) {
2874 inst->handle_config.tls_min_version = LDAP_OPT_X_TLS_PROTOCOL_TLS1_0;
2875
2876 } else {
2877 cf_log_err(conf, "Invalid 'tls.tls_min_version' value \"%s\"", inst->handle_config.tls_min_version_str);
2878 return -1;
2879 }
2880 }
2881
2882 if (inst->trunk_conf.conn_triggers) {
2883 MEM(inst->trigger_args = fr_pair_list_alloc(inst));
2884 if (module_trigger_args_build(inst->trigger_args, inst->trigger_args, cf_section_find(conf, "pool", NULL),
2886 .module = mctx->mi->module->name,
2887 .name = mctx->mi->name,
2888 .server = inst->handle_config.server,
2889 .port = inst->handle_config.port
2890 }) < 0) return -1;
2891 }
2892
2893 if (inst->bind_trunk_conf.conn_triggers) {
2894 MEM(inst->bind_trigger_args = fr_pair_list_alloc(inst));
2895 if (module_trigger_args_build(inst->bind_trigger_args, inst->bind_trigger_args, cf_section_find(conf, "bind_pool", NULL),
2897 .module = mctx->mi->module->name,
2898 .name = mctx->mi->name,
2899 .server = inst->handle_config.server,
2900 .port = inst->handle_config.port
2901 }) < 0) return -1;
2902 }
2903 return 0;
2904}
2905
2906/** Bootstrap the module
2907 *
2908 * Define attributes.
2909 *
2910 * @param[in] mctx configuration data.
2911 * @return
2912 * - 0 on success.
2913 * - < 0 on failure.
2914 */
2915static int mod_bootstrap(module_inst_ctx_t const *mctx)
2916{
2917 rlm_ldap_boot_t *boot = talloc_get_type_abort(mctx->mi->boot, rlm_ldap_boot_t);
2918 rlm_ldap_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_ldap_t);
2919 CONF_SECTION *conf = mctx->mi->conf;
2920 char buffer[256];
2921 char const *group_attribute;
2922 xlat_t *xlat;
2923
2924 if (inst->group.attribute) {
2925 group_attribute = inst->group.attribute;
2926 } else if (cf_section_name2(conf)) {
2927 snprintf(buffer, sizeof(buffer), "%s-LDAP-Group", mctx->mi->name);
2928 group_attribute = buffer;
2929 } else {
2930 group_attribute = "LDAP-Group";
2931 }
2932
2933 boot->group_da = fr_dict_attr_by_name(NULL, fr_dict_root(dict_freeradius), group_attribute);
2934
2935 /*
2936 * If the group attribute was not in the dictionary, create it
2937 */
2938 if (!boot->group_da) {
2940 group_attribute, FR_TYPE_STRING, NULL) < 0) {
2941 PERROR("Error creating group attribute");
2942 return -1;
2943
2944 }
2945 boot->group_da = fr_dict_attr_by_name(NULL, fr_dict_root(dict_freeradius), group_attribute);
2946 }
2947
2948 /*
2949 * Setup the cache attribute
2950 */
2951 if (inst->group.cache_attr_str) {
2952 boot->cache_da = fr_dict_attr_by_name(NULL, fr_dict_root(dict_freeradius), inst->group.cache_attr_str);
2953 if (!boot->cache_da) {
2955 inst->group.cache_attr_str, FR_TYPE_STRING, NULL) < 0) {
2956 PERROR("Error creating cache attribute");
2957 return -1;
2958 }
2959 boot->cache_da = fr_dict_attr_by_name(NULL, fr_dict_root(dict_freeradius), inst->group.cache_attr_str);
2960 }
2961 } else {
2962 boot->cache_da = boot->group_da; /* Default to the group_da */
2963 }
2964
2965
2966 if (inst->user.dn_attr_str) {
2967 boot->user_da = fr_dict_attr_by_name(NULL, fr_dict_root(dict_freeradius), inst->user.dn_attr_str);
2968 if (!boot->user_da) {
2970 inst->user.dn_attr_str, FR_TYPE_STRING, NULL) < 0) {
2971 PERROR("Error creating user DN cache attribute");
2972 return -1;
2973 }
2974 boot->user_da = fr_dict_attr_by_name(NULL, fr_dict_root(dict_freeradius), inst->user.dn_attr_str);
2975 }
2976 }
2977
2978 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, NULL, ldap_xlat, FR_TYPE_STRING);
2980
2981 if (unlikely(!(xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, "group", ldap_group_xlat,
2982 FR_TYPE_BOOL)))) return -1;
2985
2986 if (unlikely(!(xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, "profile", ldap_profile_xlat,
2987 FR_TYPE_BOOL)))) return -1;
2990
2991 if (unlikely(!module_rlm_xlat_register(mctx->mi->boot, mctx, "whoami", ldap_whoami_xlat,
2992 FR_TYPE_STRING))) return -1;
2993
2995
2996 return 0;
2997}
2998
2999static int mod_load(void)
3000{
3001 xlat_t *xlat;
3002
3003 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.dn.escape", ldap_dn_escape_xlat, FR_TYPE_STRING)))) return -1;
3007
3008 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.dn.safe", xlat_transparent, FR_TYPE_STRING)))) return -1;
3012
3013 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.dn.unescape", ldap_uri_unescape_xlat, FR_TYPE_STRING)))) return -1;
3016
3017 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.filter.escape", ldap_filter_escape_xlat, FR_TYPE_STRING)))) return -1;
3021
3022 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.filter.safe", xlat_transparent, FR_TYPE_STRING)))) return -1;
3026
3027 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.filter.unescape", ldap_uri_unescape_xlat, FR_TYPE_STRING)))) return -1;
3030
3031 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.uri.attr_option", ldap_xlat_uri_attr_option, FR_TYPE_STRING)))) return -1;
3034
3035 /*
3036 * ldap.uri.* are kept as aliases for ldap.dn.* so that existing configs
3037 * continue to work. They use the same safe_for token for now; if the URI
3038 * context ever needs its own rules, a separate token can be introduced.
3039 */
3040 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.uri.escape", ldap_dn_escape_xlat, FR_TYPE_STRING)))) return -1;
3044
3045 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.uri.safe", xlat_transparent, FR_TYPE_STRING)))) return -1;
3049
3050 if (unlikely(!(xlat = xlat_func_register(NULL, "ldap.uri.unescape", ldap_uri_unescape_xlat, FR_TYPE_STRING)))) return -1;
3053
3054 return 0;
3055}
3056
3057static void mod_unload(void)
3058{
3059 xlat_func_unregister("ldap.dn.escape");
3060 xlat_func_unregister("ldap.dn.safe");
3061 xlat_func_unregister("ldap.dn.unescape");
3062 xlat_func_unregister("ldap.filter.escape");
3063 xlat_func_unregister("ldap.filter.safe");
3064 xlat_func_unregister("ldap.filter.unescape");
3065 xlat_func_unregister("ldap.uri.escape");
3066 xlat_func_unregister("ldap.uri.safe");
3067 xlat_func_unregister("ldap.uri.unescape");
3068}
3070/* globally exported name */
3071extern module_rlm_t rlm_ldap;
3073 .common = {
3074 .magic = MODULE_MAGIC_INIT,
3075 .name = "ldap",
3079 .config = module_config,
3080 .onload = mod_load,
3081 .unload = mod_unload,
3082 .bootstrap = mod_bootstrap,
3083 .instantiate = mod_instantiate,
3084 .detach = mod_detach,
3086 .thread_instantiate = mod_thread_instantiate,
3087 .thread_detach = mod_thread_detach,
3088 },
3089 .method_group = {
3090 .bindings = (module_method_binding_t[]){
3091 /*
3092 * Hack to support old configurations
3093 */
3094 { .section = SECTION_NAME("accounting", CF_IDENT_ANY), .method = mod_modify, .method_env = &accounting_usermod_method_env },
3095 { .section = SECTION_NAME("authenticate", CF_IDENT_ANY), .method = mod_authenticate, .method_env = &authenticate_method_env },
3096 { .section = SECTION_NAME("authorize", CF_IDENT_ANY), .method = mod_authorize, .method_env = &authorize_method_env },
3097
3098 { .section = SECTION_NAME("recv", CF_IDENT_ANY), .method = mod_authorize, .method_env = &authorize_method_env },
3099 { .section = SECTION_NAME("send", CF_IDENT_ANY), .method = mod_modify, .method_env = &send_usermod_method_env },
3101 }
3102 }
3103};
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:40
@ 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:38
@ UNLANG_ACTION_YIELD
Temporarily pause execution until an event occurs.
Definition action.h:42
static int const char char buffer[256]
Definition acutest.h:641
int n
Definition acutest.h:642
log_entry msg
Definition acutest.h:947
static uint8_t request[4]
#define USES_APPLE_DEPRECATED_API
Definition build.h:590
#define RCSID(id)
Definition build.h:603
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:245
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
Definition build.h:422
#define unlikely(_x)
Definition build.h:486
#define UNUSED
Definition build.h:415
#define NUM_ELEMENTS(_t)
Definition build.h:437
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:774
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:687
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:759
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:744
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:730
@ CALL_ENV_CTX_TYPE_MODULE
The callenv is registered to a module method.
Definition call_env.h:222
#define CALL_ENV_TERMINATOR
Definition call_env.h:236
call_env_ctx_type_t type
Type of callenv ctx.
Definition call_env.h:227
#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_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_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
module_instance_t const * mi
Module instance that the callenv is registered to.
Definition call_env.h:229
@ 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
#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
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:722
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:666
#define FR_CONF_V3_DEPRECATED(_name, _struct, _field)
conf_parser_t entry which raises an error if a deprecated v3 item is found
Definition cf_parse.h:446
#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
int cf_table_parse_int(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
@ CONF_FLAG_MULTI
CONF_PAIR can have multiple copies.
Definition cf_parse.h:483
@ CONF_FLAG_XLAT
string will be dynamically expanded.
Definition cf_parse.h:480
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition cf_parse.h:460
int cf_table_parse_uint8(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
#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:350
#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
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:649
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:1706
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1405
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:1247
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:671
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:1640
fr_token_t cf_pair_operator(CONF_PAIR const *pair)
Return the operator of a pair.
Definition cf_util.c:1772
fr_token_t cf_pair_value_quote(CONF_PAIR const *pair)
Return the value (rhs) quoting of a pair.
Definition cf_util.c:1802
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:1614
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1758
char const * cf_pair_attr(CONF_PAIR const *pair)
Return the attr of a CONF_PAIR.
Definition cf_util.c:1742
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:340
#define cf_canonicalize_error(_ci, _slen, _msg, _str)
Definition cf_util.h:418
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:347
#define cf_log_warn(_cf, _fmt,...)
Definition cf_util.h:341
#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:2067
fr_dict_t * fr_dict_unconst(fr_dict_t const *dict)
Coerce to non-const.
Definition dict_util.c:5055
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:3608
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
Definition dict_util.c:2725
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
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
#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:146
#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:815
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:1282
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:996
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:1340
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:1145
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:550
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_interpet_frame_discard(request_t *request)
Discard the bottom most frame on the request's stack.
Definition interpret.c:2751
TALLOC_CTX * unlang_interpret_frame_talloc_ctx(request_t *request)
Get a talloc_ctx which is valid only for this frame.
Definition interpret.c:2067
#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:437
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:990
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:368
int count
Index on next free element.
Definition base.h:360
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:327
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:455
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:367
trunk_conf_t * trunk_conf
Module trunk config.
Definition base.h:369
trunk_request_t * treq
Trunk request this query is associated with.
Definition base.h:443
#define LDAP_FILTER_SAFE_FOR
Marks a value box as already escaped for use as a filter assertion value.
Definition base.h:994
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:890
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:711
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:279
fr_pair_list_t * bind_trigger_args
Passed to trigger request for bind trunks.
Definition base.h:375
fr_ldap_connection_t * ldap_conn
LDAP connection this query is running on.
Definition base.h:444
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.
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
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:370
#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:682
LDAPMessage * result
Head of LDAP results list.
Definition base.h:453
fr_event_list_t * el
Thread event list for callbacks / timeouts.
Definition base.h:371
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:357
fr_ldap_thread_trunk_t * bind_trunk
LDAP trunk used for bind auths.
Definition base.h:372
trunk_t * trunk
Connection trunk.
Definition base.h:392
fr_pair_list_t * trigger_args
Passed to trigger request for normal trunks.
Definition base.h:374
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:338
TALLOC_CTX * ctx
Context to allocate new attributes in.
Definition base.h:359
fr_rb_tree_t * binds
Tree of outstanding bind auths.
Definition base.h:373
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:413
Holds arguments for async bind auth requests.
Definition base.h:600
Connection configuration.
Definition base.h:230
Tracks the state of a libldap connection handle.
Definition base.h:326
Result of expanding the RHS of a set of maps.
Definition base.h:355
LDAP query structure.
Definition base.h:409
Holds arguments for the async SASL bind operation.
Definition base.h:491
Thread specific structure to manage LDAP trunk connections.
Definition base.h:366
Thread LDAP trunk structure.
Definition base.h:386
State of an in place iteration over an attribute's values.
Definition base.h:943
#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:1104
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:748
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:1025
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:876
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:696
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 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:1168
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:1846
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:791
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:716
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:318
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:276
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)
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_INVALID
Definition rcode.h:72
#define RETURN_UNLANG_RCODE(_rcode)
Definition rcode.h:67
#define RETURN_UNLANG_NOTFOUND
Definition rcode.h:74
#define RETURN_UNLANG_FAIL
Definition rcode.h:69
#define RETURN_UNLANG_OK
Definition rcode.h:70
#define RETURN_UNLANG_NOOP
Definition rcode.h:75
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:1521
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:1997
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:2379
static int mod_load(void)
Definition rlm_ldap.c:2996
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:1117
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:912
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:1372
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:1108
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:535
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:1396
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:1721
#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:1492
fr_dict_attr_t const * cache_da
Definition rlm_ldap.c:50
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:2133
fr_ldap_query_t * query
Current query performing the whoami operation.
Definition rlm_ldap.c:1275
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
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
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:716
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:2311
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
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:2912
#define REPEAT_MOD_AUTHORIZE_RESUME
Definition rlm_ldap.c:1703
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:2013
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:3054
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:974
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:923
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:903
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:756
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:2104
static int ldap_xlat_profile_ctx_free(ldap_xlat_profile_ctx_t *to_free)
Definition rlm_ldap.c:1130
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:725
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:626
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:2602
module_rlm_t rlm_ldap
Definition rlm_ldap.c:3069
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:1605
static int autz_ctx_free(ldap_autz_ctx_t *autz_ctx)
Ensure authorization context is properly cleared up.
Definition rlm_ldap.c:2007
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:1111
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:673
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:711
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:2092
static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
Clean up thread specific data structure.
Definition rlm_ldap.c:2582
static int mod_instantiate(module_inst_ctx_t const *mctx)
Instantiate the module.
Definition rlm_ldap.c:2649
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:699
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:2274
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:1685
char const * dn
Definition rlm_ldap.c:381
static xlat_arg_parser_t const ldap_group_xlat_arg[]
Definition rlm_ldap.c:987
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:1274
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
fr_ldap_map_exp_t expanded
Definition rlm_ldap.h:227
ldap_autz_call_env_t * call_env
Definition rlm_ldap.h:230
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
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
@ 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_query_t * query
Definition rlm_ldap.h:228
@ 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
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
@ 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
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:268
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
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_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
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:222
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:515
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:444
#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:191
#define fr_sbuff_buff(_sbuff_or_marker)
Talloc sbuff extension structure.
Definition sbuff.h:138
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:261
char const * name
Instance name e.g. user_database.
Definition module.h:361
module_flags_t flags
Flags that control how a module starts up and how a module is called.
Definition module.h:237
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:355
void * data
Module's instance data.
Definition module.h:297
#define MODULE_BOOT(_ctype)
Definition module.h:259
void * boot
Data allocated during the boostrap phase.
Definition module.h:300
void * data
Thread specific instance data.
Definition module.h:378
static module_thread_instance_t * module_thread(module_instance_t const *mi)
Retrieve module/thread specific instance for a module.
Definition module.h:517
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Definition module.h:153
#define MODULE_INST(_ctype)
Definition module.h:260
@ MODULE_TYPE_NONE
No module flags.
Definition module.h:49
Named methods exported by a module.
Definition module.h:175
static tmpl_attr_t const * tmpl_attr_tail(tmpl_t const *vpt)
Return the last attribute reference.
Definition tmpl.h:815
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:346
#define tmpl_needs_resolving(vpt)
Definition tmpl.h:230
Similar to tmpl_rules_t, but used to specify parameters that may change during subsequent resolution ...
Definition tmpl.h:391
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:343
#define FR_SIGNAL_ALLOW(_signals)
Signal mask which blocks every signal except the ones in _signals.
Definition signal.h:58
fr_signal_t
Signals that can be generated/processed by request signal handlers.
Definition signal.h:38
@ FR_SIGNAL_NONE
No signals.
Definition signal.h:39
@ 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
return count
Definition module.c:155
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:280
An element in a list of nested attribute references.
Definition tmpl.h:457
fr_dict_attr_t const *_CONST da
Resolved dictionary attribute.
Definition tmpl.h:461
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:571
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
Definition talloc.c:621
#define talloc_get_type_abort_const
Definition talloc.h:117
char const ** strings
NULL terminated array of strings.
Definition talloc.h:255
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:269
#define talloc_asprintf
Definition talloc.h:151
#define talloc_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size)
Definition talloc.h:212
#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:254
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
@ 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
enum fr_token fr_token_t
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
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
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
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
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:4851
fr_sbuff_parse_rules_t const * value_parse_rules_quoted[T_TOKEN_LAST]
Parse rules for quoted strings.
Definition value.c:620
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:4326
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:4873
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:4973
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:5014
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:5122
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:6793
@ FR_VALUE_BOX_LIST_FREE
Definition value.h:267
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
Definition value.h:668
static fr_sbuff_err_t char size_t fr_sbuff_t * in
Definition value.h:1061
#define fr_value_box_is_safe_for_only(_box, _safe_for)
Definition value.h:1132
static fr_sbuff_err_t char ** out
Definition value.h:1061
#define fr_box_is_null(_x)
Definition value.h:455
static fr_sbuff_err_t char size_t * len
Definition value.h:1061
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:679
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:520
#define xlat_func_safe_for_set(_xlat, _escaped)
Set the escaped values for output boxes.
Definition xlat_func.h:84
@ XLAT_FUNC_FLAG_PURE
Definition xlat_func.h:38