Query a Novell LDAP server with VB.Net

Once again, I am amazed at how simple tasks have become using .Net. Something I thought would be complex turns out to be completely handled by the framework. Kudos to the .Net team.

For my current project, I need to validate that a person is an internal employee before allowing them continued acccess to the web site. My company uses a Novell infrastructure, and luckily has an LDAP server that I can access for employee validation.

Luckily, Novell provides a resource for developers to begin working with LDAP at the Novell Developer Labs. You can create an account and query their server for free. So that is where I started, but eventually the Novell network admins in my company got around to my request and I was able to use the code almost without modification against our internal server.

Here is my quick console application I created to test against the Novell Developer Lab LDAP site (my container name is Fender and my login is admin.  The only modifications I had to do to get it to work with my company’s LDAP server was to learn the container names and the fields I could query.  

Imports System.DirectoryServices

Sub Main()
Dim
ds As New DirectorySearcher
Dim resultset As SearchResultCollection
Dim result As SearchResult
‘Return the securityEquals field and the cn field
Dim ResultFields() As String = {“securityEquals”, “cn”}

With ds
    ‘Set the container I want to search (.admin.Fender.user.novell)
    .SearchRoot = New DirectoryEntry(
LDAP://192.108.102.215/ou=Fender,ou=user,o=novell)
    ‘Use the array set above for return fields
    .PropertiesToLoad.AddRange(ResultFields)
   
‘Set a filter/query
    .Filter = “cn=ad*”
End With

Try
  
‘Perform the search

   
resultset = ds.FindAll()
    If resultset.Count > 0
Then
       
For Each result In resultset
            Console.WriteLine(result.Properties(“securityEquals”)(0))
       
Next
    Else
        ‘No results
       
Console.WriteLine(“No Data Found”)
    End If

Catch ex As Exception
   Console.WriteLine(“Error: “)
   Console.WriteLine(ex.Message)
End Try

End Sub

Posted on:

Comments are closed.