summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Vanackere <vincent.vanackere@gmail.com>2014-08-01 22:01:21 +0200
committerVincent Vanackere <vincent.vanackere@gmail.com>2014-08-01 22:01:21 +0200
commit03389e6f26f137e2d23faaca5da29ef55f511268 (patch)
treef3c7fb6b0fe6ad5067d37b0f45ded8f0c1dd81ca
parentMerge fixes for ldap present filter encoding/decoding from Gregory Haik (diff)
downloadldap-03389e6f26f137e2d23faaca5da29ef55f511268.tar
ldap-03389e6f26f137e2d23faaca5da29ef55f511268.tar.gz
ldap-03389e6f26f137e2d23faaca5da29ef55f511268.tar.bz2
ldap-03389e6f26f137e2d23faaca5da29ef55f511268.tar.lz
ldap-03389e6f26f137e2d23faaca5da29ef55f511268.tar.xz
ldap-03389e6f26f137e2d23faaca5da29ef55f511268.tar.zst
ldap-03389e6f26f137e2d23faaca5da29ef55f511268.zip
-rw-r--r--filter.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/filter.go b/filter.go
index 784a6ae..30e2f9f 100644
--- a/filter.go
+++ b/filter.go
@@ -124,7 +124,7 @@ func DecompileFilter(packet *ber.Packet) (ret string, err error) {
ret += "<="
ret += ber.DecodeString(packet.Children[1].Data.Bytes())
case FilterPresent:
- ret += string(packet.Data.Bytes())
+ ret += ber.DecodeString(packet.Data.Bytes())
ret += "=*"
case FilterApproxMatch:
ret += ber.DecodeString(packet.Children[0].Data.Bytes())
@@ -213,15 +213,18 @@ func compileFilter(filter string, pos int) (*ber.Packet, int, error) {
err = NewError(ErrorFilterCompile, errors.New("ldap: error parsing filter"))
return packet, newPos, err
}
- switch {
- case packet.Tag == FilterEqualityMatch && condition == "*":
+ // Handle FilterEqualityMatch as a separate case (is primitive, not constructed like the other filters)
+ if packet.Tag == FilterEqualityMatch && condition == "*" {
packet.TagType = ber.TypePrimitive
packet.Tag = FilterPresent
packet.Description = FilterMap[uint64(packet.Tag)]
packet.Data.WriteString(attribute)
+ return packet, newPos + 1, nil
+ }
+ packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, attribute, "Attribute"))
+ switch {
case packet.Tag == FilterEqualityMatch && condition[0] == '*' && condition[len(condition)-1] == '*':
// Any
- packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, attribute, "Attribute"))
packet.Tag = FilterSubstrings
packet.Description = FilterMap[uint64(packet.Tag)]
seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Substrings")
@@ -229,7 +232,6 @@ func compileFilter(filter string, pos int) (*ber.Packet, int, error) {
packet.AppendChild(seq)
case packet.Tag == FilterEqualityMatch && condition[0] == '*':
// Final
- packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, attribute, "Attribute"))
packet.Tag = FilterSubstrings
packet.Description = FilterMap[uint64(packet.Tag)]
seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Substrings")
@@ -237,14 +239,12 @@ func compileFilter(filter string, pos int) (*ber.Packet, int, error) {
packet.AppendChild(seq)
case packet.Tag == FilterEqualityMatch && condition[len(condition)-1] == '*':
// Initial
- packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, attribute, "Attribute"))
packet.Tag = FilterSubstrings
packet.Description = FilterMap[uint64(packet.Tag)]
seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Substrings")
seq.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, FilterSubstringsInitial, condition[:len(condition)-1], "Initial Substring"))
packet.AppendChild(seq)
default:
- packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, attribute, "Attribute"))
packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, condition, "Condition"))
}
newPos++