Skip to content

Commit 7fecb65

Browse files
author
robin.kluth
committed
* Fix fetchUserData for Usernames containing the whole DN
1 parent fec65ad commit 7fecb65

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/LdapAuth.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,23 +238,35 @@ public function fetchUserData($attributes = "")
238238
array_push($attributes, 'objectSid'); # Push objectsid, regardless of source array, as we need it ALWAYS!
239239
array_push($attributes, 'sIDHistory'); # Push sIDHistory, regardless of source array, as we need it ALWAYS!
240240

241+
$baseDN = $this->_ldapBaseDn;
241242
$search_filter = '(&(objectCategory=person)(samaccountname=' . $this->_username . '))';
242243

243-
$result = ldap_search($this->_l, $this->_ldapBaseDn, $search_filter, $attributes);
244+
if (strpos(strtolower($this->_username), 'cn=') === 0) {
245+
$baseDN = $this->_username;
246+
$search_filter = '(&(objectCategory=person))';
247+
}
248+
249+
Yii::debug('[FetchUserData]: BaseDN: ' . $baseDN, __METHOD__);
250+
Yii::debug('[FetchUserData]: Filter: ' . $search_filter, __METHOD__);
251+
252+
253+
$result = ldap_search($this->_l, $baseDN, $search_filter, $attributes);
244254

245255
if ($result) {
246256
$entries = ldap_get_entries($this->_l, $result);
247257
if ($entries['count'] > 1 || $entries['count'] == 0) {
258+
Yii::error('[FetchUserData]: Found 0 or more than one result!', __METHOD__);
248259
return false;
249260
}
250261
if (!isset($entries[0]) && !isset($entries[0]['objectsid'])) {
251-
Yii::error('No objectsid!', __METHOD__);
262+
Yii::error('[FetchUserData]: No objectsid!', __METHOD__);
252263
return false;
253264
}
254265
$sid = self::SIDtoString($entries[0]['objectsid'])[0];
255266
$sidHistory = isset($entries[0]['sidhistory']) ? self::SIDtoString($entries[0]['sidhistory']) : null;
256267
return array_merge(['sid' => $sid, 'sidhistory' => $sidHistory], self::handleEntry($entries[0]));
257268
} else {
269+
Yii::error('[FetchUserData]: Search failed: ' . ldap_error($this->_l), __METHOD__);
258270
return false;
259271
}
260272
}

0 commit comments

Comments
 (0)