Skip to content

Commit

Permalink
Merge pull request #454 from greenbone/mergify/bp/master/pr-453
Browse files Browse the repository at this point in the history
Add function ldap_enable_debug () (bp #453)
  • Loading branch information
timopollmeier authored Mar 10, 2021
2 parents d60bfe3 + aa124be commit 26b762c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
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

0 comments on commit 26b762c

Please sign in to comment.