Skip to content

Commit edd66db

Browse files
author
Fabian Strachanski
committed
feature(ldap): handle Active Directory extended DN Requests (<GUID=...)
1 parent 6d624e6 commit edd66db

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

providers/directory/search.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,29 @@ import (
2222

2323
type predicate func(entry Entry) bool
2424

25+
func guidFromBytes(b []byte) string {
26+
return fmt.Sprintf("%08x-%04x-%04x-%02x%02x-%x",
27+
binary.LittleEndian.Uint32(b[0:4]),
28+
binary.LittleEndian.Uint16(b[4:6]),
29+
binary.LittleEndian.Uint16(b[6:8]),
30+
b[8], b[9],
31+
b[10:16],
32+
)
33+
}
34+
35+
func updateBaseDnForGuidIfNeeded(msg *ldap.SearchRequest, e *Entry) {
36+
binGuid, ok := e.Attributes["objectGUID"]
37+
if !ok || len(binGuid) == 0 {
38+
return
39+
}
40+
msgGuid := msg.BaseDN[6 : len(msg.BaseDN)-1]
41+
if guidFromBytes([]byte(binGuid[0])) != msgGuid {
42+
return
43+
}
44+
log.Infof("Attributes: %+v", guidFromBytes([]byte(e.Attributes["objectGUID"][0])))
45+
msg.BaseDN = e.Dn
46+
}
47+
2548
func (d *Directory) serveSearch(rw ldap.ResponseWriter, r *ldap.Request) {
2649
msg := r.Message.(*ldap.SearchRequest)
2750
m, doMonitor := monitor.LdapFromContext(r.Context)
@@ -69,6 +92,10 @@ func (d *Directory) serveSearch(rw ldap.ResponseWriter, r *ldap.Request) {
6992

7093
switch msg.Scope {
7194
case ldap.ScopeBaseObject:
95+
// handle Active Directory extended DN (see MS-ADTS for details)
96+
if strings.HasPrefix(msg.BaseDN, "<GUID=") {
97+
updateBaseDnForGuidIfNeeded(msg, &e)
98+
}
7299
if e.Dn != msg.BaseDN {
73100
continue
74101
}

0 commit comments

Comments
 (0)