Search code examples
phpldapopendj

OpenDJ: Different format returned after ldap_bind


The output format of described attributes in OpenDJ changes after using ldap_bind().

Example without ldap_bind:

$ldap_port = 389;
$ldap_host = "ldap-host";
$ldap_bdn  = "ou=People,dc=example,dc=com";
$ldap_attr = array("dn","groupname");
$ldap_filter = "(cn=example-cn)";

$ldap_group = "ou=Groups,dc=example,dc=com";

if(!($ldap_conn = ldap_connect($ldap_host,$ldap_port))) {
    die("could not connect to ldap");
}

if(!$ldap_res = ldap_search($ldap_conn,$ldap_group,$ldap_filter,$ldap_attr)) {
    die("ldap_search");
}

$res = ldap_search($ldap_conn, $ldap_group, "(cn=example-cn)", array("groupname"));
$entry = ldap_first_entry($ldap_conn, $res);
while($entry)
{
    $info = ldap_get_attributes($ldap_conn, $entry);
    var_dump($info);
    $entry = ldap_next_entry($ldap_conn, $entry);
}

result:

array (size=5)
  'groupname;lang-en' => 
    array (size=2)
      'count' => int 1
      0 => string 'Computing and Data Centre' (length=25)
  0 => string 'groupname;lang-en' (length=20)
  'groupname;lang-de' => 
    array (size=2)
      'count' => int 1
      0 => string 'Rechenzentrum und Datenbanken' (length=29)
  1 => string 'groupname;lang-de' (length=20)
  'count' => int 2

If I use the ldap_bind() function of PHP

if(!ldap_bind($ldap_conn, "uid=exampleuser,ou=Special Users,dc=com", "password")) {
    die("could not bind to ldap");
}

the output format of the described attributes changes to this:

array (size=3)
  'GroupName' => 
    array (size=3)
      'count' => int 2
      0 => string 'Computing and Data Centre' (length=25)
      1 => string 'Rechenzentrum und Datenbanken' (length=29)
  0 => string 'GroupName' (length=12)
  'count' => int 1

Why do I get a different format for the same request? Is OpenDJ misconfigured, or am I using the wrong functions?


Solution

  • There is no configuration in OpenDJ that can produce such difference in results.

    The only thing I can think of is that you are not making similar calls, or not iterating through the result the same way.