Sucesfuly fix typos in LDAP log prints.
[claws.git] / src / ldaputil.c
index 3385d22ec5238af6c2734cf049ccb1f60cac1fb4..13070dd5e2a24b59e59d088c6a9de2c89238a0d8 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * 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-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
@@ -14,7 +14,6 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * 
  */
 
 /*
@@ -23,6 +22,7 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #ifdef USE_LDAP
@@ -36,6 +36,7 @@
 #include "ldaputil.h"
 #include "ldapserver.h"
 #include "ldapctrl.h"
+#include "log.h"
 
 #define SYLDAP_TEST_FILTER   "(objectclass=*)"
 #define SYLDAP_SEARCHBASE_V2 "cn=config"
@@ -77,6 +78,7 @@ static GList *ldaputil_test_v3( LDAP *ld, gint tov, gint *errcode ) {
                attribs, 0, NULL, NULL, &timeout, 0, &result );
 
        if( rc == LDAP_SUCCESS ) {
+               log_print(LOG_PROTOCOL, _("LDAP (search): successful\n"));
                /* Process entries */
                for( e = ldap_first_entry( ld, result );
                     e != NULL;
@@ -106,8 +108,11 @@ static GList *ldaputil_test_v3( LDAP *ld, gint tov, gint *errcode ) {
                        }
                        ber = NULL;
                }
-       } else
+       } else {
+               log_error(LOG_PROTOCOL, _("LDAP error (search): %d (%s)\n"),
+                               rc, ldaputil_get_error(ld));
                debug_print("LDAP: Error %d (%s)\n", rc, ldaputil_get_error(ld));
+       }
        
        if (errcode)
                *errcode = rc;
@@ -148,6 +153,7 @@ static GList *ldaputil_test_v2( LDAP *ld, gint tov ) {
                attribs, 0, NULL, NULL, &timeout, 0, &result );
 
        if( rc == LDAP_SUCCESS ) {
+               log_print(LOG_PROTOCOL, _("LDAP (search): successful\n"));
                /* Process entries */
                for( e = ldap_first_entry( ld, result );
                     e != NULL;
@@ -173,8 +179,7 @@ static GList *ldaputil_test_v2( LDAP *ld, gint tov ) {
                                                        ch = ( char * ) strchr( tmp, ':' );
                                                        if( ch ) {
                                                                gchar *bn = g_strdup( ++ch );
-                                                               g_strchomp( bn );
-                                                               g_strchug( bn );
+                                                               g_strstrip( bn );
                                                                baseDN = g_list_append(
                                                                        baseDN, g_strdup( bn ) );
                                                                g_free( bn );
@@ -191,6 +196,10 @@ static GList *ldaputil_test_v2( LDAP *ld, gint tov ) {
                        }
                        ber = NULL;
                }
+       } else {
+               log_error(LOG_PROTOCOL, _("LDAP error (search): %d (%s)\n"),
+                               rc, ldaputil_get_error(ld));
+               debug_print("LDAP: Error %d (%s)\n", rc, ldaputil_get_error(ld));
        }
        if (result)
                ldap_msgfree( result );
@@ -199,6 +208,8 @@ static GList *ldaputil_test_v2( LDAP *ld, gint tov ) {
 
 int claws_ldap_simple_bind_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd )
 {
+       debug_print("binding: DN->%s\n", dn?dn:"null");
+#ifdef G_OS_UNIX
        struct berval cred;
 
        if ( passwd != NULL ) {
@@ -209,12 +220,10 @@ int claws_ldap_simple_bind_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *pa
                cred.bv_len = 0;
        }
 
-       debug_print("binding: DN->%s\n", dn?dn:"null");
-#ifdef G_OS_UNIX
        return ldap_sasl_bind_s( ld, dn, LDAP_SASL_SIMPLE, &cred,
                NULL, NULL, NULL );
 #else
-       return ldap_simple_bind_s(ld, dn, passwd);
+       return ldap_simple_bind_s(ld, (PCHAR)dn, (PCHAR)passwd);
 #endif
 }
 
@@ -248,7 +257,6 @@ GList *ldaputil_read_basedn(
        ldapctl_set_host(ctl, host);
        ldapctl_set_timeout(ctl, tov);
        ldapctl_set_bind_dn(ctl, bindDN);
-       ldapctl_set_bind_password(ctl, bindPW, FALSE, FALSE);
 
        ld = ldapsvr_connect(ctl);
        if (ld == NULL) {
@@ -323,7 +331,14 @@ const gchar *ldaputil_get_error(LDAP *ld)
                strncpy2(error, ld_error, sizeof(error));
        else
                strncpy2(error, _("Unknown error"), sizeof(error));
+#ifndef G_OS_WIN32
+       /* From https://msdn.microsoft.com/en-us/library/aa366594%28v=vs.85%29.aspx
+        * "LDAP_OPT_ERROR_STRING returns a pointer to an internal static
+        * string table, and ldap_memfree should not be called when using
+        * this session option."
+        */
        ldap_memfree(ld_error);
+#endif
 
        return error;
 }