【发布时间】: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 位
【问题讨论】: