2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2003 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>
38 do_read( char *uri, char *host, int port, char *entry, int maxloop );
43 fprintf( stderr, "usage: %s [-h <host>] -p port -e <entry> [-l <loops>]\n",
49 main( int argc, char **argv )
53 char *host = "localhost";
58 while ( (i = getopt( argc, argv, "H:h:p:e:l:" )) != EOF ) {
60 case 'H': /* the server uri */
61 uri = strdup( optarg );
63 case 'h': /* the servers host */
64 host = strdup( optarg );
67 case 'p': /* the servers port */
68 port = atoi( optarg );
71 case 'e': /* file with entry search request */
72 entry = strdup( optarg );
75 case 'l': /* the number of loops */
76 loops = atoi( optarg );
85 if (( entry == NULL ) || ( port == -1 && uri == NULL ))
88 if ( *entry == '\0' ) {
90 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
96 do_read( uri, host, port, entry, ( 20 * loops ));
102 do_read( char *uri, char *host, int port, char *entry, int maxloop )
106 char *attrs[] = { "1.1", NULL };
107 pid_t pid = getpid();
110 ldap_initialize( &ld, uri );
112 ld = ldap_init( host, port );
115 perror( "ldap_init" );
116 exit( EXIT_FAILURE );
120 int version = LDAP_VERSION3;
121 (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
125 if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
126 ldap_perror( ld, "ldap_bind" );
127 exit( EXIT_FAILURE );
131 fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
132 (long) pid, maxloop, entry );
134 for ( i = 0; i < maxloop; i++ ) {
138 if (( rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE,
139 NULL, attrs, 1, &res )) != LDAP_SUCCESS ) {
141 ldap_perror( ld, "ldap_read" );
142 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
150 fprintf( stderr, " PID=%ld - Read done.\n", (long) pid );