]> git.pld-linux.org Git - packages/squirrelmail.git/blob - squirrelmail-ad_ldap.patch
- release 10 (by relup.sh)
[packages/squirrelmail.git] / squirrelmail-ad_ldap.patch
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
4 @@ -30,6 +30,7 @@
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
9   * </pre>
10   * NOTE. This class should not be used directly. Use the
11   *       "AddressBook" class instead.
12 @@ -98,6 +99,10 @@
13       * @since 1.5.0 and 1.4.3
14       */
15      var $protocol = '';
16 +    /**
17 +     * @var bool True if connecting to MS Active Directory
18 +     */
19 +    var $adldap = '';
20  
21      /**
22       * Constructor. Connects to database
23 @@ -132,6 +137,9 @@
24              if(isset($param['protocol'])) {
25                  $this->protocol = $param['protocol'];
26              }
27 +            if(isset($param['adldap'])) {
28 +                $this->adldap = $param['adldap'];
29 +            }
30              if(empty($param['name'])) {
31                  $this->sname = 'LDAP: ' . $param['host'];
32              }
33 @@ -178,6 +186,15 @@
34              }
35          }
36  
37 +        if($this->adldap) {
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));
41 +                } else {
42 +                    return $this->set_error('ldap_set_option failed');
43 +                }
44 +            }
45 +        }
46          if(!empty($this->binddn)) {
47              if(!@ldap_bind($this->linkid, $this->binddn, $this->bindpw)) {
48                  if(function_exists('ldap_error')) {
49 @@ -272,16 +289,21 @@
50              /* Undo sanitizing of * symbol */
51              $expr = str_replace('\2a','*',$expr);
52          }
53 -        $expression = "cn=$expr";
54  
55          /* Make sure connection is there */
56          if(!$this->open()) {
57              return false;
58          }
59  
60 +        if(!$this->adldap) {
61 +            $attributes = array('dn', 'o', 'ou', 'sn', 'givenname', 'cn', 'mail');
62 +            $expression = "cn=$expr";
63 +        } else {
64 +            $attributes = array('description', 'sn', 'givenname', 'cn', 'mail');
65 +            $expression = "(|(sn=$expr)(givenname=$expr)(sAMAccountName=$expr)(cn=$expr)(displayname=$expr))";
66 +        }
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);
71  
72          /* Should get error from server using the ldap_error() function,
73           * but it only exist in the PHP LDAP documentation. */
74 @@ -301,33 +323,59 @@
75          $ret = array();
76          $returned_rows = 0;
77          $res = @ldap_get_entries($this->linkid, $sret);
78 +
79          for($i = 0 ; $i < $res['count'] ; $i++) {
80              $row = $res[$i];
81  
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]);
89  
90 -            if(!empty($row['ou'][0])) {
91 -                $label = $this->charset_decode($row['ou'][0]);
92 -            }
93 -            else if(!empty($row['o'][0])) {
94 -                $label = $this->charset_decode($row['o'][0]);
95 -            } else {
96 -                $label = '';
97 -            }
98 +                if(!empty($row['ou'][0])) {
99 +                    $label = $this->charset_decode($row['ou'][0]);
100 +                }
101 +                else if(!empty($row['o'][0])) {
102 +                    $label = $this->charset_decode($row['o'][0]);
103 +                } else {
104 +                    $label = '';
105 +                }
106  
107 -            if(empty($row['givenname'][0])) {
108 -                $firstname = '';
109 -            } else {
110 -                $firstname = $this->charset_decode($row['givenname'][0]);
111 -            }
112 +                if(empty($row['givenname'][0])) {
113 +                    $firstname = '';
114 +                } else {
115 +                    $firstname = $this->charset_decode($row['givenname'][0]);
116 +                }
117  
118 -            if(empty($row['sn'][0])) {
119 -                $surname = '';
120 +                if(empty($row['sn'][0])) {
121 +                    $surname = '';
122 +                } else {
123 +                    $surname = $this->charset_decode($row['sn'][0]);
124 +                }
125              } else {
126 -                $surname = $this->charset_decode($row['sn'][0]);
127 +                $nickname = $this->charset_decode($row['cn'][0]);
128 +                $fullname = '';
129 +
130 +                if(!empty($row['description'][0])) {
131 +                    $label = $this->charset_decode($row['description'][0]);
132 +                } else {
133 +                    $label = '';
134 +                }
135 +
136 +                if(empty($row['givenname'][0])) {
137 +                    $firstname = '';
138 +                } else {
139 +                    $firstname = $this->charset_decode($row['givenname'][0]);
140 +                    $fullname = $this->charset_decode($row['givenname'][0]);
141 +                }
142 +
143 +                if(empty($row['sn'][0])) {
144 +                    $surname = '';
145 +                } else {
146 +                    $surname = $this->charset_decode($row['sn'][0]);
147 +                    $fullname .= ' '.$this->charset_decode($row['sn'][0]);
148 +                }
149              }
150  
151              /* Add one row to result for each e-mail address */
This page took 0.044515 seconds and 3 git commands to generate.