1 /* init.c - initialize ldap backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2006 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 ldap_back_open( BackendInfo *bi )
37 bi->bi_controls = slap_known_controls;
42 ldap_back_initialize( BackendInfo *bi )
47 #ifdef LDAP_DYNAMIC_OBJECTS
48 /* this is set because all the support a proxy has to provide
49 * is the capability to forward the refresh exop, and to
50 * pass thru entries that contain the dynamicObject class
51 * and the entryTtl attribute */
53 #endif /* LDAP_DYNAMIC_OBJECTS */
56 bi->bi_open = ldap_back_open;
61 bi->bi_db_init = ldap_back_db_init;
62 bi->bi_db_config = config_generic_wrapper;
63 bi->bi_db_open = ldap_back_db_open;
64 bi->bi_db_close = ldap_back_db_close;
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;
85 rc = chain_initialize();
91 rc = distproc_initialize();
97 return ldap_back_init_cf( bi );
101 ldap_back_db_init( Backend *be )
106 li = (ldapinfo_t *)ch_calloc( 1, sizeof( ldapinfo_t ) );
111 li->li_rebind_f = ldap_back_default_rebind;
112 li->li_urllist_f = ldap_back_default_urllist;
113 li->li_urllist_p = li;
114 ldap_pvt_thread_mutex_init( &li->li_uri_mutex );
116 BER_BVZERO( &li->li_acl_authcID );
117 BER_BVZERO( &li->li_acl_authcDN );
118 BER_BVZERO( &li->li_acl_passwd );
120 li->li_acl_authmethod = LDAP_AUTH_NONE;
121 BER_BVZERO( &li->li_acl_sasl_mech );
122 li->li_acl.sb_tls = SB_TLS_DEFAULT;
124 li->li_idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
126 BER_BVZERO( &li->li_idassert_authcID );
127 BER_BVZERO( &li->li_idassert_authcDN );
128 BER_BVZERO( &li->li_idassert_passwd );
130 BER_BVZERO( &li->li_idassert_authzID );
132 li->li_idassert_authmethod = LDAP_AUTH_NONE;
133 BER_BVZERO( &li->li_idassert_sasl_mech );
134 li->li_idassert_tls = SB_TLS_DEFAULT;
136 /* by default, use proxyAuthz control on each operation */
137 li->li_idassert_flags = LDAP_BACK_AUTH_PRESCRIPTIVE;
139 li->li_idassert_authz = NULL;
141 /* initialize flags */
142 li->li_flags = LDAP_BACK_F_CHASE_REFERRALS;
144 /* initialize version */
145 li->li_version = LDAP_VERSION3;
147 ldap_pvt_thread_mutex_init( &li->li_conninfo.lai_mutex );
150 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_NOLASTMOD;
152 be->be_cf_ocs = be->bd_info->bi_cf_ocs;
154 #if 0 /* disable by now */
155 rc = ldap_back_monitor_db_init( be );
162 ldap_back_db_open( BackendDB *be )
164 ldapinfo_t *li = (ldapinfo_t *)be->be_private;
166 slap_bindconf sb = { 0 };
169 Debug( LDAP_DEBUG_TRACE,
170 "ldap_back_db_open: URI=%s\n",
171 li->li_uri != NULL ? li->li_uri : "", 0, 0 );
173 /* by default, use proxyAuthz control on each operation */
174 switch ( li->li_idassert_mode ) {
175 case LDAP_BACK_IDASSERT_LEGACY:
176 case LDAP_BACK_IDASSERT_SELF:
177 /* however, since admin connections are pooled and shared,
178 * only static authzIDs can be native */
179 li->li_idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
186 ber_str2bv( li->li_uri, 0, 0, &sb.sb_uri );
187 sb.sb_version = li->li_version;
188 sb.sb_method = LDAP_AUTH_SIMPLE;
189 BER_BVSTR( &sb.sb_binddn, "" );
191 if ( LDAP_BACK_T_F_DISCOVER( li ) && !LDAP_BACK_T_F( li ) ) {
194 rc = slap_discover_feature( &sb,
195 slap_schema.si_ad_supportedFeatures->ad_cname.bv_val,
196 LDAP_FEATURE_ABSOLUTE_FILTERS );
197 if ( rc == LDAP_COMPARE_TRUE ) {
198 li->li_flags |= LDAP_BACK_F_T_F;
202 if ( LDAP_BACK_CANCEL_DISCOVER( li ) && !LDAP_BACK_CANCEL( li ) ) {
203 rc = slap_discover_feature( &sb,
204 slap_schema.si_ad_supportedExtension->ad_cname.bv_val,
206 if ( rc == LDAP_COMPARE_TRUE ) {
207 li->li_flags |= LDAP_BACK_F_CANCEL_EXOP;
211 #if 0 /* disable by now */
213 rc = ldap_back_monitor_db_open( be );
219 li->li_flags |= LDAP_BACK_F_ISOPEN;
226 ldap_back_conn_free( void *v_lc )
228 ldapconn_t *lc = v_lc;
230 if ( lc->lc_ld != NULL ) {
231 ldap_unbind_ext( lc->lc_ld, NULL, NULL );
233 if ( !BER_BVISNULL( &lc->lc_bound_ndn ) ) {
234 ch_free( lc->lc_bound_ndn.bv_val );
236 if ( !BER_BVISNULL( &lc->lc_cred ) ) {
237 memset( lc->lc_cred.bv_val, 0, lc->lc_cred.bv_len );
238 ch_free( lc->lc_cred.bv_val );
240 if ( !BER_BVISNULL( &lc->lc_local_ndn ) ) {
241 ch_free( lc->lc_local_ndn.bv_val );
247 ldap_back_db_close( Backend *be )
251 #if 0 /* disable by now */
252 if ( be->be_private ) {
253 rc = ldap_back_monitor_db_close( be );
261 ldap_back_db_destroy( Backend *be )
263 if ( be->be_private ) {
264 ldapinfo_t *li = ( ldapinfo_t * )be->be_private;
266 #if 0 /* disable by now */
267 (void)ldap_back_monitor_db_destroy( be );
270 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
272 if ( li->li_uri != NULL ) {
273 ch_free( li->li_uri );
276 assert( li->li_bvuri != NULL );
277 ber_bvarray_free( li->li_bvuri );
280 if ( !BER_BVISNULL( &li->li_acl_authcID ) ) {
281 ch_free( li->li_acl_authcID.bv_val );
282 BER_BVZERO( &li->li_acl_authcID );
284 if ( !BER_BVISNULL( &li->li_acl_authcDN ) ) {
285 ch_free( li->li_acl_authcDN.bv_val );
286 BER_BVZERO( &li->li_acl_authcDN );
288 if ( !BER_BVISNULL( &li->li_acl_passwd ) ) {
289 ch_free( li->li_acl_passwd.bv_val );
290 BER_BVZERO( &li->li_acl_passwd );
292 if ( !BER_BVISNULL( &li->li_acl_sasl_mech ) ) {
293 ch_free( li->li_acl_sasl_mech.bv_val );
294 BER_BVZERO( &li->li_acl_sasl_mech );
296 if ( !BER_BVISNULL( &li->li_acl_sasl_realm ) ) {
297 ch_free( li->li_acl_sasl_realm.bv_val );
298 BER_BVZERO( &li->li_acl_sasl_realm );
300 if ( !BER_BVISNULL( &li->li_idassert_authcID ) ) {
301 ch_free( li->li_idassert_authcID.bv_val );
302 BER_BVZERO( &li->li_idassert_authcID );
304 if ( !BER_BVISNULL( &li->li_idassert_authcDN ) ) {
305 ch_free( li->li_idassert_authcDN.bv_val );
306 BER_BVZERO( &li->li_idassert_authcDN );
308 if ( !BER_BVISNULL( &li->li_idassert_passwd ) ) {
309 ch_free( li->li_idassert_passwd.bv_val );
310 BER_BVZERO( &li->li_idassert_passwd );
312 if ( !BER_BVISNULL( &li->li_idassert_authzID ) ) {
313 ch_free( li->li_idassert_authzID.bv_val );
314 BER_BVZERO( &li->li_idassert_authzID );
316 if ( !BER_BVISNULL( &li->li_idassert_sasl_mech ) ) {
317 ch_free( li->li_idassert_sasl_mech.bv_val );
318 BER_BVZERO( &li->li_idassert_sasl_mech );
320 if ( !BER_BVISNULL( &li->li_idassert_sasl_realm ) ) {
321 ch_free( li->li_idassert_sasl_realm.bv_val );
322 BER_BVZERO( &li->li_idassert_sasl_realm );
324 if ( li->li_idassert_authz != NULL ) {
325 ber_bvarray_free( li->li_idassert_authz );
326 li->li_idassert_authz = NULL;
328 if ( li->li_conninfo.lai_tree ) {
329 avl_free( li->li_conninfo.lai_tree, ldap_back_conn_free );
331 if ( LDAP_BACK_QUARANTINE( li ) ) {
332 slap_retry_info_destroy( &li->li_quarantine );
333 ldap_pvt_thread_mutex_destroy( &li->li_quarantine_mutex );
336 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
337 ldap_pvt_thread_mutex_destroy( &li->li_conninfo.lai_mutex );
338 ldap_pvt_thread_mutex_destroy( &li->li_uri_mutex );
341 ch_free( be->be_private );
346 #if SLAPD_LDAP == SLAPD_MOD_DYNAMIC
348 /* conditionally define the init_module() function */
349 SLAP_BACKEND_INIT_MODULE( ldap )
351 #endif /* SLAPD_LDAP == SLAPD_MOD_DYNAMIC */