ldap-upstream/internal/ldap/search.go
2020-08-22 20:49:54 -07:00

74 lines
2.2 KiB
Go

package ldap
import (
"log"
"strings"
"github.com/ps78674/goldap/message"
ldap "github.com/ps78674/ldapserver"
"github.com/netauth/ldap/internal/buildinfo"
)
func (s *server) handleSearchDSE(w ldap.ResponseWriter, m *ldap.Message) {
nc := strings.Join(s.nc, ", ")
e := ldap.NewSearchResultEntry("")
e.AddAttribute("vendorName", "NetAuth")
e.AddAttribute("vendorVersion", message.AttributeValue(buildinfo.Version))
e.AddAttribute("objectClass", "top", "extensibleObject")
e.AddAttribute("supportedLDAPVersion", "3")
e.AddAttribute("namingContexts", message.AttributeValue(nc))
w.Write(e)
res := ldap.NewSearchResultDoneResponse(ldap.LDAPResultSuccess)
w.Write(res)
}
func (s *server) handleSearchMyCompany(w ldap.ResponseWriter, m *ldap.Message) {
r := m.GetSearchRequest()
log.Printf("handleSearchMyCompany - Request BaseDn=%s", r.BaseObject())
e := ldap.NewSearchResultEntry(string(r.BaseObject()))
e.AddAttribute("objectClass", "top", "organizationalUnit")
w.Write(e)
res := ldap.NewSearchResultDoneResponse(ldap.LDAPResultSuccess)
w.Write(res)
}
func (s *server) handleSearch(w ldap.ResponseWriter, m *ldap.Message) {
r := m.GetSearchRequest()
log.Printf("Request BaseDn=%s", r.BaseObject())
log.Printf("Request Filter=%s", r.Filter())
log.Printf("Request FilterString=%s", r.FilterString())
log.Printf("Request Attributes=%s", r.Attributes())
log.Printf("Request TimeLimit=%d", r.TimeLimit().Int())
// Handle Stop Signal (server stop / client disconnected / Abandoned request....)
select {
case <-m.Done:
log.Print("Leaving handleSearch...")
return
default:
}
e := ldap.NewSearchResultEntry("cn=Valere JEANTET, " + string(r.BaseObject()))
e.AddAttribute("mail", "valere.jeantet@gmail.com", "mail@vjeantet.fr")
e.AddAttribute("company", "SODADI")
e.AddAttribute("department", "DSI/SEC")
e.AddAttribute("l", "Ferrieres en brie")
e.AddAttribute("mobile", "0612324567")
e.AddAttribute("telephoneNumber", "0612324567")
e.AddAttribute("cn", "Valère JEANTET")
w.Write(e)
e = ldap.NewSearchResultEntry("cn=Claire Thomas, " + string(r.BaseObject()))
e.AddAttribute("mail", "claire.thomas@gmail.com")
e.AddAttribute("cn", "Claire THOMAS")
w.Write(e)
res := ldap.NewSearchResultDoneResponse(ldap.LDAPResultSuccess)
w.Write(res)
}