Skip to content

Commit

Permalink
Added util.ExctractDomainPart function
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed May 17, 2022
1 parent e3f9985 commit c9e53f0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions modules/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,19 @@ func ExtractNetbiosFromBase(dn string) string {
netbios, _, _ := strings.Cut(elements[0], "=")
return netbios
}

func ExtractDomainPart(dn string) string {
elements := strings.Split(dn, ",")
last := len(elements)
first := last // assume we have nothing

for i := len(elements) - 1; i >= 0; i-- {
if stringsplus.EqualFoldHasPrefix(elements[i], "dc=") {
first = i
} else {
break
}
}

return strings.Join(elements[first:last], ",")
}

0 comments on commit c9e53f0

Please sign in to comment.