]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/candidates.c
refine fix to ITS#4315; apply it to back-meta as well
[openldap] / servers / slapd / back-meta / candidates.c
index a59606ff702c67b449f02b1385bb7d0fc38f8b51..e78b20602dc8ab5d4054a5467c32e4dcf1cda408 100644 (file)
@@ -1,7 +1,7 @@
 /* $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.
@@ -23,6 +23,7 @@
 #include "portable.h"
 
 #include <stdio.h>
+#include "ac/string.h"
 
 #include "slap.h"
 #include "../back-ldap/back-ldap.h"
 int 
 meta_back_is_candidate(
        struct berval   *nsuffix,
+       int             suffixscope,
        struct berval   *ndn,
        int             scope )
 {
        if ( dnIsSuffix( ndn, nsuffix ) ) {
-               return META_CANDIDATE;
+               switch ( suffixscope ) {
+               case LDAP_SCOPE_SUBTREE:
+               default:
+                       return META_CANDIDATE;
+
+               case LDAP_SCOPE_SUBORDINATE:
+                       if ( ndn->bv_len > nsuffix->bv_len ) {
+                               return META_CANDIDATE;
+                       }
+                       break;
+
+               /* nearly useless; not allowed by config */
+               case LDAP_SCOPE_ONELEVEL:
+                       if ( ndn->bv_len > nsuffix->bv_len ) {
+                               struct berval   rdn = *ndn;
+
+                               rdn.bv_len -= 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 == nsuffix->bv_len ) {
+                               return META_CANDIDATE;
+                       }
+                       break;
+               }
+
+               return META_NOT_CANDIDATE;
        }
 
        if ( scope == LDAP_SCOPE_SUBTREE && dnIsSuffix( nsuffix, ndn ) ) {
@@ -76,28 +110,6 @@ meta_back_is_candidate(
        return META_NOT_CANDIDATE;
 }
 
-#if 0
-/*
- * meta_back_is_candidate_unique
- *
- * checks whether a candidate is unique
- * Note: dn MUST be normalized
- */
-static int
-meta_back_is_candidate_unique(
-       metainfo_t      *mi,
-       struct berval   *ndn )
-{
-       switch ( meta_back_select_unique_candidate( mi, ndn ) ) {
-       case META_TARGET_MULTIPLE:
-       case META_TARGET_NONE:
-               return 0;
-       }
-
-       return 1;
-}
-#endif /* 0 */
-
 /*
  * meta_back_select_unique_candidate
  *
@@ -114,7 +126,9 @@ meta_back_select_unique_candidate(
        int     i, candidate = META_TARGET_NONE;
 
        for ( i = 0; i < mi->mi_ntargets; ++i ) {
-               if ( meta_back_is_candidate( &mi->mi_targets[ i ].mt_nsuffix, ndn, LDAP_SCOPE_BASE ) )
+               if ( meta_back_is_candidate( &mi->mi_targets[ i ].mt_nsuffix,
+                               mi->mi_targets[ i ].mt_scope,
+                               ndn, LDAP_SCOPE_BASE ) )
                {
                        if ( candidate == META_TARGET_NONE ) {
                                candidate = i;
@@ -162,17 +176,18 @@ meta_clear_one_candidate(
        metasingleconn_t        *msc )
 {
        if ( msc->msc_ld ) {
-               ldap_unbind_ext_s( msc->msc_ld, NULL, NULL );
+               ldap_unbind_ext( msc->msc_ld, NULL, NULL );
                msc->msc_ld = NULL;
        }
 
        if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
-               ber_memfree( msc->msc_bound_ndn.bv_val );
+               ber_memfree_x( msc->msc_bound_ndn.bv_val, NULL );
                BER_BVZERO( &msc->msc_bound_ndn );
        }
 
        if ( !BER_BVISNULL( &msc->msc_cred ) ) {
-               ber_memfree( msc->msc_cred.bv_val );
+               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 );
        }