2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2006 The OpenLDAP Foundation.
5 * Portions Copyright 2001-2003 Pierangelo Masarati.
6 * Portions Copyright 1999-2003 Howard Chu.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by the Howard Chu for inclusion
19 * in OpenLDAP Software and subsequently enhanced by Pierangelo
28 #include <ac/socket.h>
29 #include <ac/string.h>
34 #include "../back-ldap/back-ldap.h"
35 #include "back-meta.h"
37 static LDAP_REBIND_PROC meta_back_default_rebind;
40 * a module could register a replacement for this function
42 LDAP_REBIND_PROC *meta_back_rebind_f = meta_back_default_rebind;
45 meta_back_bind( Operation *op, SlapReply *rs )
47 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
48 metaconn_t *mc = NULL;
55 SlapReply *candidates = meta_back_candidates_get( op );
57 rs->sr_err = LDAP_SUCCESS;
59 Debug( LDAP_DEBUG_ARGS, "%s meta_back_bind: dn=\"%s\".\n",
60 op->o_log_prefix, op->o_req_dn.bv_val, 0 );
62 /* the test on the bind method should be superfluous */
63 if ( op->orb_method == LDAP_AUTH_SIMPLE
64 && be_isroot_dn( op->o_bd, &op->o_req_ndn ) )
66 if ( !be_isroot_pw( op ) ) {
67 rs->sr_err = LDAP_INVALID_CREDENTIALS;
69 send_ldap_result( op, rs );
73 if ( META_BACK_DEFER_ROOTDN_BIND( mi ) ) {
74 rs->sr_err = LDAP_SUCCESS;
76 /* frontend will return success */
83 /* we need meta_back_getconn() not send result even on error,
84 * because we want to intercept the error and make it
85 * invalidCredentials */
86 mc = meta_back_getconn( op, rs, NULL, LDAP_BACK_BIND_DONTSEND );
88 char buf[ SLAP_TEXT_BUFLEN ];
90 snprintf( buf, sizeof( buf ),
91 "meta_back_bind: no target "
92 "for dn \"%s\" (%d%s%s).",
93 op->o_req_dn.bv_val, rs->sr_err,
94 rs->sr_text ? ". " : "",
95 rs->sr_text ? rs->sr_text : "" );
96 Debug( LDAP_DEBUG_ANY,
98 op->o_log_prefix, buf, 0 );
100 /* FIXME: there might be cases where we don't want
101 * to map the error onto invalidCredentials */
102 switch ( rs->sr_err ) {
103 case LDAP_NO_SUCH_OBJECT:
104 case LDAP_UNWILLING_TO_PERFORM:
105 rs->sr_err = LDAP_INVALID_CREDENTIALS;
109 send_ldap_result( op, rs );
114 * Each target is scanned ...
116 mc->mc_authz_target = META_BOUND_NONE;
117 for ( i = 0; i < mi->mi_ntargets; i++ ) {
123 * Skip non-candidates
125 if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
130 /* set rc to LDAP_SUCCESS only if at least
131 * one candidate has been tried */
135 } else if ( isroot == 0 ) {
137 * A bind operation is expected to have
138 * ONE CANDIDATE ONLY!
140 Debug( LDAP_DEBUG_ANY,
141 "### %s meta_back_bind: more than one"
142 " candidate selected...\n",
143 op->o_log_prefix, 0, 0 );
147 if ( BER_BVISNULL( &mi->mi_targets[ i ].mt_pseudorootdn ) )
149 metasingleconn_t *msc = &mc->mc_conns[ i ];
151 /* skip the target if no pseudorootdn is provided */
152 if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
153 ch_free( msc->msc_bound_ndn.bv_val );
154 BER_BVZERO( &msc->msc_bound_ndn );
157 if ( LDAP_BACK_SAVECRED( mi ) &&
158 !BER_BVISNULL( &msc->msc_cred ) )
160 /* destroy sensitive data */
161 memset( msc->msc_cred.bv_val, 0,
162 msc->msc_cred.bv_len );
163 ch_free( msc->msc_cred.bv_val );
164 BER_BVZERO( &msc->msc_cred );
170 op2.o_req_dn = mi->mi_targets[ i ].mt_pseudorootdn;
171 op2.o_req_ndn = mi->mi_targets[ i ].mt_pseudorootdn;
172 op2.orb_cred = mi->mi_targets[ i ].mt_pseudorootpw;
173 op2.orb_method = LDAP_AUTH_SIMPLE;
178 lerr = meta_back_single_bind( &op2, rs, mc, i, massage );
180 if ( lerr != LDAP_SUCCESS ) {
181 rc = rs->sr_err = lerr;
182 /* FIXME: in some cases (e.g. unavailable)
183 * do not assume it's not candidate; rather
184 * mark this as an error to be eventually
185 * reported to client */
186 candidates[ i ].sr_tag = META_NOT_CANDIDATE;
191 /* must re-insert if local DN changed as result of bind */
192 if ( rc == LDAP_SUCCESS ) {
194 mc->mc_authz_target = META_BOUND_ALL;
195 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ) );
198 if ( !dn_match( &op->o_req_ndn, &mc->mc_local_ndn ) ) {
202 /* wait for all other ops to release the connection */
204 ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
205 if ( mc->mc_refcnt > 1 ) {
206 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
207 ldap_pvt_thread_yield();
211 assert( mc->mc_refcnt == 1 );
212 tmpmc = avl_delete( &mi->mi_conninfo.lai_tree, (caddr_t)mc,
213 meta_back_conndn_cmp );
214 assert( tmpmc == mc );
216 ber_bvreplace( &mc->mc_local_ndn, &op->o_req_ndn );
217 lerr = avl_insert( &mi->mi_conninfo.lai_tree, (caddr_t)mc,
218 meta_back_conndn_cmp, meta_back_conndn_dup );
219 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
221 meta_clear_candidates( op, mc );
223 /* we can do this because mc_refcnt == 1 */
225 meta_back_conn_free( mc );
232 meta_back_release_conn( op, mc );
236 * rc is LDAP_SUCCESS if at least one bind succeeded,
237 * err is the last error that occurred during a bind;
238 * if at least (and at most?) one bind succeeds, fine.
240 if ( rc != LDAP_SUCCESS ) {
243 * deal with bind failure ...
247 * no target was found within the naming context,
248 * so bind must fail with invalid credentials
250 if ( rs->sr_err == LDAP_SUCCESS && gotit == 0 ) {
251 rs->sr_err = LDAP_INVALID_CREDENTIALS;
253 rs->sr_err = slap_map_api2result( rs );
255 send_ldap_result( op, rs );
264 * meta_back_single_bind
266 * attempts to perform a bind with creds
269 meta_back_single_bind(
276 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
277 metatarget_t *mt = &mi->mi_targets[ candidate ];
278 struct berval mdn = BER_BVNULL;
279 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
284 if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
285 ch_free( msc->msc_bound_ndn.bv_val );
286 BER_BVZERO( &msc->msc_bound_ndn );
289 if ( LDAP_BACK_SAVECRED( mi ) && !BER_BVISNULL( &msc->msc_cred ) ) {
290 /* destroy sensitive data */
291 memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len );
292 ch_free( msc->msc_cred.bv_val );
293 BER_BVZERO( &msc->msc_cred );
297 * Rewrite the bind dn if needed
303 dc.conn = op->o_conn;
307 if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
308 rs->sr_text = "DN rewrite error";
309 rs->sr_err = LDAP_OTHER;
317 /* FIXME: this fixes the bind problem right now; we need
318 * to use the asynchronous version to get the "matched"
319 * and more in case of failure ... */
320 /* FIXME: should we check if at least some of the op->o_ctrls
321 * can/should be passed? */
323 rs->sr_err = ldap_sasl_bind( msc->msc_ld, mdn.bv_val,
324 LDAP_SASL_SIMPLE, &op->orb_cred,
325 op->o_ctrls, NULL, &msgid );
326 if ( rs->sr_err == LDAP_SUCCESS ) {
330 int nretries = mt->mt_nretries;
331 char buf[ SLAP_TEXT_BUFLEN ];
333 LDAP_BACK_TV_SET( &tv );
339 switch ( ldap_result( msc->msc_ld, msgid, LDAP_MSG_ALL, &tv, &res ) ) {
341 snprintf( buf, sizeof( buf ),
342 "ldap_result=0 nretries=%d%s",
343 nretries, rebinding ? " rebinding" : "" );
344 Debug( LDAP_DEBUG_ANY,
345 "%s meta_back_single_bind[%d]: %s.\n",
346 op->o_log_prefix, candidate, buf );
348 if ( nretries != META_RETRY_NEVER ) {
349 ldap_pvt_thread_yield();
350 if ( nretries > 0 ) {
353 tv = mt->mt_bind_timeout;
357 rs->sr_err = LDAP_BUSY;
359 ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
363 /* FIXME: some times the request times out
364 * while the other party is not willing to
365 * send a response any more. Give it a second
366 * chance with a freshly bound connection */
368 nretries = mt->mt_nretries;
372 ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER,
376 ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
379 snprintf( buf, sizeof( buf ),
380 "err=%d (%s) nretries=%d",
381 rs->sr_err, ldap_err2string( rs->sr_err ), nretries );
382 Debug( LDAP_DEBUG_ANY,
383 "### %s meta_back_single_bind[%d]: %s.\n",
384 op->o_log_prefix, candidate, buf );
386 rc = slap_map_api2result( rs );
387 if ( rs->sr_err == LDAP_UNAVAILABLE && nretries != META_RETRY_NEVER ) {
388 rc = meta_back_retry( op, rs, &mc, candidate, LDAP_BACK_DONTSEND );
390 if ( nretries > 0 ) {
393 ldap_pvt_thread_yield();
401 rc = ldap_parse_result( msc->msc_ld, res, &rs->sr_err,
402 NULL, NULL, NULL, NULL, 1 );
403 if ( rc != LDAP_SUCCESS ) {
410 if ( rs->sr_err != LDAP_SUCCESS ) {
411 rs->sr_err = slap_map_api2result( rs );
415 ber_bvreplace( &msc->msc_bound_ndn, &op->o_req_dn );
416 LDAP_BACK_CONN_ISBOUND_SET( msc );
417 mc->mc_authz_target = candidate;
419 if ( LDAP_BACK_SAVECRED( mi ) ) {
420 ber_bvreplace( &msc->msc_cred, &op->orb_cred );
421 ldap_set_rebind_proc( msc->msc_ld, meta_back_rebind_f, msc );
424 if ( mi->mi_cache.ttl != META_DNCACHE_DISABLED
425 && op->o_req_ndn.bv_len != 0 )
427 ( void )meta_dncache_update_entry( &mi->mi_cache,
428 &op->o_req_ndn, candidate );
432 if ( mdn.bv_val != op->o_req_dn.bv_val ) {
440 * meta_back_single_dobind
443 meta_back_single_dobind(
448 ldap_back_send_t sendok,
452 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
453 metatarget_t *mt = &mi->mi_targets[ candidate ];
454 metaconn_t *mc = *mcp;
455 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
457 static struct berval cred = BER_BVC( "" );
460 save_nretries = nretries;
462 assert( !LDAP_BACK_CONN_ISBOUND( msc ) );
465 * meta_back_single_dobind() calls meta_back_single_bind()
468 if ( be_isroot( op ) && !BER_BVISNULL( &mi->mi_targets[ candidate ].mt_pseudorootdn ) )
472 op2.o_tag = LDAP_REQ_BIND;
473 op2.o_req_dn = mi->mi_targets[ candidate ].mt_pseudorootdn;
474 op2.o_req_ndn = mi->mi_targets[ candidate ].mt_pseudorootdn;
475 op2.orb_cred = mi->mi_targets[ candidate ].mt_pseudorootpw;
476 op2.orb_method = LDAP_AUTH_SIMPLE;
478 rc = meta_back_single_bind( &op2, rs, *mcp, candidate, 0 );
483 * Otherwise an anonymous bind is performed
484 * (note: if the target was already bound, the anonymous
485 * bind clears the previous bind).
487 if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
488 ber_memfree( msc->msc_bound_ndn.bv_val );
489 BER_BVZERO( &msc->msc_bound_ndn );
492 if ( LDAP_BACK_SAVECRED( mi ) && !BER_BVISNULL( &msc->msc_cred ) ) {
493 /* destroy sensitive data */
494 memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len );
495 ber_memfree( msc->msc_cred.bv_val );
496 BER_BVZERO( &msc->msc_cred );
499 /* FIXME: should we check if at least some of the op->o_ctrls
500 * can/should be passed? */
502 rc = ldap_sasl_bind( msc->msc_ld, "", LDAP_SASL_SIMPLE, &cred,
503 NULL, NULL, &msgid );
504 if ( rc == LDAP_SUCCESS ) {
507 char buf[ SLAP_TEXT_BUFLEN ];
509 LDAP_BACK_TV_SET( &tv );
515 switch ( ldap_result( msc->msc_ld, msgid, LDAP_MSG_ALL, &tv, &res ) ) {
517 snprintf( buf, sizeof( buf ),
518 "ldap_result=0 nretries=%d%s",
519 nretries, rebinding ? " rebinding" : "" );
520 Debug( LDAP_DEBUG_ANY,
521 "%s meta_back_single_dobind[%d]: %s.\n",
522 op->o_log_prefix, candidate, buf );
524 if ( nretries != META_RETRY_NEVER ) {
525 ldap_pvt_thread_yield();
526 if ( nretries > 0 ) {
529 tv = mt->mt_bind_timeout;
535 ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
539 /* FIXME: some times the request times out
540 * while the other party is not willing to
541 * send a response any more. Give it a second
542 * chance with a freshly bound connection */
544 nretries = save_nretries;
548 ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER,
552 ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
555 snprintf( buf, sizeof( buf ),
556 "err=%d (%s) nretries=%d",
557 rs->sr_err, ldap_err2string( rs->sr_err ), nretries );
558 Debug( LDAP_DEBUG_ANY,
559 "### %s meta_back_single_dobind[%d]: %s.\n",
560 op->o_log_prefix, candidate, buf );
562 rc = slap_map_api2result( rs );
563 if ( rc == LDAP_UNAVAILABLE && nretries != META_RETRY_NEVER ) {
565 ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
568 if ( mc->mc_refcnt == 1 ) {
569 meta_clear_one_candidate( msc );
570 LDAP_BACK_CONN_ISBOUND_CLEAR( msc );
572 ( void )rewrite_session_delete( mt->mt_rwmap.rwm_rw, op->o_conn );
574 /* mc here must be the regular mc,
575 * reset and ready for init */
576 rc = meta_back_init_one_conn( op, rs,
578 LDAP_BACK_CONN_ISPRIV( mc ),
579 LDAP_BACK_DONTSEND );
580 LDAP_BACK_CONN_BINDING_SET( msc );
583 /* can't do anything about it */
584 rc = LDAP_UNAVAILABLE;
588 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
591 if ( rc == LDAP_SUCCESS ) {
592 ldap_pvt_thread_yield();
593 if ( nretries > 0 ) {
602 rc = ldap_parse_result( msc->msc_ld, res, &rs->sr_err,
603 NULL, NULL, NULL, NULL, 1 );
604 if ( rc == LDAP_SUCCESS ) {
605 rc = slap_map_api2result( rs );
612 rc = slap_map_api2result( rs );
617 if ( rc != LDAP_SUCCESS && META_BACK_ONERR_STOP( mi ) ) {
618 LDAP_BACK_CONN_BINDING_CLEAR( msc );
619 LDAP_BACK_CONN_TAINTED_SET( mc );
620 meta_back_release_conn_lock( op, mc, dolock );
623 if ( sendok & LDAP_BACK_SENDERR ) {
624 send_ldap_result( op, rs );
639 ldap_back_send_t sendok )
641 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
647 SlapReply *candidates = meta_back_candidates_get( op );
649 if ( be_isroot( op ) ) {
653 Debug( LDAP_DEBUG_TRACE,
654 "%s meta_back_dobind: conn=%ld%s\n",
656 LDAP_BACK_PCONN_ID( mc->mc_conn ),
657 isroot ? " (isroot)" : "" );
660 * all the targets are bound as pseudoroot
662 if ( mc->mc_authz_target == META_BOUND_ALL ) {
667 for ( i = 0; i < mi->mi_ntargets; i++ ) {
668 metatarget_t *mt = &mi->mi_targets[ i ];
669 metasingleconn_t *msc = &mc->mc_conns[ i ];
670 int rc, do_retry = 1;
675 if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
679 assert( msc->msc_ld != NULL );
682 * If the target is already bound it is skipped
686 ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
687 if ( LDAP_BACK_CONN_ISBOUND( msc ) || LDAP_BACK_CONN_ISANON( msc ) ) {
688 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
692 } else if ( LDAP_BACK_CONN_BINDING( msc ) ) {
693 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
694 ldap_pvt_thread_yield();
698 LDAP_BACK_CONN_BINDING_SET( msc );
699 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
703 rc = meta_back_single_dobind( op, rs, &mc, i,
704 LDAP_BACK_DONTSEND, mt->mt_nretries, 1 );
706 * NOTE: meta_back_single_dobind() already retries;
707 * in case of failure, it resets mc...
709 if ( rc != LDAP_SUCCESS ) {
710 char buf[ SLAP_TEXT_BUFLEN ];
713 /* meta_back_single_dobind() already sent
714 * response and released connection */
719 if ( rc == LDAP_UNAVAILABLE && do_retry ) {
721 if ( meta_back_retry( op, rs, &mc, i, sendok ) ) {
724 ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
725 LDAP_BACK_CONN_BINDING_CLEAR( msc );
726 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
731 ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
732 LDAP_BACK_CONN_BINDING_CLEAR( msc );
733 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
735 snprintf( buf, sizeof( buf ),
736 "meta_back_dobind[%d]: (%s) err=%d (%s).",
737 i, isroot ? op->o_bd->be_rootdn.bv_val : "anonymous",
738 rc, ldap_err2string( rc ) );
739 Debug( LDAP_DEBUG_ANY,
741 op->o_log_prefix, buf, 0 );
744 * null cred bind should always succeed
745 * as anonymous, so a failure means
746 * the target is no longer candidate possibly
747 * due to technical reasons (remote host down?)
748 * so better clear the handle
750 /* leave the target candidate, but record the error for later use */
751 candidates[ i ].sr_err = rc;
752 if ( META_BACK_ONERR_STOP( mi ) ) {
760 Debug( LDAP_DEBUG_TRACE,
761 "%s meta_back_dobind[%d]: "
764 isroot ? op->o_bd->be_rootdn.bv_val : "anonymous" );
766 ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
767 LDAP_BACK_CONN_BINDING_CLEAR( msc );
769 LDAP_BACK_CONN_ISBOUND_SET( msc );
771 LDAP_BACK_CONN_ISANON_SET( msc );
773 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
778 Debug( LDAP_DEBUG_TRACE,
779 "%s meta_back_dobind: conn=%ld bound=%d\n",
780 op->o_log_prefix, LDAP_BACK_PCONN_ID( mc->mc_conn ), bound );
783 meta_back_release_conn( op, mc );
786 if ( sendok & LDAP_BACK_SENDERR ) {
787 if ( rs->sr_err == LDAP_SUCCESS ) {
788 rs->sr_err = LDAP_BUSY;
790 send_ldap_result( op, rs );
796 return ( bound > 0 );
800 * meta_back_default_rebind
802 * This is a callback used for chasing referrals using the same
803 * credentials as the original user on this session.
806 meta_back_default_rebind(
808 LDAP_CONST char *url,
813 metasingleconn_t *msc = ( metasingleconn_t * )params;
815 return ldap_sasl_bind_s( ld, msc->msc_bound_ndn.bv_val,
816 LDAP_SASL_SIMPLE, &msc->msc_cred,
821 * FIXME: error return must be handled in a cleaner way ...
830 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
836 const char *save_rmsg = NULL,
838 void *rmatch_ctx = NULL;
840 if ( candidate != META_TARGET_NONE ) {
841 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
843 rs->sr_err = LDAP_SUCCESS;
845 ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER, &rs->sr_err );
846 if ( rs->sr_err != LDAP_SUCCESS ) {
848 * better check the type of error. In some cases
849 * (search ?) it might be better to return a
850 * success if at least one of the targets gave
851 * positive result ...
853 ldap_get_option( msc->msc_ld,
854 LDAP_OPT_ERROR_STRING, &rmsg );
855 if ( rmsg != NULL && rmsg[ 0 ] == '\0' ) {
856 ldap_memfree( rmsg );
860 ldap_get_option( msc->msc_ld,
861 LDAP_OPT_MATCHED_DN, &rmatch );
862 if ( rmatch != NULL && rmatch[ 0 ] == '\0' ) {
863 ldap_memfree( rmatch );
867 rerr = rs->sr_err = slap_map_api2result( rs );
869 Debug(LDAP_DEBUG_ANY,
870 "==> meta_back_op_result: target"
871 " <%d> sending msg \"%s\""
872 " (matched \"%s\")\n",
873 candidate, ( rmsg ? rmsg : "" ),
874 ( rmatch ? rmatch : "" ) );
878 for ( i = 0; i < mi->mi_ntargets; i++ ) {
879 metasingleconn_t *msc = &mc->mc_conns[ i ];
883 rs->sr_err = LDAP_SUCCESS;
885 ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER, &rs->sr_err );
886 if ( rs->sr_err != LDAP_SUCCESS ) {
888 * better check the type of error. In some cases
889 * (search ?) it might be better to return a
890 * success if at least one of the targets gave
891 * positive result ...
893 ldap_get_option( msc->msc_ld,
894 LDAP_OPT_ERROR_STRING, &msg );
895 if ( msg != NULL && msg[ 0 ] == '\0' ) {
900 ldap_get_option( msc->msc_ld,
901 LDAP_OPT_MATCHED_DN, &match );
902 if ( match != NULL && match[ 0 ] == '\0' ) {
903 ldap_memfree( match );
907 rs->sr_err = slap_map_api2result( rs );
909 Debug(LDAP_DEBUG_ANY,
910 "==> meta_back_op_result: target"
911 " <%d> sending msg \"%s\""
912 " (matched \"%s\")\n",
913 i, ( msg ? msg : "" ),
914 ( match ? match : "" ) );
917 * FIXME: need to rewrite "match" (need rwinfo)
919 switch ( rs->sr_err ) {
924 ldap_memfree( rmsg );
929 if ( match != NULL ) {
931 ldap_memfree( rmatch );
944 ldap_memfree( match );
951 if ( rmsg != NULL ) {
952 save_rmsg = rs->sr_text;
955 if ( rmatch != NULL ) {
956 struct berval dn, pdn;
958 ber_str2bv( rmatch, 0, 0, &dn );
959 if ( dnPretty( NULL, &dn, &pdn, op->o_tmpmemctx ) == LDAP_SUCCESS ) {
960 ldap_memfree( rmatch );
961 rmatch_ctx = op->o_tmpmemctx;
964 save_rmatch = rs->sr_matched;
965 rs->sr_matched = rmatch;
967 send_ldap_result( op, rs );
968 if ( rmsg != NULL ) {
970 rs->sr_text = save_rmsg;
972 if ( rmatch != NULL ) {
973 ber_memfree_x( rmatch, rmatch_ctx );
974 rs->sr_matched = save_rmatch;
977 return ( ( rerr == LDAP_SUCCESS ) ? 0 : -1 );