Skip to content

Commit

Permalink
Add function ldap_enable_debug ()
Browse files Browse the repository at this point in the history
This function enables LDAP debug logging via the glib logging, which can
be used for debugging LDAP connection issues, for example.
  • Loading branch information
timopollmeier committed Mar 10, 2021
1 parent 5ea6c68 commit 3c77434
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
51 changes: 51 additions & 0 deletions util/ldaputils.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,45 @@
* LDAP directory server.
*/

/**
* @brief Wrapper function to use glib logging for LDAP debug logging.
*/
static void
ldap_log (const char *message)
{
g_debug ("OpenLDAP: %s", message);
}

/**
* @brief Enable OpenLDAP debug logging.
*
* @return 0 success, -1 error.
*/
int
ldap_enable_debug ()
{
int ret;
static int debug_level = 65535;

ret = ber_set_option (NULL, LBER_OPT_LOG_PRINT_FN, ldap_log);
if (ret != LBER_OPT_SUCCESS)
{
g_warning ("%s: Failed to set LDAP debug print function: %s",
__func__, ldap_err2string (ret));
return -1;
}

ret = ldap_set_option (NULL, LDAP_OPT_DEBUG_LEVEL, &debug_level);
if (ret != LDAP_OPT_SUCCESS)
{
g_warning ("%s: Failed to set LDAP debug level: %s",
__func__, ldap_err2string (ret));
return -1;
}

return 0;
}

/**
* @brief Authenticate against an ldap directory server.
*
Expand Down Expand Up @@ -455,6 +494,18 @@ ldap_auth_dn_is_good (const gchar *authdn)

#else

/**
* @brief Dummy function for enabling LDAP debugging for manager.
*
* @return Always -1 for failure.
*/
int
ldap_enable_debug ()
{
g_warning ("%s: GVM-libs compiled without LDAP", __func__);
return -1;
}

/**
* @brief Dummy function for manager.
*
Expand Down
3 changes: 3 additions & 0 deletions util/ldaputils.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ struct ldap_auth_info
gboolean allow_plaintext; ///< !Whether or not StartTLS is required.
};

int
ldap_enable_debug ();

int
ldap_connect_authenticate (const gchar *, const gchar *,
/* ldap_auth_info_t */ void *, const gchar *);
Expand Down

0 comments on commit 3c77434

Please sign in to comment.