-
Notifications
You must be signed in to change notification settings - Fork 9
/
handler_search_schema.go
135 lines (105 loc) · 3.45 KB
/
handler_search_schema.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"log"
"strings"
"github.com/openstandia/goldap/message"
ldap "github.com/openstandia/ldapserver"
)
func handleSearchSubschema(s *Server, w ldap.ResponseWriter, m *ldap.Message) {
r := m.GetSearchRequest()
log.Printf("handleSearchSubschema")
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("info: Leaving handleSearchSubschema...")
return
default:
}
e := ldap.NewSearchResultEntry(string(r.BaseObject()))
searchEntry := NewSearchEntry(s.schemaMap, "", map[string][]string{
"objectClass": {"top", "subentry", "subschema", "extensibleObject"},
"cn": {"Subschema"},
})
lines := strings.Split(s.schemaMap.Dump(), "\n")
valuesMap := map[string][]string{}
for _, line := range lines {
tag := strings.Split(line, ": ")
if len(tag) == 1 {
continue
}
// log.Printf("attr: %s", string(attr))
// log.Printf("attr: %s", tag)
valuesMap[tag[0]] = append(valuesMap[tag[0]], line[len(tag[0])+2:])
}
// log.Printf("v: %v", valuesMap)
// attrNames := []string{"ldapSyntaxes", "matchingRules", "matchingRuleUse", "attributeTypes", "objectClasses"}
for k, v := range valuesMap {
searchEntry.attributes[k] = v
}
sentAttrs := map[string]struct{}{}
if isAllAttributesRequested(r) {
for k, v := range searchEntry.GetAttrsOrigWithoutOperationalAttrs() {
log.Printf("- Attribute %s: %#v", k, v)
av := make([]message.AttributeValue, len(v))
for i, vv := range v {
av[i] = message.AttributeValue(vv)
}
e.AddAttribute(message.AttributeDescription(k), av...)
sentAttrs[k] = struct{}{}
}
}
for _, attr := range r.Attributes() {
a := string(attr)
log.Printf("Requested attr: %s", a)
if a != "+" {
k, values, ok := searchEntry.GetAttrOrig(a)
if !ok {
log.Printf("No schema for requested attr, ignore. attr: %s", a)
continue
}
if _, ok := sentAttrs[k]; ok {
log.Printf("Already sent, ignore. attr: %s", a)
continue
}
log.Printf("- Attribute %s=%#v", a, values)
av := make([]message.AttributeValue, len(values))
for i, vv := range values {
av[i] = message.AttributeValue(vv)
}
e.AddAttribute(message.AttributeDescription(k), av...)
sentAttrs[k] = struct{}{}
}
}
if isOperationalAttributesRequested(r) {
for k, v := range searchEntry.GetOperationalAttrsOrig() {
if _, ok := sentAttrs[k]; !ok {
av := make([]message.AttributeValue, len(v))
for i, vv := range v {
av[i] = message.AttributeValue(vv)
}
e.AddAttribute(message.AttributeDescription(k), av...)
}
}
}
w.Write(e)
// 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)
}