如何获取 Ldap 用户更改的属性而不是所有用户属性

How to get Ldap user changed attributes instead of all user attributes

有没有办法获取用户更改的属性而不是所有用户属性?

import ldap
l = ldap.initialize("ldap://localhost")
l.protocol_version = 3
l.bind_s("cn=admin,dc=example,dc=org", "admin")
r = l.search_ext("dc=example,dc=org", ldap.SCOPE_SUBTREE, "(objectClass=*)")
print("Result", l.result3(r))

要处理此问题,您需要通过在搜索查询末尾添加 + 符号来获取 openldap 内部字段,如下所示:

$ ldapsearch -h localhost -w 'admin' -x -D "cn=admin,dc=example,dc=org" -b "DC=example,DC=org" +

在 python 代码中它会像这样:

r = l.search_ext("dc=example,dc=org", ldap.SCOPE_SUBTREE, "objectClass=*", ["+",], 0)

然后 returns 重要的内部字段,例如 modifyTimestamp

或者如果你想在一个请求中获取所有内部字段和用户属性,只需添加 '*' '+' 就像这样:

 r = l.search_ext("dc=example,dc=org", ldap.SCOPE_SUBTREE, "objectClass=*", ["*", "+"], 0)

如果您想在特定日期之后获取最后更改的用户,请尝试在这样的查询中添加 modifyTimestamp

$ ldapsearch -h localhost -w 'admin' -x -D "cn=admin,dc=example,dc=org" -b "DC=example,DC=org" "modifyTimestamp>=20171012152507Z

要获取有关历史记录的更多信息,请尝试在您的 ldap 中启用 overlay accesslog 并使用它:

$ ldapsearch -x -b cn=accesslog

资源: