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;
372 ber_str2bv( pr[i].name, 0, 0, &mod->sml_type );
373 mod->sml_values = (struct berval *)ch_malloc( (pr[i].nvalues + 1) *
374 sizeof(struct berval));
375 for (j=0; j<pr[i].nvalues; j++) {
376 ber_str2bv( pr[i].values[j], 0, 1, &mod->sml_values[j]);
378 BER_BVZERO( &mod->sml_values[j] );
379 mod->sml_nvalues = NULL;
380 mod->sml_desc = NULL;
382 modtail = &mod->sml_next;
386 rc = slap_mods_check( modlist, &text, textbuf, textlen, NULL );
388 if ( rc == LDAP_SUCCESS ) {
389 rc = slap_mods_no_update_check( modlist, &text,
392 if ( rc == LDAP_SUCCESS ) {
393 rc = slap_mods_opattrs( &op, modlist, modtail,
394 &text, textbuf, textlen, 1 );
396 if ( rc == LDAP_SUCCESS ) {
397 op.o_hdr = conn->c_sasl_bindop->o_hdr;
398 op.o_tag = LDAP_REQ_MODIFY;
399 op.o_ndn = op.o_req_ndn;
401 op.o_time = slap_get_time();
402 op.o_do_not_cache = 1;
403 op.o_is_auth_check = 1;
404 op.o_req_dn = op.o_req_ndn;
405 op.orm_modlist = modlist;
407 rc = op.o_bd->be_modify( &op, &rs );
411 slap_mods_free( modlist );
412 return rc != LDAP_SUCCESS ? SASL_FAIL : SASL_OK;
414 #endif /* SASL_VERSION_FULL >= 2.1.16 */
416 static sasl_auxprop_plug_t slap_auxprop_plugin = {
419 NULL, /* glob_context */
420 NULL, /* auxprop_free */
423 #if SASL_VERSION_FULL >= 0x020110
424 slap_auxprop_store /* the declaration of this member changed
425 * in cyrus SASL from 2.1.15 to 2.1.16 */
433 const sasl_utils_t *utils,
436 sasl_auxprop_plug_t **plug,
437 const char *plugname)
439 if ( !out_version || !plug ) return SASL_BADPARAM;
441 if ( max_version < SASL_AUXPROP_PLUG_VERSION ) return SASL_BADVERS;
443 *out_version = SASL_AUXPROP_PLUG_VERSION;
444 *plug = &slap_auxprop_plugin;
448 /* Convert a SASL authcid or authzid into a DN. Store the DN in an
449 * auxiliary property, so that we can refer to it in sasl_authorize
450 * without interfering with anything else. Also, the SASL username
451 * buffer is constrained to 256 characters, and our DNs could be
452 * much longer (SLAP_LDAPDN_MAXLEN, currently set to 8192)
455 slap_sasl_canonicalize(
461 const char *user_realm,
466 Connection *conn = (Connection *)context;
467 struct propctx *props = sasl_auxprop_getctx( sconn );
468 struct propval auxvals[3];
471 const char *names[2];
476 Debug( LDAP_DEBUG_ARGS, "SASL Canonicalize [conn=%ld]: %s=\"%s\"\n",
477 conn ? conn->c_connid : -1,
478 (flags & SASL_CU_AUTHID) ? "authcid" : "authzid",
479 in ? in : "<empty>");
481 /* If name is too big, just truncate. We don't care, we're
482 * using DNs, not the usernames.
484 if ( inlen > out_max )
487 /* This is a Simple Bind using SPASSWD. That means the in-directory
488 * userPassword of the Binding user already points at SASL, so it
489 * cannot be used to actually satisfy a password comparison. Just
490 * ignore it, some other mech will process it.
492 if ( !conn->c_sasl_bindop ||
493 conn->c_sasl_bindop->orb_method != LDAP_AUTH_SASL ) goto done;
495 /* See if we need to add request, can only do it once */
496 prop_getnames( props, slap_propnames, auxvals );
497 if ( !auxvals[0].name )
498 prop_request( props, slap_propnames );
500 if ( flags & SASL_CU_AUTHID )
505 /* Need to store the Connection for auxprop_lookup */
506 if ( !auxvals[PROP_CONN].values ) {
507 names[0] = slap_propnames[PROP_CONN];
509 prop_set( props, names[0], (char *)&conn, sizeof( conn ) );
512 /* Already been here? */
513 if ( auxvals[which].values )
516 /* Normally we require an authzID to have a u: or dn: prefix.
517 * However, SASL frequently gives us an authzID that is just
518 * an exact copy of the authcID, without a prefix. We need to
519 * detect and allow this condition. If SASL calls canonicalize
520 * with SASL_CU_AUTHID|SASL_CU_AUTHZID this is a no-brainer.
521 * But if it's broken into two calls, we need to remember the
522 * authcID so that we can compare the authzID later. We store
523 * the authcID temporarily in conn->c_sasl_dn. We necessarily
524 * finish Canonicalizing before Authorizing, so there is no
525 * conflict with slap_sasl_authorize's use of this temp var.
527 * The SASL EXTERNAL mech is backwards from all the other mechs,
528 * it does authzID before the authcID. If we see that authzID
529 * has already been done, don't do anything special with authcID.
531 if ( flags == SASL_CU_AUTHID && !auxvals[PROP_AUTHZ].values ) {
532 conn->c_sasl_dn.bv_val = (char *) in;
533 } else if ( flags == SASL_CU_AUTHZID && conn->c_sasl_dn.bv_val ) {
534 rc = strcmp( in, conn->c_sasl_dn.bv_val );
535 conn->c_sasl_dn.bv_val = NULL;
536 /* They were equal, no work needed */
537 if ( !rc ) goto done;
540 bvin.bv_val = (char *)in;
542 rc = slap_sasl_getdn( conn, NULL, &bvin, (char *)user_realm, &dn,
543 (flags & SASL_CU_AUTHID) ? SLAP_GETDN_AUTHCID : SLAP_GETDN_AUTHZID );
544 if ( rc != LDAP_SUCCESS ) {
545 sasl_seterror( sconn, 0, ldap_err2string( rc ) );
549 names[0] = slap_propnames[which];
552 prop_set( props, names[0], (char *)&dn, sizeof( dn ) );
554 Debug( LDAP_DEBUG_ARGS, "SASL Canonicalize [conn=%ld]: %s=\"%s\"\n",
555 conn ? conn->c_connid : -1, names[0]+1,
556 dn.bv_val ? dn.bv_val : "<EMPTY>" );
559 AC_MEMCPY( out, in, inlen );
571 char *requested_user,
575 const char *def_realm,
577 struct propctx *props)
579 Connection *conn = (Connection *)context;
580 struct propval auxvals[3];
581 struct berval authcDN, authzDN=BER_BVNULL;
584 /* Simple Binds don't support proxy authorization, ignore it */
585 if ( !conn->c_sasl_bindop ||
586 conn->c_sasl_bindop->orb_method != LDAP_AUTH_SASL ) return SASL_OK;
588 Debug( LDAP_DEBUG_ARGS, "SASL proxy authorize [conn=%ld]: "
589 "authcid=\"%s\" authzid=\"%s\"\n",
590 conn ? conn->c_connid : -1, auth_identity, requested_user );
591 if ( conn->c_sasl_dn.bv_val ) {
592 ch_free( conn->c_sasl_dn.bv_val );
593 BER_BVZERO( &conn->c_sasl_dn );
597 prop_getnames( props, slap_propnames+1, auxvals );
599 /* Should not happen */
600 if ( !auxvals[0].values ) {
601 sasl_seterror( sconn, 0, "invalid authcid" );
605 AC_MEMCPY( &authcDN, auxvals[0].values[0], sizeof(authcDN) );
606 conn->c_sasl_dn = authcDN;
608 /* Nothing to do if no authzID was given */
609 if ( !auxvals[1].name || !auxvals[1].values ) {
613 AC_MEMCPY( &authzDN, auxvals[1].values[0], sizeof(authzDN) );
615 rc = slap_sasl_authorized( conn->c_sasl_bindop, &authcDN, &authzDN );
616 if ( rc != LDAP_SUCCESS ) {
617 Debug( LDAP_DEBUG_TRACE, "SASL Proxy Authorize [conn=%ld]: "
618 "proxy authorization disallowed (%d)\n",
619 (long) (conn ? conn->c_connid : -1), rc, 0 );
621 sasl_seterror( sconn, 0, "not authorized" );
622 ch_free( authzDN.bv_val );
626 conn->c_sasl_authz_dn = authzDN;
628 if (conn->c_sasl_bindop) {
629 Statslog( LDAP_DEBUG_STATS,
630 "conn=%lu op=%lu BIND authcid=\"%s\" authzid=\"%s\"\n",
631 conn->c_connid, conn->c_sasl_bindop->o_opid,
632 auth_identity, requested_user, 0);
635 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
636 " proxy authorization allowed authzDN=\"%s\"\n",
637 (long) (conn ? conn->c_connid : -1),
638 authzDN.bv_val ? authzDN.bv_val : "", 0 );
650 struct berval authcDN, authzDN;
652 Connection *conn = context;
654 struct berval bvauthcid, bvauthzid;
657 if ( conn->c_sasl_dn.bv_val ) {
658 ch_free( conn->c_sasl_dn.bv_val );
659 BER_BVZERO( &conn->c_sasl_dn );
662 Debug( LDAP_DEBUG_ARGS, "SASL Authorize [conn=%ld]: "
663 "authcid=\"%s\" authzid=\"%s\"\n",
664 (long) (conn ? conn->c_connid : -1),
665 authcid ? authcid : "<empty>",
666 authzid ? authzid : "<empty>" );
668 /* Figure out how much data we have for the dn */
669 rc = sasl_getprop( conn->c_sasl_authctx, SASL_REALM, (void **)&realm );
670 if( rc != SASL_OK && rc != SASL_NOTDONE ) {
671 Debug(LDAP_DEBUG_TRACE,
672 "authorize: getprop(REALM) failed!\n", 0,0,0);
673 *errstr = "Could not extract realm";
677 /* Convert the identities to DN's. If no authzid was given, client will
678 be bound as the DN matching their username */
679 bvauthcid.bv_val = authcid;
680 bvauthcid.bv_len = authcid ? strlen( authcid ) : 0;
681 rc = slap_sasl_getdn( conn, NULL, &bvauthcid, realm,
682 &authcDN, SLAP_GETDN_AUTHCID );
683 if( rc != LDAP_SUCCESS ) {
684 *errstr = ldap_err2string( rc );
687 conn->c_sasl_dn = authcDN;
688 if( ( authzid == NULL ) || !strcmp( authcid, authzid ) ) {
689 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
690 "Using authcDN=%s\n", (long) (conn ? conn->c_connid : -1), authcDN.bv_val,0 );
695 bvauthzid.bv_val = authzid;
696 bvauthzid.bv_len = authzid ? strlen( authzid ) : 0;
697 rc = slap_sasl_getdn( conn, NULL, &bvauthzid, realm,
698 &authzDN, SLAP_GETDN_AUTHZID );
699 if( rc != LDAP_SUCCESS ) {
700 *errstr = ldap_err2string( rc );
704 rc = slap_sasl_authorized(conn->c_sasl_bindop, &authcDN, &authzDN );
706 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
707 "proxy authorization disallowed (%d)\n",
708 (long) (conn ? conn->c_connid : -1), rc, 0 );
710 *errstr = "not authorized";
711 ch_free( authzDN.bv_val );
714 conn->c_sasl_authz_dn = authzDN;
717 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
718 " authorization allowed authzDN=\"%s\"\n",
719 (long) (conn ? conn->c_connid : -1),
720 authzDN.bv_val ? authzDN.bv_val : "", 0 );
722 if (conn->c_sasl_bindop) {
723 Statslog( LDAP_DEBUG_STATS,
724 "conn=%lu op=%lu BIND authcid=\"%s\" authzid=\"%s\"\n",
725 conn->c_connid, conn->c_sasl_bindop->o_opid,
726 authcid, authzid ? authzid : "", 0);
732 #endif /* SASL_VERSION_MAJOR >= 2 */
735 slap_sasl_err2ldap( int saslerr )
744 rc = LDAP_SASL_BIND_IN_PROGRESS;
753 rc = LDAP_AUTH_METHOD_NOT_SUPPORTED;
756 rc = LDAP_INVALID_CREDENTIALS;
759 rc = LDAP_INSUFFICIENT_ACCESS;
763 rc = LDAP_INAPPROPRIATE_AUTH;
775 static struct berval sasl_pwscheme = BER_BVC("{SASL}");
778 const struct berval *sc,
779 const struct berval * passwd,
780 const struct berval * cred,
785 void *ctx, *sconn = NULL;
787 for( i=0; i<cred->bv_len; i++) {
788 if(cred->bv_val[i] == '\0') {
789 return LUTIL_PASSWD_ERR; /* NUL character in password */
793 if( cred->bv_val[i] != '\0' ) {
794 return LUTIL_PASSWD_ERR; /* cred must behave like a string */
797 for( i=0; i<passwd->bv_len; i++) {
798 if(passwd->bv_val[i] == '\0') {
799 return LUTIL_PASSWD_ERR; /* NUL character in password */
803 if( passwd->bv_val[i] != '\0' ) {
804 return LUTIL_PASSWD_ERR; /* passwd must behave like a string */
807 rtn = LUTIL_PASSWD_ERR;
809 ctx = ldap_pvt_thread_pool_context();
810 ldap_pvt_thread_pool_getkey( ctx, slap_sasl_bind, &sconn, NULL );
812 if( sconn != NULL ) {
814 # if SASL_VERSION_MAJOR < 2
815 sc = sasl_checkpass( sconn,
816 passwd->bv_val, passwd->bv_len,
817 cred->bv_val, cred->bv_len,
820 sc = sasl_checkpass( sconn,
821 passwd->bv_val, passwd->bv_len,
822 cred->bv_val, cred->bv_len );
824 rtn = ( sc != SASL_OK ) ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
829 #endif /* SLAPD_SPASSWD */
831 #endif /* HAVE_CYRUS_SASL */
833 int slap_sasl_init( void )
835 #ifdef HAVE_CYRUS_SASL
837 static sasl_callback_t server_callbacks[] = {
838 { SASL_CB_LOG, &slap_sasl_log, NULL },
839 { SASL_CB_LIST_END, NULL, NULL }
842 #ifdef HAVE_SASL_VERSION
843 /* stringify the version number, sasl.h doesn't do it for us */
844 #define VSTR0(maj, min, pat) #maj "." #min "." #pat
845 #define VSTR(maj, min, pat) VSTR0(maj, min, pat)
846 #define SASL_VERSION_STRING VSTR(SASL_VERSION_MAJOR, SASL_VERSION_MINOR, \
849 sasl_version( NULL, &rc );
850 if ( ((rc >> 16) != ((SASL_VERSION_MAJOR << 8)|SASL_VERSION_MINOR)) ||
851 (rc & 0xffff) < SASL_VERSION_STEP)
853 char version[sizeof("xxx.xxx.xxxxx")];
854 sprintf( version, "%u.%d.%d", (unsigned)rc >> 24, (rc >> 16) & 0xff,
856 Debug( LDAP_DEBUG_ANY, "slap_sasl_init: SASL library version mismatch:"
857 " expected " SASL_VERSION_STRING ","
858 " got %s\n", version, 0, 0 );
863 /* SASL 2 does its own memory management internally */
864 #if SASL_VERSION_MAJOR < 2
873 ldap_pvt_sasl_mutex_new,
874 ldap_pvt_sasl_mutex_lock,
875 ldap_pvt_sasl_mutex_unlock,
876 ldap_pvt_sasl_mutex_dispose );
878 #if SASL_VERSION_MAJOR >= 2
879 generic_filter.f_desc = slap_schema.si_ad_objectClass;
881 rc = sasl_auxprop_add_plugin( "slapd", slap_auxprop_init );
882 if( rc != SASL_OK ) {
883 Debug( LDAP_DEBUG_ANY, "slap_sasl_init: auxprop add plugin failed\n",
888 /* should provide callbacks for logging */
889 /* server name should be configurable */
890 rc = sasl_server_init( server_callbacks, "slapd" );
892 if( rc != SASL_OK ) {
893 Debug( LDAP_DEBUG_ANY, "slap_sasl_init: server init failed\n",
895 #if SASL_VERSION_MAJOR < 2
896 /* A no-op used to make sure we linked with Cyrus 1.5 */
897 sasl_client_auth( NULL, NULL, NULL, 0, NULL, NULL );
904 lutil_passwd_add( &sasl_pwscheme, chk_sasl, NULL );
907 Debug( LDAP_DEBUG_TRACE, "slap_sasl_init: initialized!\n",
910 /* default security properties */
911 memset( &sasl_secprops, '\0', sizeof(sasl_secprops) );
912 sasl_secprops.max_ssf = INT_MAX;
913 sasl_secprops.maxbufsize = 65536;
914 sasl_secprops.security_flags = SASL_SEC_NOPLAINTEXT|SASL_SEC_NOANONYMOUS;
920 int slap_sasl_destroy( void )
922 #ifdef HAVE_CYRUS_SASL
931 int slap_sasl_open( Connection *conn, int reopen )
933 int sc = LDAP_SUCCESS;
934 #ifdef HAVE_CYRUS_SASL
937 sasl_conn_t *ctx = NULL;
938 sasl_callback_t *session_callbacks;
940 #if SASL_VERSION_MAJOR >= 2
941 char *ipremoteport = NULL, *iplocalport = NULL;
944 assert( conn->c_sasl_authctx == NULL );
947 assert( conn->c_sasl_extra == NULL );
950 #if SASL_VERSION_MAJOR >= 2
951 SLAP_CALLOC( 5, sizeof(sasl_callback_t));
953 SLAP_CALLOC( 3, sizeof(sasl_callback_t));
955 if( session_callbacks == NULL ) {
956 Debug( LDAP_DEBUG_ANY,
957 "slap_sasl_open: SLAP_MALLOC failed", 0, 0, 0 );
960 conn->c_sasl_extra = session_callbacks;
962 session_callbacks[cb=0].id = SASL_CB_LOG;
963 session_callbacks[cb].proc = &slap_sasl_log;
964 session_callbacks[cb++].context = conn;
966 session_callbacks[cb].id = SASL_CB_PROXY_POLICY;
967 session_callbacks[cb].proc = &slap_sasl_authorize;
968 session_callbacks[cb++].context = conn;
970 #if SASL_VERSION_MAJOR >= 2
971 session_callbacks[cb].id = SASL_CB_CANON_USER;
972 session_callbacks[cb].proc = &slap_sasl_canonicalize;
973 session_callbacks[cb++].context = conn;
976 session_callbacks[cb].id = SASL_CB_LIST_END;
977 session_callbacks[cb].proc = NULL;
978 session_callbacks[cb++].context = NULL;
980 session_callbacks = conn->c_sasl_extra;
983 conn->c_sasl_layers = 0;
985 if( global_host == NULL ) {
986 global_host = ldap_pvt_get_fqdn( NULL );
989 /* create new SASL context */
990 #if SASL_VERSION_MAJOR >= 2
991 if ( conn->c_sock_name.bv_len != 0 &&
992 strncmp( conn->c_sock_name.bv_val, "IP=", 3 ) == 0) {
995 iplocalport = ch_strdup( conn->c_sock_name.bv_val + 3 );
996 /* Convert IPv6 addresses to address;port syntax. */
997 p = strrchr( iplocalport, ' ' );
998 /* Convert IPv4 addresses to address;port syntax. */
999 if ( p == NULL ) p = strchr( iplocalport, ':' );
1004 if ( conn->c_peer_name.bv_len != 0 &&
1005 strncmp( conn->c_peer_name.bv_val, "IP=", 3 ) == 0) {
1008 ipremoteport = ch_strdup( conn->c_peer_name.bv_val + 3 );
1009 /* Convert IPv6 addresses to address;port syntax. */
1010 p = strrchr( ipremoteport, ' ' );
1011 /* Convert IPv4 addresses to address;port syntax. */
1012 if ( p == NULL ) p = strchr( ipremoteport, ':' );
1017 sc = sasl_server_new( "ldap", global_host, global_realm,
1018 iplocalport, ipremoteport, session_callbacks, SASL_SUCCESS_DATA, &ctx );
1019 if ( iplocalport != NULL ) {
1020 ch_free( iplocalport );
1022 if ( ipremoteport != NULL ) {
1023 ch_free( ipremoteport );
1026 sc = sasl_server_new( "ldap", global_host, global_realm,
1027 session_callbacks, SASL_SECURITY_LAYER, &ctx );
1030 if( sc != SASL_OK ) {
1031 Debug( LDAP_DEBUG_ANY, "sasl_server_new failed: %d\n",
1037 conn->c_sasl_authctx = ctx;
1039 if( sc == SASL_OK ) {
1040 sc = sasl_setprop( ctx,
1041 SASL_SEC_PROPS, &sasl_secprops );
1043 if( sc != SASL_OK ) {
1044 Debug( LDAP_DEBUG_ANY, "sasl_setprop failed: %d\n",
1047 slap_sasl_close( conn );
1052 sc = slap_sasl_err2ldap( sc );
1054 #elif defined(SLAP_BUILTIN_SASL)
1055 /* built-in SASL implementation */
1056 SASL_CTX *ctx = (SASL_CTX *) SLAP_MALLOC(sizeof(SASL_CTX));
1057 if( ctx == NULL ) return -1;
1059 ctx->sc_external_ssf = 0;
1060 BER_BVZERO( &ctx->sc_external_id );
1062 conn->c_sasl_authctx = ctx;
1068 int slap_sasl_external(
1071 struct berval *auth_id )
1073 #if SASL_VERSION_MAJOR >= 2
1075 sasl_conn_t *ctx = conn->c_sasl_authctx;
1077 if ( ctx == NULL ) {
1078 return LDAP_UNAVAILABLE;
1081 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
1083 if ( sc != SASL_OK ) {
1087 sc = sasl_setprop( ctx, SASL_AUTH_EXTERNAL,
1088 auth_id ? auth_id->bv_val : NULL );
1090 if ( sc != SASL_OK ) {
1094 #elif defined(HAVE_CYRUS_SASL)
1096 sasl_conn_t *ctx = conn->c_sasl_authctx;
1097 sasl_external_properties_t extprops;
1099 if ( ctx == NULL ) {
1100 return LDAP_UNAVAILABLE;
1103 memset( &extprops, '\0', sizeof(extprops) );
1105 extprops.auth_id = auth_id ? auth_id->bv_val : NULL;
1107 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
1108 (void *) &extprops );
1110 if ( sc != SASL_OK ) {
1113 #elif defined(SLAP_BUILTIN_SASL)
1114 /* built-in SASL implementation */
1115 SASL_CTX *ctx = conn->c_sasl_authctx;
1116 if ( ctx == NULL ) return LDAP_UNAVAILABLE;
1118 ctx->sc_external_ssf = ssf;
1120 ctx->sc_external_id = *auth_id;
1121 BER_BVZERO( auth_id );
1123 BER_BVZERO( &ctx->sc_external_id );
1127 return LDAP_SUCCESS;
1130 int slap_sasl_reset( Connection *conn )
1132 return LDAP_SUCCESS;
1135 char ** slap_sasl_mechs( Connection *conn )
1137 char **mechs = NULL;
1139 #ifdef HAVE_CYRUS_SASL
1140 sasl_conn_t *ctx = conn->c_sasl_authctx;
1142 if( ctx == NULL ) ctx = conn->c_sasl_sockctx;
1146 SASL_CONST char *mechstr;
1148 sc = sasl_listmech( ctx,
1149 NULL, NULL, ",", NULL,
1150 &mechstr, NULL, NULL );
1152 if( sc != SASL_OK ) {
1153 Debug( LDAP_DEBUG_ANY, "slap_sasl_listmech failed: %d\n",
1159 mechs = ldap_str2charray( mechstr, "," );
1161 #if SASL_VERSION_MAJOR < 2
1165 #elif defined(SLAP_BUILTIN_SASL)
1166 /* builtin SASL implementation */
1167 SASL_CTX *ctx = conn->c_sasl_authctx;
1168 if ( ctx != NULL && ctx->sc_external_id.bv_val ) {
1169 /* should check ssf */
1170 mechs = ldap_str2charray( "EXTERNAL", "," );
1177 int slap_sasl_close( Connection *conn )
1179 #ifdef HAVE_CYRUS_SASL
1180 sasl_conn_t *ctx = conn->c_sasl_authctx;
1183 sasl_dispose( &ctx );
1185 if ( conn->c_sasl_sockctx &&
1186 conn->c_sasl_authctx != conn->c_sasl_sockctx )
1188 ctx = conn->c_sasl_sockctx;
1189 sasl_dispose( &ctx );
1192 conn->c_sasl_authctx = NULL;
1193 conn->c_sasl_sockctx = NULL;
1194 conn->c_sasl_done = 0;
1196 free( conn->c_sasl_extra );
1197 conn->c_sasl_extra = NULL;
1199 #elif defined(SLAP_BUILTIN_SASL)
1200 SASL_CTX *ctx = conn->c_sasl_authctx;
1202 if( ctx->sc_external_id.bv_val ) {
1203 free( ctx->sc_external_id.bv_val );
1204 BER_BVZERO( &ctx->sc_external_id );
1207 conn->c_sasl_authctx = NULL;
1211 return LDAP_SUCCESS;
1214 int slap_sasl_bind( Operation *op, SlapReply *rs )
1216 #ifdef HAVE_CYRUS_SASL
1217 sasl_conn_t *ctx = op->o_conn->c_sasl_authctx;
1218 struct berval response;
1219 unsigned reslen = 0;
1222 Debug(LDAP_DEBUG_ARGS,
1223 "==> sasl_bind: dn=\"%s\" mech=%s datalen=%ld\n",
1224 op->o_req_dn.bv_len ? op->o_req_dn.bv_val : "",
1225 op->o_conn->c_sasl_bind_in_progress ? "<continuing>" :
1226 op->o_conn->c_sasl_bind_mech.bv_val,
1227 op->orb_cred.bv_len );
1230 send_ldap_error( op, rs, LDAP_UNAVAILABLE,
1231 "SASL unavailable on this session" );
1235 #if SASL_VERSION_MAJOR >= 2
1236 #define START( ctx, mech, cred, clen, resp, rlen, err ) \
1237 sasl_server_start( ctx, mech, cred, clen, resp, rlen )
1238 #define STEP( ctx, cred, clen, resp, rlen, err ) \
1239 sasl_server_step( ctx, cred, clen, resp, rlen )
1241 #define START( ctx, mech, cred, clen, resp, rlen, err ) \
1242 sasl_server_start( ctx, mech, cred, clen, resp, rlen, err )
1243 #define STEP( ctx, cred, clen, resp, rlen, err ) \
1244 sasl_server_step( ctx, cred, clen, resp, rlen, err )
1247 if ( !op->o_conn->c_sasl_bind_in_progress ) {
1248 /* If we already authenticated once, must use a new context */
1249 if ( op->o_conn->c_sasl_done ) {
1251 const char *authid = NULL;
1252 #if SASL_VERSION_MAJOR >= 2
1253 sasl_getprop( ctx, SASL_SSF_EXTERNAL, (void *)&ssf );
1254 sasl_getprop( ctx, SASL_AUTH_EXTERNAL, (void *)&authid );
1255 if ( authid ) authid = ch_strdup( authid );
1257 if ( ctx != op->o_conn->c_sasl_sockctx ) {
1258 sasl_dispose( &ctx );
1260 op->o_conn->c_sasl_authctx = NULL;
1262 slap_sasl_open( op->o_conn, 1 );
1263 ctx = op->o_conn->c_sasl_authctx;
1264 #if SASL_VERSION_MAJOR >= 2
1266 sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
1267 sasl_setprop( ctx, SASL_AUTH_EXTERNAL, authid );
1268 ch_free( (char *)authid );
1273 op->o_conn->c_sasl_bind_mech.bv_val,
1274 op->orb_cred.bv_val, op->orb_cred.bv_len,
1275 (SASL_CONST char **)&response.bv_val, &reslen, &rs->sr_text );
1279 op->orb_cred.bv_val, op->orb_cred.bv_len,
1280 (SASL_CONST char **)&response.bv_val, &reslen, &rs->sr_text );
1283 response.bv_len = reslen;
1285 if ( sc == SASL_OK ) {
1286 sasl_ssf_t *ssf = NULL;
1288 op->orb_edn = op->o_conn->c_sasl_dn;
1289 BER_BVZERO( &op->o_conn->c_sasl_dn );
1290 op->o_conn->c_sasl_done = 1;
1292 rs->sr_err = LDAP_SUCCESS;
1294 (void) sasl_getprop( ctx, SASL_SSF, (void *)&ssf );
1295 op->orb_ssf = ssf ? *ssf : 0;
1299 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1300 op->o_conn->c_sasl_layers++;
1302 /* If there's an old layer, set sockctx to NULL to
1303 * tell connection_read() to wait for us to finish.
1304 * Otherwise there is a race condition: we have to
1305 * send the Bind response using the old security
1306 * context and then remove it before reading any
1309 if ( op->o_conn->c_sasl_sockctx ) {
1310 ctx = op->o_conn->c_sasl_sockctx;
1311 op->o_conn->c_sasl_sockctx = NULL;
1313 op->o_conn->c_sasl_sockctx = op->o_conn->c_sasl_authctx;
1315 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1318 /* Must send response using old security layer */
1319 if (response.bv_len) rs->sr_sasldata = &response;
1320 send_ldap_sasl( op, rs );
1322 /* Now dispose of the old security layer.
1325 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1326 ldap_pvt_sasl_remove( op->o_conn->c_sb );
1327 op->o_conn->c_sasl_sockctx = op->o_conn->c_sasl_authctx;
1328 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1329 sasl_dispose( &ctx );
1331 } else if ( sc == SASL_CONTINUE ) {
1332 rs->sr_err = LDAP_SASL_BIND_IN_PROGRESS,
1333 rs->sr_sasldata = &response;
1334 send_ldap_sasl( op, rs );
1337 #if SASL_VERSION_MAJOR >= 2
1338 rs->sr_text = sasl_errdetail( ctx );
1340 rs->sr_err = slap_sasl_err2ldap( sc ),
1341 send_ldap_result( op, rs );
1344 #if SASL_VERSION_MAJOR < 2
1345 if( response.bv_len ) {
1346 ch_free( response.bv_val );
1350 Debug(LDAP_DEBUG_TRACE, "<== slap_sasl_bind: rc=%d\n", rs->sr_err, 0, 0);
1352 #elif defined(SLAP_BUILTIN_SASL)
1353 /* built-in SASL implementation */
1354 SASL_CTX *ctx = op->o_conn->c_sasl_authctx;
1356 if ( ctx == NULL ) {
1357 send_ldap_error( op, rs, LDAP_OTHER,
1358 "Internal SASL Error" );
1360 } else if ( bvmatch( &ext_bv, &op->o_conn->c_sasl_bind_mech ) ) {
1363 if( op->orb_cred.bv_len ) {
1364 rs->sr_text = "proxy authorization not support";
1365 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1366 send_ldap_result( op, rs );
1369 op->orb_edn = ctx->sc_external_id;
1370 rs->sr_err = LDAP_SUCCESS;
1371 rs->sr_sasldata = NULL;
1372 send_ldap_sasl( op, rs );
1376 send_ldap_error( op, rs, LDAP_AUTH_METHOD_NOT_SUPPORTED,
1377 "requested SASL mechanism not supported" );
1380 send_ldap_error( op, rs, LDAP_AUTH_METHOD_NOT_SUPPORTED,
1381 "SASL not supported" );
1387 char* slap_sasl_secprops( const char *in )
1389 #ifdef HAVE_CYRUS_SASL
1390 int rc = ldap_pvt_sasl_secprops( in, &sasl_secprops );
1392 return rc == LDAP_SUCCESS ? NULL : "Invalid security properties";
1394 return "SASL not supported";
1398 void slap_sasl_secprops_unparse( struct berval *bv )
1400 #ifdef HAVE_CYRUS_SASL
1401 ldap_pvt_sasl_secprops_unparse( &sasl_secprops, bv );
1405 #ifdef HAVE_CYRUS_SASL
1407 slap_sasl_setpass( Operation *op, SlapReply *rs )
1409 struct berval id = BER_BVNULL; /* needs to come from connection */
1410 struct berval new = BER_BVNULL;
1411 struct berval old = BER_BVNULL;
1413 assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->ore_reqoid ) == 0 );
1415 rs->sr_err = sasl_getprop( op->o_conn->c_sasl_authctx, SASL_USERNAME,
1416 (SASL_CONST void **)&id.bv_val );
1418 if( rs->sr_err != SASL_OK ) {
1419 rs->sr_text = "unable to retrieve SASL username";
1420 rs->sr_err = LDAP_OTHER;
1424 Debug( LDAP_DEBUG_ARGS, "==> slap_sasl_setpass: \"%s\"\n",
1425 id.bv_val ? id.bv_val : "", 0, 0 );
1427 rs->sr_err = slap_passwd_parse( op->ore_reqdata,
1428 NULL, &old, &new, &rs->sr_text );
1430 if( rs->sr_err != LDAP_SUCCESS ) {
1434 if( new.bv_len == 0 ) {
1435 slap_passwd_generate(&new);
1437 if( new.bv_len == 0 ) {
1438 rs->sr_text = "password generation failed.";
1439 rs->sr_err = LDAP_OTHER;
1443 rs->sr_rspdata = slap_passwd_return( &new );
1446 #if SASL_VERSION_MAJOR < 2
1447 rs->sr_err = sasl_setpass( op->o_conn->c_sasl_authctx,
1448 id.bv_val, new.bv_val, new.bv_len, 0, &rs->sr_text );
1450 rs->sr_err = sasl_setpass( op->o_conn->c_sasl_authctx, id.bv_val,
1451 new.bv_val, new.bv_len, old.bv_val, old.bv_len, 0 );
1452 if( rs->sr_err != SASL_OK ) {
1453 rs->sr_text = sasl_errdetail( op->o_conn->c_sasl_authctx );
1456 switch(rs->sr_err) {
1458 rs->sr_err = LDAP_SUCCESS;
1468 rs->sr_err = LDAP_OTHER;
1474 #endif /* HAVE_CYRUS_SASL */
1476 /* Take any sort of identity string and return a DN with the "dn:" prefix. The
1477 * string returned in *dn is in its own allocated memory, and must be free'd
1478 * by the calling process. -Mark Adamson, Carnegie Mellon
1480 * The "dn:" prefix is no longer used anywhere inside slapd. It is only used
1481 * on strings passed in directly from SASL. -Howard Chu, Symas Corp.
1488 int slap_sasl_getdn( Connection *conn, Operation *op, struct berval *id,
1489 char *user_realm, struct berval *dn, int flags )
1491 int rc, is_dn = SET_NONE, do_norm = 1;
1492 struct berval dn2, *mech;
1497 Debug( LDAP_DEBUG_ARGS, "slap_sasl_getdn: conn %d id=%s [len=%d]\n",
1499 BER_BVISNULL( id ) ? "NULL" : ( BER_BVISEMPTY( id ) ? "<empty>" : id->bv_val ),
1500 BER_BVISNULL( id ) ? 0 : ( BER_BVISEMPTY( id ) ? 0 : id->bv_len ) );
1503 op = conn->c_sasl_bindop;
1508 if ( !BER_BVISNULL( id ) ) {
1509 /* Blatantly anonymous ID */
1510 static struct berval bv_anonymous = BER_BVC( "anonymous" );
1512 if ( ber_bvstrcasecmp( id, &bv_anonymous ) == 0 ) {
1513 return( LDAP_SUCCESS );
1517 /* FIXME: if empty, should we stop? */
1518 BER_BVSTR( id, "" );
1521 if ( !BER_BVISEMPTY( &conn->c_sasl_bind_mech ) ) {
1522 mech = &conn->c_sasl_bind_mech;
1524 mech = &conn->c_authmech;
1527 /* An authcID needs to be converted to authzID form. Set the
1528 * values directly into *dn; they will be normalized later. (and
1529 * normalizing always makes a new copy.) An ID from a TLS certificate
1530 * is already normalized, so copy it and skip normalization.
1532 if( flags & SLAP_GETDN_AUTHCID ) {
1533 if( bvmatch( mech, &ext_bv )) {
1534 /* EXTERNAL DNs are already normalized */
1535 assert( !BER_BVISNULL( id ) );
1539 ber_dupbv_x( dn, id, op->o_tmpmemctx );
1542 /* convert to u:<username> form */
1548 if( is_dn == SET_NONE ) {
1549 if( !strncasecmp( id->bv_val, "u:", STRLENOF( "u:" ) ) ) {
1551 dn->bv_val = id->bv_val + STRLENOF( "u:" );
1552 dn->bv_len = id->bv_len - STRLENOF( "u:" );
1554 } else if ( !strncasecmp( id->bv_val, "dn:", STRLENOF( "dn:" ) ) ) {
1556 dn->bv_val = id->bv_val + STRLENOF( "dn:" );
1557 dn->bv_len = id->bv_len - STRLENOF( "dn:" );
1561 /* No other possibilities from here */
1562 if( is_dn == SET_NONE ) {
1564 return( LDAP_INAPPROPRIATE_AUTH );
1567 /* Username strings */
1568 if( is_dn == SET_U ) {
1569 /* ITS#3419: values may need escape */
1571 LDAPAVA *RDNs[ 4 ][ 2 ];
1576 DN[ irdn ] = RDNs[ irdn ];
1577 RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
1578 AVAs[ irdn ].la_attr = slap_schema.si_ad_uid->ad_cname;
1579 AVAs[ irdn ].la_value = *dn;
1580 AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
1581 AVAs[ irdn ].la_private = NULL;
1582 RDNs[ irdn ][ 1 ] = NULL;
1584 if ( user_realm && *user_realm ) {
1586 DN[ irdn ] = RDNs[ irdn ];
1587 RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
1588 AVAs[ irdn ].la_attr = slap_schema.si_ad_cn->ad_cname;
1589 ber_str2bv( user_realm, 0, 0, &AVAs[ irdn ].la_value );
1590 AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
1591 AVAs[ irdn ].la_private = NULL;
1592 RDNs[ irdn ][ 1 ] = NULL;
1595 if ( !BER_BVISNULL( mech ) ) {
1597 DN[ irdn ] = RDNs[ irdn ];
1598 RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
1599 AVAs[ irdn ].la_attr = slap_schema.si_ad_cn->ad_cname;
1600 AVAs[ irdn ].la_value = *mech;
1601 AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
1602 AVAs[ irdn ].la_private = NULL;
1603 RDNs[ irdn ][ 1 ] = NULL;
1607 DN[ irdn ] = RDNs[ irdn ];
1608 RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
1609 AVAs[ irdn ].la_attr = slap_schema.si_ad_cn->ad_cname;
1610 BER_BVSTR( &AVAs[ irdn ].la_value, "auth" );
1611 AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
1612 AVAs[ irdn ].la_private = NULL;
1613 RDNs[ irdn ][ 1 ] = NULL;
1618 rc = ldap_dn2bv_x( DN, dn, LDAP_DN_FORMAT_LDAPV3, op->o_tmpmemctx );
1619 if ( rc != LDAP_SUCCESS ) {
1624 Debug( LDAP_DEBUG_TRACE, "slap_sasl_getdn: u:id converted to %s\n", dn->bv_val,0,0 );
1628 /* Dup the DN in any case, so we don't risk
1629 * leaks or dangling pointers later,
1630 * and the DN value is '\0' terminated */
1631 ber_dupbv_x( &dn2, dn, op->o_tmpmemctx );
1632 dn->bv_val = dn2.bv_val;
1635 /* All strings are in DN form now. Normalize if needed. */
1637 rc = dnNormalize( 0, NULL, NULL, dn, &dn2, op->o_tmpmemctx );
1639 /* User DNs were constructed above and must be freed now */
1640 slap_sl_free( dn->bv_val, op->o_tmpmemctx );
1642 if ( rc != LDAP_SUCCESS ) {
1649 /* Run thru regexp */
1650 slap_sasl2dn( op, dn, &dn2, flags );
1651 if( !BER_BVISNULL( &dn2 ) ) {
1652 slap_sl_free( dn->bv_val, op->o_tmpmemctx );
1654 Debug( LDAP_DEBUG_TRACE, "getdn: dn:id converted to %s\n",
1658 return( LDAP_SUCCESS );