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>.
19 #include <ac/stdlib.h>
20 #include <ac/string.h>
29 #ifdef HAVE_CYRUS_SASL
30 # ifdef HAVE_SASL_SASL_H
31 # include <sasl/sasl.h>
36 # if SASL_VERSION_MAJOR >= 2
37 # ifdef HAVE_SASL_SASL_H
38 # include <sasl/saslplug.h>
40 # include <saslplug.h>
42 # define SASL_CONST const
47 #define SASL_VERSION_FULL ((SASL_VERSION_MAJOR << 16) |\
48 (SASL_VERSION_MINOR << 8) | SASL_VERSION_STEP)
50 static sasl_security_properties_t sasl_secprops;
51 #elif defined( SLAP_BUILTIN_SASL )
53 * built-in SASL implementation
54 * only supports EXTERNAL
56 typedef struct sasl_ctx {
57 slap_ssf_t sc_external_ssf;
58 struct berval sc_external_id;
65 static struct berval ext_bv = BER_BVC( "EXTERNAL" );
67 #ifdef HAVE_CYRUS_SASL
75 Connection *conn = context;
79 if ( message == NULL ) {
84 #if SASL_VERSION_MAJOR >= 2
86 level = LDAP_DEBUG_NONE;
90 level = LDAP_DEBUG_ANY;
94 level = LDAP_DEBUG_ANY;
98 level = LDAP_DEBUG_TRACE;
102 level = LDAP_DEBUG_TRACE;
106 level = LDAP_DEBUG_TRACE;
110 level = LDAP_DEBUG_TRACE;
114 level = LDAP_DEBUG_TRACE;
115 label = "Password Trace";
119 level = LDAP_DEBUG_ANY;
122 case SASL_LOG_WARNING:
123 level = LDAP_DEBUG_TRACE;
127 level = LDAP_DEBUG_TRACE;
132 return SASL_BADPARAM;
135 Debug( level, "SASL [conn=%ld] %s: %s\n",
136 conn ? conn->c_connid: -1,
144 #if SASL_VERSION_MAJOR >= 2
145 static const char *slap_propnames[] = {
146 "*slapConn", "*slapAuthcDN", "*slapAuthzDN", NULL };
148 static Filter generic_filter = { LDAP_FILTER_PRESENT };
149 static struct berval generic_filterstr = BER_BVC("(objectclass=*)");
154 #define PROP_COUNT 3 /* Number of properties we used */
156 typedef struct lookup_info {
158 const struct propval *list;
159 sasl_server_params_t *sparams;
162 static slap_response sasl_ap_lookup;
165 sasl_ap_lookup( Operation *op, SlapReply *rs )
168 AttributeDescription *ad;
172 slap_callback *tmp = op->o_callback;
173 lookup_info *sl = tmp->sc_private;
175 if (rs->sr_type != REP_SEARCH) return 0;
177 for( i = 0; sl->list[i].name; i++ ) {
178 const char *name = sl->list[i].name;
180 if ( name[0] == '*' ) {
181 if ( sl->flags & SASL_AUXPROP_AUTHZID ) continue;
182 /* Skip our private properties */
183 if ( !strcmp( name, slap_propnames[0] )) {
188 } else if ( !(sl->flags & SASL_AUXPROP_AUTHZID ) )
191 if ( sl->list[i].values ) {
192 if ( !(sl->flags & SASL_AUXPROP_OVERRIDE) ) continue;
195 rc = slap_str2ad( name, &ad, &text );
196 if ( rc != LDAP_SUCCESS ) {
197 Debug( LDAP_DEBUG_TRACE,
198 "slap_ap_lookup: str2ad(%s): %s\n", name, text, 0 );
201 a = attr_find( rs->sr_entry->e_attrs, ad );
203 if ( ! access_allowed( op, rs->sr_entry, ad, NULL, ACL_AUTH, NULL ) ) {
206 if ( sl->list[i].values && ( sl->flags & SASL_AUXPROP_OVERRIDE ) ) {
207 sl->sparams->utils->prop_erase( sl->sparams->propctx,
210 for ( bv = a->a_vals; bv->bv_val; bv++ ) {
211 sl->sparams->utils->prop_set( sl->sparams->propctx,
212 sl->list[i].name, bv->bv_val, bv->bv_len );
221 sasl_server_params_t *sparams,
228 Connection *conn = NULL;
231 sl.list = sparams->utils->prop_get( sparams->propctx );
232 sl.sparams = sparams;
235 /* Find our DN and conn first */
236 for( i = 0; sl.list[i].name; i++ ) {
237 if ( sl.list[i].name[0] == '*' ) {
238 if ( !strcmp( sl.list[i].name, slap_propnames[PROP_CONN] ) ) {
239 if ( sl.list[i].values && sl.list[i].values[0] )
240 AC_MEMCPY( &conn, sl.list[i].values[0], sizeof( conn ) );
243 if ( (flags & SASL_AUXPROP_AUTHZID) &&
244 !strcmp( sl.list[i].name, slap_propnames[PROP_AUTHZ] ) ) {
246 if ( sl.list[i].values && sl.list[i].values[0] )
247 AC_MEMCPY( &op.o_req_ndn, sl.list[i].values[0], sizeof( struct berval ) );
250 if ( !strcmp( sl.list[i].name, slap_propnames[PROP_AUTHC] ) ) {
251 if ( sl.list[i].values && sl.list[i].values[0] ) {
252 AC_MEMCPY( &op.o_req_ndn, sl.list[i].values[0], sizeof( struct berval ) );
253 if ( !(flags & SASL_AUXPROP_AUTHZID) )
260 /* Now see what else needs to be fetched */
261 for( i = 0; sl.list[i].name; i++ ) {
262 const char *name = sl.list[i].name;
264 if ( name[0] == '*' ) {
265 if ( flags & SASL_AUXPROP_AUTHZID ) continue;
266 /* Skip our private properties */
267 if ( !strcmp( name, slap_propnames[0] )) {
272 } else if ( !(flags & SASL_AUXPROP_AUTHZID ) )
275 if ( sl.list[i].values ) {
276 if ( !(flags & SASL_AUXPROP_OVERRIDE) ) continue;
283 slap_callback cb = { NULL, sasl_ap_lookup, NULL, NULL };
287 op.o_bd = select_backend( &op.o_req_ndn, 0, 1 );
289 if ( op.o_bd && op.o_bd->be_search ) {
290 SlapReply rs = {REP_RESULT};
291 op.o_hdr = conn->c_sasl_bindop->o_hdr;
292 op.o_tag = LDAP_REQ_SEARCH;
293 op.o_ndn = conn->c_ndn;
295 op.o_time = slap_get_time();
296 op.o_do_not_cache = 1;
297 op.o_is_auth_check = 1;
298 op.o_req_dn = op.o_req_ndn;
299 op.ors_scope = LDAP_SCOPE_BASE;
300 op.ors_deref = LDAP_DEREF_NEVER;
301 op.ors_tlimit = SLAP_NO_LIMIT;
303 op.ors_filter = &generic_filter;
304 op.ors_filterstr = generic_filterstr;
305 /* FIXME: we want all attributes, right? */
308 op.o_bd->be_search( &op, &rs );
313 #if SASL_VERSION_FULL >= 0x020110
317 sasl_server_params_t *sparams,
318 struct propctx *prctx,
323 SlapReply rs = {REP_RESULT};
325 Connection *conn = NULL;
326 const struct propval *pr;
327 Modifications *modlist = NULL, **modtail = &modlist, *mod;
328 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
329 char textbuf[SLAP_TEXT_BUFLEN];
331 size_t textlen = sizeof(textbuf);
333 /* just checking if we are enabled */
334 if (!prctx) return SASL_OK;
336 if (!sparams || !user) return SASL_BADPARAM;
338 pr = sparams->utils->prop_get( sparams->propctx );
340 /* Find our DN and conn first */
341 for( i = 0; pr[i].name; i++ ) {
342 if ( pr[i].name[0] == '*' ) {
343 if ( !strcmp( pr[i].name, slap_propnames[PROP_CONN] ) ) {
344 if ( pr[i].values && pr[i].values[0] )
345 AC_MEMCPY( &conn, pr[i].values[0], sizeof( conn ) );
348 if ( !strcmp( pr[i].name, slap_propnames[PROP_AUTHC] ) ) {
349 if ( pr[i].values && pr[i].values[0] ) {
350 AC_MEMCPY( &op.o_req_ndn, pr[i].values[0], sizeof( struct berval ) );
355 if (!conn || !op.o_req_ndn.bv_val) return SASL_BADPARAM;
357 op.o_bd = select_backend( &op.o_req_ndn, 0, 1 );
359 if ( !op.o_bd || !op.o_bd->be_modify ) return SASL_FAIL;
361 pr = sparams->utils->prop_get( prctx );
362 if (!pr) return SASL_BADPARAM;
364 for (i=0; pr[i].name; i++);
365 if (!i) return SASL_BADPARAM;
367 for (i=0; pr[i].name; i++) {
368 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
369 mod->sml_op = LDAP_MOD_REPLACE;
370 ber_str2bv( pr[i].name, 0, 0, &mod->sml_type );
371 mod->sml_values = (struct berval *)ch_malloc( (pr[i].nvalues + 1) *
372 sizeof(struct berval));
373 for (j=0; j<pr[i].nvalues; j++) {
374 ber_str2bv( pr[i].values[j], 0, 1, &mod->sml_values[j]);
376 BER_BVZERO( &mod->sml_values[j] );
377 mod->sml_nvalues = NULL;
378 mod->sml_desc = NULL;
380 modtail = &mod->sml_next;
384 rc = slap_mods_check( modlist, &text, textbuf, textlen, NULL );
386 if ( rc == LDAP_SUCCESS ) {
387 rc = slap_mods_no_update_check( modlist, &text,
390 if ( rc == LDAP_SUCCESS ) {
391 rc = slap_mods_opattrs( &op, modlist, modtail,
392 &text, textbuf, textlen, 1 );
394 if ( rc == LDAP_SUCCESS ) {
395 op.o_hdr = conn->c_sasl_bindop->o_hdr;
396 op.o_tag = LDAP_REQ_MODIFY;
397 op.o_ndn = op.o_req_ndn;
399 op.o_time = slap_get_time();
400 op.o_do_not_cache = 1;
401 op.o_is_auth_check = 1;
402 op.o_req_dn = op.o_req_ndn;
403 op.orm_modlist = modlist;
405 rc = op.o_bd->be_modify( &op, &rs );
409 slap_mods_free( modlist );
410 return rc != LDAP_SUCCESS ? SASL_FAIL : SASL_OK;
412 #endif /* SASL_VERSION_FULL >= 2.1.16 */
414 static sasl_auxprop_plug_t slap_auxprop_plugin = {
417 NULL, /* glob_context */
418 NULL, /* auxprop_free */
421 #if SASL_VERSION_FULL >= 0x020110
422 slap_auxprop_store /* the declaration of this member changed
423 * in cyrus SASL from 2.1.15 to 2.1.16 */
431 const sasl_utils_t *utils,
434 sasl_auxprop_plug_t **plug,
435 const char *plugname)
437 if ( !out_version || !plug ) return SASL_BADPARAM;
439 if ( max_version < SASL_AUXPROP_PLUG_VERSION ) return SASL_BADVERS;
441 *out_version = SASL_AUXPROP_PLUG_VERSION;
442 *plug = &slap_auxprop_plugin;
446 /* Convert a SASL authcid or authzid into a DN. Store the DN in an
447 * auxiliary property, so that we can refer to it in sasl_authorize
448 * without interfering with anything else. Also, the SASL username
449 * buffer is constrained to 256 characters, and our DNs could be
450 * much longer (SLAP_LDAPDN_MAXLEN, currently set to 8192)
453 slap_sasl_canonicalize(
459 const char *user_realm,
464 Connection *conn = (Connection *)context;
465 struct propctx *props = sasl_auxprop_getctx( sconn );
466 struct propval auxvals[3];
469 const char *names[2];
474 Debug( LDAP_DEBUG_ARGS, "SASL Canonicalize [conn=%ld]: %s=\"%s\"\n",
475 conn ? conn->c_connid : -1,
476 (flags & SASL_CU_AUTHID) ? "authcid" : "authzid",
477 in ? in : "<empty>");
479 /* If name is too big, just truncate. We don't care, we're
480 * using DNs, not the usernames.
482 if ( inlen > out_max )
485 /* This is a Simple Bind using SPASSWD. That means the in-directory
486 * userPassword of the Binding user already points at SASL, so it
487 * cannot be used to actually satisfy a password comparison. Just
488 * ignore it, some other mech will process it.
490 if ( !conn->c_sasl_bindop ||
491 conn->c_sasl_bindop->orb_method != LDAP_AUTH_SASL ) goto done;
493 /* See if we need to add request, can only do it once */
494 prop_getnames( props, slap_propnames, auxvals );
495 if ( !auxvals[0].name )
496 prop_request( props, slap_propnames );
498 if ( flags & SASL_CU_AUTHID )
503 /* Need to store the Connection for auxprop_lookup */
504 if ( !auxvals[PROP_CONN].values ) {
505 names[0] = slap_propnames[PROP_CONN];
507 prop_set( props, names[0], (char *)&conn, sizeof( conn ) );
510 /* Already been here? */
511 if ( auxvals[which].values )
514 /* Normally we require an authzID to have a u: or dn: prefix.
515 * However, SASL frequently gives us an authzID that is just
516 * an exact copy of the authcID, without a prefix. We need to
517 * detect and allow this condition. If SASL calls canonicalize
518 * with SASL_CU_AUTHID|SASL_CU_AUTHZID this is a no-brainer.
519 * But if it's broken into two calls, we need to remember the
520 * authcID so that we can compare the authzID later. We store
521 * the authcID temporarily in conn->c_sasl_dn. We necessarily
522 * finish Canonicalizing before Authorizing, so there is no
523 * conflict with slap_sasl_authorize's use of this temp var.
525 * The SASL EXTERNAL mech is backwards from all the other mechs,
526 * it does authzID before the authcID. If we see that authzID
527 * has already been done, don't do anything special with authcID.
529 if ( flags == SASL_CU_AUTHID && !auxvals[PROP_AUTHZ].values ) {
530 conn->c_sasl_dn.bv_val = (char *) in;
531 } else if ( flags == SASL_CU_AUTHZID && conn->c_sasl_dn.bv_val ) {
532 rc = strcmp( in, conn->c_sasl_dn.bv_val );
533 conn->c_sasl_dn.bv_val = NULL;
534 /* They were equal, no work needed */
535 if ( !rc ) goto done;
538 bvin.bv_val = (char *)in;
540 rc = slap_sasl_getdn( conn, NULL, &bvin, (char *)user_realm, &dn,
541 (flags & SASL_CU_AUTHID) ? SLAP_GETDN_AUTHCID : SLAP_GETDN_AUTHZID );
542 if ( rc != LDAP_SUCCESS ) {
543 sasl_seterror( sconn, 0, ldap_err2string( rc ) );
547 names[0] = slap_propnames[which];
550 prop_set( props, names[0], (char *)&dn, sizeof( dn ) );
552 Debug( LDAP_DEBUG_ARGS, "SASL Canonicalize [conn=%ld]: %s=\"%s\"\n",
553 conn ? conn->c_connid : -1, names[0]+1,
554 dn.bv_val ? dn.bv_val : "<EMPTY>" );
557 AC_MEMCPY( out, in, inlen );
569 char *requested_user,
573 const char *def_realm,
575 struct propctx *props)
577 Connection *conn = (Connection *)context;
578 struct propval auxvals[3];
579 struct berval authcDN, authzDN;
582 /* Simple Binds don't support proxy authorization, ignore it */
583 if ( !conn->c_sasl_bindop ||
584 conn->c_sasl_bindop->orb_method != LDAP_AUTH_SASL ) return SASL_OK;
586 Debug( LDAP_DEBUG_ARGS, "SASL proxy authorize [conn=%ld]: "
587 "authcid=\"%s\" authzid=\"%s\"\n",
588 conn ? conn->c_connid : -1, auth_identity, requested_user );
589 if ( conn->c_sasl_dn.bv_val ) {
590 ch_free( conn->c_sasl_dn.bv_val );
591 BER_BVZERO( &conn->c_sasl_dn );
595 prop_getnames( props, slap_propnames+1, auxvals );
597 /* Should not happen */
598 if ( !auxvals[0].values ) {
599 sasl_seterror( sconn, 0, "invalid authcid" );
603 AC_MEMCPY( &authcDN, auxvals[0].values[0], sizeof(authcDN) );
605 /* Nothing to do if no authzID was given */
606 if ( !auxvals[1].name || !auxvals[1].values ) {
607 conn->c_sasl_dn = authcDN;
611 AC_MEMCPY( &authzDN, auxvals[1].values[0], sizeof(authzDN) );
613 rc = slap_sasl_authorized( conn->c_sasl_bindop, &authcDN, &authzDN );
614 ch_free( authcDN.bv_val );
615 if ( rc != LDAP_SUCCESS ) {
616 Debug( LDAP_DEBUG_TRACE, "SASL Proxy Authorize [conn=%ld]: "
617 "proxy authorization disallowed (%d)\n",
618 (long) (conn ? conn->c_connid : -1), rc, 0 );
620 sasl_seterror( sconn, 0, "not authorized" );
621 ch_free( authzDN.bv_val );
625 conn->c_sasl_dn = authzDN;
627 if (conn->c_sasl_bindop) {
628 Statslog( LDAP_DEBUG_STATS,
629 "conn=%lu op=%lu BIND authcid=\"%s\"\n",
630 conn->c_connid, conn->c_sasl_bindop->o_opid,
631 auth_identity, 0, 0);
634 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
635 " proxy authorization allowed\n",
636 (long) (conn ? conn->c_connid : -1), 0, 0 );
648 struct berval authcDN, authzDN;
650 Connection *conn = context;
652 struct berval bvauthcid, bvauthzid;
655 if ( conn->c_sasl_dn.bv_val ) {
656 ch_free( conn->c_sasl_dn.bv_val );
657 BER_BVZERO( &conn->c_sasl_dn );
660 Debug( LDAP_DEBUG_ARGS, "SASL Authorize [conn=%ld]: "
661 "authcid=\"%s\" authzid=\"%s\"\n",
662 (long) (conn ? conn->c_connid : -1),
663 authcid ? authcid : "<empty>",
664 authzid ? authzid : "<empty>" );
666 /* Figure out how much data we have for the dn */
667 rc = sasl_getprop( conn->c_sasl_authctx, SASL_REALM, (void **)&realm );
668 if( rc != SASL_OK && rc != SASL_NOTDONE ) {
669 Debug(LDAP_DEBUG_TRACE,
670 "authorize: getprop(REALM) failed!\n", 0,0,0);
671 *errstr = "Could not extract realm";
675 /* Convert the identities to DN's. If no authzid was given, client will
676 be bound as the DN matching their username */
677 bvauthcid.bv_val = authcid;
678 bvauthcid.bv_len = authcid ? strlen( authcid ) : 0;
679 rc = slap_sasl_getdn( conn, NULL, &bvauthcid, realm,
680 &authcDN, SLAP_GETDN_AUTHCID );
681 if( rc != LDAP_SUCCESS ) {
682 *errstr = ldap_err2string( rc );
685 if( ( authzid == NULL ) || !strcmp( authcid, authzid ) ) {
686 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
687 "Using authcDN=%s\n", (long) (conn ? conn->c_connid : -1), authcDN.bv_val,0 );
689 conn->c_sasl_dn = authcDN;
693 bvauthzid.bv_val = authzid;
694 bvauthzid.bv_len = authzid ? strlen( authzid ) : 0;
695 rc = slap_sasl_getdn( conn, NULL, &bvauthzid, realm,
696 &authzDN, SLAP_GETDN_AUTHZID );
697 if( rc != LDAP_SUCCESS ) {
698 ch_free( authcDN.bv_val );
699 *errstr = ldap_err2string( rc );
703 rc = slap_sasl_authorized(conn->c_sasl_bindop, &authcDN, &authzDN );
704 ch_free( authcDN.bv_val );
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_dn = authzDN;
717 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
718 " authorization allowed\n",
719 (long) (conn ? conn->c_connid : -1), 0, 0 );
721 if (conn->c_sasl_bindop) {
722 Statslog( LDAP_DEBUG_STATS,
723 "conn=%lu op=%lu BIND authcid=\"%s\"\n",
724 conn->c_connid, conn->c_sasl_bindop->o_opid,
731 #endif /* SASL_VERSION_MAJOR >= 2 */
734 slap_sasl_err2ldap( int saslerr )
743 rc = LDAP_SASL_BIND_IN_PROGRESS;
752 rc = LDAP_AUTH_METHOD_NOT_SUPPORTED;
755 rc = LDAP_INVALID_CREDENTIALS;
758 rc = LDAP_INSUFFICIENT_ACCESS;
762 rc = LDAP_INAPPROPRIATE_AUTH;
774 static struct berval sasl_pwscheme = BER_BVC("{SASL}");
777 const struct berval *sc,
778 const struct berval * passwd,
779 const struct berval * cred,
784 void *ctx, *sconn = NULL;
786 for( i=0; i<cred->bv_len; i++) {
787 if(cred->bv_val[i] == '\0') {
788 return LUTIL_PASSWD_ERR; /* NUL character in password */
792 if( cred->bv_val[i] != '\0' ) {
793 return LUTIL_PASSWD_ERR; /* cred must behave like a string */
796 for( i=0; i<passwd->bv_len; i++) {
797 if(passwd->bv_val[i] == '\0') {
798 return LUTIL_PASSWD_ERR; /* NUL character in password */
802 if( passwd->bv_val[i] != '\0' ) {
803 return LUTIL_PASSWD_ERR; /* passwd must behave like a string */
806 rtn = LUTIL_PASSWD_ERR;
808 ctx = ldap_pvt_thread_pool_context();
809 ldap_pvt_thread_pool_getkey( ctx, slap_sasl_bind, &sconn, NULL );
811 if( sconn != NULL ) {
813 # if SASL_VERSION_MAJOR < 2
814 sc = sasl_checkpass( sconn,
815 passwd->bv_val, passwd->bv_len,
816 cred->bv_val, cred->bv_len,
819 sc = sasl_checkpass( sconn,
820 passwd->bv_val, passwd->bv_len,
821 cred->bv_val, cred->bv_len );
823 rtn = ( sc != SASL_OK ) ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
828 #endif /* SLAPD_SPASSWD */
830 #endif /* HAVE_CYRUS_SASL */
832 int slap_sasl_init( void )
834 #ifdef HAVE_CYRUS_SASL
836 static sasl_callback_t server_callbacks[] = {
837 { SASL_CB_LOG, &slap_sasl_log, NULL },
838 { SASL_CB_LIST_END, NULL, NULL }
841 #ifdef HAVE_SASL_VERSION
842 /* stringify the version number, sasl.h doesn't do it for us */
843 #define VSTR0(maj, min, pat) #maj "." #min "." #pat
844 #define VSTR(maj, min, pat) VSTR0(maj, min, pat)
845 #define SASL_VERSION_STRING VSTR(SASL_VERSION_MAJOR, SASL_VERSION_MINOR, \
848 sasl_version( NULL, &rc );
849 if ( ((rc >> 16) != ((SASL_VERSION_MAJOR << 8)|SASL_VERSION_MINOR)) ||
850 (rc & 0xffff) < SASL_VERSION_STEP)
852 char version[sizeof("xxx.xxx.xxxxx")];
853 sprintf( version, "%u.%d.%d", (unsigned)rc >> 24, (rc >> 16) & 0xff,
855 Debug( LDAP_DEBUG_ANY, "slap_sasl_init: SASL library version mismatch:"
856 " expected " SASL_VERSION_STRING ","
857 " got %s\n", version, 0, 0 );
862 /* SASL 2 does its own memory management internally */
863 #if SASL_VERSION_MAJOR < 2
872 ldap_pvt_sasl_mutex_new,
873 ldap_pvt_sasl_mutex_lock,
874 ldap_pvt_sasl_mutex_unlock,
875 ldap_pvt_sasl_mutex_dispose );
877 #if SASL_VERSION_MAJOR >= 2
878 generic_filter.f_desc = slap_schema.si_ad_objectClass;
880 rc = sasl_auxprop_add_plugin( "slapd", slap_auxprop_init );
881 if( rc != SASL_OK ) {
882 Debug( LDAP_DEBUG_ANY, "slap_sasl_init: auxprop add plugin failed\n",
887 /* should provide callbacks for logging */
888 /* server name should be configurable */
889 rc = sasl_server_init( server_callbacks, "slapd" );
891 if( rc != SASL_OK ) {
892 Debug( LDAP_DEBUG_ANY, "slap_sasl_init: server init failed\n",
894 #if SASL_VERSION_MAJOR < 2
895 /* A no-op used to make sure we linked with Cyrus 1.5 */
896 sasl_client_auth( NULL, NULL, NULL, 0, NULL, NULL );
903 lutil_passwd_add( &sasl_pwscheme, chk_sasl, NULL );
906 Debug( LDAP_DEBUG_TRACE, "slap_sasl_init: initialized!\n",
909 /* default security properties */
910 memset( &sasl_secprops, '\0', sizeof(sasl_secprops) );
911 sasl_secprops.max_ssf = INT_MAX;
912 sasl_secprops.maxbufsize = 65536;
913 sasl_secprops.security_flags = SASL_SEC_NOPLAINTEXT|SASL_SEC_NOANONYMOUS;
919 int slap_sasl_destroy( void )
921 #ifdef HAVE_CYRUS_SASL
930 int slap_sasl_open( Connection *conn, int reopen )
932 int sc = LDAP_SUCCESS;
933 #ifdef HAVE_CYRUS_SASL
936 sasl_conn_t *ctx = NULL;
937 sasl_callback_t *session_callbacks;
939 #if SASL_VERSION_MAJOR >= 2
940 char *ipremoteport = NULL, *iplocalport = NULL;
943 assert( conn->c_sasl_authctx == NULL );
946 assert( conn->c_sasl_extra == NULL );
949 #if SASL_VERSION_MAJOR >= 2
950 SLAP_CALLOC( 5, sizeof(sasl_callback_t));
952 SLAP_CALLOC( 3, sizeof(sasl_callback_t));
954 if( session_callbacks == NULL ) {
955 Debug( LDAP_DEBUG_ANY,
956 "slap_sasl_open: SLAP_MALLOC failed", 0, 0, 0 );
959 conn->c_sasl_extra = session_callbacks;
961 session_callbacks[cb=0].id = SASL_CB_LOG;
962 session_callbacks[cb].proc = &slap_sasl_log;
963 session_callbacks[cb++].context = conn;
965 session_callbacks[cb].id = SASL_CB_PROXY_POLICY;
966 session_callbacks[cb].proc = &slap_sasl_authorize;
967 session_callbacks[cb++].context = conn;
969 #if SASL_VERSION_MAJOR >= 2
970 session_callbacks[cb].id = SASL_CB_CANON_USER;
971 session_callbacks[cb].proc = &slap_sasl_canonicalize;
972 session_callbacks[cb++].context = conn;
975 session_callbacks[cb].id = SASL_CB_LIST_END;
976 session_callbacks[cb].proc = NULL;
977 session_callbacks[cb++].context = NULL;
979 session_callbacks = conn->c_sasl_extra;
982 conn->c_sasl_layers = 0;
984 if( global_host == NULL ) {
985 global_host = ldap_pvt_get_fqdn( NULL );
988 /* create new SASL context */
989 #if SASL_VERSION_MAJOR >= 2
990 if ( conn->c_sock_name.bv_len != 0 &&
991 strncmp( conn->c_sock_name.bv_val, "IP=", 3 ) == 0) {
994 iplocalport = ch_strdup( conn->c_sock_name.bv_val + 3 );
995 /* Convert IPv6 addresses to address;port syntax. */
996 p = strrchr( iplocalport, ' ' );
997 /* Convert IPv4 addresses to address;port syntax. */
998 if ( p == NULL ) p = strchr( iplocalport, ':' );
1003 if ( conn->c_peer_name.bv_len != 0 &&
1004 strncmp( conn->c_peer_name.bv_val, "IP=", 3 ) == 0) {
1007 ipremoteport = ch_strdup( conn->c_peer_name.bv_val + 3 );
1008 /* Convert IPv6 addresses to address;port syntax. */
1009 p = strrchr( ipremoteport, ' ' );
1010 /* Convert IPv4 addresses to address;port syntax. */
1011 if ( p == NULL ) p = strchr( ipremoteport, ':' );
1016 sc = sasl_server_new( "ldap", global_host, global_realm,
1017 iplocalport, ipremoteport, session_callbacks, SASL_SUCCESS_DATA, &ctx );
1018 if ( iplocalport != NULL ) {
1019 ch_free( iplocalport );
1021 if ( ipremoteport != NULL ) {
1022 ch_free( ipremoteport );
1025 sc = sasl_server_new( "ldap", global_host, global_realm,
1026 session_callbacks, SASL_SECURITY_LAYER, &ctx );
1029 if( sc != SASL_OK ) {
1030 Debug( LDAP_DEBUG_ANY, "sasl_server_new failed: %d\n",
1036 conn->c_sasl_authctx = ctx;
1038 if( sc == SASL_OK ) {
1039 sc = sasl_setprop( ctx,
1040 SASL_SEC_PROPS, &sasl_secprops );
1042 if( sc != SASL_OK ) {
1043 Debug( LDAP_DEBUG_ANY, "sasl_setprop failed: %d\n",
1046 slap_sasl_close( conn );
1051 sc = slap_sasl_err2ldap( sc );
1053 #elif defined(SLAP_BUILTIN_SASL)
1054 /* built-in SASL implementation */
1055 SASL_CTX *ctx = (SASL_CTX *) SLAP_MALLOC(sizeof(SASL_CTX));
1056 if( ctx == NULL ) return -1;
1058 ctx->sc_external_ssf = 0;
1059 BER_BVZERO( &ctx->sc_external_id );
1061 conn->c_sasl_authctx = ctx;
1067 int slap_sasl_external(
1070 struct berval *auth_id )
1072 #if SASL_VERSION_MAJOR >= 2
1074 sasl_conn_t *ctx = conn->c_sasl_authctx;
1076 if ( ctx == NULL ) {
1077 return LDAP_UNAVAILABLE;
1080 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
1082 if ( sc != SASL_OK ) {
1086 sc = sasl_setprop( ctx, SASL_AUTH_EXTERNAL,
1087 auth_id ? auth_id->bv_val : NULL );
1089 if ( sc != SASL_OK ) {
1093 #elif defined(HAVE_CYRUS_SASL)
1095 sasl_conn_t *ctx = conn->c_sasl_authctx;
1096 sasl_external_properties_t extprops;
1098 if ( ctx == NULL ) {
1099 return LDAP_UNAVAILABLE;
1102 memset( &extprops, '\0', sizeof(extprops) );
1104 extprops.auth_id = auth_id ? auth_id->bv_val : NULL;
1106 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
1107 (void *) &extprops );
1109 if ( sc != SASL_OK ) {
1112 #elif defined(SLAP_BUILTIN_SASL)
1113 /* built-in SASL implementation */
1114 SASL_CTX *ctx = conn->c_sasl_authctx;
1115 if ( ctx == NULL ) return LDAP_UNAVAILABLE;
1117 ctx->sc_external_ssf = ssf;
1119 ctx->sc_external_id = *auth_id;
1120 BER_BVZERO( auth_id );
1122 BER_BVZERO( &ctx->sc_external_id );
1126 return LDAP_SUCCESS;
1129 int slap_sasl_reset( Connection *conn )
1131 return LDAP_SUCCESS;
1134 char ** slap_sasl_mechs( Connection *conn )
1136 char **mechs = NULL;
1138 #ifdef HAVE_CYRUS_SASL
1139 sasl_conn_t *ctx = conn->c_sasl_authctx;
1141 if( ctx == NULL ) ctx = conn->c_sasl_sockctx;
1145 SASL_CONST char *mechstr;
1147 sc = sasl_listmech( ctx,
1148 NULL, NULL, ",", NULL,
1149 &mechstr, NULL, NULL );
1151 if( sc != SASL_OK ) {
1152 Debug( LDAP_DEBUG_ANY, "slap_sasl_listmech failed: %d\n",
1158 mechs = ldap_str2charray( mechstr, "," );
1160 #if SASL_VERSION_MAJOR < 2
1164 #elif defined(SLAP_BUILTIN_SASL)
1165 /* builtin SASL implementation */
1166 SASL_CTX *ctx = conn->c_sasl_authctx;
1167 if ( ctx != NULL && ctx->sc_external_id.bv_val ) {
1168 /* should check ssf */
1169 mechs = ldap_str2charray( "EXTERNAL", "," );
1176 int slap_sasl_close( Connection *conn )
1178 #ifdef HAVE_CYRUS_SASL
1179 sasl_conn_t *ctx = conn->c_sasl_authctx;
1182 sasl_dispose( &ctx );
1184 if ( conn->c_sasl_sockctx &&
1185 conn->c_sasl_authctx != conn->c_sasl_sockctx )
1187 ctx = conn->c_sasl_sockctx;
1188 sasl_dispose( &ctx );
1191 conn->c_sasl_authctx = NULL;
1192 conn->c_sasl_sockctx = NULL;
1193 conn->c_sasl_done = 0;
1195 free( conn->c_sasl_extra );
1196 conn->c_sasl_extra = NULL;
1198 #elif defined(SLAP_BUILTIN_SASL)
1199 SASL_CTX *ctx = conn->c_sasl_authctx;
1201 if( ctx->sc_external_id.bv_val ) {
1202 free( ctx->sc_external_id.bv_val );
1203 BER_BVZERO( &ctx->sc_external_id );
1206 conn->c_sasl_authctx = NULL;
1210 return LDAP_SUCCESS;
1213 int slap_sasl_bind( Operation *op, SlapReply *rs )
1215 #ifdef HAVE_CYRUS_SASL
1216 sasl_conn_t *ctx = op->o_conn->c_sasl_authctx;
1217 struct berval response;
1218 unsigned reslen = 0;
1221 Debug(LDAP_DEBUG_ARGS,
1222 "==> sasl_bind: dn=\"%s\" mech=%s datalen=%ld\n",
1223 op->o_req_dn.bv_len ? op->o_req_dn.bv_val : "",
1224 op->o_conn->c_sasl_bind_in_progress ? "<continuing>" :
1225 op->o_conn->c_sasl_bind_mech.bv_val,
1226 op->orb_cred.bv_len );
1229 send_ldap_error( op, rs, LDAP_UNAVAILABLE,
1230 "SASL unavailable on this session" );
1234 #if SASL_VERSION_MAJOR >= 2
1235 #define START( ctx, mech, cred, clen, resp, rlen, err ) \
1236 sasl_server_start( ctx, mech, cred, clen, resp, rlen )
1237 #define STEP( ctx, cred, clen, resp, rlen, err ) \
1238 sasl_server_step( ctx, cred, clen, resp, rlen )
1240 #define START( ctx, mech, cred, clen, resp, rlen, err ) \
1241 sasl_server_start( ctx, mech, cred, clen, resp, rlen, err )
1242 #define STEP( ctx, cred, clen, resp, rlen, err ) \
1243 sasl_server_step( ctx, cred, clen, resp, rlen, err )
1246 if ( !op->o_conn->c_sasl_bind_in_progress ) {
1247 /* If we already authenticated once, must use a new context */
1248 if ( op->o_conn->c_sasl_done ) {
1250 const char *authid = NULL;
1251 #if SASL_VERSION_MAJOR >= 2
1252 sasl_getprop( ctx, SASL_SSF_EXTERNAL, (void *)&ssf );
1253 sasl_getprop( ctx, SASL_AUTH_EXTERNAL, (void *)&authid );
1254 if ( authid ) authid = ch_strdup( authid );
1256 if ( ctx != op->o_conn->c_sasl_sockctx ) {
1257 sasl_dispose( &ctx );
1259 op->o_conn->c_sasl_authctx = NULL;
1261 slap_sasl_open( op->o_conn, 1 );
1262 ctx = op->o_conn->c_sasl_authctx;
1263 #if SASL_VERSION_MAJOR >= 2
1265 sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
1266 sasl_setprop( ctx, SASL_AUTH_EXTERNAL, authid );
1267 ch_free( (char *)authid );
1272 op->o_conn->c_sasl_bind_mech.bv_val,
1273 op->orb_cred.bv_val, op->orb_cred.bv_len,
1274 (SASL_CONST char **)&response.bv_val, &reslen, &rs->sr_text );
1278 op->orb_cred.bv_val, op->orb_cred.bv_len,
1279 (SASL_CONST char **)&response.bv_val, &reslen, &rs->sr_text );
1282 response.bv_len = reslen;
1284 if ( sc == SASL_OK ) {
1285 sasl_ssf_t *ssf = NULL;
1287 op->orb_edn = op->o_conn->c_sasl_dn;
1288 BER_BVZERO( &op->o_conn->c_sasl_dn );
1289 op->o_conn->c_sasl_done = 1;
1291 rs->sr_err = LDAP_SUCCESS;
1293 (void) sasl_getprop( ctx, SASL_SSF, (void *)&ssf );
1294 op->orb_ssf = ssf ? *ssf : 0;
1298 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1299 op->o_conn->c_sasl_layers++;
1301 /* If there's an old layer, set sockctx to NULL to
1302 * tell connection_read() to wait for us to finish.
1303 * Otherwise there is a race condition: we have to
1304 * send the Bind response using the old security
1305 * context and then remove it before reading any
1308 if ( op->o_conn->c_sasl_sockctx ) {
1309 ctx = op->o_conn->c_sasl_sockctx;
1310 op->o_conn->c_sasl_sockctx = NULL;
1312 op->o_conn->c_sasl_sockctx = op->o_conn->c_sasl_authctx;
1314 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1317 /* Must send response using old security layer */
1318 if (response.bv_len) rs->sr_sasldata = &response;
1319 send_ldap_sasl( op, rs );
1321 /* Now dispose of the old security layer.
1324 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1325 ldap_pvt_sasl_remove( op->o_conn->c_sb );
1326 op->o_conn->c_sasl_sockctx = op->o_conn->c_sasl_authctx;
1327 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1328 sasl_dispose( &ctx );
1330 } else if ( sc == SASL_CONTINUE ) {
1331 rs->sr_err = LDAP_SASL_BIND_IN_PROGRESS,
1332 rs->sr_sasldata = &response;
1333 send_ldap_sasl( op, rs );
1336 #if SASL_VERSION_MAJOR >= 2
1337 rs->sr_text = sasl_errdetail( ctx );
1339 rs->sr_err = slap_sasl_err2ldap( sc ),
1340 send_ldap_result( op, rs );
1343 #if SASL_VERSION_MAJOR < 2
1344 if( response.bv_len ) {
1345 ch_free( response.bv_val );
1349 Debug(LDAP_DEBUG_TRACE, "<== slap_sasl_bind: rc=%d\n", rs->sr_err, 0, 0);
1351 #elif defined(SLAP_BUILTIN_SASL)
1352 /* built-in SASL implementation */
1353 SASL_CTX *ctx = op->o_conn->c_sasl_authctx;
1355 if ( ctx == NULL ) {
1356 send_ldap_error( op, rs, LDAP_OTHER,
1357 "Internal SASL Error" );
1359 } else if ( bvmatch( &ext_bv, &op->o_conn->c_sasl_bind_mech ) ) {
1362 if( op->orb_cred.bv_len ) {
1363 rs->sr_text = "proxy authorization not support";
1364 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1365 send_ldap_result( op, rs );
1368 op->orb_edn = ctx->sc_external_id;
1369 rs->sr_err = LDAP_SUCCESS;
1370 rs->sr_sasldata = NULL;
1371 send_ldap_sasl( op, rs );
1375 send_ldap_error( op, rs, LDAP_AUTH_METHOD_NOT_SUPPORTED,
1376 "requested SASL mechanism not supported" );
1379 send_ldap_error( op, rs, LDAP_AUTH_METHOD_NOT_SUPPORTED,
1380 "SASL not supported" );
1386 char* slap_sasl_secprops( const char *in )
1388 #ifdef HAVE_CYRUS_SASL
1389 int rc = ldap_pvt_sasl_secprops( in, &sasl_secprops );
1391 return rc == LDAP_SUCCESS ? NULL : "Invalid security properties";
1393 return "SASL not supported";
1397 void slap_sasl_secprops_unparse( struct berval *bv )
1399 #ifdef HAVE_CYRUS_SASL
1400 ldap_pvt_sasl_secprops_unparse( &sasl_secprops, bv );
1404 #ifdef HAVE_CYRUS_SASL
1406 slap_sasl_setpass( Operation *op, SlapReply *rs )
1408 struct berval id = BER_BVNULL; /* needs to come from connection */
1409 struct berval new = BER_BVNULL;
1410 struct berval old = BER_BVNULL;
1412 assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->ore_reqoid ) == 0 );
1414 rs->sr_err = sasl_getprop( op->o_conn->c_sasl_authctx, SASL_USERNAME,
1415 (SASL_CONST void **)&id.bv_val );
1417 if( rs->sr_err != SASL_OK ) {
1418 rs->sr_text = "unable to retrieve SASL username";
1419 rs->sr_err = LDAP_OTHER;
1423 Debug( LDAP_DEBUG_ARGS, "==> slap_sasl_setpass: \"%s\"\n",
1424 id.bv_val ? id.bv_val : "", 0, 0 );
1426 rs->sr_err = slap_passwd_parse( op->ore_reqdata,
1427 NULL, &old, &new, &rs->sr_text );
1429 if( rs->sr_err != LDAP_SUCCESS ) {
1433 if( new.bv_len == 0 ) {
1434 slap_passwd_generate(&new);
1436 if( new.bv_len == 0 ) {
1437 rs->sr_text = "password generation failed.";
1438 rs->sr_err = LDAP_OTHER;
1442 rs->sr_rspdata = slap_passwd_return( &new );
1445 #if SASL_VERSION_MAJOR < 2
1446 rs->sr_err = sasl_setpass( op->o_conn->c_sasl_authctx,
1447 id.bv_val, new.bv_val, new.bv_len, 0, &rs->sr_text );
1449 rs->sr_err = sasl_setpass( op->o_conn->c_sasl_authctx, id.bv_val,
1450 new.bv_val, new.bv_len, old.bv_val, old.bv_len, 0 );
1451 if( rs->sr_err != SASL_OK ) {
1452 rs->sr_text = sasl_errdetail( op->o_conn->c_sasl_authctx );
1455 switch(rs->sr_err) {
1457 rs->sr_err = LDAP_SUCCESS;
1467 rs->sr_err = LDAP_OTHER;
1473 #endif /* HAVE_CYRUS_SASL */
1475 /* Take any sort of identity string and return a DN with the "dn:" prefix. The
1476 * string returned in *dn is in its own allocated memory, and must be free'd
1477 * by the calling process. -Mark Adamson, Carnegie Mellon
1479 * The "dn:" prefix is no longer used anywhere inside slapd. It is only used
1480 * on strings passed in directly from SASL. -Howard Chu, Symas Corp.
1487 int slap_sasl_getdn( Connection *conn, Operation *op, struct berval *id,
1488 char *user_realm, struct berval *dn, int flags )
1490 int rc, is_dn = SET_NONE, do_norm = 1;
1491 struct berval dn2, *mech;
1496 Debug( LDAP_DEBUG_ARGS, "slap_sasl_getdn: conn %d id=%s [len=%d]\n",
1498 BER_BVISNULL( id ) ? "NULL" : ( BER_BVISEMPTY( id ) ? "<empty>" : id->bv_val ),
1499 BER_BVISNULL( id ) ? 0 : ( BER_BVISEMPTY( id ) ? 0 : id->bv_len ) );
1502 op = conn->c_sasl_bindop;
1507 if ( !BER_BVISNULL( id ) ) {
1508 /* Blatantly anonymous ID */
1509 static struct berval bv_anonymous = BER_BVC( "anonymous" );
1511 if ( ber_bvstrcasecmp( id, &bv_anonymous ) == 0 ) {
1512 return( LDAP_SUCCESS );
1516 /* FIXME: if empty, should we stop? */
1517 BER_BVSTR( id, "" );
1520 if ( !BER_BVISEMPTY( &conn->c_sasl_bind_mech ) ) {
1521 mech = &conn->c_sasl_bind_mech;
1523 mech = &conn->c_authmech;
1526 /* An authcID needs to be converted to authzID form. Set the
1527 * values directly into *dn; they will be normalized later. (and
1528 * normalizing always makes a new copy.) An ID from a TLS certificate
1529 * is already normalized, so copy it and skip normalization.
1531 if( flags & SLAP_GETDN_AUTHCID ) {
1532 if( bvmatch( mech, &ext_bv )) {
1533 /* EXTERNAL DNs are already normalized */
1534 assert( !BER_BVISNULL( id ) );
1538 ber_dupbv_x( dn, id, op->o_tmpmemctx );
1541 /* convert to u:<username> form */
1547 if( is_dn == SET_NONE ) {
1548 if( !strncasecmp( id->bv_val, "u:", STRLENOF( "u:" ) ) ) {
1550 dn->bv_val = id->bv_val + STRLENOF( "u:" );
1551 dn->bv_len = id->bv_len - STRLENOF( "u:" );
1553 } else if ( !strncasecmp( id->bv_val, "dn:", STRLENOF( "dn:" ) ) ) {
1555 dn->bv_val = id->bv_val + STRLENOF( "dn:" );
1556 dn->bv_len = id->bv_len - STRLENOF( "dn:" );
1560 /* No other possibilities from here */
1561 if( is_dn == SET_NONE ) {
1563 return( LDAP_INAPPROPRIATE_AUTH );
1566 /* Username strings */
1567 if( is_dn == SET_U ) {
1568 /* ITS#3419: values may need escape */
1570 LDAPAVA *RDNs[ 4 ][ 2 ];
1575 DN[ irdn ] = RDNs[ irdn ];
1576 RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
1577 AVAs[ irdn ].la_attr = slap_schema.si_ad_uid->ad_cname;
1578 AVAs[ irdn ].la_value = *dn;
1579 AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
1580 AVAs[ irdn ].la_private = NULL;
1581 RDNs[ irdn ][ 1 ] = NULL;
1583 if ( user_realm && *user_realm ) {
1585 DN[ irdn ] = RDNs[ irdn ];
1586 RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
1587 AVAs[ irdn ].la_attr = slap_schema.si_ad_cn->ad_cname;
1588 ber_str2bv( user_realm, 0, 0, &AVAs[ irdn ].la_value );
1589 AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
1590 AVAs[ irdn ].la_private = NULL;
1591 RDNs[ irdn ][ 1 ] = NULL;
1594 if ( !BER_BVISNULL( mech ) ) {
1596 DN[ irdn ] = RDNs[ irdn ];
1597 RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
1598 AVAs[ irdn ].la_attr = slap_schema.si_ad_cn->ad_cname;
1599 AVAs[ irdn ].la_value = *mech;
1600 AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
1601 AVAs[ irdn ].la_private = NULL;
1602 RDNs[ irdn ][ 1 ] = NULL;
1606 DN[ irdn ] = RDNs[ irdn ];
1607 RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
1608 AVAs[ irdn ].la_attr = slap_schema.si_ad_cn->ad_cname;
1609 BER_BVSTR( &AVAs[ irdn ].la_value, "auth" );
1610 AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
1611 AVAs[ irdn ].la_private = NULL;
1612 RDNs[ irdn ][ 1 ] = NULL;
1617 rc = ldap_dn2bv_x( DN, dn, LDAP_DN_FORMAT_LDAPV3, op->o_tmpmemctx );
1618 if ( rc != LDAP_SUCCESS ) {
1623 Debug( LDAP_DEBUG_TRACE, "slap_sasl_getdn: u:id converted to %s\n", dn->bv_val,0,0 );
1627 /* Dup the DN in any case, so we don't risk
1628 * leaks or dangling pointers later,
1629 * and the DN value is '\0' terminated */
1630 ber_dupbv_x( &dn2, dn, op->o_tmpmemctx );
1631 dn->bv_val = dn2.bv_val;
1634 /* All strings are in DN form now. Normalize if needed. */
1636 rc = dnNormalize( 0, NULL, NULL, dn, &dn2, op->o_tmpmemctx );
1638 /* User DNs were constructed above and must be freed now */
1639 slap_sl_free( dn->bv_val, op->o_tmpmemctx );
1641 if ( rc != LDAP_SUCCESS ) {
1648 /* Run thru regexp */
1649 slap_sasl2dn( op, dn, &dn2, flags );
1650 if( !BER_BVISNULL( &dn2 ) ) {
1651 slap_sl_free( dn->bv_val, op->o_tmpmemctx );
1653 Debug( LDAP_DEBUG_TRACE, "getdn: dn:id converted to %s\n",
1657 return( LDAP_SUCCESS );