[Date Prev][Date Next] [Chronological] [Thread] [Top]

Yet another backport to suggest



Dear Howard,

Let me suggest yet another backport on the 2.3 branch (specifically on
2.3.37) from the Head, this time related to the entryDN attributes
indexing. Once again you are the original author of the commit that was
backported, it seems my contributions relate to backport your most awaited
features - am I a serial backporter ? :-)

I hope it will be interesting enough a feature to be included.

Yours sincerely,


Benoît Donnette - Expert TM2L/OSSA - www.08000linux.com
LINAGORA - 27 rue de Berri - 75008 PARIS
LINAGORA recrute : http://www.linagora.com/societe/nous_rejoindre/
diff -Naur openldap-2.3.37/servers/slapd/back-bdb/dn2id.c openldap-2.3.37_entryDn_indexed/servers/slapd/back-bdb/dn2id.c
--- openldap-2.3.37/servers/slapd/back-bdb/dn2id.c	2007-01-02 22:44:00.000000000 +0100
+++ openldap-2.3.37_entryDn_indexed/servers/slapd/back-bdb/dn2id.c	2007-07-26 10:13:51.000000000 +0200
@@ -332,7 +332,8 @@
 int
 bdb_dn2idl(
 	Operation *op,
-	Entry *e,
+	struct berval *ndn,
+	EntryInfo *ei,
 	ID *ids,
 	ID *stack )
 {
@@ -344,22 +345,23 @@
 		? DN_ONE_PREFIX : DN_SUBTREE_PREFIX;
 
 	Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl(\"%s\")\n",
-		e->e_nname.bv_val, 0, 0 );
+		ndn->bv_val, 0, 0 );
 
 #ifndef	BDB_MULTIPLE_SUFFIXES
-	if ( prefix == DN_SUBTREE_PREFIX && BEI(e)->bei_parent->bei_id == 0 ) {
+	if ( prefix == DN_SUBTREE_PREFIX && ei->bei_parent->bei_id == 0 ) {
 		BDB_IDL_ALL(bdb, ids);
 		return 0;
 	}
 #endif
 
 	DBTzero( &key );
-	key.size = e->e_nname.bv_len + 2;
+	key.size = ndn->bv_len + 2;
 	key.ulen = key.size;
 	key.flags = DB_DBT_USERMEM;
 	key.data = op->o_tmpalloc( key.size, op->o_tmpmemctx );
 	((char *)key.data)[0] = prefix;
-	AC_MEMCPY( &((char *)key.data)[1], e->e_nname.bv_val, key.size - 1 );
+	AC_MEMCPY( &((char *)key.data)[1], ndn->bv_val, key.size - 1 );
+
 
 	BDB_IDL_ZERO( ids );
 	rc = bdb_idl_fetch_key( op->o_bd, db, NULL, &key, ids, NULL, 0 );
@@ -1060,7 +1062,8 @@
 int
 hdb_dn2idl(
 	Operation	*op,
-	Entry		*e,
+	struct berval *ndn,
+	EntryInfo       *ei,
 	ID *ids,
 	ID *stack )
 {
@@ -1068,20 +1071,23 @@
 	struct dn2id_cookie cx;
 
 	Debug( LDAP_DEBUG_TRACE, "=> hdb_dn2idl(\"%s\")\n",
-		e->e_nname.bv_val, 0, 0 );
+		ndn->bv_val, 0, 0 );
 
 #ifndef BDB_MULTIPLE_SUFFIXES
 	if ( op->ors_scope != LDAP_SCOPE_ONELEVEL && 
-		BEI(e)->bei_parent->bei_id == 0 )
+		ei->bei_parent->bei_id == 0 )
+
 	{
 		BDB_IDL_ALL( bdb, ids );
 		return 0;
 	}
 #endif
 
-	cx.id = e->e_id;
+	cx.id = ei->bei_id;
+
 	BDB_ID2DISK( cx.id, &cx.nid );
-	cx.ei = e->e_id ? BEI(e) : &bdb->bi_cache.c_dntree;
+	cx.ei = ei;
+
 	cx.bdb = bdb;
 	cx.db = cx.bdb->bi_dn2id->bdi_db;
 	cx.prefix = (op->ors_scope == LDAP_SCOPE_ONELEVEL) ?
