The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
rlm_ldap.h
Go to the documentation of this file.
1#pragma once
2/**
3 * $Id: 6ee41c9cdade115ad4178ebcadf0aaf18aba78ff $
4 * @file rlm_ldap.h
5 * @brief LDAP authorization and authentication module headers.
6 *
7 * @note Do not rename to ldap.h. This causes configure checks to break
8 * in stupid ways, where the configure script will use the local ldap.h
9 * file, instead of the one from libldap.
10 *
11 * @author Arran Cudbard-Bell (a.cudbardb@freeradius.org)
12 * @copyright 2015 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
13 * @copyright 2013 Network RADIUS SAS (legal@networkradius.com)
14 * @copyright 2013-2015 The FreeRADIUS Server Project.
15 */
16#include <freeradius-devel/server/base.h>
17#include <freeradius-devel/server/module_rlm.h>
18#include <freeradius-devel/ldap/base.h>
19
20/** How profile objects are retrieved from the directory
21 *
22 */
23typedef enum {
24 LDAP_PROFILE_SEARCH_MODE_AUTO = 0, //!< Resolved at instantiation, LDAP_PROFILE_SEARCH_MODE_BULK
25 ///< when server side sorting is configured and the search
26 ///< scope is base, otherwise LDAP_PROFILE_SEARCH_MODE_SEQ.
27 LDAP_PROFILE_SEARCH_MODE_SEQ, //!< One search per profile DN, applied in list order.
28 LDAP_PROFILE_SEARCH_MODE_BULK //!< A single search retrieving every profile object,
29 ///< applied in result order. Requires base scope.
31
32typedef struct {
33 /*
34 * Options
35 */
36#ifdef LDAP_CONTROL_X_SESSION_TRACKING
37 bool session_tracking; //!< Whether we add session tracking controls, which help
38 //!< identify the autz or acct session the commands were
39 //!< issued for.
40#endif
41 struct {
42 /*
43 * User object attributes and filters
44 */
45 char const *obj_sort_by; //!< List of attributes to sort by.
46 LDAPControl *obj_sort_ctrl; //!< Server side sort control.
47
48 int obj_scope; //!< Search scope.
49
50 char const *obj_access_attr; //!< Attribute to check to see if the user should be locked out.
51 bool access_positive; //!< If true the presence of the attribute will allow access,
52 //!< else it will deny access.
53
54 char const *access_value_negate; //!< If the value of the access_attr matches this, the result
55 ///< will be negated.
56 char const *access_value_suspend; //!< Value that indicates suspension. Is not affected by
57 ///< access_positive and will always allow access, but will apply
58 ///< a different profile.
59 bool expect_password; //!< Allow the user to forcefully decide if a password should be
60 ///< expected. Controls whether warnings are issued.
61 bool expect_password_is_set; //!< Whether an expect password value was provided.
62
63 char const *profile_attr; //!< Attribute in the user object naming profiles to apply.
64 char const *profile_attr_suspend; //!< Attribute in the user object naming profiles to apply
65 ///< when the user's account is suspended.
66
67 char const *dn_attr_str; //!< Sets the attribute we use when creating and retrieving
68 //!< cached group memberships.
69
70 fr_dict_attr_t const *da; //!< The DA associated with this specific instance of the
71 //!< rlm_ldap module for caching user DNs between autz and
72 ///< auth phases.
73 } user;
74
75 /*
76 * Group object attributes and filters
77 */
78 struct {
79 char const *userobj_membership_attr; //!< Attribute that describes groups the user is a member of.
80
81 char const *obj_filter; //!< Filter to retrieve only group objects.
82 int obj_scope; //!< Search scope.
83
84 char const *obj_name_attr; //!< The name of the group.
85 char const *obj_membership_filter; //!< Filter to only retrieve groups which contain
86 //!< the user as a member.
87
88 bool cacheable_name; //!< If true the server will determine complete set of group
89 //!< memberships for the current user object, and perform any
90 //!< resolution necessary to determine the names of those
91 //!< groups, then right them to the control list (LDAP-Group).
92
93 bool cacheable_dn; //!< If true the server will determine complete set of group
94 //!< memberships for the current user object, and perform any
95 //!< resolution necessary to determine the DNs of those groups,
96 //!< then right them to the control list (LDAP-GroupDN).
97
98 char const *cache_attr_str; //!< Sets the attribute we use when creating and retrieving
99 //!< cached group memberships.
100
101 fr_dict_attr_t const *cache_da; //!< The DA associated with this specific instance of the
102 //!< rlm_ldap module.
103
104 char const *attribute; //!< Sets the attribute we use when comparing group
105 //!< group memberships.
106
107 fr_dict_attr_t const *da; //!< The DA associated with this specific instance of the
108 //!< rlm_ldap module.
109
110 bool allow_dangling_refs; //!< Don't error if we fail to resolve a group DN referenced
111 ///< from a user object.
112
113 bool skip_on_suspend; //!< Don't process groups if the user is suspended.
114
115 char const *profile_attr; //!< Attribute in group objects naming profiles to apply.
116 char const *profile_attr_suspend; //!< Attribute in group objects naming profiles to apply
117 ///< when the user's account is suspended.
118 } group;
119
120 char const *valuepair_attr; //!< Generic dynamic mapping attribute, contains a RADIUS
121 //!< attribute and value.
122
123 char const *dn_attr; //!< Attribute to match an entry's DN in a search filter.
124 ///< If unset, the value detected for the directory
125 ///< (fr_ldap_directory_t dn_attr) is used.
126
127 /*
128 * Profiles
129 */
130 struct {
131 int obj_scope; //!< Search scope.
132 ldap_profile_search_mode_t search_mode; //!< Whether profiles are retrieved one at a time or
133 ///< with a single search.
134 char const *obj_sort_by; //!< List of attributes to sort profiles by
135 LDAPControl *obj_sort_ctrl; //!< Server side sort control
136 char const *check_attr; //!< LDAP attribute containing check conditions to determine if
137 //!< the profile should be applied
138 char const *fallthrough_attr; //!< LDAP attribute containing conditions to determine if
139 ///< processing should continue to the next profile when more
140 ///< than one is returned.
141 bool fallthrough_def; //!< Should profile processing fall through by default.
142 } profile;
143
144#ifdef WITH_EDIR
145 /*
146 * eDir support
147 */
148 bool edir; //!< If true attempt to retrieve the user's cleartext password
149 //!< using the Universal Password feature of Novell eDirectory.
150 bool edir_autz; //!< If true, and we have the Universal Password, bind with it
151 //!< to perform additional authorisation checks.
152#endif
153
154 fr_ldap_config_t handle_config; //!< Connection configuration instance.
155 trunk_conf_t trunk_conf; //!< Trunk configuration
156 trunk_conf_t bind_trunk_conf; //!< Trunk configuration for trunk used for bind auths
157
158 module_instance_t const *mi; //!< Module instance data for thread lookups.
159
160 fr_pair_list_t *trigger_args; //!< Pairs passed to trigger request for standard trunk.
161 fr_pair_list_t *bind_trigger_args; //!< Pairs passed to trigger request for bind trunk.
162} rlm_ldap_t;
163
164/** Call environment used in LDAP authorization
165 *
166 */
167typedef struct {
168 fr_value_box_t user_base; //!< Base DN in which to search for users.
169 fr_value_box_t user_filter; //!< Filter to use when searching for users.
170 fr_value_box_t group_base; //!< Base DN in which to search for groups.
171 tmpl_t *group_filter; //!< tmpl to expand as group membership filter.
172 fr_value_box_t default_profile; //!< If this is set, we will search for a profile object
173 //!< with this name, and map any attributes it contains.
174 //!< No value should be set if profiles are not being used
175 //!< as there is an associated performance penalty.
176 fr_value_box_t profile_child_rdn; //!< RDN of a child object to evaluate below each profile.
177 fr_value_box_t profile_filter; //!< Filter to use when searching for profiles.
178
179 map_list_t *user_map; //!< Attribute map applied to users and profiles.
180
181 fr_value_box_t const *expect_password; //!< True if the user_map included a mapping between an LDAP
182 //!< attribute and one of our password reference attributes.
184
185/** Call environment used in group membership xlat
186 *
187 */
188typedef struct {
189 fr_value_box_t user_base; //!< Base DN in which to search for users.
190 fr_value_box_t user_filter; //!< Filter to use when searching for users.
191 fr_value_box_t group_base; //!< Base DN in which to search for groups.
192 tmpl_t *group_filter; //!< tmpl to expand as group membership filter.
194
195/** State list for resumption of authorization
196 *
197 */
198typedef enum {
203#ifdef WITH_EDIR
204 LDAP_AUTZ_EDIR_BIND,
205 LDAP_AUTZ_POST_EDIR,
206#endif
211
212/** User's access state
213 *
214 */
215typedef enum {
216 LDAP_ACCESS_ALLOWED = 0, //!< User is allowed to login.
217 LDAP_ACCESS_DISALLOWED, //!< User it not allow to login (disabled)
218 LDAP_ACCESS_SUSPENDED //!< User account has been suspended.
220
221/** Holds state of in progress async authorization
222 *
223 */
224typedef struct {
231 LDAPMessage *entry;
233 char const **profile_dn_list; //!< List of profile DNs to apply, default profile first,
234 ///< then group profiles, then profiles from the user
235 ///< object. NULL terminated.
236 talloc_str_list_t *group_dn_list; //!< DNs of the group objects the user is a member of.
237 talloc_str_list_t *group_profile_dn_list; //!< Profile DNs found in the user's group objects.
238 int profiles_applied; //!< Number of profile maps applied.
239 char const *dn;
240 ldap_access_state_t access_state; //!< What state a user's account is in.
241 rlm_rcode_t rcode; //!< What rcode we'll finally respond with.
243
244/** Return the profile attribute matching the user's access state
245 *
246 * User and group objects have their own profile attribute pairs, the
247 * caller passes the pair for the object type being processed.
248 */
249static inline char const *rlm_ldap_profile_attr_select(char const *attr, char const *attr_suspend,
250 ldap_access_state_t access_state)
251{
252 switch (access_state) {
254 return attr;
255
257 return attr_suspend;
258
260 break;
261 }
262
263 return NULL;
264}
265
266/** State list for xlat evaluation of LDAP group membership
267 */
273
274/** Holds state of in progress group membership check xlat
275 *
276 */
292
298
301
302/*
303 * user.c - User lookup functions
304 */
305static inline char const *rlm_find_user_dn_cached(rlm_ldap_t const *inst, request_t *request)
306{
307 fr_pair_t *vp;
308
309 vp = fr_pair_find_by_da(&request->control_pairs, NULL, inst->user.da);
310 if (!vp) return NULL;
311
312 RDEBUG2("Using user DN from request \"%pV\"", &vp->data);
313 return vp->vp_strvalue;
314}
315
317 unlang_result_t *p_result,
318 rlm_ldap_t const *inst, request_t *request,
319 fr_value_box_t *base, fr_value_box_t *filter_box,
320 fr_ldap_thread_trunk_t *ttrunk, char const *attrs[],
321 fr_ldap_query_t **query_out);
322
323ldap_access_state_t rlm_ldap_check_access(rlm_ldap_t const *inst, request_t *request, LDAPMessage *entry);
324
325void 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);
326
327/*
328 * groups.c - Group membership functions.
329 */
331 char const *attr);
332
334
336
339
342
344 rlm_ldap_t const *inst, request_t *request, fr_value_box_t const *check);
345
347 rlm_ldap_t const *inst, request_t *request, fr_ldap_thread_trunk_t *ttrunk,
348 char const *dn, int scope, char const *filter, fr_ldap_map_exp_t const *expanded);
349
351 rlm_ldap_t const *inst, request_t *request, fr_ldap_thread_trunk_t *ttrunk,
352 char const * const *dn_list, char const *filter,
353 fr_ldap_map_exp_t const *expanded);
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
#define HIDDEN
Definition build.h:335
fr_ldap_result_code_t
LDAP query result codes.
Definition base.h:189
Connection configuration.
Definition base.h:231
Result of expanding the RHS of a set of maps.
Definition base.h:371
LDAP query structure.
Definition base.h:425
Thread LDAP trunk structure.
Definition base.h:402
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:707
#define RDEBUG2(fmt,...)
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:44
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
unlang_action_t rlm_ldap_map_profiles(fr_ldap_result_code_t *ret, int *applied, rlm_ldap_t const *inst, request_t *request, fr_ldap_thread_trunk_t *ttrunk, char const *const *dn_list, char const *filter, fr_ldap_map_exp_t const *expanded)
Search for and apply a set of LDAP profiles.
Definition profile.c:311
ldap_profile_search_mode_t
How profile objects are retrieved from the directory.
Definition rlm_ldap.h:23
@ 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_xlat_memberof_call_env_t * env_data
Definition rlm_ldap.h:280
fr_value_box_t * basedn
Definition rlm_ldap.h:285
fr_ldap_map_exp_t expanded
Definition rlm_ldap.h:227
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:748
HIDDEN fr_dict_attr_t const * attr_password
Definition rlm_ldap.c:355
fr_value_box_t * filter
Definition rlm_ldap.h:284
fr_pair_list_t * bind_trigger_args
Pairs passed to trigger request for bind trunk.
Definition rlm_ldap.h:161
ldap_autz_call_env_t * call_env
Definition rlm_ldap.h:230
HIDDEN fr_dict_attr_t const * attr_crypt_password
Definition rlm_ldap.c:357
unlang_result_t result
Definition rlm_ldap.h:289
ldap_access_state_t
User's access state.
Definition rlm_ldap.h:215
@ 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
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:950
unlang_action_t rlm_ldap_map_profile(fr_ldap_result_code_t *ret, int *applied, rlm_ldap_t const *inst, request_t *request, fr_ldap_thread_trunk_t *ttrunk, char const *dn, int scope, char const *filter, fr_ldap_map_exp_t const *expanded)
Search for and apply an LDAP profile.
Definition profile.c:269
fr_ldap_thread_trunk_t * ttrunk
Definition rlm_ldap.h:229
HIDDEN fr_dict_attr_t const * attr_user_name
Definition base.c:101
fr_ldap_query_t * query
Definition rlm_ldap.h:287
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
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:438
tmpl_t * group_filter
tmpl to expand as group membership filter.
Definition rlm_ldap.h:171
trunk_conf_t bind_trunk_conf
Trunk configuration for trunk used for bind auths.
Definition rlm_ldap.h:156
LDAPMessage * entry
Definition rlm_ldap.h:231
HIDDEN fr_dict_attr_t const * attr_nt_password
Definition rlm_ldap.c:358
ldap_autz_status_t
State list for resumption of authorization.
Definition rlm_ldap.h:198
@ LDAP_AUTZ_GROUP
Definition rlm_ldap.h:200
@ LDAP_AUTZ_POST_PROFILES
Definition rlm_ldap.h:209
@ LDAP_AUTZ_FIND
Definition rlm_ldap.h:199
@ LDAP_AUTZ_PROFILES
Definition rlm_ldap.h:208
@ LDAP_AUTZ_MAP
Definition rlm_ldap.h:207
@ LDAP_AUTZ_GROUP_PROFILES
Definition rlm_ldap.h:201
@ LDAP_AUTZ_POST_GROUP
Definition rlm_ldap.h:202
char const ** profile_dn_list
List of profile DNs to apply, default profile first, then group profiles, then profiles from the user...
Definition rlm_ldap.h:233
fr_value_box_t * group
Definition rlm_ldap.h:279
ldap_autz_status_t status
Definition rlm_ldap.h:232
char const * valuepair_attr
Generic dynamic mapping attribute, contains a RADIUS attribute and value.
Definition rlm_ldap.h:120
fr_value_box_t profile_child_rdn
RDN of a child object to evaluate below each profile.
Definition rlm_ldap.h:176
fr_ldap_query_t * query
Definition rlm_ldap.h:228
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:1300
fr_value_box_t user_base
Base DN in which to search for users.
Definition rlm_ldap.h:189
rlm_ldap_t const * inst
Definition rlm_ldap.h:278
fr_ldap_config_t handle_config
Connection configuration instance.
Definition rlm_ldap.h:154
HIDDEN fr_dict_attr_t const * attr_user_password
Definition rlm_yubikey.c:63
ldap_group_xlat_status_t status
Definition rlm_ldap.h:288
tmpl_t * group_filter
tmpl to expand as group membership filter.
Definition rlm_ldap.h:192
fr_value_box_t group_base
Base DN in which to search for groups.
Definition rlm_ldap.h:170
char const * dn_attr
Attribute to match an entry's DN in a search filter.
Definition rlm_ldap.h:123
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
HIDDEN fr_dict_attr_t const * attr_password_with_header
Definition rlm_ldap.c:359
fr_ldap_thread_trunk_t * ttrunk
Definition rlm_ldap.h:286
fr_value_box_t group_base
Base DN in which to search for groups.
Definition rlm_ldap.h:191
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
trunk_conf_t trunk_conf
Trunk configuration.
Definition rlm_ldap.h:155
module_instance_t const * mi
Module instance data for thread lookups.
Definition rlm_ldap.h:158
void rlm_ldap_check_reply(request_t *request, rlm_ldap_t const *inst, char const *inst_name, bool expect_password, fr_ldap_thread_trunk_t const *ttrunk)
Verify we got a password from the search.
Definition user.c:258
fr_value_box_t const * expect_password
True if the user_map included a mapping between an LDAP attribute and one of our password reference a...
Definition rlm_ldap.h:181
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:852
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:1343
fr_pair_list_t * trigger_args
Pairs passed to trigger request for standard trunk.
Definition rlm_ldap.h:160
fr_value_box_t user_filter
Filter to use when searching for users.
Definition rlm_ldap.h:190
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
ldap_group_xlat_status_t
State list for xlat evaluation of LDAP group membership.
Definition rlm_ldap.h:268
@ 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
HIDDEN fr_dict_attr_t const * attr_cleartext_password
Definition rlm_ldap.c:356
talloc_str_list_t * group_dn_list
DNs of the group objects the user is a member of.
Definition rlm_ldap.h:236
module_instance_t const * dlinst
Definition rlm_ldap.h:225
ldap_access_state_t rlm_ldap_check_access(rlm_ldap_t const *inst, request_t *request, LDAPMessage *entry)
Check for presence of access attribute in result.
Definition user.c:212
char const * dn
Definition rlm_ldap.h:282
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
Module instance data.
Definition module.h:287
eap_aka_sim_process_conf_t * inst
fr_pair_t * vp
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
A NULL terminated array of strings with an append cursor.
Definition talloc.h:253
Common configuration parameters for a trunk.
Definition trunk.h:234
static TALLOC_CTX * xlat_ctx