Commit b2de7a98 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Merge branch '5889-ldap-filter-parsing-issue' into '1.4-dev'

Resolve "Ldap filter parsing issue"

See merge request fusiondirectory/fd!397
Showing with 10 additions and 19 deletions
+10 -19
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/* /*
This code is part of FusionDirectory (http://www.fusiondirectory.org/) This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2013-2016 FusionDirectory Copyright (C) 2013-2018 FusionDirectory
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -122,9 +122,10 @@ class ldapFilter ...@@ -122,9 +122,10 @@ class ldapFilter
} else { } else {
return new ldapFilter($filter[0], $subfilters); return new ldapFilter($filter[0], $subfilters);
} }
} else { } elseif (preg_match('/^([^\\(\\)\\=\\>\\<]+)('.join('|', ldapFilterLeaf::$operators).')([^\\(\\)]+)$/', $filter, $m)) {
preg_match('/^(.+)('.join('|', ldapFilterLeaf::$operators).')(.+)$/', $filter, $m);
return new ldapFilterLeaf($m[1], $m[2], $m[3]); return new ldapFilterLeaf($m[1], $m[2], $m[3]);
} else {
throw new FusionDirectoryException('Failed to parse '.$filter);
} }
} }
} }
...@@ -134,7 +135,7 @@ class ldapFilter ...@@ -134,7 +135,7 @@ class ldapFilter
*/ */
class ldapFilterLeaf extends ldapFilter class ldapFilterLeaf extends ldapFilter
{ {
static $operators = array('=','=~','>','>=','<','<='); static $operators = array('=','~=','>=','<=');
protected $pattern; protected $pattern;
protected $dnFilter = FALSE; protected $dnFilter = FALSE;
...@@ -146,7 +147,7 @@ class ldapFilterLeaf extends ldapFilter ...@@ -146,7 +147,7 @@ class ldapFilterLeaf extends ldapFilter
$left = substr($left, 0, -4); $left = substr($left, 0, -4);
} }
parent::__construct($operator, array($left, $right)); parent::__construct($operator, array($left, $right));
if (($this->operator == '=') || ($this->operator == '=~')) { if (($this->operator == '=') || ($this->operator == '~=')) {
$prefix = ''; $prefix = '';
$suffix = ''; $suffix = '';
if (preg_match('/^\\*/', $this->subparts[1])) { if (preg_match('/^\\*/', $this->subparts[1])) {
...@@ -158,6 +159,8 @@ class ldapFilterLeaf extends ldapFilter ...@@ -158,6 +159,8 @@ class ldapFilterLeaf extends ldapFilter
$search = preg_replace(array('/^\\*/','/\\*$/'), '', $this->subparts[1]); $search = preg_replace(array('/^\\*/','/\\*$/'), '', $this->subparts[1]);
if ($this->dnFilter) { if ($this->dnFilter) {
$this->pattern = '/'.$left.'='.$prefix.preg_quote($search, '/').$suffix.',/'; $this->pattern = '/'.$left.'='.$prefix.preg_quote($search, '/').$suffix.',/';
} elseif ($this->subparts[1] == '*') {
$this->pattern = '/^.*$/';
} else { } else {
$this->pattern = '/^'.$prefix.preg_quote($search, '/').$suffix.'$/'; $this->pattern = '/^'.$prefix.preg_quote($search, '/').$suffix.'$/';
} }
...@@ -178,7 +181,7 @@ class ldapFilterLeaf extends ldapFilter ...@@ -178,7 +181,7 @@ class ldapFilterLeaf extends ldapFilter
{ {
if ($this->dnFilter) { if ($this->dnFilter) {
switch ($this->operator) { switch ($this->operator) {
case '=~': case '~=':
trigger_error('Filter apply might not work as expected'); trigger_error('Filter apply might not work as expected');
case '=': case '=':
return (isset($array['dn']) && preg_match($this->pattern, $array['dn'])); return (isset($array['dn']) && preg_match($this->pattern, $array['dn']));
...@@ -193,23 +196,13 @@ class ldapFilterLeaf extends ldapFilter ...@@ -193,23 +196,13 @@ class ldapFilterLeaf extends ldapFilter
} }
foreach ($values as $value) { foreach ($values as $value) {
switch ($this->operator) { switch ($this->operator) {
case '=~': case '~=':
trigger_error('Filter apply might not work as expected'); trigger_error('Filter apply might not work as expected');
case '=': case '=':
if (preg_match($this->pattern, $value)) { if (preg_match($this->pattern, $value)) {
return TRUE; return TRUE;
} }
break; break;
case '<':
if ($value < $this->subparts[1]) {
return TRUE;
}
break;
case '>':
if ($value > $this->subparts[1]) {
return TRUE;
}
break;
case '<=': case '<=':
if ($value <= $this->subparts[1]) { if ($value <= $this->subparts[1]) {
return TRUE; return TRUE;
...@@ -260,5 +253,3 @@ function fdTemplateFilter($filter) ...@@ -260,5 +253,3 @@ function fdTemplateFilter($filter)
} }
return $filter; return $filter;
} }
?>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment