
ldapserver 패키지는 LDAP 서버를 구현합니다.
이 패키지는 작업 진행 중입니다.
ldapserver는 LDAP 프로토콜을 구사할 수 있는 서버 소프트웨어를 구축하기 위한 헬퍼 라이브러리입니다. LDAP의 대체 구현, 사용자 정의 LDAP 프록시, 또는 API를 LDAP 서버로 "가장"할 수 있는 완전히 다른 백엔드가 될 수도 있습니다.
이 패키지는 다음을 지원합니다:
AbandonRequest를 처리할 라우트를 설정하지 않으면 패키지가 대신 처리합니다. (message.Done chan으로 신호가 전송됩니다)
요청과 일치하는 라우트가 없으면 서버는 먼저 특별한 NotFound 라우트를 호출하려고 시도하며, 아무것도 지정되지 않으면 UnwillingToResponse 오류 코드(53)를 반환합니다.
기여와 의견은 언제나 환영합니다 :)
// Listen to 10389 port for LDAP Request
// and route bind request to the handleBind func
package main
import (
"log"
"os"
"os/signal"
"syscall"
ldap "github.com/vjeantet/ldapserver"
)
func main() {
//ldap logger
ldap.Logger = log.New(os.Stdout, "[server] ", log.LstdFlags)
//Create a new LDAP Server
server := ldap.NewServer()
routes := ldap.NewRouteMux()
routes.Bind(handleBind)
server.Handle(routes)
// listen on 10389
go server.ListenAndServe("127.0.0.1:10389")
// When CTRL+C, SIGINT and SIGTERM signal occurs
// Then stop server gracefully
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
<-ch
close(ch)
server.Stop()
}
// handleBind return Success if login == mysql
func handleBind(w ldap.ResponseWriter, m *ldap.Message) {
r := m.GetBindRequest()
res := ldap.NewBindResponse(ldap.LDAPResultSuccess)
if string(r.Name()) == "myLogin" {
w.Write(res)
return
}
log.Printf("Bind failed User=%s, Pass=%s", string(r.Name()), string(r.AuthenticationSimple()))
res.SetResultCode(ldap.LDAPResultInvalidCredentials)
res.SetDiagnosticMessage("invalid credentials")
w.Write(res)
}
"examples" 폴더를 살펴보세요.