1 /* init.c - initialize ldap backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2004 The OpenLDAP Foundation.
6 * Portions Copyright 1999-2003 Howard Chu.
7 * Portions Copyright 2000-2003 Pierangelo Masarati.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
19 * This work was initially developed by the Howard Chu for inclusion
20 * in OpenLDAP Software and subsequently enhanced by Pierangelo
28 #include <ac/string.h>
29 #include <ac/socket.h>
32 #include "back-ldap.h"
34 #ifdef SLAPD_LDAP_DYNAMIC
36 int init_module(int argc, char *argv[]) {
39 memset( &bi, '\0', sizeof(bi) );
41 bi.bi_init = ldap_back_initialize;
47 #endif /* SLAPD_LDAP_DYNAMIC */
54 bi->bi_controls = slap_known_controls;
61 bi->bi_db_init = ldap_back_db_init;
62 bi->bi_db_config = ldap_back_db_config;
65 bi->bi_db_destroy = ldap_back_db_destroy;
67 bi->bi_op_bind = ldap_back_bind;
69 bi->bi_op_search = ldap_back_search;
70 bi->bi_op_compare = ldap_back_compare;
71 bi->bi_op_modify = ldap_back_modify;
72 bi->bi_op_modrdn = ldap_back_modrdn;
73 bi->bi_op_add = ldap_back_add;
74 bi->bi_op_delete = ldap_back_delete;
75 bi->bi_op_abandon = 0;
77 bi->bi_extended = ldap_back_extended;
79 bi->bi_chk_referrals = 0;
80 bi->bi_entry_get_rw = ldap_back_entry_get;
82 bi->bi_connection_init = 0;
83 bi->bi_connection_destroy = ldap_back_conn_destroy;
96 struct ldapmapping *mapping;
98 li = (struct ldapinfo *) ch_calloc( 1, sizeof(struct ldapinfo) );
103 li->binddn.bv_val = NULL;
104 li->binddn.bv_len = 0;
105 li->bindpw.bv_val = NULL;
106 li->bindpw.bv_len = 0;
108 #ifdef LDAP_BACK_PROXY_AUTHZ
109 li->proxyauthzdn.bv_val = NULL;
110 li->proxyauthzdn.bv_len = 0;
111 li->proxyauthzpw.bv_val = NULL;
112 li->proxyauthzpw.bv_len = 0;
113 #endif /* LDAP_BACK_PROXY_AUTHZ */
115 #ifdef ENABLE_REWRITE
116 li->rwmap.rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
117 if ( li->rwmap.rwm_rw == NULL ) {
126 * the filter rewrite as a string must be disabled
127 * by default; it can be re-enabled by adding rules;
128 * this creates an empty rewriteContext
130 rargv[ 0 ] = "rewriteContext";
131 rargv[ 1 ] = "searchFilter";
133 rewrite_parse( li->rwmap.rwm_rw, "<suffix massage>",
136 #endif /* ENABLE_REWRITE */
138 ldap_pvt_thread_mutex_init( &li->conn_mutex );
140 ldap_back_map_init( &li->rwmap.rwm_oc, &mapping );
141 ldap_back_map_init( &li->rwmap.rwm_at, &mapping );
145 be->be_flags |= SLAP_BFLAG_NOLASTMOD;
155 struct ldapconn *lc = v_lc;
156 ldap_unbind( lc->ld );
157 if ( lc->bound_dn.bv_val ) {
158 ch_free( lc->bound_dn.bv_val );
160 if ( lc->cred.bv_val ) {
161 memset( lc->cred.bv_val, 0, lc->cred.bv_len );
162 ch_free( lc->cred.bv_val );
164 if ( lc->local_dn.bv_val ) {
165 ch_free( lc->local_dn.bv_val );
167 ldap_pvt_thread_mutex_destroy( &lc->lc_mutex );
172 mapping_free( void *v_mapping )
174 struct ldapmapping *mapping = v_mapping;
175 ch_free( mapping->src.bv_val );
176 ch_free( mapping->dst.bv_val );
181 ldap_back_db_destroy(
187 if (be->be_private) {
188 li = (struct ldapinfo *)be->be_private;
190 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
196 if (li->binddn.bv_val) {
197 ch_free(li->binddn.bv_val);
198 li->binddn.bv_val = NULL;
200 if (li->bindpw.bv_val) {
201 ch_free(li->bindpw.bv_val);
202 li->bindpw.bv_val = NULL;
204 #ifdef LDAP_BACK_PROXY_AUTHZ
205 if (li->proxyauthzdn.bv_val) {
206 ch_free(li->proxyauthzdn.bv_val);
207 li->proxyauthzdn.bv_val = NULL;
209 if (li->proxyauthzpw.bv_val) {
210 ch_free(li->proxyauthzpw.bv_val);
211 li->proxyauthzpw.bv_val = NULL;
213 #endif /* LDAP_BACK_PROXY_AUTHZ */
215 avl_free( li->conntree, ldap_back_conn_free );
217 #ifdef ENABLE_REWRITE
218 if (li->rwmap.rwm_rw) {
219 rewrite_info_delete( &li->rwmap.rwm_rw );
221 #else /* !ENABLE_REWRITE */
222 if (li->rwmap.rwm_suffix_massage) {
223 ber_bvarray_free( li->rwmap.rwm_suffix_massage );
225 #endif /* !ENABLE_REWRITE */
227 avl_free( li->rwmap.rwm_oc.remap, NULL );
228 avl_free( li->rwmap.rwm_oc.map, mapping_free );
229 avl_free( li->rwmap.rwm_at.remap, NULL );
230 avl_free( li->rwmap.rwm_at.map, mapping_free );
232 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
233 ldap_pvt_thread_mutex_destroy( &li->conn_mutex );
236 ch_free( be->be_private );