LDAP: fix determining objectclasses takes long

Fixes walk through of possibly all LDAP user entries when determining objectClasses, which results in really bad performance with bigger user bases. Includes also a fix for a potential infinity loop. And adds tests for the method in question.

Fixes #7530 

Please review @DeepDiver1975 @leo-b (do you mind?) @PVince81 or others.