split sAMAccountName from UPN
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-07-24 10:50:02 +10:00
parent 4ee3838c72
commit 00103bcb7e

12
main.go
View File

@@ -58,13 +58,23 @@ func isFlagPassed(name string) bool {
// GetGroupsOfUser returns the group for a user.
// Taken from https://github.com/jtblin/go-ldap-client/issues/13#issuecomment-456090979
func GetGroupsOfUser(username string, baseDN string, conn *ldap.Conn) ([]string, error) {
var samAccountName string
if strings.Contains(username, "@") {
s := strings.Split(username, "@")
samAccountName = s[0]
} else if strings.Contains(username, "\\") {
s := strings.Split(username, "\\")
samAccountName = s[len(s)-1]
} else {
samAccountName = username
}
// Get the users DN
// Search for the given username
searchRequest := ldap.NewSearchRequest(
baseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(uid=%s)", username),
fmt.Sprintf("(uid=%s)", samAccountName),
[]string{"dn"},
nil,
)