forked from Deuxfleurs/bottin
Case insensitive match on attribute names
This commit is contained in:
parent
4c5b3d929d
commit
131297a33f
1 changed files with 23 additions and 19 deletions
42
main.go
42
main.go
|
@ -329,8 +329,8 @@ func (server *Server) handleSearchInternal(state *State, w ldap.ResponseWriter,
|
||||||
// If attribute is not in request, exclude it from returned entry
|
// If attribute is not in request, exclude it from returned entry
|
||||||
if len(r.Attributes()) > 0 {
|
if len(r.Attributes()) > 0 {
|
||||||
found := false
|
found := false
|
||||||
for _, need := range r.Attributes() {
|
for _, requested := range r.Attributes() {
|
||||||
if string(need) == attr {
|
if strings.EqualFold(string(requested), attr) {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -389,32 +389,36 @@ func applyFilter(entry Entry, filter message.Filter) (bool, error) {
|
||||||
return !res, nil
|
return !res, nil
|
||||||
} else if fPresent, ok := filter.(message.FilterPresent); ok {
|
} else if fPresent, ok := filter.(message.FilterPresent); ok {
|
||||||
what := string(fPresent)
|
what := string(fPresent)
|
||||||
log.Printf("Present filter: %s", what)
|
// Case insensitive search
|
||||||
if _, ok := entry[what]; ok {
|
for desc := range entry {
|
||||||
return true, nil
|
if strings.EqualFold(what, desc) {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
} else if fEquality, ok := filter.(message.FilterEqualityMatch); ok {
|
} else if fEquality, ok := filter.(message.FilterEqualityMatch); ok {
|
||||||
desc := string(fEquality.AttributeDesc())
|
desc := string(fEquality.AttributeDesc())
|
||||||
target := string(fEquality.AssertionValue())
|
target := string(fEquality.AssertionValue())
|
||||||
if value, ok := entry[desc]; ok {
|
// Case insensitive attribute search
|
||||||
if vstr, ok := value.(string); ok {
|
for entry_desc, value := range entry {
|
||||||
// If we have one value for the key, match exactly
|
if strings.EqualFold(entry_desc, desc) {
|
||||||
return vstr == target, nil
|
if vstr, ok := value.(string); ok {
|
||||||
} else if vlist, ok := value.([]string); ok {
|
// If we have one value for the key, match exactly
|
||||||
// If we have several values for the key, one must match
|
return vstr == target, nil
|
||||||
for _, val := range vlist {
|
} else if vlist, ok := value.([]string); ok {
|
||||||
if val == target {
|
// If we have several values for the key, one must match
|
||||||
return true, nil
|
for _, val := range vlist {
|
||||||
|
if val == target {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false, nil
|
||||||
|
} else {
|
||||||
|
panic(fmt.Sprintf("Invalid value: %#v", value))
|
||||||
}
|
}
|
||||||
return false, nil
|
|
||||||
} else {
|
|
||||||
panic(fmt.Sprintf("Invalid value: %#v", value))
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return false, nil
|
|
||||||
}
|
}
|
||||||
|
return false, nil
|
||||||
} else {
|
} else {
|
||||||
return false, fmt.Errorf("Unsupported filter: %#v %T", filter, filter)
|
return false, fmt.Errorf("Unsupported filter: %#v %T", filter, filter)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue