Make sure you Connect to Active Directory

include builtins/ldap.e
 
constant servers = {
"ldap.somewhere.com",
}
--...
string name="name", password="passwd"
--...
for i=1 to length(servers) do
    atom ld = ldap_init(servers[i])
    integer res = ldap_simple_bind_s(ld, name, password)
    printf(1,"%s: %d [%s]\n",{servers[i],res,ldap_err_desc(res)})
    if res=LDAP_SUCCESS then
        {res, atom pMsg} = ldap_search_s(ld, "dc=somewhere,dc=com", LDAP_SCOPE_SUBTREE,
                            -- search for all persons whose names start with joe or shmoe
                            "(&(objectclass=person)(|(cn=joe*)(cn=shmoe*)))",
                            NULL, -- return all attributes
                            0)  -- want both types and values of attrs
 
        -- arduously do stuff here to result, with ldap_first_message(), ldap_parse_result(), etc.
        ldap_msgfree(pMsg)      -- free messages (embedded NULL check)
    end if
    --... after done with it...
    ldap_unbind(ld)
end for
