1 diff -ur squirrelmail-1.4.6.orig/functions/abook_ldap_server.php squirrelmail-1.4.6/functions/abook_ldap_server.php
2 --- squirrelmail-1.4.6.orig/functions/abook_ldap_server.php 2006-02-03 23:27:46.000000000 +0100
3 +++ squirrelmail-1.4.6/functions/abook_ldap_server.php 2006-06-02 19:25:42.713109500 +0200
5 * ? binddn => LDAP Bind DN.
6 * ? bindpw => LDAP Bind Password.
7 * ? protocol => LDAP Bind protocol.
8 + * ? adldap => Set to true if connecting to MS Active Directory
10 * NOTE. This class should not be used directly. Use the
11 * "AddressBook" class instead.
13 * @since 1.5.0 and 1.4.3
17 + * @var bool True if connecting to MS Active Directory
22 * Constructor. Connects to database
24 if(isset($param['protocol'])) {
25 $this->protocol = $param['protocol'];
27 + if(isset($param['adldap'])) {
28 + $this->adldap = $param['adldap'];
30 if(empty($param['name'])) {
31 $this->sname = 'LDAP: ' . $param['host'];
38 + if(!@ldap_set_option($this->linkid, LDAP_OPT_REFERRALS, 0)) {
39 + if(function_exists('ldap_error')) {
40 + return $this->set_error(ldap_error($this->linkid));
42 + return $this->set_error('ldap_set_option failed');
46 if(!empty($this->binddn)) {
47 if(!@ldap_bind($this->linkid, $this->binddn, $this->bindpw)) {
48 if(function_exists('ldap_error')) {
50 /* Undo sanitizing of * symbol */
51 $expr = str_replace('\2a','*',$expr);
53 - $expression = "cn=$expr";
55 /* Make sure connection is there */
60 + if(!$this->adldap) {
61 + $attributes = array('dn', 'o', 'ou', 'sn', 'givenname', 'cn', 'mail');
62 + $expression = "cn=$expr";
64 + $attributes = array('description', 'sn', 'givenname', 'cn', 'mail');
65 + $expression = "(|(sn=$expr)(givenname=$expr)(sAMAccountName=$expr)(cn=$expr)(displayname=$expr))";
67 $sret = @ldap_search($this->linkid, $this->basedn, $expression,
68 - array('dn', 'o', 'ou', 'sn', 'givenname', 'cn', 'mail'),
69 - 0, $this->maxrows, $this->timeout);
70 + $attributes, 0, $this->maxrows, $this->timeout);
72 /* Should get error from server using the ldap_error() function,
73 * but it only exist in the PHP LDAP documentation. */
77 $res = @ldap_get_entries($this->linkid, $sret);
79 for($i = 0 ; $i < $res['count'] ; $i++) {
82 /* Extract data common for all e-mail addresses
83 * of an object. Use only the first name */
84 - $nickname = $this->charset_decode($row['dn']);
85 - $fullname = $this->charset_decode($row['cn'][0]);
86 + if(!$this->adldap) {
87 + $nickname = $this->charset_decode($row['dn']);
88 + $fullname = $this->charset_decode($row['cn'][0]);
90 - if(!empty($row['ou'][0])) {
91 - $label = $this->charset_decode($row['ou'][0]);
93 - else if(!empty($row['o'][0])) {
94 - $label = $this->charset_decode($row['o'][0]);
98 + if(!empty($row['ou'][0])) {
99 + $label = $this->charset_decode($row['ou'][0]);
101 + else if(!empty($row['o'][0])) {
102 + $label = $this->charset_decode($row['o'][0]);
107 - if(empty($row['givenname'][0])) {
110 - $firstname = $this->charset_decode($row['givenname'][0]);
112 + if(empty($row['givenname'][0])) {
115 + $firstname = $this->charset_decode($row['givenname'][0]);
118 - if(empty($row['sn'][0])) {
120 + if(empty($row['sn'][0])) {
123 + $surname = $this->charset_decode($row['sn'][0]);
126 - $surname = $this->charset_decode($row['sn'][0]);
127 + $nickname = $this->charset_decode($row['cn'][0]);
130 + if(!empty($row['description'][0])) {
131 + $label = $this->charset_decode($row['description'][0]);
136 + if(empty($row['givenname'][0])) {
139 + $firstname = $this->charset_decode($row['givenname'][0]);
140 + $fullname = $this->charset_decode($row['givenname'][0]);
143 + if(empty($row['sn'][0])) {
146 + $surname = $this->charset_decode($row['sn'][0]);
147 + $fullname .= ' '.$this->charset_decode($row['sn'][0]);
151 /* Add one row to result for each e-mail address */