This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Copyright (c) STMicroelectronics, 2005. All Rights Reserved. |
||
4 | * |
||
5 | * Originally written by Manuel Vacelet, 2005 |
||
6 | * |
||
7 | * This file is a part of Codendi. |
||
8 | * |
||
9 | * Codendi is free software; you can redistribute it and/or modify |
||
10 | * it under the terms of the GNU General Public License as published by |
||
11 | * the Free Software Foundation; either version 2 of the License, or |
||
12 | * (at your option) any later version. |
||
13 | * |
||
14 | * Codendi is distributed in the hope that it will be useful, |
||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
17 | * GNU General Public License for more details. |
||
18 | * |
||
19 | * You should have received a copy of the GNU General Public License |
||
20 | * along with Codendi; if not, write to the Free Software |
||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
22 | * |
||
23 | * |
||
24 | */ |
||
25 | |||
26 | |||
27 | /** |
||
28 | * This class is an implementation of Iterator pattern to easily browse an LDAP |
||
29 | * result set. |
||
30 | * |
||
31 | * @see LDAPResult |
||
32 | */ |
||
33 | class LDAPResultIterator implements SeekableIterator, Countable { |
||
34 | |||
35 | var $list; |
||
36 | var $key; |
||
37 | var $valid; |
||
38 | protected $ldapParams; |
||
39 | |||
40 | /** |
||
41 | * Constructor |
||
42 | */ |
||
43 | function __construct($info, $ldapParams) { |
||
44 | $this->list = $info; |
||
45 | $this->key = 0; |
||
46 | $this->valid = ($this->count() > 0); |
||
47 | $this->ldapParams = $ldapParams; |
||
48 | } |
||
49 | |||
50 | |||
51 | /** |
||
52 | * Return the number of entries in a result set. |
||
53 | * |
||
54 | * @return int |
||
55 | */ |
||
56 | function count() { |
||
57 | if($this->list && array_key_exists('count', $this->list)){ |
||
58 | return $this->list['count']; |
||
59 | } |
||
60 | else { |
||
61 | return 0; |
||
62 | } |
||
63 | } |
||
64 | |||
65 | |||
66 | /** |
||
67 | * Return true if there is no entries in the result set. |
||
68 | * |
||
69 | * @return int |
||
70 | */ |
||
71 | function isEmpty() { |
||
72 | return empty($this->list); |
||
73 | } |
||
74 | |||
75 | |||
76 | /** |
||
77 | * Move key to the position given in parameter. |
||
78 | * |
||
79 | * @param $pos int |
||
80 | */ |
||
81 | function seek($pos) { |
||
82 | $this->key = $pos; |
||
83 | $this->valid = true; |
||
84 | if($this->key >= $this->count()) { |
||
85 | $this->valid = false; |
||
86 | } |
||
87 | if($this->key < 0) { |
||
88 | $this->valid = false; |
||
89 | } |
||
90 | } |
||
91 | |||
92 | |||
93 | /** |
||
94 | * Move key to the position given in parameter. |
||
95 | * |
||
96 | * @param $pos int |
||
97 | */ |
||
98 | function get($pos) { |
||
99 | $this->seek($pos); |
||
100 | if($this->valid) { |
||
101 | return $this->current(); |
||
102 | } |
||
103 | else { |
||
104 | return false; |
||
105 | } |
||
106 | } |
||
107 | |||
108 | |||
109 | /** |
||
110 | * Return true if result set is not empty. |
||
111 | * |
||
112 | * @return boolean |
||
113 | */ |
||
114 | function exist() { |
||
115 | return !$this->isEmpty(); |
||
116 | } |
||
117 | |||
118 | |||
119 | /** |
||
120 | * Return the current element. |
||
121 | * |
||
122 | * Standard function implemented from Iterator interface |
||
123 | * |
||
124 | * @return LDAPResult |
||
125 | */ |
||
126 | function current() { |
||
127 | return new LDAPResult($this->list[$this->key], $this->ldapParams); |
||
128 | } |
||
129 | |||
130 | |||
131 | /** |
||
132 | * Return the key of the current element. |
||
133 | * |
||
134 | * Standard function implemented from Iterator interface |
||
135 | * |
||
136 | * @return int |
||
137 | */ |
||
138 | function key() { |
||
139 | return $this->key; |
||
140 | } |
||
141 | |||
142 | |||
143 | /** |
||
144 | * Move forward to next element. |
||
145 | * |
||
146 | * Standard function implemented from Iterator interface |
||
147 | */ |
||
148 | function next() { |
||
149 | $this->valid = (++$this->key < $this->count()); |
||
150 | } |
||
151 | |||
152 | |||
153 | /** |
||
154 | * Rewind the Iterator to the first element. |
||
155 | * |
||
156 | * Standard function implemented from Iterator interface |
||
157 | */ |
||
158 | function rewind() { |
||
159 | $this->valid = true; |
||
160 | $this->key = 0; |
||
161 | } |
||
162 | |||
163 | |||
164 | /** |
||
165 | * Check if there is a current element after calls to rewind() or next(). |
||
166 | * |
||
167 | * Standard function implemented from Iterator interface |
||
168 | * |
||
169 | * @return boolean |
||
170 | */ |
||
171 | function valid() { |
||
172 | return $this->valid; |
||
173 | } |
||
174 | } |
||
175 | |||
176 | |||
177 | |||
178 | /** |
||
179 | * This class is wrapper to access to an LDAP entry |
||
180 | * |
||
181 | * Used as an iterator, it allows to iterate on all the fields in the LDAP |
||
182 | * result set: |
||
183 | * <pre> |
||
184 | * foreach($lr as $field) { |
||
185 | * echo "$field: ".$lr->get($field); |
||
186 | * } |
||
187 | * </pre> |
||
188 | * |
||
189 | * @see LDAPResultIterator |
||
190 | */ |
||
191 | class LDAPResult implements Iterator, Countable { |
||
192 | protected $ldapParams; |
||
193 | protected $info; |
||
194 | protected $index; |
||
195 | |||
196 | function __construct($info, $ldapParams) { |
||
197 | $this->ldapParams = $ldapParams; |
||
198 | $this->info = $info; |
||
199 | $this->index = 0; |
||
200 | } |
||
201 | |||
202 | function getEmail() { |
||
203 | return $this->get($this->ldapParams['mail']); |
||
204 | } |
||
205 | |||
206 | function getCommonName() { |
||
207 | return $this->get($this->ldapParams['cn']); |
||
208 | } |
||
209 | |||
210 | function getLogin() { |
||
211 | return $this->get($this->ldapParams['uid']); |
||
212 | } |
||
213 | |||
214 | function getEdUid() { |
||
215 | return $this->get($this->ldapParams['eduid']); |
||
216 | } |
||
217 | |||
218 | function getDn() { |
||
219 | return $this->info['dn']; |
||
220 | } |
||
221 | |||
222 | function getGroupMembers() { |
||
223 | $memberAttr = strtolower($this->ldapParams['grp_member']); |
||
224 | if(isset($this->info[$memberAttr])) { |
||
225 | $members = $this->info[$memberAttr]; |
||
226 | // Remove count from the info to be able to iterate on result |
||
227 | unset($members['count']); |
||
228 | return $members; |
||
229 | } else { |
||
230 | return array(); |
||
231 | } |
||
232 | } |
||
233 | |||
234 | /** |
||
235 | * Returns the first entry for a given field |
||
236 | * |
||
237 | * An LDAP Directory can store several values for each field (for instance |
||
238 | * server common names gives $this->info['cn'][0], $this->info['cn'][1], ... |
||
239 | * This method only returns the first entry. |
||
240 | * |
||
241 | * @param String $arg Entry to get |
||
242 | * |
||
243 | * @return String |
||
244 | */ |
||
245 | function get($arg) { |
||
246 | $v = $this->getAll($arg); |
||
247 | if ($v) { |
||
0 ignored issues
–
show
|
|||
248 | return $v[0]; |
||
249 | } |
||
250 | return $v; |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * Returns all entries for a given field |
||
255 | * |
||
256 | * @param String $arg Entry to get |
||
257 | * |
||
258 | * @return Array |
||
259 | */ |
||
260 | function getAll($arg) { |
||
261 | $arg = strtolower($arg); |
||
262 | if(isset($this->info[$arg])) { |
||
263 | return $this->info[$arg]; |
||
264 | } else { |
||
265 | return null; |
||
266 | } |
||
267 | } |
||
268 | |||
269 | function isEmpty() { |
||
270 | return empty($this->info); |
||
271 | } |
||
272 | |||
273 | function exist() { |
||
274 | return !$this->isEmpty(); |
||
275 | } |
||
276 | |||
277 | function count() { |
||
278 | return $this->info['count']; |
||
279 | } |
||
280 | |||
281 | function valid() { |
||
282 | return $this->index < $this->info['count']; |
||
283 | } |
||
284 | |||
285 | function next() { |
||
286 | $this->index++; |
||
287 | } |
||
288 | |||
289 | function rewind() { |
||
290 | $this->index = 0; |
||
291 | } |
||
292 | |||
293 | function current() { |
||
294 | return $this->info[$this->index]; |
||
295 | } |
||
296 | |||
297 | function key() { |
||
298 | return $this->index; |
||
299 | } |
||
300 | } |
||
301 | |||
302 | ?> |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.