English 中文(简体)
How to connect to an OpenLDAP server using ADO (or else) and Delphi
原标题:

I m trying to connect to an OpenLDAP server clone . I ve tried using Synapse Library but I was able to get only a part (about 50%) of our public contacts.

I m trying now the ADO way (I ve read that ADSI was compatible with other LDAP servers) but I can t get it working.

ADOConnection provider connection string looks like this :

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

ADOConnection.LoginPrompt is set to true.

ADOQuery SQL Statement looks like this :

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

I m getting an error when opening the ADOQuery (translated from French) : "An non valid directory path was sent"

What is wrong here ? Is there any other free solution than ADO / Synapse ?

Thank you in advance

SW

问题回答

You can use COM:

  • Generate the follwoing unit (ActiveDs_TLB.pas).

Now you can:

or

Define the following:

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

you can get LDAP objects using code like:

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;

There are some examples on the web how to use these units.





相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签