3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/stdlib.h>
14 #include <ac/socket.h>
15 #include <ac/string.h>
16 #include <ac/unistd.h>
24 do_read( char *uri, char *host, int port, char *entry, int maxloop );
29 fprintf( stderr, "usage: %s [-h <host>] -p port -e <entry> [-l <loops>]\n",
35 main( int argc, char **argv )
39 char *host = "localhost";
44 while ( (i = getopt( argc, argv, "H:h:p:e:l:" )) != EOF ) {
46 case 'H': /* the server uri */
47 uri = strdup( optarg );
49 case 'h': /* the servers host */
50 host = strdup( optarg );
53 case 'p': /* the servers port */
54 port = atoi( optarg );
57 case 'e': /* file with entry search request */
58 entry = strdup( optarg );
61 case 'l': /* the number of loops */
62 loops = atoi( optarg );
71 if (( entry == NULL ) || ( port == -1 && uri == NULL ))
74 if ( *entry == '\0' ) {
76 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
82 do_read( uri, host, port, entry, ( 20 * loops ));
88 do_read( char *uri, char *host, int port, char *entry, int maxloop )
92 char *attrs[] = { "1.1", NULL };
96 ldap_initialize( &ld, uri );
98 ld = ldap_init( host, port );
101 perror( "ldap_init" );
102 exit( EXIT_FAILURE );
106 int version = LDAP_VERSION3;
107 (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
111 if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
112 ldap_perror( ld, "ldap_bind" );
113 exit( EXIT_FAILURE );
117 fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
118 (long) pid, maxloop, entry );
120 for ( i = 0; i < maxloop; i++ ) {
124 if (( rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE,
125 NULL, attrs, 1, &res )) != LDAP_SUCCESS ) {
127 ldap_perror( ld, "ldap_read" );
128 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
136 fprintf( stderr, " PID=%ld - Read done.\n", (long) pid );