split sAMAccountName from UPN
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
12
main.go
12
main.go
@@ -58,13 +58,23 @@ func isFlagPassed(name string) bool {
|
|||||||
// GetGroupsOfUser returns the group for a user.
|
// GetGroupsOfUser returns the group for a user.
|
||||||
// Taken from https://github.com/jtblin/go-ldap-client/issues/13#issuecomment-456090979
|
// Taken from https://github.com/jtblin/go-ldap-client/issues/13#issuecomment-456090979
|
||||||
func GetGroupsOfUser(username string, baseDN string, conn *ldap.Conn) ([]string, error) {
|
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
|
// Get the users DN
|
||||||
// Search for the given username
|
// Search for the given username
|
||||||
searchRequest := ldap.NewSearchRequest(
|
searchRequest := ldap.NewSearchRequest(
|
||||||
baseDN,
|
baseDN,
|
||||||
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
|
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
|
||||||
fmt.Sprintf("(uid=%s)", username),
|
fmt.Sprintf("(uid=%s)", samAccountName),
|
||||||
[]string{"dn"},
|
[]string{"dn"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user