Ldap paged results

Ldap paged results

by Joshua Gang -
Number of replies: 3

I know this has been discussed before, but I still have not been able to get it to work. Has anybody been able to get patch 42060 to work. I am using PHP 5.3.4. I am a newbie when its comes to PHP/APACHE. I was able to compile build and patch my apache/php server, but when I try to do a very simple test (as shown by the test script included in the patch) all i get is the very first 1000 entries.

Here is my  test php code

 

$link = ldap_connect('<ldapserver>',443);
ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_bind($link,'<binduser>','<binduserpwd>');       
$cookie = '';

$test = ldap_control_paged_results($link,1000, TRUE, $cookie);
$sr = ldap_search($link,'<serachOU>','(&(SAMAccountname=*)(objectClass=user))',array('SAMAccountname'),null,null,null,null);
$entries = ldap_get_entries($link, $sr);
$test2= ldap_control_paged_results_response($link, $sr, $cookie, $estimated);

<dump var section>


$sr = ldap_search($link,'<serachOU>','(&(SAMAccountname=*)(objectClass=user))',array('SAMAccountname'),null,null,null,null);
$entries = ldap_get_entries($link, $sr);
$test2= ldap_control_paged_results_response($link, $sr, $cookie, $estimated);

<dump var section>

every time I get the cookie back but when I resubmitted the ldap sreach I still get the same results.

Average of ratings: -
In reply to Joshua Gang

Re: Ldap paged results

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Joshua,

you need to get the cookie after each search (like you do), but you also need to set it (with ldap_control_paged_results()) before the next search. I.e.:

$link = ldap_connect('',443); ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_bind($link,'','');
$cookie = '';   $test = ldap_control_paged_results($link,1000, TRUE, $cookie); $sr = ldap_search($link,'','(&(SAMAccountname=*)(objectClass=user))',array('SAMAccountname'),null,null,null,null); $entries = ldap_get_entries($link, $sr); $test2= ldap_control_paged_results_response($link, $sr, $cookie, $estimated);   <dump var section>   $test = ldap_control_paged_results($link,1000, TRUE, $cookie); // <-- You need this line here $sr = ldap_search($link,'','(&(SAMAccountname=*)(objectClass=user))',array('SAMAccountname'),null,null,null,null); $entries = ldap_get_entries($link, $sr); $test2= ldap_control_paged_results_response($link, $sr, $cookie, $estimated);   <dump var section>

Also note that the second search must use the same exact query parameters, otherwise the server will ignore the cookie and will treat the query as a new one, instead of as a continuation of the previous one.

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: Ldap paged results

by Joshua Gang -

Thank you for the reply Iñaki, but that did not work. I still get the same 1000 entries. I am using Fedora core 13 with PHP version 5.3.4. Our AD is running on Windows Server 2008 but I do not know which mode it is in. The OU that I am querying has 2517 user objects in it. I do get the cookie back which I guess is half the battle but it does not seem that the ldap_control_paged_results or the ldap_search  is sending the cookie back as I get the same cookie with the second query.

In reply to Joshua Gang

Re: Ldap paged results

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Last time I tested was with PHP 5.2.6 (shipped with Debian Lenny) and OpenLDAP 2.4.x and W2003 (but W2008 should be the same).

There have been a couple of small changes in the patch since them (in addition to the changes needed to adapt it to PHP 5.3.x conventions), so it could either be that those changes have introduced a regression or that your particular compilation is hitting another bug somewhere else.

Do you have a W2003 machine to try it with? (just to rule out W2008 out of the question)

Saludos. Iñaki.