Skip to content

Commit

Permalink
internal/ldap: Fix search equivalence translation
Browse files Browse the repository at this point in the history
  • Loading branch information
the-maldridge committed Aug 26, 2020
1 parent 4a82eb8 commit c4dd12c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions internal/ldap/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ func entitySearchExprHelper(attr, op, val string) (string, error) {

switch op {
case "=":
operator = "="
operator = ":"
val = strconv.Quote(val)
default:
return "", errors.New("search comparison is unsupported")
}
Expand Down Expand Up @@ -162,16 +163,17 @@ func (s *server) handleSearchGroups(w ldap.ResponseWriter, m *ldap.Message) {

s.l.Debug("Searching groups", "expr", expr)

members, err := s.c.GroupSearch(ctx, expr)
groups, err := s.c.GroupSearch(ctx, expr)
if err != nil {
res := ldap.NewSearchResultDoneResponse(ldap.LDAPResultOperationsError)
res.SetDiagnosticMessage(err.Error())
w.Write(res)
return
}

for i := range members {
e, err := s.groupSearchResult(ctx, members[i], r.BaseObject(), r.Attributes())
for i := range groups {
s.l.Debug("Found group", "group", groups[i].GetName())
e, err := s.groupSearchResult(ctx, groups[i], r.BaseObject(), r.Attributes())
if err != nil {
res := ldap.NewSearchResultDoneResponse(ldap.LDAPResultOperationsError)
res.SetDiagnosticMessage(err.Error())
Expand Down Expand Up @@ -214,14 +216,15 @@ func groupSearchExprHelper(attr, op, val string) (string, error) {

switch attr {
case "cn":
predicate = "name"
predicate = "Name"
default:
return "", errors.New("search attribute is unsupported")
}

switch op {
case "=":
operator = "="
operator = ":"
val = strconv.Quote(val)
default:
return "", errors.New("search comparison is unsupported")
}
Expand Down

0 comments on commit c4dd12c

Please sign in to comment.