2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2005 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
23 #include <ac/stdlib.h>
24 #include <ac/string.h>
31 #ifdef HAVE_CYRUS_SASL
32 # ifdef HAVE_SASL_SASL_H
33 # include <sasl/sasl.h>
38 # if SASL_VERSION_MAJOR >= 2
39 # ifdef HAVE_SASL_SASL_H
40 # include <sasl/saslplug.h>
42 # include <saslplug.h>
44 # define SASL_CONST const
49 #define SASL_VERSION_FULL ((SASL_VERSION_MAJOR << 16) |\
50 (SASL_VERSION_MINOR << 8) | SASL_VERSION_STEP)
52 static sasl_security_properties_t sasl_secprops;
53 #elif defined( SLAP_BUILTIN_SASL )
55 * built-in SASL implementation
56 * only supports EXTERNAL
58 typedef struct sasl_ctx {
59 slap_ssf_t sc_external_ssf;
60 struct berval sc_external_id;
67 static struct berval ext_bv = BER_BVC( "EXTERNAL" );
69 #ifdef HAVE_CYRUS_SASL
77 Connection *conn = context;
81 if ( message == NULL ) {
86 #if SASL_VERSION_MAJOR >= 2
88 level = LDAP_DEBUG_NONE;
92 level = LDAP_DEBUG_ANY;
96 level = LDAP_DEBUG_ANY;
100 level = LDAP_DEBUG_TRACE;
104 level = LDAP_DEBUG_TRACE;
108 level = LDAP_DEBUG_TRACE;
112 level = LDAP_DEBUG_TRACE;
116 level = LDAP_DEBUG_TRACE;
117 label = "Password Trace";
121 level = LDAP_DEBUG_ANY;
124 case SASL_LOG_WARNING:
125 level = LDAP_DEBUG_TRACE;
129 level = LDAP_DEBUG_TRACE;
134 return SASL_BADPARAM;
137 Debug( level, "SASL [conn=%ld] %s: %s\n",
138 conn ? conn->c_connid: -1,
146 #if SASL_VERSION_MAJOR >= 2
147 static const char *slap_propnames[] = {
148 "*slapConn", "*slapAuthcDN", "*slapAuthzDN", NULL };
150 static Filter generic_filter = { LDAP_FILTER_PRESENT };
151 static struct berval generic_filterstr = BER_BVC("(objectclass=*)");
156 #define PROP_COUNT 3 /* Number of properties we used */
158 typedef struct lookup_info {
160 const struct propval *list;
161 sasl_server_params_t *sparams;
164 static slap_response sasl_ap_lookup;
167 sasl_ap_lookup( Operation *op, SlapReply *rs )
170 AttributeDescription *ad;
174 slap_callback *tmp = op->o_callback;
175 lookup_info *sl = tmp->sc_private;
177 if (rs->sr_type != REP_SEARCH) return 0;
179 for( i = 0; sl->list[i].name; i++ ) {
180 const char *name = sl->list[i].name;
182 if ( name[0] == '*' ) {
183 if ( sl->flags & SASL_AUXPROP_AUTHZID ) continue;
184 /* Skip our private properties */
185 if ( !strcmp( name, slap_propnames[0] )) {
190 } else if ( !(sl->flags & SASL_AUXPROP_AUTHZID ) )
193 if ( sl->list[i].values ) {
194 if ( !(sl->flags & SASL_AUXPROP_OVERRIDE) ) continue;
197 rc = slap_str2ad( name, &ad, &text );
198 if ( rc != LDAP_SUCCESS ) {
199 Debug( LDAP_DEBUG_TRACE,
200 "slap_ap_lookup: str2ad(%s): %s\n", name, text, 0 );
203 a = attr_find( rs->sr_entry->e_attrs, ad );
205 if ( ! access_allowed( op, rs->sr_entry, ad, NULL, ACL_AUTH, NULL ) ) {
208 if ( sl->list[i].values && ( sl->flags & SASL_AUXPROP_OVERRIDE ) ) {
209 sl->sparams->utils->prop_erase( sl->sparams->propctx,
212 for ( bv = a->a_vals; bv->bv_val; bv++ ) {
213 sl->sparams->utils->prop_set( sl->sparams->propctx,
214 sl->list[i].name, bv->bv_val, bv->bv_len );
223 sasl_server_params_t *sparams,
230 Connection *conn = NULL;
233 sl.list = sparams->utils->prop_get( sparams->propctx );
234 sl.sparams = sparams;
237 /* Find our DN and conn first */
238 for( i = 0; sl.list[i].name; i++ ) {
239 if ( sl.list[i].name[0] == '*' ) {
240 if ( !strcmp( sl.list[i].name, slap_propnames[PROP_CONN] ) ) {
241 if ( sl.list[i].values && sl.list[i].values[0] )
242 AC_MEMCPY( &conn, sl.list[i].values[0], sizeof( conn ) );
245 if ( (flags & SASL_AUXPROP_AUTHZID) &&
246 !strcmp( sl.list[i].name, slap_propnames[PROP_AUTHZ] ) ) {
248 if ( sl.list[i].values && sl.list[i].values[0] )
249 AC_MEMCPY( &op.o_req_ndn, sl.list[i].values[0], sizeof( struct berval ) );
252 if ( !strcmp( sl.list[i].name, slap_propnames[PROP_AUTHC] ) ) {
253 if ( sl.list[i].values && sl.list[i].values[0] ) {
254 AC_MEMCPY( &op.o_req_ndn, sl.list[i].values[0], sizeof( struct berval ) );
255 if ( !(flags & SASL_AUXPROP_AUTHZID) )
262 /* Now see what else needs to be fetched */
263 for( i = 0; sl.list[i].name; i++ ) {
264 const char *name = sl.list[i].name;
266 if ( name[0] == '*' ) {
267 if ( flags & SASL_AUXPROP_AUTHZID ) continue;
268 /* Skip our private properties */
269 if ( !strcmp( name, slap_propnames[0] )) {
274 } else if ( !(flags & SASL_AUXPROP_AUTHZID ) )
277 if ( sl.list[i].values ) {
278 if ( !(flags & SASL_AUXPROP_OVERRIDE) ) continue;
285 slap_callback cb = { NULL, sasl_ap_lookup, NULL, NULL };
289 op.o_bd = select_backend( &op.o_req_ndn, 0, 1 );
291 if ( op.o_bd && op.o_bd->be_search ) {
292 SlapReply rs = {REP_RESULT};
293 op.o_hdr = conn->c_sasl_bindop->o_hdr;
294 op.o_tag = LDAP_REQ_SEARCH;
295 op.o_ndn = conn->c_ndn;
297 op.o_time = slap_get_time();
298 op.o_do_not_cache = 1;
299 op.o_is_auth_check = 1;
300 op.o_req_dn = op.o_req_ndn;
301 op.ors_scope = LDAP_SCOPE_BASE;
302 op.ors_deref = LDAP_DEREF_NEVER;
303 op.ors_tlimit = SLAP_NO_LIMIT;
305 op.ors_filter = &generic_filter;
306 op.ors_filterstr = generic_filterstr;
307 /* FIXME: we want all attributes, right? */
310 op.o_bd->be_search( &op, &rs );
315 #if SASL_VERSION_FULL >= 0x020110
319 sasl_server_params_t *sparams,
320 struct propctx *prctx,
325 SlapReply rs = {REP_RESULT};
327 Connection *conn = NULL;
328 const struct propval *pr;
329 Modifications *modlist = NULL, **modtail = &modlist, *mod;
330 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
331 char textbuf[SLAP_TEXT_BUFLEN];
333 size_t textlen = sizeof(textbuf);
335 /* just checking if we are enabled */
336 if (!prctx) return SASL_OK;
338 if (!sparams || !user) return SASL_BADPARAM;
340 pr = sparams->utils->prop_get( sparams->propctx );
342 /* Find our DN and conn first */
343 for( i = 0; pr[i].name; i++ ) {
344 if ( pr[i].name[0] == '*' ) {
345 if ( !strcmp( pr[i].name, slap_propnames[PROP_CONN] ) ) {
346 if ( pr[i].values && pr[i].values[0] )
347 AC_MEMCPY( &conn, pr[i].values[0], sizeof( conn ) );
350 if ( !strcmp( pr[i].name, slap_propnames[PROP_AUTHC] ) ) {
351 if ( pr[i].values && pr[i].values[0] ) {
352 AC_MEMCPY( &op.o_req_ndn, pr[i].values[0], sizeof( struct berval ) );
357 if (!conn || !op.o_req_ndn.bv_val) return SASL_BADPARAM;
359 op.o_bd = select_backend( &op.o_req_ndn, 0, 1 );
361 if ( !op.o_bd || !op.o_bd->be_modify ) return SASL_FAIL;
363 pr = sparams->utils->prop_get( prctx );
364 if (!pr) return SASL_BADPARAM;
366 for (i=0; pr[i].name; i++);
367 if (!i) return SASL_BADPARAM;
369 for (i=0; pr[i].name; i++) {
370 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
371 mod->sml_op = LDAP_MOD_REPLACE;
373 ber_str2bv( pr[i].name, 0, 0, &mod->sml_type );
374 mod->sml_values = (struct berval *)ch_malloc( (pr[i].nvalues + 1) *
375 sizeof(struct berval));
376 for (j=0; j<pr[i].nvalues; j++) {
377 ber_str2bv( pr[i].values[j], 0, 1, &mod->sml_values[j]);
379 BER_BVZERO( &mod->sml_values[j] );
380 mod->sml_nvalues = NULL;
381 mod->sml_desc = NULL;
383 modtail = &mod->sml_next;
387 rc = slap_mods_check( modlist, &text, textbuf, textlen, NULL );
389 if ( rc == LDAP_SUCCESS ) {
390 rc = slap_mods_no_user_mod_check( &op, modlist,
391 &text, textbuf, textlen );
393 if ( rc == LDAP_SUCCESS ) {
394 rc = slap_mods_opattrs( &op, modlist, modtail,
395 &text, textbuf, textlen, 1 );
397 if ( rc == LDAP_SUCCESS ) {
398 op.o_hdr = conn->c_sasl_bindop->o_hdr;
399 op.o_tag = LDAP_REQ_MODIFY;
400 op.o_ndn = op.o_req_ndn;
402 op.o_time = slap_get_time();
403 op.o_do_not_cache = 1;
404 op.o_is_auth_check = 1;
405 op.o_req_dn = op.o_req_ndn;
406 op.orm_modlist = modlist;
408 rc = op.o_bd->be_modify( &op, &rs );
412 slap_mods_free( modlist );
413 return rc != LDAP_SUCCESS ? SASL_FAIL : SASL_OK;
415 #endif /* SASL_VERSION_FULL >= 2.1.16 */
417 static sasl_auxprop_plug_t slap_auxprop_plugin = {
420 NULL, /* glob_context */
421 NULL, /* auxprop_free */
424 #if SASL_VERSION_FULL >= 0x020110
425 slap_auxprop_store /* the declaration of this member changed
426 * in cyrus SASL from 2.1.15 to 2.1.16 */
434 const sasl_utils_t *utils,
437 sasl_auxprop_plug_t **plug,
438 const char *plugname)
440 if ( !out_version || !plug ) return SASL_BADPARAM;
442 if ( max_version < SASL_AUXPROP_PLUG_VERSION ) return SASL_BADVERS;
444 *out_version = SASL_AUXPROP_PLUG_VERSION;
445 *plug = &slap_auxprop_plugin;
449 /* Convert a SASL authcid or authzid into a DN. Store the DN in an
450 * auxiliary property, so that we can refer to it in sasl_authorize
451 * without interfering with anything else. Also, the SASL username
452 * buffer is constrained to 256 characters, and our DNs could be
453 * much longer (SLAP_LDAPDN_MAXLEN, currently set to 8192)
456 slap_sasl_canonicalize(
462 const char *user_realm,
467 Connection *conn = (Connection *)context;
468 struct propctx *props = sasl_auxprop_getctx( sconn );
469 struct propval auxvals[3];
472 const char *names[2];
477 Debug( LDAP_DEBUG_ARGS, "SASL Canonicalize [conn=%ld]: %s=\"%s\"\n",
478 conn ? conn->c_connid : -1,
479 (flags & SASL_CU_AUTHID) ? "authcid" : "authzid",
480 in ? in : "<empty>");
482 /* If name is too big, just truncate. We don't care, we're
483 * using DNs, not the usernames.
485 if ( inlen > out_max )
488 /* This is a Simple Bind using SPASSWD. That means the in-directory
489 * userPassword of the Binding user already points at SASL, so it
490 * cannot be used to actually satisfy a password comparison. Just
491 * ignore it, some other mech will process it.
493 if ( !conn->c_sasl_bindop ||
494 conn->c_sasl_bindop->orb_method != LDAP_AUTH_SASL ) goto done;
496 /* See if we need to add request, can only do it once */
497 prop_getnames( props, slap_propnames, auxvals );
498 if ( !auxvals[0].name )
499 prop_request( props, slap_propnames );
501 if ( flags & SASL_CU_AUTHID )
506 /* Need to store the Connection for auxprop_lookup */
507 if ( !auxvals[PROP_CONN].values ) {
508 names[0] = slap_propnames[PROP_CONN];
510 prop_set( props, names[0], (char *)&conn, sizeof( conn ) );
513 /* Already been here? */
514 if ( auxvals[which].values )
517 /* Normally we require an authzID to have a u: or dn: prefix.
518 * However, SASL frequently gives us an authzID that is just
519 * an exact copy of the authcID, without a prefix. We need to
520 * detect and allow this condition. If SASL calls canonicalize
521 * with SASL_CU_AUTHID|SASL_CU_AUTHZID this is a no-brainer.
522 * But if it's broken into two calls, we need to remember the
523 * authcID so that we can compare the authzID later. We store
524 * the authcID temporarily in conn->c_sasl_dn. We necessarily
525 * finish Canonicalizing before Authorizing, so there is no
526 * conflict with slap_sasl_authorize's use of this temp var.
528 * The SASL EXTERNAL mech is backwards from all the other mechs,
529 * it does authzID before the authcID. If we see that authzID
530 * has already been done, don't do anything special with authcID.
532 if ( flags == SASL_CU_AUTHID && !auxvals[PROP_AUTHZ].values ) {
533 conn->c_sasl_dn.bv_val = (char *) in;
534 } else if ( flags == SASL_CU_AUTHZID && conn->c_sasl_dn.bv_val ) {
535 rc = strcmp( in, conn->c_sasl_dn.bv_val );
536 conn->c_sasl_dn.bv_val = NULL;
537 /* They were equal, no work needed */
538 if ( !rc ) goto done;
541 bvin.bv_val = (char *)in;
543 rc = slap_sasl_getdn( conn, NULL, &bvin, (char *)user_realm, &dn,
544 (flags & SASL_CU_AUTHID) ? SLAP_GETDN_AUTHCID : SLAP_GETDN_AUTHZID );
545 if ( rc != LDAP_SUCCESS ) {
546 sasl_seterror( sconn, 0, ldap_err2string( rc ) );
550 names[0] = slap_propnames[which];
553 prop_set( props, names[0], (char *)&dn, sizeof( dn ) );
555 Debug( LDAP_DEBUG_ARGS, "SASL Canonicalize [conn=%ld]: %s=\"%s\"\n",
556 conn ? conn->c_connid : -1, names[0]+1,
557 dn.bv_val ? dn.bv_val : "<EMPTY>" );
560 AC_MEMCPY( out, in, inlen );
572 char *requested_user,
576 const char *def_realm,
578 struct propctx *props)
580 Connection *conn = (Connection *)context;
581 struct propval auxvals[3];
582 struct berval authcDN, authzDN=BER_BVNULL;
585 /* Simple Binds don't support proxy authorization, ignore it */
586 if ( !conn->c_sasl_bindop ||
587 conn->c_sasl_bindop->orb_method != LDAP_AUTH_SASL ) return SASL_OK;
589 Debug( LDAP_DEBUG_ARGS, "SASL proxy authorize [conn=%ld]: "
590 "authcid=\"%s\" authzid=\"%s\"\n",
591 conn ? conn->c_connid : -1, auth_identity, requested_user );
592 if ( conn->c_sasl_dn.bv_val ) {
593 ch_free( conn->c_sasl_dn.bv_val );
594 BER_BVZERO( &conn->c_sasl_dn );
598 prop_getnames( props, slap_propnames+1, auxvals );
600 /* Should not happen */
601 if ( !auxvals[0].values ) {
602 sasl_seterror( sconn, 0, "invalid authcid" );
606 AC_MEMCPY( &authcDN, auxvals[0].values[0], sizeof(authcDN) );
607 conn->c_sasl_dn = authcDN;
609 /* Nothing to do if no authzID was given */
610 if ( !auxvals[1].name || !auxvals[1].values ) {
614 AC_MEMCPY( &authzDN, auxvals[1].values[0], sizeof(authzDN) );
616 rc = slap_sasl_authorized( conn->c_sasl_bindop, &authcDN, &authzDN );
617 if ( rc != LDAP_SUCCESS ) {
618 Debug( LDAP_DEBUG_TRACE, "SASL Proxy Authorize [conn=%ld]: "
619 "proxy authorization disallowed (%d)\n",
620 (long) (conn ? conn->c_connid : -1), rc, 0 );
622 sasl_seterror( sconn, 0, "not authorized" );
623 ch_free( authzDN.bv_val );
627 conn->c_sasl_authz_dn = authzDN;
629 if (conn->c_sasl_bindop) {
630 Statslog( LDAP_DEBUG_STATS,
631 "conn=%lu op=%lu BIND authcid=\"%s\" authzid=\"%s\"\n",
632 conn->c_connid, conn->c_sasl_bindop->o_opid,
633 auth_identity, requested_user, 0);
636 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
637 " proxy authorization allowed authzDN=\"%s\"\n",
638 (long) (conn ? conn->c_connid : -1),
639 authzDN.bv_val ? authzDN.bv_val : "", 0 );
651 struct berval authcDN, authzDN;
653 Connection *conn = context;
655 struct berval bvauthcid, bvauthzid;
658 if ( conn->c_sasl_dn.bv_val ) {
659 ch_free( conn->c_sasl_dn.bv_val );
660 BER_BVZERO( &conn->c_sasl_dn );
663 Debug( LDAP_DEBUG_ARGS, "SASL Authorize [conn=%ld]: "
664 "authcid=\"%s\" authzid=\"%s\"\n",
665 (long) (conn ? conn->c_connid : -1),
666 authcid ? authcid : "<empty>",
667 authzid ? authzid : "<empty>" );
669 /* Figure out how much data we have for the dn */
670 rc = sasl_getprop( conn->c_sasl_authctx, SASL_REALM, (void **)&realm );
671 if( rc != SASL_OK && rc != SASL_NOTDONE ) {
672 Debug(LDAP_DEBUG_TRACE,
673 "authorize: getprop(REALM) failed!\n", 0,0,0);
674 *errstr = "Could not extract realm";
678 /* Convert the identities to DN's. If no authzid was given, client will
679 be bound as the DN matching their username */
680 bvauthcid.bv_val = authcid;
681 bvauthcid.bv_len = authcid ? strlen( authcid ) : 0;
682 rc = slap_sasl_getdn( conn, NULL, &bvauthcid, realm,
683 &authcDN, SLAP_GETDN_AUTHCID );
684 if( rc != LDAP_SUCCESS ) {
685 *errstr = ldap_err2string( rc );
688 conn->c_sasl_dn = authcDN;
689 if( ( authzid == NULL ) || !strcmp( authcid, authzid ) ) {
690 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
691 "Using authcDN=%s\n", (long) (conn ? conn->c_connid : -1), authcDN.bv_val,0 );
696 bvauthzid.bv_val = authzid;
697 bvauthzid.bv_len = authzid ? strlen( authzid ) : 0;
698 rc = slap_sasl_getdn( conn, NULL, &bvauthzid, realm,
699 &authzDN, SLAP_GETDN_AUTHZID );
700 if( rc != LDAP_SUCCESS ) {
701 *errstr = ldap_err2string( rc );
705 rc = slap_sasl_authorized(conn->c_sasl_bindop, &authcDN, &authzDN );
707 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
708 "proxy authorization disallowed (%d)\n",
709 (long) (conn ? conn->c_connid : -1), rc, 0 );
711 *errstr = "not authorized";
712 ch_free( authzDN.bv_val );
715 conn->c_sasl_authz_dn = authzDN;
718 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
719 " authorization allowed authzDN=\"%s\"\n",
720 (long) (conn ? conn->c_connid : -1),
721 authzDN.bv_val ? authzDN.bv_val : "", 0 );
723 if (conn->c_sasl_bindop) {
724 Statslog( LDAP_DEBUG_STATS,
725 "conn=%lu op=%lu BIND authcid=\"%s\" authzid=\"%s\"\n",
726 conn->c_connid, conn->c_sasl_bindop->o_opid,
727 authcid, authzid ? authzid : "", 0);
733 #endif /* SASL_VERSION_MAJOR >= 2 */
736 slap_sasl_err2ldap( int saslerr )
745 rc = LDAP_SASL_BIND_IN_PROGRESS;
754 rc = LDAP_AUTH_METHOD_NOT_SUPPORTED;
757 rc = LDAP_INVALID_CREDENTIALS;
760 rc = LDAP_INSUFFICIENT_ACCESS;
764 rc = LDAP_INAPPROPRIATE_AUTH;
776 static struct berval sasl_pwscheme = BER_BVC("{SASL}");
779 const struct berval *sc,
780 const struct berval * passwd,
781 const struct berval * cred,
786 void *ctx, *sconn = NULL;
788 for( i=0; i<cred->bv_len; i++) {
789 if(cred->bv_val[i] == '\0') {
790 return LUTIL_PASSWD_ERR; /* NUL character in password */
794 if( cred->bv_val[i] != '\0' ) {
795 return LUTIL_PASSWD_ERR; /* cred must behave like a string */
798 for( i=0; i<passwd->bv_len; i++) {
799 if(passwd->bv_val[i] == '\0') {
800 return LUTIL_PASSWD_ERR; /* NUL character in password */
804 if( passwd->bv_val[i] != '\0' ) {
805 return LUTIL_PASSWD_ERR; /* passwd must behave like a string */
808 rtn = LUTIL_PASSWD_ERR;
810 ctx = ldap_pvt_thread_pool_context();
811 ldap_pvt_thread_pool_getkey( ctx, slap_sasl_bind, &sconn, NULL );
813 if( sconn != NULL ) {
815 # if SASL_VERSION_MAJOR < 2
816 sc = sasl_checkpass( sconn,
817 passwd->bv_val, passwd->bv_len,
818 cred->bv_val, cred->bv_len,
821 sc = sasl_checkpass( sconn,
822 passwd->bv_val, passwd->bv_len,
823 cred->bv_val, cred->bv_len );
825 rtn = ( sc != SASL_OK ) ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
830 #endif /* SLAPD_SPASSWD */
832 #endif /* HAVE_CYRUS_SASL */
834 int slap_sasl_init( void )
836 #ifdef HAVE_CYRUS_SASL
838 static sasl_callback_t server_callbacks[] = {
839 { SASL_CB_LOG, &slap_sasl_log, NULL },
840 { SASL_CB_LIST_END, NULL, NULL }
843 #ifdef HAVE_SASL_VERSION
844 /* stringify the version number, sasl.h doesn't do it for us */
845 #define VSTR0(maj, min, pat) #maj "." #min "." #pat
846 #define VSTR(maj, min, pat) VSTR0(maj, min, pat)
847 #define SASL_VERSION_STRING VSTR(SASL_VERSION_MAJOR, SASL_VERSION_MINOR, \
850 sasl_version( NULL, &rc );
851 if ( ((rc >> 16) != ((SASL_VERSION_MAJOR << 8)|SASL_VERSION_MINOR)) ||
852 (rc & 0xffff) < SASL_VERSION_STEP)
854 char version[sizeof("xxx.xxx.xxxxx")];
855 sprintf( version, "%u.%d.%d", (unsigned)rc >> 24, (rc >> 16) & 0xff,
857 Debug( LDAP_DEBUG_ANY, "slap_sasl_init: SASL library version mismatch:"
858 " expected " SASL_VERSION_STRING ","
859 " got %s\n", version, 0, 0 );
864 /* SASL 2 does its own memory management internally */
865 #if SASL_VERSION_MAJOR < 2
874 ldap_pvt_sasl_mutex_new,
875 ldap_pvt_sasl_mutex_lock,
876 ldap_pvt_sasl_mutex_unlock,
877 ldap_pvt_sasl_mutex_dispose );
879 #if SASL_VERSION_MAJOR >= 2
880 generic_filter.f_desc = slap_schema.si_ad_objectClass;
882 rc = sasl_auxprop_add_plugin( "slapd", slap_auxprop_init );
883 if( rc != SASL_OK ) {
884 Debug( LDAP_DEBUG_ANY, "slap_sasl_init: auxprop add plugin failed\n",
889 /* should provide callbacks for logging */
890 /* server name should be configurable */
891 rc = sasl_server_init( server_callbacks, "slapd" );
893 if( rc != SASL_OK ) {
894 Debug( LDAP_DEBUG_ANY, "slap_sasl_init: server init failed\n",
896 #if SASL_VERSION_MAJOR < 2
897 /* A no-op used to make sure we linked with Cyrus 1.5 */
898 sasl_client_auth( NULL, NULL, NULL, 0, NULL, NULL );
905 lutil_passwd_add( &sasl_pwscheme, chk_sasl, NULL );
908 Debug( LDAP_DEBUG_TRACE, "slap_sasl_init: initialized!\n",
911 /* default security properties */
912 memset( &sasl_secprops, '\0', sizeof(sasl_secprops) );
913 sasl_secprops.max_ssf = INT_MAX;
914 sasl_secprops.maxbufsize = 65536;
915 sasl_secprops.security_flags = SASL_SEC_NOPLAINTEXT|SASL_SEC_NOANONYMOUS;
921 int slap_sasl_destroy( void )
923 #ifdef HAVE_CYRUS_SASL
932 int slap_sasl_open( Connection *conn, int reopen )
934 int sc = LDAP_SUCCESS;
935 #ifdef HAVE_CYRUS_SASL
938 sasl_conn_t *ctx = NULL;
939 sasl_callback_t *session_callbacks;
941 #if SASL_VERSION_MAJOR >= 2
942 char *ipremoteport = NULL, *iplocalport = NULL;
945 assert( conn->c_sasl_authctx == NULL );
948 assert( conn->c_sasl_extra == NULL );
951 #if SASL_VERSION_MAJOR >= 2
952 SLAP_CALLOC( 5, sizeof(sasl_callback_t));
954 SLAP_CALLOC( 3, sizeof(sasl_callback_t));
956 if( session_callbacks == NULL ) {
957 Debug( LDAP_DEBUG_ANY,
958 "slap_sasl_open: SLAP_MALLOC failed", 0, 0, 0 );
961 conn->c_sasl_extra = session_callbacks;
963 session_callbacks[cb=0].id = SASL_CB_LOG;
964 session_callbacks[cb].proc = &slap_sasl_log;
965 session_callbacks[cb++].context = conn;
967 session_callbacks[cb].id = SASL_CB_PROXY_POLICY;
968 session_callbacks[cb].proc = &slap_sasl_authorize;
969 session_callbacks[cb++].context = conn;
971 #if SASL_VERSION_MAJOR >= 2
972 session_callbacks[cb].id = SASL_CB_CANON_USER;
973 session_callbacks[cb].proc = &slap_sasl_canonicalize;
974 session_callbacks[cb++].context = conn;
977 session_callbacks[cb].id = SASL_CB_LIST_END;
978 session_callbacks[cb].proc = NULL;
979 session_callbacks[cb++].context = NULL;
981 session_callbacks = conn->c_sasl_extra;
984 conn->c_sasl_layers = 0;
986 if( global_host == NULL ) {
987 global_host = ldap_pvt_get_fqdn( NULL );
990 /* create new SASL context */
991 #if SASL_VERSION_MAJOR >= 2
992 if ( conn->c_sock_name.bv_len != 0 &&
993 strncmp( conn->c_sock_name.bv_val, "IP=", 3 ) == 0) {
996 iplocalport = ch_strdup( conn->c_sock_name.bv_val + 3 );
997 /* Convert IPv6 addresses to address;port syntax. */
998 p = strrchr( iplocalport, ' ' );
999 /* Convert IPv4 addresses to address;port syntax. */
1000 if ( p == NULL ) p = strchr( iplocalport, ':' );
1005 if ( conn->c_peer_name.bv_len != 0 &&
1006 strncmp( conn->c_peer_name.bv_val, "IP=", 3 ) == 0) {
1009 ipremoteport = ch_strdup( conn->c_peer_name.bv_val + 3 );
1010 /* Convert IPv6 addresses to address;port syntax. */
1011 p = strrchr( ipremoteport, ' ' );
1012 /* Convert IPv4 addresses to address;port syntax. */
1013 if ( p == NULL ) p = strchr( ipremoteport, ':' );
1018 sc = sasl_server_new( "ldap", global_host, global_realm,
1019 iplocalport, ipremoteport, session_callbacks, SASL_SUCCESS_DATA, &ctx );
1020 if ( iplocalport != NULL ) {
1021 ch_free( iplocalport );
1023 if ( ipremoteport != NULL ) {
1024 ch_free( ipremoteport );
1027 sc = sasl_server_new( "ldap", global_host, global_realm,
1028 session_callbacks, SASL_SECURITY_LAYER, &ctx );
1031 if( sc != SASL_OK ) {
1032 Debug( LDAP_DEBUG_ANY, "sasl_server_new failed: %d\n",
1038 conn->c_sasl_authctx = ctx;
1040 if( sc == SASL_OK ) {
1041 sc = sasl_setprop( ctx,
1042 SASL_SEC_PROPS, &sasl_secprops );
1044 if( sc != SASL_OK ) {
1045 Debug( LDAP_DEBUG_ANY, "sasl_setprop failed: %d\n",
1048 slap_sasl_close( conn );
1053 sc = slap_sasl_err2ldap( sc );
1055 #elif defined(SLAP_BUILTIN_SASL)
1056 /* built-in SASL implementation */
1057 SASL_CTX *ctx = (SASL_CTX *) SLAP_MALLOC(sizeof(SASL_CTX));
1058 if( ctx == NULL ) return -1;
1060 ctx->sc_external_ssf = 0;
1061 BER_BVZERO( &ctx->sc_external_id );
1063 conn->c_sasl_authctx = ctx;
1069 int slap_sasl_external(
1072 struct berval *auth_id )
1074 #if SASL_VERSION_MAJOR >= 2
1076 sasl_conn_t *ctx = conn->c_sasl_authctx;
1078 if ( ctx == NULL ) {
1079 return LDAP_UNAVAILABLE;
1082 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
1084 if ( sc != SASL_OK ) {
1088 sc = sasl_setprop( ctx, SASL_AUTH_EXTERNAL,
1089 auth_id ? auth_id->bv_val : NULL );
1091 if ( sc != SASL_OK ) {
1095 #elif defined(HAVE_CYRUS_SASL)
1097 sasl_conn_t *ctx = conn->c_sasl_authctx;
1098 sasl_external_properties_t extprops;
1100 if ( ctx == NULL ) {
1101 return LDAP_UNAVAILABLE;
1104 memset( &extprops, '\0', sizeof(extprops) );
1106 extprops.auth_id = auth_id ? auth_id->bv_val : NULL;
1108 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
1109 (void *) &extprops );
1111 if ( sc != SASL_OK ) {
1114 #elif defined(SLAP_BUILTIN_SASL)
1115 /* built-in SASL implementation */
1116 SASL_CTX *ctx = conn->c_sasl_authctx;
1117 if ( ctx == NULL ) return LDAP_UNAVAILABLE;
1119 ctx->sc_external_ssf = ssf;
1121 ctx->sc_external_id = *auth_id;
1122 BER_BVZERO( auth_id );
1124 BER_BVZERO( &ctx->sc_external_id );
1128 return LDAP_SUCCESS;
1131 int slap_sasl_reset( Connection *conn )
1133 return LDAP_SUCCESS;
1136 char ** slap_sasl_mechs( Connection *conn )
1138 char **mechs = NULL;
1140 #ifdef HAVE_CYRUS_SASL
1141 sasl_conn_t *ctx = conn->c_sasl_authctx;
1143 if( ctx == NULL ) ctx = conn->c_sasl_sockctx;
1147 SASL_CONST char *mechstr;
1149 sc = sasl_listmech( ctx,
1150 NULL, NULL, ",", NULL,
1151 &mechstr, NULL, NULL );
1153 if( sc != SASL_OK ) {
1154 Debug( LDAP_DEBUG_ANY, "slap_sasl_listmech failed: %d\n",
1160 mechs = ldap_str2charray( mechstr, "," );
1162 #if SASL_VERSION_MAJOR < 2
1166 #elif defined(SLAP_BUILTIN_SASL)
1167 /* builtin SASL implementation */
1168 SASL_CTX *ctx = conn->c_sasl_authctx;
1169 if ( ctx != NULL && ctx->sc_external_id.bv_val ) {
1170 /* should check ssf */
1171 mechs = ldap_str2charray( "EXTERNAL", "," );
1178 int slap_sasl_close( Connection *conn )
1180 #ifdef HAVE_CYRUS_SASL
1181 sasl_conn_t *ctx = conn->c_sasl_authctx;
1184 sasl_dispose( &ctx );
1186 if ( conn->c_sasl_sockctx &&
1187 conn->c_sasl_authctx != conn->c_sasl_sockctx )
1189 ctx = conn->c_sasl_sockctx;
1190 sasl_dispose( &ctx );
1193 conn->c_sasl_authctx = NULL;
1194 conn->c_sasl_sockctx = NULL;
1195 conn->c_sasl_done = 0;
1197 free( conn->c_sasl_extra );
1198 conn->c_sasl_extra = NULL;
1200 #elif defined(SLAP_BUILTIN_SASL)
1201 SASL_CTX *ctx = conn->c_sasl_authctx;
1203 if( ctx->sc_external_id.bv_val ) {
1204 free( ctx->sc_external_id.bv_val );
1205 BER_BVZERO( &ctx->sc_external_id );
1208 conn->c_sasl_authctx = NULL;
1212 return LDAP_SUCCESS;
1215 int slap_sasl_bind( Operation *op, SlapReply *rs )
1217 #ifdef HAVE_CYRUS_SASL
1218 sasl_conn_t *ctx = op->o_conn->c_sasl_authctx;
1219 struct berval response;
1220 unsigned reslen = 0;
1223 Debug(LDAP_DEBUG_ARGS,
1224 "==> sasl_bind: dn=\"%s\" mech=%s datalen=%ld\n",
1225 op->o_req_dn.bv_len ? op->o_req_dn.bv_val : "",
1226 op->o_conn->c_sasl_bind_in_progress ? "<continuing>" :
1227 op->o_conn->c_sasl_bind_mech.bv_val,
1228 op->orb_cred.bv_len );
1231 send_ldap_error( op, rs, LDAP_UNAVAILABLE,
1232 "SASL unavailable on this session" );
1236 #if SASL_VERSION_MAJOR >= 2
1237 #define START( ctx, mech, cred, clen, resp, rlen, err ) \
1238 sasl_server_start( ctx, mech, cred, clen, resp, rlen )
1239 #define STEP( ctx, cred, clen, resp, rlen, err ) \
1240 sasl_server_step( ctx, cred, clen, resp, rlen )
1242 #define START( ctx, mech, cred, clen, resp, rlen, err ) \
1243 sasl_server_start( ctx, mech, cred, clen, resp, rlen, err )
1244 #define STEP( ctx, cred, clen, resp, rlen, err ) \
1245 sasl_server_step( ctx, cred, clen, resp, rlen, err )
1248 if ( !op->o_conn->c_sasl_bind_in_progress ) {
1249 /* If we already authenticated once, must use a new context */
1250 if ( op->o_conn->c_sasl_done ) {
1252 const char *authid = NULL;
1253 #if SASL_VERSION_MAJOR >= 2
1254 sasl_getprop( ctx, SASL_SSF_EXTERNAL, (void *)&ssf );
1255 sasl_getprop( ctx, SASL_AUTH_EXTERNAL, (void *)&authid );
1256 if ( authid ) authid = ch_strdup( authid );
1258 if ( ctx != op->o_conn->c_sasl_sockctx ) {
1259 sasl_dispose( &ctx );
1261 op->o_conn->c_sasl_authctx = NULL;
1263 slap_sasl_open( op->o_conn, 1 );
1264 ctx = op->o_conn->c_sasl_authctx;
1265 #if SASL_VERSION_MAJOR >= 2
1267 sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
1268 sasl_setprop( ctx, SASL_AUTH_EXTERNAL, authid );
1269 ch_free( (char *)authid );
1274 op->o_conn->c_sasl_bind_mech.bv_val,
1275 op->orb_cred.bv_val, op->orb_cred.bv_len,
1276 (SASL_CONST char **)&response.bv_val, &reslen, &rs->sr_text );
1280 op->orb_cred.bv_val, op->orb_cred.bv_len,
1281 (SASL_CONST char **)&response.bv_val, &reslen, &rs->sr_text );
1284 response.bv_len = reslen;
1286 if ( sc == SASL_OK ) {
1287 sasl_ssf_t *ssf = NULL;
1289 op->orb_edn = op->o_conn->c_sasl_dn;
1290 BER_BVZERO( &op->o_conn->c_sasl_dn );
1291 op->o_conn->c_sasl_done = 1;
1293 rs->sr_err = LDAP_SUCCESS;
1295 (void) sasl_getprop( ctx, SASL_SSF, (void *)&ssf );
1296 op->orb_ssf = ssf ? *ssf : 0;
1300 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1301 op->o_conn->c_sasl_layers++;
1303 /* If there's an old layer, set sockctx to NULL to
1304 * tell connection_read() to wait for us to finish.
1305 * Otherwise there is a race condition: we have to
1306 * send the Bind response using the old security
1307 * context and then remove it before reading any
1310 if ( op->o_conn->c_sasl_sockctx ) {
1311 ctx = op->o_conn->c_sasl_sockctx;
1312 op->o_conn->c_sasl_sockctx = NULL;
1314 op->o_conn->c_sasl_sockctx = op->o_conn->c_sasl_authctx;
1316 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1319 /* Must send response using old security layer */
1320 if (response.bv_len) rs->sr_sasldata = &response;
1321 send_ldap_sasl( op, rs );
1323 /* Now dispose of the old security layer.
1326 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1327 ldap_pvt_sasl_remove( op->o_conn->c_sb );
1328 op->o_conn->c_sasl_sockctx = op->o_conn->c_sasl_authctx;
1329 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1330 sasl_dispose( &ctx );
1332 } else if ( sc == SASL_CONTINUE ) {
1333 rs->sr_err = LDAP_SASL_BIND_IN_PROGRESS,
1334 rs->sr_sasldata = &response;
1335 send_ldap_sasl( op, rs );
1338 #if SASL_VERSION_MAJOR >= 2
1339 rs->sr_text = sasl_errdetail( ctx );
1341 rs->sr_err = slap_sasl_err2ldap( sc ),
1342 send_ldap_result( op, rs );
1345 #if SASL_VERSION_MAJOR < 2
1346 if( response.bv_len ) {
1347 ch_free( response.bv_val );
1351 Debug(LDAP_DEBUG_TRACE, "<== slap_sasl_bind: rc=%d\n", rs->sr_err, 0, 0);
1353 #elif defined(SLAP_BUILTIN_SASL)
1354 /* built-in SASL implementation */
1355 SASL_CTX *ctx = op->o_conn->c_sasl_authctx;
1357 if ( ctx == NULL ) {
1358 send_ldap_error( op, rs, LDAP_OTHER,
1359 "Internal SASL Error" );
1361 } else if ( bvmatch( &ext_bv, &op->o_conn->c_sasl_bind_mech ) ) {
1364 if( op->orb_cred.bv_len ) {
1365 rs->sr_text = "proxy authorization not support";
1366 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1367 send_ldap_result( op, rs );
1370 op->orb_edn = ctx->sc_external_id;
1371 rs->sr_err = LDAP_SUCCESS;
1372 rs->sr_sasldata = NULL;
1373 send_ldap_sasl( op, rs );
1377 send_ldap_error( op, rs, LDAP_AUTH_METHOD_NOT_SUPPORTED,
1378 "requested SASL mechanism not supported" );
1381 send_ldap_error( op, rs, LDAP_AUTH_METHOD_NOT_SUPPORTED,
1382 "SASL not supported" );
1388 char* slap_sasl_secprops( const char *in )
1390 #ifdef HAVE_CYRUS_SASL
1391 int rc = ldap_pvt_sasl_secprops( in, &sasl_secprops );
1393 return rc == LDAP_SUCCESS ? NULL : "Invalid security properties";
1395 return "SASL not supported";
1399 void slap_sasl_secprops_unparse( struct berval *bv )
1401 #ifdef HAVE_CYRUS_SASL
1402 ldap_pvt_sasl_secprops_unparse( &sasl_secprops, bv );
1406 #ifdef HAVE_CYRUS_SASL
1408 slap_sasl_setpass( Operation *op, SlapReply *rs )
1410 struct berval id = BER_BVNULL; /* needs to come from connection */
1411 struct berval new = BER_BVNULL;
1412 struct berval old = BER_BVNULL;
1414 assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->ore_reqoid ) == 0 );
1416 rs->sr_err = sasl_getprop( op->o_conn->c_sasl_authctx, SASL_USERNAME,
1417 (SASL_CONST void **)&id.bv_val );
1419 if( rs->sr_err != SASL_OK ) {
1420 rs->sr_text = "unable to retrieve SASL username";
1421 rs->sr_err = LDAP_OTHER;
1425 Debug( LDAP_DEBUG_ARGS, "==> slap_sasl_setpass: \"%s\"\n",
1426 id.bv_val ? id.bv_val : "", 0, 0 );
1428 rs->sr_err = slap_passwd_parse( op->ore_reqdata,
1429 NULL, &old, &new, &rs->sr_text );
1431 if( rs->sr_err != LDAP_SUCCESS ) {
1435 if( new.bv_len == 0 ) {
1436 slap_passwd_generate(&new);
1438 if( new.bv_len == 0 ) {
1439 rs->sr_text = "password generation failed.";
1440 rs->sr_err = LDAP_OTHER;
1444 rs->sr_rspdata = slap_passwd_return( &new );
1447 #if SASL_VERSION_MAJOR < 2
1448 rs->sr_err = sasl_setpass( op->o_conn->c_sasl_authctx,
1449 id.bv_val, new.bv_val, new.bv_len, 0, &rs->sr_text );
1451 rs->sr_err = sasl_setpass( op->o_conn->c_sasl_authctx, id.bv_val,
1452 new.bv_val, new.bv_len, old.bv_val, old.bv_len, 0 );
1453 if( rs->sr_err != SASL_OK ) {
1454 rs->sr_text = sasl_errdetail( op->o_conn->c_sasl_authctx );
1457 switch(rs->sr_err) {
1459 rs->sr_err = LDAP_SUCCESS;
1469 rs->sr_err = LDAP_OTHER;
1475 #endif /* HAVE_CYRUS_SASL */
1477 /* Take any sort of identity string and return a DN with the "dn:" prefix. The
1478 * string returned in *dn is in its own allocated memory, and must be free'd
1479 * by the calling process. -Mark Adamson, Carnegie Mellon
1481 * The "dn:" prefix is no longer used anywhere inside slapd. It is only used
1482 * on strings passed in directly from SASL. -Howard Chu, Symas Corp.
1489 int slap_sasl_getdn( Connection *conn, Operation *op, struct berval *id,
1490 char *user_realm, struct berval *dn, int flags )
1492 int rc, is_dn = SET_NONE, do_norm = 1;
1493 struct berval dn2, *mech;
1498 Debug( LDAP_DEBUG_ARGS, "slap_sasl_getdn: conn %d id=%s [len=%d]\n",
1500 BER_BVISNULL( id ) ? "NULL" : ( BER_BVISEMPTY( id ) ? "<empty>" : id->bv_val ),
1501 BER_BVISNULL( id ) ? 0 : ( BER_BVISEMPTY( id ) ? 0 : id->bv_len ) );
1504 op = conn->c_sasl_bindop;
1509 if ( !BER_BVISNULL( id ) ) {
1510 /* Blatantly anonymous ID */
1511 static struct berval bv_anonymous = BER_BVC( "anonymous" );
1513 if ( ber_bvstrcasecmp( id, &bv_anonymous ) == 0 ) {
1514 return( LDAP_SUCCESS );
1518 /* FIXME: if empty, should we stop? */
1519 BER_BVSTR( id, "" );
1522 if ( !BER_BVISEMPTY( &conn->c_sasl_bind_mech ) ) {
1523 mech = &conn->c_sasl_bind_mech;
1525 mech = &conn->c_authmech;
1528 /* An authcID needs to be converted to authzID form. Set the
1529 * values directly into *dn; they will be normalized later. (and
1530 * normalizing always makes a new copy.) An ID from a TLS certificate
1531 * is already normalized, so copy it and skip normalization.
1533 if( flags & SLAP_GETDN_AUTHCID ) {
1534 if( bvmatch( mech, &ext_bv )) {
1535 /* EXTERNAL DNs are already normalized */
1536 assert( !BER_BVISNULL( id ) );
1540 ber_dupbv_x( dn, id, op->o_tmpmemctx );
1543 /* convert to u:<username> form */
1549 if( is_dn == SET_NONE ) {
1550 if( !strncasecmp( id->bv_val, "u:", STRLENOF( "u:" ) ) ) {
1552 dn->bv_val = id->bv_val + STRLENOF( "u:" );
1553 dn->bv_len = id->bv_len - STRLENOF( "u:" );
1555 } else if ( !strncasecmp( id->bv_val, "dn:", STRLENOF( "dn:" ) ) ) {
1557 dn->bv_val = id->bv_val + STRLENOF( "dn:" );
1558 dn->bv_len = id->bv_len - STRLENOF( "dn:" );
1562 /* No other possibilities from here */
1563 if( is_dn == SET_NONE ) {
1565 return( LDAP_INAPPROPRIATE_AUTH );
1568 /* Username strings */
1569 if( is_dn == SET_U ) {
1570 /* ITS#3419: values may need escape */
1572 LDAPAVA *RDNs[ 4 ][ 2 ];
1577 DN[ irdn ] = RDNs[ irdn ];
1578 RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
1579 AVAs[ irdn ].la_attr = slap_schema.si_ad_uid->ad_cname;
1580 AVAs[ irdn ].la_value = *dn;
1581 AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
1582 AVAs[ irdn ].la_private = NULL;
1583 RDNs[ irdn ][ 1 ] = NULL;
1585 if ( user_realm && *user_realm ) {
1587 DN[ irdn ] = RDNs[ irdn ];
1588 RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
1589 AVAs[ irdn ].la_attr = slap_schema.si_ad_cn->ad_cname;
1590 ber_str2bv( user_realm, 0, 0, &AVAs[ irdn ].la_value );
1591 AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
1592 AVAs[ irdn ].la_private = NULL;
1593 RDNs[ irdn ][ 1 ] = NULL;
1596 if ( !BER_BVISNULL( mech ) ) {
1598 DN[ irdn ] = RDNs[ irdn ];
1599 RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
1600 AVAs[ irdn ].la_attr = slap_schema.si_ad_cn->ad_cname;
1601 AVAs[ irdn ].la_value = *mech;
1602 AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
1603 AVAs[ irdn ].la_private = NULL;
1604 RDNs[ irdn ][ 1 ] = NULL;
1608 DN[ irdn ] = RDNs[ irdn ];
1609 RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
1610 AVAs[ irdn ].la_attr = slap_schema.si_ad_cn->ad_cname;
1611 BER_BVSTR( &AVAs[ irdn ].la_value, "auth" );
1612 AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
1613 AVAs[ irdn ].la_private = NULL;
1614 RDNs[ irdn ][ 1 ] = NULL;
1619 rc = ldap_dn2bv_x( DN, dn, LDAP_DN_FORMAT_LDAPV3, op->o_tmpmemctx );
1620 if ( rc != LDAP_SUCCESS ) {
1625 Debug( LDAP_DEBUG_TRACE, "slap_sasl_getdn: u:id converted to %s\n", dn->bv_val,0,0 );
1629 /* Dup the DN in any case, so we don't risk
1630 * leaks or dangling pointers later,
1631 * and the DN value is '\0' terminated */
1632 ber_dupbv_x( &dn2, dn, op->o_tmpmemctx );
1633 dn->bv_val = dn2.bv_val;
1636 /* All strings are in DN form now. Normalize if needed. */
1638 rc = dnNormalize( 0, NULL, NULL, dn, &dn2, op->o_tmpmemctx );
1640 /* User DNs were constructed above and must be freed now */
1641 slap_sl_free( dn->bv_val, op->o_tmpmemctx );
1643 if ( rc != LDAP_SUCCESS ) {
1650 /* Run thru regexp */
1651 slap_sasl2dn( op, dn, &dn2, flags );
1652 if( !BER_BVISNULL( &dn2 ) ) {
1653 slap_sl_free( dn->bv_val, op->o_tmpmemctx );
1655 Debug( LDAP_DEBUG_TRACE, "getdn: dn:id converted to %s\n",
1659 return( LDAP_SUCCESS );