From 9eb4e7cc27b14c99ac2ee9f3df672533959a95d9 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Wed, 14 Mar 2007 20:01:57 +0000
Subject: [PATCH] Update the schema and memory backends so that they will properly set the matched DN field in the response if the backend doesn't have the entry specified as the search base DN but does have an ancestor for that entry.

---
 opends/src/server/org/opends/server/backends/MemoryBackend.java |   34 ++++++++++++++++++++++++----------
 1 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/opends/src/server/org/opends/server/backends/MemoryBackend.java b/opends/src/server/org/opends/server/backends/MemoryBackend.java
index 63eab74..07c7345 100644
--- a/opends/src/server/org/opends/server/backends/MemoryBackend.java
+++ b/opends/src/server/org/opends/server/backends/MemoryBackend.java
@@ -551,21 +551,35 @@
     SearchFilter filter = searchOperation.getFilter();
 
 
+    // Make sure the base entry exists if it's supposed to be in this backend.
+    Entry baseEntry = entryMap.get(baseDN);
+    if ((baseEntry == null) && handlesEntry(baseDN))
+    {
+      DN matchedDN = baseDN.getParentDNInSuffix();
+      while (matchedDN != null)
+      {
+        if (entryMap.containsKey(matchedDN))
+        {
+          break;
+        }
+
+        matchedDN = matchedDN.getParentDNInSuffix();
+      }
+
+      int    msgID   = MSGID_MEMORYBACKEND_ENTRY_DOESNT_EXIST;
+      String message = getMessage(msgID, String.valueOf(baseDN));
+      throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, message, msgID,
+                                   matchedDN, null);
+    }
+
+
     // If it's a base-level search, then just get that entry and return it if it
     // matches the filter.
     if (scope == SearchScope.BASE_OBJECT)
     {
-      Entry entry = entryMap.get(baseDN);
-      if (entry == null)
+      if (filter.matchesEntry(baseEntry))
       {
-        int    msgID   = MSGID_MEMORYBACKEND_ENTRY_DOESNT_EXIST;
-        String message = getMessage(msgID, String.valueOf(baseDN));
-        throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, message, msgID);
-      }
-
-      if (filter.matchesEntry(entry))
-      {
-        searchOperation.returnEntry(entry, new LinkedList<Control>());
+        searchOperation.returnEntry(baseEntry, new LinkedList<Control>());
       }
     }
     else

--
Gitblit v1.10.0