2010-12-17 [colin] 3.7.8cvs8
authorColin Leroy <colin@colino.net>
Fri, 17 Dec 2010 17:50:58 +0000 (17:50 +0000)
committerColin Leroy <colin@colino.net>
Fri, 17 Dec 2010 17:50:58 +0000 (17:50 +0000)
* configure.ac
* src/editldap.c
* src/ldapquery.c
* src/ldapserver.c
* src/ldapupdate.c
* src/ldaputil.c
* src/ldaputil.h
Better error logging. Disable LDAP SSL/TLS on
Windows, it's crashy/non-worky.

ChangeLog
PATCHSETS
configure.ac
src/editldap.c
src/ldapquery.c
src/ldapserver.c
src/ldapupdate.c
src/ldaputil.c
src/ldaputil.h

index 8199a2a..f9dad10 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-12-17 [colin]     3.7.8cvs8
+
+       * configure.ac
+       * src/editldap.c
+       * src/ldapquery.c
+       * src/ldapserver.c
+       * src/ldapupdate.c
+       * src/ldaputil.c
+       * src/ldaputil.h
+               Better error logging. Disable LDAP SSL/TLS on
+               Windows, it's crashy/non-worky.
+
 2010-12-17 [colin]     3.7.8cvs7
 
        * src/folder.c
index 186007b..450f369 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.28.2.44 -r 1.28.2.45 src/addrindex.c;  cvs diff -u -r 1.8.2.37 -r 1.8.2.38 src/editldap.c;  cvs diff -u -r 1.2.2.21 -r 1.2.2.22 src/ldapctrl.c;  cvs diff -u -r 1.3.2.34 -r 1.3.2.35 src/ldapquery.c;  cvs diff -u -r 1.4.2.18 -r 1.4.2.19 src/ldapserver.c;  cvs diff -u -r 1.2.2.11 -r 1.2.2.12 src/ldapserver.h;  cvs diff -u -r 1.1.2.24 -r 1.1.2.25 src/ldapupdate.c;  cvs diff -u -r 1.1.4.16 -r 1.1.4.17 src/ldaputil.c;  ) > 3.7.8cvs5.patchset
 ( cvs diff -u -r 1.9.2.30 -r 1.9.2.31 src/addressadd.c;  cvs diff -u -r 1.60.2.138 -r 1.60.2.139 src/addressbook.c;  cvs diff -u -r 1.28.2.45 -r 1.28.2.46 src/addrindex.c;  cvs diff -u -r 1.3.2.35 -r 1.3.2.36 src/ldapquery.c;  cvs diff -u -r 1.4.2.13 -r 1.4.2.14 src/ldapquery.h;  cvs diff -u -r 1.4.2.19 -r 1.4.2.20 src/ldapserver.c;  cvs diff -u -r 1.2.2.12 -r 1.2.2.13 src/ldapserver.h;  cvs diff -u -r 1.1.2.25 -r 1.1.2.26 src/ldapupdate.c;  cvs diff -u -r 1.1.4.17 -r 1.1.4.18 src/ldaputil.c;  cvs diff -u -r 1.1.4.9 -r 1.1.4.10 src/ldaputil.h;  ) > 3.7.8cvs6.patchset
 ( cvs diff -u -r 1.213.2.197 -r 1.213.2.198 src/folder.c;  ) > 3.7.8cvs7.patchset
+( cvs diff -u -r 1.654.2.4156 -r 1.654.2.4157 configure.ac;  cvs diff -u -r 1.8.2.38 -r 1.8.2.39 src/editldap.c;  cvs diff -u -r 1.3.2.36 -r 1.3.2.37 src/ldapquery.c;  cvs diff -u -r 1.4.2.20 -r 1.4.2.21 src/ldapserver.c;  cvs diff -u -r 1.1.2.26 -r 1.1.2.27 src/ldapupdate.c;  cvs diff -u -r 1.1.4.18 -r 1.1.4.19 src/ldaputil.c;  cvs diff -u -r 1.1.4.10 -r 1.1.4.11 src/ldaputil.h;  ) > 3.7.8cvs8.patchset
index 036f0ef..99195c4 100644 (file)
@@ -12,7 +12,7 @@ MINOR_VERSION=7
 MICRO_VERSION=8
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=7
+EXTRA_VERSION=8
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
@@ -669,7 +669,6 @@ elif test x"$ac_cv_enable_ldap" = xyes -a x"$ac_cv_enable_pthread" = xno; then
 elif test x"$platform_win32" = xyes; then
        AC_MSG_RESULT(yes)
        AC_DEFINE(USE_LDAP, 1, Define if you want LDAP support in addressbook.)
-       AC_DEFINE(USE_LDAP_TLS, 1, Define if you want LDAP TLS support in addressbook.)
        LDAP_LIBS="-lwldap32"
        AC_SUBST(LDAP_LIBS)
 else
