1 /* init.c - initialize ldap backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2005 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 )
44 bi->bi_open = ldap_back_open;
49 bi->bi_db_init = ldap_back_db_init;
50 bi->bi_db_config = ldap_back_db_config;
51 #ifdef LDAP_BACK_BCONFIG
52 bi->bi_db_config = config_generic_wrapper;
53 #endif /* LDAP_BACK_BCONFIG */
54 bi->bi_db_open = ldap_back_db_open;
56 bi->bi_db_destroy = ldap_back_db_destroy;
58 bi->bi_op_bind = ldap_back_bind;
60 bi->bi_op_search = ldap_back_search;
61 bi->bi_op_compare = ldap_back_compare;
62 bi->bi_op_modify = ldap_back_modify;
63 bi->bi_op_modrdn = ldap_back_modrdn;
64 bi->bi_op_add = ldap_back_add;
65 bi->bi_op_delete = ldap_back_delete;
66 bi->bi_op_abandon = 0;
68 bi->bi_extended = ldap_back_extended;
70 bi->bi_chk_referrals = 0;
71 bi->bi_entry_get_rw = ldap_back_entry_get;
73 bi->bi_connection_init = 0;
74 bi->bi_connection_destroy = ldap_back_conn_destroy;
80 #ifdef LDAP_BACK_BCONFIG
81 return ldap_back_init_cf( bi );
87 ldap_back_db_init( Backend *be )
91 li = (struct ldapinfo *)ch_calloc( 1, sizeof( struct ldapinfo ) );
96 BER_BVZERO( &li->acl_authcID );
97 BER_BVZERO( &li->acl_authcDN );
98 BER_BVZERO( &li->acl_passwd );
100 li->acl_authmethod = LDAP_AUTH_SIMPLE;
101 BER_BVZERO( &li->acl_sasl_mech );
103 li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
105 BER_BVZERO( &li->idassert_authcID );
106 BER_BVZERO( &li->idassert_authcDN );
107 BER_BVZERO( &li->idassert_passwd );
109 BER_BVZERO( &li->idassert_authzID );
111 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
112 BER_BVZERO( &li->idassert_sasl_mech );
114 /* by default, use proxyAuthz control on each operation */
115 li->idassert_flags = LDAP_BACK_AUTH_NONE;
117 li->idassert_authz = NULL;
119 /* initialize flags */
120 li->flags = LDAP_BACK_F_CHASE_REFERRALS;
122 /* initialize version */
123 li->version = LDAP_VERSION3;
125 ldap_pvt_thread_mutex_init( &li->conn_mutex );
128 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_NOLASTMOD;
130 be->be_cf_ocs = be->bd_info->bi_cf_ocs;
136 ldap_back_db_open( BackendDB *be )
138 struct ldapinfo *li = (struct ldapinfo *)be->be_private;
140 Debug( LDAP_DEBUG_TRACE,
141 "ldap_back_db_open: URI=%s\n",
142 li->url != NULL ? li->url : "", 0, 0 );
144 /* by default, use proxyAuthz control on each operation */
145 switch ( li->idassert_mode ) {
146 case LDAP_BACK_IDASSERT_LEGACY:
147 case LDAP_BACK_IDASSERT_SELF:
148 /* however, since admin connections are pooled and shared,
149 * only static authzIDs can be native */
150 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
157 #if 0 && defined(SLAPD_MONITOR)
159 /* FIXME: disabled because namingContexts doesn't have
160 * a matching rule, and using an MRA filter doesn't work
161 * because the normalized assertion is compared to the
162 * non-normalized value, which in general differs from
163 * the normalized one. See ITS#3406 */
164 struct berval filter,
165 base = BER_BVC( "cn=Databases," SLAPD_MONITOR );
166 struct berval vals[ 2 ];
169 filter.bv_len = STRLENOF( "(&(namingContexts:distinguishedNameMatch:=)(monitoredInfo=ldap))" )
170 + be->be_nsuffix[ 0 ].bv_len;
171 filter.bv_val = ch_malloc( filter.bv_len + 1 );
172 snprintf( filter.bv_val, filter.bv_len + 1,
173 "(&(namingContexts:distinguishedNameMatch:=%s)(monitoredInfo=ldap))",
174 be->be_nsuffix[ 0 ].bv_val );
176 a.a_desc = slap_schema.si_ad_labeledURI;
177 ber_str2bv( li->url, 0, 0, &vals[ 0 ] );
178 BER_BVZERO( &vals[ 1 ] );
181 if ( monitor_back_register_entry_attrs( NULL, &a, NULL, &base, LDAP_SCOPE_SUBTREE, &filter ) ) {
185 ch_free( filter.bv_val );
187 #endif /* SLAPD_MONITOR */
189 if ( li->flags & LDAP_BACK_F_SUPPORT_T_F_DISCOVER ) {
192 li->flags &= ~LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
194 rc = slap_discover_feature( li->url, li->version,
195 slap_schema.si_ad_supportedFeatures->ad_cname.bv_val,
196 LDAP_FEATURE_ABSOLUTE_FILTERS );
197 if ( rc == LDAP_COMPARE_TRUE ) {
198 li->flags |= LDAP_BACK_F_SUPPORT_T_F;
206 ldap_back_conn_free( void *v_lc )
208 struct ldapconn *lc = v_lc;
210 ldap_unbind_ext_s( lc->lc_ld, NULL, NULL );
211 if ( !BER_BVISNULL( &lc->lc_bound_ndn ) ) {
212 ch_free( lc->lc_bound_ndn.bv_val );
214 if ( !BER_BVISNULL( &lc->lc_cred ) ) {
215 memset( lc->lc_cred.bv_val, 0, lc->lc_cred.bv_len );
216 ch_free( lc->lc_cred.bv_val );
218 if ( !BER_BVISNULL( &lc->lc_local_ndn ) ) {
219 ch_free( lc->lc_local_ndn.bv_val );
221 ldap_pvt_thread_mutex_destroy( &lc->lc_mutex );
226 ldap_back_db_destroy(
232 if ( be->be_private ) {
233 li = ( struct ldapinfo * )be->be_private;
235 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
237 if ( li->url != NULL ) {
242 ldap_free_urldesc( li->lud );
245 if ( !BER_BVISNULL( &li->acl_authcID ) ) {
246 ch_free( li->acl_authcID.bv_val );
247 BER_BVZERO( &li->acl_authcID );
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 if ( !BER_BVISNULL( &li->acl_sasl_mech ) ) {
258 ch_free( li->acl_sasl_mech.bv_val );
259 BER_BVZERO( &li->acl_sasl_mech );
261 if ( !BER_BVISNULL( &li->acl_sasl_realm ) ) {
262 ch_free( li->acl_sasl_realm.bv_val );
263 BER_BVZERO( &li->acl_sasl_realm );
265 if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
266 ch_free( li->idassert_authcID.bv_val );
267 BER_BVZERO( &li->idassert_authcID );
269 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
270 ch_free( li->idassert_authcDN.bv_val );
271 BER_BVZERO( &li->idassert_authcDN );
273 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
274 ch_free( li->idassert_passwd.bv_val );
275 BER_BVZERO( &li->idassert_passwd );
277 if ( !BER_BVISNULL( &li->idassert_authzID ) ) {
278 ch_free( li->idassert_authzID.bv_val );
279 BER_BVZERO( &li->idassert_authzID );
281 if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
282 ch_free( li->idassert_sasl_mech.bv_val );
283 BER_BVZERO( &li->idassert_sasl_mech );
285 if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
286 ch_free( li->idassert_sasl_realm.bv_val );
287 BER_BVZERO( &li->idassert_sasl_realm );
289 if ( li->conntree ) {
290 avl_free( li->conntree, ldap_back_conn_free );
293 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
294 ldap_pvt_thread_mutex_destroy( &li->conn_mutex );
297 ch_free( be->be_private );
302 #if SLAPD_LDAP == SLAPD_MOD_DYNAMIC
304 /* conditionally define the init_module() function */
305 SLAP_BACKEND_INIT_MODULE( ldap )
307 #endif /* SLAPD_LDAP == SLAPD_MOD_DYNAMIC */