From 894bcfabe2aac051adc47d9a2c6b2fcb7421c9d1 Mon Sep 17 00:00:00 2001
From: david_page <david_page@localhost>
Date: Fri, 31 Aug 2007 14:55:07 +0000
Subject: [PATCH] Issue 466 partial

---
 opends/src/ads/org/opends/admin/ads/ServerDescriptor.java |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java b/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
index a955024..b69f3a3 100644
--- a/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
+++ b/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
@@ -40,7 +40,6 @@
 import javax.naming.directory.Attribute;
 import javax.naming.directory.BasicAttribute;
 import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.DirContext;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 import javax.naming.ldap.InitialLdapContext;
@@ -841,8 +840,7 @@
        file for the installer and import it into the core. */
     final String dnStr = "ds-cfg-key-id=ads-certificate,cn=ads-truststore";
     final LdapName dn = new LdapName(dnStr);
-    byte[] localInstanceKeyCertificate = null;
-    for (int i = 0; null == localInstanceKeyCertificate && i < 2 ; ++i ) {
+    for (int i = 0; i < 2 ; ++i) {
       /* If the entry does not exist in the instance's truststore backend, add
          it (which induces the CryptoManager to create the public-key
          certificate attribute), then repeat the search. */
@@ -852,12 +850,15 @@
         final String attrIDs[] = { "ds-cfg-public-key-certificate;binary" };
         sc.setReturningAttributes(attrIDs);
         final SearchResult certEntry
-           = ctx.search(dn, "(objectclass=*)", sc).next();
-        final Attribute certAttr = certEntry.getAttributes().get(
-                                        "ds-cfg-public-key-certificate;binary");
+           = ctx.search(dn, "(objectclass=ds-cfg-instance-key)", sc).next();
+        final Attribute certAttr = certEntry.getAttributes().get(attrIDs[0]);
         if (null != certAttr) {
-          localInstanceKeyCertificate = (byte[])certAttr.get();
+          /* attribute ds-cfg-public-key-certificate is a MUST in the schema */
+          desc.serverProperties.put(
+                  ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE,
+                  certAttr.get());
         }
+        break;
       }
       catch (NameNotFoundException x) {
         if (0 == i) {
@@ -868,16 +869,13 @@
           oc.add("top");
           oc.add("ds-cfg-self-signed-cert-request");
           attrs.put(oc);
-          DirContext pokeCtx = ctx.createSubcontext(dn, attrs);
-          pokeCtx.close();
+          ctx.createSubcontext(dn, attrs).close();
         }
         else {
           throw x;
         }
       }
     }
-    desc.serverProperties.put(ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE,
-            localInstanceKeyCertificate);
   }
 
 

--
Gitblit v1.10.0