1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-24 10:14:31 +01:00

Updated AD backend for user creation

This commit is contained in:
Kevin Li 2019-07-08 20:48:53 +08:00
parent bc1f380084
commit e90f27bc8d
2 changed files with 31 additions and 2 deletions

View File

@ -200,6 +200,12 @@ class Backend(ldapcherry.backend.backendLdap.Backend):
else: else:
dn = self._byte_p2(name) dn = self._byte_p2(name)
ldap_client.modify_s(
dn,
[(ldap.MOD_REPLACE, 'unicodePwd', [password_value])]
)
return
attrs = {} attrs = {}
attrs['unicodePwd'] = self._modlist(self._byte_p2(password_value)) attrs['unicodePwd'] = self._modlist(self._byte_p2(password_value))
@ -217,8 +223,31 @@ class Backend(ldapcherry.backend.backendLdap.Backend):
def add_user(self, attrs): def add_user(self, attrs):
password = attrs['unicodePwd'] password = attrs['unicodePwd']
del(attrs['unicodePwd']) del(attrs['unicodePwd'])
attrs['userPrincipalName'] = '%(name)s@%(domain)s' % {
'name': attrs['sAMAccountName'], 'domain': self.domain
}
super(Backend, self).add_user(attrs) super(Backend, self).add_user(attrs)
self._set_password(attrs['cn'], password)
ldap_client = self._bind()
dn = self._byte_p2('CN=%(cn)s,%(user_dn)s' % {
'cn': attrs['cn'], 'user_dn': self.userdn
})
# Set password
encoded_password = '"{}"'.format(password).encode('utf-16-le')
ldap_client.modify_s(
dn,
[(ldap.MOD_REPLACE, 'unicodePwd', [encoded_password])]
)
# Enable user account
ldap_client.modify_s(
dn,
[(ldap.MOD_REPLACE, 'UserAccountControl', [b'512'])]
)
ldap_client.unbind_s()
def set_attrs(self, username, attrs): def set_attrs(self, username, attrs):
if 'unicodePwd' in attrs: if 'unicodePwd' in attrs:

View File

@ -5,4 +5,4 @@
# ldapCherry # ldapCherry
# Copyright (c) 2014 Carpentier Pierre-Francois # Copyright (c) 2014 Carpentier Pierre-Francois
version = '1.1.2' version = '1.1.3'