简体   繁体   中英

How to change the user password using ldap passwd_s function

I would like to change the user's password by supplying the old and the new password.

import ldap
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
ldap.set_option(ldap.OPT_REFERRALS, 0)

con = ldap.initialize("ldaps://ldaps-direct.prod.mydomain.com")

tdn = "CN=test_user,OU=ServiceAccounts,OU=UserBase,DC=corp,DC=mydomain,DC=com"
new_password = "new_password"
old_password = "old_password"

client.passwd_s(tdn, '"%s"' % old_password, '"%s"' % new_password )

Unfortunately I am getting the error:

ldap.PROTOCOL_ERROR: {'desc': 'Protocol error', 'info': '0000203D: LdapErr: DSID-0C090F8B, comment: Unknown extended request OID, data 0, v2580'}

Is there a way to fix it?

Microsoft AD is not fully compliant to the LDAPv3 standard. I'm not sure if it supports the ldappasswd operation.

From the python-ldap documentation :

For LDAP operations the module wraps OpenLDAP's client library, libldap.

So there is high chance it will not handle the specifics of AD

There is a python module which has a specific operation to change microsoft password : https://ldap3.readthedocs.io/ldap3.extend.microsoft.modifyPassword.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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