08-19-2021, 09:54 AM
Is it possible to authenticate user via LDAP against active directory in IW 15.
In VCL-Applications the function below works fine
In intraweb-Application at line
adshlp.ADsGetObject('LDAP://'+FDomain,ActiveDs_TLB.IDirectorySearch,DSearch);
Exception says "ungültige Syntax" -> “invalid syntax” at runtime.
In VCL-Applications the function below works fine
In intraweb-Application at line
adshlp.ADsGetObject('LDAP://'+FDomain,ActiveDs_TLB.IDirectorySearch,DSearch);
Exception says "ungültige Syntax" -> “invalid syntax” at runtime.
Code:
function SearchUser (CommonName : string) : string;
var
DSearch : ActiveDs_TLB.IDirectorySearch;
opt : array[0..0] of ActiveDs_TLB.ads_searchpref_info; // has to be an array
ptrResult : THandle;
col : ActiveDs_TLB.ads_search_column;
Searchpath : WideString;
begin
Result:='';
Searchpath:='LDAP://'+FDomain;
adshlp.ADsGetObject(Searchpath,ActiveDs_TLB.IDirectorySearch,DSearch);
opt[0].dwSearchPref:=ADS_SEARCHPREF_SEARCH_SCOPE;
opt[0].vValue.dwType:=ADSTYPE_INTEGER;
opt[0].vValue.Integer:=ADS_SCOPE_SUBTREE;
if Succeeded(DSearch.SetSearchPreference(@opt[0],1)) then
begin
DSearch.ExecuteSearch('(&(objectClass=user)(sAMAccountName='+CommonName+'))',@ColNames,ColCount,ptrResult);
if DSearch.GetNextRow(ptrResult)<>S_ADS_NOMORE_ROWS then
begin
if Succeeded(DSearch.GetColumn(ptrResult,ColNames[2],col)) then
begin
if col.pADsValues<>nil then Result:=col.pAdsvalues^.CaseIgnoreString;
DSearch.FreeColumn(col);
end;
end
end
end;