]> git.sur5r.net Git - openldap/blob - servers/slapd/back-meta/init.c
Fix typo
[openldap] / servers / slapd / back-meta / init.c
1 /*
2  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  *
5  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
6  *
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.
11  *
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:
15  *
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 
18  *    flaws in it.
19  *
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.
23  *
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
28  *    alterations.
29  *
30  * 4. This notice may not be removed or altered.
31  *
32  *
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.
38  *
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.
42  *
43  * The original copyright statement follows.
44  *
45  * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
46  *
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:
50  *
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.
53  *
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.
57  *
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
61  *    documentation.
62  *
63  * 4. This notice may not be removed or altered.
64  *
65  */
66
67 #include "portable.h"
68
69 #include <stdio.h>
70
71 #include <ac/socket.h>
72
73 #include "slap.h"
74 #include "../back-ldap/back-ldap.h"
75 #include "back-meta.h"
76
77 #ifdef SLAPD_META_DYNAMIC
78
79 int
80 back_meta_LTX_init_module( int argc, char *argv[] ) {
81     BackendInfo bi;
82
83     memset( &bi, '\0', sizeof( bi ) );
84     bi.bi_type = "meta";
85     bi.bi_init = meta_back_initialize;
86
87     backend_add( &bi );
88     return 0;
89 }
90
91 #endif /* SLAPD_META_DYNAMIC */
92
93 int
94 meta_back_initialize(
95                 BackendInfo     *bi
96 )
97 {
98         bi->bi_controls = slap_known_controls;
99
100         bi->bi_open = 0;
101         bi->bi_config = 0;
102         bi->bi_close = 0;
103         bi->bi_destroy = 0;
104
105         bi->bi_db_init = meta_back_db_init;
106         bi->bi_db_config = meta_back_db_config;
107         bi->bi_db_open = 0;
108         bi->bi_db_close = 0;
109         bi->bi_db_destroy = meta_back_db_destroy;
110
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;
120
121         bi->bi_extended = 0;
122
123         bi->bi_acl_group = meta_back_group;
124         bi->bi_acl_attribute = meta_back_attribute;
125         bi->bi_chk_referrals = 0;
126
127         bi->bi_connection_init = 0;
128         bi->bi_connection_destroy = meta_back_conn_destroy;
129
130         return 0;
131 }
132
133 int
134 meta_back_db_init(
135                 Backend *be
136 )
137 {
138         struct metainfo *li;
139
140         li = ch_calloc( 1, sizeof( struct metainfo ) );
141         if ( li == NULL ) {
142                 return -1;
143         }
144         
145         /*
146          * At present the default is no default target;
147          * this may change
148          */
149         li->defaulttarget = META_DEFAULT_TARGET_NONE;
150
151         ldap_pvt_thread_mutex_init( &li->conn_mutex );
152         ldap_pvt_thread_mutex_init( &li->cache.mutex );
153         be->be_private = li;
154
155         return 0;
156 }
157
158 static void
159 conn_free( 
160         struct metaconn *lc
161 )
162 {
163         struct metasingleconn *lsc;
164
165         for ( lsc = lc->conns; !META_LAST(lsc); lsc++ ) {
166                 if ( lsc->ld != NULL ) {
167                         ldap_unbind( lsc->ld );
168                 }
169                 if ( lsc->bound_dn.bv_val ) {
170                         ber_memfree( lsc->bound_dn.bv_val );
171                 }
172                 free( lsc );
173         }
174         free( lc->conns );
175         free( lc );
176 }
177
178 static void
179 target_free(
180                 struct metatarget *lt
181 )
182 {
183         if ( lt->uri ) {
184                 free( lt->uri );
185         }
186         if ( lt->psuffix.bv_val ) {
187                 free( lt->psuffix.bv_val );
188         }
189         if ( lt->suffix.bv_val ) {
190                 free( lt->suffix.bv_val );
191         }
192         if ( lt->binddn.bv_val ) {
193                 free( lt->binddn.bv_val );
194         }
195         if ( lt->bindpw.bv_val ) {
196                 free( lt->bindpw.bv_val );
197         }
198         if ( lt->pseudorootdn.bv_val ) {
199                 free( lt->pseudorootdn.bv_val );
200         }
201         if ( lt->pseudorootpw.bv_val ) {
202                 free( lt->pseudorootpw.bv_val );
203         }
204         if ( lt->rwinfo ) {
205                 rewrite_info_delete( lt->rwinfo );
206         }
207         avl_free( lt->oc_map.remap, NULL );
208         avl_free( lt->oc_map.map, ( AVL_FREE )mapping_free );
209         avl_free( lt->at_map.remap, NULL );
210         avl_free( lt->at_map.map, ( AVL_FREE )mapping_free );
211 }
212
213 int
214 meta_back_db_destroy(
215     Backend     *be
216 )
217 {
218         struct metainfo *li;
219
220         if ( be->be_private ) {
221                 int i;
222
223                 li = ( struct metainfo * )be->be_private;
224
225                 /*
226                  * Destroy the connection tree
227                  */
228                 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
229
230                 if ( li->conntree ) {
231                         avl_free( li->conntree,
232                                         ( AVL_FREE )conn_free );
233                 }
234
235                 /*
236                  * Destroy the per-target stuff (assuming there's at
237                  * least one ...)
238                  */
239                 for ( i = 0; i < li->ntargets; i++ ) {
240                         target_free( li->targets[ i ] );
241                         free( li->targets[ i ] );
242                 }
243
244                 free( li->targets );
245
246                 ldap_pvt_thread_mutex_lock( &li->cache.mutex );
247                 if ( li->cache.tree ) {
248                         avl_free( li->cache.tree,
249                                         ( AVL_FREE )meta_dncache_free );
250                 }
251                 
252                 ldap_pvt_thread_mutex_unlock( &li->cache.mutex );
253                 ldap_pvt_thread_mutex_destroy( &li->cache.mutex );
254
255                 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
256                 ldap_pvt_thread_mutex_destroy( &li->conn_mutex );
257         }
258
259         free( be->be_private );
260         return 0;
261 }
262