Merge pull request #1493 from owncloud/fix_ldap_stored_homedir
Fix ldap stored homedir
This commit is contained in:
commit
764409117a
|
@ -87,4 +87,8 @@ if(!isset($connector)) {
|
||||||
}
|
}
|
||||||
//it is required, that connections do have ldap_configuration_active setting stored in the database
|
//it is required, that connections do have ldap_configuration_active setting stored in the database
|
||||||
$connector->getConfiguration();
|
$connector->getConfiguration();
|
||||||
$connector->saveConfiguration();
|
$connector->saveConfiguration();
|
||||||
|
|
||||||
|
// we don't save it anymore, was a well-meant bad idea. Clean up database.
|
||||||
|
$query = OC_DB::prepare('DELETE FROM `*PREFIX*preferences` WHERE `appid` = ? AND `configkey` = ?');
|
||||||
|
$query->execute(array('user_ldap' , 'homedir'));
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.3.9.0
|
0.3.9.4
|
|
@ -294,6 +294,11 @@ class Connection {
|
||||||
$params = $this->getConfigTranslationArray();
|
$params = $this->getConfigTranslationArray();
|
||||||
|
|
||||||
foreach($config as $parameter => $value) {
|
foreach($config as $parameter => $value) {
|
||||||
|
if(($parameter == 'homeFolderNamingRule'
|
||||||
|
|| $params[$parameter] == 'homeFolderNamingRule')
|
||||||
|
&& !empty($value)) {
|
||||||
|
$value = 'attr:'.$value;
|
||||||
|
}
|
||||||
if(isset($this->config[$parameter])) {
|
if(isset($this->config[$parameter])) {
|
||||||
$this->config[$parameter] = $value;
|
$this->config[$parameter] = $value;
|
||||||
if(is_array($setParameters)) {
|
if(is_array($setParameters)) {
|
||||||
|
@ -324,7 +329,7 @@ class Connection {
|
||||||
$value = base64_encode($value);
|
$value = base64_encode($value);
|
||||||
break;
|
break;
|
||||||
case 'homeFolderNamingRule':
|
case 'homeFolderNamingRule':
|
||||||
$value = empty($value) ? 'opt:username' : 'attr:'.$value;
|
$value = empty($value) ? 'opt:username' : $value;
|
||||||
break;
|
break;
|
||||||
case 'ldapBase':
|
case 'ldapBase':
|
||||||
case 'ldapBaseUsers':
|
case 'ldapBaseUsers':
|
||||||
|
|
|
@ -170,41 +170,38 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface {
|
||||||
return false;
|
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
|
* @brief get the user's home directory
|
||||||
* @param string $uid the username
|
* @param string $uid the username
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function getHome($uid) {
|
public function getHome($uid) {
|
||||||
if($this->userExists($uid)) {
|
$cacheKey = 'getHome'.$uid;
|
||||||
$homedir = \OCP\Config::getUserValue($uid, 'user_ldap', 'homedir', false);
|
if($this->connection->isCached($cacheKey)) {
|
||||||
if(!$homedir) {
|
return $this->connection->getFromCache($cacheKey);
|
||||||
$homedir = $this->determineHomeDir($uid);
|
|
||||||
}
|
|
||||||
return $homedir;
|
|
||||||
}
|
}
|
||||||
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -487,7 +487,7 @@ class OC_User {
|
||||||
*/
|
*/
|
||||||
public static function getHome($uid) {
|
public static function getHome($uid) {
|
||||||
foreach(self::$_usedBackends as $backend) {
|
foreach(self::$_usedBackends as $backend) {
|
||||||
if($backend->implementsActions(OC_USER_BACKEND_GET_HOME)) {
|
if($backend->implementsActions(OC_USER_BACKEND_GET_HOME) && $backend->userExists($uid)) {
|
||||||
$result=$backend->getHome($uid);
|
$result=$backend->getHome($uid);
|
||||||
if($result) {
|
if($result) {
|
||||||
return $result;
|
return $result;
|
||||||
|
|
Loading…
Reference in New Issue