+ while ((rc = ldap_result( ld, LDAP_RES_ANY,
+ sortattr ? 1 : 0, NULL, &res )) > 0 )
+ {
+ if( sortattr ) {
+ (void) ldap_sort_entries( ld, &res,
+ ( *sortattr == '\0' ) ? NULL : sortattr, strcasecmp );
+ }
+
+ for ( msg = ldap_first_message( ld, res );
+ msg != NULL;
+ msg = ldap_next_message( ld, msg ) )
+ {
+ nresponses++;
+
+ switch( ldap_msgtype( msg ) ) {
+ case LDAP_RES_SEARCH_ENTRY:
+ if( nresponses > 1 ) putchar('\n');
+ nentries++;
+ print_entry( ld, msg, attrsonly );
+ break;
+
+ case LDAP_RES_SEARCH_REFERENCE:
+ if( nresponses > 1 ) putchar('\n');
+ nreferences++;
+ print_reference( ld, msg );
+ break;
+
+ case LDAP_RES_EXTENDED:
+ if( nresponses > 1 ) putchar('\n');
+ nextended++;
+ print_extended( ld, msg );
+
+ rc = ldap_result2error( ld, msg, 0 );
+
+ if( rc != LDAP_SUCCESS ) {
+ ldap_perror( ld, "ldap_search" );
+ }
+
+ if( ldap_msgid( msg ) == 0 ) {
+ /* unsolicited extended operation */
+ goto done;
+ }
+
+ break;
+
+ case LDAP_RES_EXTENDED_PARTIAL:
+ if( nresponses > 1 ) putchar('\n');
+ npartial++;
+ print_partial( ld, msg );
+ break;
+
+ case LDAP_RES_SEARCH_RESULT:
+ /* if( nresponses > 1 ) putchar('\n'); */
+ rc = ldap_result2error( ld, msg, 0 );
+
+ if( rc != LDAP_SUCCESS ) {
+ ldap_perror( ld, "ldap_search" );
+ }
+
+ goto done;
+
+ }
+ }
+
+ ldap_msgfree( res );