]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/bind.c
Drop unnecessary memset()s
[openldap] / servers / slapd / back-meta / bind.c
index 888f1c0d03640384501f2f5faa96a228dda0b8ca..0f450bef669f91bfcba697769825ada9b2aae134 100644 (file)
@@ -33,6 +33,8 @@
 #include "slap.h"
 #include "../back-ldap/back-ldap.h"
 #include "back-meta.h"
+#undef ldap_debug      /* silence a warning in ldap-int.h */
+#include "../../../libraries/libldap/ldap-int.h"
 
 #include "lutil_ldap.h"
 
@@ -166,9 +168,7 @@ meta_back_bind( Operation *op, SlapReply *rs )
                                        BER_BVZERO( &msc->msc_bound_ndn );
                                }
 
-                               if ( LDAP_BACK_SAVECRED( mi ) &&
-                                       !BER_BVISNULL( &msc->msc_cred ) )
-                               {
+                               if ( !BER_BVISNULL( &msc->msc_cred ) ) {
                                        /* destroy sensitive data */
                                        memset( msc->msc_cred.bv_val, 0,
                                                msc->msc_cred.bv_len );
@@ -220,7 +220,7 @@ retry_lock:;
 
                        assert( mc->mc_refcnt == 1 );
 #if META_BACK_PRINT_CONNTREE > 0
-                       meta_back_print_conntree( mi->mi_conninfo.lai_tree, ">>> meta_back_bind" );
+                       meta_back_print_conntree( mi, ">>> meta_back_bind" );
 #endif /* META_BACK_PRINT_CONNTREE */
                        tmpmc = avl_delete( &mi->mi_conninfo.lai_tree, (caddr_t)mc,
                                meta_back_conndn_cmp );
@@ -251,18 +251,18 @@ retry_lock:;
 
                        ber_bvreplace( &mc->mc_local_ndn, &op->o_req_ndn );
                        if ( isroot ) {
-                               mc->mc_conn = LDAP_BACK_PCONN_SET( op );
+                               LDAP_BACK_CONN_ISPRIV_SET( mc );
+                               LDAP_BACK_PCONN_SET( mc, op );
                        }
                        lerr = avl_insert( &mi->mi_conninfo.lai_tree, (caddr_t)mc,
                                meta_back_conndn_cmp, meta_back_conndn_dup );
 #if META_BACK_PRINT_CONNTREE > 0
-                       meta_back_print_conntree( mi->mi_conninfo.lai_tree, "<<< meta_back_bind" );
+                       meta_back_print_conntree( mi, "<<< meta_back_bind" );
 #endif /* META_BACK_PRINT_CONNTREE */
                        ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
                        if ( lerr == -1 ) {
-                               meta_clear_candidates( op, mc );
-
                                /* we can do this because mc_refcnt == 1 */
+                               assert( mc->mc_refcnt == 1 );
                                mc->mc_refcnt = 0;
                                meta_back_conn_free( mc );
                                mc = NULL;
@@ -392,9 +392,14 @@ retry:;
                         * because there's a pending bind that will not
                         * be acknowledged */
                        ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
-                       ldap_unbind_ext( msc->msc_ld, NULL, NULL );
-                       msc->msc_ld = NULL;
-                       LDAP_BACK_CONN_BINDING_CLEAR( msc );
+                       assert( LDAP_BACK_CONN_BINDING( msc ) );
+
+#ifdef DEBUG_205
+                       Debug( LDAP_DEBUG_ANY, "### %s meta_back_bind_op_result ldap_unbind_ext[%d] ld=%p\n",
+                               op->o_log_prefix, candidate, (void *)msc->msc_ld );
+#endif /* DEBUG_205 */
+
+                       meta_clear_one_candidate( op, mc, candidate );
                        ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
 
                        rs->sr_err = timeout_err;
@@ -402,7 +407,7 @@ retry:;
                        break;
 
                case -1:
-                       ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER,
+                       ldap_get_option( msc->msc_ld, LDAP_OPT_RESULT_CODE,
                                &rs->sr_err );
 
                        snprintf( buf, sizeof( buf ),
@@ -462,7 +467,7 @@ meta_back_single_bind(
                BER_BVZERO( &msc->msc_bound_ndn );
        }
 
-       if ( LDAP_BACK_SAVECRED( mi ) && !BER_BVISNULL( &msc->msc_cred ) ) {
+       if ( !BER_BVISNULL( &msc->msc_cred ) ) {
                /* destroy sensitive data */
                memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len );
                ch_free( msc->msc_cred.bv_val );
@@ -514,6 +519,10 @@ meta_back_single_bind(
        mc->mc_authz_target = candidate;
 
        if ( LDAP_BACK_SAVECRED( mi ) ) {
+               if ( !BER_BVISNULL( &msc->msc_cred ) ) {
+                       memset( msc->msc_cred.bv_val, 0,
+                               msc->msc_cred.bv_len );
+               }
                ber_bvreplace( &msc->msc_cred, &op->orb_cred );
                ldap_set_rebind_proc( msc->msc_ld, mt->mt_rebind_f, msc );
        }
@@ -566,7 +575,7 @@ meta_back_single_dobind(
                !op->o_do_not_cache &&
                ( BER_BVISNULL( &msc->msc_bound_ndn ) ||
                        BER_BVISEMPTY( &msc->msc_bound_ndn ) ||
-                       ( LDAP_BACK_CONN_ISPRIV( msc ) && dn_match( &msc->msc_bound_ndn, &mt->mt_idassert_authcDN ) ) ||
+                       ( LDAP_BACK_CONN_ISPRIV( mc ) && dn_match( &msc->msc_bound_ndn, &mt->mt_idassert_authcDN ) ) ||
                        ( mt->mt_idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) ) )
        {
                (void)meta_back_proxy_authz_bind( mc, candidate, op, rs, sendok );
@@ -672,7 +681,8 @@ retry_binding:;
                        ++bound;
                        continue;
 
-               } else if ( LDAP_BACK_CONN_BINDING( msc ) ) {
+               } else if ( META_BACK_CONN_CREATING( msc ) || LDAP_BACK_CONN_BINDING( msc ) )
+               {
                        ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
                        ldap_pvt_thread_yield();
                        goto retry_binding;
@@ -699,7 +709,7 @@ retry_binding:;
 
 
                        if ( rc == LDAP_UNAVAILABLE ) {
-                               /* FIXME: meta_back_retry() already calls
+                               /* FIXME: meta_back_retry() already re-calls
                                 * meta_back_single_dobind() */
                                if ( meta_back_retry( op, rs, &mc, i, sendok ) ) {
                                        goto retry_ok;
@@ -709,6 +719,7 @@ retry_binding:;
                                        ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
                                        LDAP_BACK_CONN_BINDING_CLEAR( msc );
                                        ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
+                                       meta_back_release_conn( op, mc );
                                }
 
                                return 0;
@@ -865,7 +876,7 @@ meta_back_cancel(
                rc = ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
 
        } else if ( META_BACK_TGT_IGNORE( mt ) ) {
-               rc = LDAP_SUCCESS;
+               rc = ldap_pvt_discard( msc->msc_ld, msgid );
 
        } else if ( META_BACK_TGT_CANCEL( mt ) ) {
                rc = ldap_cancel_s( msc->msc_ld, msgid, NULL, NULL );
@@ -982,7 +993,7 @@ retry:;
                                goto retry;
 
                        case -1:
-                               ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER,
+                               ldap_get_option( msc->msc_ld, LDAP_OPT_RESULT_CODE,
                                                &rs->sr_err );
                                break;
 
@@ -1055,7 +1066,7 @@ retry:;
 
                        rs->sr_err = LDAP_SUCCESS;
 
-                       ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER, &rs->sr_err );
+                       ldap_get_option( msc->msc_ld, LDAP_OPT_RESULT_CODE, &rs->sr_err );
                        if ( rs->sr_err != LDAP_SUCCESS ) {
                                /*
                                 * better check the type of error. In some cases
@@ -1064,7 +1075,7 @@ retry:;
                                 * positive result ...
                                 */
                                ldap_get_option( msc->msc_ld,
-                                               LDAP_OPT_ERROR_STRING, &xtext );
+                                               LDAP_OPT_DIAGNOSTIC_MESSAGE, &xtext );
                                if ( xtext != NULL && xtext [ 0 ] == '\0' ) {
                                        ldap_memfree( xtext );
                                        xtext = NULL;