rc collects exit status all the way down but is not used at all? If code comparison at exit is intended then there exists some path that leaves it in garbage value, say when ldap_whoami or ldap_cancel fails.
rc
code
ldap_whoami
ldap_cancel