bind() returns before binding operation is done
In function main(), I had to insert sleep(3) between bind() on line 533 and search_for_groups() on line 541. Without this delay, the Active Directory server thinks the bind operation is still in progress, and search_for_groups() throws an exception. This is arguably not the right way to handle it. Ideally, bind() should poll for the completion of the operation and block until the operation finishes or times out. Script is running under Windows XP.