简体   繁体   English

ldap3 extend.microsoft.modify_password 不断返回 false

[英]ldap3 extend.microsoft.modify_password keeps returning false

I'm trying to modify an user account password in but it doesn't work, I've tried it directly in AD and it does work.我正在尝试修改用户帐户密码,但它不起作用,我直接在 AD 中尝试过,它确实有效。 I'm using ldap3 to do it, here's the steps I do.我正在使用 ldap3 来执行此操作,这是我执行的步骤。

First I do the app operation like this首先,我像这样进行应用操作

from ldap3 import Server, Connection, ALL
s = Server("ldap://192.168.x.xx", use_ssl=True)
c = Connection(s, user='adminldap', password='xxxxxxx')
c.bind()
c.add('cn=jtest,ou=users,ou=MJC,dc=mjc,dc=lan', ['user', 'posixGroup', 'top'], {'cn': 'jtest', 'sAMAccountName':'jtest', 'mail':'jtest@gmail.com','telephoneNumber':'0102030405','displayName':'jtest'})

This one works.这个有效。

Then I try to set the password然后我尝试设置密码

Path_Root = "ou=users,ou=MJC,DC=mjc,DC=lan"
Filter = "(&(objectclass=user)(&(sAMAccountName=jtest)(!(objectclass=computer))))"
c.search(search_base = Path_Root,search_filter = Filter,attributes = ["cn", "sAMAccountName", "displayName"])
if len(c.entries) == 1:
   USER_DN = c.response[0].get("dn")
   c.extend.microsoft.modify_password(USER_DN, 'Formation123')

Like this but the last line keeps returning False.像这样,但最后一行一直返回 False。

Have you got an idea why?你知道为什么吗? Thank you.谢谢你。

According to this : 据此

I looked into the source and it says old password must be None to reset password with sufficient privileges我查看了源代码,它说旧密码必须是 None 才能以足够的权限重置密码

This should work:这应该有效:

 c.extend.microsoft.modify_password(USER_DN, 'Formation123', old_password=None)

And the connection has to be encrypted.并且连接必须加密。 You may have to specify ldaps:// even though you specified use_ssl , since the LDAPS port (636) is different than the regular LDAP port (389).即使您指定use_ssl ,您也可能必须指定ldaps:// ,因为 LDAPS 端口 (636) 与常规 LDAP 端口 (389) 不同。

s = Server("ldaps://192.168.x.xx", use_ssl=True)

the solution was setting ssl on my ldap and it worked.解决方案是在我的 ldap 上设置 ssl 并且它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM