Backport bfa7157
LDAP: fix possible recursion