3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/stdlib.h>
13 #include <ac/socket.h>
14 #include <ac/string.h>
15 #include <ac/unistd.h>
18 #ifdef HAVE_SYS_PARAM_H
19 #include <sys/param.h>
27 do_read( char *host, int port, char *entry, int maxloop );
32 fprintf( stderr, "usage: %s [-h <host>] -p port -e <entry> [-l <loops>]\n",
38 main( int argc, char **argv )
41 char *host = "localhost";
46 while ( (i = getopt( argc, argv, "h:p:e:l:" )) != EOF ) {
48 case 'h': /* the servers host */
49 host = strdup( optarg );
52 case 'p': /* the servers port */
53 port = atoi( optarg );
56 case 'e': /* file with entry search request */
57 entry = strdup( optarg );
60 case 'l': /* the number of loops */
61 loops = atoi( optarg );
70 if (( entry == NULL ) || ( port == -1 ))
73 if ( *entry == '\0' ) {
75 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
81 do_read( host, port, entry, ( 4 * loops ));
88 do_read( char *host, int port, char *entry, int maxloop )
92 char *attrs[] = { "cn", "sn", NULL };
93 char *filter = "(objectclass=*)";
96 if (( ld = ldap_init( host, port )) == NULL ) {
97 perror( "ldap_init" );
101 if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
102 ldap_perror( ld, "ldap_bind" );
103 exit( EXIT_FAILURE );
107 fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
108 (long) pid, maxloop, entry );
110 for ( i = 0; i < maxloop; i++ ) {
114 if (( rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE,
115 filter, attrs, 0, &res )) != LDAP_SUCCESS ) {
117 ldap_perror( ld, "ldap_read" );
118 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
126 fprintf( stderr, " PID=%ld - Read done.\n", (long) pid );