/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1999-2005 The OpenLDAP Foundation.
+ * Copyright 1999-2006 The OpenLDAP Foundation.
* Portions Copyright 2001-2003 Pierangelo Masarati.
* Portions Copyright 1999-2003 Howard Chu.
* All rights reserved.
#include "portable.h"
#include <stdio.h>
+#include "ac/string.h"
#include "slap.h"
#include "../back-ldap/back-ldap.h"
* A possible extension will include the handling of multiple suffixes
*/
-static int
-meta_back_is_candidate_unique(
- struct metainfo *li,
- struct berval *ndn
-);
/*
* returns 1 if suffix is candidate for dn, otherwise 0
*/
int
meta_back_is_candidate(
- struct berval *nsuffix,
- struct berval *ndn,
- int scope
-)
+ metatarget_t *mt,
+ struct berval *ndn,
+ int scope )
{
- if ( dnIsSuffix( ndn, nsuffix ) ) {
- return META_CANDIDATE;
+ if ( dnIsSuffix( ndn, &mt->mt_nsuffix ) ) {
+ if ( mt->mt_subtree_exclude ) {
+ int i;
+
+ for ( i = 0; !BER_BVISNULL( &mt->mt_subtree_exclude[ i ] ); i++ ) {
+ if ( dnIsSuffix( ndn, &mt->mt_subtree_exclude[ i ] ) ) {
+ return META_NOT_CANDIDATE;
+ }
+ }
+ }
+
+ switch ( mt->mt_scope ) {
+ case LDAP_SCOPE_SUBTREE:
+ default:
+ return META_CANDIDATE;
+
+ case LDAP_SCOPE_SUBORDINATE:
+ if ( ndn->bv_len > mt->mt_nsuffix.bv_len ) {
+ return META_CANDIDATE;
+ }
+ break;
+
+ /* nearly useless; not allowed by config */
+ case LDAP_SCOPE_ONELEVEL:
+ if ( ndn->bv_len > mt->mt_nsuffix.bv_len ) {
+ struct berval rdn = *ndn;
+
+ rdn.bv_len -= mt->mt_nsuffix.bv_len
+ + STRLENOF( "," );
+ if ( dnIsOneLevelRDN( &rdn ) ) {
+ return META_CANDIDATE;
+ }
+ }
+ break;
+
+ /* nearly useless; not allowed by config */
+ case LDAP_SCOPE_BASE:
+ if ( ndn->bv_len == mt->mt_nsuffix.bv_len ) {
+ return META_CANDIDATE;
+ }
+ break;
+ }
+
+ return META_NOT_CANDIDATE;
}
- if ( scope == LDAP_SCOPE_SUBTREE && dnIsSuffix( nsuffix, ndn ) ) {
+ if ( scope == LDAP_SCOPE_SUBTREE && dnIsSuffix( &mt->mt_nsuffix, ndn ) ) {
/*
* suffix longer than dn, but common part matches
*/
return META_NOT_CANDIDATE;
}
-/*
- * meta_back_is_candidate_unique
- *
- * checks whether a candidate is unique
- * Note: dn MUST be normalized
- */
-static int
-meta_back_is_candidate_unique(
- struct metainfo *li,
- struct berval *ndn
-)
-{
- switch ( meta_back_select_unique_candidate( li, ndn ) ) {
- case META_TARGET_MULTIPLE:
- case META_TARGET_NONE:
- return 0;
- }
-
- return 1;
-}
-
/*
* meta_back_select_unique_candidate
*
- * returns the index of the candidate in case it is unique, otherwise -1
- * Note: dn MUST be normalized.
- * Note: if defined, the default candidate is returned in case of no match.
+ * returns the index of the candidate in case it is unique, otherwise
+ * META_TARGET_NONE if none matches, or
+ * META_TARGET_MULTIPLE if more than one matches
+ * Note: ndn MUST be normalized.
*/
int
meta_back_select_unique_candidate(
- struct metainfo *li,
- struct berval *ndn
-)
+ metainfo_t *mi,
+ struct berval *ndn )
{
int i, candidate = META_TARGET_NONE;
- for ( i = 0; i < li->mi_ntargets; ++i ) {
- if ( meta_back_is_candidate( &li->mi_targets[ i ]->mt_nsuffix, ndn, LDAP_SCOPE_BASE ) )
- {
+ for ( i = 0; i < mi->mi_ntargets; i++ ) {
+ metatarget_t *mt = mi->mi_targets[ i ];
+
+ if ( meta_back_is_candidate( mt, ndn, LDAP_SCOPE_BASE ) ) {
if ( candidate == META_TARGET_NONE ) {
candidate = i;
*/
int
meta_clear_unused_candidates(
- Operation *op,
- struct metaconn *lc,
- int candidate
-)
+ Operation *op,
+ int candidate )
{
- struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
+ metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
int i;
SlapReply *candidates = meta_back_candidates_get( op );
- for ( i = 0; i < li->mi_ntargets; ++i ) {
+ for ( i = 0; i < mi->mi_ntargets; ++i ) {
if ( i == candidate ) {
continue;
}
- candidates[ i ].sr_tag = META_NOT_CANDIDATE;
+ META_CANDIDATE_RESET( &candidates[ i ] );
}
return 0;
*/
int
meta_clear_one_candidate(
- struct metasingleconn *lsc
-)
+ Operation *op,
+ metaconn_t *mc,
+ int candidate )
{
- if ( lsc->msc_ld ) {
- ldap_unbind_ext_s( lsc->msc_ld, NULL, NULL );
- lsc->msc_ld = NULL;
+ metasingleconn_t *msc = &mc->mc_conns[ candidate ];
+
+ if ( msc->msc_ld != NULL ) {
+
+#ifdef DEBUG_205
+ char buf[ BUFSIZ ];
+
+ snprintf( buf, sizeof( buf ), "meta_clear_one_candidate ldap_unbind_ext[%d] mc=%p ld=%p",
+ candidate, (void *)mc, (void *)msc->msc_ld );
+ Debug( LDAP_DEBUG_ANY, "### %s %s\n",
+ op ? op->o_log_prefix : "", buf, 0 );
+#endif /* DEBUG_205 */
+
+ ldap_unbind_ext( msc->msc_ld, NULL, NULL );
+ msc->msc_ld = NULL;
}
- if ( !BER_BVISNULL( &lsc->msc_bound_ndn ) ) {
- ber_memfree( lsc->msc_bound_ndn.bv_val );
- BER_BVZERO( &lsc->msc_bound_ndn );
+ if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
+ ber_memfree_x( msc->msc_bound_ndn.bv_val, NULL );
+ BER_BVZERO( &msc->msc_bound_ndn );
}
- if ( !BER_BVISNULL( &lsc->msc_cred ) ) {
- ber_memfree( lsc->msc_cred.bv_val );
- BER_BVZERO( &lsc->msc_cred );
+ if ( !BER_BVISNULL( &msc->msc_cred ) ) {
+ memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len );
+ ber_memfree_x( msc->msc_cred.bv_val, NULL );
+ BER_BVZERO( &msc->msc_cred );
}
+ msc->msc_mscflags = 0;
+
return 0;
}