From 45443ee28cb0695a99d1d367baee9433d3420914 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 8 Dec 2014 17:12:13 +0100 Subject: [PATCH 1/2] preserve an asterisk at the start when escaping a search term --- apps/user_ldap/lib/access.php | 9 +++++++-- apps/user_ldap/user_ldap.php | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php index 5a4d324fba2..1adb25690d0 100644 --- a/apps/user_ldap/lib/access.php +++ b/apps/user_ldap/lib/access.php @@ -1087,10 +1087,15 @@ class Access extends LDAPUtility implements user\IUserTools { * @param string $input, the provided value * @return string the escaped string */ - public function escapeFilterPart($input) { + public function escapeFilterPart($input, $allowAsterisk = false) { + $asterisk = ''; + if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { + $asterisk = '*'; + $input = mb_substr($input, 1, null, 'UTF-8'); + } $search = array('*', '\\', '(', ')'); $replace = array('\\*', '\\\\', '\\(', '\\)'); - return str_replace($search, $replace, $input); + return $asterisk . str_replace($search, $replace, $input); } /** diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php index 38c32cbda4a..52278082312 100644 --- a/apps/user_ldap/user_ldap.php +++ b/apps/user_ldap/user_ldap.php @@ -93,7 +93,7 @@ class USER_LDAP extends BackendUtility implements \OCP\UserInterface { * Get a list of all users. */ public function getUsers($search = '', $limit = 10, $offset = 0) { - $search = $this->access->escapeFilterPart($search); + $search = $this->access->escapeFilterPart($search, true); $cachekey = 'getUsers-'.$search.'-'.$limit.'-'.$offset; //check if users are cached, if so return From 0577bb569ab3d6b35f36e3ef59c21587125ebc88 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 8 Dec 2014 17:22:52 +0100 Subject: [PATCH 2/2] add doc --- apps/user_ldap/lib/access.php | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php index 1adb25690d0..76747be70cf 100644 --- a/apps/user_ldap/lib/access.php +++ b/apps/user_ldap/lib/access.php @@ -1085,6 +1085,7 @@ class Access extends LDAPUtility implements user\IUserTools { /** * escapes (user provided) parts for LDAP filter * @param string $input, the provided value + * @param bool $allowAsterisk wether in * at the beginning should be preserved * @return string the escaped string */ public function escapeFilterPart($input, $allowAsterisk = false) {