在使用OpenLDAP时,如何从OpenSSL错误中获取更详细的错误信息?

在使用OpenLDAP时,如何从OpenSSL错误中获取更详细的错误信息?,openssl,ldap,openldap,Openssl,Ldap,Openldap,我有一些代码正在使用OpenLDAP的社区版本。应用程序是客户端的。 要建立与LDAP服务器的连接,我使用的是LDAP\u sasl\u bind\s,大致如下所示: char *nAuthOption = LDAP_SASL_SIMPLE; struct berval pPassword = { m_Credentials.m_sPassword.length(), const_cast<char *>(m_Credentials.m_sPassword.c_str

我有一些代码正在使用OpenLDAP的社区版本。应用程序是客户端的。 要建立与LDAP服务器的连接,我使用的是
LDAP\u sasl\u bind\s
,大致如下所示:

char *nAuthOption = LDAP_SASL_SIMPLE;
struct berval pPassword = {
    m_Credentials.m_sPassword.length(),
    const_cast<char *>(m_Credentials.m_sPassword.c_str())
};
nStatus = ldap_sasl_bind_s(m_pLDAPConnection,
                           m_Credentials.m_sUsername.c_str(),
                           nAuthOption,
                           &pPassword,
                           NULL,
                           NULL,
                           &servercredp);
free(nAuthOption);

if (nStatus!=LDAP_SUCCESS)
{
    LOGE() << METHOD_NAME << "Failed to bind to LDAP " << LDAPError(nStatus);
    return false;
}
return true;
char*nAuthOption=LDAP\u SASL\u SIMPLE;
结构berval pPassword={
m_凭证.m_sPassword.length(),
const_cast(m_Credentials.m_sPassword.c_str())
};
nStatus=ldap_sasl_bind_s(m_pldap连接,
m_Credentials.m_sUsername.c_str(),
呕吐,
&帕萨斯word,
无效的
无效的
&(CREDP);
自由(呕吐);
如果(nStatus!=LDAP\u成功)
{

LOGE()我发现从OpenLDAP获取更多详细信息的一种方法是为
libber
库提供日志回调,如下所示:

#if defined(LBER_OPT_LOG_PRINT_FN)
static void ldap_debug_cb(const char *msg) {
  /* Write out message to e.g. stderr */
  fprintf(stderr, "LDAP debug: %s\n", msg);
}
#endif /* no LBER_OPT_LOG_PRINT_FN */

#if defined(LBER_OPT_LOG_PRINT_FN)
  if (ber_set_option(NULL, LBER_OPT_LOG_PRINT_FN, ldap_debug_cb) != LBER_OPT_SUCCESS) {
     /* Log error about setting option/callback */
  }
#endif /* LBER_OPT_LOG_PRINT_FN */
请注意,您可能还需要确保OpenLDAP
LDAP\u DEBUG\u LEVEL
选项也设置为足够高的级别:

  LDAP *ldap = ...

  /* This debug level value should be LDAP_DEBUG_ANY, but that macro is, I
   * think, OpenLDAP-specific.
   */
  int debug_level = -1;

  if (ldap_set_option(ldap, LDAP_OPT_DEBUG_LEVEL, &debug_level) != LDAP_OPT_SUCCESS) {
    /* Write error about setting option */
  }
希望这有帮助