reading deleted user data from ldap

reading deleted user data from ldap

by deva m -
Number of replies: 5

Hi,

Dealing with LDAP on moodle lms,

how to get user information of deleted users from LDAP server in LMS.

the below link is done with c++ language,

https://stackoverflow.com/questions/36640272/read-deleted-users-from-active-directory

How to achieve it in PHP ?


Average of ratings: -
In reply to deva m

Re: reading deleted user data from ldap

by Eugen Neuber -

Hi,

the generic PHP code would be something like this:

?php
$ldap_host = 'xx.xxx.xx.xxx'; // IP of your LDAP server
$ldap_port = 389;
$ldap_user = 'username'; // user to bind to server
$ldap_pass = '******'; // password
$ldap_context = 'ou=users,dc=example, dc=org'; // where the infos are

// https://stackoverflow.com/questions/36640272/read-deleted-users-from-active-directory $filter = '(&(objectClass=user)(isDeleted=TRUE))'; $ldap = ldap_connect($ldap_host, $ldap_port); if (!$ldap) { die("\nERROR: no connection\n"); } else { echo "connect OK!\n"; } // https://stackoverflow.com/questions/6222641/how-to-php-ldap-search-to-get-user-ou-if-i-dont-know-the-ou-for-base-dn#6222836 ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); $ldap_bind = ldap_bind($ldap, $ldap_user, $ldap_pass); if (!$ldap_bind) { die("\nERROR: can not bind\n"); } else { echo "bind OK!\n"; } $search = ldap_search($ldap, $ldap_context, $filter); $info = ldap_get_entries($ldap, $search); echo "data for " . $info["count"] . " items returned:\n\n"; for ($i=0; $i<$info["count"]; ++$i) { echo $i + 1, " entry:\n"; echo "dn is: " . $info[$i]["dn"] . "\n"; echo "\n----\n"; } ldap_close($ldap);

It works for me on general searches, but I do not get deleted users (as your link says).

Average of ratings: Useful (1)
In reply to Eugen Neuber

Re: reading deleted user data from ldap

by deva m -

hi Neuber,

I too tried that piece of code, but doesn't seems to be working.

I'm checking on ldap server to enable any settings related to get information of deleted users.

If I get any improvement in it, will share.

And thanks for your response to my post.



Regards

Deva.

In reply to Eugen Neuber

Re: reading deleted user data from ldap

by yuvaraj balu -

Hi Eugen Neuber


Any option is need to be enable in ldap tool?


attached screen shot boolean attributes editor 'not set'


Iam not able to change value true.


please help if you can.


Thanks,

yuvaraj B

Attachment isDeleted.png
In reply to Eugen Neuber

Re: reading deleted user data from ldap

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I' afraid finding (and reanimating) deleted entries in Active Directory is a bit more complicated. Deleted object are moved to a special container (in addition to having the isDeleted attribute set to true), and the only way to search for entries in that container is using a special LDAP control value (see https://technet.microsoft.com/en-us/library/2007.09.tombstones.aspx for additional details).

Saludos. Iñaki.