【问题标题】:ldap3 extend.microsoft.modify_password keeps returning falseldap3 extend.microsoft.modify_password 不断返回 false
【发布时间】:2022-12-16 21:34:01
【问题描述】:

我正在尝试修改用户帐户密码,但它不起作用,我直接在 AD 中尝试过,它确实有效。我正在使用 ldap3 来执行此操作,这是我执行的步骤。

首先,我像这样进行应用操作

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'})

这个有效。

然后我尝试设置密码

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')

像这样,但最后一行一直返回 False。

你知道为什么吗?谢谢你。

【问题讨论】:

    标签: python python-3.x active-directory ldap ldap3


    【解决方案1】:

    根据this

    我查看了源代码,它说旧密码必须是 None 才能以足够的权限重置密码

    这应该有效:

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

    并且连接必须加密。您可能必须指定 ldaps://,即使您指定了 use_ssl,因为 LDAPS 端口 (636) 与常规 LDAP 端口 (389) 不同。

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

    【讨论】:

    • 我试过了,但它不起作用,当我输入 "ldaps://192.168.x.xx" 时,它返回错误
    • 所以,我想我明白了,为什么我无法连接 ssl。我的服务器上没有配置,我试试,然后回来告诉你是否可以
    • 嗨@Fujah,你找到解决方案了吗?请分享您的发现。
    • 是的,解决方案是在 ldap 上设置 ssl 并使用 ldaps://192.168.x.xx 访问
    【解决方案2】:

    解决方案是在我的 ldap 上设置 ssl 并且它有效。

    【讨论】:

      猜你喜欢
      • 2015-07-24
      • 1970-01-01
      • 2022-01-24
      • 2021-02-13
      • 1970-01-01
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多