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

Commit

Permalink
Stop restraining search by putting ^
Browse files Browse the repository at this point in the history
The ^ was introduced in a609f72
This broke da8e24e (which was only taking care of sql, not ldap)
If i only remember that the login contains with "jeu", now i can search ...
Introduce regexpToLdap, and use it.

"^a" matches everything that start with a
"a$" matches everything that end with a
"^a$" matches exactly a
"a" matches everything that contains a

Signed-off-by: Etienne CHAMPETIER <etienne.champetier@fiducial.net>
  • Loading branch information
Etienne CHAMPETIER committed Apr 24, 2014
1 parent 36c3aab commit 1b97c71
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
18 changes: 18 additions & 0 deletions core/src/core/classes/class.AJXP_Utils.php
Expand Up @@ -1893,4 +1893,22 @@ public static function cleanLike($regexp)
{
return ltrim(rtrim($regexp, "%"), "%");
}

public static function regexpToLdap($regexp)
{
if(empty($regexp))
return null;

$left = "*";
$right = "*";
if ($regexp[0]=="^") {
$regexp = ltrim($regexp, "^");
$left = "";
}
if ($regexp[strlen($regexp)-1] == "$") {
$regexp = rtrim($regexp, "$");
$right = "";
}
return $left.$regexp.$right;
}
}
Expand Up @@ -237,7 +237,7 @@ public function recursiveSearchGroups($baseGroup, $term)

}

$users = AuthService::listUsers($baseGroup, "^".$term);
$users = AuthService::listUsers($baseGroup, $term);
foreach ($users as $userId => $userObject) {

$nodeKey = "/data/users/".trim($userObject->getGroupPath(),"/")."/".$userId;
Expand Down
12 changes: 2 additions & 10 deletions core/src/plugins/auth.ldap/class.ldapAuthDriver.php
Expand Up @@ -330,10 +330,7 @@ public function listUsersPaginated($baseGroup, $regexp, $offset, $limit)
return array();
}

if($regexp[0]=="^") $regexp = ltrim($regexp, "^")."*";
else if($regexp[strlen($regexp)-1] == "$") $regexp = "*".rtrim($regexp, "$");

$entries = $this->getUserEntries($regexp, false, $offset, $limit, true);
$entries = $this->getUserEntries(AJXP_Utils::regexpToLdap($regexp), false, $offset, $limit, true);
$this->dynamicFilter = null;
$persons = array();
unset($entries['count']); // remove 'count' entry
Expand All @@ -354,12 +351,7 @@ public function getUsersCount($baseGroup = "/", $regexp = "", $filterProperty =
}
}

$re = null;
if (!empty($regexp)) {
if($regexp[0]=="^") $re = ltrim($regexp, "^")."*";
else if($regexp[strlen($regexp)-1] == "$") $re = "*".rtrim($regexp, "$");
}
$res = $this->getUserEntries($re, true, null);
$res = $this->getUserEntries(AJXP_Utils::regexpToLdap($regexp), true, null);
$this->dynamicFilter = null;
return $res["count"];
}
Expand Down

0 comments on commit 1b97c71

Please sign in to comment.