@@ -609,33 +609,49 @@ public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped
609609 // outside of core user management will still cache the user as non-existing.
610610 $ originalTTL = $ this ->connection ->ldapCacheTTL ;
611611 $ this ->connection ->setConfiguration (['ldapCacheTTL ' => 0 ]);
612- if (( $ isUser && $ intName !== '' && ! $ this -> ncUserManager -> userExists ( $ intName ))
613- || (! $ isUser && !\ OC :: $ server -> getGroupManager ()-> groupExists ($ intName ))) {
614- if ( $ mapper -> map ( $ fdn , $ intName, $ uuid )) {
615- $ this -> connection -> setConfiguration ([ ' ldapCacheTTL ' => $ originalTTL ]);
616- if ( $ this -> ncUserManager instanceof PublicEmitter && $ isUser ) {
617- $ this ->ncUserManager -> emit ( ' \OC\User ' , ' assignedUserId ' , [ $ intName ]);
618- }
619- $ newlyMapped = true ;
612+ if ( $ intName !== ''
613+ && (( $ isUser && !$ this -> ncUserManager -> userExists ($ intName ))
614+ || (! $ isUser && !\ OC :: $ server -> getGroupManager ()-> groupExists ( $ intName))
615+ )
616+ ) {
617+ $ this ->connection -> setConfiguration ([ ' ldapCacheTTL ' => $ originalTTL ]);
618+ $ newlyMapped = $ this -> mapAndAnnounceIfApplicable ( $ mapper , $ fdn , $ intName , $ uuid , $ isUser );
619+ if ( $ newlyMapped) {
620620 return $ intName ;
621621 }
622622 }
623- $ this ->connection ->setConfiguration (['ldapCacheTTL ' => $ originalTTL ]);
624623
624+ $ this ->connection ->setConfiguration (['ldapCacheTTL ' => $ originalTTL ]);
625625 $ altName = $ this ->createAltInternalOwnCloudName ($ intName , $ isUser );
626- if (is_string ($ altName ) && $ mapper ->map ($ fdn , $ altName , $ uuid )) {
627- if ($ this ->ncUserManager instanceof PublicEmitter && $ isUser ) {
628- $ this ->ncUserManager ->emit ('\OC\User ' , 'assignedUserId ' , [$ altName ]);
626+ if (is_string ($ altName )) {
627+ if ($ this ->mapAndAnnounceIfApplicable ($ mapper , $ fdn , $ altName , $ uuid , $ isUser )) {
628+ $ newlyMapped = true ;
629+ return $ altName ;
629630 }
630- $ newlyMapped = true ;
631- return $ altName ;
632631 }
633632
634633 //if everything else did not help..
635634 \OCP \Util::writeLog ('user_ldap ' , 'Could not create unique name for ' .$ fdn .'. ' , ILogger::INFO );
636635 return false ;
637636 }
638637
638+ protected function mapAndAnnounceIfApplicable (
639+ AbstractMapping $ mapper ,
640+ string $ fdn ,
641+ string $ name ,
642+ string $ uuid ,
643+ bool $ isUser
644+ ) :bool {
645+ if ($ mapper ->map ($ fdn , $ name , $ uuid )) {
646+ if ($ this ->ncUserManager instanceof PublicEmitter && $ isUser ) {
647+ $ this ->cacheUserExists ($ name );
648+ $ this ->ncUserManager ->emit ('\OC\User ' , 'assignedUserId ' , [$ name ]);
649+ }
650+ return true ;
651+ }
652+ return false ;
653+ }
654+
639655 /**
640656 * gives back the user names as they are used ownClod internally
641657 * @param array $ldapUsers as returned by fetchList()
0 commit comments