ldap-proxy/internal/ldap/search.go

68 lines
2.1 KiB
Go
Raw Normal View History

2020-08-21 02:03:53 -05:00
package ldap
import (
"log"
ldap "github.com/ps78674/ldapserver"
)
func (s *server) handleSearchDSE(w ldap.ResponseWriter, m *ldap.Message) {
e := ldap.NewSearchResultEntry("")
e.AddAttribute("vendorName", "NetAuth")
e.AddAttribute("vendorVersion", "1.0")
e.AddAttribute("objectClass", "top", "extensibleObject")
e.AddAttribute("supportedLDAPVersion", "3")
e.AddAttribute("namingContexts", "o=My Company, c=US")
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)
}