加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python-3.x – 无法通过ldap3 Python3更改用户密码

发布时间:2020-12-20 11:52:32 所属栏目:Python 来源:网络整理
导读:每当我尝试通过ldap3库更改某人的密码时,我会收到以下错误: {'type': 'modifyResponse','result': 53,'message': '0000001F: SvcErr: DSID-031A12D2,problem 5003 (WILL_NOT_PERFORM),data 0nx00','referrals': None,'description': 'unwillingToPerform'
每当我尝试通过ldap3库更改某人的密码时,我会收到以下错误:

{'type': 'modifyResponse','result': 53,'message': '0000001F: SvcErr: DSID-031A12D2,problem 5003 (WILL_NOT_PERFORM),data 0nx00','referrals': None,'description': 'unwillingToPerform','dn': ''}

由于以下两个条件,通常会发生此错误:用户尝试通过未加密的连接修改密码,或者使用不正确的编码发送密码.我的SSL连接很好(至少看起来像是这样):

print(connection)
>>> ldaps://DC1.DOMAIN.LOCAL:636 - ssl - user: DOMAINadmin - not lazy - bound - open - <local: 172.16.10.2:49230 - remote: 172.16.10.254:636> - tls not started - listening - SyncStrategy - internal decoder

我试图编码我正在尝试发送到LDAP服务器的字符串,但.encode(‘utf-16le’)没有做到这一点.还有其他解决方法吗?

我有一个测试域环境,Windows Server 2012 R2作为域控制器,我正在尝试更改密码的代码如下所示.

import ssl
from ldap3 import *

tls_configuration = Tls(validate=ssl.CERT_REQUIRED,version=ssl.PROTOCOL_TLSv1_2)
s = Server('DC1.domain.local',get_info=ALL,use_ssl=True,tls=tls_configuration)
password = 'mypasswordhere'
c = Connection(s,user="DOMAINadmin",password=password)
c.open()
c.bind()

user = "CN=Dummy Dumass,OU=Automatically Generated,OU=Staff,OU=RU,DC=DOMAIN,DC=LOCAL"

c.modify(user,{
    'unicodePwd': [(MODIFY_REPLACE,['New12345'])]
})

print(c.result)
c.unbind()

解决方法

ldap3包含一个更改AD密码的特定方法,使用以下代码而不是c.modify():

c.extend.microsoft.modify_password(user,new_password)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读