From 0402f7806a1e216f150d004d16823cbc73880fc4 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sun, 9 Feb 2020 18:36:13 +0100 Subject: Implement (inefficiently) search scopes --- read.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'read.go') diff --git a/read.go b/read.go index ef06109..ab80d1c 100644 --- a/read.go +++ b/read.go @@ -97,6 +97,8 @@ func (server *Server) handleSearchInternal(state *State, w ldap.ResponseWriter, return ldap.LDAPResultInsufficientAccessRights, fmt.Errorf("Please specify a base object on which you have read rights") } + baseObjectLevel := len(strings.Split(baseObject, ",")) + basePath, err := dnToConsul(baseObject) if err != nil { return ldap.LDAPResultInvalidDNSyntax, err @@ -116,6 +118,16 @@ func (server *Server) handleSearchInternal(state *State, w ldap.ResponseWriter, server.logger.Tracef("%#v", entries) for dn, entry := range entries { + if r.Scope() == message.SearchRequestScopeBaseObject { + if dn != baseObject { + continue + } + } else if r.Scope() == message.SearchRequestSingleLevel { + objectLevel := len(strings.Split(dn, ",")) + if objectLevel != baseObjectLevel + 1 { + continue + } + } // Filter out if we don't match requested filter matched, err := applyFilter(entry, r.Filter()) if err != nil { -- cgit v1.2.3