大网数据广告活动
服务器运维问答

How to remove a user from an OpenLDAP group using Python ldap3 module?

· 52CE 我爱测

I'm trying to manage group memberships for users in an OpenLDAP directory using the Python ldap3 module. The docs for the Delete operation show how to remove a user from an OU , however I simply want to remove memberUid entries i…

问题原文

原帖链接 · Server Fault · CC BY-SA 4.0

I'm trying to manage group memberships for users in an OpenLDAP directory using the Python ldap3 module. The docs for the Delete operation show how to remove a user from an OU, however I simply want to remove memberUid entries in POSIX group objects, as well as the member entries in groupOfName objects.

I tried to use the c.delete() call to do this without success. Is there another way?

My group object looks like this:

dn: cn=sales,ou=groups,dc=mycorp,dc=net
cn: sales
gidNumber: 12009
objectClass: posixGroup
objectClass: top
memberUid: milton
memberUid: trebor
memberUid: yggdrasil

The only incantation (obviously wrong) I can come up with is this:

   conn.delete ('memberUid=milton,cn=sales,ou=groups,dc=mycorp,dc=net')

The result is:

ldap3.core.exceptions.LDAPNoSuchObjectResult: LDAPNoSuchObjectResult - 32 - noSuchObject - cn=sales,ou=groups,dc=mycorp,dc=net - None - delResponse - None

已采纳解答

原帖链接 · Server Fault · CC BY-SA 4.0

In case it helps someone else, instead of conn.delete I had to use the modify method with the MODIFY_DELETE operation, while pointing at the group DN with the memberUid attribute and member to remove.

result = conn.modify("cn=sales,ou=groups,dc=mycorp,dc=net", {'memberUid': [(MODIFY_DELETE, ['milton'])]})

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-10-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。