简体   繁体   English

使用ldap3 Python获取Active Directory中的用户状态(禁用或活动)

[英]Get user status (disabled or active) in Active Directory with ldap3 Python

I am getting a list of all users in Active Directory and I need to check their status — if the user is active or disabled. 我正在获取Active Directory中所有用户的列表,我需要检查其状态-用户是处于活动状态还是处于禁用状态。 I expect that userAccountControl should return user status, but I get only 512 for all users but one (who returns 66048) and this is not correlated with user status (as far as I know). 我希望userAccountControl应该返回用户状态,但是对于所有用户,我只能得到512,但一个用户(返回66048)却与用户状态无关(据我所知)。

from ldap3 import Server, Connection

serverName = 'LDAP://server'
domainName = 'name'
userName = 'superuser'
password = 'password'
base = 'longString'

server = Server(serverName)
conn = Connection(server, read_only=True, user='{0}\\{1}'.format(domainName, userName), password=password, auto_bind=True)

conn.search(base, '(objectclass=person)', attributes=['displayName', 'mail', 'userAccountControl','sAMAccountName'])

for i in conn.entries:
    print 'USER = {0} : {1} : {2}'.format(i.sAMAccountName.values[0], i.displayName.values[0], i.userAccountControl.values[0])

USER = ABC : John Smith : 512 USER = DEF : Sarah Connor : 514 USER = GHI : Thomas Anderson : 66048 用户= ABC:约翰史密斯:512用户=默认:萨拉·康纳:514用户= GHI:托马斯·安德森:66048

Is it a correct way to get user status? 这是获取用户状态的正确方法吗? Is there any other way to check AD user status with some application with UI? 还有其他方法可以通过带有UI的某些应用程序检查AD用户状态吗?

According to userAccountControl flags : 根据userAccountControl标志

512 - Normal account (512), 512-普通帐户(512),

514 - Disable account (2 + 512), 514-停用帐户(2 + 512),

66048 - Normal account + dont expire password (65536 + 512). 66048-普通帐户+不要过期密码(65536 + 512)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ldap3 python 搜索组成员并检索他们的 sAMAcountName (Active Directory) - ldap3 python search members of a group and retrieve their sAMAcountName (Active Directory) 如何使用 Python LDAP3 列出自己的 Active Directory 组成员身份? - How to list own Active Directory group memberships with Python LDAP3? 通过 LDAP (ldap3 Python) 从 Windows 服务器的 Active Directory 获取所有用户信息 - Getting all usersinfos from Windows server's Active Directory via LDAP (ldap3 Python) 如何使用活动目录中的ldap3将现有条目(用户)添加到现有组 - How to add existing entry (user) to an existing group using ldap3 in active directory 使用ldap3 python进行Active Directory身份验证,如何避免明文密码 - Active Directory authentication using ldap3 python, how to avoid clear text password 通过ldap python将用户添加到活动目录 - add user to active directory by ldap python Python LDAP和Active Directory问题 - Python LDAP and Active Directory issue 使用 ldap python 启用 Active Directory 用户帐户 - Enable Active Directory user account using ldap python 使用 Python ldap 模块解锁 Active Directory 上的锁定用户帐户 - unlocking Locked user accounts on Active Directory using Python ldap module 在 Python 中使用 LDAP 检测 Active Directory 用户帐户是否被锁定 - Detect if an Active Directory user account is locked using LDAP in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM