throw NoUserException in getHome when the requested user does not exist anymore

This commit is contained in:
Arthur Schiwon 2015-12-11 00:12:41 +01:00
parent ae6c3c1539
commit 8c79300156
1 changed files with 25 additions and 5 deletions

View File

@ -30,6 +30,7 @@
namespace OCA\user_ldap; namespace OCA\user_ldap;
use OC\User\NoUserException;
use OCA\user_ldap\lib\BackendUtility; use OCA\user_ldap\lib\BackendUtility;
use OCA\user_ldap\lib\Access; use OCA\user_ldap\lib\Access;
use OCA\user_ldap\lib\user\OfflineUser; use OCA\user_ldap\lib\user\OfflineUser;
@ -190,15 +191,18 @@ class USER_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
/** /**
* checks whether a user is still available on LDAP * checks whether a user is still available on LDAP
*
* @param string|\OCA\User_LDAP\lib\user\User $user either the ownCloud user * @param string|\OCA\User_LDAP\lib\user\User $user either the ownCloud user
* name or an instance of that user * name or an instance of that user
* @return bool * @return bool
* @throws \Exception
* @throws \OC\ServerNotAvailableException
*/ */
public function userExistsOnLDAP($user) { public function userExistsOnLDAP($user) {
if(is_string($user)) { if(is_string($user)) {
$user = $this->access->userManager->get($user); $user = $this->access->userManager->get($user);
} }
if(!$user instanceof User) { if(is_null($user)) {
return false; return false;
} }
@ -212,6 +216,10 @@ class USER_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
return false; return false;
} }
if($user instanceof OfflineUser) {
$user->unmark();
}
return true; return true;
} }
@ -275,8 +283,11 @@ class USER_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
/** /**
* get the user's home directory * get the user's home directory
*
* @param string $uid the username * @param string $uid the username
* @return string|bool * @return bool|string
* @throws NoUserException
* @throws \Exception
*/ */
public function getHome($uid) { public function getHome($uid) {
if(isset($this->homesToKill[$uid]) && !empty($this->homesToKill[$uid])) { if(isset($this->homesToKill[$uid]) && !empty($this->homesToKill[$uid])) {
@ -295,6 +306,15 @@ class USER_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
} }
$user = $this->access->userManager->get($uid); $user = $this->access->userManager->get($uid);
if(is_null($user) || ($user instanceof OfflineUser && !$this->userExistsOnLDAP($user->getUID()))) {
throw new NoUserException($uid . ' is not a valid user anymore');
}
if($user instanceof OfflineUser) {
// apparently this user survived the userExistsOnLDAP check,
// we request the user instance again in order to retrieve a User
// instance instead
$user = $this->access->userManager->get($uid);
}
$path = $user->getHomePath(); $path = $user->getHomePath();
$this->access->cacheUserHome($uid, $path); $this->access->cacheUserHome($uid, $path);