The PKISubsystem.load() and PKIInstance.load() have been modified
to ignore blank and comment lines in CS.cfg and password.conf. If
the code fails to parse a line it will throw an exception showing
the location of the invalid line.

https://fedorahosted.org/pki/ticket/2314

A simpler version of this patch was tested by jmagne (thanks!). Pushed to master under trivial/one-liner rule.

--
Endi S. Dewata
>From 31fb6597f39337edf0ce2671b0f3415fb2302265 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <[email protected]>
Date: Tue, 24 May 2016 03:13:52 +0200
Subject: [PATCH] Ignoring blank and comment lines in configuration files.

The PKISubsystem.load() and PKIInstance.load() have been modified
to ignore blank and comment lines in CS.cfg and password.conf. If
the code fails to parse a line it will throw an exception showing
the location of the invalid line.

https://fedorahosted.org/pki/ticket/2314
---
 base/server/python/pki/server/__init__.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/base/server/python/pki/server/__init__.py b/base/server/python/pki/server/__init__.py
index 1c590c37e75315d27de6b42674f6de1d8bd651f6..20d4c2c4f206520149a3d5d182def6851bdb8bef 100644
--- a/base/server/python/pki/server/__init__.py
+++ b/base/server/python/pki/server/__init__.py
@@ -123,8 +123,12 @@ class PKISubsystem(object):
 
         lines = open(self.cs_conf).read().splitlines()
 
-        for line in lines:
+        for index, line in enumerate(lines):
+            if not line or line.startswith('#'):
+                continue
             parts = line.split('=', 1)
+            if len(parts) < 2:
+                raise Exception('Missing delimiter in %s line %d' % (self.cs_conf, index + 1))
             name = parts[0]
             value = parts[1]
             self.config[name] = value
@@ -473,8 +477,12 @@ class PKIInstance(object):
 
             lines = open(self.password_conf).read().splitlines()
 
-            for line in lines:
+            for index, line in enumerate(lines):
+                if not line or line.startswith('#'):
+                    continue
                 parts = line.split('=', 1)
+                if len(parts) < 2:
+                    raise Exception('Missing delimiter in %s line %d' % (self.password_conf, index + 1))
                 name = parts[0]
                 value = parts[1]
                 self.passwords[name] = value
-- 
2.4.11

_______________________________________________
Pki-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/pki-devel

Reply via email to