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:30:02 -0500 |
commit | 9e88e38f2fa4e6b752ac87392b8af8db03a2b82a (patch) | |
tree | 979c2a4a26718ad83decedf6296d4911be320746 /server | |
parent | e1f745fb3580c21fecf5f900c8361681581a3118 (diff) | |
download | sssd-9e88e38f2fa4e6b752ac87392b8af8db03a2b82a.tar.gz sssd-9e88e38f2fa4e6b752ac87392b8af8db03a2b82a.tar.bz2 sssd-9e88e38f2fa4e6b752ac87392b8af8db03a2b82a.zip |
Handle spaces in config parser
Fixes: #301
Diffstat (limited to 'server')
-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 aca1fbd4..ac37aec9 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 3e5029a9..9635de44 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 6725e0a7..82b3fd81 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] |