]> git.sur5r.net Git - openldap/commitdiff
import fix to ITS#4861
authorPierangelo Masarati <ando@openldap.org>
Thu, 8 Mar 2007 21:16:33 +0000 (21:16 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 8 Mar 2007 21:16:33 +0000 (21:16 +0000)
servers/slapd/back-ldap/bind.c
servers/slapd/back-ldap/search.c
servers/slapd/back-meta/bind.c
servers/slapd/back-meta/search.c

index c9d8ecbadbd9791955bbfa99cf748d47012b6cbc..70895b5033554d6f03c82fb0a78e696be5255893 100644 (file)
@@ -1613,18 +1613,46 @@ retry:;
                        if ( rc != LDAP_SUCCESS ) {
                                rs->sr_err = rc;
                        }
-                       if ( refs != NULL ) {
-                               int     i;
-
-                               for ( i = 0; refs[ i ] != NULL; i++ )
-                                       /* count */ ;
-                               rs->sr_ref = op->o_tmpalloc( sizeof( struct berval ) * ( i + 1 ),
-                                       op->o_tmpmemctx );
-                               for ( i = 0; refs[ i ] != NULL; i++ ) {
-                                       ber_str2bv( refs[ i ], 0, 0, &rs->sr_ref[ i ] );
+
+                       /* RFC 4511: referrals can only appear
+                        * if result code is LDAP_REFERRAL */
+                       if ( refs != NULL
+                               && refs[ 0 ] != NULL
+                               && refs[ 0 ][ 0 ] != '\0' )
+                       {
+                               if ( rs->sr_err != LDAP_REFERRAL ) {
+                                       Debug( LDAP_DEBUG_ANY,
+                                               "%s ldap_back_op_result: "
+                                               "got referrals with err=%d\n",
+                                               op->o_log_prefix,
+                                               rs->sr_err, 0 );
+
+                               } else {
+                                       int     i;
+
+                                       for ( i = 0; refs[ i ] != NULL; i++ )
+                                               /* count */ ;
+                                       rs->sr_ref = op->o_tmpalloc( sizeof( struct berval ) * ( i + 1 ),
+                                               op->o_tmpmemctx );
+                                       for ( i = 0; refs[ i ] != NULL; i++ ) {
+                                               ber_str2bv( refs[ i ], 0, 0, &rs->sr_ref[ i ] );
+                                       }
+                                       BER_BVZERO( &rs->sr_ref[ i ] );
                                }
-                               BER_BVZERO( &rs->sr_ref[ i ] );
+
+                       } else if ( rs->sr_err == LDAP_REFERRAL ) {
+                               Debug( LDAP_DEBUG_ANY,
+                                       "%s ldap_back_op_result: "
+                                       "got err=%d with null "
+                                       "or empty referrals\n",
+                                       op->o_log_prefix,
+                                       rs->sr_err, 0 );
+
+                               rs->sr_err = LDAP_NO_SUCH_OBJECT;
                        }
+
+                       ber_memvfree( (void **)refs );
+
                        if ( ctrls != NULL ) {
                                rs->sr_ctrls = ctrls;
                        }
@@ -1679,8 +1707,6 @@ retry:;
        rs->sr_text = NULL;
 
        if ( rs->sr_ref ) {
-               assert( refs != NULL );
-               ber_memvfree( (void **)refs );
                op->o_tmpfree( rs->sr_ref, op->o_tmpmemctx );
                rs->sr_ref = NULL;
        }
index 3c7c9a342153d97e7bed4244f2aa6095aa327017..f30fdc5ae10a71356ff5e97191b1c01bb4be4979 100644 (file)
@@ -420,32 +420,48 @@ retry:
                                freetext = 1;
                        }
 
-                       if ( references && references[ 0 ] && references[ 0 ][ 0 ] ) {
-                               int     cnt;
-
+                       /* RFC 4511: referrals can only appear
+                        * if result code is LDAP_REFERRAL */
+                       if ( references 
+                               && references[ 0 ]
+                               && references[ 0 ][ 0 ] )
+                       {
                                if ( rs->sr_err != LDAP_REFERRAL ) {
-                                       /* FIXME: error */
                                        Debug( LDAP_DEBUG_ANY,
                                                "%s ldap_back_search: "
-                                               "got referrals with %d\n",
+                                               "got referrals with err=%d\n",
                                                op->o_log_prefix,
                                                rs->sr_err, 0 );
-                                       rs->sr_err = LDAP_REFERRAL;
-                               }
 
-                               for ( cnt = 0; references[ cnt ]; cnt++ )
-                                       /* NO OP */ ;
+                               } else {
+                                       int     cnt;
+
+                                       for ( cnt = 0; references[ cnt ]; cnt++ )
+                                               /* NO OP */ ;
                                
-                               rs->sr_ref = op->o_tmpalloc( ( cnt + 1 ) * sizeof( struct berval ),
-                                       op->o_tmpmemctx );
+                                       rs->sr_ref = op->o_tmpalloc( ( cnt + 1 ) * sizeof( struct berval ),
+                                               op->o_tmpmemctx );
 
-                               for ( cnt = 0; references[ cnt ]; cnt++ ) {
-                                       /* duplicating ...*/
-                                       ber_str2bv( references[ cnt ], 0, 1, &rs->sr_ref[ cnt ] );
+                                       for ( cnt = 0; references[ cnt ]; cnt++ ) {
+                                               /* duplicating ...*/
+                                               ber_str2bv( references[ cnt ], 0, 1, &rs->sr_ref[ cnt ] );
+                                       }
+                                       BER_BVZERO( &rs->sr_ref[ cnt ] );
                                }
-                               BER_BVZERO( &rs->sr_ref[ cnt ] );
+
+                       } else if ( rs->sr_err == LDAP_REFERRAL ) {
+                               Debug( LDAP_DEBUG_ANY,
+                                       "%s ldap_back_search: "
+                                       "got err=%d with null "
+                                       "or empty referrals\n",
+                                       op->o_log_prefix,
+                                       rs->sr_err, 0 );
+
+                               rs->sr_err = LDAP_NO_SUCH_OBJECT;
                        }
 
+                       ber_memvfree( (void **)references );
+
                        if ( match.bv_val != NULL ) {
 #ifndef LDAP_NULL_IS_NULL
                                if ( match.bv_val[ 0 ] == '\0' ) {
@@ -464,11 +480,6 @@ retry:
                        }
 #endif /* LDAP_NULL_IS_NULL */
 
-                       /* cleanup */
-                       if ( references ) {
-                               ber_memvfree( (void **)references );
-                       }
-
                        rc = 0;
                        break;
                }
index f5cb6206a21c96336db255d46989b3b20b84d607..e9772150d8825b5d70df16353eed062a8f3e9145 100644 (file)
@@ -965,18 +965,46 @@ retry:;
                                if ( rc != LDAP_SUCCESS ) {
                                        rs->sr_err = rc;
                                }
-                               if ( refs != NULL ) {
-                                       int     i;
+
+                               /* RFC 4511: referrals can only appear
+                                * if result code is LDAP_REFERRAL */
+                               if ( refs != NULL
+                                       && refs[ 0 ] != NULL
+                                       && refs[ 0 ][ 0 ] != '\0' )
+                               {
+                                       if ( rs->sr_err != LDAP_REFERRAL ) {
+                                               Debug( LDAP_DEBUG_ANY,
+                                                       "%s meta_back_op_result[%d]: "
+                                                       "got referrals with err=%d\n",
+                                                       op->o_log_prefix,
+                                                       candidate, rs->sr_err );
+
+                                       } else {
+                                               int     i;
        
-                                       for ( i = 0; refs[ i ] != NULL; i++ )
-                                               /* count */ ;
-                                       rs->sr_ref = op->o_tmpalloc( sizeof( struct berval ) * ( i + 1 ),
-                                               op->o_tmpmemctx );
-                                       for ( i = 0; refs[ i ] != NULL; i++ ) {
-                                               ber_str2bv( refs[ i ], 0, 0, &rs->sr_ref[ i ] );
+                                               for ( i = 0; refs[ i ] != NULL; i++ )
+                                                       /* count */ ;
+                                               rs->sr_ref = op->o_tmpalloc( sizeof( struct berval ) * ( i + 1 ),
+                                                       op->o_tmpmemctx );
+                                               for ( i = 0; refs[ i ] != NULL; i++ ) {
+                                                       ber_str2bv( refs[ i ], 0, 0, &rs->sr_ref[ i ] );
+                                               }
+                                               BER_BVZERO( &rs->sr_ref[ i ] );
                                        }
-                                       BER_BVZERO( &rs->sr_ref[ i ] );
+
+                               } else if ( rs->sr_err == LDAP_REFERRAL ) {
+                                       Debug( LDAP_DEBUG_ANY,
+                                               "%s meta_back_op_result[%d]: "
+                                               "got err=%d with null "
+                                               "or empty referrals\n",
+                                               op->o_log_prefix,
+                                               candidate, rs->sr_err );
+
+                                       rs->sr_err = LDAP_NO_SUCH_OBJECT;
                                }
+
+                               ber_memvfree( (void **)refs );
+
                                if ( ctrls != NULL ) {
                                        rs->sr_ctrls = ctrls;
                                }
index 86efcbeea7e6613dcca87b055b52b19c54d5bc32..5d6c7ea471d6bd2ee82317ffc2ad0fe7384d8528 100644 (file)
@@ -853,7 +853,6 @@ getconn:;
                int     gotit = 0,
                        doabandon = 0,
                        alreadybound = ncandidates;
-               time_t  curr_time = 0;
 
                /* check timeout */
                if ( timeout && lastres_time > 0
@@ -1220,16 +1219,15 @@ really_bad:;
                                                NULL /* &candidates[ i ].sr_ctrls (unused) */ ,
                                                0 );
                                        if ( rs->sr_err != LDAP_SUCCESS ) {
-                                               ldap_get_option( msc->msc_ld,
-                                                       LDAP_OPT_ERROR_NUMBER,
-                                                       &rs->sr_err );
-                                               sres = slap_map_api2result( rs );
+                                               sres = slap_map_api2result( &candidates[ i ] );
                                                candidates[ i ].sr_type = REP_RESULT;
                                                ldap_msgfree( res );
                                                res = NULL;
                                                goto really_bad;
                                        }
 
+                                       rs->sr_err = candidates[ i ].sr_err;
+
                                        /* massage matchedDN if need be */
                                        if ( candidates[ i ].sr_matched != NULL ) {
                                                struct berval   match, mmatch;
@@ -1255,37 +1253,60 @@ really_bad:;
                                        }
 
                                        /* add references to array */
-                                       if ( references ) {
-                                               BerVarray       sr_ref;
-                                               int             cnt;
+                                       /* RFC 4511: referrals can only appear
+                                        * if result code is LDAP_REFERRAL */
+                                       if ( references != NULL
+                                               && references[ 0 ] != NULL
+                                               && references[ 0 ][ 0 ] != '\0' )
+                                       {
+                                               if ( rs->sr_err != LDAP_REFERRAL ) {
+                                                       Debug( LDAP_DEBUG_ANY,
+                                                               "%s meta_back_search[%ld]: "
+                                                               "got referrals with err=%d\n",
+                                                               op->o_log_prefix,
+                                                               i, rs->sr_err );
+
+                                               } else {
+                                                       BerVarray       sr_ref;
+                                                       int             cnt;
        
-                                               for ( cnt = 0; references[ cnt ]; cnt++ )
-                                                       ;
+                                                       for ( cnt = 0; references[ cnt ]; cnt++ )
+                                                               ;
        
-                                               sr_ref = ch_calloc( sizeof( struct berval ), cnt + 1 );
+                                                       sr_ref = ch_calloc( sizeof( struct berval ), cnt + 1 );
        
-                                               for ( cnt = 0; references[ cnt ]; cnt++ ) {
-                                                       ber_str2bv( references[ cnt ], 0, 1, &sr_ref[ cnt ] );
-                                               }
-                                               BER_BVZERO( &sr_ref[ cnt ] );
+                                                       for ( cnt = 0; references[ cnt ]; cnt++ ) {
+                                                               ber_str2bv( references[ cnt ], 0, 1, &sr_ref[ cnt ] );
+                                                       }
+                                                       BER_BVZERO( &sr_ref[ cnt ] );
        
-                                               ( void )ldap_back_referral_result_rewrite( &dc, sr_ref );
+                                                       ( void )ldap_back_referral_result_rewrite( &dc, sr_ref );
                                        
-                                               /* cleanup */
-                                               ber_memvfree( (void **)references );
-       
-                                               if ( rs->sr_v2ref == NULL ) {
-                                                       rs->sr_v2ref = sr_ref;
+                                                       if ( rs->sr_v2ref == NULL ) {
+                                                               rs->sr_v2ref = sr_ref;
 
-                                               } else {
-                                                       for ( cnt = 0; !BER_BVISNULL( &sr_ref[ cnt ] ); cnt++ ) {
-                                                               ber_bvarray_add( &rs->sr_v2ref, &sr_ref[ cnt ] );
+                                                       } else {
+                                                               for ( cnt = 0; !BER_BVISNULL( &sr_ref[ cnt ] ); cnt++ ) {
+                                                                       ber_bvarray_add( &rs->sr_v2ref, &sr_ref[ cnt ] );
+                                                               }
+                                                               ber_memfree( sr_ref );
                                                        }
-                                                       ber_memfree( sr_ref );
                                                }
+
+                                       } else if ( rs->sr_err == LDAP_REFERRAL ) {
+                                               Debug( LDAP_DEBUG_ANY,
+                                                       "%s meta_back_search[%ld]: "
+                                                       "got err=%d with null "
+                                                       "or empty referrals\n",
+                                                       op->o_log_prefix,
+                                                       i, rs->sr_err );
+
+                                               rs->sr_err = LDAP_NO_SUCH_OBJECT;
                                        }
+
+                                       /* cleanup */
+                                       ber_memvfree( (void **)references );
        
-                                       rs->sr_err = candidates[ i ].sr_err;
                                        sres = slap_map_api2result( rs );
        
                                        if ( StatslogTest( LDAP_DEBUG_TRACE | LDAP_DEBUG_ANY ) ) {