X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fabook_ldap_server.php;h=4198405aebab00e7e01af29b95885533a6cd7c08;hb=a3439b271e1b5fa7e61362970dbbcc5bfc75e5b1;hp=d95b1ab3736c0e161a91d171b700dbd6ce1334fc;hpb=84db4e6c4e94afec13c1078332129032becf0d6d;p=squirrelmail.git diff --git a/functions/abook_ldap_server.php b/functions/abook_ldap_server.php index d95b1ab3..4198405a 100644 --- a/functions/abook_ldap_server.php +++ b/functions/abook_ldap_server.php @@ -1,30 +1,49 @@ LDAP server hostname/IP-address - ** base => LDAP server root (base dn). Empty string allowed. - ** ? port => LDAP server TCP port number (default: 389) - ** ? charset => LDAP server charset (default: utf-8) - ** ? name => Name for LDAP server (default "LDAP: hostname") - ** Used to tag the result data - ** ? maxrows => Maximum # of rows in search result - ** ? timeout => Timeout for LDAP operations (in seconds, default: 30) - ** Might not work for all LDAP libraries or servers. - ** - ** NOTE. This class should not be used directly. Use the - ** "AddressBook" class instead. - ** - ** $Id$ - **/ - - class abook_ldap_server extends addressbook_backend { +/** + * abook_ldap_server.php + * + * Copyright (c) 1999-2001 The Squirrelmail Development Team + * Licensed under the GNU GPL. For full terms see the file COPYING. + * + * Address book backend for LDAP server + * + * An array with the following elements must be passed to + * the class constructor (elements marked ? are optional): + * + * host => LDAP server hostname/IP-address + * base => LDAP server root (base dn). Empty string allowed. + * ? port => LDAP server TCP port number (default: 389) + * ? charset => LDAP server charset (default: utf-8) + * ? name => Name for LDAP server (default "LDAP: hostname") + * Used to tag the result data + * ? maxrows => Maximum # of rows in search result + * ? timeout => Timeout for LDAP operations (in seconds, default: 30) + * Might not work for all LDAP libraries or servers. + * + * NOTE. This class should not be used directly. Use the + * "AddressBook" class instead. + * + * $Id$ + */ + +/*****************************************************************/ +/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/ +/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/ +/*** + Base level indent should begin at left margin, as ***/ +/*** the first line of the class definition below. ***/ +/*** + All identation should consist of four space blocks ***/ +/*** + Tab characters are evil. ***/ +/*** + all comments should use "slash-star ... star-slash" ***/ +/*** style -- no pound characters, no slash-slash style ***/ +/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/ +/*** ALWAYS USE { AND } CHARACTERS!!! ***/ +/*** + Please use ' instead of ", when possible. Note " ***/ +/*** should always be used in _( ) function calls. ***/ +/*** Thank you for your help making the SM code more readable. ***/ +/*****************************************************************/ + +class abook_ldap_server extends addressbook_backend { var $btype = 'remote'; var $bname = 'ldap_server'; @@ -131,7 +150,7 @@ // Encode the expression $expr = $this->charset_encode($expr); - if(!ereg('\\*', $expr)) + if(strstr($expr, "*") === false) $expr = "*$expr*"; $expression = "cn=$expr"; @@ -192,31 +211,44 @@ else $surname = $this->charset_decode($row['sn'][0]); // Add one row to result for each e-mail address - for($j = 0 ; $j < $row['mail']['count'] ; $j++) { - array_push($ret, array('nickname' => $nickname, - 'name' => $fullname, - 'firstname' => $firstname, - 'lastname' => $surname, - 'email' => $row['mail'][$j], - 'label' => $label, - 'phone' => $phone, - 'backend' => $this->bnum, - 'source' => &$this->sname)); - - // Limit number of hits - $returned_rows++; - if(($returned_rows >= $this->maxrows) && - ($this->maxrows > 0) ) { - ldap_free_result($sret); - return $ret; - } - - } + if(isset($row['mail']['count'])) { + for($j = 0 ; $j < $row['mail']['count'] ; $j++) { + array_push($ret, array('nickname' => $nickname, + 'name' => $fullname, + 'firstname' => $firstname, + 'lastname' => $surname, + 'email' => $row['mail'][$j], + 'label' => $label, + 'phone' => $phone, + 'backend' => $this->bnum, + 'source' => &$this->sname)); + + // Limit number of hits + $returned_rows++; + if(($returned_rows >= $this->maxrows) && + ($this->maxrows > 0) ) { + ldap_free_result($sret); + return $ret; + } + + } // for($j ...) + + } // isset($row['mail']['count']) + } ldap_free_result($sret); return $ret; } // end search() + + // If you run a tiny LDAP server and you want the "List All" button + // to show EVERYONE, then uncomment this tiny block of code: + // + // function list_addr() { + // return $this->search("*"); + // } + // + // Careful with this -- it could get quite large for big sites. } ?>