Enable/Disable account programmatically using Python ldap module?(使用 Python ldap 模块以编程方式启用/禁用帐户?)
问题描述
我想以编程方式启用/禁用 LDAP 用户帐户.从命令提示符我可以使用 dsutil ,这显然设置/删除 nsAccountLock 操作属性.我试图做 modify_s() 以在 Python 中设置和删除此属性,但始终收到以下错误消息:对条目 '' 的 'nsAccountLock' 属性的'写入'权限不足".
I would like to programmatically enable/disable LDAP user accounts. From the command prompt I can use dsutil and this apparently sets/removes the nsAccountLock operational attribute. I have attempted to do modify_s() to set and remove this attribute from w/in Python but always get the following error message: "Insufficient 'write' privilege to the 'nsAccountLock' attribute of entry ''".
有没有办法通过 Python 以编程方式设置/删除/添加操作属性或启用/禁用 ldap 用户?
Is there a way to set/remove/add operational attributes or otherwise enable/disable ldap users programmatically through Python?
谢谢,C
推荐答案
您应该使用包含一组控制位的属性userAccountControl".
You should use the attribute 'userAccountControl' which contains a set of control bits.
如果你是管理普通用户,启用用户:
If you are managing normal users, to enable user:
userAccountControl = 512
并禁用它:
userAccountControl = 514
一般来说,如果您想启用/禁用现有用户,您应该检索当前值并以这种方式更新它.
Generally, if you want to enable/disable an existing user, you should retrieve current value and update it this way.
userADAccountControlFlag = 2
userAccountControl = user.userAccountControl
# To enable user:
userAccountControl = userAccountControl & ~userADAccountControlFlag # (& bit-wise AND, ~ bit-wise Negate)
# To disable user:
userAccountControl = userAccountControl | userADAccountControlFlag # (| bit-wise OR)
user.userAccountControl = userAccountControl
# Then update user on ldap server
您可以在此处找到有关 userAccountControl 属性的更多信息:http://www.selfadsi.org/ads-attributes/user-userAccountControl.htm
you can find more about userAccountControl attribute here: http://www.selfadsi.org/ads-attributes/user-userAccountControl.htm
这篇关于使用 Python ldap 模块以编程方式启用/禁用帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Python ldap 模块以编程方式启用/禁用帐户?
基础教程推荐
- 修改列表中的数据帧不起作用 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 包装空间模型 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
