1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-24 10:14:31 +01:00

GH-4: fix for user attach to group

This commit is contained in:
Stan Rudenko 2017-03-03 17:54:34 -08:00
parent e37b88dbda
commit 7c5aa5b3b5

View File

@ -275,6 +275,19 @@ class Backend(ldapcherry.backend.Backend):
return None return None
return s.decode('utf-8', 'ignore') 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): def auth(self, username, password):
"""Authentication of a user""" """Authentication of a user"""
@ -399,7 +412,7 @@ class Backend(ldapcherry.backend.Backend):
# iterate on group membership attributes # iterate on group membership attributes
for attr in self.group_attrs: for attr in self.group_attrs:
# fill the content template # 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( self._logger(
severity=logging.DEBUG, severity=logging.DEBUG,
msg="%(backend)s: adding user '%(user)s'" msg="%(backend)s: adding user '%(user)s'"
@ -451,7 +464,7 @@ class Backend(ldapcherry.backend.Backend):
for group in groups: for group in groups:
group = self._str(group) group = self._str(group)
for attr in self.group_attrs: 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)] ldif = [(ldap.MOD_DELETE, attr, content)]
try: try:
ldap_client.modify_s(group, ldif) ldap_client.modify_s(group, ldif)