Skip to content

Commit

Permalink
fix add/del groups
Browse files Browse the repository at this point in the history
  • Loading branch information
kakwa committed Jun 16, 2015
1 parent 60a7329 commit 0d766d3
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions ldapcherry/backend/backendLdap.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _connect(self):
if self.checkcert == 'off':
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_ALLOW)
else:
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,ldap.OPT_X_TLS_DEMAND)
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_DEMAND)
if self.starttls == 'on':
try:
ldap_client.start_tls_s()
Expand Down Expand Up @@ -255,10 +255,14 @@ def add_to_groups(self, username, groups):
attrs = tmp[1]
attrs['dn'] = dn
for group in groups:
group = self._str(group)
for attr in self.group_attrs:
content = self.group_attrs[attr] % attrs
ldif = modlist.addModlist({ attr : content })
ldap_client.add_s(group,ldif)
content = self._str(self.group_attrs[attr] % attrs)
ldif = modlist.modifyModlist({}, { attr : content })
try:
ldap_client.modify_s(group, ldif)
except ldap.TYPE_OR_VALUE_EXISTS as e:
pass
ldap_client.unbind_s()

def del_from_groups(self, username, groups):
Expand All @@ -268,10 +272,14 @@ def del_from_groups(self, username, groups):
attrs = tmp[1]
attrs['dn'] = dn
for group in groups:
group = self._str(group)
for attr in self.group_attrs:
content = self.group_attrs[attr] % attrs
ldif = modlist.addModlist({ attr : content })
ldap_client.delete_s(group,ldif)
content = self._str(self.group_attrs[attr] % attrs)
ldif = [(ldap.MOD_DELETE, attr, content)]
try:
ldap_client.modify_s(group, ldif)
except ldap.NO_SUCH_ATTRIBUTE as e:
pass
ldap_client.unbind_s()

def search(self, searchstring):
Expand Down

0 comments on commit 0d766d3

Please sign in to comment.