summaryrefslogtreecommitdiffstats
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.php59
1 files changed, 38 insertions, 21 deletions
diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php
index bacdb8b9ae1..e95bd24fbdd 100644
--- a/apps/user_ldap/user_ldap.php
+++ b/apps/user_ldap/user_ldap.php
@@ -29,11 +29,13 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface {
private function updateQuota($dn) {
$quota = null;
- if(!empty($this->connection->ldapQuotaDefault)) {
- $quota = $this->connection->ldapQuotaDefault;
+ $quotaDefault = $this->connection->ldapQuotaDefault;
+ $quotaAttribute = $this->connection->ldapQuotaAttribute;
+ if(!empty($quotaDefault)) {
+ $quota = $quotaDefault;
}
- if(!empty($this->connection->ldapQuotaAttribute)) {
- $aQuota = $this->readAttribute($dn, $this->connection->ldapQuotaAttribute);
+ if(!empty($quotaAttribute)) {
+ $aQuota = $this->readAttribute($dn, $quotaAttribute);
if($aQuota && (count($aQuota) > 0)) {
$quota = $aQuota[0];
@@ -46,8 +48,9 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface {
private function updateEmail($dn) {
$email = null;
- if(!empty($this->connection->ldapEmailAttribute)) {
- $aEmail = $this->readAttribute($dn, $this->connection->ldapEmailAttribute);
+ $emailAttribute = $this->connection->ldapEmailAttribute;
+ if(!empty($emailAttribute)) {
+ $aEmail = $this->readAttribute($dn, $emailAttribute);
if($aEmail && (count($aEmail) > 0)) {
$email = $aEmail[0];
}
@@ -101,24 +104,38 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface {
* Get a list of all users.
*/
public function getUsers($search = '', $limit = 10, $offset = 0) {
- $ldap_users = $this->connection->getFromCache('getUsers');
- if(is_null($ldap_users)) {
- $ldap_users = $this->fetchListOfUsers($this->connection->ldapUserFilter, array($this->connection->ldapUserDisplayName, 'dn'));
- $ldap_users = $this->ownCloudUserNames($ldap_users);
- $this->connection->writeToCache('getUsers', $ldap_users);
- }
- $this->userSearch = $search;
- if(!empty($this->userSearch)) {
- $ldap_users = array_filter($ldap_users, array($this, 'userMatchesFilter'));
+ $cachekey = 'getUsers-'.$search.'-'.$limit.'-'.$offset;
+
+ //check if users are cached, if so return
+ $ldap_users = $this->connection->getFromCache($cachekey);
+ if(!is_null($ldap_users)) {
+ return $ldap_users;
}
- if($limit = -1) {
- $limit = null;
+
+ //prepare search filter
+ $search = empty($search) ? '*' : '*'.$search.'*';
+ $filter = $this->combineFilterWithAnd(array(
+ $this->connection->ldapUserFilter,
+ $this->connection->ldapGroupDisplayName.'='.$search
+ ));
+
+ \OCP\Util::writeLog('user_ldap', 'getUsers: Get users filter '.$filter, \OCP\Util::DEBUG);
+ //do the search and translate results to owncloud names
+ $ldap_users = $this->fetchListOfUsers($filter, array($this->connection->ldapUserDisplayName, 'dn'), $limit, $offset);
+ $ldap_users = $this->ownCloudUserNames($ldap_users);
+
+ if(!$this->getPagedSearchResultState()) {
+ \OCP\Util::writeLog('user_ldap', 'getUsers: We got old-style results', \OCP\Util::DEBUG);
+ //if not supported, a 'normal' search has run automatically, we just need to get our slice of the cake. And we cache the general search, too
+ $this->connection->writeToCache('getUsers-'.$search, $ldap_users);
+ $ldap_users = array_slice($ldap_users, $offset, $limit);
+ } else {
+ //debug message only
+ \OCP\Util::writeLog('user_ldap', 'getUsers: We got paged results', \OCP\Util::DEBUG);
}
- return array_slice($ldap_users, $offset, $limit);
- }
- public function userMatchesFilter($user) {
- return (strripos($user, $this->userSearch) !== false);
+ $this->connection->writeToCache($cachekey, $ldap_users);
+ return $ldap_users;
}
/**