@@ -1117,7 +1123,7 @@
 		cx.key.data = ptr;
 		cx.key.size = sizeof(ID)+1;
 		*ptr = cx.prefix;
-		cx.id = e->e_id;
+		cx.id = ei->bei_id;
 		bdb_idl_cache_put( cx.bdb, cx.db, &cx.key, cx.ids, cx.rc );
 	}
 
diff -Naur openldap-2.3.37/servers/slapd/back-bdb/filterindex.c openldap-2.3.37_entryDn_indexed/servers/slapd/back-bdb/filterindex.c
--- openldap-2.3.37/servers/slapd/back-bdb/filterindex.c	2007-01-02 22:44:00.000000000 +0100
+++ openldap-2.3.37_entryDn_indexed/servers/slapd/back-bdb/filterindex.c	2007-07-26 10:12:44.000000000 +0200
@@ -60,7 +60,6 @@
 	ID *tmp,
 	ID *stack );
 
-#ifdef LDAP_COMP_MATCH
 static int
 ext_candidates(
         Operation *op,
@@ -69,6 +68,7 @@
         ID *tmp,
         ID *stack);
 
+#ifdef LDAP_COMP_MATCH
 static int
 comp_candidates (
 	Operation *op,
@@ -189,12 +189,10 @@
 		rc = list_candidates( op, 
 			f->f_or, LDAP_FILTER_OR, ids, tmp, stack );
 		break;
-#ifdef LDAP_COMP_MATCH
 	case LDAP_FILTER_EXT:
                 Debug( LDAP_DEBUG_FILTER, "\tEXT\n", 0, 0, 0 );
                 rc = ext_candidates( op, f->f_mra, ids, tmp, stack );
                 break;
-#endif
 	default:
 		Debug( LDAP_DEBUG_FILTER, "\tUNKNOWN %lu\n",
 			(unsigned long) f->f_choice, 0, 0 );
@@ -460,6 +458,7 @@
 
 	return( rc );
 }
