LDAP: backport basic fix from PR #1493 to fix bug #1450 in stable45

Backport differs from original fix, also contains only minimal/necessary changes. That's why i decided for another PR.

Closes https://github.com/owncloud/core/issues/1450 in stable45

Please review @schiesbn @DeepDiver1975 @karlitschek @bartv2 or others