简体   繁体   中英

LDAP search query not working?

Trying to search for information about a person in a directory with LDAP . everything else works except this search string but no one can figure out what is wrong.

The result just comes up with an empty set despite that it returns values in bash.

$result = ldap_search(
    $ds, 
    $base_domain, 
    '(CN=user)'
) or die("error in search");



<?php
$DEBUGGING = True;
if($DEBUGGING)
{
    error_reporting(E_ALL);
    ini_set('display_errors', TRUE);
}



$server = 'ldaps://ds.cisco.com';
#$port = 639;
$port = 636;


$ds=ldap_connect($server, $port);
echo "connect result is " . $ds . "<br />";

if ($ds)
{

    $r = ldap_bind($ds, $username, $password);
    echo "Bind result is " . $r . "<br />";



    $base_domain = 'OU=Standard,OU=Cisco Groups,DC=cisco,DC=com';
    #$base_domain = 'dc=cisco,dc=com';
    #$base_domain = 'OU=Employees,OU=Cisco Groups,DC=cisco,DC=com';
    #$result = ldap_search($ds, $base_domain, '(&(CN=selyons))') or die ("error in search");
    #$result = ldap_search($ds, $base_domain, '(&(membersOf=CN=it-puppet-masters,OU=Standard,OU=Cisco Groups,DC=cisco,DC=com)(sAMAccountName=*))') or die ("error in search");

    $result = ldap_search($ds, $base_domain, '(CN=user)') or die("error in search");

    echo "SEARCHING" . "<br />";


    #while ($row=mysql_fetch_array($result, MYSQL_NUM))
    #{
        #print_r($row);
        #print($row[0]);
    #}

    $info = ldap_get_entries($ds, $result);



    #$arraystring = print_r($info, true);
    echo "<pre>";
    print_r($info);
    echo "</pre>";
    #echo $arraystring;
    #print_r($info[699][2][0]);
    #print_r($info[699][2][1]);
    #print_r($info[699][2][2]);
    #print_r($info[699][2][3]);
    #print_r($info[699][2][4]);

    #print_r($info[699][2]);
    #print_r($info[699]);
    #$members = $info[0]["member"];
    #echo $members;

    #for($i = 0; $i < 30; $i++)
    #{
        #print_r($info[699]);
    #}
}


?>

You are looking at the container OU=Standard,OU=Cisco Groups,DC=cisco,DC=com for an object where CN=user is true. Perhaps you meant (objectClass=user) or do you really expect to have an object whose CN attribute is set to user ?

That seems lightly implausible. You might be thinking about the AD default setup, where the Users container is actually a container and thus cn=Users and not ou=Users as you might have otherwise expected (nor dc=Users ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM