diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2009-12-07 21:17:20 +0100 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2009-12-08 12:31:46 -0500 |
commit | 573190f896b4f474e604dd86b11cbfbdd987a236 (patch) | |
tree | ce39544a739207c227e9c71b3acd7dd76a2d9202 | |
parent | 4acbe2d18ef16a4a1560fd893fe34224f68b243a (diff) | |
download | sssd-573190f896b4f474e604dd86b11cbfbdd987a236.tar.gz sssd-573190f896b4f474e604dd86b11cbfbdd987a236.tar.xz sssd-573190f896b4f474e604dd86b11cbfbdd987a236.zip |
Handle spaces in config parser
Fixes: #301
-rw-r--r-- | server/config/SSSDConfigTest.py | 8 | ||||
-rw-r--r-- | server/config/ipachangeconf.py | 33 | ||||
-rw-r--r-- | server/config/testconfigs/sssd-valid.conf | 4 |
3 files changed, 43 insertions, 2 deletions
diff --git a/server/config/SSSDConfigTest.py b/server/config/SSSDConfigTest.py index aca1fbd44..ac37aec9b 100644 --- a/server/config/SSSDConfigTest.py +++ b/server/config/SSSDConfigTest.py @@ -149,6 +149,14 @@ class SSSDConfigTestValid(unittest.TestCase): sssdconfig.write('/tmp/testModifyExistingConfig.conf') + def testSpaces(self): + sssdconfig = SSSDConfig.SSSDConfig("etc/sssd.api.conf", + "etc/sssd.api.d") + sssdconfig.import_config("testconfigs/sssd-valid.conf") + ldap_domain = sssdconfig.get_domain('LDAP') + self.assertEqual(ldap_domain.get_option('auth_provider'), 'ldap') + self.assertEqual(ldap_domain.get_option('id_provider'), 'ldap') + class SSSDConfigTestSSSDService(unittest.TestCase): def setUp(self): self.schema = SSSDConfig.SSSDConfigSchema("etc/sssd.api.conf", diff --git a/server/config/ipachangeconf.py b/server/config/ipachangeconf.py index 3e5029a94..9635de44f 100644 --- a/server/config/ipachangeconf.py +++ b/server/config/ipachangeconf.py @@ -23,6 +23,7 @@ import os import string import time import shutil +import re def openLocked(filename, perms): fd = -1 @@ -460,12 +461,44 @@ class IPAChangeConf: # A SSSD-specific subclass of IPAChangeConf class SSSDChangeConf(IPAChangeConf): + OPTCRE = re.compile( + r'(?P<option>[^:=\s][^:=]*)' # very permissive! + r'\s*=\s*' # any number of space/tab, + # followed by separator + # followed by any # space/tab + r'(?P<value>.*)$' # everything up to eol + ) + def __init__(self): IPAChangeConf.__init__(self, "SSSD") self.comment = ("#",";") self.backup_suffix = ".bak" self.opts = [] + def parseLine(self, line): + """ + Overrides IPAChangeConf parseLine so that lines are splitted + using any separator in self.assign, not just the default one + """ + + if self.matchEmpty(line): + return {'name':'empty', 'type':'empty'} + + value = self.matchComment(line) + if value: + return {'name':'comment', 'type':'comment', 'value':value.rstrip()} + + mo = self.OPTCRE.match(line) + if not mo: + raise SyntaxError, 'Syntax Error: Unknown line format' + + try: + name, value = mo.group('option', 'value') + except IndexError: + raise SyntaxError, 'Syntax Error: Unknown line format' + + return {'name':name.strip(), 'type':'option', 'value':value.strip()} + def readfp(self, fd): self.opts.extend(self.parse(fd)) diff --git a/server/config/testconfigs/sssd-valid.conf b/server/config/testconfigs/sssd-valid.conf index 6725e0a72..82b3fd819 100644 --- a/server/config/testconfigs/sssd-valid.conf +++ b/server/config/testconfigs/sssd-valid.conf @@ -30,8 +30,8 @@ auth_provider = local debug_level = 0 [domain/LDAP] -id_provider = ldap -auth_provider = ldap +id_provider = ldap +auth_provider=ldap debug_level = 0 [pam] |