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:
parent
bc1f380084
commit
e90f27bc8d
@ -200,6 +200,12 @@ class Backend(ldapcherry.backend.backendLdap.Backend):
|
||||
else:
|
||||
dn = self._byte_p2(name)
|
||||
|
||||
ldap_client.modify_s(
|
||||
dn,
|
||||
[(ldap.MOD_REPLACE, 'unicodePwd', [password_value])]
|
||||
)
|
||||
return
|
||||
|
||||
attrs = {}
|
||||
|
||||
attrs['unicodePwd'] = self._modlist(self._byte_p2(password_value))
|
||||
@ -217,8 +223,31 @@ class Backend(ldapcherry.backend.backendLdap.Backend):
|
||||
def add_user(self, attrs):
|
||||
password = attrs['unicodePwd']
|
||||
del(attrs['unicodePwd'])
|
||||
attrs['userPrincipalName'] = '%(name)s@%(domain)s' % {
|
||||
'name': attrs['sAMAccountName'], 'domain': self.domain
|
||||
}
|
||||
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):
|
||||
if 'unicodePwd' in attrs:
|
||||
|
@ -5,4 +5,4 @@
|
||||
# ldapCherry
|
||||
# Copyright (c) 2014 Carpentier Pierre-Francois
|
||||
|
||||
version = '1.1.2'
|
||||
version = '1.1.3'
|
||||
|
Loading…
Reference in New Issue
Block a user