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_connid = conn->c_connid;
445 op.ors_scope = LDAP_SCOPE_BASE;
446 op.ors_deref = LDAP_DEREF_NEVER;
448 op.ors_filter = &generic_filter;
450 op.o_bd->be_search( &op, &rs );
455 static sasl_auxprop_plug_t slap_auxprop_plugin = {
458 NULL, /* glob_context */
459 NULL, /* auxprop_free */
467 const sasl_utils_t *utils,
470 sasl_auxprop_plug_t **plug,
471 const char *plugname)
473 if ( !out_version | !plug ) return SASL_BADPARAM;
475 if ( max_version < SASL_AUXPROP_PLUG_VERSION ) return SASL_BADVERS;
477 *out_version = SASL_AUXPROP_PLUG_VERSION;
478 *plug = &slap_auxprop_plugin;
482 typedef struct checkpass_info {
488 sasl_cb_checkpass( Operation *op, SlapReply *rs )
490 slap_callback *tmp = op->o_callback;
491 checkpass_info *ci = tmp->sc_private;
495 if (rs->sr_type != REP_SEARCH) return 0;
497 ci->rc = SASL_NOVERIFY;
499 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_userPassword );
501 if ( ! access_allowed( op, rs->sr_entry, slap_schema.si_ad_userPassword,
502 NULL, ACL_AUTH, NULL ) ) return 0;
504 for ( bv = a->a_vals; bv->bv_val != NULL; bv++ ) {
505 if ( !lutil_passwd( bv, &ci->cred, NULL, &rs->sr_text ) ) {
517 const char *username,
520 struct propctx *propctx)
522 Connection *conn = (Connection *)context;
529 /* SASL will fallback to its own mechanisms if we don't
530 * find an answer here.
533 rc = slap_sasl_getdn( conn, NULL, (char *)username, 0, NULL, &op.o_req_ndn,
534 SLAP_GETDN_AUTHCID );
535 if ( rc != LDAP_SUCCESS ) {
536 sasl_seterror( sconn, 0, ldap_err2string( rc ) );
540 if ( op.o_req_ndn.bv_len == 0 ) {
541 sasl_seterror( sconn, 0,
542 "No password is associated with the Root DSE" );
543 if ( op.o_req_ndn.bv_val != NULL ) {
544 ch_free( op.o_req_ndn.bv_val );
549 op.o_bd = select_backend( &op.o_req_ndn, 0, 1 );
550 if ( op.o_bd && op.o_bd->be_search ) {
551 slap_callback cb = { sasl_cb_checkpass, NULL };
552 SlapReply rs = {REP_RESULT};
554 ci.cred.bv_val = (char *)pass;
555 ci.cred.bv_len = passlen;
558 op.o_tag = LDAP_REQ_SEARCH;
559 op.o_protocol = LDAP_VERSION3;
560 op.o_ndn = conn->c_ndn;
562 op.o_time = slap_get_time();
563 op.o_do_not_cache = 1;
564 op.o_is_auth_check = 1;
565 op.o_threadctx = conn->c_sasl_bindop->o_threadctx;
566 op.o_tmpmemctx = conn->c_sasl_bindop->o_tmpmemctx;
567 op.o_tmpmfuncs = conn->c_sasl_bindop->o_tmpmfuncs;
569 op.o_connid = conn->c_connid;
570 op.ors_scope = LDAP_SCOPE_BASE;
571 op.ors_deref = LDAP_DEREF_NEVER;
573 op.ors_filter = &generic_filter;
575 op.o_bd->be_search( &op, &rs );
577 if ( ci.rc != SASL_OK ) {
578 sasl_seterror( sconn, 0,
579 ldap_err2string( LDAP_INVALID_CREDENTIALS ) );
582 ch_free( op.o_req_ndn.bv_val );
587 /* Convert a SASL authcid or authzid into a DN. Store the DN in an
588 * auxiliary property, so that we can refer to it in sasl_authorize
589 * without interfering with anything else. Also, the SASL username
590 * buffer is constrained to 256 characters, and our DNs could be
591 * much longer (totally arbitrary length)...
594 slap_sasl_canonicalize(
600 const char *user_realm,
605 Connection *conn = (Connection *)context;
606 struct propctx *props = sasl_auxprop_getctx( sconn );
607 struct propval auxvals[3];
610 const char *names[2];
615 LDAP_LOG( TRANSPORT, ENTRY,
616 "slap_sasl_canonicalize: conn %d %s=\"%s\"\n",
617 conn ? conn->c_connid : -1,
618 (flags & SASL_CU_AUTHID) ? "authcid" : "authzid",
619 in ? in : "<empty>");
621 Debug( LDAP_DEBUG_ARGS, "SASL Canonicalize [conn=%ld]: %s=\"%s\"\n",
622 conn ? conn->c_connid : -1,
623 (flags & SASL_CU_AUTHID) ? "authcid" : "authzid",
624 in ? in : "<empty>");
627 /* If name is too big, just truncate. We don't care, we're
628 * using DNs, not the usernames.
630 if ( inlen > out_max )
633 /* See if we need to add request, can only do it once */
634 prop_getnames( props, slap_propnames, auxvals );
635 if ( !auxvals[0].name )
636 prop_request( props, slap_propnames );
638 if ( flags & SASL_CU_AUTHID )
643 /* Need to store the Connection for auxprop_lookup */
644 if ( !auxvals[PROP_CONN].values ) {
645 names[0] = slap_propnames[PROP_CONN];
647 prop_set( props, names[0], (char *)&conn, sizeof( conn ) );
650 /* Already been here? */
651 if ( auxvals[which].values )
654 /* Normally we require an authzID to have a u: or dn: prefix.
655 * However, SASL frequently gives us an authzID that is just
656 * an exact copy of the authcID, without a prefix. We need to
657 * detect and allow this condition. If SASL calls canonicalize
658 * with SASL_CU_AUTHID|SASL_CU_AUTHZID this is a no-brainer.
659 * But if it's broken into two calls, we need to remember the
660 * authcID so that we can compare the authzID later. We store
661 * the authcID temporarily in conn->c_sasl_dn. We necessarily
662 * finish Canonicalizing before Authorizing, so there is no
663 * conflict with slap_sasl_authorize's use of this temp var.
665 * The SASL EXTERNAL mech is backwards from all the other mechs,
666 * it does authzID before the authcID. If we see that authzID
667 * has already been done, don't do anything special with authcID.
669 if ( flags == SASL_CU_AUTHID && !auxvals[PROP_AUTHZ].values ) {
670 conn->c_sasl_dn.bv_val = (char *) in;
671 } else if ( flags == SASL_CU_AUTHZID && conn->c_sasl_dn.bv_val ) {
672 rc = strcmp( in, conn->c_sasl_dn.bv_val );
673 conn->c_sasl_dn.bv_val = NULL;
674 /* They were equal, no work needed */
675 if ( !rc ) goto done;
678 rc = slap_sasl_getdn( conn, NULL, (char *)in, inlen, (char *)user_realm, &dn,
679 (flags & SASL_CU_AUTHID) ? SLAP_GETDN_AUTHCID : SLAP_GETDN_AUTHZID );
680 if ( rc != LDAP_SUCCESS ) {
681 sasl_seterror( sconn, 0, ldap_err2string( rc ) );
685 names[0] = slap_propnames[which];
688 prop_set( props, names[0], (char *)&dn, sizeof( dn ) );
691 LDAP_LOG( TRANSPORT, ENTRY,
692 "slap_sasl_canonicalize: conn %d %s=\"%s\"\n",
693 conn ? conn->c_connid : -1, names[0]+1,
694 dn.bv_val ? dn.bv_val : "<EMPTY>" );
696 Debug( LDAP_DEBUG_ARGS, "SASL Canonicalize [conn=%ld]: %s=\"%s\"\n",
697 conn ? conn->c_connid : -1, names[0]+1,
698 dn.bv_val ? dn.bv_val : "<EMPTY>" );
702 AC_MEMCPY( out, in, inlen );
714 char *requested_user,
718 const char *def_realm,
720 struct propctx *props)
722 Connection *conn = (Connection *)context;
723 struct propval auxvals[3];
724 struct berval authcDN, authzDN;
728 LDAP_LOG( TRANSPORT, ENTRY,
729 "slap_sasl_authorize: conn %d authcid=\"%s\" authzid=\"%s\"\n",
730 conn ? conn->c_connid : -1, auth_identity, requested_user);
732 Debug( LDAP_DEBUG_ARGS, "SASL Authorize [conn=%ld]: "
733 "authcid=\"%s\" authzid=\"%s\"\n",
734 conn ? conn->c_connid : -1, auth_identity, requested_user );
736 if ( conn->c_sasl_dn.bv_val ) {
737 ch_free( conn->c_sasl_dn.bv_val );
738 conn->c_sasl_dn.bv_val = NULL;
739 conn->c_sasl_dn.bv_len = 0;
743 prop_getnames( props, slap_propnames+1, auxvals );
745 AC_MEMCPY( &authcDN, auxvals[0].values[0], sizeof(authcDN) );
747 /* Nothing to do if no authzID was given */
748 if ( !auxvals[1].name || !auxvals[1].values ) {
749 conn->c_sasl_dn = authcDN;
753 AC_MEMCPY( &authzDN, auxvals[1].values[0], sizeof(authzDN) );
755 rc = slap_sasl_authorized( conn->c_sasl_bindop, &authcDN, &authzDN );
756 ch_free( authcDN.bv_val );
757 if ( rc != LDAP_SUCCESS ) {
759 LDAP_LOG( TRANSPORT, INFO,
760 "slap_sasl_authorize: conn %ld authorization disallowed (%d)\n",
761 (long)(conn ? conn->c_connid : -1), rc, 0 );
763 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
764 " authorization disallowed (%d)\n",
765 (long) (conn ? conn->c_connid : -1), rc, 0 );
768 sasl_seterror( sconn, 0, "not authorized" );
769 ch_free( authzDN.bv_val );
773 conn->c_sasl_dn = authzDN;
775 if (conn->c_sasl_bindop) {
776 Statslog( LDAP_DEBUG_STATS,
777 "conn=%lu op=%lu BIND authcid=\"%s\"\n",
778 conn->c_connid, conn->c_sasl_bindop->o_opid,
779 auth_identity, 0, 0);
783 LDAP_LOG( TRANSPORT, ENTRY,
784 "slap_sasl_authorize: conn %d authorization allowed\n",
785 (long)(conn ? conn->c_connid : -1), 0, 0 );
787 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
788 " authorization allowed\n",
789 (long) (conn ? conn->c_connid : -1), 0, 0 );
802 struct berval authcDN, authzDN;
804 Connection *conn = context;
808 if ( conn->c_sasl_dn.bv_val ) {
809 ch_free( conn->c_sasl_dn.bv_val );
810 conn->c_sasl_dn.bv_val = NULL;
811 conn->c_sasl_dn.bv_len = 0;
815 LDAP_LOG( TRANSPORT, ENTRY,
816 "slap_sasl_authorize: conn %d authcid=\"%s\" authzid=\"%s\"\n",
817 conn ? conn->c_connid : -1, authcid ? authcid : "<empty>",
818 authzid ? authzid : "<empty>" );
820 Debug( LDAP_DEBUG_ARGS, "SASL Authorize [conn=%ld]: "
821 "authcid=\"%s\" authzid=\"%s\"\n",
822 (long) (conn ? conn->c_connid : -1),
823 authcid ? authcid : "<empty>",
824 authzid ? authzid : "<empty>" );
827 /* Figure out how much data we have for the dn */
828 rc = sasl_getprop( conn->c_sasl_authctx, SASL_REALM, (void **)&realm );
829 if( rc != SASL_OK && rc != SASL_NOTDONE ) {
831 LDAP_LOG( TRANSPORT, ERR,
832 "slap_sasl_authorize: getprop(REALM) failed.\n", 0, 0, 0 );
834 Debug(LDAP_DEBUG_TRACE,
835 "authorize: getprop(REALM) failed!\n", 0,0,0);
837 *errstr = "Could not extract realm";
841 /* Convert the identities to DN's. If no authzid was given, client will
842 be bound as the DN matching their username */
843 rc = slap_sasl_getdn( conn, NULL, (char *)authcid, 0, realm,
844 &authcDN, SLAP_GETDN_AUTHCID );
845 if( rc != LDAP_SUCCESS ) {
846 *errstr = ldap_err2string( rc );
849 if( ( authzid == NULL ) || !strcmp( authcid,authzid ) ) {
851 LDAP_LOG( TRANSPORT, ENTRY,
852 "slap_sasl_authorize: conn %d Using authcDN=%s\n",
853 conn ? conn->c_connid : -1, authcDN.bv_val, 0 );
855 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
856 "Using authcDN=%s\n", (long) (conn ? conn->c_connid : -1), authcDN.bv_val,0 );
859 conn->c_sasl_dn = authcDN;
862 rc = slap_sasl_getdn( conn, NULL, (char *)authzid, 0, realm,
863 &authzDN, SLAP_GETDN_AUTHZID );
864 if( rc != LDAP_SUCCESS ) {
865 ch_free( authcDN.bv_val );
866 *errstr = ldap_err2string( rc );
870 rc = slap_sasl_authorized(conn->c_sasl_bindop, &authcDN, &authzDN );
871 ch_free( authcDN.bv_val );
874 LDAP_LOG( TRANSPORT, INFO,
875 "slap_sasl_authorize: conn %ld authorization disallowed (%d)\n",
876 (long)(conn ? conn->c_connid : -1), rc, 0 );
878 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
879 " authorization disallowed (%d)\n",
880 (long) (conn ? conn->c_connid : -1), rc, 0 );
883 *errstr = "not authorized";
884 ch_free( authzDN.bv_val );
887 conn->c_sasl_dn = authzDN;
891 LDAP_LOG( TRANSPORT, RESULTS,
892 "slap_sasl_authorize: conn %d authorization allowed\n",
893 (long)(conn ? conn->c_connid : -1 ), 0, 0 );
895 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
896 " authorization allowed\n",
897 (long) (conn ? conn->c_connid : -1), 0, 0 );
900 if (conn->c_sasl_bindop) {
901 Statslog( LDAP_DEBUG_STATS,
902 "conn=%lu op=%lu BIND authcid=\"%s\"\n",
903 conn->c_connid, conn->c_sasl_bindop->o_opid,
910 #endif /* SASL_VERSION_MAJOR >= 2 */
913 slap_sasl_err2ldap( int saslerr )
922 rc = LDAP_SASL_BIND_IN_PROGRESS;
931 rc = LDAP_AUTH_METHOD_NOT_SUPPORTED;
934 rc = LDAP_INVALID_CREDENTIALS;
937 rc = LDAP_INSUFFICIENT_ACCESS;
941 rc = LDAP_INAPPROPRIATE_AUTH;
952 int slap_sasl_init( void )
954 #ifdef HAVE_CYRUS_SASL
956 static sasl_callback_t server_callbacks[] = {
957 { SASL_CB_LOG, &slap_sasl_log, NULL },
958 { SASL_CB_LIST_END, NULL, NULL }
961 #ifdef HAVE_SASL_VERSION
962 #define SASL_BUILD_VERSION ((SASL_VERSION_MAJOR << 24) |\
963 (SASL_VERSION_MINOR << 16) | SASL_VERSION_STEP)
965 sasl_version( NULL, &rc );
966 if ( ((rc >> 16) != ((SASL_VERSION_MAJOR << 8)|SASL_VERSION_MINOR)) ||
967 (rc & 0xffff) < SASL_VERSION_STEP) {
970 LDAP_LOG( TRANSPORT, INFO,
971 "slap_sasl_init: SASL version mismatch, got %x, wanted %x.\n",
972 rc, SASL_BUILD_VERSION, 0 );
974 Debug( LDAP_DEBUG_ANY,
975 "slap_sasl_init: SASL version mismatch, got %x, wanted %x.\n",
976 rc, SASL_BUILD_VERSION, 0 );
982 /* SASL 2 does its own memory management internally */
983 #if SASL_VERSION_MAJOR < 2
992 ldap_pvt_sasl_mutex_new,
993 ldap_pvt_sasl_mutex_lock,
994 ldap_pvt_sasl_mutex_unlock,
995 ldap_pvt_sasl_mutex_dispose );
997 #if SASL_VERSION_MAJOR >= 2
998 generic_filter.f_desc = slap_schema.si_ad_objectClass;
1000 sasl_auxprop_add_plugin( "slapd", slap_auxprop_init );
1002 /* should provide callbacks for logging */
1003 /* server name should be configurable */
1004 rc = sasl_server_init( server_callbacks, "slapd" );
1006 if( rc != SASL_OK ) {
1008 LDAP_LOG( TRANSPORT, INFO, "slap_sasl_init: init failed.\n", 0, 0, 0 );
1010 Debug( LDAP_DEBUG_ANY, "sasl_server_init failed\n",
1013 #if SASL_VERSION_MAJOR < 2
1014 /* A no-op used to make sure we linked with Cyrus 1.5 */
1015 sasl_client_auth( NULL, NULL, NULL, 0, NULL, NULL );
1022 LDAP_LOG( TRANSPORT, INFO, "slap_sasl_init: initialized!\n", 0, 0, 0 );
1024 Debug( LDAP_DEBUG_TRACE, "slap_sasl_init: initialized!\n",
1029 /* default security properties */
1030 memset( &sasl_secprops, '\0', sizeof(sasl_secprops) );
1031 sasl_secprops.max_ssf = INT_MAX;
1032 sasl_secprops.maxbufsize = 65536;
1033 sasl_secprops.security_flags = SASL_SEC_NOPLAINTEXT|SASL_SEC_NOANONYMOUS;
1039 int slap_sasl_destroy( void )
1041 #ifdef HAVE_CYRUS_SASL
1044 free( global_host );
1050 int slap_sasl_open( Connection *conn, int reopen )
1052 int cb, sc = LDAP_SUCCESS;
1053 #if SASL_VERSION_MAJOR >= 2
1054 char *ipremoteport = NULL, *iplocalport = NULL;
1057 #ifdef HAVE_CYRUS_SASL
1058 sasl_conn_t *ctx = NULL;
1059 sasl_callback_t *session_callbacks;
1061 assert( conn->c_sasl_authctx == NULL );
1064 assert( conn->c_sasl_extra == NULL );
1067 #if SASL_VERSION_MAJOR >= 2
1068 SLAP_CALLOC( 5, sizeof(sasl_callback_t));
1070 SLAP_CALLOC( 3, sizeof(sasl_callback_t));
1072 if( session_callbacks == NULL ) {
1074 LDAP_LOG( TRANSPORT, ERR,
1075 "slap_sasl_open: SLAP_MALLOC failed", 0, 0, 0 );
1077 Debug( LDAP_DEBUG_ANY,
1078 "slap_sasl_open: SLAP_MALLOC failed", 0, 0, 0 );
1082 conn->c_sasl_extra = session_callbacks;
1084 session_callbacks[cb=0].id = SASL_CB_LOG;
1085 session_callbacks[cb].proc = &slap_sasl_log;
1086 session_callbacks[cb++].context = conn;
1088 session_callbacks[cb].id = SASL_CB_PROXY_POLICY;
1089 session_callbacks[cb].proc = &slap_sasl_authorize;
1090 session_callbacks[cb++].context = conn;
1092 #if SASL_VERSION_MAJOR >= 2
1093 session_callbacks[cb].id = SASL_CB_CANON_USER;
1094 session_callbacks[cb].proc = &slap_sasl_canonicalize;
1095 session_callbacks[cb++].context = conn;
1097 /* XXXX: this should be conditional */
1098 session_callbacks[cb].id = SASL_CB_SERVER_USERDB_CHECKPASS;
1099 session_callbacks[cb].proc = &slap_sasl_checkpass;
1100 session_callbacks[cb++].context = conn;
1103 session_callbacks[cb].id = SASL_CB_LIST_END;
1104 session_callbacks[cb].proc = NULL;
1105 session_callbacks[cb++].context = NULL;
1107 session_callbacks = conn->c_sasl_extra;
1110 conn->c_sasl_layers = 0;
1112 if( global_host == NULL ) {
1113 global_host = ldap_pvt_get_fqdn( NULL );
1116 /* create new SASL context */
1117 #if SASL_VERSION_MAJOR >= 2
1118 if ( conn->c_sock_name.bv_len != 0 &&
1119 strncmp( conn->c_sock_name.bv_val, "IP=", 3 ) == 0) {
1122 iplocalport = ch_strdup( conn->c_sock_name.bv_val + 3 );
1123 /* Convert IPv6 addresses to address;port syntax. */
1124 p = strrchr( iplocalport, ' ' );
1125 /* Convert IPv4 addresses to address;port syntax. */
1126 if ( p == NULL ) p = strchr( iplocalport, ':' );
1131 if ( conn->c_peer_name.bv_len != 0 &&
1132 strncmp( conn->c_peer_name.bv_val, "IP=", 3 ) == 0) {
1135 ipremoteport = ch_strdup( conn->c_peer_name.bv_val + 3 );
1136 /* Convert IPv6 addresses to address;port syntax. */
1137 p = strrchr( ipremoteport, ' ' );
1138 /* Convert IPv4 addresses to address;port syntax. */
1139 if ( p == NULL ) p = strchr( ipremoteport, ':' );
1144 sc = sasl_server_new( "ldap", global_host, global_realm,
1145 iplocalport, ipremoteport, session_callbacks, SASL_SUCCESS_DATA, &ctx );
1146 if ( iplocalport != NULL ) {
1147 ch_free( iplocalport );
1149 if ( ipremoteport != NULL ) {
1150 ch_free( ipremoteport );
1153 sc = sasl_server_new( "ldap", global_host, global_realm,
1154 session_callbacks, SASL_SECURITY_LAYER, &ctx );
1157 if( sc != SASL_OK ) {
1159 LDAP_LOG( TRANSPORT, ERR,
1160 "slap_sasl_open: sasl_server_new failed: %d\n", sc, 0, 0 );
1162 Debug( LDAP_DEBUG_ANY, "sasl_server_new failed: %d\n",
1169 conn->c_sasl_authctx = ctx;
1171 if( sc == SASL_OK ) {
1172 sc = sasl_setprop( ctx,
1173 SASL_SEC_PROPS, &sasl_secprops );
1175 if( sc != SASL_OK ) {
1177 LDAP_LOG( TRANSPORT, ERR,
1178 "slap_sasl_open: sasl_setprop failed: %d \n", sc, 0, 0 );
1180 Debug( LDAP_DEBUG_ANY, "sasl_setprop failed: %d\n",
1184 slap_sasl_close( conn );
1189 sc = slap_sasl_err2ldap( sc );
1194 int slap_sasl_external(
1197 const char *auth_id )
1199 #if SASL_VERSION_MAJOR >= 2
1201 sasl_conn_t *ctx = conn->c_sasl_authctx;
1203 if ( ctx == NULL ) {
1204 return LDAP_UNAVAILABLE;
1207 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
1209 if ( sc != SASL_OK ) {
1213 sc = sasl_setprop( ctx, SASL_AUTH_EXTERNAL, auth_id );
1215 if ( sc != SASL_OK ) {
1219 #elif defined(HAVE_CYRUS_SASL)
1221 sasl_conn_t *ctx = conn->c_sasl_authctx;
1222 sasl_external_properties_t extprops;
1224 if ( ctx == NULL ) {
1225 return LDAP_UNAVAILABLE;
1228 memset( &extprops, '\0', sizeof(extprops) );
1230 extprops.auth_id = (char *) auth_id;
1232 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
1233 (void *) &extprops );
1235 if ( sc != SASL_OK ) {
1240 return LDAP_SUCCESS;
1243 int slap_sasl_reset( Connection *conn )
1245 return LDAP_SUCCESS;
1248 char ** slap_sasl_mechs( Connection *conn )
1250 char **mechs = NULL;
1252 #ifdef HAVE_CYRUS_SASL
1253 sasl_conn_t *ctx = conn->c_sasl_authctx;
1255 if( ctx == NULL ) ctx = conn->c_sasl_sockctx;
1259 SASL_CONST char *mechstr;
1261 sc = sasl_listmech( ctx,
1262 NULL, NULL, ",", NULL,
1263 &mechstr, NULL, NULL );
1265 if( sc != SASL_OK ) {
1267 LDAP_LOG( TRANSPORT, ERR,
1268 "slap_sasl_mechs: sasl_listmech failed: %d\n", sc, 0, 0 );
1270 Debug( LDAP_DEBUG_ANY, "slap_sasl_listmech failed: %d\n",
1277 mechs = ldap_str2charray( mechstr, "," );
1279 #if SASL_VERSION_MAJOR < 2
1288 int slap_sasl_close( Connection *conn )
1290 #ifdef HAVE_CYRUS_SASL
1291 sasl_conn_t *ctx = conn->c_sasl_authctx;
1294 sasl_dispose( &ctx );
1296 if ( conn->c_sasl_sockctx && conn->c_sasl_authctx != conn->c_sasl_sockctx ) {
1297 ctx = conn->c_sasl_sockctx;
1298 sasl_dispose( &ctx );
1301 conn->c_sasl_authctx = NULL;
1302 conn->c_sasl_sockctx = NULL;
1303 conn->c_sasl_done = 0;
1305 free( conn->c_sasl_extra );
1306 conn->c_sasl_extra = NULL;
1309 return LDAP_SUCCESS;
1312 int slap_sasl_bind( Operation *op, SlapReply *rs )
1314 #ifdef HAVE_CYRUS_SASL
1315 sasl_conn_t *ctx = op->o_conn->c_sasl_authctx;
1316 struct berval response;
1317 unsigned reslen = 0;
1321 LDAP_LOG( TRANSPORT, ENTRY,
1322 "sasl_bind: dn=\"%s\" mech=%s datalen=%ld\n",
1323 op->o_req_dn.bv_len ? op->o_req_dn.bv_val : "",
1324 op->o_conn->c_sasl_bind_in_progress ? "<continuing>" :
1325 op->o_conn->c_sasl_bind_mech.bv_val,
1326 op->orb_cred.bv_len );
1328 Debug(LDAP_DEBUG_ARGS,
1329 "==> sasl_bind: dn=\"%s\" mech=%s datalen=%ld\n",
1330 op->o_req_dn.bv_len ? op->o_req_dn.bv_val : "",
1331 op->o_conn->c_sasl_bind_in_progress ? "<continuing>" :
1332 op->o_conn->c_sasl_bind_mech.bv_val,
1333 op->orb_cred.bv_len );
1338 send_ldap_error( op, rs, LDAP_UNAVAILABLE,
1339 "SASL unavailable on this session" );
1343 #if SASL_VERSION_MAJOR >= 2
1344 #define START( ctx, mech, cred, clen, resp, rlen, err ) \
1345 sasl_server_start( ctx, mech, cred, clen, resp, rlen )
1346 #define STEP( ctx, cred, clen, resp, rlen, err ) \
1347 sasl_server_step( ctx, cred, clen, resp, rlen )
1349 #define START( ctx, mech, cred, clen, resp, rlen, err ) \
1350 sasl_server_start( ctx, mech, cred, clen, resp, rlen, err )
1351 #define STEP( ctx, cred, clen, resp, rlen, err ) \
1352 sasl_server_step( ctx, cred, clen, resp, rlen, err )
1355 if ( !op->o_conn->c_sasl_bind_in_progress ) {
1356 /* If we already authenticated once, must use a new context */
1357 if ( op->o_conn->c_sasl_done ) {
1359 const char *authid = NULL;
1360 #if SASL_VERSION_MAJOR >= 2
1361 sasl_getprop( ctx, SASL_SSF_EXTERNAL, (void *)&ssf );
1362 sasl_getprop( ctx, SASL_AUTH_EXTERNAL, (void *)&authid );
1363 if ( authid ) authid = ch_strdup( authid );
1365 if ( ctx != op->o_conn->c_sasl_sockctx ) {
1366 sasl_dispose( &ctx );
1368 op->o_conn->c_sasl_authctx = NULL;
1370 slap_sasl_open( op->o_conn, 1 );
1371 ctx = op->o_conn->c_sasl_authctx;
1372 #if SASL_VERSION_MAJOR >= 2
1374 sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
1375 sasl_setprop( ctx, SASL_AUTH_EXTERNAL, authid );
1376 ch_free( (char *)authid );
1381 op->o_conn->c_sasl_bind_mech.bv_val,
1382 op->orb_cred.bv_val, op->orb_cred.bv_len,
1383 (SASL_CONST char **)&response.bv_val, &reslen, &rs->sr_text );
1387 op->orb_cred.bv_val, op->orb_cred.bv_len,
1388 (SASL_CONST char **)&response.bv_val, &reslen, &rs->sr_text );
1391 response.bv_len = reslen;
1393 if ( sc == SASL_OK ) {
1394 sasl_ssf_t *ssf = NULL;
1396 op->orb_edn = op->o_conn->c_sasl_dn;
1397 op->o_conn->c_sasl_dn.bv_val = NULL;
1398 op->o_conn->c_sasl_dn.bv_len = 0;
1399 op->o_conn->c_sasl_done = 1;
1401 rs->sr_err = LDAP_SUCCESS;
1403 (void) sasl_getprop( ctx, SASL_SSF, (void *)&ssf );
1404 op->orb_ssf = ssf ? *ssf : 0;
1408 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1409 op->o_conn->c_sasl_layers++;
1411 /* If there's an old layer, set sockctx to NULL to
1412 * tell connection_read() to wait for us to finish.
1413 * Otherwise there is a race condition: we have to
1414 * send the Bind response using the old security
1415 * context and then remove it before reading any
1418 if ( op->o_conn->c_sasl_sockctx ) {
1419 ctx = op->o_conn->c_sasl_sockctx;
1420 op->o_conn->c_sasl_sockctx = NULL;
1422 op->o_conn->c_sasl_sockctx = op->o_conn->c_sasl_authctx;
1424 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1427 /* Must send response using old security layer */
1428 if (response.bv_len) rs->sr_sasldata = &response;
1429 send_ldap_sasl( op, rs );
1431 /* Now dispose of the old security layer.
1434 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1435 ldap_pvt_sasl_remove( op->o_conn->c_sb );
1436 op->o_conn->c_sasl_sockctx = op->o_conn->c_sasl_authctx;
1437 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1438 sasl_dispose( &ctx );
1440 } else if ( sc == SASL_CONTINUE ) {
1441 rs->sr_err = LDAP_SASL_BIND_IN_PROGRESS,
1442 rs->sr_sasldata = &response;
1443 send_ldap_sasl( op, rs );
1446 #if SASL_VERSION_MAJOR >= 2
1447 rs->sr_text = sasl_errdetail( ctx );
1449 rs->sr_err = slap_sasl_err2ldap( sc ),
1450 send_ldap_result( op, rs );
1453 #if SASL_VERSION_MAJOR < 2
1454 if( response.bv_len ) {
1455 ch_free( response.bv_val );
1460 LDAP_LOG( TRANSPORT, RESULTS, "slap_sasl_bind: rc=%d\n", rs->sr_err, 0, 0 );
1462 Debug(LDAP_DEBUG_TRACE, "<== slap_sasl_bind: rc=%d\n", rs->sr_err, 0, 0);
1467 send_ldap_error( op, rs, LDAP_UNAVAILABLE,
1468 "SASL not supported" );
1474 char* slap_sasl_secprops( const char *in )
1476 #ifdef HAVE_CYRUS_SASL
1477 int rc = ldap_pvt_sasl_secprops( in, &sasl_secprops );
1479 return rc == LDAP_SUCCESS ? NULL : "Invalid security properties";
1481 return "SASL not supported";
1485 #ifdef HAVE_CYRUS_SASL
1487 slap_sasl_setpass( Operation *op, SlapReply *rs )
1489 struct berval id = { 0, NULL }; /* needs to come from connection */
1490 struct berval new = { 0, NULL };
1491 struct berval old = { 0, NULL };
1493 assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->ore_reqoid ) == 0 );
1495 rs->sr_err = sasl_getprop( op->o_conn->c_sasl_authctx, SASL_USERNAME,
1496 (SASL_CONST void **)&id.bv_val );
1498 if( rs->sr_err != SASL_OK ) {
1499 rs->sr_text = "unable to retrieve SASL username";
1500 rs->sr_err = LDAP_OTHER;
1505 LDAP_LOG( BACKEND, ENTRY,
1506 "slap_sasl_setpass: \"%s\"\n",
1507 id.bv_val ? id.bv_val : "", 0, 0);
1509 Debug( LDAP_DEBUG_ARGS, "==> slap_sasl_setpass: \"%s\"\n",
1510 id.bv_val ? id.bv_val : "", 0, 0 );
1513 rs->sr_err = slap_passwd_parse( op->ore_reqdata,
1514 NULL, &old, &new, &rs->sr_text );
1516 if( rs->sr_err != LDAP_SUCCESS ) {
1520 if( new.bv_len == 0 ) {
1521 slap_passwd_generate(&new);
1523 if( new.bv_len == 0 ) {
1524 rs->sr_text = "password generation failed.";
1525 rs->sr_err = LDAP_OTHER;
1529 rs->sr_rspdata = slap_passwd_return( &new );
1532 #if SASL_VERSION_MAJOR < 2
1533 rs->sr_err = sasl_setpass( op->o_conn->c_sasl_authctx,
1534 id.bv_val, new.bv_val, new.bv_len, 0, &rs->sr_text );
1536 rs->sr_err = sasl_setpass( op->o_conn->c_sasl_authctx, id.bv_val,
1537 new.bv_val, new.bv_len, old.bv_val, old.bv_len, 0 );
1538 if( rs->sr_err != SASL_OK ) {
1539 rs->sr_text = sasl_errdetail( op->o_conn->c_sasl_authctx );
1542 switch(rs->sr_err) {
1544 rs->sr_err = LDAP_SUCCESS;
1554 rs->sr_err = LDAP_OTHER;
1560 #endif /* HAVE_CYRUS_SASL */
1562 /* Take any sort of identity string and return a DN with the "dn:" prefix. The
1563 string returned in *dn is in its own allocated memory, and must be free'd
1564 by the calling process.
1565 -Mark Adamson, Carnegie Mellon
1567 The "dn:" prefix is no longer used anywhere inside slapd. It is only used
1568 on strings passed in directly from SASL.
1569 -Howard Chu, Symas Corp.
1576 static struct berval ext_bv = BER_BVC( "EXTERNAL" );
1578 int slap_sasl_getdn( Connection *conn, Operation *op, char *id, int len,
1579 char *user_realm, struct berval *dn, int flags )
1582 int rc, is_dn = SET_NONE, do_norm = 1;
1586 LDAP_LOG( TRANSPORT, ENTRY,
1587 "slap_sasl_getdn: conn %d id=%s [len=%d]\n",
1588 conn ? conn->c_connid : -1, id ? (*id ? id : "<empty>") : "NULL", len );
1590 Debug( LDAP_DEBUG_ARGS, "slap_sasl_getdn: id=%s [len=%d]\n",
1591 id ? ( *id ? id : "<empty>" ) : "NULL", len, 0 );
1595 op = conn->c_sasl_bindop;
1602 if ( len == 0 ) len = strlen( id );
1604 /* Blatantly anonymous ID */
1605 if ( len == sizeof("anonymous") - 1 &&
1606 !strcasecmp( id, "anonymous" ) ) {
1607 return( LDAP_SUCCESS );
1613 /* An authcID needs to be converted to authzID form. Set the
1614 * values directly into *dn; they will be normalized later. (and
1615 * normalizing always makes a new copy.) An ID from a TLS certificate
1616 * is already normalized, so copy it and skip normalization.
1618 if( flags & SLAP_GETDN_AUTHCID ) {
1619 if( conn->c_sasl_bind_mech.bv_len == ext_bv.bv_len &&
1620 strcasecmp( ext_bv.bv_val, conn->c_sasl_bind_mech.bv_val ) == 0 )
1622 /* EXTERNAL DNs are already normalized */
1625 ber_str2bv_x( id, len, 1, dn, op->o_tmpmemctx );
1628 /* convert to u:<username> form */
1634 if( is_dn == SET_NONE ) {
1635 if( !strncasecmp( id, "u:", sizeof("u:")-1 )) {
1639 } else if ( !strncasecmp( id, "dn:", sizeof("dn:")-1) ) {
1646 /* No other possibilities from here */
1647 if( is_dn == SET_NONE ) {
1650 return( LDAP_INAPPROPRIATE_AUTH );
1653 /* Username strings */
1654 if( is_dn == SET_U ) {
1656 len = dn->bv_len + sizeof("uid=")-1 + sizeof(",cn=auth")-1;
1658 /* username may have embedded realm name */
1659 if( ( realm = strchr( dn->bv_val, '@') ) ) {
1661 len += sizeof(",cn=")-2;
1662 } else if( user_realm && *user_realm ) {
1663 len += strlen( user_realm ) + sizeof(",cn=")-1;
1666 if( conn->c_sasl_bind_mech.bv_len ) {
1667 len += conn->c_sasl_bind_mech.bv_len + sizeof(",cn=")-1;
1670 /* Build the new dn */
1672 dn->bv_val = sl_malloc( len+1, op->o_tmpmemctx );
1673 if( dn->bv_val == NULL ) {
1675 LDAP_LOG( TRANSPORT, ERR,
1676 "slap_sasl_getdn: SLAP_MALLOC failed", 0, 0, 0 );
1678 Debug( LDAP_DEBUG_ANY,
1679 "slap_sasl_getdn: SLAP_MALLOC failed", 0, 0, 0 );
1683 p = lutil_strcopy( dn->bv_val, "uid=" );
1684 p = lutil_strncopy( p, c1, dn->bv_len );
1687 int rlen = dn->bv_len - ( realm - c1 );
1688 p = lutil_strcopy( p, ",cn=" );
1689 p = lutil_strncopy( p, realm, rlen );
1691 } else if( user_realm && *user_realm ) {
1692 p = lutil_strcopy( p, ",cn=" );
1693 p = lutil_strcopy( p, user_realm );
1696 if( conn->c_sasl_bind_mech.bv_len ) {
1697 p = lutil_strcopy( p, ",cn=" );
1698 p = lutil_strcopy( p, conn->c_sasl_bind_mech.bv_val );
1700 p = lutil_strcopy( p, ",cn=auth" );
1701 dn->bv_len = p - dn->bv_val;
1704 LDAP_LOG( TRANSPORT, ENTRY,
1705 "slap_sasl_getdn: u:id converted to %s.\n", dn->bv_val, 0, 0 );
1707 Debug( LDAP_DEBUG_TRACE, "getdn: u:id converted to %s\n", dn->bv_val,0,0 );
1711 /* Dup the DN in any case, so we don't risk
1712 * leaks or dangling pointers later,
1713 * and the DN value is '\0' terminated */
1714 ber_dupbv_x( &dn2, dn, op->o_tmpmemctx );
1715 dn->bv_val = dn2.bv_val;
1718 /* All strings are in DN form now. Normalize if needed. */
1720 rc = dnNormalize( 0, NULL, NULL, dn, &dn2, op->o_tmpmemctx );
1722 /* User DNs were constructed above and must be freed now */
1723 sl_free( dn->bv_val, op->o_tmpmemctx );
1725 if ( rc != LDAP_SUCCESS ) {
1733 /* Run thru regexp */
1734 slap_sasl2dn( op, dn, &dn2 );
1736 sl_free( dn->bv_val, op->o_tmpmemctx );
1739 LDAP_LOG( TRANSPORT, ENTRY,
1740 "slap_sasl_getdn: dn:id converted to %s.\n", dn->bv_val, 0, 0 );
1742 Debug( LDAP_DEBUG_TRACE, "getdn: dn:id converted to %s\n",
1747 return( LDAP_SUCCESS );