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 );
50 "-H <uri> | ([-h <host>] -p <port>) "
62 main( int argc, char **argv )
66 char *host = "localhost";
71 int retries = RETRIES;
75 tester_init( "slapd-read" );
77 while ( (i = getopt( argc, argv, "H:h:p:e:Fl:L:r:t:" )) != EOF ) {
79 case 'H': /* the server uri */
80 uri = strdup( optarg );
83 case 'h': /* the servers host */
84 host = strdup( optarg );
87 case 'p': /* the servers port */
88 if ( lutil_atoi( &port, optarg ) != 0 ) {
93 case 'e': /* DN to search for */
94 entry = strdup( optarg );
101 case 'l': /* the number of loops */
102 if ( lutil_atoi( &loops, optarg ) != 0 ) {
107 case 'L': /* the number of outerloops */
108 if ( lutil_atoi( &outerloops, optarg ) != 0 ) {
113 case 'r': /* the number of retries */
114 if ( lutil_atoi( &retries, optarg ) != 0 ) {
119 case 't': /* delay in seconds */
120 if ( lutil_atoi( &delay, optarg ) != 0 ) {
131 if (( entry == NULL ) || ( port == -1 && uri == NULL ))
134 if ( *entry == '\0' ) {
135 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
137 exit( EXIT_FAILURE );
140 uri = tester_uri( uri, host, port );
142 for ( i = 0; i < outerloops; i++ ) {
143 do_read( uri, entry, loops, retries, delay, force );
146 exit( EXIT_SUCCESS );
151 do_read( char *uri, char *entry, int maxloop,
152 int maxretries, int delay, int force )
155 int i = 0, do_retry = maxretries;
156 char *attrs[] = { "1.1", NULL };
157 pid_t pid = getpid();
158 int rc = LDAP_SUCCESS;
159 int version = LDAP_VERSION3;
160 struct berval passwd = { 0, "" };
164 ldap_initialize( &ld, uri );
166 tester_perror( "ldap_initialize" );
167 exit( EXIT_FAILURE );
170 (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
171 (void) ldap_set_option( ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF );
173 if ( do_retry == maxretries ) {
174 fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
175 (long) pid, maxloop, entry );
178 rc = ldap_sasl_bind_s( ld, NULL, LDAP_SASL_SIMPLE, &passwd, NULL, NULL, NULL );
179 if ( rc != LDAP_SUCCESS ) {
180 tester_ldap_error( ld, "ldap_sasl_bind_s" );
183 case LDAP_UNAVAILABLE:
184 if ( do_retry > 0 ) {
195 exit( EXIT_FAILURE );
198 for ( ; i < maxloop; i++ ) {
199 LDAPMessage *res = NULL;
201 rc = ldap_search_ext_s( ld, entry, LDAP_SCOPE_BASE,
202 NULL, attrs, 1, NULL, NULL, NULL, LDAP_NO_LIMIT, &res );
205 /* don't log: it's intended */
212 tester_ldap_error( ld, "ldap_search_ext_s" );
219 tester_ldap_error( ld, "ldap_search_ext_s" );
220 if ( rc == LDAP_BUSY && do_retry > 0 ) {
224 if ( rc != LDAP_NO_SUCH_OBJECT ) {
236 fprintf( stderr, " PID=%ld - Read done (%d).\n", (long) pid, rc );
238 ldap_unbind_ext( ld, NULL, NULL );