aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/user_ldap.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/user_ldap.php')
-rw-r--r--apps/user_ldap/user_ldap.php89
1 files changed, 65 insertions, 24 deletions
diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php
index 6591d1d5fee..0962756228c 100644
--- a/apps/user_ldap/user_ldap.php
+++ b/apps/user_ldap/user_ldap.php
@@ -116,10 +116,9 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface {
if($limit <= 0) {
$limit = null;
}
- $search = empty($search) ? '*' : '*'.$search.'*';
$filter = $this->combineFilterWithAnd(array(
$this->connection->ldapUserFilter,
- $this->connection->ldapUserDisplayName.'='.$search
+ $this->getFilterPartForUserSearch($search)
));
\OCP\Util::writeLog('user_ldap', 'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter, \OCP\Util::DEBUG);
@@ -156,6 +155,7 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface {
}
$this->connection->writeToCache('userExists'.$uid, true);
+ $this->updateQuota($dn);
return true;
}
@@ -171,41 +171,82 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface {
}
/**
- * @brief determine the user's home directory
- * @param string $uid the owncloud username
+ * @brief get the user's home directory
+ * @param string $uid the username
* @return boolean
*/
- private function determineHomeDir($uid) {
+ public function getHome($uid) {
+ $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) {
- $homedir = \OCP\Config::getSystemValue( "datadirectory", \OC::$SERVERROOT."/data" ) . '/' . $homedir[0];
- \OCP\Config::setUserValue($uid, 'user_ldap', 'homedir', $homedir);
+ 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;
}
}
- //fallback and default: username
- $homedir = \OCP\Config::getSystemValue( "datadirectory", \OC::$SERVERROOT."/data" ) . '/' . $uid;
- \OCP\Config::setUserValue($uid, 'user_ldap', 'homedir', $homedir);
- return $homedir;
+ //false will apply default behaviour as defined and done by OC_User
+ $this->connection->writeToCache($cacheKey, false);
+ return false;
}
/**
- * @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;
+ * @brief get display name of the user
+ * @param $uid user ID of the user
+ * @return display name
+ */
+ public function getDisplayName($uid) {
+ $cacheKey = 'getDisplayName'.$uid;
+ if(!is_null($displayName = $this->connection->getFromCache($cacheKey))) {
+ return $displayName;
}
- return false;
+
+ $displayName = $this->readAttribute(
+ $this->username2dn($uid),
+ $this->connection->ldapUserDisplayName);
+
+ if($displayName && (count($displayName) > 0)) {
+ $this->connection->writeToCache($cacheKey, $displayName);
+ return $displayName[0];
+ }
+
+ return null;
+ }
+
+ /**
+ * @brief Get a list of all display names
+ * @returns array with all displayNames (value) and the correspondig uids (key)
+ *
+ * Get a list of all display names and user ids.
+ */
+ public function getDisplayNames($search = '', $limit = null, $offset = null) {
+ $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
+ if(!is_null($displayNames = $this->connection->getFromCache($cacheKey))) {
+ return $displayNames;
+ }
+
+ $displayNames = array();
+ $users = $this->getUsers($search, $limit, $offset);
+ foreach ($users as $user) {
+ $displayNames[$user] = $this->getDisplayName($user);
+ }
+ $this->connection->writeToCache($cacheKey, $displayNames);
+ return $displayNames;
}
/**