Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function ldap_enable_debug () (bp #453) #454

Merged
merged 3 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [20.8.2] (unreleased)

### Added
- Add function ldap_enable_debug () [#453](https://github.com/greenbone/gvm-libs/pull/453)

### Changed
- Use a char pointer instead of an zero-lenght array as kb_redis struct member. [443](https://github.com/greenbone/gvm-libs/pull/443)

Expand Down
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