查看活动目录用户的启用/禁用状态

发布于 2025-01-17 19:09:26 字数 1336 浏览 0 评论 0原文

使用此代码,我可以提取所有 AD 用户的信息:

var ActiveDirectory = require('activedirectory');

    var ad = new ActiveDirectory({ url: 'ldap://domain.com',
                               baseDN: 'dc=domain,dc=com',
                               username: '[email protected]',
                               password: 'password',
                               attributes: {
                                 user: [ 'givenName', 'mail', 'mobile' ],
                                //  group: [ 'anotherCustomAttribute', 'objectCategory' ]
                               }
                              });
ad.findUsers(function(err, users) {
  if (err) {
    console.log('ERROR: ' +JSON.stringify(err));
    return;
  }
 
  if ((! users) || (users.length == 0)) console.log('No users found.');
  else {
    console.log('findUsers: '+JSON.stringify(users));
  }
});

我想知道是否有办法找出启用或禁用哪个用户。我知道有一个名为 UserAccountControl 的属性,其值表示:

512=Enabled
514= Disabled
66048 = Enabled, password never expires
66050 = Disabled, password never expires

但我发现一些用户的 UserAccountControl 值与这些值不同。

我也听说过ms-DS-User-Account-Disabled,但我在用户的属性列表中找不到它。那么,我如何知道用户是否启用或禁用。

Using this code I'm able to extract all AD users' information:

var ActiveDirectory = require('activedirectory');

    var ad = new ActiveDirectory({ url: 'ldap://domain.com',
                               baseDN: 'dc=domain,dc=com',
                               username: '[email protected]',
                               password: 'password',
                               attributes: {
                                 user: [ 'givenName', 'mail', 'mobile' ],
                                //  group: [ 'anotherCustomAttribute', 'objectCategory' ]
                               }
                              });
ad.findUsers(function(err, users) {
  if (err) {
    console.log('ERROR: ' +JSON.stringify(err));
    return;
  }
 
  if ((! users) || (users.length == 0)) console.log('No users found.');
  else {
    console.log('findUsers: '+JSON.stringify(users));
  }
});

I wanted to know if there is a way to find out which user is enabled or disabled. I know that there is an attribute called UserAccountControl whose value means:

512=Enabled
514= Disabled
66048 = Enabled, password never expires
66050 = Disabled, password never expires

but I found some users whose UserAccountControl value is different from these values.

I've also heard of ms-DS-User-Account-Disabled, but I can't find it in the attribute list of users. So, how can I know if a user is enabled or disabled.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟雨扶苏 2025-01-24 19:09:26

ms-DS-User-Account-Disabled 的文档 表示仅在 ADAM(Active Directory 应用程序模式)上支持,但后来的 AD LDS (轻量级目录服务),如图所示此处

您可能拥有的 Active Directory 域服务 (AD DS) 使用 userAccountControl

userAccountControl 属性是一个位标志,这意味着二进制值中的每个位(01)都是一个标志,表示某些内容(1 已打开并且0 已关闭)。您已经发现,所有这些位的十进制表示形式可以是各种值。所以忽略十进制值。

第二位是“禁用”标志。如果第二位为1,则该帐户被禁用。这就是你想要找到的。

因此,获取 userAccountControl 属性的值,然后使用 按位 AND 运算符 (&) 来确定是否设置了第二位:

var isDisabled = (userAccountControl & 2) === 2;

其中的括号很重要,否则运算顺序不正确你 需要。

The documentation of ms-DS-User-Account-Disabled indicates that it was only supported on ADAM (Active Directory Application Mode), but also the later AD LDS (Lightweight Directory Services), as indicated here.

Active Directory Domain Services (AD DS), which is likely what you have, uses userAccountControl.

The userAccountControl attribute is a bit flag, meaning that each bit (0 or 1) in the binary value is a flag that means something (1 is on and 0 is off). The decimal representation of all those bits could be all kinds of values, so you've found. So ignore the decimal value.

The second bit is the flag for "disabled". If the second bit is 1, the account is disabled. That's what you want to find.

So get the value of the userAccountControl attribute, then use the bitwise AND operator (&) to determine if the second bit is set:

var isDisabled = (userAccountControl & 2) === 2;

The parentheses in that are important, otherwise the order of operations isn't what you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文