Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

LDAP SAMPLE

250 views
Skip to first unread message

MSRegu

unread,
Mar 18, 2002, 11:05:46 AM3/18/02
to
Hi,

The following notification sample from MSDN describes the usage of
ldap_open, ldap_search and other ldap api calls:

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/netdir/ad/example_code_for_receiving_change_notifications.asp

This is a change notification code, though uses the above ldap api calls.
Pls. use ldpa_open call as ldap_open("yourldaphost",389) port.

Also, see the following code , which uses ldap_init call instead of
ldap_open.


// LDAP V2 and V3 bind sample

// This code doesn't have complete error handling.

//LDAP API can work as either V2 or V3 client.

//By default the version is 2.

//The following code demonstrates how to bind to an AD using LDAP API
either

//by V2 or V3 client.


#include <afx.h>

#include <windows.h>

#include <winldap.h>

int main( )

{

LDAP *ld;

int ret;

ld = ldap_init("reguwin2k", LDAP_PORT);

ULONG ulres;

unsigned uiVersion; // you can set LDAP version as
LDAP_VERSION2 or LDAP_VERSION3.

// Since default is 2, you want to
set the value only in

// V3 case.

// If you are interested to check the version,, use the
following code snippt,

ulres = ldap_get_option(ld, LDAP_OPT_VERSION, &uiVersion);
//Its optional

ASSERT(ulres == LDAP_SUCCESS);

printf("LDAP version is V%d\n", uiVersion);

// Make the client as LDAP V3 aware ( in this case )

if ( uiVersion == LDAP_VERSION2)

{

uiVersion = LDAP_VERSION3;

printf("Setting client to LDAP V3 aware... \n");

ulres = ldap_set_option(ld, LDAP_OPT_VERSION, &uiVersion);

ASSERT(ulres == LDAP_SUCCESS);

}

char pzDN[ ] =
"CN=Administrator,CN=Users,DC=regusdomain,DC=nttest,DC=microsoft,DC=com";

ret = ldap_simple_bind_s(ld, pzDN,"password"); //
Authentication using DN and password

// It is done in
clear text .
//
ldap_bind and ldap_bind_s use encryption.

printf("LDAP Error Msg : %s\n", ldap_err2string(ret)); // This
err. msg shows if client

// authenticates to the server

return 0;


}

Hope this helps.

Thanks,
MSRegu.

Disclaimer: This posting is provided "AS IS" with no warranties, and
confers no rights.


Jason Robarts [MS]

unread,
Mar 18, 2002, 3:37:50 PM3/18/02
to
ldap_init() is preferred over ldap_open(). One of the key reasons is that
it allows you to set options such as LDAP_OPT_AREC_EXCLUSIVE before any
network traffic is generated. This particular option is useful when you
know that the server name you are passing in matches the DNS A record of the
server so wldap32 knows not to search for domain SRV records. Using
ldap_connect() before your next operation allows you to keep the debugging
flexibility ldap_open() offers. See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netdir/ldap
/session_options.asp for more info on session options.

Jason
--


This posting is provided "AS IS" with no warranties, and confers no rights.


"MSRegu" <Reg...@online.microsoft.com> wrote in message
news:5V8zzapzBHA.2236@cpmsftngxa09...

Joe Richards [MVP]

unread,
Mar 20, 2002, 6:32:54 AM3/20/02
to
Find and buy the book

Active Directory Programming by Gil Kirkpatrick

It is one of the best books I have found on programming LDAP for AD. The
front half of the book is all about using ADSI, the back half is all LDAP.

--
Joe Richards
www.joeware.net
---

"michel" <m...@inetlab.net> wrote in message
news:424b01c1ce64$3740a740$39ef2ecf@TKMSFTNGXA08...
> Hi,
>
> Where can find sample for use of ldap_open, ldap_search,
> ldap_result ...
> (there is no sample in SDK)
>
> Regards,
> Michel


Al Dunbar

unread,
Mar 20, 2002, 9:39:42 AM3/20/02
to
This wasn't my question, but I will have a look for Kitrkpatrick's book.

Where I am finding most of my difficulties is that much of the information
available about ADSI seems directed at C or C++, while I am only planning on
using VBScript. There are examples in VBScript, of course, but I find that
much of the explanatory material still somehow assumes the reader is well
versed in C/C++ terminology.

For example, taken from adsi25.chm:
a.. ADsGetObject function (C/C++ only)
b.. ADsOpenObject function (C/C++ only)
c.. GetObject method (VB and VBScript only)
d.. IADsOpenDSObject::OpenDSObject method (VB and VBScript)
Now, GetObject I know. But I am not sure how to go about referencing the
IADsOpenDSObject::OpenDSObject method.

adsi25.chm (and other references) speak about ADSI concepts of interfaces
and lists quite a few. However, it appears that much of this is either
behind the scenes in VBScript, not available, or inapplicable.

I am not looking for coding examples showing me exactly how to do what I
want (hey, there needs to be *some* mystery in this, or I wouldn't be
interested). Rather, I would like to see some reference that either explains
it all in a VBScript context, or in a non-language specific manner so that I
can piece things together with the available examples.

The answer may be just adsi25.chm, but with a few additional clues for the
clueless ;-)

Any suggestions?

/Al

"Joe Richards [MVP]" <humore...@hotmail.com> wrote in message
news:OIhDqLA0BHA.2816@tkmsftngp05...

Joe Richards [MVP]

unread,
Mar 20, 2002, 8:20:20 PM3/20/02
to
That book is also geared towards c++ programmers.

Vbscript handles things differently than c++. For ADSI and in fact any COM
stuff it is generally much easier to use VB or VBScript than it is to use
C++. Looking at C++ examples would add unnecessary complexity to what you
are doing.

Having said that I will admit that it does seem to be difficult to find good
info for doing ADSI calls with vbscript (and then for me at least eventually
perl). I have been stumbling around with it myself and do a heck of a lot of
searching of google groups with keywords that I think I will give me good
hits.

One book that I have found that has been helpful is Windows NT/2000 ADSI
Scripting for System Administration by Thomas Eck.

--
Joe Richards
www.joeware.net
---

"Al Dunbar" <Luigi...@hotmail.com> wrote in message
news:OFVMk1B0BHA.1712@tkmsftngp04...

0 new messages