-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLdapServer.go
61 lines (42 loc) · 902 Bytes
/
LdapServer.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
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
ldap "github.com/vjeantet/ldapserver"
"io/ioutil"
"log"
"os"
"os/signal"
"syscall"
)
var resultChan = make(chan string,100)
func main() {
//关闭log
ldap.Logger = log.New(ioutil.Discard,"",0)
server := ldap.NewServer()
routes := ldap.NewRouteMux()
server.Handle(routes)
routes.Bind(handleBind)
routes.Search(handleSearch)
go server.ListenAndServe("127.0.0.1:9998")
go func() {
for {
select {
case result := <- resultChan:
fmt.Println(result)
}
}
}()
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
<-ch
close(ch)
server.Stop()
}
func handleBind(w ldap.ResponseWriter, m *ldap.Message) {
res := ldap.NewBindResponse(ldap.LDAPResultSuccess)
w.Write(res)
}
func handleSearch(w ldap.ResponseWriter, m *ldap.Message) {
r := m.GetSearchRequest()
resultChan <- string(r.BaseObject())
}