$asterisk = '*';
$input = mb_substr($input, 1, null, 'UTF-8');
}
- $search = ['*', '\\', '(', ')'];
- $replace = ['\\*', '\\\\', '\\(', '\\)'];
- return $asterisk . str_replace($search, $replace, $input);
+ return $asterisk . ldap_escape($input, '', LDAP_ESCAPE_FILTER);
}
/**
if (is_array($objcs) && count($objcs) > 0) {
$filter .= '(|';
foreach ($objcs as $objc) {
- $filter .= '(objectclass=' . $objc . ')';
+ $filter .= '(objectclass=' . ldap_escape($objc, '', LDAP_ESCAPE_FILTER) . ')';
}
$filter .= ')';
$parts++;
}
$base = $this->configuration->ldapBase[0];
foreach ($cns as $cn) {
- $rr = $this->ldap->search($cr, $base, 'cn=' . $cn, ['dn', 'primaryGroupToken']);
+ $rr = $this->ldap->search($cr, $base, 'cn=' . ldap_escape($cn, '', LDAP_ESCAPE_FILTER), ['dn', 'primaryGroupToken']);
if (!$this->ldap->isResource($rr)) {
continue;
}
if ($dn === false || $dn === '') {
continue;
}
- $filterPart = '(memberof=' . $dn . ')';
+ $filterPart = '(memberof=' . ldap_escape($dn, '', LDAP_ESCAPE_FILTER) . ')';
if (isset($attrs['primaryGroupToken'])) {
$pgt = $attrs['primaryGroupToken'][0];
- $primaryFilterPart = '(primaryGroupID=' . $pgt .')';
+ $primaryFilterPart = '(primaryGroupID=' . ldap_escape($pgt, '', LDAP_ESCAPE_FILTER) .')';
$filterPart = '(|' . $filterPart . $primaryFilterPart . ')';
}
$filter .= $filterPart;
if (is_array($objcs) && count($objcs) > 0) {
$filter .= '(|';
foreach ($objcs as $objc) {
- $filter .= '(objectclass=' . $objc . ')';
+ $filter .= '(objectclass=' . ldap_escape($objc, '', LDAP_ESCAPE_FILTER) . ')';
}
$filter .= ')';
$parts++;
if (is_array($cns) && count($cns) > 0) {
$filter .= '(|';
foreach ($cns as $cn) {
- $filter .= '(cn=' . $cn . ')';
+ $filter .= '(cn=' . ldap_escape($cn, '', LDAP_ESCAPE_FILTER) . ')';
}
$filter .= ')';
}
public function testEscapeFilterPartEscapeWildcard() {
$input = '*';
- $expected = '\\\\*';
+ $expected = '\\2a';
$this->assertTrue($expected === $this->access->escapeFilterPart($input));
}
public function testEscapeFilterPartEscapeWildcard2() {
$input = 'foo*bar';
- $expected = 'foo\\\\*bar';
+ $expected = 'foo\\2abar';
$this->assertTrue($expected === $this->access->escapeFilterPart($input));
}