#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.
*/
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 (!ctl->enableSSL) {
- ld = ldap_init( ctl->hostName, ctl->port );
- } else {
- gchar *uri = g_strdup_printf("ldaps://%s:%d",
+
+ uri = g_strdup_printf("ldap%s://%s:%d",
+ ctl->enableSSL?"s":"",
ctl->hostName, ctl->port);
- ldap_initialize(&ld, uri);
- g_free(uri);
- }
+ ldap_initialize(&ld, uri);
+ g_free(uri);
+
if (ld == NULL)
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 );
return baseDN;
}
+int claws_ldap_simple_bind_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd )
+{
+ struct berval cred;
+
+ if ( passwd != NULL ) {
+ cred.bv_val = (char *) passwd;
+ cred.bv_len = strlen( passwd );
+ } else {
+ cred.bv_val = "";
+ cred.bv_len = 0;
+ }
+
+ return ldap_sasl_bind_s( ld, dn, LDAP_SASL_SIMPLE, &cred,
+ NULL, NULL, NULL );
+}
+
/**
* Attempt to discover the base DN for the server.
* \param host Host name.
GList *baseDN = NULL;
LDAP *ld = NULL;
gint rc;
+ gchar *uri = NULL;
#ifdef USE_LDAP_TLS
gint version;
#endif
/* Connect to server. */
- if (!ssl) {
- ld = ldap_init( host, port );
- } else {
- gchar *uri = g_strdup_printf("ldaps://%s:%d",
- host, port);
- rc = ldap_initialize(&ld, uri);
- g_free(uri);
- }
+ uri = g_strdup_printf("ldap%s://%s:%d",
+ ssl?"s":"",
+ host, port);
+ rc = ldap_initialize(&ld, uri);
+ g_free(uri);
+
if( ld == NULL ) {
return baseDN;
}
version = LDAP_VERSION3;
rc = ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
if( rc != LDAP_OPT_SUCCESS ) {
- ldap_unbind( ld );
+ ldap_unbind_ext( ld, NULL, NULL );
return baseDN;
}
rc = ldap_start_tls_s( ld, NULL, NULL );
if (rc != 0) {
- ldap_unbind( ld );
+ ldap_unbind_ext( ld, NULL, NULL );
return baseDN;
}
}
/* Bind to the server, if required */
if( bindDN ) {
if( *bindDN != '\0' ) {
- rc = ldap_simple_bind_s( ld, bindDN, bindPW );
+ rc = claws_ldap_simple_bind_s( ld, bindDN, bindPW );
if( rc != LDAP_SUCCESS ) {
- ldap_unbind( ld );
+ ldap_unbind_ext( ld, NULL, NULL );
return baseDN;
}
}
baseDN = ldaputil_test_v2( ld, tov );
}
if (ld && !LDAP_API_ERROR(rc))
- ldap_unbind( ld );
+ ldap_unbind_ext( ld, NULL, NULL );
return baseDN;
}
gint rc;
gint version;
#endif
+ gchar *uri = NULL;
+
if( host == NULL ) return retVal;
if( port < 1 ) return retVal;
- if (!ssl) {
- ld = ldap_open( host, port );
- } else {
- gchar *uri = g_strdup_printf("ldaps://%s:%d",
+
+ uri = g_strdup_printf("ldap%s://%s:%d",
+ ssl?"s":"",
host, port);
- ldap_initialize(&ld, uri);
- g_free(uri);
- }
+ ldap_initialize(&ld, uri);
+ g_free(uri);
if (ld == NULL)
return FALSE;
version = LDAP_VERSION3;
rc = ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
if( rc != LDAP_OPT_SUCCESS ) {
- ldap_unbind( ld );
+ ldap_unbind_ext( ld, NULL, NULL );
return FALSE;
}
rc = ldap_start_tls_s( ld, NULL, NULL );
if (rc != 0) {
- ldap_unbind( ld );
+ ldap_unbind_ext( ld, NULL, NULL );
return FALSE;
}
}
#endif
if( ld != NULL ) {
- ldap_unbind( ld );
+ ldap_unbind_ext( ld, NULL, NULL );
retVal = TRUE;
}
return retVal;
#ifdef USE_LDAP
#include <glib.h>
-
+#include <ldap.h>
/* Function Prototypes */
GList *ldaputil_read_basedn ( const gchar *host, const gint port,
const gchar *bindDN, const gchar *bindPW,
const gint tov, int ssl, int tls );
gboolean ldaputil_test_connect ( const gchar *host, const gint port, int ssl, int tls);
gboolean ldaputil_test_ldap_lib ( void );
+int claws_ldap_simple_bind_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd );
#endif /* USE_LDAP */