ldap-upstream/internal/ldap/search.go

62 lines
1.9 KiB
Go
Raw Normal View History

2020-08-21 02:03:53 -05:00
package ldap
import (
"log"
2020-08-22 22:49:54 -05:00
"strings"
2020-08-21 02:03:53 -05:00
2020-08-22 22:49:54 -05:00
"github.com/ps78674/goldap/message"
2020-08-21 02:03:53 -05:00
ldap "github.com/ps78674/ldapserver"
2020-08-22 22:49:54 -05:00
"github.com/netauth/ldap/internal/buildinfo"
2020-08-21 02:03:53 -05:00
)
func (s *server) handleSearchDSE(w ldap.ResponseWriter, m *ldap.Message) {
2020-08-22 22:49:54 -05:00
nc := strings.Join(s.nc, ", ")
2020-08-21 02:03:53 -05:00
e := ldap.NewSearchResultEntry("")
e.AddAttribute("vendorName", "NetAuth")
2020-08-22 22:49:54 -05:00
e.AddAttribute("vendorVersion", message.AttributeValue(buildinfo.Version))
2020-08-21 02:03:53 -05:00
e.AddAttribute("objectClass", "top", "extensibleObject")
e.AddAttribute("supportedLDAPVersion", "3")
2020-08-22 22:49:54 -05:00
e.AddAttribute("namingContexts", message.AttributeValue(nc))
2020-08-21 02:03:53 -05:00
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)
}