package public

import(
	ldap "gopkg.in/ldap.v3"
)

func LDAP_Get_PCGroup(user ,pass * string) []string {
	l, err := ldap.DialURL("ldap://127.0.0.1:389")
	if err != nil {
		PntError(err)
	}
	defer l.Close()
	if err = l.Bind(*user, *pass);err != nil {
	//if err = l.Bind("zhiweiadserver@zhiweireach.com", "if(hdc==DOMAIN20)");err != nil {
		PntError(err)
	}
	searchRequest := ldap.NewSearchRequest(
		"ou=情报部门,dc=zhiweireach,dc=com",
		ldap.ScopeWholeSubtree,ldap.NeverDerefAliases, 0, 0, false,
		"(cn=*-PC)",
	   	//"(&(objectClass=organizationalPerson))", 
		[]string{"cn"},
		nil,
	)
	
	sr, err := l.Search(searchRequest)
	if err != nil {
		PntError(err)
	}
	pcgroup := make([]string,len(sr.Entries))
	for i, entry := range sr.Entries {
		// 完整输出 entry.DN
		// 输出特定目录 entry.GetAttributeValue("cn")
		pcgroup[i] = entry.GetAttributeValue("cn")
	}
	return pcgroup
}