0

基本的に、LDAP python を使用してユーザーのパスワードをリセットしようとしています。ここでさまざまな投稿を行いましたが、運がありません:(。

使用してみました:

  • a) modify_s() - 毎回「そのようなオブジェクトはありません」を返します。別のユーザー DN で試行しました。

    {'info': "0000208D: NameErr: DSID-0310020A, problem 2001 (NO_OBJECT), data 0, best match of:\n\t'DC=mydomain,DC=com'\n", 'matched': 'DC =mydomain,DC=com', 'desc': 'そのようなオブジェクトはありません'}

    コード スニペットは次のとおりです。

    def changePassword(userEmail, oldPassword, newPassword):
     try:
        ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
    
        ldap_client = ldap.initialize("ldap://127.0.01.1:389")
        ldap_client.set_option(ldap.OPT_REFERRALS, 0)
        ldap_client.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
        ldap_client.set_option(ldap.OPT_X_TLS,ldap.OPT_X_TLS_DEMAND)
        ldap_client.set_option( ldap.OPT_X_TLS_DEMAND, True )
        ldap_client.set_option( ldap.OPT_DEBUG_LEVEL, 255 )
        ldap_client.simple_bind_s(ADMIN_EMAIL, ADMIN_PASSWORD)
    
        # Set AD password
        #unicode_pass = unicode('\"' + newPassword + '\"', "iso-8859-1")
        unicode_pass = newPassword
        password_value = unicode_pass.encode("utf-16-le")
        add_pass = [(ldap.MOD_REPLACE, 'unicodePwd', [password_value]),( ldap.MOD_REPLACE, 'unicodePwd', [password_value])]
    
        # Replace password
        try:
          user_dn = 'CN=%s,DC=mydomain,DC=com' % username
          ldap_client.modify_s(user_dn, add_pass)
          print "Active Directory password for", username, \
                "was set successfully!"
        except ldap.LDAPError, e:
          sys.stderr.write('Error setting AD password for: ' + username + '\n')
          sys.stderr.write('Message: ' + str(e) + '\n')
          ldap_client.unbind_s()
          return 'SOME_PROBLEM'
        ldap_client.unbind_s()
        return 'AUTHENTICATED'
    except ldap.INVALID_CREDENTIALS:
        ldap_client.unbind()
        return 'INVALID_CREDENTIALS'
    except ldap.SERVER_DOWN:
        return 'SERVER_UNAVAILABLE'
    
  • b) passwd(userEmail, oldPassword, newPassword). うまく実行されますが、パスワードは更新されません。

問題を特定するのに助けが必要です。

参照リンク: Python+LDAP+SSL

python-ldap と Microsoft Active Directory: ユーザーの接続と削除

Active DirectoryのユーザーのlockoutTimeとパスワードの設定方法

Python を使用してドメイン ユーザー (Windows Active Directory) のパスワードを変更するにはどうすればよいですか?

https://groups.google.com/forum/#!topic/macromedia.coldfusion.security/Rq7xx15OeBs

http://www.grotan.com/ldap/python-ldap-samples.html#add

http://marcitland.blogspot.in/2011/02/python-active-directory-linux.html

https://snipt.net/Fotinakis/change-active-directory-password-via-ldap-modify-call/

4

3 に答える 3