Fixes #3004 Refactoring config reading and ldap binding