mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-20 22:59:34 -05:00
add 'swamp' capability to slapd-read, also via slapd-tester
This commit is contained in:
parent
5e5b061719
commit
2b3b07da46
2 changed files with 172 additions and 34 deletions
|
|
@ -77,6 +77,12 @@ usage( char *name )
|
||||||
exit( EXIT_FAILURE );
|
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
|
int
|
||||||
main( int argc, char **argv )
|
main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
|
|
@ -104,7 +110,7 @@ main( int argc, char **argv )
|
||||||
/* by default, tolerate referrals and no such object */
|
/* by default, tolerate referrals and no such object */
|
||||||
tester_ignore_str2errlist( "REFERRAL,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 ) {
|
switch ( i ) {
|
||||||
case 'A':
|
case 'A':
|
||||||
noattrs++;
|
noattrs++;
|
||||||
|
|
@ -176,6 +182,10 @@ main( int argc, char **argv )
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'S':
|
||||||
|
swamp++;
|
||||||
|
break;
|
||||||
|
|
||||||
case 't': /* delay in seconds */
|
case 't': /* delay in seconds */
|
||||||
if ( lutil_atoi( &delay, optarg ) != 0 ) {
|
if ( lutil_atoi( &delay, optarg ) != 0 ) {
|
||||||
usage( argv[0] );
|
usage( argv[0] );
|
||||||
|
|
@ -334,7 +344,13 @@ do_read( char *uri, char *manager, struct berval *passwd, char *entry,
|
||||||
LDAP *ld = ldp ? *ldp : NULL;
|
LDAP *ld = ldp ? *ldp : NULL;
|
||||||
int i = 0, do_retry = maxretries;
|
int i = 0, do_retry = maxretries;
|
||||||
int rc = LDAP_SUCCESS;
|
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:;
|
retry:;
|
||||||
if ( ld == NULL ) {
|
if ( ld == NULL ) {
|
||||||
|
|
@ -378,43 +394,158 @@ retry:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( ; i < maxloop; i++ ) {
|
if ( swamp > 1 ) {
|
||||||
LDAPMessage *res = NULL;
|
do {
|
||||||
|
LDAPMessage *res = NULL;
|
||||||
|
int j, msgid;
|
||||||
|
|
||||||
rc = ldap_search_ext_s( ld, entry, LDAP_SCOPE_BASE,
|
if ( i < maxloop ) {
|
||||||
NULL, attrs, noattrs, NULL, NULL, NULL,
|
rc = ldap_search_ext( ld, entry, LDAP_SCOPE_BASE,
|
||||||
LDAP_NO_LIMIT, &res );
|
NULL, attrs, noattrs, NULL, NULL,
|
||||||
if ( res != NULL ) {
|
NULL, LDAP_NO_LIMIT, &msgids[i] );
|
||||||
ldap_msgfree( res );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( rc ) {
|
active++;
|
||||||
int first = tester_ignore_err( rc );
|
#if 0
|
||||||
char buf[ BUFSIZ ];
|
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++;
|
||||||
|
|
||||||
snprintf( buf, sizeof( buf ), "ldap_search_ext_s(%s)", entry );
|
if ( rc ) {
|
||||||
|
char buf[BUFSIZ];
|
||||||
/* if ignore.. */
|
int first = tester_ignore_err( rc );
|
||||||
if ( first ) {
|
/* if ignore.. */
|
||||||
/* only log if first occurrence */
|
if ( first ) {
|
||||||
if ( ( force < 2 && first > 0 ) || abs(first) == 1 ) {
|
/* only log if first occurrence */
|
||||||
tester_ldap_error( ld, buf, NULL );
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( swamp > 2 ) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* busy needs special handling */
|
rc = ldap_result( ld, LDAP_RES_ANY, 0, NULL, &res );
|
||||||
tester_ldap_error( ld, buf, NULL );
|
switch ( rc ) {
|
||||||
if ( rc == LDAP_BUSY && do_retry > 0 ) {
|
case -1:
|
||||||
ldap_unbind_ext( ld, NULL, NULL );
|
/* gone really bad */
|
||||||
ld = NULL;
|
goto cleanup;
|
||||||
do_retry--;
|
|
||||||
goto retry;
|
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;
|
||||||
|
|
||||||
|
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 ( res != NULL ) {
|
||||||
|
ldap_msgfree( res );
|
||||||
|
}
|
||||||
|
} while ( i < maxloop || active > 0 );
|
||||||
|
|
||||||
|
} 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 ) {
|
if ( ldp != NULL ) {
|
||||||
*ldp = ld;
|
*ldp = ld;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -482,7 +482,6 @@ main( int argc, char **argv )
|
||||||
}
|
}
|
||||||
|
|
||||||
/* setup friendly option */
|
/* setup friendly option */
|
||||||
|
|
||||||
switch ( friendly ) {
|
switch ( friendly ) {
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
|
|
@ -498,6 +497,15 @@ main( int argc, char **argv )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* setup swamp option */
|
||||||
|
if ( swamp ) {
|
||||||
|
swampopt[0] = '-';
|
||||||
|
if ( swamp > 3 ) swamp = 3;
|
||||||
|
swampopt[swamp + 1] = '\0';
|
||||||
|
for ( ; swamp-- > 0; ) swampopt[swamp + 1] = 'S';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* setup loop options */
|
||||||
if ( sloops[0] == '\0' ) snprintf( sloops, sizeof( sloops ), "%d", 10 * loops );
|
if ( sloops[0] == '\0' ) snprintf( sloops, sizeof( sloops ), "%d", 10 * loops );
|
||||||
if ( rloops[0] == '\0' ) snprintf( rloops, sizeof( rloops ), "%d", 20 * loops );
|
if ( rloops[0] == '\0' ) snprintf( rloops, sizeof( rloops ), "%d", 20 * loops );
|
||||||
if ( aloops[0] == '\0' ) snprintf( aloops, sizeof( aloops ), "%d", loops );
|
if ( aloops[0] == '\0' ) snprintf( aloops, sizeof( aloops ), "%d", loops );
|
||||||
|
|
@ -551,10 +559,6 @@ main( int argc, char **argv )
|
||||||
sargs[sanum++] = ignore;
|
sargs[sanum++] = ignore;
|
||||||
}
|
}
|
||||||
if ( swamp ) {
|
if ( swamp ) {
|
||||||
swampopt[0] = '-';
|
|
||||||
if ( swamp > 3 ) swamp = 3;
|
|
||||||
swampopt[swamp + 1] = '\0';
|
|
||||||
for ( ; swamp-- > 0; ) swampopt[swamp + 1] = 'S';
|
|
||||||
sargs[sanum++] = swampopt;
|
sargs[sanum++] = swampopt;
|
||||||
}
|
}
|
||||||
sargs[sanum++] = "-b";
|
sargs[sanum++] = "-b";
|
||||||
|
|
@ -612,6 +616,9 @@ main( int argc, char **argv )
|
||||||
rargs[ranum++] = "-i";
|
rargs[ranum++] = "-i";
|
||||||
rargs[ranum++] = ignore;
|
rargs[ranum++] = ignore;
|
||||||
}
|
}
|
||||||
|
if ( swamp ) {
|
||||||
|
rargs[ranum++] = swampopt;
|
||||||
|
}
|
||||||
rargs[ranum++] = "-e";
|
rargs[ranum++] = "-e";
|
||||||
rargs[ranum++] = NULL; /* will hold the read entry */
|
rargs[ranum++] = NULL; /* will hold the read entry */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue