Please review the attached patch for:

 * Bugzilla Bug #1447144 - CA brought down during separate KRA instance
   creation <https://bugzilla.redhat.com/show_bug.cgi?id=1447144>

Note that the Python method itself was tested in a standalone fashion against various sample configuration files to make certain that the only thing altered was an invalid section heading.

It was run against the previously modified files noted in the bug and made the following changes to the user deployment configuration files:

   # diff mlh_ca.cfg.orig mlh_ca.cfg
   24c24
   < [TOMCAT]
   ---
    > [Tomcat]

   # diff mlh_kra.cfg.orig mlh_kra.cfg
   31c31
   < [TOMCAT]
   ---
    > [Tomcat]

Application of this patch allowed the KRA to be installed successfully, and did not shutdown the CA.


From ca8c6ed4ce72f4ea4bf5146c03ece21a24863ca1 Mon Sep 17 00:00:00 2001
From: Matthew Harmsen <mharm...@redhat.com>
Date: Wed, 17 May 2017 12:40:57 -0600
Subject: [PATCH] Correct section headings in user deployment configuration
 file

Bugzilla Bug #1447144 - CA brought down during separate KRA instance creation
dogtagpki Pagure Issue #2674 - CA brought down during separate KRA instance
                               creation
---
 base/server/sbin/pkispawn | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/base/server/sbin/pkispawn b/base/server/sbin/pkispawn
index 9394b8e..16a664e 100755
--- a/base/server/sbin/pkispawn
+++ b/base/server/sbin/pkispawn
@@ -30,6 +30,7 @@ if not hasattr(sys, "hexversion") or sys.hexversion < 0x020700f0:
     print("Please upgrade to at least Python 2.7.0.")
     sys.exit(1)
 try:
+    import fileinput
     import ldap
     import os
     import requests
@@ -105,6 +106,8 @@ def main(argv):
         interactive = True
         parser.indent = 0
         print(log.PKISPAWN_INTERACTIVE_INSTALLATION)
+    else:
+        sanitize_user_deployment_cfg(config.user_deployment_cfg)
 
     # Only run this program as "root".
     if not os.geteuid() == 0:
@@ -574,6 +577,36 @@ def main(argv):
         print_final_install_information(parser.mdict)
 
 
+def sanitize_user_deployment_cfg(cfg):
+    # Correct any section headings in the user's configuration file
+    for line in fileinput.FileInput(cfg, inplace=1):
+        # Remove extraneous leading and trailing whitespace from all lines
+        line = line.strip()
+        # Normalize section headings to match '/etc/pki/default.cfg'
+        if line.startswith("["):
+            if line.upper() == "[DEFAULT]":
+                line = "[DEFAULT]"
+            elif line.upper() == "[TOMCAT]":
+                line = "[Tomcat]"
+            elif line.upper() == "[CA]":
+                line = "[CA]"
+            elif line.upper() == "[KRA]":
+                line = "[KRA]"
+            elif line.upper() == "[OCSP]":
+                line = "[OCSP]"
+            elif line.upper() == "[RA]":
+                line = "[RA]"
+            elif line.upper() == "[TKS]":
+                line = "[TKS]"
+            elif line.upper() == "[TPS]":
+                line = "[TPS]"
+            else:
+                # Notify user of the existence of an invalid section heading
+                sys.stderr.write("'%s' contains an invalid section "
+                                 "heading called '%s'!\n" % (cfg, line))
+        print(line)
+
+
 def start_logging():
     # Enable 'pkispawn' logging.
     config.pki_log_dir = config.pki_root_prefix + \
-- 
2.9.4

_______________________________________________
Pki-devel mailing list
Pki-devel@redhat.com
https://www.redhat.com/mailman/listinfo/pki-devel

Reply via email to