diff options
author | Alex Auvolat <alex@adnab.me> | 2020-01-19 18:04:42 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-01-19 18:04:42 +0100 |
commit | 131297a33f3da4111bfb617e4712f253fb4d35a3 (patch) | |
tree | c49da177d880a35683e30c00aca0c6648859e0e9 | |
parent | 4c5b3d929d327d6703d0aeafe8149c25a845a9f8 (diff) | |
download | bottin-131297a33f3da4111bfb617e4712f253fb4d35a3.tar.gz bottin-131297a33f3da4111bfb617e4712f253fb4d35a3.zip |
Case insensitive match on attribute names
-rw-r--r-- | main.go | 42 |
1 files changed, 23 insertions, 19 deletions
@@ -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 len(r.Attributes()) > 0 { found := false - for _, need := range r.Attributes() { - if string(need) == attr { + for _, requested := range r.Attributes() { + if strings.EqualFold(string(requested), attr) { found = true break } @@ -389,32 +389,36 @@ func applyFilter(entry Entry, filter message.Filter) (bool, error) { return !res, nil } else if fPresent, ok := filter.(message.FilterPresent); ok { what := string(fPresent) - log.Printf("Present filter: %s", what) - if _, ok := entry[what]; ok { - return true, nil + // Case insensitive search + for desc := range entry { + if strings.EqualFold(what, desc) { + return true, nil + } } return false, nil } else if fEquality, ok := filter.(message.FilterEqualityMatch); ok { desc := string(fEquality.AttributeDesc()) target := string(fEquality.AssertionValue()) - if value, ok := entry[desc]; ok { - if vstr, ok := value.(string); ok { - // If we have one value for the key, match exactly - return vstr == target, nil - } else if vlist, ok := value.([]string); ok { - // If we have several values for the key, one must match - for _, val := range vlist { - if val == target { - return true, nil + // Case insensitive attribute search + for entry_desc, value := range entry { + if strings.EqualFold(entry_desc, desc) { + if vstr, ok := value.(string); ok { + // If we have one value for the key, match exactly + return vstr == target, nil + } else if vlist, ok := value.([]string); ok { + // If we have several values for the key, one must match + 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 { return false, fmt.Errorf("Unsupported filter: %#v %T", filter, filter) } |