#include "zbxsysinfo.h"
#include "../sysinfo.h"
#include "simple.h"
#include "../common/net.h"
#include "ntp.h"
#include "zbxstr.h"
#include "zbxnum.h"
#include "zbxtime.h"
#include "zbxcomms.h"
#include "zbx_discoverer_constants.h"
#ifdef HAVE_LIBCURL
# include "zbxcurl.h"
# include "zbxip.h"
#endif
#ifdef HAVE_LDAP
#include <ldap.h>
#ifdef HAVE_LBER_H
# include <lber.h>
#endif
static int check_ldap(const char *host, unsigned short port, int timeout, int *value_int)
{
LDAP *ldap = NULL;
LDAPMessage *res = NULL;
LDAPMessage *msg = NULL;
BerElement *ber = NULL;
struct timeval tm;
char *attrs[2] = {"namingContexts", NULL };
char *attr = NULL;
char **valRes = NULL;
int ldapErr = 0;
*value_int = 0;
if (NULL == (ldap = ldap_init(host, port)))
{
zabbix_log(LOG_LEVEL_DEBUG, "LDAP - initialization failed [%s:%hu]", host, port);
goto lbl_ret;
}
#if defined(LDAP_OPT_SOCKET_BIND_ADDRESSES) && defined(HAVE_LDAP_SOURCEIP)
if (NULL != sysinfo_get_config_source_ip())
{
if (LDAP_SUCCESS != (ldapErr = ldap_set_option(ldap, LDAP_OPT_SOCKET_BIND_ADDRESSES,
sysinfo_get_config_source_ip())))
{
zabbix_log(LOG_LEVEL_DEBUG, "LDAP - failed to set source ip address [%s]",
ldap_err2string(ldapErr));
goto lbl_ret;
}
}
#endif
tm.tv_sec = timeout;
tm.tv_usec = 0;
if (LDAP_SUCCESS != (ldapErr = ldap_set_option(ldap, LDAP_OPT_NETWORK_TIMEOUT, &tm)))
{
zabbix_log(LOG_LEVEL_DEBUG, "LDAP - failed to set network timeout [%s]", ldap_err2string(ldapErr));
goto lbl_ret;
}
if (LDAP_SUCCESS != (ldapErr = ldap_search_s(ldap, "", LDAP_SCOPE_BASE, "(objectClass=*)", attrs, 0, &res)))
{
zabbix_log(LOG_LEVEL_DEBUG, "LDAP - searching failed [%s] [%s]", host, ldap_err2string(ldapErr));
goto lbl_ret;
}
if (NULL == (msg = ldap_first_entry(ldap, res)))
{
zabbix_log(LOG_LEVEL_DEBUG, "LDAP - empty sort result. [%s] [%s]", host, ldap_err2string(ldapErr));