This commit is contained in:
39
main.go
39
main.go
@@ -58,7 +58,7 @@ func isFlagPassed(name string) bool {
|
|||||||
// 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
|
var samAccountName string
|
||||||
groups := []string{}
|
var groups []string
|
||||||
|
|
||||||
if strings.Contains(username, "@") {
|
if strings.Contains(username, "@") {
|
||||||
s := strings.Split(username, "@")
|
s := strings.Split(username, "@")
|
||||||
@@ -88,15 +88,13 @@ func GetGroupsOfUser(username string, baseDN string, conn *ldap.Conn) ([]string,
|
|||||||
if len(sr.Entries) != 1 {
|
if len(sr.Entries) != 1 {
|
||||||
return nil, fmt.Errorf("user '%s' does not exist", samAccountName)
|
return nil, fmt.Errorf("user '%s' does not exist", samAccountName)
|
||||||
} else {
|
} else {
|
||||||
//sr.PrettyPrint(2)
|
// Get the groups of the first result
|
||||||
|
groups = sr.Entries[0].GetAttributeValues("memberOf")
|
||||||
|
/*
|
||||||
for _, entry := range sr.Entries {
|
for _, entry := range sr.Entries {
|
||||||
//entry.PrettyPrint(2)
|
entry.PrettyPrint(2)
|
||||||
groups := entry.GetAttributeValues("memberOf")
|
|
||||||
for _, group := range groups {
|
|
||||||
fmt.Println(group)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -257,29 +255,4 @@ func main() {
|
|||||||
fmt.Println(string(b))
|
fmt.Println(string(b))
|
||||||
return
|
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