Only parse dereference value if we actually have a value to parse
[freeradius.git] / src / modules / rlm_ldap / rlm_ldap.c
1 /*
2  *   This program is is free software; you can redistribute it and/or modify
3  *   it under the terms of the GNU General Public License, version 2 if the
4  *   License as published by the Free Software Foundation.
5  *
6  *   This program is distributed in the hope that it will be useful,
7  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
8  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9  *   GNU General Public License for more details.
10  *
11  *   You should have received a copy of the GNU General Public License
12  *   along with this program; if not, write to the Free Software
13  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
14  */
15
16 /**
17  * $Id$
18  * @file rlm_ldap.c
19  * @brief LDAP authorization and authentication module.
20  *
21  * @author Arran Cudbard-Bell <a.cudbardb@freeradius.org>
22  * @author Alan DeKok <aland@freeradius.org>
23  *
24  * @copyright 2013 Network RADIUS SARL <info@networkradius.com>
25  * @copyright 2012-2013 Arran Cudbard-Bell <a.cudbardb@freeradius.org>
26  * @copyright 2012 Alan DeKok <aland@freeradius.org>
27  * @copyright 1999-2013 The FreeRADIUS Server Project.
28  */
29 RCSID("$Id$")
30
31 #include        <freeradius-devel/rad_assert.h>
32
33 #include        <stdarg.h>
34 #include        <ctype.h>
35
36 #include        "ldap.h"
37
38 /*
39  *      Scopes
40  */
41 FR_NAME_NUMBER const ldap_scope[] = {
42         { "sub",        LDAP_SCOPE_SUB  },
43         { "one",        LDAP_SCOPE_ONE  },
44         { "base",       LDAP_SCOPE_BASE },
45 #ifdef LDAP_SCOPE_CHILDREN
46         { "children",   LDAP_SCOPE_CHILDREN },
47 #endif
48         {  NULL , -1 }
49 };
50
51 #ifdef LDAP_OPT_X_TLS_NEVER
52 FR_NAME_NUMBER const ldap_tls_require_cert[] = {
53         { "never",      LDAP_OPT_X_TLS_NEVER    },
54         { "demand",     LDAP_OPT_X_TLS_DEMAND   },
55         { "allow",      LDAP_OPT_X_TLS_ALLOW    },
56         { "try",        LDAP_OPT_X_TLS_TRY      },
57         { "hard",       LDAP_OPT_X_TLS_HARD     },      /* oh yes, just like that */
58
59         {  NULL , -1 }
60 };
61 #endif
62
63 FR_NAME_NUMBER const ldap_dereference[] = {
64         { "never",      LDAP_DEREF_NEVER        },
65         { "searching",  LDAP_DEREF_SEARCHING    },
66         { "finding",    LDAP_DEREF_FINDING      },
67         { "always",     LDAP_DEREF_ALWAYS       },
68
69         {  NULL , -1 }
70 };
71
72 /*
73  *      TLS Configuration
74  */
75 static CONF_PARSER tls_config[] = {
76         /*
77          *      Deprecated attributes
78          */
79         { "cacertfile", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, ldap_instance_t, tls_ca_file), NULL },
80         { "ca_file", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT, ldap_instance_t, tls_ca_file), NULL },
81
82         { "cacertdir", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, ldap_instance_t, tls_ca_path), NULL },
83         { "ca_path", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT, ldap_instance_t, tls_ca_path), NULL },
84
85         { "certfile", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, ldap_instance_t, tls_certificate_file), NULL },
86         { "certificate_file", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT, ldap_instance_t, tls_certificate_file), NULL },
87
88         { "keyfile", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, ldap_instance_t, tls_private_key_file), NULL }, // OK if it changes on HUP
89         { "private_key_file", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT, ldap_instance_t, tls_private_key_file), NULL }, // OK if it changes on HUP
90
91         { "randfile", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, ldap_instance_t, tls_random_file), NULL },
92         { "random_file", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT, ldap_instance_t, tls_random_file), NULL },
93
94         /*
95          *      LDAP Specific TLS attributes
96          */
97         { "start_tls", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, start_tls), "no" },
98         { "require_cert", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, tls_require_cert_str), NULL },
99
100         { NULL, -1, 0, NULL, NULL }
101 };
102
103
104 static CONF_PARSER profile_config[] = {
105         { "filter", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, profile_filter), "(&)" },   //!< Correct filter for
106                                                                                                 //!< when the DN is
107                                                                                                 //!< known.
108         { "attribute", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, profile_attr), NULL },
109         { "default", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, default_profile), NULL },
110
111         { NULL, -1, 0, NULL, NULL }
112 };
113
114 /*
115  *      User configuration
116  */
117 static CONF_PARSER user_config[] = {
118         { "filter", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, userobj_filter), "(uid=%u)" },
119         { "scope", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, userobj_scope_str), "sub" },
120         { "base_dn", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, userobj_base_dn), "" },
121
122         { "access_attribute", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, userobj_access_attr), NULL },
123         { "access_positive", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, access_positive), "yes" },
124
125         { NULL, -1, 0, NULL, NULL }
126 };
127
128 /*
129  *      Group configuration
130  */
131 static CONF_PARSER group_config[] = {
132         { "filter", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, groupobj_filter), NULL },
133         { "scope", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, groupobj_scope_str), "sub" },
134         { "base_dn", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, groupobj_base_dn), "" },
135
136         { "name_attribute", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, groupobj_name_attr), "cn" },
137         { "membership_attribute", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, userobj_membership_attr), NULL },
138         { "membership_filter", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, groupobj_membership_filter), NULL },
139         { "cacheable_name", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, cacheable_group_name), "no" },
140         { "cacheable_dn", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, cacheable_group_dn), "no" },
141         { "cache_attribute", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, cache_attribute), NULL },
142
143         { NULL, -1, 0, NULL, NULL }
144 };
145
146 /*
147  *      Client configuration
148  */
149 static CONF_PARSER client_attribute[] = {
150         { "identifier", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_identifier), "host" },
151         { "shortname", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_shortname), "cn" },
152         { "nas_type", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_type), NULL },
153         { "secret", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_secret), NULL },
154         { "virtual_server", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_server), NULL },
155         { "require_message_authenticator", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_require_ma), NULL },
156
157         { NULL, -1, 0, NULL, NULL }
158 };
159
160 static CONF_PARSER client_config[] = {
161         { "filter", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_filter), NULL },
162         { "scope", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_scope_str), "sub" },
163         { "base_dn", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_base_dn), "" },
164         { "attribute", FR_CONF_POINTER(PW_TYPE_SUBSECTION, NULL), (void const *) client_attribute },
165
166         { NULL, -1, 0, NULL, NULL }
167 };
168
169 /*
170  *      Reference for accounting updates
171  */
172 static const CONF_PARSER acct_section_config[] = {
173         { "reference", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_acct_section_t, reference), "." },
174
175         {NULL, -1, 0, NULL, NULL}
176 };
177
178 /*
179  *      Various options that don't belong in the main configuration.
180  *
181  *      Note that these overlap a bit with the connection pool code!
182  */
183 static CONF_PARSER option_config[] = {
184         /*
185          *      Debugging flags to the server
186          */
187         { "ldap_debug", FR_CONF_OFFSET(PW_TYPE_INTEGER, ldap_instance_t, ldap_debug), "0x0000" },
188
189         { "dereference", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, dereference_str), NULL },
190
191         { "chase_referrals", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, chase_referrals), NULL },
192
193         { "rebind", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, rebind), NULL },
194
195 #ifdef LDAP_OPT_NETWORK_TIMEOUT
196         /* timeout on network activity */
197         { "net_timeout", FR_CONF_OFFSET(PW_TYPE_INTEGER, ldap_instance_t, net_timeout), "10" },
198 #endif
199
200         /* timeout for search results */
201         { "res_timeout", FR_CONF_OFFSET(PW_TYPE_INTEGER, ldap_instance_t, res_timeout), "20" },
202
203         /* allow server unlimited time for search (server-side limit) */
204         { "srv_timelimit", FR_CONF_OFFSET(PW_TYPE_INTEGER, ldap_instance_t, srv_timelimit), "20" },
205
206 #ifdef LDAP_OPT_X_KEEPALIVE_IDLE
207         { "idle", FR_CONF_OFFSET(PW_TYPE_INTEGER, ldap_instance_t, keepalive_idle), "60" },
208 #endif
209 #ifdef LDAP_OPT_X_KEEPALIVE_PROBES
210         { "probes", FR_CONF_OFFSET(PW_TYPE_INTEGER, ldap_instance_t, keepalive_probes), "3" },
211 #endif
212 #ifdef LDAP_OPT_X_KEEPALIVE_INTERVAL
213         { "interval", FR_CONF_OFFSET(PW_TYPE_INTEGER, ldap_instance_t, keepalive_interval), "30" },
214 #endif
215
216         { NULL, -1, 0, NULL, NULL }
217 };
218
219
220 static const CONF_PARSER module_config[] = {
221         { "server", FR_CONF_OFFSET(PW_TYPE_STRING | PW_TYPE_REQUIRED, ldap_instance_t, server), "localhost" },
222         { "port", FR_CONF_OFFSET(PW_TYPE_SHORT, ldap_instance_t, port), "389" },
223
224         { "password", FR_CONF_OFFSET(PW_TYPE_STRING | PW_TYPE_SECRET, ldap_instance_t, password), "" },
225         { "identity", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, admin_dn), "" },
226
227         { "valuepair_attribute", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, valuepair_attr), NULL },
228
229 #ifdef WITH_EDIR
230         /* support for eDirectory Universal Password */
231         { "edir", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, edir), NULL }, /* NULL defaults to "no" */
232
233         /*
234          *      Attempt to bind with the cleartext password we got from eDirectory
235          *      Universal password for additional authorization checks.
236          */
237         { "edir_autz", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, edir_autz), NULL }, /* NULL defaults to "no" */
238 #endif
239
240         { "read_clients", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, do_clients), NULL }, /* NULL defaults to "no" */
241
242         { "user", FR_CONF_POINTER(PW_TYPE_SUBSECTION, NULL), (void const *) user_config },
243
244         { "group", FR_CONF_POINTER(PW_TYPE_SUBSECTION, NULL), (void const *) group_config },
245
246         { "client", FR_CONF_POINTER(PW_TYPE_SUBSECTION, NULL), (void const *) client_config },
247
248         { "profile", FR_CONF_POINTER(PW_TYPE_SUBSECTION, NULL), (void const *) profile_config },
249
250         { "options", FR_CONF_POINTER(PW_TYPE_SUBSECTION, NULL), (void const *) option_config },
251
252         { "tls", FR_CONF_POINTER(PW_TYPE_SUBSECTION, NULL), (void const *) tls_config },
253
254         {NULL, -1, 0, NULL, NULL}
255 };
256
257 /** Expand an LDAP URL into a query, and return a string result from that query.
258  *
259  */
260 static ssize_t ldap_xlat(void *instance, REQUEST *request, char const *fmt, char *out, size_t freespace)
261 {
262         ldap_rcode_t status;
263         size_t len = 0;
264         ldap_instance_t *inst = instance;
265         LDAPURLDesc *ldap_url;
266         LDAPMessage *result = NULL;
267         LDAPMessage *entry = NULL;
268         char **vals;
269         ldap_handle_t *conn;
270         int ldap_errno;
271         char const *url;
272         char const **attrs;
273
274         url = fmt;
275
276         if (!ldap_is_ldap_url(url)) {
277                 REDEBUG("String passed does not look like an LDAP URL");
278                 return -1;
279         }
280
281         if (ldap_url_parse(url, &ldap_url)){
282                 REDEBUG("Parsing LDAP URL failed");
283                 return -1;
284         }
285
286         /*
287          *      Nothing, empty string, "*" string, or got 2 things, die.
288          */
289         if (!ldap_url->lud_attrs || !ldap_url->lud_attrs[0] ||
290             !*ldap_url->lud_attrs[0] ||
291             (strcmp(ldap_url->lud_attrs[0], "*") == 0) ||
292             ldap_url->lud_attrs[1]) {
293                 REDEBUG("Bad attributes list in LDAP URL. URL must specify exactly one attribute to retrieve");
294
295                 goto free_urldesc;
296         }
297
298         if (ldap_url->lud_host &&
299             ((strncmp(inst->server, ldap_url->lud_host, strlen(inst->server)) != 0) ||
300              ((uint32_t) ldap_url->lud_port != inst->port))) {
301                 RDEBUG("Requested server/port is \"%s:%i\"", ldap_url->lud_host, inst->port);
302
303                 goto free_urldesc;
304         }
305
306         conn = rlm_ldap_get_socket(inst, request);
307         if (!conn) goto free_urldesc;
308
309         memcpy(&attrs, &ldap_url->lud_attrs, sizeof(attrs));
310
311         status = rlm_ldap_search(inst, request, &conn, ldap_url->lud_dn, ldap_url->lud_scope, ldap_url->lud_filter,
312                                  attrs, &result);
313         switch (status) {
314                 case LDAP_PROC_SUCCESS:
315                         break;
316                 case LDAP_PROC_NO_RESULT:
317                         RDEBUG("Search returned not found");
318                 default:
319                         goto free_socket;
320         }
321
322         rad_assert(conn);
323         rad_assert(result);
324
325         entry = ldap_first_entry(conn->handle, result);
326         if (!entry) {
327                 ldap_get_option(conn->handle, LDAP_OPT_RESULT_CODE, &ldap_errno);
328                 REDEBUG("Failed retrieving entry: %s", ldap_err2string(ldap_errno));
329                 len = -1;
330                 goto free_result;
331         }
332
333         vals = ldap_get_values(conn->handle, entry, ldap_url->lud_attrs[0]);
334         if (!vals) {
335                 RDEBUG("No \"%s\" attributes found in specified object", ldap_url->lud_attrs[0]);
336                 goto free_result;
337         }
338
339         len = strlen(vals[0]);
340         if (len >= freespace){
341                 goto free_vals;
342         }
343
344         strlcpy(out, vals[0], freespace);
345
346 free_vals:
347         ldap_value_free(vals);
348 free_result:
349         ldap_msgfree(result);
350 free_socket:
351         rlm_ldap_release_socket(inst, conn);
352 free_urldesc:
353         ldap_free_urldesc(ldap_url);
354
355         return len;
356 }
357
358 /** Perform LDAP-Group comparison checking
359  *
360  * Attempts to match users to groups using a variety of methods.
361  *
362  * @param instance of the rlm_ldap module.
363  * @param request Current request.
364  * @param thing Unknown.
365  * @param check Which group to check for user membership.
366  * @param check_pairs Unknown.
367  * @param reply_pairs Unknown.
368  * @return 1 on failure (or if the user is not a member), else 0.
369  */
370 static int rlm_ldap_groupcmp(void *instance, REQUEST *request, UNUSED VALUE_PAIR *thing, VALUE_PAIR *check,
371                              UNUSED VALUE_PAIR *check_pairs, UNUSED VALUE_PAIR **reply_pairs)
372 {
373         ldap_instance_t *inst = instance;
374         rlm_rcode_t     rcode;
375
376         bool            found = false;
377         bool            check_is_dn;
378
379         ldap_handle_t   *conn = NULL;
380         char const      *user_dn;
381
382         rad_assert(inst->groupobj_base_dn);
383
384         RDEBUG("Searching for user in group \"%s\"", check->vp_strvalue);
385
386         if (check->length == 0) {
387                 RDEBUG("Cannot do comparison (group name is empty)");
388                 return 1;
389         }
390
391         /*
392          *      Check if we can do cached membership verification
393          */
394         check_is_dn = rlm_ldap_is_dn(check->vp_strvalue);
395         if ((check_is_dn && inst->cacheable_group_dn) || (!check_is_dn && inst->cacheable_group_name)) {
396                 switch(rlm_ldap_check_cached(inst, request, check)) {
397                         case RLM_MODULE_NOTFOUND:
398                                 found = false;
399                                 goto finish;
400                         case RLM_MODULE_OK:
401                                 found = true;
402                                 goto finish;
403                         /*
404                          *      Fallback to dynamic search on failure
405                          */
406                         case RLM_MODULE_FAIL:
407                         case RLM_MODULE_INVALID:
408                         default:
409                                 break;
410                 }
411         }
412
413         conn = rlm_ldap_get_socket(inst, request);
414         if (!conn) return 1;
415
416         /*
417          *      This is used in the default membership filter.
418          */
419         user_dn = rlm_ldap_find_user(inst, request, &conn, NULL, false, NULL, &rcode);
420         if (!user_dn) {
421                 rlm_ldap_release_socket(inst, conn);
422                 return 1;
423         }
424
425         rad_assert(conn);
426
427         /*
428          *      Check groupobj user membership
429          */
430         if (inst->groupobj_membership_filter) {
431                 switch(rlm_ldap_check_groupobj_dynamic(inst, request, &conn, check)) {
432                         case RLM_MODULE_NOTFOUND:
433                                 break;
434                         case RLM_MODULE_OK:
435                                 found = true;
436                         default:
437                                 goto finish;
438                 }
439         }
440
441         rad_assert(conn);
442
443         /*
444          *      Check userobj group membership
445          */
446         if (inst->userobj_membership_attr) {
447                 switch(rlm_ldap_check_userobj_dynamic(inst, request, &conn, user_dn, check)) {
448                         case RLM_MODULE_NOTFOUND:
449                                 break;
450                         case RLM_MODULE_OK:
451                                 found = true;
452                         default:
453                                 goto finish;
454                 }
455         }
456
457         rad_assert(conn);
458
459         finish:
460         if (conn) {
461                 rlm_ldap_release_socket(inst, conn);
462         }
463
464         if (!found) {
465                 RDEBUG("User is not a member of specified group");
466
467                 return 1;
468         }
469
470         return 0;
471 }
472
473 /** Detach from the LDAP server and cleanup internal state.
474  *
475  */
476 static int mod_detach(void *instance)
477 {
478         ldap_instance_t *inst = instance;
479
480         fr_connection_pool_delete(inst->pool);
481
482         if (inst->user_map) {
483                 talloc_free(inst->user_map);
484         }
485
486         return 0;
487 }
488
489 /** Parse an accounting sub section.
490  *
491  * Allocate a new ldap_acct_section_t and write the config data into it.
492  *
493  * @param[in] inst rlm_ldap configuration.
494  * @param[in] parent of the config section.
495  * @param[out] config to write the sub section parameters to.
496  * @param[in] comp The section name were parsing the config for.
497  * @return 0 on success, else < 0 on failure.
498  */
499 static int parse_sub_section(ldap_instance_t *inst, CONF_SECTION *parent, ldap_acct_section_t **config,
500                              rlm_components_t comp)
501 {
502         CONF_SECTION *cs;
503
504         char const *name = section_type_value[comp].section;
505
506         cs = cf_section_sub_find(parent, name);
507         if (!cs) {
508                 INFO("rlm_ldap (%s): Couldn't find configuration for %s, will return NOOP for calls "
509                        "from this section", inst->xlat_name, name);
510
511                 return 0;
512         }
513
514         *config = talloc_zero(inst, ldap_acct_section_t);
515         if (cf_section_parse(cs, *config, acct_section_config) < 0) {
516                 LDAP_ERR("Failed parsing configuration for section %s", name);
517
518                 return -1;
519         }
520
521         (*config)->cs = cs;
522
523         return 0;
524 }
525
526 /** Instantiate the module
527  *
528  * Creates a new instance of the module reading parameters from a configuration section.
529  *
530  * @param conf to parse.
531  * @param instance Where to write pointer to configuration data.
532  * @return 0 on success < 0 on failure.
533  */
534 static int mod_instantiate(CONF_SECTION *conf, void *instance)
535 {
536         CONF_SECTION *options;
537         ldap_instance_t *inst = instance;
538
539         inst->cs = conf;
540
541         options = cf_section_sub_find(conf, "options");
542         if (!options || !cf_pair_find(options, "chase_referrals")) {
543                 inst->chase_referrals_unset = true;      /* use OpenLDAP defaults */
544         }
545
546         inst->xlat_name = cf_section_name2(conf);
547         if (!inst->xlat_name) {
548                 inst->xlat_name = cf_section_name1(conf);
549         }
550
551         /*
552          *      If the configuration parameters can't be parsed, then fail.
553          */
554         if ((parse_sub_section(inst, conf, &inst->accounting, RLM_COMPONENT_ACCT) < 0) ||
555             (parse_sub_section(inst, conf, &inst->postauth, RLM_COMPONENT_POST_AUTH) < 0)) {
556                 LDAP_ERR("Failed parsing configuration");
557
558                 goto error;
559         }
560
561         /*
562          *      Sanity checks for cacheable groups code.
563          */
564         if (inst->cacheable_group_name && inst->groupobj_membership_filter) {
565                 if (!inst->groupobj_name_attr) {
566                         LDAP_ERR("Directive 'group.name_attribute' must be set if cacheable group names are enabled");
567
568                         goto error;
569                 }
570         }
571
572         /*
573          *      Check for URLs.  If they're used and the library doesn't support them, then complain.
574          */
575         inst->is_url = 0;
576         if (ldap_is_ldap_url(inst->server)) {
577 #ifdef HAVE_LDAP_INITIALIZE
578                 inst->is_url = 1;
579                 inst->port = 0;
580 #else
581                 LDAP_ERR("Directive 'server' is in URL form but ldap_initialize() is not available");
582                 goto error;
583 #endif
584         }
585
586 #ifdef LDAP_OPT_X_TLS_NEVER
587         /*
588          *      Workaround for servers which support LDAPS but not START TLS
589          */
590         if (inst->port == LDAPS_PORT || inst->tls_mode) {
591                 inst->tls_mode = LDAP_OPT_X_TLS_HARD;
592         } else {
593                 inst->tls_mode = 0;
594         }
595 #endif
596
597         /*
598          *      Convert dereference strings to enumerated constants
599          */
600         if (inst->dereference_str) {
601                 inst->dereference = fr_str2int(ldap_dereference, inst->dereference_str, -1);
602                 if (inst->dereference < 0) {
603                         LDAP_ERR("Invalid 'dereference' value \"%s\", expected 'never', 'searching', "
604                                  "'finding' or 'always'", inst->dereference_str);
605                         goto error;
606                 }
607         }
608
609 #if LDAP_SET_REBIND_PROC_ARGS != 3
610         /*
611          *      The 2-argument rebind doesn't take an instance variable.  Our rebind function needs the instance
612          *      variable for the username, password, etc.
613          */
614         if (inst->rebind == true) {
615                 LDAP_ERR("Cannot use 'rebind' directive as this version of libldap does not support the API "
616                          "that we need");
617
618                 goto error;
619         }
620 #endif
621
622         /*
623          *      Convert scope strings to enumerated constants
624          */
625         inst->userobj_scope = fr_str2int(ldap_scope, inst->userobj_scope_str, -1);
626         if (inst->userobj_scope < 0) {
627                 LDAP_ERR("Invalid 'user.scope' value \"%s\", expected 'sub', 'one', 'base' or 'children'",
628                          inst->userobj_scope_str);
629                 goto error;
630         }
631
632         inst->groupobj_scope = fr_str2int(ldap_scope, inst->groupobj_scope_str, -1);
633         if (inst->groupobj_scope < 0) {
634                 LDAP_ERR("Invalid 'group.scope' value \"%s\", expected 'sub', 'one', 'base' or 'children'",
635                          inst->groupobj_scope_str);
636                 goto error;
637         }
638
639         inst->clientobj_scope = fr_str2int(ldap_scope, inst->clientobj_scope_str, -1);
640         if (inst->clientobj_scope < 0) {
641                 LDAP_ERR("Invalid 'client.scope' value \"%s\", expected 'sub', 'one', 'base' or 'children'",
642                          inst->clientobj_scope_str);
643                 goto error;
644         }
645
646         if (inst->tls_require_cert_str) {
647 #ifdef LDAP_OPT_X_TLS_NEVER
648                 /*
649                  *      Convert cert strictness to enumerated constants
650                  */
651                 inst->tls_require_cert = fr_str2int(ldap_tls_require_cert, inst->tls_require_cert_str, -1);
652                 if (inst->tls_require_cert < 0) {
653                         LDAP_ERR("Invalid 'tls.require_cert' value \"%s\", expected 'never', 'demand', 'allow', "
654                                  "'try' or 'hard'", inst->tls_require_cert_str);
655                         goto error;
656                 }
657 #else
658                 LDAP_ERR("Modifying 'tls.require_cert' is not supported by current version of libldap. "
659                          "Please upgrade or substitute current libldap and rebuild this module");
660
661                 goto error;
662 #endif
663         }
664         /*
665          *      Build the attribute map
666          */
667         if (rlm_ldap_map_verify(inst, &(inst->user_map)) < 0) {
668                 goto error;
669         }
670
671         /*
672          *      Group comparison checks.
673          */
674         if (cf_section_name2(conf)) {
675                 static ATTR_FLAGS flags;
676                 char buffer[256];
677
678                 snprintf(buffer, sizeof(buffer), "%s-Ldap-Group", inst->xlat_name);
679                 if (dict_addattr(buffer, -1, 0, PW_TYPE_STRING, flags) < 0) {
680                         LDAP_ERR("Error creating group attribute: %s", fr_strerror());
681
682                         return -1;
683                 }
684                 inst->group_da = dict_attrbyname(buffer);
685                 if (!inst->group_da) {
686                         LDAP_ERR("Failed creating attribute %s", buffer);
687
688                         goto error;
689                 }
690
691                 paircompare_register(inst->group_da, dict_attrbyvalue(PW_USER_NAME, 0), false, rlm_ldap_groupcmp, inst);
692         /*
693          *      Were the default instance
694          */
695         } else {
696                 inst->group_da = dict_attrbyvalue(PW_LDAP_GROUP, 0);
697                 paircompare_register(dict_attrbyvalue(PW_LDAP_GROUP, 0), dict_attrbyvalue(PW_USER_NAME, 0),
698                                 false, rlm_ldap_groupcmp, inst);
699         }
700
701         xlat_register(inst->xlat_name, ldap_xlat, rlm_ldap_escape_func, inst);
702
703         /*
704          *      Setup the cache attribute
705          */
706         if (inst->cache_attribute) {
707                 static ATTR_FLAGS flags;
708
709                 if (dict_addattr(inst->cache_attribute, -1, 0, PW_TYPE_STRING, flags) < 0) {
710                         LDAP_ERR("Error creating cache attribute: %s", fr_strerror());
711
712                         return -1;
713                 }
714                 inst->cache_da = dict_attrbyname(inst->cache_attribute);
715         } else {
716                 inst->cache_da = inst->group_da;        /* Default to the group_da */
717         }
718
719         /*
720          *      Initialize the socket pool.
721          */
722         inst->pool = fr_connection_pool_init(inst->cs, inst, mod_conn_create, NULL, mod_conn_delete, NULL);
723         if (!inst->pool) {
724                 return -1;
725         }
726
727         /*
728          *      Bulk load dynamic clients.
729          */
730         if (inst->do_clients) {
731                 if (rlm_ldap_load_clients(inst) < 0) {
732                         LDAP_ERR("Error loading clients");
733
734                         return -1;
735                 }
736         }
737
738         return 0;
739
740 error:
741         return -1;
742 }
743
744 static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(void *instance, REQUEST *request)
745 {
746         rlm_rcode_t     rcode;
747         ldap_rcode_t    status;
748         char const      *dn;
749         ldap_instance_t *inst = instance;
750         ldap_handle_t   *conn;
751
752         /*
753          * Ensure that we're being passed a plain-text password, and not
754          * anything else.
755          */
756
757         if (!request->username) {
758                 REDEBUG("Attribute \"User-Name\" is required for authentication");
759
760                 return RLM_MODULE_INVALID;
761         }
762
763         if (!request->password ||
764             (request->password->da->attr != PW_USER_PASSWORD)) {
765                 RWDEBUG("You have set \"Auth-Type := LDAP\" somewhere");
766                 RWDEBUG("*********************************************");
767                 RWDEBUG("* THAT CONFIGURATION IS WRONG.  DELETE IT.   ");
768                 RWDEBUG("* YOU ARE PREVENTING THE SERVER FROM WORKING");
769                 RWDEBUG("*********************************************");
770
771                 REDEBUG("Attribute \"User-Password\" is required for authentication");
772
773                 return RLM_MODULE_INVALID;
774         }
775
776         if (request->password->length == 0) {
777                 REDEBUG("Empty password supplied");
778
779                 return RLM_MODULE_INVALID;
780         }
781
782         RDEBUG("Login attempt by \"%s\"", request->username->vp_strvalue);
783
784         conn = rlm_ldap_get_socket(inst, request);
785         if (!conn) return RLM_MODULE_FAIL;
786
787         /*
788          *      Get the DN by doing a search.
789          */
790         dn = rlm_ldap_find_user(inst, request, &conn, NULL, false, NULL, &rcode);
791         if (!dn) {
792                 rlm_ldap_release_socket(inst, conn);
793
794                 return rcode;
795         }
796
797         /*
798          *      Bind as the user
799          */
800         conn->rebound = true;
801         status = rlm_ldap_bind(inst, request, &conn, dn, request->password->vp_strvalue, true);
802         switch (status) {
803         case LDAP_PROC_SUCCESS:
804                 rcode = RLM_MODULE_OK;
805                 RDEBUG("Bind as user \"%s\" was successful", dn);
806                 break;
807
808         case LDAP_PROC_NOT_PERMITTED:
809                 rcode = RLM_MODULE_USERLOCK;
810                 break;
811
812         case LDAP_PROC_REJECT:
813                 rcode = RLM_MODULE_REJECT;
814                 break;
815
816         case LDAP_PROC_BAD_DN:
817                 rcode = RLM_MODULE_INVALID;
818                 break;
819
820         case LDAP_PROC_NO_RESULT:
821                 rcode = RLM_MODULE_NOTFOUND;
822                 break;
823
824         default:
825                 rcode = RLM_MODULE_FAIL;
826                 break;
827         };
828
829         rlm_ldap_release_socket(inst, conn);
830
831         return rcode;
832 }
833
834 static rlm_rcode_t CC_HINT(nonnull) mod_authorize(void *instance, REQUEST *request)
835 {
836         rlm_rcode_t     rcode = RLM_MODULE_OK;
837         ldap_rcode_t    status;
838         int             ldap_errno;
839         int             i;
840         ldap_instance_t *inst = instance;
841         char            **vals;
842         VALUE_PAIR      *vp;
843         ldap_handle_t   *conn;
844         LDAPMessage     *result, *entry;
845         char const      *dn = NULL;
846         rlm_ldap_map_xlat_t     expanded; /* faster than mallocing every time */
847
848         if (!request->username) {
849                 RDEBUG2("Attribute \"User-Name\" is required for authorization");
850
851                 return RLM_MODULE_NOOP;
852         }
853
854         /*
855          *      Check for valid input, zero length names not permitted
856          */
857         if (request->username->length == 0) {
858                 RDEBUG2("Zero length username not permitted");
859
860                 return RLM_MODULE_INVALID;
861         }
862
863         if (rlm_ldap_map_xlat(request, inst->user_map, &expanded) < 0) {
864                 return RLM_MODULE_FAIL;
865         }
866
867         conn = rlm_ldap_get_socket(inst, request);
868         if (!conn) return RLM_MODULE_FAIL;
869
870         /*
871          *      Add any additional attributes we need for checking access, memberships, and profiles
872          */
873         if (inst->userobj_access_attr) {
874                 expanded.attrs[expanded.count++] = inst->userobj_access_attr;
875         }
876
877         if (inst->userobj_membership_attr && (inst->cacheable_group_dn || inst->cacheable_group_name)) {
878                 expanded.attrs[expanded.count++] = inst->userobj_membership_attr;
879         }
880
881         if (inst->profile_attr) {
882                 expanded.attrs[expanded.count++] = inst->profile_attr;
883         }
884
885         if (inst->valuepair_attr) {
886                 expanded.attrs[expanded.count++] = inst->valuepair_attr;
887         }
888
889         expanded.attrs[expanded.count] = NULL;
890
891         dn = rlm_ldap_find_user(inst, request, &conn, expanded.attrs, true, &result, &rcode);
892         if (!dn) {
893                 goto finish;
894         }
895
896         entry = ldap_first_entry(conn->handle, result);
897         if (!entry) {
898                 ldap_get_option(conn->handle, LDAP_OPT_RESULT_CODE, &ldap_errno);
899                 REDEBUG("Failed retrieving entry: %s", ldap_err2string(ldap_errno));
900
901                 goto finish;
902         }
903
904         /*
905          *      Check for access.
906          */
907         if (inst->userobj_access_attr) {
908                 rcode = rlm_ldap_check_access(inst, request, conn, entry);
909                 if (rcode != RLM_MODULE_OK) {
910                         goto finish;
911                 }
912         }
913
914         /*
915          *      Check if we need to cache group memberships
916          */
917         if (inst->cacheable_group_dn || inst->cacheable_group_name) {
918                 if (inst->userobj_membership_attr) {
919                         rcode = rlm_ldap_cacheable_userobj(inst, request, &conn, entry, inst->userobj_membership_attr);
920                         if (rcode != RLM_MODULE_OK) {
921                                 goto finish;
922                         }
923                 }
924
925                 rcode = rlm_ldap_cacheable_groupobj(inst, request, &conn);
926                 if (rcode != RLM_MODULE_OK) {
927                         goto finish;
928                 }
929         }
930
931 #ifdef WITH_EDIR
932         /*
933          *      We already have a Cleartext-Password.  Skip edir.
934          */
935         if (pairfind(request->config_items, PW_CLEARTEXT_PASSWORD, 0, TAG_ANY)) {
936                 goto skip_edir;
937         }
938
939         /*
940          *      Retrieve Universal Password if we use eDirectory
941          */
942         if (inst->edir) {
943                 int res = 0;
944                 char password[256];
945                 size_t pass_size = sizeof(password);
946
947                 /*
948                  *      Retrive universal password
949                  */
950                 res = nmasldap_get_password(conn->handle, dn, password, &pass_size);
951                 if (res != 0) {
952                         REDEBUG("Failed to retrieve eDirectory password: (%i) %s", res, edir_errstr(res));
953                         rcode = RLM_MODULE_FAIL;
954
955                         goto finish;
956                 }
957
958                 /*
959                  *      Add Cleartext-Password attribute to the request
960                  */
961                 vp = radius_paircreate(request, &request->config_items, PW_CLEARTEXT_PASSWORD, 0);
962                 pairstrcpy(vp, password);
963                 vp->length = pass_size;
964
965                 if (RDEBUG_ENABLED3) {
966                         RDEBUG3("Added eDirectory password.  control:%s += '%s'", vp->da->name, vp->vp_strvalue);
967                 } else {
968                         RDEBUG2("Added eDirectory password");
969                 }
970
971                 if (inst->edir_autz) {
972                         RDEBUG2("Binding as user for eDirectory authorization checks");
973                         /*
974                          *      Bind as the user
975                          */
976                         conn->rebound = true;
977                         status = rlm_ldap_bind(inst, request, &conn, dn, vp->vp_strvalue, true);
978                         switch (status) {
979                         case LDAP_PROC_SUCCESS:
980                                 rcode = RLM_MODULE_OK;
981                                 RDEBUG("Bind as user '%s' was successful", dn);
982                                 break;
983
984                         case LDAP_PROC_NOT_PERMITTED:
985                                 rcode = RLM_MODULE_USERLOCK;
986                                 goto finish;
987
988                         case LDAP_PROC_REJECT:
989                                 rcode = RLM_MODULE_REJECT;
990                                 goto finish;
991
992                         case LDAP_PROC_BAD_DN:
993                                 rcode = RLM_MODULE_INVALID;
994                                 goto finish;
995
996                         case LDAP_PROC_NO_RESULT:
997                                 rcode = RLM_MODULE_NOTFOUND;
998                                 goto finish;
999
1000                         default:
1001                                 rcode = RLM_MODULE_FAIL;
1002                                 goto finish;
1003                         };
1004                 }
1005         }
1006
1007 skip_edir:
1008 #endif
1009
1010         /*
1011          *      Apply ONE user profile, or a default user profile.
1012          */
1013         if (inst->default_profile) {
1014                 char profile[1024];
1015
1016                 if (radius_xlat(profile, sizeof(profile), request, inst->default_profile, NULL, NULL) < 0) {
1017                         REDEBUG("Failed creating default profile string");
1018
1019                         rcode = RLM_MODULE_INVALID;
1020                         goto finish;
1021                 }
1022
1023                 rlm_ldap_map_profile(inst, request, &conn, profile, &expanded);
1024         }
1025
1026         /*
1027          *      Apply a SET of user profiles.
1028          */
1029         if (inst->profile_attr) {
1030                 vals = ldap_get_values(conn->handle, entry, inst->profile_attr);
1031                 if (vals != NULL) {
1032                         for (i = 0; vals[i] != NULL; i++) {
1033                                 rlm_ldap_map_profile(inst, request, &conn, vals[i], &expanded);
1034                         }
1035
1036                         ldap_value_free(vals);
1037                 }
1038         }
1039
1040         if (inst->user_map || inst->valuepair_attr) {
1041                 RDEBUG("Processing user attributes");
1042                 rlm_ldap_map_do(inst, request, conn->handle, &expanded, entry);
1043                 rlm_ldap_check_reply(inst, request);
1044         }
1045
1046 finish:
1047         rlm_ldap_map_xlat_free(&expanded);
1048         if (result) {
1049                 ldap_msgfree(result);
1050         }
1051         rlm_ldap_release_socket(inst, conn);
1052
1053         return rcode;
1054 }
1055
1056 /** Modify user's object in LDAP
1057  *
1058  * Process a modifcation map to update a user object in the LDAP directory.
1059  *
1060  * @param inst rlm_ldap instance.
1061  * @param request Current request.
1062  * @param section that holds the map to process.
1063  * @return one of the RLM_MODULE_* values.
1064  */
1065 static rlm_rcode_t user_modify(ldap_instance_t *inst, REQUEST *request, ldap_acct_section_t *section)
1066 {
1067         rlm_rcode_t     rcode = RLM_MODULE_OK;
1068         ldap_rcode_t    status;
1069
1070         ldap_handle_t   *conn = NULL;
1071
1072         LDAPMod         *mod_p[LDAP_MAX_ATTRMAP + 1], mod_s[LDAP_MAX_ATTRMAP];
1073         LDAPMod         **modify = mod_p;
1074
1075         char            *passed[LDAP_MAX_ATTRMAP * 2];
1076         int             i, total = 0, last_pass = 0;
1077
1078         char            *expanded[LDAP_MAX_ATTRMAP];
1079         int             last_exp = 0;
1080
1081         char const      *attr;
1082         char const      *value;
1083
1084         char const      *dn;
1085         /*
1086          *      Build our set of modifications using the update sections in
1087          *      the config.
1088          */
1089         CONF_ITEM       *ci;
1090         CONF_PAIR       *cp;
1091         CONF_SECTION    *cs;
1092         FR_TOKEN        op;
1093         char            path[MAX_STRING_LEN];
1094
1095         char            *p = path;
1096
1097         rad_assert(section);
1098
1099         /*
1100          *      Locate the update section were going to be using
1101          */
1102         if (section->reference[0] != '.') {
1103                 *p++ = '.';
1104         }
1105
1106         if (radius_xlat(p, (sizeof(path) - (p - path)) - 1, request, section->reference, NULL, NULL) < 0) {
1107                 goto error;
1108         }
1109
1110         ci = cf_reference_item(NULL, section->cs, path);
1111         if (!ci) {
1112                 goto error;
1113         }
1114
1115         if (!cf_item_is_section(ci)){
1116                 REDEBUG("Reference must resolve to a section");
1117
1118                 goto error;
1119         }
1120
1121         cs = cf_section_sub_find(cf_itemtosection(ci), "update");
1122         if (!cs) {
1123                 REDEBUG("Section must contain 'update' subsection");
1124
1125                 goto error;
1126         }
1127
1128         /*
1129          *      Iterate over all the pairs, building our mods array
1130          */
1131         for (ci = cf_item_find_next(cs, NULL); ci != NULL; ci = cf_item_find_next(cs, ci)) {
1132                 bool do_xlat = false;
1133
1134                 if (total == LDAP_MAX_ATTRMAP) {
1135                         REDEBUG("Modify map size exceeded");
1136
1137                         goto error;
1138                 }
1139
1140                 if (!cf_item_is_pair(ci)) {
1141                         REDEBUG("Entry is not in \"ldap-attribute = value\" format");
1142
1143                         goto error;
1144                 }
1145
1146                 /*
1147                  *      Retrieve all the information we need about the pair
1148                  */
1149                 cp = cf_itemtopair(ci);
1150                 value = cf_pair_value(cp);
1151                 attr = cf_pair_attr(cp);
1152                 op = cf_pair_operator(cp);
1153
1154                 if (!value || (*value == '\0')) {
1155                         RDEBUG("Empty value string, skipping attribute \"%s\"", attr);
1156
1157                         continue;
1158                 }
1159
1160                 switch (cf_pair_value_type(cp)) {
1161                 case T_BARE_WORD:
1162                 case T_SINGLE_QUOTED_STRING:
1163                         break;
1164
1165                 case T_BACK_QUOTED_STRING:
1166                 case T_DOUBLE_QUOTED_STRING:
1167                         do_xlat = true;
1168                         break;
1169
1170                 default:
1171                         rad_assert(0);
1172                         goto error;
1173                 }
1174
1175                 if (op == T_OP_CMP_FALSE) {
1176                         passed[last_pass] = NULL;
1177                 } else if (do_xlat) {
1178                         char *exp = NULL;
1179
1180                         if (radius_axlat(&exp, request, value, NULL, NULL) <= 0) {
1181                                 RDEBUG("Skipping attribute \"%s\"", attr);
1182
1183                                 talloc_free(exp);
1184
1185                                 continue;
1186                         }
1187
1188                         expanded[last_exp++] = exp;
1189                         passed[last_pass] = exp;
1190                 /*
1191                  *      Static strings
1192                  */
1193                 } else {
1194                         memcpy(&(passed[last_pass]), &value, sizeof(passed[last_pass]));
1195                 }
1196
1197                 passed[last_pass + 1] = NULL;
1198
1199                 mod_s[total].mod_values = &(passed[last_pass]);
1200
1201                 last_pass += 2;
1202
1203                 switch (op) {
1204                 /*
1205                  *  T_OP_EQ is *NOT* supported, it is impossible to
1206                  *  support because of the lack of transactions in LDAP
1207                  */
1208                 case T_OP_ADD:
1209                         mod_s[total].mod_op = LDAP_MOD_ADD;
1210                         break;
1211
1212                 case T_OP_SET:
1213                         mod_s[total].mod_op = LDAP_MOD_REPLACE;
1214                         break;
1215
1216                 case T_OP_SUB:
1217                 case T_OP_CMP_FALSE:
1218                         mod_s[total].mod_op = LDAP_MOD_DELETE;
1219                         break;
1220
1221 #ifdef LDAP_MOD_INCREMENT
1222                 case T_OP_INCRM:
1223                         mod_s[total].mod_op = LDAP_MOD_INCREMENT;
1224                         break;
1225 #endif
1226                 default:
1227                         REDEBUG("Operator '%s' is not supported for LDAP modify operations",
1228                                 fr_int2str(fr_tokens, op, "<INVALID>"));
1229
1230                         goto error;
1231                 }
1232
1233                 /*
1234                  *      Now we know the value is ok, copy the pointers into
1235                  *      the ldapmod struct.
1236                  */
1237                 memcpy(&(mod_s[total].mod_type), &attr, sizeof(mod_s[total].mod_type));
1238
1239                 mod_p[total] = &(mod_s[total]);
1240                 total++;
1241         }
1242
1243         if (total == 0) {
1244                 rcode = RLM_MODULE_NOOP;
1245                 goto release;
1246         }
1247
1248         mod_p[total] = NULL;
1249
1250         conn = rlm_ldap_get_socket(inst, request);
1251         if (!conn) return RLM_MODULE_FAIL;
1252
1253
1254         dn = rlm_ldap_find_user(inst, request, &conn, NULL, false, NULL, &rcode);
1255         if (!dn || (rcode != RLM_MODULE_OK)) {
1256                 goto error;
1257         }
1258
1259         status = rlm_ldap_modify(inst, request, &conn, dn, modify);
1260         switch (status) {
1261         case LDAP_PROC_SUCCESS:
1262                 break;
1263
1264         case LDAP_PROC_REJECT:
1265         case LDAP_PROC_BAD_DN:
1266                 rcode = RLM_MODULE_INVALID;
1267                 break;
1268
1269         default:
1270                 rcode = RLM_MODULE_FAIL;
1271                 break;
1272         };
1273
1274         release:
1275         error:
1276         /*
1277          *      Free up any buffers we allocated for xlat expansion
1278          */
1279         for (i = 0; i < last_exp; i++) {
1280                 talloc_free(expanded[i]);
1281         }
1282
1283         rlm_ldap_release_socket(inst, conn);
1284
1285         return rcode;
1286 }
1287
1288 static rlm_rcode_t CC_HINT(nonnull) mod_accounting(void *instance, REQUEST * request) {
1289         ldap_instance_t *inst = instance;
1290
1291         if (inst->accounting) {
1292                 return user_modify(inst, request, inst->accounting);
1293         }
1294
1295         return RLM_MODULE_NOOP;
1296 }
1297
1298 static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST * request)
1299 {
1300         ldap_instance_t *inst = instance;
1301
1302         if (inst->postauth) {
1303                 return user_modify(inst, request, inst->postauth);
1304         }
1305
1306         return RLM_MODULE_NOOP;
1307 }
1308
1309
1310 /* globally exported name */
1311 module_t rlm_ldap = {
1312         RLM_MODULE_INIT,
1313         "ldap",
1314         RLM_TYPE_THREAD_SAFE,   /* type: reserved        */
1315         sizeof(ldap_instance_t),
1316         module_config,
1317         mod_instantiate,        /* instantiation         */
1318         mod_detach,             /* detach                */
1319         {
1320                 mod_authenticate,       /* authentication        */
1321                 mod_authorize,          /* authorization         */
1322                 NULL,                   /* preaccounting         */
1323                 mod_accounting,         /* accounting            */
1324                 NULL,                   /* checksimul            */
1325                 NULL,                   /* pre-proxy             */
1326                 NULL,                   /* post-proxy            */
1327                 mod_post_auth           /* post-auth */
1328         },
1329 };