This commit is contained in:
41
main.go
41
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))
|
||||
*/
|
||||
}
|
||||
|
Reference in New Issue
Block a user