From 3790dd899db51a47f770ee52f339cfd2539e2bbd Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Thu, 17 Jan 2008 08:50:31 +0000
Subject: [PATCH] Fix for 2811 (dsreplication disable doesn't remove references to current server from replicated servers) The fix makes dsreplication enable and dsreplication disable symmetric.  When the user disables the last replicated suffix, we inform that the replication server will also be disabled.  So when the last repilcated suffix is disabled, replication on cn=schema and cn=admin data are also disabled and the registration information updated properly.

---
 opends/src/ads/org/opends/admin/ads/ADSContext.java |   92 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 91 insertions(+), 1 deletions(-)

diff --git a/opends/src/ads/org/opends/admin/ads/ADSContext.java b/opends/src/ads/org/opends/admin/ads/ADSContext.java
index bea0f71..e221e52 100644
--- a/opends/src/ads/org/opends/admin/ads/ADSContext.java
+++ b/opends/src/ads/org/opends/admin/ads/ADSContext.java
@@ -504,7 +504,7 @@
         serverProperties.put(ServerProperty.ID,newServerId);
       }
       BasicAttributes attrs = makeAttrsFromServerProperties(serverProperties);
-      dirContext.modifyAttributes(dn, InitialLdapContext.REPLACE_ATTRIBUTE,
+      dirContext.modifyAttributes(dn, DirContext.REPLACE_ATTRIBUTE,
           attrs);
       if (serverProperties.containsKey(
                                 ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE))
@@ -542,6 +542,11 @@
     LdapName dn = makeDNFromServerProperties(serverProperties);
     try
     {
+      if (serverProperties.containsKey(
+          ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE))
+      {
+        unregisterInstanceKeyCertificate(serverProperties, dn);
+      }
       dirContext.destroySubcontext(dn);
     }
     catch (NameNotFoundException x)
@@ -554,6 +559,74 @@
       throw new ADSContextException(
           ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
     }
+
+    // Unregister the server in server groups
+    try
+    {
+      NamingEnumeration ne;
+      SearchControls sc = new SearchControls();
+
+      String serverID = getServerID(serverProperties);
+      if (serverID != null)
+      {
+        String memberAttrName = ServerGroupProperty.MEMBERS.getAttributeName();
+        String filter = "("+memberAttrName+"=cn="+serverID+")";
+        sc.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+        ne = dirContext.search(getServerGroupContainerDN(), filter, sc);
+        while (ne.hasMore())
+        {
+          SearchResult sr = (SearchResult)ne.next();
+          String groupDn = sr.getNameInNamespace();
+          BasicAttribute newAttr = new BasicAttribute(memberAttrName);
+          NamingEnumeration attrs = sr.getAttributes().getAll();
+          while (attrs.hasMore())
+          {
+            Attribute attr = (Attribute)attrs.next();
+            String attrID = attr.getID();
+
+            if (attrID.equalsIgnoreCase(memberAttrName))
+            {
+              NamingEnumeration ae = attr.getAll();
+              while (ae.hasMore())
+              {
+                String value = (String)ae.next();
+                if (!value.equalsIgnoreCase("cn="+serverID))
+                {
+                  newAttr.add(value);
+                }
+              }
+            }
+          }
+          BasicAttributes newAttrs = new BasicAttributes();
+          newAttrs.put(newAttr);
+          if (newAttr.size() > 0)
+          {
+            dirContext.modifyAttributes(groupDn, DirContext.REPLACE_ATTRIBUTE,
+                newAttrs);
+          }
+          else
+          {
+            dirContext.modifyAttributes(groupDn, DirContext.REMOVE_ATTRIBUTE,
+                newAttrs);
+          }
+        }
+      }
+    }
+    catch (NameNotFoundException x)
+    {
+      throw new ADSContextException(
+          ADSContextException.ErrorType.BROKEN_INSTALL);
+    }
+    catch (NoPermissionException x)
+    {
+      throw new ADSContextException(
+          ADSContextException.ErrorType.ACCESS_PERMISSION);
+    }
+    catch (NamingException x)
+    {
+      throw new ADSContextException(
+          ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
+    }
   }
 
   /**
@@ -2193,6 +2266,23 @@
   }
 
   /**
+  Unregister instance key-pair public-key certificate provided in
+  serverProperties..
+  @param serverProperties Properties of the server being unregistered to which
+  the instance key entry belongs.
+  @param serverEntryDn The server's ADS entry DN.
+  @throws NamingException In case some JNDI operation fails.
+  */
+ private void unregisterInstanceKeyCertificate(
+         Map<ServerProperty, Object> serverProperties,
+         LdapName serverEntryDn)
+ throws ADSContextException {
+   ADSContextHelper helper = new ADSContextHelper();
+   helper.unregisterInstanceKeyCertificate(dirContext, serverProperties,
+       serverEntryDn);
+ }
+
+  /**
    Return the set of valid (i.e., not tagged as compromised) instance key-pair
    public-key certificate entries in ADS.
    NOTE: calling this method assumes that all the jar files are present in the

--
Gitblit v1.10.0