From 06432bc393ff2f8c824c14c56cec6808af3d5137 Mon Sep 17 00:00:00 2001
From: pgamba <pgamba@localhost>
Date: Mon, 19 Oct 2009 19:46:52 +0000
Subject: [PATCH] Fix#4296 ECL root DSE entry may contain changelog attribute containing ECL base DN

---
 opends/src/server/org/opends/server/replication/server/ReplicationServer.java                         |   24 ++++--
 opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ExternalChangeLogTest.java    |    2 
 opends/src/server/org/opends/server/replication/common/FirstChangeNumberVirtualAttributeProvider.java |    5 +
 opends/src/server/org/opends/server/replication/common/LastChangeNumberVirtualAttributeProvider.java  |    5 +
 opends/resource/schema/00-core.ldif                                                                   |    7 +
 opends/src/server/org/opends/server/replication/common/ChangelogBaseDNVirtualAttributeProvider.java   |  172 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 207 insertions(+), 8 deletions(-)

diff --git a/opends/resource/schema/00-core.ldif b/opends/resource/schema/00-core.ldif
index 06661fd..606a8ad 100644
--- a/opends/resource/schema/00-core.ldif
+++ b/opends/resource/schema/00-core.ldif
@@ -456,6 +456,13 @@
   SYNTAX 1.3.6.1.4.1.1466.115.121.1.27
   SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation
   X-ORIGIN 'draft-ietf-boreham-numsubordinates' )
