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 #if SLAPD_LDAP == SLAPD_MOD_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 */
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;
63 bi->bi_db_open = ldap_back_db_open;
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;
94 struct ldapmapping *mapping;
96 li = (struct ldapinfo *) ch_calloc( 1, sizeof(struct ldapinfo) );
101 BER_BVZERO( &li->acl_authcDN );
102 BER_BVZERO( &li->acl_passwd );
104 #ifdef LDAP_BACK_PROXY_AUTHZ
105 li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
107 BER_BVZERO( &li->idassert_authcID );
108 BER_BVZERO( &li->idassert_authcDN );
109 BER_BVZERO( &li->idassert_passwd );
111 BER_BVZERO( &li->idassert_authzID );
112 li->idassert_authz = NULL;
114 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
115 li->idassert_sasl_flags = LDAP_SASL_QUIET;
116 BER_BVZERO( &li->idassert_sasl_mech );
117 BER_BVZERO( &li->idassert_sasl_realm );
119 li->idassert_ppolicy = 0;
121 /* by default, use proxyAuthz control on each operation */
122 li->idassert_flags = LDAP_BACK_AUTH_NONE;
123 #endif /* LDAP_BACK_PROXY_AUTHZ */
125 #ifdef ENABLE_REWRITE
126 li->rwmap.rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
127 if ( li->rwmap.rwm_rw == NULL ) {
136 * the filter rewrite as a string must be disabled
137 * by default; it can be re-enabled by adding rules;
138 * this creates an empty rewriteContext
140 rargv[ 0 ] = "rewriteContext";
141 rargv[ 1 ] = "searchFilter";
143 rewrite_parse( li->rwmap.rwm_rw, "<suffix massage>",
146 rargv[ 0 ] = "rewriteContext";
147 rargv[ 1 ] = "default";
149 rewrite_parse( li->rwmap.rwm_rw, "<suffix massage>",
152 #endif /* ENABLE_REWRITE */
154 ldap_pvt_thread_mutex_init( &li->conn_mutex );
156 ldap_back_map_init( &li->rwmap.rwm_oc, &mapping );
157 ldap_back_map_init( &li->rwmap.rwm_at, &mapping );
160 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
166 ldap_back_db_open( BackendDB *be )
168 struct ldapinfo *li = (struct ldapinfo *)be->be_private;
171 LDAP_LOG( BACK_LDAP, DETAIL1,
172 "ldap_back_db_open: URI=%s\n", li->url, 0, 0 );
174 Debug( LDAP_DEBUG_TRACE,
175 "ldap_back_db_open: URI=%s\n", li->url, 0, 0 );
178 #ifdef LDAP_BACK_PROXY_AUTHZ
179 /* by default, use proxyAuthz control on each operation */
180 switch ( li->idassert_mode ) {
181 case LDAP_BACK_IDASSERT_LEGACY:
182 case LDAP_BACK_IDASSERT_SELF:
183 /* however, since admin connections are pooled and shared,
184 * only static authzIDs can be native */
185 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
191 #endif /* LDAP_BACK_PROXY_AUTHZ */
201 struct ldapconn *lc = v_lc;
202 ldap_unbind( lc->ld );
203 if ( lc->bound_dn.bv_val ) {
204 ch_free( lc->bound_dn.bv_val );
206 if ( lc->cred.bv_val ) {
207 memset( lc->cred.bv_val, 0, lc->cred.bv_len );
208 ch_free( lc->cred.bv_val );
210 if ( lc->local_dn.bv_val ) {
211 ch_free( lc->local_dn.bv_val );
213 ldap_pvt_thread_mutex_destroy( &lc->lc_mutex );
218 mapping_free( void *v_mapping )
220 struct ldapmapping *mapping = v_mapping;
221 ch_free( mapping->src.bv_val );
222 ch_free( mapping->dst.bv_val );
227 ldap_back_db_destroy(
233 if (be->be_private) {
234 li = (struct ldapinfo *)be->be_private;
236 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
243 ldap_free_urldesc( li->lud );
246 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
247 ch_free( li->acl_authcDN.bv_val );
248 BER_BVZERO( &li->acl_authcDN );
250 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
251 ch_free( li->acl_passwd.bv_val );
252 BER_BVZERO( &li->acl_passwd );
254 #ifdef LDAP_BACK_PROXY_AUTHZ
255 if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
256 ch_free( li->idassert_authcID.bv_val );
257 BER_BVZERO( &li->idassert_authcID );
259 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
260 ch_free( li->idassert_authcDN.bv_val );
261 BER_BVZERO( &li->idassert_authcDN );
263 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
264 ch_free( li->idassert_passwd.bv_val );
265 BER_BVZERO( &li->idassert_passwd );
267 if ( !BER_BVISNULL( &li->idassert_authzID ) ) {
268 ch_free( li->idassert_authzID.bv_val );
269 BER_BVZERO( &li->idassert_authzID );
271 if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
272 ch_free( li->idassert_sasl_mech.bv_val );
273 BER_BVZERO( &li->idassert_sasl_mech );
275 if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
276 ch_free( li->idassert_sasl_realm.bv_val );
277 BER_BVZERO( &li->idassert_sasl_realm );
279 #endif /* LDAP_BACK_PROXY_AUTHZ */
281 avl_free( li->conntree, ldap_back_conn_free );
283 #ifdef ENABLE_REWRITE
284 if (li->rwmap.rwm_rw) {
285 rewrite_info_delete( &li->rwmap.rwm_rw );
287 #else /* !ENABLE_REWRITE */
288 if (li->rwmap.rwm_suffix_massage) {
289 ber_bvarray_free( li->rwmap.rwm_suffix_massage );
291 #endif /* !ENABLE_REWRITE */
293 avl_free( li->rwmap.rwm_oc.remap, NULL );
294 avl_free( li->rwmap.rwm_oc.map, mapping_free );
295 avl_free( li->rwmap.rwm_at.remap, NULL );
296 avl_free( li->rwmap.rwm_at.map, mapping_free );
298 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
299 ldap_pvt_thread_mutex_destroy( &li->conn_mutex );
302 ch_free( be->be_private );