3 * Copyright 1998-2002 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 *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 )
38 char *host = "localhost";
43 while ( (i = getopt( argc, argv, "h:p:e:l:" )) != EOF ) {
45 case 'h': /* the servers host */
46 host = strdup( optarg );
49 case 'p': /* the servers port */
50 port = atoi( optarg );
53 case 'e': /* file with entry search request */
54 entry = strdup( optarg );
57 case 'l': /* the number of loops */
58 loops = atoi( optarg );
67 if (( entry == NULL ) || ( port == -1 ))
70 if ( *entry == '\0' ) {
72 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
78 do_read( host, port, entry, ( 20 * loops ));
84 do_read( char *host, int port, char *entry, int maxloop )
88 char *attrs[] = { "1.1", NULL };
91 if (( ld = ldap_init( host, port )) == NULL ) {
92 perror( "ldap_init" );
97 int version = LDAP_VERSION3;
98 (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
102 if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
103 ldap_perror( ld, "ldap_bind" );
104 exit( EXIT_FAILURE );
108 fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
109 (long) pid, maxloop, entry );
111 for ( i = 0; i < maxloop; i++ ) {
115 if (( rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE,
116 NULL, attrs, 1, &res )) != LDAP_SUCCESS ) {
118 ldap_perror( ld, "ldap_read" );
119 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
127 fprintf( stderr, " PID=%ld - Read done.\n", (long) pid );