2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2006 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 * This work was initially developed by Kurt Spanier for inclusion
17 * in OpenLDAP Software.
24 #include <ac/stdlib.h>
28 #include <ac/socket.h>
29 #include <ac/string.h>
30 #include <ac/unistd.h>
36 #include "slapd-common.h"
42 do_read( char *uri, char *entry, int maxloop,
43 int maxretries, int delay );
50 "-H <uri> | ([-h <host>] -p <port>) "
61 main( int argc, char **argv )
65 char *host = "localhost";
70 int retries = RETRIES;
73 tester_init( "slapd-read" );
75 while ( (i = getopt( argc, argv, "H:h:p:e:l:L:r:t:" )) != EOF ) {
77 case 'H': /* the server uri */
78 uri = strdup( optarg );
81 case 'h': /* the servers host */
82 host = strdup( optarg );
85 case 'p': /* the servers port */
86 if ( lutil_atoi( &port, optarg ) != 0 ) {
91 case 'e': /* DN to search for */
92 entry = strdup( optarg );
95 case 'l': /* the number of loops */
96 if ( lutil_atoi( &loops, optarg ) != 0 ) {
101 case 'L': /* the number of outerloops */
102 if ( lutil_atoi( &outerloops, optarg ) != 0 ) {
107 case 'r': /* the number of retries */
108 if ( lutil_atoi( &retries, optarg ) != 0 ) {
113 case 't': /* delay in seconds */
114 if ( lutil_atoi( &delay, optarg ) != 0 ) {
125 if (( entry == NULL ) || ( port == -1 && uri == NULL ))
128 if ( *entry == '\0' ) {
129 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
131 exit( EXIT_FAILURE );
134 uri = tester_uri( uri, host, port );
136 for ( i = 0; i < outerloops; i++ ) {
137 do_read( uri, entry, loops, retries, delay );
140 exit( EXIT_SUCCESS );
145 do_read( char *uri, char *entry, int maxloop,
146 int maxretries, int delay )
149 int i = 0, do_retry = maxretries;
150 char *attrs[] = { "1.1", NULL };
151 pid_t pid = getpid();
152 int rc = LDAP_SUCCESS;
153 int version = LDAP_VERSION3;
154 struct berval passwd = { 0, "" };
157 ldap_initialize( &ld, uri );
159 tester_perror( "ldap_initialize" );
160 exit( EXIT_FAILURE );
163 (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
165 if ( do_retry == maxretries ) {
166 fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
167 (long) pid, maxloop, entry );
170 rc = ldap_sasl_bind_s( ld, NULL, LDAP_SASL_SIMPLE, &passwd, NULL, NULL, NULL );
171 if ( rc != LDAP_SUCCESS ) {
172 tester_ldap_error( ld, "ldap_sasl_bind_s" );
175 case LDAP_UNAVAILABLE:
176 if ( do_retry > 0 ) {
187 exit( EXIT_FAILURE );
190 for ( ; i < maxloop; i++ ) {
193 rc = ldap_search_ext_s( ld, entry, LDAP_SCOPE_BASE,
194 NULL, attrs, 1, NULL, NULL, NULL, LDAP_NO_LIMIT, &res );
195 if ( rc != LDAP_SUCCESS ) {
196 tester_ldap_error( ld, "ldap_search_ext_s" );
197 if ( rc == LDAP_BUSY && do_retry > 0 ) {
201 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
209 fprintf( stderr, " PID=%ld - Read done (%d).\n", (long) pid, rc );
211 ldap_unbind_ext( ld, NULL, NULL );