forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (37 loc) · 966 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"log"
"os"
"os/signal"
"syscall"
ldap "github.com/vjeantet/ldapserver"
)
func main() {
//Create a new LDAP Server
server := ldap.NewServer()
routes := ldap.NewRouteMux()
routes.Bind(handleBind)
server.Handle(routes)
// listen on 10389
go server.ListenAndServe(":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.GetLogin()) == "myLogin" {
w.Write(res)
return
}
log.Printf("Bind failed User=%s, Pass=%s", string(r.GetLogin()), string(r.GetPassword()))
res.ResultCode = ldap.LDAPResultInvalidCredentials
res.DiagnosticMessage = "invalid credentials"
w.Write(res)
}