Delphi ldap\u搜索\u sW功能在Windows Server 2012 R2 X64上崩溃?
为了在Active Directory服务中搜索特定用户,我们使用了Delphi ldap\u搜索\u sW功能在Windows Server 2012 R2 X64上崩溃?,delphi,ldap,delphi-7,Delphi,Ldap,Delphi 7,为了在Active Directory服务中搜索特定用户,我们使用了ldap\u search\u sWAPI。但是,在Windows Server 2012的情况下,它会使我的exe崩溃。没有返回错误代码,EXE只是停止工作 我拥有的EXE是32位应用程序。所以我猜它将从“SysWow64”目录加载。以下是如何完成调用的示例行:- pld声明: type // record declaration begins {$EXTERNALSYM PLDAP} PLDAP = ^LDAP;
ldap\u search\u sW
API。但是,在Windows Server 2012的情况下,它会使我的exe崩溃。没有返回错误代码,EXE只是停止工作
我拥有的EXE是32位应用程序。所以我猜它将从“SysWow64”目录加载。以下是如何完成调用的示例行:-
pld声明:
type // record declaration begins
{$EXTERNALSYM PLDAP}
PLDAP = ^LDAP;
{$EXTERNALSYM LDAP}
LDAP = record
ld_sb: record
sb_sd: ULONG;
Reserved1: array [0..(10 * sizeof(ULONG))] of Byte;
sb_naddr: ULONG; // notzero implies CLDAP available
Reserved2: array [0..(6 * sizeof(ULONG)) - 1] of Byte;
//
// Following parameters MAY match up to reference implementation of LDAP
//
ld_host: PChar;
ld_version: ULONG;
ld_lberoptions: Byte;
//
// Safe to assume that these parameters are in same location as
// reference implementation of LDAP API.
//
ld_deref: ULONG;
ld_timelimit: ULONG;
ld_sizelimit: ULONG;
ld_errno: ULONG;
ld_matched: PChar;
ld_error: PChar;
ld_msgid: ULONG;
Reserved3: array [0..(6*sizeof(ULONG))] of Byte;
//
// Following parameters may match up to reference implementation of LDAP API.
//
ld_cldaptries: ULONG;
ld_cldaptimeout: ULONG;
ld_refhoplimit: ULONG;
ld_options: ULONG;
end; // record declaration end
pld : PLDAP;
pld := Session.pld; // session PLD is assigned as is to it
The sessions' PLD is initialized as
ldappld := ldap_initW(PWideChar(ldapServerW), ldapPort) // this is eventually assigned to Session's PLD which is assigned to the PLD used Below
LdapCheck(ldap_search_sW(pld, PWideChar('DC=esbs,DC=local'), LDAP_SCOPE_SUBTREE, '(objectCategory=user)', nil, 0, plmSearch));
我应该采取什么步骤
以下是EXE崩溃的windows转储:
Problem signature:
Problem Event Name: APPCRASH
Application Name: project1.exe
Application Version: 0.1.1.0
Application Timestamp: 2a425e19
Fault Module Name: KERNELBASE.dll
Fault Module Version: 6.2.8400.0
Fault Module Timestamp: 4fb7184e
Exception Code: 000006ba
Exception Offset: 00017945
OS Version: 6.2.8400.2.0.0.400.8
Locale ID: 1033
Additional Information 1: 91d0
Additional Information 2: 91d025961d4c758a8b5ea7ee1390f3b7
Additional Information 3: c3ce
Additional Information 4: c3cebe78f080ab69603c33ad36d75750
职能声明:
{$EXTERNALSYM ldap_search_sW}
function ldap_search_sW(ld: PLDAP; base: PWideChar; scope: ULONG; filter, attrs: PWideChar; attrsonly: ULONG; var res: PLDAPMessage): ULONG; cdecl;
我们已经解决了这个问题,我在这里发布解决方案。我们使用的
ldap\u search\u sW
函数中没有问题。在连接到ADS之前,我们用于验证提供的用户名和密码。然后我们使用ldap\u initW
、ldap\u set\u optionW
和ldap\u simple\u bind\u sW
连接到服务器
然后通过ldap\u search\u sW
读取用户列表。
在Server 2012中,如果跳过了身份验证部分,则exe不会崩溃。
身份验证按以下方式完成:-
function AuthenticateADSUserW(ADSUserName, ADSPassword, ADSip: String;Var Fun_Obj:String): Boolean;
var
AuthResult : Integer;
hInstance: THandle;
ADSServerName,
ADSUsrNam,
ADSPwd,
ADSPortNo,
Error: Array [0..255] of char;
ldapDomain,
ldapUserName,
ldapPassword : WideString;
hr : integer;
obj : IADs;
begin
try
Result := False;
Fun_Obj := '';
// Insert code to securely retrieve the user name and password.
try
ldapDomain := UTF8Decode(ADSip);
ldapUserName := UTF8Decode(ADSUserName);
ldapPassword := UTF8Decode(ADSPassword);
CoInitialize(Nil); //Added By Sameer
hr := ADsOpenObject('LDAP://'+ldapDomain,
ldapUserName,
ldapPassword,
ADS_SECURE_AUTHENTICATION,
IADs,
obj);
Fun_Obj := obj.ADsPath ;
if Succeeded(hr) then
Result := True;
except
on e : exception do
begin
escan.Updatelog('Error '+e.ClassName + ': ' + e.Message,1,0);
Result := False;
end;
//lblMessage.Caption := e.ClassName + ': ' + #13#10 + e.Message;
end;
finally
CoUninitialize;
end;
end;
我们跳过了这一步,而是通过检索所提供用户名的基本DN来进行身份验证。如果返回基本DN,则认为用户已通过身份验证。如果返回为空,则用户未经过身份验证
希望它能帮助别人。@DavidHeffernan:我在尝试不同的事情。我必须承认,我被那个异常代码难住了。除了在应用程序中收集诊断信息外,你还有类似Mad的东西吗?@DavidHeffernan:我有Eureka日志6。我是否应该将它附加到项目中,然后再试一次?我当然会推荐这样做。@DavidHeffernan:我试过附加Eureka日志,除此之外,其他都是单独附加的。这两次,exe都崩溃了,两次都没有生成对话框。仅显示windows对话框