>From dd9981800cd218552670717614ee6c74f21c0a12 Mon Sep 17 00:00:00 2001
From: Ade Lee <alee@redhat.com>
Date: Fri, 19 Oct 2012 01:35:04 -0400
Subject: [PATCH 77/77] Provide option to install, rather than replicate
 schema in a clone

---
 base/ca/shared/conf/manager.ldif                   |  2 +-
 .../certsrv/system/ConfigurationRequest.java       | 13 +++++++++
 .../cms/servlet/csadmin/ConfigurationUtils.java    | 33 +++++++++++++++++++---
 .../cms/servlet/csadmin/DatabasePanel.java         |  1 +
 .../cms/servlet/csadmin/SystemConfigService.java   |  9 ++++++
 base/deploy/config/pkideployment.cfg               |  1 +
 base/deploy/src/scriptlets/pkijython.py            |  1 +
 base/kra/shared/conf/manager.ldif                  |  2 +-
 base/ocsp/shared/conf/manager.ldif                 |  2 +-
 base/tks/shared/conf/manager.ldif                  |  2 +-
 10 files changed, 58 insertions(+), 8 deletions(-)

diff --git a/base/ca/shared/conf/manager.ldif b/base/ca/shared/conf/manager.ldif
index 52e486987d721d799112ef61475e1a45ec19f1be..61aa70b8d6804951be0a1115ce72197ba0e286c4 100644
--- a/base/ca/shared/conf/manager.ldif
+++ b/base/ca/shared/conf/manager.ldif
@@ -8,7 +8,7 @@ ou: csusers
 dn: {rootSuffix}
 changetype: modify
 add: aci
-aci: (targetattr=*)(version 3.0; acl "cert manager access"; allow (all) userdn = "ldap:///{dbuser}";)
+aci: (targetattr=*)(version 3.0; acl "cert manager access v2"; allow (all) userdn = "ldap:///{dbuser}";)
 
 dn: cn=ldbm database,cn=plugins,cn=config
 changetype: modify
