zakird / pyad

Python Active Directory Tools | *Not actively maintained*
http://zakird.github.io/pyad/
176 stars 72 forks source link

unable to create user - character limit 20 #62

Closed hdep closed 7 years ago

hdep commented 7 years ago

Hello,

I try to create a user as following :

ou = pyad.adcontainer.ADContainer.from_dn("OU=Users, DC=company, DC=local")
new_user = pyad.adcontainer.ADUser.create("Anne XXXXXX XXX XXXXXXXX", ou, password="Passw0rd", upn_suffix="@company.local", optional_attributes = {"samaccountname":"htest","userPrincipalName":login + "@company.local","givenname":"Hugo","sn":"Test","displayName":"Hugo Test"})

I got an error :

c:\>C:\Users\hugo\Desktop\user_ad.py
Traceback (most recent call last):
  File "C:\Users\hugo\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyad\adcontainer.py", line 38, in create_user
    obj.SetInfo()
  File "<COMObject <unknown>>", line 2, in SetInfo
pywintypes.com_error: (-2147352567, 'Une exception s\u2019est produite.', (0, 'A
ctive Directory', 'Un périphérique attaché au système ne fonctionne pas correcte
ment.\r\n', None, 0, -2147024865), None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\hugo\Desktop\user_ad.py", line 13, in <module>
    new_user = pyad.adcontainer.ADUser.create("Anne XXXXXX XXX XXXXXXXX", ou, pa
ssword="Passw0rd", upn_suffix="@company.local", optional_attributes = {"samaccou
ntname":"htest","userPrincipalName":login + "@company.local","givenname":"Hugo",
"sn":"Test","displayName":"Hugo Test"})
  File "C:\Users\hugo\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyad\aduser.py", line 16, in create
    optional_attributes=optional_attributes
  File "C:\Users\hugo\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyad\adcontainer.py", line 47, in create_user
    pyadutils.pass_up_com_exception(e)
  File "C:\Users\hugo\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyad\pyadutils.py", line 58, in pass_up_com_exception
    raise WIN32_ERRORS.get(info['error_num'], win32Exception)(error_info=info, a
dditional_info=additional_info)
pyad.pyadexceptions.win32Exception: 0x8007001f: Un périphérique attaché au systè
me ne fonctionne pas correctement.

After some test it appears that it works if name field is 20 character max. Are you aware of this limitation ? from windows point of view it should be OK.

Regards,

hdep commented 7 years ago

It seems that this is a windows 2012 limitation for samaccountname (20 character max). So there is something I don't understand with this lib about the first field.