1 /* init.c - initialize ldap backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by the Howard Chu for inclusion
18 * in OpenLDAP Software and subsequently enhanced by Pierangelo
21 /* This is an altered version */
23 * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
25 * Permission is granted to anyone to use this software for any purpose
26 * on any computer system, and to alter it and redistribute it, subject
27 * to the following restrictions:
29 * 1. The author is not responsible for the consequences of use of this
30 * software, no matter how awful, even if they arise from flaws in it.
32 * 2. The origin of this software must not be misrepresented, either by
33 * explicit claim or by omission. Since few users ever read sources,
34 * credits should appear in the documentation.
36 * 3. Altered versions must be plainly marked as such, and must not be
37 * misrepresented as being the original software. Since few users
38 * ever read sources, credits should appear in the documentation.
40 * 4. This notice may not be removed or altered.
44 * Copyright 2000, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
46 * This software is being modified by Pierangelo Masarati.
47 * The previously reported conditions apply to the modified code as well.
48 * Changes in the original code are highlighted where required.
49 * Credits for the original code go to the author, Howard Chu.
56 #include <ac/string.h>
57 #include <ac/socket.h>
60 #include "back-ldap.h"
62 #ifdef SLAPD_LDAP_DYNAMIC
64 int init_module(int argc, char *argv[]) {
67 memset( &bi, '\0', sizeof(bi) );
69 bi.bi_init = ldap_back_initialize;
75 #endif /* SLAPD_LDAP_DYNAMIC */
82 bi->bi_controls = slap_known_controls;
89 bi->bi_db_init = ldap_back_db_init;
90 bi->bi_db_config = ldap_back_db_config;
93 bi->bi_db_destroy = ldap_back_db_destroy;
95 bi->bi_op_bind = ldap_back_bind;
97 bi->bi_op_search = ldap_back_search;
98 bi->bi_op_compare = ldap_back_compare;
99 bi->bi_op_modify = ldap_back_modify;
100 bi->bi_op_modrdn = ldap_back_modrdn;
101 bi->bi_op_add = ldap_back_add;
102 bi->bi_op_delete = ldap_back_delete;
103 bi->bi_op_abandon = 0;
105 bi->bi_extended = ldap_back_extended;
107 bi->bi_chk_referrals = 0;
108 bi->bi_entry_get_rw = ldap_back_entry_get;
110 bi->bi_connection_init = 0;
111 bi->bi_connection_destroy = ldap_back_conn_destroy;
124 struct ldapmapping *mapping;
126 li = (struct ldapinfo *) ch_calloc( 1, sizeof(struct ldapinfo) );
131 li->binddn.bv_val = NULL;
132 li->binddn.bv_len = 0;
133 li->bindpw.bv_val = NULL;
134 li->bindpw.bv_len = 0;
136 #ifdef ENABLE_REWRITE
137 li->rwmap.rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
138 if ( li->rwmap.rwm_rw == NULL ) {
142 #endif /* ENABLE_REWRITE */
144 ldap_pvt_thread_mutex_init( &li->conn_mutex );
146 ldap_back_map_init( &li->rwmap.rwm_oc, &mapping );
147 ldap_back_map_init( &li->rwmap.rwm_at, &mapping );
151 be->be_flags |= SLAP_BFLAG_NOLASTMOD;
161 struct ldapconn *lc = v_lc;
162 ldap_unbind( lc->ld );
163 if ( lc->bound_dn.bv_val ) {
164 ch_free( lc->bound_dn.bv_val );
166 if ( lc->cred.bv_val ) {
167 memset( lc->cred.bv_val, 0, lc->cred.bv_len );
168 ch_free( lc->cred.bv_val );
170 if ( lc->local_dn.bv_val ) {
171 ch_free( lc->local_dn.bv_val );
173 ldap_pvt_thread_mutex_destroy( &lc->lc_mutex );
178 mapping_free( void *v_mapping )
180 struct ldapmapping *mapping = v_mapping;
181 ch_free( mapping->src.bv_val );
182 ch_free( mapping->dst.bv_val );
187 ldap_back_db_destroy(
193 if (be->be_private) {
194 li = (struct ldapinfo *)be->be_private;
196 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
202 if (li->binddn.bv_val) {
203 ch_free(li->binddn.bv_val);
204 li->binddn.bv_val = NULL;
206 if (li->bindpw.bv_val) {
207 ch_free(li->bindpw.bv_val);
208 li->bindpw.bv_val = NULL;
211 avl_free( li->conntree, ldap_back_conn_free );
213 #ifdef ENABLE_REWRITE
214 if (li->rwmap.rwm_rw) {
215 rewrite_info_delete( &li->rwmap.rwm_rw );
217 #else /* !ENABLE_REWRITE */
218 if (li->rwmap.rwm_suffix_massage) {
219 ber_bvarray_free( li->rwmap.rwm_suffix_massage );
221 #endif /* !ENABLE_REWRITE */
223 avl_free( li->rwmap.rwm_oc.remap, NULL );
224 avl_free( li->rwmap.rwm_oc.map, mapping_free );
225 avl_free( li->rwmap.rwm_at.remap, NULL );
226 avl_free( li->rwmap.rwm_at.map, mapping_free );
228 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
229 ldap_pvt_thread_mutex_destroy( &li->conn_mutex );
232 ch_free( be->be_private );