Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit d43cab3

Browse files
committed
Auth.multi : when looking for shared users only, skip master driver.
Auth.ldap : fix users count caching per baseGroup.
1 parent 1ee2dba commit d43cab3

File tree

2 files changed

+51
-19
lines changed

2 files changed

+51
-19
lines changed

core/src/plugins/auth.ldap/LdapAuthDriver.php

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Pydio\Core\Controller\ProgressBarCLI;
2727
use Pydio\Core\Services\RolesService;
2828
use Pydio\Core\Services\UsersService;
29+
use Pydio\Core\Utils\FileHelper;
2930
use Pydio\Core\Utils\Vars\InputFilter;
3031
use Pydio\Core\Utils\Vars\StringHelper;
3132

@@ -343,7 +344,7 @@ public function getUserEntries($login = null, $countOnly = false, $offset = -1,
343344
//Update progress bar in CLI mode
344345
$isListAll = (($offset == -1) && ($limit == -1) && (is_null($login)) && $regexpOnSearchAttr && (php_sapi_name() == "cli"));
345346
if ($isListAll) {
346-
$total = $this->getCountFromCache();
347+
$total = $this->getCountFromCache("/");
347348
$progressBar = new ProgressBarCLI();
348349
$progressBar->init($index, $total["count"], "Get ldap users");
349350
}
@@ -460,10 +461,17 @@ public function listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recurs
460461
return $persons;
461462
}
462463

464+
/**
465+
* @param string $baseGroup
466+
* @param string $regexp
467+
* @param null $filterProperty
468+
* @param null $filterValue
469+
* @param bool $recursive
470+
* @return mixed
471+
*/
463472
public function getUsersCount($baseGroup = "/", $regexp = "", $filterProperty = null, $filterValue = null, $recursive = true)
464473
{
465-
$check_cache = $this->getCountFromCache();
466-
474+
$check_cache = $this->getCountFromCache($baseGroup);
467475
if ((is_array($check_cache) && $check_cache["count"] > 0)) {
468476
return $check_cache["count"];
469477
}
@@ -477,7 +485,7 @@ public function getUsersCount($baseGroup = "/", $regexp = "", $filterProperty =
477485
}
478486

479487
$res = $this->getUserEntries(StringHelper::regexpToLdap($regexp), true, null);
480-
$this->saveCountToCache($res);
488+
$this->saveCountToCache($res, $baseGroup);
481489
$this->dynamicFilter = null;
482490
return $res["count"];
483491
}
@@ -988,30 +996,50 @@ public function fakeMemberOf($conn, $groupDN, $filterString, $atts, &$entry)
988996
}
989997
}
990998

991-
public function getCountFromCache()
999+
/**
1000+
* @return string
1001+
* @throws \Exception
1002+
*/
1003+
private function getCacheCountFileName(){
1004+
return $this->getPluginCacheDir() . DIRECTORY_SEPARATOR . "ldap.ser";
1005+
}
1006+
1007+
/**
1008+
* @param $baseGroup
1009+
* @return int
1010+
*/
1011+
public function getCountFromCache($baseGroup)
9921012
{
9931013
$ttl = $this->getOption("LDAP_COUNT_CACHE_TTL");
9941014
if (empty($ttl)) $ttl = 1;
995-
$fileName = "ldap.ser";
996-
if (file_exists($this->getPluginCacheDir() . DIRECTORY_SEPARATOR . $fileName)) {
997-
$fileContent = unserialize(file_get_contents($this->getPluginCacheDir() . DIRECTORY_SEPARATOR . $fileName));
998-
if (($fileContent) && ($fileContent["count"]) && ($fileContent["timestamp"]) && ((time() - $fileContent["timestamp"]) < 60 * 60 * $ttl)) {
999-
return $fileContent;
1000-
}
1015+
$fileContent = FileHelper::loadSerialFile($this->getCacheCountFileName());
1016+
if (!empty($fileContent) && $fileContent[$baseGroup]["count"] && $fileContent[$baseGroup]["timestamp"] && (time() - $fileContent[$baseGroup]["timestamp"]) < 60 * 60 * $ttl ) {
1017+
return $fileContent[$baseGroup];
10011018
}
10021019
return 0;
10031020
}
10041021

1005-
public function saveCountToCache($fileContent)
1022+
/**
1023+
* @param $fileContent
1024+
* @param $baseGroup
1025+
* @throws \Exception
1026+
*/
1027+
public function saveCountToCache($fileContent, $baseGroup)
10061028
{
1007-
$fileName = "ldap.ser";
10081029
if (!is_dir($this->getPluginCacheDir(false, true))) return;
1009-
if (is_array($fileContent) && ($fileContent > 0)) {
1030+
$fileName = $this->getCacheCountFileName();
1031+
1032+
$existing = FileHelper::loadSerialFile($fileName);
1033+
if(!empty($existing) && is_array($existing)) {
1034+
$data = $existing;
1035+
}else{
1036+
$data = [];
1037+
}
1038+
1039+
if (is_array($fileContent) && count($fileContent) > 0) {
10101040
$fileContent["timestamp"] = time();
1011-
if (file_exists($this->getPluginCacheDir() . DIRECTORY_SEPARATOR . $fileName)) {
1012-
unlink($this->getPluginCacheDir() . "/" . $fileName);
1013-
}
1014-
file_put_contents($this->getPluginCacheDir() . DIRECTORY_SEPARATOR . $fileName, serialize($fileContent));
1041+
$data[$baseGroup] = $fileContent;
1042+
FileHelper::saveSerialFile($fileName, $data, false);
10151043
}
10161044
}
10171045

core/src/plugins/auth.multi/MultiAuthDriver.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,11 @@ public function getUsersCount($baseGroup = "/", $regexp = "", $filterProperty =
266266
{
267267
if (empty($this->baseName)) {
268268
if ($this->masterSlaveMode) {
269-
return $this->drivers[$this->slaveName]->getUsersCount($baseGroup, $regexp, $filterProperty, $filterValue, $recursive) + $this->drivers[$this->masterName]->getUsersCount($baseGroup, $regexp, $filterProperty, $filterValue, $recursive);
269+
if($filterProperty === 'parent' && $filterValue === AJXP_FILTER_NOT_EMPTY){
270+
return $this->drivers[$this->slaveName]->getUsersCount($baseGroup, $regexp, $filterProperty, $filterValue, $recursive);
271+
}else{
272+
return $this->drivers[$this->slaveName]->getUsersCount($baseGroup, $regexp, $filterProperty, $filterValue, $recursive) + $this->drivers[$this->masterName]->getUsersCount($baseGroup, $regexp, $filterProperty, $filterValue, $recursive);
273+
}
270274
} else {
271275
$keys = array_keys($this->drivers);
272276
return $this->drivers[$keys[0]]->getUsersCount($baseGroup, $regexp, $filterProperty, $filterValue, $recursive) + $this->drivers[$keys[1]]->getUsersCount($baseGroup, $regexp, $filterProperty, $filterValue, $recursive);

0 commit comments

Comments
 (0)