我能够使用LDAP3成功连接并检索我的LDAP组成员,如下所示
from ldap3 import Server, Connection, ALL, SUBTREE
from ldap3.extend.microsoft.addMembersToGroups import ad_add_members_to_groups as addMembersToGroups
>>> conn = Connection(Server('ldaps://ldap.****.com:***', get_info=ALL),check_names=False, auto_bind=False,user="ANT\*****",password="******", authentication="NTLM")
>>>
>>> conn.open()
>>> conn.search('ou=Groups,o=****.com', '(&(cn=MY-LDAP-GROUP))', attributes=['cn', 'objectclass', 'memberuid'])
it returns True and I can see members by printing
conn.entries
>>>
上面的行表示MY-LDAP-GROUP
存在,并在搜索时返回TRUE
,但在我尝试将用户添加到组时抛出LDAP group not found,如下所示
>>> addMembersToGroups(conn, ['myuser'], 'MY-LDAP-GROUP')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/****/anaconda3/lib/python3.7/site-packages/ldap3/extend/microsoft/addMembersToGroups.py", line 69, in ad_add_members_to_groups
raise LDAPInvalidDnError(group + ' not found')
ldap3.core.exceptions.LDAPInvalidDnError: MY-LDAP-GROUP not found
>>>
返回
True
只意味着搜索成功。这并不意味着发现了什么。在conn.entries
里有什么东西吗但我怀疑你真正的问题是不同的。如果this是
ad_add_members_to_groups
的源代码,那么它需要组的distinguishedName
(注意参数名group_dn
),但是您传递的是cn
(公共名)。例如,您的代码应该类似于:如果您不知道DN,则从搜索中请求
distinguishedName
属性警告一句:
ad_add_members_to_groups
的代码在添加新成员之前检索所有当前成员。如果您与成员众多的组一起工作,您可能会遇到性能问题(例如,如果该组有1000个成员,则在添加任何成员之前将加载所有1000个成员)。您实际上不需要这样做(您可以在不查看当前成员的情况下添加新成员)。我认为他们试图避免的是,当你试图添加已经在组中的人时,会出现错误。但我认为有更好的方法来处理这个问题。如果你只与小团体合作,这对你来说可能并不重要在经历了这么多的尝试和错误后,我感到沮丧,并使用较旧的
python-ldap
库添加现有用户。现在我的代码是ldap3
和ldap
的混合体我知道这不是OP想要的。但这可能会帮助一些人
在这里,用户Dinesh Kumar已经是组group1的一部分。我想把他加进去 发送到另一个成功且不干扰现有组的组group2
相关问题 更多 >
编程相关推荐