gpt4 book ai didi

linux - Active Directory 上的 LDAP 搜索

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:22:06 26 4
gpt4 key购买 nike

我正在尝试发出请求以查找将在 30 天内到期的所有帐户(来自 Linux 服务器,因此使用 ldapsearch)。

这是我发送到 AD 服务器的请求:

ldapsearch -x -h IP -D "[domain][user]"-w [password] -b "DC=[DC],DC=[DC]"-s sub "(&(objectCategory=person) (objectClass=user)(accountExpires>=1)(accountExpires<=30))"

我没有得到任何名称,因为所有帐户似乎都有一个 accountExpires 为 0 或 2^63 -1。

当我从 windows powershell(在 windows 服务器上)启动这个请求时,我得到了正确的答案:

搜索-ADAccount -AccountExpiring -TimeSpan 30.00:00:00 |其中 {$_.ObjectClass -eq 'user'} |金融时报名称,对象类 –A

你能解释一下为什么我的 ldapsearch 没有给出相同的结果吗?

谢谢!

最佳答案

accountExpires 属性的格式是自 1601 年 1 月 1 日(UTC)以来的 100 纳秒间隔数。参见 these details对于属性:

The date when the account expires. This value represents the number of 100-nanosecond intervals since January 1, 1601 (UTC). A value of 0 or 0x7FFFFFFFFFFFFFFF (9223372036854775807) indicates that the account never expires.

因此,您需要将 Linux/Unix 时间戳格式化为该格式,以获得发送到 AD 的正确值。它可能类似于(请原谅糟糕的 bash 技能...):

# Get the windows timestamp value for 30 days from now...
expires_at=$(($(($(date -d "+30 days" +"%s") * 10000000)) + 116444736000000000))

然后是 LDAP 过滤器:

(&(objectCategory=person)(objectClass=user)(accountExpires>=1)(accountExpires<=$expires_at))

关于linux - Active Directory 上的 LDAP 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41721710/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com