diff --git a/internal/ldap/ldap.go b/internal/ldap/ldap.go index b053982..55ff897 100644 --- a/internal/ldap/ldap.go +++ b/internal/ldap/ldap.go @@ -91,11 +91,11 @@ func (s *server) SetDomain(domain string) { } // Register routes that are dependent on the namingConvention - s.routes.Search(s.handleSearchDSE). + s.routes.Search(s.handleBaseDnSearch). BaseDn(strings.Join(s.nc, ",")). Scope(ldap.SearchRequestScopeBaseObject). Filter("(objectclass=*)"). - Label("Search - ROOT DSE") + Label("Search - Base DN") entitySearchDN := "ou=entities," + strings.Join(s.nc, ",") s.routes.Search(s.handleSearchEntities). diff --git a/internal/ldap/search.go b/internal/ldap/search.go index 572f130..ae805eb 100644 --- a/internal/ldap/search.go +++ b/internal/ldap/search.go @@ -28,6 +28,36 @@ func (s *server) handleSearchDSE(w ldap.ResponseWriter, m *ldap.Message) { w.Write(res) } +func (s *server) handleBaseDnSearch(w ldap.ResponseWriter, m *ldap.Message) { + ctx := context.Background() + s.l.Debug("Base DN search") + r := m.GetSearchRequest() + + ents, err := s.c.GroupSearch(ctx, "Name:*") + if err != nil { + res := ldap.NewSearchResultDoneResponse(ldap.LDAPResultOperationsError) + res.SetDiagnosticMessage(err.Error()) + w.Write(res) + return + } + + for i := range ents { + e, err := s.groupSearchResult(ctx, ents[i], r.BaseObject(), r.Attributes()) + if err != nil { + res := ldap.NewSearchResultDoneResponse(ldap.LDAPResultOperationsError) + res.SetDiagnosticMessage(err.Error()) + w.Write(res) + return + } + w.Write(e) + } + + s.l.Debug("Entities", "res", ents) + + res := ldap.NewSearchResultDoneResponse(ldap.LDAPResultSuccess) + w.Write(res) +} + func (s *server) handleSearchEntities(w ldap.ResponseWriter, m *ldap.Message) { ctx := context.Background() s.l.Debug("Search Entities")