General developer forum

reading deleted user data from ldap

 
Picture of deva m
reading deleted user data from ldap
 

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: -
Eugen Neuber
Re: reading deleted user data from ldap
 

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)
Picture of deva m
Re: reading deleted user data from ldap
 

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.

 
Average of ratings: -
Picture of yuvaraj balu
Re: reading deleted user data from ldap
 

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


 
Average of ratings: -
Eugen Neuber
Re: reading deleted user data from ldap
 

Hi yuvaraj balu,

I am sorry that I can't help you here. I'm not an LDAP-Admin...

kind regards,

Eugen

 
Average of ratings: -
Picture of Iñaki Arenaza
Re: reading deleted user data from ldap
Core developersDocumentation writersParticularly helpful MoodlersPlugin 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.

 
Average of ratings: -