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