@@ -238,23 +238,35 @@ public function fetchUserData($attributes = "")
238
238
array_push ($ attributes , 'objectSid ' ); # Push objectsid, regardless of source array, as we need it ALWAYS!
239
239
array_push ($ attributes , 'sIDHistory ' ); # Push sIDHistory, regardless of source array, as we need it ALWAYS!
240
240
241
+ $ baseDN = $ this ->_ldapBaseDn ;
241
242
$ search_filter = '(&(objectCategory=person)(samaccountname= ' . $ this ->_username . ')) ' ;
242
243
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 );
244
254
245
255
if ($ result ) {
246
256
$ entries = ldap_get_entries ($ this ->_l , $ result );
247
257
if ($ entries ['count ' ] > 1 || $ entries ['count ' ] == 0 ) {
258
+ Yii::error ('[FetchUserData]: Found 0 or more than one result! ' , __METHOD__ );
248
259
return false ;
249
260
}
250
261
if (!isset ($ entries [0 ]) && !isset ($ entries [0 ]['objectsid ' ])) {
251
- Yii::error ('No objectsid! ' , __METHOD__ );
262
+ Yii::error ('[FetchUserData]: No objectsid! ' , __METHOD__ );
252
263
return false ;
253
264
}
254
265
$ sid = self ::SIDtoString ($ entries [0 ]['objectsid ' ])[0 ];
255
266
$ sidHistory = isset ($ entries [0 ]['sidhistory ' ]) ? self ::SIDtoString ($ entries [0 ]['sidhistory ' ]) : null ;
256
267
return array_merge (['sid ' => $ sid , 'sidhistory ' => $ sidHistory ], self ::handleEntry ($ entries [0 ]));
257
268
} else {
269
+ Yii::error ('[FetchUserData]: Search failed: ' . ldap_error ($ this ->_l ), __METHOD__ );
258
270
return false ;
259
271
}
260
272
}
0 commit comments