
August 23rd, 2012, 12:23 PM
|
|
Registered User
|
|
Join Date: Aug 2012
Posts: 1
Time spent in forums: 18 m 32 sec
Reputation Power: 0
|
|
|
Ldap_get_entries returning zero elements in an array
Hi all,
I'm pretty new to LDAP. I'm programming an application to unlock users. The first stage is to read them. I have manage to read the users with a code similar to the one below (the only thing I change was the domain and ip). However because the DB in which the changes are going to be made is critical I'm testing the code in another server. I used Ldp (a small viewer) to check I can connect to the AD and everything worked OK.
After that, I have my code which was working perfectly, to connect to the testing server and I cannot get the data. However, I can connect and bind perfectly. The search returns "Resource id #15" but the ldap_get_entries returns a empty array when it's suppose to return some data.
Another thing, when I query the testing server from the server which executes my .php with the following command:
Code:
ldapsearch -LLL -h 10.105.17.97 -D "CN=Consultas LDAP,CN=Users,DC=adtest,DC=com" -P 3 -b "CN=Users,dc=adtest,dc=com" -x -w Password1925 "(samaccountname=ajacoby)" displayName
I do get the correct data, so I don't thing there is any problem with connection nither with permissions.
I hope somebody can helpme since I don't know where to look for a problem...
PHP Code:
<table border="1" align="center" >
<tr>
<td valign="top">
<table bgcolor="white" border="1" cellpadding="1" cellspacing="0">
<tr bgcolor="#c0c0ff"><td align='center' colspan="10"><b>Lockout </b></t
d></tr>
<tr bgcolor="#c0c0c0"><td align='center' colspan="5"><b>Users Found</b></td></tr>
<tr>
<td align='center'><b>Name</b></td>
<td align='center'><b>Account</b></td>
<td align='center'><b>Grup</b></td>
<td align='center'><b>CR</b></td>
<td align='center'><b>Lockout Time</b></td></tr>
<?php
include("logon.conf");
$username=$_POST[data_ser_user];
global $ad,$user,$clave;
$con=ldap_connect($ad) or die("Could not connect to $ad");
$bind=ldap_bind($con,$user,$clave);
if(!$bind)
{
print "Error in the BIND";
}
else
{
print "Authenticated";
}
$filter="(&(objectClass=user)(&(|(samaccountname=$username*)(name=$username*)))(physicalDeliveryOfficeName=$cr*))";
$fields=array("samaccountname","name","memberof","physicalDeliveryOfficeName","lockoutTime");
$sr=ldap_search($con,"CN=Users,DC=adtest,DC=com",$filter,$fields);
print " SR ";
print $sr;
$entries=array();
$entries=ldap_get_entries($con,$sr);
print " ENTRIES ";
print $entries['count'];
for($i=0;$i<$entries['count'];$i++)
{
$link_name="<a href=\"javascript:document.".$entries[$i]['samaccountname'][0].".submit();\">".$entries[$i]['samaccountname'][0]."</a>";
print "\n ";
print "<form name='".$entries[$i]['samaccountname'][0]."' "." method=\"POST\""." action='usr_unlock.php'>";
print "<input type='hidden' name='usr_2_unlock' value='".$entries[$i]['samaccountname'][0]."'>";
print "</form>";
///////
if(isset($entries[$i]['samaccountname'][0]))
print "<tr><td>".$entries[$i]['name'][0];
print "</td><td>".$link_name;
print "</td><td>"."tmp SIN GRUPO";
print "</td><td>".$entries[$i]['physicaldeliveryofficename'][0];
print "</td><td>".$entries[$i]['lockouttime'][0]."</td></tr>";
}
?>
</table>
</table>
the logon.conf which is included in the code is this:
PHP Code:
<?php
$user="CN=Consultas LDAP,CN=Users,DC=adtest,DC=com";
$clave="Password1925";
$ad="10.105.17.97";
$puerto="389";
?>
Thanks in advance!
|