/*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2003-2012 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 USE_LDAP
#include <glib.h>
+#include <glib/gi18n.h>
#include <sys/time.h>
#include <string.h>
#include "addritem.h"
#include "addrcache.h"
#include "common/utils.h"
+#include "log.h"
/*
* Key for thread specific data.
}
}
if( fullName ) {
- g_strchug( fullName ); g_strchomp( fullName );
+ g_strstrip( fullName );
allocated = TRUE;
}
}
if (attrib->name && strcmp(attrib->name, "jpegPhoto")) {
addritem_person_add_attribute( person, attrib );
} else {
- if (qry && qry->server && qry->server->control) {
+ if (qry->server && qry->server->control) {
gchar *dir = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S,
ADDRBOOK_DIR, G_DIR_SEPARATOR_S, NULL );
gchar *filename = g_strdup_printf("%s-%s-%s",
if( ber != NULL ) {
ber_free( ber, 0 );
}
- g_free( dnEntry );
+ ldap_memfree( dnEntry );
return listReturn;
}
* \return Error/status code.
*/
static gint ldapqry_disconnect( LdapQuery *qry ) {
+ gint rc;
/* Disconnect */
- if( qry->ldap ) ldap_unbind_ext( qry->ldap, NULL, NULL );
+ if( qry->ldap ) {
+ rc = ldap_unbind_ext( qry->ldap, NULL, NULL );
+ if (rc != LDAP_SUCCESS) {
+ log_error(LOG_PROTOCOL, _("LDAP error (unbind): %d (%s)\n"),
+ rc, ldaputil_get_error(qry->ldap));
+ } else {
+ log_message(LOG_PROTOCOL, _("LDAP (unbind): successful\n"));
+ }
+ }
qry->ldap = NULL;
ldapqry_touch( qry );
ADDRQUERY_RETVAL(qry) = LDAPRC_TIMEOUT;
rc = ldap_search_ext_s( ld, ctl->baseDN, LDAP_SCOPE_SUBTREE, criteria,
attribs, 0, NULL, NULL, &timeout, 0, &result );
- debug_print("LDAP Error: ldap_search_st: %d\n", rc);
- debug_print("LDAP Error: ldap_search_st: %s\n", ldaputil_get_error(ld));
+ debug_print("LDAP ldap_search_ext_s: %d (%s)\n", rc, ldaputil_get_error(ld));
ldapctl_free_attribute_array( attribs );
g_free( criteria );
criteria = NULL;
if( rc == LDAP_TIMEOUT ) {
+ log_warning(LOG_PROTOCOL, _("LDAP (search): timeout\n"));
return ADDRQUERY_RETVAL(qry);
}
ADDRQUERY_RETVAL(qry) = LDAPRC_SEARCH;
/* Test valid returns */
searchFlag = FALSE;
if( rc == LDAP_ADMINLIMIT_EXCEEDED ) {
+ log_warning(LOG_PROTOCOL, _("LDAP (search): server limits exceeded\n"));
searchFlag = TRUE;
}
else if( rc == LDAP_SUCCESS ) {
+ log_message(LOG_PROTOCOL, _("LDAP (search): successful\n"));
searchFlag = TRUE;
}
else if( rc == LDAP_PARTIAL_RESULTS || (result && ldap_count_entries(ld, result) > 0) ) {
+ log_message(LOG_PROTOCOL, _("LDAP (search): successful (partial results)\n"));
searchFlag = TRUE;
}
else {
- debug_print("LDAP Error: ldap_search_st: %d\n", rc);
- debug_print("LDAP Error: ldap_search_st: %s\n", ldaputil_get_error(ld));
+ log_error(LOG_PROTOCOL, _("LDAP error (search): %d (%s)\n"), rc, ldaputil_get_error(ld));
return ADDRQUERY_RETVAL(qry);
}
ADDRQUERY_RETVAL(qry) = LDAPRC_STOP_FLAG;
+#ifdef G_OS_WIN32
+ debug_print("Total results are: %lu\n", ldap_count_entries(ld, result));
+#else
debug_print("Total results are: %d\n", ldap_count_entries(ld, result));
+#endif
/* Process results */
first = TRUE;
qry->thread = g_malloc0( sizeof( pthread_t ) );
/* Setup thread */
- pthread_create( qry->thread, NULL,
- (void *) ldapqry_search, (void *) qry );
+ if (pthread_create( qry->thread, NULL,
+ (void *) ldapqry_search, (void *) qry ) != 0) {
+ g_free(qry->thread);
+ qry->thread = NULL;
+ ADDRQUERY_RETVAL(qry) = LDAPRC_SEARCH;
+ }
}
}
return ADDRQUERY_RETVAL(qry);
}
ADDRQUERY_RETVAL(qry) = LDAPRC_SEARCH;
if( rc != LDAP_SUCCESS ) {
- debug_print("LDAP Error: ldap_search_st: %s\n", ldaputil_get_error(ld));
+ log_error(LOG_PROTOCOL, _("LDAP error (search): %d (%s)\n"),
+ rc, ldaputil_get_error(ld));
+ debug_print("LDAP Error: ldap_search_ext_s: %d (%s)\n",
+ rc, ldaputil_get_error(ld));
return ADDRQUERY_RETVAL(qry);
+ } else {
+ log_message(LOG_PROTOCOL, _("LDAP (search): successful\n"));
}
+#ifdef G_OS_WIN32
+ debug_print("Total results are: %lu\n", ldap_count_entries(ld, result));
+#else
debug_print("Total results are: %d\n", ldap_count_entries(ld, result));
+#endif
/* Process results */
ADDRQUERY_RETVAL(qry) = LDAPRC_STOP_FLAG;