簡體   English   中英

錯誤 - UNWILLING_TO_PERFORM - 在 AD ldap 中使用 python 代碼更改用戶密碼時

[英]Error - UNWILLING_TO_PERFORM - while change user password in AD ldap using python code

我正在創建一個簡單的 python function 來更改用戶密碼。 我已經測試了我的 AD 設置,能夠搜索用戶並獲得正確的響應,但是當嘗試運行 l.modify_s 時,我收到以下錯誤。 AD 用戶具有所需的權限。 不知道為什么我會收到這個錯誤。

任何幫助都會很棒。 如果您還需要更多信息或代碼以更好地理解問題,請告訴我。

  "errorType": "**UNWILLING_TO_PERFORM**",
  "errorMessage": "{'info': u'0000001F: SvcErr: DSID-031A12D2, problem 5003 (WILL_NOT_PERFORM), data 0\\n', 'msgid': 3, 'msgtype': 103, 'result': 53, 'desc': u'Server is unwilling to perform', 'ctrls': []}"
}```

Please find my code below

``` import ldap
import os
import boto3
import random
import string

from base64 import b64decode

import ldap

def lambda_handler(event, context): 
    try:
        cert = os.path.join('/Users/marsh79/Downloads', 'Serverssl.cer')
        print "My cert is", cert
        # LDAP connection initialization
        l = ldap.initialize('ldap://example.corp.com')
        # Set LDAP protocol version used
        l.protocol_version = ldap.VERSION3
        #Force cert validation
        l.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_DEMAND)
        # Set path name of file containing all trusted CA certificates
        l.set_option(ldap.OPT_X_TLS_CACERTFILE, cert)
        # Force libldap to create a new SSL context (must be last TLS option!)
        l.set_option(ldap.OPT_X_TLS_NEWCTX, 0)

        bind = l.simple_bind_s("admin@corp.example.com", "secret_pass")
 
        base = "OU=Enterprise,OU=Users,OU=corp,DC=corp,DC=example,DC=com"
        criteria = "(objectClass=user)"
        attributes = ['distinguishedName']
        result = l.search_s(base, ldap.SCOPE_SUBTREE, criteria, attributes)
 
        results = [entry for dn, entry in result if isinstance(entry, dict)]
        
        new_password='secretpass_new'
        unicode_pass = unicode('\"' + new_password + '\"', 'iso-8859-1')
        password_value = unicode_pass.encode('utf-16-le')
        add_pass = [(ldap.MOD_REPLACE, 'unicodePwd', [password_value])]
        
        print "My result distinguishedName1:", results[0]['distinguishedName'][0]
        print "My result distinguishedName2:", results[1]['distinguishedName'][0]

        
        l.modify_s(results[0]['distinguishedName'][0],add_pass)
        
        print results
        
    finally:
        l.unbind()

我檢查了很多東西

  1. 密碼復雜度很好
  2. 在我的 AD 服務器上啟用了安全的 ldap 並使用 ldp.exe 對此進行了測試,我可以使用端口 636 進行連接
  3. 如果我只需要搜索用戶,我就可以運行此代碼。 我得到搜索結果。
  4. 但是當我嘗試修改密碼時,它就壞了,我的腦袋只是想弄清楚哪里出了問題:X

我不是 Python 程序員,但我知道 AD 和 LDAP 是如何工作的。 它可能仍未通過 LDAPS 連接。 從我在網上看到的示例中,您可能需要指定ldaps://

l = ldap.initialize('ldaps://<server name>.corp.example.com')

或者也可能是端口:

l = ldap.initialize('ldaps://<server name>.corp.example.com:636')

您不需要在客戶端提供證書文件,但服務器上的證書頒發者必須受到客戶端計算機的信任。 我想這就是你試圖用cert做的事情。 但您可能不必這樣做。 嘗試不使用它,看看會發生什么。 如果您在 Windows 上運行它,它可能會使用 Windows 本身的可信證書存儲,只要服務器不使用自簽名證書,它就應該可以工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM