2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2004 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>.
22 #include <ac/string.h>
23 #include <ac/socket.h>
26 #include "../back-ldap/back-ldap.h"
27 #include "back-meta.h"
30 #if SLAPD_META == SLAPD_MOD_DYNAMIC
33 init_module( int argc, char *argv[] ) {
36 memset( &bi, '\0', sizeof( bi ) );
38 bi.bi_init = meta_back_initialize;
44 #endif /* SLAPD_META */
51 bi->bi_controls = slap_known_controls;
60 bi->bi_open = meta_back_open;
65 bi->bi_db_init = meta_back_db_init;
66 bi->bi_db_config = meta_back_db_config;
69 bi->bi_db_destroy = meta_back_db_destroy;
71 bi->bi_op_bind = meta_back_bind;
73 bi->bi_op_search = meta_back_search;
74 bi->bi_op_compare = meta_back_compare;
75 bi->bi_op_modify = meta_back_modify;
76 bi->bi_op_modrdn = meta_back_modrdn;
77 bi->bi_op_add = meta_back_add;
78 bi->bi_op_delete = meta_back_delete;
79 bi->bi_op_abandon = 0;
83 bi->bi_chk_referrals = 0;
85 bi->bi_connection_init = 0;
86 bi->bi_connection_destroy = meta_back_conn_destroy;
98 struct rewrite_info *rwinfo;
100 rwinfo = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
101 if ( rwinfo == NULL ) {
105 li = ch_calloc( 1, sizeof( struct metainfo ) );
107 rewrite_info_delete( &rwinfo );
112 * At present the default is no default target;
115 li->defaulttarget = META_DEFAULT_TARGET_NONE;
118 ldap_pvt_thread_mutex_init( &li->conn_mutex );
119 ldap_pvt_thread_mutex_init( &li->cache.mutex );
130 struct metaconn *lc = v_lc;
131 struct metasingleconn *lsc;
133 for ( lsc = lc->conns; !META_LAST(lsc); lsc++ ) {
134 if ( lsc->ld != NULL ) {
135 ldap_unbind( lsc->ld );
137 if ( lsc->bound_dn.bv_val ) {
138 ber_memfree( lsc->bound_dn.bv_val );
140 if ( lsc->cred.bv_val ) {
141 memset( lsc->cred.bv_val, 0, lsc->cred.bv_len );
142 ber_memfree( lsc->cred.bv_val );
150 mapping_free( void *v_mapping )
152 struct ldapmapping *mapping = v_mapping;
153 ch_free( mapping->src.bv_val );
154 ch_free( mapping->dst.bv_val );
160 struct metatarget *lt
166 if ( lt->psuffix.bv_val ) {
167 free( lt->psuffix.bv_val );
169 if ( lt->suffix.bv_val ) {
170 free( lt->suffix.bv_val );
172 if ( lt->binddn.bv_val ) {
173 free( lt->binddn.bv_val );
175 if ( lt->bindpw.bv_val ) {
176 free( lt->bindpw.bv_val );
178 if ( lt->pseudorootdn.bv_val ) {
179 free( lt->pseudorootdn.bv_val );
181 if ( lt->pseudorootpw.bv_val ) {
182 free( lt->pseudorootpw.bv_val );
184 if ( lt->rwmap.rwm_rw ) {
185 rewrite_info_delete( <->rwmap.rwm_rw );
187 avl_free( lt->rwmap.rwm_oc.remap, NULL );
188 avl_free( lt->rwmap.rwm_oc.map, mapping_free );
189 avl_free( lt->rwmap.rwm_at.remap, NULL );
190 avl_free( lt->rwmap.rwm_at.map, mapping_free );
194 meta_back_db_destroy(
200 if ( be->be_private ) {
203 li = ( struct metainfo * )be->be_private;
206 * Destroy the connection tree
208 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
210 if ( li->conntree ) {
211 avl_free( li->conntree, conn_free );
215 * Destroy the per-target stuff (assuming there's at
218 for ( i = 0; i < li->ntargets; i++ ) {
219 target_free( li->targets[ i ] );
220 free( li->targets[ i ] );
225 ldap_pvt_thread_mutex_lock( &li->cache.mutex );
226 if ( li->cache.tree ) {
227 avl_free( li->cache.tree, meta_dncache_free );
230 ldap_pvt_thread_mutex_unlock( &li->cache.mutex );
231 ldap_pvt_thread_mutex_destroy( &li->cache.mutex );
233 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
234 ldap_pvt_thread_mutex_destroy( &li->conn_mutex );
237 free( be->be_private );