In this text, I will provide a demonstration for two basic functions of LDAP.
Search Scope of "Base"
A search performed on the server with the above parameters will result in the server spitting out information about itself.
In order to form this search with the IP*Works! component, we only need to fill in a few simple properties:
LDAP1.ServerName = txtServer.Text
LDAP1.DN = ""
LDAP1.SearchFilter = "objectClass=*"
LDAP1.SearchScope = ssBaseObject
LDAP1.Search
After this search is complete, a SearchComplete event will fire - at which time we know that we have received
all of the relevant information from the server and we are free to examine the results. These results are
provided in the Attr arrays. First, LDAP1.AttrCount provides the number of attributes. LDAP1.AttrType(i) provides
the type of the ith attribute, and the LDAP1.AttrValue(i) provides the value of the ith attribute.
One way to extract this data is to add the results to a listbox:
For i = 0 To LDAP1.AttrCount - 1
lstResults.AddItem (LDAP1.AttrType(i) & ":" & LDAP1.AttrValue(i))
Next
Basic LDAP Entry Query
LDAP Directories can of course be used to contain any type of information, but most commonly the information you see
is about people. For example, lets say our server, named NSOFTWARE, contains information about all of the employees
in the company.
Lets go ahead and single out one particular employee, Lance Robinson, me. My UID is LRobinson. Our goal is to
perform a search for all of the attributes of the entry for LRobinson. The first step is to determine the DN
for that entry.
Bind and Determine User DN
When initially connecting to the LDAP server, we can bind anonymously or we can authenticate. For the purposes
of this document, we'll just bind anonymously. After binding (connecting), we'll issue a search on the base DN
of my directory for the UID LRobinson. We can determine the base DN's for the servers from the namingContext attributes
of the DSE search we did above.
LDAP1.ServerName = txtMyServer.Text
LDAP1.Bind 'anonymously bind to the server
LDAP1.DN = "NSOFTWARE" 'The DN to NSOFTWARE, which we obtained from the DSE Search
LDAP1.SearchFilter = "uid=LRobinson" 'search for this uid
LDAP1.Search
For each entry on the server in the directory with DN NSOFTWARE that matches the UID=LRobinson, a SearchResult
event will fire, reporting the DN of the matching entry. We'll grab this information, since that is what we need
in order to perform a direct search on this user. In this particular search on my server, the SearchResult event
fired once, with the following DN: "uid=LRobinson, ou=People, dc=com".
Query User DN
From here its easy! Now that we know the DN of the user, simply perform a new search on this DN:
LDAP1.DN = "uid=LRobinson, ou=People, dc=com"
LDAP1.SearchFilter = "ObjectClass=*"
LDAP1.Search
Now a search will be performed on the LRobinson entry. When the SearchComplete event fires, we know that we
have all of the information that the server has returned and we can parse through it and do with it what we will.
Below I am displaying the information as before - to a listbox:
For i = 0 To LDAP1.AttrCount - 1
lstResults.AddItem (LDAP1.AttrType(i) & ":" & LDAP1.AttrValue(i))
Next
The results will look like the following:
objectClass: Person
: organizationalPerson
: inetorgperson
: top
sn: Robinson
cn: Lance Robinson
uid: LRobinson
creatorsName: uid=admin,ou=administrators
modifiersName: uid=admin,ou=administrators
createTimestamp: 20010710235642Z
modifyTimestamp: 20020313152716Z
mail: lancer@nsoftware.com
description: Incredibly good-looking
: Incredibly smart
roomNumber: 110
More Information
For information about the author, please contact
lancer@nsoftware.com.
For more information about IP*Works! or the LDAP component, please visit /n
software.
Copyright © 2002, Lance Robinson - All Rights
Reserved. For publishing permissions, contact
lancer@nsoftware.com.