index ff061ee..01fcbdf 100644 (file)
@@ -243,7 +243,7 @@ static void edit_ldap_server_check( void ) {
                debug_print("ldap server: %s\nport: %d\nssl: %d\ntls: %d\nbindDN: %s\n", sHost, iPort, ssl, tls, sBind);
                if( ldaputil_test_connect( sHost, iPort, ssl, tls, iTime ) ) {
                        /* Attempt to read base DN */
-                       baseDN = ldaputil_read_basedn( sHost, iPort, sBind, sPass, iTime, ssl, tls );
+                       baseDN = ldaputil_read_basedn(sHost, iPort, sBind, sPass, iTime, ssl, tls);
                        if( baseDN ) {
                                GList *node = baseDN;
                                while( node ) {
index 2af3efe..aa76330 100644 (file)
@@ -794,7 +794,7 @@ static gint ldapqry_search_retrieve( LdapQuery *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;
@@ -816,7 +816,7 @@ static gint ldapqry_search_retrieve( LdapQuery *qry ) {
        }
        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;
@@ -1209,7 +1209,7 @@ static gint ldapqry_locate_retrieve( LdapQuery *qry ) {
        }
        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);
        }
 
index 670cbab..66eb975 100644 (file)
@@ -724,13 +724,10 @@ void ldapsrv_set_options (gint secs, LDAP *ld)
 #ifdef G_OS_UNIX
        i = LDAP_OPT_X_TLS_ALLOW;
        rc = ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, &i);
-       debug_print("cert %s\n", ldap_err2string(rc));
+       debug_print("cert %s\n", ldaputil_get_error(ld));
        /* can crash old libldaps... */
        rc = ldap_set_option(NULL, LDAP_OPT_NETWORK_TIMEOUT, &timeout);
-       debug_print("tm %s\n", ldap_err2string(rc));
-#else
-       rc = ldap_set_option(NULL, LDAP_OPT_TIMELIMIT, &secs);
-       debug_print("tm %s\n", ldap_err2string(rc));
+       debug_print("tm %s\n", ldaputil_get_error(ld));
 #endif
 }
 
@@ -756,6 +753,14 @@ LDAP *ldapsvr_connect(LdapControl *ctl) {
        ldap_initialize(&ld, uri);
 #else
        ld = ldap_sslinit(ctl->hostName, ctl->port, ctl->enableSSL);
+       if (ctl->enableSSL) {
+               ldap_get_option(ld,LDAP_OPT_SSL,(void*)&rc);
+               if ((void *)rc != LDAP_OPT_ON) {
+                       debug_print("Enabling SSL\n");
+                       if (ldap_set_option(ld,LDAP_OPT_SSL,LDAP_OPT_ON) != 0)
+                               debug_print("Failed: %s\n", ldaputil_get_error(ld));
+               }
+       }
 #endif
        g_free(uri);
 
@@ -763,23 +768,24 @@ LDAP *ldapsvr_connect(LdapControl *ctl) {
                return NULL;
 
 
-       debug_print("connected to LDAP host %s on port %d\n", ctl->hostName, ctl->port);
+       debug_print("Got handle to LDAP host %s on port %d\n", ctl->hostName, 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;
-       }
-
+       } else
+               g_printerr("LDAP: Error %d (%s)\n",
+                       rc, ldaputil_get_error(ld));
+#ifdef USE_LDAP_TLS
+       /* Handle TLS */
        if (ctl->version == LDAP_VERSION3) {
                if (ctl->enableTLS && !ctl->enableSSL) {
                        rc = ldap_start_tls_s(ld, NULL, NULL);
                        
                        if (rc != LDAP_SUCCESS) {
                                g_printerr("LDAP Error(tls): ldap_simple_bind_s: %s\n",
-                                       ldap_err2string(rc));
+                                       ldaputil_get_error(ld));
                                return NULL;
                        }
                }
@@ -794,7 +800,7 @@ LDAP *ldapsvr_connect(LdapControl *ctl) {
                        if (rc != LDAP_SUCCESS) {
                                g_printerr("bindDN: %s, bindPass xxx\n", ctl->bindDN);
                                g_printerr("LDAP Error(bind): ldap_simple_bind_s: %s\n",
-                                       ldap_err2string(rc));
+                                       ldaputil_get_error(ld));
                                g_free(pwd);
                                return NULL;
                        }
index 5d42fb0..85d06d5 100644 (file)
@@ -663,7 +663,7 @@ void ldapsvr_compare_attr(LDAP *ld, gchar *dn, gint cnt, LDAPMod *mods[]) {
 #endif
 
                g_printerr("ldap_compare for (%s:%s)\" failed[0x%x]: %s\n",
-               mods[i]->mod_type, value, rc, ldap_err2string(rc));
+               mods[i]->mod_type, value, rc, ldaputil_get_error(ld));
                g_free(value);
        }
 }
