Python LDAP

编程入门 行业动态 更新时间:2024-10-28 19:29:45
Python LDAP - 将用户移动到不同的OU(Python LDAP - Move user to different OU)

背景: 我一直在我的Linux机器上使用python-ldap模块来管理远程Windows Server 2008上的用户帐户。我已经能够搜索,创建和修改用户,但更改用户的“ou”除外。

我尝试过使用'modify_s'和'modrdn_s',但由于modrdn只允许你改变dn的第一部分,我没有运气修改'ou'或将用户移动到新的'ou'。

暂时我正在创建一个新用户并从旧用户复制我能够的所有属性,然后删除旧用户。 但这不允许我保留用户创建日期和其他不可编辑的信息。

我已经彻底搜索了互联网并找到了一些解决方案,但是: 在其他操作系统上: 如何使用Python将用户移动到其他OU 和其他编程语言: Active Directory LDAP将用户移动到不同的OU - Ruby 这可能在Linux上的python-ldap中还是有任何解决方法? 谢谢!

Background: I have been using the python-ldap module on my Linux machine to manage user accounts on a remote Windows Server 2008. I have been able to search for, create, and modify users, with the exception of changing a user's 'ou'.

I have tried using 'modify_s' and 'modrdn_s' but since modrdn only allows you to change the first part of a dn, I haven't had luck modifying the 'ou' or moving a user to a new 'ou'.

Temporarily I am creating a new user and copying all the attributes that I am able to from the old user, then deleting the old user. But this doesn't allow me to retain the user creation date and other un-editable information.

I have thoroughly searched the internet and found a few solutions, but: on other operating systems: How do you move a user to a different OU using Python and other programming languages: Active Directory LDAP move user to different OU - Ruby Is this possible in python-ldap on Linux or are there any work-arounds? Thank you!

最满意答案

您需要使用rename_s并指定newsuperior参数。

快速示例代码:

ldap.rename_s('cn=UserName,ou=OldContainer,dc=example,dc=com', 'cn=UserName', 'ou=NewContainer,dc=example,dc=com')

You need to use rename_s and specify the newsuperior parameter.

Quick sample code:

ldap.rename_s('cn=UserName,ou=OldContainer,dc=example,dc=com', 'cn=UserName', 'ou=NewContainer,dc=example,dc=com')

更多推荐

本文发布于:2023-07-15 22:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1119411.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Python   LDAP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!