经过一些研究并下载了一些库,我找到了答案。我为测试和帮助需要的人制作了这个基本功能。
在这里对这个问题感到抱歉,但我希望有一天它对某人有所帮助。
procedure TForm1.OnClick2(Sender: TObject);
var
ldap: TLDAPsend;
l: TStringList;
host, username, psswd, base, cpf, result : string;
begin
ldap := TLDAPsend.Create;
l := TStringList.Create;
host := teHost.text;
username := teUser.text;
psswd := tePsswd.text;
base := teBase.text; //The base that you want to make the research.
cpf := teCpf.text;
result := '';
try
ldap.TargetHost := host; //like an IP. xxx.xxx.xxx.xxx
//next line is the key to getting AD authentication working
ldap.UserName := username; //like 'uid=_user_,ou=blabla,ou=blabla,ou=blabla,dc=bla,dc=bla,dc=bla'
ldap.Password := psswd;
ldap.Login;
Label1.Caption := 'Logged...';
ldap.BindSasl; // BindSasl have more security than Bind.
Label1.caption := 'Bind...';
l.Add('cn'); //I want just the name, so search the 'cn'. If want more just add.
ldap.Search(base, False, 'uid=' + cpf, l); //search with the CPF (an kind of documentation number)
Label1.Caption := 'Success !';
{The next line have a function "getLastLine" cause the LDAPResult print something like this:
Results: 1
Result: 0
Object: uid=xxxxxxxx,ou=xxx,ou=xxx,ou=xxx,dc=xxx,dc=xxx,dc=xxx
Attribute: cn
Fulano Ciclano de Tal
}
result := getLastLine(LDAPResultdump(ldap.SearchResult), #$D#$A);
if (result <> '') and (result<> 'Results: 0') then
begin
teName.visible := true;
teName.text := result;
end
else
begin
Label1.Caption := 'No Result...';
teName.Visible := false;
end;
ldap.Logout;
finally
ldap.Free;
l.Free;
end;
end;
PS:这需要一些库,主要是“ldapsend”,其他的比如asn1util和blcksock。所有都可以在突触包上找到。一些库有错误,但只需将其删除。