1

我正在尝试连接到 OpenLDAP 服务器“克隆”。我尝试过使用 Synapse Library,但我只能获得一部分(大约 50%)我们的公共联系人。

我现在正在尝试 ADO 方式(我已经读过 ADSI 与其他 LDAP 服务器兼容),但我无法让它工作。

ADOConnection 提供程序连接字符串如下所示:

Provider=ADsDSOObject;Encrypt Password=False;Integrated Security=SSPI;Data Source=NIS;Mode=Read;Bind Flags=0;ADSI Flag=-2147483648;

ADOConnection.LoginPrompt 设置为 true。

ADOQuery SQL 语句如下所示:

Select Description FROM 'LDAP://192.168.xxx.xxx/fn=Public Folders/cn=user@domain.com/fn=ContactRoot' WHERE objectClass='*'

打开 ADOQuery(从法语翻译)时出现错误:“发送了一个无效的目录路径”

这里有什么问题?除了 ADO / Synapse还有其他免费的解决方案吗?

先感谢您

西南

4

1 回答 1

0

您可以使用 COM:

  • 生成以下单元 (ActiveDs_TLB.pas)。

现在你可以:

或者

定义以下内容:

function ADsGetObject( lpszPathName: WideString; const riid: TGUID; out ppObject ):HRESULT; stdcall; external 'activeds.dll';

您可以使用以下代码获取 LDAP 对象:

function GetUserNameFromAD( const ADName: string ): string;
var
    Token:              THandle;
    Info, User, Domain: array [ 0..255 ] of Byte;
    ILen, ULen, DLen:   Longword;
    Use:                SID_NAME_USE;
    Usr:                IAdsUser;
begin
    Result := '';
    // Get the thread token. If the current thread is not impersonating, get the process token.
    if not OpenThreadToken( GetCurrentThread(), TOKEN_QUERY, True, Token ) then begin
        if GetLastError() <> ERROR_NO_TOKEN then Exit;
        if not OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, Token ) then Exit;
    end;
    try
        // Get name of domain and username using the token.
        if not GetTokenInformation( Token, TokenUser, @Info, sizeof( Info ), ILen ) then Exit;
        ULen := sizeof( User );
        DLen := sizeof( Domain );
        if not LookupAccountSid( nil, PSIDAndAttributes( @Info )^.Sid, @User, ULen, @Domain, DLen, Use ) then Exit;
        // Should be the specified domain
        if ADName <> PChar( @Domain ) then Exit;
        // Check user and domain with the AD and obtain the username from the AD
        if ADsGetObject( 'WinNT://' + PChar( @Domain ) + '/' + PChar( @User ), IADsUser, Usr ) <> S_OK then Exit;
        if Assigned( Usr ) then Result := Usr.Name;
    finally
        CloseHandle(Token);
    end;
end;

网上有一些示例如何使用这些单位。

于 2010-02-23T22:17:00.720 回答