首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用python-ldap添加组

使用python-ldap添加组
EN

Stack Overflow用户
提问于 2016-04-25 06:15:10
回答 1查看 3.5K关注 0票数 3

我需要加入有几个成员的小组。所以我使用下面的代码

代码语言:javascript
复制
import ldap
import ldap.modlist as modlist

# Open a connection
l = ldap.initialize("ldap://localhost:389/")

# Bind/authenticate with a user with apropriate rights to add objects
l.simple_bind_s("cn=manager,dc=maxcrc,dc=com","secret")

# The dn of our new entry/object
dn="cn=semuaFK,ou=group,dc=maxcrc,dc=com" 

# A dict to help build the "body" of the object
attrs = {}
attrs['objectclass'] = ['top','groupofnames']
attrs['member'] = 'cn=user1,ou=people,dc=maxcrc,dc=com'
attrs['member'] = 'cn=user2,ou=people,dc=maxcrc,dc=com'
attrs['description'] = 'ini group untuk semua dosen dokter'

# Convert our dict to nice syntax for the add-function using modlist-module
ldif = modlist.addModlist(attrs)

# Do the actual synchronous add-operation to the ldapserver
l.add_s(dn,ldif)

# Its nice to the server to disconnect and free resources when done
l.unbind_s()

在组中添加成员

代码语言:javascript
复制
attrs['member'] = 'cn=user1,ou=people,dc=maxcrc,dc=com'
attrs['member'] = 'cn=user2,ou=people,dc=maxcrc,dc=com'

但结果是一个只有一个成员的团体。只将user2添加到组中。如何组成一个组,还添加了几个成员

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-26 02:46:01

member是一个多值属性(与objectClass一样)。从代码来看,问题似乎是用第2行覆盖了member属性的值。代码应该如下所示:

代码语言:javascript
复制
attrs['member'] = [ 'cn=users1,ou=people,dc=maxcrc,dc=com', 'cn=users2,ou=people,dc=maxcrc,dc=com' ]`

代码语言:javascript
复制
attrs['member'] = [ 'cn=users1,ou=people,dc=maxcrc,dc=com' ]
attrs['member'] += 'cn=users2,ou=people,dc=maxcrc,dc=com'
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36833231

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档