Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LDAP Operations error

Tags:

php

ldap

I have a problem with ldap connection.

$hostname="ldap://sub.domain.com";
$ds=ldap_connect($hostname, 389);
ldap_set_option ($ds, LDAP_OPT_REFERRALS, 0) or die('Unable to set LDAP opt referrals');
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3) or die('Unable to set LDAP protocol version');

if ($ds)
{
$dn = "OU=Users,OU=ro,DC=sub,DC=domain,DC=com";

if (!($ldapc=ldap_bind($ds))) { 
    echo "<p>Error:" . ldap_error($ds) . "</p>"; 
    echo "<p>Error number:" . ldap_errno($ds) . "</p>"; 
    echo "<p>Error:" . ldap_err2str(ldap_errno($ds)) . "</p>"; 
    die;
} 

$attributes = array("sn");
$filter = "(sn=*)";
$result = ldap_search($ds, $dn, $filter, $attributes);

echo $result;
$info = ldap_get_entries($ds, $result);
for ($i=0; $i < $info["count"]; $i++) {
    echo $info[$i]["ou"][0];
}
} else {
    echo "<h4>Unable to connect to LDAP server</h4>";
}

ldap_unbind($ds);

The ldap any anonymous connection works because I test it in a AD browser and everything is fine. In this code it stops at

ldap_search($ds, $dn, $filter, $attributes);

I receive the warning:

Warning: ldap_search(): Search: Operations error in ..\index.php on line 38

I don't really know what can be the cause of this error, I appreciate your help.

like image 338
Dogaru Ionut Avatar asked Jul 19 '13 09:07

Dogaru Ionut


People also ask

What is an LDAP error?

LDAP Error Codes is an Result Code indicating something went wrong. They are really LDAP Result Codes and we have a lot of them well defined.

What is LDAP operation?

The LDAP operation defines how to interact with the LDAP server instance, such as creating, retrieving, updating, searching for, and deleting objects in the data directory. Create a separate operation component for each action required for your integration.


2 Answers

To get it off the unanswered list:


I found the problem, was the bind problem. The server accepts the anonymous bind but not the search. And with an user and pass worked but i was making a mistake. For user i considered just de windows's username not the all location from AD, now it works.

like image 121
cweiske Avatar answered Sep 30 '22 20:09

cweiske


Had this problem, but i was correctly bind with a user who was allowed to search.

I solved it by setting up this option to work with active directory :

ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);
like image 41
Tanariel Avatar answered Sep 30 '22 19:09

Tanariel