/*
- * 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-2015 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 <sys/time.h>
#include <string.h>
-#include <lber.h>
#include "defs.h"
#include "ldaputil.h"
#include "ldapquery.h"
#include "ldapctrl.h"
+#include "ldapserver.h"
#include "mgutils.h"
#include "addritem.h"
}
}
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;
}
static gint ldapqry_connect( LdapQuery *qry ) {
LdapControl *ctl;
LDAP *ld = NULL;
- gint rc;
- gint version;
- gchar *uri = NULL;
/* Initialize connection */
if (debug_get_mode()) {
qry->elapsedTime = -1;
ADDRQUERY_RETVAL(qry) = LDAPRC_INIT;
- ldapsrv_set_options (ctl->timeOut, NULL);
-
- uri = g_strdup_printf("ldap%s://%s:%d",
- ctl->enableSSL?"s":"",
- ctl->hostName, ctl->port);
- ldap_initialize(&ld, uri);
- g_free(uri);
+ ld = ldapsvr_connect(ctl);
if (ld == NULL)
return ADDRQUERY_RETVAL(qry);
debug_print("connected to LDAP host %s on port %d\n",
ctl->hostName?ctl->hostName:"null", ctl->port);
-#ifdef USE_LDAP_TLS
- /* Handle TLS */
- version = LDAP_VERSION3;
- rc = ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
- if( rc == LDAP_OPT_SUCCESS ) {
- ctl->version = LDAP_VERSION3;
- }
-
- if( ctl->version == LDAP_VERSION3 ) {
- if( ctl->enableTLS && !ctl->enableSSL ) {
- ADDRQUERY_RETVAL(qry) = LDAPRC_TLS;
- rc = ldap_start_tls_s( ld, NULL, NULL );
-
- debug_print("rc=%d\n", rc);
- debug_print("LDAP Status: set_option: %s\n", ldap_err2string(rc));
-
- if( rc != LDAP_SUCCESS ) {
- return ADDRQUERY_RETVAL(qry);
- }
- }
- }
-#endif
-
- /* Bind to the server, if required */
- ADDRQUERY_RETVAL(qry) = LDAPRC_BIND;
- if( ctl->bindDN ) {
- if( * ctl->bindDN != '\0' ) {
- debug_print("binding...\n");
- rc = claws_ldap_simple_bind_s( ld, ctl->bindDN, ctl->bindPass );
- debug_print("rc=%d\n", rc);
- if( rc != LDAP_SUCCESS ) {
- debug_print("LDAP Error: ldap_simple_bind_s: %s\n", ldap_err2string(rc));
- return ADDRQUERY_RETVAL(qry);
- }
- }
- }
ADDRQUERY_RETVAL(qry) = LDAPRC_STOP_FLAG;
if( ldapqry_get_stop_flag( qry ) ) {
return ADDRQUERY_RETVAL(qry);
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", ldap_err2string(rc));
+ debug_print("LDAP Error: ldap_search_st: %s\n", ldaputil_get_error(ld));
ldapctl_free_attribute_array( attribs );
g_free( criteria );
criteria = NULL;
}
else {
debug_print("LDAP Error: ldap_search_st: %d\n", rc);
- debug_print("LDAP Error: ldap_search_st: %s\n", ldap_err2string(rc));
+ debug_print("LDAP Error: ldap_search_st: %s\n", 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;
listEMail = ldapqry_process_single_entry( cache, qry, ld, e );
/* Process callback */
- if( qry->callBackEntry ) {
+ if( qry->callBackEntry )
qry->callBackEntry( qry, ADDRQUERY_ID(qry), listEMail, qry->data );
- }
- else {
- /*if (debug_get_mode()) {
- GList *node = listEMail;
- while (node) {
- addritem_print_item_email(node->data, stdout);
- node = g_list_next(node);
- }
- }*/
+ else
g_list_free( listEMail );
- }
pthread_mutex_unlock( qry->mutexEntry );
}
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);
qry = ( LdapQuery * ) ptr;
cm_return_if_fail( qry != NULL );
- debug_print("ldapqry_destroyer::%d::%s\n", (int) pthread_self(),
- ADDRQUERY_NAME(qry)?ADDRQUERY_NAME(qry):"null");
-
/* Perform any destruction here */
if( qry->control != NULL ) {
ldapctl_free( qry->control );
void ldapqry_cancel( LdapQuery *qry ) {
cm_return_if_fail( qry != NULL );
- debug_print("cancelling::%d::%s\n", (int) pthread_self(),
- ADDRQUERY_NAME(qry)?ADDRQUERY_NAME(qry):"null");
if( ldapqry_get_busy_flag( qry ) ) {
if( qry->thread ) {
debug_print("calling pthread_cancel\n");
}
ADDRQUERY_RETVAL(qry) = LDAPRC_SEARCH;
if( rc != LDAP_SUCCESS ) {
- debug_print("LDAP Error: ldap_search_st: %s\n", ldap_err2string(rc));
+ debug_print("LDAP Error: ldap_search_st: %s\n", ldaputil_get_error(ld));
return ADDRQUERY_RETVAL(qry);
}
+#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;