Skip to content

Commit 0292ff1

Browse files
authored
Merge branch 'main' into feature_ad_guid_search
2 parents edd66db + 7b87894 commit 0292ff1

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

providers/directory/search.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ func updateBaseDnForGuidIfNeeded(msg *ldap.SearchRequest, e *Entry) {
4545
msg.BaseDN = e.Dn
4646
}
4747

48+
var matchingRules = map[string]string{
49+
"1.3.6.1.4.1.1466.115.121.1.38": "objectIdentifierMatch",
50+
"1.3.6.1.4.1.1466.115.121.1.15": "caseIgnoreMatch",
51+
"1.3.6.1.4.1.1466.115.121.1.26": "caseExactMatch",
52+
"1.3.6.1.4.1.1466.115.121.1.7": "booleanMatch",
53+
"1.3.6.1.4.1.1466.115.121.1.27": "integerMatch",
54+
"1.3.6.1.4.1.1466.115.121.1.12": "distinguishedNameMatch",
55+
"1.3.6.1.4.1.1466.115.121.1.24": "generalizedTimeMatch",
56+
"1.3.6.1.4.1.1466.115.121.1.5": "octetStringMatch",
57+
}
58+
59+
func inferMatchingRule(syntaxOID string) string {
60+
if v, ok := matchingRules[syntaxOID]; ok {
61+
return v
62+
}
63+
return "caseExactMatch"
64+
}
65+
66+
4867
func (d *Directory) serveSearch(rw ldap.ResponseWriter, r *ldap.Request) {
4968
msg := r.Message.(*ldap.SearchRequest)
5069
m, doMonitor := monitor.LdapFromContext(r.Context)
@@ -107,6 +126,10 @@ func (d *Directory) serveSearch(rw ldap.ResponseWriter, r *ldap.Request) {
107126
if dn := strings.Join(parts[1:], ","); dn != msg.BaseDN {
108127
continue
109128
}
129+
case ldap.ScopeWholeSubtree:
130+
if !strings.HasSuffix(strings.ToLower(e.Dn), strings.ToLower(msg.BaseDN)) {
131+
continue
132+
}
110133
}
111134
if d.skip(&e, msg.BaseDN) {
112135
continue
@@ -370,6 +393,9 @@ func (p *parser) equal(name, value string) (predicate, error) {
370393
if p.s != nil {
371394
t, ok := p.s.AttributeTypes[name]
372395
if ok {
396+
if t.Equality == "" {
397+
t.Equality = inferMatchingRule(t.Syntax)
398+
}
373399
switch t.Equality {
374400
case "caseIgnoreMatch", "2.5.13.2":
375401
f = func(s string) bool {

0 commit comments

Comments
 (0)