@@ -701,7 +701,7 @@ int ldapsvr_compare_manual_attr(LDAP *ld, LdapServer *server, gchar *dn, char *a
                rc = ldap_search_ext_s(ld, ctl->baseDN, LDAP_SCOPE_ONELEVEL, filter, NULL, 0, NULL, NULL, NULL, 0, &res);
 
                if (rc) {
-                       g_printerr("ldap_search for attr=%s\" failed[0x%x]: %s\n",attr, rc, ldap_err2string(rc));
+                       g_printerr("ldap_search for attr=%s\" failed[0x%x]: %s\n",attr, rc, ldaputil_get_error(ld));
                        retVal = -2;
                }
                else {
@@ -796,7 +796,7 @@ int ldapsvr_deside_operation(LDAP *ld, LdapServer *server, char *dn, char *attr,
 #endif
 
        debug_print("ldap_compare for (%s:%s)\" error_code[0x%x]: %s\n",
-               attr, value, rc, ldap_err2string(rc));
+               attr, value, rc, ldaputil_get_error(ld));
        switch (rc) {
                case LDAP_COMPARE_FALSE: 
                        if (dummy)
@@ -938,7 +938,7 @@ void ldapsvr_handle_other_attributes(LDAP *ld, LdapServer *server, char *dn, GHa
                                server->retVal = LDAPRC_ALREADY_EXIST;
                                break;
                        default:
-                               g_printerr("ldap_modify for dn=%s\" failed[0x%x]: %s\n", dn, rc, ldap_err2string(rc));
+                               g_printerr("ldap_modify for dn=%s\" failed[0x%x]: %s\n", dn, rc, ldaputil_get_error(ld));
                                if (rc == 0x8)
                                        server->retVal = LDAPRC_STRONG_AUTH;
                                else
@@ -1081,7 +1081,7 @@ void ldapsvr_add_contact(LdapServer *server, GHashTable *contact) {
                                break;
                        default:
                                g_printerr("ldap_modify for dn=%s\" failed[0x%x]: %s\n",
-                                               base_dn, rc, ldap_err2string(rc));
+                                               base_dn, rc, ldaputil_get_error(ld));
                                if (rc == 0x8)
                                        server->retVal = LDAPRC_STRONG_AUTH;
                                else
@@ -1154,7 +1154,7 @@ void ldapsvr_update_contact(LdapServer *server, GHashTable *contact) {
                        else {
                                g_printerr("Current dn: %s\n", dn);
                                g_printerr("new dn: %s\n", newRdn);
-                               g_printerr("LDAP Error(ldap_modrdn2_s) failed[0x%x]: %s\n", rc, ldap_err2string(rc));
+                               g_printerr("LDAP Error(ldap_modrdn2_s) failed[0x%x]: %s\n", rc, ldaputil_get_error(ld));
                                g_free(newRdn);
                                clean_up(ld, server, contact);
                                return;
@@ -1310,7 +1310,7 @@ void ldapsvr_update_contact(LdapServer *server, GHashTable *contact) {
                rc = ldap_modify_ext_s(ld, dn, mods, NULL, NULL);
                if (rc) {
                        g_printerr("ldap_modify for dn=%s\" failed[0x%x]: %s\n",
-                    dn, rc, ldap_err2string(rc));
+                    dn, rc, ldaputil_get_error(ld));
                        server->retVal = LDAPRC_NAMING_VIOLATION;
                }
                if (mail)
@@ -1351,7 +1351,7 @@ void ldapsvr_delete_contact(LdapServer *server, GHashTable *contact) {
        rc = ldap_delete_ext_s(ld, dn, NULL, NULL);
        if (rc) {
                g_printerr("ldap_modify for dn=%s\" failed[0x%x]: %s\n",
-                               dn, rc, ldap_err2string(rc));
+                               dn, rc, ldaputil_get_error(ld));
                server->retVal = LDAPRC_NODN;
        }
        clean_up(ld, server, contact);
index 9c74f07..ccaff9f 100644 (file)
@@ -28,6 +28,7 @@
 #ifdef USE_LDAP
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <string.h>
 #include <sys/time.h>
 #include <errno.h>
@@ -105,7 +106,9 @@ static GList *ldaputil_test_v3( LDAP *ld, gint tov, gint *errcode ) {
                        }
                        ber = NULL;
                }
-       } 
+       } else
+               debug_print("LDAP: Error %d (%s)\n", rc, ldaputil_get_error(ld));
+       
        if (errcode)
                *errcode = rc;
        if (result)
@@ -310,6 +313,20 @@ gboolean ldaputil_test_ldap_lib( void ) {
        return TRUE;
 }
 
+const gchar *ldaputil_get_error(LDAP *ld)
+{
+       gchar *ld_error;
+       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));
+       ldap_memfree(ld_error);
+
+       return error;
+}
 #endif /* USE_LDAP */
 
 /*
index db6ed99..ca35054 100644 (file)
@@ -45,6 +45,7 @@ GList *ldaputil_read_basedn   ( const gchar *host, const gint port,
 gboolean ldaputil_test_connect ( const gchar *host, const gint port, int ssl, int tls, int secs);
 gboolean ldaputil_test_ldap_lib        ( void );
 int claws_ldap_simple_bind_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd );
+const gchar *ldaputil_get_error(LDAP *ld);
 
 #endif /* USE_LDAP */