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 bi->bi_db_open = ldap_back_db_open;
53 bi->bi_db_destroy = ldap_back_db_destroy;
55 bi->bi_op_bind = ldap_back_bind;
57 bi->bi_op_search = ldap_back_search;
58 bi->bi_op_compare = ldap_back_compare;
59 bi->bi_op_modify = ldap_back_modify;
60 bi->bi_op_modrdn = ldap_back_modrdn;
61 bi->bi_op_add = ldap_back_add;
62 bi->bi_op_delete = ldap_back_delete;
63 bi->bi_op_abandon = 0;
65 bi->bi_extended = ldap_back_extended;
67 bi->bi_chk_referrals = 0;
68 bi->bi_entry_get_rw = ldap_back_entry_get;
70 bi->bi_connection_init = 0;
71 bi->bi_connection_destroy = ldap_back_conn_destroy;
73 if ( chain_init( ) ) {
81 ldap_back_db_init( Backend *be )
85 li = (struct ldapinfo *)ch_calloc( 1, sizeof( struct ldapinfo ) );
90 BER_BVZERO( &li->acl_authcDN );
91 BER_BVZERO( &li->acl_passwd );
93 #ifdef LDAP_BACK_PROXY_AUTHZ
94 li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
96 BER_BVZERO( &li->idassert_authcID );
97 BER_BVZERO( &li->idassert_authcDN );
98 BER_BVZERO( &li->idassert_passwd );
100 BER_BVZERO( &li->idassert_authzID );
101 li->idassert_authz = NULL;
103 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
104 li->idassert_sasl_flags = LDAP_SASL_QUIET;
105 BER_BVZERO( &li->idassert_sasl_mech );
106 BER_BVZERO( &li->idassert_sasl_realm );
108 li->idassert_ppolicy = 0;
110 /* by default, use proxyAuthz control on each operation */
111 li->idassert_flags = LDAP_BACK_AUTH_NONE;
112 #endif /* LDAP_BACK_PROXY_AUTHZ */
114 ldap_pvt_thread_mutex_init( &li->conn_mutex );
117 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_NOLASTMOD;
123 ldap_back_db_open( BackendDB *be )
125 struct ldapinfo *li = (struct ldapinfo *)be->be_private;
127 Debug( LDAP_DEBUG_TRACE,
128 "ldap_back_db_open: URI=%s\n",
129 li->url != NULL ? li->url : "", 0, 0 );
131 #ifdef LDAP_BACK_PROXY_AUTHZ
132 /* by default, use proxyAuthz control on each operation */
133 switch ( li->idassert_mode ) {
134 case LDAP_BACK_IDASSERT_LEGACY:
135 case LDAP_BACK_IDASSERT_SELF:
136 /* however, since admin connections are pooled and shared,
137 * only static authzIDs can be native */
138 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
144 #endif /* LDAP_BACK_PROXY_AUTHZ */
146 #if 0 && defined(SLAPD_MONITOR)
148 struct berval filter,
149 base = BER_BVC( "cn=Databases,cn=Monitor" );
150 struct berval vals[ 2 ];
153 filter.bv_len = STRLENOF( "(&(namingContexts:distinguishedNameMatch:=)(monitoredInfo=ldap))" )
154 + be->be_nsuffix[ 0 ].bv_len;
155 filter.bv_val = ch_malloc( filter.bv_len + 1 );
156 snprintf( filter.bv_val, filter.bv_len + 1,
157 "(&(namingContexts:distinguishedNameMatch:=%s)(monitoredInfo=ldap))",
158 be->be_nsuffix[ 0 ].bv_val );
160 a.a_desc = slap_schema.si_ad_labeledURI;
161 ber_str2bv( li->url, 0, 0, &vals[ 0 ] );
162 BER_BVZERO( &vals[ 1 ] );
165 if ( monitor_back_register_entry_attrs( NULL, &a, NULL, &base, LDAP_SCOPE_SUBTREE, &filter ) ) {
169 ch_free( filter.bv_val );
171 #endif /* SLAPD_MONITOR */
177 ldap_back_conn_free( void *v_lc )
179 struct ldapconn *lc = v_lc;
181 ldap_unbind_ext_s( lc->lc_ld, NULL, NULL );
182 if ( !BER_BVISNULL( &lc->lc_bound_ndn ) ) {
183 ch_free( lc->lc_bound_ndn.bv_val );
185 if ( !BER_BVISNULL( &lc->lc_cred ) ) {
186 memset( lc->lc_cred.bv_val, 0, lc->lc_cred.bv_len );
187 ch_free( lc->lc_cred.bv_val );
189 if ( !BER_BVISNULL( &lc->lc_local_ndn ) ) {
190 ch_free( lc->lc_local_ndn.bv_val );
192 ldap_pvt_thread_mutex_destroy( &lc->lc_mutex );
197 ldap_back_db_destroy(
203 if ( be->be_private ) {
204 li = ( struct ldapinfo * )be->be_private;
206 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
208 if ( li->url != NULL ) {
213 ldap_free_urldesc( li->lud );
216 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
217 ch_free( li->acl_authcDN.bv_val );
218 BER_BVZERO( &li->acl_authcDN );
220 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
221 ch_free( li->acl_passwd.bv_val );
222 BER_BVZERO( &li->acl_passwd );
224 #ifdef LDAP_BACK_PROXY_AUTHZ
225 if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
226 ch_free( li->idassert_authcID.bv_val );
227 BER_BVZERO( &li->idassert_authcID );
229 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
230 ch_free( li->idassert_authcDN.bv_val );
231 BER_BVZERO( &li->idassert_authcDN );
233 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
234 ch_free( li->idassert_passwd.bv_val );
235 BER_BVZERO( &li->idassert_passwd );
237 if ( !BER_BVISNULL( &li->idassert_authzID ) ) {
238 ch_free( li->idassert_authzID.bv_val );
239 BER_BVZERO( &li->idassert_authzID );
241 if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
242 ch_free( li->idassert_sasl_mech.bv_val );
243 BER_BVZERO( &li->idassert_sasl_mech );
245 if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
246 ch_free( li->idassert_sasl_realm.bv_val );
247 BER_BVZERO( &li->idassert_sasl_realm );
249 #endif /* LDAP_BACK_PROXY_AUTHZ */
250 if ( li->conntree ) {
251 avl_free( li->conntree, ldap_back_conn_free );
254 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
255 ldap_pvt_thread_mutex_destroy( &li->conn_mutex );
258 ch_free( be->be_private );
263 #if SLAPD_LDAP == SLAPD_MOD_DYNAMIC
265 /* conditionally define the init_module() function */
266 SLAP_BACKEND_INIT_MODULE( ldap )
268 #endif /* SLAPD_LDAP == SLAPD_MOD_DYNAMIC */