diff --git a/include/class_ldapFilter.inc b/include/class_ldapFilter.inc index 206d28c6de18f63e8462280bfbedf1ee96acaf1f..b9921b8550423fcf709f68dcca2cb246706aa9bd 100644 --- a/include/class_ldapFilter.inc +++ b/include/class_ldapFilter.inc @@ -1,6 +1,7 @@ <?php /* This code is part of FusionDirectory (http://www.fusiondirectory.org/) + Copyright (C) 2013-2018 FusionDirectory This program is free software; you can redistribute it and/or modify @@ -121,9 +122,10 @@ class ldapFilter } else { return new ldapFilter($filter[0], $subfilters); } - } else { - preg_match('/^(.+)('.join('|', ldapFilterLeaf::$operators).')(.+)$/', $filter, $m); + } elseif (preg_match('/^([^\\(\\)\\=\\>\\<]+)('.join('|', ldapFilterLeaf::$operators).')([^\\(\\)]+)$/', $filter, $m)) { return new ldapFilterLeaf($m[1], $m[2], $m[3]); + } else { + throw new FusionDirectoryException('Failed to parse '.$filter); } } } @@ -133,7 +135,7 @@ class ldapFilter */ class ldapFilterLeaf extends ldapFilter { - static $operators = array('=','=~','>','>=','<','<='); + static $operators = array('=','~=','>=','<='); protected $pattern; protected $dnFilter = FALSE; @@ -145,7 +147,7 @@ class ldapFilterLeaf extends ldapFilter $left = substr($left, 0, -4); } parent::__construct($operator, array($left, $right)); - if (($this->operator == '=') || ($this->operator == '=~')) { + if (($this->operator == '=') || ($this->operator == '~=')) { $prefix = ''; $suffix = ''; if (preg_match('/^\\*/', $this->subparts[1])) { @@ -157,6 +159,8 @@ class ldapFilterLeaf extends ldapFilter $search = preg_replace(array('/^\\*/','/\\*$/'), '', $this->subparts[1]); if ($this->dnFilter) { $this->pattern = '/'.$left.'='.$prefix.preg_quote($search, '/').$suffix.',/'; + } elseif ($this->subparts[1] == '*') { + $this->pattern = '/^.*$/'; } else { $this->pattern = '/^'.$prefix.preg_quote($search, '/').$suffix.'$/'; } @@ -177,7 +181,7 @@ class ldapFilterLeaf extends ldapFilter { if ($this->dnFilter) { switch ($this->operator) { - case '=~': + case '~=': trigger_error('Filter apply might not work as expected'); case '=': return (isset($array['dn']) && preg_match($this->pattern, $array['dn'])); @@ -192,23 +196,13 @@ class ldapFilterLeaf extends ldapFilter } foreach ($values as $value) { switch ($this->operator) { - case '=~': + case '~=': trigger_error('Filter apply might not work as expected'); case '=': if (preg_match($this->pattern, $value)) { return TRUE; } break; - case '<': - if ($value < $this->subparts[1]) { - return TRUE; - } - break; - case '>': - if ($value > $this->subparts[1]) { - return TRUE; - } - break; case '<=': if ($value <= $this->subparts[1]) { return TRUE; @@ -259,5 +253,3 @@ function fdTemplateFilter($filter) } return $filter; } - -?>