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 li->li_rebind_f = ldap_back_default_rebind;
107 li->li_urllist_f = ldap_back_default_urllist;
108 li->li_urllist_p = li;
109 ldap_pvt_thread_mutex_init( &li->li_uri_mutex );
111 BER_BVZERO( &li->li_acl_authcID );
112 BER_BVZERO( &li->li_acl_authcDN );
113 BER_BVZERO( &li->li_acl_passwd );
115 li->li_acl_authmethod = LDAP_AUTH_NONE;
116 BER_BVZERO( &li->li_acl_sasl_mech );
117 li->li_acl.sb_tls = SB_TLS_DEFAULT;
119 li->li_idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
121 BER_BVZERO( &li->li_idassert_authcID );
122 BER_BVZERO( &li->li_idassert_authcDN );
123 BER_BVZERO( &li->li_idassert_passwd );
125 BER_BVZERO( &li->li_idassert_authzID );
127 li->li_idassert_authmethod = LDAP_AUTH_NONE;
128 BER_BVZERO( &li->li_idassert_sasl_mech );
129 li->li_idassert_tls = SB_TLS_DEFAULT;
131 /* by default, use proxyAuthz control on each operation */
132 li->li_idassert_flags = LDAP_BACK_AUTH_PRESCRIPTIVE;
134 li->li_idassert_authz = NULL;
136 /* initialize flags */
137 li->li_flags = LDAP_BACK_F_CHASE_REFERRALS;
139 /* initialize version */
140 li->li_version = LDAP_VERSION3;
142 ldap_pvt_thread_mutex_init( &li->li_conninfo.lai_mutex );
145 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_NOLASTMOD;
147 be->be_cf_ocs = be->bd_info->bi_cf_ocs;
153 ldap_back_db_open( BackendDB *be )
155 ldapinfo_t *li = (ldapinfo_t *)be->be_private;
157 slap_bindconf sb = { 0 };
160 Debug( LDAP_DEBUG_TRACE,
161 "ldap_back_db_open: URI=%s\n",
162 li->li_uri != NULL ? li->li_uri : "", 0, 0 );
164 /* by default, use proxyAuthz control on each operation */
165 switch ( li->li_idassert_mode ) {
166 case LDAP_BACK_IDASSERT_LEGACY:
167 case LDAP_BACK_IDASSERT_SELF:
168 /* however, since admin connections are pooled and shared,
169 * only static authzIDs can be native */
170 li->li_idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
177 ber_str2bv( li->li_uri, 0, 0, &sb.sb_uri );
178 sb.sb_version = li->li_version;
179 sb.sb_method = LDAP_AUTH_SIMPLE;
180 BER_BVSTR( &sb.sb_binddn, "" );
182 if ( LDAP_BACK_T_F_DISCOVER( li ) && !LDAP_BACK_T_F( li ) ) {
185 rc = slap_discover_feature( &sb,
186 slap_schema.si_ad_supportedFeatures->ad_cname.bv_val,
187 LDAP_FEATURE_ABSOLUTE_FILTERS );
188 if ( rc == LDAP_COMPARE_TRUE ) {
189 li->li_flags |= LDAP_BACK_F_T_F;
193 if ( LDAP_BACK_CANCEL_DISCOVER( li ) && !LDAP_BACK_CANCEL( li ) ) {
194 rc = slap_discover_feature( &sb,
195 slap_schema.si_ad_supportedExtension->ad_cname.bv_val,
197 if ( rc == LDAP_COMPARE_TRUE ) {
198 li->li_flags |= LDAP_BACK_F_CANCEL_EXOP;
202 li->li_flags |= LDAP_BACK_F_ISOPEN;
208 ldap_back_conn_free( void *v_lc )
210 ldapconn_t *lc = v_lc;
212 if ( lc->lc_ld != NULL ) {
213 ldap_unbind_ext( lc->lc_ld, NULL, NULL );
215 if ( !BER_BVISNULL( &lc->lc_bound_ndn ) ) {
216 ch_free( lc->lc_bound_ndn.bv_val );
218 if ( !BER_BVISNULL( &lc->lc_cred ) ) {
219 memset( lc->lc_cred.bv_val, 0, lc->lc_cred.bv_len );
220 ch_free( lc->lc_cred.bv_val );
222 if ( !BER_BVISNULL( &lc->lc_local_ndn ) ) {
223 ch_free( lc->lc_local_ndn.bv_val );
229 ldap_back_db_destroy(
233 if ( be->be_private ) {
234 ldapinfo_t *li = ( ldapinfo_t * )be->be_private;
236 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
238 if ( li->li_uri != NULL ) {
239 ch_free( li->li_uri );
242 assert( li->li_bvuri != NULL );
243 ber_bvarray_free( li->li_bvuri );
246 if ( !BER_BVISNULL( &li->li_acl_authcID ) ) {
247 ch_free( li->li_acl_authcID.bv_val );
248 BER_BVZERO( &li->li_acl_authcID );
250 if ( !BER_BVISNULL( &li->li_acl_authcDN ) ) {
251 ch_free( li->li_acl_authcDN.bv_val );
252 BER_BVZERO( &li->li_acl_authcDN );
254 if ( !BER_BVISNULL( &li->li_acl_passwd ) ) {
255 ch_free( li->li_acl_passwd.bv_val );
256 BER_BVZERO( &li->li_acl_passwd );
258 if ( !BER_BVISNULL( &li->li_acl_sasl_mech ) ) {
259 ch_free( li->li_acl_sasl_mech.bv_val );
260 BER_BVZERO( &li->li_acl_sasl_mech );
262 if ( !BER_BVISNULL( &li->li_acl_sasl_realm ) ) {
263 ch_free( li->li_acl_sasl_realm.bv_val );
264 BER_BVZERO( &li->li_acl_sasl_realm );
266 if ( !BER_BVISNULL( &li->li_idassert_authcID ) ) {
267 ch_free( li->li_idassert_authcID.bv_val );
268 BER_BVZERO( &li->li_idassert_authcID );
270 if ( !BER_BVISNULL( &li->li_idassert_authcDN ) ) {
271 ch_free( li->li_idassert_authcDN.bv_val );
272 BER_BVZERO( &li->li_idassert_authcDN );
274 if ( !BER_BVISNULL( &li->li_idassert_passwd ) ) {
275 ch_free( li->li_idassert_passwd.bv_val );
276 BER_BVZERO( &li->li_idassert_passwd );
278 if ( !BER_BVISNULL( &li->li_idassert_authzID ) ) {
279 ch_free( li->li_idassert_authzID.bv_val );
280 BER_BVZERO( &li->li_idassert_authzID );
282 if ( !BER_BVISNULL( &li->li_idassert_sasl_mech ) ) {
283 ch_free( li->li_idassert_sasl_mech.bv_val );
284 BER_BVZERO( &li->li_idassert_sasl_mech );
286 if ( !BER_BVISNULL( &li->li_idassert_sasl_realm ) ) {
287 ch_free( li->li_idassert_sasl_realm.bv_val );
288 BER_BVZERO( &li->li_idassert_sasl_realm );
290 if ( li->li_idassert_authz != NULL ) {
291 ber_bvarray_free( li->li_idassert_authz );
292 li->li_idassert_authz = NULL;
294 if ( li->li_conninfo.lai_tree ) {
295 avl_free( li->li_conninfo.lai_tree, ldap_back_conn_free );
297 if ( LDAP_BACK_QUARANTINE( li ) ) {
298 slap_retry_info_destroy( &li->li_quarantine );
299 ldap_pvt_thread_mutex_destroy( &li->li_quarantine_mutex );
302 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
303 ldap_pvt_thread_mutex_destroy( &li->li_conninfo.lai_mutex );
304 ldap_pvt_thread_mutex_destroy( &li->li_uri_mutex );
307 ch_free( be->be_private );
312 #if SLAPD_LDAP == SLAPD_MOD_DYNAMIC
314 /* conditionally define the init_module() function */
315 SLAP_BACKEND_INIT_MODULE( ldap )
317 #endif /* SLAPD_LDAP == SLAPD_MOD_DYNAMIC */