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"
38 meta_back_bind( Operation *op, SlapReply *rs )
40 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
41 metaconn_t *mc = NULL;
48 SlapReply *candidates = meta_back_candidates_get( op );
50 rs->sr_err = LDAP_SUCCESS;
52 Debug( LDAP_DEBUG_ARGS, "%s meta_back_bind: dn=\"%s\".\n",
53 op->o_log_prefix, op->o_req_dn.bv_val, 0 );
55 /* the test on the bind method should be superfluous */
56 if ( op->orb_method == LDAP_AUTH_SIMPLE
57 && be_isroot_dn( op->o_bd, &op->o_req_ndn ) )
59 if ( !be_isroot_pw( op ) ) {
60 rs->sr_err = LDAP_INVALID_CREDENTIALS;
62 send_ldap_result( op, rs );
66 if ( META_BACK_DEFER_ROOTDN_BIND( mi ) ) {
67 rs->sr_err = LDAP_SUCCESS;
69 /* frontend will return success */
76 /* we need meta_back_getconn() not send result even on error,
77 * because we want to intercept the error and make it
78 * invalidCredentials */
79 mc = meta_back_getconn( op, rs, NULL, LDAP_BACK_BIND_DONTSEND );
81 if ( LogTest( LDAP_DEBUG_ANY ) ) {
82 char buf[ SLAP_TEXT_BUFLEN ];
84 snprintf( buf, sizeof( buf ),
85 "meta_back_bind: no target "
86 "for dn \"%s\" (%d%s%s).",
87 op->o_req_dn.bv_val, rs->sr_err,
88 rs->sr_text ? ". " : "",
89 rs->sr_text ? rs->sr_text : "" );
90 Debug( LDAP_DEBUG_ANY,
92 op->o_log_prefix, buf, 0 );
95 /* FIXME: there might be cases where we don't want
96 * to map the error onto invalidCredentials */
97 switch ( rs->sr_err ) {
98 case LDAP_NO_SUCH_OBJECT:
99 case LDAP_UNWILLING_TO_PERFORM:
100 rs->sr_err = LDAP_INVALID_CREDENTIALS;
104 send_ldap_result( op, rs );
109 * Each target is scanned ...
111 mc->mc_authz_target = META_BOUND_NONE;
112 for ( i = 0; i < mi->mi_ntargets; i++ ) {
113 metatarget_t *mt = mi->mi_targets[ i ];
119 * Skip non-candidates
121 if ( !META_IS_CANDIDATE( &candidates[ i ] ) ) {
126 /* set rc to LDAP_SUCCESS only if at least
127 * one candidate has been tried */
131 } else if ( isroot == 0 ) {
133 * A bind operation is expected to have
134 * ONE CANDIDATE ONLY!
136 Debug( LDAP_DEBUG_ANY,
137 "### %s meta_back_bind: more than one"
138 " candidate selected...\n",
139 op->o_log_prefix, 0, 0 );
143 if ( BER_BVISNULL( &mt->mt_pseudorootdn ) )
145 metasingleconn_t *msc = &mc->mc_conns[ i ];
147 /* skip the target if no pseudorootdn is provided */
148 if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
149 ch_free( msc->msc_bound_ndn.bv_val );
150 BER_BVZERO( &msc->msc_bound_ndn );
153 if ( LDAP_BACK_SAVECRED( mi ) &&
154 !BER_BVISNULL( &msc->msc_cred ) )
156 /* destroy sensitive data */
157 memset( msc->msc_cred.bv_val, 0,
158 msc->msc_cred.bv_len );
159 ch_free( msc->msc_cred.bv_val );
160 BER_BVZERO( &msc->msc_cred );
166 op2.o_req_dn = mt->mt_pseudorootdn;
167 op2.o_req_ndn = mt->mt_pseudorootdn;
168 op2.orb_cred = mt->mt_pseudorootpw;
169 op2.orb_method = LDAP_AUTH_SIMPLE;
174 lerr = meta_back_single_bind( &op2, rs, mc, i, massage );
176 if ( lerr != LDAP_SUCCESS ) {
177 rc = rs->sr_err = lerr;
178 /* FIXME: in some cases (e.g. unavailable)
179 * do not assume it's not candidate; rather
180 * mark this as an error to be eventually
181 * reported to client */
182 META_CANDIDATE_CLEAR( &candidates[ i ] );
187 /* must re-insert if local DN changed as result of bind */
188 if ( rc == LDAP_SUCCESS ) {
190 mc->mc_authz_target = META_BOUND_ALL;
191 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ) );
194 if ( !dn_match( &op->o_req_ndn, &mc->mc_local_ndn ) ) {
198 /* wait for all other ops to release the connection */
200 ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
201 if ( mc->mc_refcnt > 1 ) {
202 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
203 ldap_pvt_thread_yield();
207 assert( mc->mc_refcnt == 1 );
208 tmpmc = avl_delete( &mi->mi_conninfo.lai_tree, (caddr_t)mc,
209 meta_back_conndn_cmp );
210 assert( tmpmc == mc );
212 /* delete all cached connections with the current connection */
213 if ( LDAP_BACK_SINGLECONN( mi ) ) {
214 while ( ( tmpmc = avl_delete( &mi->mi_conninfo.lai_tree, (caddr_t)mc, meta_back_conn_cmp ) ) != NULL )
216 Debug( LDAP_DEBUG_TRACE,
217 "=>meta_back_bind: destroying conn %ld (refcnt=%u)\n",
218 LDAP_BACK_PCONN_ID( mc->mc_conn ), mc->mc_refcnt, 0 );
220 if ( tmpmc->mc_refcnt != 0 ) {
222 LDAP_BACK_CONN_TAINTED_SET( tmpmc );
226 * Needs a test because the handler may be corrupted,
227 * and calling ldap_unbind on a corrupted header results
228 * in a segmentation fault
230 meta_back_conn_free( tmpmc );
235 ber_bvreplace( &mc->mc_local_ndn, &op->o_req_ndn );
236 if ( be_isroot_dn( op->o_bd, &op->o_req_ndn ) ) {
237 mc->mc_conn = LDAP_BACK_PCONN_SET( op );
239 lerr = avl_insert( &mi->mi_conninfo.lai_tree, (caddr_t)mc,
240 meta_back_conndn_cmp, meta_back_conndn_dup );
241 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
243 meta_clear_candidates( op, mc );
245 /* we can do this because mc_refcnt == 1 */
247 meta_back_conn_free( mc );
254 meta_back_release_conn( op, mc );
258 * rc is LDAP_SUCCESS if at least one bind succeeded,
259 * err is the last error that occurred during a bind;
260 * if at least (and at most?) one bind succeeds, fine.
262 if ( rc != LDAP_SUCCESS ) {
265 * deal with bind failure ...
269 * no target was found within the naming context,
270 * so bind must fail with invalid credentials
272 if ( rs->sr_err == LDAP_SUCCESS && gotit == 0 ) {
273 rs->sr_err = LDAP_INVALID_CREDENTIALS;
275 rs->sr_err = slap_map_api2result( rs );
277 send_ldap_result( op, rs );
286 meta_back_bind_op_result(
292 ldap_back_send_t sendok )
294 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
295 metatarget_t *mt = mi->mi_targets[ candidate ];
296 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
300 int nretries = mt->mt_nretries;
301 char buf[ SLAP_TEXT_BUFLEN ];
303 if ( rs->sr_err == LDAP_SUCCESS ) {
304 LDAP_BACK_TV_SET( &tv );
310 switch ( ldap_result( msc->msc_ld, msgid, LDAP_MSG_ALL, &tv, &res ) ) {
312 Debug( LDAP_DEBUG_ANY,
313 "%s meta_back_single_bind[%d]: ldap_result=0 nretries=%d.\n",
314 op->o_log_prefix, candidate, nretries );
316 if ( nretries != META_RETRY_NEVER ) {
317 ldap_pvt_thread_yield();
318 if ( nretries > 0 ) {
321 tv = mt->mt_bind_timeout;
325 rs->sr_err = LDAP_BUSY;
326 (void)meta_back_cancel( mc, op, rs, msgid, candidate, sendok );
330 ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER,
333 snprintf( buf, sizeof( buf ),
334 "err=%d (%s) nretries=%d",
335 rs->sr_err, ldap_err2string( rs->sr_err ), nretries );
336 Debug( LDAP_DEBUG_ANY,
337 "### %s meta_back_single_bind[%d]: %s.\n",
338 op->o_log_prefix, candidate, buf );
342 rc = ldap_parse_result( msc->msc_ld, res, &rs->sr_err,
343 NULL, NULL, NULL, NULL, 1 );
344 if ( rc != LDAP_SUCCESS ) {
351 return rs->sr_err = slap_map_api2result( rs );
355 * meta_back_single_bind
357 * attempts to perform a bind with creds
360 meta_back_single_bind(
367 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
368 metatarget_t *mt = mi->mi_targets[ candidate ];
369 struct berval mdn = BER_BVNULL;
370 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
373 if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
374 ch_free( msc->msc_bound_ndn.bv_val );
375 BER_BVZERO( &msc->msc_bound_ndn );
378 if ( LDAP_BACK_SAVECRED( mi ) && !BER_BVISNULL( &msc->msc_cred ) ) {
379 /* destroy sensitive data */
380 memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len );
381 ch_free( msc->msc_cred.bv_val );
382 BER_BVZERO( &msc->msc_cred );
386 * Rewrite the bind dn if needed
392 dc.conn = op->o_conn;
396 if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
397 rs->sr_text = "DN rewrite error";
398 rs->sr_err = LDAP_OTHER;
406 /* FIXME: this fixes the bind problem right now; we need
407 * to use the asynchronous version to get the "matched"
408 * and more in case of failure ... */
409 /* FIXME: should we check if at least some of the op->o_ctrls
410 * can/should be passed? */
411 rs->sr_err = ldap_sasl_bind( msc->msc_ld, mdn.bv_val,
412 LDAP_SASL_SIMPLE, &op->orb_cred,
413 op->o_ctrls, NULL, &msgid );
414 meta_back_bind_op_result( op, rs, mc, candidate, msgid, LDAP_BACK_DONTSEND );
415 if ( rs->sr_err != LDAP_SUCCESS ) {
419 ber_bvreplace( &msc->msc_bound_ndn, &op->o_req_dn );
420 LDAP_BACK_CONN_ISBOUND_SET( msc );
421 mc->mc_authz_target = candidate;
423 if ( LDAP_BACK_SAVECRED( mi ) ) {
424 ber_bvreplace( &msc->msc_cred, &op->orb_cred );
425 ldap_set_rebind_proc( msc->msc_ld, mt->mt_rebind_f, msc );
429 if ( mi->mi_cache.ttl != META_DNCACHE_DISABLED
430 && !BER_BVISEMPTY( &op->o_req_ndn ) )
432 ( void )meta_dncache_update_entry( &mi->mi_cache,
433 &op->o_req_ndn, candidate );
437 if ( mdn.bv_val != op->o_req_dn.bv_val ) {
441 if ( META_BACK_TGT_QUARANTINE( mt ) ) {
442 meta_back_quarantine( op, rs, candidate );
449 * meta_back_single_dobind
452 meta_back_single_dobind(
457 ldap_back_send_t sendok,
461 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
462 metatarget_t *mt = mi->mi_targets[ candidate ];
463 metaconn_t *mc = *mcp;
464 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
466 static struct berval cred = BER_BVC( "" );
469 assert( !LDAP_BACK_CONN_ISBOUND( msc ) );
472 * meta_back_single_dobind() calls meta_back_single_bind()
475 if ( be_isroot( op ) && !BER_BVISNULL( &mt->mt_pseudorootdn ) )
479 op2.o_tag = LDAP_REQ_BIND;
480 op2.o_req_dn = mt->mt_pseudorootdn;
481 op2.o_req_ndn = mt->mt_pseudorootdn;
482 op2.orb_cred = mt->mt_pseudorootpw;
483 op2.orb_method = LDAP_AUTH_SIMPLE;
485 rc = meta_back_single_bind( &op2, rs, *mcp, candidate, 0 );
490 * Otherwise an anonymous bind is performed
491 * (note: if the target was already bound, the anonymous
492 * bind clears the previous bind).
494 if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
495 ber_memfree( msc->msc_bound_ndn.bv_val );
496 BER_BVZERO( &msc->msc_bound_ndn );
499 if ( LDAP_BACK_SAVECRED( mi ) && !BER_BVISNULL( &msc->msc_cred ) ) {
500 /* destroy sensitive data */
501 memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len );
502 ber_memfree( msc->msc_cred.bv_val );
503 BER_BVZERO( &msc->msc_cred );
506 /* FIXME: should we check if at least some of the op->o_ctrls
507 * can/should be passed? */
508 rs->sr_err = ldap_sasl_bind( msc->msc_ld, "", LDAP_SASL_SIMPLE, &cred,
509 NULL, NULL, &msgid );
510 rc = meta_back_bind_op_result( op, rs, mc, candidate, msgid, sendok );
514 if ( rc != LDAP_SUCCESS ) {
516 ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
518 LDAP_BACK_CONN_BINDING_CLEAR( msc );
519 if ( META_BACK_ONERR_STOP( mi ) ) {
520 LDAP_BACK_CONN_TAINTED_SET( mc );
521 meta_back_release_conn_lock( op, mc, 0 );
525 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
528 if ( META_BACK_ONERR_STOP( mi ) && ( sendok & LDAP_BACK_SENDERR ) ) {
529 send_ldap_result( op, rs );
533 if ( META_BACK_TGT_QUARANTINE( mt ) ) {
534 meta_back_quarantine( op, rs, candidate );
548 ldap_back_send_t sendok )
550 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
556 SlapReply *candidates = meta_back_candidates_get( op );
558 if ( be_isroot( op ) ) {
562 Debug( LDAP_DEBUG_TRACE,
563 "%s meta_back_dobind: conn=%ld%s\n",
565 LDAP_BACK_PCONN_ID( mc->mc_conn ),
566 isroot ? " (isroot)" : "" );
569 * all the targets are bound as pseudoroot
571 if ( mc->mc_authz_target == META_BOUND_ALL ) {
576 for ( i = 0; i < mi->mi_ntargets; i++ ) {
577 metatarget_t *mt = mi->mi_targets[ i ];
578 metasingleconn_t *msc = &mc->mc_conns[ i ];
579 int rc, do_retry = 1;
584 if ( !META_IS_CANDIDATE( &candidates[ i ] ) ) {
588 assert( msc->msc_ld != NULL );
591 * If the target is already bound it is skipped
595 ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
596 if ( LDAP_BACK_CONN_ISBOUND( msc ) || LDAP_BACK_CONN_ISANON( msc ) ) {
597 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
601 } else if ( LDAP_BACK_CONN_BINDING( msc ) ) {
602 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
603 ldap_pvt_thread_yield();
608 LDAP_BACK_CONN_BINDING_SET( msc );
609 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
612 rc = meta_back_single_dobind( op, rs, &mc, i,
613 LDAP_BACK_DONTSEND, mt->mt_nretries, 1 );
615 * NOTE: meta_back_single_dobind() already retries;
616 * in case of failure, it resets mc...
618 if ( rc != LDAP_SUCCESS ) {
619 char buf[ SLAP_TEXT_BUFLEN ];
622 /* meta_back_single_dobind() already sent
623 * response and released connection */
628 if ( rc == LDAP_UNAVAILABLE && do_retry ) {
630 if ( meta_back_retry( op, rs, &mc, i, sendok ) ) {
635 ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
636 LDAP_BACK_CONN_BINDING_CLEAR( msc );
637 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
643 ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
644 LDAP_BACK_CONN_BINDING_CLEAR( msc );
645 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
647 snprintf( buf, sizeof( buf ),
648 "meta_back_dobind[%d]: (%s) err=%d (%s).",
649 i, isroot ? op->o_bd->be_rootdn.bv_val : "anonymous",
650 rc, ldap_err2string( rc ) );
651 Debug( LDAP_DEBUG_ANY,
653 op->o_log_prefix, buf, 0 );
656 * null cred bind should always succeed
657 * as anonymous, so a failure means
658 * the target is no longer candidate possibly
659 * due to technical reasons (remote host down?)
660 * so better clear the handle
662 /* leave the target candidate, but record the error for later use */
663 candidates[ i ].sr_err = rc;
664 if ( META_BACK_ONERR_STOP( mi ) ) {
672 Debug( LDAP_DEBUG_TRACE,
673 "%s meta_back_dobind[%d]: "
676 isroot ? op->o_bd->be_rootdn.bv_val : "anonymous" );
678 ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
679 LDAP_BACK_CONN_BINDING_CLEAR( msc );
681 LDAP_BACK_CONN_ISBOUND_SET( msc );
683 LDAP_BACK_CONN_ISANON_SET( msc );
685 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
690 Debug( LDAP_DEBUG_TRACE,
691 "%s meta_back_dobind: conn=%ld bound=%d\n",
692 op->o_log_prefix, LDAP_BACK_PCONN_ID( mc->mc_conn ), bound );
695 meta_back_release_conn( op, mc );
698 if ( sendok & LDAP_BACK_SENDERR ) {
699 if ( rs->sr_err == LDAP_SUCCESS ) {
700 rs->sr_err = LDAP_BUSY;
702 send_ldap_result( op, rs );
708 return ( bound > 0 );
712 * meta_back_default_rebind
714 * This is a callback used for chasing referrals using the same
715 * credentials as the original user on this session.
718 meta_back_default_rebind(
720 LDAP_CONST char *url,
725 metasingleconn_t *msc = ( metasingleconn_t * )params;
727 return ldap_sasl_bind_s( ld, msc->msc_bound_ndn.bv_val,
728 LDAP_SASL_SIMPLE, &msc->msc_cred,
733 * meta_back_default_urllist
735 * This is a callback used for mucking with the urllist
738 meta_back_default_urllist(
740 LDAPURLDesc **urllist,
744 metatarget_t *mt = (metatarget_t *)params;
745 LDAPURLDesc **urltail;
747 if ( urllist == url ) {
751 for ( urltail = &(*url)->lud_next; *urltail; urltail = &(*urltail)->lud_next )
758 ldap_pvt_thread_mutex_lock( &mt->mt_uri_mutex );
760 ch_free( mt->mt_uri );
763 ldap_get_option( ld, LDAP_OPT_URI, (void *)&mt->mt_uri );
764 ldap_pvt_thread_mutex_unlock( &mt->mt_uri_mutex );
776 ldap_back_send_t sendok )
778 metainfo_t *mi = (metainfo_t *)op->o_bd->be_private;
780 metatarget_t *mt = mi->mi_targets[ candidate ];
781 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
783 /* default behavior */
784 if ( META_BACK_TGT_ABANDON( mt ) ) {
785 return ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
788 if ( META_BACK_TGT_IGNORE( mt ) ) {
792 if ( META_BACK_TGT_CANCEL( mt ) ) {
793 /* FIXME: asynchronous? */
794 return ldap_cancel_s( msc->msc_ld, msgid, NULL, NULL );
805 * FIXME: error return must be handled in a cleaner way ...
814 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
820 const char *save_rmsg = NULL,
822 void *rmatch_ctx = NULL;
824 assert( mc != NULL );
826 if ( candidate != META_TARGET_NONE ) {
827 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
829 rs->sr_err = LDAP_SUCCESS;
831 ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER, &rs->sr_err );
832 if ( rs->sr_err != LDAP_SUCCESS ) {
834 * better check the type of error. In some cases
835 * (search ?) it might be better to return a
836 * success if at least one of the targets gave
837 * positive result ...
839 ldap_get_option( msc->msc_ld,
840 LDAP_OPT_ERROR_STRING, &rmsg );
841 if ( rmsg != NULL && rmsg[ 0 ] == '\0' ) {
842 ldap_memfree( rmsg );
846 ldap_get_option( msc->msc_ld,
847 LDAP_OPT_MATCHED_DN, &rmatch );
848 if ( rmatch != NULL && rmatch[ 0 ] == '\0' ) {
849 ldap_memfree( rmatch );
853 rerr = rs->sr_err = slap_map_api2result( rs );
855 if ( LogTest( LDAP_DEBUG_ANY ) ) {
856 char buf[ SLAP_TEXT_BUFLEN ];
858 snprintf( buf, sizeof( buf ),
859 "meta_back_op_result[%d] "
860 "err=%d text=\"%s\" matched=\"%s\"",
861 candidate, rs->sr_err,
862 ( rmsg ? rmsg : "" ),
863 ( rmatch ? rmatch : "" ) );
864 Debug( LDAP_DEBUG_ANY, "%s %s.\n",
865 op->o_log_prefix, buf, 0 );
869 if ( META_BACK_TGT_QUARANTINE( mi->mi_targets[ candidate ] ) ) {
870 meta_back_quarantine( op, rs, candidate );
874 for ( i = 0; i < mi->mi_ntargets; i++ ) {
875 metasingleconn_t *msc = &mc->mc_conns[ i ];
879 rs->sr_err = LDAP_SUCCESS;
881 ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER, &rs->sr_err );
882 if ( rs->sr_err != LDAP_SUCCESS ) {
884 * better check the type of error. In some cases
885 * (search ?) it might be better to return a
886 * success if at least one of the targets gave
887 * positive result ...
889 ldap_get_option( msc->msc_ld,
890 LDAP_OPT_ERROR_STRING, &msg );
891 if ( msg != NULL && msg[ 0 ] == '\0' ) {
896 ldap_get_option( msc->msc_ld,
897 LDAP_OPT_MATCHED_DN, &match );
898 if ( match != NULL && match[ 0 ] == '\0' ) {
899 ldap_memfree( match );
903 rs->sr_err = slap_map_api2result( rs );
905 if ( LogTest( LDAP_DEBUG_ANY ) ) {
906 char buf[ SLAP_TEXT_BUFLEN ];
908 snprintf( buf, sizeof( buf ),
909 "meta_back_op_result[%d] "
910 "err=%d text=\"%s\" matched=\"%s\"",
912 ( rmsg ? rmsg : "" ),
913 ( rmatch ? rmatch : "" ) );
914 Debug( LDAP_DEBUG_ANY, "%s %s.\n",
915 op->o_log_prefix, buf, 0 );
919 * FIXME: need to rewrite "match" (need rwinfo)
921 switch ( rs->sr_err ) {
926 ldap_memfree( rmsg );
931 if ( match != NULL ) {
933 ldap_memfree( rmatch );
946 ldap_memfree( match );
950 if ( META_BACK_TGT_QUARANTINE( mi->mi_targets[ i ] ) ) {
951 meta_back_quarantine( op, rs, i );
957 if ( rmsg != NULL ) {
958 save_rmsg = rs->sr_text;
961 if ( rmatch != NULL ) {
962 struct berval dn, pdn;
964 ber_str2bv( rmatch, 0, 0, &dn );
965 if ( dnPretty( NULL, &dn, &pdn, op->o_tmpmemctx ) == LDAP_SUCCESS ) {
966 ldap_memfree( rmatch );
967 rmatch_ctx = op->o_tmpmemctx;
970 save_rmatch = rs->sr_matched;
971 rs->sr_matched = rmatch;
973 send_ldap_result( op, rs );
974 if ( rmsg != NULL ) {
976 rs->sr_text = save_rmsg;
978 if ( rmatch != NULL ) {
979 ber_memfree_x( rmatch, rmatch_ctx );
980 rs->sr_matched = save_rmatch;
983 return ( ( rerr == LDAP_SUCCESS ) ? 0 : -1 );