Reputation: 63
I've setup a new webserver with Apache 2.4, PHP7 and Zend framework
The authentication works with a single user just fine so i know that i have installed the Zend framework correct and it is working.
My problem is that i now want to display a full list of all users on the DC and their groups. How do i generate an array (or display) with all users ?
Upvotes: 0
Views: 282
Reputation: 3861
As you are using the Zend Framework you might want to have a look at zend-ldap
the easiest way to retrieve a list of nodes would be like this:
use Zend\Ldap\Ldap;
$options = [/* ... */];
$ldap = new Ldap($options);
$ldap->bind();
$result = $ldap->search(
'(uid=*)',
$searchBase,
Ldap::SEARCH_SCOPE_SUB
);
foreach ($result as $item) {
echo $item["dn"] . ': ' . $item['cn'][0] . PHP_EOL;
}
But beware: There are two limits to the number of items returned: one is set by the client which can be overwritten but the second is set by the server and is not changeable. So usually you will not be able to retrieve more than 1000 items in one go.
We are currently working on a way to circumvent that limit when a certain extension is installed on the LDAP-Server (which is not always the case) but currently that limit is set.
For more informations on the parameters to Zend\Ldap\Ldap::search()
you might want to have a look at the source-code
For this to work you will need to install zend-ldap via composer require zendframework/zend-ldap
Upvotes: 1
Reputation: 312
What you could do after binding is something like this:
$filter = "uid=*";
$sr = ldap_search($ds, $dn, $filter) or die ("bummer");
$results = ldap_get_entries($ds, $sr);
var_dump($results);
Additionally, you could add a fourth parameter $justthese to make sure you only pull the data you will need, which saves times and bandwidth. Then it would be:
$filter = "uid=*";
$justthese = array("cn","uid","mobile","email");
$sr = ldap_search($ds, $dn, $filter, $justthese) or die ("bummer");
$results = ldap_get_entries($ds, $sr);
var_dump($results);
Upvotes: 0