]> git.sur5r.net Git - openldap/commitdiff
further cleanup
authorPierangelo Masarati <ando@openldap.org>
Wed, 10 Jan 2007 00:53:05 +0000 (00:53 +0000)
committerPierangelo Masarati <ando@openldap.org>
Wed, 10 Jan 2007 00:53:05 +0000 (00:53 +0000)
servers/slapd/back-ldap/add.c
servers/slapd/back-ldap/bind.c
servers/slapd/back-ldap/compare.c
servers/slapd/back-ldap/config.c
servers/slapd/back-ldap/delete.c
servers/slapd/back-ldap/extended.c
servers/slapd/back-ldap/modify.c
servers/slapd/back-ldap/modrdn.c
servers/slapd/back-ldap/proto-ldap.h
servers/slapd/back-ldap/search.c

index df82a9f8eb31e28bec804475cbff29f479c09cfe..9a5c4f5422a3acdf0a3f3b524bf328e484e1d264 100644 (file)
@@ -125,7 +125,7 @@ cleanup:
        }
 
        if ( lc ) {
-               ldap_back_release_conn( op, rs, lc );
+               ldap_back_release_conn( li, lc );
        }
 
        Debug( LDAP_DEBUG_ARGS, "<== ldap_back_add(\"%s\"): %d\n",
index ad268f8ba0e6235f9e3aa2ea9b2920d5c0afbe6c..630e627d9cc8b06e914776bfd05b014ad7a88cb7 100644 (file)
@@ -112,7 +112,7 @@ ldap_back_print_conntree( ldapinfo_t *li, char *msg )
 #endif /* LDAP_BACK_PRINT_CONNTREE */
 
 static int
-ldap_back_freeconn( Operation *op, ldapconn_t *lc, int dolock );
+ldap_back_freeconn( ldapinfo_t *li, ldapconn_t *lc, int dolock );
 
 static ldapconn_t *
 ldap_back_getconn( Operation *op, SlapReply *rs, ldap_back_send_t sendok,
@@ -133,6 +133,40 @@ ldap_back_prepare_conn( ldapconn_t *lc, Operation *op, SlapReply *rs,
 static int
 ldap_back_conndnlc_cmp( const void *c1, const void *c2 );
 
+ldapconn_t *
+ldap_back_conn_delete( ldapinfo_t *li, ldapconn_t *lc )
+{
+       if ( LDAP_BACK_PCONN_ISPRIV( lc ) ) {
+               if ( LDAP_BACK_CONN_CACHED( lc ) ) {
+                       assert( lc->lc_q.tqe_prev != NULL );
+                       assert( li->li_conn_priv[ LDAP_BACK_CONN2PRIV( lc ) ].lic_num > 0 );
+                       li->li_conn_priv[ LDAP_BACK_CONN2PRIV( lc ) ].lic_num--;
+                       LDAP_TAILQ_REMOVE( &li->li_conn_priv[ LDAP_BACK_CONN2PRIV( lc ) ].lic_priv, lc, lc_q );
+                       LDAP_TAILQ_ENTRY_INIT( lc, lc_q );
+                       LDAP_BACK_CONN_CACHED_CLEAR( lc );
+
+               } else {
+                       assert( LDAP_BACK_CONN_TAINTED( lc ) );
+                       assert( lc->lc_q.tqe_prev == NULL );
+               }
+
+       } else {
+               ldapconn_t      *tmplc = NULL;
+
+               if ( LDAP_BACK_CONN_CACHED( lc ) ) {
+                       assert( !LDAP_BACK_CONN_TAINTED( lc ) );
+                       tmplc = avl_delete( &li->li_conninfo.lai_tree, (caddr_t)lc,
+                               ldap_back_conndnlc_cmp );
+                       assert( tmplc == lc );
+                       LDAP_BACK_CONN_CACHED_CLEAR( lc );
+               }
+
+               assert( LDAP_BACK_CONN_TAINTED( lc ) || tmplc == lc );
+       }
+
+       return lc;
+}
+
 int
 ldap_back_bind( Operation *op, SlapReply *rs )
 {
@@ -187,7 +221,7 @@ retry:;
                 * connection with identity assertion */
                /* NOTE: use with care */
                if ( li->li_idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) {
-                       ldap_back_release_conn( op, rs, lc );
+                       ldap_back_release_conn( li, lc );
                        return( rc );
                }
 
@@ -232,27 +266,7 @@ retry_lock:;
 #endif /* LDAP_BACK_PRINT_CONNTREE */
 
                assert( lc->lc_refcnt == 1 );
-               if ( LDAP_BACK_PCONN_ISPRIV( lc ) ) {
-                       /* this can happen, for example, if the bind fails
-                        * for some reason... */
-                       if ( lc->lc_q.tqe_prev != NULL ) {
-                               assert( LDAP_BACK_CONN_CACHED( lc ) );
-                               assert( li->li_conn_priv[ LDAP_BACK_CONN2PRIV( lc ) ].lic_num > 0 );
-                               LDAP_TAILQ_REMOVE( &li->li_conn_priv[ LDAP_BACK_CONN2PRIV( lc ) ].lic_priv, lc, lc_q );
-                               li->li_conn_priv[ LDAP_BACK_CONN2PRIV( lc ) ].lic_num--;
-                               lc->lc_q.tqe_prev = NULL;
-                               lc->lc_q.tqe_next = NULL;
-
-                       } else {
-                               assert( !LDAP_BACK_CONN_CACHED( lc ) );
-                       }
-
-               } else {
-                       tmplc = avl_delete( &li->li_conninfo.lai_tree, (caddr_t)lc,
-                                       ldap_back_conndnlc_cmp );
-                       assert( ( LDAP_BACK_CONN_TAINTED( lc ) && tmplc == NULL ) || lc == tmplc );
-               }
-               LDAP_BACK_CONN_CACHED_CLEAR( lc );
+               ldap_back_conn_delete( li, lc );
 
                /* delete all cached connections with the current connection */
                if ( LDAP_BACK_SINGLECONN( li ) ) {
@@ -307,7 +321,7 @@ retry_lock:;
        }
 
        if ( lc != NULL ) {
-               ldap_back_release_conn( op, rs, lc );
+               ldap_back_release_conn( li, lc );
        }
 
        return( rc );
@@ -409,10 +423,8 @@ ldap_back_conndn_dup( void *c1, void *c2 )
 }
 
 static int
-ldap_back_freeconn( Operation *op, ldapconn_t *lc, int dolock )
+ldap_back_freeconn( ldapinfo_t *li, ldapconn_t *lc, int dolock )
 {
-       ldapinfo_t      *li = (ldapinfo_t *) op->o_bd->be_private;
-
        if ( dolock ) {
                ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
        }
@@ -421,31 +433,7 @@ ldap_back_freeconn( Operation *op, ldapconn_t *lc, int dolock )
        ldap_back_print_conntree( li, ">>> ldap_back_freeconn" );
 #endif /* LDAP_BACK_PRINT_CONNTREE */
 
-       if ( LDAP_BACK_PCONN_ISPRIV( lc ) ) {
-               if ( lc->lc_q.tqe_prev != NULL ) {
-                       assert( LDAP_BACK_CONN_CACHED( lc ) );
-                       assert( li->li_conn_priv[ LDAP_BACK_CONN2PRIV( lc ) ].lic_num > 0 );
-                       li->li_conn_priv[ LDAP_BACK_CONN2PRIV( lc ) ].lic_num--;
-                       LDAP_TAILQ_REMOVE( &li->li_conn_priv[ LDAP_BACK_CONN2PRIV( lc ) ].lic_priv, lc, lc_q );
-                       LDAP_BACK_CONN_CACHED_CLEAR( lc );
-
-               } else {
-                       assert( !LDAP_BACK_CONN_CACHED( lc ) );
-               }
-               lc->lc_q.tqe_prev = NULL;
-               lc->lc_q.tqe_next = NULL;
-
-       } else {
-               ldapconn_t      *tmplc = NULL;
-
-               if ( LDAP_BACK_CONN_CACHED( lc ) ) {
-                       tmplc = avl_delete( &li->li_conninfo.lai_tree, (caddr_t)lc,
-                               ldap_back_conndnlc_cmp );
-                       assert( tmplc == lc );
-                       LDAP_BACK_CONN_CACHED_CLEAR( lc );
-               }
-               assert( LDAP_BACK_CONN_TAINTED( lc ) || tmplc == lc );
-       }
+       (void)ldap_back_conn_delete( li, lc );
 
        if ( lc->lc_refcnt == 0 ) {
                ldap_back_conn_free( (void *)lc );
@@ -849,8 +837,7 @@ retry_lock:
                                {
                                        LDAP_TAILQ_REMOVE( &li->li_conn_priv[ LDAP_BACK_CONN2PRIV( lc ) ].lic_priv,
                                                lc, lc_q );
-                                       lc->lc_q.tqe_prev = NULL;
-                                       lc->lc_q.tqe_next = NULL;
+                                       LDAP_TAILQ_ENTRY_INIT( lc, lc_q );
                                        LDAP_TAILQ_INSERT_TAIL( &li->li_conn_priv[ LDAP_BACK_CONN2PRIV( lc ) ].lic_priv,
                                                lc, lc_q );
                                }
@@ -1078,26 +1065,8 @@ retry_lock:
                        ldap_back_print_conntree( li, ">>> ldap_back_getconn(timeout)" );
 #endif /* LDAP_BACK_PRINT_CONNTREE */
 
-                       if ( LDAP_BACK_PCONN_ISPRIV( lc ) ) {
-                               if ( lc->lc_q.tqe_prev != NULL ) {
-                                       assert( LDAP_BACK_CONN_CACHED( lc ) );
-                                       assert( li->li_conn_priv[ LDAP_BACK_CONN2PRIV( lc ) ].lic_num > 0 );
-                                       LDAP_TAILQ_REMOVE( &li->li_conn_priv[ LDAP_BACK_CONN2PRIV( lc ) ].lic_priv,
-                                               lc, lc_q );
-                                       li->li_conn_priv[ LDAP_BACK_CONN2PRIV( lc ) ].lic_num--;
-                                       lc->lc_q.tqe_prev = NULL;
-                                       lc->lc_q.tqe_next = NULL;
-
-                               } else {
-                                       assert( !LDAP_BACK_CONN_CACHED( lc ) );
-                               }
-
-                       } else {
-                               (void)avl_delete( &li->li_conninfo.lai_tree, (caddr_t)lc,
-                                       ldap_back_conndnlc_cmp );
-                       }
+                       (void)ldap_back_conn_delete( li, lc );
                        LDAP_BACK_CONN_TAINTED_SET( lc );
-                       LDAP_BACK_CONN_CACHED_CLEAR( lc );
 
 #if LDAP_BACK_PRINT_CONNTREE > 0
                        ldap_back_print_conntree( li, "<<< ldap_back_getconn(timeout)" );
@@ -1110,7 +1079,7 @@ retry_lock:
                        char    buf[ SLAP_TEXT_BUFLEN ];
 
                        snprintf( buf, sizeof( buf ),
-                               "conn %p fetched refcnt=%u %s",
+                               "conn %p fetched refcnt=%u%s",
                                (void *)lc, refcnt, expiring ? " expiring" : "" );
                        Debug( LDAP_DEBUG_TRACE,
                                "=>ldap_back_getconn: %s.\n", buf, 0, 0 );
@@ -1126,12 +1095,10 @@ done:;
 
 void
 ldap_back_release_conn_lock(
-       Operation               *op,
-       SlapReply               *rs,
+       ldapinfo_t              *li,
        ldapconn_t              **lcp,
        int                     dolock )
 {
-       ldapinfo_t      *li = (ldapinfo_t *)op->o_bd->be_private;
 
        ldapconn_t      *lc = *lcp;
 
@@ -1142,7 +1109,7 @@ ldap_back_release_conn_lock(
        LDAP_BACK_CONN_BINDING_CLEAR( lc );
        lc->lc_refcnt--;
        if ( LDAP_BACK_CONN_TAINTED( lc ) ) {
-               ldap_back_freeconn( op, lc, 0 );
+               ldap_back_freeconn( li, lc, 0 );
                *lcp = NULL;
        }
        if ( dolock ) {
@@ -1417,19 +1384,11 @@ retry:;
                                }
                                goto retry;
                        }
-
-               } else {
-                       if ( dolock ) {
-                               ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
-                       }
-                       if ( dolock ) {
-                               ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
-                       }
                }
 
                assert( lc->lc_refcnt == 1 );
                lc->lc_refcnt = 0;
-               ldap_back_freeconn( op, lc, dolock );
+               ldap_back_freeconn( li, lc, dolock );
                *lcp = NULL;
                rs->sr_err = slap_map_api2result( rs );
 
@@ -1456,7 +1415,7 @@ done:;
        LDAP_BACK_CONN_BINDING_CLEAR( lc );
        rc = LDAP_BACK_CONN_ISBOUND( lc );
        if ( !rc ) {
-               ldap_back_release_conn_lock( op, rs, lcp, dolock );
+               ldap_back_release_conn_lock( li, lcp, dolock );
 
        } else if ( LDAP_BACK_SAVECRED( li ) ) {
                ldap_set_rebind_proc( lc->lc_ld, li->li_rebind_f, lc );
@@ -1809,7 +1768,7 @@ ldap_back_retry( ldapconn_t **lcp, Operation *op, SlapReply *rs, ldap_back_send_
                if ( rc != LDAP_SUCCESS ) {
                        /* freeit, because lc_refcnt == 1 */
                        (*lcp)->lc_refcnt = 0;
-                       (void)ldap_back_freeconn( op, *lcp, 0 );
+                       (void)ldap_back_freeconn( li, *lcp, 0 );
                        *lcp = NULL;
                        rc = 0;
 
@@ -1825,7 +1784,7 @@ ldap_back_retry( ldapconn_t **lcp, Operation *op, SlapReply *rs, ldap_back_send_
                                /* freeit, because lc_refcnt == 1 */
                                (*lcp)->lc_refcnt = 0;
                                LDAP_BACK_CONN_TAINTED_SET( *lcp );
-                               (void)ldap_back_freeconn( op, *lcp, 0 );
+                               (void)ldap_back_freeconn( li, *lcp, 0 );
                                *lcp = NULL;
                        }
                }
@@ -1836,7 +1795,7 @@ ldap_back_retry( ldapconn_t **lcp, Operation *op, SlapReply *rs, ldap_back_send_
                        (void *)(*lcp), (*lcp)->lc_refcnt, 0 );
 
                LDAP_BACK_CONN_TAINTED_SET( *lcp );
-               ldap_back_release_conn_lock( op, rs, lcp, 0 );
+               ldap_back_release_conn_lock( li, lcp, 0 );
                assert( *lcp == NULL );
 
                if ( sendok ) {
index ee964a1183d731f38a5965455a0c021e061311dd..a0a1b598075ffc0c58a399431916519a1169884b 100644 (file)
@@ -78,7 +78,7 @@ cleanup:
        (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls );
        
        if ( lc != NULL ) {
-               ldap_back_release_conn( op, rs, lc );
+               ldap_back_release_conn( li, lc );
        }
 
        return rs->sr_err;
index 2408592898cbfb3b8f349fccc1e87e4ea99c6b6f..215555372c24f6edbda7989e3b562ef5313fc2f3 100644 (file)
@@ -2006,7 +2006,7 @@ retry:
                }
 
                if ( lc != NULL ) {
-                       ldap_back_release_conn( &op2, rs, lc );
+                       ldap_back_release_conn( (ldapinfo_t *)op2.o_bd->be_private, lc );
                }
 
        } else {
index abf56c37f225fddfd36b2b5908c3820d3aff4ab7..fa6ff873ac472c2e8d711d735512fa0794ee2daf 100644 (file)
@@ -36,7 +36,7 @@ ldap_back_delete(
                Operation       *op,
                SlapReply       *rs )
 {
-       ldapinfo_t      *li = (ldapinfo_t *)op->o_bd->be_private;
+       ldapinfo_t              *li = (ldapinfo_t *)op->o_bd->be_private;
 
        ldapconn_t              *lc = NULL;
        ber_int_t               msgid;
@@ -76,7 +76,7 @@ cleanup:
        (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls );
 
        if ( lc != NULL ) {
-               ldap_back_release_conn( op, rs, lc );
+               ldap_back_release_conn( li, lc );
        }
 
        return rc;
index 12db3fce16f3da297462fa96878e7be25a5c6366..38dbfcd71105a186412fce941b49825da89f99cc 100644 (file)
@@ -78,7 +78,7 @@ ldap_back_extended_one( Operation *op, SlapReply *rs, BI_op_extended exop )
 
 done:;
        if ( lc != NULL ) {
-               ldap_back_release_conn( op, rs, lc );
+               ldap_back_release_conn( li, lc );
        }
                        
        return rc;
@@ -216,7 +216,7 @@ retry:
        }
 
        if ( lc != NULL ) {
-               ldap_back_release_conn( op, rs, lc );
+               ldap_back_release_conn( li, lc );
        }
 
        return rc;
@@ -316,7 +316,7 @@ retry:
        }
 
        if ( lc != NULL ) {
-               ldap_back_release_conn( op, rs, lc );
+               ldap_back_release_conn( li, lc );
        }
 
        return rc;
index d49499efcbc7185315bf7665a42fa993a8d96c1d..3c287cd8db02c67fffdebdc2b239da4e1f119849 100644 (file)
@@ -130,7 +130,7 @@ cleanup:;
        ch_free( modv );
 
        if ( lc != NULL ) {
-               ldap_back_release_conn( op, rs, lc );
+               ldap_back_release_conn( li, lc );
        }
 
        return rc;
index 802701d622e74496030ed30cce73954887a9c09e..a578dd19ab02ae6540967243df578faace94caa6 100644 (file)
@@ -101,7 +101,7 @@ cleanup:
        (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls );
 
        if ( lc != NULL ) {
-               ldap_back_release_conn( op, rs, lc );
+               ldap_back_release_conn( li, lc );
        }
 
        return rc;
index 4b2059fc23a210ce0dde10262d427e66fe725bcf..8eca7f6593a204e53e5e4d0eb76b255754f04b5e 100644 (file)
@@ -45,8 +45,8 @@ extern BI_connection_destroy  ldap_back_conn_destroy;
 
 extern BI_entry_get_rw         ldap_back_entry_get;
 
-void ldap_back_release_conn_lock( Operation *op, SlapReply *rs, ldapconn_t **lcp, int dolock );
-#define ldap_back_release_conn(op, rs, lc) ldap_back_release_conn_lock((op), (rs), &(lc), 1)
+void ldap_back_release_conn_lock( ldapinfo_t *li, ldapconn_t **lcp, int dolock );
+#define ldap_back_release_conn(li, lc) ldap_back_release_conn_lock((li), &(lc), 1)
 int ldap_back_dobind( ldapconn_t **lcp, Operation *op, SlapReply *rs, ldap_back_send_t sendok );
 int ldap_back_retry( ldapconn_t **lcp, Operation *op, SlapReply *rs, ldap_back_send_t sendok );
 int ldap_back_map_result( SlapReply *rs );
@@ -61,6 +61,8 @@ extern int ldap_back_conn_cmp( const void *c1, const void *c2);
 extern int ldap_back_conndn_dup( void *c1, void *c2 );
 extern void ldap_back_conn_free( void *c );
 
+extern ldapconn_t * ldap_back_conn_delete( ldapinfo_t *li, ldapconn_t *lc );
+
 extern int
 ldap_back_proxy_authz_ctrl(
                struct berval   *bound_ndn,
index 75366a79f782bc0a3531a25040a77d790e759221..cc10b655729a010bb6bb8c2ec6393c2f74179796 100644 (file)
@@ -521,7 +521,7 @@ finish:;
        }
 
        if ( lc != NULL ) {
-               ldap_back_release_conn( op, rs, lc );
+               ldap_back_release_conn( li, lc );
        }
 
        return rs->sr_err;
@@ -821,7 +821,7 @@ cleanup:
        }
 
        if ( lc != NULL ) {
-               ldap_back_release_conn( op, &rs, lc );
+               ldap_back_release_conn( li, lc );
        }
 
        return rc;