s4/ldap: Refactor the fix for ldap nested searches