【问题标题】:Unable to authenticate ,enable the user in active Directory ,the user account created by using python ldap无法验证,启用活动目录中的用户,使用python ldap创建的用户帐户
【发布时间】:2016-11-01 15:04:37
【问题描述】:

这里我附上了用于在 Windows Active Directory 2008 r2 中创建用户和验证用户的 python 文件

创建.py

import ldap
import ldap.modlist as modlist
name='testing3'
password='p@ssw0rd'
l = ldap.initialize('ldap://##2.168.3#.##')
l.simple_bind_s('Administrator@example.local', 'p@ssw0rd1')
dn="cn="+name+",ou=oli,dc=example,dc=local"
attrs = {}
attrs['objectclass'] = ['Top','person','organizationalPerson','user']
attrs['cn'] = name
attrs['displayName'] = name
attrs['name'] = name
attrs['givenName'] = name
attrs['mail'] = name
attrs['ou'] = "Users"
#attrs['pwdLastSet'] = "-1"
attrs['userPrincipalName'] = name + "@naanal.local
attrs['userAccountControl'] = '514'
attrs['sAMAccountName'] = name
attrs['userPassword'] = password
ldif = modlist.addModlist(attrs)    
l.add_s(dn,ldif)
l.unbind_s()

使用此程序在 Active Directory 中创建用户但无法创建启用的用户帐户。我可以使用 userAccountcontrol=''512` 但它不工作 .userAccountcontrol='514' 它工作但用户帐户被禁用。 使用 ldap modify 更改 userAccountcontrol 出现错误“当我尝试启用用户帐户时出现错误”{'info': '0000052D: SvcErr: DSID-031A120C, 问题 5003 (WILL_NOT_PERFORM), data 0\n', 'desc ': '服务器不愿意执行'}""

Authe.py

import ldap
username='shan'
password='p@ssw0rd'
LDAP_SERVER = 'ldap://###.##.##.##'
LDAP_USERNAME = '%s@example.local' % username
LDAP_PASSWORD = password
base_dn = 'DC=example,DC=example'
ldap_filter = 'userPrincipalName=%s@example.local' % username
attrs = ['memberOf']
try:  
     ldap_client = ldap.initialize(LDAP_SERVER)   
     ldap_client.set_option(ldap.OPT_REFERRALS,0)
     ldap_client.simple_bind_s(LDAP_USERNAME, LDAP_PASSWORD)
     print 'successfull'
except ldap.INVALID_CREDENTIALS:
     ldap_client.unbind()
     print 'Wrong username ili password'
except ldap.SERVER_DOWN:
     print 'AD server not awailable'

使用 create.py 创建用户帐户。然后在活动目录中手动启用用户帐户。在我尝试验证创建的用户帐户后未检测到。但使用 authe.py 文件检测到手动创建的帐户 我正在使用 Ubuntu 14.04 64 位

【问题讨论】:

    标签: python ldap


    【解决方案1】:

    你的代码有两个问题:

    1. Active Directory 将密码存储在unicodePwd 属性中,而不是userPassword。有关更多详细信息,请参阅此link。本文还解释了必须如何对 unicodePwd 的值进行编码 (UTF-16)

    2. 另一个问题(参考文章中也对此进行了解释)是,无论何时更改密码属性(包括创建用户),都必须通过安全连接连接到 Active Directory。以ldap:// 开头的网址让我相信您的连接不安全。

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多