2 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
7 * This work has been developed to fulfill the requirements
8 * of SysNet s.n.c. <http:www.sys-net.it> and it has been donated
9 * to the OpenLDAP Foundation in the hope that it may be useful
10 * to the Open Source community, but WITHOUT ANY WARRANTY.
12 * Permission is granted to anyone to use this software for any purpose
13 * on any computer system, and to alter it and redistribute it, subject
14 * to the following restrictions:
16 * 1. The author and SysNet s.n.c. are not responsible for the consequences
17 * of use of this software, no matter how awful, even if they arise from
20 * 2. The origin of this software must not be misrepresented, either by
21 * explicit claim or by omission. Since few users ever read sources,
22 * credits should appear in the documentation.
24 * 3. Altered versions must be plainly marked as such, and must not be
25 * misrepresented as being the original software. Since few users
26 * ever read sources, credits should appear in the documentation.
27 * SysNet s.n.c. cannot be responsible for the consequences of the
30 * 4. This notice may not be removed or altered.
33 * This software is based on the backend back-ldap, implemented
34 * by Howard Chu <hyc@highlandsun.com>, and modified by Mark Valence
35 * <kurash@sassafras.com>, Pierangelo Masarati <ando@sys-net.it> and other
36 * contributors. The contribution of the original software to the present
37 * implementation is acknowledged in this copyright statement.
39 * A special acknowledgement goes to Howard for the overall architecture
40 * (and for borrowing large pieces of code), and to Mark, who implemented
41 * from scratch the attribute/objectclass mapping.
43 * The original copyright statement follows.
45 * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
47 * Permission is granted to anyone to use this software for any purpose
48 * on any computer system, and to alter it and redistribute it, subject
49 * to the following restrictions:
51 * 1. The author is not responsible for the consequences of use of this
52 * software, no matter how awful, even if they arise from flaws in it.
54 * 2. The origin of this software must not be misrepresented, either by
55 * explicit claim or by omission. Since few users ever read sources,
56 * credits should appear in the documentation.
58 * 3. Altered versions must be plainly marked as such, and must not be
59 * misrepresented as being the original software. Since few users
60 * ever read sources, credits should appear in the
63 * 4. This notice may not be removed or altered.
71 #include <ac/socket.h>
74 #include "../back-ldap/back-ldap.h"
75 #include "back-meta.h"
77 #ifdef SLAPD_META_DYNAMIC
80 back_meta_LTX_init_module( int argc, char *argv[] ) {
83 memset( &bi, '\0', sizeof( bi ) );
85 bi.bi_init = meta_back_initialize;
91 #endif /* SLAPD_META_DYNAMIC */
98 bi->bi_controls = slap_known_controls;
105 bi->bi_db_init = meta_back_db_init;
106 bi->bi_db_config = meta_back_db_config;
109 bi->bi_db_destroy = meta_back_db_destroy;
111 bi->bi_op_bind = meta_back_bind;
112 bi->bi_op_unbind = 0;
113 bi->bi_op_search = meta_back_search;
114 bi->bi_op_compare = meta_back_compare;
115 bi->bi_op_modify = meta_back_modify;
116 bi->bi_op_modrdn = meta_back_modrdn;
117 bi->bi_op_add = meta_back_add;
118 bi->bi_op_delete = meta_back_delete;
119 bi->bi_op_abandon = 0;
123 bi->bi_chk_referrals = 0;
125 bi->bi_connection_init = 0;
126 bi->bi_connection_destroy = meta_back_conn_destroy;
139 struct rewrite_info *rwinfo;
143 rwinfo = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
144 if ( rwinfo == NULL ) {
148 cm = (cache_manager *)ch_malloc(sizeof(cache_manager));
150 rewrite_info_delete( rwinfo );
154 qm = (query_manager*)ch_malloc(sizeof(query_manager));
156 rewrite_info_delete( rwinfo );
164 cm->numtemplates = 0;
165 cm->num_entries_limit = 5;
167 cm->thresh_hi = 500000;
168 cm->thresh_lo = 700000;
169 cm->num_cached_queries = 0;
170 cm->total_entries = 0;
171 cm->max_queries = 10000;
173 cm->consistency_time = slap_get_time();
174 cm->consistency_cycle_time = 1000;
176 qm->attr_sets = NULL;
177 qm->templates = NULL;
179 qm->lru_bottom = NULL;
181 qm->qcfunc = query_containment;
182 qm->crfunc = cache_replacement;
183 qm->addfunc = add_query;
184 ldap_pvt_thread_mutex_init(&qm->lru_mutex);
186 ldap_pvt_thread_mutex_init(&cm->cache_mutex);
187 ldap_pvt_thread_mutex_init(&cm->remove_mutex);
188 ldap_pvt_thread_mutex_init( &cm->consistency_mutex );
189 #endif /* LDAP_CACHING */
191 li = ch_calloc( 1, sizeof( struct metainfo ) );
197 * At present the default is no default target;
200 li->defaulttarget = META_DEFAULT_TARGET_NONE;
204 /* FIXME: what about qm ? */
205 #endif /* LDAP_CACHING */
207 ldap_pvt_thread_mutex_init( &li->conn_mutex );
208 ldap_pvt_thread_mutex_init( &li->cache.mutex );
219 struct metaconn *lc = v_lc;
220 struct metasingleconn *lsc;
222 for ( lsc = lc->conns; !META_LAST(lsc); lsc++ ) {
223 if ( lsc->ld != NULL ) {
224 ldap_unbind( lsc->ld );
226 if ( lsc->bound_dn.bv_val ) {
227 ber_memfree( lsc->bound_dn.bv_val );
236 struct metatarget *lt
242 if ( lt->psuffix.bv_val ) {
243 free( lt->psuffix.bv_val );
245 if ( lt->suffix.bv_val ) {
246 free( lt->suffix.bv_val );
248 if ( lt->binddn.bv_val ) {
249 free( lt->binddn.bv_val );
251 if ( lt->bindpw.bv_val ) {
252 free( lt->bindpw.bv_val );
254 if ( lt->pseudorootdn.bv_val ) {
255 free( lt->pseudorootdn.bv_val );
257 if ( lt->pseudorootpw.bv_val ) {
258 free( lt->pseudorootpw.bv_val );
261 rewrite_info_delete( lt->rwinfo );
263 avl_free( lt->oc_map.remap, NULL );
264 avl_free( lt->oc_map.map, mapping_free );
265 avl_free( lt->at_map.remap, NULL );
266 avl_free( lt->at_map.map, mapping_free );
270 meta_back_db_destroy(
276 if ( be->be_private ) {
279 li = ( struct metainfo * )be->be_private;
282 * Destroy the connection tree
284 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
286 if ( li->conntree ) {
287 avl_free( li->conntree, conn_free );
291 * Destroy the per-target stuff (assuming there's at
294 for ( i = 0; i < li->ntargets; i++ ) {
295 target_free( li->targets[ i ] );
296 free( li->targets[ i ] );
301 ldap_pvt_thread_mutex_lock( &li->cache.mutex );
302 if ( li->cache.tree ) {
303 avl_free( li->cache.tree, meta_dncache_free );
306 ldap_pvt_thread_mutex_unlock( &li->cache.mutex );
307 ldap_pvt_thread_mutex_destroy( &li->cache.mutex );
309 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
310 ldap_pvt_thread_mutex_destroy( &li->conn_mutex );
313 free( be->be_private );