2013-08-30 47 views
0

對於在Active Directory Services中搜索特定用戶,我們使用了ldap_search_sW API。但是,在Windows Server 2012的情況下崩潰我的exe文件。沒有返回錯誤代碼,EXE停止工作。ldap_search_sW函數在Windows Server 2012 R2 X64上崩潰?

我的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崩潰轉儲窗口:

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; 
+0

@DavidHeffernan:我在嘗試不同的事情。 – CyprUS

+0

我必須承認,我被這個異常代碼難倒了。你有沒有像madExcept在應用程序來收集診斷? –

+0

@DavidHeffernan:我有Eureka Log 6。我應該將它附加到項目然後嘗試? – CyprUS

回答

0

我們已經解決了這個問題,我在這裏張貼的解決方案。我們使用的ldap_search_sW函數沒有問題。在連接到ADS之前,我們用來驗證提供的用戶名和密碼。然後我們使用ldap_initW,ldap_set_optionWldap_simple_bind_sW連接到服務器。

然後通過ldap_search_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認證。如果返回BASE DN,則認爲用戶已通過身份驗證。如果返回爲空,則用戶未通過身份驗證。

希望它可以幫助別人。

相關問題