]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/init.c
fix ITS#3464
[openldap] / servers / slapd / back-meta / init.c
index 2c1f4cf506f1ca7feda8a4d0550e9bade6c39138..e7883ce14738fb4077c9eda321983e02961997d3 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1999-2003 The OpenLDAP Foundation.
+ * Copyright 1999-2005 The OpenLDAP Foundation.
  * Portions Copyright 2001-2003 Pierangelo Masarati.
  * Portions Copyright 1999-2003 Howard Chu.
  * All rights reserved.
 #include "../back-ldap/back-ldap.h"
 #include "back-meta.h"
 
-#ifdef SLAPD_META_DYNAMIC
-
 int
-init_module( int argc, char *argv[] ) {
-    BackendInfo bi;
-
-    memset( &bi, '\0', sizeof( bi ) );
-    bi.bi_type = "meta";
-    bi.bi_init = meta_back_initialize;
-
-    backend_add( &bi );
-    return 0;
+meta_back_open(
+       BackendInfo *bi
+)
+{
+       bi->bi_controls = slap_known_controls;
+       return 0;
 }
 
-#endif /* SLAPD_META_DYNAMIC */
-
 int
 meta_back_initialize(
                BackendInfo     *bi
 )
 {
-       bi->bi_controls = slap_known_controls;
-
-       bi->bi_open = 0;
+       bi->bi_open = meta_back_open;
        bi->bi_config = 0;
        bi->bi_close = 0;
        bi->bi_destroy = 0;
@@ -119,58 +110,68 @@ conn_free(
        void *v_lc
 )
 {
-       struct metaconn *lc = v_lc;
-       struct metasingleconn *lsc;
+       struct metaconn         *lc = v_lc;
+       struct metasingleconn   *lsc;
 
-       for ( lsc = lc->conns; !META_LAST(lsc); lsc++ ) {
-               if ( lsc->ld != NULL ) {
-                       ldap_unbind( lsc->ld );
+       for ( lsc = lc->mc_conns; !META_LAST( lsc ); lsc++ ) {
+               if ( lsc->msc_ld != NULL ) {
+                       ldap_unbind_ext_s( lsc->msc_ld, NULL, NULL );
                }
-               if ( lsc->bound_dn.bv_val ) {
-                       ber_memfree( lsc->bound_dn.bv_val );
+               if ( !BER_BVISNULL( &lsc->msc_bound_ndn ) ) {
+                       ber_memfree( lsc->msc_bound_ndn.bv_val );
                }
-               if ( lsc->cred.bv_val ) {
-                       memset( lsc->cred.bv_val, 0, lsc->cred.bv_len );
-                       ber_memfree( lsc->cred.bv_val );
+               if ( !BER_BVISNULL( &lsc->msc_cred ) ) {
+                       /* destroy sensitive data */
+                       memset( lsc->msc_cred.bv_val, 0, lsc->msc_cred.bv_len );
+                       ber_memfree( lsc->msc_cred.bv_val );
                }
        }
-       free( lc->conns );
+       free( lc->mc_conns );
        free( lc );
 }
 
+static void
+mapping_free( void *v_mapping )
+{
+       struct ldapmapping *mapping = v_mapping;
+       ch_free( mapping->src.bv_val );
+       ch_free( mapping->dst.bv_val );
+       ch_free( mapping );
+}
+
 static void
 target_free(
                struct metatarget *lt
 )
 {
-       if ( lt->uri ) {
-               free( lt->uri );
+       if ( lt->mt_uri ) {
+               free( lt->mt_uri );
        }
-       if ( lt->psuffix.bv_val ) {
-               free( lt->psuffix.bv_val );
+       if ( !BER_BVISNULL( &lt->mt_psuffix ) ) {
+               free( lt->mt_psuffix.bv_val );
        }
-       if ( lt->suffix.bv_val ) {
-               free( lt->suffix.bv_val );
+       if ( !BER_BVISNULL( &lt->mt_nsuffix ) ) {
+               free( lt->mt_nsuffix.bv_val );
        }
-       if ( lt->binddn.bv_val ) {
-               free( lt->binddn.bv_val );
+       if ( !BER_BVISNULL( &lt->mt_binddn ) ) {
+               free( lt->mt_binddn.bv_val );
        }
-       if ( lt->bindpw.bv_val ) {
-               free( lt->bindpw.bv_val );
+       if ( !BER_BVISNULL( &lt->mt_bindpw ) ) {
+               free( lt->mt_bindpw.bv_val );
        }
-       if ( lt->pseudorootdn.bv_val ) {
-               free( lt->pseudorootdn.bv_val );
+       if ( !BER_BVISNULL( &lt->mt_pseudorootdn ) ) {
+               free( lt->mt_pseudorootdn.bv_val );
        }
-       if ( lt->pseudorootpw.bv_val ) {
-               free( lt->pseudorootpw.bv_val );
+       if ( !BER_BVISNULL( &lt->mt_pseudorootpw ) ) {
+               free( lt->mt_pseudorootpw.bv_val );
        }
-       if ( lt->rwmap.rwm_rw ) {
-               rewrite_info_delete( &lt->rwmap.rwm_rw );
+       if ( lt->mt_rwmap.rwm_rw ) {
+               rewrite_info_delete( &lt->mt_rwmap.rwm_rw );
        }
-       avl_free( lt->rwmap.rwm_oc.remap, NULL );
-       avl_free( lt->rwmap.rwm_oc.map, mapping_free );
-       avl_free( lt->rwmap.rwm_at.remap, NULL );
-       avl_free( lt->rwmap.rwm_at.map, mapping_free );
+       avl_free( lt->mt_rwmap.rwm_oc.remap, NULL );
+       avl_free( lt->mt_rwmap.rwm_oc.map, mapping_free );
+       avl_free( lt->mt_rwmap.rwm_at.remap, NULL );
+       avl_free( lt->mt_rwmap.rwm_at.map, mapping_free );
 }
 
 int
@@ -221,3 +222,11 @@ meta_back_db_destroy(
        return 0;
 }
 
+#if SLAPD_META == SLAPD_MOD_DYNAMIC
+
+/* conditionally define the init_module() function */
+SLAP_BACKEND_INIT_MODULE( meta )
+
+#endif /* SLAPD_META == SLAPD_MOD_DYNAMIC */
+
+