@@ -527,6 +527,7 @@ public function dn2username($fdn, $ldapName = null) {
527527 * @param bool|null $newlyMapped
528528 * @param array|null $record
529529 * @return false|string with with the name to use in Nextcloud
530+ * @throws \Exception
530531 */
531532 public function dn2ocname ($ fdn , $ ldapName = null , $ isUser = true , &$ newlyMapped = null , array $ record = null ) {
532533 $ newlyMapped = false ;
@@ -586,7 +587,7 @@ public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped
586587 // outside of core user management will still cache the user as non-existing.
587588 $ originalTTL = $ this ->connection ->ldapCacheTTL ;
588589 $ this ->connection ->setConfiguration (array ('ldapCacheTTL ' => 0 ));
589- if (($ isUser && !\OCP \User::userExists ($ intName ))
590+ if (($ isUser && $ intName !== '' && !\OCP \User::userExists ($ intName ))
590591 || (!$ isUser && !\OC ::$ server ->getGroupManager ()->groupExists ($ intName ))) {
591592 if ($ mapper ->map ($ fdn , $ intName , $ uuid )) {
592593 $ this ->connection ->setConfiguration (array ('ldapCacheTTL ' => $ originalTTL ));
@@ -830,7 +831,9 @@ public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null,
830831 $ recordsToUpdate = array_filter ($ ldapRecords , function ($ record ) use ($ isBackgroundJobModeAjax ) {
831832 $ newlyMapped = false ;
832833 $ uid = $ this ->dn2ocname ($ record ['dn ' ][0 ], null , true , $ newlyMapped , $ record );
833- $ this ->cacheUserExists ($ uid );
834+ if (is_string ($ uid )) {
835+ $ this ->cacheUserExists ($ uid );
836+ }
834837 return ($ uid !== false ) && ($ newlyMapped || $ isBackgroundJobModeAjax );
835838 });
836839 }
@@ -1022,7 +1025,7 @@ private function invokeLDAPMethod() {
10221025 *
10231026 * @param $filter
10241027 * @param $base
1025- * @param null $attr
1028+ * @param string[]| null $attr
10261029 * @param int $limit optional, maximum results to be counted
10271030 * @param int $offset optional, a starting point
10281031 * @return array|false array with the search result as first value and pagedSearchOK as
@@ -1106,6 +1109,7 @@ private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $li
11061109
11071110 /**
11081111 * executes an LDAP search, but counts the results only
1112+ *
11091113 * @param string $filter the LDAP filter for the search
11101114 * @param array $base an array containing the LDAP subtree(s) that shall be searched
11111115 * @param string|string[] $attr optional, array, one or more attributes that shall be
@@ -1115,7 +1119,7 @@ private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $li
11151119 * @param bool $skipHandling indicates whether the pages search operation is
11161120 * completed
11171121 * @return int|false Integer or false if the search could not be initialized
1118- *
1122+ * @throws ServerNotAvailableException
11191123 */
11201124 private function count ($ filter , $ base , $ attr = null , $ limit = null , $ offset = null , $ skipHandling = false ) {
11211125 \OCP \Util::writeLog ('user_ldap ' , 'Count filter: ' .print_r ($ filter , true ), \OCP \Util::DEBUG );
@@ -1130,8 +1134,7 @@ private function count($filter, $base, $attr = null, $limit = null, $offset = nu
11301134 $ this ->connection ->getConnectionResource ();
11311135
11321136 do {
1133- $ search = $ this ->executeSearch ($ filter , $ base , $ attr ,
1134- $ limitPerPage , $ offset );
1137+ $ search = $ this ->executeSearch ($ filter , $ base , $ attr , $ limitPerPage , $ offset );
11351138 if ($ search === false ) {
11361139 return $ counter > 0 ? $ counter : false ;
11371140 }
@@ -1286,7 +1289,7 @@ public function search($filter, $base, $attr = null, $limit = null, $offset = nu
12861289 */
12871290 public function sanitizeUsername ($ name ) {
12881291 if ($ this ->connection ->ldapIgnoreNamingRules ) {
1289- return $ name ;
1292+ return trim ( $ name) ;
12901293 }
12911294
12921295 // Transliteration
0 commit comments