mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
LDAP: do not store user home as it destroys configurability. always fetch it. use of cache is save however, it is cleared when settings are saved
This commit is contained in:
parent
a721f7d59f
commit
3cef8f1216
1 changed files with 25 additions and 28 deletions
|
|
@ -170,41 +170,38 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief determine the user's home directory
|
||||
* @param string $uid the owncloud username
|
||||
* @return boolean
|
||||
*/
|
||||
private function determineHomeDir($uid) {
|
||||
if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
|
||||
$attr = substr($this->connection->homeFolderNamingRule, strlen('attr:'));
|
||||
$homedir = $this->readAttribute($this->username2dn($uid), $attr);
|
||||
if($homedir) {
|
||||
$homedir = \OCP\Config::getSystemValue( "datadirectory", \OC::$SERVERROOT."/data" ) . '/' . $homedir[0];
|
||||
\OCP\Config::setUserValue($uid, 'user_ldap', 'homedir', $homedir);
|
||||
return $homedir;
|
||||
}
|
||||
}
|
||||
|
||||
//fallback and default: username
|
||||
$homedir = \OCP\Config::getSystemValue( "datadirectory", \OC::$SERVERROOT."/data" ) . '/' . $uid;
|
||||
\OCP\Config::setUserValue($uid, 'user_ldap', 'homedir', $homedir);
|
||||
return $homedir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the user's home directory
|
||||
* @param string $uid the username
|
||||
* @return boolean
|
||||
*/
|
||||
public function getHome($uid) {
|
||||
if($this->userExists($uid)) {
|
||||
$homedir = \OCP\Config::getUserValue($uid, 'user_ldap', 'homedir', false);
|
||||
if(!$homedir) {
|
||||
$homedir = $this->determineHomeDir($uid);
|
||||
}
|
||||
return $homedir;
|
||||
$cacheKey = 'getHome'.$uid;
|
||||
if($this->connection->isCached($cacheKey)) {
|
||||
return $this->connection->getFromCache($cacheKey);
|
||||
}
|
||||
if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
|
||||
$attr = substr($this->connection->homeFolderNamingRule, strlen('attr:'));
|
||||
$homedir = $this->readAttribute($this->username2dn($uid), $attr);
|
||||
if($homedir && isset($homedir[0])) {
|
||||
$path = $homedir[0];
|
||||
//if attribute's value is an absolute path take this, otherwise append it to data dir
|
||||
//check for / at the beginning or pattern c:\ resp. c:/
|
||||
if(
|
||||
'/' == $path[0]
|
||||
|| (3 < strlen($path) && ctype_alpha($path[0]) && $path[1] == ':' && ('\\' == $path[2] || '/' == $path[2]))
|
||||
) {
|
||||
$homedir = $path;
|
||||
} else {
|
||||
$homedir = \OCP\Config::getSystemValue( "datadirectory", \OC::$SERVERROOT."/data" ) . '/' . $homedir[0];
|
||||
}
|
||||
$this->connection->writeToCache($cacheKey, $homedir);
|
||||
return $homedir;
|
||||
}
|
||||
}
|
||||
|
||||
//false will apply default behaviour as defined and done by OC_User
|
||||
$this->connection->writeToCache($cacheKey, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue