pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0022-Prevent-set_directive-from-clobbering-other-keys.patch

c58629
From 8ea1652c64956eea6dd0708f61b3330befcf1a31 Mon Sep 17 00:00:00 2001
c58629
From: Fraser Tweedale <ftweedal@redhat.com>
c58629
Date: Sat, 21 Nov 2020 08:47:57 +1100
c58629
Subject: [PATCH] Prevent set_directive from clobbering other keys
c58629
c58629
`set_directive` only looks for a prefix of the line matching the
c58629
given directive (key).  If a directive is encountered for which the
c58629
given key is prefix, it will be vanquished.
c58629
c58629
This occurs in the case of `{ca,kra}.sslserver.cert[req]`; the
c58629
`cert` directive gets updated after certificate renewal, and the
c58629
`certreq` directive gets clobbered.  This can cause failures later
c58629
on during KRA installation, and possibly cloning.
c58629
c58629
Match the whole directive to avoid this issue.
c58629
c58629
Fixes: https://pagure.io/freeipa/issue/7288
c58629
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
c58629
---
c58629
 ipaserver/install/cainstance.py     | 2 +-
c58629
 ipaserver/install/dogtaginstance.py | 2 +-
c58629
 ipaserver/install/installutils.py   | 6 +++---
c58629
 3 files changed, 5 insertions(+), 5 deletions(-)
c58629
c58629
diff --git a/ipaserver/install/cainstance.py b/ipaserver/install/cainstance.py
c58629
index 62f79b28000b015edb66f4c39a270097ab3ed666..f45d2c8b89ba4b81be5acbbe85f256e85ef630fb 100644
c58629
--- a/ipaserver/install/cainstance.py
c58629
+++ b/ipaserver/install/cainstance.py
c58629
@@ -931,7 +931,7 @@ class CAInstance(DogtagInstance):
c58629
         installutils.set_directive(caconfig, 'ca.publish.rule.instance.FileCrlRule.enable', 'true', quotes=False, separator='=')
c58629
         installutils.set_directive(caconfig, 'ca.publish.rule.instance.FileCrlRule.mapper', 'NoMap', quotes=False, separator='=')
c58629
         installutils.set_directive(caconfig, 'ca.publish.rule.instance.FileCrlRule.pluginName', 'Rule', quotes=False, separator='=')
c58629
-        installutils.set_directive(caconfig, 'ca.publish.rule.instance.FileCrlRule.predicate=', '', quotes=False, separator='')
c58629
+        installutils.set_directive(caconfig, 'ca.publish.rule.instance.FileCrlRule.predicate', '', quotes=False, separator='=')
c58629
         installutils.set_directive(caconfig, 'ca.publish.rule.instance.FileCrlRule.publisher', 'FileBaseCRLPublisher', quotes=False, separator='=')
c58629
         installutils.set_directive(caconfig, 'ca.publish.rule.instance.FileCrlRule.type', 'crl', quotes=False, separator='=')
c58629
 
c58629
diff --git a/ipaserver/install/dogtaginstance.py b/ipaserver/install/dogtaginstance.py
c58629
index 1fdc3e50a46877374e4f1aa8435d09f6b4e62180..9470e1a13608a8a84aab8a36c269a708e3f3e9f4 100644
c58629
--- a/ipaserver/install/dogtaginstance.py
c58629
+++ b/ipaserver/install/dogtaginstance.py
c58629
@@ -212,7 +212,7 @@ class DogtagInstance(service.Service):
c58629
                 separator='=')
c58629
             # Remove internaldb password as is not needed anymore
c58629
             installutils.set_directive(paths.PKI_TOMCAT_PASSWORD_CONF,
c58629
-                                       'internaldb', None)
c58629
+                                       'internaldb', None, separator='=')
c58629
 
c58629
     def uninstall(self):
c58629
         if self.is_installed():
c58629
diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
c58629
index 01930c4de6f0edd16b31aeba1c926fe581e9635b..821609beb533fcc9064500a88ccd07b35142f1df 100644
c58629
--- a/ipaserver/install/installutils.py
c58629
+++ b/ipaserver/install/installutils.py
c58629
@@ -433,7 +433,7 @@ def set_directive(filename, directive, value, quotes=True, separator=' '):
c58629
 
c58629
     A value of None means to drop the directive.
c58629
 
c58629
-    This has only been tested with nss.conf
c58629
+    Does not tolerate (or put) spaces around the separator.
c58629
 
c58629
     :param filename: input filename
c58629
     :param directive: directive name
c58629
@@ -442,7 +442,7 @@ def set_directive(filename, directive, value, quotes=True, separator=' '):
c58629
         any existing double quotes are first escaped to avoid
c58629
         unparseable directives.
c58629
     :param separator: character serving as separator between directive and
c58629
-        value
c58629
+        value.  Correct value required even when dropping a directive.
c58629
     """
c58629
 
c58629
     new_directive_value = ""
c58629
@@ -457,7 +457,7 @@ def set_directive(filename, directive, value, quotes=True, separator=' '):
c58629
     fd = open(filename)
c58629
     newfile = []
c58629
     for line in fd:
c58629
-        if line.lstrip().startswith(directive):
c58629
+        if re.match(r'\s*{}'.format(re.escape(directive + separator)), line):
c58629
             valueset = True
c58629
             if value is not None:
c58629
                 newfile.append(new_directive_value)
c58629
-- 
c58629
2.13.6
c58629