+#endif
 
 static int
 ext_candidates(
@@ -469,19 +468,75 @@
         ID *tmp,
         ID *stack)
 {
+	struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
+
+#ifdef LDAP_COMP_MATCH
 	/*
 	 * Currently Only Component Indexing for componentFilterMatch is supported
 	 * Indexing for an extensible filter is not supported yet
 	 */
-	if ( !mra->ma_cf ) {
-		struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
-		BDB_IDL_ALL( bdb, ids );
-		return 0;
+	if ( mra->ma_cf ) {
+		return comp_candidates ( op, locker, mra, mra->ma_cf, ids, tmp, stack);
+	}
+#endif
+	if ( mra->ma_desc == slap_schema.si_ad_entryDN ) {
+		int rc;
+		EntryInfo *ei;
+
+		BDB_IDL_ZERO( ids );
+		if ( mra->ma_rule == slap_schema.si_mr_distinguishedNameMatch ) {
+			ei = NULL;
+			rc = bdb_cache_find_ndn( op, NULL, &mra->ma_value, &ei );
+			if ( rc == LDAP_SUCCESS )
+				bdb_idl_insert( ids, ei->bei_id );
+			if ( ei )
+				bdb_cache_entryinfo_unlock( ei );
+			return 0;
+		} else if ( mra->ma_rule && mra->ma_rule->smr_match ==
+			dnRelativeMatch && dnIsSuffix( &mra->ma_value,
+				op->o_bd->be_nsuffix )) {
+			int scope;
+			if ( mra->ma_rule == slap_schema.si_mr_dnSuperiorMatch ) {
+				struct berval pdn;
+				ei = NULL;
+				dnParent( &mra->ma_value, &pdn );
+				bdb_cache_find_ndn( op, NULL, &pdn, &ei );
+				if ( ei ) {
+					bdb_cache_entryinfo_unlock( ei );
+					while ( ei && ei->bei_id ) {
+						bdb_idl_insert( ids, ei->bei_id );
+						ei = ei->bei_parent;
+					}
+				}
+				return 0;
+			}
+			if ( mra->ma_rule == slap_schema.si_mr_dnSubtreeMatch )
+				scope = LDAP_SCOPE_SUBTREE;
+			else if ( mra->ma_rule == slap_schema.si_mr_dnOneLevelMatch )
+				scope = LDAP_SCOPE_ONELEVEL;
+			else if ( mra->ma_rule == slap_schema.si_mr_dnSubordinateMatch )
+				scope = LDAP_SCOPE_SUBORDINATE;
+			else
+				scope = LDAP_SCOPE_BASE;
+			if ( scope > LDAP_SCOPE_BASE ) {
+				ei = NULL;
+				rc = bdb_cache_find_ndn( op, NULL, &mra->ma_value, &ei );
+				if ( ei )
+					bdb_cache_entryinfo_unlock( ei );
+				if ( rc == LDAP_SUCCESS ) {
+					int sc = op->ors_scope;
+					op->ors_scope = scope;
+					rc = bdb_dn2idl( op, &mra->ma_value, ei, ids,
+						stack );
+				}
+				return 0;
+			}
+		}
 	}
 
-	return comp_candidates ( op, mra, mra->ma_cf, ids, tmp, stack);
+	BDB_IDL_ALL( bdb, ids );
+	return 0;
 }
-#endif
 
 static int
 list_candidates(
diff -Naur openldap-2.3.37/servers/slapd/back-bdb/proto-bdb.h openldap-2.3.37_entryDn_indexed/servers/slapd/back-bdb/proto-bdb.h
--- openldap-2.3.37/servers/slapd/back-bdb/proto-bdb.h	2007-01-25 13:42:38.000000000 +0100
+++ openldap-2.3.37_entryDn_indexed/servers/slapd/back-bdb/proto-bdb.h	2007-07-26 10:12:49.000000000 +0200
@@ -120,7 +120,8 @@
 
 int bdb_dn2idl(
 	Operation *op,
-	Entry *e,
+        struct berval *ndn,
+        EntryInfo *ei,
 	ID *ids,
 	ID *stack );
 
diff -Naur openldap-2.3.37/servers/slapd/back-bdb/search.c openldap-2.3.37_entryDn_indexed/servers/slapd/back-bdb/search.c
--- openldap-2.3.37/servers/slapd/back-bdb/search.c	2007-01-02 22:44:00.000000000 +0100
+++ openldap-2.3.37_entryDn_indexed/servers/slapd/back-bdb/search.c	2007-07-26 10:12:54.000000000 +0200
@@ -207,7 +207,7 @@
 		 * to the cumulative list of candidates.
 		 */
 		BDB_IDL_CPY( curscop, aliases );
-		rs->sr_err = bdb_dn2idl( op, e, subscop,
+		rs->sr_err = bdb_dn2idl( op, &e->e_nname, BEI(e), subscop,
 			subscop2+BDB_IDL_DB_SIZE );
 		if (first) {
 			first = 0;
@@ -317,7 +317,7 @@
 	ID		scopes[BDB_IDL_DB_SIZE];
 	Entry		*e = NULL, base, e_root = {0};
 	Entry		*matched = NULL;
-	EntryInfo	*ei, ei_root = {0};
+	EntryInfo       *ei;
 	struct berval	realbase = BER_BVNULL;
 #ifdef SLAP_ACL_HONOR_DISCLOSE
 	slap_mask_t	mask;
@@ -356,13 +356,11 @@
 
 	if ( op->o_req_ndn.bv_len == 0 ) {
 		/* DIT root special case */
-		ei_root.bei_e = &e_root;
-		ei_root.bei_parent = &ei_root;
-		e_root.e_private = &ei_root;
+		ei = &bdb->bi_cache.c_dntree;
+		e_root.e_private = ei;
 		e_root.e_id = 0;
 		BER_BVSTR( &e_root.e_nname, "" );
 		BER_BVSTR( &e_root.e_name, "" );
-		ei = &ei_root;
 		rs->sr_err = LDAP_SUCCESS;
 	} else {
 		if ( op->ors_deref & LDAP_DEREF_FINDING ) {
@@ -1116,7 +1114,7 @@
 	if( op->ors_deref & LDAP_DEREF_SEARCHING ) {
 		rc = search_aliases( op, rs, e, locker, ids, scopes, stack );
 	} else {
-		rc = bdb_dn2idl( op, e, ids, stack );
+		rc = bdb_dn2idl( op, &e->e_nname, BEI(e), ids, stack );
 	}
 
 	if ( rc == LDAP_SUCCESS ) {