This commit is contained in:
Stanislav 2017-04-22 22:40:03 +00:00 committed by GitHub
commit 9425f26396
1 changed files with 15 additions and 2 deletions

View File

@ -327,6 +327,19 @@ class Backend(ldapcherry.backend.Backend):
return None
return s.decode('utf-8', 'ignore')
def _extract_content(self, args, formatting):
match_object = re.search('\((.+)\)', formatting)
if not match_object:
raise Exception
arg_key = match_object.group(1)
if isinstance(args[arg_key], list):
return args[arg_key][0]
else:
return args[arg_key]
def auth(self, username, password):
"""Authentication of a user"""
@ -452,7 +465,7 @@ class Backend(ldapcherry.backend.Backend):
# iterate on group membership attributes
for attr in self.group_attrs:
# fill the content template
content = self._str(self.group_attrs[attr] % attrs)
content = self._str(self._extract_content(attrs, self.group_attrs[attr]))
self._logger(
severity=logging.DEBUG,
msg="%(backend)s: adding user '%(user)s'"
@ -505,7 +518,7 @@ class Backend(ldapcherry.backend.Backend):
for group in groups:
group = self._str(group)
for attr in self.group_attrs:
content = self._str(self.group_attrs[attr] % attrs)
content = self._str(self._extract_content(attrs, self.group_attrs[attr]))
ldif = [(ldap.MOD_DELETE, attr, content)]
try:
ldap_client.modify_s(group, ldif)