/*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2003-2009 Match Grun and the Claws Mail team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2003-2018 Match Grun and the Claws Mail team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
*/
/*
#ifdef HAVE_CONFIG_H
# include "config.h"
+#include "claws-features.h"
#endif
#ifdef USE_LDAP
#include <glib.h>
+#include <glib/gi18n.h>
#include <string.h>
#include <sys/time.h>
-#include <ldap.h>
-#include <lber.h>
#include <errno.h>
#include "common/utils.h"
+#include "ldaputil.h"
#include "ldapserver.h"
#include "ldapctrl.h"
+#include "log.h"
#define SYLDAP_TEST_FILTER "(objectclass=*)"
#define SYLDAP_SEARCHBASE_V2 "cn=config"
attribs, 0, NULL, NULL, &timeout, 0, &result );
if( rc == LDAP_SUCCESS ) {
+ log_message(LOG_PROTOCOL, _("LDAP (search): succesful\n"));
/* Process entries */
for( e = ldap_first_entry( ld, result );
e != NULL;
}
ber = NULL;
}
- }
+ } else {
+ log_error(LOG_PROTOCOL, _("LDAP error (search): %d (%s)\n"),
+ rc, ldaputil_get_error(ld));
+ debug_print("LDAP: Error %d (%s)\n", rc, ldaputil_get_error(ld));
+ }
+
if (errcode)
*errcode = rc;
if (result)
attribs, 0, NULL, NULL, &timeout, 0, &result );
if( rc == LDAP_SUCCESS ) {
+ log_message(LOG_PROTOCOL, _("LDAP (search): succesful\n"));
/* Process entries */
for( e = ldap_first_entry( ld, result );
e != NULL;
ch = ( char * ) strchr( tmp, ':' );
if( ch ) {
gchar *bn = g_strdup( ++ch );
- g_strchomp( bn );
- g_strchug( bn );
+ g_strstrip( bn );
baseDN = g_list_append(
baseDN, g_strdup( bn ) );
g_free( bn );
}
ber = NULL;
}
+ } else {
+ log_error(LOG_PROTOCOL, _("LDAP error (search): %d (%s)\n"),
+ rc, ldaputil_get_error(ld));
+ debug_print("LDAP: Error %d (%s)\n", rc, ldaputil_get_error(ld));
}
if (result)
ldap_msgfree( result );
int claws_ldap_simple_bind_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd )
{
+ debug_print("binding: DN->%s\n", dn?dn:"null");
+#ifdef G_OS_UNIX
struct berval cred;
if ( passwd != NULL ) {
cred.bv_len = 0;
}
- debug_print("binding: DN->%s\n", dn?dn:"null");
return ldap_sasl_bind_s( ld, dn, LDAP_SASL_SIMPLE, &cred,
NULL, NULL, NULL );
+#else
+ return ldap_simple_bind_s(ld, (PCHAR)dn, (PCHAR)passwd);
+#endif
}
/**
ldapctl_set_host(ctl, host);
ldapctl_set_timeout(ctl, tov);
ldapctl_set_bind_dn(ctl, bindDN);
- ldapctl_set_bind_password(ctl, bindPW, FALSE, FALSE);
ld = ldapsvr_connect(ctl);
if (ld == NULL) {
if (baseDN)
debug_print("Using LDAP v3\n");
+#ifdef G_OS_UNIX
if( baseDN == NULL && !LDAP_API_ERROR(rc) ) {
+#else
+ if( baseDN == NULL) {
+#endif
baseDN = ldaputil_test_v2( ld, tov );
if (baseDN)
debug_print("Using LDAP v2\n");
return TRUE;
}
+const gchar *ldaputil_get_error(LDAP *ld)
+{
+ gchar *ld_error = NULL;
+ static gchar error[512];
+
+ ldap_get_option( ld, LDAP_OPT_ERROR_STRING, &ld_error);
+ if (ld_error != NULL)
+ strncpy2(error, ld_error, sizeof(error));
+ else
+ strncpy2(error, _("Unknown error"), sizeof(error));
+#ifndef G_OS_WIN32
+ /* From https://msdn.microsoft.com/en-us/library/aa366594%28v=vs.85%29.aspx
+ * "LDAP_OPT_ERROR_STRING returns a pointer to an internal static
+ * string table, and ldap_memfree should not be called when using
+ * this session option."
+ */
+ ldap_memfree(ld_error);
+#endif
+
+ return error;
+}
#endif /* USE_LDAP */
/*