aboutsummaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorMarin Ivanov <[email protected]>2019-02-13 07:20:14 +0200
committerMarin Ivanov <[email protected]>2019-02-13 07:26:13 +0200
commita1a0a3aae7ef762250b9295985be1eee41d7a49e (patch)
tree39accaebbd5c1fad072fc7ecb2360c0db6b21bef /server.go
parentcb4f041b8be79b49eb046466ceb1bea9cfcaeb87 (diff)
Revert the simplification of Searcher and Binder interfaces
* Revert "Simplify sever search functions" commit 9402a7d580c2dd929c68cf8b3038a1e6496f607f. * Revert "Simplify server bind functions" commit 82a8f44a2f4cf0686635d2a23ebb41a8f445194e. * Fix tests
Diffstat (limited to 'server.go')
-rw-r--r--server.go30
1 files changed, 19 insertions, 11 deletions
diff --git a/server.go b/server.go
index d520414..28b5257 100644
--- a/server.go
+++ b/server.go
@@ -12,9 +12,12 @@ import (
"github.com/metala/ldap/internal/asn1-ber"
)
-type BindFunc func(bindDN, bindSimplePw string, conn net.Conn) (LDAPResultCode, error)
-type SearchFunc func(boundDN string, req SearchRequest, conn net.Conn) (ServerSearchResult, error)
-
+type Binder interface {
+ Bind(bindDN, bindSimplePw string, conn net.Conn) (LDAPResultCode, error)
+}
+type Searcher interface {
+ Search(boundDN string, req SearchRequest, conn net.Conn) (ServerSearchResult, error)
+}
type Adder interface {
Add(boundDN string, req AddRequest, conn net.Conn) (LDAPResultCode, error)
}
@@ -45,9 +48,8 @@ type Closer interface {
//
type Server struct {
- Bind BindFunc
- Search SearchFunc
-
+ BindFns map[string]Binder
+ SearchFns map[string]Searcher
AddFns map[string]Adder
ModifyFns map[string]Modifier
DeleteFns map[string]Deleter
@@ -87,6 +89,8 @@ func NewServer() *Server {
s := new(Server)
d := defaultHandler{}
+ s.BindFns = make(map[string]Binder)
+ s.SearchFns = make(map[string]Searcher)
s.AddFns = make(map[string]Adder)
s.ModifyFns = make(map[string]Modifier)
s.DeleteFns = make(map[string]Deleter)
@@ -96,10 +100,8 @@ func NewServer() *Server {
s.ExtendedFns = make(map[string]Extender)
s.UnbindFns = make(map[string]Unbinder)
s.CloseFns = make(map[string]Closer)
-
- s.Bind = d.Bind
- s.Search = d.Search
-
+ s.BindFunc("", d)
+ s.SearchFunc("", d)
s.AddFunc("", d)
s.ModifyFunc("", d)
s.DeleteFunc("", d)
@@ -114,6 +116,12 @@ func NewServer() *Server {
s.closing = make(chan struct{})
return s
}
+func (server *Server) BindFunc(baseDN string, f Binder) {
+ server.BindFns[baseDN] = f
+}
+func (server *Server) SearchFunc(baseDN string, f Searcher) {
+ server.SearchFns[baseDN] = f
+}
func (server *Server) AddFunc(baseDN string, f Adder) {
server.AddFns[baseDN] = f
}
@@ -296,7 +304,7 @@ handler:
case ApplicationBindRequest:
server.Stats.countBinds(1)
- ldapResultCode := HandleBindRequest(req, server.Bind, conn)
+ ldapResultCode := HandleBindRequest(req, server.BindFns, conn)
if ldapResultCode == LDAPResultSuccess {
boundDN, ok = req.Children[1].Value.(string)
if !ok {