]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/sasl.c
Sync with 2.x
[openldap] / libraries / libldap / sasl.c
index a17ca56c9eda4b4e05778c1696a90d276aee583f..12cb3816638676ba485978f53ffef7c5731fa1a6 100644 (file)
@@ -37,7 +37,6 @@
 
 #include "ldap-int.h"
 
-
 /*
  * ldap_sasl_bind - bind to the ldap server (and X.500).
  * The dn (usually NULL), mechanism, and credentials are provided.
@@ -366,24 +365,25 @@ ldap_pvt_sasl_getmechs ( LDAP *ld, char **pmechlist )
                
        e = ldap_first_entry( ld, res );
        if ( e == NULL ) {
+               ldap_msgfree( res );
                if ( ld->ld_errno == LDAP_SUCCESS ) {
-                       ld->ld_errno = LDAP_UNAVAILABLE;
+                       ld->ld_errno = LDAP_NO_SUCH_OBJECT;
                }
                return ld->ld_errno;
        }
 
        values = ldap_get_values( ld, e, "supportedSASLMechanisms" );
        if ( values == NULL ) {
-               ld->ld_errno = LDAP_NO_SUCH_ATTRIBUTE;
                ldap_msgfree( res );
+               ld->ld_errno = LDAP_NO_SUCH_ATTRIBUTE;
                return ld->ld_errno;
        }
 
        mechlist = ldap_charray2str( values, " " );
        if ( mechlist == NULL ) {
-               ld->ld_errno = LDAP_NO_MEMORY;
                LDAP_VFREE( values );
                ldap_msgfree( res );
+               ld->ld_errno = LDAP_NO_MEMORY;
                return ld->ld_errno;
        } 
 
@@ -416,13 +416,17 @@ ldap_sasl_interactive_bind_s(
 {
        int rc;
 
+#if defined( LDAP_R_COMPILE ) && defined( HAVE_CYRUS_SASL )
+       ldap_pvt_thread_mutex_lock( &ldap_int_sasl_mutex );
+#endif
+
        if( mechs == NULL || *mechs == '\0' ) {
                char *smechs;
 
                rc = ldap_pvt_sasl_getmechs( ld, &smechs );
 
                if( rc != LDAP_SUCCESS ) {
-                       return rc;
+                       goto done;
                }
 
                Debug( LDAP_DEBUG_TRACE,
@@ -441,5 +445,10 @@ ldap_sasl_interactive_bind_s(
                serverControls, clientControls,
                flags, interact, defaults );
 
+done:
+#if defined( LDAP_R_COMPILE ) && defined( HAVE_CYRUS_SASL )
+       ldap_pvt_thread_mutex_unlock( &ldap_int_sasl_mutex );
+#endif
+
        return rc;
 }