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, int force, int chaserefs );
50 "-H <uri> | ([-h <host>] -p <port>) "
63 main( int argc, char **argv )
67 char *host = "localhost";
72 int retries = RETRIES;
77 tester_init( "slapd-read" );
79 while ( (i = getopt( argc, argv, "CH:h:p:e:Fl:L:r:t:" )) != EOF ) {
85 case 'H': /* the server uri */
86 uri = strdup( optarg );
89 case 'h': /* the servers host */
90 host = strdup( optarg );
93 case 'p': /* the servers port */
94 if ( lutil_atoi( &port, optarg ) != 0 ) {
99 case 'e': /* DN to search for */
100 entry = strdup( optarg );
107 case 'l': /* the number of loops */
108 if ( lutil_atoi( &loops, optarg ) != 0 ) {
113 case 'L': /* the number of outerloops */
114 if ( lutil_atoi( &outerloops, optarg ) != 0 ) {
119 case 'r': /* the number of retries */
120 if ( lutil_atoi( &retries, optarg ) != 0 ) {
125 case 't': /* delay in seconds */
126 if ( lutil_atoi( &delay, optarg ) != 0 ) {
137 if (( entry == NULL ) || ( port == -1 && uri == NULL ))
140 if ( *entry == '\0' ) {
141 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
143 exit( EXIT_FAILURE );
146 uri = tester_uri( uri, host, port );
148 for ( i = 0; i < outerloops; i++ ) {
149 do_read( uri, entry, loops, retries, delay, force, chaserefs );
152 exit( EXIT_SUCCESS );
157 do_read( char *uri, char *entry, int maxloop,
158 int maxretries, int delay, int force, int chaserefs )
161 int i = 0, do_retry = maxretries;
162 char *attrs[] = { "1.1", NULL };
163 pid_t pid = getpid();
164 int rc = LDAP_SUCCESS;
165 int version = LDAP_VERSION3;
166 struct berval passwd = { 0, "" };
170 ldap_initialize( &ld, uri );
172 tester_perror( "ldap_initialize" );
173 exit( EXIT_FAILURE );
176 (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
177 (void) ldap_set_option( ld, LDAP_OPT_REFERRALS,
178 chaserefs ? LDAP_OPT_ON : LDAP_OPT_OFF );
180 if ( do_retry == maxretries ) {
181 fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
182 (long) pid, maxloop, entry );
185 rc = ldap_sasl_bind_s( ld, NULL, LDAP_SASL_SIMPLE, &passwd, NULL, NULL, NULL );
186 if ( rc != LDAP_SUCCESS ) {
187 tester_ldap_error( ld, "ldap_sasl_bind_s" );
190 case LDAP_UNAVAILABLE:
191 if ( do_retry > 0 ) {
202 exit( EXIT_FAILURE );
205 for ( ; i < maxloop; i++ ) {
206 LDAPMessage *res = NULL;
208 rc = ldap_search_ext_s( ld, entry, LDAP_SCOPE_BASE,
209 NULL, attrs, 1, NULL, NULL, NULL, LDAP_NO_LIMIT, &res );
212 /* don't log: it's intended */
219 tester_ldap_error( ld, "ldap_search_ext_s" );
226 tester_ldap_error( ld, "ldap_search_ext_s" );
227 if ( rc == LDAP_BUSY && do_retry > 0 ) {
231 if ( rc != LDAP_NO_SUCH_OBJECT ) {
243 fprintf( stderr, " PID=%ld - Read done (%d).\n", (long) pid, rc );
245 ldap_unbind_ext( ld, NULL, NULL );