]> git.sur5r.net Git - openldap/commitdiff
further cleanup of ldapsearch response
authorPierangelo Masarati <ando@OpenLDAP.org>
Mon, 22 Aug 2011 17:18:07 +0000 (11:18 -0600)
committerPierangelo Masarati <ando@OpenLDAP.org>
Mon, 22 Aug 2011 17:19:30 +0000 (11:19 -0600)
clients/tools/ldapsearch.c

index ff50e8fecc131e0011e5f756f5ff9d7c67c24022..068acb3e1b5e30485409e7ef5dffaef49fd518a9 100644 (file)
@@ -1376,7 +1376,7 @@ static int dosearch(
        int sizelimit )
 {
        char                    *filter;
-       int                     rc;
+       int                     rc, rc2 = LDAP_OTHER;
        int                     nresponses;
        int                     nentries;
        int                     nreferences;
@@ -1439,8 +1439,7 @@ static int dosearch(
        }
 
        if( rc != LDAP_SUCCESS ) {
-               fprintf( stderr, _("%s: ldap_search_ext: %s (%d)\n"),
-                       prog, ldap_err2string( rc ), rc );
+               tool_perror( "ldap_search_ext", rc, NULL, NULL, NULL, NULL );
                return( rc );
        }
 
@@ -1459,9 +1458,8 @@ static int dosearch(
                sortattr ? LDAP_MSG_ALL : LDAP_MSG_ONE,
                tvp, &res )) > 0 )
        {
-               rc = tool_check_abandon( ld, msgid );
-               if ( rc ) {
-                       return rc;
+               if ( tool_check_abandon( ld, msgid ) ) {
+                       return -1;
                }
 
                if( sortattr ) {
@@ -1509,7 +1507,7 @@ static int dosearch(
                                /* pagedResults stuff is dealt with
                                 * in tool_print_ctrls(), called by
                                 * print_results(). */
-                               rc = print_result( ld, msg, 1 );
+                               rc2 = print_result( ld, msg, 1 );
                                if ( ldapsync == LDAP_SYNC_REFRESH_AND_PERSIST ) {
                                        break;
                                }
@@ -1553,18 +1551,8 @@ static int dosearch(
        }
 
 done:
-       if ( tvp == NULL && rc == 0 ) {
-               ldap_get_option( ld, LDAP_OPT_RESULT_CODE, (void *)&rc );
-       }
-
-       switch ( rc ) {
-       case LDAP_SUCCESS:
-       case LDAP_REFERRAL:
-               break;
-
-       default:
-               tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
-               return( rc );
+       if ( tvp == NULL && rc != LDAP_RES_SEARCH_RESULT ) {
+               ldap_get_option( ld, LDAP_OPT_RESULT_CODE, (void *)&rc2 );
        }
 
        ldap_msgfree( res );
@@ -1598,7 +1586,11 @@ done:
                if( nreferences ) printf( _("# numReferences: %d\n"), nreferences );
        }
 
-       return( rc );
+       if ( rc != LDAP_RES_SEARCH_RESULT ) {
+               tool_perror( "ldap_result", rc2, NULL, NULL, NULL, NULL );
+       }
+
+       return( rc2 );
 }
 
 /* This is the proposed new way of doing things.