PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > [PHP] ldap_search results limited
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
[PHP] ldap_search results limited

Réponse
 
LinkBack Outils de la discussion
Vieux 07/05/2008, 19h50   #1
mburtch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut [PHP] ldap_search results limited


I am running into a problem with my queries returning a limited number of
result entries. The LDAP server is Kerio Mail Server, and I am verified that
the SIZELIMIT in the server's configuration is 0 (no limit). For some
reason, my server seems to be limited to 200 results if no limit is
specified in ldap_search(), or 201 (?!) if I specify a limit larger than
200.

// setting the protocol version
ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3); // returns TRUE

// getting & settings SIZELIMIT options
ldap_get_option($conn, LDAP_OPT_SIZELIMIT, $optVal); // returns 0
ldap_set_option($conn, LDAP_OPT_SIZELIMIT, 1000); // returns TRUE

// some example queries
$res = ldap_search($conn, "", "cn=*", $attrs, false, 0); // 200 results
$res = ldap_search($conn, "", "cn=*", $attrs, false, 1000); // 201 results
$res = ldap_search($conn, "", "cn=*", $attrs, false, 199); // 199 results

I am using MAMP with PHP 5.2.5. Any ideas?

- MB
--
View this message in context: http://www.nabble.com/ldap_search-re...p17112001.html
Sent from the PHP - General mailing list archive at Nabble.com.

  Réponse avec citation
Vieux 07/05/2008, 19h58   #2
Nathan Nobbe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] ldap_search results limited

On Wed, May 7, 2008 at 12:50 PM, mburtch <mburtch@gmail.com> wrote:

>
> I am running into a problem with my queries returning a limited number of
> result entries. The LDAP server is Kerio Mail Server, and I am verified
> that
> the SIZELIMIT in the server's configuration is 0 (no limit). For some
> reason, my server seems to be limited to 200 results if no limit is
> specified in ldap_search(), or 201 (?!) if I specify a limit larger than
> 200.
>
> // setting the protocol version
> ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3); // returns TRUE
>
> // getting & settings SIZELIMIT options
> ldap_get_option($conn, LDAP_OPT_SIZELIMIT, $optVal); // returns 0
> ldap_set_option($conn, LDAP_OPT_SIZELIMIT, 1000); // returns TRUE
>
> // some example queries
> $res = ldap_search($conn, "", "cn=*", $attrs, false, 0); // 200 results
> $res = ldap_search($conn, "", "cn=*", $attrs, false, 1000); // 201 results
> $res = ldap_search($conn, "", "cn=*", $attrs, false, 199); // 199 results
>
> I am using MAMP with PHP 5.2.5. Any ideas?



hard to say if its a php issue.. have you tried using phpLdapAdmin ? i
usually set that up on my ldap installs; kindofa nice failsafe.

-nathan

  Réponse avec citation
Vieux 07/05/2008, 20h23   #3
Jay Blanchard
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: [PHP] ldap_search results limited

[snip]
> I am running into a problem with my queries returning a limited number

of
> result entries.

[/snip]

Most LDAP servers set a limit, it is usually not a PHP problem. One way
to solve is to query by first letter of last name and throw into an
array (iterating through the alphabet).

function ldapUserList($username, $password, $ip="127.0.0.1"){

$arrLetters = array("A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W",
"X", "Y", "Z");

/* connect to AD server */
if(!$ds=ldap_connect($ip)){
echo "did not connect...please contact system
administrator or go back to try again";
}

/* set LDAP option */
$un = "domain\\".$username;
$upw = $password;
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ds, LDAP_OPT_SIZELIMIT, 0);

/* bind to AD server */
if(!$r=ldap_bind($ds, $un, $upw)){
echo 'You are not authorized and or, your login information
was incorrect<br />';
echo $un.": ".$upw."<br />\n";
} else {
$userArray = array();
foreach($arrLetters as $letter){

/*
* search AD for users with surnames (sn), valid
e-mail addresses (mail)
* and make sure that they are valid
(msExchHideFromAddessLists)
*/

$sr= @ldap_search($ds, "dc=domain, dc=local",
"(&(&(sn=".$letter."*)(mail=*@domain.com))(!(msExc hHideFromAddressLists=
TRUE)))");
$info = ldap_get_entries($ds, $sr);
if(0 != count($info)){
/* place all valid entries into a usable
array */
for ($i=0; $i<count($info); $i++) {
/* make sure the item being
pushed into the array is not empty */
if('' !=
$info[$i]["mailnickname"][0]){
//array_push($userArray,
$info[$i]["mailnickname"][0] . "+".$info[$i]["cn"][0] .
"+".$info[$i]["mail"][0]);
$fullname =
$info[$i]["cn"][0];
$arrFN = explode("
",$fullname);
$fullname = $arrFN[1].",
".$arrFN[0];
$readname = $arrFN[0]."
".$arrFN[1];
$tusername =
strtolower($info[$i]["samaccountname"][0]);
$tempArray =
array("username"=>$tusername, "fullname"=>$fullname,
"readname"=>$readname);
array_push($userArray,
$tempArray);
}
}
}
}
}
/* sort the user array alphabetically and re-align numeric key
*/

