mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-21 17:04:21 +01:00
fix self user password modification in AD Backend
In some forms, the 'cn' attribute might not be accessible. The _set_password method relied on 'cn' to build the user dn. Now it accepts the cn or the dn (by_cn switch).
This commit is contained in:
parent
6ef44b9b2e
commit
320f57ab76
@ -174,16 +174,19 @@ class Backend(ldapcherry.backend.backendLdap.Backend):
|
||||
ad_groups.append('cn=' + group + ',' + self.groupdn)
|
||||
return ad_groups
|
||||
|
||||
def _set_password(self, cn, password):
|
||||
def _set_password(self, name, password, by_cn=True):
|
||||
unicode_pass = '\"' + password + '\"'
|
||||
password_value = unicode_pass.encode('utf-16-le')
|
||||
|
||||
ldap_client = self._bind()
|
||||
|
||||
dn = self._str('CN=%(cn)s,%(user_dn)s' % {
|
||||
'cn': cn,
|
||||
'user_dn': self.userdn
|
||||
})
|
||||
if by_cn:
|
||||
dn = self._str('CN=%(cn)s,%(user_dn)s' % {
|
||||
'cn': name,
|
||||
'user_dn': self.userdn
|
||||
})
|
||||
else:
|
||||
dn = name
|
||||
|
||||
attrs = {}
|
||||
|
||||
@ -201,7 +204,8 @@ class Backend(ldapcherry.backend.backendLdap.Backend):
|
||||
password = attrs['unicodePwd']
|
||||
del(attrs['unicodePwd'])
|
||||
super(Backend, self).add_user(attrs)
|
||||
self._set_password(attrs['cn'], password)
|
||||
userdn = self._get_user(username, NO_ATTR)
|
||||
self._set_password(userdn, password, False)
|
||||
|
||||
def set_attrs(self, username, attrs):
|
||||
if 'unicodePwd' in attrs:
|
||||
|
Loading…
Reference in New Issue
Block a user