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 )
45 #ifdef LDAP_DYNAMIC_OBJECTS
46 /* this is set because all the support a proxy has to provide
47 * is the capability to forward the refresh exop, and to
48 * pass thru entries that contain the dynamicObject class
49 * and the entryTtl attribute */
51 #endif /* LDAP_DYNAMIC_OBJECTS */
54 bi->bi_open = ldap_back_open;
59 bi->bi_db_init = ldap_back_db_init;
60 bi->bi_db_config = config_generic_wrapper;
61 bi->bi_db_open = ldap_back_db_open;
63 bi->bi_db_destroy = ldap_back_db_destroy;
65 bi->bi_op_bind = ldap_back_bind;
67 bi->bi_op_search = ldap_back_search;
68 bi->bi_op_compare = ldap_back_compare;
69 bi->bi_op_modify = ldap_back_modify;
70 bi->bi_op_modrdn = ldap_back_modrdn;
71 bi->bi_op_add = ldap_back_add;
72 bi->bi_op_delete = ldap_back_delete;
73 bi->bi_op_abandon = 0;
75 bi->bi_extended = ldap_back_extended;
77 bi->bi_chk_referrals = 0;
78 bi->bi_entry_get_rw = ldap_back_entry_get;
80 bi->bi_connection_init = 0;
81 bi->bi_connection_destroy = ldap_back_conn_destroy;
83 if ( chain_initialize() ) {
88 if ( distproc_initialize() ) {
93 return ldap_back_init_cf( bi );
97 ldap_back_db_init( Backend *be )
101 li = (ldapinfo_t *)ch_calloc( 1, sizeof( ldapinfo_t ) );
106 BER_BVZERO( &li->li_acl_authcID );
107 BER_BVZERO( &li->li_acl_authcDN );
108 BER_BVZERO( &li->li_acl_passwd );
110 li->li_acl_authmethod = LDAP_AUTH_NONE;
111 BER_BVZERO( &li->li_acl_sasl_mech );
112 li->li_acl.sb_tls = SB_TLS_DEFAULT;
114 li->li_idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
116 BER_BVZERO( &li->li_idassert_authcID );
117 BER_BVZERO( &li->li_idassert_authcDN );
118 BER_BVZERO( &li->li_idassert_passwd );
120 BER_BVZERO( &li->li_idassert_authzID );
122 li->li_idassert_authmethod = LDAP_AUTH_NONE;
123 BER_BVZERO( &li->li_idassert_sasl_mech );
124 li->li_idassert.sb_tls = SB_TLS_DEFAULT;
126 /* by default, use proxyAuthz control on each operation */
127 li->li_idassert_flags = LDAP_BACK_AUTH_PRESCRIPTIVE;
129 li->li_idassert_authz = NULL;
131 /* initialize flags */
132 li->li_flags = LDAP_BACK_F_CHASE_REFERRALS;
134 /* initialize version */
135 li->li_version = LDAP_VERSION3;
137 ldap_pvt_thread_mutex_init( &li->li_conninfo.lai_mutex );
140 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_NOLASTMOD;
142 be->be_cf_ocs = be->bd_info->bi_cf_ocs;
148 ldap_back_db_open( BackendDB *be )
150 ldapinfo_t *li = (ldapinfo_t *)be->be_private;
152 Debug( LDAP_DEBUG_TRACE,
153 "ldap_back_db_open: URI=%s\n",
154 li->li_uri != NULL ? li->li_uri : "", 0, 0 );
156 /* by default, use proxyAuthz control on each operation */
157 switch ( li->li_idassert_mode ) {
158 case LDAP_BACK_IDASSERT_LEGACY:
159 case LDAP_BACK_IDASSERT_SELF:
160 /* however, since admin connections are pooled and shared,
161 * only static authzIDs can be native */
162 li->li_idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
169 #if 0 && defined(SLAPD_MONITOR)
171 /* FIXME: disabled because namingContexts doesn't have
172 * a matching rule, and using an MRA filter doesn't work
173 * because the normalized assertion is compared to the
174 * non-normalized value, which in general differs from
175 * the normalized one. See ITS#3406 */
176 struct berval filter,
177 base = BER_BVC( "cn=Databases," SLAPD_MONITOR );
180 filter.bv_len = STRLENOF( "(&(namingContexts:distinguishedNameMatch:=)(monitoredInfo=ldap))" )
181 + be->be_nsuffix[ 0 ].bv_len;
182 filter.bv_val = ch_malloc( filter.bv_len + 1 );
183 snprintf( filter.bv_val, filter.bv_len + 1,
184 "(&(namingContexts:distinguishedNameMatch:=%s)(monitoredInfo=ldap))",
185 be->be_nsuffix[ 0 ].bv_val );
187 a.a_desc = slap_schema.si_ad_labeledURI;
188 a.a_vals = li->li_bvuri;
189 a.a_nvals = li->li_bvuri;
190 if ( monitor_back_register_entry_attrs( NULL, &a, NULL, &base, LDAP_SCOPE_SUBTREE, &filter ) ) {
194 ch_free( filter.bv_val );
196 #endif /* SLAPD_MONITOR */
198 if ( li->li_flags & LDAP_BACK_F_SUPPORT_T_F_DISCOVER ) {
201 li->li_flags &= ~LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
203 rc = slap_discover_feature( li->li_uri, li->li_version,
204 slap_schema.si_ad_supportedFeatures->ad_cname.bv_val,
205 LDAP_FEATURE_ABSOLUTE_FILTERS );
206 if ( rc == LDAP_COMPARE_TRUE ) {
207 li->li_flags |= LDAP_BACK_F_SUPPORT_T_F;
215 ldap_back_conn_free( void *v_lc )
217 ldapconn_t *lc = v_lc;
219 if ( lc->lc_ld != NULL ) {
220 ldap_unbind_ext( lc->lc_ld, NULL, NULL );
222 if ( !BER_BVISNULL( &lc->lc_bound_ndn ) ) {
223 ch_free( lc->lc_bound_ndn.bv_val );
225 if ( !BER_BVISNULL( &lc->lc_cred ) ) {
226 memset( lc->lc_cred.bv_val, 0, lc->lc_cred.bv_len );
227 ch_free( lc->lc_cred.bv_val );
229 if ( !BER_BVISNULL( &lc->lc_local_ndn ) ) {
230 ch_free( lc->lc_local_ndn.bv_val );
236 ldap_back_db_destroy(
240 if ( be->be_private ) {
241 ldapinfo_t *li = ( ldapinfo_t * )be->be_private;
243 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
245 if ( li->li_uri != NULL ) {
246 ch_free( li->li_uri );
249 assert( li->li_bvuri != NULL );
250 ber_bvarray_free( li->li_bvuri );
253 if ( !BER_BVISNULL( &li->li_acl_authcID ) ) {
254 ch_free( li->li_acl_authcID.bv_val );
255 BER_BVZERO( &li->li_acl_authcID );
257 if ( !BER_BVISNULL( &li->li_acl_authcDN ) ) {
258 ch_free( li->li_acl_authcDN.bv_val );
259 BER_BVZERO( &li->li_acl_authcDN );
261 if ( !BER_BVISNULL( &li->li_acl_passwd ) ) {
262 ch_free( li->li_acl_passwd.bv_val );
263 BER_BVZERO( &li->li_acl_passwd );
265 if ( !BER_BVISNULL( &li->li_acl_sasl_mech ) ) {
266 ch_free( li->li_acl_sasl_mech.bv_val );
267 BER_BVZERO( &li->li_acl_sasl_mech );
269 if ( !BER_BVISNULL( &li->li_acl_sasl_realm ) ) {
270 ch_free( li->li_acl_sasl_realm.bv_val );
271 BER_BVZERO( &li->li_acl_sasl_realm );
273 if ( !BER_BVISNULL( &li->li_idassert_authcID ) ) {
274 ch_free( li->li_idassert_authcID.bv_val );
275 BER_BVZERO( &li->li_idassert_authcID );
277 if ( !BER_BVISNULL( &li->li_idassert_authcDN ) ) {
278 ch_free( li->li_idassert_authcDN.bv_val );
279 BER_BVZERO( &li->li_idassert_authcDN );
281 if ( !BER_BVISNULL( &li->li_idassert_passwd ) ) {
282 ch_free( li->li_idassert_passwd.bv_val );
283 BER_BVZERO( &li->li_idassert_passwd );
285 if ( !BER_BVISNULL( &li->li_idassert_authzID ) ) {
286 ch_free( li->li_idassert_authzID.bv_val );
287 BER_BVZERO( &li->li_idassert_authzID );
289 if ( !BER_BVISNULL( &li->li_idassert_sasl_mech ) ) {
290 ch_free( li->li_idassert_sasl_mech.bv_val );
291 BER_BVZERO( &li->li_idassert_sasl_mech );
293 if ( !BER_BVISNULL( &li->li_idassert_sasl_realm ) ) {
294 ch_free( li->li_idassert_sasl_realm.bv_val );
295 BER_BVZERO( &li->li_idassert_sasl_realm );
297 if ( li->li_idassert_authz != NULL ) {
298 ber_bvarray_free( li->li_idassert_authz );
299 li->li_idassert_authz = NULL;
301 if ( li->li_conninfo.lai_tree ) {
302 avl_free( li->li_conninfo.lai_tree, ldap_back_conn_free );
305 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
306 ldap_pvt_thread_mutex_destroy( &li->li_conninfo.lai_mutex );
309 ch_free( be->be_private );
314 #if SLAPD_LDAP == SLAPD_MOD_DYNAMIC
316 /* conditionally define the init_module() function */
317 SLAP_BACKEND_INIT_MODULE( ldap )
319 #endif /* SLAPD_LDAP == SLAPD_MOD_DYNAMIC */