MCPcopy Create free account
hub / github.com/Synzack/ldapper / GroupsQuery

Function GroupsQuery

Queries/QueryGroups.go:11–42  ·  view source on GitHub ↗
(groupInput string, baseDN string, conn *ldap.Conn)

Source from the content-addressed store, hash-verified

9)
10
11func GroupsQuery(groupInput string, baseDN string, conn *ldap.Conn) (queryResult string) {
12
13 query := fmt.Sprintf("(samaccountname=%s)", groupInput)
14 searchReq := Globals.LdapSearch(baseDN, query)
15
16 result, err := conn.Search(searchReq)
17 if err != nil {
18 fmt.Printf("Query error, %s", err)
19 }
20 //fmt.Printf("\nUser: %s\n", groupInput)
21
22 if len(result.Entries) > 0 {
23 queryResult += fmt.Sprintf("\nGroup Memberships - %s:\n-------------------------------------------------------------------------------\n", groupInput)
24 for i, cn := range result.Entries[0].GetAttributeValues("memberOf") {
25 s := strings.Split(cn, ",")
26 cn := strings.Replace(s[0], "CN=", "", -1)
27 if strings.Contains(cn, " ") {
28 cn = ("'" + cn + "' ")
29 }
30
31 queryResult += fmt.Sprintf("%s\t", cn)
32 i++
33 if i%3 == 0 {
34 queryResult += ("\n")
35 }
36 }
37 queryResult += ("\n")
38 } else {
39 queryResult = fmt.Sprintf("No results for \"%s\", check query.\n", groupInput)
40 }
41 return
42}

Callers 1

mainFunction · 0.92

Calls 1

LdapSearchFunction · 0.92

Tested by

no test coverage detected