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"
35 #if SLAPD_LDAP == SLAPD_MOD_DYNAMIC
37 int init_module(int argc, char *argv[]) {
40 memset( &bi, '\0', sizeof(bi) );
42 bi.bi_init = ldap_back_initialize;
48 #endif /* SLAPD_LDAP */
55 bi->bi_controls = slap_known_controls;
64 bi->bi_open = ldap_back_open;
69 bi->bi_db_init = ldap_back_db_init;
70 bi->bi_db_config = ldap_back_db_config;
71 bi->bi_db_open = ldap_back_db_open;
73 bi->bi_db_destroy = ldap_back_db_destroy;
75 bi->bi_op_bind = ldap_back_bind;
77 bi->bi_op_search = ldap_back_search;
78 bi->bi_op_compare = ldap_back_compare;
79 bi->bi_op_modify = ldap_back_modify;
80 bi->bi_op_modrdn = ldap_back_modrdn;
81 bi->bi_op_add = ldap_back_add;
82 bi->bi_op_delete = ldap_back_delete;
83 bi->bi_op_abandon = 0;
85 bi->bi_extended = ldap_back_extended;
87 bi->bi_chk_referrals = 0;
88 bi->bi_entry_get_rw = ldap_back_entry_get;
90 bi->bi_connection_init = 0;
91 bi->bi_connection_destroy = ldap_back_conn_destroy;
102 struct ldapmapping *mapping;
104 li = (struct ldapinfo *) ch_calloc( 1, sizeof(struct ldapinfo) );
109 BER_BVZERO( &li->acl_authcDN );
110 BER_BVZERO( &li->acl_passwd );
112 #ifdef LDAP_BACK_PROXY_AUTHZ
113 li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
115 BER_BVZERO( &li->idassert_authcID );
116 BER_BVZERO( &li->idassert_authcDN );
117 BER_BVZERO( &li->idassert_passwd );
119 BER_BVZERO( &li->idassert_authzID );
120 li->idassert_authz = NULL;
122 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
123 li->idassert_sasl_flags = LDAP_SASL_QUIET;
124 BER_BVZERO( &li->idassert_sasl_mech );
125 BER_BVZERO( &li->idassert_sasl_realm );
127 li->idassert_ppolicy = 0;
129 /* by default, use proxyAuthz control on each operation */
130 li->idassert_flags = LDAP_BACK_AUTH_NONE;
131 #endif /* LDAP_BACK_PROXY_AUTHZ */
133 #ifdef ENABLE_REWRITE
134 li->rwmap.rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
135 if ( li->rwmap.rwm_rw == NULL ) {
144 * the filter rewrite as a string must be disabled
145 * by default; it can be re-enabled by adding rules;
146 * this creates an empty rewriteContext
148 rargv[ 0 ] = "rewriteContext";
149 rargv[ 1 ] = "searchFilter";
151 rewrite_parse( li->rwmap.rwm_rw, "<suffix massage>",
154 rargv[ 0 ] = "rewriteContext";
155 rargv[ 1 ] = "default";
157 rewrite_parse( li->rwmap.rwm_rw, "<suffix massage>",
160 #endif /* ENABLE_REWRITE */
162 ldap_pvt_thread_mutex_init( &li->conn_mutex );
164 ldap_back_map_init( &li->rwmap.rwm_oc, &mapping );
165 ldap_back_map_init( &li->rwmap.rwm_at, &mapping );
168 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
174 ldap_back_db_open( BackendDB *be )
176 struct ldapinfo *li = (struct ldapinfo *)be->be_private;
178 Debug( LDAP_DEBUG_TRACE,
179 "ldap_back_db_open: URI=%s\n", li->url, 0, 0 );
181 #ifdef LDAP_BACK_PROXY_AUTHZ
182 /* by default, use proxyAuthz control on each operation */
183 switch ( li->idassert_mode ) {
184 case LDAP_BACK_IDASSERT_LEGACY:
185 case LDAP_BACK_IDASSERT_SELF:
186 /* however, since admin connections are pooled and shared,
187 * only static authzIDs can be native */
188 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
194 #endif /* LDAP_BACK_PROXY_AUTHZ */
204 struct ldapconn *lc = v_lc;
205 ldap_unbind( lc->ld );
206 if ( lc->bound_dn.bv_val ) {
207 ch_free( lc->bound_dn.bv_val );
209 if ( lc->cred.bv_val ) {
210 memset( lc->cred.bv_val, 0, lc->cred.bv_len );
211 ch_free( lc->cred.bv_val );
213 if ( lc->local_dn.bv_val ) {
214 ch_free( lc->local_dn.bv_val );
216 ldap_pvt_thread_mutex_destroy( &lc->lc_mutex );
221 mapping_free( void *v_mapping )
223 struct ldapmapping *mapping = v_mapping;
224 ch_free( mapping->src.bv_val );
225 ch_free( mapping->dst.bv_val );
230 ldap_back_db_destroy(
236 if (be->be_private) {
237 li = (struct ldapinfo *)be->be_private;
239 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
246 ldap_free_urldesc( li->lud );
249 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
250 ch_free( li->acl_authcDN.bv_val );
251 BER_BVZERO( &li->acl_authcDN );
253 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
254 ch_free( li->acl_passwd.bv_val );
255 BER_BVZERO( &li->acl_passwd );
257 #ifdef LDAP_BACK_PROXY_AUTHZ
258 if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
259 ch_free( li->idassert_authcID.bv_val );
260 BER_BVZERO( &li->idassert_authcID );
262 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
263 ch_free( li->idassert_authcDN.bv_val );
264 BER_BVZERO( &li->idassert_authcDN );
266 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
267 ch_free( li->idassert_passwd.bv_val );
268 BER_BVZERO( &li->idassert_passwd );
270 if ( !BER_BVISNULL( &li->idassert_authzID ) ) {
271 ch_free( li->idassert_authzID.bv_val );
272 BER_BVZERO( &li->idassert_authzID );
274 if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
275 ch_free( li->idassert_sasl_mech.bv_val );
276 BER_BVZERO( &li->idassert_sasl_mech );
278 if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
279 ch_free( li->idassert_sasl_realm.bv_val );
280 BER_BVZERO( &li->idassert_sasl_realm );
282 #endif /* LDAP_BACK_PROXY_AUTHZ */
284 avl_free( li->conntree, ldap_back_conn_free );
286 #ifdef ENABLE_REWRITE
287 if (li->rwmap.rwm_rw) {
288 rewrite_info_delete( &li->rwmap.rwm_rw );
290 #else /* !ENABLE_REWRITE */
291 if (li->rwmap.rwm_suffix_massage) {
292 ber_bvarray_free( li->rwmap.rwm_suffix_massage );
294 #endif /* !ENABLE_REWRITE */
296 avl_free( li->rwmap.rwm_oc.remap, NULL );
297 avl_free( li->rwmap.rwm_oc.map, mapping_free );
298 avl_free( li->rwmap.rwm_at.remap, NULL );
299 avl_free( li->rwmap.rwm_at.map, mapping_free );
301 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
302 ldap_pvt_thread_mutex_destroy( &li->conn_mutex );
305 ch_free( be->be_private );