3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/stdlib.h>
11 #include <ac/string.h>
20 #ifdef HAVE_CYRUS_SASL
21 # ifdef HAVE_SASL_SASL_H
22 # include <sasl/sasl.h>
27 # if SASL_VERSION_MAJOR >= 2
28 # include <sasl/saslplug.h>
29 # define SASL_CONST const
34 static sasl_security_properties_t sasl_secprops;
35 #endif /* HAVE_CYRUS_SASL */
41 int slap_sasl_config( int cargc, char **cargv, char *line,
42 const char *fname, int lineno )
44 /* set SASL proxy authorization policy */
45 if ( strcasecmp( cargv[0], "sasl-authz-policy" ) == 0 ) {
48 LDAP_LOG( CONFIG, CRIT,
49 "%s: line %d: missing policy in"
50 " \"sasl-authz-policy <policy>\" line\n",
53 Debug( LDAP_DEBUG_ANY,
54 "%s: line %d: missing policy in"
55 " \"sasl-authz-policy <policy>\" line\n",
61 if ( slap_sasl_setpolicy( cargv[1] ) ) {
63 LDAP_LOG( CONFIG, CRIT,
64 "%s: line %d: unable "
65 "to parse value \"%s\" "
66 "in \"sasl-authz-policy "
68 fname, lineno, cargv[1] );
70 Debug( LDAP_DEBUG_ANY,
71 "%s: line %d: unable "
72 "to parse value \"%s\" "
73 "in \"sasl-authz-policy "
75 fname, lineno, cargv[1] );
80 } else if ( !strcasecmp( cargv[0], "sasl-regexp" )
81 || !strcasecmp( cargv[0], "saslregexp" ) )
86 LDAP_LOG( CONFIG, CRIT,
87 "%s: line %d: need 2 args in "
88 "\"saslregexp <match> <replace>\"\n",
91 Debug( LDAP_DEBUG_ANY,
92 "%s: line %d: need 2 args in "
93 "\"saslregexp <match> <replace>\"\n",
99 rc = slap_sasl_regexp_config( cargv[1], cargv[2] );
104 #ifdef HAVE_CYRUS_SASL
106 } else if ( strcasecmp( cargv[0], "sasl-host" ) == 0 ) {
109 LDAP_LOG( CONFIG, CRIT,
110 "%s: line %d: missing host in \"sasl-host <host>\" line\n",
113 Debug( LDAP_DEBUG_ANY,
114 "%s: line %d: missing host in \"sasl-host <host>\" line\n",
121 if ( global_host != NULL ) {
123 LDAP_LOG( CONFIG, CRIT,
124 "%s: line %d: already set sasl-host!\n",
127 Debug( LDAP_DEBUG_ANY,
128 "%s: line %d: already set sasl-host!\n",
135 global_host = ch_strdup( cargv[1] );
139 } else if ( strcasecmp( cargv[0], "sasl-realm" ) == 0 ) {
142 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
143 "missing realm in \"sasl-realm <realm>\" line.\n",
146 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
147 "missing realm in \"sasl-realm <realm>\" line.\n",
154 if ( global_realm != NULL ) {
156 LDAP_LOG( CONFIG, CRIT,
157 "%s: line %d: already set sasl-realm!\n",
160 Debug( LDAP_DEBUG_ANY,
161 "%s: line %d: already set sasl-realm!\n",
168 global_realm = ch_strdup( cargv[1] );
171 /* SASL security properties */
172 } else if ( strcasecmp( cargv[0], "sasl-secprops" ) == 0 ) {
177 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
178 "missing flags in \"sasl-secprops <properties>\" line\n",
181 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
182 "missing flags in \"sasl-secprops <properties>\" line\n",
189 txt = slap_sasl_secprops( cargv[1] );
192 LDAP_LOG( CONFIG, CRIT,
193 "%s: line %d sasl-secprops: %s\n",
194 fname, lineno, txt );
196 Debug( LDAP_DEBUG_ANY,
197 "%s: line %d: sasl-secprops: %s\n",
198 fname, lineno, txt );
203 #endif /* HAVE_CYRUS_SASL */
209 #ifdef HAVE_CYRUS_SASL
217 Connection *conn = context;
221 if ( message == NULL ) {
222 return SASL_BADPARAM;
226 #if SASL_VERSION_MAJOR >= 2
228 level = LDAP_DEBUG_NONE;
232 level = LDAP_DEBUG_ANY;
236 level = LDAP_DEBUG_ANY;
240 level = LDAP_DEBUG_TRACE;
244 level = LDAP_DEBUG_TRACE;
248 level = LDAP_DEBUG_TRACE;
252 level = LDAP_DEBUG_TRACE;
256 level = LDAP_DEBUG_TRACE;
257 label = "Password Trace";
261 level = LDAP_DEBUG_ANY;
264 case SASL_LOG_WARNING:
265 level = LDAP_DEBUG_TRACE;
269 level = LDAP_DEBUG_TRACE;
274 return SASL_BADPARAM;
278 LDAP_LOG( TRANSPORT, ENTRY,
279 "SASL [conn=%ld] %s: %s\n", conn ? conn->c_connid : -1, label, message);
281 Debug( level, "SASL [conn=%ld] %s: %s\n",
282 conn ? conn->c_connid: -1,
291 #if SASL_VERSION_MAJOR >= 2
292 static const char *slap_propnames[] = {
293 "*slapConn", "*authcDN", "*authzDN", NULL };
295 static Filter generic_filter = { LDAP_FILTER_PRESENT };
301 typedef struct lookup_info {
304 const struct propval *list;
305 sasl_server_params_t *sparams;
308 static slap_response sasl_ap_lookup, sasl_cb_checkpass;
311 sasl_ap_lookup( Operation *op, SlapReply *rs )
314 AttributeDescription *ad;
318 slap_callback *tmp = op->o_callback;
319 lookup_info *sl = tmp->sc_private;
321 if (rs->sr_type != REP_SEARCH) return 0;
323 for( i = 0; i < sl->last; i++ ) {
324 const char *name = sl->list[i].name;
326 if ( name[0] == '*' ) {
327 if ( sl->flags & SASL_AUXPROP_AUTHZID ) continue;
329 } else if ( !(sl->flags & SASL_AUXPROP_AUTHZID ) )
332 if ( sl->list[i].values ) {
333 if ( !(sl->flags & SASL_AUXPROP_OVERRIDE) ) continue;
336 rc = slap_str2ad( name, &ad, &text );
337 if ( rc != LDAP_SUCCESS ) {
339 LDAP_LOG( TRANSPORT, DETAIL1,
340 "slap_auxprop: str2ad(%s): %s\n", name, text, 0 );
342 Debug( LDAP_DEBUG_TRACE,
343 "slap_auxprop: str2ad(%s): %s\n", name, text, 0 );
347 a = attr_find( rs->sr_entry->e_attrs, ad );
349 if ( ! access_allowed( op, rs->sr_entry, ad, NULL, ACL_AUTH, NULL ) ) {
352 if ( sl->list[i].values && ( sl->flags & SASL_AUXPROP_OVERRIDE ) ) {
353 sl->sparams->utils->prop_erase( sl->sparams->propctx,
356 for ( bv = a->a_vals; bv->bv_val; bv++ ) {
357 sl->sparams->utils->prop_set( sl->sparams->propctx,
358 sl->list[i].name, bv->bv_val, bv->bv_len );
367 sasl_server_params_t *sparams,
374 Connection *conn = NULL;
377 sl.list = sparams->utils->prop_get( sparams->propctx );
378 sl.sparams = sparams;
381 /* Find our DN and conn first */
382 for( i = 0, sl.last = 0; sl.list[i].name; i++ ) {
383 if ( sl.list[i].name[0] == '*' ) {
384 if ( !strcmp( sl.list[i].name, slap_propnames[PROP_CONN] ) ) {
385 if ( sl.list[i].values && sl.list[i].values[0] )
386 AC_MEMCPY( &conn, sl.list[i].values[0], sizeof( conn ) );
387 if ( !sl.last ) sl.last = i;
389 if ( (flags & SASL_AUXPROP_AUTHZID) &&
390 !strcmp( sl.list[i].name, slap_propnames[PROP_AUTHZ] ) ) {
392 if ( sl.list[i].values && sl.list[i].values[0] )
393 AC_MEMCPY( &op.o_req_ndn, sl.list[i].values[0], sizeof( struct berval ) );
394 if ( !sl.last ) sl.last = i;
397 if ( !strcmp( sl.list[i].name, slap_propnames[PROP_AUTHC] ) ) {
398 if ( !sl.last ) sl.last = i;
399 if ( sl.list[i].values && sl.list[i].values[0] ) {
400 AC_MEMCPY( &op.o_req_ndn, sl.list[i].values[0], sizeof( struct berval ) );
401 if ( !(flags & SASL_AUXPROP_AUTHZID) )
408 /* Now see what else needs to be fetched */
409 for( i = 0; i < sl.last; i++ ) {
410 const char *name = sl.list[i].name;
412 if ( name[0] == '*' ) {
413 if ( flags & SASL_AUXPROP_AUTHZID ) continue;
415 } else if ( !(flags & SASL_AUXPROP_AUTHZID ) )
418 if ( sl.list[i].values ) {
419 if ( !(flags & SASL_AUXPROP_OVERRIDE) ) continue;
425 slap_callback cb = { sasl_ap_lookup, NULL };
429 op.o_bd = select_backend( &op.o_req_ndn, 0, 1 );
431 if ( op.o_bd && op.o_bd->be_search ) {
432 SlapReply rs = {REP_RESULT};
433 op.o_tag = LDAP_REQ_SEARCH;
434 op.o_protocol = LDAP_VERSION3;
435 op.o_ndn = conn->c_ndn;
437 op.o_time = slap_get_time();
438 op.o_do_not_cache = 1;
439 op.o_is_auth_check = 1;
440 op.o_threadctx = conn->c_sasl_bindop->o_threadctx;
441 op.o_tmpmemctx = conn->c_sasl_bindop->o_tmpmemctx;
442 op.o_tmpmfuncs = conn->c_sasl_bindop->o_tmpmfuncs;
444 op.o_pb = conn->c_sasl_bindop->o_pb;
447 op.o_connid = conn->c_connid;
448 op.ors_scope = LDAP_SCOPE_BASE;
449 op.ors_deref = LDAP_DEREF_NEVER;
451 op.ors_filter = &generic_filter;
453 op.o_bd->be_search( &op, &rs );
458 static sasl_auxprop_plug_t slap_auxprop_plugin = {
461 NULL, /* glob_context */
462 NULL, /* auxprop_free */
470 const sasl_utils_t *utils,
473 sasl_auxprop_plug_t **plug,
474 const char *plugname)
476 if ( !out_version | !plug ) return SASL_BADPARAM;
478 if ( max_version < SASL_AUXPROP_PLUG_VERSION ) return SASL_BADVERS;
480 *out_version = SASL_AUXPROP_PLUG_VERSION;
481 *plug = &slap_auxprop_plugin;
485 typedef struct checkpass_info {
491 sasl_cb_checkpass( Operation *op, SlapReply *rs )
493 slap_callback *tmp = op->o_callback;
494 checkpass_info *ci = tmp->sc_private;
498 if (rs->sr_type != REP_SEARCH) return 0;
500 ci->rc = SASL_NOVERIFY;
502 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_userPassword );
504 if ( ! access_allowed( op, rs->sr_entry, slap_schema.si_ad_userPassword,
505 NULL, ACL_AUTH, NULL ) ) return 0;
507 for ( bv = a->a_vals; bv->bv_val != NULL; bv++ ) {
508 if ( !lutil_passwd( bv, &ci->cred, NULL, &rs->sr_text ) ) {
520 const char *username,
523 struct propctx *propctx)
525 Connection *conn = (Connection *)context;
532 /* SASL will fallback to its own mechanisms if we don't
533 * find an answer here.
536 rc = slap_sasl_getdn( conn, NULL, (char *)username, 0, NULL, &op.o_req_ndn,
537 SLAP_GETDN_AUTHCID );
538 if ( rc != LDAP_SUCCESS ) {
539 sasl_seterror( sconn, 0, ldap_err2string( rc ) );
543 if ( op.o_req_ndn.bv_len == 0 ) {
544 sasl_seterror( sconn, 0,
545 "No password is associated with the Root DSE" );
546 if ( op.o_req_ndn.bv_val != NULL ) {
547 ch_free( op.o_req_ndn.bv_val );
552 op.o_bd = select_backend( &op.o_req_ndn, 0, 1 );
553 if ( op.o_bd && op.o_bd->be_search ) {
554 slap_callback cb = { sasl_cb_checkpass, NULL };
555 SlapReply rs = {REP_RESULT};
557 ci.cred.bv_val = (char *)pass;
558 ci.cred.bv_len = passlen;
561 op.o_tag = LDAP_REQ_SEARCH;
562 op.o_protocol = LDAP_VERSION3;
563 op.o_ndn = conn->c_ndn;
565 op.o_time = slap_get_time();
566 op.o_do_not_cache = 1;
567 op.o_is_auth_check = 1;
568 op.o_threadctx = conn->c_sasl_bindop->o_threadctx;
569 op.o_tmpmemctx = conn->c_sasl_bindop->o_tmpmemctx;
570 op.o_tmpmfuncs = conn->c_sasl_bindop->o_tmpmfuncs;
572 op.o_pb = conn->c_sasl_bindop->o_pb;
575 op.o_connid = conn->c_connid;
576 op.ors_scope = LDAP_SCOPE_BASE;
577 op.ors_deref = LDAP_DEREF_NEVER;
579 op.ors_filter = &generic_filter;
581 op.o_bd->be_search( &op, &rs );
583 if ( ci.rc != SASL_OK ) {
584 sasl_seterror( sconn, 0,
585 ldap_err2string( LDAP_INVALID_CREDENTIALS ) );
588 ch_free( op.o_req_ndn.bv_val );
593 /* Convert a SASL authcid or authzid into a DN. Store the DN in an
594 * auxiliary property, so that we can refer to it in sasl_authorize
595 * without interfering with anything else. Also, the SASL username
596 * buffer is constrained to 256 characters, and our DNs could be
597 * much longer (totally arbitrary length)...
600 slap_sasl_canonicalize(
606 const char *user_realm,
611 Connection *conn = (Connection *)context;
612 struct propctx *props = sasl_auxprop_getctx( sconn );
613 struct propval auxvals[3];
616 const char *names[2];
621 LDAP_LOG( TRANSPORT, ENTRY,
622 "slap_sasl_canonicalize: conn %d %s=\"%s\"\n",
623 conn ? conn->c_connid : -1,
624 (flags & SASL_CU_AUTHID) ? "authcid" : "authzid",
625 in ? in : "<empty>");
627 Debug( LDAP_DEBUG_ARGS, "SASL Canonicalize [conn=%ld]: %s=\"%s\"\n",
628 conn ? conn->c_connid : -1,
629 (flags & SASL_CU_AUTHID) ? "authcid" : "authzid",
630 in ? in : "<empty>");
633 /* If name is too big, just truncate. We don't care, we're
634 * using DNs, not the usernames.
636 if ( inlen > out_max )
639 /* See if we need to add request, can only do it once */
640 prop_getnames( props, slap_propnames, auxvals );
641 if ( !auxvals[0].name )
642 prop_request( props, slap_propnames );
644 if ( flags & SASL_CU_AUTHID )
649 /* Need to store the Connection for auxprop_lookup */
650 if ( !auxvals[PROP_CONN].values ) {
651 names[0] = slap_propnames[PROP_CONN];
653 prop_set( props, names[0], (char *)&conn, sizeof( conn ) );
656 /* Already been here? */
657 if ( auxvals[which].values )
660 /* Normally we require an authzID to have a u: or dn: prefix.
661 * However, SASL frequently gives us an authzID that is just
662 * an exact copy of the authcID, without a prefix. We need to
663 * detect and allow this condition. If SASL calls canonicalize
664 * with SASL_CU_AUTHID|SASL_CU_AUTHZID this is a no-brainer.
665 * But if it's broken into two calls, we need to remember the
666 * authcID so that we can compare the authzID later. We store
667 * the authcID temporarily in conn->c_sasl_dn. We necessarily
668 * finish Canonicalizing before Authorizing, so there is no
669 * conflict with slap_sasl_authorize's use of this temp var.
671 * The SASL EXTERNAL mech is backwards from all the other mechs,
672 * it does authzID before the authcID. If we see that authzID
673 * has already been done, don't do anything special with authcID.
675 if ( flags == SASL_CU_AUTHID && !auxvals[PROP_AUTHZ].values ) {
676 conn->c_sasl_dn.bv_val = (char *) in;
677 } else if ( flags == SASL_CU_AUTHZID && conn->c_sasl_dn.bv_val ) {
678 rc = strcmp( in, conn->c_sasl_dn.bv_val );
679 conn->c_sasl_dn.bv_val = NULL;
680 /* They were equal, no work needed */
681 if ( !rc ) goto done;
684 rc = slap_sasl_getdn( conn, NULL, (char *)in, inlen, (char *)user_realm, &dn,
685 (flags & SASL_CU_AUTHID) ? SLAP_GETDN_AUTHCID : SLAP_GETDN_AUTHZID );
686 if ( rc != LDAP_SUCCESS ) {
687 sasl_seterror( sconn, 0, ldap_err2string( rc ) );
691 names[0] = slap_propnames[which];
694 prop_set( props, names[0], (char *)&dn, sizeof( dn ) );
697 LDAP_LOG( TRANSPORT, ENTRY,
698 "slap_sasl_canonicalize: conn %d %s=\"%s\"\n",
699 conn ? conn->c_connid : -1, names[0]+1,
700 dn.bv_val ? dn.bv_val : "<EMPTY>" );
702 Debug( LDAP_DEBUG_ARGS, "SASL Canonicalize [conn=%ld]: %s=\"%s\"\n",
703 conn ? conn->c_connid : -1, names[0]+1,
704 dn.bv_val ? dn.bv_val : "<EMPTY>" );
708 AC_MEMCPY( out, in, inlen );
720 char *requested_user,
724 const char *def_realm,
726 struct propctx *props)
728 Connection *conn = (Connection *)context;
729 struct propval auxvals[3];
730 struct berval authcDN, authzDN;
734 LDAP_LOG( TRANSPORT, ENTRY,
735 "slap_sasl_authorize: conn %d authcid=\"%s\" authzid=\"%s\"\n",
736 conn ? conn->c_connid : -1, auth_identity, requested_user);
738 Debug( LDAP_DEBUG_ARGS, "SASL Authorize [conn=%ld]: "
739 "authcid=\"%s\" authzid=\"%s\"\n",
740 conn ? conn->c_connid : -1, auth_identity, requested_user );
742 if ( conn->c_sasl_dn.bv_val ) {
743 ch_free( conn->c_sasl_dn.bv_val );
744 conn->c_sasl_dn.bv_val = NULL;
745 conn->c_sasl_dn.bv_len = 0;
749 prop_getnames( props, slap_propnames+1, auxvals );
751 AC_MEMCPY( &authcDN, auxvals[0].values[0], sizeof(authcDN) );
753 /* Nothing to do if no authzID was given */
754 if ( !auxvals[1].name || !auxvals[1].values ) {
755 conn->c_sasl_dn = authcDN;
759 AC_MEMCPY( &authzDN, auxvals[1].values[0], sizeof(authzDN) );
761 rc = slap_sasl_authorized( conn->c_sasl_bindop, &authcDN, &authzDN );
762 ch_free( authcDN.bv_val );
763 if ( rc != LDAP_SUCCESS ) {
765 LDAP_LOG( TRANSPORT, INFO,
766 "slap_sasl_authorize: conn %ld authorization disallowed (%d)\n",
767 (long)(conn ? conn->c_connid : -1), rc, 0 );
769 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
770 " authorization disallowed (%d)\n",
771 (long) (conn ? conn->c_connid : -1), rc, 0 );
774 sasl_seterror( sconn, 0, "not authorized" );
775 ch_free( authzDN.bv_val );
779 conn->c_sasl_dn = authzDN;
781 if (conn->c_sasl_bindop) {
782 Statslog( LDAP_DEBUG_STATS,
783 "conn=%lu op=%lu BIND authcid=\"%s\"\n",
784 conn->c_connid, conn->c_sasl_bindop->o_opid,
785 auth_identity, 0, 0);
789 LDAP_LOG( TRANSPORT, ENTRY,
790 "slap_sasl_authorize: conn %d authorization allowed\n",
791 (long)(conn ? conn->c_connid : -1), 0, 0 );
793 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
794 " authorization allowed\n",
795 (long) (conn ? conn->c_connid : -1), 0, 0 );
808 struct berval authcDN, authzDN;
810 Connection *conn = context;
814 if ( conn->c_sasl_dn.bv_val ) {
815 ch_free( conn->c_sasl_dn.bv_val );
816 conn->c_sasl_dn.bv_val = NULL;
817 conn->c_sasl_dn.bv_len = 0;
821 LDAP_LOG( TRANSPORT, ENTRY,
822 "slap_sasl_authorize: conn %d authcid=\"%s\" authzid=\"%s\"\n",
823 conn ? conn->c_connid : -1, authcid ? authcid : "<empty>",
824 authzid ? authzid : "<empty>" );
826 Debug( LDAP_DEBUG_ARGS, "SASL Authorize [conn=%ld]: "
827 "authcid=\"%s\" authzid=\"%s\"\n",
828 (long) (conn ? conn->c_connid : -1),
829 authcid ? authcid : "<empty>",
830 authzid ? authzid : "<empty>" );
833 /* Figure out how much data we have for the dn */
834 rc = sasl_getprop( conn->c_sasl_authctx, SASL_REALM, (void **)&realm );
835 if( rc != SASL_OK && rc != SASL_NOTDONE ) {
837 LDAP_LOG( TRANSPORT, ERR,
838 "slap_sasl_authorize: getprop(REALM) failed.\n", 0, 0, 0 );
840 Debug(LDAP_DEBUG_TRACE,
841 "authorize: getprop(REALM) failed!\n", 0,0,0);
843 *errstr = "Could not extract realm";
847 /* Convert the identities to DN's. If no authzid was given, client will
848 be bound as the DN matching their username */
849 rc = slap_sasl_getdn( conn, NULL, (char *)authcid, 0, realm,
850 &authcDN, SLAP_GETDN_AUTHCID );
851 if( rc != LDAP_SUCCESS ) {
852 *errstr = ldap_err2string( rc );
855 if( ( authzid == NULL ) || !strcmp( authcid,authzid ) ) {
857 LDAP_LOG( TRANSPORT, ENTRY,
858 "slap_sasl_authorize: conn %d Using authcDN=%s\n",
859 conn ? conn->c_connid : -1, authcDN.bv_val, 0 );
861 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
862 "Using authcDN=%s\n", (long) (conn ? conn->c_connid : -1), authcDN.bv_val,0 );
865 conn->c_sasl_dn = authcDN;
868 rc = slap_sasl_getdn( conn, NULL, (char *)authzid, 0, realm,
869 &authzDN, SLAP_GETDN_AUTHZID );
870 if( rc != LDAP_SUCCESS ) {
871 ch_free( authcDN.bv_val );
872 *errstr = ldap_err2string( rc );
876 rc = slap_sasl_authorized(conn->c_sasl_bindop, &authcDN, &authzDN );
877 ch_free( authcDN.bv_val );
880 LDAP_LOG( TRANSPORT, INFO,
881 "slap_sasl_authorize: conn %ld authorization disallowed (%d)\n",
882 (long)(conn ? conn->c_connid : -1), rc, 0 );
884 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
885 " authorization disallowed (%d)\n",
886 (long) (conn ? conn->c_connid : -1), rc, 0 );
889 *errstr = "not authorized";
890 ch_free( authzDN.bv_val );
893 conn->c_sasl_dn = authzDN;
897 LDAP_LOG( TRANSPORT, RESULTS,
898 "slap_sasl_authorize: conn %d authorization allowed\n",
899 (long)(conn ? conn->c_connid : -1 ), 0, 0 );
901 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
902 " authorization allowed\n",
903 (long) (conn ? conn->c_connid : -1), 0, 0 );
906 if (conn->c_sasl_bindop) {
907 Statslog( LDAP_DEBUG_STATS,
908 "conn=%lu op=%lu BIND authcid=\"%s\"\n",
909 conn->c_connid, conn->c_sasl_bindop->o_opid,
916 #endif /* SASL_VERSION_MAJOR >= 2 */
919 slap_sasl_err2ldap( int saslerr )
928 rc = LDAP_SASL_BIND_IN_PROGRESS;
937 rc = LDAP_AUTH_METHOD_NOT_SUPPORTED;
940 rc = LDAP_INVALID_CREDENTIALS;
943 rc = LDAP_INSUFFICIENT_ACCESS;
947 rc = LDAP_INAPPROPRIATE_AUTH;
958 int slap_sasl_init( void )
960 #ifdef HAVE_CYRUS_SASL
962 static sasl_callback_t server_callbacks[] = {
963 { SASL_CB_LOG, &slap_sasl_log, NULL },
964 { SASL_CB_LIST_END, NULL, NULL }
967 #ifdef HAVE_SASL_VERSION
968 #define SASL_BUILD_VERSION ((SASL_VERSION_MAJOR << 24) |\
969 (SASL_VERSION_MINOR << 16) | SASL_VERSION_STEP)
971 sasl_version( NULL, &rc );
972 if ( ((rc >> 16) != ((SASL_VERSION_MAJOR << 8)|SASL_VERSION_MINOR)) ||
973 (rc & 0xffff) < SASL_VERSION_STEP) {
976 LDAP_LOG( TRANSPORT, INFO,
977 "slap_sasl_init: SASL version mismatch, got %x, wanted %x.\n",
978 rc, SASL_BUILD_VERSION, 0 );
980 Debug( LDAP_DEBUG_ANY,
981 "slap_sasl_init: SASL version mismatch, got %x, wanted %x.\n",
982 rc, SASL_BUILD_VERSION, 0 );
988 /* SASL 2 does its own memory management internally */
989 #if SASL_VERSION_MAJOR < 2
998 ldap_pvt_sasl_mutex_new,
999 ldap_pvt_sasl_mutex_lock,
1000 ldap_pvt_sasl_mutex_unlock,
1001 ldap_pvt_sasl_mutex_dispose );
1003 #if SASL_VERSION_MAJOR >= 2
1004 generic_filter.f_desc = slap_schema.si_ad_objectClass;
1006 sasl_auxprop_add_plugin( "slapd", slap_auxprop_init );
1008 /* should provide callbacks for logging */
1009 /* server name should be configurable */
1010 rc = sasl_server_init( server_callbacks, "slapd" );
1012 if( rc != SASL_OK ) {
1014 LDAP_LOG( TRANSPORT, INFO, "slap_sasl_init: init failed.\n", 0, 0, 0 );
1016 Debug( LDAP_DEBUG_ANY, "sasl_server_init failed\n",
1019 #if SASL_VERSION_MAJOR < 2
1020 /* A no-op used to make sure we linked with Cyrus 1.5 */
1021 sasl_client_auth( NULL, NULL, NULL, 0, NULL, NULL );
1028 LDAP_LOG( TRANSPORT, INFO, "slap_sasl_init: initialized!\n", 0, 0, 0 );
1030 Debug( LDAP_DEBUG_TRACE, "slap_sasl_init: initialized!\n",
1035 /* default security properties */
1036 memset( &sasl_secprops, '\0', sizeof(sasl_secprops) );
1037 sasl_secprops.max_ssf = INT_MAX;
1038 sasl_secprops.maxbufsize = 65536;
1039 sasl_secprops.security_flags = SASL_SEC_NOPLAINTEXT|SASL_SEC_NOANONYMOUS;
1045 int slap_sasl_destroy( void )
1047 #ifdef HAVE_CYRUS_SASL
1050 free( global_host );
1056 int slap_sasl_open( Connection *conn, int reopen )
1058 int cb, sc = LDAP_SUCCESS;
1059 #if SASL_VERSION_MAJOR >= 2
1060 char *ipremoteport = NULL, *iplocalport = NULL;
1063 #ifdef HAVE_CYRUS_SASL
1064 sasl_conn_t *ctx = NULL;
1065 sasl_callback_t *session_callbacks;
1067 assert( conn->c_sasl_authctx == NULL );
1070 assert( conn->c_sasl_extra == NULL );
1073 #if SASL_VERSION_MAJOR >= 2
1074 SLAP_CALLOC( 5, sizeof(sasl_callback_t));
1076 SLAP_CALLOC( 3, sizeof(sasl_callback_t));
1078 if( session_callbacks == NULL ) {
1080 LDAP_LOG( TRANSPORT, ERR,
1081 "slap_sasl_open: SLAP_MALLOC failed", 0, 0, 0 );
1083 Debug( LDAP_DEBUG_ANY,
1084 "slap_sasl_open: SLAP_MALLOC failed", 0, 0, 0 );
1088 conn->c_sasl_extra = session_callbacks;
1090 session_callbacks[cb=0].id = SASL_CB_LOG;
1091 session_callbacks[cb].proc = &slap_sasl_log;
1092 session_callbacks[cb++].context = conn;
1094 session_callbacks[cb].id = SASL_CB_PROXY_POLICY;
1095 session_callbacks[cb].proc = &slap_sasl_authorize;
1096 session_callbacks[cb++].context = conn;
1098 #if SASL_VERSION_MAJOR >= 2
1099 session_callbacks[cb].id = SASL_CB_CANON_USER;
1100 session_callbacks[cb].proc = &slap_sasl_canonicalize;
1101 session_callbacks[cb++].context = conn;
1103 /* XXXX: this should be conditional */
1104 session_callbacks[cb].id = SASL_CB_SERVER_USERDB_CHECKPASS;
1105 session_callbacks[cb].proc = &slap_sasl_checkpass;
1106 session_callbacks[cb++].context = conn;
1109 session_callbacks[cb].id = SASL_CB_LIST_END;
1110 session_callbacks[cb].proc = NULL;
1111 session_callbacks[cb++].context = NULL;
1113 session_callbacks = conn->c_sasl_extra;
1116 conn->c_sasl_layers = 0;
1118 if( global_host == NULL ) {
1119 global_host = ldap_pvt_get_fqdn( NULL );
1122 /* create new SASL context */
1123 #if SASL_VERSION_MAJOR >= 2
1124 if ( conn->c_sock_name.bv_len != 0 &&
1125 strncmp( conn->c_sock_name.bv_val, "IP=", 3 ) == 0) {
1128 iplocalport = ch_strdup( conn->c_sock_name.bv_val + 3 );
1129 /* Convert IPv6 addresses to address;port syntax. */
1130 p = strrchr( iplocalport, ' ' );
1131 /* Convert IPv4 addresses to address;port syntax. */
1132 if ( p == NULL ) p = strchr( iplocalport, ':' );
1137 if ( conn->c_peer_name.bv_len != 0 &&
1138 strncmp( conn->c_peer_name.bv_val, "IP=", 3 ) == 0) {
1141 ipremoteport = ch_strdup( conn->c_peer_name.bv_val + 3 );
1142 /* Convert IPv6 addresses to address;port syntax. */
1143 p = strrchr( ipremoteport, ' ' );
1144 /* Convert IPv4 addresses to address;port syntax. */
1145 if ( p == NULL ) p = strchr( ipremoteport, ':' );
1150 sc = sasl_server_new( "ldap", global_host, global_realm,
1151 iplocalport, ipremoteport, session_callbacks, SASL_SUCCESS_DATA, &ctx );
1152 if ( iplocalport != NULL ) {
1153 ch_free( iplocalport );
1155 if ( ipremoteport != NULL ) {
1156 ch_free( ipremoteport );
1159 sc = sasl_server_new( "ldap", global_host, global_realm,
1160 session_callbacks, SASL_SECURITY_LAYER, &ctx );
1163 if( sc != SASL_OK ) {
1165 LDAP_LOG( TRANSPORT, ERR,
1166 "slap_sasl_open: sasl_server_new failed: %d\n", sc, 0, 0 );
1168 Debug( LDAP_DEBUG_ANY, "sasl_server_new failed: %d\n",
1175 conn->c_sasl_authctx = ctx;
1177 if( sc == SASL_OK ) {
1178 sc = sasl_setprop( ctx,
1179 SASL_SEC_PROPS, &sasl_secprops );
1181 if( sc != SASL_OK ) {
1183 LDAP_LOG( TRANSPORT, ERR,
1184 "slap_sasl_open: sasl_setprop failed: %d \n", sc, 0, 0 );
1186 Debug( LDAP_DEBUG_ANY, "sasl_setprop failed: %d\n",
1190 slap_sasl_close( conn );
1195 sc = slap_sasl_err2ldap( sc );
1200 int slap_sasl_external(
1203 const char *auth_id )
1205 #if SASL_VERSION_MAJOR >= 2
1207 sasl_conn_t *ctx = conn->c_sasl_authctx;
1209 if ( ctx == NULL ) {
1210 return LDAP_UNAVAILABLE;
1213 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
1215 if ( sc != SASL_OK ) {
1219 sc = sasl_setprop( ctx, SASL_AUTH_EXTERNAL, auth_id );
1221 if ( sc != SASL_OK ) {
1225 #elif defined(HAVE_CYRUS_SASL)
1227 sasl_conn_t *ctx = conn->c_sasl_authctx;
1228 sasl_external_properties_t extprops;
1230 if ( ctx == NULL ) {
1231 return LDAP_UNAVAILABLE;
1234 memset( &extprops, '\0', sizeof(extprops) );
1236 extprops.auth_id = (char *) auth_id;
1238 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
1239 (void *) &extprops );
1241 if ( sc != SASL_OK ) {
1246 return LDAP_SUCCESS;
1249 int slap_sasl_reset( Connection *conn )
1251 return LDAP_SUCCESS;
1254 char ** slap_sasl_mechs( Connection *conn )
1256 char **mechs = NULL;
1258 #ifdef HAVE_CYRUS_SASL
1259 sasl_conn_t *ctx = conn->c_sasl_authctx;
1261 if( ctx == NULL ) ctx = conn->c_sasl_sockctx;
1265 SASL_CONST char *mechstr;
1267 sc = sasl_listmech( ctx,
1268 NULL, NULL, ",", NULL,
1269 &mechstr, NULL, NULL );
1271 if( sc != SASL_OK ) {
1273 LDAP_LOG( TRANSPORT, ERR,
1274 "slap_sasl_mechs: sasl_listmech failed: %d\n", sc, 0, 0 );
1276 Debug( LDAP_DEBUG_ANY, "slap_sasl_listmech failed: %d\n",
1283 mechs = ldap_str2charray( mechstr, "," );
1285 #if SASL_VERSION_MAJOR < 2
1294 int slap_sasl_close( Connection *conn )
1296 #ifdef HAVE_CYRUS_SASL
1297 sasl_conn_t *ctx = conn->c_sasl_authctx;
1300 sasl_dispose( &ctx );
1302 if ( conn->c_sasl_sockctx && conn->c_sasl_authctx != conn->c_sasl_sockctx ) {
1303 ctx = conn->c_sasl_sockctx;
1304 sasl_dispose( &ctx );
1307 conn->c_sasl_authctx = NULL;
1308 conn->c_sasl_sockctx = NULL;
1309 conn->c_sasl_done = 0;
1311 free( conn->c_sasl_extra );
1312 conn->c_sasl_extra = NULL;
1315 return LDAP_SUCCESS;
1318 int slap_sasl_bind( Operation *op, SlapReply *rs )
1320 #ifdef HAVE_CYRUS_SASL
1321 sasl_conn_t *ctx = op->o_conn->c_sasl_authctx;
1322 struct berval response;
1323 unsigned reslen = 0;
1327 LDAP_LOG( TRANSPORT, ENTRY,
1328 "sasl_bind: dn=\"%s\" mech=%s datalen=%ld\n",
1329 op->o_req_dn.bv_len ? op->o_req_dn.bv_val : "",
1330 op->o_conn->c_sasl_bind_in_progress ? "<continuing>" :
1331 op->o_conn->c_sasl_bind_mech.bv_val,
1332 op->orb_cred.bv_len );
1334 Debug(LDAP_DEBUG_ARGS,
1335 "==> sasl_bind: dn=\"%s\" mech=%s datalen=%ld\n",
1336 op->o_req_dn.bv_len ? op->o_req_dn.bv_val : "",
1337 op->o_conn->c_sasl_bind_in_progress ? "<continuing>" :
1338 op->o_conn->c_sasl_bind_mech.bv_val,
1339 op->orb_cred.bv_len );
1344 send_ldap_error( op, rs, LDAP_UNAVAILABLE,
1345 "SASL unavailable on this session" );
1349 #if SASL_VERSION_MAJOR >= 2
1350 #define START( ctx, mech, cred, clen, resp, rlen, err ) \
1351 sasl_server_start( ctx, mech, cred, clen, resp, rlen )
1352 #define STEP( ctx, cred, clen, resp, rlen, err ) \
1353 sasl_server_step( ctx, cred, clen, resp, rlen )
1355 #define START( ctx, mech, cred, clen, resp, rlen, err ) \
1356 sasl_server_start( ctx, mech, cred, clen, resp, rlen, err )
1357 #define STEP( ctx, cred, clen, resp, rlen, err ) \
1358 sasl_server_step( ctx, cred, clen, resp, rlen, err )
1361 if ( !op->o_conn->c_sasl_bind_in_progress ) {
1362 /* If we already authenticated once, must use a new context */
1363 if ( op->o_conn->c_sasl_done ) {
1365 const char *authid = NULL;
1366 #if SASL_VERSION_MAJOR >= 2
1367 sasl_getprop( ctx, SASL_SSF_EXTERNAL, (void *)&ssf );
1368 sasl_getprop( ctx, SASL_AUTH_EXTERNAL, (void *)&authid );
1369 if ( authid ) authid = ch_strdup( authid );
1371 if ( ctx != op->o_conn->c_sasl_sockctx ) {
1372 sasl_dispose( &ctx );
1374 op->o_conn->c_sasl_authctx = NULL;
1376 slap_sasl_open( op->o_conn, 1 );
1377 ctx = op->o_conn->c_sasl_authctx;
1378 #if SASL_VERSION_MAJOR >= 2
1380 sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
1381 sasl_setprop( ctx, SASL_AUTH_EXTERNAL, authid );
1382 ch_free( (char *)authid );
1387 op->o_conn->c_sasl_bind_mech.bv_val,
1388 op->orb_cred.bv_val, op->orb_cred.bv_len,
1389 (SASL_CONST char **)&response.bv_val, &reslen, &rs->sr_text );
1393 op->orb_cred.bv_val, op->orb_cred.bv_len,
1394 (SASL_CONST char **)&response.bv_val, &reslen, &rs->sr_text );
1397 response.bv_len = reslen;
1399 if ( sc == SASL_OK ) {
1400 sasl_ssf_t *ssf = NULL;
1402 op->orb_edn = op->o_conn->c_sasl_dn;
1403 op->o_conn->c_sasl_dn.bv_val = NULL;
1404 op->o_conn->c_sasl_dn.bv_len = 0;
1405 op->o_conn->c_sasl_done = 1;
1407 rs->sr_err = LDAP_SUCCESS;
1409 (void) sasl_getprop( ctx, SASL_SSF, (void *)&ssf );
1410 op->orb_ssf = ssf ? *ssf : 0;
1414 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1415 op->o_conn->c_sasl_layers++;
1417 /* If there's an old layer, set sockctx to NULL to
1418 * tell connection_read() to wait for us to finish.
1419 * Otherwise there is a race condition: we have to
1420 * send the Bind response using the old security
1421 * context and then remove it before reading any
1424 if ( op->o_conn->c_sasl_sockctx ) {
1425 ctx = op->o_conn->c_sasl_sockctx;
1426 op->o_conn->c_sasl_sockctx = NULL;
1428 op->o_conn->c_sasl_sockctx = op->o_conn->c_sasl_authctx;
1430 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1433 /* Must send response using old security layer */
1434 if (response.bv_len) rs->sr_sasldata = &response;
1435 send_ldap_sasl( op, rs );
1437 /* Now dispose of the old security layer.
1440 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1441 ldap_pvt_sasl_remove( op->o_conn->c_sb );
1442 op->o_conn->c_sasl_sockctx = op->o_conn->c_sasl_authctx;
1443 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1444 sasl_dispose( &ctx );
1446 } else if ( sc == SASL_CONTINUE ) {
1447 rs->sr_err = LDAP_SASL_BIND_IN_PROGRESS,
1448 rs->sr_sasldata = &response;
1449 send_ldap_sasl( op, rs );
1452 #if SASL_VERSION_MAJOR >= 2
1453 rs->sr_text = sasl_errdetail( ctx );
1455 rs->sr_err = slap_sasl_err2ldap( sc ),
1456 send_ldap_result( op, rs );
1459 #if SASL_VERSION_MAJOR < 2
1460 if( response.bv_len ) {
1461 ch_free( response.bv_val );
1466 LDAP_LOG( TRANSPORT, RESULTS, "slap_sasl_bind: rc=%d\n", rs->sr_err, 0, 0 );
1468 Debug(LDAP_DEBUG_TRACE, "<== slap_sasl_bind: rc=%d\n", rs->sr_err, 0, 0);
1473 send_ldap_error( op, rs, LDAP_UNAVAILABLE,
1474 "SASL not supported" );
1480 char* slap_sasl_secprops( const char *in )
1482 #ifdef HAVE_CYRUS_SASL
1483 int rc = ldap_pvt_sasl_secprops( in, &sasl_secprops );
1485 return rc == LDAP_SUCCESS ? NULL : "Invalid security properties";
1487 return "SASL not supported";
1491 #ifdef HAVE_CYRUS_SASL
1493 slap_sasl_setpass( Operation *op, SlapReply *rs )
1495 struct berval id = { 0, NULL }; /* needs to come from connection */
1496 struct berval new = { 0, NULL };
1497 struct berval old = { 0, NULL };
1499 assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->ore_reqoid ) == 0 );
1501 rs->sr_err = sasl_getprop( op->o_conn->c_sasl_authctx, SASL_USERNAME,
1502 (SASL_CONST void **)&id.bv_val );
1504 if( rs->sr_err != SASL_OK ) {
1505 rs->sr_text = "unable to retrieve SASL username";
1506 rs->sr_err = LDAP_OTHER;
1511 LDAP_LOG( BACKEND, ENTRY,
1512 "slap_sasl_setpass: \"%s\"\n",
1513 id.bv_val ? id.bv_val : "", 0, 0);
1515 Debug( LDAP_DEBUG_ARGS, "==> slap_sasl_setpass: \"%s\"\n",
1516 id.bv_val ? id.bv_val : "", 0, 0 );
1519 rs->sr_err = slap_passwd_parse( op->ore_reqdata,
1520 NULL, &old, &new, &rs->sr_text );
1522 if( rs->sr_err != LDAP_SUCCESS ) {
1526 if( new.bv_len == 0 ) {
1527 slap_passwd_generate(&new);
1529 if( new.bv_len == 0 ) {
1530 rs->sr_text = "password generation failed.";
1531 rs->sr_err = LDAP_OTHER;
1535 rs->sr_rspdata = slap_passwd_return( &new );
1538 #if SASL_VERSION_MAJOR < 2
1539 rs->sr_err = sasl_setpass( op->o_conn->c_sasl_authctx,
1540 id.bv_val, new.bv_val, new.bv_len, 0, &rs->sr_text );
1542 rs->sr_err = sasl_setpass( op->o_conn->c_sasl_authctx, id.bv_val,
1543 new.bv_val, new.bv_len, old.bv_val, old.bv_len, 0 );
1544 if( rs->sr_err != SASL_OK ) {
1545 rs->sr_text = sasl_errdetail( op->o_conn->c_sasl_authctx );
1548 switch(rs->sr_err) {
1550 rs->sr_err = LDAP_SUCCESS;
1560 rs->sr_err = LDAP_OTHER;
1566 #endif /* HAVE_CYRUS_SASL */
1568 /* Take any sort of identity string and return a DN with the "dn:" prefix. The
1569 string returned in *dn is in its own allocated memory, and must be free'd
1570 by the calling process.
1571 -Mark Adamson, Carnegie Mellon
1573 The "dn:" prefix is no longer used anywhere inside slapd. It is only used
1574 on strings passed in directly from SASL.
1575 -Howard Chu, Symas Corp.
1582 static struct berval ext_bv = BER_BVC( "EXTERNAL" );
1584 int slap_sasl_getdn( Connection *conn, Operation *op, char *id, int len,
1585 char *user_realm, struct berval *dn, int flags )
1588 int rc, is_dn = SET_NONE, do_norm = 1;
1592 LDAP_LOG( TRANSPORT, ENTRY,
1593 "slap_sasl_getdn: conn %d id=%s [len=%d]\n",
1594 conn ? conn->c_connid : -1, id ? (*id ? id : "<empty>") : "NULL", len );
1596 Debug( LDAP_DEBUG_ARGS, "slap_sasl_getdn: id=%s [len=%d]\n",
1597 id ? ( *id ? id : "<empty>" ) : "NULL", len, 0 );
1601 op = conn->c_sasl_bindop;
1608 if ( len == 0 ) len = strlen( id );
1610 /* Blatantly anonymous ID */
1611 if ( len == sizeof("anonymous") - 1 &&
1612 !strcasecmp( id, "anonymous" ) ) {
1613 return( LDAP_SUCCESS );
1619 /* An authcID needs to be converted to authzID form. Set the
1620 * values directly into *dn; they will be normalized later. (and
1621 * normalizing always makes a new copy.) An ID from a TLS certificate
1622 * is already normalized, so copy it and skip normalization.
1624 if( flags & SLAP_GETDN_AUTHCID ) {
1625 if( conn->c_sasl_bind_mech.bv_len == ext_bv.bv_len &&
1626 strcasecmp( ext_bv.bv_val, conn->c_sasl_bind_mech.bv_val ) == 0 )
1628 /* EXTERNAL DNs are already normalized */
1631 ber_str2bv_x( id, len, 1, dn, op->o_tmpmemctx );
1634 /* convert to u:<username> form */
1640 if( is_dn == SET_NONE ) {
1641 if( !strncasecmp( id, "u:", sizeof("u:")-1 )) {
1645 } else if ( !strncasecmp( id, "dn:", sizeof("dn:")-1) ) {
1652 /* No other possibilities from here */
1653 if( is_dn == SET_NONE ) {
1656 return( LDAP_INAPPROPRIATE_AUTH );
1659 /* Username strings */
1660 if( is_dn == SET_U ) {
1662 len = dn->bv_len + sizeof("uid=")-1 + sizeof(",cn=auth")-1;
1664 /* username may have embedded realm name */
1665 if( ( realm = strchr( dn->bv_val, '@') ) ) {
1667 len += sizeof(",cn=")-2;
1668 } else if( user_realm && *user_realm ) {
1669 len += strlen( user_realm ) + sizeof(",cn=")-1;
1672 if( conn->c_sasl_bind_mech.bv_len ) {
1673 len += conn->c_sasl_bind_mech.bv_len + sizeof(",cn=")-1;
1676 /* Build the new dn */
1678 dn->bv_val = sl_malloc( len+1, op->o_tmpmemctx );
1679 if( dn->bv_val == NULL ) {
1681 LDAP_LOG( TRANSPORT, ERR,
1682 "slap_sasl_getdn: SLAP_MALLOC failed", 0, 0, 0 );
1684 Debug( LDAP_DEBUG_ANY,
1685 "slap_sasl_getdn: SLAP_MALLOC failed", 0, 0, 0 );
1689 p = lutil_strcopy( dn->bv_val, "uid=" );
1690 p = lutil_strncopy( p, c1, dn->bv_len );
1693 int rlen = dn->bv_len - ( realm - c1 );
1694 p = lutil_strcopy( p, ",cn=" );
1695 p = lutil_strncopy( p, realm, rlen );
1697 } else if( user_realm && *user_realm ) {
1698 p = lutil_strcopy( p, ",cn=" );
1699 p = lutil_strcopy( p, user_realm );
1702 if( conn->c_sasl_bind_mech.bv_len ) {
1703 p = lutil_strcopy( p, ",cn=" );
1704 p = lutil_strcopy( p, conn->c_sasl_bind_mech.bv_val );
1706 p = lutil_strcopy( p, ",cn=auth" );
1707 dn->bv_len = p - dn->bv_val;
1710 LDAP_LOG( TRANSPORT, ENTRY,
1711 "slap_sasl_getdn: u:id converted to %s.\n", dn->bv_val, 0, 0 );
1713 Debug( LDAP_DEBUG_TRACE, "getdn: u:id converted to %s\n", dn->bv_val,0,0 );
1717 /* Dup the DN in any case, so we don't risk
1718 * leaks or dangling pointers later,
1719 * and the DN value is '\0' terminated */
1720 ber_dupbv_x( &dn2, dn, op->o_tmpmemctx );
1721 dn->bv_val = dn2.bv_val;
1724 /* All strings are in DN form now. Normalize if needed. */
1726 rc = dnNormalize( 0, NULL, NULL, dn, &dn2, op->o_tmpmemctx );
1728 /* User DNs were constructed above and must be freed now */
1729 sl_free( dn->bv_val, op->o_tmpmemctx );
1731 if ( rc != LDAP_SUCCESS ) {
1739 /* Run thru regexp */
1740 slap_sasl2dn( op, dn, &dn2 );
1742 sl_free( dn->bv_val, op->o_tmpmemctx );
1745 LDAP_LOG( TRANSPORT, ENTRY,
1746 "slap_sasl_getdn: dn:id converted to %s.\n", dn->bv_val, 0, 0 );
1748 Debug( LDAP_DEBUG_TRACE, "getdn: dn:id converted to %s\n",
1753 return( LDAP_SUCCESS );