array_multisort($userArray[1], SORT_ASC, SORT_STRING);
return $userArray;
}



$userArray = ldapUserList($_SESSION['user'], $_SESSION['password'],
"127.0.0.1");

Sorry about the funky line breaks
  Réponse avec citation
Vieux 07/05/2008, 21h26   #4
Matt Burtch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] ldap_search results limited

Thanks for the tips. phpLDAPAdmin was hanging while trying to authenticate,
but I'll give it a try again later.

Nathan: splitting up the search; I hadn't considered this! It is working
nicely for the time being, thanks.

- MB

On Wed, May 7, 2008 at 3:23 PM, Jay Blanchard <jblanchard@pocket.com> wrote:

> [snip]
> > I am running into a problem with my queries returning a limited number

> of
> > result entries.

> [/snip]
>
> Most LDAP servers set a limit, it is usually not a PHP problem. One way
> to solve is to query by first letter of last name and throw into an
> array (iterating through the alphabet).
>
> function ldapUserList($username, $password, $ip="127.0.0.1"){
>
> $arrLetters = array("A", "B", "C", "D", "E", "F", "G", "H", "I",
> "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W",
> "X", "Y", "Z");
>
> /* connect to AD server */
> if(!$ds=ldap_connect($ip)){
> echo "did not connect...please contact system
> administrator or go back to try again";
> }
>
> /* set LDAP option */
> $un = "domain\\".$username;
> $upw = $password;
> ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
> ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
> ldap_set_option($ds, LDAP_OPT_SIZELIMIT, 0);
>
> /* bind to AD server */
> if(!$r=ldap_bind($ds, $un, $upw)){
> echo 'You are not authorized and or, your login information
> was incorrect<br />';
> echo $un.": ".$upw."<br />\n";
> } else {
> $userArray = array();
> foreach($arrLetters as $letter){
>
> /*
> * search AD for users with surnames (sn), valid
> e-mail addresses (mail)
> * and make sure that they are valid
> (msExchHideFromAddessLists)
> */
>
> $sr= @ldap_search($ds, "dc=domain, dc=local",
> "(&(&(sn=".$letter."*)(mail=*@domain.com))(!(msExc hHideFromAddressLists=
> TRUE)))");
> $info = ldap_get_entries($ds, $sr);
> if(0 != count($info)){
> /* place all valid entries into a usable
> array */
> for ($i=0; $i<count($info); $i++) {
> /* make sure the item being
> pushed into the array is not empty */
> if('' !=
> $info[$i]["mailnickname"][0]){
> //array_push($userArray,
> $info[$i]["mailnickname"][0] . "+".$info[$i]["cn"][0] .
> "+".$info[$i]["mail"][0]);
> $fullname =
> $info[$i]["cn"][0];
> $arrFN = explode("
> ",$fullname);
> $fullname = $arrFN[1].",
> ".$arrFN[0];
> $readname = $arrFN[0]."
> ".$arrFN[1];
> $tusername =
> strtolower($info[$i]["samaccountname"][0]);
> $tempArray =
> array("username"=>$tusername, "fullname"=>$fullname,
> "readname"=>$readname);
> array_push($userArray,
> $tempArray);
> }
> }
> }
> }
> }
> /* sort the user array alphabetically and re-align numeric key
> */
>
> array_multisort($userArray[1], SORT_ASC, SORT_STRING);
> return $userArray;
> }
>
>
>
> $userArray = ldapUserList($_SESSION['user'], $_SESSION['password'],
> "127.0.0.1");
>
> Sorry about the funky line breaks
>


  Réponse avec citation
Vieux 07/05/2008, 21h30   #5
Nathan Nobbe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] ldap_search results limited

On Wed, May 7, 2008 at 2:26 PM, Matt Burtch <mburtch@gmail.com> wrote:

> Thanks for the tips. phpLDAPAdmin was hanging while trying to
> authenticate, but I'll give it a try again later.
>
> Nathan: splitting up the search; I hadn't considered this! It is working
> nicely for the time being, thanks.



umm, that was jay who gave the tip, but ... youre welcome!

-nathan

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 04h54.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15187 seconds with 13 queries