diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-04-17 12:49:47 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-04-17 12:49:47 +0200 |
commit | ab550d682f5ddbef35c3a11f7672c2fab26d4659 (patch) | |
tree | 5ac537f067f3886580691b32a6dd1887b5351d1e /apps | |
parent | 32000dd1af8b4b9893c5dc6ebb6f34723f83b179 (diff) | |
download | nextcloud-server-ab550d682f5ddbef35c3a11f7672c2fab26d4659.tar.gz nextcloud-server-ab550d682f5ddbef35c3a11f7672c2fab26d4659.zip |
do not rerun expensive sanitizer against already processed DNs
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/user_ldap/lib/Helper.php | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/apps/user_ldap/lib/Helper.php b/apps/user_ldap/lib/Helper.php index 90fa3d05892..2247cf6e278 100644 --- a/apps/user_ldap/lib/Helper.php +++ b/apps/user_ldap/lib/Helper.php @@ -34,6 +34,7 @@ namespace OCA\User_LDAP; +use OC\Cache\CappedMemoryCache; use OCP\IConfig; class Helper { @@ -41,6 +42,9 @@ class Helper { /** @var IConfig */ private $config; + /** @var CappedMemoryCache */ + protected $sanitizeDnCache; + /** * Helper constructor. * @@ -48,6 +52,7 @@ class Helper { */ public function __construct(IConfig $config) { $this->config = $config; + $this->sanitizeDnCache = new CappedMemoryCache(10000); } /** @@ -242,12 +247,20 @@ class Helper { return $result; } + if(!is_string($dn)) { + throw new \LogicException('String expected ' . \gettype($dn) . ' given'); + } + + if (($sanitizedDn = $this->sanitizeDnCache->get($dn)) !== null) { + return $sanitizedDn; + } + //OID sometimes gives back DNs with whitespace after the comma // a la "uid=foo, cn=bar, dn=..." We need to tackle this! - $dn = preg_replace('/([^\\\]),(\s+)/u', '\1,', $dn); + $sanitizedDn = preg_replace('/([^\\\]),(\s+)/u', '\1,', $dn); //make comparisons and everything work - $dn = mb_strtolower($dn, 'UTF-8'); + $sanitizedDn = mb_strtolower($sanitizedDn, 'UTF-8'); //escape DN values according to RFC 2253 – this is already done by ldap_explode_dn //to use the DN in search filters, \ needs to be escaped to \5c additionally @@ -265,9 +278,10 @@ class Helper { ')' => '\29', '*' => '\2A', ]; - $dn = str_replace(array_keys($replacements), array_values($replacements), $dn); + $sanitizedDn = str_replace(array_keys($replacements), array_values($replacements), $sanitizedDn); + $this->sanitizeDnCache->set($dn, $sanitizedDn); - return $dn; + return $sanitizedDn; } /** |