2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2004 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>
33 #define LDAP_DEPRECATED 1
39 do_read( char *uri, char *host, int port, char *entry, int maxloop );
44 fprintf( stderr, "usage: %s [-h <host>] -p port -e <entry> [-l <loops>]\n",
50 main( int argc, char **argv )
54 char *host = "localhost";
59 while ( (i = getopt( argc, argv, "H:h:p:e:l:" )) != EOF ) {
61 case 'H': /* the server uri */
62 uri = strdup( optarg );
64 case 'h': /* the servers host */
65 host = strdup( optarg );
68 case 'p': /* the servers port */
69 port = atoi( optarg );
72 case 'e': /* file with entry search request */
73 entry = strdup( optarg );
76 case 'l': /* the number of loops */
77 loops = atoi( optarg );
86 if (( entry == NULL ) || ( port == -1 && uri == NULL ))
89 if ( *entry == '\0' ) {
91 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
97 do_read( uri, host, port, entry, ( 20 * loops ));
103 do_read( char *uri, char *host, int port, char *entry, int maxloop )
107 char *attrs[] = { "1.1", NULL };
108 pid_t pid = getpid();
109 int rc = LDAP_SUCCESS;
112 ldap_initialize( &ld, uri );
114 ld = ldap_init( host, port );
117 perror( "ldap_init" );
118 exit( EXIT_FAILURE );
122 int version = LDAP_VERSION3;
123 (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
127 if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
128 ldap_perror( ld, "ldap_bind" );
129 exit( EXIT_FAILURE );
133 fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
134 (long) pid, maxloop, entry );
136 for ( i = 0; i < maxloop; i++ ) {
139 rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE,
140 NULL, attrs, 1, &res );
141 if ( rc != LDAP_SUCCESS ) {
142 ldap_perror( ld, "ldap_read" );
143 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
151 fprintf( stderr, " PID=%ld - Read done (%d).\n", (long) pid, rc );