Skip to content

Commit

Permalink
fix self user password modification in AD Backend
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
kakwa committed Jul 21, 2016
1 parent 6ef44b9 commit 320f57a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions ldapcherry/backend/backendAD.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,19 @@ def _build_groupdn(self, groups):
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 = {}

Expand All @@ -201,7 +204,8 @@ def add_user(self, attrs):
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:
Expand Down

0 comments on commit 320f57a

Please sign in to comment.