+ sasldn->bv_val = NULL;
+ sasldn->bv_len = 0;
+ cb.sc_private = sasldn;
+
+ /* Convert the SASL name into a minimal URI */
+ if( !slap_sasl_regexp( saslname, ®out, flags, opx->o_tmpmemctx ) ) {
+ goto FINISHED;
+ }
+
+ rc = slap_parseURI( opx, ®out, &op.o_req_dn,
+ &op.o_req_ndn, &op.oq_search.rs_scope, &op.oq_search.rs_filter,
+ &op.ors_filterstr );
+ if( regout.bv_val ) sl_free( regout.bv_val, opx->o_tmpmemctx );
+ if( rc != LDAP_SUCCESS ) {
+ goto FINISHED;
+ }
+
+ /* Must do an internal search */
+ op.o_bd = select_backend( &op.o_req_ndn, 0, 1 );
+
+ /* Massive shortcut: search scope == base */
+ switch ( op.oq_search.rs_scope ) {
+ case LDAP_SCOPE_BASE:
+ case LDAP_X_SCOPE_EXACT:
+ *sasldn = op.o_req_ndn;
+ op.o_req_ndn.bv_len = 0;
+ op.o_req_ndn.bv_val = NULL;
+ /* intentionally continue to next case */
+
+ case LDAP_X_SCOPE_REGEX:
+ case LDAP_X_SCOPE_SUBTREE:
+ case LDAP_X_SCOPE_CHILDREN:
+ /* correctly parsed, but illegal */
+ goto FINISHED;
+
+ case LDAP_SCOPE_ONELEVEL:
+ case LDAP_SCOPE_SUBTREE:
+ case LDAP_SCOPE_SUBORDINATE:
+ /* do a search */
+ break;
+
+ default:
+ /* catch unhandled cases (there shouldn't be) */
+ assert( 0 );
+ }
+
+#ifdef NEW_LOGGING
+ LDAP_LOG( TRANSPORT, DETAIL1,
+ "slap_sasl2dn: performing internal search (base=%s, scope=%d)\n",
+ op.o_req_ndn.bv_val, op.oq_search.rs_scope, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "slap_sasl2dn: performing internal search (base=%s, scope=%d)\n",
+ op.o_req_ndn.bv_val, op.oq_search.rs_scope, 0 );
+#endif
+
+ if(( op.o_bd == NULL ) || ( op.o_bd->be_search == NULL)) {
+ goto FINISHED;
+ }
+
+ op.o_conn = opx->o_conn;
+ op.o_connid = opx->o_connid;
+ op.o_tag = LDAP_REQ_SEARCH;
+ op.o_protocol = LDAP_VERSION3;
+ op.o_ndn = opx->o_conn->c_ndn;
+ op.o_callback = &cb;
+ op.o_time = slap_get_time();
+ op.o_do_not_cache = 1;
+ op.o_is_auth_check = 1;
+ op.o_threadctx = opx->o_threadctx;
+ op.o_tmpmemctx = opx->o_tmpmemctx;
+ op.o_tmpmfuncs = opx->o_tmpmfuncs;
+#ifdef LDAP_SLAPI
+ op.o_pb = opx->o_pb;
+#endif
+ op.oq_search.rs_deref = LDAP_DEREF_NEVER;
+ op.oq_search.rs_slimit = 1;
+ op.oq_search.rs_attrsonly = 1;
+ op.o_req_dn = op.o_req_ndn;
+
+ op.o_bd->be_search( &op, &rs );
+
+FINISHED:
+ if( sasldn->bv_len ) {
+ opx->o_conn->c_authz_backend = op.o_bd;
+ }
+ if( op.o_req_dn.bv_len ) ch_free( op.o_req_dn.bv_val );
+ if( op.o_req_ndn.bv_len ) sl_free( op.o_req_ndn.bv_val, opx->o_tmpmemctx );
+ if( op.oq_search.rs_filter ) filter_free_x( opx, op.oq_search.rs_filter );
+ if( op.ors_filterstr.bv_len ) ch_free( op.ors_filterstr.bv_val );