11 #include <sys/param.h>
19 do_read( char *host, int port, char *entry, int maxloop );
24 fprintf( stderr, "usage: %s [-h <host>] -p port -e <entry> [-l <loops>]\n",
30 main( int argc, char **argv )
33 char *host = "localhost";
38 while ( (i = getopt( argc, argv, "h:p:e:l:" )) != EOF ) {
40 case 'h': /* the servers host */
41 host = strdup( optarg );
44 case 'p': /* the servers port */
45 port = atoi( optarg );
48 case 'e': /* file with entry search request */
49 entry = strdup( optarg );
52 case 'l': /* the number of loops */
53 loops = atoi( optarg );
62 if (( entry == NULL ) || ( port == -1 ))
65 if ( *entry == '\0' ) {
67 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
73 do_read( host, port, entry, ( 4 * loops ));
80 do_read( char *host, int port, char *entry, int maxloop )
84 char *attrs[] = { "cn", "sn", NULL };
85 char *filter = "(objectclass=*)";
88 if (( ld = ldap_init( host, port )) == NULL ) {
89 perror( "ldap_init" );
93 if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
94 ldap_perror( ld, "ldap_bind" );
99 fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
100 pid, maxloop, entry );
102 for ( i = 0; i < maxloop; i++ ) {
106 if (( rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE,
107 filter, attrs, 0, &res )) != LDAP_SUCCESS ) {
109 ldap_perror( ld, "ldap_read" );
110 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
118 fprintf( stderr, " PID=%ld - Read done.\n", pid );