From ba5e949a9e20a7f9ff63e343e41bd5759f15978b Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Mon, 24 Jul 2023 11:58:14 +1000 Subject: [PATCH] output groups in json --- main.go | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/main.go b/main.go index 061f32f..32ce8f2 100644 --- a/main.go +++ b/main.go @@ -58,7 +58,7 @@ 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{} + var groups []string if strings.Contains(username, "@") { s := strings.Split(username, "@") @@ -88,15 +88,13 @@ func GetGroupsOfUser(username string, baseDN string, conn *ldap.Conn) ([]string, if len(sr.Entries) != 1 { return nil, fmt.Errorf("user '%s' does not exist", samAccountName) } else { - //sr.PrettyPrint(2) - - for _, entry := range sr.Entries { - //entry.PrettyPrint(2) - groups := entry.GetAttributeValues("memberOf") - for _, group := range groups { - fmt.Println(group) + // Get the groups of the first result + groups = sr.Entries[0].GetAttributeValues("memberOf") + /* + for _, entry := range sr.Entries { + entry.PrettyPrint(2) } - } + */ } /* @@ -257,29 +255,4 @@ func main() { fmt.Println(string(b)) return } - - /* - config := &auth.Config{ - Server: *server, - Port: 636, - BaseDN: *baseDN, - Security: auth.SecurityTLS, - RootCAs: system, - } - - //fmt.Printf("Connecting to ldap server '%s' with DN '%s' on port 636\n", *server, *baseDN) - - status, err := auth.Authenticate(config, *username, *password) - - if err != nil { - //handle err - //fmt.Println("Error : %s", err) - output.Error = err.Error() - } - - output.AuthSuccess = status - - b, _ := json.Marshal(output) - fmt.Println(string(b)) - */ }