12 #include <sys/param.h>
20 do_read( char *host, int port, char *entry, int maxloop );
25 fprintf( stderr, "usage: %s [-h <host>] -p port -e <entry> [-l <loops>]\n",
31 main( int argc, char **argv )
34 char *host = "localhost";
39 while ( (i = getopt( argc, argv, "h:p:e:l:" )) != EOF ) {
41 case 'h': /* the servers host */
42 host = strdup( optarg );
45 case 'p': /* the servers port */
46 port = atoi( optarg );
49 case 'e': /* file with entry search request */
50 entry = strdup( optarg );
53 case 'l': /* the number of loops */
54 loops = atoi( optarg );
63 if (( entry == NULL ) || ( port == -1 ))
66 if ( *entry == '\0' ) {
68 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
74 do_read( host, port, entry, ( 4 * loops ));
81 do_read( char *host, int port, char *entry, int maxloop )
85 char *attrs[] = { "cn", "sn", NULL };
86 char *filter = "(objectclass=*)";
89 if (( ld = ldap_init( host, port )) == NULL ) {
90 perror( "ldap_init" );
94 if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
95 ldap_perror( ld, "ldap_bind" );
100 fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
101 (long) pid, maxloop, entry );
103 for ( i = 0; i < maxloop; i++ ) {
107 if (( rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE,
108 filter, attrs, 0, &res )) != LDAP_SUCCESS ) {
110 ldap_perror( ld, "ldap_read" );
111 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
119 fprintf( stderr, " PID=%ld - Read done.\n", (long) pid );