From 3c5e55b83ee80db9639a7be11e90ea0578dd43ef Mon Sep 17 00:00:00 2001 From: William Luke Date: Fri, 5 Jul 2024 16:53:33 -0500 Subject: [PATCH] Implement base DN search that's basically group search --- internal/ldap/ldap.go | 4 ++-- internal/ldap/search.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) 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")