From 6e14e82719330c918c5b4139cc80c51d7ebc5fba Mon Sep 17 00:00:00 2001 From: Jeroen Simonetti Date: Wed, 1 Jun 2016 16:55:37 +0200 Subject: Implement FilterSubstrings (#2) * Implement FilterSubstrings * Remove unneeded if Signed-off-by: Jeroen Simonetti Signed-off-by: Jeroen Simonetti --- filter.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'filter.go') diff --git a/filter.go b/filter.go index 0c9706a..df3c86a 100644 --- a/filter.go +++ b/filter.go @@ -306,8 +306,33 @@ func ServerApplyFilter(f *ber.Packet, entry *Entry) (bool, LDAPResultCode) { } else if !ok { return true, LDAPResultSuccess } - case "FilterSubstrings": // TODO - return false, LDAPResultOperationsError + case "Substrings": + if len(f.Children) != 2 { + return false, LDAPResultOperationsError + } + attribute := f.Children[0].Value.(string) + bytes := f.Children[1].Children[0].Data.Bytes() + value := string(bytes[:]) + for _, a := range entry.Attributes { + if strings.ToLower(a.Name) == strings.ToLower(attribute) { + for _, v := range a.Values { + switch f.Children[1].Children[0].Tag { + case FilterSubstringsInitial: + if strings.HasPrefix(v, value) { + return true, LDAPResultSuccess + } + case FilterSubstringsAny: + if strings.Contains(v, value) { + return true, LDAPResultSuccess + } + case FilterSubstringsFinal: + if strings.HasSuffix(v, value) { + return true, LDAPResultSuccess + } + } + } + } + } case "FilterGreaterOrEqual": // TODO return false, LDAPResultOperationsError case "FilterLessOrEqual": // TODO -- cgit v1.2.3