diff --git a/base/common/src/com/netscape/certsrv/system/ConfigurationRequest.java b/base/common/src/com/netscape/certsrv/system/ConfigurationRequest.java
index 6482b5f42a3e061340962f1a787c9d3af7aa5c9d..7a07a30ddce5a979ee517f4afe6444e7bfdd0ea3 100644
--- a/base/common/src/com/netscape/certsrv/system/ConfigurationRequest.java
+++ b/base/common/src/com/netscape/certsrv/system/ConfigurationRequest.java
@@ -56,6 +56,7 @@ public class ConfigurationRequest {
     private static final String REMOVEDATA = "removeData";
     private static final String MASTER_REPLICATION_PORT = "masterReplicationPort";
     private static final String CLONE_REPLICATION_PORT = "cloneReplicationPort";
+    private static final String REPLICATE_SCHEMA = "replicateSchema";
     private static final String REPLICATION_SECURITY = "replicationSecurity";
     private static final String ISSUING_CA = "issuingCa";
     private static final String BACKUP_KEYS = "backupKeys";
@@ -149,6 +150,9 @@ public class ConfigurationRequest {
     protected String cloneReplicationPort;
 
     @XmlElement
+    protected String replicateSchema;
+
+    @XmlElement
     protected String replicationSecurity;
 
     @XmlElementRef
@@ -221,6 +225,7 @@ public class ConfigurationRequest {
         removeData = form.getFirst(REMOVEDATA);
         masterReplicationPort = form.getFirst(MASTER_REPLICATION_PORT);
         cloneReplicationPort = form.getFirst(CLONE_REPLICATION_PORT);
+        replicateSchema = form.getFirst(REPLICATE_SCHEMA);
         replicationSecurity = form.getFirst(REPLICATION_SECURITY);
         //TODO - figure out how to get the cert requests
         issuingCA = form.getFirst(ISSUING_CA);
@@ -721,6 +726,14 @@ public class ConfigurationRequest {
         this.stepTwo = stepTwo;
     }
 
+    public String getReplicateSchema() {
+        return replicateSchema;
+    }
+
+    public void setReplicateSchema(String replicateSchema) {
+        this.replicateSchema = replicateSchema;
+    }
+
     @Override
     public String toString() {
         return "ConfigurationRequest [pin=XXXX" +
diff --git a/base/common/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java b/base/common/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
index d90ab211e6dd9598871b1eefe247a3f169c8972a..64b3f49d21b4d4f86e1c3056096a31934c770555 100644
--- a/base/common/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
+++ b/base/common/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
@@ -1257,11 +1257,18 @@ public class ConfigurationUtils {
         try {
             String select = cs.getString("preop.subsystem.select", "");
             if (select.equals("clone")) {
-                // if this is clone, add index before replication
-                // don't put in the schema or bad things will happen
+                // in most cases, we want to replicate the schema and therefore
+                // NOT add it here.  We provide this option though in case the
+                // clone already has schema and we want to replicate back to the
+                // master.
+                boolean replicateSchema = cs.getBoolean("preop.internaldb.replicateSchema", true);
+                if (! replicateSchema) {
+                    importLDIFS("preop.internaldb.schema.ldif", conn);
+                }
                 importLDIFS("preop.internaldb.ldif", conn);
+
+                // add the index before replication, add VLV indexes afterwards
                 importLDIFS("preop.internaldb.index_ldif", conn);
-                importLDIFS("preop.internaldb.manager_ldif", conn);
             } else {
                 // data will be replicated from the master to the clone
                 // so clone does not need the data
@@ -1269,7 +1276,6 @@ public class ConfigurationUtils {
                 importLDIFS("preop.internaldb.ldif", conn);
                 importLDIFS("preop.internaldb.data_ldif", conn);
                 importLDIFS("preop.internaldb.index_ldif", conn);
-                importLDIFS("preop.internaldb.manager_ldif", conn);
             }
         } catch (Exception e) {
             e.printStackTrace();
@@ -1509,6 +1515,25 @@ public class ConfigurationUtils {
         return dir.delete();
     }
 
+    public static void populateDBManager() throws Exception {
+        CMS.debug("populateDBManager(): start");
+        IConfigStore cs = CMS.getConfigStore();
+
+        IConfigStore dbCfg = cs.getSubStore("internaldb");
+        ILdapConnFactory dbFactory = CMS.getLdapBoundConnFactory();
+        dbFactory.init(dbCfg);
+        LDAPConnection conn = dbFactory.getConn();
+
+        try {
+            importLDIFS("preop.internaldb.manager_ldif", conn);
+        } catch (Exception e) {
+            CMS.debug("populateDBManager(): Exception thrown: " + e);
+            throw e;
+        } finally {
+            releaseConnection(conn);
+        }
+    }
+
     public static void populateVLVIndexes() throws Exception {
         CMS.debug("populateVLVIndexes(): start");
         IConfigStore cs = CMS.getConfigStore();
diff --git a/base/common/src/com/netscape/cms/servlet/csadmin/DatabasePanel.java b/base/common/src/com/netscape/cms/servlet/csadmin/DatabasePanel.java
index 67f10bd8e6f2ee732ebfd89f102cc1db7acaa023..5beb81244fd0e725ef0e5bc57ee023f3852b6797 100644
--- a/base/common/src/com/netscape/cms/servlet/csadmin/DatabasePanel.java
+++ b/base/common/src/com/netscape/cms/servlet/csadmin/DatabasePanel.java
@@ -489,6 +489,7 @@ public class DatabasePanel extends WizardPanelBase {
             }
 
             ConfigurationUtils.reInitSubsystem(csType);
+            ConfigurationUtils.populateDBManager();
             ConfigurationUtils.populateVLVIndexes();
 
             cs.putBoolean("preop.Database.done", true);
diff --git a/base/common/src/com/netscape/cms/servlet/csadmin/SystemConfigService.java b/base/common/src/com/netscape/cms/servlet/csadmin/SystemConfigService.java
index 3b6ea1a1f1854e63f9dcbb30adca149a0c17a86d..f89c2ec60b3a860d1941f4334018edef66c2a8c0 100644
--- a/base/common/src/com/netscape/cms/servlet/csadmin/SystemConfigService.java
+++ b/base/common/src/com/netscape/cms/servlet/csadmin/SystemConfigService.java
@@ -365,6 +365,8 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
                 replicationSecurity = "None";
             }
             cs.putString("internaldb.ldapconn.replicationSecurity", replicationSecurity);
+
+            cs.putString("preop.internaldb.replicateSchema", data.getReplicateSchema());
         }
 
         try {
@@ -391,6 +393,7 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
             }
 
             ConfigurationUtils.reInitSubsystem(csType);
+            ConfigurationUtils.populateDBManager();
             ConfigurationUtils.populateVLVIndexes();
 
         } catch (Exception e) {
@@ -865,6 +868,12 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
             }
         }
 
+        if ((data.getReplicateSchema() != null) && (data.getReplicateSchema().equalsIgnoreCase("false"))) {
+            data.setReplicateSchema("false");
+        } else {
+            data.setReplicateSchema("true");
+        }
+
         if ((data.getBackupKeys() != null) && data.getBackupKeys().equals("true")) {
             if ((data.getBackupFile() == null) || (data.getBackupFile().length()<=0)) {
                 //TODO: also check for valid path, perhaps by touching file there
diff --git a/base/deploy/config/pkideployment.cfg b/base/deploy/config/pkideployment.cfg
index a7e61ccb8186a06d005c5f2e91fc3c809fe558eb..2a62c5e7d4192d35ddf5462cacaa561362e3d707 100644
--- a/base/deploy/config/pkideployment.cfg
+++ b/base/deploy/config/pkideployment.cfg
@@ -107,6 +107,7 @@ pki_https_port=443
 pki_ajp_port=8009
 pki_clone=False
 pki_clone_pkcs12_path=
+pki_clone_replicate_schema=True
 pki_clone_replication_master_port=
 pki_clone_replication_clone_port=
 pki_clone_replication_security=None
diff --git a/base/deploy/src/scriptlets/pkijython.py b/base/deploy/src/scriptlets/pkijython.py
index 28a70504693abe41f939801cd602d5e92ef58ee5..e984e03779d5cfc069f26e043f42526cf5189880 100644
--- a/base/deploy/src/scriptlets/pkijython.py
+++ b/base/deploy/src/scriptlets/pkijython.py
@@ -290,6 +290,7 @@ class rest_client:
         data.setCloneUri(self.master['pki_clone_uri'])
         data.setP12File(self.master['pki_clone_pkcs12_path'])
         data.setP12Password(self.sensitive['pki_clone_pkcs12_password'])
+        data.setReplicateSchema(self.master['pki_clone_replicate_schema'])
         data.setReplicationSecurity(
             self.master['pki_clone_replication_security'])
         if self.master['pki_clone_replication_master_port']:
diff --git a/base/kra/shared/conf/manager.ldif b/base/kra/shared/conf/manager.ldif
index 52e486987d721d799112ef61475e1a45ec19f1be..61aa70b8d6804951be0a1115ce72197ba0e286c4 100644
--- a/base/kra/shared/conf/manager.ldif
+++ b/base/kra/shared/conf/manager.ldif
@@ -8,7 +8,7 @@ ou: csusers
 dn: {rootSuffix}
 changetype: modify
 add: aci
-aci: (targetattr=*)(version 3.0; acl "cert manager access"; allow (all) userdn = "ldap:///{dbuser}";)
+aci: (targetattr=*)(version 3.0; acl "cert manager access v2"; allow (all) userdn = "ldap:///{dbuser}";)
 
 dn: cn=ldbm database,cn=plugins,cn=config
 changetype: modify
diff --git a/base/ocsp/shared/conf/manager.ldif b/base/ocsp/shared/conf/manager.ldif
index 52e486987d721d799112ef61475e1a45ec19f1be..61aa70b8d6804951be0a1115ce72197ba0e286c4 100644
--- a/base/ocsp/shared/conf/manager.ldif
+++ b/base/ocsp/shared/conf/manager.ldif
@@ -8,7 +8,7 @@ ou: csusers
 dn: {rootSuffix}
 changetype: modify
 add: aci
-aci: (targetattr=*)(version 3.0; acl "cert manager access"; allow (all) userdn = "ldap:///{dbuser}";)
+aci: (targetattr=*)(version 3.0; acl "cert manager access v2"; allow (all) userdn = "ldap:///{dbuser}";)
 
 dn: cn=ldbm database,cn=plugins,cn=config
 changetype: modify
diff --git a/base/tks/shared/conf/manager.ldif b/base/tks/shared/conf/manager.ldif
index 52e486987d721d799112ef61475e1a45ec19f1be..61aa70b8d6804951be0a1115ce72197ba0e286c4 100644
--- a/base/tks/shared/conf/manager.ldif
+++ b/base/tks/shared/conf/manager.ldif
@@ -8,7 +8,7 @@ ou: csusers
 dn: {rootSuffix}
 changetype: modify
 add: aci
-aci: (targetattr=*)(version 3.0; acl "cert manager access"; allow (all) userdn = "ldap:///{dbuser}";)
+aci: (targetattr=*)(version 3.0; acl "cert manager access v2"; allow (all) userdn = "ldap:///{dbuser}";)
 
 dn: cn=ldbm database,cn=plugins,cn=config
 changetype: modify
-- 
1.7.11.4

