Open ricardobiundo opened 5 years ago
If I try to get a control value I also get null even if the value is set to true in active directory:
// The username and password we want to check
username := "test"
var ldapServer = "IP_ADDRESS"
var ldapPort = uint16(389)
conn, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort))
if err != nil {
log.Fatal(err)
}
defer conn.Close()
err = conn.Bind("cn=ADMIN_USER,cn=Users,dc=EXAMPLE,dc=COM", "PASSWORD")
if err != nil {
log.Fatal(err)
}
searchRequest := ldap.NewSearchRequest(
"dc=EXAMPLE,dc=COM",
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(&(objectClass=organizationalPerson)(sAMAccountName=%s))", username),
[]string{"dn"},
nil,
)
sr, err := conn.Search(searchRequest)
if err != nil {
log.Fatal(err)
}
for _, entry := range sr.Entries {
fmt.Printf("%s: %v\n", entry.DN, entry.GetAttributeValue("description"))
}
passwordMustChangeControl := ldap.FindControl(sr.Controls, ldap.ControlTypeVChuPasswordMustChange)
fmt.Println("changepass: ", passwordMustChangeControl)
In your provided example you request only []string{"dn"},
, if you need more attributes, you need to declare them explicitly in this array.
And ControlTypeVChuPasswordMustChange
is not supported by MS AD.
My entry attributes are empty and if I try to get the value of an attribute I get nothing either. I get:
Code:
I have tried with GetAttributeValue, GetAttributeValues and both AD and LDAP names in this table: https://www.manageengine.com/products/ad-manager/help/csv-import-management/active-directory-ldap-attributes.html
The data: