From a721f7d59f4851bf13b6387e1f6d19fa3175d61b Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 6 Feb 2013 02:26:35 +0100 Subject: [PATCH 1/6] check whether user belongs to the backend before calling getHome() --- lib/user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/user.php b/lib/user.php index f953d22154..f530163e5b 100644 --- a/lib/user.php +++ b/lib/user.php @@ -467,7 +467,7 @@ class OC_User { */ public static function getHome($uid) { 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); if($result) { return $result; From 3cef8f1216a776c1537105cc24facc44e2843a9a Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 6 Feb 2013 02:28:09 +0100 Subject: [PATCH 2/6] 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 --- apps/user_ldap/user_ldap.php | 53 +++++++++++++++++------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php index 6aa8cd9b83..540b22c7dc 100644 --- a/apps/user_ldap/user_ldap.php +++ b/apps/user_ldap/user_ldap.php @@ -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; } From c6aa370604d5a5898719ef9378f3444171016768 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 6 Feb 2013 02:29:03 +0100 Subject: [PATCH 3/6] code style --- apps/user_ldap/user_ldap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php index 540b22c7dc..0962756228 100644 --- a/apps/user_ldap/user_ldap.php +++ b/apps/user_ldap/user_ldap.php @@ -193,7 +193,7 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface { ) { $homedir = $path; } else { - $homedir = \OCP\Config::getSystemValue( "datadirectory", \OC::$SERVERROOT."/data" ) . '/' . $homedir[0]; + $homedir = \OCP\Config::getSystemValue('datadirectory', \OC::$SERVERROOT.'/data' ) . '/' . $homedir[0]; } $this->connection->writeToCache($cacheKey, $homedir); return $homedir; From 993831b6df5e7df1a6fcc7344f1fecd93006674c Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 6 Feb 2013 02:29:55 +0100 Subject: [PATCH 4/6] LDAP: version bump -> clean up database --- apps/user_ldap/appinfo/update.php | 5 ++++- apps/user_ldap/appinfo/version | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/user_ldap/appinfo/update.php b/apps/user_ldap/appinfo/update.php index f9681e38e6..5b8364884f 100644 --- a/apps/user_ldap/appinfo/update.php +++ b/apps/user_ldap/appinfo/update.php @@ -87,4 +87,7 @@ if(!isset($connector)) { } //it is required, that connections do have ldap_configuration_active setting stored in the database $connector->getConfiguration(); -$connector->saveConfiguration(); \ No newline at end of file +$connector->saveConfiguration(); + +// we don't save it anymore, was a well-meant bad idea +\OC_Preferences::deleteKey('%', 'user_ldap' , 'homedir'); \ No newline at end of file diff --git a/apps/user_ldap/appinfo/version b/apps/user_ldap/appinfo/version index 705e30728e..44938339fa 100644 --- a/apps/user_ldap/appinfo/version +++ b/apps/user_ldap/appinfo/version @@ -1 +1 @@ -0.3.9.0 \ No newline at end of file +0.3.9.1 \ No newline at end of file From af2acadc6602b2ebd33a8b7d74d82e1590870c0a Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 6 Feb 2013 13:04:35 +0100 Subject: [PATCH 5/6] LDAP: fix settings handling of homeFolderNamingRule option --- apps/user_ldap/lib/connection.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php index acc33e047c..63d0f2ac20 100644 --- a/apps/user_ldap/lib/connection.php +++ b/apps/user_ldap/lib/connection.php @@ -294,6 +294,11 @@ class Connection { $params = $this->getConfigTranslationArray(); foreach($config as $parameter => $value) { + if(($parameter == 'homeFolderNamingRule' + || $params[$parameter] == 'homeFolderNamingRule') + && !empty($value)) { + $value = 'attr:'.$value; + } if(isset($this->config[$parameter])) { $this->config[$parameter] = $value; if(is_array($setParameters)) { @@ -324,7 +329,7 @@ class Connection { $value = base64_encode($value); break; case 'homeFolderNamingRule': - $value = empty($value) ? 'opt:username' : 'attr:'.$value; + $value = empty($value) ? 'opt:username' : $value; break; case 'ldapBase': case 'ldapBaseUsers': From 1c94ec71eff884238e2269407cca5ee3d02f8a63 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 9 Feb 2013 13:10:53 +0100 Subject: [PATCH 6/6] LDAP: fix database cleanup in update script --- apps/user_ldap/appinfo/update.php | 5 +++-- apps/user_ldap/appinfo/version | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/user_ldap/appinfo/update.php b/apps/user_ldap/appinfo/update.php index 5b8364884f..bc32d4ef4c 100644 --- a/apps/user_ldap/appinfo/update.php +++ b/apps/user_ldap/appinfo/update.php @@ -89,5 +89,6 @@ if(!isset($connector)) { $connector->getConfiguration(); $connector->saveConfiguration(); -// we don't save it anymore, was a well-meant bad idea -\OC_Preferences::deleteKey('%', 'user_ldap' , 'homedir'); \ No newline at end of file +// 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')); diff --git a/apps/user_ldap/appinfo/version b/apps/user_ldap/appinfo/version index 44938339fa..e4d93c8d61 100644 --- a/apps/user_ldap/appinfo/version +++ b/apps/user_ldap/appinfo/version @@ -1 +1 @@ -0.3.9.1 \ No newline at end of file +0.3.9.4 \ No newline at end of file