different debugging
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-07-24 11:13:13 +10:00
parent 2521e2472a
commit 01d1e4fd4b

10
main.go
View File

@@ -58,6 +58,8 @@ func isFlagPassed(name string) bool {
// 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
groups := []string{}
if strings.Contains(username, "@") {
s := strings.Split(username, "@")
samAccountName = s[0]
@@ -74,7 +76,7 @@ func GetGroupsOfUser(username string, baseDN string, conn *ldap.Conn) ([]string,
baseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(CN=%s)", ldap.EscapeFilter(samAccountName)),
[]string{"dn"},
[]string{},
nil,
)
@@ -87,6 +89,9 @@ func GetGroupsOfUser(username string, baseDN string, conn *ldap.Conn) ([]string,
return nil, fmt.Errorf("user '%s' does not exist", samAccountName)
}
sr.PrettyPrint(2)
/*
userdn := sr.Entries[0].DN
fmt.Printf("userdn is '%s' from CN '%s'", userdn, samAccountName)
@@ -102,11 +107,12 @@ func GetGroupsOfUser(username string, baseDN string, conn *ldap.Conn) ([]string,
return nil, err
}
groups := []string{}
for _, entry := range sr.Entries {
fmt.Println(entry.GetAttributeValue("cn"))
groups = append(groups, entry.GetAttributeValue("cn"))
}
*/
return groups, nil
}