[SSSD] [PATCH] config API: read only specific files from schemaplugindir

Sumit Bose sbose at redhat.com
Fri Feb 28 09:29:29 UTC 2014


Hi,

as mentioned earlier on this list the python config API currently reads
any file from /usr/share/sssd/sssd.api.d which might result in all kinds
of strange errors if e.g. editor swap or backup files can be found in
this directory.

With this patch only files matching the pattern '^sssd-.*\.conf$' are
read from this directory.

bye,
Sumit
-------------- next part --------------
From 7362ead0e8453b503f3f7a0decbb07c8379ff751 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Thu, 27 Feb 2014 12:08:03 +0100
Subject: [PATCH] config API: read only specific files from schemaplugindir

Currently the config API read any file in the schema plugin dir,
typically /usr/share/sssd/sssd.api.d. If there are any unexpected files,
like e.g. editor copies or backups, the python code might break because
it cannot parse the files.

With this patch only files matching the pattern '^sssd-.*\.conf$' are
read from this directory.

Additionally this patch contains a file which will break the config API
self test if it is not filtered out correctly.
---
 Makefile.am                                | 3 ++-
 src/config/SSSDConfig/__init__.py.in       | 4 +++-
 src/config/etc/sssd.api.d/crash_test_dummy | 1 +
 3 files changed, 6 insertions(+), 2 deletions(-)
 create mode 100644 src/config/etc/sssd.api.d/crash_test_dummy

diff --git a/Makefile.am b/Makefile.am
index 05653a2..9f010d9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -274,7 +274,8 @@ dist_noinst_DATA = \
     src/config/testconfigs/sssd-noversion.conf \
     src/config/testconfigs/sssd-badversion.conf \
     src/config/testconfigs/sssd-invalid.conf \
-    src/config/testconfigs/sssd-invalid-badbool.conf
+    src/config/testconfigs/sssd-invalid-badbool.conf \
+    src/config/etc/sssd.api.d/crash_test_dummy
 
 ###############################
 # Global compilation settings #
diff --git a/src/config/SSSDConfig/__init__.py.in b/src/config/SSSDConfig/__init__.py.in
index 8563a91..5659f9a 100644
--- a/src/config/SSSDConfig/__init__.py.in
+++ b/src/config/SSSDConfig/__init__.py.in
@@ -7,6 +7,7 @@ Created on Sep 18, 2009
 import os
 import gettext
 import exceptions
+import re
 from ipachangeconf import SSSDChangeConf
 
 # Exceptions
@@ -399,7 +400,8 @@ class SSSDConfigSchema(SSSDChangeConf):
             self.readfp(fd)
             fd.close()
             # Read in the provider files
-            for file in os.listdir(schemaplugindir):
+            for file in filter(lambda f: re.search('^sssd-.*\.conf$', f),
+                                         os.listdir(schemaplugindir)):
                 fd = open(schemaplugindir+ "/" + file)
                 self.readfp(fd)
                 fd.close()
diff --git a/src/config/etc/sssd.api.d/crash_test_dummy b/src/config/etc/sssd.api.d/crash_test_dummy
new file mode 100644
index 0000000..02e447e
--- /dev/null
+++ b/src/config/etc/sssd.api.d/crash_test_dummy
@@ -0,0 +1 @@
+Please do not delete this file, it is part of the config API self-test.
-- 
1.8.3.1



More information about the sssd-devel mailing list