Click here to Skip to main content
15,886,788 members
Articles / Desktop Programming / MFC

Implementing Interoperable LDAP Applications

Rate me:
Please Sign up or sign in to vote.
3.59/5 (16 votes)
14 Apr 200225 min read 187K   2.7K   60  
Implementing Ldap wrapper classes for both W2K and Unix
<HTML>
   <HEAD>
      <META NAME="GENERATOR" Content="Microsoft Developer Studio">
      <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">

      <STYLE>
         A {text-decoration: none; color: MidnightBlue}
      </STYLE>

      <TITLE>Implementing Interoperable LDAP Applications</TITLE>
   </HEAD>
<BODY>

   <!-- -------------------------------------------------------------------- -->

   <center>
   <font face=arial size=5>
      Implementing Interoperable LDAP Applications
   </font><br>
   <font face=arial size=4>
      By Eduardo Sobrino
   </font>
   </center>

   <!-- -------------------------------------------------------------------- -->
   <!-- For your Information -->

   <br><br>
   <table bgcolor=lightgrey width="100%"><tr><td>
   <font face=arial size=4 color=white>
      <a name=#LDAPBYR>Before You Read</a>
   </font>
   </td><td align=right>
   <font size=1><a href=#LDAPTOC>[ BACK ] </a></font>
   </td></tr></table>

   <br>
   The following document provides an overview of the ClLdap and related classes
   that implements "portable" code that support LDAP to manage directory 
   services from an application.  ClLdap is a high level class and hides
   most details of managing a connection and directories. The current version
   also provides <a href=#LDAPMSSQL>MS-SQL external procedures</a> to manage the
   ClLdap class and LDAP request queueing using <a href=#LDAPMSMQ>MS-Message
   Queue</a> based on LDIF wrapped by a XML document (read on for details).
   To handle queued transactions I have added a service that will run in
   NT/W2k that fetches the transactions from the queue and sudmit them to the
   Directory Services server using LDAP (protocol).

   <br><br>
   Why to take a look at this work? You can do it your self, still, I have spent
   some time working and experimenting and coding for LDAP and trying to mantain
   an interoperable (W2k to UNIX and vs) code that implements it. This experience
   I am trying to give to you and may be of value so take a peek.
   The code samples in other references provide you with samples of calling
   LDAP API functions, Here I have tried to implement a collection of classes
   that from my point of view are a lot more simpler to use. For example, with
   the "ClLdap" and "ClLdapUser" classes you can manage users as simple as:
   
   <br><br>
   <center>
   <table bgcolor=PaleGoldenrod><tr><td>
   <xmp>

   int main(int argc, char* argv[])
   {  ClLdap myLdap ;

      // connect to default LDAP server and authenticate currently logged user.

      if (myLdap.Connect()) {
         if (myLdap.AuthenticateUser()) {

            // get an "LDAP" related user object located at given RDN
            // (Relative Distinguished Name) "CN=Users,OU=MyOrganization"...

            ClLdapUser myuser(&myLdap,"CN=Users,OU=MyOrganization") ;

            // if this users don't exist, then add them...

            if (!myuser.Exists("Maria"))
               myuser.Add("Maria","batata") ;
            if (!luser.Exists("Carmina"))
               myuser.Add("Carmina","bacalao") ;

            // reset "Maria's password to "malanga"
            // don't miss-interpret the following (YOU CAN'T ACCESS THE
            // PASSWORD OR CHANGE IT IN LDAP) this you will learn fast;
            // deep in a bit later I have more on password info...

            myuser.SetPassword("Maria","malanga") ;

            // find the value of Maria's "CN" (Common-Name)...

            char rVal[MINSTRLEN+1] ;
            myuser.Find("Maria","cn",rVal,MINSTRLEN) ;
            cout << "Maria's CN=" << rVal << endl ;

            // authenticate Maria with the password "malanga"

            myuser.Authenticate("Maria","malanga") ;

            // delete entries...

            myuser.Delete("Maria") ;
            myuser.Delete("Carmina") ;

         }
         // disconnect from server
         myLdap.Disconnect() ;
      }
   }
   </xmp>
   </td></tr></table>
   </center>

   <br>
   To learn about LDAP and Active Directory you should get acquainted with
   the terminology (eg. LDAP, RDN, ...).  Beside that, the above code does
   a lot in very few lines.  A nice thing about it is that you will be able to
   compile the code for Windows 2k or UNIX and "will work as good".

</BODY>
</HTML>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Puerto Rico Puerto Rico
C/C++ programmer since 1984.

Comments and Discussions