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: 74e8097292507127776c80ae5abb9d19cda03bd3 $
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 char const *profile_sort_by; //!< List of attributes to sort profiles by
105 LDAPControl *profile_sort_ctrl; //!< Server side sort control
106 char const *profile_check_attr; //!< LDAP attribute containing check conditions to determine if
107 //!< the profile should be applied
108
109#ifdef WITH_EDIR
110 /*
111 * eDir support
112 */
113 bool edir; //!< If true attempt to retrieve the user's cleartext password
114 //!< using the Universal Password feature of Novell eDirectory.
115 bool edir_autz; //!< If true, and we have the Universal Password, bind with it
116 //!< to perform additional authorisation checks.
117#endif
118
119 fr_ldap_config_t handle_config; //!< Connection configuration instance.
120 trunk_conf_t trunk_conf; //!< Trunk configuration
121 trunk_conf_t bind_trunk_conf; //!< Trunk configuration for trunk used for bind auths
122
123 module_instance_t const *mi; //!< Module instance data for thread lookups.
124} rlm_ldap_t;
125
126/** Call environment used in LDAP authorization
127 *
128 */
129typedef struct {
130 fr_value_box_t user_base; //!< Base DN in which to search for users.
131 fr_value_box_t user_filter; //!< Filter to use when searching for users.
132 fr_value_box_t group_base; //!< Base DN in which to search for groups.
133 tmpl_t *group_filter; //!< tmpl to expand as group membership filter.
134 fr_value_box_t default_profile; //!< If this is set, we will search for a profile object
135 //!< with this name, and map any attributes it contains.
136 //!< No value should be set if profiles are not being used
137 //!< as there is an associated performance penalty.
138 fr_value_box_t profile_filter; //!< Filter to use when searching for profiles.
139
140 map_list_t *user_map; //!< Attribute map applied to users and profiles.
141
142 fr_value_box_t const *expect_password; //!< True if the user_map included a mapping between an LDAP
143 //!< attribute and one of our password reference attributes.
145
146/** Call environment used in group membership xlat
147 *
148 */
149typedef struct {
150 fr_value_box_t user_base; //!< Base DN in which to search for users.
151 fr_value_box_t user_filter; //!< Filter to use when searching for users.
152 fr_value_box_t group_base; //!< Base DN in which to search for groups.
153 tmpl_t *group_filter; //!< tmpl to expand as group membership filter.
155
156/** State list for resumption of authorization
157 *
158 */
172
173/** User's access state
174 *
175 */
176typedef enum {
177 LDAP_ACCESS_ALLOWED = 0, //!< User is allowed to login.
178 LDAP_ACCESS_DISALLOWED, //!< User it not allow to login (disabled)
179 LDAP_ACCESS_SUSPENDED //!< User account has been suspended.
181
182/** Holds state of in progress async authorization
183 *
184 */
200
201/** State list for xlat evaluation of LDAP group membership
202 */
208
209/** Holds state of in progress group membership check xlat
210 *
211 */
226
233
236
237/*
238 * user.c - User lookup functions
239 */
240static inline char const *rlm_find_user_dn_cached(request_t *request)
241{
242 fr_pair_t *vp;
243
244 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_ldap_userdn);
245 if (!vp) return NULL;
246
247 RDEBUG2("Using user DN from request \"%pV\"", &vp->data);
248 return vp->vp_strvalue;
249}
250
251unlang_action_t rlm_ldap_find_user_async(TALLOC_CTX *ctx, rlm_ldap_t const *inst, request_t *request,
252 fr_value_box_t *base, fr_value_box_t *filter_box,
253 fr_ldap_thread_trunk_t *ttrunk, char const *attrs[],
254 fr_ldap_query_t **query_out);
255
256ldap_access_state_t rlm_ldap_check_access(rlm_ldap_t const *inst, request_t *request, LDAPMessage *entry);
257
258void 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);
259
260/*
261 * groups.c - Group membership functions.
262 */
264 char const *attr);
265
267
270
273
275 rlm_ldap_t const *inst, request_t *request, fr_value_box_t const *check);
276
278 rlm_ldap_t const *inst, request_t *request, fr_ldap_thread_trunk_t *ttrunk,
279 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:215
char const * profile_attr
Attribute that identifies profiles to apply.
Definition rlm_ldap.h:100
fr_value_box_t * basedn
Definition rlm_ldap.h:220
fr_ldap_map_exp_t expanded
Definition rlm_ldap.h:188
HIDDEN fr_dict_attr_t const * attr_password
Definition rlm_ldap.c:319
fr_value_box_t * filter
Definition rlm_ldap.h:219
ldap_autz_call_env_t * call_env
Definition rlm_ldap.h:191
struct berval ** profile_values
Definition rlm_ldap.h:194
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:321
ldap_access_state_t
User's access state.
Definition rlm_ldap.h:176
@ LDAP_ACCESS_SUSPENDED
User account has been suspended.
Definition rlm_ldap.h:179
@ LDAP_ACCESS_ALLOWED
User is allowed to login.
Definition rlm_ldap.h:177
@ LDAP_ACCESS_DISALLOWED
User it not allow to login (disabled)
Definition rlm_ldap.h:178
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:190
HIDDEN fr_dict_attr_t const * attr_user_name
Definition base.c:104
fr_ldap_query_t * query
Definition rlm_ldap.h:222
rlm_ldap_t const * inst
Definition rlm_ldap.h:187
fr_value_box_t profile_filter
Filter to use when searching for profiles.
Definition rlm_ldap.h:138
fr_value_box_t user_filter
Filter to use when searching for users.
Definition rlm_ldap.h:131
tmpl_t * group_filter
tmpl to expand as group membership filter.
Definition rlm_ldap.h:133
trunk_conf_t bind_trunk_conf
Trunk configuration for trunk used for bind auths.
Definition rlm_ldap.h:121
LDAPMessage * entry
Definition rlm_ldap.h:192
HIDDEN fr_dict_attr_t const * attr_nt_password
Definition rlm_ldap.c:323
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:159
@ LDAP_AUTZ_GROUP
Definition rlm_ldap.h:161
@ LDAP_AUTZ_FIND
Definition rlm_ldap.h:160
@ LDAP_AUTZ_DEFAULT_PROFILE
Definition rlm_ldap.h:168
@ LDAP_AUTZ_USER_PROFILE
Definition rlm_ldap.h:170
@ LDAP_AUTZ_MAP
Definition rlm_ldap.h:167
@ LDAP_AUTZ_POST_DEFAULT_PROFILE
Definition rlm_ldap.h:169
@ LDAP_AUTZ_POST_GROUP
Definition rlm_ldap.h:162
fr_value_box_t * group
Definition rlm_ldap.h:214
ldap_autz_status_t status
Definition rlm_ldap.h:193
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:189
char * profile_value
Definition rlm_ldap.h:196
fr_value_box_t user_base
Base DN in which to search for users.
Definition rlm_ldap.h:150
rlm_ldap_t const * inst
Definition rlm_ldap.h:213
HIDDEN fr_dict_attr_t const * attr_ldap_userdn
Definition rlm_ldap.c:322
fr_ldap_config_t handle_config
Connection configuration instance.
Definition rlm_ldap.h:119
HIDDEN fr_dict_attr_t const * attr_user_password
ldap_group_xlat_status_t status
Definition rlm_ldap.h:223
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:153
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:132
ldap_access_state_t access_state
What state a user's account is in.
Definition rlm_ldap.h:198
fr_value_box_t user_base
Base DN in which to search for users.
Definition rlm_ldap.h:130
LDAPControl * profile_sort_ctrl
Server side sort control.
Definition rlm_ldap.h:105
HIDDEN fr_dict_attr_t const * attr_password_with_header
Definition rlm_ldap.c:324
int profile_scope
Search scope.
Definition rlm_ldap.h:99
fr_ldap_thread_trunk_t * ttrunk
Definition rlm_ldap.h:221
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:152
char const * dn
Definition rlm_ldap.h:197
map_list_t * user_map
Attribute map applied to users and profiles.
Definition rlm_ldap.h:140
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:240
trunk_conf_t trunk_conf
Trunk configuration.
Definition rlm_ldap.h:120
module_instance_t const * mi
Module instance data for thread lookups.
Definition rlm_ldap.h:123
char const * profile_sort_by
List of attributes to sort profiles by.
Definition rlm_ldap.h:104
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:142
fr_value_box_t user_filter
Filter to use when searching for users.
Definition rlm_ldap.h:151
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:134
ldap_group_xlat_status_t
State list for xlat evaluation of LDAP group membership.
Definition rlm_ldap.h:203
@ GROUP_XLAT_MEMB_FILTER
Definition rlm_ldap.h:205
@ GROUP_XLAT_MEMB_ATTR
Definition rlm_ldap.h:206
@ GROUP_XLAT_FIND_USER
Definition rlm_ldap.h:204
HIDDEN fr_dict_attr_t const * attr_cleartext_password
Definition rlm_ldap.c:320
char const * profile_check_attr
LDAP attribute containing check conditions to determine if the profile should be applied.
Definition rlm_ldap.h:106
module_instance_t const * dlinst
Definition rlm_ldap.h:186
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:217
Call environment used in LDAP authorization.
Definition rlm_ldap.h:129
Holds state of in progress async authorization.
Definition rlm_ldap.h:185
Holds state of in progress group membership check xlat.
Definition rlm_ldap.h:212
Call environment used in group membership xlat.
Definition rlm_ldap.h:149
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