]> git.sur5r.net Git - openldap/commitdiff
ITS#2325 fix: properly freeing prompts->results
authorKurt Zeilenga <kurt@openldap.org>
Fri, 21 Feb 2003 18:39:26 +0000 (18:39 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Fri, 21 Feb 2003 18:39:26 +0000 (18:39 +0000)
libraries/libldap/cyrus.c
libraries/liblutil/sasl.c

index 3032f8c8dc70a7a36f3294ea63ff320b5a34f0c0..922f22c185211713fc8aa059071b170ea4a48628 100644 (file)
@@ -601,36 +601,20 @@ ldap_int_sasl_bind(
 
                if( saslrc == SASL_INTERACT ) {
                        int res;
-
-#if SASL_VERSION_MAJOR >= 2
-                       /* XXX the application should free interact results.
-                        * FIXME: this should happen only 
-                        * if saslrc == SASL_INTERACT
-                        *
-                        * I assume that prompts->result is not needed
-                        * by the subsequent call to (interact)() */
-                       if ( prompts != NULL && prompts->result != NULL ) {
-                               LDAP_FREE( (void *)prompts->result );
-                               prompts->result = NULL;
-                       }
-#endif
-
                        if( !interact ) break;
                        res = (interact)( ld, flags, defaults, prompts );
-                       if( res != LDAP_SUCCESS ) {
-                               break;
-                       }
+                       if( res != LDAP_SUCCESS ) break;
                }
        } while ( saslrc == SASL_INTERACT );
 
        ccred.bv_len = credlen;
 
        if ( (saslrc != SASL_OK) && (saslrc != SASL_CONTINUE) ) {
-               ld->ld_errno = sasl_err2ldap( saslrc );
+               rc = ld->ld_errno = sasl_err2ldap( saslrc );
 #if SASL_VERSION_MAJOR >= 2
                ld->ld_error = (char *)sasl_errdetail( ctx );
 #endif
-               return ld->ld_errno;
+               goto done;
        }
 
        do {
@@ -662,7 +646,8 @@ ldap_int_sasl_bind(
 #endif
                                ber_bvfree( scred );
                        }
-                       return ld->ld_errno;
+                       rc = ld->ld_errno;
+                       goto done;
                }
 
                if( rc == LDAP_SUCCESS && saslrc == SASL_OK ) {
@@ -679,7 +664,8 @@ ldap_int_sasl_bind(
                                        rc, saslrc, scred->bv_len );
 #endif
                                ber_bvfree( scred );
-                               return ld->ld_errno = LDAP_LOCAL_ERROR;
+                               rc = ld->ld_errno = LDAP_LOCAL_ERROR;
+                               goto done;
                        }
                        break;
                }
@@ -712,9 +698,7 @@ ldap_int_sasl_bind(
                                int res;
                                if( !interact ) break;
                                res = (interact)( ld, flags, defaults, prompts );
-                               if( res != LDAP_SUCCESS ) {
-                                       break;
-                               }
+                               if( res != LDAP_SUCCESS ) break;
                        }
                } while ( saslrc == SASL_INTERACT );
 
@@ -726,19 +710,19 @@ ldap_int_sasl_bind(
 #if SASL_VERSION_MAJOR >= 2
                        ld->ld_error = (char *)sasl_errdetail( ctx );
 #endif
-                       return ld->ld_errno;
+                       rc = ld->ld_errno;
+                       goto done;
                }
        } while ( rc == LDAP_SASL_BIND_IN_PROGRESS );
 
-       if ( rc != LDAP_SUCCESS ) {
-               return rc;
-       }
+       if ( rc != LDAP_SUCCESS ) goto done;
 
        if ( saslrc != SASL_OK ) {
 #if SASL_VERSION_MAJOR >= 2
                ld->ld_error = (char *)sasl_errdetail( ctx );
 #endif
-               return ld->ld_errno = sasl_err2ldap( saslrc );
+               rc = ld->ld_errno = sasl_err2ldap( saslrc );
+               goto done;
        }
 
        if( flags != LDAP_SASL_QUIET ) {
@@ -772,6 +756,12 @@ ldap_int_sasl_bind(
                }
        }
 
+done:
+       if( interact ) {
+               /* cleanup */
+               (void) (interact)( NULL, flags, defaults, prompts );
+       }
+
        return rc;
 }
 
index 6dd4df5c6fb62906a0a32022bb8e9642b6a04d55..0746cf6447e8605a794f41cdb908b1e477b56c07 100644 (file)
@@ -190,6 +190,16 @@ int lutil_sasl_interact(
 {
        sasl_interact_t *interact = in;
 
+       if( interact->result ) {
+               /* we have results from a previous interaction */
+               free( interact->result );
+               interact->result = NULL;
+       }
+
+       if( ld == NULL ) {
+               return LDAP_SUCCESS;
+       }
+
        if( flags == LDAP_SASL_INTERACTIVE ) {
                fputs( "SASL Interaction\n", stderr );
        }