/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2003-2004 Match Grun
+ * Copyright (C) 2003-2007 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
#include <string.h>
#include <lber.h>
+#include "ldaputil.h"
#include "ldapquery.h"
#include "ldapctrl.h"
#include "mgutils.h"
#include "addritem.h"
#include "addrcache.h"
-#include "ldapquery.h"
-
/*
* Key for thread specific data.
*/
{
GSList *list = NULL;
gint i;
- gchar **vals;
+ struct berval **vals;
- if( ( vals = ldap_get_values( ld, entry, attr ) ) != NULL ) {
+ if( ( vals = ldap_get_values_len( ld, entry, attr ) ) != NULL ) {
for( i = 0; vals[i] != NULL; i++ ) {
/* printf( "lv\t%s: %s\n", attr, vals[i] ); */
- list = g_slist_append( list, g_strdup( vals[i] ) );
+ list = g_slist_append( list, g_strndup( vals[i]->bv_val, vals[i]->bv_len) );
}
}
- ldap_value_free( vals );
+ ldap_value_free_len( vals );
return list;
}
*/
static GSList *ldapqry_add_single_value( LDAP *ld, LDAPMessage *entry, char *attr ) {
GSList *list = NULL;
- gchar **vals;
+ struct berval **vals;
- if( ( vals = ldap_get_values( ld, entry, attr ) ) != NULL ) {
+ if( ( vals = ldap_get_values_len( ld, entry, attr ) ) != NULL ) {
if( vals[0] != NULL ) {
/* printf( "sv\t%s: %s\n", attr, vals[0] ); */
- list = g_slist_append( list, g_strdup( vals[0] ) );
+ list = g_slist_append( list, g_strndup( vals[0]->bv_val, vals[0]->bv_len ));
}
}
- ldap_value_free( vals );
+ ldap_value_free_len( vals );
return list;
}
*/
static gint ldapqry_connect( LdapQuery *qry ) {
LdapControl *ctl;
- LDAP *ld;
+ LDAP *ld = NULL;
gint rc;
gint version;
+ gchar *uri = NULL;
/* Initialize connection */
/* printf( "===ldapqry_connect===\n" ); */
qry->startTime = qry->touchTime;
qry->elapsedTime = -1;
ADDRQUERY_RETVAL(qry) = LDAPRC_INIT;
- if( ( ld = ldap_init( ctl->hostName, ctl->port ) ) == NULL ) {
+
+ uri = g_strdup_printf("ldap%s://%s:%d",
+ ctl->enableSSL?"s":"",
+ ctl->hostName, ctl->port);
+ ldap_initialize(&ld, uri);
+ g_free(uri);
+
+ if (ld == NULL)
return ADDRQUERY_RETVAL(qry);
- }
+
qry->ldap = ld;
ADDRQUERY_RETVAL(qry) = LDAPRC_STOP_FLAG;
if( ldapqry_get_stop_flag( qry ) ) {
}
if( ctl->version == LDAP_VERSION3 ) {
- if( ctl->enableTLS ) {
+ if( ctl->enableTLS && !ctl->enableSSL ) {
ADDRQUERY_RETVAL(qry) = LDAPRC_TLS;
rc = ldap_start_tls_s( ld, NULL, NULL );
- /*
- printf( "rc=%d\n", rc );
- printf( "LDAP Status: set_option: %s\n", ldap_err2string( rc ) );
- */
+
+ /* printf( "rc=%d\n", rc );
+ printf( "LDAP Status: set_option: %s\n", ldap_err2string( rc ) ); */
+
if( rc != LDAP_SUCCESS ) {
return ADDRQUERY_RETVAL(qry);
}
if( ctl->bindDN ) {
if( * ctl->bindDN != '\0' ) {
/* printf( "binding...\n" ); */
- rc = ldap_simple_bind_s( ld, ctl->bindDN, ctl->bindPass );
+ rc = claws_ldap_simple_bind_s( ld, ctl->bindDN, ctl->bindPass );
/* printf( "rc=%d\n", rc ); */
if( rc != LDAP_SUCCESS ) {
/*
*/
static gint ldapqry_disconnect( LdapQuery *qry ) {
/* Disconnect */
- if( qry->ldap ) ldap_unbind( qry->ldap );
+ if( qry->ldap ) ldap_unbind_ext( qry->ldap, NULL, NULL );
qry->ldap = NULL;
ldapqry_touch( qry );
{
GList *list = NULL;
gint i;
- gchar **vals;
+ struct berval **vals;
NameValuePair *nvp;
list = listValues;
- if( ( vals = ldap_get_values( ld, entry, attr ) ) != NULL ) {
+ if( ( vals = ldap_get_values_len( ld, entry, attr ) ) != NULL ) {
for( i = 0; vals[i] != NULL; i++ ) {
- nvp = ldapqry_create_name_value( attr, vals[i] );
+ gchar *tmp = g_strndup( vals[i]->bv_val, vals[i]->bv_len);
+ nvp = ldapqry_create_name_value( attr, tmp );
+ g_free(tmp);
list = g_list_append( list, nvp );
}
}
- ldap_value_free( vals );
+ ldap_value_free_len( vals );
return list;
}