Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morteza-mori/c66e5d67fbf969036c86ad9836754c24 to your computer and use it in GitHub Desktop.
Save morteza-mori/c66e5d67fbf969036c86ad9836754c24 to your computer and use it in GitHub Desktop.
How to get OpenLdap user changed attributes instead of all user attributes

To handle this issue, you need to get openldap internal fields by adding a + sign at the end of search query like so:

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

And in python code it would like this:

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

Then it returns internal fields which are important like modifyTimestamp.

Or if you want to get all internal fields and user attributes in one request, just add '*' '+' like this:

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

If you want to get last changed user after a specific date, try to add modifyTimestamp on query like this:

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

To get more info about history, try to enable overlay accesslog in your ldap and use it:

    $ ldapsearch -x -b cn=accesslog

Resources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment