【发布时间】:2017-08-31 20:45:35
【问题描述】:
首先,我使用 Python 才大约 5 个月。我一直在尝试编写一个将(最终)进行批量用户创建的程序。当像下面这样格式化时,它将成功创建一个新的用户对象,但“userAccountControl”属性将默认为 546,ACCOUNTDISABLE | PASSWD_NOTREQD | NORMAL_ACCOUNT,“userPass”的值将在 AD 中对象的属性编辑器中以八位字节字符串的形式显示为纯文本。该程序正在使用 ldap3 库:https://pypi.python.org/pypi/ldap3
class fromconfig:
def __init__(self):
Config = configparser.ConfigParser()
Config.read("config.ini")
self.serverip = Config.get('serverinfo', 'ip')
self.basepath = Config.get('serverinfo', 'base')
self.container = Config.get('serverinfo', 'container')
self.dc1 = Config.get('serverinfo', 'dc1')
self.dc2 = Config.get('serverinfo', 'dc2')
self.ou = Config.get('serverinfo', 'ou')
def add_user(username, givenname, surname, userPrincipalName, SAMAccountName, userPassword):
ad_server = Server(config.serverip, use_ssl=True, get_info=ALL)
ad_c = Connection(ad_server, user='domain\\user', password='password', authentication=NTLM)
if ad_c.bind():
ad_c.add('cn={},cn={},dc={},dc={}'.format(username, config.ou, config.dc1, config.dc2), ['person', 'user'], {'givenName': givenname, 'sn': surname, 'userPrincipalName': userPrincipalName, 'sAMAccountName': SAMAccountName, 'userPassword': userPassword})
print(ad_c.result)
ad_c.unbind()
我希望能够在程序中为 userAccountControl 定义一个 512 值,或者以其他方式成功启用该帐户,这样我就不必在以后返回并取消选中 AD 中的“帐户已禁用”。当我尝试通过它时,ad_c.result 返回错误 53。这与我通过 AD 进入并尝试直接修改属性或取消选中禁用帐户复选框时收到的错误相同。 AD 服务器上的错误 53 对话框显示“密码不符合长度或复杂性要求”,但我用于测试的密码是我过去在 AD 上使用的密码,没有任何问题。所以我认为这个问题与 userPassword 的存储方式有关,而不是复杂性或权限。
【问题讨论】:
标签: python active-directory ldap