The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
rlm_ldap.h
Go to the documentation of this file.
1#pragma once
2/**
3 * $Id: 4c7911a86e7575dbd42035e5ab1f3ffa12b2fe0b $
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
20typedef struct {
21 /*
22 * Options
23 */
24#ifdef LDAP_CONTROL_X_SESSION_TRACKING
25 bool session_tracking; //!< Whether we add session tracking controls, which help
26 //!< identify the autz or acct session the commands were
27 //!< issued for.
28#endif
29 struct {
30 /*
31 * User object attributes and filters
32 */
33 char const *obj_sort_by; //!< List of attributes to sort by.
34 LDAPControl *obj_sort_ctrl; //!< Server side sort control.
35
36 int obj_scope; //!< Search scope.
37
38 char const *obj_access_attr; //!< Attribute to check to see if the user should be locked out.
39 bool access_positive; //!< If true the presence of the attribute will allow access,
40 //!< else it will deny access.
41
42 char const *access_value_negate; //!< If the value of the access_attr matches this, the result
43 ///< will be negated.
44 char const *access_value_suspend; //!< Value that indicates suspension. Is not affected by
45 ///< access_positive and will always allow access, but will apply
46 ///< a different profile.
47 bool expect_password; //!< Allow the user to forcefully decide if a password should be
48 ///< expected. Controls whether warnings are issued.
49 bool expect_password_is_set; //!< Whether an expect password value was provided.
50 } user;
51
52 /*
53 * Group object attributes and filters
54 */
55 struct {
56 char const *userobj_membership_attr; //!< Attribute that describes groups the user is a member of.
57
58 char const *obj_filter; //!< Filter to retrieve only group objects.
59 int obj_scope; //!< Search scope.
60
61 char const *obj_name_attr; //!< The name of the group.
62 char const *obj_membership_filter; //!< Filter to only retrieve groups which contain
63 //!< the user as a member.
64
65 bool cacheable_name; //!< If true the server will determine complete set of group
66 //!< memberships for the current user object, and perform any
67 //!< resolution necessary to determine the names of those
68 //!< groups, then right them to the control list (LDAP-Group).
69
70 bool cacheable_dn; //!< If true the server will determine complete set of group
71 //!< memberships for the current user object, and perform any
72 //!< resolution necessary to determine the DNs of those groups,
73 //!< then right them to the control list (LDAP-GroupDN).
74
75 char const *cache_attribute; //!< Sets the attribute we use when creating and retrieving
76 //!< cached group memberships.
77
78 fr_dict_attr_t const *cache_da; //!< The DA associated with this specific instance of the
79 //!< rlm_ldap module.
80
81 char const *attribute; //!< Sets the attribute we use when comparing group
82 //!< group memberships.
83
84 fr_dict_attr_t const *da; //!< The DA associated with this specific instance of the
85 //!< rlm_ldap module.
86
87 bool allow_dangling_refs; //!< Don't error if we fail to resolve a group DN referenced
88 ///< from a user object.
89
90 bool skip_on_suspend; //!< Don't process groups if the user is suspended.
91 } group;
92
93 char const *valuepair_attr; //!< Generic dynamic mapping attribute, contains a RADIUS
94 //!< attribute and value.
95
96 /*
97 * Profiles
98 */
99 int profile_scope; //!< Search scope.
100 char const *profile_attr; //!< Attribute that identifies profiles to apply. May appear
101 //!< in userobj or groupobj.
102 char const *profile_attr_suspend; //!< Attribute that identifies profiles to apply when the user's
103 ///< account is suspended. May appear in userobj or groupobj.
104
105#ifdef WITH_EDIR
106 /*
107 * eDir support
108 */
109 bool edir; //!< If true attempt to retrieve the user's cleartext password
110 //!< using the Universal Password feature of Novell eDirectory.
111 bool edir_autz; //!< If true, and we have the Universal Password, bind with it
112 //!< to perform additional authorisation checks.
113#endif
114
115 fr_ldap_config_t handle_config; //!< Connection configuration instance.
116 trunk_conf_t trunk_conf; //!< Trunk configuration
117 trunk_conf_t bind_trunk_conf; //!< Trunk configuration for trunk used for bind auths
118
119 module_instance_t const *mi; //!< Module instance data for thread lookups.
120} rlm_ldap_t;
121
122/** Call environment used in LDAP authorization
123 *
124 */
125typedef struct {
126 fr_value_box_t user_base; //!< Base DN in which to search for users.
127 fr_value_box_t user_filter; //!< Filter to use when searching for users.
128 fr_value_box_t group_base; //!< Base DN in which to search for groups.
129 tmpl_t *group_filter; //!< tmpl to expand as group membership filter.
130 fr_value_box_t default_profile; //!< If this is set, we will search for a profile object
131 //!< with this name, and map any attributes it contains.
132 //!< No value should be set if profiles are not being used
133 //!< as there is an associated performance penalty.
134 fr_value_box_t profile_filter; //!< Filter to use when searching for profiles.
135
136 map_list_t *user_map; //!< Attribute map applied to users and profiles.
137
138 fr_value_box_t const *expect_password; //!< True if the user_map included a mapping between an LDAP
139 //!< attribute and one of our password reference attributes.
141
142/** Call environment used in group membership xlat
143 *
144 */
145typedef struct {
146 fr_value_box_t user_base; //!< Base DN in which to search for users.
147 fr_value_box_t user_filter; //!< Filter to use when searching for users.
148 fr_value_box_t group_base; //!< Base DN in which to search for groups.
149 tmpl_t *group_filter; //!< tmpl to expand as group membership filter.
151
152/** State list for resumption of authorization
153 *
154 */
168
169/** User's access state
170 *
171 */
172typedef enum {
173 LDAP_ACCESS_ALLOWED = 0, //!< User is allowed to login.
174 LDAP_ACCESS_DISALLOWED, //!< User it not allow to login (disabled)
175 LDAP_ACCESS_SUSPENDED //!< User account has been suspended.
177
178/** Holds state of in progress async authorization
179 *
180 */
196
197/** State list for xlat evaluation of LDAP group membership
198 */
204
205/** Holds state of in progress group membership check xlat
206 *
207 */
222
229
232
233/*
234 * user.c - User lookup functions
235 */
236static inline char const *rlm_find_user_dn_cached(request_t *request)
237{
238 fr_pair_t *vp;
239
240 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_ldap_userdn);
241 if (!vp) return NULL;
242
243 RDEBUG2("Using user DN from request \"%pV\"", &vp->data);
244 return vp->vp_strvalue;
245}
246
247unlang_action_t rlm_ldap_find_user_async(TALLOC_CTX *ctx, rlm_ldap_t const *inst, request_t *request,
248 fr_value_box_t *base, fr_value_box_t *filter_box,
249 fr_ldap_thread_trunk_t *ttrunk, char const *attrs[],
250 fr_ldap_query_t **query_out);
251
252ldap_access_state_t rlm_ldap_check_access(rlm_ldap_t const *inst, request_t *request, LDAPMessage *entry);
253
254void 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);
255
256/*
257 * groups.c - Group membership functions.
258 */
260 char const *attr);
261
263
266
269
271 rlm_ldap_t const *inst, request_t *request, fr_value_box_t const *check);
272
274 rlm_ldap_t const *inst, request_t *request, fr_ldap_thread_trunk_t *ttrunk,
275 char const *dn, int scope, char const *filter, 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:314
fr_ldap_result_code_t
LDAP query result codes.
Definition base.h:188
Connection configuration.
Definition base.h:221
Result of expanding the RHS of a set of maps.
Definition base.h:370
LDAP query structure.
Definition base.h:422
Thread LDAP trunk structure.
Definition base.h:399
#define check(_handle, _len_p)
Definition bio.c:44
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:693
#define RDEBUG2(fmt,...)
Definition radclient.h:54
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
ldap_xlat_memberof_call_env_t * env_data
Definition rlm_ldap.h:211
char const * profile_attr
Attribute that identifies profiles to apply.
Definition rlm_ldap.h:100
fr_value_box_t * basedn
Definition rlm_ldap.h:216
fr_ldap_map_exp_t expanded
Definition rlm_ldap.h:184
HIDDEN fr_dict_attr_t const * attr_password
Definition rlm_ldap.c:317
fr_value_box_t * filter
Definition rlm_ldap.h:215
ldap_autz_call_env_t * call_env
Definition rlm_ldap.h:187
struct berval ** profile_values
Definition rlm_ldap.h:190
unlang_action_t rlm_ldap_map_profile(fr_ldap_result_code_t *ret, 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:144
HIDDEN fr_dict_attr_t const * attr_crypt_password
Definition rlm_ldap.c:319
ldap_access_state_t
User's access state.
Definition rlm_ldap.h:172
@ LDAP_ACCESS_SUSPENDED
User account has been suspended.
Definition rlm_ldap.h:175
@ LDAP_ACCESS_ALLOWED
User is allowed to login.
Definition rlm_ldap.h:173
@ LDAP_ACCESS_DISALLOWED
User it not allow to login (disabled)
Definition rlm_ldap.h:174
unlang_action_t rlm_ldap_cacheable_userobj(rlm_rcode_t *p_result, request_t *request, ldap_autz_ctx_t *autz_ctx, char const *attr)
Convert group membership information into attributes.
Definition groups.c:443
fr_ldap_thread_trunk_t * ttrunk
Definition rlm_ldap.h:186
HIDDEN fr_dict_attr_t const * attr_user_name
Definition base.c:104
fr_ldap_query_t * query
Definition rlm_ldap.h:218
rlm_ldap_t const * inst
Definition rlm_ldap.h:183
fr_value_box_t profile_filter
Filter to use when searching for profiles.
Definition rlm_ldap.h:134
fr_value_box_t user_filter
Filter to use when searching for users.
Definition rlm_ldap.h:127
tmpl_t * group_filter
tmpl to expand as group membership filter.
Definition rlm_ldap.h:129
trunk_conf_t bind_trunk_conf
Trunk configuration for trunk used for bind auths.
Definition rlm_ldap.h:117
LDAPMessage * entry
Definition rlm_ldap.h:188
HIDDEN fr_dict_attr_t const * attr_nt_password
Definition rlm_ldap.c:321
char const * profile_attr_suspend
Attribute that identifies profiles to apply when the user's account is suspended.
Definition rlm_ldap.h:102
ldap_autz_status_t
State list for resumption of authorization.
Definition rlm_ldap.h:155
@ LDAP_AUTZ_GROUP
Definition rlm_ldap.h:157
@ LDAP_AUTZ_FIND
Definition rlm_ldap.h:156
@ LDAP_AUTZ_DEFAULT_PROFILE
Definition rlm_ldap.h:164
@ LDAP_AUTZ_USER_PROFILE
Definition rlm_ldap.h:166
@ LDAP_AUTZ_MAP
Definition rlm_ldap.h:163
@ LDAP_AUTZ_POST_DEFAULT_PROFILE
Definition rlm_ldap.h:165
@ LDAP_AUTZ_POST_GROUP
Definition rlm_ldap.h:158
fr_value_box_t * group
Definition rlm_ldap.h:210
ldap_autz_status_t status
Definition rlm_ldap.h:189
char const * valuepair_attr
Generic dynamic mapping attribute, contains a RADIUS attribute and value.
Definition rlm_ldap.h:93
fr_ldap_query_t * query
Definition rlm_ldap.h:185
char * profile_value
Definition rlm_ldap.h:192
fr_value_box_t user_base
Base DN in which to search for users.
Definition rlm_ldap.h:146
rlm_ldap_t const * inst
Definition rlm_ldap.h:209
HIDDEN fr_dict_attr_t const * attr_ldap_userdn
Definition rlm_ldap.c:320
fr_ldap_config_t handle_config
Connection configuration instance.
Definition rlm_ldap.h:115
HIDDEN fr_dict_attr_t const * attr_user_password
ldap_group_xlat_status_t status
Definition rlm_ldap.h:219
unlang_action_t rlm_ldap_check_userobj_dynamic(rlm_rcode_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:1117
tmpl_t * group_filter
tmpl to expand as group membership filter.
Definition rlm_ldap.h:149
unlang_action_t rlm_ldap_check_cached(rlm_rcode_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:1155
fr_value_box_t group_base
Base DN in which to search for groups.
Definition rlm_ldap.h:128
ldap_access_state_t access_state
What state a user's account is in.
Definition rlm_ldap.h:194
fr_value_box_t user_base
Base DN in which to search for users.
Definition rlm_ldap.h:126
HIDDEN fr_dict_attr_t const * attr_password_with_header
Definition rlm_ldap.c:322
int profile_scope
Search scope.
Definition rlm_ldap.h:99
fr_ldap_thread_trunk_t * ttrunk
Definition rlm_ldap.h:217
unlang_action_t rlm_ldap_find_user_async(TALLOC_CTX *ctx, 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:159
fr_value_box_t group_base
Base DN in which to search for groups.
Definition rlm_ldap.h:148
char const * dn
Definition rlm_ldap.h:193
map_list_t * user_map
Attribute map applied to users and profiles.
Definition rlm_ldap.h:136
unlang_action_t rlm_ldap_cacheable_groupobj(rlm_rcode_t *p_result, request_t *request, ldap_autz_ctx_t *autz_ctx)
Convert group membership information into attributes.
Definition groups.c:700
static char const * rlm_find_user_dn_cached(request_t *request)
Definition rlm_ldap.h:236
trunk_conf_t trunk_conf
Trunk configuration.
Definition rlm_ldap.h:116
module_instance_t const * mi
Module instance data for thread lookups.
Definition rlm_ldap.h:119
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:251
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:138
fr_value_box_t user_filter
Filter to use when searching for users.
Definition rlm_ldap.h:147
unlang_action_t rlm_ldap_check_groupobj_dynamic(rlm_rcode_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:786
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:130
ldap_group_xlat_status_t
State list for xlat evaluation of LDAP group membership.
Definition rlm_ldap.h:199
@ GROUP_XLAT_MEMB_FILTER
Definition rlm_ldap.h:201
@ GROUP_XLAT_MEMB_ATTR
Definition rlm_ldap.h:202
@ GROUP_XLAT_FIND_USER
Definition rlm_ldap.h:200
HIDDEN fr_dict_attr_t const * attr_cleartext_password
Definition rlm_ldap.c:318
module_instance_t const * dlinst
Definition rlm_ldap.h:182
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:199
char const * dn
Definition rlm_ldap.h:213
Call environment used in LDAP authorization.
Definition rlm_ldap.h:125
Holds state of in progress async authorization.
Definition rlm_ldap.h:181
Holds state of in progress group membership check xlat.
Definition rlm_ldap.h:208
Call environment used in group membership xlat.
Definition rlm_ldap.h:145
Module instance data.
Definition module.h:265
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
Common configuration parameters for a trunk.
Definition trunk.h:224
static TALLOC_CTX * xlat_ctx