views:

651

answers:

2

Suppose i have a following LDAP query:

Base DN: OU=Groups,DC=office,DC=domain,DC=org
Filter: (member:1.2.840.113556.1.4.1941:=CN=adam smith,OU=Users,DC=office,DC=domain,DC=org)

How can I execute it under Delphi(2007)? Examples using ADO seem to have SQL'ish syntax and I do not now how to convert it?

+3  A: 

In Delphi, you can use two ways of getting at your data:

  • either the "SQL'ish" syntax you describe - basically ADO access to Active Directory. That's easy, if you have a SQL background, but it's also limited in some ways (e.g. you cannot get at multi-valued attributes and such). You'll find some Search Tips on ADO on Richard Mueller's site (AD Programming MVP)

  • import the ActiveDs.tlb type library and use the COM interfaces (most notably IDirectorySearch) provided by ADSI to search. It's a rather messy COM interface, that's probably why most tend to use the ADO search stuff which is more readily approachable

Way back when I was still programming Delphi, I did a lot of Active Directory stuff and puts some of my Delphi / AD tips and some sample code onto my site. It's not been updated in quite a while though :-( But the ADSISearch component might be of interest to you (and other Delphites)

Update: can you try this "SQL-ish" statement in your TADOCommand??

SELECT sAMAccountName, displayName 
FROM 'LDAP://OU=Groups,DC=office,DC=domain,DC=org' 
WHERE objectCategory='group'
  AND member:1.2.840.113556.1.4.1941:=(CN=adam smith,OU=Users,DC=office,DC=domain,DC=org)
marc_s
Thank you for your repy! I really need to run only one query ( the one that I posted above). If someone is able to re-write it so that I can use it TADOCommand...?
marian12
Yes, but 1.2.840.113556.1.4.1941 (LDAP_MATCHING_RULE_IN_CHAIN) gives me ALL groups that user belongs to (not only those from memberof) - this happens when groups are members of other grous - I need them ALL.
marian12
A: 
AND member:1.2.840.113556.1.4.1941:=(CN=adam smith,OU=Users,DC=office,DC=domain,DC=org)

Thanks but how the above supposed to work? You mean?:

AND member='1.2.840.113556.1.4.1941:=(CN=adam smith,OU=Users,DC=office,DC=domain,DC=org'

Can not put this part to work...

marian12
does't your version need a closing ")" after DC=org ??
marc_s
tried everything by now... Back to your second advice.: Im using WinLDAP library that interfaces WinApi
marian12