mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 09:24: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)
|
ad_groups.append('cn=' + group + ',' + self.groupdn)
|
||||||
return ad_groups
|
return ad_groups
|
||||||
|
|
||||||
def _set_password(self, cn, password):
|
def _set_password(self, name, password, by_cn=True):
|
||||||
unicode_pass = '\"' + password + '\"'
|
unicode_pass = '\"' + password + '\"'
|
||||||
password_value = unicode_pass.encode('utf-16-le')
|
password_value = unicode_pass.encode('utf-16-le')
|
||||||
|
|
||||||
ldap_client = self._bind()
|
ldap_client = self._bind()
|
||||||
|
|
||||||
dn = self._str('CN=%(cn)s,%(user_dn)s' % {
|
if by_cn:
|
||||||
'cn': cn,
|
dn = self._str('CN=%(cn)s,%(user_dn)s' % {
|
||||||
'user_dn': self.userdn
|
'cn': name,
|
||||||
})
|
'user_dn': self.userdn
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
dn = name
|
||||||
|
|
||||||
attrs = {}
|
attrs = {}
|
||||||
|
|
||||||
@ -201,7 +204,8 @@ class Backend(ldapcherry.backend.backendLdap.Backend):
|
|||||||
password = attrs['unicodePwd']
|
password = attrs['unicodePwd']
|
||||||
del(attrs['unicodePwd'])
|
del(attrs['unicodePwd'])
|
||||||
super(Backend, self).add_user(attrs)
|
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):
|
def set_attrs(self, username, attrs):
|
||||||
if 'unicodePwd' in attrs:
|
if 'unicodePwd' in attrs:
|
||||||
|
Loading…
Reference in New Issue
Block a user