0

I am completely new with LDAP and I need to retreive some informations in my office LDAP, nobody's here to help me. Here is the information I got (I change a little bit for security reasons) :

  • host : the.ldap.host
  • search base : ou=People,dc=xxx,dc=yyyy,dc=zzzzz
  • filter : (projectTeams=manager)
  • user : uid=eric, ou=Technical,dc=xxx,dc=yyyy,dc=zzzzz
  • password : blabla

That's all I get to do the job to find all the "manager"

Here is my code :

Dim oRoot2 As DirectoryEntry = New DirectoryEntry ("LDAP://the.ldap.host", "uid=eric,ou=Technical,dc=xxx,dc=yyyy,dc=zzzzz", "blabla",AuthenticationTypes.None)
try
    Dim connected As Object = oRoot2.NativeObject
    msgbox "Connected"
    Dim searcher As DirectorySearcher = New DirectorySearcher(oRoot2)
    searcher.Filter = "(projectTeams=manager)"
    Dim DirEntry As DirectoryEntry
    For Each result As SearchResult In searcher.FindAll
        DirEntry = result.GetDirectoryEntry
        lst.Items.Add(DirEntry.Properties("iam-uid").Value)
    Next
catch ex as exception
    msgbox (ex.message)
End try

When running, I received the "Connected" messagebox but then I get an error "There is no such objet on the server". This error is thrown when performing the line bellow :

For Each result As SearchResult In searcher.FindAll

I do not know how to code that the search base is "ou=People,dc=xxx,dc=yyyy,dc=zzzzz"

I already spent two days trying. All help is welcome.

EricS
  • 1
  • 2
  • 1
    Try adding some debugging steps. wrapping parts in Try/Catches or IF statements may help to drill down where the issue is. This link may assist with the Try/Catch: https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/try-catch-finally-statement – Petay87 Aug 29 '18 at 13:35
  • Thanks, I edit the post to explain on which line the error occurs. – EricS Aug 29 '18 at 13:43
  • In the past I've used the following to load results into search result collection: Dim result As SearchResultCollection = searcher.FindAll(). Then you would do your For Each res As SearchResult In result. Check this link out for an example: http://www.visual-basic-tutorials.com/Tutorials/Controls/DirectorySearcher.html – Petay87 Aug 29 '18 at 13:53
  • Also - You have "uid=eric,ou=Technical,dc=xxx,dc=yyyy,dc=zzzzz" this is not going to work as you are not looking inside an OU here, you need to remove the uid part so that you are only left with the base ou to search in. My guess would be: ou=Technical,dc=xxx,dc=yyyy,dc=zzzzz – Petay87 Aug 29 '18 at 13:57
  • If I remove the uid part, how to set the login for the connection ? – EricS Aug 29 '18 at 14:15
  • DirectoryEntry("LDAP://the.ldap.host/ou=Technical,dc=xxx,dc=yyyy,dc=zzzzz", "USERNAME", "PASSWORD"). A couple of links to browse over: https://stackoverflow.com/questions/20002036/vb-net-ldap-connection-cant-show-ou-users https://stackoverflow.com/questions/1405011/ldap-directory-entry-in-net-not-working-with-ou-users https://forums.asp.net/t/1546755.aspx?LDAP+Connection+with+VB+NET – Petay87 Aug 30 '18 at 07:04
  • Thank you Petay87 ! one of your links gave me some informations and some hyperlink to surf and I finally discover how to proceed. – EricS Sep 06 '18 at 05:52

1 Answers1

0

I finally found a way to get the information I need, here is the code that works for me :

Dim oRoot2 As DirectoryEntry = New DirectoryEntry ("LDAP://the.ldap.host/ou=People,dc=xxx,dc=yyyy,dc=zzzzz", "uid=eric,ou=Technical,dc=xxx,dc=yyyy,dc=zzzzz", "blabla",AuthenticationTypes.None)

This small change changes everything and the rest of the code (see below) is working now.

try Dim connected As Object = oRoot2.NativeObject msgbox "Connected" Dim searcher As DirectorySearcher = New DirectorySearcher(oRoot2) searcher.Filter = "(projectTeams=manager)" Dim DirEntry As DirectoryEntry For Each result As SearchResult In searcher.FindAll DirEntry = result.GetDirectoryEntry lst.Items.Add(DirEntry.Properties("iam-uid").Value) Next catch ex as exception msgbox (ex.message) End try

It took me 3 working days to find this...pfff.

EricS
  • 1
  • 2