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.
Check that length-based functions are not executed in loop conditions.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | //------------------------------------------------------------------------------ |
||
4 | // |
||
5 | // eTraxis - Records tracking web-based system |
||
6 | // Copyright (C) 2005-2009 Artem Rodygin |
||
7 | // |
||
8 | // This program is free software: you can redistribute it and/or modify |
||
9 | // it under the terms of the GNU General Public License as published by |
||
10 | // the Free Software Foundation, either version 3 of the License, or |
||
11 | // (at your option) any later version. |
||
12 | // |
||
13 | // This program is distributed in the hope that it will be useful, |
||
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | // GNU General Public License for more details. |
||
17 | // |
||
18 | // You should have received a copy of the GNU General Public License |
||
19 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
20 | // |
||
21 | //------------------------------------------------------------------------------ |
||
22 | |||
23 | /** |
||
24 | * LDAP |
||
25 | * |
||
26 | * This module implements several functions to work with LDAP servers. |
||
27 | * |
||
28 | * @package Engine |
||
29 | * @subpackage LDAP |
||
30 | */ |
||
31 | |||
32 | /**#@+ |
||
33 | * Dependency. |
||
34 | */ |
||
35 | require_once('../config.php'); |
||
36 | require_once('../engine/debug.php'); |
||
37 | require_once('../engine/utility.php'); |
||
38 | /**#@-*/ |
||
39 | |||
40 | //------------------------------------------------------------------------------ |
||
41 | // Definitions. |
||
42 | //------------------------------------------------------------------------------ |
||
43 | |||
44 | /**#@+ |
||
45 | * LDAP error code. |
||
46 | */ |
||
47 | define('LDAP_SUCCESS', 0x00); |
||
48 | define('LDAP_OPERATIONS_ERROR', 0x01); |
||
49 | define('LDAP_PROTOCOL_ERROR', 0x02); |
||
50 | define('LDAP_TIMELIMIT_EXCEEDED', 0x03); |
||
51 | define('LDAP_SIZELIMIT_EXCEEDED', 0x04); |
||
52 | define('LDAP_COMPARE_FALSE', 0x05); |
||
53 | define('LDAP_COMPARE_TRUE', 0x06); |
||
54 | define('LDAP_AUTH_METHOD_NOT_SUPPORTED', 0x07); |
||
55 | define('LDAP_STRONG_AUTH_REQUIRED', 0x08); |
||
56 | define('LDAP_PARTIAL_RESULTS', 0x09); |
||
57 | define('LDAP_REFERRAL', 0x0A); |
||
58 | define('LDAP_ADMINLIMIT_EXCEEDED', 0x0B); |
||
59 | define('LDAP_UNAVAILABLE_CRITICAL_EXTENSION', 0x0C); |
||
60 | define('LDAP_CONFIDENTIALITY_REQUIRED', 0x0D); |
||
61 | define('LDAP_SASL_BIND_INPROGRESS', 0x0E); |
||
62 | define('LDAP_NO_SUCH_ATTRIBUTE', 0x10); |
||
63 | define('LDAP_UNDEFINED_TYPE', 0x11); |
||
64 | define('LDAP_INAPPROPRIATE_MATCHING', 0x12); |
||
65 | define('LDAP_CONSTRAINT_VIOLATION', 0x13); |
||
66 | define('LDAP_TYPE_OR_VALUE_EXISTS', 0x14); |
||
67 | define('LDAP_INVALID_SYNTAX', 0x15); |
||
68 | define('LDAP_NO_SUCH_OBJECT', 0x20); |
||
69 | define('LDAP_ALIAS_PROBLEM', 0x21); |
||
70 | define('LDAP_INVALID_DN_SYNTAX', 0x22); |
||
71 | define('LDAP_IS_LEAF', 0x23); |
||
72 | define('LDAP_ALIAS_DEREF_PROBLEM', 0x24); |
||
73 | define('LDAP_INAPPROPRIATE_AUTH', 0x30); |
||
74 | define('LDAP_INVALID_CREDENTIALS', 0x31); |
||
75 | define('LDAP_INSUFFICIENT_ACCESS', 0x32); |
||
76 | define('LDAP_BUSY', 0x33); |
||
77 | define('LDAP_UNAVAILABLE', 0x34); |
||
78 | define('LDAP_UNWILLING_TO_PERFORM', 0x35); |
||
79 | define('LDAP_LOOP_DETECT', 0x36); |
||
80 | define('LDAP_SORT_CONTROL_MISSING', 0x3C); |
||
81 | define('LDAP_INDEX_RANGE_ERROR', 0x3D); |
||
82 | define('LDAP_NAMING_VIOLATION', 0x40); |
||
83 | define('LDAP_OBJECT_CLASS_VIOLATION', 0x41); |
||
84 | define('LDAP_NOT_ALLOWED_ON_NONLEAF', 0x42); |
||
85 | define('LDAP_NOT_ALLOWED_ON_RDN', 0x43); |
||
86 | define('LDAP_ALREADY_EXISTS', 0x44); |
||
87 | define('LDAP_NO_OBJECT_CLASS_MODS', 0x45); |
||
88 | define('LDAP_RESULTS_TOO_LARGE', 0x46); |
||
89 | define('LDAP_AFFECTS_MULTIPLE_DSAS', 0x47); |
||
90 | define('LDAP_OTHER', 0x50); |
||
91 | define('LDAP_SERVER_DOWN', 0x51); |
||
92 | define('LDAP_LOCAL_ERROR', 0x52); |
||
93 | define('LDAP_ENCODING_ERROR', 0x53); |
||
94 | define('LDAP_DECODING_ERROR', 0x54); |
||
95 | define('LDAP_TIMEOUT', 0x55); |
||
96 | define('LDAP_AUTH_UNKNOWN', 0x56); |
||
97 | define('LDAP_FILTER_ERROR', 0x57); |
||
98 | define('LDAP_USER_CANCELLED', 0x58); |
||
99 | define('LDAP_PARAM_ERROR', 0x59); |
||
100 | define('LDAP_NO_MEMORY', 0x5A); |
||
101 | define('LDAP_CONNECT_ERROR', 0x5B); |
||
102 | define('LDAP_NOT_SUPPORTED', 0x5C); |
||
103 | define('LDAP_CONTROL_NOT_FOUND', 0x5D); |
||
104 | define('LDAP_NO_RESULTS_RETURNED', 0x5E); |
||
105 | define('LDAP_MORE_RESULTS_TO_RETURN', 0x5F); |
||
106 | define('LDAP_CLIENT_LOOP', 0x60); |
||
107 | define('LDAP_REFERRAL_LIMIT_EXCEEDED', 0x61); |
||
108 | /**#@-*/ |
||
109 | |||
110 | //------------------------------------------------------------------------------ |
||
111 | // Functions. |
||
112 | //------------------------------------------------------------------------------ |
||
113 | |||
114 | /** |
||
115 | * Searches for specified username on LDAP server. |
||
116 | * |
||
117 | * The function searches for specified <i>username</i>. |
||
118 | * If user is found, then his display name and email address are returned, otherwise NULL is returned. |
||
119 | * If <i>password</i> is specified, then function also tries to authorize on LDAP server using specified <i>username</i> and <i>password</i>. |
||
120 | * If authorization is failed, NULL is returned, even when user with specified <i>username</i> was successfully found. |
||
121 | * |
||
122 | * @param string $username Login of user to be found. |
||
123 | * @param string $password Password of user. |
||
124 | * @return array The array which contains two items: first item is display name of user, second one - his email. |
||
125 | * If user was not found, or cannot be authorized with specified password, then NULL is returned. |
||
126 | */ |
||
127 | function ldap_finduser ($username, $password = NULL) |
||
128 | { |
||
129 | debug_write_log(DEBUG_TRACE, '[ldap_finduser]'); |
||
130 | debug_write_log(DEBUG_DUMP, '[ldap_finduser] $username = ' . $username); |
||
131 | |||
132 | $link = @ldap_connect(LDAP_HOST, LDAP_PORT); |
||
133 | |||
134 | if (!$link) |
||
135 | { |
||
136 | debug_write_log(DEBUG_ERROR, '[ldap_finduser] ldap_connect() error.'); |
||
137 | return NULL; |
||
138 | } |
||
139 | |||
140 | $retval = NULL; |
||
141 | |||
142 | if (!@ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, 3)) |
||
143 | { |
||
144 | debug_write_log(DEBUG_ERROR, '[ldap_finduser] ldap_set_option(LDAP_OPT_PROTOCOL_VERSION) error: ' . ldap_err2str(ldap_errno($link))); |
||
145 | } |
||
146 | View Code Duplication | elseif (!@ldap_set_option($link, LDAP_OPT_REFERRALS, 0)) |
|
147 | { |
||
148 | debug_write_log(DEBUG_ERROR, '[ldap_finduser] ldap_set_option(LDAP_OPT_REFERRALS) error: ' . ldap_err2str(ldap_errno($link))); |
||
149 | } |
||
150 | View Code Duplication | elseif (LDAP_USE_TLS && !@ldap_start_tls($link)) |
|
151 | { |
||
152 | debug_write_log(DEBUG_ERROR, '[ldap_finduser] ldap_start_tls() error: ' . ldap_err2str(ldap_errno($link))); |
||
153 | } |
||
154 | View Code Duplication | elseif (!@ldap_bind($link, LDAP_USERNAME, LDAP_PASSWORD)) |
|
155 | { |
||
156 | debug_write_log(DEBUG_WARNING, '[ldap_finduser] ldap_bind(anonymous) error: ' . ldap_err2str(ldap_errno($link))); |
||
157 | } |
||
158 | else |
||
159 | { |
||
160 | $attrs = array('dn', LDAP_ATTR_FULLNAME, LDAP_ATTR_EMAIL); |
||
161 | $basedn = mb_split(';', LDAP_BASEDN); |
||
162 | |||
163 | for ($i = 0; $i < count($basedn) && is_null($retval); $i++) |
||
164 | { |
||
165 | debug_write_log(DEBUG_DUMP, '[ldap_finduser] $basedn = ' . $basedn[$i]); |
||
166 | |||
167 | $result = @ldap_search($link, $basedn[$i], sprintf("(%s=%s)", LDAP_ATTR_LOGIN, $username), $attrs); |
||
168 | |||
169 | if (!$result) |
||
170 | { |
||
171 | debug_write_log(DEBUG_WARNING, '[ldap_finduser] ldap_search() error: ' . ldap_err2str(ldap_errno($link))); |
||
172 | } |
||
173 | else |
||
174 | { |
||
175 | $entries = @ldap_get_entries($link, $result); |
||
176 | |||
177 | if (!$entries || count($entries) <= 1) |
||
178 | { |
||
179 | debug_write_log(DEBUG_WARNING, '[ldap_finduser] ldap_get_entries() error: ' . ldap_err2str(ldap_errno($link))); |
||
180 | } |
||
181 | elseif (!is_null($password) && !@ldap_bind($link, $entries[0]['dn'], $password)) |
||
182 | { |
||
183 | debug_write_log(DEBUG_WARNING, '[ldap_finduser] ldap_bind(username) error: ' . ldap_err2str(ldap_errno($link))); |
||
184 | } |
||
185 | else |
||
186 | { |
||
187 | if (empty($entries[0][LDAP_ATTR_FULLNAME][0]) || |
||
188 | empty($entries[0][LDAP_ATTR_EMAIL ][0])) |
||
189 | { |
||
190 | debug_write_log(DEBUG_NOTICE, '[ldap_finduser] Found entries are empty.'); |
||
191 | } |
||
192 | else |
||
193 | { |
||
194 | debug_write_log(DEBUG_DUMP, '[ldap_finduser] LDAP(displayname) = ' . $entries[0][LDAP_ATTR_FULLNAME][0]); |
||
195 | debug_write_log(DEBUG_DUMP, '[ldap_finduser] LDAP(mail) = ' . $entries[0][LDAP_ATTR_EMAIL ][0]); |
||
196 | |||
197 | $retval = array($entries[0][LDAP_ATTR_FULLNAME][0], |
||
198 | $entries[0][LDAP_ATTR_EMAIL ][0]); |
||
199 | } |
||
200 | } |
||
201 | } |
||
202 | } |
||
203 | } |
||
204 | |||
205 | ldap_close($link); |
||
206 | |||
207 | return $retval; |
||
208 | } |
||
209 | |||
210 | /** |
||
211 | * Searches for all users of LDAP server and returns array with all findings. |
||
212 | * |
||
213 | * If login, display name, or email of some LDAP user is empty, it will not be returned. |
||
214 | * |
||
215 | * @return array Array, where each item is associative array with two items. |
||
216 | * First item is user's login and accessable via "username" index. |
||
217 | * Second item is user's display name and accessable via "fullname" index. |
||
218 | */ |
||
219 | function ldap_findallusers () |
||
220 | { |
||
221 | debug_write_log(DEBUG_TRACE, '[ldap_findallusers]'); |
||
222 | |||
223 | $link = @ldap_connect(LDAP_HOST, LDAP_PORT); |
||
224 | |||
225 | if (!$link) |
||
226 | { |
||
227 | debug_write_log(DEBUG_ERROR, '[ldap_findallusers] ldap_connect() error.'); |
||
228 | return NULL; |
||
229 | } |
||
230 | |||
231 | $retval = array(); |
||
232 | |||
233 | if (!@ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, 3)) |
||
234 | { |
||
235 | debug_write_log(DEBUG_ERROR, '[ldap_findallusers] ldap_set_option(LDAP_OPT_PROTOCOL_VERSION) error: ' . ldap_err2str(ldap_errno($link))); |
||
236 | } |
||
237 | View Code Duplication | elseif (!@ldap_set_option($link, LDAP_OPT_REFERRALS, 0)) |
|
238 | { |
||
239 | debug_write_log(DEBUG_ERROR, '[ldap_findallusers] ldap_set_option(LDAP_OPT_REFERRALS) error: ' . ldap_err2str(ldap_errno($link))); |
||
240 | } |
||
241 | View Code Duplication | elseif (LDAP_USE_TLS && !@ldap_start_tls($link)) |
|
242 | { |
||
243 | debug_write_log(DEBUG_ERROR, '[ldap_finduser] ldap_start_tls() error: ' . ldap_err2str(ldap_errno($link))); |
||
244 | } |
||
245 | View Code Duplication | elseif (!@ldap_bind($link, LDAP_USERNAME, LDAP_PASSWORD)) |
|
246 | { |
||
247 | debug_write_log(DEBUG_WARNING, '[ldap_findallusers] ldap_bind(anonymous) error: ' . ldap_err2str(ldap_errno($link))); |
||
248 | } |
||
249 | else |
||
250 | { |
||
251 | $attrs = array(LDAP_ATTR_LOGIN, LDAP_ATTR_FULLNAME, LDAP_ATTR_EMAIL); |
||
252 | $basedn = mb_split(';', LDAP_BASEDN); |
||
253 | |||
254 | for ($i = 0; $i < count($basedn); $i++) |
||
0 ignored issues
–
show
|
|||
255 | { |
||
256 | debug_write_log(DEBUG_DUMP, '[ldap_findallusers] $basedn = ' . $basedn[$i]); |
||
257 | |||
258 | $result = @ldap_search($link, $basedn[$i], sprintf("(&(objectcategory=person)(objectclass=user)(%s=*))", LDAP_ATTR_LOGIN), $attrs); |
||
259 | |||
260 | if (!$result) |
||
261 | { |
||
262 | debug_write_log(DEBUG_WARNING, '[ldap_findallusers] ldap_search() error: ' . ldap_err2str(ldap_errno($link))); |
||
263 | } |
||
264 | else |
||
265 | { |
||
266 | $entries = @ldap_get_entries($link, $result); |
||
267 | |||
268 | if (!$entries || count($entries) <= 1) |
||
269 | { |
||
270 | debug_write_log(DEBUG_WARNING, '[ldap_findallusers] ldap_get_entries() error: ' . ldap_err2str(ldap_errno($link))); |
||
271 | } |
||
272 | else |
||
273 | { |
||
274 | for ($i = 0; $i < count($entries) - 1; $i++) |
||
275 | { |
||
276 | if (!empty($entries[$i][LDAP_ATTR_LOGIN ][0]) && |
||
277 | !empty($entries[$i][LDAP_ATTR_FULLNAME][0]) && |
||
278 | !empty($entries[$i][LDAP_ATTR_EMAIL ][0])) |
||
279 | { |
||
280 | $entry = array('username' => $entries[$i][LDAP_ATTR_LOGIN ][0], |
||
281 | 'fullname' => $entries[$i][LDAP_ATTR_FULLNAME][0]); |
||
282 | |||
283 | array_push($retval, $entry); |
||
284 | } |
||
285 | } |
||
286 | } |
||
287 | } |
||
288 | } |
||
289 | } |
||
290 | |||
291 | ldap_close($link); |
||
292 | |||
293 | return $retval; |
||
294 | } |
||
295 | |||
296 | ?> |
||
297 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: