2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2005 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_single_bind(
52 meta_back_bind( Operation *op, SlapReply *rs )
54 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
55 metaconn_t *mc = NULL;
62 SlapReply *candidates = meta_back_candidates_get( op );
64 rs->sr_err = LDAP_SUCCESS;
66 Debug( LDAP_DEBUG_ARGS, "%s meta_back_bind: dn=\"%s\".\n",
67 op->o_log_prefix, op->o_req_dn.bv_val, 0 );
69 /* the test on the bind method should be superfluous */
70 if ( op->orb_method == LDAP_AUTH_SIMPLE
71 && be_isroot_dn( op->o_bd, &op->o_req_ndn ) )
73 if ( !be_isroot_pw( op ) ) {
74 rs->sr_err = LDAP_INVALID_CREDENTIALS;
76 send_ldap_result( op, rs );
80 if ( META_BACK_DEFER_ROOTDN_BIND( mi ) ) {
81 rs->sr_err = LDAP_SUCCESS;
83 send_ldap_result( op, rs );
90 /* we need meta_back_getconn() not send result even on error,
91 * because we want to intercept the error and make it
92 * invalidCredentials */
93 mc = meta_back_getconn( op, rs, NULL, LDAP_BACK_DONTSEND );
95 char buf[ SLAP_TEXT_BUFLEN ];
97 snprintf( buf, sizeof( buf ),
98 "meta_back_bind: no target "
99 "for dn \"%s\" (%d%s%s).",
100 op->o_req_dn.bv_val, rs->sr_err,
101 rs->sr_text ? ". " : "",
102 rs->sr_text ? rs->sr_text : "" );
103 Debug( LDAP_DEBUG_ANY,
105 op->o_log_prefix, buf, 0 );
107 /* FIXME: there might be cases where we don't want
108 * to map the error onto invalidCredentials */
109 switch ( rs->sr_err ) {
110 case LDAP_NO_SUCH_OBJECT:
111 case LDAP_UNWILLING_TO_PERFORM:
112 rs->sr_err = LDAP_INVALID_CREDENTIALS;
116 send_ldap_result( op, rs );
121 * Each target is scanned ...
123 mc->mc_authz_target = META_BOUND_NONE;
124 for ( i = 0; i < mi->mi_ntargets; i++ ) {
129 * Skip non-candidates
131 if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
136 /* set rc to LDAP_SUCCESS only if at least
137 * one candidate has been tried */
141 } else if ( isroot == 0 ) {
143 * A bind operation is expected to have
144 * ONE CANDIDATE ONLY!
146 Debug( LDAP_DEBUG_ANY,
147 "### %s meta_back_bind: more than one"
148 " candidate is trying to bind...\n",
149 op->o_log_prefix, 0, 0 );
153 if ( BER_BVISNULL( &mi->mi_targets[ i ].mt_pseudorootdn ) )
155 metasingleconn_t *msc = &mc->mc_conns[ i ];
157 /* skip the target if no pseudorootdn is provided */
158 if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
159 ch_free( msc->msc_bound_ndn.bv_val );
160 BER_BVZERO( &msc->msc_bound_ndn );
163 if ( LDAP_BACK_SAVECRED( mi ) &&
164 !BER_BVISNULL( &msc->msc_cred ) )
166 /* destroy sensitive data */
167 memset( msc->msc_cred.bv_val, 0,
168 msc->msc_cred.bv_len );
169 ch_free( msc->msc_cred.bv_val );
170 BER_BVZERO( &msc->msc_cred );
176 op2.o_req_dn = mi->mi_targets[ i ].mt_pseudorootdn;
177 op2.o_req_ndn = mi->mi_targets[ i ].mt_pseudorootdn;
178 op2.orb_cred = mi->mi_targets[ i ].mt_pseudorootpw;
179 op2.orb_method = LDAP_AUTH_SIMPLE;
182 lerr = meta_back_single_bind( &op2, rs, mc, i );
183 if ( lerr != LDAP_SUCCESS ) {
185 candidates[ i ].sr_tag = META_NOT_CANDIDATE;
187 if ( META_BACK_ONERR_STOP( mi ) ) {
194 /* must re-insert if local DN changed as result of bind */
195 if ( rc == LDAP_SUCCESS ) {
197 mc->mc_authz_target = META_BOUND_ALL;
198 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ) );
201 if ( !dn_match( &op->o_req_ndn, &mc->mc_local_ndn ) ) {
204 /* wait for all other ops to release the connection */
206 ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
207 if ( mc->mc_refcnt > 1 ) {
208 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
209 ldap_pvt_thread_yield();
213 assert( mc->mc_refcnt == 1 );
214 mc = avl_delete( &mi->mi_conntree, (caddr_t)mc,
215 meta_back_conn_cmp );
216 assert( mc != NULL );
218 ber_bvreplace( &mc->mc_local_ndn, &op->o_req_ndn );
219 lerr = avl_insert( &mi->mi_conntree, (caddr_t)mc,
220 meta_back_conn_cmp, meta_back_conn_dup );
221 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
223 for ( i = 0; i < mi->mi_ntargets; ++i ) {
224 if ( mc->mc_conns[ i ].msc_ld != NULL ) {
225 meta_clear_one_candidate( &mc->mc_conns[ i ] );
229 /* we can do this because mc_refcnt == 1 */
231 meta_back_conn_free( mc );
238 meta_back_release_conn( op, mc );
242 * rc is LDAP_SUCCESS if at least one bind succeeded,
243 * err is the last error that occurred during a bind;
244 * if at least (and at most?) one bind succeeds, fine.
246 if ( rc != LDAP_SUCCESS ) {
249 * deal with bind failure ...
253 * no target was found within the naming context,
254 * so bind must fail with invalid credentials
256 if ( rs->sr_err == LDAP_SUCCESS && gotit == 0 ) {
257 rs->sr_err = LDAP_INVALID_CREDENTIALS;
259 rs->sr_err = slap_map_api2result( rs );
261 send_ldap_result( op, rs );
270 * meta_back_single_bind
272 * attempts to perform a bind with creds
275 meta_back_single_bind(
281 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
282 metatarget_t *mt = &mi->mi_targets[ candidate ];
283 struct berval mdn = BER_BVNULL;
285 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
290 if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
291 ch_free( msc->msc_bound_ndn.bv_val );
292 BER_BVZERO( &msc->msc_bound_ndn );
295 if ( LDAP_BACK_SAVECRED( mi ) && !BER_BVISNULL( &msc->msc_cred ) ) {
296 /* destroy sensitive data */
297 memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len );
298 ch_free( msc->msc_cred.bv_val );
299 BER_BVZERO( &msc->msc_cred );
303 * Rewrite the bind dn if needed
306 dc.conn = op->o_conn;
310 if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
311 send_ldap_result( op, rs );
315 /* FIXME: this fixes the bind problem right now; we need
316 * to use the asynchronous version to get the "matched"
317 * and more in case of failure ... */
318 /* FIXME: should we check if at least some of the op->o_ctrls
319 * can/should be passed? */
321 rs->sr_err = ldap_sasl_bind( msc->msc_ld, mdn.bv_val,
322 LDAP_SASL_SIMPLE, &op->orb_cred,
323 op->o_ctrls, NULL, &msgid );
324 if ( rs->sr_err == LDAP_SUCCESS ) {
328 int nretries = mt->mt_nretries;
330 LDAP_BACK_TV_SET( &tv );
337 tv.tv_usec = META_BIND_TIMEOUT;
338 switch ( ldap_result( msc->msc_ld, msgid, 0, &tv, &res ) ) {
340 Debug( LDAP_DEBUG_ANY,
341 "%s meta_back_single_bind: "
342 "ldap_result=0 nretries=%d%s\n",
343 op->o_log_prefix, nretries,
344 rebinding ? " rebinding" : "" );
346 if ( nretries != META_RETRY_NEVER ) {
347 ldap_pvt_thread_yield();
348 if ( nretries > 0 ) {
351 LDAP_BACK_TV_SET( &tv );
354 rs->sr_err = LDAP_BUSY;
356 ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
360 /* FIXME: some times the request times out
361 * while the other party is not willing to
362 * send a response any more. Give it a second
363 * chance with a freshly bound connection */
365 nretries = mt->mt_nretries;
369 ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER,
373 ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
376 Debug( LDAP_DEBUG_ANY,
377 "### %s meta_back_single_bind: "
378 "err=%d nretries=%d\n",
379 op->o_log_prefix, rs->sr_err, nretries );
381 rc = slap_map_api2result( rs );
382 if ( rs->sr_err == LDAP_UNAVAILABLE && nretries != META_RETRY_NEVER ) {
383 ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
384 if ( mc->mc_refcnt == 1 ) {
385 ldap_unbind_ext_s( msc->msc_ld, NULL, NULL );
387 LDAP_BACK_CONN_ISBOUND_CLEAR( msc );
389 ( void )rewrite_session_delete( mt->mt_rwmap.rwm_rw, op->o_conn );
391 /* mc here must be the regular mc,
392 * reset and ready for init */
393 rc = meta_back_init_one_conn( op, rs,
394 mt, mc, msc, LDAP_BACK_CONN_ISPRIV( mc ),
395 candidate == mc->mc_authz_target,
396 LDAP_BACK_DONTSEND );
399 /* can't do anything about it */
403 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
406 if ( nretries > 0 ) {
409 ldap_pvt_thread_yield();
416 rc = ldap_parse_result( msc->msc_ld, res, &rs->sr_err,
417 NULL, NULL, NULL, NULL, 1 );
418 if ( rc != LDAP_SUCCESS ) {
425 if ( rs->sr_err != LDAP_SUCCESS ) {
426 rs->sr_err = slap_map_api2result( rs );
430 ber_bvreplace( &msc->msc_bound_ndn, &op->o_req_dn );
431 LDAP_BACK_CONN_ISBOUND_SET( msc );
432 mc->mc_authz_target = candidate;
434 if ( LDAP_BACK_SAVECRED( mi ) ) {
435 ber_bvreplace( &msc->msc_cred, &op->orb_cred );
436 ldap_set_rebind_proc( msc->msc_ld, meta_back_rebind_f, msc );
439 if ( mi->mi_cache.ttl != META_DNCACHE_DISABLED
440 && op->o_req_ndn.bv_len != 0 )
442 ( void )meta_dncache_update_entry( &mi->mi_cache,
443 &op->o_req_ndn, candidate );
447 if ( mdn.bv_val != op->o_req_dn.bv_val ) {
455 * meta_back_single_dobind
458 meta_back_single_dobind(
463 ldap_back_send_t sendok,
467 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
468 metatarget_t *mt = &mi->mi_targets[ candidate ];
469 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
471 static struct berval cred = BER_BVC( "" );
474 save_nretries = nretries;
476 assert( !LDAP_BACK_CONN_ISBOUND( msc ) );
479 * Otherwise an anonymous bind is performed
480 * (note: if the target was already bound, the anonymous
481 * bind clears the previous bind).
483 if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
484 ber_memfree( msc->msc_bound_ndn.bv_val );
485 BER_BVZERO( &msc->msc_bound_ndn );
488 if ( LDAP_BACK_SAVECRED( mi ) && !BER_BVISNULL( &msc->msc_cred ) ) {
489 /* destroy sensitive data */
490 memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len );
491 ber_memfree( msc->msc_cred.bv_val );
492 BER_BVZERO( &msc->msc_cred );
495 /* FIXME: should we check if at least some of the op->o_ctrls
496 * can/should be passed? */
498 rc = ldap_sasl_bind( msc->msc_ld, "", LDAP_SASL_SIMPLE, &cred,
499 NULL, NULL, &msgid );
500 if ( rc == LDAP_SUCCESS ) {
504 LDAP_BACK_TV_SET( &tv );
511 tv.tv_usec = META_BIND_TIMEOUT;
512 switch ( ldap_result( msc->msc_ld, msgid, 0, &tv, &res ) ) {
514 Debug( LDAP_DEBUG_ANY,
515 "%s meta_back_single_dobind: "
516 "ldap_result=0 nretries=%d%s\n",
517 op->o_log_prefix, nretries,
518 rebinding ? " rebinding" : "" );
520 if ( nretries != META_RETRY_NEVER ) {
521 ldap_pvt_thread_yield();
522 if ( nretries > 0 ) {
525 LDAP_BACK_TV_SET( &tv );
531 ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
535 /* FIXME: some times the request times out
536 * while the other party is not willing to
537 * send a response any more. Give it a second
538 * chance with a freshly bound connection */
540 nretries = save_nretries;
544 ldap_get_option( msc->msc_ld,
545 LDAP_OPT_ERROR_NUMBER, &rs->sr_err );
548 ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
551 Debug( LDAP_DEBUG_ANY,
552 "### %s meta_back_single_dobind: "
553 "err=%d nretries=%d\n",
554 op->o_log_prefix, rs->sr_err, nretries );
556 rc = slap_map_api2result( rs );
557 if ( rc == LDAP_UNAVAILABLE && nretries != META_RETRY_NEVER ) {
559 ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
562 if ( mc->mc_refcnt == 1 ) {
563 ldap_unbind_ext_s( msc->msc_ld, NULL, NULL );
565 LDAP_BACK_CONN_ISBOUND_CLEAR( msc );
567 ( void )rewrite_session_delete( mt->mt_rwmap.rwm_rw, op->o_conn );
569 /* mc here must be the regular mc,
570 * reset and ready for init */
571 rc = meta_back_init_one_conn( op, rs,
573 LDAP_BACK_CONN_ISPRIV( mc ),
574 candidate == mc->mc_authz_target,
575 LDAP_BACK_DONTSEND );
579 /* can't do anything about it */
580 rc = LDAP_UNAVAILABLE;
584 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
587 if ( rc == LDAP_SUCCESS ) {
588 ldap_pvt_thread_yield();
589 if ( nretries > 0 ) {
598 rc = ldap_parse_result( msc->msc_ld, res, &rs->sr_err,
599 NULL, NULL, NULL, NULL, 1 );
600 if ( rc == LDAP_SUCCESS ) {
601 rc = slap_map_api2result( rs );
608 rc = slap_map_api2result( rs );
612 if ( rc != LDAP_SUCCESS && ( sendok & LDAP_BACK_SENDERR ) ) {
613 send_ldap_result( op, rs );
627 ldap_back_send_t sendok )
629 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
635 SlapReply *candidates = meta_back_candidates_get( op );
637 if ( be_isroot( op ) ) {
641 Debug( LDAP_DEBUG_TRACE,
642 "%s meta_back_dobind: conn=%ld%s\n",
644 LDAP_BACK_PCONN_ID( mc->mc_conn ),
645 isroot ? " (isroot)" : "" );
647 ldap_pvt_thread_mutex_lock( &mc->mc_mutex );
650 * all the targets are bound as pseudoroot
652 if ( mc->mc_authz_target == META_BOUND_ALL ) {
657 for ( i = 0; i < mi->mi_ntargets; i++ ) {
658 metatarget_t *mt = &mi->mi_targets[ i ];
659 metasingleconn_t *msc = &mc->mc_conns[ i ];
666 if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
670 assert( msc->msc_ld != NULL );
673 * If the target is already bound it is skipped
675 if ( LDAP_BACK_CONN_ISBOUND( msc ) || LDAP_BACK_CONN_ISANON( msc ) ) {
680 if ( isroot && !BER_BVISNULL( &mi->mi_targets[ i ].mt_pseudorootdn ) )
684 op2.o_tag = LDAP_REQ_BIND;
685 op2.o_req_dn = mi->mi_targets[ i ].mt_pseudorootdn;
686 op2.o_req_ndn = mi->mi_targets[ i ].mt_pseudorootdn;
687 op2.orb_cred = mi->mi_targets[ i ].mt_pseudorootpw;
688 op2.orb_method = LDAP_AUTH_SIMPLE;
690 rootdn = mi->mi_targets[ i ].mt_pseudorootdn.bv_val;
692 rc = meta_back_single_bind( &op2, rs, mc, i );
695 rc = meta_back_single_dobind( op, rs, mc, i,
696 LDAP_BACK_DONTSEND, mt->mt_nretries, 1 );
699 if ( rc != LDAP_SUCCESS ) {
700 char buf[ SLAP_TEXT_BUFLEN ];
702 snprintf( buf, sizeof( buf ),
703 "meta_back_dobind[%d]: (%s) err=%d.",
704 i, rootdn ? rootdn : "anonymous", rc );
705 Debug( LDAP_DEBUG_ANY,
707 op->o_log_prefix, buf, 0 );
710 * null cred bind should always succeed
711 * as anonymous, so a failure means
712 * the target is no longer candidate possibly
713 * due to technical reasons (remote host down?)
714 * so better clear the handle
716 /* leave the target candidate, but record the error for later use */
717 candidates[ i ].sr_err = rc;
718 if ( META_BACK_ONERR_STOP( mi ) ) {
725 Debug( LDAP_DEBUG_TRACE,
726 "%s meta_back_dobind[%d]: "
729 rootdn ? rootdn : "anonymous" );
732 LDAP_BACK_CONN_ISBOUND_SET( msc );
734 LDAP_BACK_CONN_ISANON_SET( msc );
740 ldap_pvt_thread_mutex_unlock( &mc->mc_mutex );
742 Debug( LDAP_DEBUG_TRACE,
743 "%s meta_back_dobind: conn=%ld bound=%d\n",
744 op->o_log_prefix, LDAP_BACK_PCONN_ID( mc->mc_conn ), bound );
747 meta_back_release_conn( op, mc );
749 if ( sendok & LDAP_BACK_SENDERR ) {
750 if ( rs->sr_err == LDAP_SUCCESS ) {
751 rs->sr_err = LDAP_BUSY;
753 send_ldap_result( op, rs );
761 * meta_back_default_rebind
763 * This is a callback used for chasing referrals using the same
764 * credentials as the original user on this session.
767 meta_back_default_rebind(
769 LDAP_CONST char *url,
774 metasingleconn_t *msc = ( metasingleconn_t * )params;
776 return ldap_sasl_bind_s( ld, msc->msc_bound_ndn.bv_val,
777 LDAP_SASL_SIMPLE, &msc->msc_cred,
782 * FIXME: error return must be handled in a cleaner way ...
791 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
797 const char *save_rmsg = NULL,
799 void *rmatch_ctx = NULL;
801 if ( candidate != META_TARGET_NONE ) {
802 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
804 rs->sr_err = LDAP_SUCCESS;
806 ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER, &rs->sr_err );
807 if ( rs->sr_err != LDAP_SUCCESS ) {
809 * better check the type of error. In some cases
810 * (search ?) it might be better to return a
811 * success if at least one of the targets gave
812 * positive result ...
814 ldap_get_option( msc->msc_ld,
815 LDAP_OPT_ERROR_STRING, &rmsg );
816 if ( rmsg != NULL && rmsg[ 0 ] == '\0' ) {
817 ldap_memfree( rmsg );
821 ldap_get_option( msc->msc_ld,
822 LDAP_OPT_MATCHED_DN, &rmatch );
823 if ( rmatch != NULL && rmatch[ 0 ] == '\0' ) {
824 ldap_memfree( rmatch );
828 rerr = rs->sr_err = slap_map_api2result( rs );
830 Debug(LDAP_DEBUG_ANY,
831 "==> meta_back_op_result: target"
832 " <%d> sending msg \"%s\""
833 " (matched \"%s\")\n",
834 candidate, ( rmsg ? rmsg : "" ),
835 ( rmatch ? rmatch : "" ) );
839 for ( i = 0; i < mi->mi_ntargets; i++ ) {
840 metasingleconn_t *msc = &mc->mc_conns[ i ];
844 rs->sr_err = LDAP_SUCCESS;
846 ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER, &rs->sr_err );
847 if ( rs->sr_err != LDAP_SUCCESS ) {
849 * better check the type of error. In some cases
850 * (search ?) it might be better to return a
851 * success if at least one of the targets gave
852 * positive result ...
854 ldap_get_option( msc->msc_ld,
855 LDAP_OPT_ERROR_STRING, &msg );
856 if ( msg != NULL && msg[ 0 ] == '\0' ) {
861 ldap_get_option( msc->msc_ld,
862 LDAP_OPT_MATCHED_DN, &match );
863 if ( match != NULL && match[ 0 ] == '\0' ) {
864 ldap_memfree( match );
868 rs->sr_err = slap_map_api2result( rs );
870 Debug(LDAP_DEBUG_ANY,
871 "==> meta_back_op_result: target"
872 " <%d> sending msg \"%s\""
873 " (matched \"%s\")\n",
874 i, ( msg ? msg : "" ),
875 ( match ? match : "" ) );
878 * FIXME: need to rewrite "match" (need rwinfo)
880 switch ( rs->sr_err ) {
885 ldap_memfree( rmsg );
890 if ( match != NULL ) {
892 ldap_memfree( rmatch );
905 ldap_memfree( match );
912 if ( rmsg != NULL ) {
913 save_rmsg = rs->sr_text;
916 if ( rmatch != NULL ) {
917 struct berval dn, pdn;
919 ber_str2bv( rmatch, 0, 0, &dn );
920 if ( dnPretty( NULL, &dn, &pdn, op->o_tmpmemctx ) == LDAP_SUCCESS ) {
921 ldap_memfree( rmatch );
922 rmatch_ctx = op->o_tmpmemctx;
925 save_rmatch = rs->sr_matched;
926 rs->sr_matched = rmatch;
928 send_ldap_result( op, rs );
929 if ( rmsg != NULL ) {
931 rs->sr_text = save_rmsg;
933 if ( rmatch != NULL ) {
934 ber_memfree_x( rmatch, rmatch_ctx );
935 rs->sr_matched = save_rmatch;
938 return ( ( rerr == LDAP_SUCCESS ) ? 0 : -1 );