]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/init.c
refine fix to ITS#4315; apply it to back-meta as well
[openldap] / servers / slapd / back-meta / init.c
index 336f00171303d65ea08997f9c0f99f638e1cb66b..06549b9c8b98bb8e2e5abbdbf3a210d8b7e30e17 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1999-2005 The OpenLDAP Foundation.
+ * Copyright 1999-2006 The OpenLDAP Foundation.
  * Portions Copyright 2001-2003 Pierangelo Masarati.
  * Portions Copyright 1999-2003 Howard Chu.
  * All rights reserved.
@@ -30,7 +30,9 @@ int
 meta_back_open(
        BackendInfo     *bi )
 {
+       /* FIXME: need to remove the pagedResults, and likely more... */
        bi->bi_controls = slap_known_controls;
+
        return 0;
 }
 
@@ -38,6 +40,20 @@ int
 meta_back_initialize(
        BackendInfo     *bi )
 {
+       bi->bi_flags =
+#if 0
+       /* this is not (yet) set essentially because back-meta does not
+        * directly support extended operations... */
+#ifdef LDAP_DYNAMIC_OBJECTS
+               /* this is set because all the support a proxy has to provide
+                * is the capability to forward the refresh exop, and to
+                * pass thru entries that contain the dynamicObject class
+                * and the entryTtl attribute */
+               SLAP_BFLAG_DYNAMIC |
+#endif /* LDAP_DYNAMIC_OBJECTS */
+#endif
+               0;
+
        bi->bi_open = meta_back_open;
        bi->bi_config = 0;
        bi->bi_close = 0;
@@ -75,19 +91,20 @@ meta_back_db_init(
 {
        metainfo_t      *mi;
 
-       mi = ch_malloc( sizeof( metainfo_t ) );
+       mi = ch_calloc( 1, sizeof( metainfo_t ) );
        if ( mi == NULL ) {
                return -1;
        }
-       memset( mi, 0, sizeof( metainfo_t ) );
 
        /*
         * At present the default is no default target;
         * this may change
         */
        mi->mi_defaulttarget = META_DEFAULT_TARGET_NONE;
+       mi->mi_bind_timeout.tv_sec = 0;
+       mi->mi_bind_timeout.tv_usec = META_BIND_TIMEOUT;
 
-       ldap_pvt_thread_mutex_init( &mi->mi_conn_mutex );
+       ldap_pvt_thread_mutex_init( &mi->mi_conninfo.lai_mutex );
        ldap_pvt_thread_mutex_init( &mi->mi_cache.mutex );
 
        /* safe default */
@@ -108,7 +125,8 @@ meta_back_db_open(
        int             i, rc;
 
        for ( i = 0; i < mi->mi_ntargets; i++ ) {
-               if ( mi->mi_targets[ i ].mt_flags & LDAP_BACK_F_SUPPORT_T_F_DISCOVER ) {
+               if ( mi->mi_targets[ i ].mt_flags & LDAP_BACK_F_SUPPORT_T_F_DISCOVER )
+               {
                        mi->mi_targets[ i ].mt_flags &= ~LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
                        rc = slap_discover_feature( mi->mi_targets[ i ].mt_uri,
                                        mi->mi_targets[ i ].mt_version,
@@ -123,36 +141,30 @@ meta_back_db_open(
        return 0;
 }
 
-static void
-conn_free( 
+void
+meta_back_conn_free( 
        void            *v_mc )
 {
        metaconn_t              *mc = v_mc;
        int                     i, ntargets;
 
+       assert( mc != NULL );
+       assert( mc->mc_refcnt == 0 );
+
+       if ( !BER_BVISNULL( &mc->mc_local_ndn ) ) {
+               free( mc->mc_local_ndn.bv_val );
+       }
+
        assert( mc->mc_conns != NULL );
 
        /* at least one must be present... */
        ntargets = mc->mc_conns[ 0 ].msc_info->mi_ntargets;
 
        for ( i = 0; i < ntargets; i++ ) {
-               metasingleconn_t        *msc = &mc->mc_conns[ i ];
-
-               if ( msc->msc_ld != NULL ) {
-                       ldap_unbind_ext_s( msc->msc_ld, NULL, NULL );
-               }
-
-               if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
-                       ber_memfree( msc->msc_bound_ndn.bv_val );
-               }
-
-               if ( !BER_BVISNULL( &msc->msc_cred ) ) {
-                       /* destroy sensitive data */
-                       memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len );
-                       ber_memfree( msc->msc_cred.bv_val );
-               }
+               (void)meta_clear_one_candidate( &mc->mc_conns[ i ] );
        }
 
+       ldap_pvt_thread_mutex_destroy( &mc->mc_mutex );
        free( mc );
 }
 
@@ -166,6 +178,17 @@ mapping_free(
        ch_free( mapping );
 }
 
+static void
+mapping_dst_free(
+       void            *v_mapping )
+{
+       struct ldapmapping *mapping = v_mapping;
+
+       if ( BER_BVISEMPTY( &mapping->dst ) ) {
+               mapping_free( &mapping[ -1 ] );
+       }
+}
+
 static void
 target_free(
        metatarget_t    *mt )
@@ -194,9 +217,9 @@ target_free(
        if ( mt->mt_rwmap.rwm_rw ) {
                rewrite_info_delete( &mt->mt_rwmap.rwm_rw );
        }
-       avl_free( mt->mt_rwmap.rwm_oc.remap, NULL );
+       avl_free( mt->mt_rwmap.rwm_oc.remap, mapping_dst_free );
        avl_free( mt->mt_rwmap.rwm_oc.map, mapping_free );
-       avl_free( mt->mt_rwmap.rwm_at.remap, NULL );
+       avl_free( mt->mt_rwmap.rwm_at.remap, mapping_dst_free );
        avl_free( mt->mt_rwmap.rwm_at.map, mapping_free );
 }
 
@@ -214,21 +237,23 @@ meta_back_db_destroy(
                /*
                 * Destroy the connection tree
                 */
-               ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
+               ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
 
-               if ( mi->mi_conntree ) {
-                       avl_free( mi->mi_conntree, conn_free );
+               if ( mi->mi_conninfo.lai_tree ) {
+                       avl_free( mi->mi_conninfo.lai_tree, meta_back_conn_free );
                }
 
                /*
                 * Destroy the per-target stuff (assuming there's at
                 * least one ...)
                 */
-               for ( i = 0; i < mi->mi_ntargets; i++ ) {
-                       target_free( &mi->mi_targets[ i ] );
-               }
+               if ( mi->mi_targets != NULL ) {
+                       for ( i = 0; i < mi->mi_ntargets; i++ ) {
+                               target_free( &mi->mi_targets[ i ] );
+                       }
 
-               free( mi->mi_targets );
+                       free( mi->mi_targets );
+               }
 
                ldap_pvt_thread_mutex_lock( &mi->mi_cache.mutex );
                if ( mi->mi_cache.tree ) {
@@ -238,8 +263,8 @@ meta_back_db_destroy(
                ldap_pvt_thread_mutex_unlock( &mi->mi_cache.mutex );
                ldap_pvt_thread_mutex_destroy( &mi->mi_cache.mutex );
 
-               ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
-               ldap_pvt_thread_mutex_destroy( &mi->mi_conn_mutex );
+               ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
+               ldap_pvt_thread_mutex_destroy( &mi->mi_conninfo.lai_mutex );
 
                if ( mi->mi_candidates != NULL ) {
                        ber_memfree_x( mi->mi_candidates, NULL );