From 7c5aa5b3b5a6238b4f5ba4a1ba53c43d622d4e2c Mon Sep 17 00:00:00 2001 From: Stan Rudenko Date: Fri, 3 Mar 2017 17:54:34 -0800 Subject: [PATCH] GH-4: fix for user attach to group --- ldapcherry/backend/backendLdap.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ldapcherry/backend/backendLdap.py b/ldapcherry/backend/backendLdap.py index b180451..3fe60ec 100644 --- a/ldapcherry/backend/backendLdap.py +++ b/ldapcherry/backend/backendLdap.py @@ -275,6 +275,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""" @@ -399,7 +412,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'" @@ -451,7 +464,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)