+attributeTypes: ( 2.16.840.1.113730.3.1.35 NAME 'changelog' 
+  DESC 'the distinguished name of the entry which contains
+  the set of entries comprising this server's changelog'
+  EQUALITY distinguishedNameMatch
+  SYNTAX 1.3.6.1.4.1.1466.115.121.1.12
+  SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation
+  X-ORIGIN 'draft-good-ldap-changelog' )
 objectClasses: ( 2.5.6.0 NAME 'top' ABSTRACT MUST objectClass
   X-ORIGIN 'RFC 4512' )
 objectClasses: ( 2.5.6.1 NAME 'alias' SUP top STRUCTURAL MUST aliasedObjectName
diff --git a/opends/src/server/org/opends/server/replication/common/ChangelogBaseDNVirtualAttributeProvider.java b/opends/src/server/org/opends/server/replication/common/ChangelogBaseDNVirtualAttributeProvider.java
new file mode 100644
index 0000000..1f899e6
--- /dev/null
+++ b/opends/src/server/org/opends/server/replication/common/ChangelogBaseDNVirtualAttributeProvider.java
@@ -0,0 +1,172 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Copyright 2009 Sun Microsystems, Inc.
+ */
+package org.opends.server.replication.common;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.opends.messages.Message;
+import org.opends.server.admin.server.ConfigurationChangeListener;
+import org.opends.server.admin.std.server.UserDefinedVirtualAttributeCfg;
+import org.opends.server.api.VirtualAttributeProvider;
+import org.opends.server.config.ConfigException;
+import org.opends.server.core.SearchOperation;
+import org.opends.server.types.AttributeValue;
+import org.opends.server.types.AttributeValues;
+import org.opends.server.types.ByteString;
+import org.opends.server.types.ConfigChangeResult;
+import org.opends.server.types.Entry;
+import org.opends.server.types.InitializationException;
+import org.opends.server.types.ResultCode;
+import org.opends.server.types.VirtualAttributeRule;
+import org.opends.server.util.ServerConstants;
+
+
+
+/**
+ * This class implements a virtual attribute provider that specifies the
+ * changelog attribute of the root DSE entry that contain the baseDn of the ECL.
+ */
+public class ChangelogBaseDNVirtualAttributeProvider
+       extends VirtualAttributeProvider<UserDefinedVirtualAttributeCfg>
+       implements ConfigurationChangeListener<UserDefinedVirtualAttributeCfg>
+{
+  /**
+   * Creates a new instance of this member virtual attribute provider.
+   */
+  public ChangelogBaseDNVirtualAttributeProvider()
+  {
+    super();
+
+    // All initialization should be performed in the
+    // initializeVirtualAttributeProvider method.
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override()
+  public void initializeVirtualAttributeProvider(
+                            UserDefinedVirtualAttributeCfg configuration)
+         throws ConfigException, InitializationException
+  {
+    // No initialization required
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override()
+  public void finalizeVirtualAttributeProvider()
+  {
+    //
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override()
+  public boolean isMultiValued()
+  {
+    return false;
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override()
+  public Set<AttributeValue> getValues(Entry entry,VirtualAttributeRule rule)
+  {
+    Set<AttributeValue> values = new HashSet<AttributeValue>();
+    AttributeValue value =
+      AttributeValues.create(
+          ByteString.valueOf(ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT),
+          ByteString.valueOf(ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT));
+    values=Collections.singleton(value);
+    return values;
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override()
+  public boolean isSearchable(VirtualAttributeRule rule,
+                              SearchOperation searchOperation)
+  {
+    // We will not allow searches based only on user-defined virtual attributes.
+    return false;
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override()
+  public void processSearch(VirtualAttributeRule rule,
+                            SearchOperation searchOperation)
+  {
+    searchOperation.setResultCode(ResultCode.UNWILLING_TO_PERFORM);
+    return;
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isConfigurationChangeAcceptable(
+                      UserDefinedVirtualAttributeCfg configuration,
+                      List<Message> unacceptableReasons)
+  {
+    return false;
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public ConfigChangeResult applyConfigurationChange(
+                                 UserDefinedVirtualAttributeCfg configuration)
+  {
+    return new ConfigChangeResult(ResultCode.OTHER, false);
+  }
+}
+
diff --git a/opends/src/server/org/opends/server/replication/common/FirstChangeNumberVirtualAttributeProvider.java b/opends/src/server/org/opends/server/replication/common/FirstChangeNumberVirtualAttributeProvider.java
index f3459f8..07f42c5 100644
--- a/opends/src/server/org/opends/server/replication/common/FirstChangeNumberVirtualAttributeProvider.java
+++ b/opends/src/server/org/opends/server/replication/common/FirstChangeNumberVirtualAttributeProvider.java
@@ -45,6 +45,7 @@
 import org.opends.server.types.AttributeValues;
 import org.opends.server.types.ByteString;
 import org.opends.server.types.ConfigChangeResult;
+import org.opends.server.types.DN;
 import org.opends.server.types.Entry;
 import org.opends.server.types.InitializationException;
 import org.opends.server.types.ResultCode;
@@ -123,6 +124,10 @@
     String first="0";
     try
     {
+      if (!entry.getDN().equals(DN.decode("")))
+      {
+        return values;
+      }
       ECLWorkflowElement eclwe = (ECLWorkflowElement)
       DirectoryServer.getWorkflowElement("EXTERNAL CHANGE LOG");
       if (eclwe!=null)
diff --git a/opends/src/server/org/opends/server/replication/common/LastChangeNumberVirtualAttributeProvider.java b/opends/src/server/org/opends/server/replication/common/LastChangeNumberVirtualAttributeProvider.java
index a17a07d..bd26ab2 100644
--- a/opends/src/server/org/opends/server/replication/common/LastChangeNumberVirtualAttributeProvider.java
+++ b/opends/src/server/org/opends/server/replication/common/LastChangeNumberVirtualAttributeProvider.java
@@ -45,6 +45,7 @@
 import org.opends.server.types.AttributeValues;
 import org.opends.server.types.ByteString;
 import org.opends.server.types.ConfigChangeResult;
+import org.opends.server.types.DN;
 import org.opends.server.types.Entry;
 import org.opends.server.types.InitializationException;
 import org.opends.server.types.ResultCode;
@@ -123,6 +124,10 @@
     String last = "0";
     try
     {
+      if (!entry.getDN().equals(DN.decode("")))
+      {
+        return values;
+      }
       ECLWorkflowElement eclwe = (ECLWorkflowElement)
       DirectoryServer.getWorkflowElement("EXTERNAL CHANGE LOG");
       if (eclwe!=null)
diff --git a/opends/src/server/org/opends/server/replication/server/ReplicationServer.java b/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
index 7a461f0..9cef25b 100644
--- a/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
+++ b/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
@@ -652,13 +652,21 @@
     NetworkGroup internalNetworkGroup = NetworkGroup.getInternalNetworkGroup();
     internalNetworkGroup.registerWorkflow(externalChangeLogWorkflow);
 
-    enableECLVirtualAttr("lastexternalchangelogcookie",
-        new LastCookieVirtualProvider());
-    enableECLVirtualAttr("firstchangenumber",
-        new FirstChangeNumberVirtualAttributeProvider());
-    enableECLVirtualAttr("lastchangenumber",
-        new LastChangeNumberVirtualAttributeProvider());
-
+    try
+    {
+      enableECLVirtualAttr("lastexternalchangelogcookie",
+          new LastCookieVirtualProvider());
+      enableECLVirtualAttr("firstchangenumber",
+          new FirstChangeNumberVirtualAttributeProvider());
+      enableECLVirtualAttr("lastchangenumber",
+          new LastChangeNumberVirtualAttributeProvider());
+      enableECLVirtualAttr("changelog",
+          new ChangelogBaseDNVirtualAttributeProvider());
+    }
+    catch (Exception e)
+    {
+      TRACER.debugCaught(DebugLogLevel.ERROR, e);
+    }
   }
 
   private void enableECLVirtualAttr(String attrName,
@@ -1312,7 +1320,7 @@
     {
       try
       {
-        draftCNDbHandler.clear();
+        try { draftCNDbHandler.clear(); } catch(Exception e){}
         draftCNDbHandler.shutdown();
         lastGeneratedDraftCN = 0;
         draftCNDbHandler = null;
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ExternalChangeLogTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ExternalChangeLogTest.java
index 2be61af..17b4dc4 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ExternalChangeLogTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ExternalChangeLogTest.java
@@ -3292,6 +3292,8 @@
               String.valueOf(expectedFirst));
           checkValue(resultEntry,"lastchangenumber",
               String.valueOf(expectedLast));
+          checkValue(resultEntry,"changelog",
+              String.valueOf("cn=changelog"));
         }
       }
     }

--
Gitblit v1.10.0