exit( EXIT_FAILURE );
}
+/* -S: just send requests without reading responses
+ * -SS: send all requests asynchronous and immediately start reading responses
+ * -SSS: send all requests asynchronous; then read responses
+ */
+static int swamp;
+
int
main( int argc, char **argv )
{
/* by default, tolerate referrals and no such object */
tester_ignore_str2errlist( "REFERRAL,NO_SUCH_OBJECT" );
- while ( (i = getopt( argc, argv, "ACD:e:Ff:H:h:i:L:l:p:r:t:T:w:" )) != EOF ) {
+ while ( (i = getopt( argc, argv, "ACD:e:Ff:H:h:i:L:l:p:r:St:T:w:" )) != EOF ) {
switch ( i ) {
case 'A':
noattrs++;
}
break;
+ case 'S':
+ swamp++;
+ break;
+
case 't': /* delay in seconds */
if ( lutil_atoi( &delay, optarg ) != 0 ) {
usage( argv[0] );
LDAP *ld = ldp ? *ldp : NULL;
int i = 0, do_retry = maxretries;
int rc = LDAP_SUCCESS;
- int version = LDAP_VERSION3;
+ int version = LDAP_VERSION3;
+ int *msgids = NULL, active = 0;
+
+ /* make room for msgid */
+ if ( swamp > 1 ) {
+ msgids = (int *)calloc( sizeof(int), maxloop );
+ }
retry:;
if ( ld == NULL ) {
}
}
- for ( ; i < maxloop; i++ ) {
- LDAPMessage *res = NULL;
+ if ( swamp > 1 ) {
+ do {
+ LDAPMessage *res = NULL;
+ int j, msgid;
+
+ if ( i < maxloop ) {
+ rc = ldap_search_ext( ld, entry, LDAP_SCOPE_BASE,
+ NULL, attrs, noattrs, NULL, NULL,
+ NULL, LDAP_NO_LIMIT, &msgids[i] );
+
+ active++;
+#if 0
+ fprintf( stderr,
+ ">>> PID=%ld - Search(%d, %d, %d, %d): "
+ "base=\"%s\" scope=%s filter=\"%s\"\n",
+ (long) pid, maxloop, i, active, msgids[i],
+ entry, ldap_pvt_scope2str( scope ), filter );
+#endif
+ i++;
+
+ if ( rc ) {
+ char buf[BUFSIZ];
+ int first = tester_ignore_err( rc );
+ /* if ignore.. */
+ if ( first ) {
+ /* only log if first occurrence */
+ if ( ( force < 2 && first > 0 ) || abs(first) == 1 ) {
+ tester_ldap_error( ld, "ldap_search_ext", NULL );
+ }
+ continue;
+ }
+
+ /* busy needs special handling */
+ snprintf( buf, sizeof( buf ), "entry=\"%s\"\n", entry );
+ tester_ldap_error( ld, "ldap_search_ext", buf );
+ if ( rc == LDAP_BUSY && do_retry > 0 ) {
+ ldap_unbind_ext( ld, NULL, NULL );
+ ld = NULL;
+ do_retry--;
+ goto retry;
+ }
+ break;
+ }
- rc = ldap_search_ext_s( ld, entry, LDAP_SCOPE_BASE,
- NULL, attrs, noattrs, NULL, NULL, NULL,
- LDAP_NO_LIMIT, &res );
- if ( res != NULL ) {
- ldap_msgfree( res );
- }
+ if ( swamp > 2 ) {
+ continue;
+ }
+ }
- if ( rc ) {
- int first = tester_ignore_err( rc );
- char buf[ BUFSIZ ];
+ rc = ldap_result( ld, LDAP_RES_ANY, 0, NULL, &res );
+ switch ( rc ) {
+ case -1:
+ /* gone really bad */
+ goto cleanup;
+
+ case 0:
+ /* timeout (impossible) */
+ break;
+
+ case LDAP_RES_SEARCH_ENTRY:
+ case LDAP_RES_SEARCH_REFERENCE:
+ /* ignore */
+ break;
+
+ case LDAP_RES_SEARCH_RESULT:
+ /* just remove, no error checking (TODO?) */
+ msgid = ldap_msgid( res );
+
+ /* linear search, bah */
+ for ( j = 0; j < i; j++ ) {
+ if ( msgids[ j ] == msgid ) {
+ msgids[ j ] = -1;
+ active--;
+#if 0
+ fprintf( stderr,
+ "<<< PID=%ld - SearchDone(%d, %d, %d, %d): "
+ "entry=\"%s\"\n",
+ (long) pid, maxloop, j, active, msgid, entry );
+#endif
+ break;
+ }
+ }
+ break;
- snprintf( buf, sizeof( buf ), "ldap_search_ext_s(%s)", entry );
+ default:
+ /* other messages unexpected */
+ fprintf( stderr,
+ "### PID=%ld - Search(%d): "
+ "entry=\"%s\" attrs=%s%s. unexpected response tag=%d\n",
+ (long) pid, maxloop,
+ entry, attrs[0], attrs[1] ? " (more...)" : "", rc );
+ break;
+ }
- /* if ignore.. */
- if ( first ) {
- /* only log if first occurrence */
- if ( ( force < 2 && first > 0 ) || abs(first) == 1 ) {
- tester_ldap_error( ld, buf, NULL );
- }
- continue;
+ if ( res != NULL ) {
+ ldap_msgfree( res );
}
+ } while ( i < maxloop || active > 0 );
- /* busy needs special handling */
- tester_ldap_error( ld, buf, NULL );
- if ( rc == LDAP_BUSY && do_retry > 0 ) {
- ldap_unbind_ext( ld, NULL, NULL );
- ld = NULL;
- do_retry--;
- goto retry;
+ } else {
+ for ( ; i < maxloop; i++ ) {
+ LDAPMessage *res = NULL;
+
+ if (swamp) {
+ int msgid;
+ rc = ldap_search_ext( ld, entry, LDAP_SCOPE_BASE,
+ NULL, attrs, noattrs, NULL, NULL,
+ NULL, LDAP_NO_LIMIT, &msgid );
+ if ( rc == LDAP_SUCCESS ) continue;
+ else break;
+ }
+
+ rc = ldap_search_ext_s( ld, entry, LDAP_SCOPE_BASE,
+ NULL, attrs, noattrs, NULL, NULL, NULL,
+ LDAP_NO_LIMIT, &res );
+ if ( res != NULL ) {
+ ldap_msgfree( res );
+ }
+
+ if ( rc ) {
+ int first = tester_ignore_err( rc );
+ char buf[ BUFSIZ ];
+
+ snprintf( buf, sizeof( buf ), "ldap_search_ext_s(%s)", entry );
+
+ /* if ignore.. */
+ if ( first ) {
+ /* only log if first occurrence */
+ if ( ( force < 2 && first > 0 ) || abs(first) == 1 ) {
+ tester_ldap_error( ld, buf, NULL );
+ }
+ continue;
+ }
+
+ /* busy needs special handling */
+ tester_ldap_error( ld, buf, NULL );
+ if ( rc == LDAP_BUSY && do_retry > 0 ) {
+ ldap_unbind_ext( ld, NULL, NULL );
+ ld = NULL;
+ do_retry--;
+ goto retry;
+ }
+ break;
}
- break;
}
}
+cleanup:;
+ if ( msgids != NULL ) {
+ free( msgids );
+ }
+
if ( ldp != NULL ) {
*ldp = ld;